2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/devel-api/events/pan-gesture-devel.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/input-options.h>
23 #include <dali/integration-api/profiling.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/public-api/dali-core.h>
27 #include <test-touch-event-utils.h>
34 void utc_dali_pan_gesture_detector_startup(void)
36 test_return_value = TET_UNDEF;
39 void utc_dali_pan_gesture_detector_cleanup(void)
41 test_return_value = TET_PASS;
44 ///////////////////////////////////////////////////////////////////////////////
47 const int PAN_EVENT_TIME_DELTA = 8;
48 const int PAN_GESTURE_UPDATE_COUNT = 50;
50 // Stores data that is populated in the callback and will be read by the test cases
54 : functorCalled(false),
55 voidFunctorCalled(false),
62 functorCalled = false;
63 voidFunctorCalled = false;
65 receivedGesture.Reset();
71 bool voidFunctorCalled;
72 PanGesture receivedGesture;
76 // Functor that sets the data when called
77 struct GestureReceivedFunctor
79 GestureReceivedFunctor(SignalData& data)
84 void operator()(Actor actor, const PanGesture& pan)
86 signalData.functorCalled = true;
87 signalData.receivedGesture = pan;
88 signalData.pannedActor = actor;
93 signalData.voidFunctorCalled = true;
96 SignalData& signalData;
99 // Functor that removes the gestured actor from stage
100 struct UnstageActorFunctor : public GestureReceivedFunctor
102 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
103 : GestureReceivedFunctor(data),
104 stateToUnstage(stateToUnstage),
109 void operator()(Actor actor, const PanGesture& pan)
111 GestureReceivedFunctor::operator()(actor, pan);
113 if(pan.GetState() == stateToUnstage)
119 GestureState& stateToUnstage;
120 Integration::Scene scene;
123 // Data for constraints
124 struct ConstraintData
132 Vector2 screenPosition;
133 Vector2 screenDisplacement;
134 Vector2 screenVelocity;
135 Vector2 localPosition;
136 Vector2 localDisplacement;
137 Vector2 localVelocity;
143 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
149 // Constraint used with panning properties
152 PanConstraint(ConstraintData& data)
153 : constraintData(data)
157 void operator()(Vector3& current, const PropertyInputContainer& inputs)
159 constraintData.screenPosition = inputs[0]->GetVector2();
160 constraintData.screenDisplacement = inputs[1]->GetVector2();
161 constraintData.screenVelocity = inputs[2]->GetVector2();
162 constraintData.localPosition = inputs[3]->GetVector2();
163 constraintData.localDisplacement = inputs[4]->GetVector2();
164 constraintData.localVelocity = inputs[5]->GetVector2();
165 constraintData.panning = inputs[6]->GetBoolean();
166 constraintData.called = true;
167 current = Vector3::ZERO;
170 ConstraintData& constraintData;
173 // Generate a PanGesture
174 PanGesture GeneratePan(unsigned int time,
176 Vector2 screenPosition,
177 Vector2 localPosition,
178 Vector2 screenDisplacement = Vector2::ONE,
179 Vector2 localDisplacement = Vector2::ONE,
180 Vector2 screenVelocity = Vector2::ONE,
181 Vector2 localVelocity = Vector2::ONE,
182 unsigned int numberOfTouches = 1)
184 Dali::PanGesture pan = DevelPanGesture::New(state);
186 DevelPanGesture::SetTime(pan, time);
188 DevelPanGesture::SetScreenPosition(pan, screenPosition);
189 DevelPanGesture::SetPosition(pan, localPosition);
191 DevelPanGesture::SetScreenDisplacement(pan, screenDisplacement);
192 DevelPanGesture::SetDisplacement(pan, localDisplacement);
194 DevelPanGesture::SetScreenVelocity(pan, screenVelocity);
195 DevelPanGesture::SetVelocity(pan, localVelocity);
197 DevelPanGesture::SetNumberOfTouches(pan, numberOfTouches);
204 ///////////////////////////////////////////////////////////////////////////////
206 // Positive test case for a method
207 int UtcDaliPanGestureDetectorConstructor(void)
209 TestApplication application;
211 PanGestureDetector detector;
212 DALI_TEST_CHECK(!detector);
216 int UtcDaliPanGestureDetectorCopyConstructorP(void)
218 TestApplication application;
220 PanGestureDetector detector = PanGestureDetector::New();
222 PanGestureDetector copy(detector);
223 DALI_TEST_CHECK(detector);
227 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
229 TestApplication application;
231 PanGestureDetector detector = PanGestureDetector::New();
233 PanGestureDetector assign;
235 DALI_TEST_CHECK(detector);
237 DALI_TEST_CHECK(detector == assign);
241 int UtcDaliPanGestureDetectorMoveConstructorP(void)
243 TestApplication application;
245 PanGestureDetector detector = PanGestureDetector::New();
246 DALI_TEST_CHECK(detector);
248 PanGestureDetector moved = std::move(detector);
249 DALI_TEST_CHECK(moved);
250 DALI_TEST_CHECK(!detector);
254 int UtcDaliPanGestureDetectorMoveAssignmentOperatorP(void)
256 TestApplication application;
258 PanGestureDetector detector;
259 detector = PanGestureDetector::New();
260 DALI_TEST_CHECK(detector);
262 PanGestureDetector moved;
263 moved = std::move(detector);
264 DALI_TEST_CHECK(moved);
265 DALI_TEST_CHECK(!detector);
269 // Negative test case for a method
270 int UtcDaliPanGestureDetectorNew(void)
272 TestApplication application;
274 PanGestureDetector detector = PanGestureDetector::New();
276 DALI_TEST_CHECK(detector);
278 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
279 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
280 DALI_TEST_EQUALS(std::numeric_limits<uint32_t>::max(), detector.GetMaximumMotionEventAge(), TEST_LOCATION);
282 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
283 Actor actor = Actor::New();
284 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
285 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
286 detector.Attach(actor);
288 application.GetScene().Add(actor);
291 application.SendNotification();
292 application.Render();
294 // Use long press function for touch event
295 TestStartLongPress(application);
300 int UtcDaliPanGestureDetectorDownCast(void)
302 TestApplication application;
303 tet_infoline("Testing Dali::GestureDetector::DownCast()");
305 PanGestureDetector detector = PanGestureDetector::New();
307 BaseHandle object(detector);
309 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
310 DALI_TEST_CHECK(detector2);
312 PanGestureDetector detector3 = DownCast<PanGestureDetector>(object);
313 DALI_TEST_CHECK(detector3);
315 BaseHandle unInitializedObject;
316 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
317 DALI_TEST_CHECK(!detector4);
319 PanGestureDetector detector5 = DownCast<PanGestureDetector>(unInitializedObject);
320 DALI_TEST_CHECK(!detector5);
322 GestureDetector detector6 = PanGestureDetector::New();
323 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
324 DALI_TEST_CHECK(detector7);
328 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
330 TestApplication application;
332 PanGestureDetector detector = PanGestureDetector::New();
334 unsigned int min = 2;
336 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
338 detector.SetMinimumTouchesRequired(min);
340 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
342 // Attach an actor and change the minimum touches
344 Actor actor = Actor::New();
345 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
346 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
347 application.GetScene().Add(actor);
350 application.SendNotification();
351 application.Render();
354 GestureReceivedFunctor functor(data);
356 detector.Attach(actor);
357 detector.DetectedSignal().Connect(&application, functor);
359 detector.SetMinimumTouchesRequired(3);
361 // Create a second gesture detector that requires even less minimum touches
362 PanGestureDetector secondDetector = PanGestureDetector::New();
363 secondDetector.Attach(actor);
365 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
370 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
372 TestApplication application;
374 PanGestureDetector detector = PanGestureDetector::New();
376 unsigned int max = 3;
378 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
380 detector.SetMaximumTouchesRequired(max);
382 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
384 // Attach an actor and change the maximum touches
386 Actor actor = Actor::New();
387 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
388 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
389 application.GetScene().Add(actor);
392 application.SendNotification();
393 application.Render();
396 GestureReceivedFunctor functor(data);
398 detector.Attach(actor);
399 detector.DetectedSignal().Connect(&application, functor);
401 detector.SetMaximumTouchesRequired(4);
403 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
408 int UtcDaliPanGestureSetMaximumMotionEventAge(void)
410 TestApplication application;
412 PanGestureDetector detector = PanGestureDetector::New();
414 uint32_t minTime = 20;
416 DALI_TEST_CHECK(minTime != detector.GetMaximumMotionEventAge());
418 detector.SetMaximumMotionEventAge(minTime);
420 DALI_TEST_EQUALS(minTime, detector.GetMaximumMotionEventAge(), TEST_LOCATION);
422 // Attach an actor and change the maximum touches
424 Actor actor = Actor::New();
425 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
426 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
427 application.GetScene().Add(actor);
430 application.SendNotification();
431 application.Render();
434 GestureReceivedFunctor functor(data);
436 detector.Attach(actor);
437 detector.DetectedSignal().Connect(&application, functor);
439 detector.SetMaximumMotionEventAge(minTime * 2);
441 DALI_TEST_EQUALS(minTime * 2, detector.GetMaximumMotionEventAge(), TEST_LOCATION);
446 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
448 TestApplication application;
450 PanGestureDetector detector = PanGestureDetector::New();
451 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
455 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
457 TestApplication application;
459 PanGestureDetector detector = PanGestureDetector::New();
460 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
464 int UtcDaliPanGestureGetMaximumMotionEventAge(void)
466 TestApplication application;
468 PanGestureDetector detector = PanGestureDetector::New();
469 DALI_TEST_EQUALS(std::numeric_limits<uint32_t>::max(), detector.GetMaximumMotionEventAge(), TEST_LOCATION);
473 int UtcDaliPanGestureSignalReceptionNegative(void)
475 TestApplication application;
477 Actor actor = Actor::New();
478 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
479 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
480 application.GetScene().Add(actor);
483 application.SendNotification();
484 application.Render();
487 GestureReceivedFunctor functor(data);
489 PanGestureDetector detector = PanGestureDetector::New();
490 detector.Attach(actor);
491 detector.DetectedSignal().Connect(&application, functor);
493 // Do a pan outside actor's area
495 TestStartPan(application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time);
497 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
499 // Continue pan into actor's area - we should still not receive the signal
501 TestMovePan(application, Vector2(20.0f, 20.0f), time);
503 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
505 // Stop panning - we should still not receive the signal
507 TestEndPan(application, Vector2(12.0f, 12.0f), time);
509 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
513 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
515 TestApplication application;
517 Actor actor = Actor::New();
518 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
519 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
520 application.GetScene().Add(actor);
523 application.SendNotification();
524 application.Render();
527 GestureReceivedFunctor functor(data);
529 PanGestureDetector detector = PanGestureDetector::New();
530 detector.Attach(actor);
531 detector.DetectedSignal().Connect(&application, functor);
533 // Start pan within the actor's area
535 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
537 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
538 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
539 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
540 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
541 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
542 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
543 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
545 // Continue the pan within the actor's area - we should still receive the signal
548 TestMovePan(application, Vector2(26.0f, 4.0f), time);
549 time += TestGetFrameInterval();
551 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
552 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
553 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
554 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
555 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
556 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
557 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
559 // Pan Gesture leaves actor's area - we should still receive the signal
562 TestMovePan(application, Vector2(346.0f, 4.0f), time);
563 time += TestGetFrameInterval();
565 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
566 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
567 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
568 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
569 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
570 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
571 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
573 // Gesture ends - we would receive a finished state
576 TestEndPan(application, Vector2(314.0f, 4.0f), time);
578 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
579 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
580 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
581 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
582 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
583 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
584 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
588 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
590 TestApplication application;
592 Actor actor = Actor::New();
593 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
594 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
595 application.GetScene().Add(actor);
598 application.SendNotification();
599 application.Render();
602 GestureReceivedFunctor functor(data);
604 PanGestureDetector detector = PanGestureDetector::New();
605 detector.Attach(actor);
606 detector.DetectedSignal().Connect(&application, functor);
608 // Start pan within the actor's area
610 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
612 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
613 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
614 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
615 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
616 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
617 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
618 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
620 // Continue the pan within the actor's area - we should still receive the signal
623 TestMovePan(application, Vector2(26.0f, 4.0f), time);
624 time += TestGetFrameInterval();
626 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
627 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
628 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
629 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
630 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
631 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
632 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
634 // Gesture ends within actor's area - we would receive a finished state
637 TestEndPan(application, Vector2(10.0f, 4.0f), time);
639 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
640 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
641 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
642 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
643 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
644 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
645 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
649 int UtcDaliPanGestureSignalReceptionDetach(void)
651 TestApplication application;
653 Actor actor = Actor::New();
654 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
655 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
656 application.GetScene().Add(actor);
659 application.SendNotification();
660 application.Render();
663 GestureReceivedFunctor functor(data);
665 PanGestureDetector detector = PanGestureDetector::New();
666 detector.Attach(actor);
667 detector.DetectedSignal().Connect(&application, functor);
669 // Start pan within the actor's area
671 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
672 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
674 // Continue the pan within the actor's area - we should still receive the signal
677 TestMovePan(application, Vector2(26.0f, 4.0f), time);
678 time += TestGetFrameInterval();
680 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
682 // Gesture ends within actor's area
685 TestEndPan(application, Vector2(10.0f, 4.0f), time);
686 time += TestGetFrameInterval();
688 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
691 detector.DetachAll();
693 // Ensure we are no longer signalled
696 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
697 TestMovePan(application, Vector2(26.0f, 4.0f), time);
698 time += TestGetFrameInterval();
699 TestEndPan(application, Vector2(10.0f, 4.0f), time);
701 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
705 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
707 TestApplication application;
709 Actor actor = Actor::New();
710 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
711 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
712 application.GetScene().Add(actor);
715 application.SendNotification();
716 application.Render();
719 GestureReceivedFunctor functor(data);
721 PanGestureDetector detector = PanGestureDetector::New();
722 detector.Attach(actor);
723 detector.DetectedSignal().Connect(&application, functor);
725 // Start pan within the actor's area
727 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
728 application.SendNotification();
730 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
732 // Continue the pan within the actor's area - we should still receive the signal
735 TestMovePan(application, Vector2(26.0f, 4.0f), time);
736 time += TestGetFrameInterval();
738 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
740 // Detach actor during the pan, we should not receive the next event
741 detector.DetachAll();
743 // Gesture ends within actor's area
746 TestEndPan(application, Vector2(10.0f, 4.0f), time);
748 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
752 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
754 TestApplication application;
757 GestureReceivedFunctor functor(data);
759 PanGestureDetector detector = PanGestureDetector::New();
760 detector.DetectedSignal().Connect(&application, functor);
762 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
764 Actor tempActor = Actor::New();
765 tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
766 tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
767 application.GetScene().Add(tempActor);
768 detector.Attach(tempActor);
772 // Actor lifetime is scoped
774 Actor actor = Actor::New();
775 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
776 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
777 application.GetScene().Add(actor);
780 application.SendNotification();
781 application.Render();
783 detector.Attach(actor);
785 // Start pan within the actor's area
786 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
788 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
790 // Continue the pan within the actor's area - we should still receive the signal
793 TestMovePan(application, Vector2(26.0f, 4.0f), time);
794 time += TestGetFrameInterval();
796 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
798 // Remove the actor from stage and reset the data
799 application.GetScene().Remove(actor);
802 application.SendNotification();
803 application.Render();
806 // Actor should now have been destroyed
808 // Gesture ends within the area where the actor used to be
811 TestEndPan(application, Vector2(10.0f, 4.0f), time);
813 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
817 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
819 TestApplication application;
821 Actor actor = Actor::New();
822 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
823 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
824 application.GetScene().Add(actor);
827 application.SendNotification();
828 application.Render();
831 GestureReceivedFunctor functor(data);
833 PanGestureDetector detector = PanGestureDetector::New();
834 detector.Attach(actor);
835 detector.DetectedSignal().Connect(&application, functor);
837 // Do an entire pan, only check finished value
839 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
843 TestEndPan(application, Vector2(25.0f, 28.0f), time);
845 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
846 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
848 // Rotate actor again and render a couple of times
849 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
850 application.SendNotification();
851 application.Render();
853 // Do an entire pan, only check finished value
854 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
858 TestEndPan(application, Vector2(25.0f, 28.0f), time);
860 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
861 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
863 // Rotate actor again and render a couple of times
864 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
865 application.SendNotification();
866 application.Render();
868 // Do an entire pan, only check finished value
869 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
873 TestEndPan(application, Vector2(25.0f, 28.0f), time);
875 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
876 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
880 int UtcDaliPanGestureSignalReceptionChildHit(void)
882 TestApplication application;
884 Actor parent = Actor::New();
885 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
886 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
887 application.GetScene().Add(parent);
889 // Set child to completely cover parent.
890 // Change rotation of child to be different from parent so that we can check if our local coordinate
891 // conversion of the parent actor is correct.
892 Actor child = Actor::New();
893 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
894 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
895 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
896 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
900 application.SendNotification();
901 application.Render();
904 GestureReceivedFunctor functor(data);
906 PanGestureDetector detector = PanGestureDetector::New();
907 detector.Attach(parent);
908 detector.DetectedSignal().Connect(&application, functor);
910 // Do an entire pan, only check finished value - hits child area but parent should still receive it
912 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
916 TestEndPan(application, Vector2(25.0f, 28.0f), time);
918 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
919 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
920 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
922 // Attach child and generate same touch points to yield a different displacement
923 // (Also proves that you can detach and then re-attach another actor)
924 detector.Attach(child);
925 detector.Detach(parent);
927 // Do an entire pan, only check finished value
928 TestStartPan(application, Vector2(11.0f, 12.0f), Vector2(27.0f, 12.0f), time);
932 TestEndPan(application, Vector2(25.0f, 28.0f), time);
934 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
935 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
936 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
940 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
942 TestApplication application;
944 Actor first = Actor::New();
945 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
946 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
947 application.GetScene().Add(first);
949 Actor second = Actor::New();
950 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
951 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
952 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
953 application.GetScene().Add(second);
956 application.SendNotification();
957 application.Render();
960 GestureReceivedFunctor functor(data);
962 PanGestureDetector detector = PanGestureDetector::New();
963 detector.Attach(first);
964 detector.Attach(second);
965 detector.DetectedSignal().Connect(&application, functor);
967 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
968 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
970 // Start pan within second actor's area
972 TestStartPan(application, Vector2(110.0f, 20.0f), Vector2(126.0f, 20.0f), time);
974 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
975 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
977 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
978 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
980 // Pan moves into first actor's area - second actor should receive the pan
983 TestMovePan(application, Vector2(126.0f, 20.0f), time);
984 time += TestGetFrameInterval();
986 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
987 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
989 // Detach the second actor during the pan, we should not receive the next event
990 detector.Detach(second);
992 // Gesture ends within actor's area
995 TestMovePan(application, Vector2(26.0f, 20.0f), time);
996 TestEndPan(application, Vector2(10.0f, 4.0f), time);
998 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1003 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1005 TestApplication application;
1007 Actor actor = Actor::New();
1008 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1009 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1010 application.GetScene().Add(actor);
1012 // Render and notify
1013 application.SendNotification();
1014 application.Render();
1017 GestureReceivedFunctor functor(data);
1019 PanGestureDetector detector = PanGestureDetector::New();
1020 detector.Attach(actor);
1021 detector.DetectedSignal().Connect(&application, functor);
1023 // Start pan in actor's area
1024 uint32_t time = 100;
1025 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1027 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1029 // Pan continues within actor's area
1032 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1033 time += TestGetFrameInterval();
1035 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1037 // Actor become invisible - actor should not receive the next pan
1038 actor.SetProperty(Actor::Property::VISIBLE, false);
1040 // Render and notify
1041 application.SendNotification();
1042 application.Render();
1044 // Gesture ends within actor's area
1047 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1049 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1053 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1055 TestApplication application;
1057 Actor actor = Actor::New();
1058 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1059 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1060 application.GetScene().Add(actor);
1062 Actor actor2 = Actor::New();
1063 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1064 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
1065 application.GetScene().Add(actor2);
1067 // Render and notify
1068 application.SendNotification();
1069 application.Render();
1071 // Attach actor to one detector
1072 SignalData firstData;
1073 GestureReceivedFunctor firstFunctor(firstData);
1074 PanGestureDetector firstDetector = PanGestureDetector::New();
1075 firstDetector.Attach(actor);
1076 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1078 // Attach actor to another detector
1079 SignalData secondData;
1080 GestureReceivedFunctor secondFunctor(secondData);
1081 PanGestureDetector secondDetector = PanGestureDetector::New();
1082 secondDetector.Attach(actor);
1083 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1085 // Add second actor to second detector, when we remove the actor, this will make sure that this
1086 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1087 // functor should still not be called (which is what we're also testing).
1088 secondDetector.Attach(actor2);
1090 // Pan in actor's area - both detector's functors should be called
1091 uint32_t time = 100;
1092 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1094 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1095 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1097 // Pan continues in actor's area - both detector's functors should be called
1101 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1102 time += TestGetFrameInterval();
1104 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1105 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1107 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1108 firstDetector.Detach(actor);
1112 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1114 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1115 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1117 // New pan on actor, only secondDetector has actor attached
1121 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1123 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1124 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1126 // Detach actor from secondDetector
1127 secondDetector.Detach(actor);
1131 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1133 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1134 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1139 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1141 TestApplication application;
1143 Actor actor1 = Actor::New();
1144 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1145 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1146 application.GetScene().Add(actor1);
1148 GestureReceivedFunctor functor1(data1);
1149 PanGestureDetector detector1 = PanGestureDetector::New();
1150 detector1.Attach(actor1);
1151 detector1.DetectedSignal().Connect(&application, functor1);
1153 Actor actor2 = Actor::New();
1154 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1155 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
1156 actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
1157 application.GetScene().Add(actor2);
1159 GestureReceivedFunctor functor2(data2);
1160 PanGestureDetector detector2 = PanGestureDetector::New();
1161 detector2.Attach(actor2);
1162 detector2.DetectedSignal().Connect(&application, functor2);
1164 // Render and notify
1165 application.SendNotification();
1166 application.Render();
1168 // Start pan in actor1's area, only data1 should be set
1169 uint32_t time = 100;
1170 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1172 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1173 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1177 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1179 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1181 TestApplication application;
1183 Actor actor = Actor::New();
1184 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1185 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1186 application.GetScene().Add(actor);
1188 // Render and notify
1189 application.SendNotification();
1190 application.Render();
1192 // Gesture possible in actor's area (using long-press)
1193 uint32_t time = 100;
1194 TestStartLongPress(application, 10.0f, 20.0f, time);
1195 time += TestGetFrameInterval();
1197 // Attach actor to detector
1199 GestureReceivedFunctor functor(data);
1200 PanGestureDetector detector = PanGestureDetector::New();
1201 detector.DetectedSignal().Connect(&application, functor);
1202 detector.Attach(actor);
1204 // Start a pan, initially it'll only be possible, we shouldn't receive it
1205 TestMovePan(application, Vector2(10.0f, 20.0f), time);
1206 time += TestGetFrameInterval();
1207 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1209 // Now the pan truly starts, we should receive a signal
1210 TestMovePan(application, Vector2(26.0f, 20.0f), time);
1211 time += TestGetFrameInterval();
1212 TestMovePan(application, Vector2(32.0f, 32.0f), time);
1213 time += TestGetFrameInterval();
1214 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1216 // Finish the pan, we should still receive a signal
1218 TestEndPan(application, Vector2(32.0f, 32.0f), time);
1219 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1224 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1226 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1227 // pan actor was there before (parent)
1229 TestApplication application;
1231 Actor parent = Actor::New();
1232 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1233 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1234 application.GetScene().Add(parent);
1236 Actor child = Actor::New();
1237 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1238 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1239 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1242 // Create detector for parent and attach
1243 SignalData parentData;
1244 GestureReceivedFunctor parentFunctor(parentData);
1245 PanGestureDetector parentDetector = PanGestureDetector::New();
1246 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1247 parentDetector.Attach(parent);
1249 // Create detector for child but do not attach
1250 SignalData childData;
1251 GestureReceivedFunctor childFunctor(childData);
1252 PanGestureDetector childDetector = PanGestureDetector::New();
1253 childDetector.DetectedSignal().Connect(&application, childFunctor);
1255 // Render and notify
1256 application.SendNotification();
1257 application.Render();
1259 // Do a full pan in both actors' area, only the parent's functor should be called
1260 uint32_t time = 100;
1261 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1262 DALI_TEST_EQUALS(parentData.functorCalled, true, TEST_LOCATION);
1263 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1266 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1267 DALI_TEST_EQUALS(parentData.functorCalled, true, TEST_LOCATION);
1268 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1272 // Gesture possible in both actors' area (using long-press), no functors called
1273 TestStartLongPress(application, 10.0f, 20.0f, time);
1274 time += TestGetFrameInterval();
1275 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1276 DALI_TEST_EQUALS(childData.functorCalled, false, TEST_LOCATION);
1278 // Attach the child as well now
1279 childDetector.Attach(child);
1281 // Now the pan truly starts, we should receive a signal for the child only
1282 TestMovePan(application, Vector2(26.0f, 20.0f), time);
1283 time += TestGetFrameInterval();
1284 TestMovePan(application, Vector2(32.0f, 32.0f), time);
1285 time += TestGetFrameInterval();
1286 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1287 DALI_TEST_EQUALS(childData.functorCalled, true, TEST_LOCATION);
1291 // Finish the pan, again only the child should still receive a signal
1292 TestEndPan(application, Vector2(32.0f, 32.0f), time);
1293 DALI_TEST_EQUALS(parentData.functorCalled, false, TEST_LOCATION);
1294 DALI_TEST_EQUALS(childData.functorCalled, true, TEST_LOCATION);
1299 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1301 TestApplication application;
1303 Actor actor = Actor::New();
1304 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1305 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1306 application.GetScene().Add(actor);
1308 // Render and notify
1309 application.SendNotification();
1310 application.Render();
1312 // Attach actor to detector
1314 GestureReceivedFunctor functor(data);
1315 PanGestureDetector detector = PanGestureDetector::New();
1316 detector.Attach(actor);
1317 detector.DetectedSignal().Connect(&application, functor);
1319 // Gesture possible in actor's area.
1320 uint32_t time = 100;
1321 TestStartLongPress(application, 10.0f, 20.0f, time);
1322 time += TestGetFrameInterval();
1324 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1326 // Move actor somewhere else
1327 actor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
1329 // Render and notify
1330 application.SendNotification();
1331 application.Render();
1333 // Emit STARTED event, we should not receive the pan.
1334 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1335 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1336 time += TestGetFrameInterval();
1338 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1340 // LONG_PRESS possible in empty area.
1341 TestStartLongPress(application, 10.0f, 20.0f, time);
1342 time += TestGetFrameInterval();
1344 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1346 // Move actor in to the long press position.
1347 actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1349 // Render and notify
1350 application.SendNotification();
1351 application.Render();
1353 // Emit STARTED event, we should be receiving the pan now.
1354 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1355 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1356 time += TestGetFrameInterval();
1358 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1360 // Normal pan in actor's area for completeness.
1362 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1363 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1364 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1368 int UtcDaliPanGestureActorUnstaged(void)
1370 TestApplication application;
1372 Actor actor = Actor::New();
1373 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1374 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1375 application.GetScene().Add(actor);
1377 // Render and notify
1378 application.SendNotification();
1379 application.Render();
1381 // State to remove actor in.
1382 GestureState stateToUnstage(GestureState::STARTED);
1384 // Attach actor to detector
1386 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
1387 PanGestureDetector detector = PanGestureDetector::New();
1388 detector.Attach(actor);
1389 detector.DetectedSignal().Connect(&application, functor);
1392 uint32_t time = 100;
1393 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1395 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1398 TestEndPan(application, Vector2(26.0f, 20.0f), time);
1400 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1403 // Render and notify
1404 application.SendNotification();
1405 application.Render();
1407 // Re-add actor to stage
1408 application.GetScene().Add(actor);
1410 // Render and notify
1411 application.SendNotification();
1412 application.Render();
1414 // Change state to GestureState::CONTINUING to remove
1415 stateToUnstage = GestureState::CONTINUING;
1418 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1420 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1423 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1424 time += TestGetFrameInterval();
1426 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1430 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1432 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1435 // Render and notify
1436 application.SendNotification();
1437 application.Render();
1439 // Re-add actor to stage
1440 application.GetScene().Add(actor);
1442 // Render and notify
1443 application.SendNotification();
1444 application.Render();
1446 // Change state to GestureState::FINISHED to remove
1447 stateToUnstage = GestureState::FINISHED;
1450 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1452 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1455 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1456 time += TestGetFrameInterval();
1458 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1461 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1463 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1464 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
1468 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1470 TestApplication application;
1472 Actor actor = Actor::New();
1473 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1474 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1475 application.GetScene().Add(actor);
1477 // Create and add a second actor so that GestureDetector destruction does not come into play.
1478 Actor dummyActor(Actor::New());
1479 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1480 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
1481 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1482 application.GetScene().Add(dummyActor);
1484 // Render and notify
1485 application.SendNotification();
1486 application.Render();
1488 // State to remove actor in.
1489 GestureState stateToUnstage(GestureState::STARTED);
1491 // Attach actor to detector
1493 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
1494 PanGestureDetector detector = PanGestureDetector::New();
1495 detector.Attach(actor);
1496 detector.Attach(dummyActor);
1497 detector.DetectedSignal().Connect(&application, functor);
1499 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
1500 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1501 // position, we should still not be signalled.
1504 uint32_t time = 100;
1505 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1507 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1510 // Render and notify
1511 application.SendNotification();
1512 application.Render();
1514 // Re add to the stage, we should not be signalled
1515 application.GetScene().Add(actor);
1517 // Render and notify
1518 application.SendNotification();
1519 application.Render();
1521 // Continue signal emission
1522 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1523 time += TestGetFrameInterval();
1525 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1528 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1529 time += TestGetFrameInterval();
1531 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1534 // Here we delete an actor in started, we should not receive any subsequent signalling.
1537 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
1539 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1542 // Render and notify
1543 application.SendNotification();
1544 application.Render();
1546 // Delete actor as well
1549 // Render and notify
1550 application.SendNotification();
1551 application.Render();
1553 // Continue signal emission
1554 TestMovePan(application, Vector2(26.0f, 4.0f), time);
1555 time += TestGetFrameInterval();
1557 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1560 TestEndPan(application, Vector2(10.0f, 4.0f), time);
1562 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1566 int UtcDaliPanGestureAngleHandling(void)
1568 TestApplication application;
1570 PanGestureDetector detector = PanGestureDetector::New();
1571 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1573 detector.AddAngle(PanGestureDetector::DIRECTION_LEFT, Radian(Math::PI * 0.25));
1574 DALI_TEST_EQUALS(detector.GetAngleCount(), 1u, TEST_LOCATION);
1576 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1578 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT)
1580 tet_result(TET_PASS);
1588 tet_printf("%s, angle not added\n", TEST_LOCATION);
1589 tet_result(TET_FAIL);
1592 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Radian(Math::PI * 0.25));
1593 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1595 // Remove something not in the container.
1596 detector.RemoveAngle(PanGestureDetector::DIRECTION_UP);
1597 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1599 detector.RemoveAngle(PanGestureDetector::DIRECTION_RIGHT);
1600 DALI_TEST_EQUALS(detector.GetAngleCount(), 1u, TEST_LOCATION);
1601 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1603 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT)
1605 tet_printf("%s, angle not removed\n", TEST_LOCATION);
1606 tet_result(TET_FAIL);
1611 detector.ClearAngles();
1612 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1616 int UtcDaliPanGestureGetAngle(void)
1618 TestApplication application;
1620 PanGestureDetector detector = PanGestureDetector::New();
1621 DALI_TEST_EQUALS(detector.GetAngleCount(), 0, TEST_LOCATION);
1623 detector.AddAngle(PanGestureDetector::DIRECTION_LEFT);
1624 DALI_TEST_EQUALS(detector.GetAngleCount(), 1, TEST_LOCATION);
1626 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT);
1627 DALI_TEST_EQUALS(detector.GetAngleCount(), 2, TEST_LOCATION);
1629 detector.AddAngle(PanGestureDetector::DIRECTION_UP);
1630 DALI_TEST_EQUALS(detector.GetAngleCount(), 3, TEST_LOCATION);
1632 detector.AddAngle(PanGestureDetector::DIRECTION_DOWN);
1633 DALI_TEST_EQUALS(detector.GetAngleCount(), 4, TEST_LOCATION);
1635 DALI_TEST_EQUALS(detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION);
1636 DALI_TEST_EQUALS(detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION);
1637 DALI_TEST_EQUALS(detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION);
1638 DALI_TEST_EQUALS(detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION);
1643 inline float RadiansToDegrees(float radian)
1645 return radian * 180.0f / Math::PI;
1648 int UtcDaliPanGestureAngleOutOfRange(void)
1650 TestApplication application;
1652 PanGestureDetector detector = PanGestureDetector::New();
1653 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1659 detector.AddAngle(Degree(180.0f));
1660 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-180.0f)), 0.000001, TEST_LOCATION);
1661 detector.ClearAngles();
1663 detector.AddAngle(Degree(190.0f));
1664 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-170.0f)), 0.000001, TEST_LOCATION);
1665 detector.ClearAngles();
1667 detector.AddAngle(Degree(-190.0f));
1668 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(170.0f)), 0.000001, TEST_LOCATION);
1669 detector.ClearAngles();
1671 detector.AddAngle(Degree(350.0f));
1672 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-10.0f)), 0.000001, TEST_LOCATION);
1673 detector.ClearAngles();
1675 detector.AddAngle(Degree(-350.0f));
1676 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1677 detector.ClearAngles();
1679 detector.AddAngle(Degree(370.0f));
1680 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1681 detector.ClearAngles();
1683 detector.AddAngle(Degree(-370.0f));
1684 DALI_TEST_EQUALS(detector.GetAngle(0).first, Radian(Degree(-10.0f)), 0.000001, TEST_LOCATION);
1685 detector.ClearAngles();
1691 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(0.0f));
1692 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(0.0f)), 0.000001, TEST_LOCATION);
1693 detector.ClearAngles();
1695 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(-10.0f));
1696 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(10.0f)), 0.000001, TEST_LOCATION);
1697 detector.ClearAngles();
1699 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(-181.0f));
1700 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(180.0f)), 0.000001, TEST_LOCATION);
1701 detector.ClearAngles();
1703 detector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(181.0f));
1704 DALI_TEST_EQUALS(detector.GetAngle(0).second, Radian(Degree(180.0f)), 0.000001, TEST_LOCATION);
1705 detector.ClearAngles();
1709 int UtcDaliPanGestureAngleProcessing(void)
1711 TestApplication application;
1713 Actor parent = Actor::New();
1714 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1715 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1716 application.GetScene().Add(parent);
1718 Actor child = Actor::New();
1719 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1720 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1723 // Render and notify
1724 application.SendNotification();
1725 application.Render();
1727 // Parent detector only requires up pans
1728 PanGestureDetector parentDetector = PanGestureDetector::New();
1729 parentDetector.Attach(parent);
1730 parentDetector.AddAngle(PanGestureDetector::DIRECTION_UP, Degree(30.0f));
1731 SignalData parentData;
1732 GestureReceivedFunctor parentFunctor(parentData);
1733 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1735 // Child detector only requires right pans
1736 PanGestureDetector childDetector = PanGestureDetector::New();
1737 childDetector.Attach(child);
1738 childDetector.AddAngle(PanGestureDetector::DIRECTION_RIGHT, Degree(30.0f));
1739 SignalData childData;
1740 GestureReceivedFunctor childFunctor(childData);
1741 childDetector.DetectedSignal().Connect(&application, childFunctor);
1743 // Generate an Up pan gesture, only parent should receive it.
1744 uint32_t time = 100;
1745 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 4.0f), time);
1747 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1748 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1750 TestEndPan(application, Vector2(20.0f, 4.0f), time);
1751 time += TestGetFrameInterval();
1755 // Generate a Right pan gesture, only child should receive it.
1756 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(36.0f, 20.0f), time);
1758 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1759 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1761 TestEndPan(application, Vector2(4.0f, 20.0f), time);
1762 time += TestGetFrameInterval();
1766 // Generate a Down pan gesture, no one should receive it.
1767 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 36.0f), time);
1769 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1770 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1772 TestEndPan(application, Vector2(20.0f, 36.0f), time);
1773 time += TestGetFrameInterval();
1777 // Generate a Left pan gesture, no one should receive it.
1778 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 20.0f), time);
1780 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1781 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1783 TestEndPan(application, Vector2(4.0f, 20.0f), time);
1789 int UtcDaliPanGestureDirectionHandling(void)
1791 TestApplication application;
1793 PanGestureDetector detector = PanGestureDetector::New();
1794 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1796 detector.AddDirection(PanGestureDetector::DIRECTION_LEFT, Radian(Math::PI * 0.25));
1797 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1799 for(size_t i = 0; detector.GetAngleCount(); i++)
1801 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT)
1803 tet_result(TET_PASS);
1811 tet_printf("%s, angle not added\n", TEST_LOCATION);
1812 tet_result(TET_FAIL);
1816 for(size_t i = 0; i < detector.GetAngleCount(); i++)
1818 if(detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT)
1820 tet_result(TET_PASS);
1828 tet_printf("%s, angle not added\n", TEST_LOCATION);
1829 tet_result(TET_FAIL);
1832 // Remove something not in the container.
1833 detector.RemoveDirection(PanGestureDetector::DIRECTION_UP);
1834 DALI_TEST_EQUALS(detector.GetAngleCount(), 2u, TEST_LOCATION);
1836 detector.RemoveDirection(PanGestureDetector::DIRECTION_RIGHT);
1837 DALI_TEST_EQUALS(detector.GetAngleCount(), 0u, TEST_LOCATION);
1841 int UtcDaliPanGestureDirectionProcessing(void)
1843 TestApplication application;
1845 Actor parent = Actor::New();
1846 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1847 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1848 application.GetScene().Add(parent);
1850 Actor child = Actor::New();
1851 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1852 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1855 // Render and notify
1856 application.SendNotification();
1857 application.Render();
1859 // Parent detector only requires vertical panning
1860 PanGestureDetector parentDetector = PanGestureDetector::New();
1861 parentDetector.Attach(parent);
1862 parentDetector.AddDirection(PanGestureDetector::DIRECTION_VERTICAL, Degree(30.0f));
1863 SignalData parentData;
1864 GestureReceivedFunctor parentFunctor(parentData);
1865 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1867 // Child detector only requires horizontal panning
1868 PanGestureDetector childDetector = PanGestureDetector::New();
1869 childDetector.Attach(child);
1870 childDetector.AddDirection(PanGestureDetector::DIRECTION_HORIZONTAL, Degree(30.0f));
1871 SignalData childData;
1872 GestureReceivedFunctor childFunctor(childData);
1873 childDetector.DetectedSignal().Connect(&application, childFunctor);
1875 // Generate an Up pan gesture, only parent should receive it.
1876 uint32_t time = 100;
1877 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 4.0f), time);
1879 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1880 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1882 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1883 time += TestGetFrameInterval();
1887 // Generate a Right pan gesture, only child should receive it.
1888 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(36.0f, 20.0f), time);
1890 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1891 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1893 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1894 time += TestGetFrameInterval();
1898 // Generate a Down pan gesture, only parent should receive it.
1899 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(20.0f, 36.0f), time);
1901 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1902 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1904 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1905 time += TestGetFrameInterval();
1909 // Generate a Left pan gesture, only child should receive it.
1910 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 20.0f), time);
1912 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1913 DALI_TEST_EQUALS(true, childData.functorCalled, TEST_LOCATION);
1915 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1916 time += TestGetFrameInterval();
1920 // Generate a pan at -45 degrees, no one should receive it.
1921 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(9.0f, 31.0f), time);
1923 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1924 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1926 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1927 time += TestGetFrameInterval();
1931 // Generate a pan at 45 degrees, no one should receive it.
1932 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(31.0f, 31.0f), time);
1934 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1935 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1937 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1938 time += TestGetFrameInterval();
1942 // Generate a pan at -135 degrees, no one should receive it.
1943 TestStartPan(application, Vector2(20.0f, 20.0f), Vector2(4.0f, 4.0f), time);
1945 DALI_TEST_EQUALS(false, parentData.functorCalled, TEST_LOCATION);
1946 DALI_TEST_EQUALS(false, childData.functorCalled, TEST_LOCATION);
1948 TestEndPan(application, Vector2(20.0f, 20.0f), time);
1954 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1956 TestApplication application;
1957 Integration::SetPanGesturePredictionMode(0);
1958 Integration::SetPanGestureSmoothingMode(0);
1960 Actor actor = Actor::New();
1961 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1962 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1963 application.GetScene().Add(actor);
1965 // Add a pan detector
1966 PanGestureDetector detector = PanGestureDetector::New();
1967 detector.Attach(actor);
1969 GestureReceivedFunctor functor(data);
1970 detector.DetectedSignal().Connect(&application, functor);
1972 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
1974 ConstraintData constraintData;
1975 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
1976 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
1977 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
1978 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
1979 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
1980 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
1981 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
1982 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
1985 // Render and notify
1986 application.SendNotification();
1987 application.Render();
1989 Vector2 startPosition(1.0f, 1.0f);
1990 Vector2 position(-14.0f, 1.0f);
1991 Vector2 direction(Vector2::XAXIS * -5.0f);
1992 uint32_t time = 100;
1994 TestStartPan(application, startPosition, position, time);
1996 for(int i = 0; i < 47; i++)
1998 position += direction;
1999 TestMovePan(application, position, time);
2000 time += TestGetFrameInterval();
2001 application.SendNotification();
2002 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2005 TestEndPan(application, position, time);
2006 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2008 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2009 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2010 DALI_TEST_EQUALS(constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION);
2011 DALI_TEST_EQUALS(constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION);
2013 constraintData.Reset();
2017 int UtcDaliPanGestureNoPredictionSmoothing(void)
2019 TestApplication application;
2020 Integration::SetPanGesturePredictionMode(0);
2021 Integration::SetPanGestureSmoothingMode(1);
2023 Actor actor = Actor::New();
2024 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2025 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2026 application.GetScene().Add(actor);
2028 // Add a pan detector
2029 PanGestureDetector detector = PanGestureDetector::New();
2030 detector.Attach(actor);
2032 GestureReceivedFunctor functor(data);
2033 detector.DetectedSignal().Connect(&application, functor);
2035 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2037 ConstraintData constraintData;
2038 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2039 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2040 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2041 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2042 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2043 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2044 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2045 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2048 // Render and notify
2049 application.SendNotification();
2050 application.Render();
2052 Vector2 startPosition(1.0f, 1.0f);
2053 Vector2 position(-14.0f, 1.0f);
2054 Vector2 direction(Vector2::XAXIS * -5.0f);
2055 uint32_t time = 100;
2057 TestStartPan(application, startPosition, position, time);
2059 for(int i = 0; i < 47; i++)
2061 position += direction;
2062 TestMovePan(application, position, time);
2063 time += TestGetFrameInterval();
2064 application.SendNotification();
2065 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2068 TestEndPan(application, position, time);
2069 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2071 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2072 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2073 // Take into account resampling done when prediction is off.
2074 DALI_TEST_EQUALS(constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION);
2075 DALI_TEST_EQUALS(constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION);
2077 constraintData.Reset();
2081 int UtcDaliPanGesturePredictionNoSmoothing(void)
2083 TestApplication application;
2084 Integration::SetPanGesturePredictionMode(1);
2085 Integration::SetPanGestureSmoothingMode(0);
2087 Actor actor = Actor::New();
2088 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2089 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2090 application.GetScene().Add(actor);
2092 // Add a pan detector
2093 PanGestureDetector detector = PanGestureDetector::New();
2094 detector.Attach(actor);
2096 GestureReceivedFunctor functor(data);
2097 detector.DetectedSignal().Connect(&application, functor);
2099 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2101 ConstraintData constraintData;
2102 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2103 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2104 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2105 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2106 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2107 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2108 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2109 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2112 // Render and notify
2113 application.SendNotification();
2114 application.Render();
2116 Vector2 startPosition(1.0f, 1.0f);
2117 Vector2 position(-1.0f, 1.0f);
2118 Vector2 direction(Vector2::XAXIS * -1.0f);
2119 uint32_t time = 100;
2121 TestStartPan(application, startPosition, position, time);
2123 for(int i = 0; i < 47; i++)
2125 position += direction;
2126 TestMovePan(application, position, time);
2127 time += TestGetFrameInterval();
2128 application.SendNotification();
2129 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2132 TestEndPan(application, position, time);
2133 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2135 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2136 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2137 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2138 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2140 constraintData.Reset();
2144 int UtcDaliPanGesturePredictionSmoothing01(void)
2146 TestApplication application;
2147 Integration::SetPanGesturePredictionMode(1);
2148 Integration::SetPanGestureSmoothingMode(1);
2150 Actor actor = Actor::New();
2151 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2152 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2153 application.GetScene().Add(actor);
2155 // Add a pan detector
2156 PanGestureDetector detector = PanGestureDetector::New();
2157 detector.Attach(actor);
2159 GestureReceivedFunctor functor(data);
2160 detector.DetectedSignal().Connect(&application, functor);
2162 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2164 ConstraintData constraintData;
2165 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2166 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2167 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2168 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2169 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2170 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2171 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2172 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2175 // Render and notify
2176 application.SendNotification();
2177 application.Render();
2179 Vector2 startPosition(1.0f, 1.0f);
2180 Vector2 position(-1.0f, 1.0f);
2181 Vector2 direction(Vector2::XAXIS * -1.0f);
2182 uint32_t time = 100;
2184 TestStartPan(application, startPosition, position, time);
2186 for(int i = 0; i < 47; i++)
2188 position += direction;
2189 TestMovePan(application, position, time);
2190 time += TestGetFrameInterval();
2191 application.SendNotification();
2192 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2195 TestEndPan(application, position, time);
2196 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2198 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2199 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2200 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2201 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION);
2203 constraintData.Reset();
2207 int UtcDaliPanGesturePredictionSmoothing02(void)
2209 TestApplication application;
2210 Integration::SetPanGesturePredictionMode(1);
2211 Integration::SetPanGestureMaximumPredictionAmount(1);
2212 Integration::SetPanGesturePredictionAmountAdjustment(2);
2213 Integration::SetPanGestureSmoothingMode(1);
2214 Integration::SetPanGestureSmoothingAmount(0.25f);
2216 Actor actor = Actor::New();
2217 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2218 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2219 application.GetScene().Add(actor);
2221 // Add a pan detector
2222 PanGestureDetector detector = PanGestureDetector::New();
2223 detector.Attach(actor);
2225 GestureReceivedFunctor functor(data);
2226 detector.DetectedSignal().Connect(&application, functor);
2228 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2230 ConstraintData constraintData;
2231 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2232 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2233 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2234 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2235 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2236 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2237 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2238 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2241 // Render and notify
2242 application.SendNotification();
2243 application.Render();
2245 Vector2 startPosition(2.0f, 2.0f);
2246 Vector2 position(4.0f, 2.0f);
2247 Vector2 directionX(Vector2::XAXIS);
2248 Vector2 directionY(Vector2::YAXIS);
2249 uint32_t time = 100;
2251 TestStartPan(application, startPosition, position, time);
2253 for(int i = 0; i < 7; i++)
2255 position += directionX;
2256 TestMovePan(application, position, time);
2257 time += TestGetFrameInterval();
2258 application.SendNotification();
2259 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2262 position += directionX * 10.0f;
2263 TestMovePan(application, position, time);
2264 time += TestGetFrameInterval();
2265 application.SendNotification();
2266 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2268 for(int i = 0; i < 2; i++)
2270 position += (directionX * -1.0f);
2271 TestMovePan(application, position, time);
2272 time += TestGetFrameInterval();
2273 application.SendNotification();
2274 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2277 for(int i = 0; i < 10; i++)
2279 position += directionX;
2280 TestMovePan(application, position, time);
2281 time += TestGetFrameInterval();
2282 application.SendNotification();
2283 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2286 for(int i = 0; i < 10; i++)
2288 position += directionY;
2289 TestMovePan(application, position, time);
2290 time += TestGetFrameInterval();
2291 application.SendNotification();
2292 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2295 TestEndPan(application, position, time);
2296 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2298 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2299 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2300 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2301 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2303 constraintData.Reset();
2307 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2309 TestApplication application;
2311 Integration::SetPanGesturePredictionMode(2);
2312 Integration::SetPanGesturePredictionAmount(57);
2313 Integration::SetPanGestureSmoothingMode(2);
2314 Integration::SetPanGestureUseActualTimes(false);
2315 Integration::SetPanGestureInterpolationTimeRange(10);
2316 Integration::SetPanGestureScalarOnlyPredictionEnabled(false);
2317 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2318 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2319 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2320 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2321 Integration::SetPanGestureMultitapSmoothingRange(34);
2323 Actor actor = Actor::New();
2324 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2325 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2326 application.GetScene().Add(actor);
2328 // Add a pan detector
2329 PanGestureDetector detector = PanGestureDetector::New();
2330 detector.Attach(actor);
2332 GestureReceivedFunctor functor(data);
2333 detector.DetectedSignal().Connect(&application, functor);
2335 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2337 ConstraintData constraintData;
2338 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2339 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2340 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2341 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2342 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2343 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2344 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2345 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2348 // Render and notify
2349 application.SendNotification();
2350 application.Render();
2352 Vector2 startPosition(2.0f, 2.0f);
2353 Vector2 position(-1.0f, 2.0f);
2354 Vector2 direction(Vector2::XAXIS * -1.0f);
2355 uint32_t time = 100;
2357 TestStartPan(application, startPosition, position, time);
2359 for(int i = 0; i < 27; i++)
2361 position += direction;
2362 TestMovePan(application, position, time);
2363 time += TestGetFrameInterval();
2364 application.SendNotification();
2365 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2368 TestEndPan(application, position, time);
2369 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2371 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2372 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2373 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2374 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2376 constraintData.Reset();
2380 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2382 TestApplication application;
2384 Integration::SetPanGesturePredictionMode(2);
2385 Integration::SetPanGestureSmoothingMode(2);
2386 Integration::SetPanGestureUseActualTimes(true);
2387 Integration::SetPanGestureInterpolationTimeRange(10);
2388 Integration::SetPanGestureScalarOnlyPredictionEnabled(true);
2389 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2390 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2391 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2392 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2393 Integration::SetPanGestureMultitapSmoothingRange(34);
2395 Integration::EnableProfiling(Integration::PROFILING_TYPE_PAN_GESTURE);
2397 Actor actor = Actor::New();
2398 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2399 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2400 application.GetScene().Add(actor);
2402 // Add a pan detector
2403 PanGestureDetector detector = PanGestureDetector::New();
2404 detector.Attach(actor);
2406 GestureReceivedFunctor functor(data);
2407 detector.DetectedSignal().Connect(&application, functor);
2409 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2411 ConstraintData constraintData;
2412 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2413 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2414 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2415 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2416 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2417 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2418 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2419 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2422 // Render and notify
2423 application.SendNotification();
2424 application.Render();
2426 Vector2 startPosition(2.0f, 2.0f);
2427 Vector2 position(17.0f, 2.0f);
2428 Vector2 direction(Vector2::XAXIS * -1.0f);
2429 uint32_t time = 100;
2431 TestStartPan(application, startPosition, position, time);
2433 for(int i = 0; i < 10; i++)
2435 position += direction;
2436 TestMovePan(application, position, time);
2437 time += TestGetFrameInterval();
2439 position += direction;
2440 TestMovePan(application, position, time);
2441 time += TestGetFrameInterval();
2443 position += direction;
2444 TestMovePan(application, position, time);
2445 time += TestGetFrameInterval();
2447 application.SendNotification();
2448 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2451 for(int i = 0; i < 10; i++)
2453 application.SendNotification();
2454 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2457 for(int i = 0; i < 10; i++)
2459 position += direction;
2460 TestMovePan(application, position, time);
2461 application.SendNotification();
2462 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2465 for(int i = 0; i < 10; i++)
2467 position += direction;
2468 TestMovePan(application, position, time);
2469 time += TestGetFrameInterval();
2470 application.SendNotification();
2471 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2474 TestEndPan(application, position, time);
2475 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2477 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2478 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2479 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2480 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2482 constraintData.Reset();
2486 int UtcDaliPanGesturePrediction2Smoothing(void)
2488 TestApplication application;
2490 Integration::SetPanGesturePredictionMode(2);
2491 Integration::SetPanGesturePredictionAmount(57);
2492 Integration::SetPanGestureSmoothingMode(1);
2493 Integration::SetPanGestureUseActualTimes(false);
2494 Integration::SetPanGestureInterpolationTimeRange(10);
2495 Integration::SetPanGestureScalarOnlyPredictionEnabled(true);
2496 Integration::SetPanGestureTwoPointPredictionEnabled(true);
2497 Integration::SetPanGestureTwoPointInterpolatePastTime(42);
2498 Integration::SetPanGestureTwoPointVelocityBias(0.35f);
2499 Integration::SetPanGestureTwoPointAccelerationBias(0.10f);
2500 Integration::SetPanGestureMultitapSmoothingRange(34);
2502 Actor actor = Actor::New();
2503 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2504 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2505 application.GetScene().Add(actor);
2507 // Add a pan detector
2508 PanGestureDetector detector = PanGestureDetector::New();
2509 detector.Attach(actor);
2511 GestureReceivedFunctor functor(data);
2512 detector.DetectedSignal().Connect(&application, functor);
2514 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2516 ConstraintData constraintData;
2517 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2518 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2519 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2520 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2521 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2522 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2523 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2524 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2527 // Render and notify
2528 application.SendNotification();
2529 application.Render();
2531 Vector2 startPosition(2.0f, 2.0f);
2532 Vector2 position(17.0f, 2.0f);
2533 Vector2 direction(Vector2::XAXIS * -1.0f);
2534 uint32_t time = 100;
2536 TestStartPan(application, startPosition, position, time);
2538 for(int i = 0; i < 10; i++)
2540 position += direction;
2541 TestMovePan(application, position, time);
2542 time += TestGetFrameInterval();
2543 application.SendNotification();
2544 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2547 position += direction;
2548 TestMovePan(application, position, time);
2549 time += TestGetFrameInterval();
2551 position += direction;
2552 TestMovePan(application, position, time);
2553 time += TestGetFrameInterval();
2555 position += direction;
2556 TestMovePan(application, position, time);
2557 time += TestGetFrameInterval();
2559 application.SendNotification();
2560 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2562 for(int i = 0; i < 5; i++)
2564 application.SendNotification();
2565 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2568 for(int i = 0; i < 10; i++)
2570 position += direction;
2571 TestMovePan(application, position, time);
2572 time += TestGetFrameInterval();
2573 application.SendNotification();
2574 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2577 TestEndPan(application, position, time);
2578 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2580 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2581 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2582 DALI_TEST_EQUALS(constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2583 DALI_TEST_EQUALS(constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION);
2585 constraintData.Reset();
2589 int UtcDaliPanGestureSetProperties(void)
2591 TestApplication application;
2592 TestRenderController& renderController(application.GetRenderController());
2593 Integration::SetPanGesturePredictionMode(0);
2594 Integration::SetPanGestureSmoothingMode(0);
2596 Actor actor = Actor::New();
2597 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2598 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2599 application.GetScene().Add(actor);
2601 // Add a pan detector
2602 PanGestureDetector detector = PanGestureDetector::New();
2603 detector.Attach(actor);
2605 GestureReceivedFunctor functor(data);
2606 detector.DetectedSignal().Connect(&application, functor);
2608 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2609 Property::Index animatableGestureProperty = detector.RegisterProperty("Dummy Property", Vector3::ZERO); // For code coverage
2611 ConstraintData constraintData;
2612 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2613 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2614 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2615 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2616 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2617 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2618 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2619 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2620 constraint.AddSource(Source(detector, animatableGestureProperty));
2623 // Render and notify
2624 application.SendNotification();
2625 application.Render();
2627 renderController.Initialize();
2628 DALI_TEST_EQUALS(renderController.WasCalled(TestRenderController::RequestUpdateFunc), false, TEST_LOCATION);
2630 Vector2 screenPosition(20.0f, 20.0f);
2631 Vector2 screenDisplacement(1.0f, 1.0f);
2632 Vector2 screenVelocity(1.3f, 4.0f);
2633 Vector2 localPosition(21.0f, 21.0f);
2634 Vector2 localDisplacement(0.5f, 0.5f);
2635 Vector2 localVelocity(1.5f, 2.5f);
2637 PanGestureDetector::SetPanGestureProperties(GeneratePan(1u, GestureState::STARTED, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity));
2638 DALI_TEST_EQUALS(renderController.WasCalled(TestRenderController::RequestUpdateFunc), true, TEST_LOCATION);
2640 // Render and notify
2641 application.SendNotification();
2642 application.Render();
2644 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2645 DALI_TEST_EQUALS(constraintData.screenPosition, screenPosition, TEST_LOCATION);
2646 DALI_TEST_EQUALS(constraintData.localPosition, localPosition, TEST_LOCATION);
2647 DALI_TEST_EQUALS(constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION);
2648 DALI_TEST_EQUALS(constraintData.localDisplacement, localDisplacement, TEST_LOCATION);
2649 DALI_TEST_EQUALS(constraintData.screenVelocity, screenVelocity, TEST_LOCATION);
2650 DALI_TEST_EQUALS(constraintData.localVelocity, localVelocity, TEST_LOCATION);
2651 constraintData.Reset();
2655 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2657 TestApplication application;
2658 Integration::SetPanGesturePredictionMode(0);
2660 Actor actor = Actor::New();
2661 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2662 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2663 application.GetScene().Add(actor);
2665 // Add a pan detector
2666 PanGestureDetector detector = PanGestureDetector::New();
2667 detector.Attach(actor);
2669 GestureReceivedFunctor functor(data);
2670 detector.DetectedSignal().Connect(&application, functor);
2672 Property::Index property = actor.RegisterProperty("Dummy Property", Vector3::ZERO);
2674 ConstraintData constraintData;
2675 Constraint constraint = Constraint::New<Vector3>(actor, property, PanConstraint(constraintData));
2676 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_POSITION));
2677 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT));
2678 constraint.AddSource(Source(detector, PanGestureDetector::Property::SCREEN_VELOCITY));
2679 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_POSITION));
2680 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT));
2681 constraint.AddSource(Source(detector, PanGestureDetector::Property::LOCAL_VELOCITY));
2682 constraint.AddSource(Source(detector, PanGestureDetector::Property::PANNING));
2685 // Render and notify
2686 application.SendNotification();
2687 application.Render();
2689 Vector2 currentPosition(20.0f, 4.0f);
2690 uint32_t time = 100;
2691 TestStartPan(application, Vector2(20.0f, 20.0f), currentPosition, time);
2692 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2694 Vector2 screenPosition(100.0f, 20.0f);
2695 Vector2 localPosition(110.0f, 110.0f);
2697 PanGestureDetector::SetPanGestureProperties(GeneratePan(1u, GestureState::STARTED, screenPosition, localPosition));
2699 // Render and notify
2700 application.SendNotification();
2701 application.Render();
2703 DALI_TEST_EQUALS(constraintData.called, true, TEST_LOCATION);
2704 DALI_TEST_EQUALS(constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION);
2705 DALI_TEST_EQUALS(constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION);
2706 constraintData.Reset();
2710 int UtcDaliPanGesturePropertyIndices(void)
2712 TestApplication application;
2713 PanGestureDetector detector = PanGestureDetector::New();
2715 Property::IndexContainer indices;
2716 detector.GetPropertyIndices(indices);
2717 DALI_TEST_CHECK(indices.Size());
2718 DALI_TEST_EQUALS(indices.Size(), detector.GetPropertyCount(), TEST_LOCATION);
2724 struct PropertyStringIndex
2726 const char* const name;
2727 const Property::Index index;
2728 const Property::Type type;
2729 const Property::Value value;
2732 const PropertyStringIndex PROPERTY_TABLE[] =
2734 {"screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO},
2735 {"screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO},
2736 {"screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO},
2737 {"localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO},
2738 {"localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO},
2739 {"localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO},
2740 {"panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false},
2742 const unsigned int PROPERTY_TABLE_COUNT = sizeof(PROPERTY_TABLE) / sizeof(PROPERTY_TABLE[0]);
2743 } // unnamed namespace
2745 int UtcDaliPanGestureProperties(void)
2747 TestApplication application;
2748 PanGestureDetector detector = PanGestureDetector::New();
2750 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2752 DALI_TEST_EQUALS(detector.GetPropertyName(PROPERTY_TABLE[i].index), std::string(PROPERTY_TABLE[i].name), TEST_LOCATION);
2753 DALI_TEST_EQUALS(detector.GetPropertyIndex(PROPERTY_TABLE[i].name), PROPERTY_TABLE[i].index, TEST_LOCATION);
2754 DALI_TEST_EQUALS(detector.GetPropertyType(PROPERTY_TABLE[i].index), PROPERTY_TABLE[i].type, TEST_LOCATION);
2755 DALI_TEST_EQUALS(detector.IsPropertyWritable(PROPERTY_TABLE[i].index), false, TEST_LOCATION);
2756 DALI_TEST_EQUALS(detector.IsPropertyAnimatable(PROPERTY_TABLE[i].index), false, TEST_LOCATION);
2757 DALI_TEST_EQUALS(detector.IsPropertyAConstraintInput(PROPERTY_TABLE[i].index), true, TEST_LOCATION);
2758 detector.SetProperty(PROPERTY_TABLE[i].index, Property::Value()); // Just for Coverage
2764 int UtcDaliPanGestureGetProperty(void)
2766 TestApplication application;
2767 PanGestureDetector detector = PanGestureDetector::New();
2769 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2771 if(PROPERTY_TABLE[i].type == Property::VECTOR2)
2773 bool value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<bool>();
2774 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<bool>(), value, TEST_LOCATION);
2776 else if(PROPERTY_TABLE[i].type == Property::BOOLEAN)
2778 Vector2 value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<Vector2>();
2779 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<Vector2>(), value, TEST_LOCATION);
2786 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2788 TestApplication application;
2790 Actor actor = Actor::New();
2791 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2792 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2793 application.GetScene().Add(actor);
2795 // Add a pan detector
2796 PanGestureDetector detector = PanGestureDetector::New();
2797 detector.Attach(actor);
2799 // Render and notify
2800 application.SendNotification();
2801 application.Render();
2803 for(unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i)
2805 detector.SetProperty(PROPERTY_TABLE[i].index, Property::Value()); // Just for Coverage
2807 if(PROPERTY_TABLE[i].type == Property::VECTOR2)
2809 bool value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<bool>();
2810 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<bool>(), value, TEST_LOCATION);
2812 else if(PROPERTY_TABLE[i].type == Property::BOOLEAN)
2814 Vector2 value = detector.GetProperty(PROPERTY_TABLE[i].index).Get<Vector2>();
2815 DALI_TEST_EQUALS(PROPERTY_TABLE[i].value.Get<Vector2>(), value, TEST_LOCATION);
2822 int UtcDaliPanGestureLayerConsumesTouch(void)
2824 TestApplication application;
2826 Actor actor = Actor::New();
2827 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2828 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2829 application.GetScene().Add(actor);
2831 // Add a pan detector
2832 PanGestureDetector detector = PanGestureDetector::New();
2833 detector.Attach(actor);
2835 GestureReceivedFunctor functor(data);
2836 detector.DetectedSignal().Connect(&application, functor);
2838 // Add a layer to overlap the actor
2839 Layer layer = Layer::New();
2840 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2841 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2842 application.GetScene().Add(layer);
2845 // Render and notify
2846 application.SendNotification();
2847 application.Render();
2849 // Emit signals, should receive
2850 uint32_t time = 100;
2851 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2852 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2853 time += TestGetFrameInterval();
2855 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2858 // Set layer to consume all touch
2859 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
2861 // Render and notify
2862 application.SendNotification();
2863 application.Render();
2865 // Emit the same signals again, should not receive
2866 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2867 TestEndPan(application, Vector2(26.0f, 20.0f), time);
2869 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2875 int UtcDaliPanGestureNoTimeDiff(void)
2877 TestApplication application;
2879 Actor actor = Actor::New();
2880 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2881 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2882 application.GetScene().Add(actor);
2884 // Add a pan detector
2885 PanGestureDetector detector = PanGestureDetector::New();
2886 detector.Attach(actor);
2888 GestureReceivedFunctor functor(data);
2889 detector.DetectedSignal().Connect(&application, functor);
2891 // Render and notify
2892 application.SendNotification();
2893 application.Render();
2895 // As normal helper function adds intervals between presses we must generate the sequence
2896 // using other helper functions
2897 TestStartLongPress(application, 10.0f, 20.0f, 100); // Used to send a down press event
2898 TestMovePan(application, Vector2(26.0f, 20.0f), 100);
2899 TestMovePan(application, Vector2(26.0f, 20.0f), 100); // 2 motions required to trigger
2900 TestEndPan(application, Vector2(26.0f, 20.0f), 100);
2902 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2903 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetVelocity().x));
2904 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetVelocity().y));
2905 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetScreenVelocity().x));
2906 DALI_TEST_CHECK(!std::isinf(data.receivedGesture.GetScreenVelocity().y));
2914 int UtcDaliPanGestureDisableDetectionDuringPanN(void)
2916 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
2918 TestApplication application;
2920 Actor actor = Actor::New();
2921 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2922 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2923 application.GetScene().Add(actor);
2925 // Add a pan detector
2926 PanGestureDetector detector = PanGestureDetector::New();
2927 bool functorCalled = false;
2928 detector.Attach(actor);
2929 detector.DetectedSignal().Connect(
2931 [&detector, &functorCalled](Actor actor, const PanGesture& pan) {
2932 if(pan.GetState() == GestureState::FINISHED)
2934 detector.Detach(actor);
2935 functorCalled = true;
2939 // Render and notify
2940 application.SendNotification();
2941 application.Render();
2943 // Try the gesture, should not crash
2946 uint32_t time = 100;
2947 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2948 TestEndPan(application, Vector2(26.0f, 20.0f));
2950 DALI_TEST_CHECK(true); // No crash, test has passed
2951 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
2955 DALI_TEST_CHECK(false); // If we crash, the test has failed
2961 int UtcDaliPanGestureWhenGesturePropargation(void)
2963 TestApplication application;
2965 Actor parentActor = Actor::New();
2966 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2967 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2969 Actor childActor = Actor::New();
2970 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2971 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2973 parentActor.Add(childActor);
2974 application.GetScene().Add(parentActor);
2976 // Render and notify
2977 application.SendNotification();
2978 application.Render();
2981 GestureReceivedFunctor pFunctor(pData);
2983 PanGestureDetector parentDetector = PanGestureDetector::New();
2984 parentDetector.Attach(parentActor);
2985 parentDetector.DetectedSignal().Connect(&application, pFunctor);
2988 GestureReceivedFunctor cFunctor(cData);
2990 PanGestureDetector childDetector = PanGestureDetector::New();
2991 childDetector.Attach(childActor);
2992 childDetector.DetectedSignal().Connect(&application, cFunctor);
2994 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
2995 uint32_t time = 100;
2996 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
2998 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
2999 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
3003 TestMovePan(application, Vector2(26.0f, 4.0f), time);
3004 time += TestGetFrameInterval();
3006 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
3007 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
3011 TestEndPan(application, Vector2(26.0f, 20.0f), time);
3013 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
3014 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
3018 // If GesturePropargation is set, a gesture event is to pass over to the parent.
3019 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
3021 // So now the parent got the gesture event.
3022 TestStartPan(application, Vector2(10.0f, 20.0f), Vector2(26.0f, 20.0f), time);
3023 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
3024 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
3028 TestMovePan(application, Vector2(26.0f, 4.0f), time);
3029 time += TestGetFrameInterval();
3031 // child does not receive gestures. This is because we have passed the permission of the gesture to the parent.
3032 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
3033 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);
3037 TestEndPan(application, Vector2(26.0f, 20.0f), time);
3038 DALI_TEST_EQUALS(false, cData.functorCalled, TEST_LOCATION);
3039 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);