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-data-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 // Data for constraints
123 struct ConstraintData
131 Vector2 screenPosition;
132 Vector2 screenDisplacement;
133 Vector2 screenVelocity;
134 Vector2 localPosition;
135 Vector2 localDisplacement;
136 Vector2 localVelocity;
142 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
148 // Constraint used with panning properties
151 PanConstraint( ConstraintData& data ) : constraintData(data) { }
153 void operator()( Vector3& current, const PropertyInputContainer& inputs )
155 constraintData.screenPosition = inputs[0]->GetVector2();
156 constraintData.screenDisplacement = inputs[1]->GetVector2();
157 constraintData.screenVelocity = inputs[2]->GetVector2();
158 constraintData.localPosition = inputs[3]->GetVector2();
159 constraintData.localDisplacement = inputs[4]->GetVector2();
160 constraintData.localVelocity = inputs[5]->GetVector2();
161 constraintData.panning = inputs[6]->GetBoolean();
162 constraintData.called = true;
163 current = Vector3::ZERO;
166 ConstraintData& constraintData;
169 // Generate a PanGesture
170 PanGesture GeneratePan( unsigned int time,
171 Gesture::State state,
172 Vector2 screenPosition,
173 Vector2 localPosition,
174 Vector2 screenDisplacement = Vector2::ONE,
175 Vector2 localDisplacement = Vector2::ONE,
176 Vector2 screenVelocity = Vector2::ONE,
177 Vector2 localVelocity = Vector2::ONE,
178 unsigned int numberOfTouches = 1 )
180 PanGesture pan( state );
184 pan.screenPosition = screenPosition;
185 pan.position = localPosition;
187 pan.screenDisplacement = screenDisplacement;
188 pan.displacement = localDisplacement;
190 pan.screenVelocity = screenVelocity;
191 pan.velocity = localVelocity;
193 pan.numberOfTouches = numberOfTouches;
200 ///////////////////////////////////////////////////////////////////////////////
202 // Positive test case for a method
203 int UtcDaliPanGestureDetectorConstructor(void)
205 TestApplication application;
207 PanGestureDetector detector;
208 DALI_TEST_CHECK(!detector);
212 int UtcDaliPanGestureDetectorCopyConstructorP(void)
214 TestApplication application;
216 PanGestureDetector detector = PanGestureDetector::New();
218 PanGestureDetector copy( detector );
219 DALI_TEST_CHECK( detector );
223 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
225 TestApplication application;
227 PanGestureDetector detector = PanGestureDetector::New();
229 PanGestureDetector assign;
231 DALI_TEST_CHECK( detector );
233 DALI_TEST_CHECK( detector == assign );
237 // Negative test case for a method
238 int UtcDaliPanGestureDetectorNew(void)
240 TestApplication application;
242 PanGestureDetector detector = PanGestureDetector::New();
244 DALI_TEST_CHECK(detector);
246 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
247 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
249 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
250 Actor actor = Actor::New();
251 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
252 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
253 detector.Attach(actor);
255 application.GetScene().Add(actor);
258 application.SendNotification();
259 application.Render();
261 // Use long press function for touch event
262 TestStartLongPress( application );
267 int UtcDaliPanGestureDetectorDownCast(void)
269 TestApplication application;
270 tet_infoline("Testing Dali::GestureDetector::DownCast()");
272 PanGestureDetector detector = PanGestureDetector::New();
274 BaseHandle object(detector);
276 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
277 DALI_TEST_CHECK(detector2);
279 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
280 DALI_TEST_CHECK(detector3);
282 BaseHandle unInitializedObject;
283 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
284 DALI_TEST_CHECK(!detector4);
286 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
287 DALI_TEST_CHECK(!detector5);
289 GestureDetector detector6 = PanGestureDetector::New();
290 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
291 DALI_TEST_CHECK(detector7);
295 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
297 TestApplication application;
299 PanGestureDetector detector = PanGestureDetector::New();
301 unsigned int min = 2;
303 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
305 detector.SetMinimumTouchesRequired(min);
307 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
309 // Attach an actor and change the minimum touches
311 Actor actor = Actor::New();
312 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
313 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
314 application.GetScene().Add(actor);
317 application.SendNotification();
318 application.Render();
321 GestureReceivedFunctor functor(data);
323 detector.Attach(actor);
324 detector.DetectedSignal().Connect(&application, functor);
326 detector.SetMinimumTouchesRequired(3);
328 // Create a second gesture detector that requires even less minimum touches
329 PanGestureDetector secondDetector = PanGestureDetector::New();
330 secondDetector.Attach(actor);
332 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
337 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
339 TestApplication application;
341 PanGestureDetector detector = PanGestureDetector::New();
343 unsigned int max = 3;
345 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
347 detector.SetMaximumTouchesRequired(max);
349 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
351 // Attach an actor and change the maximum touches
353 Actor actor = Actor::New();
354 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
355 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
356 application.GetScene().Add(actor);
359 application.SendNotification();
360 application.Render();
363 GestureReceivedFunctor functor(data);
365 detector.Attach(actor);
366 detector.DetectedSignal().Connect(&application, functor);
368 detector.SetMaximumTouchesRequired(4);
370 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
375 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
377 TestApplication application;
379 PanGestureDetector detector = PanGestureDetector::New();
380 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
384 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
386 TestApplication application;
388 PanGestureDetector detector = PanGestureDetector::New();
389 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
393 int UtcDaliPanGestureSignalReceptionNegative(void)
395 TestApplication application;
397 Actor actor = Actor::New();
398 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
399 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
400 application.GetScene().Add(actor);
403 application.SendNotification();
404 application.Render();
407 GestureReceivedFunctor functor(data);
409 PanGestureDetector detector = PanGestureDetector::New();
410 detector.Attach(actor);
411 detector.DetectedSignal().Connect(&application, functor);
413 // Do a pan outside actor's area
415 TestStartPan( application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time );
417 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
419 // Continue pan into actor's area - we should still not receive the signal
421 TestMovePan( application, Vector2(20.0f, 20.0f), time );
423 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
425 // Stop panning - we should still not receive the signal
427 TestEndPan( application, Vector2(12.0f, 12.0f), time);
429 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
433 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
435 TestApplication application;
437 Actor actor = Actor::New();
438 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
439 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
440 application.GetScene().Add(actor);
443 application.SendNotification();
444 application.Render();
447 GestureReceivedFunctor functor(data);
449 PanGestureDetector detector = PanGestureDetector::New();
450 detector.Attach(actor);
451 detector.DetectedSignal().Connect(&application, functor);
453 // Start pan within the actor's area
455 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
457 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
458 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
459 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
460 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
461 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
462 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
463 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
465 // Continue the pan within the actor's area - we should still receive the signal
468 TestMovePan( application, Vector2(26.0f, 4.0f), time );
469 time += TestGetFrameInterval();
471 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
472 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
473 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
474 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
475 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
476 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
477 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
479 // Pan Gesture leaves actor's area - we should still receive the signal
482 TestMovePan( application, Vector2(346.0f, 4.0f), time );
483 time += TestGetFrameInterval();
485 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
486 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
487 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
488 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
489 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
490 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
491 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
493 // Gesture ends - we would receive a finished state
496 TestEndPan( application, Vector2(314.0f, 4.0f), time );
498 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
499 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
500 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
501 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
502 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
503 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
504 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
508 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
510 TestApplication application;
512 Actor actor = Actor::New();
513 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
514 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
515 application.GetScene().Add(actor);
518 application.SendNotification();
519 application.Render();
522 GestureReceivedFunctor functor(data);
524 PanGestureDetector detector = PanGestureDetector::New();
525 detector.Attach(actor);
526 detector.DetectedSignal().Connect(&application, functor);
528 // Start pan within the actor's area
530 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
532 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
533 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
534 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
535 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
536 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
537 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
538 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
540 // Continue the pan within the actor's area - we should still receive the signal
543 TestMovePan( application, Vector2(26.0f, 4.0f), time );
544 time += TestGetFrameInterval();
546 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
547 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
548 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
549 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
550 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
551 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
552 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
554 // Gesture ends within actor's area - we would receive a finished state
557 TestEndPan( application, Vector2(10.0f, 4.0f), time );
559 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
560 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
561 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
562 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
563 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
564 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
565 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
569 int UtcDaliPanGestureSignalReceptionDetach(void)
571 TestApplication application;
573 Actor actor = Actor::New();
574 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
575 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
576 application.GetScene().Add(actor);
579 application.SendNotification();
580 application.Render();
583 GestureReceivedFunctor functor(data);
585 PanGestureDetector detector = PanGestureDetector::New();
586 detector.Attach(actor);
587 detector.DetectedSignal().Connect(&application, functor);
589 // Start pan within the actor's area
591 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
592 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
594 // Continue the pan within the actor's area - we should still receive the signal
597 TestMovePan( application, Vector2(26.0f, 4.0f), time );
598 time += TestGetFrameInterval();
600 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
602 // Gesture ends within actor's area
605 TestEndPan( application, Vector2(10.0f, 4.0f), time );
606 time += TestGetFrameInterval();
608 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
611 detector.DetachAll();
613 // Ensure we are no longer signalled
616 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
617 TestMovePan( application, Vector2(26.0f, 4.0f), time );
618 time += TestGetFrameInterval();
619 TestEndPan( application, Vector2(10.0f, 4.0f), time );
621 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
625 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
627 TestApplication application;
629 Actor actor = Actor::New();
630 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
631 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
632 application.GetScene().Add(actor);
635 application.SendNotification();
636 application.Render();
639 GestureReceivedFunctor functor(data);
641 PanGestureDetector detector = PanGestureDetector::New();
642 detector.Attach(actor);
643 detector.DetectedSignal().Connect(&application, functor);
645 // Start pan within the actor's area
647 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
648 application.SendNotification();
650 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
652 // Continue the pan within the actor's area - we should still receive the signal
655 TestMovePan( application, Vector2(26.0f, 4.0f), time );
656 time += TestGetFrameInterval();
658 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
660 // Detach actor during the pan, we should not receive the next event
661 detector.DetachAll();
663 // Gesture ends within actor's area
666 TestEndPan( application, Vector2(10.0f, 4.0f), time );
668 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
672 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
674 TestApplication application;
677 GestureReceivedFunctor functor(data);
679 PanGestureDetector detector = PanGestureDetector::New();
680 detector.DetectedSignal().Connect(&application, functor);
682 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
684 Actor tempActor = Actor::New();
685 tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
686 tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
687 application.GetScene().Add(tempActor);
688 detector.Attach(tempActor);
692 // Actor lifetime is scoped
694 Actor actor = Actor::New();
695 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
696 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
697 application.GetScene().Add(actor);
700 application.SendNotification();
701 application.Render();
703 detector.Attach(actor);
705 // Start pan within the actor's area
706 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
708 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
710 // Continue the pan within the actor's area - we should still receive the signal
713 TestMovePan( application, Vector2(26.0f, 4.0f), time );
714 time += TestGetFrameInterval();
716 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
718 // Remove the actor from stage and reset the data
719 application.GetScene().Remove(actor);
722 application.SendNotification();
723 application.Render();
726 // Actor should now have been destroyed
728 // Gesture ends within the area where the actor used to be
731 TestEndPan( application, Vector2(10.0f, 4.0f), time );
733 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
737 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
739 TestApplication application;
741 Actor actor = Actor::New();
742 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
743 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
744 application.GetScene().Add(actor);
747 application.SendNotification();
748 application.Render();
751 GestureReceivedFunctor functor(data);
753 PanGestureDetector detector = PanGestureDetector::New();
754 detector.Attach(actor);
755 detector.DetectedSignal().Connect(&application, functor);
757 // Do an entire pan, only check finished value
759 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
763 TestEndPan( application, Vector2(25.0f, 28.0f), time );
765 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
766 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
768 // Rotate actor again and render a couple of times
769 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
770 application.SendNotification();
771 application.Render();
773 // Do an entire pan, only check finished value
774 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
778 TestEndPan( application, Vector2(25.0f, 28.0f), time );
780 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
781 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
783 // Rotate actor again and render a couple of times
784 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
785 application.SendNotification();
786 application.Render();
788 // Do an entire pan, only check finished value
789 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
793 TestEndPan( application, Vector2(25.0f, 28.0f), time );
795 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
796 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
800 int UtcDaliPanGestureSignalReceptionChildHit(void)
802 TestApplication application;
804 Actor parent = Actor::New();
805 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
806 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
807 application.GetScene().Add(parent);
809 // Set child to completely cover parent.
810 // Change rotation of child to be different from parent so that we can check if our local coordinate
811 // conversion of the parent actor is correct.
812 Actor child = Actor::New();
813 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
814 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
815 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
816 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
821 application.SendNotification();
822 application.Render();
825 GestureReceivedFunctor functor(data);
827 PanGestureDetector detector = PanGestureDetector::New();
828 detector.Attach(parent);
829 detector.DetectedSignal().Connect(&application, functor);
831 // Do an entire pan, only check finished value - hits child area but parent should still receive it
833 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
837 TestEndPan( application, Vector2(25.0f, 28.0f), time );
839 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
840 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
841 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
843 // Attach child and generate same touch points to yield a different displacement
844 // (Also proves that you can detach and then re-attach another actor)
845 detector.Attach(child);
846 detector.Detach(parent);
848 // Do an entire pan, only check finished value
849 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
853 TestEndPan( application, Vector2(25.0f, 28.0f), time );
855 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
856 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
857 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
861 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
863 TestApplication application;
865 Actor first = Actor::New();
866 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
867 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
868 application.GetScene().Add(first);
870 Actor second = Actor::New();
871 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
872 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
873 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
874 application.GetScene().Add(second);
877 application.SendNotification();
878 application.Render();
881 GestureReceivedFunctor functor(data);
883 PanGestureDetector detector = PanGestureDetector::New();
884 detector.Attach(first);
885 detector.Attach(second);
886 detector.DetectedSignal().Connect(&application, functor);
888 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
889 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
891 // Start pan within second actor's area
893 TestStartPan( application, Vector2( 110.0f, 20.0f ), Vector2( 126.0f, 20.0f ), time );
895 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
896 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
898 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
899 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
901 // Pan moves into first actor's area - second actor should receive the pan
904 TestMovePan( application, Vector2(126.0f, 20.0f), time );
905 time += TestGetFrameInterval();
907 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
908 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
910 // Detach the second actor during the pan, we should not receive the next event
911 detector.Detach(second);
913 // Gesture ends within actor's area
916 TestMovePan( application, Vector2(26.0f, 20.0f), time );
917 TestEndPan( application, Vector2(10.0f, 4.0f), time );
919 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
924 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
926 TestApplication application;
928 Actor actor = Actor::New();
929 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
930 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
931 application.GetScene().Add(actor);
934 application.SendNotification();
935 application.Render();
938 GestureReceivedFunctor functor(data);
940 PanGestureDetector detector = PanGestureDetector::New();
941 detector.Attach(actor);
942 detector.DetectedSignal().Connect(&application, functor);
944 // Start pan in actor's area
946 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
948 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
950 // Pan continues within actor's area
953 TestMovePan( application, Vector2(26.0f, 4.0f), time );
954 time += TestGetFrameInterval();
956 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
958 // Actor become invisible - actor should not receive the next pan
959 actor.SetProperty( Actor::Property::VISIBLE,false);
962 application.SendNotification();
963 application.Render();
965 // Gesture ends within actor's area
968 TestEndPan( application, Vector2(10.0f, 4.0f), time );
970 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
974 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
976 TestApplication application;
978 Actor actor = Actor::New();
979 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
980 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
981 application.GetScene().Add(actor);
983 Actor actor2 = Actor::New();
984 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
985 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
986 application.GetScene().Add(actor2);
989 application.SendNotification();
990 application.Render();
992 // Attach actor to one detector
993 SignalData firstData;
994 GestureReceivedFunctor firstFunctor(firstData);
995 PanGestureDetector firstDetector = PanGestureDetector::New();
996 firstDetector.Attach(actor);
997 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
999 // Attach actor to another detector
1000 SignalData secondData;
1001 GestureReceivedFunctor secondFunctor(secondData);
1002 PanGestureDetector secondDetector = PanGestureDetector::New();
1003 secondDetector.Attach(actor);
1004 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1006 // Add second actor to second detector, when we remove the actor, this will make sure that this
1007 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1008 // functor should still not be called (which is what we're also testing).
1009 secondDetector.Attach(actor2);
1011 // Pan in actor's area - both detector's functors should be called
1012 uint32_t time = 100;
1013 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1015 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1016 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1018 // Pan continues in actor's area - both detector's functors should be called
1022 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1023 time += TestGetFrameInterval();
1025 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1026 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1028 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1029 firstDetector.Detach(actor);
1033 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1035 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1036 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1038 // New pan on actor, only secondDetector has actor attached
1042 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1044 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1045 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1047 // Detach actor from secondDetector
1048 secondDetector.Detach(actor);
1052 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1054 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1055 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1060 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1062 TestApplication application;
1064 Actor actor1 = Actor::New();
1065 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1066 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1067 application.GetScene().Add(actor1);
1069 GestureReceivedFunctor functor1(data1);
1070 PanGestureDetector detector1 = PanGestureDetector::New();
1071 detector1.Attach(actor1);
1072 detector1.DetectedSignal().Connect(&application, functor1);
1074 Actor actor2 = Actor::New();
1075 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1076 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
1077 actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
1078 application.GetScene().Add(actor2);
1080 GestureReceivedFunctor functor2(data2);
1081 PanGestureDetector detector2 = PanGestureDetector::New();
1082 detector2.Attach(actor2);
1083 detector2.DetectedSignal().Connect(&application, functor2);
1085 // Render and notify
1086 application.SendNotification();
1087 application.Render();
1089 // Start pan in actor1's area, only data1 should be set
1090 uint32_t time = 100;
1091 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1093 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1094 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1098 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1100 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1102 TestApplication application;
1104 Actor actor = Actor::New();
1105 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1106 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1107 application.GetScene().Add(actor);
1109 // Render and notify
1110 application.SendNotification();
1111 application.Render();
1113 // Gesture possible in actor's area (using long-press)
1114 uint32_t time = 100;
1115 TestStartLongPress( application, 10.0f, 20.0f, time );
1116 time += TestGetFrameInterval();
1118 // Attach actor to detector
1120 GestureReceivedFunctor functor( data );
1121 PanGestureDetector detector = PanGestureDetector::New();
1122 detector.DetectedSignal().Connect( &application, functor );
1123 detector.Attach(actor);
1125 // Start a pan, initially it'll only be possible, we shouldn't receive it
1126 TestMovePan( application, Vector2( 10.0f, 20.0f ), time );
1127 time += TestGetFrameInterval();
1128 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1130 // Now the pan truly starts, we should receive a signal
1131 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1132 time += TestGetFrameInterval();
1133 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1134 time += TestGetFrameInterval();
1135 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1137 // Finish the pan, we should still receive a signal
1139 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1140 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1145 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1147 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1148 // pan actor was there before (parent)
1150 TestApplication application;
1152 Actor parent = Actor::New();
1153 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1154 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1155 application.GetScene().Add( parent );
1157 Actor child = Actor::New();
1158 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1159 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
1160 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1161 parent.Add( child );
1163 // Create detector for parent and attach
1164 SignalData parentData;
1165 GestureReceivedFunctor parentFunctor( parentData );
1166 PanGestureDetector parentDetector = PanGestureDetector::New();
1167 parentDetector.DetectedSignal().Connect( &application, parentFunctor );
1168 parentDetector.Attach( parent );
1170 // Create detector for child but do not attach
1171 SignalData childData;
1172 GestureReceivedFunctor childFunctor( childData );
1173 PanGestureDetector childDetector = PanGestureDetector::New();
1174 childDetector.DetectedSignal().Connect( &application, childFunctor );
1176 // Render and notify
1177 application.SendNotification();
1178 application.Render();
1180 // Do a full pan in both actors' area, only the parent's functor should be called
1181 uint32_t time = 100;
1182 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1183 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1184 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1187 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1188 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1189 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1193 // Gesture possible in both actors' area (using long-press), no functors called
1194 TestStartLongPress( application, 10.0f, 20.0f, time );
1195 time += TestGetFrameInterval();
1196 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1197 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1199 // Attach the child as well now
1200 childDetector.Attach( child );
1202 // Now the pan truly starts, we should receive a signal for the child only
1203 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1204 time += TestGetFrameInterval();
1205 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1206 time += TestGetFrameInterval();
1207 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1208 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1212 // Finish the pan, again only the child should still receive a signal
1213 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1214 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1215 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1220 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1222 TestApplication application;
1224 Actor actor = Actor::New();
1225 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1226 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1227 application.GetScene().Add(actor);
1229 // Render and notify
1230 application.SendNotification();
1231 application.Render();
1233 // Attach actor to detector
1235 GestureReceivedFunctor functor( data );
1236 PanGestureDetector detector = PanGestureDetector::New();
1237 detector.Attach(actor);
1238 detector.DetectedSignal().Connect( &application, functor );
1240 // Gesture possible in actor's area.
1241 uint32_t time = 100;
1242 TestStartLongPress( application, 10.0f, 20.0f, time );
1243 time += TestGetFrameInterval();
1245 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1247 // Move actor somewhere else
1248 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
1250 // Render and notify
1251 application.SendNotification();
1252 application.Render();
1254 // Emit Started event, we should not receive the pan.
1255 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1256 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1257 time += TestGetFrameInterval();
1259 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1261 // LongPress possible in empty area.
1262 TestStartLongPress( application, 10.0f, 20.0f, time );
1263 time += TestGetFrameInterval();
1265 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1267 // Move actor in to the long press position.
1268 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
1270 // Render and notify
1271 application.SendNotification();
1272 application.Render();
1274 // Emit Started event, we should be receiving the pan now.
1275 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1276 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1277 time += TestGetFrameInterval();
1279 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1281 // Normal pan in actor's area for completeness.
1283 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1284 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1285 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1289 int UtcDaliPanGestureActorUnstaged(void)
1291 TestApplication application;
1293 Actor actor = Actor::New();
1294 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1295 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1296 application.GetScene().Add(actor);
1298 // Render and notify
1299 application.SendNotification();
1300 application.Render();
1302 // State to remove actor in.
1303 Gesture::State stateToUnstage( Gesture::Started );
1305 // Attach actor to detector
1307 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1308 PanGestureDetector detector = PanGestureDetector::New();
1309 detector.Attach(actor);
1310 detector.DetectedSignal().Connect( &application, functor );
1313 uint32_t time = 100;
1314 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1316 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1319 TestEndPan( application, Vector2(26.0f, 20.0f), time );
1321 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1324 // Render and notify
1325 application.SendNotification();
1326 application.Render();
1328 // Re-add actor to stage
1329 application.GetScene().Add(actor);
1331 // Render and notify
1332 application.SendNotification();
1333 application.Render();
1335 // Change state to Gesture::Continuing to remove
1336 stateToUnstage = Gesture::Continuing;
1339 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1341 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1344 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1345 time += TestGetFrameInterval();
1347 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1351 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1353 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1356 // Render and notify
1357 application.SendNotification();
1358 application.Render();
1360 // Re-add actor to stage
1361 application.GetScene().Add(actor);
1363 // Render and notify
1364 application.SendNotification();
1365 application.Render();
1367 // Change state to Gesture::Finished to remove
1368 stateToUnstage = Gesture::Finished;
1371 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1373 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1376 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1377 time += TestGetFrameInterval();
1379 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1382 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1384 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1385 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1389 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1391 TestApplication application;
1393 Actor actor = Actor::New();
1394 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1395 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1396 application.GetScene().Add(actor);
1398 // Create and add a second actor so that GestureDetector destruction does not come into play.
1399 Actor dummyActor( Actor::New() );
1400 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1401 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
1402 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1403 application.GetScene().Add(dummyActor);
1405 // Render and notify
1406 application.SendNotification();
1407 application.Render();
1409 // State to remove actor in.
1410 Gesture::State stateToUnstage( Gesture::Started );
1412 // Attach actor to detector
1414 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1415 PanGestureDetector detector = PanGestureDetector::New();
1416 detector.Attach(actor);
1417 detector.Attach(dummyActor);
1418 detector.DetectedSignal().Connect( &application, functor );
1420 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1421 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1422 // position, we should still not be signalled.
1425 uint32_t time = 100;
1426 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1428 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1431 // Render and notify
1432 application.SendNotification();
1433 application.Render();
1435 // Re add to the stage, we should not be signalled
1436 application.GetScene().Add(actor);
1438 // Render and notify
1439 application.SendNotification();
1440 application.Render();
1442 // Continue signal emission
1443 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1444 time += TestGetFrameInterval();
1446 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1449 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1450 time += TestGetFrameInterval();
1452 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1455 // Here we delete an actor in started, we should not receive any subsequent signalling.
1458 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1460 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1463 // Render and notify
1464 application.SendNotification();
1465 application.Render();
1467 // Delete actor as well
1470 // Render and notify
1471 application.SendNotification();
1472 application.Render();
1474 // Continue signal emission
1475 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1476 time += TestGetFrameInterval();
1478 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1481 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1483 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1487 int UtcDaliPanGestureAngleHandling(void)
1489 TestApplication application;
1491 PanGestureDetector detector = PanGestureDetector::New();
1492 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1494 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1495 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1497 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1499 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1501 tet_result( TET_PASS );
1509 tet_printf("%s, angle not added\n", TEST_LOCATION );
1510 tet_result( TET_FAIL );
1513 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1514 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1516 // Remove something not in the container.
1517 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1518 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1520 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1521 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1522 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1524 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1526 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1527 tet_result( TET_FAIL );
1532 detector.ClearAngles();
1533 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1537 int UtcDaliPanGestureGetAngle(void)
1539 TestApplication application;
1541 PanGestureDetector detector = PanGestureDetector::New();
1542 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1544 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1545 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1547 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1548 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1550 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1551 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1553 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1554 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1556 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1557 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1558 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1559 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1564 inline float RadiansToDegrees( float radian )
1566 return radian * 180.0f / Math::PI;
1569 int UtcDaliPanGestureAngleOutOfRange(void)
1571 TestApplication application;
1573 PanGestureDetector detector = PanGestureDetector::New();
1574 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1580 detector.AddAngle( Degree(180.0f) );
1581 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1582 detector.ClearAngles();
1584 detector.AddAngle( Degree(190.0f) );
1585 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1586 detector.ClearAngles();
1588 detector.AddAngle( Degree(-190.0f) );
1589 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1590 detector.ClearAngles();
1592 detector.AddAngle( Degree(350.0f) );
1593 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1594 detector.ClearAngles();
1596 detector.AddAngle( Degree(-350.0f) );
1597 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1598 detector.ClearAngles();
1600 detector.AddAngle( Degree(370.0f) );
1601 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1602 detector.ClearAngles();
1604 detector.AddAngle( Degree(-370.0f) );
1605 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1606 detector.ClearAngles();
1612 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1613 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1614 detector.ClearAngles();
1616 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1617 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1618 detector.ClearAngles();
1620 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1621 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1622 detector.ClearAngles();
1624 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1625 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1626 detector.ClearAngles();
1630 int UtcDaliPanGestureAngleProcessing(void)
1632 TestApplication application;
1634 Actor parent = Actor::New();
1635 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1636 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1637 application.GetScene().Add(parent);
1639 Actor child = Actor::New();
1640 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1641 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1644 // Render and notify
1645 application.SendNotification();
1646 application.Render();
1648 // Parent detector only requires up pans
1649 PanGestureDetector parentDetector = PanGestureDetector::New();
1650 parentDetector.Attach( parent );
1651 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1652 SignalData parentData;
1653 GestureReceivedFunctor parentFunctor(parentData);
1654 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1656 // Child detector only requires right pans
1657 PanGestureDetector childDetector = PanGestureDetector::New();
1658 childDetector.Attach( child );
1659 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1660 SignalData childData;
1661 GestureReceivedFunctor childFunctor(childData);
1662 childDetector.DetectedSignal().Connect(&application, childFunctor);
1664 // Generate an Up pan gesture, only parent should receive it.
1665 uint32_t time = 100;
1666 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1668 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1669 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1671 TestEndPan( application, Vector2(20.0f, 4.0f), time );
1672 time += TestGetFrameInterval();
1676 // Generate a Right pan gesture, only child should receive it.
1677 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1679 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1680 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1682 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1683 time += TestGetFrameInterval();
1687 // Generate a Down pan gesture, no one should receive it.
1688 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1690 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1691 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1693 TestEndPan( application, Vector2(20.0f, 36.0f), time );
1694 time += TestGetFrameInterval();
1698 // Generate a Left pan gesture, no one should receive it.
1699 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1701 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1702 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1704 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1710 int UtcDaliPanGestureDirectionHandling(void)
1712 TestApplication application;
1714 PanGestureDetector detector = PanGestureDetector::New();
1715 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1717 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1718 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1720 for ( size_t i = 0; detector.GetAngleCount(); i++)
1722 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1724 tet_result( TET_PASS );
1733 tet_printf("%s, angle not added\n", TEST_LOCATION );
1734 tet_result( TET_FAIL );
1738 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1740 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1742 tet_result( TET_PASS );
1750 tet_printf("%s, angle not added\n", TEST_LOCATION );
1751 tet_result( TET_FAIL );
1754 // Remove something not in the container.
1755 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1756 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1758 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1759 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1763 int UtcDaliPanGestureDirectionProcessing(void)
1765 TestApplication application;
1767 Actor parent = Actor::New();
1768 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1769 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1770 application.GetScene().Add(parent);
1772 Actor child = Actor::New();
1773 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1774 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1777 // Render and notify
1778 application.SendNotification();
1779 application.Render();
1781 // Parent detector only requires vertical panning
1782 PanGestureDetector parentDetector = PanGestureDetector::New();
1783 parentDetector.Attach( parent );
1784 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1785 SignalData parentData;
1786 GestureReceivedFunctor parentFunctor(parentData);
1787 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1789 // Child detector only requires horizontal panning
1790 PanGestureDetector childDetector = PanGestureDetector::New();
1791 childDetector.Attach( child );
1792 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1793 SignalData childData;
1794 GestureReceivedFunctor childFunctor(childData);
1795 childDetector.DetectedSignal().Connect(&application, childFunctor);
1797 // Generate an Up pan gesture, only parent should receive it.
1798 uint32_t time = 100;
1799 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1801 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1802 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1804 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1805 time += TestGetFrameInterval();
1809 // Generate a Right pan gesture, only child should receive it.
1810 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1812 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1813 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1815 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1816 time += TestGetFrameInterval();
1820 // Generate a Down pan gesture, only parent should receive it.
1821 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1823 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1824 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1826 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1827 time += TestGetFrameInterval();
1831 // Generate a Left pan gesture, only child should receive it.
1832 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1834 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1835 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1837 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1838 time += TestGetFrameInterval();
1842 // Generate a pan at -45 degrees, no one should receive it.
1843 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 9.0f, 31.0f ), time );
1845 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1846 DALI_TEST_EQUALS( false, 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( 31.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 -135 degrees, no one should receive it.
1865 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 4.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 );
1876 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1878 TestApplication application;
1879 Integration::SetPanGesturePredictionMode(0);
1880 Integration::SetPanGestureSmoothingMode(0);
1882 Actor actor = Actor::New();
1883 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1884 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1885 application.GetScene().Add(actor);
1887 // Add a pan detector
1888 PanGestureDetector detector = PanGestureDetector::New();
1889 detector.Attach( actor );
1891 GestureReceivedFunctor functor( data );
1892 detector.DetectedSignal().Connect( &application, functor );
1894 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1896 ConstraintData constraintData;
1897 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1898 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1899 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1900 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1901 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1902 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1903 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1904 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1907 // Render and notify
1908 application.SendNotification();
1909 application.Render();
1911 Vector2 startPosition( 1.0f, 1.0f );
1912 Vector2 position( -14.0f, 1.0f );
1913 Vector2 direction(Vector2::XAXIS * -5.0f);
1914 uint32_t time = 100;
1916 TestStartPan( application, startPosition, position, time );
1918 for(int i = 0; i < 47; i++ )
1920 position += direction;
1921 TestMovePan( application, position, time );
1922 time += TestGetFrameInterval();
1923 application.SendNotification();
1924 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1927 TestEndPan( application, position, time );
1928 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1930 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1931 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1932 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1933 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1935 constraintData.Reset();
1939 int UtcDaliPanGestureNoPredictionSmoothing(void)
1941 TestApplication application;
1942 Integration::SetPanGesturePredictionMode(0);
1943 Integration::SetPanGestureSmoothingMode(1);
1945 Actor actor = Actor::New();
1946 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1947 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1948 application.GetScene().Add(actor);
1950 // Add a pan detector
1951 PanGestureDetector detector = PanGestureDetector::New();
1952 detector.Attach( actor );
1954 GestureReceivedFunctor functor( data );
1955 detector.DetectedSignal().Connect( &application, functor );
1957 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1959 ConstraintData constraintData;
1960 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1961 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1962 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1963 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1964 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1965 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1966 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1967 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1970 // Render and notify
1971 application.SendNotification();
1972 application.Render();
1974 Vector2 startPosition( 1.0f, 1.0f );
1975 Vector2 position( -14.0f, 1.0f );
1976 Vector2 direction(Vector2::XAXIS * -5.0f);
1977 uint32_t time = 100;
1979 TestStartPan( application, startPosition, position, time );
1981 for(int i = 0; i < 47; i++ )
1983 position += direction;
1984 TestMovePan( application, position, time );
1985 time += TestGetFrameInterval();
1986 application.SendNotification();
1987 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1990 TestEndPan( application, position, time );
1991 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1993 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1994 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1995 // Take into account resampling done when prediction is off.
1996 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
1997 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
1999 constraintData.Reset();
2003 int UtcDaliPanGesturePredictionNoSmoothing(void)
2005 TestApplication application;
2006 Integration::SetPanGesturePredictionMode(1);
2007 Integration::SetPanGestureSmoothingMode(0);
2009 Actor actor = Actor::New();
2010 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2011 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2012 application.GetScene().Add(actor);
2014 // Add a pan detector
2015 PanGestureDetector detector = PanGestureDetector::New();
2016 detector.Attach( actor );
2018 GestureReceivedFunctor functor( data );
2019 detector.DetectedSignal().Connect( &application, functor );
2021 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2023 ConstraintData constraintData;
2024 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2025 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2026 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2027 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2028 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2029 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2030 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2031 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2034 // Render and notify
2035 application.SendNotification();
2036 application.Render();
2038 Vector2 startPosition( 1.0f, 1.0f );
2039 Vector2 position( -1.0f, 1.0f );
2040 Vector2 direction(Vector2::XAXIS * -1.0f);
2041 uint32_t time = 100;
2043 TestStartPan( application, startPosition, position, time );
2045 for(int i = 0; i < 47; i++ )
2047 position += direction;
2048 TestMovePan( application, position, time );
2049 time += TestGetFrameInterval();
2050 application.SendNotification();
2051 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2054 TestEndPan( application, position, time );
2055 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2057 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2058 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2059 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2060 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2062 constraintData.Reset();
2066 int UtcDaliPanGesturePredictionSmoothing01(void)
2068 TestApplication application;
2069 Integration::SetPanGesturePredictionMode(1);
2070 Integration::SetPanGestureSmoothingMode(1);
2072 Actor actor = Actor::New();
2073 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2074 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2075 application.GetScene().Add(actor);
2077 // Add a pan detector
2078 PanGestureDetector detector = PanGestureDetector::New();
2079 detector.Attach( actor );
2081 GestureReceivedFunctor functor( data );
2082 detector.DetectedSignal().Connect( &application, functor );
2084 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2086 ConstraintData constraintData;
2087 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2088 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2089 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2090 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2091 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2092 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2093 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2094 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2097 // Render and notify
2098 application.SendNotification();
2099 application.Render();
2101 Vector2 startPosition( 1.0f, 1.0f );
2102 Vector2 position( -1.0f, 1.0f );
2103 Vector2 direction(Vector2::XAXIS * -1.0f);
2104 uint32_t time = 100;
2106 TestStartPan( application, startPosition, position, time );
2108 for(int i = 0; i < 47; i++ )
2110 position += direction;
2111 TestMovePan( application, position, time );
2112 time += TestGetFrameInterval();
2113 application.SendNotification();
2114 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2117 TestEndPan( application, position, time );
2118 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2120 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2121 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2122 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2123 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2125 constraintData.Reset();
2129 int UtcDaliPanGesturePredictionSmoothing02(void)
2131 TestApplication application;
2132 Integration::SetPanGesturePredictionMode( 1 );
2133 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2134 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2135 Integration::SetPanGestureSmoothingMode( 1 );
2136 Integration::SetPanGestureSmoothingAmount( 0.25f );
2138 Actor actor = Actor::New();
2139 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2140 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2141 application.GetScene().Add(actor);
2143 // Add a pan detector
2144 PanGestureDetector detector = PanGestureDetector::New();
2145 detector.Attach( actor );
2147 GestureReceivedFunctor functor( data );
2148 detector.DetectedSignal().Connect( &application, functor );
2150 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2152 ConstraintData constraintData;
2153 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2154 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2155 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2156 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2157 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2158 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2159 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2160 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2163 // Render and notify
2164 application.SendNotification();
2165 application.Render();
2167 Vector2 startPosition( 2.0f, 2.0f );
2168 Vector2 position( 4.0f, 2.0f );
2169 Vector2 directionX(Vector2::XAXIS);
2170 Vector2 directionY(Vector2::YAXIS);
2171 uint32_t time = 100;
2173 TestStartPan( application, startPosition, position, time );
2175 for(int i = 0; i < 7; i++ )
2177 position += directionX;
2178 TestMovePan( application, position, time );
2179 time += TestGetFrameInterval();
2180 application.SendNotification();
2181 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2184 position += directionX * 10.0f;
2185 TestMovePan( application, position, time );
2186 time += TestGetFrameInterval();
2187 application.SendNotification();
2188 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2190 for(int i = 0; i < 2; i++ )
2192 position += ( directionX * -1.0f );
2193 TestMovePan( application, position, time );
2194 time += TestGetFrameInterval();
2195 application.SendNotification();
2196 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2199 for(int i = 0; i < 10; i++ )
2201 position += directionX;
2202 TestMovePan( application, position, time );
2203 time += TestGetFrameInterval();
2204 application.SendNotification();
2205 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2208 for(int i = 0; i < 10; i++ )
2210 position += directionY;
2211 TestMovePan( application, position, time );
2212 time += TestGetFrameInterval();
2213 application.SendNotification();
2214 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2217 TestEndPan( application, position, time );
2218 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2220 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2221 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2222 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2223 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2225 constraintData.Reset();
2229 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2231 TestApplication application;
2233 Integration::SetPanGesturePredictionMode( 2 );
2234 Integration::SetPanGesturePredictionAmount( 57 );
2235 Integration::SetPanGestureSmoothingMode( 2 );
2236 Integration::SetPanGestureUseActualTimes( false );
2237 Integration::SetPanGestureInterpolationTimeRange( 10 );
2238 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2239 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2240 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2241 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2242 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2243 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2245 Actor actor = Actor::New();
2246 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2247 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2248 application.GetScene().Add(actor);
2250 // Add a pan detector
2251 PanGestureDetector detector = PanGestureDetector::New();
2252 detector.Attach( actor );
2254 GestureReceivedFunctor functor( data );
2255 detector.DetectedSignal().Connect( &application, functor );
2257 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2259 ConstraintData constraintData;
2260 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2261 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2262 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2263 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2264 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2265 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2266 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2267 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2270 // Render and notify
2271 application.SendNotification();
2272 application.Render();
2274 Vector2 startPosition( 2.0f, 2.0f );
2275 Vector2 position( -1.0f, 2.0f );
2276 Vector2 direction(Vector2::XAXIS * -1.0f);
2277 uint32_t time = 100;
2279 TestStartPan( application, startPosition, position, time );
2281 for(int i = 0; i < 27; i++ )
2283 position += direction;
2284 TestMovePan( application, position, time );
2285 time += TestGetFrameInterval();
2286 application.SendNotification();
2287 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2290 TestEndPan( application, position, time );
2291 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2293 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2294 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2295 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2296 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2298 constraintData.Reset();
2302 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2304 TestApplication application;
2306 Integration::SetPanGesturePredictionMode( 2 );
2307 Integration::SetPanGestureSmoothingMode( 2 );
2308 Integration::SetPanGestureUseActualTimes( true );
2309 Integration::SetPanGestureInterpolationTimeRange( 10 );
2310 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2311 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2312 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2313 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2314 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2315 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2317 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2319 Actor actor = Actor::New();
2320 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2321 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2322 application.GetScene().Add(actor);
2324 // Add a pan detector
2325 PanGestureDetector detector = PanGestureDetector::New();
2326 detector.Attach( actor );
2328 GestureReceivedFunctor functor( data );
2329 detector.DetectedSignal().Connect( &application, functor );
2331 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2333 ConstraintData constraintData;
2334 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2335 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2336 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2337 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2338 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2339 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2340 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2341 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2344 // Render and notify
2345 application.SendNotification();
2346 application.Render();
2348 Vector2 startPosition( 2.0f, 2.0f );
2349 Vector2 position( 17.0f, 2.0f );
2350 Vector2 direction(Vector2::XAXIS * -1.0f);
2351 uint32_t time = 100;
2353 TestStartPan( application, startPosition, position, time );
2355 for(int i = 0; i < 10; i++ )
2357 position += direction;
2358 TestMovePan( application, position, time );
2359 time += TestGetFrameInterval();
2361 position += direction;
2362 TestMovePan( application, position, time );
2363 time += TestGetFrameInterval();
2365 position += direction;
2366 TestMovePan( application, position, time );
2367 time += TestGetFrameInterval();
2369 application.SendNotification();
2370 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2373 for(int i = 0; i < 10; i++ )
2375 application.SendNotification();
2376 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2379 for(int i = 0; i < 10; i++ )
2381 position += direction;
2382 TestMovePan( application, position, time );
2383 application.SendNotification();
2384 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2387 for(int i = 0; i < 10; i++ )
2389 position += direction;
2390 TestMovePan( application, position, time );
2391 time += TestGetFrameInterval();
2392 application.SendNotification();
2393 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2396 TestEndPan( application, position, time );
2397 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2399 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2400 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2401 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2402 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2404 constraintData.Reset();
2408 int UtcDaliPanGesturePrediction2Smoothing(void)
2410 TestApplication application;
2412 Integration::SetPanGesturePredictionMode( 2 );
2413 Integration::SetPanGesturePredictionAmount( 57 );
2414 Integration::SetPanGestureSmoothingMode( 1 );
2415 Integration::SetPanGestureUseActualTimes( false );
2416 Integration::SetPanGestureInterpolationTimeRange( 10 );
2417 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2418 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2419 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2420 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2421 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2422 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2424 Actor actor = Actor::New();
2425 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2426 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2427 application.GetScene().Add(actor);
2429 // Add a pan detector
2430 PanGestureDetector detector = PanGestureDetector::New();
2431 detector.Attach( actor );
2433 GestureReceivedFunctor functor( data );
2434 detector.DetectedSignal().Connect( &application, functor );
2436 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2438 ConstraintData constraintData;
2439 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2440 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2441 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2442 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2443 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2444 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2445 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2446 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2449 // Render and notify
2450 application.SendNotification();
2451 application.Render();
2453 Vector2 startPosition( 2.0f, 2.0f );
2454 Vector2 position( 17.0f, 2.0f );
2455 Vector2 direction(Vector2::XAXIS * -1.0f);
2456 uint32_t time = 100;
2458 TestStartPan( application, startPosition, position, time );
2460 for(int i = 0; i < 10; i++ )
2462 position += direction;
2463 TestMovePan( application, position, time );
2464 time += TestGetFrameInterval();
2465 application.SendNotification();
2466 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2470 position += direction;
2471 TestMovePan( application, position, time );
2472 time += TestGetFrameInterval();
2474 position += direction;
2475 TestMovePan( application, position, time );
2476 time += TestGetFrameInterval();
2478 position += direction;
2479 TestMovePan( application, position, time );
2480 time += TestGetFrameInterval();
2482 application.SendNotification();
2483 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2485 for(int i = 0; i < 5; i++ )
2487 application.SendNotification();
2488 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2491 for(int i = 0; i < 10; i++ )
2493 position += direction;
2494 TestMovePan( application, position, time );
2495 time += TestGetFrameInterval();
2496 application.SendNotification();
2497 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2500 TestEndPan( application, position, time );
2501 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2503 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2504 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2505 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2506 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2508 constraintData.Reset();
2512 int UtcDaliPanGestureSetProperties(void)
2514 TestApplication application;
2515 TestRenderController& renderController( application.GetRenderController() );
2516 Integration::SetPanGesturePredictionMode(0);
2517 Integration::SetPanGestureSmoothingMode(0);
2519 Actor actor = Actor::New();
2520 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2521 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2522 application.GetScene().Add(actor);
2524 // Add a pan detector
2525 PanGestureDetector detector = PanGestureDetector::New();
2526 detector.Attach( actor );
2528 GestureReceivedFunctor functor( data );
2529 detector.DetectedSignal().Connect( &application, functor );
2531 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2532 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2534 ConstraintData constraintData;
2535 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2536 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2537 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2538 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2539 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2540 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2541 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2542 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2543 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2546 // Render and notify
2547 application.SendNotification();
2548 application.Render();
2550 renderController.Initialize();
2551 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2553 Vector2 screenPosition( 20.0f, 20.0f );
2554 Vector2 screenDisplacement( 1.0f, 1.0f );
2555 Vector2 screenVelocity( 1.3f, 4.0f );
2556 Vector2 localPosition( 21.0f, 21.0f );
2557 Vector2 localDisplacement( 0.5f, 0.5f );
2558 Vector2 localVelocity( 1.5f, 2.5f );
2560 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2561 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2563 // Render and notify
2564 application.SendNotification();
2565 application.Render();
2567 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2568 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2569 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2570 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2571 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2572 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2573 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2574 constraintData.Reset();
2578 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2580 TestApplication application;
2581 Integration::SetPanGesturePredictionMode(0);
2583 Actor actor = Actor::New();
2584 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2585 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2586 application.GetScene().Add(actor);
2588 // Add a pan detector
2589 PanGestureDetector detector = PanGestureDetector::New();
2590 detector.Attach( actor );
2592 GestureReceivedFunctor functor( data );
2593 detector.DetectedSignal().Connect( &application, functor );
2595 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2597 ConstraintData constraintData;
2598 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2599 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2600 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2601 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2602 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2603 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2604 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2605 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2608 // Render and notify
2609 application.SendNotification();
2610 application.Render();
2612 Vector2 currentPosition( 20.0f, 4.0f );
2613 uint32_t time = 100;
2614 TestStartPan( application, Vector2( 20.0f, 20.0f ), currentPosition, time );
2615 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2617 Vector2 screenPosition( 100.0f, 20.0f );
2618 Vector2 localPosition( 110.0f, 110.0f );
2620 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2622 // Render and notify
2623 application.SendNotification();
2624 application.Render();
2626 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2627 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2628 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2629 constraintData.Reset();
2633 int UtcDaliPanGesturePropertyIndices(void)
2635 TestApplication application;
2636 PanGestureDetector detector = PanGestureDetector::New();
2638 Property::IndexContainer indices;
2639 detector.GetPropertyIndices( indices );
2640 DALI_TEST_CHECK( indices.Size() );
2641 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2647 struct PropertyStringIndex
2649 const char * const name;
2650 const Property::Index index;
2651 const Property::Type type;
2652 const Property::Value value;
2655 const PropertyStringIndex PROPERTY_TABLE[] =
2657 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2658 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2659 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2660 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2661 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2662 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2663 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2665 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2666 } // unnamed namespace
2669 int UtcDaliPanGestureProperties(void)
2671 TestApplication application;
2672 PanGestureDetector detector = PanGestureDetector::New();
2674 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2676 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2677 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2678 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2679 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2680 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2681 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2682 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2688 int UtcDaliPanGestureGetProperty(void)
2690 TestApplication application;
2691 PanGestureDetector detector = PanGestureDetector::New();
2693 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2695 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2697 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2698 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2700 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2702 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2703 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2710 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2712 TestApplication application;
2714 Actor actor = Actor::New();
2715 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2716 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2717 application.GetScene().Add(actor);
2719 // Add a pan detector
2720 PanGestureDetector detector = PanGestureDetector::New();
2721 detector.Attach( actor );
2723 // Render and notify
2724 application.SendNotification();
2725 application.Render();
2727 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2729 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2731 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2733 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2734 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2736 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2738 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2739 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2746 int UtcDaliPanGestureLayerConsumesTouch(void)
2748 TestApplication application;
2750 Actor actor = Actor::New();
2751 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2752 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2753 application.GetScene().Add(actor);
2755 // Add a pan detector
2756 PanGestureDetector detector = PanGestureDetector::New();
2757 detector.Attach( actor );
2759 GestureReceivedFunctor functor( data );
2760 detector.DetectedSignal().Connect( &application, functor );
2762 // Add a layer to overlap the actor
2763 Layer layer = Layer::New();
2764 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2765 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2766 application.GetScene().Add( layer );
2769 // Render and notify
2770 application.SendNotification();
2771 application.Render();
2773 // Emit signals, should receive
2774 uint32_t time = 100;
2775 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2776 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2777 time += TestGetFrameInterval();
2779 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2782 // Set layer to consume all touch
2783 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
2785 // Render and notify
2786 application.SendNotification();
2787 application.Render();
2789 // Emit the same signals again, should not receive
2790 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2791 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2793 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2799 int UtcDaliPanGestureNoTimeDiff(void)
2801 TestApplication application;
2803 Actor actor = Actor::New();
2804 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2805 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2806 application.GetScene().Add(actor);
2808 // Add a pan detector
2809 PanGestureDetector detector = PanGestureDetector::New();
2810 detector.Attach( actor );
2812 GestureReceivedFunctor functor( data );
2813 detector.DetectedSignal().Connect( &application, functor );
2815 // Render and notify
2816 application.SendNotification();
2817 application.Render();
2819 // As normal helper function adds intervals between presses we must generate the sequence
2820 // using other helper functions
2821 TestStartLongPress( application, 10.0f, 20.0f, 100 ); // Used to send a down press event
2822 TestMovePan( application, Vector2(26.0f, 20.0f), 100 );
2823 TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); // 2 motions required to trigger
2824 TestEndPan( application, Vector2(26.0f, 20.0f), 100 );
2826 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2827 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2828 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2829 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2830 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );
2838 int UtcDaliPanGestureInterruptedWhenTouchConsumed(void)
2840 TestApplication application;
2842 Actor actor = Actor::New();
2843 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2844 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2845 application.GetScene().Add(actor);
2847 bool consume = false;
2848 TouchDataFunctorConsumeSetter touchFunctor(consume);
2849 actor.TouchSignal().Connect(&application,touchFunctor);
2851 // Render and notify
2852 application.SendNotification();
2853 application.Render();
2856 GestureReceivedFunctor functor(data);
2858 PanGestureDetector detector = PanGestureDetector::New();
2859 detector.Attach(actor);
2860 detector.DetectedSignal().Connect(&application, functor);
2862 // Start gesture within the actor's area, we should receive the pan as the touch is NOT being consumed
2863 uint32_t time = 100;
2864 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2866 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2867 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
2870 // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
2873 TestMovePan( application, Vector2(26.0f, 4.0f), time );
2874 time += TestGetFrameInterval();
2876 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2877 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
2882 int UtcDaliPanGestureDisableDetectionDuringPanN(void)
2884 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
2886 TestApplication application;
2888 Actor actor = Actor::New();
2889 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2890 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2891 application.GetScene().Add(actor);
2893 // Add a pan detector
2894 PanGestureDetector detector = PanGestureDetector::New();
2895 bool functorCalled = false;
2896 detector.Attach( actor );
2897 detector.DetectedSignal().Connect(
2899 [&detector, &functorCalled](Actor actor, const PanGesture& pan)
2901 if( pan.state == Gesture::Finished )
2903 detector.Detach(actor);
2904 functorCalled = true;
2908 // Render and notify
2909 application.SendNotification();
2910 application.Render();
2912 // Try the gesture, should not crash
2915 uint32_t time = 100;
2916 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2917 TestEndPan( application, Vector2(26.0f, 20.0f) );
2919 DALI_TEST_CHECK( true ); // No crash, test has passed
2920 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
2924 DALI_TEST_CHECK( false ); // If we crash, the test has failed