2 * Copyright (c) 2020 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/events/pan-gesture-devel.h>
20 #include <dali/integration-api/events/touch-event-integ.h>
21 #include <dali/integration-api/input-options.h>
22 #include <dali/integration-api/profiling.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali/public-api/dali-core.h>
26 #include <test-touch-event-utils.h>
33 void utc_dali_pan_gesture_detector_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_pan_gesture_detector_cleanup(void)
40 test_return_value = TET_PASS;
43 ///////////////////////////////////////////////////////////////////////////////
46 const int PAN_EVENT_TIME_DELTA = 8;
47 const int PAN_GESTURE_UPDATE_COUNT = 50;
49 // Stores data that is populated in the callback and will be read by the test cases
53 : functorCalled(false),
54 voidFunctorCalled(false),
61 functorCalled = false;
62 voidFunctorCalled = false;
64 receivedGesture.Reset();
70 bool voidFunctorCalled;
71 PanGesture receivedGesture;
75 // Functor that sets the data when called
76 struct GestureReceivedFunctor
78 GestureReceivedFunctor(SignalData& data)
83 void operator()(Actor actor, const PanGesture& pan)
85 signalData.functorCalled = true;
86 signalData.receivedGesture = pan;
87 signalData.pannedActor = actor;
92 signalData.voidFunctorCalled = true;
95 SignalData& signalData;
98 // Functor that removes the gestured actor from stage
99 struct UnstageActorFunctor : public GestureReceivedFunctor
101 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
102 : GestureReceivedFunctor(data),
103 stateToUnstage(stateToUnstage),
108 void operator()(Actor actor, const PanGesture& pan)
110 GestureReceivedFunctor::operator()(actor, pan);
112 if(pan.GetState() == stateToUnstage)
118 GestureState& stateToUnstage;
119 Integration::Scene scene;
122 // Data for constraints
123 struct ConstraintData
131 Vector2 screenPosition;
132 Vector2 screenDisplacement;
133 Vector2 screenVelocity;
134 Vector2 localPosition;
135 Vector2 localDisplacement;
136 Vector2 localVelocity;
142 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
148 // Constraint used with panning properties
151 PanConstraint(ConstraintData& data)
152 : constraintData(data)
156 void operator()(Vector3& current, const PropertyInputContainer& inputs)
158 constraintData.screenPosition = inputs[0]->GetVector2();
159 constraintData.screenDisplacement = inputs[1]->GetVector2();
160 constraintData.screenVelocity = inputs[2]->GetVector2();
161 constraintData.localPosition = inputs[3]->GetVector2();
162 constraintData.localDisplacement = inputs[4]->GetVector2();
163 constraintData.localVelocity = inputs[5]->GetVector2();
164 constraintData.panning = inputs[6]->GetBoolean();
165 constraintData.called = true;
166 current = Vector3::ZERO;
169 ConstraintData& constraintData;
172 // Generate a PanGesture
173 PanGesture GeneratePan(unsigned int time,
175 Vector2 screenPosition,
176 Vector2 localPosition,
177 Vector2 screenDisplacement = Vector2::ONE,
178 Vector2 localDisplacement = Vector2::ONE,
179 Vector2 screenVelocity = Vector2::ONE,
180 Vector2 localVelocity = Vector2::ONE,
181 unsigned int numberOfTouches = 1)
183 Dali::PanGesture pan = DevelPanGesture::New(state);
185 DevelPanGesture::SetTime(pan, time);
187 DevelPanGesture::SetScreenPosition(pan, screenPosition);
188 DevelPanGesture::SetPosition(pan, localPosition);
190 DevelPanGesture::SetScreenDisplacement(pan, screenDisplacement);
191 DevelPanGesture::SetDisplacement(pan, localDisplacement);
193 DevelPanGesture::SetScreenVelocity(pan, screenVelocity);
194 DevelPanGesture::SetVelocity(pan, localVelocity);
196 DevelPanGesture::SetNumberOfTouches(pan, numberOfTouches);
203 ///////////////////////////////////////////////////////////////////////////////
205 // Positive test case for a method
206 int UtcDaliPanGestureDetectorConstructor(void)
208 TestApplication application;
210 PanGestureDetector detector;
211 DALI_TEST_CHECK(!detector);
215 int UtcDaliPanGestureDetectorCopyConstructorP(void)
217 TestApplication application;
219 PanGestureDetector detector = PanGestureDetector::New();
221 PanGestureDetector copy(detector);
222 DALI_TEST_CHECK(detector);
226 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
228 TestApplication application;
230 PanGestureDetector detector = PanGestureDetector::New();
232 PanGestureDetector assign;
234 DALI_TEST_CHECK(detector);
236 DALI_TEST_CHECK(detector == assign);
240 // Negative test case for a method
241 int UtcDaliPanGestureDetectorNew(void)
243 TestApplication application;
245 PanGestureDetector detector = PanGestureDetector::New();
247 DALI_TEST_CHECK(detector);
249 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
250 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
252 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
253 Actor actor = Actor::New();
254 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
255 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
256 detector.Attach(actor);
258 application.GetScene().Add(actor);
261 application.SendNotification();
262 application.Render();
264 // Use long press function for touch event
265 TestStartLongPress(application);
270 int UtcDaliPanGestureDetectorDownCast(void)
272 TestApplication application;
273 tet_infoline("Testing Dali::GestureDetector::DownCast()");
275 PanGestureDetector detector = PanGestureDetector::New();
277 BaseHandle object(detector);
279 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
280 DALI_TEST_CHECK(detector2);
282 PanGestureDetector detector3 = DownCast<PanGestureDetector>(object);
283 DALI_TEST_CHECK(detector3);
285 BaseHandle unInitializedObject;
286 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
287 DALI_TEST_CHECK(!detector4);
289 PanGestureDetector detector5 = DownCast<PanGestureDetector>(unInitializedObject);
290 DALI_TEST_CHECK(!detector5);
292 GestureDetector detector6 = PanGestureDetector::New();
293 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
294 DALI_TEST_CHECK(detector7);
298 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
300 TestApplication application;
302 PanGestureDetector detector = PanGestureDetector::New();
304 unsigned int min = 2;
306 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
308 detector.SetMinimumTouchesRequired(min);
310 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
312 // Attach an actor and change the minimum touches
314 Actor actor = Actor::New();
315 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
316 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
317 application.GetScene().Add(actor);
320 application.SendNotification();
321 application.Render();
324 GestureReceivedFunctor functor(data);
326 detector.Attach(actor);
327 detector.DetectedSignal().Connect(&application, functor);
329 detector.SetMinimumTouchesRequired(3);
331 // Create a second gesture detector that requires even less minimum touches
332 PanGestureDetector secondDetector = PanGestureDetector::New();
333 secondDetector.Attach(actor);
335 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
340 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
342 TestApplication application;
344 PanGestureDetector detector = PanGestureDetector::New();
346 unsigned int max = 3;
348 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
350 detector.SetMaximumTouchesRequired(max);
352 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
354 // Attach an actor and change the maximum touches
356 Actor actor = Actor::New();
357 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
358 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
359 application.GetScene().Add(actor);
362 application.SendNotification();
363 application.Render();
366 GestureReceivedFunctor functor(data);
368 detector.Attach(actor);
369 detector.DetectedSignal().Connect(&application, functor);
371 detector.SetMaximumTouchesRequired(4);
373 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
378 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
380 TestApplication application;
382 PanGestureDetector detector = PanGestureDetector::New();
383 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
387 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
389 TestApplication application;
391 PanGestureDetector detector = PanGestureDetector::New();
392 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
396 int UtcDaliPanGestureSignalReceptionNegative(void)
398 TestApplication application;
400 Actor actor = Actor::New();
401 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
402 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
403 application.GetScene().Add(actor);
406 application.SendNotification();
407 application.Render();
410 GestureReceivedFunctor functor(data);
412 PanGestureDetector detector = PanGestureDetector::New();
413 detector.Attach(actor);
414 detector.DetectedSignal().Connect(&application, functor);
416 // Do a pan outside actor's area
418 TestStartPan(application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time);
420 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
422 // Continue pan into actor's area - we should still not receive the signal
424 TestMovePan(application, Vector2(20.0f, 20.0f), time);
426 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
428 // Stop panning - we should still not receive the signal
430 TestEndPan(application, Vector2(12.0f, 12.0f), time);
432 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
436 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
438 TestApplication application;
440 Actor actor = Actor::New();
441 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
442 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
443 application.GetScene().Add(actor);
446 application.SendNotification();
447 application.Render();
450 GestureReceivedFunctor functor(data);
452 PanGestureDetector detector = PanGestureDetector::New();
453 detector.Attach(actor);
454 detector.DetectedSignal().Connect(&application, functor);
456 // Start pan within the actor's area
458 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
460 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
461 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
462 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
463 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
464 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
465 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
466 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
468 // Continue the pan within the actor's area - we should still receive the signal
471 TestMovePan(application, Vector2(26.0f, 4.0f), time);
472 time += TestGetFrameInterval();
474 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
475 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
476 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
477 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
478 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
479 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
480 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
482 // Pan Gesture leaves actor's area - we should still receive the signal
485 TestMovePan(application, Vector2(346.0f, 4.0f), time);
486 time += TestGetFrameInterval();
488 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
489 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
490 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
491 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
492 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
493 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
494 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
496 // Gesture ends - we would receive a finished state
499 TestEndPan(application, Vector2(314.0f, 4.0f), time);
501 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
502 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
503 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
504 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
505 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
506 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
507 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
511 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
513 TestApplication application;
515 Actor actor = Actor::New();
516 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
517 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
518 application.GetScene().Add(actor);
521 application.SendNotification();
522 application.Render();
525 GestureReceivedFunctor functor(data);
527 PanGestureDetector detector = PanGestureDetector::New();
528 detector.Attach(actor);
529 detector.DetectedSignal().Connect(&application, functor);
531 // Start pan within the actor's area
533 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
535 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
536 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
537 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
538 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
539 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
540 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
541 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
543 // Continue the pan within the actor's area - we should still receive the signal
546 TestMovePan(application, Vector2(26.0f, 4.0f), time);
547 time += TestGetFrameInterval();
549 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
550 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
551 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
552 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
553 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
554 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
555 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
557 // Gesture ends within actor's area - we would receive a finished state
560 TestEndPan(application, Vector2(10.0f, 4.0f), time);
562 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
563 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
564 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
565 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
566 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
568 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
572 int UtcDaliPanGestureSignalReceptionDetach(void)
574 TestApplication application;
576 Actor actor = Actor::New();
577 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
578 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
579 application.GetScene().Add(actor);
582 application.SendNotification();
583 application.Render();
586 GestureReceivedFunctor functor(data);
588 PanGestureDetector detector = PanGestureDetector::New();
589 detector.Attach(actor);
590 detector.DetectedSignal().Connect(&application, functor);
592 // Start pan within the actor's area
594 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
595 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
597 // Continue the pan within the actor's area - we should still receive the signal
600 TestMovePan(application, Vector2(26.0f, 4.0f), time);
601 time += TestGetFrameInterval();
603 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
605 // Gesture ends within actor's area
608 TestEndPan(application, Vector2(10.0f, 4.0f), time);
609 time += TestGetFrameInterval();
611 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
614 detector.DetachAll();
616 // Ensure we are no longer signalled
619 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
620 TestMovePan(application, Vector2(26.0f, 4.0f), time);
621 time += TestGetFrameInterval();
622 TestEndPan(application, Vector2(10.0f, 4.0f), time);
624 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
628 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
630 TestApplication application;
632 Actor actor = Actor::New();
633 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
634 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
635 application.GetScene().Add(actor);
638 application.SendNotification();
639 application.Render();
642 GestureReceivedFunctor functor(data);
644 PanGestureDetector detector = PanGestureDetector::New();
645 detector.Attach(actor);
646 detector.DetectedSignal().Connect(&application, functor);
648 // Start pan within the actor's area
650 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
651 application.SendNotification();
653 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
655 // Continue the pan within the actor's area - we should still receive the signal
658 TestMovePan(application, Vector2(26.0f, 4.0f), time);
659 time += TestGetFrameInterval();
661 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
663 // Detach actor during the pan, we should not receive the next event
664 detector.DetachAll();
666 // Gesture ends within actor's area
669 TestEndPan(application, Vector2(10.0f, 4.0f), time);
671 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
675 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
677 TestApplication application;
680 GestureReceivedFunctor functor(data);
682 PanGestureDetector detector = PanGestureDetector::New();
683 detector.DetectedSignal().Connect(&application, functor);
685 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
687 Actor tempActor = Actor::New();
688 tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
689 tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
690 application.GetScene().Add(tempActor);
691 detector.Attach(tempActor);
695 // Actor lifetime is scoped
697 Actor actor = Actor::New();
698 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
699 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
700 application.GetScene().Add(actor);
703 application.SendNotification();
704 application.Render();
706 detector.Attach(actor);
708 // Start pan within the actor's area
709 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
711 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
713 // Continue the pan within the actor's area - we should still receive the signal
716 TestMovePan(application, Vector2(26.0f, 4.0f), time);
717 time += TestGetFrameInterval();
719 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
721 // Remove the actor from stage and reset the data
722 application.GetScene().Remove(actor);
725 application.SendNotification();
726 application.Render();
729 // Actor should now have been destroyed
731 // Gesture ends within the area where the actor used to be
734 TestEndPan(application, Vector2(10.0f, 4.0f), time);
736 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
740 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
742 TestApplication application;
744 Actor actor = Actor::New();
745 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
746 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
747 application.GetScene().Add(actor);
750 application.SendNotification();
751 application.Render();
754 GestureReceivedFunctor functor(data);
756 PanGestureDetector detector = PanGestureDetector::New();
757 detector.Attach(actor);
758 detector.DetectedSignal().Connect(&application, functor);
760 // Do an entire pan, only check finished value
762 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
766 TestEndPan(application, Vector2(25.0f, 28.0f), time);
768 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
769 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
771 // Rotate actor again and render a couple of times
772 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
773 application.SendNotification();
774 application.Render();
776 // Do an entire pan, only check finished value
777 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
781 TestEndPan(application, Vector2(25.0f, 28.0f), time);
783 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
784 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
786 // Rotate actor again and render a couple of times
787 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
788 application.SendNotification();
789 application.Render();
791 // Do an entire pan, only check finished value
792 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
796 TestEndPan(application, Vector2(25.0f, 28.0f), time);
798 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
799 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
803 int UtcDaliPanGestureSignalReceptionChildHit(void)
805 TestApplication application;
807 Actor parent = Actor::New();
808 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
809 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
810 application.GetScene().Add(parent);
812 // Set child to completely cover parent.
813 // Change rotation of child to be different from parent so that we can check if our local coordinate
814 // conversion of the parent actor is correct.
815 Actor child = Actor::New();
816 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
817 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
818 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
819 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
823 application.SendNotification();
824 application.Render();
827 GestureReceivedFunctor functor(data);
829 PanGestureDetector detector = PanGestureDetector::New();
830 detector.Attach(parent);
831 detector.DetectedSignal().Connect(&application, functor);
833 // Do an entire pan, only check finished value - hits child area but parent should still receive it
835 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
839 TestEndPan(application, Vector2(25.0f, 28.0f), time);
841 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
842 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
843 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
845 // Attach child and generate same touch points to yield a different displacement
846 // (Also proves that you can detach and then re-attach another actor)
847 detector.Attach(child);
848 detector.Detach(parent);
850 // Do an entire pan, only check finished value
851 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
855 TestEndPan(application, Vector2(25.0f, 28.0f), time);
857 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
858 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
859 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
863 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
865 TestApplication application;
867 Actor first = Actor::New();
868 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
869 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
870 application.GetScene().Add(first);
872 Actor second = Actor::New();
873 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
874 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
875 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
876 application.GetScene().Add(second);
879 application.SendNotification();
880 application.Render();
883 GestureReceivedFunctor functor(data);
885 PanGestureDetector detector = PanGestureDetector::New();
886 detector.Attach(first);
887 detector.Attach(second);
888 detector.DetectedSignal().Connect(&application, functor);
890 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
891 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
893 // Start pan within second actor's area
895 TestStartPan(application, Vector2(110.0f, 20.0f), Vector2(126.0f, 20.0f), time);
897 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
898 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
900 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
901 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
903 // Pan moves into first actor's area - second actor should receive the pan
906 TestMovePan(application, Vector2(126.0f, 20.0f), time);
907 time += TestGetFrameInterval();
909 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
910 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
912 // Detach the second actor during the pan, we should not receive the next event
913 detector.Detach(second);
915 // Gesture ends within actor's area
918 TestMovePan(application, Vector2(26.0f, 20.0f), time);
919 TestEndPan(application, Vector2(10.0f, 4.0f), time);
921 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
926 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
928 TestApplication application;
930 Actor actor = Actor::New();
931 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
932 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
933 application.GetScene().Add(actor);
936 application.SendNotification();
937 application.Render();
940 GestureReceivedFunctor functor(data);
942 PanGestureDetector detector = PanGestureDetector::New();
943 detector.Attach(actor);
944 detector.DetectedSignal().Connect(&application, functor);
946 // Start pan in actor's area
948 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
950 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
952 // Pan continues within actor's area
955 TestMovePan(application, Vector2(26.0f, 4.0f), time);
956 time += TestGetFrameInterval();
958 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
960 // Actor become invisible - actor should not receive the next pan
961 actor.SetProperty(Actor::Property::VISIBLE, false);
964 application.SendNotification();
965 application.Render();
967 // Gesture ends within actor's area
970 TestEndPan(application, Vector2(10.0f, 4.0f), time);
972 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
976 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
978 TestApplication application;
980 Actor actor = Actor::New();
981 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
982 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
983 application.GetScene().Add(actor);
985 Actor actor2 = Actor::New();
986 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
987 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
988 application.GetScene().Add(actor2);
991 application.SendNotification();
992 application.Render();
994 // Attach actor to one detector
995 SignalData firstData;
996 GestureReceivedFunctor firstFunctor(firstData);
997 PanGestureDetector firstDetector = PanGestureDetector::New();
998 firstDetector.Attach(actor);
999 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1001 // Attach actor to another detector
1002 SignalData secondData;
1003 GestureReceivedFunctor secondFunctor(secondData);
1004 PanGestureDetector secondDetector = PanGestureDetector::New();
1005 secondDetector.Attach(actor);
1006 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1008 // Add second actor to second detector, when we remove the actor, this will make sure that this
1009 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1010 // functor should still not be called (which is what we're also testing).
1011 secondDetector.Attach(actor2);
1013 // Pan in actor's area - both detector's functors should be called
1014 uint32_t time = 100;
1015 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1017 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1018 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1020 // Pan continues in actor's area - both detector's functors should be called
1024 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1025 time += TestGetFrameInterval();
1027 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1028 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1030 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1031 firstDetector.Detach(actor);
1035 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1037 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1038 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1040 // New pan on actor, only secondDetector has actor attached
1044 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1046 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1047 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1049 // Detach actor from secondDetector
1050 secondDetector.Detach(actor);
1054 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1056 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1057 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1062 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1064 TestApplication application;
1066 Actor actor1 = Actor::New();
1067 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1068 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1069 application.GetScene().Add(actor1);
1071 GestureReceivedFunctor functor1(data1);
1072 PanGestureDetector detector1 = PanGestureDetector::New();
1073 detector1.Attach(actor1);
1074 detector1.DetectedSignal().Connect(&application, functor1);
1076 Actor actor2 = Actor::New();
1077 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1078 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
1079 actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
1080 application.GetScene().Add(actor2);
1082 GestureReceivedFunctor functor2(data2);
1083 PanGestureDetector detector2 = PanGestureDetector::New();
1084 detector2.Attach(actor2);
1085 detector2.DetectedSignal().Connect(&application, functor2);
1087 // Render and notify
1088 application.SendNotification();
1089 application.Render();
1091 // Start pan in actor1's area, only data1 should be set
1092 uint32_t time = 100;
1093 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1095 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1096 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1100 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1102 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1104 TestApplication application;
1106 Actor actor = Actor::New();
1107 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1108 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1109 application.GetScene().Add(actor);
1111 // Render and notify
1112 application.SendNotification();
1113 application.Render();
1115 // Gesture possible in actor's area (using long-press)
1116 uint32_t time = 100;
1117 TestStartLongPress(application, 10.0f, 20.0f, time);
1118 time += TestGetFrameInterval();
1120 // Attach actor to detector
1122 GestureReceivedFunctor functor(data);
1123 PanGestureDetector detector = PanGestureDetector::New();
1124 detector.DetectedSignal().Connect(&application, functor);
1125 detector.Attach(actor);
1127 // Start a pan, initially it'll only be possible, we shouldn't receive it
1128 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1129 time += TestGetFrameInterval();
1130 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1132 // Now the pan truly starts, we should receive a signal
1133 TestMovePan(application, Vector2(26.0f, 20.0f), time);
1134 time += TestGetFrameInterval();
1135 TestMovePan(application, Vector2(32.0f, 32.0f), time);
1136 time += TestGetFrameInterval();
1137 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1139 // Finish the pan, we should still receive a signal
1141 TestEndPan(application, Vector2(32.0f, 32.0f), time);
1142 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1147 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1149 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1150 // pan actor was there before (parent)
1152 TestApplication application;
1154 Actor parent = Actor::New();
1155 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1156 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1157 application.GetScene().Add(parent);
1159 Actor child = Actor::New();
1160 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1161 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1162 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1165 // Create detector for parent and attach
1166 SignalData parentData;
1167 GestureReceivedFunctor parentFunctor(parentData);
1168 PanGestureDetector parentDetector = PanGestureDetector::New();
1169 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1170 parentDetector.Attach(parent);
1172 // Create detector for child but do not attach
1173 SignalData childData;
1174 GestureReceivedFunctor childFunctor(childData);
1175 PanGestureDetector childDetector = PanGestureDetector::New();
1176 childDetector.DetectedSignal().Connect(&application, childFunctor);
1178 // Render and notify
1179 application.SendNotification();
1180 application.Render();
1182 // Do a full pan in both actors' area, only the parent's functor should be called
1183 uint32_t time = 100;
1184 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1185 DALI_TEST_EQUALS(parentData.functorCalled, true, TEST_LOCATION);
1186 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1189 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1190 DALI_TEST_EQUALS(parentData.functorCalled, true, TEST_LOCATION);
1191 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1195 // Gesture possible in both actors' area (using long-press), no functors called
1196 TestStartLongPress(application, 10.0f, 20.0f, time);
1197 time += TestGetFrameInterval();
1198 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1199 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1201 // Attach the child as well now
1202 childDetector.Attach(child);
1204 // Now the pan truly starts, we should receive a signal for the child only
1205 TestMovePan(application, Vector2(26.0f, 20.0f), time);
1206 time += TestGetFrameInterval();
1207 TestMovePan(application, Vector2(32.0f, 32.0f), time);
1208 time += TestGetFrameInterval();
1209 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1210 DALI_TEST_EQUALS(childData.functorCalled, true, TEST_LOCATION);
1214 // Finish the pan, again only the child should still receive a signal
1215 TestEndPan(application, Vector2(32.0f, 32.0f), time);
1216 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1217 DALI_TEST_EQUALS(childData.functorCalled, true, TEST_LOCATION);
1222 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1224 TestApplication application;
1226 Actor actor = Actor::New();
1227 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1228 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1229 application.GetScene().Add(actor);
1231 // Render and notify
1232 application.SendNotification();
1233 application.Render();
1235 // Attach actor to detector
1237 GestureReceivedFunctor functor(data);
1238 PanGestureDetector detector = PanGestureDetector::New();
1239 detector.Attach(actor);
1240 detector.DetectedSignal().Connect(&application, functor);
1242 // Gesture possible in actor's area.
1243 uint32_t time = 100;
1244 TestStartLongPress(application, 10.0f, 20.0f, time);
1245 time += TestGetFrameInterval();
1247 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1249 // Move actor somewhere else
1250 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
1252 // Render and notify
1253 application.SendNotification();
1254 application.Render();
1256 // Emit STARTED event, we should not receive the pan.
1257 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1258 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1259 time += TestGetFrameInterval();
1261 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1263 // LONG_PRESS possible in empty area.
1264 TestStartLongPress(application, 10.0f, 20.0f, time);
1265 time += TestGetFrameInterval();
1267 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1269 // Move actor in to the long press position.
1270 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1272 // Render and notify
1273 application.SendNotification();
1274 application.Render();
1276 // Emit STARTED event, we should be receiving the pan now.
1277 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1278 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1279 time += TestGetFrameInterval();
1281 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1283 // Normal pan in actor's area for completeness.
1285 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1286 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1287 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1291 int UtcDaliPanGestureActorUnstaged(void)
1293 TestApplication application;
1295 Actor actor = Actor::New();
1296 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1297 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1298 application.GetScene().Add(actor);
1300 // Render and notify
1301 application.SendNotification();
1302 application.Render();
1304 // State to remove actor in.
1305 GestureState stateToUnstage(GestureState::STARTED);
1307 // Attach actor to detector
1309 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
1310 PanGestureDetector detector = PanGestureDetector::New();
1311 detector.Attach(actor);
1312 detector.DetectedSignal().Connect(&application, functor);
1315 uint32_t time = 100;
1316 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1318 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1321 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1323 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1326 // Render and notify
1327 application.SendNotification();
1328 application.Render();
1330 // Re-add actor to stage
1331 application.GetScene().Add(actor);
1333 // Render and notify
1334 application.SendNotification();
1335 application.Render();
1337 // Change state to GestureState::CONTINUING to remove
1338 stateToUnstage = GestureState::CONTINUING;
1341 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1343 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1346 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1347 time += TestGetFrameInterval();
1349 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1353 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1355 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1358 // Render and notify
1359 application.SendNotification();
1360 application.Render();
1362 // Re-add actor to stage
1363 application.GetScene().Add(actor);
1365 // Render and notify
1366 application.SendNotification();
1367 application.Render();
1369 // Change state to GestureState::FINISHED to remove
1370 stateToUnstage = GestureState::FINISHED;
1373 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1375 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1378 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1379 time += TestGetFrameInterval();
1381 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1384 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1386 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1387 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
1391 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1393 TestApplication application;
1395 Actor actor = Actor::New();
1396 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1397 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1398 application.GetScene().Add(actor);
1400 // Create and add a second actor so that GestureDetector destruction does not come into play.
1401 Actor dummyActor(Actor::New());
1402 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1403 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
1404 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1405 application.GetScene().Add(dummyActor);
1407 // Render and notify
1408 application.SendNotification();
1409 application.Render();
1411 // State to remove actor in.
1412 GestureState stateToUnstage(GestureState::STARTED);
1414 // Attach actor to detector
1416 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
1417 PanGestureDetector detector = PanGestureDetector::New();
1418 detector.Attach(actor);
1419 detector.Attach(dummyActor);
1420 detector.DetectedSignal().Connect(&application, functor);
1422 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
1423 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1424 // position, we should still not be signalled.
1427 uint32_t time = 100;
1428 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1430 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1433 // Render and notify
1434 application.SendNotification();
1435 application.Render();
1437 // Re add to the stage, we should not be signalled
1438 application.GetScene().Add(actor);
1440 // Render and notify
1441 application.SendNotification();
1442 application.Render();
1444 // Continue signal emission
1445 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1446 time += TestGetFrameInterval();
1448 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1451 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1452 time += TestGetFrameInterval();
1454 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1457 // Here we delete an actor in started, we should not receive any subsequent signalling.
1460 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1462 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1465 // Render and notify
1466 application.SendNotification();
1467 application.Render();
1469 // Delete actor as well
1472 // Render and notify
1473 application.SendNotification();
1474 application.Render();
1476 // Continue signal emission
1477 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1478 time += TestGetFrameInterval();
1480 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1483 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1485 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1489 int UtcDaliPanGestureAngleHandling(void)
1491 TestApplication application;
1493 PanGestureDetector detector = PanGestureDetector::New();
1494 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1496 detector.AddAngle(PanGestureDetector::DIRECTION_LEFT, Radian(Math::PI * 0.25));
1497 DALI_TEST_EQUALS(detector.GetAngleCount(), 1u, TEST_LOCATION);
1499 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1501 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT)
1503 tet_result(TET_PASS);
1511 tet_printf("%s, angle not added\n", TEST_LOCATION);
1512 tet_result(TET_FAIL);
1515 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Radian(Math::PI * 0.25));
1516 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1518 // Remove something not in the container.
1519 detector.RemoveAngle(PanGestureDetector::DIRECTION_UP);
1520 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1522 detector.RemoveAngle(PanGestureDetector::DIRECTION_RIGHT);
1523 DALI_TEST_EQUALS(detector.GetAngleCount(), 1u, TEST_LOCATION);
1524 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1526 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT)
1528 tet_printf("%s, angle not removed\n", TEST_LOCATION);
1529 tet_result(TET_FAIL);
1534 detector.ClearAngles();
1535 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1539 int UtcDaliPanGestureGetAngle(void)
1541 TestApplication application;
1543 PanGestureDetector detector = PanGestureDetector::New();
1544 DALI_TEST_EQUALS(detector.GetAngleCount(), 0, TEST_LOCATION);
1546 detector.AddAngle(PanGestureDetector::DIRECTION_LEFT);
1547 DALI_TEST_EQUALS(detector.GetAngleCount(), 1, TEST_LOCATION);
1549 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT);
1550 DALI_TEST_EQUALS(detector.GetAngleCount(), 2, TEST_LOCATION);
1552 detector.AddAngle(PanGestureDetector::DIRECTION_UP);
1553 DALI_TEST_EQUALS(detector.GetAngleCount(), 3, TEST_LOCATION);
1555 detector.AddAngle(PanGestureDetector::DIRECTION_DOWN);
1556 DALI_TEST_EQUALS(detector.GetAngleCount(), 4, TEST_LOCATION);
1558 DALI_TEST_EQUALS(detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION);
1559 DALI_TEST_EQUALS(detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION);
1560 DALI_TEST_EQUALS(detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION);
1561 DALI_TEST_EQUALS(detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION);
1566 inline float RadiansToDegrees(float radian)
1568 return radian * 180.0f / Math::PI;
1571 int UtcDaliPanGestureAngleOutOfRange(void)
1573 TestApplication application;
1575 PanGestureDetector detector = PanGestureDetector::New();
1576 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1582 detector.AddAngle(Degree(180.0f));
1583 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-180.0f)), 0.000001, TEST_LOCATION);
1584 detector.ClearAngles();
1586 detector.AddAngle(Degree(190.0f));
1587 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-170.0f)), 0.000001, TEST_LOCATION);
1588 detector.ClearAngles();
1590 detector.AddAngle(Degree(-190.0f));
1591 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(170.0f)), 0.000001, TEST_LOCATION);
1592 detector.ClearAngles();
1594 detector.AddAngle(Degree(350.0f));
1595 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-10.0f)), 0.000001, TEST_LOCATION);
1596 detector.ClearAngles();
1598 detector.AddAngle(Degree(-350.0f));
1599 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1600 detector.ClearAngles();
1602 detector.AddAngle(Degree(370.0f));
1603 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1604 detector.ClearAngles();
1606 detector.AddAngle(Degree(-370.0f));
1607 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-10.0f)), 0.000001, TEST_LOCATION);
1608 detector.ClearAngles();
1614 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(0.0f));
1615 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(0.0f)), 0.000001, TEST_LOCATION);
1616 detector.ClearAngles();
1618 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(-10.0f));
1619 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1620 detector.ClearAngles();
1622 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(-181.0f));
1623 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(180.0f)), 0.000001, TEST_LOCATION);
1624 detector.ClearAngles();
1626 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(181.0f));
1627 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(180.0f)), 0.000001, TEST_LOCATION);
1628 detector.ClearAngles();
1632 int UtcDaliPanGestureAngleProcessing(void)
1634 TestApplication application;
1636 Actor parent = Actor::New();
1637 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1638 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1639 application.GetScene().Add(parent);
1641 Actor child = Actor::New();
1642 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1643 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1646 // Render and notify
1647 application.SendNotification();
1648 application.Render();
1650 // Parent detector only requires up pans
1651 PanGestureDetector parentDetector = PanGestureDetector::New();
1652 parentDetector.Attach(parent);
1653 parentDetector.AddAngle(PanGestureDetector::DIRECTION_UP, Degree(30.0f));
1654 SignalData parentData;
1655 GestureReceivedFunctor parentFunctor(parentData);
1656 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1658 // Child detector only requires right pans
1659 PanGestureDetector childDetector = PanGestureDetector::New();
1660 childDetector.Attach(child);
1661 childDetector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(30.0f));
1662 SignalData childData;
1663 GestureReceivedFunctor childFunctor(childData);
1664 childDetector.DetectedSignal().Connect(&application, childFunctor);
1666 // Generate an Up pan gesture, only parent should receive it.
1667 uint32_t time = 100;
1668 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 4.0f), time);
1670 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1671 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1673 TestEndPan(application, Vector2(20.0f, 4.0f), time);
1674 time += TestGetFrameInterval();
1678 // Generate a Right pan gesture, only child should receive it.
1679 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(36.0f, 20.0f), time);
1681 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1682 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1684 TestEndPan(application, Vector2(4.0f, 20.0f), time);
1685 time += TestGetFrameInterval();
1689 // Generate a Down pan gesture, no one should receive it.
1690 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 36.0f), time);
1692 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1693 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1695 TestEndPan(application, Vector2(20.0f, 36.0f), time);
1696 time += TestGetFrameInterval();
1700 // Generate a Left pan gesture, no one should receive it.
1701 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 20.0f), time);
1703 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1704 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1706 TestEndPan(application, Vector2(4.0f, 20.0f), time);
1712 int UtcDaliPanGestureDirectionHandling(void)
1714 TestApplication application;
1716 PanGestureDetector detector = PanGestureDetector::New();
1717 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1719 detector.AddDirection(PanGestureDetector::DIRECTION_LEFT, Radian(Math::PI * 0.25));
1720 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1722 for(size_t i = 0; detector.GetAngleCount(); i++)
1724 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT)
1726 tet_result(TET_PASS);
1734 tet_printf("%s, angle not added\n", TEST_LOCATION);
1735 tet_result(TET_FAIL);
1739 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1741 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT)
1743 tet_result(TET_PASS);
1751 tet_printf("%s, angle not added\n", TEST_LOCATION);
1752 tet_result(TET_FAIL);
1755 // Remove something not in the container.
1756 detector.RemoveDirection(PanGestureDetector::DIRECTION_UP);
1757 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1759 detector.RemoveDirection(PanGestureDetector::DIRECTION_RIGHT);
1760 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1764 int UtcDaliPanGestureDirectionProcessing(void)
1766 TestApplication application;
1768 Actor parent = Actor::New();
1769 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1770 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1771 application.GetScene().Add(parent);
1773 Actor child = Actor::New();
1774 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1775 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1778 // Render and notify
1779 application.SendNotification();
1780 application.Render();
1782 // Parent detector only requires vertical panning
1783 PanGestureDetector parentDetector = PanGestureDetector::New();
1784 parentDetector.Attach(parent);
1785 parentDetector.AddDirection(PanGestureDetector::DIRECTION_VERTICAL, Degree(30.0f));
1786 SignalData parentData;
1787 GestureReceivedFunctor parentFunctor(parentData);
1788 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1790 // Child detector only requires horizontal panning
1791 PanGestureDetector childDetector = PanGestureDetector::New();
1792 childDetector.Attach(child);
1793 childDetector.AddDirection(PanGestureDetector::DIRECTION_HORIZONTAL, Degree(30.0f));
1794 SignalData childData;
1795 GestureReceivedFunctor childFunctor(childData);
1796 childDetector.DetectedSignal().Connect(&application, childFunctor);
1798 // Generate an Up pan gesture, only parent should receive it.
1799 uint32_t time = 100;
1800 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 4.0f), time);
1802 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1803 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1805 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1806 time += TestGetFrameInterval();
1810 // Generate a Right pan gesture, only child should receive it.
1811 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(36.0f, 20.0f), time);
1813 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1814 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1816 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1817 time += TestGetFrameInterval();
1821 // Generate a Down pan gesture, only parent should receive it.
1822 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 36.0f), time);
1824 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1825 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1827 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1828 time += TestGetFrameInterval();
1832 // Generate a Left pan gesture, only child should receive it.
1833 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 20.0f), time);
1835 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1836 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1838 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1839 time += TestGetFrameInterval();
1843 // Generate a pan at -45 degrees, no one should receive it.
1844 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(9.0f, 31.0f), time);
1846 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1847 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1849 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1850 time += TestGetFrameInterval();
1854 // Generate a pan at 45 degrees, no one should receive it.
1855 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(31.0f, 31.0f), time);
1857 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1858 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1860 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1861 time += TestGetFrameInterval();
1865 // Generate a pan at -135 degrees, no one should receive it.
1866 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 4.0f), time);
1868 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1869 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1871 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1877 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1879 TestApplication application;
1880 Integration::SetPanGesturePredictionMode(0);
1881 Integration::SetPanGestureSmoothingMode(0);
1883 Actor actor = Actor::New();
1884 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1885 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1886 application.GetScene().Add(actor);
1888 // Add a pan detector
1889 PanGestureDetector detector = PanGestureDetector::New();
1890 detector.Attach(actor);
1892 GestureReceivedFunctor functor(data);
1893 detector.DetectedSignal().Connect(&application, functor);
1895 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
1897 ConstraintData constraintData;
1898 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
1899 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
1900 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
1901 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
1902 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
1903 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
1904 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
1905 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
1908 // Render and notify
1909 application.SendNotification();
1910 application.Render();
1912 Vector2 startPosition(1.0f, 1.0f);
1913 Vector2 position(-14.0f, 1.0f);
1914 Vector2 direction(Vector2::XAXIS * -5.0f);
1915 uint32_t time = 100;
1917 TestStartPan(application, startPosition, position, time);
1919 for(int i = 0; i < 47; i++)
1921 position += direction;
1922 TestMovePan(application, position, time);
1923 time += TestGetFrameInterval();
1924 application.SendNotification();
1925 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1928 TestEndPan(application, position, time);
1929 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1931 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1932 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
1933 DALI_TEST_EQUALS(constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION);
1934 DALI_TEST_EQUALS(constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION);
1936 constraintData.Reset();
1940 int UtcDaliPanGestureNoPredictionSmoothing(void)
1942 TestApplication application;
1943 Integration::SetPanGesturePredictionMode(0);
1944 Integration::SetPanGestureSmoothingMode(1);
1946 Actor actor = Actor::New();
1947 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1948 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1949 application.GetScene().Add(actor);
1951 // Add a pan detector
1952 PanGestureDetector detector = PanGestureDetector::New();
1953 detector.Attach(actor);
1955 GestureReceivedFunctor functor(data);
1956 detector.DetectedSignal().Connect(&application, functor);
1958 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
1960 ConstraintData constraintData;
1961 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
1962 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
1963 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
1964 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
1965 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
1966 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
1967 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
1968 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
1971 // Render and notify
1972 application.SendNotification();
1973 application.Render();
1975 Vector2 startPosition(1.0f, 1.0f);
1976 Vector2 position(-14.0f, 1.0f);
1977 Vector2 direction(Vector2::XAXIS * -5.0f);
1978 uint32_t time = 100;
1980 TestStartPan(application, startPosition, position, time);
1982 for(int i = 0; i < 47; i++)
1984 position += direction;
1985 TestMovePan(application, position, time);
1986 time += TestGetFrameInterval();
1987 application.SendNotification();
1988 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1991 TestEndPan(application, position, time);
1992 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1994 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1995 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
1996 // Take into account resampling done when prediction is off.
1997 DALI_TEST_EQUALS(constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION);
1998 DALI_TEST_EQUALS(constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION);
2000 constraintData.Reset();
2004 int UtcDaliPanGesturePredictionNoSmoothing(void)
2006 TestApplication application;
2007 Integration::SetPanGesturePredictionMode(1);
2008 Integration::SetPanGestureSmoothingMode(0);
2010 Actor actor = Actor::New();
2011 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2012 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2013 application.GetScene().Add(actor);
2015 // Add a pan detector
2016 PanGestureDetector detector = PanGestureDetector::New();
2017 detector.Attach(actor);
2019 GestureReceivedFunctor functor(data);
2020 detector.DetectedSignal().Connect(&application, functor);
2022 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2024 ConstraintData constraintData;
2025 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2026 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2027 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2028 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2029 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2030 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2031 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2032 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2035 // Render and notify
2036 application.SendNotification();
2037 application.Render();
2039 Vector2 startPosition(1.0f, 1.0f);
2040 Vector2 position(-1.0f, 1.0f);
2041 Vector2 direction(Vector2::XAXIS * -1.0f);
2042 uint32_t time = 100;
2044 TestStartPan(application, startPosition, position, time);
2046 for(int i = 0; i < 47; i++)
2048 position += direction;
2049 TestMovePan(application, position, time);
2050 time += TestGetFrameInterval();
2051 application.SendNotification();
2052 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2055 TestEndPan(application, position, time);
2056 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2058 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2059 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2060 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2061 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2063 constraintData.Reset();
2067 int UtcDaliPanGesturePredictionSmoothing01(void)
2069 TestApplication application;
2070 Integration::SetPanGesturePredictionMode(1);
2071 Integration::SetPanGestureSmoothingMode(1);
2073 Actor actor = Actor::New();
2074 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2075 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2076 application.GetScene().Add(actor);
2078 // Add a pan detector
2079 PanGestureDetector detector = PanGestureDetector::New();
2080 detector.Attach(actor);
2082 GestureReceivedFunctor functor(data);
2083 detector.DetectedSignal().Connect(&application, functor);
2085 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2087 ConstraintData constraintData;
2088 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2089 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2090 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2091 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2092 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2093 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2094 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2095 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2098 // Render and notify
2099 application.SendNotification();
2100 application.Render();
2102 Vector2 startPosition(1.0f, 1.0f);
2103 Vector2 position(-1.0f, 1.0f);
2104 Vector2 direction(Vector2::XAXIS * -1.0f);
2105 uint32_t time = 100;
2107 TestStartPan(application, startPosition, position, time);
2109 for(int i = 0; i < 47; i++)
2111 position += direction;
2112 TestMovePan(application, position, time);
2113 time += TestGetFrameInterval();
2114 application.SendNotification();
2115 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2118 TestEndPan(application, position, time);
2119 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2121 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2122 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2123 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2124 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2126 constraintData.Reset();
2130 int UtcDaliPanGesturePredictionSmoothing02(void)
2132 TestApplication application;
2133 Integration::SetPanGesturePredictionMode(1);
2134 Integration::SetPanGestureMaximumPredictionAmount(1);
2135 Integration::SetPanGesturePredictionAmountAdjustment(2);
2136 Integration::SetPanGestureSmoothingMode(1);
2137 Integration::SetPanGestureSmoothingAmount(0.25f);
2139 Actor actor = Actor::New();
2140 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2141 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2142 application.GetScene().Add(actor);
2144 // Add a pan detector
2145 PanGestureDetector detector = PanGestureDetector::New();
2146 detector.Attach(actor);
2148 GestureReceivedFunctor functor(data);
2149 detector.DetectedSignal().Connect(&application, functor);
2151 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2153 ConstraintData constraintData;
2154 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2155 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2156 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2157 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2158 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2159 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2160 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2161 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2164 // Render and notify
2165 application.SendNotification();
2166 application.Render();
2168 Vector2 startPosition(2.0f, 2.0f);
2169 Vector2 position(4.0f, 2.0f);
2170 Vector2 directionX(Vector2::XAXIS);
2171 Vector2 directionY(Vector2::YAXIS);
2172 uint32_t time = 100;
2174 TestStartPan(application, startPosition, position, time);
2176 for(int i = 0; i < 7; i++)
2178 position += directionX;
2179 TestMovePan(application, position, time);
2180 time += TestGetFrameInterval();
2181 application.SendNotification();
2182 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2185 position += directionX * 10.0f;
2186 TestMovePan(application, position, time);
2187 time += TestGetFrameInterval();
2188 application.SendNotification();
2189 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2191 for(int i = 0; i < 2; i++)
2193 position += (directionX * -1.0f);
2194 TestMovePan(application, position, time);
2195 time += TestGetFrameInterval();
2196 application.SendNotification();
2197 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2200 for(int i = 0; i < 10; i++)
2202 position += directionX;
2203 TestMovePan(application, position, time);
2204 time += TestGetFrameInterval();
2205 application.SendNotification();
2206 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2209 for(int i = 0; i < 10; i++)
2211 position += directionY;
2212 TestMovePan(application, position, time);
2213 time += TestGetFrameInterval();
2214 application.SendNotification();
2215 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2218 TestEndPan(application, position, time);
2219 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2221 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2222 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2223 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2224 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2226 constraintData.Reset();
2230 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2232 TestApplication application;
2234 Integration::SetPanGesturePredictionMode(2);
2235 Integration::SetPanGesturePredictionAmount(57);
2236 Integration::SetPanGestureSmoothingMode(2);
2237 Integration::SetPanGestureUseActualTimes(false);
2238 Integration::SetPanGestureInterpolationTimeRange(10);
2239 Integration::SetPanGestureScalarOnlyPredictionEnabled(false);
2240 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2241 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2242 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2243 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2244 Integration::SetPanGestureMultitapSmoothingRange(34);
2246 Actor actor = Actor::New();
2247 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2248 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2249 application.GetScene().Add(actor);
2251 // Add a pan detector
2252 PanGestureDetector detector = PanGestureDetector::New();
2253 detector.Attach(actor);
2255 GestureReceivedFunctor functor(data);
2256 detector.DetectedSignal().Connect(&application, functor);
2258 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2260 ConstraintData constraintData;
2261 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2262 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2263 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2264 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2265 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2266 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2267 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2268 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2271 // Render and notify
2272 application.SendNotification();
2273 application.Render();
2275 Vector2 startPosition(2.0f, 2.0f);
2276 Vector2 position(-1.0f, 2.0f);
2277 Vector2 direction(Vector2::XAXIS * -1.0f);
2278 uint32_t time = 100;
2280 TestStartPan(application, startPosition, position, time);
2282 for(int i = 0; i < 27; i++)
2284 position += direction;
2285 TestMovePan(application, position, time);
2286 time += TestGetFrameInterval();
2287 application.SendNotification();
2288 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2291 TestEndPan(application, position, time);
2292 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2294 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2295 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2296 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2297 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2299 constraintData.Reset();
2303 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2305 TestApplication application;
2307 Integration::SetPanGesturePredictionMode(2);
2308 Integration::SetPanGestureSmoothingMode(2);
2309 Integration::SetPanGestureUseActualTimes(true);
2310 Integration::SetPanGestureInterpolationTimeRange(10);
2311 Integration::SetPanGestureScalarOnlyPredictionEnabled(true);
2312 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2313 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2314 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2315 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2316 Integration::SetPanGestureMultitapSmoothingRange(34);
2318 Integration::EnableProfiling(Integration::PROFILING_TYPE_PAN_GESTURE);
2320 Actor actor = Actor::New();
2321 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2322 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2323 application.GetScene().Add(actor);
2325 // Add a pan detector
2326 PanGestureDetector detector = PanGestureDetector::New();
2327 detector.Attach(actor);
2329 GestureReceivedFunctor functor(data);
2330 detector.DetectedSignal().Connect(&application, functor);
2332 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2334 ConstraintData constraintData;
2335 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2336 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2337 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2338 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2339 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2340 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2341 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2342 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2345 // Render and notify
2346 application.SendNotification();
2347 application.Render();
2349 Vector2 startPosition(2.0f, 2.0f);
2350 Vector2 position(17.0f, 2.0f);
2351 Vector2 direction(Vector2::XAXIS * -1.0f);
2352 uint32_t time = 100;
2354 TestStartPan(application, startPosition, position, time);
2356 for(int i = 0; i < 10; i++)
2358 position += direction;
2359 TestMovePan(application, position, time);
2360 time += TestGetFrameInterval();
2362 position += direction;
2363 TestMovePan(application, position, time);
2364 time += TestGetFrameInterval();
2366 position += direction;
2367 TestMovePan(application, position, time);
2368 time += TestGetFrameInterval();
2370 application.SendNotification();
2371 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2374 for(int i = 0; i < 10; i++)
2376 application.SendNotification();
2377 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2380 for(int i = 0; i < 10; i++)
2382 position += direction;
2383 TestMovePan(application, position, time);
2384 application.SendNotification();
2385 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2388 for(int i = 0; i < 10; i++)
2390 position += direction;
2391 TestMovePan(application, position, time);
2392 time += TestGetFrameInterval();
2393 application.SendNotification();
2394 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2397 TestEndPan(application, position, time);
2398 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2400 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2401 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2402 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2403 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2405 constraintData.Reset();
2409 int UtcDaliPanGesturePrediction2Smoothing(void)
2411 TestApplication application;
2413 Integration::SetPanGesturePredictionMode(2);
2414 Integration::SetPanGesturePredictionAmount(57);
2415 Integration::SetPanGestureSmoothingMode(1);
2416 Integration::SetPanGestureUseActualTimes(false);
2417 Integration::SetPanGestureInterpolationTimeRange(10);
2418 Integration::SetPanGestureScalarOnlyPredictionEnabled(true);
2419 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2420 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2421 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2422 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2423 Integration::SetPanGestureMultitapSmoothingRange(34);
2425 Actor actor = Actor::New();
2426 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2427 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2428 application.GetScene().Add(actor);
2430 // Add a pan detector
2431 PanGestureDetector detector = PanGestureDetector::New();
2432 detector.Attach(actor);
2434 GestureReceivedFunctor functor(data);
2435 detector.DetectedSignal().Connect(&application, functor);
2437 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2439 ConstraintData constraintData;
2440 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2441 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2442 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2443 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2444 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2445 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2446 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2447 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2450 // Render and notify
2451 application.SendNotification();
2452 application.Render();
2454 Vector2 startPosition(2.0f, 2.0f);
2455 Vector2 position(17.0f, 2.0f);
2456 Vector2 direction(Vector2::XAXIS * -1.0f);
2457 uint32_t time = 100;
2459 TestStartPan(application, startPosition, position, time);
2461 for(int i = 0; i < 10; i++)
2463 position += direction;
2464 TestMovePan(application, position, time);
2465 time += TestGetFrameInterval();
2466 application.SendNotification();
2467 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2470 position += direction;
2471 TestMovePan(application, position, time);
2472 time += TestGetFrameInterval();
2474 position += direction;
2475 TestMovePan(application, position, time);
2476 time += TestGetFrameInterval();
2478 position += direction;
2479 TestMovePan(application, position, time);
2480 time += TestGetFrameInterval();
2482 application.SendNotification();
2483 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2485 for(int i = 0; i < 5; i++)
2487 application.SendNotification();
2488 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2491 for(int i = 0; i < 10; i++)
2493 position += direction;
2494 TestMovePan(application, position, time);
2495 time += TestGetFrameInterval();
2496 application.SendNotification();
2497 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2500 TestEndPan(application, position, time);
2501 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2503 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2504 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2505 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2506 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2508 constraintData.Reset();
2512 int UtcDaliPanGestureSetProperties(void)
2514 TestApplication application;
2515 TestRenderController& renderController(application.GetRenderController());
2516 Integration::SetPanGesturePredictionMode(0);
2517 Integration::SetPanGestureSmoothingMode(0);
2519 Actor actor = Actor::New();
2520 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2521 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2522 application.GetScene().Add(actor);
2524 // Add a pan detector
2525 PanGestureDetector detector = PanGestureDetector::New();
2526 detector.Attach(actor);
2528 GestureReceivedFunctor functor(data);
2529 detector.DetectedSignal().Connect(&application, functor);
2531 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2532 Property::Index animatableGestureProperty = detector.RegisterProperty("Dummy Property", Vector3::ZERO); // For code coverage
2534 ConstraintData constraintData;
2535 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2536 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2537 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2538 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2539 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2540 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2541 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2542 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2543 constraint.AddSource(Source(detector, animatableGestureProperty));
2546 // Render and notify
2547 application.SendNotification();
2548 application.Render();
2550 renderController.Initialize();
2551 DALI_TEST_EQUALS(renderController.WasCalled(TestRenderController::RequestUpdateFunc), false, TEST_LOCATION);
2553 Vector2 screenPosition(20.0f, 20.0f);
2554 Vector2 screenDisplacement(1.0f, 1.0f);
2555 Vector2 screenVelocity(1.3f, 4.0f);
2556 Vector2 localPosition(21.0f, 21.0f);
2557 Vector2 localDisplacement(0.5f, 0.5f);
2558 Vector2 localVelocity(1.5f, 2.5f);
2560 PanGestureDetector::SetPanGestureProperties(GeneratePan(1u, GestureState::STARTED, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity));
2561 DALI_TEST_EQUALS(renderController.WasCalled(TestRenderController::RequestUpdateFunc), true, TEST_LOCATION);
2563 // Render and notify
2564 application.SendNotification();
2565 application.Render();
2567 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2568 DALI_TEST_EQUALS(constraintData.screenPosition, screenPosition, TEST_LOCATION);
2569 DALI_TEST_EQUALS(constraintData.localPosition, localPosition, TEST_LOCATION);
2570 DALI_TEST_EQUALS(constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION);
2571 DALI_TEST_EQUALS(constraintData.localDisplacement, localDisplacement, TEST_LOCATION);
2572 DALI_TEST_EQUALS(constraintData.screenVelocity, screenVelocity, TEST_LOCATION);
2573 DALI_TEST_EQUALS(constraintData.localVelocity, localVelocity, TEST_LOCATION);
2574 constraintData.Reset();
2578 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2580 TestApplication application;
2581 Integration::SetPanGesturePredictionMode(0);
2583 Actor actor = Actor::New();
2584 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2585 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2586 application.GetScene().Add(actor);
2588 // Add a pan detector
2589 PanGestureDetector detector = PanGestureDetector::New();
2590 detector.Attach(actor);
2592 GestureReceivedFunctor functor(data);
2593 detector.DetectedSignal().Connect(&application, functor);
2595 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2597 ConstraintData constraintData;
2598 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2599 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2600 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2601 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2602 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2603 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2604 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2605 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2608 // Render and notify
2609 application.SendNotification();
2610 application.Render();
2612 Vector2 currentPosition(20.0f, 4.0f);
2613 uint32_t time = 100;
2614 TestStartPan(application, Vector2(20.0f, 20.0f), currentPosition, time);
2615 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2617 Vector2 screenPosition(100.0f, 20.0f);
2618 Vector2 localPosition(110.0f, 110.0f);
2620 PanGestureDetector::SetPanGestureProperties(GeneratePan(1u, GestureState::STARTED, screenPosition, localPosition));
2622 // Render and notify
2623 application.SendNotification();
2624 application.Render();
2626 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2627 DALI_TEST_EQUALS(constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION);
2628 DALI_TEST_EQUALS(constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION);
2629 constraintData.Reset();
2633 int UtcDaliPanGesturePropertyIndices(void)
2635 TestApplication application;
2636 PanGestureDetector detector = PanGestureDetector::New();
2638 Property::IndexContainer indices;
2639 detector.GetPropertyIndices(indices);
2640 DALI_TEST_CHECK(indices.Size());
2641 DALI_TEST_EQUALS(indices.Size(), detector.GetPropertyCount(), TEST_LOCATION);
2647 struct PropertyStringIndex
2649 const char* const name;
2650 const Property::Index index;
2651 const Property::Type type;
2652 const Property::Value value;
2655 const PropertyStringIndex PROPERTY_TABLE[] =
2657 {"screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO},
2658 {"screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO},
2659 {"screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO},
2660 {"localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO},
2661 {"localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO},
2662 {"localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO},
2663 {"panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false},
2665 const unsigned int PROPERTY_TABLE_COUNT = sizeof(PROPERTY_TABLE) / sizeof(PROPERTY_TABLE[0]);
2666 } // unnamed namespace
2668 int UtcDaliPanGestureProperties(void)
2670 TestApplication application;
2671 PanGestureDetector detector = PanGestureDetector::New();
2673 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2675 DALI_TEST_EQUALS(detector.GetPropertyName(PROPERTY_TABLE[i].index), std::string(PROPERTY_TABLE[i].name), TEST_LOCATION);
2676 DALI_TEST_EQUALS(detector.GetPropertyIndex(PROPERTY_TABLE[i].name), PROPERTY_TABLE[i].index, TEST_LOCATION);
2677 DALI_TEST_EQUALS(detector.GetPropertyType(PROPERTY_TABLE[i].index), PROPERTY_TABLE[i].type, TEST_LOCATION);
2678 DALI_TEST_EQUALS(detector.IsPropertyWritable(PROPERTY_TABLE[i].index), false, TEST_LOCATION);
2679 DALI_TEST_EQUALS(detector.IsPropertyAnimatable(PROPERTY_TABLE[i].index), false, TEST_LOCATION);
2680 DALI_TEST_EQUALS(detector.IsPropertyAConstraintInput(PROPERTY_TABLE[i].index), true, TEST_LOCATION);
2681 detector.SetProperty(PROPERTY_TABLE[i].index, Property::Value()); // Just for Coverage
2687 int UtcDaliPanGestureGetProperty(void)
2689 TestApplication application;
2690 PanGestureDetector detector = PanGestureDetector::New();
2692 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2694 if(PROPERTY_TABLE[i].type == Property::VECTOR2)
2696 bool value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<bool>();
2697 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<bool>(), value, TEST_LOCATION);
2699 else if(PROPERTY_TABLE[i].type == Property::BOOLEAN)
2701 Vector2 value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<Vector2>();
2702 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<Vector2>(), value, TEST_LOCATION);
2709 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2711 TestApplication application;
2713 Actor actor = Actor::New();
2714 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2715 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2716 application.GetScene().Add(actor);
2718 // Add a pan detector
2719 PanGestureDetector detector = PanGestureDetector::New();
2720 detector.Attach(actor);
2722 // Render and notify
2723 application.SendNotification();
2724 application.Render();
2726 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2728 detector.SetProperty(PROPERTY_TABLE[i].index, Property::Value()); // Just for Coverage
2730 if(PROPERTY_TABLE[i].type == Property::VECTOR2)
2732 bool value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<bool>();
2733 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<bool>(), value, TEST_LOCATION);
2735 else if(PROPERTY_TABLE[i].type == Property::BOOLEAN)
2737 Vector2 value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<Vector2>();
2738 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<Vector2>(), value, TEST_LOCATION);
2745 int UtcDaliPanGestureLayerConsumesTouch(void)
2747 TestApplication application;
2749 Actor actor = Actor::New();
2750 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2751 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2752 application.GetScene().Add(actor);
2754 // Add a pan detector
2755 PanGestureDetector detector = PanGestureDetector::New();
2756 detector.Attach(actor);
2758 GestureReceivedFunctor functor(data);
2759 detector.DetectedSignal().Connect(&application, functor);
2761 // Add a layer to overlap the actor
2762 Layer layer = Layer::New();
2763 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2764 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2765 application.GetScene().Add(layer);
2768 // Render and notify
2769 application.SendNotification();
2770 application.Render();
2772 // Emit signals, should receive
2773 uint32_t time = 100;
2774 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2775 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2776 time += TestGetFrameInterval();
2778 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2781 // Set layer to consume all touch
2782 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
2784 // Render and notify
2785 application.SendNotification();
2786 application.Render();
2788 // Emit the same signals again, should not receive
2789 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2790 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2792 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2798 int UtcDaliPanGestureNoTimeDiff(void)
2800 TestApplication application;
2802 Actor actor = Actor::New();
2803 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2804 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2805 application.GetScene().Add(actor);
2807 // Add a pan detector
2808 PanGestureDetector detector = PanGestureDetector::New();
2809 detector.Attach(actor);
2811 GestureReceivedFunctor functor(data);
2812 detector.DetectedSignal().Connect(&application, functor);
2814 // Render and notify
2815 application.SendNotification();
2816 application.Render();
2818 // As normal helper function adds intervals between presses we must generate the sequence
2819 // using other helper functions
2820 TestStartLongPress(application, 10.0f, 20.0f, 100); // Used to send a down press event
2821 TestMovePan(application, Vector2(26.0f, 20.0f), 100);
2822 TestMovePan(application, Vector2(26.0f, 20.0f), 100); // 2 motions required to trigger
2823 TestEndPan(application, Vector2(26.0f, 20.0f), 100);
2825 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2826 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetVelocity().x));
2827 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetVelocity().y));
2828 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetScreenVelocity().x));
2829 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetScreenVelocity().y));