2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali/integration-api/profiling.h>
26 #include <dali/integration-api/input-options.h>
27 #include <dali-test-suite-utils.h>
28 #include <test-touch-utils.h>
29 #include <test-touch-data-utils.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),
55 receivedGesture(Gesture::Clear)
60 functorCalled = false;
61 voidFunctorCalled = false;
63 receivedGesture.state = Gesture::Clear;
64 receivedGesture.velocity = Vector2(0.0f, 0.0f);
65 receivedGesture.displacement = Vector2(0.0f, 0.0f);
66 receivedGesture.position = Vector2(0.0f, 0.0f);
67 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
68 receivedGesture.numberOfTouches = 0;
74 bool voidFunctorCalled;
75 PanGesture receivedGesture;
79 // Functor that sets the data when called
80 struct GestureReceivedFunctor
82 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
84 void operator()(Actor actor, const PanGesture& pan)
86 signalData.functorCalled = true;
87 signalData.receivedGesture = pan;
88 signalData.pannedActor = actor;
93 signalData.voidFunctorCalled = true;
96 SignalData& signalData;
99 // Functor that removes the gestured actor from stage
100 struct UnstageActorFunctor : public GestureReceivedFunctor
102 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage, Integration::Scene scene )
103 : GestureReceivedFunctor( data ),
104 stateToUnstage( stateToUnstage ),
109 void operator()( Actor actor, const PanGesture& pan )
111 GestureReceivedFunctor::operator()( actor, pan );
113 if ( pan.state == stateToUnstage )
115 scene.Remove( actor );
119 Gesture::State& stateToUnstage;
120 Integration::Scene scene;
123 // Functor for receiving a touch event
124 struct TouchEventFunctor
126 bool operator()(Actor actor, const TouchEvent& touch)
132 // Data for constraints
133 struct ConstraintData
141 Vector2 screenPosition;
142 Vector2 screenDisplacement;
143 Vector2 screenVelocity;
144 Vector2 localPosition;
145 Vector2 localDisplacement;
146 Vector2 localVelocity;
152 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
158 // Constraint used with panning properties
161 PanConstraint( ConstraintData& data ) : constraintData(data) { }
163 void operator()( Vector3& current, const PropertyInputContainer& inputs )
165 constraintData.screenPosition = inputs[0]->GetVector2();
166 constraintData.screenDisplacement = inputs[1]->GetVector2();
167 constraintData.screenVelocity = inputs[2]->GetVector2();
168 constraintData.localPosition = inputs[3]->GetVector2();
169 constraintData.localDisplacement = inputs[4]->GetVector2();
170 constraintData.localVelocity = inputs[5]->GetVector2();
171 constraintData.panning = inputs[6]->GetBoolean();
172 constraintData.called = true;
173 current = Vector3::ZERO;
176 ConstraintData& constraintData;
179 // Generate a PanGesture
180 PanGesture GeneratePan( unsigned int time,
181 Gesture::State state,
182 Vector2 screenPosition,
183 Vector2 localPosition,
184 Vector2 screenDisplacement = Vector2::ONE,
185 Vector2 localDisplacement = Vector2::ONE,
186 Vector2 screenVelocity = Vector2::ONE,
187 Vector2 localVelocity = Vector2::ONE,
188 unsigned int numberOfTouches = 1 )
190 PanGesture pan( state );
194 pan.screenPosition = screenPosition;
195 pan.position = localPosition;
197 pan.screenDisplacement = screenDisplacement;
198 pan.displacement = localDisplacement;
200 pan.screenVelocity = screenVelocity;
201 pan.velocity = localVelocity;
203 pan.numberOfTouches = numberOfTouches;
210 ///////////////////////////////////////////////////////////////////////////////
212 // Positive test case for a method
213 int UtcDaliPanGestureDetectorConstructor(void)
215 TestApplication application;
217 PanGestureDetector detector;
218 DALI_TEST_CHECK(!detector);
222 int UtcDaliPanGestureDetectorCopyConstructorP(void)
224 TestApplication application;
226 PanGestureDetector detector = PanGestureDetector::New();
228 PanGestureDetector copy( detector );
229 DALI_TEST_CHECK( detector );
233 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
235 TestApplication application;
237 PanGestureDetector detector = PanGestureDetector::New();
239 PanGestureDetector assign;
241 DALI_TEST_CHECK( detector );
243 DALI_TEST_CHECK( detector == assign );
247 // Negative test case for a method
248 int UtcDaliPanGestureDetectorNew(void)
250 TestApplication application;
252 PanGestureDetector detector = PanGestureDetector::New();
254 DALI_TEST_CHECK(detector);
256 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
257 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
259 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
260 Actor actor = Actor::New();
261 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
262 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
263 detector.Attach(actor);
265 application.GetScene().Add(actor);
268 application.SendNotification();
269 application.Render();
271 // Use long press function for touch event
272 TestStartLongPress( application );
277 int UtcDaliPanGestureDetectorDownCast(void)
279 TestApplication application;
280 tet_infoline("Testing Dali::GestureDetector::DownCast()");
282 PanGestureDetector detector = PanGestureDetector::New();
284 BaseHandle object(detector);
286 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
287 DALI_TEST_CHECK(detector2);
289 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
290 DALI_TEST_CHECK(detector3);
292 BaseHandle unInitializedObject;
293 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
294 DALI_TEST_CHECK(!detector4);
296 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
297 DALI_TEST_CHECK(!detector5);
299 GestureDetector detector6 = PanGestureDetector::New();
300 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
301 DALI_TEST_CHECK(detector7);
305 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
307 TestApplication application;
309 PanGestureDetector detector = PanGestureDetector::New();
311 unsigned int min = 2;
313 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
315 detector.SetMinimumTouchesRequired(min);
317 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
319 // Attach an actor and change the minimum touches
321 Actor actor = Actor::New();
322 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
323 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
324 application.GetScene().Add(actor);
327 application.SendNotification();
328 application.Render();
331 GestureReceivedFunctor functor(data);
333 detector.Attach(actor);
334 detector.DetectedSignal().Connect(&application, functor);
336 detector.SetMinimumTouchesRequired(3);
338 // Create a second gesture detector that requires even less minimum touches
339 PanGestureDetector secondDetector = PanGestureDetector::New();
340 secondDetector.Attach(actor);
342 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
347 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
349 TestApplication application;
351 PanGestureDetector detector = PanGestureDetector::New();
353 unsigned int max = 3;
355 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
357 detector.SetMaximumTouchesRequired(max);
359 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
361 // Attach an actor and change the maximum touches
363 Actor actor = Actor::New();
364 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
365 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
366 application.GetScene().Add(actor);
369 application.SendNotification();
370 application.Render();
373 GestureReceivedFunctor functor(data);
375 detector.Attach(actor);
376 detector.DetectedSignal().Connect(&application, functor);
378 detector.SetMaximumTouchesRequired(4);
380 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
385 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
387 TestApplication application;
389 PanGestureDetector detector = PanGestureDetector::New();
390 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
394 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
396 TestApplication application;
398 PanGestureDetector detector = PanGestureDetector::New();
399 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
403 int UtcDaliPanGestureSignalReceptionNegative(void)
405 TestApplication application;
407 Actor actor = Actor::New();
408 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
409 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
410 application.GetScene().Add(actor);
413 application.SendNotification();
414 application.Render();
417 GestureReceivedFunctor functor(data);
419 PanGestureDetector detector = PanGestureDetector::New();
420 detector.Attach(actor);
421 detector.DetectedSignal().Connect(&application, functor);
423 // Do a pan outside actor's area
425 TestStartPan( application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time );
427 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
429 // Continue pan into actor's area - we should still not receive the signal
431 TestMovePan( application, Vector2(20.0f, 20.0f), time );
433 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
435 // Stop panning - we should still not receive the signal
437 TestEndPan( application, Vector2(12.0f, 12.0f), time);
439 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
443 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
445 TestApplication application;
447 Actor actor = Actor::New();
448 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
449 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
450 application.GetScene().Add(actor);
453 application.SendNotification();
454 application.Render();
457 GestureReceivedFunctor functor(data);
459 PanGestureDetector detector = PanGestureDetector::New();
460 detector.Attach(actor);
461 detector.DetectedSignal().Connect(&application, functor);
463 // Start pan within the actor's area
465 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
467 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
468 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
469 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
470 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
471 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
472 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
473 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
475 // Continue the pan within the actor's area - we should still receive the signal
478 TestMovePan( application, Vector2(26.0f, 4.0f), time );
479 time += TestGetFrameInterval();
481 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
482 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
483 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
484 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
485 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
486 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
487 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
489 // Pan Gesture leaves actor's area - we should still receive the signal
492 TestMovePan( application, Vector2(346.0f, 4.0f), time );
493 time += TestGetFrameInterval();
495 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
496 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
497 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
498 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
499 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
500 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
501 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
503 // Gesture ends - we would receive a finished state
506 TestEndPan( application, Vector2(314.0f, 4.0f), time );
508 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
509 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
510 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
511 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
512 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
513 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
514 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
518 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
520 TestApplication application;
522 Actor actor = Actor::New();
523 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
524 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
525 application.GetScene().Add(actor);
528 application.SendNotification();
529 application.Render();
532 GestureReceivedFunctor functor(data);
534 PanGestureDetector detector = PanGestureDetector::New();
535 detector.Attach(actor);
536 detector.DetectedSignal().Connect(&application, functor);
538 // Start pan within the actor's area
540 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
542 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
543 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
544 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
545 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
546 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
547 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
548 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
550 // Continue the pan within the actor's area - we should still receive the signal
553 TestMovePan( application, Vector2(26.0f, 4.0f), time );
554 time += TestGetFrameInterval();
556 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
557 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
558 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
559 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
561 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
562 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
564 // Gesture ends within actor's area - we would receive a finished state
567 TestEndPan( application, Vector2(10.0f, 4.0f), time );
569 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
570 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
571 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
572 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
573 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
574 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
575 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
579 int UtcDaliPanGestureSignalReceptionDetach(void)
581 TestApplication application;
583 Actor actor = Actor::New();
584 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
585 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
586 application.GetScene().Add(actor);
589 application.SendNotification();
590 application.Render();
593 GestureReceivedFunctor functor(data);
595 PanGestureDetector detector = PanGestureDetector::New();
596 detector.Attach(actor);
597 detector.DetectedSignal().Connect(&application, functor);
599 // Start pan within the actor's area
601 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
602 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
604 // Continue the pan within the actor's area - we should still receive the signal
607 TestMovePan( application, Vector2(26.0f, 4.0f), time );
608 time += TestGetFrameInterval();
610 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612 // Gesture ends within actor's area
615 TestEndPan( application, Vector2(10.0f, 4.0f), time );
616 time += TestGetFrameInterval();
618 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
621 detector.DetachAll();
623 // Ensure we are no longer signalled
626 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
627 TestMovePan( application, Vector2(26.0f, 4.0f), time );
628 time += TestGetFrameInterval();
629 TestEndPan( application, Vector2(10.0f, 4.0f), time );
631 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
635 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
637 TestApplication application;
639 Actor actor = Actor::New();
640 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
641 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
642 application.GetScene().Add(actor);
645 application.SendNotification();
646 application.Render();
649 GestureReceivedFunctor functor(data);
651 PanGestureDetector detector = PanGestureDetector::New();
652 detector.Attach(actor);
653 detector.DetectedSignal().Connect(&application, functor);
655 // Start pan within the actor's area
657 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
658 application.SendNotification();
660 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
662 // Continue the pan within the actor's area - we should still receive the signal
665 TestMovePan( application, Vector2(26.0f, 4.0f), time );
666 time += TestGetFrameInterval();
668 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
670 // Detach actor during the pan, we should not receive the next event
671 detector.DetachAll();
673 // Gesture ends within actor's area
676 TestEndPan( application, Vector2(10.0f, 4.0f), time );
678 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
682 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
684 TestApplication application;
687 GestureReceivedFunctor functor(data);
689 PanGestureDetector detector = PanGestureDetector::New();
690 detector.DetectedSignal().Connect(&application, functor);
692 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
694 Actor tempActor = Actor::New();
695 tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
696 tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
697 application.GetScene().Add(tempActor);
698 detector.Attach(tempActor);
702 // Actor lifetime is scoped
704 Actor actor = Actor::New();
705 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
706 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
707 application.GetScene().Add(actor);
710 application.SendNotification();
711 application.Render();
713 detector.Attach(actor);
715 // Start pan within the actor's area
716 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
718 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
720 // Continue the pan within the actor's area - we should still receive the signal
723 TestMovePan( application, Vector2(26.0f, 4.0f), time );
724 time += TestGetFrameInterval();
726 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
728 // Remove the actor from stage and reset the data
729 application.GetScene().Remove(actor);
732 application.SendNotification();
733 application.Render();
736 // Actor should now have been destroyed
738 // Gesture ends within the area where the actor used to be
741 TestEndPan( application, Vector2(10.0f, 4.0f), time );
743 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
747 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
749 TestApplication application;
751 Actor actor = Actor::New();
752 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
753 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
754 application.GetScene().Add(actor);
757 application.SendNotification();
758 application.Render();
761 GestureReceivedFunctor functor(data);
763 PanGestureDetector detector = PanGestureDetector::New();
764 detector.Attach(actor);
765 detector.DetectedSignal().Connect(&application, functor);
767 // Do an entire pan, only check finished value
769 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
773 TestEndPan( application, Vector2(25.0f, 28.0f), time );
775 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
776 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
778 // Rotate actor again and render a couple of times
779 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
780 application.SendNotification();
781 application.Render();
783 // Do an entire pan, only check finished value
784 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
788 TestEndPan( application, Vector2(25.0f, 28.0f), time );
790 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
791 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
793 // Rotate actor again and render a couple of times
794 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
795 application.SendNotification();
796 application.Render();
798 // Do an entire pan, only check finished value
799 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
803 TestEndPan( application, Vector2(25.0f, 28.0f), time );
805 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
806 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
810 int UtcDaliPanGestureSignalReceptionChildHit(void)
812 TestApplication application;
814 Actor parent = Actor::New();
815 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
816 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
817 application.GetScene().Add(parent);
819 // Set child to completely cover parent.
820 // Change rotation of child to be different from parent so that we can check if our local coordinate
821 // conversion of the parent actor is correct.
822 Actor child = Actor::New();
823 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
824 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
825 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
826 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
829 TouchEventFunctor touchFunctor;
830 child.TouchedSignal().Connect(&application, touchFunctor);
833 application.SendNotification();
834 application.Render();
837 GestureReceivedFunctor functor(data);
839 PanGestureDetector detector = PanGestureDetector::New();
840 detector.Attach(parent);
841 detector.DetectedSignal().Connect(&application, functor);
843 // Do an entire pan, only check finished value - hits child area but parent should still receive it
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, parent == data.pannedActor, TEST_LOCATION);
853 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
855 // Attach child and generate same touch points to yield a different displacement
856 // (Also proves that you can detach and then re-attach another actor)
857 detector.Attach(child);
858 detector.Detach(parent);
860 // Do an entire pan, only check finished value
861 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
865 TestEndPan( application, Vector2(25.0f, 28.0f), time );
867 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
868 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
869 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
873 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
875 TestApplication application;
877 Actor first = Actor::New();
878 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
879 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
880 application.GetScene().Add(first);
882 Actor second = Actor::New();
883 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
884 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
885 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
886 application.GetScene().Add(second);
889 application.SendNotification();
890 application.Render();
893 GestureReceivedFunctor functor(data);
895 PanGestureDetector detector = PanGestureDetector::New();
896 detector.Attach(first);
897 detector.Attach(second);
898 detector.DetectedSignal().Connect(&application, functor);
900 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
901 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
903 // Start pan within second actor's area
905 TestStartPan( application, Vector2( 110.0f, 20.0f ), Vector2( 126.0f, 20.0f ), time );
907 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), first.GetParent(), TEST_LOCATION);
908 DALI_TEST_EQUALS(application.GetScene().GetRootLayer(), second.GetParent(), TEST_LOCATION);
910 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
911 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
913 // Pan moves into first actor's area - second actor should receive the pan
916 TestMovePan( application, Vector2(126.0f, 20.0f), time );
917 time += TestGetFrameInterval();
919 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
920 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
922 // Detach the second actor during the pan, we should not receive the next event
923 detector.Detach(second);
925 // Gesture ends within actor's area
928 TestMovePan( application, Vector2(26.0f, 20.0f), time );
929 TestEndPan( application, Vector2(10.0f, 4.0f), time );
931 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
936 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
938 TestApplication application;
940 Actor actor = Actor::New();
941 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
942 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
943 application.GetScene().Add(actor);
946 application.SendNotification();
947 application.Render();
950 GestureReceivedFunctor functor(data);
952 PanGestureDetector detector = PanGestureDetector::New();
953 detector.Attach(actor);
954 detector.DetectedSignal().Connect(&application, functor);
956 // Start pan in actor's area
958 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
960 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
962 // Pan continues within actor's area
965 TestMovePan( application, Vector2(26.0f, 4.0f), time );
966 time += TestGetFrameInterval();
968 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
970 // Actor become invisible - actor should not receive the next pan
971 actor.SetProperty( Actor::Property::VISIBLE,false);
974 application.SendNotification();
975 application.Render();
977 // Gesture ends within actor's area
980 TestEndPan( application, Vector2(10.0f, 4.0f), time );
982 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
986 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
988 TestApplication application;
990 Actor actor = Actor::New();
991 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
992 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
993 application.GetScene().Add(actor);
995 Actor actor2 = Actor::New();
996 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
997 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
998 application.GetScene().Add(actor2);
1000 // Render and notify
1001 application.SendNotification();
1002 application.Render();
1004 // Attach actor to one detector
1005 SignalData firstData;
1006 GestureReceivedFunctor firstFunctor(firstData);
1007 PanGestureDetector firstDetector = PanGestureDetector::New();
1008 firstDetector.Attach(actor);
1009 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1011 // Attach actor to another detector
1012 SignalData secondData;
1013 GestureReceivedFunctor secondFunctor(secondData);
1014 PanGestureDetector secondDetector = PanGestureDetector::New();
1015 secondDetector.Attach(actor);
1016 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1018 // Add second actor to second detector, when we remove the actor, this will make sure that this
1019 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1020 // functor should still not be called (which is what we're also testing).
1021 secondDetector.Attach(actor2);
1023 // Pan in actor's area - both detector's functors should be called
1024 uint32_t time = 100;
1025 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1027 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1028 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1030 // Pan continues in actor's area - both detector's functors should be called
1034 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1035 time += TestGetFrameInterval();
1037 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1038 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1040 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1041 firstDetector.Detach(actor);
1045 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1047 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1048 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1050 // New pan on actor, only secondDetector has actor attached
1054 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1056 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1057 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1059 // Detach actor from secondDetector
1060 secondDetector.Detach(actor);
1064 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1066 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1067 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1072 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1074 TestApplication application;
1076 Actor actor1 = Actor::New();
1077 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1078 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1079 application.GetScene().Add(actor1);
1081 GestureReceivedFunctor functor1(data1);
1082 PanGestureDetector detector1 = PanGestureDetector::New();
1083 detector1.Attach(actor1);
1084 detector1.DetectedSignal().Connect(&application, functor1);
1086 Actor actor2 = Actor::New();
1087 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1088 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
1089 actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
1090 application.GetScene().Add(actor2);
1092 GestureReceivedFunctor functor2(data2);
1093 PanGestureDetector detector2 = PanGestureDetector::New();
1094 detector2.Attach(actor2);
1095 detector2.DetectedSignal().Connect(&application, functor2);
1097 // Render and notify
1098 application.SendNotification();
1099 application.Render();
1101 // Start pan in actor1's area, only data1 should be set
1102 uint32_t time = 100;
1103 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1105 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1106 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1110 int UtcDaliPanGestureSignalReceptionAttachActorAfterDown(void)
1112 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event
1114 TestApplication application;
1116 Actor actor = Actor::New();
1117 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1118 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1119 application.GetScene().Add(actor);
1121 // Render and notify
1122 application.SendNotification();
1123 application.Render();
1125 // Gesture possible in actor's area (using long-press)
1126 uint32_t time = 100;
1127 TestStartLongPress( application, 10.0f, 20.0f, time );
1128 time += TestGetFrameInterval();
1130 // Attach actor to detector
1132 GestureReceivedFunctor functor( data );
1133 PanGestureDetector detector = PanGestureDetector::New();
1134 detector.DetectedSignal().Connect( &application, functor );
1135 detector.Attach(actor);
1137 // Start a pan, initially it'll only be possible, we shouldn't receive it
1138 TestMovePan( application, Vector2( 10.0f, 20.0f ), time );
1139 time += TestGetFrameInterval();
1140 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1142 // Now the pan truly starts, we should receive a signal
1143 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1144 time += TestGetFrameInterval();
1145 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1146 time += TestGetFrameInterval();
1147 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1149 // Finish the pan, we should still receive a signal
1151 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1152 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1157 int UtcDaliPanGestureSignalReceptionAttachActorAfterDownAfterInitialPanToAnotherActor(void)
1159 // This test checks to ensure a pan is possible after attaching an actor after a down (possible) event even if another
1160 // pan actor was there before (parent)
1162 TestApplication application;
1164 Actor parent = Actor::New();
1165 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1166 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1167 application.GetScene().Add( parent );
1169 Actor child = Actor::New();
1170 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1171 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
1172 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1173 parent.Add( child );
1175 // Create detector for parent and attach
1176 SignalData parentData;
1177 GestureReceivedFunctor parentFunctor( parentData );
1178 PanGestureDetector parentDetector = PanGestureDetector::New();
1179 parentDetector.DetectedSignal().Connect( &application, parentFunctor );
1180 parentDetector.Attach( parent );
1182 // Create detector for child but do not attach
1183 SignalData childData;
1184 GestureReceivedFunctor childFunctor( childData );
1185 PanGestureDetector childDetector = PanGestureDetector::New();
1186 childDetector.DetectedSignal().Connect( &application, childFunctor );
1188 // Render and notify
1189 application.SendNotification();
1190 application.Render();
1192 // Do a full pan in both actors' area, only the parent's functor should be called
1193 uint32_t time = 100;
1194 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1195 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1196 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1199 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1200 DALI_TEST_EQUALS( parentData.functorCalled, true, TEST_LOCATION );
1201 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1205 // Gesture possible in both actors' area (using long-press), no functors called
1206 TestStartLongPress( application, 10.0f, 20.0f, time );
1207 time += TestGetFrameInterval();
1208 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1209 DALI_TEST_EQUALS( childData.functorCalled, false, TEST_LOCATION );
1211 // Attach the child as well now
1212 childDetector.Attach( child );
1214 // Now the pan truly starts, we should receive a signal for the child only
1215 TestMovePan( application, Vector2( 26.0f, 20.0f ), time );
1216 time += TestGetFrameInterval();
1217 TestMovePan( application, Vector2( 32.0f, 32.0f ), time );
1218 time += TestGetFrameInterval();
1219 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1220 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1224 // Finish the pan, again only the child should still receive a signal
1225 TestEndPan( application, Vector2( 32.0f, 32.0f ), time );
1226 DALI_TEST_EQUALS( parentData.functorCalled, false, TEST_LOCATION );
1227 DALI_TEST_EQUALS( childData.functorCalled, true, TEST_LOCATION );
1232 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1234 TestApplication application;
1236 Actor actor = Actor::New();
1237 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1238 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1239 application.GetScene().Add(actor);
1241 // Render and notify
1242 application.SendNotification();
1243 application.Render();
1245 // Attach actor to detector
1247 GestureReceivedFunctor functor( data );
1248 PanGestureDetector detector = PanGestureDetector::New();
1249 detector.Attach(actor);
1250 detector.DetectedSignal().Connect( &application, functor );
1252 // Gesture possible in actor's area.
1253 uint32_t time = 100;
1254 TestStartLongPress( application, 10.0f, 20.0f, time );
1255 time += TestGetFrameInterval();
1257 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1259 // Move actor somewhere else
1260 actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
1262 // Render and notify
1263 application.SendNotification();
1264 application.Render();
1266 // Emit Started event, we should not receive the pan.
1267 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1268 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1269 time += TestGetFrameInterval();
1271 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1273 // LongPress possible in empty area.
1274 TestStartLongPress( application, 10.0f, 20.0f, time );
1275 time += TestGetFrameInterval();
1277 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1279 // Move actor in to the long press position.
1280 actor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
1282 // Render and notify
1283 application.SendNotification();
1284 application.Render();
1286 // Emit Started event, we should be receiving the pan now.
1287 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1288 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1289 time += TestGetFrameInterval();
1291 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1293 // Normal pan in actor's area for completeness.
1295 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1296 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1297 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1301 int UtcDaliPanGestureActorUnstaged(void)
1303 TestApplication application;
1305 Actor actor = Actor::New();
1306 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1307 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1308 application.GetScene().Add(actor);
1310 // Render and notify
1311 application.SendNotification();
1312 application.Render();
1314 // State to remove actor in.
1315 Gesture::State stateToUnstage( Gesture::Started );
1317 // Attach actor to detector
1319 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1320 PanGestureDetector detector = PanGestureDetector::New();
1321 detector.Attach(actor);
1322 detector.DetectedSignal().Connect( &application, functor );
1325 uint32_t time = 100;
1326 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1328 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1331 TestEndPan( application, Vector2(26.0f, 20.0f), time );
1333 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1336 // Render and notify
1337 application.SendNotification();
1338 application.Render();
1340 // Re-add actor to stage
1341 application.GetScene().Add(actor);
1343 // Render and notify
1344 application.SendNotification();
1345 application.Render();
1347 // Change state to Gesture::Continuing to remove
1348 stateToUnstage = Gesture::Continuing;
1351 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1353 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1356 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1357 time += TestGetFrameInterval();
1359 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1363 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1365 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1368 // Render and notify
1369 application.SendNotification();
1370 application.Render();
1372 // Re-add actor to stage
1373 application.GetScene().Add(actor);
1375 // Render and notify
1376 application.SendNotification();
1377 application.Render();
1379 // Change state to Gesture::Finished to remove
1380 stateToUnstage = Gesture::Finished;
1383 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1385 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1388 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1389 time += TestGetFrameInterval();
1391 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1394 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1396 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1397 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1401 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1403 TestApplication application;
1405 Actor actor = Actor::New();
1406 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1407 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1408 application.GetScene().Add(actor);
1410 // Create and add a second actor so that GestureDetector destruction does not come into play.
1411 Actor dummyActor( Actor::New() );
1412 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1413 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
1414 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1415 application.GetScene().Add(dummyActor);
1417 // Render and notify
1418 application.SendNotification();
1419 application.Render();
1421 // State to remove actor in.
1422 Gesture::State stateToUnstage( Gesture::Started );
1424 // Attach actor to detector
1426 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
1427 PanGestureDetector detector = PanGestureDetector::New();
1428 detector.Attach(actor);
1429 detector.Attach(dummyActor);
1430 detector.DetectedSignal().Connect( &application, functor );
1432 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1433 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1434 // position, we should still not be signalled.
1437 uint32_t time = 100;
1438 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1440 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1443 // Render and notify
1444 application.SendNotification();
1445 application.Render();
1447 // Re add to the stage, we should not be signalled
1448 application.GetScene().Add(actor);
1450 // Render and notify
1451 application.SendNotification();
1452 application.Render();
1454 // Continue signal emission
1455 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1456 time += TestGetFrameInterval();
1458 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1461 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1462 time += TestGetFrameInterval();
1464 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1467 // Here we delete an actor in started, we should not receive any subsequent signalling.
1470 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1472 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1475 // Render and notify
1476 application.SendNotification();
1477 application.Render();
1479 // Delete actor as well
1482 // Render and notify
1483 application.SendNotification();
1484 application.Render();
1486 // Continue signal emission
1487 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1488 time += TestGetFrameInterval();
1490 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1493 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1495 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1499 int UtcDaliPanGestureAngleHandling(void)
1501 TestApplication application;
1503 PanGestureDetector detector = PanGestureDetector::New();
1504 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1506 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1507 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1509 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1511 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1513 tet_result( TET_PASS );
1521 tet_printf("%s, angle not added\n", TEST_LOCATION );
1522 tet_result( TET_FAIL );
1525 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1526 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1528 // Remove something not in the container.
1529 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1530 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1532 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1533 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1534 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1536 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1538 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1539 tet_result( TET_FAIL );
1544 detector.ClearAngles();
1545 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1549 int UtcDaliPanGestureGetAngle(void)
1551 TestApplication application;
1553 PanGestureDetector detector = PanGestureDetector::New();
1554 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1556 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1557 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1559 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1560 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1562 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1563 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1565 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1566 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1568 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1569 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1570 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1571 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1576 inline float RadiansToDegrees( float radian )
1578 return radian * 180.0f / Math::PI;
1581 int UtcDaliPanGestureAngleOutOfRange(void)
1583 TestApplication application;
1585 PanGestureDetector detector = PanGestureDetector::New();
1586 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1592 detector.AddAngle( Degree(180.0f) );
1593 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1594 detector.ClearAngles();
1596 detector.AddAngle( Degree(190.0f) );
1597 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1598 detector.ClearAngles();
1600 detector.AddAngle( Degree(-190.0f) );
1601 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1602 detector.ClearAngles();
1604 detector.AddAngle( Degree(350.0f) );
1605 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1606 detector.ClearAngles();
1608 detector.AddAngle( Degree(-350.0f) );
1609 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1610 detector.ClearAngles();
1612 detector.AddAngle( Degree(370.0f) );
1613 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1614 detector.ClearAngles();
1616 detector.AddAngle( Degree(-370.0f) );
1617 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1618 detector.ClearAngles();
1624 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1625 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1626 detector.ClearAngles();
1628 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1629 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1630 detector.ClearAngles();
1632 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1633 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1634 detector.ClearAngles();
1636 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1637 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1638 detector.ClearAngles();
1642 int UtcDaliPanGestureAngleProcessing(void)
1644 TestApplication application;
1646 Actor parent = Actor::New();
1647 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1648 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1649 application.GetScene().Add(parent);
1651 Actor child = Actor::New();
1652 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1653 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1656 // Render and notify
1657 application.SendNotification();
1658 application.Render();
1660 // Parent detector only requires up pans
1661 PanGestureDetector parentDetector = PanGestureDetector::New();
1662 parentDetector.Attach( parent );
1663 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1664 SignalData parentData;
1665 GestureReceivedFunctor parentFunctor(parentData);
1666 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1668 // Child detector only requires right pans
1669 PanGestureDetector childDetector = PanGestureDetector::New();
1670 childDetector.Attach( child );
1671 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1672 SignalData childData;
1673 GestureReceivedFunctor childFunctor(childData);
1674 childDetector.DetectedSignal().Connect(&application, childFunctor);
1676 // Generate an Up pan gesture, only parent should receive it.
1677 uint32_t time = 100;
1678 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1680 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1681 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1683 TestEndPan( application, Vector2(20.0f, 4.0f), time );
1684 time += TestGetFrameInterval();
1688 // Generate a Right pan gesture, only child should receive it.
1689 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1691 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1692 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1694 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1695 time += TestGetFrameInterval();
1699 // Generate a Down pan gesture, no one should receive it.
1700 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1702 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1703 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1705 TestEndPan( application, Vector2(20.0f, 36.0f), time );
1706 time += TestGetFrameInterval();
1710 // Generate a Left pan gesture, no one should receive it.
1711 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1713 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1714 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1716 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1722 int UtcDaliPanGestureDirectionHandling(void)
1724 TestApplication application;
1726 PanGestureDetector detector = PanGestureDetector::New();
1727 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1729 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1730 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1732 for ( size_t i = 0; detector.GetAngleCount(); i++)
1734 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1736 tet_result( TET_PASS );
1745 tet_printf("%s, angle not added\n", TEST_LOCATION );
1746 tet_result( TET_FAIL );
1750 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1752 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1754 tet_result( TET_PASS );
1762 tet_printf("%s, angle not added\n", TEST_LOCATION );
1763 tet_result( TET_FAIL );
1766 // Remove something not in the container.
1767 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1768 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1770 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1771 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1775 int UtcDaliPanGestureDirectionProcessing(void)
1777 TestApplication application;
1779 Actor parent = Actor::New();
1780 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1781 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1782 application.GetScene().Add(parent);
1784 Actor child = Actor::New();
1785 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1786 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1789 // Render and notify
1790 application.SendNotification();
1791 application.Render();
1793 // Parent detector only requires vertical panning
1794 PanGestureDetector parentDetector = PanGestureDetector::New();
1795 parentDetector.Attach( parent );
1796 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1797 SignalData parentData;
1798 GestureReceivedFunctor parentFunctor(parentData);
1799 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1801 // Child detector only requires horizontal panning
1802 PanGestureDetector childDetector = PanGestureDetector::New();
1803 childDetector.Attach( child );
1804 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1805 SignalData childData;
1806 GestureReceivedFunctor childFunctor(childData);
1807 childDetector.DetectedSignal().Connect(&application, childFunctor);
1809 // Generate an Up pan gesture, only parent should receive it.
1810 uint32_t time = 100;
1811 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1813 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1814 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1816 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1817 time += TestGetFrameInterval();
1821 // Generate a Right pan gesture, only child should receive it.
1822 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1824 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1825 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1827 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1828 time += TestGetFrameInterval();
1832 // Generate a Down pan gesture, only parent should receive it.
1833 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1835 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1836 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1838 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1839 time += TestGetFrameInterval();
1843 // Generate a Left pan gesture, only child should receive it.
1844 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1846 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1847 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1849 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1850 time += TestGetFrameInterval();
1854 // Generate a pan at -45 degrees, no one should receive it.
1855 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 9.0f, 31.0f ), time );
1857 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1858 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1860 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1861 time += TestGetFrameInterval();
1865 // Generate a pan at 45 degrees, no one should receive it.
1866 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 31.0f, 31.0f ), time );
1868 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1869 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1871 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1872 time += TestGetFrameInterval();
1876 // Generate a pan at -135 degrees, no one should receive it.
1877 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 4.0f ), time );
1879 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1880 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1882 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1888 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1890 TestApplication application;
1891 Integration::SetPanGesturePredictionMode(0);
1892 Integration::SetPanGestureSmoothingMode(0);
1894 Actor actor = Actor::New();
1895 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1896 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1897 application.GetScene().Add(actor);
1899 // Add a pan detector
1900 PanGestureDetector detector = PanGestureDetector::New();
1901 detector.Attach( actor );
1903 GestureReceivedFunctor functor( data );
1904 detector.DetectedSignal().Connect( &application, functor );
1906 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1908 ConstraintData constraintData;
1909 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1910 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1911 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1912 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1913 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1914 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1915 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1916 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1919 // Render and notify
1920 application.SendNotification();
1921 application.Render();
1923 Vector2 startPosition( 1.0f, 1.0f );
1924 Vector2 position( -14.0f, 1.0f );
1925 Vector2 direction(Vector2::XAXIS * -5.0f);
1926 uint32_t time = 100;
1928 TestStartPan( application, startPosition, position, time );
1930 for(int i = 0; i < 47; i++ )
1932 position += direction;
1933 TestMovePan( application, position, time );
1934 time += TestGetFrameInterval();
1935 application.SendNotification();
1936 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1939 TestEndPan( application, position, time );
1940 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1942 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1943 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1944 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1945 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1947 constraintData.Reset();
1951 int UtcDaliPanGestureNoPredictionSmoothing(void)
1953 TestApplication application;
1954 Integration::SetPanGesturePredictionMode(0);
1955 Integration::SetPanGestureSmoothingMode(1);
1957 Actor actor = Actor::New();
1958 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1959 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1960 application.GetScene().Add(actor);
1962 // Add a pan detector
1963 PanGestureDetector detector = PanGestureDetector::New();
1964 detector.Attach( actor );
1966 GestureReceivedFunctor functor( data );
1967 detector.DetectedSignal().Connect( &application, functor );
1969 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1971 ConstraintData constraintData;
1972 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1973 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1974 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1975 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1976 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1977 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1978 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1979 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1982 // Render and notify
1983 application.SendNotification();
1984 application.Render();
1986 Vector2 startPosition( 1.0f, 1.0f );
1987 Vector2 position( -14.0f, 1.0f );
1988 Vector2 direction(Vector2::XAXIS * -5.0f);
1989 uint32_t time = 100;
1991 TestStartPan( application, startPosition, position, time );
1993 for(int i = 0; i < 47; i++ )
1995 position += direction;
1996 TestMovePan( application, position, time );
1997 time += TestGetFrameInterval();
1998 application.SendNotification();
1999 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2002 TestEndPan( application, position, time );
2003 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2005 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2006 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2007 // Take into account resampling done when prediction is off.
2008 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2009 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2011 constraintData.Reset();
2015 int UtcDaliPanGesturePredictionNoSmoothing(void)
2017 TestApplication application;
2018 Integration::SetPanGesturePredictionMode(1);
2019 Integration::SetPanGestureSmoothingMode(0);
2021 Actor actor = Actor::New();
2022 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2023 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2024 application.GetScene().Add(actor);
2026 // Add a pan detector
2027 PanGestureDetector detector = PanGestureDetector::New();
2028 detector.Attach( actor );
2030 GestureReceivedFunctor functor( data );
2031 detector.DetectedSignal().Connect( &application, functor );
2033 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2035 ConstraintData constraintData;
2036 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2037 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2038 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2039 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2040 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2041 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2042 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2043 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2046 // Render and notify
2047 application.SendNotification();
2048 application.Render();
2050 Vector2 startPosition( 1.0f, 1.0f );
2051 Vector2 position( -1.0f, 1.0f );
2052 Vector2 direction(Vector2::XAXIS * -1.0f);
2053 uint32_t time = 100;
2055 TestStartPan( application, startPosition, position, time );
2057 for(int i = 0; i < 47; i++ )
2059 position += direction;
2060 TestMovePan( application, position, time );
2061 time += TestGetFrameInterval();
2062 application.SendNotification();
2063 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2066 TestEndPan( application, position, time );
2067 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2069 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2070 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2071 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2072 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2074 constraintData.Reset();
2078 int UtcDaliPanGesturePredictionSmoothing01(void)
2080 TestApplication application;
2081 Integration::SetPanGesturePredictionMode(1);
2082 Integration::SetPanGestureSmoothingMode(1);
2084 Actor actor = Actor::New();
2085 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2086 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2087 application.GetScene().Add(actor);
2089 // Add a pan detector
2090 PanGestureDetector detector = PanGestureDetector::New();
2091 detector.Attach( actor );
2093 GestureReceivedFunctor functor( data );
2094 detector.DetectedSignal().Connect( &application, functor );
2096 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2098 ConstraintData constraintData;
2099 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2100 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2101 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2102 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2103 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2104 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2105 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2106 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2109 // Render and notify
2110 application.SendNotification();
2111 application.Render();
2113 Vector2 startPosition( 1.0f, 1.0f );
2114 Vector2 position( -1.0f, 1.0f );
2115 Vector2 direction(Vector2::XAXIS * -1.0f);
2116 uint32_t time = 100;
2118 TestStartPan( application, startPosition, position, time );
2120 for(int i = 0; i < 47; i++ )
2122 position += direction;
2123 TestMovePan( application, position, time );
2124 time += TestGetFrameInterval();
2125 application.SendNotification();
2126 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2129 TestEndPan( application, position, time );
2130 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2132 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2133 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2134 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2135 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2137 constraintData.Reset();
2141 int UtcDaliPanGesturePredictionSmoothing02(void)
2143 TestApplication application;
2144 Integration::SetPanGesturePredictionMode( 1 );
2145 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2146 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2147 Integration::SetPanGestureSmoothingMode( 1 );
2148 Integration::SetPanGestureSmoothingAmount( 0.25f );
2150 Actor actor = Actor::New();
2151 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2152 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2153 application.GetScene().Add(actor);
2155 // Add a pan detector
2156 PanGestureDetector detector = PanGestureDetector::New();
2157 detector.Attach( actor );
2159 GestureReceivedFunctor functor( data );
2160 detector.DetectedSignal().Connect( &application, functor );
2162 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2164 ConstraintData constraintData;
2165 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2166 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2167 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2168 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2169 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2170 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2171 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2172 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2175 // Render and notify
2176 application.SendNotification();
2177 application.Render();
2179 Vector2 startPosition( 2.0f, 2.0f );
2180 Vector2 position( 4.0f, 2.0f );
2181 Vector2 directionX(Vector2::XAXIS);
2182 Vector2 directionY(Vector2::YAXIS);
2183 uint32_t time = 100;
2185 TestStartPan( application, startPosition, position, time );
2187 for(int i = 0; i < 7; i++ )
2189 position += directionX;
2190 TestMovePan( application, position, time );
2191 time += TestGetFrameInterval();
2192 application.SendNotification();
2193 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2196 position += directionX * 10.0f;
2197 TestMovePan( application, position, time );
2198 time += TestGetFrameInterval();
2199 application.SendNotification();
2200 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2202 for(int i = 0; i < 2; i++ )
2204 position += ( directionX * -1.0f );
2205 TestMovePan( application, position, time );
2206 time += TestGetFrameInterval();
2207 application.SendNotification();
2208 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2211 for(int i = 0; i < 10; i++ )
2213 position += directionX;
2214 TestMovePan( application, position, time );
2215 time += TestGetFrameInterval();
2216 application.SendNotification();
2217 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2220 for(int i = 0; i < 10; i++ )
2222 position += directionY;
2223 TestMovePan( application, position, time );
2224 time += TestGetFrameInterval();
2225 application.SendNotification();
2226 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2229 TestEndPan( application, position, time );
2230 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2232 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2233 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2234 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2235 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2237 constraintData.Reset();
2241 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2243 TestApplication application;
2245 Integration::SetPanGesturePredictionMode( 2 );
2246 Integration::SetPanGesturePredictionAmount( 57 );
2247 Integration::SetPanGestureSmoothingMode( 2 );
2248 Integration::SetPanGestureUseActualTimes( false );
2249 Integration::SetPanGestureInterpolationTimeRange( 10 );
2250 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2251 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2252 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2253 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2254 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2255 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2257 Actor actor = Actor::New();
2258 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2259 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2260 application.GetScene().Add(actor);
2262 // Add a pan detector
2263 PanGestureDetector detector = PanGestureDetector::New();
2264 detector.Attach( actor );
2266 GestureReceivedFunctor functor( data );
2267 detector.DetectedSignal().Connect( &application, functor );
2269 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2271 ConstraintData constraintData;
2272 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2273 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2274 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2275 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2276 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2277 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2278 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2279 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2282 // Render and notify
2283 application.SendNotification();
2284 application.Render();
2286 Vector2 startPosition( 2.0f, 2.0f );
2287 Vector2 position( -1.0f, 2.0f );
2288 Vector2 direction(Vector2::XAXIS * -1.0f);
2289 uint32_t time = 100;
2291 TestStartPan( application, startPosition, position, time );
2293 for(int i = 0; i < 27; i++ )
2295 position += direction;
2296 TestMovePan( application, position, time );
2297 time += TestGetFrameInterval();
2298 application.SendNotification();
2299 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2302 TestEndPan( application, position, time );
2303 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2305 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2306 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2307 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2308 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2310 constraintData.Reset();
2314 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2316 TestApplication application;
2318 Integration::SetPanGesturePredictionMode( 2 );
2319 Integration::SetPanGestureSmoothingMode( 2 );
2320 Integration::SetPanGestureUseActualTimes( true );
2321 Integration::SetPanGestureInterpolationTimeRange( 10 );
2322 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2323 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2324 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2325 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2326 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2327 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2329 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2331 Actor actor = Actor::New();
2332 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2333 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2334 application.GetScene().Add(actor);
2336 // Add a pan detector
2337 PanGestureDetector detector = PanGestureDetector::New();
2338 detector.Attach( actor );
2340 GestureReceivedFunctor functor( data );
2341 detector.DetectedSignal().Connect( &application, functor );
2343 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2345 ConstraintData constraintData;
2346 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2347 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2348 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2349 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2350 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2351 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2352 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2353 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2356 // Render and notify
2357 application.SendNotification();
2358 application.Render();
2360 Vector2 startPosition( 2.0f, 2.0f );
2361 Vector2 position( 17.0f, 2.0f );
2362 Vector2 direction(Vector2::XAXIS * -1.0f);
2363 uint32_t time = 100;
2365 TestStartPan( application, startPosition, position, time );
2367 for(int i = 0; i < 10; i++ )
2369 position += direction;
2370 TestMovePan( application, position, time );
2371 time += TestGetFrameInterval();
2373 position += direction;
2374 TestMovePan( application, position, time );
2375 time += TestGetFrameInterval();
2377 position += direction;
2378 TestMovePan( application, position, time );
2379 time += TestGetFrameInterval();
2381 application.SendNotification();
2382 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2385 for(int i = 0; i < 10; i++ )
2387 application.SendNotification();
2388 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2391 for(int i = 0; i < 10; i++ )
2393 position += direction;
2394 TestMovePan( application, position, time );
2395 application.SendNotification();
2396 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2399 for(int i = 0; i < 10; i++ )
2401 position += direction;
2402 TestMovePan( application, position, time );
2403 time += TestGetFrameInterval();
2404 application.SendNotification();
2405 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2408 TestEndPan( application, position, time );
2409 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2411 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2412 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2413 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2414 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2416 constraintData.Reset();
2420 int UtcDaliPanGesturePrediction2Smoothing(void)
2422 TestApplication application;
2424 Integration::SetPanGesturePredictionMode( 2 );
2425 Integration::SetPanGesturePredictionAmount( 57 );
2426 Integration::SetPanGestureSmoothingMode( 1 );
2427 Integration::SetPanGestureUseActualTimes( false );
2428 Integration::SetPanGestureInterpolationTimeRange( 10 );
2429 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2430 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2431 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2432 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2433 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2434 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2436 Actor actor = Actor::New();
2437 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2438 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2439 application.GetScene().Add(actor);
2441 // Add a pan detector
2442 PanGestureDetector detector = PanGestureDetector::New();
2443 detector.Attach( actor );
2445 GestureReceivedFunctor functor( data );
2446 detector.DetectedSignal().Connect( &application, functor );
2448 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2450 ConstraintData constraintData;
2451 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2452 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2453 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2454 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2455 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2456 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2457 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2458 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2461 // Render and notify
2462 application.SendNotification();
2463 application.Render();
2465 Vector2 startPosition( 2.0f, 2.0f );
2466 Vector2 position( 17.0f, 2.0f );
2467 Vector2 direction(Vector2::XAXIS * -1.0f);
2468 uint32_t time = 100;
2470 TestStartPan( application, startPosition, position, time );
2472 for(int i = 0; i < 10; i++ )
2474 position += direction;
2475 TestMovePan( application, position, time );
2476 time += TestGetFrameInterval();
2477 application.SendNotification();
2478 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2482 position += direction;
2483 TestMovePan( application, position, time );
2484 time += TestGetFrameInterval();
2486 position += direction;
2487 TestMovePan( application, position, time );
2488 time += TestGetFrameInterval();
2490 position += direction;
2491 TestMovePan( application, position, time );
2492 time += TestGetFrameInterval();
2494 application.SendNotification();
2495 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2497 for(int i = 0; i < 5; i++ )
2499 application.SendNotification();
2500 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2503 for(int i = 0; i < 10; i++ )
2505 position += direction;
2506 TestMovePan( application, position, time );
2507 time += TestGetFrameInterval();
2508 application.SendNotification();
2509 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2512 TestEndPan( application, position, time );
2513 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2515 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2516 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2517 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2518 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2520 constraintData.Reset();
2524 int UtcDaliPanGestureSetProperties(void)
2526 TestApplication application;
2527 TestRenderController& renderController( application.GetRenderController() );
2528 Integration::SetPanGesturePredictionMode(0);
2529 Integration::SetPanGestureSmoothingMode(0);
2531 Actor actor = Actor::New();
2532 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2533 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2534 application.GetScene().Add(actor);
2536 // Add a pan detector
2537 PanGestureDetector detector = PanGestureDetector::New();
2538 detector.Attach( actor );
2540 GestureReceivedFunctor functor( data );
2541 detector.DetectedSignal().Connect( &application, functor );
2543 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2544 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2546 ConstraintData constraintData;
2547 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2548 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2549 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2550 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2551 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2552 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2553 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2554 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2555 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2558 // Render and notify
2559 application.SendNotification();
2560 application.Render();
2562 renderController.Initialize();
2563 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2565 Vector2 screenPosition( 20.0f, 20.0f );
2566 Vector2 screenDisplacement( 1.0f, 1.0f );
2567 Vector2 screenVelocity( 1.3f, 4.0f );
2568 Vector2 localPosition( 21.0f, 21.0f );
2569 Vector2 localDisplacement( 0.5f, 0.5f );
2570 Vector2 localVelocity( 1.5f, 2.5f );
2572 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2573 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2575 // Render and notify
2576 application.SendNotification();
2577 application.Render();
2579 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2580 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2581 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2582 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2583 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2584 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2585 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2586 constraintData.Reset();
2590 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2592 TestApplication application;
2593 Integration::SetPanGesturePredictionMode(0);
2595 Actor actor = Actor::New();
2596 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2597 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2598 application.GetScene().Add(actor);
2600 // Add a pan detector
2601 PanGestureDetector detector = PanGestureDetector::New();
2602 detector.Attach( actor );
2604 GestureReceivedFunctor functor( data );
2605 detector.DetectedSignal().Connect( &application, functor );
2607 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2609 ConstraintData constraintData;
2610 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2611 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2612 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2613 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2614 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2615 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2616 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2617 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2620 // Render and notify
2621 application.SendNotification();
2622 application.Render();
2624 Vector2 currentPosition( 20.0f, 4.0f );
2625 uint32_t time = 100;
2626 TestStartPan( application, Vector2( 20.0f, 20.0f ), currentPosition, time );
2627 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2629 Vector2 screenPosition( 100.0f, 20.0f );
2630 Vector2 localPosition( 110.0f, 110.0f );
2632 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2634 // Render and notify
2635 application.SendNotification();
2636 application.Render();
2638 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2639 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2640 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2641 constraintData.Reset();
2645 int UtcDaliPanGesturePropertyIndices(void)
2647 TestApplication application;
2648 PanGestureDetector detector = PanGestureDetector::New();
2650 Property::IndexContainer indices;
2651 detector.GetPropertyIndices( indices );
2652 DALI_TEST_CHECK( indices.Size() );
2653 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2659 struct PropertyStringIndex
2661 const char * const name;
2662 const Property::Index index;
2663 const Property::Type type;
2664 const Property::Value value;
2667 const PropertyStringIndex PROPERTY_TABLE[] =
2669 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2670 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2671 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2672 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2673 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2674 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2675 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2677 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2678 } // unnamed namespace
2681 int UtcDaliPanGestureProperties(void)
2683 TestApplication application;
2684 PanGestureDetector detector = PanGestureDetector::New();
2686 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2688 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2689 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2690 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2691 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2692 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2693 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2694 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2700 int UtcDaliPanGestureGetProperty(void)
2702 TestApplication application;
2703 PanGestureDetector detector = PanGestureDetector::New();
2705 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2707 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2709 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2710 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2712 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2714 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2715 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2722 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2724 TestApplication application;
2726 Actor actor = Actor::New();
2727 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2728 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2729 application.GetScene().Add(actor);
2731 // Add a pan detector
2732 PanGestureDetector detector = PanGestureDetector::New();
2733 detector.Attach( actor );
2735 // Render and notify
2736 application.SendNotification();
2737 application.Render();
2739 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2741 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2743 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2745 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2746 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2748 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2750 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2751 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2758 int UtcDaliPanGestureLayerConsumesTouch(void)
2760 TestApplication application;
2762 Actor actor = Actor::New();
2763 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2764 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2765 application.GetScene().Add(actor);
2767 // Add a pan detector
2768 PanGestureDetector detector = PanGestureDetector::New();
2769 detector.Attach( actor );
2771 GestureReceivedFunctor functor( data );
2772 detector.DetectedSignal().Connect( &application, functor );
2774 // Add a layer to overlap the actor
2775 Layer layer = Layer::New();
2776 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2777 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2778 application.GetScene().Add( layer );
2781 // Render and notify
2782 application.SendNotification();
2783 application.Render();
2785 // Emit signals, should receive
2786 uint32_t time = 100;
2787 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2788 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2789 time += TestGetFrameInterval();
2791 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2794 // Set layer to consume all touch
2795 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
2797 // Render and notify
2798 application.SendNotification();
2799 application.Render();
2801 // Emit the same signals again, should not receive
2802 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2803 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2805 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2811 int UtcDaliPanGestureNoTimeDiff(void)
2813 TestApplication application;
2815 Actor actor = Actor::New();
2816 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2817 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2818 application.GetScene().Add(actor);
2820 // Add a pan detector
2821 PanGestureDetector detector = PanGestureDetector::New();
2822 detector.Attach( actor );
2824 GestureReceivedFunctor functor( data );
2825 detector.DetectedSignal().Connect( &application, functor );
2827 // Render and notify
2828 application.SendNotification();
2829 application.Render();
2831 // As normal helper function adds intervals between presses we must generate the sequence
2832 // using other helper functions
2833 TestStartLongPress( application, 10.0f, 20.0f, 100 ); // Used to send a down press event
2834 TestMovePan( application, Vector2(26.0f, 20.0f), 100 );
2835 TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); // 2 motions required to trigger
2836 TestEndPan( application, Vector2(26.0f, 20.0f), 100 );
2838 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2839 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2840 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2841 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2842 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );
2850 int UtcDaliPanGestureInterruptedWhenTouchConsumed(void)
2852 TestApplication application;
2854 Actor actor = Actor::New();
2855 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2856 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2857 application.GetScene().Add(actor);
2859 bool consume = false;
2860 TouchDataFunctorConsumeSetter touchFunctor(consume);
2861 actor.TouchSignal().Connect(&application,touchFunctor);
2863 // Render and notify
2864 application.SendNotification();
2865 application.Render();
2868 GestureReceivedFunctor functor(data);
2870 PanGestureDetector detector = PanGestureDetector::New();
2871 detector.Attach(actor);
2872 detector.DetectedSignal().Connect(&application, functor);
2874 // Start gesture within the actor's area, we should receive the pan as the touch is NOT being consumed
2875 uint32_t time = 100;
2876 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2878 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2879 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
2882 // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
2885 TestMovePan( application, Vector2(26.0f, 4.0f), time );
2886 time += TestGetFrameInterval();
2888 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2889 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
2894 int UtcDaliPanGestureDisableDetectionDuringPanN(void)
2896 // Crash occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
2898 TestApplication application;
2900 Actor actor = Actor::New();
2901 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2902 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2903 application.GetScene().Add(actor);
2905 // Add a pan detector
2906 PanGestureDetector detector = PanGestureDetector::New();
2907 bool functorCalled = false;
2908 detector.Attach( actor );
2909 detector.DetectedSignal().Connect(
2911 [&detector, &functorCalled](Actor actor, const PanGesture& pan)
2913 if( pan.state == Gesture::Finished )
2915 detector.Detach(actor);
2916 functorCalled = true;
2920 // Render and notify
2921 application.SendNotification();
2922 application.Render();
2924 // Try the gesture, should not crash
2927 uint32_t time = 100;
2928 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2929 TestEndPan( application, Vector2(26.0f, 20.0f) );
2931 DALI_TEST_CHECK( true ); // No crash, test has passed
2932 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
2936 DALI_TEST_CHECK( false ); // If we crash, the test has failed