2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/integration-api/events/touch-event-integ.h>
21 #include <dali/integration-api/render-task-list-integ.h>
22 #include <dali/public-api/dali-core.h>
24 #include <test-touch-event-utils.h>
30 void utc_dali_pinch_gesture_detector_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_pinch_gesture_detector_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled(false),
48 voidFunctorCalled(false),
55 functorCalled = false;
56 voidFunctorCalled = false;
58 receivedGesture.Reset();
64 bool voidFunctorCalled;
65 PinchGesture receivedGesture;
69 // Functor that sets the data when called
70 struct GestureReceivedFunctor
72 GestureReceivedFunctor(SignalData& data)
77 void operator()(Actor actor, const PinchGesture& pinch)
79 signalData.functorCalled = true;
80 signalData.receivedGesture = pinch;
81 signalData.pinchedActor = actor;
86 signalData.voidFunctorCalled = true;
89 SignalData& signalData;
92 // Functor that removes the gestured actor from stage
93 struct UnstageActorFunctor : public GestureReceivedFunctor
95 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
96 : GestureReceivedFunctor(data),
97 stateToUnstage(stateToUnstage),
102 void operator()(Actor actor, const PinchGesture& pinch)
104 GestureReceivedFunctor::operator()(actor, pinch);
106 if(pinch.GetState() == stateToUnstage)
112 GestureState& stateToUnstage;
113 Integration::Scene scene;
118 ///////////////////////////////////////////////////////////////////////////////
120 int UtcDaliPinchGestureDetectorConstructor(void)
122 TestApplication application;
124 PinchGestureDetector detector;
125 DALI_TEST_CHECK(!detector);
129 int UtcDaliPinchGestureDetectorCopyConstructorP(void)
131 TestApplication application;
133 PinchGestureDetector detector = PinchGestureDetector::New();
135 PinchGestureDetector copy(detector);
136 DALI_TEST_CHECK(detector);
140 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
142 TestApplication application;
144 PinchGestureDetector detector = PinchGestureDetector::New();
146 PinchGestureDetector assign;
148 DALI_TEST_CHECK(detector);
150 DALI_TEST_CHECK(detector == assign);
154 int UtcDaliPinchGestureDetectorMoveConstructorP(void)
156 TestApplication application;
158 PinchGestureDetector detector = PinchGestureDetector::New();
159 DALI_TEST_CHECK(detector);
161 PinchGestureDetector moved = std::move(detector);
162 DALI_TEST_CHECK(moved);
163 DALI_TEST_CHECK(!detector);
167 int UtcDaliPinchGestureDetectorMoveAssignmentOperatorP(void)
169 TestApplication application;
171 PinchGestureDetector detector;
172 detector = PinchGestureDetector::New();
173 DALI_TEST_CHECK(detector);
175 PinchGestureDetector moved;
176 moved = std::move(detector);
177 DALI_TEST_CHECK(moved);
178 DALI_TEST_CHECK(!detector);
182 int UtcDaliPinchGestureDetectorNew(void)
184 TestApplication application;
186 PinchGestureDetector detector = PinchGestureDetector::New();
188 DALI_TEST_CHECK(detector);
190 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
191 Actor actor = Actor::New();
192 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
193 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
194 application.GetScene().Add(actor);
197 application.SendNotification();
198 application.Render();
200 detector.Attach(actor);
202 Integration::TouchEvent touchEvent(1);
203 Integration::Point point;
204 point.SetDeviceId(1);
205 point.SetState(PointState::DOWN);
206 point.SetScreenPosition(Vector2(20.0f, 20.0f));
207 touchEvent.AddPoint(point);
208 application.ProcessEvent(touchEvent);
210 Integration::Point point2;
211 point.SetDeviceId(1);
212 point.SetState(PointState::DOWN);
213 point.SetScreenPosition(Vector2(20.0f, 20.0f));
214 touchEvent.AddPoint(point2);
215 application.ProcessEvent(touchEvent);
219 int UtcDaliPinchGestureDetectorDownCast(void)
221 TestApplication application;
222 tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
224 PinchGestureDetector detector = PinchGestureDetector::New();
226 BaseHandle object(detector);
228 PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
229 DALI_TEST_CHECK(detector2);
231 PinchGestureDetector detector3 = DownCast<PinchGestureDetector>(object);
232 DALI_TEST_CHECK(detector3);
234 BaseHandle unInitializedObject;
235 PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
236 DALI_TEST_CHECK(!detector4);
238 PinchGestureDetector detector5 = DownCast<PinchGestureDetector>(unInitializedObject);
239 DALI_TEST_CHECK(!detector5);
241 GestureDetector detector6 = PinchGestureDetector::New();
242 PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
243 DALI_TEST_CHECK(detector7);
247 // Negative test case for a method
248 int UtcDaliPinchGestureSignalReceptionNegative(void)
250 TestApplication application;
252 Actor actor = Actor::New();
253 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
254 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
255 application.GetScene().Add(actor);
258 application.SendNotification();
259 application.Render();
262 GestureReceivedFunctor functor(data);
264 PinchGestureDetector detector = PinchGestureDetector::New();
265 detector.Attach(actor);
266 detector.DetectedSignal().Connect(&application, functor);
268 // Do a pinch outside actor's area
269 TestStartPinch(application, Vector2(112.0f, 62.0f), Vector2(112.0f, 162.0f), Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), 100);
271 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
273 // Continue pinch into actor's area - we should still not receive the signal
275 TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
277 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
279 // Stop pinching - we should still not receive the signal
281 TestEndPinch(application, Vector2(6.0f, 6.0f), Vector2(18.0f, 18.0f), Vector2(10.0f, 8.0f), Vector2(14.0f, 16.0f), 300);
283 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
287 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
289 TestApplication application;
291 Actor actor = Actor::New();
292 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
293 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
294 application.GetScene().Add(actor);
297 application.SendNotification();
298 application.Render();
301 GestureReceivedFunctor functor(data);
303 PinchGestureDetector detector = PinchGestureDetector::New();
304 detector.Attach(actor);
305 detector.DetectedSignal().Connect(&application, functor);
307 // Start pan within the actor's area
308 TestStartPinch(application, Vector2(5.0f, 20.0f), Vector2(35.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
309 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
310 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
311 DALI_TEST_EQUALS(0.666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
312 DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
313 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
314 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
316 // Continue the pan within the actor's area - we should still receive the signal
318 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), 400);
319 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
320 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
321 DALI_TEST_EQUALS(0.2666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
322 DALI_TEST_EQUALS(80.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
323 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
324 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
326 // Pinch Gesture leaves actor's area - we should still receive the signal
328 TestContinuePinch(application, Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), 1000);
329 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
330 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
331 DALI_TEST_EQUALS(1.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
332 DALI_TEST_EQUALS(213.333f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
333 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
334 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
336 // Gesture ends - we would receive a finished state
338 TestEndPinch(application, Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), Vector2(305.0f, 10.0f), Vector2(315.0f, 10.0f), 1500);
339 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
340 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
341 DALI_TEST_EQUALS(0.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
342 DALI_TEST_EQUALS(600.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
343 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
344 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
348 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
350 TestApplication application;
352 Actor actor = Actor::New();
353 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
354 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
355 application.GetScene().Add(actor);
358 application.SendNotification();
359 application.Render();
362 GestureReceivedFunctor functor(data);
364 PinchGestureDetector detector = PinchGestureDetector::New();
365 detector.Attach(actor);
366 detector.DetectedSignal().Connect(&application, functor);
368 // Start pinch within the actor's area
369 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
370 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
371 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
372 DALI_TEST_EQUALS(0.555f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
373 DALI_TEST_EQUALS(106.667f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
374 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
375 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
377 // Continue the pinch within the actor's area - we should still receive the signal
379 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
380 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
381 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
382 DALI_TEST_EQUALS(0.277f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
383 DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
384 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
385 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
387 // Gesture ends within actor's area - we would receive a finished state
389 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
390 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
391 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
392 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
393 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
394 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
395 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
399 int UtcDaliPinchGestureSignalReceptionDetach(void)
401 TestApplication application;
403 Actor actor = Actor::New();
404 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
405 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
406 application.GetScene().Add(actor);
409 application.SendNotification();
410 application.Render();
413 GestureReceivedFunctor functor(data);
415 PinchGestureDetector detector = PinchGestureDetector::New();
416 detector.Attach(actor);
417 detector.DetectedSignal().Connect(&application, functor);
419 // Start pinch within the actor's area
420 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
421 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
422 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
424 // Continue the pinch within the actor's area - we should still receive the signal
426 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
427 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
428 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
430 // Gesture ends within actor's area
432 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
433 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
434 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
437 detector.DetachAll();
439 // Ensure we are no longer signalled
441 TestGeneratePinch(application);
442 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
446 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
448 TestApplication application;
450 Actor actor = Actor::New();
451 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
452 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
453 application.GetScene().Add(actor);
456 application.SendNotification();
457 application.Render();
460 GestureReceivedFunctor functor(data);
462 PinchGestureDetector detector = PinchGestureDetector::New();
463 detector.Attach(actor);
464 detector.DetectedSignal().Connect(&application, functor);
466 // Start pinch within the actor's area
467 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
468 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
469 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
471 // Continue the pinch within the actor's area - we should still receive the signal
473 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
474 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
475 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
477 // Detach actor during the pinch, we should not receive the next event
478 detector.DetachAll();
480 // Gesture ends within actor's area
482 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
483 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
487 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
489 TestApplication application;
492 GestureReceivedFunctor functor(data);
494 PinchGestureDetector detector = PinchGestureDetector::New();
495 detector.DetectedSignal().Connect(&application, functor);
497 // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
499 Actor tempActor = Actor::New();
500 tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
501 tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
502 application.GetScene().Add(tempActor);
503 detector.Attach(tempActor);
505 // Actor lifetime is scoped
507 Actor actor = Actor::New();
508 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
509 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
510 application.GetScene().Add(actor);
513 application.SendNotification();
514 application.Render();
516 detector.Attach(actor);
518 // Start pinch within the actor's area
519 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
520 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
521 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
523 // Continue the pinch within the actor's area - we should still receive the signal
525 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
526 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
527 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
529 // Remove the actor from stage and reset the data
530 application.GetScene().Remove(actor);
533 application.SendNotification();
534 application.Render();
537 // Actor should now have been destroyed
539 // Gesture ends within the area where the actor used to be
541 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
542 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
546 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
548 TestApplication application;
550 Actor actor = Actor::New();
551 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
552 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
553 application.GetScene().Add(actor);
555 // Render and notify a couple of times
556 application.SendNotification();
557 application.Render();
560 GestureReceivedFunctor functor(data);
562 PinchGestureDetector detector = PinchGestureDetector::New();
563 detector.Attach(actor);
564 detector.DetectedSignal().Connect(&application, functor);
566 // Do an entire pinch, only check finished value
567 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
569 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
570 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
571 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
572 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
573 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
574 DALI_TEST_EQUALS(Vector2(70.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
576 // Rotate actor again and render and notify
577 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
578 application.SendNotification();
579 application.Render();
581 // Do an entire pinch, only check finished value
582 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
584 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
585 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
586 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
587 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
588 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
589 DALI_TEST_EQUALS(Vector2(30.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
591 // Rotate actor again and render and notify
592 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
593 application.SendNotification();
594 application.Render();
596 // Do an entire pinch, only check finished value
597 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 4100);
599 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 5000);
600 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
601 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
602 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
603 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
604 DALI_TEST_EQUALS(Vector2(30.0f, 70.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
608 int UtcDaliPinchGestureSignalReceptionChildHit(void)
610 TestApplication application;
612 Actor parent = Actor::New();
613 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
614 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
615 application.GetScene().Add(parent);
617 // Set child to completely cover parent.
618 // Change rotation of child to be different from parent so that we can check if our local coordinate
619 // conversion of the parent actor is correct.
620 Actor child = Actor::New();
621 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
622 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
623 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
624 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
628 application.SendNotification();
629 application.Render();
632 GestureReceivedFunctor functor(data);
634 PinchGestureDetector detector = PinchGestureDetector::New();
635 detector.Attach(parent);
636 detector.DetectedSignal().Connect(&application, functor);
638 // Do an entire pan, only check finished value - hits child area but parent should still receive it
639 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
641 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
642 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
643 DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
644 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
645 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
646 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
648 // Attach child and generate same touch points to yield same results
649 // (Also proves that you can detach and then re-attach another actor)
650 detector.Attach(child);
651 detector.Detach(parent);
653 // Do an entire pan, only check finished value
654 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
656 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
657 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
658 DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
659 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
660 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
661 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
662 DALI_TEST_EQUALS(Vector2(20.0f, 80.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
666 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
668 TestApplication application;
670 Actor first = Actor::New();
671 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
672 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
673 application.GetScene().Add(first);
675 Actor second = Actor::New();
676 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
677 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
678 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
679 application.GetScene().Add(second);
682 application.SendNotification();
683 application.Render();
686 GestureReceivedFunctor functor(data);
688 PinchGestureDetector detector = PinchGestureDetector::New();
689 detector.Attach(first);
690 detector.Attach(second);
691 detector.DetectedSignal().Connect(&application, functor);
693 // Start pinch within second actor's area
694 TestStartPinch(application, Vector2(102.0f, 20.0f), Vector2(138.0f, 20.0f), Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), 100);
695 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
696 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
698 // Pinch moves into first actor's area - second actor should receive the pinch
700 TestContinuePinch(application, Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
701 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
702 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
704 // Detach the second actor during the pinch, we should not receive the next event
705 detector.Detach(second);
707 // Gesture ends within actor's area
709 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(119.0f, 20.0f), Vector2(121.0f, 20.0f), 3000);
710 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
714 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
716 TestApplication application;
718 Actor actor = Actor::New();
719 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
720 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
721 application.GetScene().Add(actor);
724 application.SendNotification();
725 application.Render();
728 GestureReceivedFunctor functor(data);
730 PinchGestureDetector detector = PinchGestureDetector::New();
731 detector.Attach(actor);
732 detector.DetectedSignal().Connect(&application, functor);
734 // Start pinch in actor's area
735 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
736 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
738 // Pan continues within actor's area
740 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
741 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
743 // Actor become invisible - actor should not receive the next pinch
744 actor.SetProperty(Actor::Property::VISIBLE, false);
747 application.SendNotification();
748 application.Render();
750 // Gesture ends within actor's area
752 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
753 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
757 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
759 TestApplication application;
761 Actor actor = Actor::New();
762 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
763 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
764 application.GetScene().Add(actor);
766 Actor actor2 = Actor::New();
767 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
768 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
769 application.GetScene().Add(actor2);
772 application.SendNotification();
773 application.Render();
775 // Attach actor to one detector
776 SignalData firstData;
777 GestureReceivedFunctor firstFunctor(firstData);
778 PinchGestureDetector firstDetector = PinchGestureDetector::New();
779 firstDetector.Attach(actor);
780 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
782 // Attach actor to another detector
783 SignalData secondData;
784 GestureReceivedFunctor secondFunctor(secondData);
785 PinchGestureDetector secondDetector = PinchGestureDetector::New();
786 secondDetector.Attach(actor);
787 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
789 // Add second actor to second detector, when we remove the actor, this will make sure that this
790 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
791 // functor should still not be called (which is what we're also testing).
792 secondDetector.Attach(actor2);
794 // Pinch in actor's area - both detector's functors should be called
795 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
796 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
797 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
799 // Pinch continues in actor's area - both detector's functors should be called
802 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
803 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
804 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
806 // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
807 firstDetector.Detach(actor);
810 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
811 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
812 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
814 // New pinch on actor, only secondDetector has actor attached
817 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
818 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
819 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
821 // Detach actor from secondDetector
822 secondDetector.Detach(actor);
825 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
826 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
827 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
831 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
833 TestApplication application;
835 Actor actor1 = Actor::New();
836 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
837 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
838 application.GetScene().Add(actor1);
840 GestureReceivedFunctor functor1(data1);
841 PinchGestureDetector detector1 = PinchGestureDetector::New();
842 detector1.Attach(actor1);
843 detector1.DetectedSignal().Connect(&application, functor1);
845 Actor actor2 = Actor::New();
846 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
847 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
848 actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
849 application.GetScene().Add(actor2);
851 GestureReceivedFunctor functor2(data2);
852 PinchGestureDetector detector2 = PinchGestureDetector::New();
853 detector2.Attach(actor2);
854 detector2.DetectedSignal().Connect(&application, functor2);
857 application.SendNotification();
858 application.Render();
860 // Start pan in actor1's area, only data1 should be set
861 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
862 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
863 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
867 int UtcDaliPinchGestureActorUnstaged(void)
869 TestApplication application;
871 Actor actor = Actor::New();
872 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
873 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
874 application.GetScene().Add(actor);
877 application.SendNotification();
878 application.Render();
880 // State to remove actor in.
881 GestureState stateToUnstage(GestureState::STARTED);
883 // Attach actor to detector
885 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
886 PinchGestureDetector detector = PinchGestureDetector::New();
887 detector.Attach(actor);
888 detector.DetectedSignal().Connect(&application, functor);
891 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
892 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
894 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
895 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
899 application.SendNotification();
900 application.Render();
902 // Re-add actor to stage
903 application.GetScene().Add(actor);
906 application.SendNotification();
907 application.Render();
909 // Change state to GestureState::CONTINUING to remove
910 stateToUnstage = GestureState::CONTINUING;
913 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
914 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
916 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
917 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
919 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
920 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
924 application.SendNotification();
925 application.Render();
927 // Re-add actor to stage
928 application.GetScene().Add(actor);
931 application.SendNotification();
932 application.Render();
934 // Change state to GestureState::CONTINUING to remove
935 stateToUnstage = GestureState::FINISHED;
938 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
939 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
941 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
942 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
944 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
945 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
946 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
950 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
952 TestApplication application;
954 Actor actor = Actor::New();
955 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
956 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
957 application.GetScene().Add(actor);
959 // Create and add a second actor so that GestureDetector destruction does not come into play.
960 Actor dummyActor(Actor::New());
961 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
962 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
963 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
964 application.GetScene().Add(dummyActor);
967 application.SendNotification();
968 application.Render();
970 // State to remove actor in.
971 GestureState stateToUnstage(GestureState::STARTED);
973 // Attach actor to detector
975 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
976 PinchGestureDetector detector = PinchGestureDetector::New();
977 detector.Attach(actor);
978 detector.Attach(dummyActor);
979 detector.DetectedSignal().Connect(&application, functor);
981 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
982 // before we get a continuing state. As we were removed from the stage, even if we're at the same
983 // position, we should still not be signalled.
986 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
987 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
991 application.SendNotification();
992 application.Render();
994 // Re add to the stage, we should not be signalled
995 application.GetScene().Add(actor);
998 application.SendNotification();
999 application.Render();
1001 // Continue signal emission
1002 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
1003 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1005 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1006 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1009 // Here we delete an actor in started, we should not receive any subsequent signalling.
1012 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
1013 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1016 // Render and notify
1017 application.SendNotification();
1018 application.Render();
1020 // Delete actor as well
1023 // Render and notify
1024 application.SendNotification();
1025 application.Render();
1027 // Continue signal emission
1028 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
1029 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1031 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
1032 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1036 int UtcDaliPinchGestureLayerConsumesTouch(void)
1038 TestApplication application;
1040 Actor actor = Actor::New();
1041 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1042 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1043 application.GetScene().Add(actor);
1047 GestureReceivedFunctor functor(data);
1048 PinchGestureDetector detector = PinchGestureDetector::New();
1049 detector.Attach(actor);
1050 detector.DetectedSignal().Connect(&application, functor);
1052 // Add a layer to overlap the actor
1053 Layer layer = Layer::New();
1054 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1055 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1056 application.GetScene().Add(layer);
1059 // Render and notify
1060 application.SendNotification();
1061 application.Render();
1063 // Emit signals, should receive
1064 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1065 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1066 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1069 // Set layer to consume all touch
1070 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
1072 // Render and notify
1073 application.SendNotification();
1074 application.Render();
1076 // Emit the same signals again, should not receive
1077 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
1078 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 2000);
1079 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1085 int UtcDaliPinchGestureDisableDetectionDuringPinchN(void)
1087 // Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1089 TestApplication application;
1091 Actor actor = Actor::New();
1092 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1093 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1094 application.GetScene().Add(actor);
1097 PinchGestureDetector detector = PinchGestureDetector::New();
1098 bool functorCalled = false;
1099 detector.Attach(actor);
1100 detector.DetectedSignal().Connect(
1102 [&detector, &functorCalled](Actor actor, const PinchGesture& gesture) {
1103 if(gesture.GetState() == GestureState::FINISHED)
1105 detector.Detach(actor);
1106 functorCalled = true;
1110 // Render and notify
1111 application.SendNotification();
1112 application.Render();
1114 // Try the gesture, should not crash
1117 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1118 TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
1119 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1121 DALI_TEST_CHECK(true); // No crash, test has passed
1122 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1126 DALI_TEST_CHECK(false); // If we crash, the test has failed
1132 int UtcDaliPinchGestureWhenGesturePropargation(void)
1134 TestApplication application;
1136 Actor parentActor = Actor::New();
1137 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1138 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1140 Actor childActor = Actor::New();
1141 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1142 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1144 parentActor.Add(childActor);
1145 application.GetScene().Add(parentActor);
1147 // Render and notify
1148 application.SendNotification();
1149 application.Render();
1152 GestureReceivedFunctor pFunctor(pData);
1154 PinchGestureDetector parentDetector = PinchGestureDetector::New();
1155 parentDetector.Attach(parentActor);
1156 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1159 GestureReceivedFunctor cFunctor(cData);
1161 PinchGestureDetector childDetector = PinchGestureDetector::New();
1162 childDetector.Attach(childActor);
1163 childDetector.DetectedSignal().Connect(&application, cFunctor);
1165 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1166 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1167 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1168 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1172 TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
1173 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1174 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1178 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 300);
1179 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1180 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1184 // If GesturePropargation is set, a gesture event is to pass over to the parent.
1185 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1187 // So now the parent got the gesture event.
1188 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 700);
1189 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1190 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1194 // child does not receive gestures. This is because we have passed the permission of the gesture to the parent.
1195 TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 800);
1196 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
1197 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1201 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 900);
1202 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
1203 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);