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 UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1109 TestApplication application;
1111 Actor actor = Actor::New();
1112 actor.SetSize(100.0f, 100.0f);
1113 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1114 Stage::GetCurrent().Add(actor);
1116 // Render and notify
1117 application.SendNotification();
1118 application.Render();
1120 // Attach actor to detector
1122 GestureReceivedFunctor functor( data );
1123 PanGestureDetector detector = PanGestureDetector::New();
1124 detector.Attach(actor);
1125 detector.DetectedSignal().Connect( &application, functor );
1127 // Gesture possible in actor's area.
1128 // application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1129 uint32_t time = 100;
1130 TestStartLongPress( application, 10.0f, 20.0f, time );
1131 time += TestGetFrameInterval();
1133 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1135 // Move actor somewhere else
1136 actor.SetPosition( 100.0f, 100.0f );
1138 // Render and notify
1139 application.SendNotification();
1140 application.Render();
1142 // Emit Started event, we should not receive the long press.
1143 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1144 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1145 time += TestGetFrameInterval();
1147 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1149 // LongPress possible in empty area.
1150 TestStartLongPress( application, 10.0f, 20.0f, time );
1151 time += TestGetFrameInterval();
1153 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1155 // Move actor in to the long press position.
1156 actor.SetPosition( 0.0f, 0.0f );
1158 // Render and notify
1159 application.SendNotification();
1160 application.Render();
1162 // Emit Started event, we should not receive the long press.
1163 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1164 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1165 time += TestGetFrameInterval();
1167 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1169 // Normal long press in actor's area for completeness.
1170 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1171 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1172 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1176 int UtcDaliPanGestureActorUnstaged(void)
1178 TestApplication application;
1180 Actor actor = Actor::New();
1181 actor.SetSize(100.0f, 100.0f);
1182 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1183 Stage::GetCurrent().Add(actor);
1185 // Render and notify
1186 application.SendNotification();
1187 application.Render();
1189 // State to remove actor in.
1190 Gesture::State stateToUnstage( Gesture::Started );
1192 // Attach actor to detector
1194 UnstageActorFunctor functor( data, stateToUnstage );
1195 PanGestureDetector detector = PanGestureDetector::New();
1196 detector.Attach(actor);
1197 detector.DetectedSignal().Connect( &application, functor );
1200 uint32_t time = 100;
1201 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1203 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1206 TestEndPan( application, Vector2(26.0f, 20.0f), time );
1208 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1211 // Render and notify
1212 application.SendNotification();
1213 application.Render();
1215 // Re-add actor to stage
1216 Stage::GetCurrent().Add(actor);
1218 // Render and notify
1219 application.SendNotification();
1220 application.Render();
1222 // Change state to Gesture::Continuing to remove
1223 stateToUnstage = Gesture::Continuing;
1226 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1228 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1231 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1232 time += TestGetFrameInterval();
1234 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1238 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1240 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1243 // Render and notify
1244 application.SendNotification();
1245 application.Render();
1247 // Re-add actor to stage
1248 Stage::GetCurrent().Add(actor);
1250 // Render and notify
1251 application.SendNotification();
1252 application.Render();
1254 // Change state to Gesture::Finished to remove
1255 stateToUnstage = Gesture::Finished;
1258 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1260 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1263 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1264 time += TestGetFrameInterval();
1266 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1269 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1271 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1272 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1276 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1278 TestApplication application;
1280 Actor actor = Actor::New();
1281 actor.SetSize(100.0f, 100.0f);
1282 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1283 Stage::GetCurrent().Add(actor);
1285 // Create and add a second actor so that GestureDetector destruction does not come into play.
1286 Actor dummyActor( Actor::New() );
1287 dummyActor.SetSize( 100.0f, 100.0f );
1288 dummyActor.SetPosition( 100.0f, 100.0f );
1289 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1290 Stage::GetCurrent().Add(dummyActor);
1292 // Render and notify
1293 application.SendNotification();
1294 application.Render();
1296 // State to remove actor in.
1297 Gesture::State stateToUnstage( Gesture::Started );
1299 // Attach actor to detector
1301 UnstageActorFunctor functor( data, stateToUnstage );
1302 PanGestureDetector detector = PanGestureDetector::New();
1303 detector.Attach(actor);
1304 detector.Attach(dummyActor);
1305 detector.DetectedSignal().Connect( &application, functor );
1307 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1308 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1309 // position, we should still not be signalled.
1312 uint32_t time = 100;
1313 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1315 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1318 // Render and notify
1319 application.SendNotification();
1320 application.Render();
1322 // Re add to the stage, we should not be signalled
1323 Stage::GetCurrent().Add(actor);
1325 // Render and notify
1326 application.SendNotification();
1327 application.Render();
1329 // Continue signal emission
1330 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1331 time += TestGetFrameInterval();
1333 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1336 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1337 time += TestGetFrameInterval();
1339 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1342 // Here we delete an actor in started, we should not receive any subsequent signalling.
1345 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1347 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1350 // Render and notify
1351 application.SendNotification();
1352 application.Render();
1354 // Delete actor as well
1357 // Render and notify
1358 application.SendNotification();
1359 application.Render();
1361 // Continue signal emission
1362 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1363 time += TestGetFrameInterval();
1365 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1368 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1370 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1374 int UtcDaliPanGestureAngleHandling(void)
1376 TestApplication application;
1378 PanGestureDetector detector = PanGestureDetector::New();
1379 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1381 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1382 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1384 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1386 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1388 tet_result( TET_PASS );
1396 tet_printf("%s, angle not added\n", TEST_LOCATION );
1397 tet_result( TET_FAIL );
1400 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1401 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1403 // Remove something not in the container.
1404 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1405 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1407 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1408 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1409 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1411 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1413 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1414 tet_result( TET_FAIL );
1419 detector.ClearAngles();
1420 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1424 int UtcDaliPanGestureGetAngle(void)
1426 TestApplication application;
1428 PanGestureDetector detector = PanGestureDetector::New();
1429 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1431 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1432 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1434 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1435 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1437 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1438 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1440 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1441 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1443 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1444 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1445 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1446 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1451 inline float RadiansToDegrees( float radian )
1453 return radian * 180.0f / Math::PI;
1456 int UtcDaliPanGestureAngleOutOfRange(void)
1458 TestApplication application;
1460 PanGestureDetector detector = PanGestureDetector::New();
1461 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1467 detector.AddAngle( Degree(180.0f) );
1468 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1469 detector.ClearAngles();
1471 detector.AddAngle( Degree(190.0f) );
1472 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1473 detector.ClearAngles();
1475 detector.AddAngle( Degree(-190.0f) );
1476 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1477 detector.ClearAngles();
1479 detector.AddAngle( Degree(350.0f) );
1480 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1481 detector.ClearAngles();
1483 detector.AddAngle( Degree(-350.0f) );
1484 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1485 detector.ClearAngles();
1487 detector.AddAngle( Degree(370.0f) );
1488 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1489 detector.ClearAngles();
1491 detector.AddAngle( Degree(-370.0f) );
1492 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1493 detector.ClearAngles();
1499 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1500 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1501 detector.ClearAngles();
1503 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1504 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1505 detector.ClearAngles();
1507 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1508 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1509 detector.ClearAngles();
1511 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1512 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1513 detector.ClearAngles();
1517 int UtcDaliPanGestureAngleProcessing(void)
1519 TestApplication application;
1521 Actor parent = Actor::New();
1522 parent.SetSize(100.0f, 100.0f);
1523 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1524 Stage::GetCurrent().Add(parent);
1526 Actor child = Actor::New();
1527 child.SetSize(100.0f, 100.0f);
1528 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1531 // Render and notify
1532 application.SendNotification();
1533 application.Render();
1535 // Parent detector only requires up pans
1536 PanGestureDetector parentDetector = PanGestureDetector::New();
1537 parentDetector.Attach( parent );
1538 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1539 SignalData parentData;
1540 GestureReceivedFunctor parentFunctor(parentData);
1541 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1543 // Child detector only requires right pans
1544 PanGestureDetector childDetector = PanGestureDetector::New();
1545 childDetector.Attach( child );
1546 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1547 SignalData childData;
1548 GestureReceivedFunctor childFunctor(childData);
1549 childDetector.DetectedSignal().Connect(&application, childFunctor);
1551 // Generate an Up pan gesture, only parent should receive it.
1552 uint32_t time = 100;
1553 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1555 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1556 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1558 TestEndPan( application, Vector2(20.0f, 4.0f), time );
1559 time += TestGetFrameInterval();
1563 // Generate a Right pan gesture, only child should receive it.
1564 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1566 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1567 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1569 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1570 time += TestGetFrameInterval();
1574 // Generate a Down pan gesture, no one should receive it.
1575 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1577 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1578 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1580 TestEndPan( application, Vector2(20.0f, 36.0f), time );
1581 time += TestGetFrameInterval();
1585 // Generate a Left pan gesture, no one should receive it.
1586 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1588 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1589 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1591 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1597 int UtcDaliPanGestureDirectionHandling(void)
1599 TestApplication application;
1601 PanGestureDetector detector = PanGestureDetector::New();
1602 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1604 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1605 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1607 for ( size_t i = 0; detector.GetAngleCount(); i++)
1609 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1611 tet_result( TET_PASS );
1620 tet_printf("%s, angle not added\n", TEST_LOCATION );
1621 tet_result( TET_FAIL );
1625 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1627 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1629 tet_result( TET_PASS );
1637 tet_printf("%s, angle not added\n", TEST_LOCATION );
1638 tet_result( TET_FAIL );
1641 // Remove something not in the container.
1642 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1643 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1645 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1646 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1650 int UtcDaliPanGestureDirectionProcessing(void)
1652 TestApplication application;
1654 Actor parent = Actor::New();
1655 parent.SetSize(100.0f, 100.0f);
1656 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1657 Stage::GetCurrent().Add(parent);
1659 Actor child = Actor::New();
1660 child.SetSize(100.0f, 100.0f);
1661 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1664 // Render and notify
1665 application.SendNotification();
1666 application.Render();
1668 // Parent detector only requires vertical panning
1669 PanGestureDetector parentDetector = PanGestureDetector::New();
1670 parentDetector.Attach( parent );
1671 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1672 SignalData parentData;
1673 GestureReceivedFunctor parentFunctor(parentData);
1674 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1676 // Child detector only requires horizontal panning
1677 PanGestureDetector childDetector = PanGestureDetector::New();
1678 childDetector.Attach( child );
1679 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1680 SignalData childData;
1681 GestureReceivedFunctor childFunctor(childData);
1682 childDetector.DetectedSignal().Connect(&application, childFunctor);
1684 // Generate an Up pan gesture, only parent should receive it.
1685 uint32_t time = 100;
1686 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1688 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1689 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1691 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1692 time += TestGetFrameInterval();
1696 // Generate a Right pan gesture, only child should receive it.
1697 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1699 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1700 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1702 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1703 time += TestGetFrameInterval();
1707 // Generate a Down pan gesture, only parent should receive it.
1708 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1710 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1711 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1713 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1714 time += TestGetFrameInterval();
1718 // Generate a Left pan gesture, only child should receive it.
1719 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1721 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1722 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1724 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1725 time += TestGetFrameInterval();
1729 // Generate a pan at -45 degrees, no one should receive it.
1730 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 9.0f, 31.0f ), time );
1732 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1733 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1735 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1736 time += TestGetFrameInterval();
1740 // Generate a pan at 45 degrees, no one should receive it.
1741 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 31.0f, 31.0f ), time );
1743 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1744 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1746 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1747 time += TestGetFrameInterval();
1751 // Generate a pan at -135 degrees, no one should receive it.
1752 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 4.0f ), time );
1754 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1755 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1757 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1763 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1765 TestApplication application;
1766 Integration::SetPanGesturePredictionMode(0);
1767 Integration::SetPanGestureSmoothingMode(0);
1769 Actor actor = Actor::New();
1770 actor.SetSize(100.0f, 100.0f);
1771 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1772 Stage::GetCurrent().Add(actor);
1774 // Add a pan detector
1775 PanGestureDetector detector = PanGestureDetector::New();
1776 detector.Attach( actor );
1778 GestureReceivedFunctor functor( data );
1779 detector.DetectedSignal().Connect( &application, functor );
1781 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1783 ConstraintData constraintData;
1784 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1785 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1786 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1787 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1788 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1789 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1790 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1791 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1794 // Render and notify
1795 application.SendNotification();
1796 application.Render();
1798 Vector2 startPosition( 1.0f, 1.0f );
1799 Vector2 position( -14.0f, 1.0f );
1800 Vector2 direction(Vector2::XAXIS * -5.0f);
1801 uint32_t time = 100;
1803 TestStartPan( application, startPosition, position, time );
1805 for(int i = 0; i < 47; i++ )
1807 position += direction;
1808 TestMovePan( application, position, time );
1809 time += TestGetFrameInterval();
1810 application.SendNotification();
1811 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1814 TestEndPan( application, position, time );
1815 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1817 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1818 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1819 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1820 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1822 constraintData.Reset();
1826 int UtcDaliPanGestureNoPredictionSmoothing(void)
1828 TestApplication application;
1829 Integration::SetPanGesturePredictionMode(0);
1830 Integration::SetPanGestureSmoothingMode(1);
1832 Actor actor = Actor::New();
1833 actor.SetSize(100.0f, 100.0f);
1834 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1835 Stage::GetCurrent().Add(actor);
1837 // Add a pan detector
1838 PanGestureDetector detector = PanGestureDetector::New();
1839 detector.Attach( actor );
1841 GestureReceivedFunctor functor( data );
1842 detector.DetectedSignal().Connect( &application, functor );
1844 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1846 ConstraintData constraintData;
1847 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1848 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1849 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1850 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1851 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1852 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1853 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1854 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1857 // Render and notify
1858 application.SendNotification();
1859 application.Render();
1861 Vector2 startPosition( 1.0f, 1.0f );
1862 Vector2 position( -14.0f, 1.0f );
1863 Vector2 direction(Vector2::XAXIS * -5.0f);
1864 uint32_t time = 100;
1866 TestStartPan( application, startPosition, position, time );
1868 for(int i = 0; i < 47; i++ )
1870 position += direction;
1871 TestMovePan( application, position, time );
1872 time += TestGetFrameInterval();
1873 application.SendNotification();
1874 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1877 TestEndPan( application, position, time );
1878 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1880 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1881 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1882 // Take into account resampling done when prediction is off.
1883 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
1884 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
1886 constraintData.Reset();
1890 int UtcDaliPanGesturePredictionNoSmoothing(void)
1892 TestApplication application;
1893 Integration::SetPanGesturePredictionMode(1);
1894 Integration::SetPanGestureSmoothingMode(0);
1896 Actor actor = Actor::New();
1897 actor.SetSize(100.0f, 100.0f);
1898 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1899 Stage::GetCurrent().Add(actor);
1901 // Add a pan detector
1902 PanGestureDetector detector = PanGestureDetector::New();
1903 detector.Attach( actor );
1905 GestureReceivedFunctor functor( data );
1906 detector.DetectedSignal().Connect( &application, functor );
1908 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1910 ConstraintData constraintData;
1911 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1912 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1913 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1914 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1915 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1916 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1917 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1918 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1921 // Render and notify
1922 application.SendNotification();
1923 application.Render();
1925 Vector2 startPosition( 1.0f, 1.0f );
1926 Vector2 position( -1.0f, 1.0f );
1927 Vector2 direction(Vector2::XAXIS * -1.0f);
1928 uint32_t time = 100;
1930 TestStartPan( application, startPosition, position, time );
1932 for(int i = 0; i < 47; i++ )
1934 position += direction;
1935 TestMovePan( application, position, time );
1936 time += TestGetFrameInterval();
1937 application.SendNotification();
1938 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1941 TestEndPan( application, position, time );
1942 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1944 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1945 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1946 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
1947 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
1949 constraintData.Reset();
1953 int UtcDaliPanGesturePredictionSmoothing01(void)
1955 TestApplication application;
1956 Integration::SetPanGesturePredictionMode(1);
1957 Integration::SetPanGestureSmoothingMode(1);
1959 Actor actor = Actor::New();
1960 actor.SetSize(100.0f, 100.0f);
1961 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1962 Stage::GetCurrent().Add(actor);
1964 // Add a pan detector
1965 PanGestureDetector detector = PanGestureDetector::New();
1966 detector.Attach( actor );
1968 GestureReceivedFunctor functor( data );
1969 detector.DetectedSignal().Connect( &application, functor );
1971 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1973 ConstraintData constraintData;
1974 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1975 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1976 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1977 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1978 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1979 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1980 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1981 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1984 // Render and notify
1985 application.SendNotification();
1986 application.Render();
1988 Vector2 startPosition( 1.0f, 1.0f );
1989 Vector2 position( -1.0f, 1.0f );
1990 Vector2 direction(Vector2::XAXIS * -1.0f);
1991 uint32_t time = 100;
1993 TestStartPan( application, startPosition, position, time );
1995 for(int i = 0; i < 47; i++ )
1997 position += direction;
1998 TestMovePan( application, position, time );
1999 time += TestGetFrameInterval();
2000 application.SendNotification();
2001 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2004 TestEndPan( application, position, time );
2005 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2007 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2008 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2009 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2010 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2012 constraintData.Reset();
2016 int UtcDaliPanGesturePredictionSmoothing02(void)
2018 TestApplication application;
2019 Integration::SetPanGesturePredictionMode( 1 );
2020 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2021 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2022 Integration::SetPanGestureSmoothingMode( 1 );
2023 Integration::SetPanGestureSmoothingAmount( 0.25f );
2025 Actor actor = Actor::New();
2026 actor.SetSize(100.0f, 100.0f);
2027 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2028 Stage::GetCurrent().Add(actor);
2030 // Add a pan detector
2031 PanGestureDetector detector = PanGestureDetector::New();
2032 detector.Attach( actor );
2034 GestureReceivedFunctor functor( data );
2035 detector.DetectedSignal().Connect( &application, functor );
2037 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2039 ConstraintData constraintData;
2040 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2041 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2042 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2043 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2044 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2045 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2046 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2047 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2050 // Render and notify
2051 application.SendNotification();
2052 application.Render();
2054 Vector2 startPosition( 2.0f, 2.0f );
2055 Vector2 position( 4.0f, 2.0f );
2056 Vector2 directionX(Vector2::XAXIS);
2057 Vector2 directionY(Vector2::YAXIS);
2058 uint32_t time = 100;
2060 TestStartPan( application, startPosition, position, time );
2062 for(int i = 0; i < 7; i++ )
2064 position += directionX;
2065 TestMovePan( application, position, time );
2066 time += TestGetFrameInterval();
2067 application.SendNotification();
2068 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2071 position += directionX * 10.0f;
2072 TestMovePan( application, position, time );
2073 time += TestGetFrameInterval();
2074 application.SendNotification();
2075 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2077 for(int i = 0; i < 2; i++ )
2079 position += ( directionX * -1.0f );
2080 TestMovePan( application, position, time );
2081 time += TestGetFrameInterval();
2082 application.SendNotification();
2083 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2086 for(int i = 0; i < 10; i++ )
2088 position += directionX;
2089 TestMovePan( application, position, time );
2090 time += TestGetFrameInterval();
2091 application.SendNotification();
2092 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2095 for(int i = 0; i < 10; i++ )
2097 position += directionY;
2098 TestMovePan( application, position, time );
2099 time += TestGetFrameInterval();
2100 application.SendNotification();
2101 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2104 TestEndPan( application, position, time );
2105 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2107 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2108 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2109 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2110 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2112 constraintData.Reset();
2116 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2118 TestApplication application;
2120 Integration::SetPanGesturePredictionMode( 2 );
2121 Integration::SetPanGesturePredictionAmount( 57 );
2122 Integration::SetPanGestureSmoothingMode( 2 );
2123 Integration::SetPanGestureUseActualTimes( false );
2124 Integration::SetPanGestureInterpolationTimeRange( 10 );
2125 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2126 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2127 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2128 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2129 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2130 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2132 Actor actor = Actor::New();
2133 actor.SetSize(100.0f, 100.0f);
2134 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2135 Stage::GetCurrent().Add(actor);
2137 // Add a pan detector
2138 PanGestureDetector detector = PanGestureDetector::New();
2139 detector.Attach( actor );
2141 GestureReceivedFunctor functor( data );
2142 detector.DetectedSignal().Connect( &application, functor );
2144 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2146 ConstraintData constraintData;
2147 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2148 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2149 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2150 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2151 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2152 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2153 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2154 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2157 // Render and notify
2158 application.SendNotification();
2159 application.Render();
2161 Vector2 startPosition( 2.0f, 2.0f );
2162 Vector2 position( -1.0f, 2.0f );
2163 Vector2 direction(Vector2::XAXIS * -1.0f);
2164 uint32_t time = 100;
2166 TestStartPan( application, startPosition, position, time );
2168 for(int i = 0; i < 27; i++ )
2170 position += direction;
2171 TestMovePan( application, position, time );
2172 time += TestGetFrameInterval();
2173 application.SendNotification();
2174 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2177 TestEndPan( application, position, time );
2178 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2180 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2181 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2182 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2183 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2185 constraintData.Reset();
2189 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2191 TestApplication application;
2193 Integration::SetPanGesturePredictionMode( 2 );
2194 Integration::SetPanGestureSmoothingMode( 2 );
2195 Integration::SetPanGestureUseActualTimes( true );
2196 Integration::SetPanGestureInterpolationTimeRange( 10 );
2197 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2198 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2199 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2200 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2201 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2202 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2204 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2206 Actor actor = Actor::New();
2207 actor.SetSize(100.0f, 100.0f);
2208 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2209 Stage::GetCurrent().Add(actor);
2211 // Add a pan detector
2212 PanGestureDetector detector = PanGestureDetector::New();
2213 detector.Attach( actor );
2215 GestureReceivedFunctor functor( data );
2216 detector.DetectedSignal().Connect( &application, functor );
2218 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2220 ConstraintData constraintData;
2221 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2222 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2223 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2224 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2225 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2226 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2227 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2228 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2231 // Render and notify
2232 application.SendNotification();
2233 application.Render();
2235 Vector2 startPosition( 2.0f, 2.0f );
2236 Vector2 position( 17.0f, 2.0f );
2237 Vector2 direction(Vector2::XAXIS * -1.0f);
2238 uint32_t time = 100;
2240 TestStartPan( application, startPosition, position, time );
2242 for(int i = 0; i < 10; i++ )
2244 position += direction;
2245 TestMovePan( application, position, time );
2246 time += TestGetFrameInterval();
2248 position += direction;
2249 TestMovePan( application, position, time );
2250 time += TestGetFrameInterval();
2252 position += direction;
2253 TestMovePan( application, position, time );
2254 time += TestGetFrameInterval();
2256 application.SendNotification();
2257 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2260 for(int i = 0; i < 10; i++ )
2262 application.SendNotification();
2263 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2266 for(int i = 0; i < 10; i++ )
2268 position += direction;
2269 TestMovePan( application, position, time );
2270 application.SendNotification();
2271 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2274 for(int i = 0; i < 10; i++ )
2276 position += direction;
2277 TestMovePan( application, position, time );
2278 time += TestGetFrameInterval();
2279 application.SendNotification();
2280 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2283 TestEndPan( application, position, time );
2284 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2286 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2287 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2288 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2289 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2291 constraintData.Reset();
2295 int UtcDaliPanGesturePrediction2Smoothing(void)
2297 TestApplication application;
2299 Integration::SetPanGesturePredictionMode( 2 );
2300 Integration::SetPanGesturePredictionAmount( 57 );
2301 Integration::SetPanGestureSmoothingMode( 1 );
2302 Integration::SetPanGestureUseActualTimes( false );
2303 Integration::SetPanGestureInterpolationTimeRange( 10 );
2304 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2305 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2306 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2307 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2308 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2309 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2311 Actor actor = Actor::New();
2312 actor.SetSize(100.0f, 100.0f);
2313 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2314 Stage::GetCurrent().Add(actor);
2316 // Add a pan detector
2317 PanGestureDetector detector = PanGestureDetector::New();
2318 detector.Attach( actor );
2320 GestureReceivedFunctor functor( data );
2321 detector.DetectedSignal().Connect( &application, functor );
2323 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2325 ConstraintData constraintData;
2326 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2327 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2328 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2329 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2330 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2331 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2332 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2333 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2336 // Render and notify
2337 application.SendNotification();
2338 application.Render();
2340 Vector2 startPosition( 2.0f, 2.0f );
2341 Vector2 position( 17.0f, 2.0f );
2342 Vector2 direction(Vector2::XAXIS * -1.0f);
2343 uint32_t time = 100;
2345 TestStartPan( application, startPosition, position, time );
2347 for(int i = 0; i < 10; i++ )
2349 position += direction;
2350 TestMovePan( application, position, time );
2351 time += TestGetFrameInterval();
2352 application.SendNotification();
2353 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2357 position += direction;
2358 TestMovePan( application, position, time );
2359 time += TestGetFrameInterval();
2361 position += direction;
2362 TestMovePan( application, position, time );
2363 time += TestGetFrameInterval();
2365 position += direction;
2366 TestMovePan( application, position, time );
2367 time += TestGetFrameInterval();
2369 application.SendNotification();
2370 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2372 for(int i = 0; i < 5; i++ )
2374 application.SendNotification();
2375 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2378 for(int i = 0; i < 10; i++ )
2380 position += direction;
2381 TestMovePan( application, position, time );
2382 time += TestGetFrameInterval();
2383 application.SendNotification();
2384 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2387 TestEndPan( application, position, time );
2388 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2390 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2391 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2392 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2393 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2395 constraintData.Reset();
2399 int UtcDaliPanGestureSetProperties(void)
2401 TestApplication application;
2402 TestRenderController& renderController( application.GetRenderController() );
2403 Integration::SetPanGesturePredictionMode(0);
2404 Integration::SetPanGestureSmoothingMode(0);
2406 Actor actor = Actor::New();
2407 actor.SetSize(100.0f, 100.0f);
2408 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2409 Stage::GetCurrent().Add(actor);
2411 // Add a pan detector
2412 PanGestureDetector detector = PanGestureDetector::New();
2413 detector.Attach( actor );
2415 GestureReceivedFunctor functor( data );
2416 detector.DetectedSignal().Connect( &application, functor );
2418 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2419 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2421 ConstraintData constraintData;
2422 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2423 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2424 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2425 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2426 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2427 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2428 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2429 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2430 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2433 // Render and notify
2434 application.SendNotification();
2435 application.Render();
2437 renderController.Initialize();
2438 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2440 Vector2 screenPosition( 20.0f, 20.0f );
2441 Vector2 screenDisplacement( 1.0f, 1.0f );
2442 Vector2 screenVelocity( 1.3f, 4.0f );
2443 Vector2 localPosition( 21.0f, 21.0f );
2444 Vector2 localDisplacement( 0.5f, 0.5f );
2445 Vector2 localVelocity( 1.5f, 2.5f );
2447 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2448 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2450 // Render and notify
2451 application.SendNotification();
2452 application.Render();
2454 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2455 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2456 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2457 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2458 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2459 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2460 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2461 constraintData.Reset();
2465 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2467 TestApplication application;
2468 Integration::SetPanGesturePredictionMode(0);
2470 Actor actor = Actor::New();
2471 actor.SetSize(100.0f, 100.0f);
2472 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2473 Stage::GetCurrent().Add(actor);
2475 // Add a pan detector
2476 PanGestureDetector detector = PanGestureDetector::New();
2477 detector.Attach( actor );
2479 GestureReceivedFunctor functor( data );
2480 detector.DetectedSignal().Connect( &application, functor );
2482 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2484 ConstraintData constraintData;
2485 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2486 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2487 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2488 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2489 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2490 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2491 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2492 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2495 // Render and notify
2496 application.SendNotification();
2497 application.Render();
2499 Vector2 currentPosition( 20.0f, 4.0f );
2500 uint32_t time = 100;
2501 TestStartPan( application, Vector2( 20.0f, 20.0f ), currentPosition, time );
2502 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2504 Vector2 screenPosition( 100.0f, 20.0f );
2505 Vector2 localPosition( 110.0f, 110.0f );
2507 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2509 // Render and notify
2510 application.SendNotification();
2511 application.Render();
2513 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2514 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2515 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2516 constraintData.Reset();
2520 int UtcDaliPanGesturePropertyIndices(void)
2522 TestApplication application;
2523 PanGestureDetector detector = PanGestureDetector::New();
2525 Property::IndexContainer indices;
2526 detector.GetPropertyIndices( indices );
2527 DALI_TEST_CHECK( indices.Size() );
2528 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2534 struct PropertyStringIndex
2536 const char * const name;
2537 const Property::Index index;
2538 const Property::Type type;
2539 const Property::Value value;
2542 const PropertyStringIndex PROPERTY_TABLE[] =
2544 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2545 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2546 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2547 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2548 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2549 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2550 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2552 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2553 } // unnamed namespace
2556 int UtcDaliPanGestureProperties(void)
2558 TestApplication application;
2559 PanGestureDetector detector = PanGestureDetector::New();
2561 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2563 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2564 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2565 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2566 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2567 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2568 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2569 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2575 int UtcDaliPanGestureGetProperty(void)
2577 TestApplication application;
2578 PanGestureDetector detector = PanGestureDetector::New();
2580 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2582 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2584 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2585 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2587 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2589 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2590 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2597 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2599 TestApplication application;
2601 Actor actor = Actor::New();
2602 actor.SetSize(100.0f, 100.0f);
2603 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2604 Stage::GetCurrent().Add(actor);
2606 // Add a pan detector
2607 PanGestureDetector detector = PanGestureDetector::New();
2608 detector.Attach( actor );
2610 // Render and notify
2611 application.SendNotification();
2612 application.Render();
2614 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2616 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2618 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2620 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2621 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2623 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2625 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2626 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2633 int UtcDaliPanGestureLayerConsumesTouch(void)
2635 TestApplication application;
2637 Actor actor = Actor::New();
2638 actor.SetSize(100.0f, 100.0f);
2639 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2640 Stage::GetCurrent().Add(actor);
2642 // Add a pan detector
2643 PanGestureDetector detector = PanGestureDetector::New();
2644 detector.Attach( actor );
2646 GestureReceivedFunctor functor( data );
2647 detector.DetectedSignal().Connect( &application, functor );
2649 // Add a layer to overlap the actor
2650 Layer layer = Layer::New();
2651 layer.SetSize(100.0f, 100.0f);
2652 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2653 Stage::GetCurrent().Add( layer );
2656 // Render and notify
2657 application.SendNotification();
2658 application.Render();
2660 // Emit signals, should receive
2661 uint32_t time = 100;
2662 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2663 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2664 time += TestGetFrameInterval();
2666 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2669 // Set layer to consume all touch
2670 layer.SetTouchConsumed( true );
2672 // Render and notify
2673 application.SendNotification();
2674 application.Render();
2676 // Emit the same signals again, should not receive
2677 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2678 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2680 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2686 int UtcDaliPanGestureNoTimeDiff(void)
2688 TestApplication application;
2690 Actor actor = Actor::New();
2691 actor.SetSize(100.0f, 100.0f);
2692 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2693 Stage::GetCurrent().Add(actor);
2695 // Add a pan detector
2696 PanGestureDetector detector = PanGestureDetector::New();
2697 detector.Attach( actor );
2699 GestureReceivedFunctor functor( data );
2700 detector.DetectedSignal().Connect( &application, functor );
2702 // Render and notify
2703 application.SendNotification();
2704 application.Render();
2706 // As normal helper function adds intervals between presses we must generate the sequence
2707 // using other helper functions
2708 TestStartLongPress( application, 10.0f, 20.0f, 100 ); // Used to send a down press event
2709 TestMovePan( application, Vector2(26.0f, 20.0f), 100 );
2710 TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); // 2 motions required to trigger
2711 TestEndPan( application, Vector2(26.0f, 20.0f), 100 );
2713 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2714 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2715 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2716 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2717 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );