2 * Copyright (c) 2019 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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/integration-api/profiling.h>
26 #include <dali/integration-api/input-options.h>
27 #include <dali-test-suite-utils.h>
28 #include <test-touch-utils.h>
32 void utc_dali_pan_gesture_detector_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_pan_gesture_detector_cleanup(void)
39 test_return_value = TET_PASS;
42 ///////////////////////////////////////////////////////////////////////////////
45 const int PAN_EVENT_TIME_DELTA = 8;
46 const int PAN_GESTURE_UPDATE_COUNT = 50;
48 // Stores data that is populated in the callback and will be read by the test cases
52 : functorCalled(false),
53 voidFunctorCalled(false),
54 receivedGesture(Gesture::Clear)
59 functorCalled = false;
60 voidFunctorCalled = false;
62 receivedGesture.state = Gesture::Clear;
63 receivedGesture.velocity = Vector2(0.0f, 0.0f);
64 receivedGesture.displacement = Vector2(0.0f, 0.0f);
65 receivedGesture.position = Vector2(0.0f, 0.0f);
66 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
67 receivedGesture.numberOfTouches = 0;
73 bool voidFunctorCalled;
74 PanGesture receivedGesture;
78 // Functor that sets the data when called
79 struct GestureReceivedFunctor
81 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
83 void operator()(Actor actor, const PanGesture& pan)
85 signalData.functorCalled = true;
86 signalData.receivedGesture = pan;
87 signalData.pannedActor = actor;
92 signalData.voidFunctorCalled = true;
95 SignalData& signalData;
98 // Functor that removes the gestured actor from stage
99 struct UnstageActorFunctor : public GestureReceivedFunctor
101 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
102 : GestureReceivedFunctor( data ),
103 stateToUnstage( stateToUnstage )
107 void operator()( Actor actor, const PanGesture& pan )
109 GestureReceivedFunctor::operator()( actor, pan );
111 if ( pan.state == stateToUnstage )
113 Stage::GetCurrent().Remove( actor );
117 Gesture::State& stateToUnstage;
120 // Functor for receiving a touch event
121 struct TouchEventFunctor
123 bool operator()(Actor actor, const TouchEvent& touch)
129 // Data for constraints
130 struct ConstraintData
138 Vector2 screenPosition;
139 Vector2 screenDisplacement;
140 Vector2 screenVelocity;
141 Vector2 localPosition;
142 Vector2 localDisplacement;
143 Vector2 localVelocity;
149 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
155 // Constraint used with panning properties
158 PanConstraint( ConstraintData& data ) : constraintData(data) { }
160 void operator()( Vector3& current, const PropertyInputContainer& inputs )
162 constraintData.screenPosition = inputs[0]->GetVector2();
163 constraintData.screenDisplacement = inputs[1]->GetVector2();
164 constraintData.screenVelocity = inputs[2]->GetVector2();
165 constraintData.localPosition = inputs[3]->GetVector2();
166 constraintData.localDisplacement = inputs[4]->GetVector2();
167 constraintData.localVelocity = inputs[5]->GetVector2();
168 constraintData.panning = inputs[6]->GetBoolean();
169 constraintData.called = true;
170 current = Vector3::ZERO;
173 ConstraintData& constraintData;
176 // Generate a PanGesture
177 PanGesture GeneratePan( unsigned int time,
178 Gesture::State state,
179 Vector2 screenPosition,
180 Vector2 localPosition,
181 Vector2 screenDisplacement = Vector2::ONE,
182 Vector2 localDisplacement = Vector2::ONE,
183 Vector2 screenVelocity = Vector2::ONE,
184 Vector2 localVelocity = Vector2::ONE,
185 unsigned int numberOfTouches = 1 )
187 PanGesture pan( state );
191 pan.screenPosition = screenPosition;
192 pan.position = localPosition;
194 pan.screenDisplacement = screenDisplacement;
195 pan.displacement = localDisplacement;
197 pan.screenVelocity = screenVelocity;
198 pan.velocity = localVelocity;
200 pan.numberOfTouches = numberOfTouches;
207 ///////////////////////////////////////////////////////////////////////////////
209 // Positive test case for a method
210 int UtcDaliPanGestureDetectorConstructor(void)
212 TestApplication application;
214 PanGestureDetector detector;
215 DALI_TEST_CHECK(!detector);
219 int UtcDaliPanGestureDetectorCopyConstructorP(void)
221 TestApplication application;
223 PanGestureDetector detector = PanGestureDetector::New();
225 PanGestureDetector copy( detector );
226 DALI_TEST_CHECK( detector );
230 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
232 TestApplication application;
234 PanGestureDetector detector = PanGestureDetector::New();
236 PanGestureDetector assign;
238 DALI_TEST_CHECK( detector );
240 DALI_TEST_CHECK( detector == assign );
244 // Negative test case for a method
245 int UtcDaliPanGestureDetectorNew(void)
247 TestApplication application;
249 PanGestureDetector detector = PanGestureDetector::New();
251 DALI_TEST_CHECK(detector);
253 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
254 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
256 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
257 Actor actor = Actor::New();
258 actor.SetSize(100.0f, 100.0f);
259 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
260 detector.Attach(actor);
262 Stage::GetCurrent().Add(actor);
265 application.SendNotification();
266 application.Render();
268 // Use long press function for touch event
269 TestStartLongPress( application );
274 int UtcDaliPanGestureDetectorDownCast(void)
276 TestApplication application;
277 tet_infoline("Testing Dali::GestureDetector::DownCast()");
279 PanGestureDetector detector = PanGestureDetector::New();
281 BaseHandle object(detector);
283 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
284 DALI_TEST_CHECK(detector2);
286 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
287 DALI_TEST_CHECK(detector3);
289 BaseHandle unInitializedObject;
290 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
291 DALI_TEST_CHECK(!detector4);
293 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
294 DALI_TEST_CHECK(!detector5);
296 GestureDetector detector6 = PanGestureDetector::New();
297 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
298 DALI_TEST_CHECK(detector7);
302 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
304 TestApplication application;
306 PanGestureDetector detector = PanGestureDetector::New();
308 unsigned int min = 2;
310 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
312 detector.SetMinimumTouchesRequired(min);
314 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
316 // Attach an actor and change the minimum touches
318 Actor actor = Actor::New();
319 actor.SetSize(100.0f, 100.0f);
320 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
321 Stage::GetCurrent().Add(actor);
324 application.SendNotification();
325 application.Render();
328 GestureReceivedFunctor functor(data);
330 detector.Attach(actor);
331 detector.DetectedSignal().Connect(&application, functor);
333 detector.SetMinimumTouchesRequired(3);
335 // Create a second gesture detector that requires even less minimum touches
336 PanGestureDetector secondDetector = PanGestureDetector::New();
337 secondDetector.Attach(actor);
339 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
344 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
346 TestApplication application;
348 PanGestureDetector detector = PanGestureDetector::New();
350 unsigned int max = 3;
352 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
354 detector.SetMaximumTouchesRequired(max);
356 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
358 // Attach an actor and change the maximum touches
360 Actor actor = Actor::New();
361 actor.SetSize(100.0f, 100.0f);
362 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
363 Stage::GetCurrent().Add(actor);
366 application.SendNotification();
367 application.Render();
370 GestureReceivedFunctor functor(data);
372 detector.Attach(actor);
373 detector.DetectedSignal().Connect(&application, functor);
375 detector.SetMaximumTouchesRequired(4);
377 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
382 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
384 TestApplication application;
386 PanGestureDetector detector = PanGestureDetector::New();
387 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
391 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
393 TestApplication application;
395 PanGestureDetector detector = PanGestureDetector::New();
396 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
400 int UtcDaliPanGestureSignalReceptionNegative(void)
402 TestApplication application;
404 Actor actor = Actor::New();
405 actor.SetSize(100.0f, 100.0f);
406 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
407 Stage::GetCurrent().Add(actor);
410 application.SendNotification();
411 application.Render();
414 GestureReceivedFunctor functor(data);
416 PanGestureDetector detector = PanGestureDetector::New();
417 detector.Attach(actor);
418 detector.DetectedSignal().Connect(&application, functor);
420 // Do a pan outside actor's area
422 TestStartPan( application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time );
424 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
426 // Continue pan into actor's area - we should still not receive the signal
428 TestMovePan( application, Vector2(20.0f, 20.0f), time );
430 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
432 // Stop panning - we should still not receive the signal
434 TestEndPan( application, Vector2(12.0f, 12.0f), time);
436 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
440 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
442 TestApplication application;
444 Actor actor = Actor::New();
445 actor.SetSize(100.0f, 100.0f);
446 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
447 Stage::GetCurrent().Add(actor);
450 application.SendNotification();
451 application.Render();
454 GestureReceivedFunctor functor(data);
456 PanGestureDetector detector = PanGestureDetector::New();
457 detector.Attach(actor);
458 detector.DetectedSignal().Connect(&application, functor);
460 // Start pan within the actor's area
462 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
464 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
465 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
466 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
467 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
468 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
469 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
470 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
472 // Continue the pan within the actor's area - we should still receive the signal
475 TestMovePan( application, Vector2(26.0f, 4.0f), time );
476 time += TestGetFrameInterval();
478 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
479 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
480 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
481 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
482 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
483 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
484 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
486 // Pan Gesture leaves actor's area - we should still receive the signal
489 TestMovePan( application, Vector2(346.0f, 4.0f), time );
490 time += TestGetFrameInterval();
492 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
493 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
494 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
495 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
496 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
497 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
498 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
500 // Gesture ends - we would receive a finished state
503 TestEndPan( application, Vector2(314.0f, 4.0f), time );
505 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
506 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
507 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
508 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
509 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
510 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
511 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
515 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
517 TestApplication application;
519 Actor actor = Actor::New();
520 actor.SetSize(100.0f, 100.0f);
521 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
522 Stage::GetCurrent().Add(actor);
525 application.SendNotification();
526 application.Render();
529 GestureReceivedFunctor functor(data);
531 PanGestureDetector detector = PanGestureDetector::New();
532 detector.Attach(actor);
533 detector.DetectedSignal().Connect(&application, functor);
535 // Start pan within the actor's area
537 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
539 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
540 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
541 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
542 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
543 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
544 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
545 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
547 // Continue the pan within the actor's area - we should still receive the signal
550 TestMovePan( application, Vector2(26.0f, 4.0f), time );
551 time += TestGetFrameInterval();
553 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
554 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
555 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
556 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
557 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
558 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
559 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
561 // Gesture ends within actor's area - we would receive a finished state
564 TestEndPan( application, Vector2(10.0f, 4.0f), time );
566 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
567 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
568 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
569 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
570 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
571 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
572 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
576 int UtcDaliPanGestureSignalReceptionDetach(void)
578 TestApplication application;
580 Actor actor = Actor::New();
581 actor.SetSize(100.0f, 100.0f);
582 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
583 Stage::GetCurrent().Add(actor);
586 application.SendNotification();
587 application.Render();
590 GestureReceivedFunctor functor(data);
592 PanGestureDetector detector = PanGestureDetector::New();
593 detector.Attach(actor);
594 detector.DetectedSignal().Connect(&application, functor);
596 // Start pan within the actor's area
598 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
599 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
601 // Continue the pan within the actor's area - we should still receive the signal
604 TestMovePan( application, Vector2(26.0f, 4.0f), time );
605 time += TestGetFrameInterval();
607 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
609 // Gesture ends within actor's area
612 TestEndPan( application, Vector2(10.0f, 4.0f), time );
613 time += TestGetFrameInterval();
615 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
618 detector.DetachAll();
620 // Ensure we are no longer signalled
623 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
624 TestMovePan( application, Vector2(26.0f, 4.0f), time );
625 time += TestGetFrameInterval();
626 TestEndPan( application, Vector2(10.0f, 4.0f), time );
628 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
632 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
634 TestApplication application;
636 Actor actor = Actor::New();
637 actor.SetSize(100.0f, 100.0f);
638 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
639 Stage::GetCurrent().Add(actor);
642 application.SendNotification();
643 application.Render();
646 GestureReceivedFunctor functor(data);
648 PanGestureDetector detector = PanGestureDetector::New();
649 detector.Attach(actor);
650 detector.DetectedSignal().Connect(&application, functor);
652 // Start pan within the actor's area
654 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
655 application.SendNotification();
657 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
659 // Continue the pan within the actor's area - we should still receive the signal
662 TestMovePan( application, Vector2(26.0f, 4.0f), time );
663 time += TestGetFrameInterval();
665 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
667 // Detach actor during the pan, we should not receive the next event
668 detector.DetachAll();
670 // Gesture ends within actor's area
673 TestEndPan( application, Vector2(10.0f, 4.0f), time );
675 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
679 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
681 TestApplication application;
684 GestureReceivedFunctor functor(data);
686 PanGestureDetector detector = PanGestureDetector::New();
687 detector.DetectedSignal().Connect(&application, functor);
689 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
691 Actor tempActor = Actor::New();
692 tempActor.SetSize(100.0f, 100.0f);
693 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
694 Stage::GetCurrent().Add(tempActor);
695 detector.Attach(tempActor);
699 // Actor lifetime is scoped
701 Actor actor = Actor::New();
702 actor.SetSize(100.0f, 100.0f);
703 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
704 Stage::GetCurrent().Add(actor);
707 application.SendNotification();
708 application.Render();
710 detector.Attach(actor);
712 // Start pan within the actor's area
713 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
715 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
717 // Continue the pan within the actor's area - we should still receive the signal
720 TestMovePan( application, Vector2(26.0f, 4.0f), time );
721 time += TestGetFrameInterval();
723 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
725 // Remove the actor from stage and reset the data
726 Stage::GetCurrent().Remove(actor);
729 application.SendNotification();
730 application.Render();
733 // Actor should now have been destroyed
735 // Gesture ends within the area where the actor used to be
738 TestEndPan( application, Vector2(10.0f, 4.0f), time );
740 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
744 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
746 TestApplication application;
748 Actor actor = Actor::New();
749 actor.SetSize(100.0f, 100.0f);
750 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
751 Stage::GetCurrent().Add(actor);
754 application.SendNotification();
755 application.Render();
758 GestureReceivedFunctor functor(data);
760 PanGestureDetector detector = PanGestureDetector::New();
761 detector.Attach(actor);
762 detector.DetectedSignal().Connect(&application, functor);
764 // Do an entire pan, only check finished value
766 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
770 TestEndPan( application, Vector2(25.0f, 28.0f), time );
772 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
773 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
775 // Rotate actor again and render a couple of times
776 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
777 application.SendNotification();
778 application.Render();
780 // Do an entire pan, only check finished value
781 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
785 TestEndPan( application, Vector2(25.0f, 28.0f), time );
787 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
788 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
790 // Rotate actor again and render a couple of times
791 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
792 application.SendNotification();
793 application.Render();
795 // Do an entire pan, only check finished value
796 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
800 TestEndPan( application, Vector2(25.0f, 28.0f), time );
802 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
803 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
807 int UtcDaliPanGestureSignalReceptionChildHit(void)
809 TestApplication application;
811 Actor parent = Actor::New();
812 parent.SetSize(100.0f, 100.0f);
813 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
814 Stage::GetCurrent().Add(parent);
816 // Set child to completely cover parent.
817 // Change rotation of child to be different from parent so that we can check if our local coordinate
818 // conversion of the parent actor is correct.
819 Actor child = Actor::New();
820 child.SetSize(100.0f, 100.0f);
821 child.SetAnchorPoint(AnchorPoint::CENTER);
822 child.SetParentOrigin(ParentOrigin::CENTER);
823 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
826 TouchEventFunctor touchFunctor;
827 child.TouchedSignal().Connect(&application, touchFunctor);
830 application.SendNotification();
831 application.Render();
834 GestureReceivedFunctor functor(data);
836 PanGestureDetector detector = PanGestureDetector::New();
837 detector.Attach(parent);
838 detector.DetectedSignal().Connect(&application, functor);
840 // Do an entire pan, only check finished value - hits child area but parent should still receive it
842 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
846 TestEndPan( application, Vector2(25.0f, 28.0f), time );
848 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
849 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
850 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
852 // Attach child and generate same touch points to yield a different displacement
853 // (Also proves that you can detach and then re-attach another actor)
854 detector.Attach(child);
855 detector.Detach(parent);
857 // Do an entire pan, only check finished value
858 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
862 TestEndPan( application, Vector2(25.0f, 28.0f), time );
864 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
865 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
866 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
870 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
872 TestApplication application;
874 Actor first = Actor::New();
875 first.SetSize(100.0f, 100.0f);
876 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
877 Stage::GetCurrent().Add(first);
879 Actor second = Actor::New();
880 second.SetSize(100.0f, 100.0f);
882 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
883 Stage::GetCurrent().Add(second);
886 application.SendNotification();
887 application.Render();
890 GestureReceivedFunctor functor(data);
892 PanGestureDetector detector = PanGestureDetector::New();
893 detector.Attach(first);
894 detector.Attach(second);
895 detector.DetectedSignal().Connect(&application, functor);
897 DALI_TEST_EQUALS(Stage::GetCurrent().GetRootLayer(), first.GetParent(), TEST_LOCATION);
898 DALI_TEST_EQUALS(Stage::GetCurrent().GetRootLayer(), second.GetParent(), TEST_LOCATION);
900 // Start pan within second actor's area
902 TestStartPan( application, Vector2( 110.0f, 20.0f ), Vector2( 126.0f, 20.0f ), time );
904 DALI_TEST_EQUALS(Stage::GetCurrent().GetRootLayer(), first.GetParent(), TEST_LOCATION);
905 DALI_TEST_EQUALS(Stage::GetCurrent().GetRootLayer(), second.GetParent(), TEST_LOCATION);
907 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
908 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
910 // Pan moves into first actor's area - second actor should receive the pan
913 TestMovePan( application, Vector2(126.0f, 20.0f), time );
914 time += TestGetFrameInterval();
916 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
917 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
919 // Detach the second actor during the pan, we should not receive the next event
920 detector.Detach(second);
922 // Gesture ends within actor's area
925 TestMovePan( application, Vector2(26.0f, 20.0f), time );
926 TestEndPan( application, Vector2(10.0f, 4.0f), time );
928 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
933 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
935 TestApplication application;
937 Actor actor = Actor::New();
938 actor.SetSize(100.0f, 100.0f);
939 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
940 Stage::GetCurrent().Add(actor);
943 application.SendNotification();
944 application.Render();
947 GestureReceivedFunctor functor(data);
949 PanGestureDetector detector = PanGestureDetector::New();
950 detector.Attach(actor);
951 detector.DetectedSignal().Connect(&application, functor);
953 // Start pan in actor's area
955 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
957 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
959 // Pan continues within actor's area
962 TestMovePan( application, Vector2(26.0f, 4.0f), time );
963 time += TestGetFrameInterval();
965 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
967 // Actor become invisible - actor should not receive the next pan
968 actor.SetVisible(false);
971 application.SendNotification();
972 application.Render();
974 // Gesture ends within actor's area
977 TestEndPan( application, Vector2(10.0f, 4.0f), time );
979 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
983 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
985 TestApplication application;
987 Actor actor = Actor::New();
988 actor.SetSize(100.0f, 100.0f);
989 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
990 Stage::GetCurrent().Add(actor);
992 Actor actor2 = Actor::New();
993 actor2.SetSize(100.0f, 100.0f);
994 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
995 Stage::GetCurrent().Add(actor2);
998 application.SendNotification();
999 application.Render();
1001 // Attach actor to one detector
1002 SignalData firstData;
1003 GestureReceivedFunctor firstFunctor(firstData);
1004 PanGestureDetector firstDetector = PanGestureDetector::New();
1005 firstDetector.Attach(actor);
1006 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1008 // Attach actor to another detector
1009 SignalData secondData;
1010 GestureReceivedFunctor secondFunctor(secondData);
1011 PanGestureDetector secondDetector = PanGestureDetector::New();
1012 secondDetector.Attach(actor);
1013 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1015 // Add second actor to second detector, when we remove the actor, this will make sure that this
1016 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1017 // functor should still not be called (which is what we're also testing).
1018 secondDetector.Attach(actor2);
1020 // Pan in actor's area - both detector's functors should be called
1021 uint32_t time = 100;
1022 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1024 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1025 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1027 // Pan continues in actor's area - both detector's functors should be called
1031 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1032 time += TestGetFrameInterval();
1034 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1035 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1037 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1038 firstDetector.Detach(actor);
1042 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1044 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1045 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1047 // New pan on actor, only secondDetector has actor attached
1051 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1053 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1054 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1056 // Detach actor from secondDetector
1057 secondDetector.Detach(actor);
1061 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1063 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1064 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1069 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1071 TestApplication application;
1073 Actor actor1 = Actor::New();
1074 actor1.SetSize(100.0f, 100.0f);
1075 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1076 Stage::GetCurrent().Add(actor1);
1078 GestureReceivedFunctor functor1(data1);
1079 PanGestureDetector detector1 = PanGestureDetector::New();
1080 detector1.Attach(actor1);
1081 detector1.DetectedSignal().Connect(&application, functor1);
1083 Actor actor2 = Actor::New();
1084 actor2.SetSize(100.0f, 100.0f);
1085 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1086 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1087 Stage::GetCurrent().Add(actor2);
1089 GestureReceivedFunctor functor2(data2);
1090 PanGestureDetector detector2 = PanGestureDetector::New();
1091 detector2.Attach(actor2);
1092 detector2.DetectedSignal().Connect(&application, functor2);
1094 // Render and notify
1095 application.SendNotification();
1096 application.Render();
1098 // Start pan in actor1's area, only data1 should be set
1099 uint32_t time = 100;
1100 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1102 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1103 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1107 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1109 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1111 TestApplication application;
1113 Actor actor = Actor::New();
1114 actor.SetSize(100.0f, 100.0f);
1115 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1116 Stage::GetCurrent().Add(actor);
1118 // Render and notify
1119 application.SendNotification();
1120 application.Render();
1122 // Gesture possible in actor's area (using long-press)
1123 uint32_t time = 100;
1124 TestStartLongPress( application, 10.0f, 20.0f, time );
1125 time += TestGetFrameInterval();
1127 // Attach actor to detector
1129 GestureReceivedFunctor functor( data );
1130 PanGestureDetector detector = PanGestureDetector::New();
1131 detector.DetectedSignal().Connect( &application, functor );
1132 detector.Attach(actor);
1134 // Start a pan, initially it'll only be possible, we shouldn't receive it
1135 TestMovePan( application, Vector2( 10.0f, 20.0f ), time );
1136 time += TestGetFrameInterval();
1137 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1139 // Now the pan truly starts, we should receive a signal
1140 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1141 time += TestGetFrameInterval();
1142 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1143 time += TestGetFrameInterval();
1144 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1146 // Finish the pan, we should still receive a signal
1148 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1149 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1154 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1156 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1157 // pan actor was there before (parent)
1159 TestApplication application;
1161 Actor parent = Actor::New();
1162 parent.SetSize(100.0f, 100.0f);
1163 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1164 Stage::GetCurrent().Add( parent );
1166 Actor child = Actor::New();
1167 child.SetSize(100.0f, 100.0f);
1168 child.SetAnchorPoint(AnchorPoint::CENTER);
1169 child.SetParentOrigin(ParentOrigin::CENTER);
1170 parent.Add( child );
1172 // Create detector for parent and attach
1173 SignalData parentData;
1174 GestureReceivedFunctor parentFunctor( parentData );
1175 PanGestureDetector parentDetector = PanGestureDetector::New();
1176 parentDetector.DetectedSignal().Connect( &application, parentFunctor );
1177 parentDetector.Attach( parent );
1179 // Create detector for child but do not attach
1180 SignalData childData;
1181 GestureReceivedFunctor childFunctor( childData );
1182 PanGestureDetector childDetector = PanGestureDetector::New();
1183 childDetector.DetectedSignal().Connect( &application, childFunctor );
1185 // Render and notify
1186 application.SendNotification();
1187 application.Render();
1189 // Do a full pan in both actors' area, only the parent's functor should be called
1190 uint32_t time = 100;
1191 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1192 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1193 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1196 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1197 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1198 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1202 // Gesture possible in both actors' area (using long-press), no functors called
1203 TestStartLongPress( application, 10.0f, 20.0f, time );
1204 time += TestGetFrameInterval();
1205 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1206 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1208 // Attach the child as well now
1209 childDetector.Attach( child );
1211 // Now the pan truly starts, we should receive a signal for the child only
1212 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1213 time += TestGetFrameInterval();
1214 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1215 time += TestGetFrameInterval();
1216 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1217 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1221 // Finish the pan, again only the child should still receive a signal
1222 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1223 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1224 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1229 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1231 TestApplication application;
1233 Actor actor = Actor::New();
1234 actor.SetSize(100.0f, 100.0f);
1235 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1236 Stage::GetCurrent().Add(actor);
1238 // Render and notify
1239 application.SendNotification();
1240 application.Render();
1242 // Attach actor to detector
1244 GestureReceivedFunctor functor( data );
1245 PanGestureDetector detector = PanGestureDetector::New();
1246 detector.Attach(actor);
1247 detector.DetectedSignal().Connect( &application, functor );
1249 // Gesture possible in actor's area.
1250 uint32_t time = 100;
1251 TestStartLongPress( application, 10.0f, 20.0f, time );
1252 time += TestGetFrameInterval();
1254 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1256 // Move actor somewhere else
1257 actor.SetPosition( 100.0f, 100.0f );
1259 // Render and notify
1260 application.SendNotification();
1261 application.Render();
1263 // Emit Started event, we should not receive the pan.
1264 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1265 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1266 time += TestGetFrameInterval();
1268 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1270 // LongPress possible in empty area.
1271 TestStartLongPress( application, 10.0f, 20.0f, time );
1272 time += TestGetFrameInterval();
1274 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1276 // Move actor in to the long press position.
1277 actor.SetPosition( 0.0f, 0.0f );
1279 // Render and notify
1280 application.SendNotification();
1281 application.Render();
1283 // Emit Started event, we should be receiving the pan now.
1284 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1285 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1286 time += TestGetFrameInterval();
1288 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1290 // Normal pan in actor's area for completeness.
1292 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1293 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1294 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1298 int UtcDaliPanGestureActorUnstaged(void)
1300 TestApplication application;
1302 Actor actor = Actor::New();
1303 actor.SetSize(100.0f, 100.0f);
1304 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1305 Stage::GetCurrent().Add(actor);
1307 // Render and notify
1308 application.SendNotification();
1309 application.Render();
1311 // State to remove actor in.
1312 Gesture::State stateToUnstage( Gesture::Started );
1314 // Attach actor to detector
1316 UnstageActorFunctor functor( data, stateToUnstage );
1317 PanGestureDetector detector = PanGestureDetector::New();
1318 detector.Attach(actor);
1319 detector.DetectedSignal().Connect( &application, functor );
1322 uint32_t time = 100;
1323 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1325 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1328 TestEndPan( application, Vector2(26.0f, 20.0f), time );
1330 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1333 // Render and notify
1334 application.SendNotification();
1335 application.Render();
1337 // Re-add actor to stage
1338 Stage::GetCurrent().Add(actor);
1340 // Render and notify
1341 application.SendNotification();
1342 application.Render();
1344 // Change state to Gesture::Continuing to remove
1345 stateToUnstage = Gesture::Continuing;
1348 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1350 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1353 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1354 time += TestGetFrameInterval();
1356 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1360 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1362 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1365 // Render and notify
1366 application.SendNotification();
1367 application.Render();
1369 // Re-add actor to stage
1370 Stage::GetCurrent().Add(actor);
1372 // Render and notify
1373 application.SendNotification();
1374 application.Render();
1376 // Change state to Gesture::Finished to remove
1377 stateToUnstage = Gesture::Finished;
1380 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1382 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1385 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1386 time += TestGetFrameInterval();
1388 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1391 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1393 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1394 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1398 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1400 TestApplication application;
1402 Actor actor = Actor::New();
1403 actor.SetSize(100.0f, 100.0f);
1404 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1405 Stage::GetCurrent().Add(actor);
1407 // Create and add a second actor so that GestureDetector destruction does not come into play.
1408 Actor dummyActor( Actor::New() );
1409 dummyActor.SetSize( 100.0f, 100.0f );
1410 dummyActor.SetPosition( 100.0f, 100.0f );
1411 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1412 Stage::GetCurrent().Add(dummyActor);
1414 // Render and notify
1415 application.SendNotification();
1416 application.Render();
1418 // State to remove actor in.
1419 Gesture::State stateToUnstage( Gesture::Started );
1421 // Attach actor to detector
1423 UnstageActorFunctor functor( data, stateToUnstage );
1424 PanGestureDetector detector = PanGestureDetector::New();
1425 detector.Attach(actor);
1426 detector.Attach(dummyActor);
1427 detector.DetectedSignal().Connect( &application, functor );
1429 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1430 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1431 // position, we should still not be signalled.
1434 uint32_t time = 100;
1435 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1437 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1440 // Render and notify
1441 application.SendNotification();
1442 application.Render();
1444 // Re add to the stage, we should not be signalled
1445 Stage::GetCurrent().Add(actor);
1447 // Render and notify
1448 application.SendNotification();
1449 application.Render();
1451 // Continue signal emission
1452 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1453 time += TestGetFrameInterval();
1455 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1458 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1459 time += TestGetFrameInterval();
1461 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1464 // Here we delete an actor in started, we should not receive any subsequent signalling.
1467 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1469 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1472 // Render and notify
1473 application.SendNotification();
1474 application.Render();
1476 // Delete actor as well
1479 // Render and notify
1480 application.SendNotification();
1481 application.Render();
1483 // Continue signal emission
1484 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1485 time += TestGetFrameInterval();
1487 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1490 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1492 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1496 int UtcDaliPanGestureAngleHandling(void)
1498 TestApplication application;
1500 PanGestureDetector detector = PanGestureDetector::New();
1501 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1503 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1504 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1506 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1508 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1510 tet_result( TET_PASS );
1518 tet_printf("%s, angle not added\n", TEST_LOCATION );
1519 tet_result( TET_FAIL );
1522 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1523 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1525 // Remove something not in the container.
1526 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1527 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1529 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1530 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1531 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1533 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1535 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1536 tet_result( TET_FAIL );
1541 detector.ClearAngles();
1542 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1546 int UtcDaliPanGestureGetAngle(void)
1548 TestApplication application;
1550 PanGestureDetector detector = PanGestureDetector::New();
1551 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1553 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1554 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1556 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1557 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1559 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1560 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1562 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1563 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1565 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1566 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1567 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1568 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1573 inline float RadiansToDegrees( float radian )
1575 return radian * 180.0f / Math::PI;
1578 int UtcDaliPanGestureAngleOutOfRange(void)
1580 TestApplication application;
1582 PanGestureDetector detector = PanGestureDetector::New();
1583 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1589 detector.AddAngle( Degree(180.0f) );
1590 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1591 detector.ClearAngles();
1593 detector.AddAngle( Degree(190.0f) );
1594 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1595 detector.ClearAngles();
1597 detector.AddAngle( Degree(-190.0f) );
1598 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1599 detector.ClearAngles();
1601 detector.AddAngle( Degree(350.0f) );
1602 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1603 detector.ClearAngles();
1605 detector.AddAngle( Degree(-350.0f) );
1606 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1607 detector.ClearAngles();
1609 detector.AddAngle( Degree(370.0f) );
1610 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1611 detector.ClearAngles();
1613 detector.AddAngle( Degree(-370.0f) );
1614 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1615 detector.ClearAngles();
1621 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1622 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1623 detector.ClearAngles();
1625 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1626 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1627 detector.ClearAngles();
1629 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1630 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1631 detector.ClearAngles();
1633 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1634 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1635 detector.ClearAngles();
1639 int UtcDaliPanGestureAngleProcessing(void)
1641 TestApplication application;
1643 Actor parent = Actor::New();
1644 parent.SetSize(100.0f, 100.0f);
1645 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1646 Stage::GetCurrent().Add(parent);
1648 Actor child = Actor::New();
1649 child.SetSize(100.0f, 100.0f);
1650 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1653 // Render and notify
1654 application.SendNotification();
1655 application.Render();
1657 // Parent detector only requires up pans
1658 PanGestureDetector parentDetector = PanGestureDetector::New();
1659 parentDetector.Attach( parent );
1660 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1661 SignalData parentData;
1662 GestureReceivedFunctor parentFunctor(parentData);
1663 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1665 // Child detector only requires right pans
1666 PanGestureDetector childDetector = PanGestureDetector::New();
1667 childDetector.Attach( child );
1668 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1669 SignalData childData;
1670 GestureReceivedFunctor childFunctor(childData);
1671 childDetector.DetectedSignal().Connect(&application, childFunctor);
1673 // Generate an Up pan gesture, only parent should receive it.
1674 uint32_t time = 100;
1675 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1677 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1678 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1680 TestEndPan( application, Vector2(20.0f, 4.0f), time );
1681 time += TestGetFrameInterval();
1685 // Generate a Right pan gesture, only child should receive it.
1686 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1688 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1689 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1691 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1692 time += TestGetFrameInterval();
1696 // Generate a Down pan gesture, no one should receive it.
1697 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1699 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1700 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1702 TestEndPan( application, Vector2(20.0f, 36.0f), time );
1703 time += TestGetFrameInterval();
1707 // Generate a Left pan gesture, no one should receive it.
1708 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1710 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1711 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1713 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1719 int UtcDaliPanGestureDirectionHandling(void)
1721 TestApplication application;
1723 PanGestureDetector detector = PanGestureDetector::New();
1724 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1726 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1727 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1729 for ( size_t i = 0; detector.GetAngleCount(); i++)
1731 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1733 tet_result( TET_PASS );
1742 tet_printf("%s, angle not added\n", TEST_LOCATION );
1743 tet_result( TET_FAIL );
1747 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1749 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1751 tet_result( TET_PASS );
1759 tet_printf("%s, angle not added\n", TEST_LOCATION );
1760 tet_result( TET_FAIL );
1763 // Remove something not in the container.
1764 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1765 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1767 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1768 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1772 int UtcDaliPanGestureDirectionProcessing(void)
1774 TestApplication application;
1776 Actor parent = Actor::New();
1777 parent.SetSize(100.0f, 100.0f);
1778 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1779 Stage::GetCurrent().Add(parent);
1781 Actor child = Actor::New();
1782 child.SetSize(100.0f, 100.0f);
1783 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1786 // Render and notify
1787 application.SendNotification();
1788 application.Render();
1790 // Parent detector only requires vertical panning
1791 PanGestureDetector parentDetector = PanGestureDetector::New();
1792 parentDetector.Attach( parent );
1793 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1794 SignalData parentData;
1795 GestureReceivedFunctor parentFunctor(parentData);
1796 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1798 // Child detector only requires horizontal panning
1799 PanGestureDetector childDetector = PanGestureDetector::New();
1800 childDetector.Attach( child );
1801 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1802 SignalData childData;
1803 GestureReceivedFunctor childFunctor(childData);
1804 childDetector.DetectedSignal().Connect(&application, childFunctor);
1806 // Generate an Up pan gesture, only parent should receive it.
1807 uint32_t time = 100;
1808 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1810 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1811 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1813 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1814 time += TestGetFrameInterval();
1818 // Generate a Right pan gesture, only child should receive it.
1819 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1821 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1822 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1824 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1825 time += TestGetFrameInterval();
1829 // Generate a Down pan gesture, only parent should receive it.
1830 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1832 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1833 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1835 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1836 time += TestGetFrameInterval();
1840 // Generate a Left pan gesture, only child should receive it.
1841 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1843 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1844 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1846 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1847 time += TestGetFrameInterval();
1851 // Generate a pan at -45 degrees, no one should receive it.
1852 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 9.0f, 31.0f ), time );
1854 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1855 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1857 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1858 time += TestGetFrameInterval();
1862 // Generate a pan at 45 degrees, no one should receive it.
1863 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 31.0f, 31.0f ), time );
1865 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1866 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1868 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1869 time += TestGetFrameInterval();
1873 // Generate a pan at -135 degrees, no one should receive it.
1874 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 4.0f ), time );
1876 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1877 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1879 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1885 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1887 TestApplication application;
1888 Integration::SetPanGesturePredictionMode(0);
1889 Integration::SetPanGestureSmoothingMode(0);
1891 Actor actor = Actor::New();
1892 actor.SetSize(100.0f, 100.0f);
1893 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1894 Stage::GetCurrent().Add(actor);
1896 // Add a pan detector
1897 PanGestureDetector detector = PanGestureDetector::New();
1898 detector.Attach( actor );
1900 GestureReceivedFunctor functor( data );
1901 detector.DetectedSignal().Connect( &application, functor );
1903 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1905 ConstraintData constraintData;
1906 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1907 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1908 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1909 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1910 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1911 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1912 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1913 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1916 // Render and notify
1917 application.SendNotification();
1918 application.Render();
1920 Vector2 startPosition( 1.0f, 1.0f );
1921 Vector2 position( -14.0f, 1.0f );
1922 Vector2 direction(Vector2::XAXIS * -5.0f);
1923 uint32_t time = 100;
1925 TestStartPan( application, startPosition, position, time );
1927 for(int i = 0; i < 47; i++ )
1929 position += direction;
1930 TestMovePan( application, position, time );
1931 time += TestGetFrameInterval();
1932 application.SendNotification();
1933 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1936 TestEndPan( application, position, time );
1937 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1939 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1940 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1941 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1942 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1944 constraintData.Reset();
1948 int UtcDaliPanGestureNoPredictionSmoothing(void)
1950 TestApplication application;
1951 Integration::SetPanGesturePredictionMode(0);
1952 Integration::SetPanGestureSmoothingMode(1);
1954 Actor actor = Actor::New();
1955 actor.SetSize(100.0f, 100.0f);
1956 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1957 Stage::GetCurrent().Add(actor);
1959 // Add a pan detector
1960 PanGestureDetector detector = PanGestureDetector::New();
1961 detector.Attach( actor );
1963 GestureReceivedFunctor functor( data );
1964 detector.DetectedSignal().Connect( &application, functor );
1966 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1968 ConstraintData constraintData;
1969 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1970 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1971 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1972 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1973 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1974 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1975 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1976 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1979 // Render and notify
1980 application.SendNotification();
1981 application.Render();
1983 Vector2 startPosition( 1.0f, 1.0f );
1984 Vector2 position( -14.0f, 1.0f );
1985 Vector2 direction(Vector2::XAXIS * -5.0f);
1986 uint32_t time = 100;
1988 TestStartPan( application, startPosition, position, time );
1990 for(int i = 0; i < 47; i++ )
1992 position += direction;
1993 TestMovePan( application, position, time );
1994 time += TestGetFrameInterval();
1995 application.SendNotification();
1996 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1999 TestEndPan( application, position, time );
2000 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2002 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2003 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2004 // Take into account resampling done when prediction is off.
2005 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2006 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2008 constraintData.Reset();
2012 int UtcDaliPanGesturePredictionNoSmoothing(void)
2014 TestApplication application;
2015 Integration::SetPanGesturePredictionMode(1);
2016 Integration::SetPanGestureSmoothingMode(0);
2018 Actor actor = Actor::New();
2019 actor.SetSize(100.0f, 100.0f);
2020 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2021 Stage::GetCurrent().Add(actor);
2023 // Add a pan detector
2024 PanGestureDetector detector = PanGestureDetector::New();
2025 detector.Attach( actor );
2027 GestureReceivedFunctor functor( data );
2028 detector.DetectedSignal().Connect( &application, functor );
2030 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2032 ConstraintData constraintData;
2033 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2034 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2035 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2036 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2037 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2038 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2039 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2040 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2043 // Render and notify
2044 application.SendNotification();
2045 application.Render();
2047 Vector2 startPosition( 1.0f, 1.0f );
2048 Vector2 position( -1.0f, 1.0f );
2049 Vector2 direction(Vector2::XAXIS * -1.0f);
2050 uint32_t time = 100;
2052 TestStartPan( application, startPosition, position, time );
2054 for(int i = 0; i < 47; i++ )
2056 position += direction;
2057 TestMovePan( application, position, time );
2058 time += TestGetFrameInterval();
2059 application.SendNotification();
2060 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2063 TestEndPan( application, position, time );
2064 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2066 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2067 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2068 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2069 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2071 constraintData.Reset();
2075 int UtcDaliPanGesturePredictionSmoothing01(void)
2077 TestApplication application;
2078 Integration::SetPanGesturePredictionMode(1);
2079 Integration::SetPanGestureSmoothingMode(1);
2081 Actor actor = Actor::New();
2082 actor.SetSize(100.0f, 100.0f);
2083 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2084 Stage::GetCurrent().Add(actor);
2086 // Add a pan detector
2087 PanGestureDetector detector = PanGestureDetector::New();
2088 detector.Attach( actor );
2090 GestureReceivedFunctor functor( data );
2091 detector.DetectedSignal().Connect( &application, functor );
2093 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2095 ConstraintData constraintData;
2096 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2097 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2098 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2099 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2100 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2101 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2102 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2103 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2106 // Render and notify
2107 application.SendNotification();
2108 application.Render();
2110 Vector2 startPosition( 1.0f, 1.0f );
2111 Vector2 position( -1.0f, 1.0f );
2112 Vector2 direction(Vector2::XAXIS * -1.0f);
2113 uint32_t time = 100;
2115 TestStartPan( application, startPosition, position, time );
2117 for(int i = 0; i < 47; i++ )
2119 position += direction;
2120 TestMovePan( application, position, time );
2121 time += TestGetFrameInterval();
2122 application.SendNotification();
2123 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2126 TestEndPan( application, position, time );
2127 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2129 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2130 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2131 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2132 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2134 constraintData.Reset();
2138 int UtcDaliPanGesturePredictionSmoothing02(void)
2140 TestApplication application;
2141 Integration::SetPanGesturePredictionMode( 1 );
2142 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2143 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2144 Integration::SetPanGestureSmoothingMode( 1 );
2145 Integration::SetPanGestureSmoothingAmount( 0.25f );
2147 Actor actor = Actor::New();
2148 actor.SetSize(100.0f, 100.0f);
2149 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2150 Stage::GetCurrent().Add(actor);
2152 // Add a pan detector
2153 PanGestureDetector detector = PanGestureDetector::New();
2154 detector.Attach( actor );
2156 GestureReceivedFunctor functor( data );
2157 detector.DetectedSignal().Connect( &application, functor );
2159 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2161 ConstraintData constraintData;
2162 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2163 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2164 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2165 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2166 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2167 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2168 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2169 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2172 // Render and notify
2173 application.SendNotification();
2174 application.Render();
2176 Vector2 startPosition( 2.0f, 2.0f );
2177 Vector2 position( 4.0f, 2.0f );
2178 Vector2 directionX(Vector2::XAXIS);
2179 Vector2 directionY(Vector2::YAXIS);
2180 uint32_t time = 100;
2182 TestStartPan( application, startPosition, position, time );
2184 for(int i = 0; i < 7; i++ )
2186 position += directionX;
2187 TestMovePan( application, position, time );
2188 time += TestGetFrameInterval();
2189 application.SendNotification();
2190 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2193 position += directionX * 10.0f;
2194 TestMovePan( application, position, time );
2195 time += TestGetFrameInterval();
2196 application.SendNotification();
2197 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2199 for(int i = 0; i < 2; i++ )
2201 position += ( directionX * -1.0f );
2202 TestMovePan( application, position, time );
2203 time += TestGetFrameInterval();
2204 application.SendNotification();
2205 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2208 for(int i = 0; i < 10; i++ )
2210 position += directionX;
2211 TestMovePan( application, position, time );
2212 time += TestGetFrameInterval();
2213 application.SendNotification();
2214 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2217 for(int i = 0; i < 10; i++ )
2219 position += directionY;
2220 TestMovePan( application, position, time );
2221 time += TestGetFrameInterval();
2222 application.SendNotification();
2223 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2226 TestEndPan( application, position, time );
2227 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2229 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2230 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2231 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2232 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2234 constraintData.Reset();
2238 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2240 TestApplication application;
2242 Integration::SetPanGesturePredictionMode( 2 );
2243 Integration::SetPanGesturePredictionAmount( 57 );
2244 Integration::SetPanGestureSmoothingMode( 2 );
2245 Integration::SetPanGestureUseActualTimes( false );
2246 Integration::SetPanGestureInterpolationTimeRange( 10 );
2247 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2248 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2249 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2250 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2251 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2252 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2254 Actor actor = Actor::New();
2255 actor.SetSize(100.0f, 100.0f);
2256 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2257 Stage::GetCurrent().Add(actor);
2259 // Add a pan detector
2260 PanGestureDetector detector = PanGestureDetector::New();
2261 detector.Attach( actor );
2263 GestureReceivedFunctor functor( data );
2264 detector.DetectedSignal().Connect( &application, functor );
2266 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2268 ConstraintData constraintData;
2269 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2270 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2271 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2272 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2273 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2274 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2275 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2276 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2279 // Render and notify
2280 application.SendNotification();
2281 application.Render();
2283 Vector2 startPosition( 2.0f, 2.0f );
2284 Vector2 position( -1.0f, 2.0f );
2285 Vector2 direction(Vector2::XAXIS * -1.0f);
2286 uint32_t time = 100;
2288 TestStartPan( application, startPosition, position, time );
2290 for(int i = 0; i < 27; i++ )
2292 position += direction;
2293 TestMovePan( application, position, time );
2294 time += TestGetFrameInterval();
2295 application.SendNotification();
2296 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2299 TestEndPan( application, position, time );
2300 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2302 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2303 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2304 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2305 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2307 constraintData.Reset();
2311 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2313 TestApplication application;
2315 Integration::SetPanGesturePredictionMode( 2 );
2316 Integration::SetPanGestureSmoothingMode( 2 );
2317 Integration::SetPanGestureUseActualTimes( true );
2318 Integration::SetPanGestureInterpolationTimeRange( 10 );
2319 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2320 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2321 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2322 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2323 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2324 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2326 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2328 Actor actor = Actor::New();
2329 actor.SetSize(100.0f, 100.0f);
2330 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2331 Stage::GetCurrent().Add(actor);
2333 // Add a pan detector
2334 PanGestureDetector detector = PanGestureDetector::New();
2335 detector.Attach( actor );
2337 GestureReceivedFunctor functor( data );
2338 detector.DetectedSignal().Connect( &application, functor );
2340 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2342 ConstraintData constraintData;
2343 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2344 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2345 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2346 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2347 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2348 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2349 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2350 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2353 // Render and notify
2354 application.SendNotification();
2355 application.Render();
2357 Vector2 startPosition( 2.0f, 2.0f );
2358 Vector2 position( 17.0f, 2.0f );
2359 Vector2 direction(Vector2::XAXIS * -1.0f);
2360 uint32_t time = 100;
2362 TestStartPan( application, startPosition, position, time );
2364 for(int i = 0; i < 10; i++ )
2366 position += direction;
2367 TestMovePan( application, position, time );
2368 time += TestGetFrameInterval();
2370 position += direction;
2371 TestMovePan( application, position, time );
2372 time += TestGetFrameInterval();
2374 position += direction;
2375 TestMovePan( application, position, time );
2376 time += TestGetFrameInterval();
2378 application.SendNotification();
2379 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2382 for(int i = 0; i < 10; i++ )
2384 application.SendNotification();
2385 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2388 for(int i = 0; i < 10; i++ )
2390 position += direction;
2391 TestMovePan( application, position, time );
2392 application.SendNotification();
2393 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2396 for(int i = 0; i < 10; i++ )
2398 position += direction;
2399 TestMovePan( application, position, time );
2400 time += TestGetFrameInterval();
2401 application.SendNotification();
2402 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2405 TestEndPan( application, position, time );
2406 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2408 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2409 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2410 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2411 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2413 constraintData.Reset();
2417 int UtcDaliPanGesturePrediction2Smoothing(void)
2419 TestApplication application;
2421 Integration::SetPanGesturePredictionMode( 2 );
2422 Integration::SetPanGesturePredictionAmount( 57 );
2423 Integration::SetPanGestureSmoothingMode( 1 );
2424 Integration::SetPanGestureUseActualTimes( false );
2425 Integration::SetPanGestureInterpolationTimeRange( 10 );
2426 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2427 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2428 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2429 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2430 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2431 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2433 Actor actor = Actor::New();
2434 actor.SetSize(100.0f, 100.0f);
2435 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2436 Stage::GetCurrent().Add(actor);
2438 // Add a pan detector
2439 PanGestureDetector detector = PanGestureDetector::New();
2440 detector.Attach( actor );
2442 GestureReceivedFunctor functor( data );
2443 detector.DetectedSignal().Connect( &application, functor );
2445 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2447 ConstraintData constraintData;
2448 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2449 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2450 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2451 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2452 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2453 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2454 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2455 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2458 // Render and notify
2459 application.SendNotification();
2460 application.Render();
2462 Vector2 startPosition( 2.0f, 2.0f );
2463 Vector2 position( 17.0f, 2.0f );
2464 Vector2 direction(Vector2::XAXIS * -1.0f);
2465 uint32_t time = 100;
2467 TestStartPan( application, startPosition, position, time );
2469 for(int i = 0; i < 10; i++ )
2471 position += direction;
2472 TestMovePan( application, position, time );
2473 time += TestGetFrameInterval();
2474 application.SendNotification();
2475 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2479 position += direction;
2480 TestMovePan( application, position, time );
2481 time += TestGetFrameInterval();
2483 position += direction;
2484 TestMovePan( application, position, time );
2485 time += TestGetFrameInterval();
2487 position += direction;
2488 TestMovePan( application, position, time );
2489 time += TestGetFrameInterval();
2491 application.SendNotification();
2492 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2494 for(int i = 0; i < 5; i++ )
2496 application.SendNotification();
2497 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2500 for(int i = 0; i < 10; i++ )
2502 position += direction;
2503 TestMovePan( application, position, time );
2504 time += TestGetFrameInterval();
2505 application.SendNotification();
2506 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2509 TestEndPan( application, position, time );
2510 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2512 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2513 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2514 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2515 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2517 constraintData.Reset();
2521 int UtcDaliPanGestureSetProperties(void)
2523 TestApplication application;
2524 TestRenderController& renderController( application.GetRenderController() );
2525 Integration::SetPanGesturePredictionMode(0);
2526 Integration::SetPanGestureSmoothingMode(0);
2528 Actor actor = Actor::New();
2529 actor.SetSize(100.0f, 100.0f);
2530 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2531 Stage::GetCurrent().Add(actor);
2533 // Add a pan detector
2534 PanGestureDetector detector = PanGestureDetector::New();
2535 detector.Attach( actor );
2537 GestureReceivedFunctor functor( data );
2538 detector.DetectedSignal().Connect( &application, functor );
2540 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2541 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2543 ConstraintData constraintData;
2544 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2545 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2546 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2547 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2548 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2549 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2550 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2551 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2552 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2555 // Render and notify
2556 application.SendNotification();
2557 application.Render();
2559 renderController.Initialize();
2560 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2562 Vector2 screenPosition( 20.0f, 20.0f );
2563 Vector2 screenDisplacement( 1.0f, 1.0f );
2564 Vector2 screenVelocity( 1.3f, 4.0f );
2565 Vector2 localPosition( 21.0f, 21.0f );
2566 Vector2 localDisplacement( 0.5f, 0.5f );
2567 Vector2 localVelocity( 1.5f, 2.5f );
2569 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2570 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2572 // Render and notify
2573 application.SendNotification();
2574 application.Render();
2576 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2577 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2578 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2579 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2580 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2581 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2582 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2583 constraintData.Reset();
2587 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2589 TestApplication application;
2590 Integration::SetPanGesturePredictionMode(0);
2592 Actor actor = Actor::New();
2593 actor.SetSize(100.0f, 100.0f);
2594 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2595 Stage::GetCurrent().Add(actor);
2597 // Add a pan detector
2598 PanGestureDetector detector = PanGestureDetector::New();
2599 detector.Attach( actor );
2601 GestureReceivedFunctor functor( data );
2602 detector.DetectedSignal().Connect( &application, functor );
2604 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2606 ConstraintData constraintData;
2607 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2608 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2609 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2610 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2611 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2612 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2613 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2614 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2617 // Render and notify
2618 application.SendNotification();
2619 application.Render();
2621 Vector2 currentPosition( 20.0f, 4.0f );
2622 uint32_t time = 100;
2623 TestStartPan( application, Vector2( 20.0f, 20.0f ), currentPosition, time );
2624 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2626 Vector2 screenPosition( 100.0f, 20.0f );
2627 Vector2 localPosition( 110.0f, 110.0f );
2629 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2631 // Render and notify
2632 application.SendNotification();
2633 application.Render();
2635 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2636 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2637 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2638 constraintData.Reset();
2642 int UtcDaliPanGesturePropertyIndices(void)
2644 TestApplication application;
2645 PanGestureDetector detector = PanGestureDetector::New();
2647 Property::IndexContainer indices;
2648 detector.GetPropertyIndices( indices );
2649 DALI_TEST_CHECK( indices.Size() );
2650 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2656 struct PropertyStringIndex
2658 const char * const name;
2659 const Property::Index index;
2660 const Property::Type type;
2661 const Property::Value value;
2664 const PropertyStringIndex PROPERTY_TABLE[] =
2666 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2667 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2668 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2669 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2670 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2671 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2672 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2674 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2675 } // unnamed namespace
2678 int UtcDaliPanGestureProperties(void)
2680 TestApplication application;
2681 PanGestureDetector detector = PanGestureDetector::New();
2683 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2685 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2686 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2687 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2688 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2689 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2690 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2691 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2697 int UtcDaliPanGestureGetProperty(void)
2699 TestApplication application;
2700 PanGestureDetector detector = PanGestureDetector::New();
2702 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2704 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2706 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2707 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2709 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2711 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2712 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2719 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2721 TestApplication application;
2723 Actor actor = Actor::New();
2724 actor.SetSize(100.0f, 100.0f);
2725 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2726 Stage::GetCurrent().Add(actor);
2728 // Add a pan detector
2729 PanGestureDetector detector = PanGestureDetector::New();
2730 detector.Attach( actor );
2732 // Render and notify
2733 application.SendNotification();
2734 application.Render();
2736 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2738 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2740 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2742 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2743 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2745 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2747 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2748 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2755 int UtcDaliPanGestureLayerConsumesTouch(void)
2757 TestApplication application;
2759 Actor actor = Actor::New();
2760 actor.SetSize(100.0f, 100.0f);
2761 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2762 Stage::GetCurrent().Add(actor);
2764 // Add a pan detector
2765 PanGestureDetector detector = PanGestureDetector::New();
2766 detector.Attach( actor );
2768 GestureReceivedFunctor functor( data );
2769 detector.DetectedSignal().Connect( &application, functor );
2771 // Add a layer to overlap the actor
2772 Layer layer = Layer::New();
2773 layer.SetSize(100.0f, 100.0f);
2774 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2775 Stage::GetCurrent().Add( layer );
2778 // Render and notify
2779 application.SendNotification();
2780 application.Render();
2782 // Emit signals, should receive
2783 uint32_t time = 100;
2784 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2785 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2786 time += TestGetFrameInterval();
2788 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2791 // Set layer to consume all touch
2792 layer.SetTouchConsumed( true );
2794 // Render and notify
2795 application.SendNotification();
2796 application.Render();
2798 // Emit the same signals again, should not receive
2799 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2800 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2802 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2808 int UtcDaliPanGestureNoTimeDiff(void)
2810 TestApplication application;
2812 Actor actor = Actor::New();
2813 actor.SetSize(100.0f, 100.0f);
2814 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2815 Stage::GetCurrent().Add(actor);
2817 // Add a pan detector
2818 PanGestureDetector detector = PanGestureDetector::New();
2819 detector.Attach( actor );
2821 GestureReceivedFunctor functor( data );
2822 detector.DetectedSignal().Connect( &application, functor );
2824 // Render and notify
2825 application.SendNotification();
2826 application.Render();
2828 // As normal helper function adds intervals between presses we must generate the sequence
2829 // using other helper functions
2830 TestStartLongPress( application, 10.0f, 20.0f, 100 ); // Used to send a down press event
2831 TestMovePan( application, Vector2(26.0f, 20.0f), 100 );
2832 TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); // 2 motions required to trigger
2833 TestEndPan( application, Vector2(26.0f, 20.0f), 100 );
2835 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2836 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2837 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2838 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2839 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );