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/events/touch-integ.h>
22 #include <dali/integration-api/render-task-list-integ.h>
23 #include <dali/internal/event/events/touch-event-impl.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
25 #include <dali/public-api/dali-core.h>
27 #include <test-touch-event-utils.h>
33 void utc_dali_pinch_gesture_detector_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_pinch_gesture_detector_cleanup(void)
40 test_return_value = TET_PASS;
43 ///////////////////////////////////////////////////////////////////////////////
46 // Stores data that is populated in the callback and will be read by the TET cases
50 : functorCalled(false),
51 voidFunctorCalled(false),
58 functorCalled = false;
59 voidFunctorCalled = false;
61 receivedGesture.Reset();
67 bool voidFunctorCalled;
68 PinchGesture receivedGesture;
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
75 GestureReceivedFunctor(SignalData& data)
80 void operator()(Actor actor, const PinchGesture& pinch)
82 signalData.functorCalled = true;
83 signalData.receivedGesture = pinch;
84 signalData.pinchedActor = actor;
89 signalData.voidFunctorCalled = true;
92 SignalData& signalData;
95 // Functor that removes the gestured actor from stage
96 struct UnstageActorFunctor : public GestureReceivedFunctor
98 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
99 : GestureReceivedFunctor(data),
100 stateToUnstage(stateToUnstage),
105 void operator()(Actor actor, const PinchGesture& pinch)
107 GestureReceivedFunctor::operator()(actor, pinch);
109 if(pinch.GetState() == stateToUnstage)
115 GestureState& stateToUnstage;
116 Integration::Scene scene;
120 Integration::TouchEvent GenerateDoubleTouch(PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time)
122 Integration::TouchEvent touchEvent;
123 Integration::Point point;
124 point.SetState(stateA);
125 point.SetScreenPosition(screenPositionA);
126 point.SetDeviceClass(Device::Class::TOUCH);
127 point.SetDeviceSubclass(Device::Subclass::NONE);
128 touchEvent.points.push_back(point);
129 point.SetScreenPosition(screenPositionB);
130 point.SetState(stateB);
131 touchEvent.points.push_back(point);
132 touchEvent.time = time;
138 ///////////////////////////////////////////////////////////////////////////////
140 int UtcDaliPinchGestureDetectorConstructor(void)
142 TestApplication application;
144 PinchGestureDetector detector;
145 DALI_TEST_CHECK(!detector);
149 int UtcDaliPinchGestureDetectorCopyConstructorP(void)
151 TestApplication application;
153 PinchGestureDetector detector = PinchGestureDetector::New();
155 PinchGestureDetector copy(detector);
156 DALI_TEST_CHECK(detector);
160 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
162 TestApplication application;
164 PinchGestureDetector detector = PinchGestureDetector::New();
166 PinchGestureDetector assign;
168 DALI_TEST_CHECK(detector);
170 DALI_TEST_CHECK(detector == assign);
174 int UtcDaliPinchGestureDetectorMoveConstructorP(void)
176 TestApplication application;
178 PinchGestureDetector detector = PinchGestureDetector::New();
179 DALI_TEST_CHECK(detector);
181 PinchGestureDetector moved = std::move(detector);
182 DALI_TEST_CHECK(moved);
183 DALI_TEST_CHECK(!detector);
187 int UtcDaliPinchGestureDetectorMoveAssignmentOperatorP(void)
189 TestApplication application;
191 PinchGestureDetector detector;
192 detector = PinchGestureDetector::New();
193 DALI_TEST_CHECK(detector);
195 PinchGestureDetector moved;
196 moved = std::move(detector);
197 DALI_TEST_CHECK(moved);
198 DALI_TEST_CHECK(!detector);
202 int UtcDaliPinchGestureDetectorNew(void)
204 TestApplication application;
206 PinchGestureDetector detector = PinchGestureDetector::New();
208 DALI_TEST_CHECK(detector);
210 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
211 Actor actor = Actor::New();
212 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
213 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
214 application.GetScene().Add(actor);
217 application.SendNotification();
218 application.Render();
220 detector.Attach(actor);
222 Integration::TouchEvent touchEvent(1);
223 Integration::Point point;
224 point.SetDeviceId(1);
225 point.SetState(PointState::DOWN);
226 point.SetScreenPosition(Vector2(20.0f, 20.0f));
227 touchEvent.AddPoint(point);
228 application.ProcessEvent(touchEvent);
230 Integration::Point point2;
231 point.SetDeviceId(1);
232 point.SetState(PointState::DOWN);
233 point.SetScreenPosition(Vector2(20.0f, 20.0f));
234 touchEvent.AddPoint(point2);
235 application.ProcessEvent(touchEvent);
239 int UtcDaliPinchGestureDetectorDownCast(void)
241 TestApplication application;
242 tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
244 PinchGestureDetector detector = PinchGestureDetector::New();
246 BaseHandle object(detector);
248 PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
249 DALI_TEST_CHECK(detector2);
251 PinchGestureDetector detector3 = DownCast<PinchGestureDetector>(object);
252 DALI_TEST_CHECK(detector3);
254 BaseHandle unInitializedObject;
255 PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
256 DALI_TEST_CHECK(!detector4);
258 PinchGestureDetector detector5 = DownCast<PinchGestureDetector>(unInitializedObject);
259 DALI_TEST_CHECK(!detector5);
261 GestureDetector detector6 = PinchGestureDetector::New();
262 PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
263 DALI_TEST_CHECK(detector7);
267 // Negative test case for a method
268 int UtcDaliPinchGestureSignalReceptionNegative(void)
270 TestApplication application;
272 Actor actor = Actor::New();
273 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
274 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
275 application.GetScene().Add(actor);
278 application.SendNotification();
279 application.Render();
282 GestureReceivedFunctor functor(data);
284 PinchGestureDetector detector = PinchGestureDetector::New();
285 detector.Attach(actor);
286 detector.DetectedSignal().Connect(&application, functor);
288 // Do a pinch outside actor's area
289 TestStartPinch(application, Vector2(112.0f, 62.0f), Vector2(112.0f, 162.0f), Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), 100);
291 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
293 // Continue pinch into actor's area - we should still not receive the signal
295 TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
297 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
299 // Stop pinching - we should still not receive the signal
301 TestEndPinch(application, Vector2(6.0f, 6.0f), Vector2(18.0f, 18.0f), Vector2(10.0f, 8.0f), Vector2(14.0f, 16.0f), 300);
303 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
307 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
309 TestApplication application;
311 Actor actor = Actor::New();
312 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
313 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
314 application.GetScene().Add(actor);
317 application.SendNotification();
318 application.Render();
321 GestureReceivedFunctor functor(data);
323 PinchGestureDetector detector = PinchGestureDetector::New();
324 detector.Attach(actor);
325 detector.DetectedSignal().Connect(&application, functor);
327 // Start pan within the actor's area
328 TestStartPinch(application, Vector2(5.0f, 20.0f), Vector2(35.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
329 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
330 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
331 DALI_TEST_EQUALS(0.666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
332 DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
333 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
334 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
336 // Continue the pan within the actor's area - we should still receive the signal
338 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), 400);
339 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
340 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
341 DALI_TEST_EQUALS(0.2666f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
342 DALI_TEST_EQUALS(80.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
343 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
344 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
346 // Pinch Gesture leaves actor's area - we should still receive the signal
348 TestContinuePinch(application, Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), 1000);
349 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
350 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
351 DALI_TEST_EQUALS(1.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
352 DALI_TEST_EQUALS(213.333f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
353 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
354 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
356 // Gesture ends - we would receive a finished state
358 TestEndPinch(application, Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), Vector2(305.0f, 10.0f), Vector2(315.0f, 10.0f), 1500);
359 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
360 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
361 DALI_TEST_EQUALS(0.333f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
362 DALI_TEST_EQUALS(600.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
363 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
364 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
368 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
370 TestApplication application;
372 Actor actor = Actor::New();
373 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
374 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
375 application.GetScene().Add(actor);
378 application.SendNotification();
379 application.Render();
382 GestureReceivedFunctor functor(data);
384 PinchGestureDetector detector = PinchGestureDetector::New();
385 detector.Attach(actor);
386 detector.DetectedSignal().Connect(&application, functor);
388 // Start pinch within the actor's area
389 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
390 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
391 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
392 DALI_TEST_EQUALS(0.555f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
393 DALI_TEST_EQUALS(106.667f, 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);
397 // Continue the pinch within the actor's area - we should still receive the signal
399 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
400 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
401 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
402 DALI_TEST_EQUALS(0.277f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
403 DALI_TEST_EQUALS(66.666f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
404 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
405 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
407 // Gesture ends within actor's area - we would receive a finished state
409 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
410 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
411 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
412 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
413 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
414 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
415 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
419 int UtcDaliPinchGestureSignalReceptionDetach(void)
421 TestApplication application;
423 Actor actor = Actor::New();
424 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
425 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
426 application.GetScene().Add(actor);
429 application.SendNotification();
430 application.Render();
433 GestureReceivedFunctor functor(data);
435 PinchGestureDetector detector = PinchGestureDetector::New();
436 detector.Attach(actor);
437 detector.DetectedSignal().Connect(&application, functor);
439 // Start pinch within the actor's area
440 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
441 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
442 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
444 // Continue the pinch within the actor's area - we should still receive the signal
446 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
447 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
448 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
450 // Gesture ends within actor's area
452 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
453 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
454 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
457 detector.DetachAll();
459 // Ensure we are no longer signalled
461 TestGeneratePinch(application);
462 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
466 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
468 TestApplication application;
470 Actor actor = Actor::New();
471 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
472 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
473 application.GetScene().Add(actor);
476 application.SendNotification();
477 application.Render();
480 GestureReceivedFunctor functor(data);
482 PinchGestureDetector detector = PinchGestureDetector::New();
483 detector.Attach(actor);
484 detector.DetectedSignal().Connect(&application, functor);
486 // Start pinch within the actor's area
487 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
488 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
489 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
491 // Continue the pinch within the actor's area - we should still receive the signal
493 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
494 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
495 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
497 // Detach actor during the pinch, we should not receive the next event
498 detector.DetachAll();
500 // Gesture ends within actor's area
502 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
503 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
507 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
509 TestApplication application;
512 GestureReceivedFunctor functor(data);
514 PinchGestureDetector detector = PinchGestureDetector::New();
515 detector.DetectedSignal().Connect(&application, functor);
517 // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
519 Actor tempActor = Actor::New();
520 tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
521 tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
522 application.GetScene().Add(tempActor);
523 detector.Attach(tempActor);
525 // Actor lifetime is scoped
527 Actor actor = Actor::New();
528 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
529 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
530 application.GetScene().Add(actor);
533 application.SendNotification();
534 application.Render();
536 detector.Attach(actor);
538 // Start pinch within the actor's area
539 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
540 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
541 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
543 // Continue the pinch within the actor's area - we should still receive the signal
545 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
546 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
547 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
549 // Remove the actor from stage and reset the data
550 application.GetScene().Remove(actor);
553 application.SendNotification();
554 application.Render();
557 // Actor should now have been destroyed
559 // Gesture ends within the area where the actor used to be
561 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
562 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
566 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
568 TestApplication application;
570 Actor actor = Actor::New();
571 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
572 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
573 application.GetScene().Add(actor);
575 // Render and notify a couple of times
576 application.SendNotification();
577 application.Render();
580 GestureReceivedFunctor functor(data);
582 PinchGestureDetector detector = PinchGestureDetector::New();
583 detector.Attach(actor);
584 detector.DetectedSignal().Connect(&application, functor);
586 // Do an entire pinch, only check finished value
587 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
589 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
590 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
591 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
592 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
593 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
594 DALI_TEST_EQUALS(Vector2(70.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
596 // Rotate actor again and render and notify
597 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
598 application.SendNotification();
599 application.Render();
601 // Do an entire pinch, only check finished value
602 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
604 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
605 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
606 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
607 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
608 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
609 DALI_TEST_EQUALS(Vector2(30.0f, 30.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
611 // Rotate actor again and render and notify
612 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
613 application.SendNotification();
614 application.Render();
616 // Do an entire pinch, only check finished value
617 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 4100);
619 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 5000);
620 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
621 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
622 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
623 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
624 DALI_TEST_EQUALS(Vector2(30.0f, 70.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
628 int UtcDaliPinchGestureSignalReceptionChildHit(void)
630 TestApplication application;
632 Actor parent = Actor::New();
633 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
634 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
635 application.GetScene().Add(parent);
637 // Set child to completely cover parent.
638 // Change rotation of child to be different from parent so that we can check if our local coordinate
639 // conversion of the parent actor is correct.
640 Actor child = Actor::New();
641 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
642 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
643 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
644 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
648 application.SendNotification();
649 application.Render();
652 GestureReceivedFunctor functor(data);
654 PinchGestureDetector detector = PinchGestureDetector::New();
655 detector.Attach(parent);
656 detector.DetectedSignal().Connect(&application, functor);
658 // Do an entire pan, only check finished value - hits child area but parent should still receive it
659 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
661 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
662 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
663 DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
664 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
665 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
666 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
668 // Attach child and generate same touch points to yield same results
669 // (Also proves that you can detach and then re-attach another actor)
670 detector.Attach(child);
671 detector.Detach(parent);
673 // Do an entire pan, only check finished value
674 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
676 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
677 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
678 DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
679 DALI_TEST_EQUALS(0.055f, data.receivedGesture.GetScale(), 0.01f, TEST_LOCATION);
680 DALI_TEST_EQUALS(160.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
681 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
682 DALI_TEST_EQUALS(Vector2(20.0f, 80.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
686 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
688 TestApplication application;
690 Actor first = Actor::New();
691 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
692 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
693 application.GetScene().Add(first);
695 Actor second = Actor::New();
696 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
697 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
698 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
699 application.GetScene().Add(second);
702 application.SendNotification();
703 application.Render();
706 GestureReceivedFunctor functor(data);
708 PinchGestureDetector detector = PinchGestureDetector::New();
709 detector.Attach(first);
710 detector.Attach(second);
711 detector.DetectedSignal().Connect(&application, functor);
713 // Start pinch within second actor's area
714 TestStartPinch(application, Vector2(102.0f, 20.0f), Vector2(138.0f, 20.0f), Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), 100);
715 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
716 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
718 // Pinch moves into first actor's area - second actor should receive the pinch
720 TestContinuePinch(application, Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
721 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
722 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
724 // Detach the second actor during the pinch, we should not receive the next event
725 detector.Detach(second);
727 // Gesture ends within actor's area
729 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(119.0f, 20.0f), Vector2(121.0f, 20.0f), 3000);
730 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
734 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
736 TestApplication application;
738 Actor actor = Actor::New();
739 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
740 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
741 application.GetScene().Add(actor);
744 application.SendNotification();
745 application.Render();
748 GestureReceivedFunctor functor(data);
750 PinchGestureDetector detector = PinchGestureDetector::New();
751 detector.Attach(actor);
752 detector.DetectedSignal().Connect(&application, functor);
754 // Start pinch in actor's area
755 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
756 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
758 // Pan continues within actor's area
760 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
761 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
763 // Actor become invisible - actor should not receive the next pinch
764 actor.SetProperty(Actor::Property::VISIBLE, false);
767 application.SendNotification();
768 application.Render();
770 // Gesture ends within actor's area
772 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
773 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
777 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
779 TestApplication application;
781 Actor actor = Actor::New();
782 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
783 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
784 application.GetScene().Add(actor);
786 Actor actor2 = Actor::New();
787 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
788 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
789 application.GetScene().Add(actor2);
792 application.SendNotification();
793 application.Render();
795 // Attach actor to one detector
796 SignalData firstData;
797 GestureReceivedFunctor firstFunctor(firstData);
798 PinchGestureDetector firstDetector = PinchGestureDetector::New();
799 firstDetector.Attach(actor);
800 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
802 // Attach actor to another detector
803 SignalData secondData;
804 GestureReceivedFunctor secondFunctor(secondData);
805 PinchGestureDetector secondDetector = PinchGestureDetector::New();
806 secondDetector.Attach(actor);
807 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
809 // Add second actor to second detector, when we remove the actor, this will make sure that this
810 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
811 // functor should still not be called (which is what we're also testing).
812 secondDetector.Attach(actor2);
814 // Pinch in actor's area - both detector's functors should be called
815 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
816 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
817 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
819 // Pinch continues in actor's area - both detector's functors should be called
822 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
823 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
824 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
826 // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
827 firstDetector.Detach(actor);
830 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
831 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
832 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
834 // New pinch on actor, only secondDetector has actor attached
837 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
838 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
839 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
841 // Detach actor from secondDetector
842 secondDetector.Detach(actor);
845 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
846 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
847 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
851 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
853 TestApplication application;
855 Actor actor1 = Actor::New();
856 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
857 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
858 application.GetScene().Add(actor1);
860 GestureReceivedFunctor functor1(data1);
861 PinchGestureDetector detector1 = PinchGestureDetector::New();
862 detector1.Attach(actor1);
863 detector1.DetectedSignal().Connect(&application, functor1);
865 Actor actor2 = Actor::New();
866 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
867 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
868 actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
869 application.GetScene().Add(actor2);
871 GestureReceivedFunctor functor2(data2);
872 PinchGestureDetector detector2 = PinchGestureDetector::New();
873 detector2.Attach(actor2);
874 detector2.DetectedSignal().Connect(&application, functor2);
877 application.SendNotification();
878 application.Render();
880 // Start pan in actor1's area, only data1 should be set
881 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
882 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
883 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
887 int UtcDaliPinchGestureActorUnstaged(void)
889 TestApplication application;
891 Actor actor = Actor::New();
892 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
893 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
894 application.GetScene().Add(actor);
897 application.SendNotification();
898 application.Render();
900 // State to remove actor in.
901 GestureState stateToUnstage(GestureState::STARTED);
903 // Attach actor to detector
905 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
906 PinchGestureDetector detector = PinchGestureDetector::New();
907 detector.Attach(actor);
908 detector.DetectedSignal().Connect(&application, functor);
911 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
912 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
914 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
915 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
919 application.SendNotification();
920 application.Render();
922 // Re-add actor to stage
923 application.GetScene().Add(actor);
926 application.SendNotification();
927 application.Render();
929 // Change state to GestureState::CONTINUING to remove
930 stateToUnstage = GestureState::CONTINUING;
933 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
934 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
936 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
937 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
939 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
940 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
944 application.SendNotification();
945 application.Render();
947 // Re-add actor to stage
948 application.GetScene().Add(actor);
951 application.SendNotification();
952 application.Render();
954 // Change state to GestureState::CONTINUING to remove
955 stateToUnstage = GestureState::FINISHED;
958 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
959 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
961 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
962 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
964 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
965 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
966 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
970 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
972 TestApplication application;
974 Actor actor = Actor::New();
975 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
976 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
977 application.GetScene().Add(actor);
979 // Create and add a second actor so that GestureDetector destruction does not come into play.
980 Actor dummyActor(Actor::New());
981 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
982 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
983 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
984 application.GetScene().Add(dummyActor);
987 application.SendNotification();
988 application.Render();
990 // State to remove actor in.
991 GestureState stateToUnstage(GestureState::STARTED);
993 // Attach actor to detector
995 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
996 PinchGestureDetector detector = PinchGestureDetector::New();
997 detector.Attach(actor);
998 detector.Attach(dummyActor);
999 detector.DetectedSignal().Connect(&application, functor);
1001 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
1002 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1003 // position, we should still not be signalled.
1006 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1007 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1010 // Render and notify
1011 application.SendNotification();
1012 application.Render();
1014 // Re add to the stage, we should not be signalled
1015 application.GetScene().Add(actor);
1017 // Render and notify
1018 application.SendNotification();
1019 application.Render();
1021 // Continue signal emission
1022 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
1023 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1025 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1026 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1029 // Here we delete an actor in started, we should not receive any subsequent signalling.
1032 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
1033 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1036 // Render and notify
1037 application.SendNotification();
1038 application.Render();
1040 // Delete actor as well
1043 // Render and notify
1044 application.SendNotification();
1045 application.Render();
1047 // Continue signal emission
1048 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
1049 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1051 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
1052 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1056 int UtcDaliPinchGestureLayerConsumesTouch(void)
1058 TestApplication application;
1060 Actor actor = Actor::New();
1061 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1062 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1063 application.GetScene().Add(actor);
1067 GestureReceivedFunctor functor(data);
1068 PinchGestureDetector detector = PinchGestureDetector::New();
1069 detector.Attach(actor);
1070 detector.DetectedSignal().Connect(&application, functor);
1072 // Add a layer to overlap the actor
1073 Layer layer = Layer::New();
1074 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1075 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1076 application.GetScene().Add(layer);
1079 // Render and notify
1080 application.SendNotification();
1081 application.Render();
1083 // Emit signals, should receive
1084 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1085 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1086 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1089 // Set layer to consume all touch
1090 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
1092 // Render and notify
1093 application.SendNotification();
1094 application.Render();
1096 // Emit the same signals again, should not receive
1097 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
1098 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 2000);
1099 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1105 int UtcDaliPinchGestureDisableDetectionDuringPinchN(void)
1107 // Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1109 TestApplication application;
1111 Actor actor = Actor::New();
1112 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1113 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1114 application.GetScene().Add(actor);
1117 PinchGestureDetector detector = PinchGestureDetector::New();
1118 bool functorCalled = false;
1119 detector.Attach(actor);
1120 detector.DetectedSignal().Connect(
1122 [&detector, &functorCalled](Actor actor, const PinchGesture& gesture) {
1123 if(gesture.GetState() == GestureState::FINISHED)
1125 detector.Detach(actor);
1126 functorCalled = true;
1130 // Render and notify
1131 application.SendNotification();
1132 application.Render();
1134 // Try the gesture, should not crash
1137 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1138 TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
1139 TestEndPinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1141 DALI_TEST_CHECK(true); // No crash, test has passed
1142 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1146 DALI_TEST_CHECK(false); // If we crash, the test has failed
1152 int UtcDaliPinchGestureWhenGesturePropargation(void)
1154 TestApplication application;
1156 Actor parentActor = Actor::New();
1157 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1158 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1160 Actor childActor = Actor::New();
1161 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1162 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1164 parentActor.Add(childActor);
1165 application.GetScene().Add(parentActor);
1167 // Render and notify
1168 application.SendNotification();
1169 application.Render();
1172 GestureReceivedFunctor pFunctor(pData);
1174 PinchGestureDetector parentDetector = PinchGestureDetector::New();
1175 parentDetector.Attach(parentActor);
1176 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1179 GestureReceivedFunctor cFunctor(cData);
1181 PinchGestureDetector childDetector = PinchGestureDetector::New();
1182 childDetector.Attach(childActor);
1183 childDetector.DetectedSignal().Connect(&application, cFunctor);
1185 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1186 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1187 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1188 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1192 TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
1193 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1194 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1198 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 300);
1199 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1200 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1204 // If GesturePropargation is set, a gesture event is to pass over to the parent.
1205 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1207 // So now the parent got the gesture event.
1208 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 700);
1209 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1210 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1214 // child does not receive gestures. This is because we have passed the permission of the gesture to the parent.
1215 TestContinuePinch(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 800);
1216 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
1217 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1221 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 900);
1222 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
1223 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
1230 int UtcDaliPinchGestureSignalReceptionWithGeometryHittest(void)
1232 TestApplication application;
1233 application.GetScene().SetGeometryHittestEnabled(true);
1235 Actor actor = Actor::New();
1236 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1237 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1238 application.GetScene().Add(actor);
1240 // Render and notify
1241 application.SendNotification();
1242 application.Render();
1245 GestureReceivedFunctor functor(data);
1247 PinchGestureDetector detector = PinchGestureDetector::New();
1248 detector.Attach(actor);
1249 detector.DetectedSignal().Connect(&application, functor);
1251 // Start pinch within the actor's area
1252 TestStartPinch(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1253 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1254 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
1256 // Continue the pinch within the actor's area - we should still receive the signal
1258 TestContinuePinch(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
1259 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1260 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
1262 // Gesture ends within actor's area
1264 TestEndPinch(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1265 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1266 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
1269 detector.DetachAll();
1271 // Ensure we are no longer signalled
1273 TestGeneratePinch(application);
1274 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1278 int UtcDaliPinchGestureHandleEvent(void)
1280 TestApplication application;
1281 Integration::Scene scene = application.GetScene();
1282 RenderTaskList taskList = scene.GetRenderTaskList();
1283 Dali::RenderTask task = taskList.GetTask(0);
1285 Actor parentActor = Actor::New();
1286 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1287 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1289 Actor childActor = Actor::New();
1290 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1291 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1293 parentActor.Add(childActor);
1294 application.GetScene().Add(parentActor);
1296 // Render and notify
1297 application.SendNotification();
1298 application.Render();
1301 GestureReceivedFunctor pFunctor(pData);
1303 PinchGestureDetector parentDetector = PinchGestureDetector::New();
1304 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1306 Integration::TouchEvent tp = GenerateDoubleTouch(PointState::DOWN, Vector2(2.0f, 20.0f), PointState::DOWN, Vector2(38.0f, 20.0f), 100);
1307 Internal::TouchEventPtr touchEventImpl(new Internal::TouchEvent(100));
1308 touchEventImpl->AddPoint(tp.GetPoint(0));
1309 touchEventImpl->AddPoint(tp.GetPoint(1));
1310 touchEventImpl->SetRenderTask(task);
1311 Dali::TouchEvent touchEventHandle(touchEventImpl.Get());
1312 parentDetector.HandleEvent(parentActor, touchEventHandle);
1314 tp = GenerateDoubleTouch(PointState::MOTION, Vector2(10.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 20.0f), 150);
1315 touchEventImpl = new Internal::TouchEvent(150);
1316 touchEventImpl->AddPoint(tp.GetPoint(0));
1317 touchEventImpl->AddPoint(tp.GetPoint(1));
1318 touchEventImpl->SetRenderTask(task);
1319 touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1320 parentDetector.HandleEvent(parentActor, touchEventHandle);
1322 tp = GenerateDoubleTouch(PointState::MOTION, Vector2(10.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 20.0f), 200);
1323 touchEventImpl = new Internal::TouchEvent(200);
1324 touchEventImpl->AddPoint(tp.GetPoint(0));
1325 touchEventImpl->AddPoint(tp.GetPoint(1));
1326 touchEventImpl->SetRenderTask(task);
1327 touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1328 parentDetector.HandleEvent(parentActor, touchEventHandle);
1330 tp = GenerateDoubleTouch(PointState::MOTION, Vector2(10.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 20.0f), 250);
1331 touchEventImpl = new Internal::TouchEvent(250);
1332 touchEventImpl->AddPoint(tp.GetPoint(0));
1333 touchEventImpl->AddPoint(tp.GetPoint(1));
1334 touchEventImpl->SetRenderTask(task);
1335 touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1336 parentDetector.HandleEvent(parentActor, touchEventHandle);
1338 tp = GenerateDoubleTouch(PointState::MOTION, Vector2(10.0f, 20.0f), PointState::MOTION, Vector2(30.0f, 20.0f), 300);
1339 touchEventImpl = new Internal::TouchEvent(300);
1340 touchEventImpl->AddPoint(tp.GetPoint(0));
1341 touchEventImpl->AddPoint(tp.GetPoint(1));
1342 touchEventImpl->SetRenderTask(task);
1343 touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1344 parentDetector.HandleEvent(parentActor, touchEventHandle);
1346 tp = GenerateDoubleTouch(PointState::UP, Vector2(10.0f, 20.0f), PointState::UP, Vector2(30.0f, 20.0f), 350);
1347 touchEventImpl = new Internal::TouchEvent(350);
1348 touchEventImpl->AddPoint(tp.GetPoint(0));
1349 touchEventImpl->AddPoint(tp.GetPoint(1));
1350 touchEventImpl->SetRenderTask(task);
1351 touchEventHandle = Dali::TouchEvent(touchEventImpl.Get());
1352 parentDetector.HandleEvent(parentActor, touchEventHandle);
1355 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);