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-event-utils.h>
29 #include <dali/devel-api/events/pan-gesture-devel.h>
33 void utc_dali_pan_gesture_detector_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_pan_gesture_detector_cleanup(void)
40 test_return_value = TET_PASS;
43 ///////////////////////////////////////////////////////////////////////////////
46 const int PAN_EVENT_TIME_DELTA = 8;
47 const int PAN_GESTURE_UPDATE_COUNT = 50;
49 // Stores data that is populated in the callback and will be read by the test cases
53 : functorCalled(false),
54 voidFunctorCalled(false),
60 functorCalled = false;
61 voidFunctorCalled = false;
63 receivedGesture.Reset();
69 bool voidFunctorCalled;
70 PanGesture receivedGesture;
74 // Functor that sets the data when called
75 struct GestureReceivedFunctor
77 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
79 void operator()(Actor actor, const PanGesture& pan)
81 signalData.functorCalled = true;
82 signalData.receivedGesture = pan;
83 signalData.pannedActor = actor;
88 signalData.voidFunctorCalled = true;
91 SignalData& signalData;
94 // Functor that removes the gestured actor from stage
95 struct UnstageActorFunctor : public GestureReceivedFunctor
97 UnstageActorFunctor( SignalData& data, GestureState& stateToUnstage, Integration::Scene scene )
98 : GestureReceivedFunctor( data ),
99 stateToUnstage( stateToUnstage ),
104 void operator()( Actor actor, const PanGesture& pan )
106 GestureReceivedFunctor::operator()( actor, pan );
108 if ( pan.GetState() == stateToUnstage )
110 scene.Remove( actor );
114 GestureState& stateToUnstage;
115 Integration::Scene scene;
118 // Data for constraints
119 struct ConstraintData
127 Vector2 screenPosition;
128 Vector2 screenDisplacement;
129 Vector2 screenVelocity;
130 Vector2 localPosition;
131 Vector2 localDisplacement;
132 Vector2 localVelocity;
138 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
144 // Constraint used with panning properties
147 PanConstraint( ConstraintData& data ) : constraintData(data) { }
149 void operator()( Vector3& current, const PropertyInputContainer& inputs )
151 constraintData.screenPosition = inputs[0]->GetVector2();
152 constraintData.screenDisplacement = inputs[1]->GetVector2();
153 constraintData.screenVelocity = inputs[2]->GetVector2();
154 constraintData.localPosition = inputs[3]->GetVector2();
155 constraintData.localDisplacement = inputs[4]->GetVector2();
156 constraintData.localVelocity = inputs[5]->GetVector2();
157 constraintData.panning = inputs[6]->GetBoolean();
158 constraintData.called = true;
159 current = Vector3::ZERO;
162 ConstraintData& constraintData;
165 // Generate a PanGesture
166 PanGesture GeneratePan( unsigned int time,
168 Vector2 screenPosition,
169 Vector2 localPosition,
170 Vector2 screenDisplacement = Vector2::ONE,
171 Vector2 localDisplacement = Vector2::ONE,
172 Vector2 screenVelocity = Vector2::ONE,
173 Vector2 localVelocity = Vector2::ONE,
174 unsigned int numberOfTouches = 1 )
176 Dali::PanGesture pan = DevelPanGesture::New( state );
178 DevelPanGesture::SetTime( pan, time );
180 DevelPanGesture::SetScreenPosition( pan, screenPosition );
181 DevelPanGesture::SetPosition( pan, localPosition );
183 DevelPanGesture::SetScreenDisplacement( pan, screenDisplacement );
184 DevelPanGesture::SetDisplacement( pan, localDisplacement );
186 DevelPanGesture::SetScreenVelocity( pan, screenVelocity );
187 DevelPanGesture::SetVelocity( pan, localVelocity );
189 DevelPanGesture::SetNumberOfTouches( pan, numberOfTouches );
196 ///////////////////////////////////////////////////////////////////////////////
198 // Positive test case for a method
199 int UtcDaliPanGestureDetectorConstructor(void)
201 TestApplication application;
203 PanGestureDetector detector;
204 DALI_TEST_CHECK(!detector);
208 int UtcDaliPanGestureDetectorCopyConstructorP(void)
210 TestApplication application;
212 PanGestureDetector detector = PanGestureDetector::New();
214 PanGestureDetector copy( detector );
215 DALI_TEST_CHECK( detector );
219 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
221 TestApplication application;
223 PanGestureDetector detector = PanGestureDetector::New();
225 PanGestureDetector assign;
227 DALI_TEST_CHECK( detector );
229 DALI_TEST_CHECK( detector == assign );
233 // Negative test case for a method
234 int UtcDaliPanGestureDetectorNew(void)
236 TestApplication application;
238 PanGestureDetector detector = PanGestureDetector::New();
240 DALI_TEST_CHECK(detector);
242 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
243 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
245 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
246 Actor actor = Actor::New();
247 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
248 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
249 detector.Attach(actor);
251 application.GetScene().Add(actor);
254 application.SendNotification();
255 application.Render();
257 // Use long press function for touch event
258 TestStartLongPress( application );
263 int UtcDaliPanGestureDetectorDownCast(void)
265 TestApplication application;
266 tet_infoline("Testing Dali::GestureDetector::DownCast()");
268 PanGestureDetector detector = PanGestureDetector::New();
270 BaseHandle object(detector);
272 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
273 DALI_TEST_CHECK(detector2);
275 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
276 DALI_TEST_CHECK(detector3);
278 BaseHandle unInitializedObject;
279 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
280 DALI_TEST_CHECK(!detector4);
282 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
283 DALI_TEST_CHECK(!detector5);
285 GestureDetector detector6 = PanGestureDetector::New();
286 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
287 DALI_TEST_CHECK(detector7);
291 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
293 TestApplication application;
295 PanGestureDetector detector = PanGestureDetector::New();
297 unsigned int min = 2;
299 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
301 detector.SetMinimumTouchesRequired(min);
303 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
305 // Attach an actor and change the minimum touches
307 Actor actor = Actor::New();
308 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
309 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
310 application.GetScene().Add(actor);
313 application.SendNotification();
314 application.Render();
317 GestureReceivedFunctor functor(data);
319 detector.Attach(actor);
320 detector.DetectedSignal().Connect(&application, functor);
322 detector.SetMinimumTouchesRequired(3);
324 // Create a second gesture detector that requires even less minimum touches
325 PanGestureDetector secondDetector = PanGestureDetector::New();
326 secondDetector.Attach(actor);
328 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
333 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
335 TestApplication application;
337 PanGestureDetector detector = PanGestureDetector::New();
339 unsigned int max = 3;
341 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
343 detector.SetMaximumTouchesRequired(max);
345 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
347 // Attach an actor and change the maximum touches
349 Actor actor = Actor::New();
350 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
351 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
352 application.GetScene().Add(actor);
355 application.SendNotification();
356 application.Render();
359 GestureReceivedFunctor functor(data);
361 detector.Attach(actor);
362 detector.DetectedSignal().Connect(&application, functor);
364 detector.SetMaximumTouchesRequired(4);
366 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
371 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
373 TestApplication application;
375 PanGestureDetector detector = PanGestureDetector::New();
376 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
380 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
382 TestApplication application;
384 PanGestureDetector detector = PanGestureDetector::New();
385 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
389 int UtcDaliPanGestureSignalReceptionNegative(void)
391 TestApplication application;
393 Actor actor = Actor::New();
394 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
395 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
396 application.GetScene().Add(actor);
399 application.SendNotification();
400 application.Render();
403 GestureReceivedFunctor functor(data);
405 PanGestureDetector detector = PanGestureDetector::New();
406 detector.Attach(actor);
407 detector.DetectedSignal().Connect(&application, functor);
409 // Do a pan outside actor's area
411 TestStartPan( application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time );
413 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
415 // Continue pan into actor's area - we should still not receive the signal
417 TestMovePan( application, Vector2(20.0f, 20.0f), time );
419 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
421 // Stop panning - we should still not receive the signal
423 TestEndPan( application, Vector2(12.0f, 12.0f), time);
425 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
429 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
431 TestApplication application;
433 Actor actor = Actor::New();
434 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
435 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
436 application.GetScene().Add(actor);
439 application.SendNotification();
440 application.Render();
443 GestureReceivedFunctor functor(data);
445 PanGestureDetector detector = PanGestureDetector::New();
446 detector.Attach(actor);
447 detector.DetectedSignal().Connect(&application, functor);
449 // Start pan within the actor's area
451 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
453 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
454 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
455 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
456 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
457 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
458 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
459 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
461 // Continue the pan within the actor's area - we should still receive the signal
464 TestMovePan( application, Vector2(26.0f, 4.0f), time );
465 time += TestGetFrameInterval();
467 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
468 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
469 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
470 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
471 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
472 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
473 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
475 // Pan Gesture leaves actor's area - we should still receive the signal
478 TestMovePan( application, Vector2(346.0f, 4.0f), time );
479 time += TestGetFrameInterval();
481 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
482 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
483 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
484 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
485 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
486 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
487 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
489 // Gesture ends - we would receive a finished state
492 TestEndPan( application, Vector2(314.0f, 4.0f), time );
494 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
495 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
496 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
497 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
498 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
499 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
500 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
504 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
506 TestApplication application;
508 Actor actor = Actor::New();
509 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
510 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
511 application.GetScene().Add(actor);
514 application.SendNotification();
515 application.Render();
518 GestureReceivedFunctor functor(data);
520 PanGestureDetector detector = PanGestureDetector::New();
521 detector.Attach(actor);
522 detector.DetectedSignal().Connect(&application, functor);
524 // Start pan within the actor's area
526 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
528 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
529 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
530 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
531 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
532 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
533 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
534 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
536 // Continue the pan within the actor's area - we should still receive the signal
539 TestMovePan( application, Vector2(26.0f, 4.0f), time );
540 time += TestGetFrameInterval();
542 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
543 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
544 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
545 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
546 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
547 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
548 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
550 // Gesture ends within actor's area - we would receive a finished state
553 TestEndPan( application, Vector2(10.0f, 4.0f), time );
555 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
556 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
557 DALI_TEST_EQUALS(1u, data.receivedGesture.GetNumberOfTouches(), TEST_LOCATION);
558 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION);
559 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.GetVelocity(), 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
561 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
565 int UtcDaliPanGestureSignalReceptionDetach(void)
567 TestApplication application;
569 Actor actor = Actor::New();
570 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
571 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
572 application.GetScene().Add(actor);
575 application.SendNotification();
576 application.Render();
579 GestureReceivedFunctor functor(data);
581 PanGestureDetector detector = PanGestureDetector::New();
582 detector.Attach(actor);
583 detector.DetectedSignal().Connect(&application, functor);
585 // Start pan within the actor's area
587 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
588 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
590 // Continue the pan within the actor's area - we should still receive the signal
593 TestMovePan( application, Vector2(26.0f, 4.0f), time );
594 time += TestGetFrameInterval();
596 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
598 // Gesture ends within actor's area
601 TestEndPan( application, Vector2(10.0f, 4.0f), time );
602 time += TestGetFrameInterval();
604 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
607 detector.DetachAll();
609 // Ensure we are no longer signalled
612 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
613 TestMovePan( application, Vector2(26.0f, 4.0f), time );
614 time += TestGetFrameInterval();
615 TestEndPan( application, Vector2(10.0f, 4.0f), time );
617 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
621 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
623 TestApplication application;
625 Actor actor = Actor::New();
626 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
627 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
628 application.GetScene().Add(actor);
631 application.SendNotification();
632 application.Render();
635 GestureReceivedFunctor functor(data);
637 PanGestureDetector detector = PanGestureDetector::New();
638 detector.Attach(actor);
639 detector.DetectedSignal().Connect(&application, functor);
641 // Start pan within the actor's area
643 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
644 application.SendNotification();
646 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
648 // Continue the pan within the actor's area - we should still receive the signal
651 TestMovePan( application, Vector2(26.0f, 4.0f), time );
652 time += TestGetFrameInterval();
654 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
656 // Detach actor during the pan, we should not receive the next event
657 detector.DetachAll();
659 // Gesture ends within actor's area
662 TestEndPan( application, Vector2(10.0f, 4.0f), time );
664 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
668 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
670 TestApplication application;
673 GestureReceivedFunctor functor(data);
675 PanGestureDetector detector = PanGestureDetector::New();
676 detector.DetectedSignal().Connect(&application, functor);
678 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
680 Actor tempActor = Actor::New();
681 tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
682 tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
683 application.GetScene().Add(tempActor);
684 detector.Attach(tempActor);
688 // Actor lifetime is scoped
690 Actor actor = Actor::New();
691 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
692 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
693 application.GetScene().Add(actor);
696 application.SendNotification();
697 application.Render();
699 detector.Attach(actor);
701 // Start pan within the actor's area
702 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
704 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
706 // Continue the pan within the actor's area - we should still receive the signal
709 TestMovePan( application, Vector2(26.0f, 4.0f), time );
710 time += TestGetFrameInterval();
712 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
714 // Remove the actor from stage and reset the data
715 application.GetScene().Remove(actor);
718 application.SendNotification();
719 application.Render();
722 // Actor should now have been destroyed
724 // Gesture ends within the area where the actor used to be
727 TestEndPan( application, Vector2(10.0f, 4.0f), time );
729 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
733 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
735 TestApplication application;
737 Actor actor = Actor::New();
738 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
739 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
740 application.GetScene().Add(actor);
743 application.SendNotification();
744 application.Render();
747 GestureReceivedFunctor functor(data);
749 PanGestureDetector detector = PanGestureDetector::New();
750 detector.Attach(actor);
751 detector.DetectedSignal().Connect(&application, functor);
753 // Do an entire pan, only check finished value
755 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
759 TestEndPan( application, Vector2(25.0f, 28.0f), time );
761 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
762 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
764 // Rotate actor again and render a couple of times
765 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
766 application.SendNotification();
767 application.Render();
769 // Do an entire pan, only check finished value
770 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
774 TestEndPan( application, Vector2(25.0f, 28.0f), time );
776 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
777 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
779 // Rotate actor again and render a couple of times
780 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
781 application.SendNotification();
782 application.Render();
784 // Do an entire pan, only check finished value
785 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
789 TestEndPan( application, Vector2(25.0f, 28.0f), time );
791 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
792 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
796 int UtcDaliPanGestureSignalReceptionChildHit(void)
798 TestApplication application;
800 Actor parent = Actor::New();
801 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
802 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
803 application.GetScene().Add(parent);
805 // Set child to completely cover parent.
806 // Change rotation of child to be different from parent so that we can check if our local coordinate
807 // conversion of the parent actor is correct.
808 Actor child = Actor::New();
809 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
810 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
811 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
812 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
817 application.SendNotification();
818 application.Render();
821 GestureReceivedFunctor functor(data);
823 PanGestureDetector detector = PanGestureDetector::New();
824 detector.Attach(parent);
825 detector.DetectedSignal().Connect(&application, functor);
827 // Do an entire pan, only check finished value - hits child area but parent should still receive it
829 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
833 TestEndPan( application, Vector2(25.0f, 28.0f), time );
835 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
836 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
837 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
839 // Attach child and generate same touch points to yield a different displacement
840 // (Also proves that you can detach and then re-attach another actor)
841 detector.Attach(child);
842 detector.Detach(parent);
844 // Do an entire pan, only check finished value
845 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
849 TestEndPan( application, Vector2(25.0f, 28.0f), time );
851 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
852 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
853 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.GetDisplacement(), 0.01f, TEST_LOCATION); // Actor relative
857 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
859 TestApplication application;
861 Actor first = Actor::New();
862 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
863 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
864 application.GetScene().Add(first);
866 Actor second = Actor::New();
867 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
868 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
869 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
870 application.GetScene().Add(second);
873 application.SendNotification();
874 application.Render();
877 GestureReceivedFunctor functor(data);
879 PanGestureDetector detector = PanGestureDetector::New();
880 detector.Attach(first);
881 detector.Attach(second);
882 detector.DetectedSignal().Connect(&application, functor);
884 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
885 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
887 // Start pan within second actor's area
889 TestStartPan( application, Vector2( 110.0f, 20.0f ), Vector2( 126.0f, 20.0f ), time );
891 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
892 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
894 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
895 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
897 // Pan moves into first actor's area - second actor should receive the pan
900 TestMovePan( application, Vector2(126.0f, 20.0f), time );
901 time += TestGetFrameInterval();
903 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
904 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
906 // Detach the second actor during the pan, we should not receive the next event
907 detector.Detach(second);
909 // Gesture ends within actor's area
912 TestMovePan( application, Vector2(26.0f, 20.0f), time );
913 TestEndPan( application, Vector2(10.0f, 4.0f), time );
915 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
920 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
922 TestApplication application;
924 Actor actor = Actor::New();
925 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
926 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
927 application.GetScene().Add(actor);
930 application.SendNotification();
931 application.Render();
934 GestureReceivedFunctor functor(data);
936 PanGestureDetector detector = PanGestureDetector::New();
937 detector.Attach(actor);
938 detector.DetectedSignal().Connect(&application, functor);
940 // Start pan in actor's area
942 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
944 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
946 // Pan continues within actor's area
949 TestMovePan( application, Vector2(26.0f, 4.0f), time );
950 time += TestGetFrameInterval();
952 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
954 // Actor become invisible - actor should not receive the next pan
955 actor.SetProperty( Actor::Property::VISIBLE,false);
958 application.SendNotification();
959 application.Render();
961 // Gesture ends within actor's area
964 TestEndPan( application, Vector2(10.0f, 4.0f), time );
966 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
970 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
972 TestApplication application;
974 Actor actor = Actor::New();
975 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
976 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
977 application.GetScene().Add(actor);
979 Actor actor2 = Actor::New();
980 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
981 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
982 application.GetScene().Add(actor2);
985 application.SendNotification();
986 application.Render();
988 // Attach actor to one detector
989 SignalData firstData;
990 GestureReceivedFunctor firstFunctor(firstData);
991 PanGestureDetector firstDetector = PanGestureDetector::New();
992 firstDetector.Attach(actor);
993 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
995 // Attach actor to another detector
996 SignalData secondData;
997 GestureReceivedFunctor secondFunctor(secondData);
998 PanGestureDetector secondDetector = PanGestureDetector::New();
999 secondDetector.Attach(actor);
1000 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1002 // Add second actor to second detector, when we remove the actor, this will make sure that this
1003 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1004 // functor should still not be called (which is what we're also testing).
1005 secondDetector.Attach(actor2);
1007 // Pan in actor's area - both detector's functors should be called
1008 uint32_t time = 100;
1009 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1011 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1012 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1014 // Pan continues in actor's area - both detector's functors should be called
1018 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1019 time += TestGetFrameInterval();
1021 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1022 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1024 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1025 firstDetector.Detach(actor);
1029 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1031 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1032 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1034 // New pan on actor, only secondDetector has actor attached
1038 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1040 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1041 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1043 // Detach actor from secondDetector
1044 secondDetector.Detach(actor);
1048 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1050 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1051 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1056 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1058 TestApplication application;
1060 Actor actor1 = Actor::New();
1061 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1062 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1063 application.GetScene().Add(actor1);
1065 GestureReceivedFunctor functor1(data1);
1066 PanGestureDetector detector1 = PanGestureDetector::New();
1067 detector1.Attach(actor1);
1068 detector1.DetectedSignal().Connect(&application, functor1);
1070 Actor actor2 = Actor::New();
1071 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1072 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
1073 actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
1074 application.GetScene().Add(actor2);
1076 GestureReceivedFunctor functor2(data2);
1077 PanGestureDetector detector2 = PanGestureDetector::New();
1078 detector2.Attach(actor2);
1079 detector2.DetectedSignal().Connect(&application, functor2);
1081 // Render and notify
1082 application.SendNotification();
1083 application.Render();
1085 // Start pan in actor1's area, only data1 should be set
1086 uint32_t time = 100;
1087 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1089 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1090 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1094 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1096 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1098 TestApplication application;
1100 Actor actor = Actor::New();
1101 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1102 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1103 application.GetScene().Add(actor);
1105 // Render and notify
1106 application.SendNotification();
1107 application.Render();
1109 // Gesture possible in actor's area (using long-press)
1110 uint32_t time = 100;
1111 TestStartLongPress( application, 10.0f, 20.0f, time );
1112 time += TestGetFrameInterval();
1114 // Attach actor to detector
1116 GestureReceivedFunctor functor( data );
1117 PanGestureDetector detector = PanGestureDetector::New();
1118 detector.DetectedSignal().Connect( &application, functor );
1119 detector.Attach(actor);
1121 // Start a pan, initially it'll only be possible, we shouldn't receive it
1122 TestMovePan( application, Vector2( 10.0f, 20.0f ), time );
1123 time += TestGetFrameInterval();
1124 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1126 // Now the pan truly starts, we should receive a signal
1127 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1128 time += TestGetFrameInterval();
1129 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1130 time += TestGetFrameInterval();
1131 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1133 // Finish the pan, we should still receive a signal
1135 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1136 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1141 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1143 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1144 // pan actor was there before (parent)
1146 TestApplication application;
1148 Actor parent = Actor::New();
1149 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1150 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1151 application.GetScene().Add( parent );
1153 Actor child = Actor::New();
1154 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1155 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
1156 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1157 parent.Add( child );
1159 // Create detector for parent and attach
1160 SignalData parentData;
1161 GestureReceivedFunctor parentFunctor( parentData );
1162 PanGestureDetector parentDetector = PanGestureDetector::New();
1163 parentDetector.DetectedSignal().Connect( &application, parentFunctor );
1164 parentDetector.Attach( parent );
1166 // Create detector for child but do not attach
1167 SignalData childData;
1168 GestureReceivedFunctor childFunctor( childData );
1169 PanGestureDetector childDetector = PanGestureDetector::New();
1170 childDetector.DetectedSignal().Connect( &application, childFunctor );
1172 // Render and notify
1173 application.SendNotification();
1174 application.Render();
1176 // Do a full pan in both actors' area, only the parent's functor should be called
1177 uint32_t time = 100;
1178 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1179 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1180 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1183 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1184 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1185 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1189 // Gesture possible in both actors' area (using long-press), no functors called
1190 TestStartLongPress( application, 10.0f, 20.0f, time );
1191 time += TestGetFrameInterval();
1192 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1193 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1195 // Attach the child as well now
1196 childDetector.Attach( child );
1198 // Now the pan truly starts, we should receive a signal for the child only
1199 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1200 time += TestGetFrameInterval();
1201 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1202 time += TestGetFrameInterval();
1203 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1204 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1208 // Finish the pan, again only the child should still receive a signal
1209 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1210 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1211 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1216 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1218 TestApplication application;
1220 Actor actor = Actor::New();
1221 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1222 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1223 application.GetScene().Add(actor);
1225 // Render and notify
1226 application.SendNotification();
1227 application.Render();
1229 // Attach actor to detector
1231 GestureReceivedFunctor functor( data );
1232 PanGestureDetector detector = PanGestureDetector::New();
1233 detector.Attach(actor);
1234 detector.DetectedSignal().Connect( &application, functor );
1236 // Gesture possible in actor's area.
1237 uint32_t time = 100;
1238 TestStartLongPress( application, 10.0f, 20.0f, time );
1239 time += TestGetFrameInterval();
1241 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1243 // Move actor somewhere else
1244 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
1246 // Render and notify
1247 application.SendNotification();
1248 application.Render();
1250 // Emit STARTED event, we should not receive the pan.
1251 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1252 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1253 time += TestGetFrameInterval();
1255 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1257 // LONG_PRESS possible in empty area.
1258 TestStartLongPress( application, 10.0f, 20.0f, time );
1259 time += TestGetFrameInterval();
1261 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1263 // Move actor in to the long press position.
1264 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
1266 // Render and notify
1267 application.SendNotification();
1268 application.Render();
1270 // Emit STARTED event, we should be receiving the pan now.
1271 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1272 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1273 time += TestGetFrameInterval();
1275 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1277 // Normal pan in actor's area for completeness.
1279 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1280 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1281 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1285 int UtcDaliPanGestureActorUnstaged(void)
1287 TestApplication application;
1289 Actor actor = Actor::New();
1290 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1291 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1292 application.GetScene().Add(actor);
1294 // Render and notify
1295 application.SendNotification();
1296 application.Render();
1298 // State to remove actor in.
1299 GestureState stateToUnstage( GestureState::STARTED );
1301 // Attach actor to detector
1303 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1304 PanGestureDetector detector = PanGestureDetector::New();
1305 detector.Attach(actor);
1306 detector.DetectedSignal().Connect( &application, functor );
1309 uint32_t time = 100;
1310 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1312 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1315 TestEndPan( application, Vector2(26.0f, 20.0f), time );
1317 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1320 // Render and notify
1321 application.SendNotification();
1322 application.Render();
1324 // Re-add actor to stage
1325 application.GetScene().Add(actor);
1327 // Render and notify
1328 application.SendNotification();
1329 application.Render();
1331 // Change state to GestureState::CONTINUING to remove
1332 stateToUnstage = GestureState::CONTINUING;
1335 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1337 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1340 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1341 time += TestGetFrameInterval();
1343 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1347 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1349 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1352 // Render and notify
1353 application.SendNotification();
1354 application.Render();
1356 // Re-add actor to stage
1357 application.GetScene().Add(actor);
1359 // Render and notify
1360 application.SendNotification();
1361 application.Render();
1363 // Change state to GestureState::FINISHED to remove
1364 stateToUnstage = GestureState::FINISHED;
1367 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1369 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1372 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1373 time += TestGetFrameInterval();
1375 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1378 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1380 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1381 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1385 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1387 TestApplication application;
1389 Actor actor = Actor::New();
1390 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1391 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1392 application.GetScene().Add(actor);
1394 // Create and add a second actor so that GestureDetector destruction does not come into play.
1395 Actor dummyActor( Actor::New() );
1396 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1397 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
1398 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1399 application.GetScene().Add(dummyActor);
1401 // Render and notify
1402 application.SendNotification();
1403 application.Render();
1405 // State to remove actor in.
1406 GestureState stateToUnstage( GestureState::STARTED );
1408 // Attach actor to detector
1410 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1411 PanGestureDetector detector = PanGestureDetector::New();
1412 detector.Attach(actor);
1413 detector.Attach(dummyActor);
1414 detector.DetectedSignal().Connect( &application, functor );
1416 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
1417 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1418 // position, we should still not be signalled.
1421 uint32_t time = 100;
1422 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1424 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1427 // Render and notify
1428 application.SendNotification();
1429 application.Render();
1431 // Re add to the stage, we should not be signalled
1432 application.GetScene().Add(actor);
1434 // Render and notify
1435 application.SendNotification();
1436 application.Render();
1438 // Continue signal emission
1439 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1440 time += TestGetFrameInterval();
1442 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1445 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1446 time += TestGetFrameInterval();
1448 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1451 // Here we delete an actor in started, we should not receive any subsequent signalling.
1454 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1456 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1459 // Render and notify
1460 application.SendNotification();
1461 application.Render();
1463 // Delete actor as well
1466 // Render and notify
1467 application.SendNotification();
1468 application.Render();
1470 // Continue signal emission
1471 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1472 time += TestGetFrameInterval();
1474 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1477 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1479 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1483 int UtcDaliPanGestureAngleHandling(void)
1485 TestApplication application;
1487 PanGestureDetector detector = PanGestureDetector::New();
1488 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1490 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1491 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1493 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1495 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1497 tet_result( TET_PASS );
1505 tet_printf("%s, angle not added\n", TEST_LOCATION );
1506 tet_result( TET_FAIL );
1509 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1510 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1512 // Remove something not in the container.
1513 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1514 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1516 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1517 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1518 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1520 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1522 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1523 tet_result( TET_FAIL );
1528 detector.ClearAngles();
1529 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1533 int UtcDaliPanGestureGetAngle(void)
1535 TestApplication application;
1537 PanGestureDetector detector = PanGestureDetector::New();
1538 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1540 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1541 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1543 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1544 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1546 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1547 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1549 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1550 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1552 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1553 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1554 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1555 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1560 inline float RadiansToDegrees( float radian )
1562 return radian * 180.0f / Math::PI;
1565 int UtcDaliPanGestureAngleOutOfRange(void)
1567 TestApplication application;
1569 PanGestureDetector detector = PanGestureDetector::New();
1570 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1576 detector.AddAngle( Degree(180.0f) );
1577 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1578 detector.ClearAngles();
1580 detector.AddAngle( Degree(190.0f) );
1581 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.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(350.0f) );
1589 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.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(370.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();
1608 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1609 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1610 detector.ClearAngles();
1612 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1613 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1614 detector.ClearAngles();
1616 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1617 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.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();
1626 int UtcDaliPanGestureAngleProcessing(void)
1628 TestApplication application;
1630 Actor parent = Actor::New();
1631 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1632 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1633 application.GetScene().Add(parent);
1635 Actor child = Actor::New();
1636 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1637 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1640 // Render and notify
1641 application.SendNotification();
1642 application.Render();
1644 // Parent detector only requires up pans
1645 PanGestureDetector parentDetector = PanGestureDetector::New();
1646 parentDetector.Attach( parent );
1647 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1648 SignalData parentData;
1649 GestureReceivedFunctor parentFunctor(parentData);
1650 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1652 // Child detector only requires right pans
1653 PanGestureDetector childDetector = PanGestureDetector::New();
1654 childDetector.Attach( child );
1655 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1656 SignalData childData;
1657 GestureReceivedFunctor childFunctor(childData);
1658 childDetector.DetectedSignal().Connect(&application, childFunctor);
1660 // Generate an Up pan gesture, only parent should receive it.
1661 uint32_t time = 100;
1662 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1664 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1665 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1667 TestEndPan( application, Vector2(20.0f, 4.0f), time );
1668 time += TestGetFrameInterval();
1672 // Generate a Right pan gesture, only child should receive it.
1673 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1675 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1676 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1678 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1679 time += TestGetFrameInterval();
1683 // Generate a Down pan gesture, no one should receive it.
1684 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1686 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1687 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1689 TestEndPan( application, Vector2(20.0f, 36.0f), time );
1690 time += TestGetFrameInterval();
1694 // Generate a Left pan gesture, no one should receive it.
1695 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1697 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1698 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1700 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1706 int UtcDaliPanGestureDirectionHandling(void)
1708 TestApplication application;
1710 PanGestureDetector detector = PanGestureDetector::New();
1711 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1713 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1714 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1716 for ( size_t i = 0; detector.GetAngleCount(); i++)
1718 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1720 tet_result( TET_PASS );
1729 tet_printf("%s, angle not added\n", TEST_LOCATION );
1730 tet_result( TET_FAIL );
1734 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1736 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1738 tet_result( TET_PASS );
1746 tet_printf("%s, angle not added\n", TEST_LOCATION );
1747 tet_result( TET_FAIL );
1750 // Remove something not in the container.
1751 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1752 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1754 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1755 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1759 int UtcDaliPanGestureDirectionProcessing(void)
1761 TestApplication application;
1763 Actor parent = Actor::New();
1764 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1765 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1766 application.GetScene().Add(parent);
1768 Actor child = Actor::New();
1769 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1770 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1773 // Render and notify
1774 application.SendNotification();
1775 application.Render();
1777 // Parent detector only requires vertical panning
1778 PanGestureDetector parentDetector = PanGestureDetector::New();
1779 parentDetector.Attach( parent );
1780 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1781 SignalData parentData;
1782 GestureReceivedFunctor parentFunctor(parentData);
1783 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1785 // Child detector only requires horizontal panning
1786 PanGestureDetector childDetector = PanGestureDetector::New();
1787 childDetector.Attach( child );
1788 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1789 SignalData childData;
1790 GestureReceivedFunctor childFunctor(childData);
1791 childDetector.DetectedSignal().Connect(&application, childFunctor);
1793 // Generate an Up pan gesture, only parent should receive it.
1794 uint32_t time = 100;
1795 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1797 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1798 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1800 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1801 time += TestGetFrameInterval();
1805 // Generate a Right pan gesture, only child should receive it.
1806 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1808 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1809 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1811 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1812 time += TestGetFrameInterval();
1816 // Generate a Down pan gesture, only parent should receive it.
1817 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1819 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1820 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1822 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1823 time += TestGetFrameInterval();
1827 // Generate a Left pan gesture, only child should receive it.
1828 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1830 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1831 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1833 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1834 time += TestGetFrameInterval();
1838 // Generate a pan at -45 degrees, no one should receive it.
1839 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 9.0f, 31.0f ), time );
1841 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1842 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1844 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1845 time += TestGetFrameInterval();
1849 // Generate a pan at 45 degrees, no one should receive it.
1850 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 31.0f, 31.0f ), time );
1852 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1853 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1855 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1856 time += TestGetFrameInterval();
1860 // Generate a pan at -135 degrees, no one should receive it.
1861 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 4.0f ), time );
1863 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1864 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1866 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1872 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1874 TestApplication application;
1875 Integration::SetPanGesturePredictionMode(0);
1876 Integration::SetPanGestureSmoothingMode(0);
1878 Actor actor = Actor::New();
1879 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1880 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1881 application.GetScene().Add(actor);
1883 // Add a pan detector
1884 PanGestureDetector detector = PanGestureDetector::New();
1885 detector.Attach( actor );
1887 GestureReceivedFunctor functor( data );
1888 detector.DetectedSignal().Connect( &application, functor );
1890 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1892 ConstraintData constraintData;
1893 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1894 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1895 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1896 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1897 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1898 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1899 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1900 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1903 // Render and notify
1904 application.SendNotification();
1905 application.Render();
1907 Vector2 startPosition( 1.0f, 1.0f );
1908 Vector2 position( -14.0f, 1.0f );
1909 Vector2 direction(Vector2::XAXIS * -5.0f);
1910 uint32_t time = 100;
1912 TestStartPan( application, startPosition, position, time );
1914 for(int i = 0; i < 47; i++ )
1916 position += direction;
1917 TestMovePan( application, position, time );
1918 time += TestGetFrameInterval();
1919 application.SendNotification();
1920 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1923 TestEndPan( application, position, time );
1924 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1926 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1927 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1928 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1929 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1931 constraintData.Reset();
1935 int UtcDaliPanGestureNoPredictionSmoothing(void)
1937 TestApplication application;
1938 Integration::SetPanGesturePredictionMode(0);
1939 Integration::SetPanGestureSmoothingMode(1);
1941 Actor actor = Actor::New();
1942 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1943 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1944 application.GetScene().Add(actor);
1946 // Add a pan detector
1947 PanGestureDetector detector = PanGestureDetector::New();
1948 detector.Attach( actor );
1950 GestureReceivedFunctor functor( data );
1951 detector.DetectedSignal().Connect( &application, functor );
1953 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1955 ConstraintData constraintData;
1956 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1957 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1958 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1959 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1960 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1961 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1962 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1963 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1966 // Render and notify
1967 application.SendNotification();
1968 application.Render();
1970 Vector2 startPosition( 1.0f, 1.0f );
1971 Vector2 position( -14.0f, 1.0f );
1972 Vector2 direction(Vector2::XAXIS * -5.0f);
1973 uint32_t time = 100;
1975 TestStartPan( application, startPosition, position, time );
1977 for(int i = 0; i < 47; i++ )
1979 position += direction;
1980 TestMovePan( application, position, time );
1981 time += TestGetFrameInterval();
1982 application.SendNotification();
1983 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1986 TestEndPan( application, position, time );
1987 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1989 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1990 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1991 // Take into account resampling done when prediction is off.
1992 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
1993 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
1995 constraintData.Reset();
1999 int UtcDaliPanGesturePredictionNoSmoothing(void)
2001 TestApplication application;
2002 Integration::SetPanGesturePredictionMode(1);
2003 Integration::SetPanGestureSmoothingMode(0);
2005 Actor actor = Actor::New();
2006 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2007 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2008 application.GetScene().Add(actor);
2010 // Add a pan detector
2011 PanGestureDetector detector = PanGestureDetector::New();
2012 detector.Attach( actor );
2014 GestureReceivedFunctor functor( data );
2015 detector.DetectedSignal().Connect( &application, functor );
2017 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2019 ConstraintData constraintData;
2020 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2021 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2022 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2023 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2024 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2025 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2026 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2027 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2030 // Render and notify
2031 application.SendNotification();
2032 application.Render();
2034 Vector2 startPosition( 1.0f, 1.0f );
2035 Vector2 position( -1.0f, 1.0f );
2036 Vector2 direction(Vector2::XAXIS * -1.0f);
2037 uint32_t time = 100;
2039 TestStartPan( application, startPosition, position, time );
2041 for(int i = 0; i < 47; i++ )
2043 position += direction;
2044 TestMovePan( application, position, time );
2045 time += TestGetFrameInterval();
2046 application.SendNotification();
2047 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2050 TestEndPan( application, position, time );
2051 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2053 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2054 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2055 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2056 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2058 constraintData.Reset();
2062 int UtcDaliPanGesturePredictionSmoothing01(void)
2064 TestApplication application;
2065 Integration::SetPanGesturePredictionMode(1);
2066 Integration::SetPanGestureSmoothingMode(1);
2068 Actor actor = Actor::New();
2069 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2070 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2071 application.GetScene().Add(actor);
2073 // Add a pan detector
2074 PanGestureDetector detector = PanGestureDetector::New();
2075 detector.Attach( actor );
2077 GestureReceivedFunctor functor( data );
2078 detector.DetectedSignal().Connect( &application, functor );
2080 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2082 ConstraintData constraintData;
2083 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2084 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2085 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2086 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2087 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2088 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2089 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2090 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2093 // Render and notify
2094 application.SendNotification();
2095 application.Render();
2097 Vector2 startPosition( 1.0f, 1.0f );
2098 Vector2 position( -1.0f, 1.0f );
2099 Vector2 direction(Vector2::XAXIS * -1.0f);
2100 uint32_t time = 100;
2102 TestStartPan( application, startPosition, position, time );
2104 for(int i = 0; i < 47; i++ )
2106 position += direction;
2107 TestMovePan( application, position, time );
2108 time += TestGetFrameInterval();
2109 application.SendNotification();
2110 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2113 TestEndPan( application, position, time );
2114 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2116 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2117 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2118 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2119 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2121 constraintData.Reset();
2125 int UtcDaliPanGesturePredictionSmoothing02(void)
2127 TestApplication application;
2128 Integration::SetPanGesturePredictionMode( 1 );
2129 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2130 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2131 Integration::SetPanGestureSmoothingMode( 1 );
2132 Integration::SetPanGestureSmoothingAmount( 0.25f );
2134 Actor actor = Actor::New();
2135 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2136 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2137 application.GetScene().Add(actor);
2139 // Add a pan detector
2140 PanGestureDetector detector = PanGestureDetector::New();
2141 detector.Attach( actor );
2143 GestureReceivedFunctor functor( data );
2144 detector.DetectedSignal().Connect( &application, functor );
2146 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2148 ConstraintData constraintData;
2149 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2150 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2151 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2152 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2153 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2154 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2155 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2156 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2159 // Render and notify
2160 application.SendNotification();
2161 application.Render();
2163 Vector2 startPosition( 2.0f, 2.0f );
2164 Vector2 position( 4.0f, 2.0f );
2165 Vector2 directionX(Vector2::XAXIS);
2166 Vector2 directionY(Vector2::YAXIS);
2167 uint32_t time = 100;
2169 TestStartPan( application, startPosition, position, time );
2171 for(int i = 0; i < 7; i++ )
2173 position += directionX;
2174 TestMovePan( application, position, time );
2175 time += TestGetFrameInterval();
2176 application.SendNotification();
2177 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2180 position += directionX * 10.0f;
2181 TestMovePan( application, position, time );
2182 time += TestGetFrameInterval();
2183 application.SendNotification();
2184 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2186 for(int i = 0; i < 2; i++ )
2188 position += ( directionX * -1.0f );
2189 TestMovePan( application, position, time );
2190 time += TestGetFrameInterval();
2191 application.SendNotification();
2192 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2195 for(int i = 0; i < 10; i++ )
2197 position += directionX;
2198 TestMovePan( application, position, time );
2199 time += TestGetFrameInterval();
2200 application.SendNotification();
2201 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2204 for(int i = 0; i < 10; i++ )
2206 position += directionY;
2207 TestMovePan( application, position, time );
2208 time += TestGetFrameInterval();
2209 application.SendNotification();
2210 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2213 TestEndPan( application, position, time );
2214 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2216 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2217 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2218 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2219 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2221 constraintData.Reset();
2225 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2227 TestApplication application;
2229 Integration::SetPanGesturePredictionMode( 2 );
2230 Integration::SetPanGesturePredictionAmount( 57 );
2231 Integration::SetPanGestureSmoothingMode( 2 );
2232 Integration::SetPanGestureUseActualTimes( false );
2233 Integration::SetPanGestureInterpolationTimeRange( 10 );
2234 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2235 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2236 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2237 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2238 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2239 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2241 Actor actor = Actor::New();
2242 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2243 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2244 application.GetScene().Add(actor);
2246 // Add a pan detector
2247 PanGestureDetector detector = PanGestureDetector::New();
2248 detector.Attach( actor );
2250 GestureReceivedFunctor functor( data );
2251 detector.DetectedSignal().Connect( &application, functor );
2253 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2255 ConstraintData constraintData;
2256 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2257 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2258 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2259 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2260 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2261 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2262 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2263 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2266 // Render and notify
2267 application.SendNotification();
2268 application.Render();
2270 Vector2 startPosition( 2.0f, 2.0f );
2271 Vector2 position( -1.0f, 2.0f );
2272 Vector2 direction(Vector2::XAXIS * -1.0f);
2273 uint32_t time = 100;
2275 TestStartPan( application, startPosition, position, time );
2277 for(int i = 0; i < 27; i++ )
2279 position += direction;
2280 TestMovePan( application, position, time );
2281 time += TestGetFrameInterval();
2282 application.SendNotification();
2283 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2286 TestEndPan( application, position, time );
2287 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2289 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2290 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2291 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2292 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2294 constraintData.Reset();
2298 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2300 TestApplication application;
2302 Integration::SetPanGesturePredictionMode( 2 );
2303 Integration::SetPanGestureSmoothingMode( 2 );
2304 Integration::SetPanGestureUseActualTimes( true );
2305 Integration::SetPanGestureInterpolationTimeRange( 10 );
2306 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2307 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2308 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2309 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2310 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2311 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2313 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2315 Actor actor = Actor::New();
2316 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2317 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2318 application.GetScene().Add(actor);
2320 // Add a pan detector
2321 PanGestureDetector detector = PanGestureDetector::New();
2322 detector.Attach( actor );
2324 GestureReceivedFunctor functor( data );
2325 detector.DetectedSignal().Connect( &application, functor );
2327 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2329 ConstraintData constraintData;
2330 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2331 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2332 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2333 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2334 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2335 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2336 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2337 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2340 // Render and notify
2341 application.SendNotification();
2342 application.Render();
2344 Vector2 startPosition( 2.0f, 2.0f );
2345 Vector2 position( 17.0f, 2.0f );
2346 Vector2 direction(Vector2::XAXIS * -1.0f);
2347 uint32_t time = 100;
2349 TestStartPan( application, startPosition, position, time );
2351 for(int i = 0; i < 10; i++ )
2353 position += direction;
2354 TestMovePan( application, position, time );
2355 time += TestGetFrameInterval();
2357 position += direction;
2358 TestMovePan( application, position, time );
2359 time += TestGetFrameInterval();
2361 position += direction;
2362 TestMovePan( application, position, time );
2363 time += TestGetFrameInterval();
2365 application.SendNotification();
2366 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2369 for(int i = 0; i < 10; i++ )
2371 application.SendNotification();
2372 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2375 for(int i = 0; i < 10; i++ )
2377 position += direction;
2378 TestMovePan( application, position, time );
2379 application.SendNotification();
2380 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2383 for(int i = 0; i < 10; i++ )
2385 position += direction;
2386 TestMovePan( application, position, time );
2387 time += TestGetFrameInterval();
2388 application.SendNotification();
2389 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2392 TestEndPan( application, position, time );
2393 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2395 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2396 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2397 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2398 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2400 constraintData.Reset();
2404 int UtcDaliPanGesturePrediction2Smoothing(void)
2406 TestApplication application;
2408 Integration::SetPanGesturePredictionMode( 2 );
2409 Integration::SetPanGesturePredictionAmount( 57 );
2410 Integration::SetPanGestureSmoothingMode( 1 );
2411 Integration::SetPanGestureUseActualTimes( false );
2412 Integration::SetPanGestureInterpolationTimeRange( 10 );
2413 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2414 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2415 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2416 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2417 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2418 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2420 Actor actor = Actor::New();
2421 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2422 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2423 application.GetScene().Add(actor);
2425 // Add a pan detector
2426 PanGestureDetector detector = PanGestureDetector::New();
2427 detector.Attach( actor );
2429 GestureReceivedFunctor functor( data );
2430 detector.DetectedSignal().Connect( &application, functor );
2432 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2434 ConstraintData constraintData;
2435 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2436 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2437 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2438 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2439 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2440 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2441 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2442 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2445 // Render and notify
2446 application.SendNotification();
2447 application.Render();
2449 Vector2 startPosition( 2.0f, 2.0f );
2450 Vector2 position( 17.0f, 2.0f );
2451 Vector2 direction(Vector2::XAXIS * -1.0f);
2452 uint32_t time = 100;
2454 TestStartPan( application, startPosition, position, time );
2456 for(int i = 0; i < 10; i++ )
2458 position += direction;
2459 TestMovePan( application, position, time );
2460 time += TestGetFrameInterval();
2461 application.SendNotification();
2462 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2466 position += direction;
2467 TestMovePan( application, position, time );
2468 time += TestGetFrameInterval();
2470 position += direction;
2471 TestMovePan( application, position, time );
2472 time += TestGetFrameInterval();
2474 position += direction;
2475 TestMovePan( application, position, time );
2476 time += TestGetFrameInterval();
2478 application.SendNotification();
2479 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2481 for(int i = 0; i < 5; i++ )
2483 application.SendNotification();
2484 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2487 for(int i = 0; i < 10; i++ )
2489 position += direction;
2490 TestMovePan( application, position, time );
2491 time += TestGetFrameInterval();
2492 application.SendNotification();
2493 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2496 TestEndPan( application, position, time );
2497 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2499 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2500 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2501 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2502 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2504 constraintData.Reset();
2508 int UtcDaliPanGestureSetProperties(void)
2510 TestApplication application;
2511 TestRenderController& renderController( application.GetRenderController() );
2512 Integration::SetPanGesturePredictionMode(0);
2513 Integration::SetPanGestureSmoothingMode(0);
2515 Actor actor = Actor::New();
2516 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2517 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2518 application.GetScene().Add(actor);
2520 // Add a pan detector
2521 PanGestureDetector detector = PanGestureDetector::New();
2522 detector.Attach( actor );
2524 GestureReceivedFunctor functor( data );
2525 detector.DetectedSignal().Connect( &application, functor );
2527 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2528 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2530 ConstraintData constraintData;
2531 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2532 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2533 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2534 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2535 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2536 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2537 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2538 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2539 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2542 // Render and notify
2543 application.SendNotification();
2544 application.Render();
2546 renderController.Initialize();
2547 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2549 Vector2 screenPosition( 20.0f, 20.0f );
2550 Vector2 screenDisplacement( 1.0f, 1.0f );
2551 Vector2 screenVelocity( 1.3f, 4.0f );
2552 Vector2 localPosition( 21.0f, 21.0f );
2553 Vector2 localDisplacement( 0.5f, 0.5f );
2554 Vector2 localVelocity( 1.5f, 2.5f );
2556 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, GestureState::STARTED, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2557 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2559 // Render and notify
2560 application.SendNotification();
2561 application.Render();
2563 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2564 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2565 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2566 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2567 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2568 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2569 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2570 constraintData.Reset();
2574 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2576 TestApplication application;
2577 Integration::SetPanGesturePredictionMode(0);
2579 Actor actor = Actor::New();
2580 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2581 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2582 application.GetScene().Add(actor);
2584 // Add a pan detector
2585 PanGestureDetector detector = PanGestureDetector::New();
2586 detector.Attach( actor );
2588 GestureReceivedFunctor functor( data );
2589 detector.DetectedSignal().Connect( &application, functor );
2591 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2593 ConstraintData constraintData;
2594 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2595 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2596 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2597 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2598 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2599 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2600 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2601 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2604 // Render and notify
2605 application.SendNotification();
2606 application.Render();
2608 Vector2 currentPosition( 20.0f, 4.0f );
2609 uint32_t time = 100;
2610 TestStartPan( application, Vector2( 20.0f, 20.0f ), currentPosition, time );
2611 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2613 Vector2 screenPosition( 100.0f, 20.0f );
2614 Vector2 localPosition( 110.0f, 110.0f );
2616 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, GestureState::STARTED, screenPosition, localPosition ) );
2618 // Render and notify
2619 application.SendNotification();
2620 application.Render();
2622 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2623 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2624 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2625 constraintData.Reset();
2629 int UtcDaliPanGesturePropertyIndices(void)
2631 TestApplication application;
2632 PanGestureDetector detector = PanGestureDetector::New();
2634 Property::IndexContainer indices;
2635 detector.GetPropertyIndices( indices );
2636 DALI_TEST_CHECK( indices.Size() );
2637 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2643 struct PropertyStringIndex
2645 const char * const name;
2646 const Property::Index index;
2647 const Property::Type type;
2648 const Property::Value value;
2651 const PropertyStringIndex PROPERTY_TABLE[] =
2653 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2654 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2655 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2656 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2657 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2658 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2659 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2661 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2662 } // unnamed namespace
2665 int UtcDaliPanGestureProperties(void)
2667 TestApplication application;
2668 PanGestureDetector detector = PanGestureDetector::New();
2670 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2672 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2673 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2674 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2675 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2676 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2677 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2678 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2684 int UtcDaliPanGestureGetProperty(void)
2686 TestApplication application;
2687 PanGestureDetector detector = PanGestureDetector::New();
2689 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2691 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2693 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2694 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2696 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2698 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2699 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2706 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2708 TestApplication application;
2710 Actor actor = Actor::New();
2711 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2712 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2713 application.GetScene().Add(actor);
2715 // Add a pan detector
2716 PanGestureDetector detector = PanGestureDetector::New();
2717 detector.Attach( actor );
2719 // Render and notify
2720 application.SendNotification();
2721 application.Render();
2723 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2725 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2727 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2729 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2730 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2732 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2734 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2735 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2742 int UtcDaliPanGestureLayerConsumesTouch(void)
2744 TestApplication application;
2746 Actor actor = Actor::New();
2747 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2748 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2749 application.GetScene().Add(actor);
2751 // Add a pan detector
2752 PanGestureDetector detector = PanGestureDetector::New();
2753 detector.Attach( actor );
2755 GestureReceivedFunctor functor( data );
2756 detector.DetectedSignal().Connect( &application, functor );
2758 // Add a layer to overlap the actor
2759 Layer layer = Layer::New();
2760 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2761 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2762 application.GetScene().Add( layer );
2765 // Render and notify
2766 application.SendNotification();
2767 application.Render();
2769 // Emit signals, should receive
2770 uint32_t time = 100;
2771 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2772 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2773 time += TestGetFrameInterval();
2775 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2778 // Set layer to consume all touch
2779 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
2781 // Render and notify
2782 application.SendNotification();
2783 application.Render();
2785 // Emit the same signals again, should not receive
2786 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2787 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2789 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2795 int UtcDaliPanGestureNoTimeDiff(void)
2797 TestApplication application;
2799 Actor actor = Actor::New();
2800 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2801 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2802 application.GetScene().Add(actor);
2804 // Add a pan detector
2805 PanGestureDetector detector = PanGestureDetector::New();
2806 detector.Attach( actor );
2808 GestureReceivedFunctor functor( data );
2809 detector.DetectedSignal().Connect( &application, functor );
2811 // Render and notify
2812 application.SendNotification();
2813 application.Render();
2815 // As normal helper function adds intervals between presses we must generate the sequence
2816 // using other helper functions
2817 TestStartLongPress( application, 10.0f, 20.0f, 100 ); // Used to send a down press event
2818 TestMovePan( application, Vector2(26.0f, 20.0f), 100 );
2819 TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); // 2 motions required to trigger
2820 TestEndPan( application, Vector2(26.0f, 20.0f), 100 );
2822 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2823 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.GetVelocity().x ) );
2824 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.GetVelocity().y ) );
2825 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.GetScreenVelocity().x ) );
2826 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.GetScreenVelocity().y ) );
2834 int UtcDaliPanGestureInterruptedWhenTouchConsumed(void)
2836 TestApplication application;
2838 Actor actor = Actor::New();
2839 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2840 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2841 application.GetScene().Add(actor);
2843 bool consume = false;
2844 TouchEventFunctorConsumeSetter touchFunctor(consume);
2845 actor.TouchedSignal().Connect(&application,touchFunctor);
2847 // Render and notify
2848 application.SendNotification();
2849 application.Render();
2852 GestureReceivedFunctor functor(data);
2854 PanGestureDetector detector = PanGestureDetector::New();
2855 detector.Attach(actor);
2856 detector.DetectedSignal().Connect(&application, functor);
2858 // Start gesture within the actor's area, we should receive the pan as the touch is NOT being consumed
2859 uint32_t time = 100;
2860 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2862 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2863 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
2866 // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
2869 TestMovePan( application, Vector2(26.0f, 4.0f), time );
2870 time += TestGetFrameInterval();
2872 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2873 DALI_TEST_EQUALS(GestureState::CANCELLED, data.receivedGesture.GetState(), TEST_LOCATION);
2878 int UtcDaliPanGestureDisableDetectionDuringPanN(void)
2880 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
2882 TestApplication application;
2884 Actor actor = Actor::New();
2885 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2886 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2887 application.GetScene().Add(actor);
2889 // Add a pan detector
2890 PanGestureDetector detector = PanGestureDetector::New();
2891 bool functorCalled = false;
2892 detector.Attach( actor );
2893 detector.DetectedSignal().Connect(
2895 [&detector, &functorCalled](Actor actor, const PanGesture& pan)
2897 if( pan.GetState() == GestureState::FINISHED )
2899 detector.Detach(actor);
2900 functorCalled = true;
2904 // Render and notify
2905 application.SendNotification();
2906 application.Render();
2908 // Try the gesture, should not crash
2911 uint32_t time = 100;
2912 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2913 TestEndPan( application, Vector2(26.0f, 20.0f) );
2915 DALI_TEST_CHECK( true ); // No crash, test has passed
2916 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
2920 DALI_TEST_CHECK( false ); // If we crash, the test has failed