2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/events/pan-gesture-devel.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/profiling.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/public-api/dali-core.h>
27 #include <test-touch-event-utils.h>
34 void utc_dali_pan_gesture_detector_startup(void)
36 test_return_value = TET_UNDEF;
39 void utc_dali_pan_gesture_detector_cleanup(void)
41 test_return_value = TET_PASS;
44 ///////////////////////////////////////////////////////////////////////////////
47 const int PAN_EVENT_TIME_DELTA = 8;
48 const int PAN_GESTURE_UPDATE_COUNT = 50;
50 // Stores data that is populated in the callback and will be read by the test cases
54 : functorCalled(false),
55 voidFunctorCalled(false),
62 functorCalled = false;
63 voidFunctorCalled = false;
65 receivedGesture.Reset();
71 bool voidFunctorCalled;
72 PanGesture receivedGesture;
76 // Functor that sets the data when called
77 struct GestureReceivedFunctor
79 GestureReceivedFunctor(SignalData& data)
84 void operator()(Actor actor, const PanGesture& pan)
86 signalData.functorCalled = true;
87 signalData.receivedGesture = pan;
88 signalData.pannedActor = actor;
93 signalData.voidFunctorCalled = true;
96 SignalData& signalData;
99 // Functor that removes the gestured actor from stage
100 struct UnstageActorFunctor : public GestureReceivedFunctor
102 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
103 : GestureReceivedFunctor(data),
104 stateToUnstage(stateToUnstage),
109 void operator()(Actor actor, const PanGesture& pan)
111 GestureReceivedFunctor::operator()(actor, pan);
113 if(pan.GetState() == stateToUnstage)
119 GestureState& stateToUnstage;
120 Integration::Scene scene;
123 // Data for constraints
124 struct ConstraintData
132 Vector2 screenPosition;
133 Vector2 screenDisplacement;
134 Vector2 screenVelocity;
135 Vector2 localPosition;
136 Vector2 localDisplacement;
137 Vector2 localVelocity;
143 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
149 // Constraint used with panning properties
152 PanConstraint(ConstraintData& data)
153 : constraintData(data)
157 void operator()(Vector3& current, const PropertyInputContainer& inputs)
159 constraintData.screenPosition = inputs[0]->GetVector2();
160 constraintData.screenDisplacement = inputs[1]->GetVector2();
161 constraintData.screenVelocity = inputs[2]->GetVector2();
162 constraintData.localPosition = inputs[3]->GetVector2();
163 constraintData.localDisplacement = inputs[4]->GetVector2();
164 constraintData.localVelocity = inputs[5]->GetVector2();
165 constraintData.panning = inputs[6]->GetBoolean();
166 constraintData.called = true;
167 current = Vector3::ZERO;
170 ConstraintData& constraintData;
173 // Generate a PanGesture
174 PanGesture GeneratePan(unsigned int time,
176 Vector2 screenPosition,
177 Vector2 localPosition,
178 Vector2 screenDisplacement = Vector2::ONE,
179 Vector2 localDisplacement = Vector2::ONE,
180 Vector2 screenVelocity = Vector2::ONE,
181 Vector2 localVelocity = Vector2::ONE,
182 unsigned int numberOfTouches = 1)
184 Dali::PanGesture pan = DevelPanGesture::New(state);
186 DevelPanGesture::SetTime(pan, time);
188 DevelPanGesture::SetScreenPosition(pan, screenPosition);
189 DevelPanGesture::SetPosition(pan, localPosition);
191 DevelPanGesture::SetScreenDisplacement(pan, screenDisplacement);
192 DevelPanGesture::SetDisplacement(pan, localDisplacement);
194 DevelPanGesture::SetScreenVelocity(pan, screenVelocity);
195 DevelPanGesture::SetVelocity(pan, localVelocity);
197 DevelPanGesture::SetNumberOfTouches(pan, numberOfTouches);
204 ///////////////////////////////////////////////////////////////////////////////
206 // Positive test case for a method
207 int UtcDaliPanGestureDetectorConstructor(void)
209 TestApplication application;
211 PanGestureDetector detector;
212 DALI_TEST_CHECK(!detector);
216 int UtcDaliPanGestureDetectorCopyConstructorP(void)
218 TestApplication application;
220 PanGestureDetector detector = PanGestureDetector::New();
222 PanGestureDetector copy(detector);
223 DALI_TEST_CHECK(detector);
227 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
229 TestApplication application;
231 PanGestureDetector detector = PanGestureDetector::New();
233 PanGestureDetector assign;
235 DALI_TEST_CHECK(detector);
237 DALI_TEST_CHECK(detector == assign);
241 // Negative test case for a method
242 int UtcDaliPanGestureDetectorNew(void)
244 TestApplication application;
246 PanGestureDetector detector = PanGestureDetector::New();
248 DALI_TEST_CHECK(detector);
250 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
251 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
253 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
254 Actor actor = Actor::New();
255 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
256 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
257 detector.Attach(actor);
259 application.GetScene().Add(actor);
262 application.SendNotification();
263 application.Render();
265 // Use long press function for touch event
266 TestStartLongPress(application);
271 int UtcDaliPanGestureDetectorDownCast(void)
273 TestApplication application;
274 tet_infoline("Testing Dali::GestureDetector::DownCast()");
276 PanGestureDetector detector = PanGestureDetector::New();
278 BaseHandle object(detector);
280 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
281 DALI_TEST_CHECK(detector2);
283 PanGestureDetector detector3 = DownCast<PanGestureDetector>(object);
284 DALI_TEST_CHECK(detector3);
286 BaseHandle unInitializedObject;
287 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
288 DALI_TEST_CHECK(!detector4);
290 PanGestureDetector detector5 = DownCast<PanGestureDetector>(unInitializedObject);
291 DALI_TEST_CHECK(!detector5);
293 GestureDetector detector6 = PanGestureDetector::New();
294 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
295 DALI_TEST_CHECK(detector7);
299 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
301 TestApplication application;
303 PanGestureDetector detector = PanGestureDetector::New();
305 unsigned int min = 2;
307 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
309 detector.SetMinimumTouchesRequired(min);
311 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
313 // Attach an actor and change the minimum touches
315 Actor actor = Actor::New();
316 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
317 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
318 application.GetScene().Add(actor);
321 application.SendNotification();
322 application.Render();
325 GestureReceivedFunctor functor(data);
327 detector.Attach(actor);
328 detector.DetectedSignal().Connect(&application, functor);
330 detector.SetMinimumTouchesRequired(3);
332 // Create a second gesture detector that requires even less minimum touches
333 PanGestureDetector secondDetector = PanGestureDetector::New();
334 secondDetector.Attach(actor);
336 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
341 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
343 TestApplication application;
345 PanGestureDetector detector = PanGestureDetector::New();
347 unsigned int max = 3;
349 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
351 detector.SetMaximumTouchesRequired(max);
353 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
355 // Attach an actor and change the maximum touches
357 Actor actor = Actor::New();
358 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
359 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
360 application.GetScene().Add(actor);
363 application.SendNotification();
364 application.Render();
367 GestureReceivedFunctor functor(data);
369 detector.Attach(actor);
370 detector.DetectedSignal().Connect(&application, functor);
372 detector.SetMaximumTouchesRequired(4);
374 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
379 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
381 TestApplication application;
383 PanGestureDetector detector = PanGestureDetector::New();
384 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
388 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
390 TestApplication application;
392 PanGestureDetector detector = PanGestureDetector::New();
393 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
397 int UtcDaliPanGestureSignalReceptionNegative(void)
399 TestApplication application;
401 Actor actor = Actor::New();
402 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
403 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
404 application.GetScene().Add(actor);
407 application.SendNotification();
408 application.Render();
411 GestureReceivedFunctor functor(data);
413 PanGestureDetector detector = PanGestureDetector::New();
414 detector.Attach(actor);
415 detector.DetectedSignal().Connect(&application, functor);
417 // Do a pan outside actor's area
419 TestStartPan(application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time);
421 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
423 // Continue pan into actor's area - we should still not receive the signal
425 TestMovePan(application, Vector2(20.0f, 20.0f), time);
427 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
429 // Stop panning - we should still not receive the signal
431 TestEndPan(application, Vector2(12.0f, 12.0f), time);
433 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
437 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
439 TestApplication application;
441 Actor actor = Actor::New();
442 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
443 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
444 application.GetScene().Add(actor);
447 application.SendNotification();
448 application.Render();
451 GestureReceivedFunctor functor(data);
453 PanGestureDetector detector = PanGestureDetector::New();
454 detector.Attach(actor);
455 detector.DetectedSignal().Connect(&application, functor);
457 // Start pan within the actor's area
459 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
461 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
462 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
463 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
464 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
465 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
466 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
467 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
469 // Continue the pan within the actor's area - we should still receive the signal
472 TestMovePan(application, Vector2(26.0f, 4.0f), time);
473 time += TestGetFrameInterval();
475 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
476 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
477 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
478 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
479 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
480 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
481 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
483 // Pan Gesture leaves actor's area - we should still receive the signal
486 TestMovePan(application, Vector2(346.0f, 4.0f), time);
487 time += TestGetFrameInterval();
489 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
490 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
491 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
492 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
493 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
494 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
495 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
497 // Gesture ends - we would receive a finished state
500 TestEndPan(application, Vector2(314.0f, 4.0f), time);
502 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
503 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
504 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
505 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
506 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
507 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
508 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
512 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
514 TestApplication application;
516 Actor actor = Actor::New();
517 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
518 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
519 application.GetScene().Add(actor);
522 application.SendNotification();
523 application.Render();
526 GestureReceivedFunctor functor(data);
528 PanGestureDetector detector = PanGestureDetector::New();
529 detector.Attach(actor);
530 detector.DetectedSignal().Connect(&application, functor);
532 // Start pan within the actor's area
534 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
536 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
537 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
538 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
539 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
540 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
541 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
542 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
544 // Continue the pan within the actor's area - we should still receive the signal
547 TestMovePan(application, Vector2(26.0f, 4.0f), time);
548 time += TestGetFrameInterval();
550 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
551 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
552 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
553 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
554 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
555 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
556 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
558 // Gesture ends within actor's area - we would receive a finished state
561 TestEndPan(application, Vector2(10.0f, 4.0f), time);
563 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
564 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
565 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
566 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
568 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
569 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
573 int UtcDaliPanGestureSignalReceptionDetach(void)
575 TestApplication application;
577 Actor actor = Actor::New();
578 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
579 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
580 application.GetScene().Add(actor);
583 application.SendNotification();
584 application.Render();
587 GestureReceivedFunctor functor(data);
589 PanGestureDetector detector = PanGestureDetector::New();
590 detector.Attach(actor);
591 detector.DetectedSignal().Connect(&application, functor);
593 // Start pan within the actor's area
595 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
596 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
598 // Continue the pan within the actor's area - we should still receive the signal
601 TestMovePan(application, Vector2(26.0f, 4.0f), time);
602 time += TestGetFrameInterval();
604 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
606 // Gesture ends within actor's area
609 TestEndPan(application, Vector2(10.0f, 4.0f), time);
610 time += TestGetFrameInterval();
612 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
615 detector.DetachAll();
617 // Ensure we are no longer signalled
620 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
621 TestMovePan(application, Vector2(26.0f, 4.0f), time);
622 time += TestGetFrameInterval();
623 TestEndPan(application, Vector2(10.0f, 4.0f), time);
625 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
629 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
631 TestApplication application;
633 Actor actor = Actor::New();
634 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
635 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
636 application.GetScene().Add(actor);
639 application.SendNotification();
640 application.Render();
643 GestureReceivedFunctor functor(data);
645 PanGestureDetector detector = PanGestureDetector::New();
646 detector.Attach(actor);
647 detector.DetectedSignal().Connect(&application, functor);
649 // Start pan within the actor's area
651 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
652 application.SendNotification();
654 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
656 // Continue the pan within the actor's area - we should still receive the signal
659 TestMovePan(application, Vector2(26.0f, 4.0f), time);
660 time += TestGetFrameInterval();
662 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
664 // Detach actor during the pan, we should not receive the next event
665 detector.DetachAll();
667 // Gesture ends within actor's area
670 TestEndPan(application, Vector2(10.0f, 4.0f), time);
672 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
676 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
678 TestApplication application;
681 GestureReceivedFunctor functor(data);
683 PanGestureDetector detector = PanGestureDetector::New();
684 detector.DetectedSignal().Connect(&application, functor);
686 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
688 Actor tempActor = Actor::New();
689 tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
690 tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
691 application.GetScene().Add(tempActor);
692 detector.Attach(tempActor);
696 // Actor lifetime is scoped
698 Actor actor = Actor::New();
699 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
700 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
701 application.GetScene().Add(actor);
704 application.SendNotification();
705 application.Render();
707 detector.Attach(actor);
709 // Start pan within the actor's area
710 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
712 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
714 // Continue the pan within the actor's area - we should still receive the signal
717 TestMovePan(application, Vector2(26.0f, 4.0f), time);
718 time += TestGetFrameInterval();
720 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
722 // Remove the actor from stage and reset the data
723 application.GetScene().Remove(actor);
726 application.SendNotification();
727 application.Render();
730 // Actor should now have been destroyed
732 // Gesture ends within the area where the actor used to be
735 TestEndPan(application, Vector2(10.0f, 4.0f), time);
737 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
741 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
743 TestApplication application;
745 Actor actor = Actor::New();
746 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
747 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
748 application.GetScene().Add(actor);
751 application.SendNotification();
752 application.Render();
755 GestureReceivedFunctor functor(data);
757 PanGestureDetector detector = PanGestureDetector::New();
758 detector.Attach(actor);
759 detector.DetectedSignal().Connect(&application, functor);
761 // Do an entire pan, only check finished value
763 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
767 TestEndPan(application, Vector2(25.0f, 28.0f), time);
769 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
770 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
772 // Rotate actor again and render a couple of times
773 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
774 application.SendNotification();
775 application.Render();
777 // Do an entire pan, only check finished value
778 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
782 TestEndPan(application, Vector2(25.0f, 28.0f), time);
784 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
785 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
787 // Rotate actor again and render a couple of times
788 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
789 application.SendNotification();
790 application.Render();
792 // Do an entire pan, only check finished value
793 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
797 TestEndPan(application, Vector2(25.0f, 28.0f), time);
799 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
800 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
804 int UtcDaliPanGestureSignalReceptionChildHit(void)
806 TestApplication application;
808 Actor parent = Actor::New();
809 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
810 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
811 application.GetScene().Add(parent);
813 // Set child to completely cover parent.
814 // Change rotation of child to be different from parent so that we can check if our local coordinate
815 // conversion of the parent actor is correct.
816 Actor child = Actor::New();
817 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
818 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
819 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
820 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
824 application.SendNotification();
825 application.Render();
828 GestureReceivedFunctor functor(data);
830 PanGestureDetector detector = PanGestureDetector::New();
831 detector.Attach(parent);
832 detector.DetectedSignal().Connect(&application, functor);
834 // Do an entire pan, only check finished value - hits child area but parent should still receive it
836 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
840 TestEndPan(application, Vector2(25.0f, 28.0f), time);
842 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
843 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
844 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
846 // Attach child and generate same touch points to yield a different displacement
847 // (Also proves that you can detach and then re-attach another actor)
848 detector.Attach(child);
849 detector.Detach(parent);
851 // Do an entire pan, only check finished value
852 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
856 TestEndPan(application, Vector2(25.0f, 28.0f), time);
858 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
859 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
860 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
864 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
866 TestApplication application;
868 Actor first = Actor::New();
869 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
870 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
871 application.GetScene().Add(first);
873 Actor second = Actor::New();
874 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
875 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
876 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
877 application.GetScene().Add(second);
880 application.SendNotification();
881 application.Render();
884 GestureReceivedFunctor functor(data);
886 PanGestureDetector detector = PanGestureDetector::New();
887 detector.Attach(first);
888 detector.Attach(second);
889 detector.DetectedSignal().Connect(&application, functor);
891 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
892 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
894 // Start pan within second actor's area
896 TestStartPan(application, Vector2(110.0f, 20.0f), Vector2(126.0f, 20.0f), time);
898 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
899 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
901 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
902 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
904 // Pan moves into first actor's area - second actor should receive the pan
907 TestMovePan(application, Vector2(126.0f, 20.0f), time);
908 time += TestGetFrameInterval();
910 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
911 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
913 // Detach the second actor during the pan, we should not receive the next event
914 detector.Detach(second);
916 // Gesture ends within actor's area
919 TestMovePan(application, Vector2(26.0f, 20.0f), time);
920 TestEndPan(application, Vector2(10.0f, 4.0f), time);
922 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
927 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
929 TestApplication application;
931 Actor actor = Actor::New();
932 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
933 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
934 application.GetScene().Add(actor);
937 application.SendNotification();
938 application.Render();
941 GestureReceivedFunctor functor(data);
943 PanGestureDetector detector = PanGestureDetector::New();
944 detector.Attach(actor);
945 detector.DetectedSignal().Connect(&application, functor);
947 // Start pan in actor's area
949 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
951 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
953 // Pan continues within actor's area
956 TestMovePan(application, Vector2(26.0f, 4.0f), time);
957 time += TestGetFrameInterval();
959 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
961 // Actor become invisible - actor should not receive the next pan
962 actor.SetProperty(Actor::Property::VISIBLE, false);
965 application.SendNotification();
966 application.Render();
968 // Gesture ends within actor's area
971 TestEndPan(application, Vector2(10.0f, 4.0f), time);
973 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
977 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
979 TestApplication application;
981 Actor actor = Actor::New();
982 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
983 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
984 application.GetScene().Add(actor);
986 Actor actor2 = Actor::New();
987 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
988 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
989 application.GetScene().Add(actor2);
992 application.SendNotification();
993 application.Render();
995 // Attach actor to one detector
996 SignalData firstData;
997 GestureReceivedFunctor firstFunctor(firstData);
998 PanGestureDetector firstDetector = PanGestureDetector::New();
999 firstDetector.Attach(actor);
1000 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1002 // Attach actor to another detector
1003 SignalData secondData;
1004 GestureReceivedFunctor secondFunctor(secondData);
1005 PanGestureDetector secondDetector = PanGestureDetector::New();
1006 secondDetector.Attach(actor);
1007 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1009 // Add second actor to second detector, when we remove the actor, this will make sure that this
1010 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1011 // functor should still not be called (which is what we're also testing).
1012 secondDetector.Attach(actor2);
1014 // Pan in actor's area - both detector's functors should be called
1015 uint32_t time = 100;
1016 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1018 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1019 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1021 // Pan continues in actor's area - both detector's functors should be called
1025 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1026 time += TestGetFrameInterval();
1028 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1029 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1031 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1032 firstDetector.Detach(actor);
1036 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1038 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1039 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1041 // New pan on actor, only secondDetector has actor attached
1045 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1047 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1048 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1050 // Detach actor from secondDetector
1051 secondDetector.Detach(actor);
1055 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1057 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1058 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1063 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1065 TestApplication application;
1067 Actor actor1 = Actor::New();
1068 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1069 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1070 application.GetScene().Add(actor1);
1072 GestureReceivedFunctor functor1(data1);
1073 PanGestureDetector detector1 = PanGestureDetector::New();
1074 detector1.Attach(actor1);
1075 detector1.DetectedSignal().Connect(&application, functor1);
1077 Actor actor2 = Actor::New();
1078 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1079 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
1080 actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
1081 application.GetScene().Add(actor2);
1083 GestureReceivedFunctor functor2(data2);
1084 PanGestureDetector detector2 = PanGestureDetector::New();
1085 detector2.Attach(actor2);
1086 detector2.DetectedSignal().Connect(&application, functor2);
1088 // Render and notify
1089 application.SendNotification();
1090 application.Render();
1092 // Start pan in actor1's area, only data1 should be set
1093 uint32_t time = 100;
1094 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1096 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1097 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1101 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1103 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1105 TestApplication application;
1107 Actor actor = Actor::New();
1108 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1109 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1110 application.GetScene().Add(actor);
1112 // Render and notify
1113 application.SendNotification();
1114 application.Render();
1116 // Gesture possible in actor's area (using long-press)
1117 uint32_t time = 100;
1118 TestStartLongPress(application, 10.0f, 20.0f, time);
1119 time += TestGetFrameInterval();
1121 // Attach actor to detector
1123 GestureReceivedFunctor functor(data);
1124 PanGestureDetector detector = PanGestureDetector::New();
1125 detector.DetectedSignal().Connect(&application, functor);
1126 detector.Attach(actor);
1128 // Start a pan, initially it'll only be possible, we shouldn't receive it
1129 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1130 time += TestGetFrameInterval();
1131 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1133 // Now the pan truly starts, we should receive a signal
1134 TestMovePan(application, Vector2(26.0f, 20.0f), time);
1135 time += TestGetFrameInterval();
1136 TestMovePan(application, Vector2(32.0f, 32.0f), time);
1137 time += TestGetFrameInterval();
1138 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1140 // Finish the pan, we should still receive a signal
1142 TestEndPan(application, Vector2(32.0f, 32.0f), time);
1143 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1148 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1150 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1151 // pan actor was there before (parent)
1153 TestApplication application;
1155 Actor parent = Actor::New();
1156 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1157 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1158 application.GetScene().Add(parent);
1160 Actor child = Actor::New();
1161 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1162 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1163 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1166 // Create detector for parent and attach
1167 SignalData parentData;
1168 GestureReceivedFunctor parentFunctor(parentData);
1169 PanGestureDetector parentDetector = PanGestureDetector::New();
1170 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1171 parentDetector.Attach(parent);
1173 // Create detector for child but do not attach
1174 SignalData childData;
1175 GestureReceivedFunctor childFunctor(childData);
1176 PanGestureDetector childDetector = PanGestureDetector::New();
1177 childDetector.DetectedSignal().Connect(&application, childFunctor);
1179 // Render and notify
1180 application.SendNotification();
1181 application.Render();
1183 // Do a full pan in both actors' area, only the parent's functor should be called
1184 uint32_t time = 100;
1185 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1186 DALI_TEST_EQUALS(parentData.functorCalled, true, TEST_LOCATION);
1187 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1190 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1191 DALI_TEST_EQUALS(parentData.functorCalled, true, TEST_LOCATION);
1192 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1196 // Gesture possible in both actors' area (using long-press), no functors called
1197 TestStartLongPress(application, 10.0f, 20.0f, time);
1198 time += TestGetFrameInterval();
1199 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1200 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1202 // Attach the child as well now
1203 childDetector.Attach(child);
1205 // Now the pan truly starts, we should receive a signal for the child only
1206 TestMovePan(application, Vector2(26.0f, 20.0f), time);
1207 time += TestGetFrameInterval();
1208 TestMovePan(application, Vector2(32.0f, 32.0f), time);
1209 time += TestGetFrameInterval();
1210 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1211 DALI_TEST_EQUALS(childData.functorCalled, true, TEST_LOCATION);
1215 // Finish the pan, again only the child should still receive a signal
1216 TestEndPan(application, Vector2(32.0f, 32.0f), time);
1217 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1218 DALI_TEST_EQUALS(childData.functorCalled, true, TEST_LOCATION);
1223 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1225 TestApplication application;
1227 Actor actor = Actor::New();
1228 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1229 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1230 application.GetScene().Add(actor);
1232 // Render and notify
1233 application.SendNotification();
1234 application.Render();
1236 // Attach actor to detector
1238 GestureReceivedFunctor functor(data);
1239 PanGestureDetector detector = PanGestureDetector::New();
1240 detector.Attach(actor);
1241 detector.DetectedSignal().Connect(&application, functor);
1243 // Gesture possible in actor's area.
1244 uint32_t time = 100;
1245 TestStartLongPress(application, 10.0f, 20.0f, time);
1246 time += TestGetFrameInterval();
1248 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1250 // Move actor somewhere else
1251 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
1253 // Render and notify
1254 application.SendNotification();
1255 application.Render();
1257 // Emit STARTED event, we should not receive the pan.
1258 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1259 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1260 time += TestGetFrameInterval();
1262 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1264 // LONG_PRESS possible in empty area.
1265 TestStartLongPress(application, 10.0f, 20.0f, time);
1266 time += TestGetFrameInterval();
1268 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1270 // Move actor in to the long press position.
1271 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1273 // Render and notify
1274 application.SendNotification();
1275 application.Render();
1277 // Emit STARTED event, we should be receiving the pan now.
1278 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1279 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1280 time += TestGetFrameInterval();
1282 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1284 // Normal pan in actor's area for completeness.
1286 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1287 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1288 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1292 int UtcDaliPanGestureActorUnstaged(void)
1294 TestApplication application;
1296 Actor actor = Actor::New();
1297 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1298 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1299 application.GetScene().Add(actor);
1301 // Render and notify
1302 application.SendNotification();
1303 application.Render();
1305 // State to remove actor in.
1306 GestureState stateToUnstage(GestureState::STARTED);
1308 // Attach actor to detector
1310 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
1311 PanGestureDetector detector = PanGestureDetector::New();
1312 detector.Attach(actor);
1313 detector.DetectedSignal().Connect(&application, functor);
1316 uint32_t time = 100;
1317 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1319 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1322 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1324 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1327 // Render and notify
1328 application.SendNotification();
1329 application.Render();
1331 // Re-add actor to stage
1332 application.GetScene().Add(actor);
1334 // Render and notify
1335 application.SendNotification();
1336 application.Render();
1338 // Change state to GestureState::CONTINUING to remove
1339 stateToUnstage = GestureState::CONTINUING;
1342 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1344 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1347 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1348 time += TestGetFrameInterval();
1350 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1354 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1356 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1359 // Render and notify
1360 application.SendNotification();
1361 application.Render();
1363 // Re-add actor to stage
1364 application.GetScene().Add(actor);
1366 // Render and notify
1367 application.SendNotification();
1368 application.Render();
1370 // Change state to GestureState::FINISHED to remove
1371 stateToUnstage = GestureState::FINISHED;
1374 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1376 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1379 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1380 time += TestGetFrameInterval();
1382 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1385 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1387 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1388 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
1392 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1394 TestApplication application;
1396 Actor actor = Actor::New();
1397 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1398 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1399 application.GetScene().Add(actor);
1401 // Create and add a second actor so that GestureDetector destruction does not come into play.
1402 Actor dummyActor(Actor::New());
1403 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1404 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
1405 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1406 application.GetScene().Add(dummyActor);
1408 // Render and notify
1409 application.SendNotification();
1410 application.Render();
1412 // State to remove actor in.
1413 GestureState stateToUnstage(GestureState::STARTED);
1415 // Attach actor to detector
1417 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
1418 PanGestureDetector detector = PanGestureDetector::New();
1419 detector.Attach(actor);
1420 detector.Attach(dummyActor);
1421 detector.DetectedSignal().Connect(&application, functor);
1423 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
1424 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1425 // position, we should still not be signalled.
1428 uint32_t time = 100;
1429 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1431 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1434 // Render and notify
1435 application.SendNotification();
1436 application.Render();
1438 // Re add to the stage, we should not be signalled
1439 application.GetScene().Add(actor);
1441 // Render and notify
1442 application.SendNotification();
1443 application.Render();
1445 // Continue signal emission
1446 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1447 time += TestGetFrameInterval();
1449 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1452 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1453 time += TestGetFrameInterval();
1455 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1458 // Here we delete an actor in started, we should not receive any subsequent signalling.
1461 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1463 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1466 // Render and notify
1467 application.SendNotification();
1468 application.Render();
1470 // Delete actor as well
1473 // Render and notify
1474 application.SendNotification();
1475 application.Render();
1477 // Continue signal emission
1478 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1479 time += TestGetFrameInterval();
1481 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1484 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1486 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1490 int UtcDaliPanGestureAngleHandling(void)
1492 TestApplication application;
1494 PanGestureDetector detector = PanGestureDetector::New();
1495 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1497 detector.AddAngle(PanGestureDetector::DIRECTION_LEFT, Radian(Math::PI * 0.25));
1498 DALI_TEST_EQUALS(detector.GetAngleCount(), 1u, TEST_LOCATION);
1500 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1502 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT)
1504 tet_result(TET_PASS);
1512 tet_printf("%s, angle not added\n", TEST_LOCATION);
1513 tet_result(TET_FAIL);
1516 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Radian(Math::PI * 0.25));
1517 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1519 // Remove something not in the container.
1520 detector.RemoveAngle(PanGestureDetector::DIRECTION_UP);
1521 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1523 detector.RemoveAngle(PanGestureDetector::DIRECTION_RIGHT);
1524 DALI_TEST_EQUALS(detector.GetAngleCount(), 1u, TEST_LOCATION);
1525 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1527 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT)
1529 tet_printf("%s, angle not removed\n", TEST_LOCATION);
1530 tet_result(TET_FAIL);
1535 detector.ClearAngles();
1536 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1540 int UtcDaliPanGestureGetAngle(void)
1542 TestApplication application;
1544 PanGestureDetector detector = PanGestureDetector::New();
1545 DALI_TEST_EQUALS(detector.GetAngleCount(), 0, TEST_LOCATION);
1547 detector.AddAngle(PanGestureDetector::DIRECTION_LEFT);
1548 DALI_TEST_EQUALS(detector.GetAngleCount(), 1, TEST_LOCATION);
1550 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT);
1551 DALI_TEST_EQUALS(detector.GetAngleCount(), 2, TEST_LOCATION);
1553 detector.AddAngle(PanGestureDetector::DIRECTION_UP);
1554 DALI_TEST_EQUALS(detector.GetAngleCount(), 3, TEST_LOCATION);
1556 detector.AddAngle(PanGestureDetector::DIRECTION_DOWN);
1557 DALI_TEST_EQUALS(detector.GetAngleCount(), 4, TEST_LOCATION);
1559 DALI_TEST_EQUALS(detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION);
1560 DALI_TEST_EQUALS(detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION);
1561 DALI_TEST_EQUALS(detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION);
1562 DALI_TEST_EQUALS(detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION);
1567 inline float RadiansToDegrees(float radian)
1569 return radian * 180.0f / Math::PI;
1572 int UtcDaliPanGestureAngleOutOfRange(void)
1574 TestApplication application;
1576 PanGestureDetector detector = PanGestureDetector::New();
1577 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1583 detector.AddAngle(Degree(180.0f));
1584 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-180.0f)), 0.000001, TEST_LOCATION);
1585 detector.ClearAngles();
1587 detector.AddAngle(Degree(190.0f));
1588 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-170.0f)), 0.000001, TEST_LOCATION);
1589 detector.ClearAngles();
1591 detector.AddAngle(Degree(-190.0f));
1592 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(170.0f)), 0.000001, TEST_LOCATION);
1593 detector.ClearAngles();
1595 detector.AddAngle(Degree(350.0f));
1596 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-10.0f)), 0.000001, TEST_LOCATION);
1597 detector.ClearAngles();
1599 detector.AddAngle(Degree(-350.0f));
1600 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1601 detector.ClearAngles();
1603 detector.AddAngle(Degree(370.0f));
1604 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1605 detector.ClearAngles();
1607 detector.AddAngle(Degree(-370.0f));
1608 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-10.0f)), 0.000001, TEST_LOCATION);
1609 detector.ClearAngles();
1615 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(0.0f));
1616 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(0.0f)), 0.000001, TEST_LOCATION);
1617 detector.ClearAngles();
1619 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(-10.0f));
1620 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1621 detector.ClearAngles();
1623 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(-181.0f));
1624 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(180.0f)), 0.000001, TEST_LOCATION);
1625 detector.ClearAngles();
1627 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(181.0f));
1628 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(180.0f)), 0.000001, TEST_LOCATION);
1629 detector.ClearAngles();
1633 int UtcDaliPanGestureAngleProcessing(void)
1635 TestApplication application;
1637 Actor parent = Actor::New();
1638 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1639 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1640 application.GetScene().Add(parent);
1642 Actor child = Actor::New();
1643 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1644 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1647 // Render and notify
1648 application.SendNotification();
1649 application.Render();
1651 // Parent detector only requires up pans
1652 PanGestureDetector parentDetector = PanGestureDetector::New();
1653 parentDetector.Attach(parent);
1654 parentDetector.AddAngle(PanGestureDetector::DIRECTION_UP, Degree(30.0f));
1655 SignalData parentData;
1656 GestureReceivedFunctor parentFunctor(parentData);
1657 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1659 // Child detector only requires right pans
1660 PanGestureDetector childDetector = PanGestureDetector::New();
1661 childDetector.Attach(child);
1662 childDetector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(30.0f));
1663 SignalData childData;
1664 GestureReceivedFunctor childFunctor(childData);
1665 childDetector.DetectedSignal().Connect(&application, childFunctor);
1667 // Generate an Up pan gesture, only parent should receive it.
1668 uint32_t time = 100;
1669 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 4.0f), time);
1671 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1672 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1674 TestEndPan(application, Vector2(20.0f, 4.0f), time);
1675 time += TestGetFrameInterval();
1679 // Generate a Right pan gesture, only child should receive it.
1680 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(36.0f, 20.0f), time);
1682 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1683 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1685 TestEndPan(application, Vector2(4.0f, 20.0f), time);
1686 time += TestGetFrameInterval();
1690 // Generate a Down pan gesture, no one should receive it.
1691 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 36.0f), time);
1693 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1694 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1696 TestEndPan(application, Vector2(20.0f, 36.0f), time);
1697 time += TestGetFrameInterval();
1701 // Generate a Left pan gesture, no one should receive it.
1702 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 20.0f), time);
1704 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1705 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1707 TestEndPan(application, Vector2(4.0f, 20.0f), time);
1713 int UtcDaliPanGestureDirectionHandling(void)
1715 TestApplication application;
1717 PanGestureDetector detector = PanGestureDetector::New();
1718 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1720 detector.AddDirection(PanGestureDetector::DIRECTION_LEFT, Radian(Math::PI * 0.25));
1721 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1723 for(size_t i = 0; detector.GetAngleCount(); i++)
1725 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT)
1727 tet_result(TET_PASS);
1735 tet_printf("%s, angle not added\n", TEST_LOCATION);
1736 tet_result(TET_FAIL);
1740 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1742 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT)
1744 tet_result(TET_PASS);
1752 tet_printf("%s, angle not added\n", TEST_LOCATION);
1753 tet_result(TET_FAIL);
1756 // Remove something not in the container.
1757 detector.RemoveDirection(PanGestureDetector::DIRECTION_UP);
1758 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1760 detector.RemoveDirection(PanGestureDetector::DIRECTION_RIGHT);
1761 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1765 int UtcDaliPanGestureDirectionProcessing(void)
1767 TestApplication application;
1769 Actor parent = Actor::New();
1770 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1771 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1772 application.GetScene().Add(parent);
1774 Actor child = Actor::New();
1775 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1776 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1779 // Render and notify
1780 application.SendNotification();
1781 application.Render();
1783 // Parent detector only requires vertical panning
1784 PanGestureDetector parentDetector = PanGestureDetector::New();
1785 parentDetector.Attach(parent);
1786 parentDetector.AddDirection(PanGestureDetector::DIRECTION_VERTICAL, Degree(30.0f));
1787 SignalData parentData;
1788 GestureReceivedFunctor parentFunctor(parentData);
1789 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1791 // Child detector only requires horizontal panning
1792 PanGestureDetector childDetector = PanGestureDetector::New();
1793 childDetector.Attach(child);
1794 childDetector.AddDirection(PanGestureDetector::DIRECTION_HORIZONTAL, Degree(30.0f));
1795 SignalData childData;
1796 GestureReceivedFunctor childFunctor(childData);
1797 childDetector.DetectedSignal().Connect(&application, childFunctor);
1799 // Generate an Up pan gesture, only parent should receive it.
1800 uint32_t time = 100;
1801 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 4.0f), time);
1803 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1804 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1806 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1807 time += TestGetFrameInterval();
1811 // Generate a Right pan gesture, only child should receive it.
1812 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(36.0f, 20.0f), time);
1814 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1815 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1817 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1818 time += TestGetFrameInterval();
1822 // Generate a Down pan gesture, only parent should receive it.
1823 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 36.0f), time);
1825 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1826 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1828 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1829 time += TestGetFrameInterval();
1833 // Generate a Left pan gesture, only child should receive it.
1834 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 20.0f), time);
1836 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1837 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1839 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1840 time += TestGetFrameInterval();
1844 // Generate a pan at -45 degrees, no one should receive it.
1845 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(9.0f, 31.0f), time);
1847 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1848 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1850 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1851 time += TestGetFrameInterval();
1855 // Generate a pan at 45 degrees, no one should receive it.
1856 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(31.0f, 31.0f), time);
1858 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1859 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1861 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1862 time += TestGetFrameInterval();
1866 // Generate a pan at -135 degrees, no one should receive it.
1867 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 4.0f), time);
1869 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1870 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1872 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1878 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1880 TestApplication application;
1881 Integration::SetPanGesturePredictionMode(0);
1882 Integration::SetPanGestureSmoothingMode(0);
1884 Actor actor = Actor::New();
1885 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1886 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1887 application.GetScene().Add(actor);
1889 // Add a pan detector
1890 PanGestureDetector detector = PanGestureDetector::New();
1891 detector.Attach(actor);
1893 GestureReceivedFunctor functor(data);
1894 detector.DetectedSignal().Connect(&application, functor);
1896 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
1898 ConstraintData constraintData;
1899 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
1900 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
1901 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
1902 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
1903 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
1904 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
1905 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
1906 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
1909 // Render and notify
1910 application.SendNotification();
1911 application.Render();
1913 Vector2 startPosition(1.0f, 1.0f);
1914 Vector2 position(-14.0f, 1.0f);
1915 Vector2 direction(Vector2::XAXIS * -5.0f);
1916 uint32_t time = 100;
1918 TestStartPan(application, startPosition, position, time);
1920 for(int i = 0; i < 47; i++)
1922 position += direction;
1923 TestMovePan(application, position, time);
1924 time += TestGetFrameInterval();
1925 application.SendNotification();
1926 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1929 TestEndPan(application, position, time);
1930 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1932 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1933 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
1934 DALI_TEST_EQUALS(constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION);
1935 DALI_TEST_EQUALS(constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION);
1937 constraintData.Reset();
1941 int UtcDaliPanGestureNoPredictionSmoothing(void)
1943 TestApplication application;
1944 Integration::SetPanGesturePredictionMode(0);
1945 Integration::SetPanGestureSmoothingMode(1);
1947 Actor actor = Actor::New();
1948 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1949 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1950 application.GetScene().Add(actor);
1952 // Add a pan detector
1953 PanGestureDetector detector = PanGestureDetector::New();
1954 detector.Attach(actor);
1956 GestureReceivedFunctor functor(data);
1957 detector.DetectedSignal().Connect(&application, functor);
1959 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
1961 ConstraintData constraintData;
1962 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
1963 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
1964 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
1965 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
1966 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
1967 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
1968 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
1969 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
1972 // Render and notify
1973 application.SendNotification();
1974 application.Render();
1976 Vector2 startPosition(1.0f, 1.0f);
1977 Vector2 position(-14.0f, 1.0f);
1978 Vector2 direction(Vector2::XAXIS * -5.0f);
1979 uint32_t time = 100;
1981 TestStartPan(application, startPosition, position, time);
1983 for(int i = 0; i < 47; i++)
1985 position += direction;
1986 TestMovePan(application, position, time);
1987 time += TestGetFrameInterval();
1988 application.SendNotification();
1989 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1992 TestEndPan(application, position, time);
1993 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1995 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1996 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
1997 // Take into account resampling done when prediction is off.
1998 DALI_TEST_EQUALS(constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION);
1999 DALI_TEST_EQUALS(constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION);
2001 constraintData.Reset();
2005 int UtcDaliPanGesturePredictionNoSmoothing(void)
2007 TestApplication application;
2008 Integration::SetPanGesturePredictionMode(1);
2009 Integration::SetPanGestureSmoothingMode(0);
2011 Actor actor = Actor::New();
2012 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2013 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2014 application.GetScene().Add(actor);
2016 // Add a pan detector
2017 PanGestureDetector detector = PanGestureDetector::New();
2018 detector.Attach(actor);
2020 GestureReceivedFunctor functor(data);
2021 detector.DetectedSignal().Connect(&application, functor);
2023 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2025 ConstraintData constraintData;
2026 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2027 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2028 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2029 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2030 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2031 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2032 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2033 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2036 // Render and notify
2037 application.SendNotification();
2038 application.Render();
2040 Vector2 startPosition(1.0f, 1.0f);
2041 Vector2 position(-1.0f, 1.0f);
2042 Vector2 direction(Vector2::XAXIS * -1.0f);
2043 uint32_t time = 100;
2045 TestStartPan(application, startPosition, position, time);
2047 for(int i = 0; i < 47; i++)
2049 position += direction;
2050 TestMovePan(application, position, time);
2051 time += TestGetFrameInterval();
2052 application.SendNotification();
2053 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2056 TestEndPan(application, position, time);
2057 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2059 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2060 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2061 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2062 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2064 constraintData.Reset();
2068 int UtcDaliPanGesturePredictionSmoothing01(void)
2070 TestApplication application;
2071 Integration::SetPanGesturePredictionMode(1);
2072 Integration::SetPanGestureSmoothingMode(1);
2074 Actor actor = Actor::New();
2075 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2076 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2077 application.GetScene().Add(actor);
2079 // Add a pan detector
2080 PanGestureDetector detector = PanGestureDetector::New();
2081 detector.Attach(actor);
2083 GestureReceivedFunctor functor(data);
2084 detector.DetectedSignal().Connect(&application, functor);
2086 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2088 ConstraintData constraintData;
2089 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2090 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2091 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2092 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2093 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2094 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2095 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2096 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2099 // Render and notify
2100 application.SendNotification();
2101 application.Render();
2103 Vector2 startPosition(1.0f, 1.0f);
2104 Vector2 position(-1.0f, 1.0f);
2105 Vector2 direction(Vector2::XAXIS * -1.0f);
2106 uint32_t time = 100;
2108 TestStartPan(application, startPosition, position, time);
2110 for(int i = 0; i < 47; i++)
2112 position += direction;
2113 TestMovePan(application, position, time);
2114 time += TestGetFrameInterval();
2115 application.SendNotification();
2116 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2119 TestEndPan(application, position, time);
2120 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2122 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2123 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2124 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2125 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2127 constraintData.Reset();
2131 int UtcDaliPanGesturePredictionSmoothing02(void)
2133 TestApplication application;
2134 Integration::SetPanGesturePredictionMode(1);
2135 Integration::SetPanGestureMaximumPredictionAmount(1);
2136 Integration::SetPanGesturePredictionAmountAdjustment(2);
2137 Integration::SetPanGestureSmoothingMode(1);
2138 Integration::SetPanGestureSmoothingAmount(0.25f);
2140 Actor actor = Actor::New();
2141 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2142 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2143 application.GetScene().Add(actor);
2145 // Add a pan detector
2146 PanGestureDetector detector = PanGestureDetector::New();
2147 detector.Attach(actor);
2149 GestureReceivedFunctor functor(data);
2150 detector.DetectedSignal().Connect(&application, functor);
2152 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2154 ConstraintData constraintData;
2155 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2156 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2157 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2158 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2159 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2160 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2161 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2162 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2165 // Render and notify
2166 application.SendNotification();
2167 application.Render();
2169 Vector2 startPosition(2.0f, 2.0f);
2170 Vector2 position(4.0f, 2.0f);
2171 Vector2 directionX(Vector2::XAXIS);
2172 Vector2 directionY(Vector2::YAXIS);
2173 uint32_t time = 100;
2175 TestStartPan(application, startPosition, position, time);
2177 for(int i = 0; i < 7; i++)
2179 position += directionX;
2180 TestMovePan(application, position, time);
2181 time += TestGetFrameInterval();
2182 application.SendNotification();
2183 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2186 position += directionX * 10.0f;
2187 TestMovePan(application, position, time);
2188 time += TestGetFrameInterval();
2189 application.SendNotification();
2190 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2192 for(int i = 0; i < 2; i++)
2194 position += (directionX * -1.0f);
2195 TestMovePan(application, position, time);
2196 time += TestGetFrameInterval();
2197 application.SendNotification();
2198 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2201 for(int i = 0; i < 10; i++)
2203 position += directionX;
2204 TestMovePan(application, position, time);
2205 time += TestGetFrameInterval();
2206 application.SendNotification();
2207 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2210 for(int i = 0; i < 10; i++)
2212 position += directionY;
2213 TestMovePan(application, position, time);
2214 time += TestGetFrameInterval();
2215 application.SendNotification();
2216 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2219 TestEndPan(application, position, time);
2220 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2222 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2223 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2224 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2225 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2227 constraintData.Reset();
2231 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2233 TestApplication application;
2235 Integration::SetPanGesturePredictionMode(2);
2236 Integration::SetPanGesturePredictionAmount(57);
2237 Integration::SetPanGestureSmoothingMode(2);
2238 Integration::SetPanGestureUseActualTimes(false);
2239 Integration::SetPanGestureInterpolationTimeRange(10);
2240 Integration::SetPanGestureScalarOnlyPredictionEnabled(false);
2241 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2242 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2243 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2244 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2245 Integration::SetPanGestureMultitapSmoothingRange(34);
2247 Actor actor = Actor::New();
2248 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2249 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2250 application.GetScene().Add(actor);
2252 // Add a pan detector
2253 PanGestureDetector detector = PanGestureDetector::New();
2254 detector.Attach(actor);
2256 GestureReceivedFunctor functor(data);
2257 detector.DetectedSignal().Connect(&application, functor);
2259 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2261 ConstraintData constraintData;
2262 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2263 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2264 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2265 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2266 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2267 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2268 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2269 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2272 // Render and notify
2273 application.SendNotification();
2274 application.Render();
2276 Vector2 startPosition(2.0f, 2.0f);
2277 Vector2 position(-1.0f, 2.0f);
2278 Vector2 direction(Vector2::XAXIS * -1.0f);
2279 uint32_t time = 100;
2281 TestStartPan(application, startPosition, position, time);
2283 for(int i = 0; i < 27; i++)
2285 position += direction;
2286 TestMovePan(application, position, time);
2287 time += TestGetFrameInterval();
2288 application.SendNotification();
2289 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2292 TestEndPan(application, position, time);
2293 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2295 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2296 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2297 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2298 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2300 constraintData.Reset();
2304 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2306 TestApplication application;
2308 Integration::SetPanGesturePredictionMode(2);
2309 Integration::SetPanGestureSmoothingMode(2);
2310 Integration::SetPanGestureUseActualTimes(true);
2311 Integration::SetPanGestureInterpolationTimeRange(10);
2312 Integration::SetPanGestureScalarOnlyPredictionEnabled(true);
2313 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2314 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2315 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2316 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2317 Integration::SetPanGestureMultitapSmoothingRange(34);
2319 Integration::EnableProfiling(Integration::PROFILING_TYPE_PAN_GESTURE);
2321 Actor actor = Actor::New();
2322 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2323 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2324 application.GetScene().Add(actor);
2326 // Add a pan detector
2327 PanGestureDetector detector = PanGestureDetector::New();
2328 detector.Attach(actor);
2330 GestureReceivedFunctor functor(data);
2331 detector.DetectedSignal().Connect(&application, functor);
2333 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2335 ConstraintData constraintData;
2336 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2337 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2338 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2339 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2340 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2341 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2342 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2343 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2346 // Render and notify
2347 application.SendNotification();
2348 application.Render();
2350 Vector2 startPosition(2.0f, 2.0f);
2351 Vector2 position(17.0f, 2.0f);
2352 Vector2 direction(Vector2::XAXIS * -1.0f);
2353 uint32_t time = 100;
2355 TestStartPan(application, startPosition, position, time);
2357 for(int i = 0; i < 10; i++)
2359 position += direction;
2360 TestMovePan(application, position, time);
2361 time += TestGetFrameInterval();
2363 position += direction;
2364 TestMovePan(application, position, time);
2365 time += TestGetFrameInterval();
2367 position += direction;
2368 TestMovePan(application, position, time);
2369 time += TestGetFrameInterval();
2371 application.SendNotification();
2372 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2375 for(int i = 0; i < 10; i++)
2377 application.SendNotification();
2378 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2381 for(int i = 0; i < 10; i++)
2383 position += direction;
2384 TestMovePan(application, position, time);
2385 application.SendNotification();
2386 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2389 for(int i = 0; i < 10; i++)
2391 position += direction;
2392 TestMovePan(application, position, time);
2393 time += TestGetFrameInterval();
2394 application.SendNotification();
2395 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2398 TestEndPan(application, position, time);
2399 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2401 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2402 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2403 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2404 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2406 constraintData.Reset();
2410 int UtcDaliPanGesturePrediction2Smoothing(void)
2412 TestApplication application;
2414 Integration::SetPanGesturePredictionMode(2);
2415 Integration::SetPanGesturePredictionAmount(57);
2416 Integration::SetPanGestureSmoothingMode(1);
2417 Integration::SetPanGestureUseActualTimes(false);
2418 Integration::SetPanGestureInterpolationTimeRange(10);
2419 Integration::SetPanGestureScalarOnlyPredictionEnabled(true);
2420 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2421 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2422 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2423 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2424 Integration::SetPanGestureMultitapSmoothingRange(34);
2426 Actor actor = Actor::New();
2427 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2428 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2429 application.GetScene().Add(actor);
2431 // Add a pan detector
2432 PanGestureDetector detector = PanGestureDetector::New();
2433 detector.Attach(actor);
2435 GestureReceivedFunctor functor(data);
2436 detector.DetectedSignal().Connect(&application, functor);
2438 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2440 ConstraintData constraintData;
2441 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2442 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2443 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2444 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2445 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2446 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2447 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2448 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2451 // Render and notify
2452 application.SendNotification();
2453 application.Render();
2455 Vector2 startPosition(2.0f, 2.0f);
2456 Vector2 position(17.0f, 2.0f);
2457 Vector2 direction(Vector2::XAXIS * -1.0f);
2458 uint32_t time = 100;
2460 TestStartPan(application, startPosition, position, time);
2462 for(int i = 0; i < 10; i++)
2464 position += direction;
2465 TestMovePan(application, position, time);
2466 time += TestGetFrameInterval();
2467 application.SendNotification();
2468 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2471 position += direction;
2472 TestMovePan(application, position, time);
2473 time += TestGetFrameInterval();
2475 position += direction;
2476 TestMovePan(application, position, time);
2477 time += TestGetFrameInterval();
2479 position += direction;
2480 TestMovePan(application, position, time);
2481 time += TestGetFrameInterval();
2483 application.SendNotification();
2484 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2486 for(int i = 0; i < 5; i++)
2488 application.SendNotification();
2489 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2492 for(int i = 0; i < 10; i++)
2494 position += direction;
2495 TestMovePan(application, position, time);
2496 time += TestGetFrameInterval();
2497 application.SendNotification();
2498 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2501 TestEndPan(application, position, time);
2502 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2504 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2505 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2506 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2507 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2509 constraintData.Reset();
2513 int UtcDaliPanGestureSetProperties(void)
2515 TestApplication application;
2516 TestRenderController& renderController(application.GetRenderController());
2517 Integration::SetPanGesturePredictionMode(0);
2518 Integration::SetPanGestureSmoothingMode(0);
2520 Actor actor = Actor::New();
2521 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2522 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2523 application.GetScene().Add(actor);
2525 // Add a pan detector
2526 PanGestureDetector detector = PanGestureDetector::New();
2527 detector.Attach(actor);
2529 GestureReceivedFunctor functor(data);
2530 detector.DetectedSignal().Connect(&application, functor);
2532 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2533 Property::Index animatableGestureProperty = detector.RegisterProperty("Dummy Property", Vector3::ZERO); // For code coverage
2535 ConstraintData constraintData;
2536 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2537 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2538 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2539 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2540 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2541 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2542 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2543 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2544 constraint.AddSource(Source(detector, animatableGestureProperty));
2547 // Render and notify
2548 application.SendNotification();
2549 application.Render();
2551 renderController.Initialize();
2552 DALI_TEST_EQUALS(renderController.WasCalled(TestRenderController::RequestUpdateFunc), false, TEST_LOCATION);
2554 Vector2 screenPosition(20.0f, 20.0f);
2555 Vector2 screenDisplacement(1.0f, 1.0f);
2556 Vector2 screenVelocity(1.3f, 4.0f);
2557 Vector2 localPosition(21.0f, 21.0f);
2558 Vector2 localDisplacement(0.5f, 0.5f);
2559 Vector2 localVelocity(1.5f, 2.5f);
2561 PanGestureDetector::SetPanGestureProperties(GeneratePan(1u, GestureState::STARTED, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity));
2562 DALI_TEST_EQUALS(renderController.WasCalled(TestRenderController::RequestUpdateFunc), true, TEST_LOCATION);
2564 // Render and notify
2565 application.SendNotification();
2566 application.Render();
2568 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2569 DALI_TEST_EQUALS(constraintData.screenPosition, screenPosition, TEST_LOCATION);
2570 DALI_TEST_EQUALS(constraintData.localPosition, localPosition, TEST_LOCATION);
2571 DALI_TEST_EQUALS(constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION);
2572 DALI_TEST_EQUALS(constraintData.localDisplacement, localDisplacement, TEST_LOCATION);
2573 DALI_TEST_EQUALS(constraintData.screenVelocity, screenVelocity, TEST_LOCATION);
2574 DALI_TEST_EQUALS(constraintData.localVelocity, localVelocity, TEST_LOCATION);
2575 constraintData.Reset();
2579 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2581 TestApplication application;
2582 Integration::SetPanGesturePredictionMode(0);
2584 Actor actor = Actor::New();
2585 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2586 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2587 application.GetScene().Add(actor);
2589 // Add a pan detector
2590 PanGestureDetector detector = PanGestureDetector::New();
2591 detector.Attach(actor);
2593 GestureReceivedFunctor functor(data);
2594 detector.DetectedSignal().Connect(&application, functor);
2596 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2598 ConstraintData constraintData;
2599 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2600 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2601 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2602 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2603 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2604 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2605 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2606 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2609 // Render and notify
2610 application.SendNotification();
2611 application.Render();
2613 Vector2 currentPosition(20.0f, 4.0f);
2614 uint32_t time = 100;
2615 TestStartPan(application, Vector2(20.0f, 20.0f), currentPosition, time);
2616 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2618 Vector2 screenPosition(100.0f, 20.0f);
2619 Vector2 localPosition(110.0f, 110.0f);
2621 PanGestureDetector::SetPanGestureProperties(GeneratePan(1u, GestureState::STARTED, screenPosition, localPosition));
2623 // Render and notify
2624 application.SendNotification();
2625 application.Render();
2627 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2628 DALI_TEST_EQUALS(constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION);
2629 DALI_TEST_EQUALS(constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION);
2630 constraintData.Reset();
2634 int UtcDaliPanGesturePropertyIndices(void)
2636 TestApplication application;
2637 PanGestureDetector detector = PanGestureDetector::New();
2639 Property::IndexContainer indices;
2640 detector.GetPropertyIndices(indices);
2641 DALI_TEST_CHECK(indices.Size());
2642 DALI_TEST_EQUALS(indices.Size(), detector.GetPropertyCount(), TEST_LOCATION);
2648 struct PropertyStringIndex
2650 const char* const name;
2651 const Property::Index index;
2652 const Property::Type type;
2653 const Property::Value value;
2656 const PropertyStringIndex PROPERTY_TABLE[] =
2658 {"screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO},
2659 {"screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO},
2660 {"screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO},
2661 {"localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO},
2662 {"localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO},
2663 {"localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO},
2664 {"panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false},
2666 const unsigned int PROPERTY_TABLE_COUNT = sizeof(PROPERTY_TABLE) / sizeof(PROPERTY_TABLE[0]);
2667 } // unnamed namespace
2669 int UtcDaliPanGestureProperties(void)
2671 TestApplication application;
2672 PanGestureDetector detector = PanGestureDetector::New();
2674 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2676 DALI_TEST_EQUALS(detector.GetPropertyName(PROPERTY_TABLE[i].index), std::string(PROPERTY_TABLE[i].name), TEST_LOCATION);
2677 DALI_TEST_EQUALS(detector.GetPropertyIndex(PROPERTY_TABLE[i].name), PROPERTY_TABLE[i].index, TEST_LOCATION);
2678 DALI_TEST_EQUALS(detector.GetPropertyType(PROPERTY_TABLE[i].index), PROPERTY_TABLE[i].type, TEST_LOCATION);
2679 DALI_TEST_EQUALS(detector.IsPropertyWritable(PROPERTY_TABLE[i].index), false, TEST_LOCATION);
2680 DALI_TEST_EQUALS(detector.IsPropertyAnimatable(PROPERTY_TABLE[i].index), false, TEST_LOCATION);
2681 DALI_TEST_EQUALS(detector.IsPropertyAConstraintInput(PROPERTY_TABLE[i].index), true, TEST_LOCATION);
2682 detector.SetProperty(PROPERTY_TABLE[i].index, Property::Value()); // Just for Coverage
2688 int UtcDaliPanGestureGetProperty(void)
2690 TestApplication application;
2691 PanGestureDetector detector = PanGestureDetector::New();
2693 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2695 if(PROPERTY_TABLE[i].type == Property::VECTOR2)
2697 bool value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<bool>();
2698 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<bool>(), value, TEST_LOCATION);
2700 else if(PROPERTY_TABLE[i].type == Property::BOOLEAN)
2702 Vector2 value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<Vector2>();
2703 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<Vector2>(), value, TEST_LOCATION);
2710 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2712 TestApplication application;
2714 Actor actor = Actor::New();
2715 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2716 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2717 application.GetScene().Add(actor);
2719 // Add a pan detector
2720 PanGestureDetector detector = PanGestureDetector::New();
2721 detector.Attach(actor);
2723 // Render and notify
2724 application.SendNotification();
2725 application.Render();
2727 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2729 detector.SetProperty(PROPERTY_TABLE[i].index, Property::Value()); // Just for Coverage
2731 if(PROPERTY_TABLE[i].type == Property::VECTOR2)
2733 bool value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<bool>();
2734 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<bool>(), value, TEST_LOCATION);
2736 else if(PROPERTY_TABLE[i].type == Property::BOOLEAN)
2738 Vector2 value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<Vector2>();
2739 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<Vector2>(), value, TEST_LOCATION);
2746 int UtcDaliPanGestureLayerConsumesTouch(void)
2748 TestApplication application;
2750 Actor actor = Actor::New();
2751 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2752 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2753 application.GetScene().Add(actor);
2755 // Add a pan detector
2756 PanGestureDetector detector = PanGestureDetector::New();
2757 detector.Attach(actor);
2759 GestureReceivedFunctor functor(data);
2760 detector.DetectedSignal().Connect(&application, functor);
2762 // Add a layer to overlap the actor
2763 Layer layer = Layer::New();
2764 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2765 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2766 application.GetScene().Add(layer);
2769 // Render and notify
2770 application.SendNotification();
2771 application.Render();
2773 // Emit signals, should receive
2774 uint32_t time = 100;
2775 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2776 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2777 time += TestGetFrameInterval();
2779 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2782 // Set layer to consume all touch
2783 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
2785 // Render and notify
2786 application.SendNotification();
2787 application.Render();
2789 // Emit the same signals again, should not receive
2790 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2791 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2793 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2799 int UtcDaliPanGestureNoTimeDiff(void)
2801 TestApplication application;
2803 Actor actor = Actor::New();
2804 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2805 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2806 application.GetScene().Add(actor);
2808 // Add a pan detector
2809 PanGestureDetector detector = PanGestureDetector::New();
2810 detector.Attach(actor);
2812 GestureReceivedFunctor functor(data);
2813 detector.DetectedSignal().Connect(&application, functor);
2815 // Render and notify
2816 application.SendNotification();
2817 application.Render();
2819 // As normal helper function adds intervals between presses we must generate the sequence
2820 // using other helper functions
2821 TestStartLongPress(application, 10.0f, 20.0f, 100); // Used to send a down press event
2822 TestMovePan(application, Vector2(26.0f, 20.0f), 100);
2823 TestMovePan(application, Vector2(26.0f, 20.0f), 100); // 2 motions required to trigger
2824 TestEndPan(application, Vector2(26.0f, 20.0f), 100);
2826 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2827 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetVelocity().x));
2828 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetVelocity().y));
2829 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetScreenVelocity().x));
2830 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetScreenVelocity().y));
2838 int UtcDaliPanGestureDisableDetectionDuringPanN(void)
2840 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
2842 TestApplication application;
2844 Actor actor = Actor::New();
2845 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2846 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2847 application.GetScene().Add(actor);
2849 // Add a pan detector
2850 PanGestureDetector detector = PanGestureDetector::New();
2851 bool functorCalled = false;
2852 detector.Attach(actor);
2853 detector.DetectedSignal().Connect(
2855 [&detector, &functorCalled](Actor actor, const PanGesture& pan) {
2856 if(pan.GetState() == GestureState::FINISHED)
2858 detector.Detach(actor);
2859 functorCalled = true;
2863 // Render and notify
2864 application.SendNotification();
2865 application.Render();
2867 // Try the gesture, should not crash
2870 uint32_t time = 100;
2871 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2872 TestEndPan(application, Vector2(26.0f, 20.0f));
2874 DALI_TEST_CHECK(true); // No crash, test has passed
2875 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
2879 DALI_TEST_CHECK(false); // If we crash, the test has failed
2885 int UtcDaliPanGestureWhenGesturePropargation(void)
2887 TestApplication application;
2889 Actor parentActor = Actor::New();
2890 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2891 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2893 Actor childActor = Actor::New();
2894 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2895 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2897 parentActor.Add(childActor);
2898 application.GetScene().Add(parentActor);
2900 // Render and notify
2901 application.SendNotification();
2902 application.Render();
2905 GestureReceivedFunctor pFunctor(pData);
2907 PanGestureDetector parentDetector = PanGestureDetector::New();
2908 parentDetector.Attach(parentActor);
2909 parentDetector.DetectedSignal().Connect(&application, pFunctor);
2912 GestureReceivedFunctor cFunctor(cData);
2914 PanGestureDetector childDetector = PanGestureDetector::New();
2915 childDetector.Attach(childActor);
2916 childDetector.DetectedSignal().Connect(&application, cFunctor);
2918 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
2919 uint32_t time = 100;
2920 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2922 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2923 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
2927 TestMovePan(application, Vector2(26.0f, 4.0f), time);
2928 time += TestGetFrameInterval();
2930 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2931 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
2935 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2937 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2938 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
2942 // If GesturePropargation is set, a gesture event is to pass over to the parent.
2943 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
2945 // So now the parent got the gesture event.
2946 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2947 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2948 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
2952 TestMovePan(application, Vector2(26.0f, 4.0f), time);
2953 time += TestGetFrameInterval();
2955 // child does not receive gestures. This is because we have passed the permission of the gesture to the parent.
2956 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
2957 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
2961 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2962 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
2963 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);