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/devel-api/events/pan-gesture-devel.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/profiling.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/public-api/dali-core.h>
27 #include <test-touch-event-utils.h>
34 void utc_dali_pan_gesture_detector_startup(void)
36 test_return_value = TET_UNDEF;
39 void utc_dali_pan_gesture_detector_cleanup(void)
41 test_return_value = TET_PASS;
44 ///////////////////////////////////////////////////////////////////////////////
47 const int PAN_EVENT_TIME_DELTA = 8;
48 const int PAN_GESTURE_UPDATE_COUNT = 50;
50 // Stores data that is populated in the callback and will be read by the test cases
54 : functorCalled(false),
55 voidFunctorCalled(false),
62 functorCalled = false;
63 voidFunctorCalled = false;
65 receivedGesture.Reset();
71 bool voidFunctorCalled;
72 PanGesture receivedGesture;
76 // Functor that sets the data when called
77 struct GestureReceivedFunctor
79 GestureReceivedFunctor(SignalData& data)
84 void operator()(Actor actor, const PanGesture& pan)
86 signalData.functorCalled = true;
87 signalData.receivedGesture = pan;
88 signalData.pannedActor = actor;
93 signalData.voidFunctorCalled = true;
96 SignalData& signalData;
99 // Functor that removes the gestured actor from stage
100 struct UnstageActorFunctor : public GestureReceivedFunctor
102 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
103 : GestureReceivedFunctor(data),
104 stateToUnstage(stateToUnstage),
109 void operator()(Actor actor, const PanGesture& pan)
111 GestureReceivedFunctor::operator()(actor, pan);
113 if(pan.GetState() == stateToUnstage)
119 GestureState& stateToUnstage;
120 Integration::Scene scene;
123 // Data for constraints
124 struct ConstraintData
132 Vector2 screenPosition;
133 Vector2 screenDisplacement;
134 Vector2 screenVelocity;
135 Vector2 localPosition;
136 Vector2 localDisplacement;
137 Vector2 localVelocity;
143 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
149 // Constraint used with panning properties
152 PanConstraint(ConstraintData& data)
153 : constraintData(data)
157 void operator()(Vector3& current, const PropertyInputContainer& inputs)
159 constraintData.screenPosition = inputs[0]->GetVector2();
160 constraintData.screenDisplacement = inputs[1]->GetVector2();
161 constraintData.screenVelocity = inputs[2]->GetVector2();
162 constraintData.localPosition = inputs[3]->GetVector2();
163 constraintData.localDisplacement = inputs[4]->GetVector2();
164 constraintData.localVelocity = inputs[5]->GetVector2();
165 constraintData.panning = inputs[6]->GetBoolean();
166 constraintData.called = true;
167 current = Vector3::ZERO;
170 ConstraintData& constraintData;
173 // Generate a PanGesture
174 PanGesture GeneratePan(unsigned int time,
176 Vector2 screenPosition,
177 Vector2 localPosition,
178 Vector2 screenDisplacement = Vector2::ONE,
179 Vector2 localDisplacement = Vector2::ONE,
180 Vector2 screenVelocity = Vector2::ONE,
181 Vector2 localVelocity = Vector2::ONE,
182 unsigned int numberOfTouches = 1)
184 Dali::PanGesture pan = DevelPanGesture::New(state);
186 DevelPanGesture::SetTime(pan, time);
188 DevelPanGesture::SetScreenPosition(pan, screenPosition);
189 DevelPanGesture::SetPosition(pan, localPosition);
191 DevelPanGesture::SetScreenDisplacement(pan, screenDisplacement);
192 DevelPanGesture::SetDisplacement(pan, localDisplacement);
194 DevelPanGesture::SetScreenVelocity(pan, screenVelocity);
195 DevelPanGesture::SetVelocity(pan, localVelocity);
197 DevelPanGesture::SetNumberOfTouches(pan, numberOfTouches);
204 ///////////////////////////////////////////////////////////////////////////////
206 // Positive test case for a method
207 int UtcDaliPanGestureDetectorConstructor(void)
209 TestApplication application;
211 PanGestureDetector detector;
212 DALI_TEST_CHECK(!detector);
216 int UtcDaliPanGestureDetectorCopyConstructorP(void)
218 TestApplication application;
220 PanGestureDetector detector = PanGestureDetector::New();
222 PanGestureDetector copy(detector);
223 DALI_TEST_CHECK(detector);
227 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
229 TestApplication application;
231 PanGestureDetector detector = PanGestureDetector::New();
233 PanGestureDetector assign;
235 DALI_TEST_CHECK(detector);
237 DALI_TEST_CHECK(detector == assign);
241 // Negative test case for a method
242 int UtcDaliPanGestureDetectorNew(void)
244 TestApplication application;
246 PanGestureDetector detector = PanGestureDetector::New();
248 DALI_TEST_CHECK(detector);
250 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
251 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
252 DALI_TEST_EQUALS(std::numeric_limits<uint32_t>::max(), detector.GetMaximumMotionEventAge(), TEST_LOCATION);
254 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
255 Actor actor = Actor::New();
256 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
257 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
258 detector.Attach(actor);
260 application.GetScene().Add(actor);
263 application.SendNotification();
264 application.Render();
266 // Use long press function for touch event
267 TestStartLongPress(application);
272 int UtcDaliPanGestureDetectorDownCast(void)
274 TestApplication application;
275 tet_infoline("Testing Dali::GestureDetector::DownCast()");
277 PanGestureDetector detector = PanGestureDetector::New();
279 BaseHandle object(detector);
281 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
282 DALI_TEST_CHECK(detector2);
284 PanGestureDetector detector3 = DownCast<PanGestureDetector>(object);
285 DALI_TEST_CHECK(detector3);
287 BaseHandle unInitializedObject;
288 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
289 DALI_TEST_CHECK(!detector4);
291 PanGestureDetector detector5 = DownCast<PanGestureDetector>(unInitializedObject);
292 DALI_TEST_CHECK(!detector5);
294 GestureDetector detector6 = PanGestureDetector::New();
295 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
296 DALI_TEST_CHECK(detector7);
300 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
302 TestApplication application;
304 PanGestureDetector detector = PanGestureDetector::New();
306 unsigned int min = 2;
308 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
310 detector.SetMinimumTouchesRequired(min);
312 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
314 // Attach an actor and change the minimum touches
316 Actor actor = Actor::New();
317 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
318 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
319 application.GetScene().Add(actor);
322 application.SendNotification();
323 application.Render();
326 GestureReceivedFunctor functor(data);
328 detector.Attach(actor);
329 detector.DetectedSignal().Connect(&application, functor);
331 detector.SetMinimumTouchesRequired(3);
333 // Create a second gesture detector that requires even less minimum touches
334 PanGestureDetector secondDetector = PanGestureDetector::New();
335 secondDetector.Attach(actor);
337 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
342 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
344 TestApplication application;
346 PanGestureDetector detector = PanGestureDetector::New();
348 unsigned int max = 3;
350 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
352 detector.SetMaximumTouchesRequired(max);
354 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
356 // Attach an actor and change the maximum touches
358 Actor actor = Actor::New();
359 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
360 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
361 application.GetScene().Add(actor);
364 application.SendNotification();
365 application.Render();
368 GestureReceivedFunctor functor(data);
370 detector.Attach(actor);
371 detector.DetectedSignal().Connect(&application, functor);
373 detector.SetMaximumTouchesRequired(4);
375 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
380 int UtcDaliPanGestureSetMaximumMotionEventAge(void)
382 TestApplication application;
384 PanGestureDetector detector = PanGestureDetector::New();
386 uint32_t minTime = 20;
388 DALI_TEST_CHECK(minTime != detector.GetMaximumMotionEventAge());
390 detector.SetMaximumMotionEventAge(minTime);
392 DALI_TEST_EQUALS(minTime, detector.GetMaximumMotionEventAge(), TEST_LOCATION);
394 // Attach an actor and change the maximum touches
396 Actor actor = Actor::New();
397 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
398 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
399 application.GetScene().Add(actor);
402 application.SendNotification();
403 application.Render();
406 GestureReceivedFunctor functor(data);
408 detector.Attach(actor);
409 detector.DetectedSignal().Connect(&application, functor);
411 detector.SetMaximumMotionEventAge(minTime / 2);
413 DALI_TEST_EQUALS(minTime / 2, detector.GetMaximumMotionEventAge(), TEST_LOCATION);
418 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
420 TestApplication application;
422 PanGestureDetector detector = PanGestureDetector::New();
423 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
427 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
429 TestApplication application;
431 PanGestureDetector detector = PanGestureDetector::New();
432 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
436 int UtcDaliPanGestureGetMaximumMotionEventAge(void)
438 TestApplication application;
440 PanGestureDetector detector = PanGestureDetector::New();
441 DALI_TEST_EQUALS(std::numeric_limits<uint32_t>::max(), detector.GetMaximumMotionEventAge(), TEST_LOCATION);
445 int UtcDaliPanGestureSignalReceptionNegative(void)
447 TestApplication application;
449 Actor actor = Actor::New();
450 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
451 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
452 application.GetScene().Add(actor);
455 application.SendNotification();
456 application.Render();
459 GestureReceivedFunctor functor(data);
461 PanGestureDetector detector = PanGestureDetector::New();
462 detector.Attach(actor);
463 detector.DetectedSignal().Connect(&application, functor);
465 // Do a pan outside actor's area
467 TestStartPan(application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time);
469 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
471 // Continue pan into actor's area - we should still not receive the signal
473 TestMovePan(application, Vector2(20.0f, 20.0f), time);
475 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
477 // Stop panning - we should still not receive the signal
479 TestEndPan(application, Vector2(12.0f, 12.0f), time);
481 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
485 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
487 TestApplication application;
489 Actor actor = Actor::New();
490 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
491 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
492 application.GetScene().Add(actor);
495 application.SendNotification();
496 application.Render();
499 GestureReceivedFunctor functor(data);
501 PanGestureDetector detector = PanGestureDetector::New();
502 detector.Attach(actor);
503 detector.DetectedSignal().Connect(&application, functor);
505 // Start pan within the actor's area
507 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
509 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
510 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
511 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
512 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
513 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
514 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
515 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
517 // Continue the pan within the actor's area - we should still receive the signal
520 TestMovePan(application, Vector2(26.0f, 4.0f), time);
521 time += TestGetFrameInterval();
523 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
524 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
525 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
526 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
527 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
528 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
529 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
531 // Pan Gesture leaves actor's area - we should still receive the signal
534 TestMovePan(application, Vector2(346.0f, 4.0f), time);
535 time += TestGetFrameInterval();
537 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
538 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
539 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
540 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
541 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
542 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
543 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
545 // Gesture ends - we would receive a finished state
548 TestEndPan(application, Vector2(314.0f, 4.0f), time);
550 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
551 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
552 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
553 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
554 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
555 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
556 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
560 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
562 TestApplication application;
564 Actor actor = Actor::New();
565 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
566 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
567 application.GetScene().Add(actor);
570 application.SendNotification();
571 application.Render();
574 GestureReceivedFunctor functor(data);
576 PanGestureDetector detector = PanGestureDetector::New();
577 detector.Attach(actor);
578 detector.DetectedSignal().Connect(&application, functor);
580 // Start pan within the actor's area
582 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
584 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
585 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
586 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
587 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
588 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
589 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
590 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
592 // Continue the pan within the actor's area - we should still receive the signal
595 TestMovePan(application, Vector2(26.0f, 4.0f), time);
596 time += TestGetFrameInterval();
598 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
599 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
600 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
601 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
602 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
603 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
604 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
606 // Gesture ends within actor's area - we would receive a finished state
609 TestEndPan(application, Vector2(10.0f, 4.0f), time);
611 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
613 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
614 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
615 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
616 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
617 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
621 int UtcDaliPanGestureSignalReceptionDetach(void)
623 TestApplication application;
625 Actor actor = Actor::New();
626 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
627 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
628 application.GetScene().Add(actor);
631 application.SendNotification();
632 application.Render();
635 GestureReceivedFunctor functor(data);
637 PanGestureDetector detector = PanGestureDetector::New();
638 detector.Attach(actor);
639 detector.DetectedSignal().Connect(&application, functor);
641 // Start pan within the actor's area
643 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
644 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
646 // Continue the pan within the actor's area - we should still receive the signal
649 TestMovePan(application, Vector2(26.0f, 4.0f), time);
650 time += TestGetFrameInterval();
652 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
654 // Gesture ends within actor's area
657 TestEndPan(application, Vector2(10.0f, 4.0f), time);
658 time += TestGetFrameInterval();
660 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
663 detector.DetachAll();
665 // Ensure we are no longer signalled
668 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
669 TestMovePan(application, Vector2(26.0f, 4.0f), time);
670 time += TestGetFrameInterval();
671 TestEndPan(application, Vector2(10.0f, 4.0f), time);
673 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
677 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
679 TestApplication application;
681 Actor actor = Actor::New();
682 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
683 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
684 application.GetScene().Add(actor);
687 application.SendNotification();
688 application.Render();
691 GestureReceivedFunctor functor(data);
693 PanGestureDetector detector = PanGestureDetector::New();
694 detector.Attach(actor);
695 detector.DetectedSignal().Connect(&application, functor);
697 // Start pan within the actor's area
699 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
700 application.SendNotification();
702 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
704 // Continue the pan within the actor's area - we should still receive the signal
707 TestMovePan(application, Vector2(26.0f, 4.0f), time);
708 time += TestGetFrameInterval();
710 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
712 // Detach actor during the pan, we should not receive the next event
713 detector.DetachAll();
715 // Gesture ends within actor's area
718 TestEndPan(application, Vector2(10.0f, 4.0f), time);
720 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
724 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
726 TestApplication application;
729 GestureReceivedFunctor functor(data);
731 PanGestureDetector detector = PanGestureDetector::New();
732 detector.DetectedSignal().Connect(&application, functor);
734 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
736 Actor tempActor = Actor::New();
737 tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
738 tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
739 application.GetScene().Add(tempActor);
740 detector.Attach(tempActor);
744 // Actor lifetime is scoped
746 Actor actor = Actor::New();
747 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
748 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
749 application.GetScene().Add(actor);
752 application.SendNotification();
753 application.Render();
755 detector.Attach(actor);
757 // Start pan within the actor's area
758 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
760 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
762 // Continue the pan within the actor's area - we should still receive the signal
765 TestMovePan(application, Vector2(26.0f, 4.0f), time);
766 time += TestGetFrameInterval();
768 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
770 // Remove the actor from stage and reset the data
771 application.GetScene().Remove(actor);
774 application.SendNotification();
775 application.Render();
778 // Actor should now have been destroyed
780 // Gesture ends within the area where the actor used to be
783 TestEndPan(application, Vector2(10.0f, 4.0f), time);
785 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
789 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
791 TestApplication application;
793 Actor actor = Actor::New();
794 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
795 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
796 application.GetScene().Add(actor);
799 application.SendNotification();
800 application.Render();
803 GestureReceivedFunctor functor(data);
805 PanGestureDetector detector = PanGestureDetector::New();
806 detector.Attach(actor);
807 detector.DetectedSignal().Connect(&application, functor);
809 // Do an entire pan, only check finished value
811 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
815 TestEndPan(application, Vector2(25.0f, 28.0f), time);
817 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
818 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
820 // Rotate actor again and render a couple of times
821 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
822 application.SendNotification();
823 application.Render();
825 // Do an entire pan, only check finished value
826 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
830 TestEndPan(application, Vector2(25.0f, 28.0f), time);
832 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
833 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
835 // Rotate actor again and render a couple of times
836 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
837 application.SendNotification();
838 application.Render();
840 // Do an entire pan, only check finished value
841 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
845 TestEndPan(application, Vector2(25.0f, 28.0f), time);
847 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
848 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
852 int UtcDaliPanGestureSignalReceptionChildHit(void)
854 TestApplication application;
856 Actor parent = Actor::New();
857 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
858 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
859 application.GetScene().Add(parent);
861 // Set child to completely cover parent.
862 // Change rotation of child to be different from parent so that we can check if our local coordinate
863 // conversion of the parent actor is correct.
864 Actor child = Actor::New();
865 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
866 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
867 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
868 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
872 application.SendNotification();
873 application.Render();
876 GestureReceivedFunctor functor(data);
878 PanGestureDetector detector = PanGestureDetector::New();
879 detector.Attach(parent);
880 detector.DetectedSignal().Connect(&application, functor);
882 // Do an entire pan, only check finished value - hits child area but parent should still receive it
884 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
888 TestEndPan(application, Vector2(25.0f, 28.0f), time);
890 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
891 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
892 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
894 // Attach child and generate same touch points to yield a different displacement
895 // (Also proves that you can detach and then re-attach another actor)
896 detector.Attach(child);
897 detector.Detach(parent);
899 // Do an entire pan, only check finished value
900 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
904 TestEndPan(application, Vector2(25.0f, 28.0f), time);
906 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
907 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
908 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
912 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
914 TestApplication application;
916 Actor first = Actor::New();
917 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
918 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
919 application.GetScene().Add(first);
921 Actor second = Actor::New();
922 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
923 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
924 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
925 application.GetScene().Add(second);
928 application.SendNotification();
929 application.Render();
932 GestureReceivedFunctor functor(data);
934 PanGestureDetector detector = PanGestureDetector::New();
935 detector.Attach(first);
936 detector.Attach(second);
937 detector.DetectedSignal().Connect(&application, functor);
939 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
940 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
942 // Start pan within second actor's area
944 TestStartPan(application, Vector2(110.0f, 20.0f), Vector2(126.0f, 20.0f), time);
946 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
947 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
949 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
950 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
952 // Pan moves into first actor's area - second actor should receive the pan
955 TestMovePan(application, Vector2(126.0f, 20.0f), time);
956 time += TestGetFrameInterval();
958 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
959 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
961 // Detach the second actor during the pan, we should not receive the next event
962 detector.Detach(second);
964 // Gesture ends within actor's area
967 TestMovePan(application, Vector2(26.0f, 20.0f), time);
968 TestEndPan(application, Vector2(10.0f, 4.0f), time);
970 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
975 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
977 TestApplication application;
979 Actor actor = Actor::New();
980 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
981 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
982 application.GetScene().Add(actor);
985 application.SendNotification();
986 application.Render();
989 GestureReceivedFunctor functor(data);
991 PanGestureDetector detector = PanGestureDetector::New();
992 detector.Attach(actor);
993 detector.DetectedSignal().Connect(&application, functor);
995 // Start pan in actor's area
997 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
999 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1001 // Pan continues within actor's area
1004 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1005 time += TestGetFrameInterval();
1007 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1009 // Actor become invisible - actor should not receive the next pan
1010 actor.SetProperty(Actor::Property::VISIBLE, false);
1012 // Render and notify
1013 application.SendNotification();
1014 application.Render();
1016 // Gesture ends within actor's area
1019 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1021 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1025 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1027 TestApplication application;
1029 Actor actor = Actor::New();
1030 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1031 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1032 application.GetScene().Add(actor);
1034 Actor actor2 = Actor::New();
1035 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1036 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
1037 application.GetScene().Add(actor2);
1039 // Render and notify
1040 application.SendNotification();
1041 application.Render();
1043 // Attach actor to one detector
1044 SignalData firstData;
1045 GestureReceivedFunctor firstFunctor(firstData);
1046 PanGestureDetector firstDetector = PanGestureDetector::New();
1047 firstDetector.Attach(actor);
1048 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1050 // Attach actor to another detector
1051 SignalData secondData;
1052 GestureReceivedFunctor secondFunctor(secondData);
1053 PanGestureDetector secondDetector = PanGestureDetector::New();
1054 secondDetector.Attach(actor);
1055 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1057 // Add second actor to second detector, when we remove the actor, this will make sure that this
1058 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1059 // functor should still not be called (which is what we're also testing).
1060 secondDetector.Attach(actor2);
1062 // Pan in actor's area - both detector's functors should be called
1063 uint32_t time = 100;
1064 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1066 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1067 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1069 // Pan continues in actor's area - both detector's functors should be called
1073 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1074 time += TestGetFrameInterval();
1076 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1077 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1079 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1080 firstDetector.Detach(actor);
1084 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1086 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1087 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1089 // New pan on actor, only secondDetector has actor attached
1093 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1095 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1096 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1098 // Detach actor from secondDetector
1099 secondDetector.Detach(actor);
1103 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1105 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1106 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1111 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1113 TestApplication application;
1115 Actor actor1 = Actor::New();
1116 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1117 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1118 application.GetScene().Add(actor1);
1120 GestureReceivedFunctor functor1(data1);
1121 PanGestureDetector detector1 = PanGestureDetector::New();
1122 detector1.Attach(actor1);
1123 detector1.DetectedSignal().Connect(&application, functor1);
1125 Actor actor2 = Actor::New();
1126 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1127 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
1128 actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
1129 application.GetScene().Add(actor2);
1131 GestureReceivedFunctor functor2(data2);
1132 PanGestureDetector detector2 = PanGestureDetector::New();
1133 detector2.Attach(actor2);
1134 detector2.DetectedSignal().Connect(&application, functor2);
1136 // Render and notify
1137 application.SendNotification();
1138 application.Render();
1140 // Start pan in actor1's area, only data1 should be set
1141 uint32_t time = 100;
1142 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1144 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1145 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1149 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1151 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1153 TestApplication application;
1155 Actor actor = Actor::New();
1156 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1157 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1158 application.GetScene().Add(actor);
1160 // Render and notify
1161 application.SendNotification();
1162 application.Render();
1164 // Gesture possible in actor's area (using long-press)
1165 uint32_t time = 100;
1166 TestStartLongPress(application, 10.0f, 20.0f, time);
1167 time += TestGetFrameInterval();
1169 // Attach actor to detector
1171 GestureReceivedFunctor functor(data);
1172 PanGestureDetector detector = PanGestureDetector::New();
1173 detector.DetectedSignal().Connect(&application, functor);
1174 detector.Attach(actor);
1176 // Start a pan, initially it'll only be possible, we shouldn't receive it
1177 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1178 time += TestGetFrameInterval();
1179 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1181 // Now the pan truly starts, we should receive a signal
1182 TestMovePan(application, Vector2(26.0f, 20.0f), time);
1183 time += TestGetFrameInterval();
1184 TestMovePan(application, Vector2(32.0f, 32.0f), time);
1185 time += TestGetFrameInterval();
1186 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1188 // Finish the pan, we should still receive a signal
1190 TestEndPan(application, Vector2(32.0f, 32.0f), time);
1191 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1196 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1198 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1199 // pan actor was there before (parent)
1201 TestApplication application;
1203 Actor parent = Actor::New();
1204 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1205 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1206 application.GetScene().Add(parent);
1208 Actor child = Actor::New();
1209 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1210 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1211 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1214 // Create detector for parent and attach
1215 SignalData parentData;
1216 GestureReceivedFunctor parentFunctor(parentData);
1217 PanGestureDetector parentDetector = PanGestureDetector::New();
1218 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1219 parentDetector.Attach(parent);
1221 // Create detector for child but do not attach
1222 SignalData childData;
1223 GestureReceivedFunctor childFunctor(childData);
1224 PanGestureDetector childDetector = PanGestureDetector::New();
1225 childDetector.DetectedSignal().Connect(&application, childFunctor);
1227 // Render and notify
1228 application.SendNotification();
1229 application.Render();
1231 // Do a full pan in both actors' area, only the parent's functor should be called
1232 uint32_t time = 100;
1233 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1234 DALI_TEST_EQUALS(parentData.functorCalled, true, TEST_LOCATION);
1235 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1238 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1239 DALI_TEST_EQUALS(parentData.functorCalled, true, TEST_LOCATION);
1240 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1244 // Gesture possible in both actors' area (using long-press), no functors called
1245 TestStartLongPress(application, 10.0f, 20.0f, time);
1246 time += TestGetFrameInterval();
1247 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1248 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1250 // Attach the child as well now
1251 childDetector.Attach(child);
1253 // Now the pan truly starts, we should receive a signal for the child only
1254 TestMovePan(application, Vector2(26.0f, 20.0f), time);
1255 time += TestGetFrameInterval();
1256 TestMovePan(application, Vector2(32.0f, 32.0f), time);
1257 time += TestGetFrameInterval();
1258 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1259 DALI_TEST_EQUALS(childData.functorCalled, true, TEST_LOCATION);
1263 // Finish the pan, again only the child should still receive a signal
1264 TestEndPan(application, Vector2(32.0f, 32.0f), time);
1265 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1266 DALI_TEST_EQUALS(childData.functorCalled, true, TEST_LOCATION);
1271 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1273 TestApplication application;
1275 Actor actor = Actor::New();
1276 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1277 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1278 application.GetScene().Add(actor);
1280 // Render and notify
1281 application.SendNotification();
1282 application.Render();
1284 // Attach actor to detector
1286 GestureReceivedFunctor functor(data);
1287 PanGestureDetector detector = PanGestureDetector::New();
1288 detector.Attach(actor);
1289 detector.DetectedSignal().Connect(&application, functor);
1291 // Gesture possible in actor's area.
1292 uint32_t time = 100;
1293 TestStartLongPress(application, 10.0f, 20.0f, time);
1294 time += TestGetFrameInterval();
1296 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1298 // Move actor somewhere else
1299 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
1301 // Render and notify
1302 application.SendNotification();
1303 application.Render();
1305 // Emit STARTED event, we should not receive the pan.
1306 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1307 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1308 time += TestGetFrameInterval();
1310 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1312 // LONG_PRESS possible in empty area.
1313 TestStartLongPress(application, 10.0f, 20.0f, time);
1314 time += TestGetFrameInterval();
1316 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1318 // Move actor in to the long press position.
1319 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1321 // Render and notify
1322 application.SendNotification();
1323 application.Render();
1325 // Emit STARTED event, we should be receiving the pan now.
1326 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1327 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1328 time += TestGetFrameInterval();
1330 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1332 // Normal pan in actor's area for completeness.
1334 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1335 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1336 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1340 int UtcDaliPanGestureActorUnstaged(void)
1342 TestApplication application;
1344 Actor actor = Actor::New();
1345 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1346 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1347 application.GetScene().Add(actor);
1349 // Render and notify
1350 application.SendNotification();
1351 application.Render();
1353 // State to remove actor in.
1354 GestureState stateToUnstage(GestureState::STARTED);
1356 // Attach actor to detector
1358 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
1359 PanGestureDetector detector = PanGestureDetector::New();
1360 detector.Attach(actor);
1361 detector.DetectedSignal().Connect(&application, functor);
1364 uint32_t time = 100;
1365 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1367 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1370 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1372 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1375 // Render and notify
1376 application.SendNotification();
1377 application.Render();
1379 // Re-add actor to stage
1380 application.GetScene().Add(actor);
1382 // Render and notify
1383 application.SendNotification();
1384 application.Render();
1386 // Change state to GestureState::CONTINUING to remove
1387 stateToUnstage = GestureState::CONTINUING;
1390 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1392 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1395 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1396 time += TestGetFrameInterval();
1398 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1402 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1404 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1407 // Render and notify
1408 application.SendNotification();
1409 application.Render();
1411 // Re-add actor to stage
1412 application.GetScene().Add(actor);
1414 // Render and notify
1415 application.SendNotification();
1416 application.Render();
1418 // Change state to GestureState::FINISHED to remove
1419 stateToUnstage = GestureState::FINISHED;
1422 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1424 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1427 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1428 time += TestGetFrameInterval();
1430 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1433 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1435 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1436 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
1440 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1442 TestApplication application;
1444 Actor actor = Actor::New();
1445 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1446 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1447 application.GetScene().Add(actor);
1449 // Create and add a second actor so that GestureDetector destruction does not come into play.
1450 Actor dummyActor(Actor::New());
1451 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1452 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
1453 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1454 application.GetScene().Add(dummyActor);
1456 // Render and notify
1457 application.SendNotification();
1458 application.Render();
1460 // State to remove actor in.
1461 GestureState stateToUnstage(GestureState::STARTED);
1463 // Attach actor to detector
1465 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
1466 PanGestureDetector detector = PanGestureDetector::New();
1467 detector.Attach(actor);
1468 detector.Attach(dummyActor);
1469 detector.DetectedSignal().Connect(&application, functor);
1471 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
1472 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1473 // position, we should still not be signalled.
1476 uint32_t time = 100;
1477 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1479 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1482 // Render and notify
1483 application.SendNotification();
1484 application.Render();
1486 // Re add to the stage, we should not be signalled
1487 application.GetScene().Add(actor);
1489 // Render and notify
1490 application.SendNotification();
1491 application.Render();
1493 // Continue signal emission
1494 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1495 time += TestGetFrameInterval();
1497 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1500 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1501 time += TestGetFrameInterval();
1503 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1506 // Here we delete an actor in started, we should not receive any subsequent signalling.
1509 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1511 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1514 // Render and notify
1515 application.SendNotification();
1516 application.Render();
1518 // Delete actor as well
1521 // Render and notify
1522 application.SendNotification();
1523 application.Render();
1525 // Continue signal emission
1526 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1527 time += TestGetFrameInterval();
1529 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1532 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1534 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1538 int UtcDaliPanGestureAngleHandling(void)
1540 TestApplication application;
1542 PanGestureDetector detector = PanGestureDetector::New();
1543 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1545 detector.AddAngle(PanGestureDetector::DIRECTION_LEFT, Radian(Math::PI * 0.25));
1546 DALI_TEST_EQUALS(detector.GetAngleCount(), 1u, TEST_LOCATION);
1548 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1550 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT)
1552 tet_result(TET_PASS);
1560 tet_printf("%s, angle not added\n", TEST_LOCATION);
1561 tet_result(TET_FAIL);
1564 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Radian(Math::PI * 0.25));
1565 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1567 // Remove something not in the container.
1568 detector.RemoveAngle(PanGestureDetector::DIRECTION_UP);
1569 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1571 detector.RemoveAngle(PanGestureDetector::DIRECTION_RIGHT);
1572 DALI_TEST_EQUALS(detector.GetAngleCount(), 1u, TEST_LOCATION);
1573 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1575 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT)
1577 tet_printf("%s, angle not removed\n", TEST_LOCATION);
1578 tet_result(TET_FAIL);
1583 detector.ClearAngles();
1584 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1588 int UtcDaliPanGestureGetAngle(void)
1590 TestApplication application;
1592 PanGestureDetector detector = PanGestureDetector::New();
1593 DALI_TEST_EQUALS(detector.GetAngleCount(), 0, TEST_LOCATION);
1595 detector.AddAngle(PanGestureDetector::DIRECTION_LEFT);
1596 DALI_TEST_EQUALS(detector.GetAngleCount(), 1, TEST_LOCATION);
1598 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT);
1599 DALI_TEST_EQUALS(detector.GetAngleCount(), 2, TEST_LOCATION);
1601 detector.AddAngle(PanGestureDetector::DIRECTION_UP);
1602 DALI_TEST_EQUALS(detector.GetAngleCount(), 3, TEST_LOCATION);
1604 detector.AddAngle(PanGestureDetector::DIRECTION_DOWN);
1605 DALI_TEST_EQUALS(detector.GetAngleCount(), 4, TEST_LOCATION);
1607 DALI_TEST_EQUALS(detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION);
1608 DALI_TEST_EQUALS(detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION);
1609 DALI_TEST_EQUALS(detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION);
1610 DALI_TEST_EQUALS(detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION);
1615 inline float RadiansToDegrees(float radian)
1617 return radian * 180.0f / Math::PI;
1620 int UtcDaliPanGestureAngleOutOfRange(void)
1622 TestApplication application;
1624 PanGestureDetector detector = PanGestureDetector::New();
1625 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1631 detector.AddAngle(Degree(180.0f));
1632 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-180.0f)), 0.000001, TEST_LOCATION);
1633 detector.ClearAngles();
1635 detector.AddAngle(Degree(190.0f));
1636 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-170.0f)), 0.000001, TEST_LOCATION);
1637 detector.ClearAngles();
1639 detector.AddAngle(Degree(-190.0f));
1640 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(170.0f)), 0.000001, TEST_LOCATION);
1641 detector.ClearAngles();
1643 detector.AddAngle(Degree(350.0f));
1644 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-10.0f)), 0.000001, TEST_LOCATION);
1645 detector.ClearAngles();
1647 detector.AddAngle(Degree(-350.0f));
1648 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1649 detector.ClearAngles();
1651 detector.AddAngle(Degree(370.0f));
1652 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1653 detector.ClearAngles();
1655 detector.AddAngle(Degree(-370.0f));
1656 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-10.0f)), 0.000001, TEST_LOCATION);
1657 detector.ClearAngles();
1663 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(0.0f));
1664 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(0.0f)), 0.000001, TEST_LOCATION);
1665 detector.ClearAngles();
1667 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(-10.0f));
1668 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1669 detector.ClearAngles();
1671 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(-181.0f));
1672 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(180.0f)), 0.000001, TEST_LOCATION);
1673 detector.ClearAngles();
1675 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(181.0f));
1676 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(180.0f)), 0.000001, TEST_LOCATION);
1677 detector.ClearAngles();
1681 int UtcDaliPanGestureAngleProcessing(void)
1683 TestApplication application;
1685 Actor parent = Actor::New();
1686 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1687 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1688 application.GetScene().Add(parent);
1690 Actor child = Actor::New();
1691 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1692 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1695 // Render and notify
1696 application.SendNotification();
1697 application.Render();
1699 // Parent detector only requires up pans
1700 PanGestureDetector parentDetector = PanGestureDetector::New();
1701 parentDetector.Attach(parent);
1702 parentDetector.AddAngle(PanGestureDetector::DIRECTION_UP, Degree(30.0f));
1703 SignalData parentData;
1704 GestureReceivedFunctor parentFunctor(parentData);
1705 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1707 // Child detector only requires right pans
1708 PanGestureDetector childDetector = PanGestureDetector::New();
1709 childDetector.Attach(child);
1710 childDetector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(30.0f));
1711 SignalData childData;
1712 GestureReceivedFunctor childFunctor(childData);
1713 childDetector.DetectedSignal().Connect(&application, childFunctor);
1715 // Generate an Up pan gesture, only parent should receive it.
1716 uint32_t time = 100;
1717 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 4.0f), time);
1719 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1720 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1722 TestEndPan(application, Vector2(20.0f, 4.0f), time);
1723 time += TestGetFrameInterval();
1727 // Generate a Right pan gesture, only child should receive it.
1728 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(36.0f, 20.0f), time);
1730 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1731 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1733 TestEndPan(application, Vector2(4.0f, 20.0f), time);
1734 time += TestGetFrameInterval();
1738 // Generate a Down pan gesture, no one should receive it.
1739 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 36.0f), time);
1741 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1742 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1744 TestEndPan(application, Vector2(20.0f, 36.0f), time);
1745 time += TestGetFrameInterval();
1749 // Generate a Left pan gesture, no one should receive it.
1750 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 20.0f), time);
1752 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1753 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1755 TestEndPan(application, Vector2(4.0f, 20.0f), time);
1761 int UtcDaliPanGestureDirectionHandling(void)
1763 TestApplication application;
1765 PanGestureDetector detector = PanGestureDetector::New();
1766 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1768 detector.AddDirection(PanGestureDetector::DIRECTION_LEFT, Radian(Math::PI * 0.25));
1769 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1771 for(size_t i = 0; detector.GetAngleCount(); i++)
1773 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT)
1775 tet_result(TET_PASS);
1783 tet_printf("%s, angle not added\n", TEST_LOCATION);
1784 tet_result(TET_FAIL);
1788 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1790 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT)
1792 tet_result(TET_PASS);
1800 tet_printf("%s, angle not added\n", TEST_LOCATION);
1801 tet_result(TET_FAIL);
1804 // Remove something not in the container.
1805 detector.RemoveDirection(PanGestureDetector::DIRECTION_UP);
1806 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1808 detector.RemoveDirection(PanGestureDetector::DIRECTION_RIGHT);
1809 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1813 int UtcDaliPanGestureDirectionProcessing(void)
1815 TestApplication application;
1817 Actor parent = Actor::New();
1818 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1819 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1820 application.GetScene().Add(parent);
1822 Actor child = Actor::New();
1823 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1824 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1827 // Render and notify
1828 application.SendNotification();
1829 application.Render();
1831 // Parent detector only requires vertical panning
1832 PanGestureDetector parentDetector = PanGestureDetector::New();
1833 parentDetector.Attach(parent);
1834 parentDetector.AddDirection(PanGestureDetector::DIRECTION_VERTICAL, Degree(30.0f));
1835 SignalData parentData;
1836 GestureReceivedFunctor parentFunctor(parentData);
1837 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1839 // Child detector only requires horizontal panning
1840 PanGestureDetector childDetector = PanGestureDetector::New();
1841 childDetector.Attach(child);
1842 childDetector.AddDirection(PanGestureDetector::DIRECTION_HORIZONTAL, Degree(30.0f));
1843 SignalData childData;
1844 GestureReceivedFunctor childFunctor(childData);
1845 childDetector.DetectedSignal().Connect(&application, childFunctor);
1847 // Generate an Up pan gesture, only parent should receive it.
1848 uint32_t time = 100;
1849 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 4.0f), time);
1851 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1852 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1854 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1855 time += TestGetFrameInterval();
1859 // Generate a Right pan gesture, only child should receive it.
1860 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(36.0f, 20.0f), time);
1862 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1863 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1865 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1866 time += TestGetFrameInterval();
1870 // Generate a Down pan gesture, only parent should receive it.
1871 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 36.0f), time);
1873 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1874 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1876 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1877 time += TestGetFrameInterval();
1881 // Generate a Left pan gesture, only child should receive it.
1882 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 20.0f), time);
1884 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1885 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1887 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1888 time += TestGetFrameInterval();
1892 // Generate a pan at -45 degrees, no one should receive it.
1893 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(9.0f, 31.0f), time);
1895 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1896 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1898 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1899 time += TestGetFrameInterval();
1903 // Generate a pan at 45 degrees, no one should receive it.
1904 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(31.0f, 31.0f), time);
1906 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1907 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1909 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1910 time += TestGetFrameInterval();
1914 // Generate a pan at -135 degrees, no one should receive it.
1915 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 4.0f), time);
1917 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1918 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1920 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1926 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1928 TestApplication application;
1929 Integration::SetPanGesturePredictionMode(0);
1930 Integration::SetPanGestureSmoothingMode(0);
1932 Actor actor = Actor::New();
1933 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1934 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1935 application.GetScene().Add(actor);
1937 // Add a pan detector
1938 PanGestureDetector detector = PanGestureDetector::New();
1939 detector.Attach(actor);
1941 GestureReceivedFunctor functor(data);
1942 detector.DetectedSignal().Connect(&application, functor);
1944 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
1946 ConstraintData constraintData;
1947 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
1948 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
1949 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
1950 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
1951 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
1952 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
1953 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
1954 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
1957 // Render and notify
1958 application.SendNotification();
1959 application.Render();
1961 Vector2 startPosition(1.0f, 1.0f);
1962 Vector2 position(-14.0f, 1.0f);
1963 Vector2 direction(Vector2::XAXIS * -5.0f);
1964 uint32_t time = 100;
1966 TestStartPan(application, startPosition, position, time);
1968 for(int i = 0; i < 47; i++)
1970 position += direction;
1971 TestMovePan(application, position, time);
1972 time += TestGetFrameInterval();
1973 application.SendNotification();
1974 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1977 TestEndPan(application, position, time);
1978 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1980 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1981 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
1982 DALI_TEST_EQUALS(constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION);
1983 DALI_TEST_EQUALS(constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION);
1985 constraintData.Reset();
1989 int UtcDaliPanGestureNoPredictionSmoothing(void)
1991 TestApplication application;
1992 Integration::SetPanGesturePredictionMode(0);
1993 Integration::SetPanGestureSmoothingMode(1);
1995 Actor actor = Actor::New();
1996 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1997 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1998 application.GetScene().Add(actor);
2000 // Add a pan detector
2001 PanGestureDetector detector = PanGestureDetector::New();
2002 detector.Attach(actor);
2004 GestureReceivedFunctor functor(data);
2005 detector.DetectedSignal().Connect(&application, functor);
2007 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2009 ConstraintData constraintData;
2010 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2011 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2012 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2013 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2014 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2015 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2016 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2017 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2020 // Render and notify
2021 application.SendNotification();
2022 application.Render();
2024 Vector2 startPosition(1.0f, 1.0f);
2025 Vector2 position(-14.0f, 1.0f);
2026 Vector2 direction(Vector2::XAXIS * -5.0f);
2027 uint32_t time = 100;
2029 TestStartPan(application, startPosition, position, time);
2031 for(int i = 0; i < 47; i++)
2033 position += direction;
2034 TestMovePan(application, position, time);
2035 time += TestGetFrameInterval();
2036 application.SendNotification();
2037 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2040 TestEndPan(application, position, time);
2041 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2043 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2044 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2045 // Take into account resampling done when prediction is off.
2046 DALI_TEST_EQUALS(constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION);
2047 DALI_TEST_EQUALS(constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION);
2049 constraintData.Reset();
2053 int UtcDaliPanGesturePredictionNoSmoothing(void)
2055 TestApplication application;
2056 Integration::SetPanGesturePredictionMode(1);
2057 Integration::SetPanGestureSmoothingMode(0);
2059 Actor actor = Actor::New();
2060 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2061 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2062 application.GetScene().Add(actor);
2064 // Add a pan detector
2065 PanGestureDetector detector = PanGestureDetector::New();
2066 detector.Attach(actor);
2068 GestureReceivedFunctor functor(data);
2069 detector.DetectedSignal().Connect(&application, functor);
2071 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2073 ConstraintData constraintData;
2074 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2075 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2076 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2077 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2078 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2079 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2080 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2081 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2084 // Render and notify
2085 application.SendNotification();
2086 application.Render();
2088 Vector2 startPosition(1.0f, 1.0f);
2089 Vector2 position(-1.0f, 1.0f);
2090 Vector2 direction(Vector2::XAXIS * -1.0f);
2091 uint32_t time = 100;
2093 TestStartPan(application, startPosition, position, time);
2095 for(int i = 0; i < 47; i++)
2097 position += direction;
2098 TestMovePan(application, position, time);
2099 time += TestGetFrameInterval();
2100 application.SendNotification();
2101 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2104 TestEndPan(application, position, time);
2105 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2107 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2108 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2109 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2110 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2112 constraintData.Reset();
2116 int UtcDaliPanGesturePredictionSmoothing01(void)
2118 TestApplication application;
2119 Integration::SetPanGesturePredictionMode(1);
2120 Integration::SetPanGestureSmoothingMode(1);
2122 Actor actor = Actor::New();
2123 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2124 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2125 application.GetScene().Add(actor);
2127 // Add a pan detector
2128 PanGestureDetector detector = PanGestureDetector::New();
2129 detector.Attach(actor);
2131 GestureReceivedFunctor functor(data);
2132 detector.DetectedSignal().Connect(&application, functor);
2134 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2136 ConstraintData constraintData;
2137 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2138 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2139 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2140 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2141 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2142 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2143 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2144 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2147 // Render and notify
2148 application.SendNotification();
2149 application.Render();
2151 Vector2 startPosition(1.0f, 1.0f);
2152 Vector2 position(-1.0f, 1.0f);
2153 Vector2 direction(Vector2::XAXIS * -1.0f);
2154 uint32_t time = 100;
2156 TestStartPan(application, startPosition, position, time);
2158 for(int i = 0; i < 47; i++)
2160 position += direction;
2161 TestMovePan(application, position, time);
2162 time += TestGetFrameInterval();
2163 application.SendNotification();
2164 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2167 TestEndPan(application, position, time);
2168 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2170 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2171 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2172 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2173 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2175 constraintData.Reset();
2179 int UtcDaliPanGesturePredictionSmoothing02(void)
2181 TestApplication application;
2182 Integration::SetPanGesturePredictionMode(1);
2183 Integration::SetPanGestureMaximumPredictionAmount(1);
2184 Integration::SetPanGesturePredictionAmountAdjustment(2);
2185 Integration::SetPanGestureSmoothingMode(1);
2186 Integration::SetPanGestureSmoothingAmount(0.25f);
2188 Actor actor = Actor::New();
2189 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2190 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2191 application.GetScene().Add(actor);
2193 // Add a pan detector
2194 PanGestureDetector detector = PanGestureDetector::New();
2195 detector.Attach(actor);
2197 GestureReceivedFunctor functor(data);
2198 detector.DetectedSignal().Connect(&application, functor);
2200 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2202 ConstraintData constraintData;
2203 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2204 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2205 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2206 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2207 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2208 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2209 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2210 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2213 // Render and notify
2214 application.SendNotification();
2215 application.Render();
2217 Vector2 startPosition(2.0f, 2.0f);
2218 Vector2 position(4.0f, 2.0f);
2219 Vector2 directionX(Vector2::XAXIS);
2220 Vector2 directionY(Vector2::YAXIS);
2221 uint32_t time = 100;
2223 TestStartPan(application, startPosition, position, time);
2225 for(int i = 0; i < 7; i++)
2227 position += directionX;
2228 TestMovePan(application, position, time);
2229 time += TestGetFrameInterval();
2230 application.SendNotification();
2231 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2234 position += directionX * 10.0f;
2235 TestMovePan(application, position, time);
2236 time += TestGetFrameInterval();
2237 application.SendNotification();
2238 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2240 for(int i = 0; i < 2; i++)
2242 position += (directionX * -1.0f);
2243 TestMovePan(application, position, time);
2244 time += TestGetFrameInterval();
2245 application.SendNotification();
2246 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2249 for(int i = 0; i < 10; i++)
2251 position += directionX;
2252 TestMovePan(application, position, time);
2253 time += TestGetFrameInterval();
2254 application.SendNotification();
2255 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2258 for(int i = 0; i < 10; i++)
2260 position += directionY;
2261 TestMovePan(application, position, time);
2262 time += TestGetFrameInterval();
2263 application.SendNotification();
2264 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2267 TestEndPan(application, position, time);
2268 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2270 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2271 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2272 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2273 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2275 constraintData.Reset();
2279 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2281 TestApplication application;
2283 Integration::SetPanGesturePredictionMode(2);
2284 Integration::SetPanGesturePredictionAmount(57);
2285 Integration::SetPanGestureSmoothingMode(2);
2286 Integration::SetPanGestureUseActualTimes(false);
2287 Integration::SetPanGestureInterpolationTimeRange(10);
2288 Integration::SetPanGestureScalarOnlyPredictionEnabled(false);
2289 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2290 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2291 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2292 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2293 Integration::SetPanGestureMultitapSmoothingRange(34);
2295 Actor actor = Actor::New();
2296 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2297 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2298 application.GetScene().Add(actor);
2300 // Add a pan detector
2301 PanGestureDetector detector = PanGestureDetector::New();
2302 detector.Attach(actor);
2304 GestureReceivedFunctor functor(data);
2305 detector.DetectedSignal().Connect(&application, functor);
2307 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2309 ConstraintData constraintData;
2310 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2311 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2312 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2313 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2314 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2315 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2316 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2317 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2320 // Render and notify
2321 application.SendNotification();
2322 application.Render();
2324 Vector2 startPosition(2.0f, 2.0f);
2325 Vector2 position(-1.0f, 2.0f);
2326 Vector2 direction(Vector2::XAXIS * -1.0f);
2327 uint32_t time = 100;
2329 TestStartPan(application, startPosition, position, time);
2331 for(int i = 0; i < 27; i++)
2333 position += direction;
2334 TestMovePan(application, position, time);
2335 time += TestGetFrameInterval();
2336 application.SendNotification();
2337 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2340 TestEndPan(application, position, time);
2341 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2343 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2344 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2345 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2346 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2348 constraintData.Reset();
2352 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2354 TestApplication application;
2356 Integration::SetPanGesturePredictionMode(2);
2357 Integration::SetPanGestureSmoothingMode(2);
2358 Integration::SetPanGestureUseActualTimes(true);
2359 Integration::SetPanGestureInterpolationTimeRange(10);
2360 Integration::SetPanGestureScalarOnlyPredictionEnabled(true);
2361 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2362 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2363 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2364 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2365 Integration::SetPanGestureMultitapSmoothingRange(34);
2367 Integration::EnableProfiling(Integration::PROFILING_TYPE_PAN_GESTURE);
2369 Actor actor = Actor::New();
2370 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2371 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2372 application.GetScene().Add(actor);
2374 // Add a pan detector
2375 PanGestureDetector detector = PanGestureDetector::New();
2376 detector.Attach(actor);
2378 GestureReceivedFunctor functor(data);
2379 detector.DetectedSignal().Connect(&application, functor);
2381 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2383 ConstraintData constraintData;
2384 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2385 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2386 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2387 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2388 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2389 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2390 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2391 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2394 // Render and notify
2395 application.SendNotification();
2396 application.Render();
2398 Vector2 startPosition(2.0f, 2.0f);
2399 Vector2 position(17.0f, 2.0f);
2400 Vector2 direction(Vector2::XAXIS * -1.0f);
2401 uint32_t time = 100;
2403 TestStartPan(application, startPosition, position, time);
2405 for(int i = 0; i < 10; i++)
2407 position += direction;
2408 TestMovePan(application, position, time);
2409 time += TestGetFrameInterval();
2411 position += direction;
2412 TestMovePan(application, position, time);
2413 time += TestGetFrameInterval();
2415 position += direction;
2416 TestMovePan(application, position, time);
2417 time += TestGetFrameInterval();
2419 application.SendNotification();
2420 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2423 for(int i = 0; i < 10; i++)
2425 application.SendNotification();
2426 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2429 for(int i = 0; i < 10; i++)
2431 position += direction;
2432 TestMovePan(application, position, time);
2433 application.SendNotification();
2434 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2437 for(int i = 0; i < 10; i++)
2439 position += direction;
2440 TestMovePan(application, position, time);
2441 time += TestGetFrameInterval();
2442 application.SendNotification();
2443 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2446 TestEndPan(application, position, time);
2447 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2449 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2450 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2451 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2452 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2454 constraintData.Reset();
2458 int UtcDaliPanGesturePrediction2Smoothing(void)
2460 TestApplication application;
2462 Integration::SetPanGesturePredictionMode(2);
2463 Integration::SetPanGesturePredictionAmount(57);
2464 Integration::SetPanGestureSmoothingMode(1);
2465 Integration::SetPanGestureUseActualTimes(false);
2466 Integration::SetPanGestureInterpolationTimeRange(10);
2467 Integration::SetPanGestureScalarOnlyPredictionEnabled(true);
2468 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2469 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2470 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2471 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2472 Integration::SetPanGestureMultitapSmoothingRange(34);
2474 Actor actor = Actor::New();
2475 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2476 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2477 application.GetScene().Add(actor);
2479 // Add a pan detector
2480 PanGestureDetector detector = PanGestureDetector::New();
2481 detector.Attach(actor);
2483 GestureReceivedFunctor functor(data);
2484 detector.DetectedSignal().Connect(&application, functor);
2486 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2488 ConstraintData constraintData;
2489 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2490 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2491 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2492 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2493 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2494 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2495 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2496 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2499 // Render and notify
2500 application.SendNotification();
2501 application.Render();
2503 Vector2 startPosition(2.0f, 2.0f);
2504 Vector2 position(17.0f, 2.0f);
2505 Vector2 direction(Vector2::XAXIS * -1.0f);
2506 uint32_t time = 100;
2508 TestStartPan(application, startPosition, position, time);
2510 for(int i = 0; i < 10; i++)
2512 position += direction;
2513 TestMovePan(application, position, time);
2514 time += TestGetFrameInterval();
2515 application.SendNotification();
2516 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2519 position += direction;
2520 TestMovePan(application, position, time);
2521 time += TestGetFrameInterval();
2523 position += direction;
2524 TestMovePan(application, position, time);
2525 time += TestGetFrameInterval();
2527 position += direction;
2528 TestMovePan(application, position, time);
2529 time += TestGetFrameInterval();
2531 application.SendNotification();
2532 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2534 for(int i = 0; i < 5; i++)
2536 application.SendNotification();
2537 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2540 for(int i = 0; i < 10; i++)
2542 position += direction;
2543 TestMovePan(application, position, time);
2544 time += TestGetFrameInterval();
2545 application.SendNotification();
2546 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2549 TestEndPan(application, position, time);
2550 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2552 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2553 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2554 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2555 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2557 constraintData.Reset();
2561 int UtcDaliPanGestureSetProperties(void)
2563 TestApplication application;
2564 TestRenderController& renderController(application.GetRenderController());
2565 Integration::SetPanGesturePredictionMode(0);
2566 Integration::SetPanGestureSmoothingMode(0);
2568 Actor actor = Actor::New();
2569 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2570 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2571 application.GetScene().Add(actor);
2573 // Add a pan detector
2574 PanGestureDetector detector = PanGestureDetector::New();
2575 detector.Attach(actor);
2577 GestureReceivedFunctor functor(data);
2578 detector.DetectedSignal().Connect(&application, functor);
2580 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2581 Property::Index animatableGestureProperty = detector.RegisterProperty("Dummy Property", Vector3::ZERO); // For code coverage
2583 ConstraintData constraintData;
2584 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2585 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2586 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2587 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2588 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2589 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2590 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2591 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2592 constraint.AddSource(Source(detector, animatableGestureProperty));
2595 // Render and notify
2596 application.SendNotification();
2597 application.Render();
2599 renderController.Initialize();
2600 DALI_TEST_EQUALS(renderController.WasCalled(TestRenderController::RequestUpdateFunc), false, TEST_LOCATION);
2602 Vector2 screenPosition(20.0f, 20.0f);
2603 Vector2 screenDisplacement(1.0f, 1.0f);
2604 Vector2 screenVelocity(1.3f, 4.0f);
2605 Vector2 localPosition(21.0f, 21.0f);
2606 Vector2 localDisplacement(0.5f, 0.5f);
2607 Vector2 localVelocity(1.5f, 2.5f);
2609 PanGestureDetector::SetPanGestureProperties(GeneratePan(1u, GestureState::STARTED, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity));
2610 DALI_TEST_EQUALS(renderController.WasCalled(TestRenderController::RequestUpdateFunc), true, TEST_LOCATION);
2612 // Render and notify
2613 application.SendNotification();
2614 application.Render();
2616 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2617 DALI_TEST_EQUALS(constraintData.screenPosition, screenPosition, TEST_LOCATION);
2618 DALI_TEST_EQUALS(constraintData.localPosition, localPosition, TEST_LOCATION);
2619 DALI_TEST_EQUALS(constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION);
2620 DALI_TEST_EQUALS(constraintData.localDisplacement, localDisplacement, TEST_LOCATION);
2621 DALI_TEST_EQUALS(constraintData.screenVelocity, screenVelocity, TEST_LOCATION);
2622 DALI_TEST_EQUALS(constraintData.localVelocity, localVelocity, TEST_LOCATION);
2623 constraintData.Reset();
2627 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2629 TestApplication application;
2630 Integration::SetPanGesturePredictionMode(0);
2632 Actor actor = Actor::New();
2633 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2634 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2635 application.GetScene().Add(actor);
2637 // Add a pan detector
2638 PanGestureDetector detector = PanGestureDetector::New();
2639 detector.Attach(actor);
2641 GestureReceivedFunctor functor(data);
2642 detector.DetectedSignal().Connect(&application, functor);
2644 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2646 ConstraintData constraintData;
2647 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2648 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2649 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2650 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2651 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2652 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2653 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2654 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2657 // Render and notify
2658 application.SendNotification();
2659 application.Render();
2661 Vector2 currentPosition(20.0f, 4.0f);
2662 uint32_t time = 100;
2663 TestStartPan(application, Vector2(20.0f, 20.0f), currentPosition, time);
2664 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2666 Vector2 screenPosition(100.0f, 20.0f);
2667 Vector2 localPosition(110.0f, 110.0f);
2669 PanGestureDetector::SetPanGestureProperties(GeneratePan(1u, GestureState::STARTED, screenPosition, localPosition));
2671 // Render and notify
2672 application.SendNotification();
2673 application.Render();
2675 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2676 DALI_TEST_EQUALS(constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION);
2677 DALI_TEST_EQUALS(constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION);
2678 constraintData.Reset();
2682 int UtcDaliPanGesturePropertyIndices(void)
2684 TestApplication application;
2685 PanGestureDetector detector = PanGestureDetector::New();
2687 Property::IndexContainer indices;
2688 detector.GetPropertyIndices(indices);
2689 DALI_TEST_CHECK(indices.Size());
2690 DALI_TEST_EQUALS(indices.Size(), detector.GetPropertyCount(), TEST_LOCATION);
2696 struct PropertyStringIndex
2698 const char* const name;
2699 const Property::Index index;
2700 const Property::Type type;
2701 const Property::Value value;
2704 const PropertyStringIndex PROPERTY_TABLE[] =
2706 {"screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO},
2707 {"screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO},
2708 {"screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO},
2709 {"localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO},
2710 {"localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO},
2711 {"localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO},
2712 {"panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false},
2714 const unsigned int PROPERTY_TABLE_COUNT = sizeof(PROPERTY_TABLE) / sizeof(PROPERTY_TABLE[0]);
2715 } // unnamed namespace
2717 int UtcDaliPanGestureProperties(void)
2719 TestApplication application;
2720 PanGestureDetector detector = PanGestureDetector::New();
2722 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2724 DALI_TEST_EQUALS(detector.GetPropertyName(PROPERTY_TABLE[i].index), std::string(PROPERTY_TABLE[i].name), TEST_LOCATION);
2725 DALI_TEST_EQUALS(detector.GetPropertyIndex(PROPERTY_TABLE[i].name), PROPERTY_TABLE[i].index, TEST_LOCATION);
2726 DALI_TEST_EQUALS(detector.GetPropertyType(PROPERTY_TABLE[i].index), PROPERTY_TABLE[i].type, TEST_LOCATION);
2727 DALI_TEST_EQUALS(detector.IsPropertyWritable(PROPERTY_TABLE[i].index), false, TEST_LOCATION);
2728 DALI_TEST_EQUALS(detector.IsPropertyAnimatable(PROPERTY_TABLE[i].index), false, TEST_LOCATION);
2729 DALI_TEST_EQUALS(detector.IsPropertyAConstraintInput(PROPERTY_TABLE[i].index), true, TEST_LOCATION);
2730 detector.SetProperty(PROPERTY_TABLE[i].index, Property::Value()); // Just for Coverage
2736 int UtcDaliPanGestureGetProperty(void)
2738 TestApplication application;
2739 PanGestureDetector detector = PanGestureDetector::New();
2741 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2743 if(PROPERTY_TABLE[i].type == Property::VECTOR2)
2745 bool value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<bool>();
2746 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<bool>(), value, TEST_LOCATION);
2748 else if(PROPERTY_TABLE[i].type == Property::BOOLEAN)
2750 Vector2 value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<Vector2>();
2751 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<Vector2>(), value, TEST_LOCATION);
2758 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2760 TestApplication application;
2762 Actor actor = Actor::New();
2763 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2764 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2765 application.GetScene().Add(actor);
2767 // Add a pan detector
2768 PanGestureDetector detector = PanGestureDetector::New();
2769 detector.Attach(actor);
2771 // Render and notify
2772 application.SendNotification();
2773 application.Render();
2775 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2777 detector.SetProperty(PROPERTY_TABLE[i].index, Property::Value()); // Just for Coverage
2779 if(PROPERTY_TABLE[i].type == Property::VECTOR2)
2781 bool value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<bool>();
2782 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<bool>(), value, TEST_LOCATION);
2784 else if(PROPERTY_TABLE[i].type == Property::BOOLEAN)
2786 Vector2 value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<Vector2>();
2787 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<Vector2>(), value, TEST_LOCATION);
2794 int UtcDaliPanGestureLayerConsumesTouch(void)
2796 TestApplication application;
2798 Actor actor = Actor::New();
2799 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2800 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2801 application.GetScene().Add(actor);
2803 // Add a pan detector
2804 PanGestureDetector detector = PanGestureDetector::New();
2805 detector.Attach(actor);
2807 GestureReceivedFunctor functor(data);
2808 detector.DetectedSignal().Connect(&application, functor);
2810 // Add a layer to overlap the actor
2811 Layer layer = Layer::New();
2812 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2813 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2814 application.GetScene().Add(layer);
2817 // Render and notify
2818 application.SendNotification();
2819 application.Render();
2821 // Emit signals, should receive
2822 uint32_t time = 100;
2823 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2824 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2825 time += TestGetFrameInterval();
2827 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2830 // Set layer to consume all touch
2831 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
2833 // Render and notify
2834 application.SendNotification();
2835 application.Render();
2837 // Emit the same signals again, should not receive
2838 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2839 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2841 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2847 int UtcDaliPanGestureNoTimeDiff(void)
2849 TestApplication application;
2851 Actor actor = Actor::New();
2852 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2853 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2854 application.GetScene().Add(actor);
2856 // Add a pan detector
2857 PanGestureDetector detector = PanGestureDetector::New();
2858 detector.Attach(actor);
2860 GestureReceivedFunctor functor(data);
2861 detector.DetectedSignal().Connect(&application, functor);
2863 // Render and notify
2864 application.SendNotification();
2865 application.Render();
2867 // As normal helper function adds intervals between presses we must generate the sequence
2868 // using other helper functions
2869 TestStartLongPress(application, 10.0f, 20.0f, 100); // Used to send a down press event
2870 TestMovePan(application, Vector2(26.0f, 20.0f), 100);
2871 TestMovePan(application, Vector2(26.0f, 20.0f), 100); // 2 motions required to trigger
2872 TestEndPan(application, Vector2(26.0f, 20.0f), 100);
2874 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2875 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetVelocity().x));
2876 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetVelocity().y));
2877 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetScreenVelocity().x));
2878 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetScreenVelocity().y));
2886 int UtcDaliPanGestureDisableDetectionDuringPanN(void)
2888 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
2890 TestApplication application;
2892 Actor actor = Actor::New();
2893 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2894 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2895 application.GetScene().Add(actor);
2897 // Add a pan detector
2898 PanGestureDetector detector = PanGestureDetector::New();
2899 bool functorCalled = false;
2900 detector.Attach(actor);
2901 detector.DetectedSignal().Connect(
2903 [&detector, &functorCalled](Actor actor, const PanGesture& pan) {
2904 if(pan.GetState() == GestureState::FINISHED)
2906 detector.Detach(actor);
2907 functorCalled = true;
2911 // Render and notify
2912 application.SendNotification();
2913 application.Render();
2915 // Try the gesture, should not crash
2918 uint32_t time = 100;
2919 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2920 TestEndPan(application, Vector2(26.0f, 20.0f));
2922 DALI_TEST_CHECK(true); // No crash, test has passed
2923 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
2927 DALI_TEST_CHECK(false); // If we crash, the test has failed
2933 int UtcDaliPanGestureWhenGesturePropargation(void)
2935 TestApplication application;
2937 Actor parentActor = Actor::New();
2938 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2939 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2941 Actor childActor = Actor::New();
2942 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2943 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2945 parentActor.Add(childActor);
2946 application.GetScene().Add(parentActor);
2948 // Render and notify
2949 application.SendNotification();
2950 application.Render();
2953 GestureReceivedFunctor pFunctor(pData);
2955 PanGestureDetector parentDetector = PanGestureDetector::New();
2956 parentDetector.Attach(parentActor);
2957 parentDetector.DetectedSignal().Connect(&application, pFunctor);
2960 GestureReceivedFunctor cFunctor(cData);
2962 PanGestureDetector childDetector = PanGestureDetector::New();
2963 childDetector.Attach(childActor);
2964 childDetector.DetectedSignal().Connect(&application, cFunctor);
2966 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
2967 uint32_t time = 100;
2968 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2970 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2971 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
2975 TestMovePan(application, Vector2(26.0f, 4.0f), time);
2976 time += TestGetFrameInterval();
2978 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2979 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
2983 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2985 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2986 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
2990 // If GesturePropargation is set, a gesture event is to pass over to the parent.
2991 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
2993 // So now the parent got the gesture event.
2994 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2995 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2996 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
3000 TestMovePan(application, Vector2(26.0f, 4.0f), time);
3001 time += TestGetFrameInterval();
3003 // child does not receive gestures. This is because we have passed the permission of the gesture to the parent.
3004 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
3005 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
3009 TestEndPan(application, Vector2(26.0f, 20.0f), time);
3010 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
3011 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);