2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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, Integration::Scene scene )
102 : GestureReceivedFunctor( data ),
103 stateToUnstage( stateToUnstage ),
108 void operator()( Actor actor, const PanGesture& pan )
110 GestureReceivedFunctor::operator()( actor, pan );
112 if ( pan.state == stateToUnstage )
114 scene.Remove( actor );
118 Gesture::State& stateToUnstage;
119 Integration::Scene scene;
122 // Functor for receiving a touch event
123 struct TouchEventFunctor
125 bool operator()(Actor actor, const TouchEvent& touch)
131 // Data for constraints
132 struct ConstraintData
140 Vector2 screenPosition;
141 Vector2 screenDisplacement;
142 Vector2 screenVelocity;
143 Vector2 localPosition;
144 Vector2 localDisplacement;
145 Vector2 localVelocity;
151 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
157 // Constraint used with panning properties
160 PanConstraint( ConstraintData& data ) : constraintData(data) { }
162 void operator()( Vector3& current, const PropertyInputContainer& inputs )
164 constraintData.screenPosition = inputs[0]->GetVector2();
165 constraintData.screenDisplacement = inputs[1]->GetVector2();
166 constraintData.screenVelocity = inputs[2]->GetVector2();
167 constraintData.localPosition = inputs[3]->GetVector2();
168 constraintData.localDisplacement = inputs[4]->GetVector2();
169 constraintData.localVelocity = inputs[5]->GetVector2();
170 constraintData.panning = inputs[6]->GetBoolean();
171 constraintData.called = true;
172 current = Vector3::ZERO;
175 ConstraintData& constraintData;
178 // Generate a PanGesture
179 PanGesture GeneratePan( unsigned int time,
180 Gesture::State state,
181 Vector2 screenPosition,
182 Vector2 localPosition,
183 Vector2 screenDisplacement = Vector2::ONE,
184 Vector2 localDisplacement = Vector2::ONE,
185 Vector2 screenVelocity = Vector2::ONE,
186 Vector2 localVelocity = Vector2::ONE,
187 unsigned int numberOfTouches = 1 )
189 PanGesture pan( state );
193 pan.screenPosition = screenPosition;
194 pan.position = localPosition;
196 pan.screenDisplacement = screenDisplacement;
197 pan.displacement = localDisplacement;
199 pan.screenVelocity = screenVelocity;
200 pan.velocity = localVelocity;
202 pan.numberOfTouches = numberOfTouches;
209 ///////////////////////////////////////////////////////////////////////////////
211 // Positive test case for a method
212 int UtcDaliPanGestureDetectorConstructor(void)
214 TestApplication application;
216 PanGestureDetector detector;
217 DALI_TEST_CHECK(!detector);
221 int UtcDaliPanGestureDetectorCopyConstructorP(void)
223 TestApplication application;
225 PanGestureDetector detector = PanGestureDetector::New();
227 PanGestureDetector copy( detector );
228 DALI_TEST_CHECK( detector );
232 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
234 TestApplication application;
236 PanGestureDetector detector = PanGestureDetector::New();
238 PanGestureDetector assign;
240 DALI_TEST_CHECK( detector );
242 DALI_TEST_CHECK( detector == assign );
246 // Negative test case for a method
247 int UtcDaliPanGestureDetectorNew(void)
249 TestApplication application;
251 PanGestureDetector detector = PanGestureDetector::New();
253 DALI_TEST_CHECK(detector);
255 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
256 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
258 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
259 Actor actor = Actor::New();
260 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
261 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
262 detector.Attach(actor);
264 application.GetScene().Add(actor);
267 application.SendNotification();
268 application.Render();
270 // Use long press function for touch event
271 TestStartLongPress( application );
276 int UtcDaliPanGestureDetectorDownCast(void)
278 TestApplication application;
279 tet_infoline("Testing Dali::GestureDetector::DownCast()");
281 PanGestureDetector detector = PanGestureDetector::New();
283 BaseHandle object(detector);
285 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
286 DALI_TEST_CHECK(detector2);
288 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
289 DALI_TEST_CHECK(detector3);
291 BaseHandle unInitializedObject;
292 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
293 DALI_TEST_CHECK(!detector4);
295 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
296 DALI_TEST_CHECK(!detector5);
298 GestureDetector detector6 = PanGestureDetector::New();
299 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
300 DALI_TEST_CHECK(detector7);
304 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
306 TestApplication application;
308 PanGestureDetector detector = PanGestureDetector::New();
310 unsigned int min = 2;
312 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
314 detector.SetMinimumTouchesRequired(min);
316 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
318 // Attach an actor and change the minimum touches
320 Actor actor = Actor::New();
321 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
322 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
323 application.GetScene().Add(actor);
326 application.SendNotification();
327 application.Render();
330 GestureReceivedFunctor functor(data);
332 detector.Attach(actor);
333 detector.DetectedSignal().Connect(&application, functor);
335 detector.SetMinimumTouchesRequired(3);
337 // Create a second gesture detector that requires even less minimum touches
338 PanGestureDetector secondDetector = PanGestureDetector::New();
339 secondDetector.Attach(actor);
341 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
346 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
348 TestApplication application;
350 PanGestureDetector detector = PanGestureDetector::New();
352 unsigned int max = 3;
354 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
356 detector.SetMaximumTouchesRequired(max);
358 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
360 // Attach an actor and change the maximum touches
362 Actor actor = Actor::New();
363 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
364 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
365 application.GetScene().Add(actor);
368 application.SendNotification();
369 application.Render();
372 GestureReceivedFunctor functor(data);
374 detector.Attach(actor);
375 detector.DetectedSignal().Connect(&application, functor);
377 detector.SetMaximumTouchesRequired(4);
379 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
384 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
386 TestApplication application;
388 PanGestureDetector detector = PanGestureDetector::New();
389 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
393 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
395 TestApplication application;
397 PanGestureDetector detector = PanGestureDetector::New();
398 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
402 int UtcDaliPanGestureSignalReceptionNegative(void)
404 TestApplication application;
406 Actor actor = Actor::New();
407 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
408 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
409 application.GetScene().Add(actor);
412 application.SendNotification();
413 application.Render();
416 GestureReceivedFunctor functor(data);
418 PanGestureDetector detector = PanGestureDetector::New();
419 detector.Attach(actor);
420 detector.DetectedSignal().Connect(&application, functor);
422 // Do a pan outside actor's area
424 TestStartPan( application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time );
426 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
428 // Continue pan into actor's area - we should still not receive the signal
430 TestMovePan( application, Vector2(20.0f, 20.0f), time );
432 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
434 // Stop panning - we should still not receive the signal
436 TestEndPan( application, Vector2(12.0f, 12.0f), time);
438 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
442 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
444 TestApplication application;
446 Actor actor = Actor::New();
447 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
448 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
449 application.GetScene().Add(actor);
452 application.SendNotification();
453 application.Render();
456 GestureReceivedFunctor functor(data);
458 PanGestureDetector detector = PanGestureDetector::New();
459 detector.Attach(actor);
460 detector.DetectedSignal().Connect(&application, functor);
462 // Start pan within the actor's area
464 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
466 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
467 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
468 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
469 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
470 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
471 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
472 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
474 // Continue the pan within the actor's area - we should still receive the signal
477 TestMovePan( application, Vector2(26.0f, 4.0f), time );
478 time += TestGetFrameInterval();
480 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
481 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
482 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
483 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
484 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
485 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
486 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
488 // Pan Gesture leaves actor's area - we should still receive the signal
491 TestMovePan( application, Vector2(346.0f, 4.0f), time );
492 time += TestGetFrameInterval();
494 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
495 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
496 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
497 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
498 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
499 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
500 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
502 // Gesture ends - we would receive a finished state
505 TestEndPan( application, Vector2(314.0f, 4.0f), time );
507 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
508 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
509 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
510 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
511 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
512 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
513 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
517 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
519 TestApplication application;
521 Actor actor = Actor::New();
522 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
523 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
524 application.GetScene().Add(actor);
527 application.SendNotification();
528 application.Render();
531 GestureReceivedFunctor functor(data);
533 PanGestureDetector detector = PanGestureDetector::New();
534 detector.Attach(actor);
535 detector.DetectedSignal().Connect(&application, functor);
537 // Start pan within the actor's area
539 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
541 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
542 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
543 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
544 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
545 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
546 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
547 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
549 // Continue the pan within the actor's area - we should still receive the signal
552 TestMovePan( application, Vector2(26.0f, 4.0f), time );
553 time += TestGetFrameInterval();
555 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
556 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
557 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
558 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
559 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
561 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
563 // Gesture ends within actor's area - we would receive a finished state
566 TestEndPan( application, Vector2(10.0f, 4.0f), time );
568 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
569 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
570 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
571 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
572 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
573 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
574 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
578 int UtcDaliPanGestureSignalReceptionDetach(void)
580 TestApplication application;
582 Actor actor = Actor::New();
583 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
584 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
585 application.GetScene().Add(actor);
588 application.SendNotification();
589 application.Render();
592 GestureReceivedFunctor functor(data);
594 PanGestureDetector detector = PanGestureDetector::New();
595 detector.Attach(actor);
596 detector.DetectedSignal().Connect(&application, functor);
598 // Start pan within the actor's area
600 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
601 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
603 // Continue the pan within the actor's area - we should still receive the signal
606 TestMovePan( application, Vector2(26.0f, 4.0f), time );
607 time += TestGetFrameInterval();
609 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
611 // Gesture ends within actor's area
614 TestEndPan( application, Vector2(10.0f, 4.0f), time );
615 time += TestGetFrameInterval();
617 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
620 detector.DetachAll();
622 // Ensure we are no longer signalled
625 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
626 TestMovePan( application, Vector2(26.0f, 4.0f), time );
627 time += TestGetFrameInterval();
628 TestEndPan( application, Vector2(10.0f, 4.0f), time );
630 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
634 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
636 TestApplication application;
638 Actor actor = Actor::New();
639 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
640 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
641 application.GetScene().Add(actor);
644 application.SendNotification();
645 application.Render();
648 GestureReceivedFunctor functor(data);
650 PanGestureDetector detector = PanGestureDetector::New();
651 detector.Attach(actor);
652 detector.DetectedSignal().Connect(&application, functor);
654 // Start pan within the actor's area
656 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
657 application.SendNotification();
659 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
661 // Continue the pan within the actor's area - we should still receive the signal
664 TestMovePan( application, Vector2(26.0f, 4.0f), time );
665 time += TestGetFrameInterval();
667 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
669 // Detach actor during the pan, we should not receive the next event
670 detector.DetachAll();
672 // Gesture ends within actor's area
675 TestEndPan( application, Vector2(10.0f, 4.0f), time );
677 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
681 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
683 TestApplication application;
686 GestureReceivedFunctor functor(data);
688 PanGestureDetector detector = PanGestureDetector::New();
689 detector.DetectedSignal().Connect(&application, functor);
691 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
693 Actor tempActor = Actor::New();
694 tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
695 tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
696 application.GetScene().Add(tempActor);
697 detector.Attach(tempActor);
701 // Actor lifetime is scoped
703 Actor actor = Actor::New();
704 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
705 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
706 application.GetScene().Add(actor);
709 application.SendNotification();
710 application.Render();
712 detector.Attach(actor);
714 // Start pan within the actor's area
715 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
717 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
719 // Continue the pan within the actor's area - we should still receive the signal
722 TestMovePan( application, Vector2(26.0f, 4.0f), time );
723 time += TestGetFrameInterval();
725 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
727 // Remove the actor from stage and reset the data
728 application.GetScene().Remove(actor);
731 application.SendNotification();
732 application.Render();
735 // Actor should now have been destroyed
737 // Gesture ends within the area where the actor used to be
740 TestEndPan( application, Vector2(10.0f, 4.0f), time );
742 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
746 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
748 TestApplication application;
750 Actor actor = Actor::New();
751 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
752 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
753 application.GetScene().Add(actor);
756 application.SendNotification();
757 application.Render();
760 GestureReceivedFunctor functor(data);
762 PanGestureDetector detector = PanGestureDetector::New();
763 detector.Attach(actor);
764 detector.DetectedSignal().Connect(&application, functor);
766 // Do an entire pan, only check finished value
768 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
772 TestEndPan( application, Vector2(25.0f, 28.0f), time );
774 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
775 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
777 // Rotate actor again and render a couple of times
778 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
779 application.SendNotification();
780 application.Render();
782 // Do an entire pan, only check finished value
783 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
787 TestEndPan( application, Vector2(25.0f, 28.0f), time );
789 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
790 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
792 // Rotate actor again and render a couple of times
793 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
794 application.SendNotification();
795 application.Render();
797 // Do an entire pan, only check finished value
798 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
802 TestEndPan( application, Vector2(25.0f, 28.0f), time );
804 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
805 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
809 int UtcDaliPanGestureSignalReceptionChildHit(void)
811 TestApplication application;
813 Actor parent = Actor::New();
814 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
815 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
816 application.GetScene().Add(parent);
818 // Set child to completely cover parent.
819 // Change rotation of child to be different from parent so that we can check if our local coordinate
820 // conversion of the parent actor is correct.
821 Actor child = Actor::New();
822 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
823 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
824 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
825 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
828 TouchEventFunctor touchFunctor;
829 child.TouchedSignal().Connect(&application, touchFunctor);
832 application.SendNotification();
833 application.Render();
836 GestureReceivedFunctor functor(data);
838 PanGestureDetector detector = PanGestureDetector::New();
839 detector.Attach(parent);
840 detector.DetectedSignal().Connect(&application, functor);
842 // Do an entire pan, only check finished value - hits child area but parent should still receive it
844 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
848 TestEndPan( application, Vector2(25.0f, 28.0f), time );
850 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
851 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
852 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
854 // Attach child and generate same touch points to yield a different displacement
855 // (Also proves that you can detach and then re-attach another actor)
856 detector.Attach(child);
857 detector.Detach(parent);
859 // Do an entire pan, only check finished value
860 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
864 TestEndPan( application, Vector2(25.0f, 28.0f), time );
866 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
867 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
868 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
872 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
874 TestApplication application;
876 Actor first = Actor::New();
877 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
878 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
879 application.GetScene().Add(first);
881 Actor second = Actor::New();
882 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
883 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
884 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
885 application.GetScene().Add(second);
888 application.SendNotification();
889 application.Render();
892 GestureReceivedFunctor functor(data);
894 PanGestureDetector detector = PanGestureDetector::New();
895 detector.Attach(first);
896 detector.Attach(second);
897 detector.DetectedSignal().Connect(&application, functor);
899 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
900 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
902 // Start pan within second actor's area
904 TestStartPan( application, Vector2( 110.0f, 20.0f ), Vector2( 126.0f, 20.0f ), time );
906 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
907 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
909 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
910 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
912 // Pan moves into first actor's area - second actor should receive the pan
915 TestMovePan( application, Vector2(126.0f, 20.0f), time );
916 time += TestGetFrameInterval();
918 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
919 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
921 // Detach the second actor during the pan, we should not receive the next event
922 detector.Detach(second);
924 // Gesture ends within actor's area
927 TestMovePan( application, Vector2(26.0f, 20.0f), time );
928 TestEndPan( application, Vector2(10.0f, 4.0f), time );
930 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
935 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
937 TestApplication application;
939 Actor actor = Actor::New();
940 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
941 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
942 application.GetScene().Add(actor);
945 application.SendNotification();
946 application.Render();
949 GestureReceivedFunctor functor(data);
951 PanGestureDetector detector = PanGestureDetector::New();
952 detector.Attach(actor);
953 detector.DetectedSignal().Connect(&application, functor);
955 // Start pan in actor's area
957 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
959 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
961 // Pan continues within actor's area
964 TestMovePan( application, Vector2(26.0f, 4.0f), time );
965 time += TestGetFrameInterval();
967 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
969 // Actor become invisible - actor should not receive the next pan
970 actor.SetProperty( Actor::Property::VISIBLE,false);
973 application.SendNotification();
974 application.Render();
976 // Gesture ends within actor's area
979 TestEndPan( application, Vector2(10.0f, 4.0f), time );
981 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
985 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
987 TestApplication application;
989 Actor actor = Actor::New();
990 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
991 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
992 application.GetScene().Add(actor);
994 Actor actor2 = Actor::New();
995 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
996 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
997 application.GetScene().Add(actor2);
1000 application.SendNotification();
1001 application.Render();
1003 // Attach actor to one detector
1004 SignalData firstData;
1005 GestureReceivedFunctor firstFunctor(firstData);
1006 PanGestureDetector firstDetector = PanGestureDetector::New();
1007 firstDetector.Attach(actor);
1008 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1010 // Attach actor to another detector
1011 SignalData secondData;
1012 GestureReceivedFunctor secondFunctor(secondData);
1013 PanGestureDetector secondDetector = PanGestureDetector::New();
1014 secondDetector.Attach(actor);
1015 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1017 // Add second actor to second detector, when we remove the actor, this will make sure that this
1018 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1019 // functor should still not be called (which is what we're also testing).
1020 secondDetector.Attach(actor2);
1022 // Pan in actor's area - both detector's functors should be called
1023 uint32_t time = 100;
1024 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1026 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1027 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1029 // Pan continues in actor's area - both detector's functors should be called
1033 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1034 time += TestGetFrameInterval();
1036 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1037 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1039 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1040 firstDetector.Detach(actor);
1044 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1046 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1047 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1049 // New pan on actor, only secondDetector has actor attached
1053 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1055 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1056 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1058 // Detach actor from secondDetector
1059 secondDetector.Detach(actor);
1063 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1065 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1066 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1071 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1073 TestApplication application;
1075 Actor actor1 = Actor::New();
1076 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1077 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1078 application.GetScene().Add(actor1);
1080 GestureReceivedFunctor functor1(data1);
1081 PanGestureDetector detector1 = PanGestureDetector::New();
1082 detector1.Attach(actor1);
1083 detector1.DetectedSignal().Connect(&application, functor1);
1085 Actor actor2 = Actor::New();
1086 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1087 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
1088 actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
1089 application.GetScene().Add(actor2);
1091 GestureReceivedFunctor functor2(data2);
1092 PanGestureDetector detector2 = PanGestureDetector::New();
1093 detector2.Attach(actor2);
1094 detector2.DetectedSignal().Connect(&application, functor2);
1096 // Render and notify
1097 application.SendNotification();
1098 application.Render();
1100 // Start pan in actor1's area, only data1 should be set
1101 uint32_t time = 100;
1102 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1104 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1105 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1109 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1111 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1113 TestApplication application;
1115 Actor actor = Actor::New();
1116 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1117 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1118 application.GetScene().Add(actor);
1120 // Render and notify
1121 application.SendNotification();
1122 application.Render();
1124 // Gesture possible in actor's area (using long-press)
1125 uint32_t time = 100;
1126 TestStartLongPress( application, 10.0f, 20.0f, time );
1127 time += TestGetFrameInterval();
1129 // Attach actor to detector
1131 GestureReceivedFunctor functor( data );
1132 PanGestureDetector detector = PanGestureDetector::New();
1133 detector.DetectedSignal().Connect( &application, functor );
1134 detector.Attach(actor);
1136 // Start a pan, initially it'll only be possible, we shouldn't receive it
1137 TestMovePan( application, Vector2( 10.0f, 20.0f ), time );
1138 time += TestGetFrameInterval();
1139 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1141 // Now the pan truly starts, we should receive a signal
1142 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1143 time += TestGetFrameInterval();
1144 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1145 time += TestGetFrameInterval();
1146 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1148 // Finish the pan, we should still receive a signal
1150 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1151 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1156 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1158 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1159 // pan actor was there before (parent)
1161 TestApplication application;
1163 Actor parent = Actor::New();
1164 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1165 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1166 application.GetScene().Add( parent );
1168 Actor child = Actor::New();
1169 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1170 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
1171 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1172 parent.Add( child );
1174 // Create detector for parent and attach
1175 SignalData parentData;
1176 GestureReceivedFunctor parentFunctor( parentData );
1177 PanGestureDetector parentDetector = PanGestureDetector::New();
1178 parentDetector.DetectedSignal().Connect( &application, parentFunctor );
1179 parentDetector.Attach( parent );
1181 // Create detector for child but do not attach
1182 SignalData childData;
1183 GestureReceivedFunctor childFunctor( childData );
1184 PanGestureDetector childDetector = PanGestureDetector::New();
1185 childDetector.DetectedSignal().Connect( &application, childFunctor );
1187 // Render and notify
1188 application.SendNotification();
1189 application.Render();
1191 // Do a full pan in both actors' area, only the parent's functor should be called
1192 uint32_t time = 100;
1193 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1194 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1195 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1198 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1199 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1200 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1204 // Gesture possible in both actors' area (using long-press), no functors called
1205 TestStartLongPress( application, 10.0f, 20.0f, time );
1206 time += TestGetFrameInterval();
1207 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1208 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1210 // Attach the child as well now
1211 childDetector.Attach( child );
1213 // Now the pan truly starts, we should receive a signal for the child only
1214 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1215 time += TestGetFrameInterval();
1216 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1217 time += TestGetFrameInterval();
1218 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1219 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1223 // Finish the pan, again only the child should still receive a signal
1224 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1225 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1226 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1231 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1233 TestApplication application;
1235 Actor actor = Actor::New();
1236 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1237 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1238 application.GetScene().Add(actor);
1240 // Render and notify
1241 application.SendNotification();
1242 application.Render();
1244 // Attach actor to detector
1246 GestureReceivedFunctor functor( data );
1247 PanGestureDetector detector = PanGestureDetector::New();
1248 detector.Attach(actor);
1249 detector.DetectedSignal().Connect( &application, functor );
1251 // Gesture possible in actor's area.
1252 uint32_t time = 100;
1253 TestStartLongPress( application, 10.0f, 20.0f, time );
1254 time += TestGetFrameInterval();
1256 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1258 // Move actor somewhere else
1259 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
1261 // Render and notify
1262 application.SendNotification();
1263 application.Render();
1265 // Emit Started event, we should not receive the pan.
1266 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1267 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1268 time += TestGetFrameInterval();
1270 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1272 // LongPress possible in empty area.
1273 TestStartLongPress( application, 10.0f, 20.0f, time );
1274 time += TestGetFrameInterval();
1276 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1278 // Move actor in to the long press position.
1279 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
1281 // Render and notify
1282 application.SendNotification();
1283 application.Render();
1285 // Emit Started event, we should be receiving the pan now.
1286 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1287 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1288 time += TestGetFrameInterval();
1290 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1292 // Normal pan in actor's area for completeness.
1294 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1295 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1296 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1300 int UtcDaliPanGestureActorUnstaged(void)
1302 TestApplication application;
1304 Actor actor = Actor::New();
1305 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1306 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1307 application.GetScene().Add(actor);
1309 // Render and notify
1310 application.SendNotification();
1311 application.Render();
1313 // State to remove actor in.
1314 Gesture::State stateToUnstage( Gesture::Started );
1316 // Attach actor to detector
1318 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1319 PanGestureDetector detector = PanGestureDetector::New();
1320 detector.Attach(actor);
1321 detector.DetectedSignal().Connect( &application, functor );
1324 uint32_t time = 100;
1325 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1327 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1330 TestEndPan( application, Vector2(26.0f, 20.0f), time );
1332 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1335 // Render and notify
1336 application.SendNotification();
1337 application.Render();
1339 // Re-add actor to stage
1340 application.GetScene().Add(actor);
1342 // Render and notify
1343 application.SendNotification();
1344 application.Render();
1346 // Change state to Gesture::Continuing to remove
1347 stateToUnstage = Gesture::Continuing;
1350 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1352 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1355 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1356 time += TestGetFrameInterval();
1358 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1362 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1364 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1367 // Render and notify
1368 application.SendNotification();
1369 application.Render();
1371 // Re-add actor to stage
1372 application.GetScene().Add(actor);
1374 // Render and notify
1375 application.SendNotification();
1376 application.Render();
1378 // Change state to Gesture::Finished to remove
1379 stateToUnstage = Gesture::Finished;
1382 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1384 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1387 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1388 time += TestGetFrameInterval();
1390 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1393 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1395 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1396 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1400 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1402 TestApplication application;
1404 Actor actor = Actor::New();
1405 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1406 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1407 application.GetScene().Add(actor);
1409 // Create and add a second actor so that GestureDetector destruction does not come into play.
1410 Actor dummyActor( Actor::New() );
1411 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1412 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
1413 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1414 application.GetScene().Add(dummyActor);
1416 // Render and notify
1417 application.SendNotification();
1418 application.Render();
1420 // State to remove actor in.
1421 Gesture::State stateToUnstage( Gesture::Started );
1423 // Attach actor to detector
1425 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1426 PanGestureDetector detector = PanGestureDetector::New();
1427 detector.Attach(actor);
1428 detector.Attach(dummyActor);
1429 detector.DetectedSignal().Connect( &application, functor );
1431 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1432 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1433 // position, we should still not be signalled.
1436 uint32_t time = 100;
1437 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1439 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1442 // Render and notify
1443 application.SendNotification();
1444 application.Render();
1446 // Re add to the stage, we should not be signalled
1447 application.GetScene().Add(actor);
1449 // Render and notify
1450 application.SendNotification();
1451 application.Render();
1453 // Continue signal emission
1454 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1455 time += TestGetFrameInterval();
1457 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1460 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1461 time += TestGetFrameInterval();
1463 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1466 // Here we delete an actor in started, we should not receive any subsequent signalling.
1469 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1471 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1474 // Render and notify
1475 application.SendNotification();
1476 application.Render();
1478 // Delete actor as well
1481 // Render and notify
1482 application.SendNotification();
1483 application.Render();
1485 // Continue signal emission
1486 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1487 time += TestGetFrameInterval();
1489 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1492 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1494 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1498 int UtcDaliPanGestureAngleHandling(void)
1500 TestApplication application;
1502 PanGestureDetector detector = PanGestureDetector::New();
1503 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1505 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1506 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1508 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1510 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1512 tet_result( TET_PASS );
1520 tet_printf("%s, angle not added\n", TEST_LOCATION );
1521 tet_result( TET_FAIL );
1524 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1525 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1527 // Remove something not in the container.
1528 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1529 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1531 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1532 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1533 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1535 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1537 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1538 tet_result( TET_FAIL );
1543 detector.ClearAngles();
1544 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1548 int UtcDaliPanGestureGetAngle(void)
1550 TestApplication application;
1552 PanGestureDetector detector = PanGestureDetector::New();
1553 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1555 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1556 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1558 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1559 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1561 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1562 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1564 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1565 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1567 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1568 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1569 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1570 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1575 inline float RadiansToDegrees( float radian )
1577 return radian * 180.0f / Math::PI;
1580 int UtcDaliPanGestureAngleOutOfRange(void)
1582 TestApplication application;
1584 PanGestureDetector detector = PanGestureDetector::New();
1585 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1591 detector.AddAngle( Degree(180.0f) );
1592 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1593 detector.ClearAngles();
1595 detector.AddAngle( Degree(190.0f) );
1596 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1597 detector.ClearAngles();
1599 detector.AddAngle( Degree(-190.0f) );
1600 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1601 detector.ClearAngles();
1603 detector.AddAngle( Degree(350.0f) );
1604 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1605 detector.ClearAngles();
1607 detector.AddAngle( Degree(-350.0f) );
1608 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1609 detector.ClearAngles();
1611 detector.AddAngle( Degree(370.0f) );
1612 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1613 detector.ClearAngles();
1615 detector.AddAngle( Degree(-370.0f) );
1616 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1617 detector.ClearAngles();
1623 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1624 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1625 detector.ClearAngles();
1627 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1628 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1629 detector.ClearAngles();
1631 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1632 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1633 detector.ClearAngles();
1635 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1636 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1637 detector.ClearAngles();
1641 int UtcDaliPanGestureAngleProcessing(void)
1643 TestApplication application;
1645 Actor parent = Actor::New();
1646 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1647 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1648 application.GetScene().Add(parent);
1650 Actor child = Actor::New();
1651 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1652 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1655 // Render and notify
1656 application.SendNotification();
1657 application.Render();
1659 // Parent detector only requires up pans
1660 PanGestureDetector parentDetector = PanGestureDetector::New();
1661 parentDetector.Attach( parent );
1662 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1663 SignalData parentData;
1664 GestureReceivedFunctor parentFunctor(parentData);
1665 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1667 // Child detector only requires right pans
1668 PanGestureDetector childDetector = PanGestureDetector::New();
1669 childDetector.Attach( child );
1670 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1671 SignalData childData;
1672 GestureReceivedFunctor childFunctor(childData);
1673 childDetector.DetectedSignal().Connect(&application, childFunctor);
1675 // Generate an Up pan gesture, only parent should receive it.
1676 uint32_t time = 100;
1677 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1679 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1680 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1682 TestEndPan( application, Vector2(20.0f, 4.0f), time );
1683 time += TestGetFrameInterval();
1687 // Generate a Right pan gesture, only child should receive it.
1688 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1690 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1691 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1693 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1694 time += TestGetFrameInterval();
1698 // Generate a Down pan gesture, no one should receive it.
1699 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1701 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1702 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1704 TestEndPan( application, Vector2(20.0f, 36.0f), time );
1705 time += TestGetFrameInterval();
1709 // Generate a Left pan gesture, no one should receive it.
1710 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1712 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1713 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1715 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1721 int UtcDaliPanGestureDirectionHandling(void)
1723 TestApplication application;
1725 PanGestureDetector detector = PanGestureDetector::New();
1726 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1728 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1729 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1731 for ( size_t i = 0; detector.GetAngleCount(); i++)
1733 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1735 tet_result( TET_PASS );
1744 tet_printf("%s, angle not added\n", TEST_LOCATION );
1745 tet_result( TET_FAIL );
1749 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1751 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1753 tet_result( TET_PASS );
1761 tet_printf("%s, angle not added\n", TEST_LOCATION );
1762 tet_result( TET_FAIL );
1765 // Remove something not in the container.
1766 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1767 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1769 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1770 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1774 int UtcDaliPanGestureDirectionProcessing(void)
1776 TestApplication application;
1778 Actor parent = Actor::New();
1779 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1780 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1781 application.GetScene().Add(parent);
1783 Actor child = Actor::New();
1784 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1785 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1788 // Render and notify
1789 application.SendNotification();
1790 application.Render();
1792 // Parent detector only requires vertical panning
1793 PanGestureDetector parentDetector = PanGestureDetector::New();
1794 parentDetector.Attach( parent );
1795 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1796 SignalData parentData;
1797 GestureReceivedFunctor parentFunctor(parentData);
1798 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1800 // Child detector only requires horizontal panning
1801 PanGestureDetector childDetector = PanGestureDetector::New();
1802 childDetector.Attach( child );
1803 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1804 SignalData childData;
1805 GestureReceivedFunctor childFunctor(childData);
1806 childDetector.DetectedSignal().Connect(&application, childFunctor);
1808 // Generate an Up pan gesture, only parent should receive it.
1809 uint32_t time = 100;
1810 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1812 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1813 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1815 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1816 time += TestGetFrameInterval();
1820 // Generate a Right pan gesture, only child should receive it.
1821 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1823 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1824 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1826 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1827 time += TestGetFrameInterval();
1831 // Generate a Down pan gesture, only parent should receive it.
1832 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1834 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1835 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1837 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1838 time += TestGetFrameInterval();
1842 // Generate a Left pan gesture, only child should receive it.
1843 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1845 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1846 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1848 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1849 time += TestGetFrameInterval();
1853 // Generate a pan at -45 degrees, no one should receive it.
1854 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 9.0f, 31.0f ), time );
1856 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1857 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1859 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1860 time += TestGetFrameInterval();
1864 // Generate a pan at 45 degrees, no one should receive it.
1865 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 31.0f, 31.0f ), time );
1867 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1868 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1870 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1871 time += TestGetFrameInterval();
1875 // Generate a pan at -135 degrees, no one should receive it.
1876 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 4.0f ), time );
1878 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1879 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1881 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1887 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1889 TestApplication application;
1890 Integration::SetPanGesturePredictionMode(0);
1891 Integration::SetPanGestureSmoothingMode(0);
1893 Actor actor = Actor::New();
1894 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1895 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1896 application.GetScene().Add(actor);
1898 // Add a pan detector
1899 PanGestureDetector detector = PanGestureDetector::New();
1900 detector.Attach( actor );
1902 GestureReceivedFunctor functor( data );
1903 detector.DetectedSignal().Connect( &application, functor );
1905 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1907 ConstraintData constraintData;
1908 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1909 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1910 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1911 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1912 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1913 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1914 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1915 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1918 // Render and notify
1919 application.SendNotification();
1920 application.Render();
1922 Vector2 startPosition( 1.0f, 1.0f );
1923 Vector2 position( -14.0f, 1.0f );
1924 Vector2 direction(Vector2::XAXIS * -5.0f);
1925 uint32_t time = 100;
1927 TestStartPan( application, startPosition, position, time );
1929 for(int i = 0; i < 47; i++ )
1931 position += direction;
1932 TestMovePan( application, position, time );
1933 time += TestGetFrameInterval();
1934 application.SendNotification();
1935 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1938 TestEndPan( application, position, time );
1939 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1941 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1942 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1943 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1944 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1946 constraintData.Reset();
1950 int UtcDaliPanGestureNoPredictionSmoothing(void)
1952 TestApplication application;
1953 Integration::SetPanGesturePredictionMode(0);
1954 Integration::SetPanGestureSmoothingMode(1);
1956 Actor actor = Actor::New();
1957 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1958 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1959 application.GetScene().Add(actor);
1961 // Add a pan detector
1962 PanGestureDetector detector = PanGestureDetector::New();
1963 detector.Attach( actor );
1965 GestureReceivedFunctor functor( data );
1966 detector.DetectedSignal().Connect( &application, functor );
1968 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1970 ConstraintData constraintData;
1971 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1972 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1973 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1974 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1975 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1976 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1977 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1978 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1981 // Render and notify
1982 application.SendNotification();
1983 application.Render();
1985 Vector2 startPosition( 1.0f, 1.0f );
1986 Vector2 position( -14.0f, 1.0f );
1987 Vector2 direction(Vector2::XAXIS * -5.0f);
1988 uint32_t time = 100;
1990 TestStartPan( application, startPosition, position, time );
1992 for(int i = 0; i < 47; i++ )
1994 position += direction;
1995 TestMovePan( application, position, time );
1996 time += TestGetFrameInterval();
1997 application.SendNotification();
1998 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2001 TestEndPan( application, position, time );
2002 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2004 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2005 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2006 // Take into account resampling done when prediction is off.
2007 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2008 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2010 constraintData.Reset();
2014 int UtcDaliPanGesturePredictionNoSmoothing(void)
2016 TestApplication application;
2017 Integration::SetPanGesturePredictionMode(1);
2018 Integration::SetPanGestureSmoothingMode(0);
2020 Actor actor = Actor::New();
2021 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2022 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2023 application.GetScene().Add(actor);
2025 // Add a pan detector
2026 PanGestureDetector detector = PanGestureDetector::New();
2027 detector.Attach( actor );
2029 GestureReceivedFunctor functor( data );
2030 detector.DetectedSignal().Connect( &application, functor );
2032 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2034 ConstraintData constraintData;
2035 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2036 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2037 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2038 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2039 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2040 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2041 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2042 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2045 // Render and notify
2046 application.SendNotification();
2047 application.Render();
2049 Vector2 startPosition( 1.0f, 1.0f );
2050 Vector2 position( -1.0f, 1.0f );
2051 Vector2 direction(Vector2::XAXIS * -1.0f);
2052 uint32_t time = 100;
2054 TestStartPan( application, startPosition, position, time );
2056 for(int i = 0; i < 47; i++ )
2058 position += direction;
2059 TestMovePan( application, position, time );
2060 time += TestGetFrameInterval();
2061 application.SendNotification();
2062 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2065 TestEndPan( application, position, time );
2066 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2068 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2069 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2070 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2071 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2073 constraintData.Reset();
2077 int UtcDaliPanGesturePredictionSmoothing01(void)
2079 TestApplication application;
2080 Integration::SetPanGesturePredictionMode(1);
2081 Integration::SetPanGestureSmoothingMode(1);
2083 Actor actor = Actor::New();
2084 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2085 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2086 application.GetScene().Add(actor);
2088 // Add a pan detector
2089 PanGestureDetector detector = PanGestureDetector::New();
2090 detector.Attach( actor );
2092 GestureReceivedFunctor functor( data );
2093 detector.DetectedSignal().Connect( &application, functor );
2095 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2097 ConstraintData constraintData;
2098 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2099 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2100 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2101 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2102 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2103 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2104 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2105 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2108 // Render and notify
2109 application.SendNotification();
2110 application.Render();
2112 Vector2 startPosition( 1.0f, 1.0f );
2113 Vector2 position( -1.0f, 1.0f );
2114 Vector2 direction(Vector2::XAXIS * -1.0f);
2115 uint32_t time = 100;
2117 TestStartPan( application, startPosition, position, time );
2119 for(int i = 0; i < 47; i++ )
2121 position += direction;
2122 TestMovePan( application, position, time );
2123 time += TestGetFrameInterval();
2124 application.SendNotification();
2125 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2128 TestEndPan( application, position, time );
2129 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2131 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2132 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2133 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2134 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2136 constraintData.Reset();
2140 int UtcDaliPanGesturePredictionSmoothing02(void)
2142 TestApplication application;
2143 Integration::SetPanGesturePredictionMode( 1 );
2144 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2145 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2146 Integration::SetPanGestureSmoothingMode( 1 );
2147 Integration::SetPanGestureSmoothingAmount( 0.25f );
2149 Actor actor = Actor::New();
2150 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2151 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2152 application.GetScene().Add(actor);
2154 // Add a pan detector
2155 PanGestureDetector detector = PanGestureDetector::New();
2156 detector.Attach( actor );
2158 GestureReceivedFunctor functor( data );
2159 detector.DetectedSignal().Connect( &application, functor );
2161 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2163 ConstraintData constraintData;
2164 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2165 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2166 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2167 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2168 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2169 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2170 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2171 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2174 // Render and notify
2175 application.SendNotification();
2176 application.Render();
2178 Vector2 startPosition( 2.0f, 2.0f );
2179 Vector2 position( 4.0f, 2.0f );
2180 Vector2 directionX(Vector2::XAXIS);
2181 Vector2 directionY(Vector2::YAXIS);
2182 uint32_t time = 100;
2184 TestStartPan( application, startPosition, position, time );
2186 for(int i = 0; i < 7; i++ )
2188 position += directionX;
2189 TestMovePan( application, position, time );
2190 time += TestGetFrameInterval();
2191 application.SendNotification();
2192 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2195 position += directionX * 10.0f;
2196 TestMovePan( application, position, time );
2197 time += TestGetFrameInterval();
2198 application.SendNotification();
2199 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2201 for(int i = 0; i < 2; i++ )
2203 position += ( directionX * -1.0f );
2204 TestMovePan( application, position, time );
2205 time += TestGetFrameInterval();
2206 application.SendNotification();
2207 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2210 for(int i = 0; i < 10; i++ )
2212 position += directionX;
2213 TestMovePan( application, position, time );
2214 time += TestGetFrameInterval();
2215 application.SendNotification();
2216 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2219 for(int i = 0; i < 10; i++ )
2221 position += directionY;
2222 TestMovePan( application, position, time );
2223 time += TestGetFrameInterval();
2224 application.SendNotification();
2225 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2228 TestEndPan( application, position, time );
2229 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2231 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2232 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2233 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2234 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2236 constraintData.Reset();
2240 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2242 TestApplication application;
2244 Integration::SetPanGesturePredictionMode( 2 );
2245 Integration::SetPanGesturePredictionAmount( 57 );
2246 Integration::SetPanGestureSmoothingMode( 2 );
2247 Integration::SetPanGestureUseActualTimes( false );
2248 Integration::SetPanGestureInterpolationTimeRange( 10 );
2249 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2250 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2251 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2252 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2253 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2254 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2256 Actor actor = Actor::New();
2257 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2258 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2259 application.GetScene().Add(actor);
2261 // Add a pan detector
2262 PanGestureDetector detector = PanGestureDetector::New();
2263 detector.Attach( actor );
2265 GestureReceivedFunctor functor( data );
2266 detector.DetectedSignal().Connect( &application, functor );
2268 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2270 ConstraintData constraintData;
2271 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2272 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2273 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2274 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2275 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2276 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2277 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2278 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2281 // Render and notify
2282 application.SendNotification();
2283 application.Render();
2285 Vector2 startPosition( 2.0f, 2.0f );
2286 Vector2 position( -1.0f, 2.0f );
2287 Vector2 direction(Vector2::XAXIS * -1.0f);
2288 uint32_t time = 100;
2290 TestStartPan( application, startPosition, position, time );
2292 for(int i = 0; i < 27; i++ )
2294 position += direction;
2295 TestMovePan( application, position, time );
2296 time += TestGetFrameInterval();
2297 application.SendNotification();
2298 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2301 TestEndPan( application, position, time );
2302 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2304 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2305 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2306 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2307 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2309 constraintData.Reset();
2313 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2315 TestApplication application;
2317 Integration::SetPanGesturePredictionMode( 2 );
2318 Integration::SetPanGestureSmoothingMode( 2 );
2319 Integration::SetPanGestureUseActualTimes( true );
2320 Integration::SetPanGestureInterpolationTimeRange( 10 );
2321 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2322 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2323 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2324 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2325 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2326 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2328 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2330 Actor actor = Actor::New();
2331 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2332 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2333 application.GetScene().Add(actor);
2335 // Add a pan detector
2336 PanGestureDetector detector = PanGestureDetector::New();
2337 detector.Attach( actor );
2339 GestureReceivedFunctor functor( data );
2340 detector.DetectedSignal().Connect( &application, functor );
2342 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2344 ConstraintData constraintData;
2345 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2346 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2347 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2348 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2349 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2350 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2351 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2352 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2355 // Render and notify
2356 application.SendNotification();
2357 application.Render();
2359 Vector2 startPosition( 2.0f, 2.0f );
2360 Vector2 position( 17.0f, 2.0f );
2361 Vector2 direction(Vector2::XAXIS * -1.0f);
2362 uint32_t time = 100;
2364 TestStartPan( application, startPosition, position, time );
2366 for(int i = 0; i < 10; i++ )
2368 position += direction;
2369 TestMovePan( application, position, time );
2370 time += TestGetFrameInterval();
2372 position += direction;
2373 TestMovePan( application, position, time );
2374 time += TestGetFrameInterval();
2376 position += direction;
2377 TestMovePan( application, position, time );
2378 time += TestGetFrameInterval();
2380 application.SendNotification();
2381 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2384 for(int i = 0; i < 10; i++ )
2386 application.SendNotification();
2387 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2390 for(int i = 0; i < 10; i++ )
2392 position += direction;
2393 TestMovePan( application, position, time );
2394 application.SendNotification();
2395 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2398 for(int i = 0; i < 10; i++ )
2400 position += direction;
2401 TestMovePan( application, position, time );
2402 time += TestGetFrameInterval();
2403 application.SendNotification();
2404 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2407 TestEndPan( application, position, time );
2408 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2410 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2411 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2412 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2413 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2415 constraintData.Reset();
2419 int UtcDaliPanGesturePrediction2Smoothing(void)
2421 TestApplication application;
2423 Integration::SetPanGesturePredictionMode( 2 );
2424 Integration::SetPanGesturePredictionAmount( 57 );
2425 Integration::SetPanGestureSmoothingMode( 1 );
2426 Integration::SetPanGestureUseActualTimes( false );
2427 Integration::SetPanGestureInterpolationTimeRange( 10 );
2428 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2429 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2430 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2431 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2432 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2433 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2435 Actor actor = Actor::New();
2436 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2437 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2438 application.GetScene().Add(actor);
2440 // Add a pan detector
2441 PanGestureDetector detector = PanGestureDetector::New();
2442 detector.Attach( actor );
2444 GestureReceivedFunctor functor( data );
2445 detector.DetectedSignal().Connect( &application, functor );
2447 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2449 ConstraintData constraintData;
2450 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2451 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2452 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2453 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2454 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2455 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2456 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2457 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2460 // Render and notify
2461 application.SendNotification();
2462 application.Render();
2464 Vector2 startPosition( 2.0f, 2.0f );
2465 Vector2 position( 17.0f, 2.0f );
2466 Vector2 direction(Vector2::XAXIS * -1.0f);
2467 uint32_t time = 100;
2469 TestStartPan( application, startPosition, position, time );
2471 for(int i = 0; i < 10; i++ )
2473 position += direction;
2474 TestMovePan( application, position, time );
2475 time += TestGetFrameInterval();
2476 application.SendNotification();
2477 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2481 position += direction;
2482 TestMovePan( application, position, time );
2483 time += TestGetFrameInterval();
2485 position += direction;
2486 TestMovePan( application, position, time );
2487 time += TestGetFrameInterval();
2489 position += direction;
2490 TestMovePan( application, position, time );
2491 time += TestGetFrameInterval();
2493 application.SendNotification();
2494 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2496 for(int i = 0; i < 5; i++ )
2498 application.SendNotification();
2499 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2502 for(int i = 0; i < 10; i++ )
2504 position += direction;
2505 TestMovePan( application, position, time );
2506 time += TestGetFrameInterval();
2507 application.SendNotification();
2508 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2511 TestEndPan( application, position, time );
2512 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2514 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2515 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2516 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2517 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2519 constraintData.Reset();
2523 int UtcDaliPanGestureSetProperties(void)
2525 TestApplication application;
2526 TestRenderController& renderController( application.GetRenderController() );
2527 Integration::SetPanGesturePredictionMode(0);
2528 Integration::SetPanGestureSmoothingMode(0);
2530 Actor actor = Actor::New();
2531 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2532 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2533 application.GetScene().Add(actor);
2535 // Add a pan detector
2536 PanGestureDetector detector = PanGestureDetector::New();
2537 detector.Attach( actor );
2539 GestureReceivedFunctor functor( data );
2540 detector.DetectedSignal().Connect( &application, functor );
2542 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2543 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2545 ConstraintData constraintData;
2546 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2547 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2548 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2549 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2550 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2551 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2552 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2553 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2554 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2557 // Render and notify
2558 application.SendNotification();
2559 application.Render();
2561 renderController.Initialize();
2562 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2564 Vector2 screenPosition( 20.0f, 20.0f );
2565 Vector2 screenDisplacement( 1.0f, 1.0f );
2566 Vector2 screenVelocity( 1.3f, 4.0f );
2567 Vector2 localPosition( 21.0f, 21.0f );
2568 Vector2 localDisplacement( 0.5f, 0.5f );
2569 Vector2 localVelocity( 1.5f, 2.5f );
2571 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2572 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2574 // Render and notify
2575 application.SendNotification();
2576 application.Render();
2578 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2579 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2580 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2581 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2582 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2583 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2584 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2585 constraintData.Reset();
2589 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2591 TestApplication application;
2592 Integration::SetPanGesturePredictionMode(0);
2594 Actor actor = Actor::New();
2595 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2596 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2597 application.GetScene().Add(actor);
2599 // Add a pan detector
2600 PanGestureDetector detector = PanGestureDetector::New();
2601 detector.Attach( actor );
2603 GestureReceivedFunctor functor( data );
2604 detector.DetectedSignal().Connect( &application, functor );
2606 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2608 ConstraintData constraintData;
2609 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2610 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2611 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2612 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2613 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2614 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2615 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2616 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2619 // Render and notify
2620 application.SendNotification();
2621 application.Render();
2623 Vector2 currentPosition( 20.0f, 4.0f );
2624 uint32_t time = 100;
2625 TestStartPan( application, Vector2( 20.0f, 20.0f ), currentPosition, time );
2626 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2628 Vector2 screenPosition( 100.0f, 20.0f );
2629 Vector2 localPosition( 110.0f, 110.0f );
2631 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2633 // Render and notify
2634 application.SendNotification();
2635 application.Render();
2637 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2638 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2639 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2640 constraintData.Reset();
2644 int UtcDaliPanGesturePropertyIndices(void)
2646 TestApplication application;
2647 PanGestureDetector detector = PanGestureDetector::New();
2649 Property::IndexContainer indices;
2650 detector.GetPropertyIndices( indices );
2651 DALI_TEST_CHECK( indices.Size() );
2652 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2658 struct PropertyStringIndex
2660 const char * const name;
2661 const Property::Index index;
2662 const Property::Type type;
2663 const Property::Value value;
2666 const PropertyStringIndex PROPERTY_TABLE[] =
2668 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2669 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2670 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2671 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2672 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2673 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2674 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2676 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2677 } // unnamed namespace
2680 int UtcDaliPanGestureProperties(void)
2682 TestApplication application;
2683 PanGestureDetector detector = PanGestureDetector::New();
2685 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2687 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2688 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2689 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2690 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2691 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2692 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2693 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2699 int UtcDaliPanGestureGetProperty(void)
2701 TestApplication application;
2702 PanGestureDetector detector = PanGestureDetector::New();
2704 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2706 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2708 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2709 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2711 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2713 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2714 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2721 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2723 TestApplication application;
2725 Actor actor = Actor::New();
2726 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2727 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2728 application.GetScene().Add(actor);
2730 // Add a pan detector
2731 PanGestureDetector detector = PanGestureDetector::New();
2732 detector.Attach( actor );
2734 // Render and notify
2735 application.SendNotification();
2736 application.Render();
2738 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2740 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2742 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2744 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2745 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2747 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2749 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2750 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2757 int UtcDaliPanGestureLayerConsumesTouch(void)
2759 TestApplication application;
2761 Actor actor = Actor::New();
2762 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2763 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2764 application.GetScene().Add(actor);
2766 // Add a pan detector
2767 PanGestureDetector detector = PanGestureDetector::New();
2768 detector.Attach( actor );
2770 GestureReceivedFunctor functor( data );
2771 detector.DetectedSignal().Connect( &application, functor );
2773 // Add a layer to overlap the actor
2774 Layer layer = Layer::New();
2775 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2776 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2777 application.GetScene().Add( layer );
2780 // Render and notify
2781 application.SendNotification();
2782 application.Render();
2784 // Emit signals, should receive
2785 uint32_t time = 100;
2786 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2787 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2788 time += TestGetFrameInterval();
2790 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2793 // Set layer to consume all touch
2794 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
2796 // Render and notify
2797 application.SendNotification();
2798 application.Render();
2800 // Emit the same signals again, should not receive
2801 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2802 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2804 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2810 int UtcDaliPanGestureNoTimeDiff(void)
2812 TestApplication application;
2814 Actor actor = Actor::New();
2815 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2816 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2817 application.GetScene().Add(actor);
2819 // Add a pan detector
2820 PanGestureDetector detector = PanGestureDetector::New();
2821 detector.Attach( actor );
2823 GestureReceivedFunctor functor( data );
2824 detector.DetectedSignal().Connect( &application, functor );
2826 // Render and notify
2827 application.SendNotification();
2828 application.Render();
2830 // As normal helper function adds intervals between presses we must generate the sequence
2831 // using other helper functions
2832 TestStartLongPress( application, 10.0f, 20.0f, 100 ); // Used to send a down press event
2833 TestMovePan( application, Vector2(26.0f, 20.0f), 100 );
2834 TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); // 2 motions required to trigger
2835 TestEndPan( application, Vector2(26.0f, 20.0f), 100 );
2837 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2838 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2839 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2840 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2841 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );