2 * Copyright (c) 2014 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/events/pan-gesture-event.h>
25 #include <dali/integration-api/system-overlay.h>
26 #include <dali/integration-api/profiling.h>
27 #include <dali/integration-api/input-options.h>
28 #include <dali-test-suite-utils.h>
29 #include <test-touch-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 )
103 : GestureReceivedFunctor( data ),
104 stateToUnstage( stateToUnstage )
108 void operator()( Actor actor, const PanGesture& pan )
110 GestureReceivedFunctor::operator()( actor, pan );
112 if ( pan.state == stateToUnstage )
114 Stage::GetCurrent().Remove( actor );
118 Gesture::State& stateToUnstage;
121 // Functor for receiving a touch event
122 struct TouchEventFunctor
124 bool operator()(Actor actor, const TouchEvent& touch)
130 // Data for constraints
131 struct ConstraintData
138 Vector2 screenPosition;
139 Vector2 screenDisplacement;
140 Vector2 screenVelocity;
141 Vector2 localPosition;
142 Vector2 localDisplacement;
143 Vector2 localVelocity;
148 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
153 // Constraint used with panning properties
156 PanConstraint( ConstraintData& data ) : constraintData(data) { }
158 void operator()( Vector3& current, const PropertyInputContainer& inputs )
160 constraintData.screenPosition = inputs[0]->GetVector2();
161 constraintData.screenDisplacement = inputs[1]->GetVector2();
162 constraintData.screenVelocity = inputs[2]->GetVector2();
163 constraintData.localPosition = inputs[3]->GetVector2();
164 constraintData.localDisplacement = inputs[4]->GetVector2();
165 constraintData.localVelocity = inputs[5]->GetVector2();
166 constraintData.called = true;
167 current = Vector3::ZERO;
170 ConstraintData& constraintData;
173 // Generate a PanGestureEvent to send to Core
174 Integration::PanGestureEvent GeneratePan(
175 Gesture::State state,
176 Vector2 previousPosition,
177 Vector2 currentPosition,
178 unsigned long timeDelta,
179 unsigned int numberOfTouches = 1,
180 unsigned int time = 1u)
182 Integration::PanGestureEvent pan(state);
184 pan.previousPosition = previousPosition;
185 pan.currentPosition = currentPosition;
186 pan.timeDelta = timeDelta;
187 pan.numberOfTouches = numberOfTouches;
193 // Generate a PanGesture
194 PanGesture GeneratePan( unsigned int time,
195 Gesture::State state,
196 Vector2 screenPosition,
197 Vector2 localPosition,
198 Vector2 screenDisplacement = Vector2::ONE,
199 Vector2 localDisplacement = Vector2::ONE,
200 Vector2 screenVelocity = Vector2::ONE,
201 Vector2 localVelocity = Vector2::ONE,
202 unsigned int numberOfTouches = 1 )
204 PanGesture pan( state );
208 pan.screenPosition = screenPosition;
209 pan.position = localPosition;
211 pan.screenDisplacement = screenDisplacement;
212 pan.displacement = localDisplacement;
214 pan.screenVelocity = screenVelocity;
215 pan.velocity = localVelocity;
217 pan.numberOfTouches = numberOfTouches;
223 * Helper to generate PanGestureEvent
225 * @param[in] application Application instance
226 * @param[in] state The Gesture State
227 * @param[in] pos The current position of touch.
229 static void SendPan(TestApplication& application, Gesture::State state, const Vector2& pos)
232 static int LastTime = 0;
234 if( (state == Gesture::Started) ||
235 (state == Gesture::Possible) )
241 application.ProcessEvent(GeneratePan(state, last, pos, PAN_EVENT_TIME_DELTA));
245 LastTime += PAN_EVENT_TIME_DELTA;
248 static Vector2 PerformSwipeGestureSwipe(TestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
250 // Now do a pan starting from (start) and heading (direction)
252 SendPan(application, Gesture::Possible, pos);
253 SendPan(application, Gesture::Started, pos);
254 application.SendNotification();
255 application.Render();
257 for(int i = 0;i<frames;i++)
259 pos += direction; // Move in this direction
260 SendPan(application, Gesture::Continuing, pos);
261 application.SendNotification();
262 application.Render();
267 SendPan(application, Gesture::Finished, pos);
268 application.SendNotification();
269 application.Render();
277 ///////////////////////////////////////////////////////////////////////////////
279 // Positive test case for a method
280 int UtcDaliPanGestureDetectorConstructor(void)
282 TestApplication application;
284 PanGestureDetector detector;
285 DALI_TEST_CHECK(!detector);
289 int UtcDaliPanGestureDetectorCopyConstructorP(void)
291 TestApplication application;
293 PanGestureDetector detector = PanGestureDetector::New();;
295 PanGestureDetector copy( detector );
296 DALI_TEST_CHECK( detector );
300 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
302 TestApplication application;
304 PanGestureDetector detector = PanGestureDetector::New();;
306 PanGestureDetector assign;
308 DALI_TEST_CHECK( detector );
310 DALI_TEST_CHECK( detector == assign );
314 // Negative test case for a method
315 int UtcDaliPanGestureDetectorNew(void)
317 TestApplication application;
319 PanGestureDetector detector = PanGestureDetector::New();
321 DALI_TEST_CHECK(detector);
323 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
324 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
326 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
327 Actor actor = Actor::New();
328 actor.SetSize(100.0f, 100.0f);
329 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
330 detector.Attach(actor);
332 Stage::GetCurrent().Add(actor);
335 application.SendNotification();
336 application.Render();
338 Integration::TouchEvent touchEvent(1);
339 Integration::Point point;
340 point.SetDeviceId( 1 );
341 point.SetState( PointState::DOWN );
342 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
343 touchEvent.AddPoint(point);
344 application.ProcessEvent(touchEvent);
348 int UtcDaliPanGestureDetectorDownCast(void)
350 TestApplication application;
351 tet_infoline("Testing Dali::GestureDetector::DownCast()");
353 PanGestureDetector detector = PanGestureDetector::New();
355 BaseHandle object(detector);
357 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
358 DALI_TEST_CHECK(detector2);
360 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
361 DALI_TEST_CHECK(detector3);
363 BaseHandle unInitializedObject;
364 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
365 DALI_TEST_CHECK(!detector4);
367 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
368 DALI_TEST_CHECK(!detector5);
370 GestureDetector detector6 = PanGestureDetector::New();
371 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
372 DALI_TEST_CHECK(detector7);
376 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
378 TestApplication application;
380 PanGestureDetector detector = PanGestureDetector::New();
382 unsigned int min = 2;
384 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
386 detector.SetMinimumTouchesRequired(min);
388 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
390 // Attach an actor and change the minimum touches
392 Actor actor = Actor::New();
393 actor.SetSize(100.0f, 100.0f);
394 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
395 Stage::GetCurrent().Add(actor);
398 application.SendNotification();
399 application.Render();
402 GestureReceivedFunctor functor(data);
404 detector.Attach(actor);
405 detector.DetectedSignal().Connect(&application, functor);
407 TestGestureManager& gestureManager = application.GetGestureManager();
408 gestureManager.Initialize();
410 detector.SetMinimumTouchesRequired(3);
412 // Gesture detection should have been updated only
413 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
414 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
415 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
418 gestureManager.Initialize();
420 // Create a second gesture detector that requires even less minimum touches
421 PanGestureDetector secondDetector = PanGestureDetector::New();
422 secondDetector.Attach(actor);
424 // Gesture detection should have been updated only
425 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
426 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
427 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
431 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
433 TestApplication application;
435 PanGestureDetector detector = PanGestureDetector::New();
437 unsigned int max = 3;
439 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
441 detector.SetMaximumTouchesRequired(max);
443 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
445 // Attach an actor and change the maximum touches
447 Actor actor = Actor::New();
448 actor.SetSize(100.0f, 100.0f);
449 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
450 Stage::GetCurrent().Add(actor);
453 application.SendNotification();
454 application.Render();
457 GestureReceivedFunctor functor(data);
459 detector.Attach(actor);
460 detector.DetectedSignal().Connect(&application, functor);
462 TestGestureManager& gestureManager = application.GetGestureManager();
463 gestureManager.Initialize();
465 detector.SetMaximumTouchesRequired(4);
467 // Gesture detection should have been updated only
468 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
469 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
470 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
473 gestureManager.Initialize();
475 // Create a second gesture detector that requires even less maximum touches
476 PanGestureDetector secondDetector = PanGestureDetector::New();
477 secondDetector.Attach(actor);
479 // Gesture detection should NOT have been updated
480 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
481 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
482 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
486 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
488 TestApplication application;
490 PanGestureDetector detector = PanGestureDetector::New();
491 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
495 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
497 TestApplication application;
499 PanGestureDetector detector = PanGestureDetector::New();
500 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
504 int UtcDaliPanGestureSignalReceptionNegative(void)
506 TestApplication application;
508 Actor actor = Actor::New();
509 actor.SetSize(100.0f, 100.0f);
510 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
511 Stage::GetCurrent().Add(actor);
514 application.SendNotification();
515 application.Render();
518 GestureReceivedFunctor functor(data);
520 PanGestureDetector detector = PanGestureDetector::New();
521 detector.Attach(actor);
522 detector.DetectedSignal().Connect(&application, functor);
524 // Do a pan outside actor's area
525 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
526 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
527 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
529 // Continue pan into actor's area - we should still not receive the signal
531 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
532 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
534 // Stop panning - we should still not receive the signal
536 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
537 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
541 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
543 TestApplication application;
545 Actor actor = Actor::New();
546 actor.SetSize(100.0f, 100.0f);
547 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
548 Stage::GetCurrent().Add(actor);
551 application.SendNotification();
552 application.Render();
555 GestureReceivedFunctor functor(data);
557 PanGestureDetector detector = PanGestureDetector::New();
558 detector.Attach(actor);
559 detector.DetectedSignal().Connect(&application, functor);
561 // Start pan within the actor's area
562 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
563 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
564 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
565 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
566 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
567 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
568 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
569 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
570 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
572 // Continue the pan within the actor's area - we should still receive the signal
574 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
575 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
576 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
577 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
578 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
579 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
580 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
581 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
583 // Pan Gesture leaves actor's area - we should still receive the signal
585 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
586 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
587 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
588 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
589 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
590 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
591 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
592 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
594 // Gesture ends - we would receive a finished state
596 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
597 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
598 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
599 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
600 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
601 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
602 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
603 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
607 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
609 TestApplication application;
611 Actor actor = Actor::New();
612 actor.SetSize(100.0f, 100.0f);
613 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
614 Stage::GetCurrent().Add(actor);
617 application.SendNotification();
618 application.Render();
621 GestureReceivedFunctor functor(data);
623 PanGestureDetector detector = PanGestureDetector::New();
624 detector.Attach(actor);
625 detector.DetectedSignal().Connect(&application, functor);
627 // Start pan within the actor's area
628 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
629 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
630 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
631 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
632 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
633 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
634 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
635 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
636 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
638 // Continue the pan within the actor's area - we should still receive the signal
640 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
641 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
642 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
643 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
644 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
645 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
646 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
647 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
649 // Gesture ends within actor's area - we would receive a finished state
651 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
652 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
653 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
654 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
655 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
656 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
657 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
658 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
662 int UtcDaliPanGestureSignalReceptionCancelled(void)
664 TestApplication application;
666 Actor actor = Actor::New();
667 actor.SetSize(100.0f, 100.0f);
668 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
669 Stage::GetCurrent().Add(actor);
672 application.SendNotification();
673 application.Render();
676 GestureReceivedFunctor functor(data);
678 PanGestureDetector detector = PanGestureDetector::New();
679 detector.Attach(actor);
680 detector.DetectedSignal().Connect(&application, functor);
682 // Start pan within the actor's area
683 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
684 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
685 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
686 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
688 // Continue the pan within the actor's area - we should still receive the signal
690 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
691 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
692 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
694 // The gesture is cancelled
696 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
697 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
698 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
702 int UtcDaliPanGestureSignalReceptionDetach(void)
704 TestApplication application;
706 Actor actor = Actor::New();
707 actor.SetSize(100.0f, 100.0f);
708 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
709 Stage::GetCurrent().Add(actor);
712 application.SendNotification();
713 application.Render();
716 GestureReceivedFunctor functor(data);
718 PanGestureDetector detector = PanGestureDetector::New();
719 detector.Attach(actor);
720 detector.DetectedSignal().Connect(&application, functor);
722 // Start pan within the actor's area
723 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
724 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
725 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
727 // Continue the pan within the actor's area - we should still receive the signal
729 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
730 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
732 // Gesture ends within actor's area
734 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
735 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
738 detector.DetachAll();
740 // Ensure we are no longer signalled
742 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
743 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
744 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
745 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
746 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
750 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
752 TestApplication application;
754 Actor actor = Actor::New();
755 actor.SetSize(100.0f, 100.0f);
756 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
757 Stage::GetCurrent().Add(actor);
760 application.SendNotification();
761 application.Render();
764 GestureReceivedFunctor functor(data);
766 PanGestureDetector detector = PanGestureDetector::New();
767 detector.Attach(actor);
768 detector.DetectedSignal().Connect(&application, functor);
770 // Start pan within the actor's area
771 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
772 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
773 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
775 // Continue the pan within the actor's area - we should still receive the signal
777 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
778 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
780 // Detach actor during the pan, we should not receive the next event
781 detector.DetachAll();
783 // Gesture ends within actor's area
785 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
786 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
790 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
792 TestApplication application;
795 GestureReceivedFunctor functor(data);
797 PanGestureDetector detector = PanGestureDetector::New();
798 detector.DetectedSignal().Connect(&application, functor);
800 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
802 Actor tempActor = Actor::New();
803 tempActor.SetSize(100.0f, 100.0f);
804 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
805 Stage::GetCurrent().Add(tempActor);
806 detector.Attach(tempActor);
808 // Actor lifetime is scoped
810 Actor actor = Actor::New();
811 actor.SetSize(100.0f, 100.0f);
812 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
813 Stage::GetCurrent().Add(actor);
816 application.SendNotification();
817 application.Render();
819 detector.Attach(actor);
821 // Start pan within the actor's area
822 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
823 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
824 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
826 // Continue the pan within the actor's area - we should still receive the signal
828 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
829 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
831 // Remove the actor from stage and reset the data
832 Stage::GetCurrent().Remove(actor);
835 application.SendNotification();
836 application.Render();
839 // Actor should now have been destroyed
841 // Gesture ends within the area where the actor used to be
843 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
844 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
848 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
850 TestApplication application;
852 Actor actor = Actor::New();
853 actor.SetSize(100.0f, 100.0f);
854 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
855 Stage::GetCurrent().Add(actor);
858 application.SendNotification();
859 application.Render();
862 GestureReceivedFunctor functor(data);
864 PanGestureDetector detector = PanGestureDetector::New();
865 detector.Attach(actor);
866 detector.DetectedSignal().Connect(&application, functor);
868 // Do an entire pan, only check finished value
869 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
870 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
872 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
873 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
874 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
876 // Rotate actor again and render a couple of times
877 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
878 application.SendNotification();
879 application.Render();
881 // Do an entire pan, only check finished value
882 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
883 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
885 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
886 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
887 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
889 // Rotate actor again and render a couple of times
890 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
891 application.SendNotification();
892 application.Render();
894 // Do an entire pan, only check finished value
895 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
896 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
898 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
899 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
900 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
904 int UtcDaliPanGestureSignalReceptionChildHit(void)
906 TestApplication application;
908 Actor parent = Actor::New();
909 parent.SetSize(100.0f, 100.0f);
910 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
911 Stage::GetCurrent().Add(parent);
913 // Set child to completely cover parent.
914 // Change rotation of child to be different from parent so that we can check if our local coordinate
915 // conversion of the parent actor is correct.
916 Actor child = Actor::New();
917 child.SetSize(100.0f, 100.0f);
918 child.SetAnchorPoint(AnchorPoint::CENTER);
919 child.SetParentOrigin(ParentOrigin::CENTER);
920 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
923 TouchEventFunctor touchFunctor;
924 child.TouchedSignal().Connect(&application, touchFunctor);
927 application.SendNotification();
928 application.Render();
931 GestureReceivedFunctor functor(data);
933 PanGestureDetector detector = PanGestureDetector::New();
934 detector.Attach(parent);
935 detector.DetectedSignal().Connect(&application, functor);
937 // Do an entire pan, only check finished value - hits child area but parent should still receive it
938 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
939 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
941 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
942 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
943 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
944 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
946 // Attach child and generate same touch points to yield a different displacement
947 // (Also proves that you can detach and then re-attach another actor)
948 detector.Attach(child);
949 detector.Detach(parent);
951 // Do an entire pan, only check finished value
952 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
953 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
955 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
956 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
957 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
958 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
962 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
964 TestApplication application;
966 Actor first = Actor::New();
967 first.SetSize(100.0f, 100.0f);
968 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
969 Stage::GetCurrent().Add(first);
971 Actor second = Actor::New();
972 second.SetSize(100.0f, 100.0f);
974 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
975 Stage::GetCurrent().Add(second);
978 application.SendNotification();
979 application.Render();
982 GestureReceivedFunctor functor(data);
984 PanGestureDetector detector = PanGestureDetector::New();
985 detector.Attach(first);
986 detector.Attach(second);
987 detector.DetectedSignal().Connect(&application, functor);
989 // Start pan within second actor's area
990 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
991 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
992 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
993 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
995 // Pan moves into first actor's area - second actor should receive the pan
997 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
998 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
999 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1001 // Detach the second actor during the pan, we should not receive the next event
1002 detector.Detach(second);
1004 // Gesture ends within actor's area
1006 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1007 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1011 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1013 TestApplication application;
1015 Actor actor = Actor::New();
1016 actor.SetSize(100.0f, 100.0f);
1017 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1018 Stage::GetCurrent().Add(actor);
1020 // Render and notify
1021 application.SendNotification();
1022 application.Render();
1025 GestureReceivedFunctor functor(data);
1027 PanGestureDetector detector = PanGestureDetector::New();
1028 detector.Attach(actor);
1029 detector.DetectedSignal().Connect(&application, functor);
1031 // Start pan in actor's area
1032 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1033 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1034 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1036 // Pan continues within actor's area
1038 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1039 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1041 // Actor become invisible - actor should not receive the next pan
1042 actor.SetVisible(false);
1044 // Render and notify
1045 application.SendNotification();
1046 application.Render();
1048 // Gesture ends within actor's area
1050 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1051 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1055 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1057 TestApplication application;
1058 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1060 Actor first = Actor::New();
1061 first.SetSize(100.0f, 100.0f);
1062 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1063 Stage::GetCurrent().Add(first);
1065 Actor second = Actor::New();
1066 second.SetSize(100.0f, 100.0f);
1067 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1070 // Render and notify
1071 application.SendNotification();
1072 application.Render();
1075 GestureReceivedFunctor functor(data);
1077 PanGestureDetector firstDetector = PanGestureDetector::New();
1078 firstDetector.Attach(first);
1079 firstDetector.DetectedSignal().Connect(&application, functor);
1081 // secondDetector is scoped
1083 // Reset gestureManager statistics
1084 gestureManager.Initialize();
1086 PanGestureDetector secondDetector = PanGestureDetector::New();
1087 secondDetector.SetMinimumTouchesRequired(2);
1088 secondDetector.SetMaximumTouchesRequired(2);
1089 secondDetector.Attach(second);
1090 secondDetector.DetectedSignal().Connect(&application, functor);
1092 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1093 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1094 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1096 // Start pan within second actor's area
1097 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1098 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1099 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1100 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1102 // Two touch pan changes to single touch - we should receive a finished state
1104 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1105 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1106 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1107 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1109 // Pan continues as single touch gesture - we should not receive any gesture
1111 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1112 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1114 // Pan ends - still no signal
1116 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1117 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1119 // Single touch pan starts - first actor should be panned
1121 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1122 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1123 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1124 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1126 // Pan changes to double-touch - we should receive a finished state
1128 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1129 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1130 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1131 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1133 // Pan continues as double touch gesture - we should not receive any gesture
1135 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1136 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1138 // Pan ends - still no signal
1140 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1141 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1143 // Reset gesture manager statistics
1144 gestureManager.Initialize();
1147 // secondDetector has now been deleted. Gesture detection should have been updated only
1148 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1149 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1150 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1154 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1156 TestApplication application;
1158 Actor actor = Actor::New();
1159 actor.SetSize(100.0f, 100.0f);
1160 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1161 Stage::GetCurrent().Add(actor);
1163 Actor actor2 = Actor::New();
1164 actor2.SetSize(100.0f, 100.0f);
1165 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1166 Stage::GetCurrent().Add(actor2);
1168 // Render and notify
1169 application.SendNotification();
1170 application.Render();
1172 // Attach actor to one detector
1173 SignalData firstData;
1174 GestureReceivedFunctor firstFunctor(firstData);
1175 PanGestureDetector firstDetector = PanGestureDetector::New();
1176 firstDetector.Attach(actor);
1177 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1179 // Attach actor to another detector
1180 SignalData secondData;
1181 GestureReceivedFunctor secondFunctor(secondData);
1182 PanGestureDetector secondDetector = PanGestureDetector::New();
1183 secondDetector.Attach(actor);
1184 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1186 // Add second actor to second detector, when we remove the actor, this will make sure that this
1187 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1188 // functor should still not be called (which is what we're also testing).
1189 secondDetector.Attach(actor2);
1191 // Pan in actor's area - both detector's functors should be called
1192 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1193 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1194 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1195 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1197 // Pan continues in actor's area - both detector's functors should be called
1200 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1201 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1202 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1204 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1205 firstDetector.Detach(actor);
1208 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1209 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1210 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1212 // New pan on actor, only secondDetector has actor attached
1215 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1216 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1217 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1218 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1220 // Detach actor from secondDetector
1221 secondDetector.Detach(actor);
1224 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1225 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1226 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1230 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1232 // Should handle two started events gracefully.
1234 TestApplication application;
1236 Actor actor = Actor::New();
1237 actor.SetSize(100.0f, 100.0f);
1238 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1239 Stage::GetCurrent().Add(actor);
1242 GestureReceivedFunctor functor(data);
1244 PanGestureDetector detector = PanGestureDetector::New();
1245 detector.Attach(actor);
1246 detector.DetectedSignal().Connect(&application, functor);
1248 // Render and notify
1249 application.SendNotification();
1250 application.Render();
1252 // Start pan in actor's area
1253 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1254 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1255 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1257 // Send another start in actor's area
1259 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1260 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1262 // Add a child actor to overlap actor and send another start in actor's area
1263 Actor child = Actor::New();
1264 child.SetSize(100.0f, 100.0f);
1265 child.SetAnchorPoint(AnchorPoint::CENTER);
1266 child.SetParentOrigin(ParentOrigin::CENTER);
1269 TouchEventFunctor touchFunctor;
1270 child.TouchedSignal().Connect(&application, touchFunctor);
1272 // Render and notify
1273 application.SendNotification();
1274 application.Render();
1276 // Send another possible and start in actor's area
1278 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1279 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1280 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1282 // Send another start in actor's area
1284 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1285 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1286 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1290 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1292 TestApplication application;
1294 Actor actor1 = Actor::New();
1295 actor1.SetSize(100.0f, 100.0f);
1296 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1297 Stage::GetCurrent().Add(actor1);
1299 GestureReceivedFunctor functor1(data1);
1300 PanGestureDetector detector1 = PanGestureDetector::New();
1301 detector1.Attach(actor1);
1302 detector1.DetectedSignal().Connect(&application, functor1);
1304 Actor actor2 = Actor::New();
1305 actor2.SetSize(100.0f, 100.0f);
1306 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1307 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1308 Stage::GetCurrent().Add(actor2);
1310 GestureReceivedFunctor functor2(data2);
1311 PanGestureDetector detector2 = PanGestureDetector::New();
1312 detector2.Attach(actor2);
1313 detector2.DetectedSignal().Connect(&application, functor2);
1315 // Render and notify
1316 application.SendNotification();
1317 application.Render();
1319 // Start pan in actor1's area, only data1 should be set
1320 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1321 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1322 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1323 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1327 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1329 TestApplication application;
1331 Actor actor = Actor::New();
1332 actor.SetSize(100.0f, 100.0f);
1333 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1334 Stage::GetCurrent().Add(actor);
1336 // Render and notify
1337 application.SendNotification();
1338 application.Render();
1340 // Attach actor to detector
1342 GestureReceivedFunctor functor( data );
1343 PanGestureDetector detector = PanGestureDetector::New();
1344 detector.Attach(actor);
1345 detector.DetectedSignal().Connect( &application, functor );
1347 // Gesture possible in actor's area.
1348 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1349 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1351 // Move actor somewhere else
1352 actor.SetPosition( 100.0f, 100.0f );
1354 // Render and notify
1355 application.SendNotification();
1356 application.Render();
1358 // Emit Started event, we should not receive the long press.
1359 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1360 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1361 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1363 // LongPress possible in empty area.
1364 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1365 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1367 // Move actor in to the long press position.
1368 actor.SetPosition( 0.0f, 0.0f );
1370 // Render and notify
1371 application.SendNotification();
1372 application.Render();
1374 // Emit Started event, we should not receive the long press.
1375 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1376 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1377 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1379 // Normal long press in actor's area for completeness.
1380 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1381 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1382 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1383 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1387 int UtcDaliPanGestureEmitIncorrectState(void)
1389 TestApplication application;
1391 Actor actor = Actor::New();
1392 actor.SetSize(100.0f, 100.0f);
1393 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1394 Stage::GetCurrent().Add(actor);
1396 // Render and notify
1397 application.SendNotification();
1398 application.Render();
1400 // Attach actor to detector
1402 GestureReceivedFunctor functor( data );
1403 PanGestureDetector detector = PanGestureDetector::New();
1404 detector.Attach(actor);
1405 detector.DetectedSignal().Connect( &application, functor );
1407 // Try a Clear state
1410 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1411 tet_result(TET_FAIL);
1413 catch ( Dali::DaliException& e )
1415 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1420 int UtcDaliPanGestureActorUnstaged(void)
1422 TestApplication application;
1424 Actor actor = Actor::New();
1425 actor.SetSize(100.0f, 100.0f);
1426 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1427 Stage::GetCurrent().Add(actor);
1429 // Render and notify
1430 application.SendNotification();
1431 application.Render();
1433 // State to remove actor in.
1434 Gesture::State stateToUnstage( Gesture::Started );
1436 // Attach actor to detector
1438 UnstageActorFunctor functor( data, stateToUnstage );
1439 PanGestureDetector detector = PanGestureDetector::New();
1440 detector.Attach(actor);
1441 detector.DetectedSignal().Connect( &application, functor );
1444 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1445 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1446 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1448 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1449 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1452 // Render and notify
1453 application.SendNotification();
1454 application.Render();
1456 // Re-add actor to stage
1457 Stage::GetCurrent().Add(actor);
1459 // Render and notify
1460 application.SendNotification();
1461 application.Render();
1463 // Change state to Gesture::Continuing to remove
1464 stateToUnstage = Gesture::Continuing;
1467 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1468 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1469 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1471 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1472 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1474 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1475 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1478 // Render and notify
1479 application.SendNotification();
1480 application.Render();
1482 // Re-add actor to stage
1483 Stage::GetCurrent().Add(actor);
1485 // Render and notify
1486 application.SendNotification();
1487 application.Render();
1489 // Change state to Gesture::Finished to remove
1490 stateToUnstage = Gesture::Finished;
1493 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1494 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1495 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1497 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1498 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1500 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1501 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1502 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1506 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1508 TestApplication application;
1510 Actor actor = Actor::New();
1511 actor.SetSize(100.0f, 100.0f);
1512 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1513 Stage::GetCurrent().Add(actor);
1515 // Create and add a second actor so that GestureDetector destruction does not come into play.
1516 Actor dummyActor( Actor::New() );
1517 dummyActor.SetSize( 100.0f, 100.0f );
1518 dummyActor.SetPosition( 100.0f, 100.0f );
1519 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1520 Stage::GetCurrent().Add(dummyActor);
1522 // Render and notify
1523 application.SendNotification();
1524 application.Render();
1526 // State to remove actor in.
1527 Gesture::State stateToUnstage( Gesture::Started );
1529 // Attach actor to detector
1531 UnstageActorFunctor functor( data, stateToUnstage );
1532 PanGestureDetector detector = PanGestureDetector::New();
1533 detector.Attach(actor);
1534 detector.Attach(dummyActor);
1535 detector.DetectedSignal().Connect( &application, functor );
1537 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1538 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1539 // position, we should still not be signalled.
1542 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1543 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1544 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1547 // Render and notify
1548 application.SendNotification();
1549 application.Render();
1551 // Re add to the stage, we should not be signalled
1552 Stage::GetCurrent().Add(actor);
1554 // Render and notify
1555 application.SendNotification();
1556 application.Render();
1558 // Continue signal emission
1559 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1560 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1562 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1563 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1566 // Here we delete an actor in started, we should not receive any subsequent signalling.
1569 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1570 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1571 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1574 // Render and notify
1575 application.SendNotification();
1576 application.Render();
1578 // Delete actor as well
1581 // Render and notify
1582 application.SendNotification();
1583 application.Render();
1585 // Continue signal emission
1586 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1587 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1589 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1590 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1594 int UtcDaliPanGestureSystemOverlay(void)
1596 TestApplication application;
1597 Dali::Integration::Core& core = application.GetCore();
1598 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1599 systemOverlay.GetOverlayRenderTasks().CreateTask();
1601 Actor actor = Actor::New();
1602 actor.SetSize(100.0f, 100.0f);
1603 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1604 systemOverlay.Add(actor);
1606 // Render and notify
1607 application.SendNotification();
1608 application.Render();
1611 GestureReceivedFunctor functor(data);
1613 PanGestureDetector detector = PanGestureDetector::New();
1614 detector.Attach(actor);
1615 detector.DetectedSignal().Connect(&application, functor);
1617 Vector2 screenCoordsStart( 10.0f, 20.0f );
1618 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1620 // Start pan within the actor's area
1621 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1622 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1623 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1627 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1629 TestApplication application;
1630 Dali::Integration::Core& core = application.GetCore();
1631 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1632 systemOverlay.GetOverlayRenderTasks().CreateTask();
1634 // SystemOverlay actor
1635 Actor systemOverlayActor = Actor::New();
1636 systemOverlayActor.SetSize(100.0f, 100.0f);
1637 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1638 systemOverlay.Add(systemOverlayActor);
1641 Actor stageActor = Actor::New();
1642 stageActor.SetSize(100.0f, 100.0f);
1643 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1644 Stage::GetCurrent().Add(stageActor);
1646 // Render and notify
1647 application.SendNotification();
1648 application.Render();
1650 // Set system-overlay actor to touchable
1651 TouchEventData touchData;
1652 TouchEventDataFunctor touchFunctor( touchData );
1653 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1655 // Set stage actor to receive the gesture
1657 GestureReceivedFunctor functor(data);
1659 PanGestureDetector detector = PanGestureDetector::New();
1660 detector.Attach(stageActor);
1661 detector.DetectedSignal().Connect(&application, functor);
1663 Vector2 screenCoordsStart( 10.0f, 20.0f );
1664 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1666 // Start pan within the two actors' area
1667 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1668 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1669 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1670 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1671 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1676 // Do touch in the same area
1677 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoordsStart ) );
1678 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1679 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1684 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1686 TestApplication application;
1687 Dali::Integration::Core& core = application.GetCore();
1688 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1689 systemOverlay.GetOverlayRenderTasks().CreateTask();
1691 // SystemOverlay actor
1692 Actor systemOverlayActor = Actor::New();
1693 systemOverlayActor.SetSize(100.0f, 100.0f);
1694 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1695 systemOverlay.Add(systemOverlayActor);
1698 Actor stageActor = Actor::New();
1699 stageActor.SetSize(100.0f, 100.0f);
1700 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1701 Stage::GetCurrent().Add(stageActor);
1703 // Render and notify
1704 application.SendNotification();
1705 application.Render();
1707 // Set stage actor to touchable
1708 TouchEventData touchData;
1709 TouchEventDataFunctor touchFunctor( touchData );
1710 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1712 // Set system-overlay actor to have the gesture
1714 GestureReceivedFunctor functor(data);
1716 PanGestureDetector detector = PanGestureDetector::New();
1717 detector.Attach(systemOverlayActor);
1718 detector.DetectedSignal().Connect(&application, functor);
1720 Vector2 screenCoordsStart( 10.0f, 20.0f );
1721 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1723 // Start pan within the two actors' area
1724 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1725 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1726 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1727 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1728 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1733 // Do touch in the same area
1734 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoordsStart ) );
1735 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1736 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1741 int UtcDaliPanGestureAngleHandling(void)
1743 TestApplication application;
1745 PanGestureDetector detector = PanGestureDetector::New();
1746 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1748 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1749 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1751 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1753 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1755 tet_result( TET_PASS );
1763 tet_printf("%s, angle not added\n", TEST_LOCATION );
1764 tet_result( TET_FAIL );
1767 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1768 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1770 // Remove something not in the container.
1771 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1772 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1774 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1775 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1776 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1778 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1780 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1781 tet_result( TET_FAIL );
1786 detector.ClearAngles();
1787 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1791 int UtcDaliPanGestureGetAngle(void)
1793 TestApplication application;
1795 PanGestureDetector detector = PanGestureDetector::New();
1796 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1798 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1799 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1801 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1802 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1804 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1805 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1807 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1808 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1810 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1811 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1812 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1813 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1818 inline float RadiansToDegrees( float radian )
1820 return radian * 180.0f / Math::PI;
1823 int UtcDaliPanGestureAngleOutOfRange(void)
1825 TestApplication application;
1827 PanGestureDetector detector = PanGestureDetector::New();
1828 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1834 detector.AddAngle( Degree(180.0f) );
1835 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1836 detector.ClearAngles();
1838 detector.AddAngle( Degree(190.0f) );
1839 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1840 detector.ClearAngles();
1842 detector.AddAngle( Degree(-190.0f) );
1843 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1844 detector.ClearAngles();
1846 detector.AddAngle( Degree(350.0f) );
1847 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1848 detector.ClearAngles();
1850 detector.AddAngle( Degree(-350.0f) );
1851 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1852 detector.ClearAngles();
1854 detector.AddAngle( Degree(370.0f) );
1855 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1856 detector.ClearAngles();
1858 detector.AddAngle( Degree(-370.0f) );
1859 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1860 detector.ClearAngles();
1866 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1867 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1868 detector.ClearAngles();
1870 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1871 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1872 detector.ClearAngles();
1874 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1875 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1876 detector.ClearAngles();
1878 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1879 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1880 detector.ClearAngles();
1884 int UtcDaliPanGestureAngleProcessing(void)
1886 TestApplication application;
1888 Actor parent = Actor::New();
1889 parent.SetSize(100.0f, 100.0f);
1890 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1891 Stage::GetCurrent().Add(parent);
1893 Actor child = Actor::New();
1894 child.SetSize(100.0f, 100.0f);
1895 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1898 // Render and notify
1899 application.SendNotification();
1900 application.Render();
1902 // Parent detector only requires up pans
1903 PanGestureDetector parentDetector = PanGestureDetector::New();
1904 parentDetector.Attach( parent );
1905 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1906 SignalData parentData;
1907 GestureReceivedFunctor parentFunctor(parentData);
1908 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1910 // Child detector only requires right pans
1911 PanGestureDetector childDetector = PanGestureDetector::New();
1912 childDetector.Attach( child );
1913 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1914 SignalData childData;
1915 GestureReceivedFunctor childFunctor(childData);
1916 childDetector.DetectedSignal().Connect(&application, childFunctor);
1918 // Generate an Up pan gesture, only parent should receive it.
1919 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1920 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1921 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1922 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1923 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1927 // Generate a Right pan gesture, only child should receive it.
1928 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1929 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1930 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1931 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1932 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1936 // Generate a Down pan gesture, no one should receive it.
1937 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1938 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1939 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1940 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1941 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1945 // Generate a Left pan gesture, no one should receive it.
1946 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1947 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1948 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1949 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1950 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1956 int UtcDaliPanGestureDirectionHandling(void)
1958 TestApplication application;
1960 PanGestureDetector detector = PanGestureDetector::New();
1961 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1963 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1964 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1966 for ( size_t i = 0; detector.GetAngleCount(); i++)
1968 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1970 tet_result( TET_PASS );
1979 tet_printf("%s, angle not added\n", TEST_LOCATION );
1980 tet_result( TET_FAIL );
1984 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1986 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1988 tet_result( TET_PASS );
1996 tet_printf("%s, angle not added\n", TEST_LOCATION );
1997 tet_result( TET_FAIL );
2000 // Remove something not in the container.
2001 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
2002 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
2004 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
2005 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
2009 int UtcDaliPanGestureDirectionProcessing(void)
2011 TestApplication application;
2013 Actor parent = Actor::New();
2014 parent.SetSize(100.0f, 100.0f);
2015 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2016 Stage::GetCurrent().Add(parent);
2018 Actor child = Actor::New();
2019 child.SetSize(100.0f, 100.0f);
2020 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2023 // Render and notify
2024 application.SendNotification();
2025 application.Render();
2027 // Parent detector only requires vertical panning
2028 PanGestureDetector parentDetector = PanGestureDetector::New();
2029 parentDetector.Attach( parent );
2030 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
2031 SignalData parentData;
2032 GestureReceivedFunctor parentFunctor(parentData);
2033 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2035 // Child detector only requires horizontal panning
2036 PanGestureDetector childDetector = PanGestureDetector::New();
2037 childDetector.Attach( child );
2038 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2039 SignalData childData;
2040 GestureReceivedFunctor childFunctor(childData);
2041 childDetector.DetectedSignal().Connect(&application, childFunctor);
2043 // Generate an Up pan gesture, only parent should receive it.
2044 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2045 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
2046 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2047 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2048 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2052 // Generate a Right pan gesture, only child should receive it.
2053 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2054 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2055 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2056 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2057 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2061 // Generate a Down pan gesture, only parent should receive it.
2062 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2063 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2064 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2065 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2066 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2070 // Generate a Left pan gesture, only child should receive it.
2071 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2072 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2073 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2074 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2075 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2079 // Generate a pan at -45 degrees, no one should receive it.
2080 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2081 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2082 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2083 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2084 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2088 // Generate a pan at 45 degrees, no one should receive it.
2089 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2090 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2091 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2092 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2093 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2097 // Generate a pan at 135 degrees, no one should receive it.
2098 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2099 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2100 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2101 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2102 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2106 // Generate a pan at -135 degrees, no one should receive it.
2107 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2108 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2109 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2110 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2111 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2117 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2119 TestApplication application;
2120 Integration::SetPanGesturePredictionMode(0);
2121 Integration::SetPanGestureSmoothingMode(0);
2123 Actor actor = Actor::New();
2124 actor.SetSize(100.0f, 100.0f);
2125 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2126 Stage::GetCurrent().Add(actor);
2128 // Add a pan detector
2129 PanGestureDetector detector = PanGestureDetector::New();
2130 detector.Attach( actor );
2132 GestureReceivedFunctor functor( data );
2133 detector.DetectedSignal().Connect( &application, functor );
2135 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2137 ConstraintData constraintData;
2138 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2139 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2140 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2141 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2142 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2143 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2144 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2147 // Render and notify
2148 application.SendNotification();
2149 application.Render();
2151 Vector2 direction(Vector2::XAXIS * -5.0f);
2152 Vector2 startPosition( 1.0f, 1.0f );
2153 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2154 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2155 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2156 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2157 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2159 constraintData.Reset();
2163 int UtcDaliPanGestureNoPredictionSmoothing(void)
2165 TestApplication application;
2166 Integration::SetPanGesturePredictionMode(0);
2167 Integration::SetPanGestureSmoothingMode(1);
2169 Actor actor = Actor::New();
2170 actor.SetSize(100.0f, 100.0f);
2171 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2172 Stage::GetCurrent().Add(actor);
2174 // Add a pan detector
2175 PanGestureDetector detector = PanGestureDetector::New();
2176 detector.Attach( actor );
2178 GestureReceivedFunctor functor( data );
2179 detector.DetectedSignal().Connect( &application, functor );
2181 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2183 ConstraintData constraintData;
2184 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2185 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2186 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2187 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2188 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2189 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2190 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2193 // Render and notify
2194 application.SendNotification();
2195 application.Render();
2197 Vector2 direction(Vector2::XAXIS * -5.0f);
2198 Vector2 previousPosition( 20.0f, 20.0f );
2199 Vector2 currentPosition( 20.0f, 10.0f );
2200 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2201 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2202 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2203 // Take into account resampling done when prediction is off.
2204 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2205 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2207 constraintData.Reset();
2211 int UtcDaliPanGesturePredictionNoSmoothing(void)
2213 TestApplication application;
2214 Integration::SetPanGesturePredictionMode(1);
2215 Integration::SetPanGestureSmoothingMode(0);
2217 Actor actor = Actor::New();
2218 actor.SetSize(100.0f, 100.0f);
2219 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2220 Stage::GetCurrent().Add(actor);
2222 // Add a pan detector
2223 PanGestureDetector detector = PanGestureDetector::New();
2224 detector.Attach( actor );
2226 GestureReceivedFunctor functor( data );
2227 detector.DetectedSignal().Connect( &application, functor );
2229 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2231 ConstraintData constraintData;
2232 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2233 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2234 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2235 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2236 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2237 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2238 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2241 // Render and notify
2242 application.SendNotification();
2243 application.Render();
2245 Vector2 direction(Vector2::XAXIS * -1.0f);
2246 Vector2 previousPosition( 20.0f, 20.0f );
2247 Vector2 currentPosition( 20.0f, 10.0f );
2248 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2249 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2250 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2251 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2252 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2254 constraintData.Reset();
2258 int UtcDaliPanGesturePredictionSmoothing(void)
2260 TestApplication application;
2261 Integration::SetPanGesturePredictionMode(1);
2262 Integration::SetPanGestureSmoothingMode(1);
2264 Actor actor = Actor::New();
2265 actor.SetSize(100.0f, 100.0f);
2266 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2267 Stage::GetCurrent().Add(actor);
2269 // Add a pan detector
2270 PanGestureDetector detector = PanGestureDetector::New();
2271 detector.Attach( actor );
2273 GestureReceivedFunctor functor( data );
2274 detector.DetectedSignal().Connect( &application, functor );
2276 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2278 ConstraintData constraintData;
2279 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2280 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2281 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2282 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2283 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2284 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2285 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2288 // Render and notify
2289 application.SendNotification();
2290 application.Render();
2292 Vector2 direction(Vector2::XAXIS * -1.0f);
2293 Vector2 previousPosition( 20.0f, 20.0f );
2294 Vector2 currentPosition( 20.0f, 10.0f );
2295 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2296 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2297 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2298 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2299 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2301 constraintData.Reset();
2305 int UtcDaliPanGestureSetProperties(void)
2307 TestApplication application;
2308 TestRenderController& renderController( application.GetRenderController() );
2309 Integration::SetPanGesturePredictionMode(0);
2310 Integration::SetPanGestureSmoothingMode(0);
2312 Actor actor = Actor::New();
2313 actor.SetSize(100.0f, 100.0f);
2314 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2315 Stage::GetCurrent().Add(actor);
2317 // Add a pan detector
2318 PanGestureDetector detector = PanGestureDetector::New();
2319 detector.Attach( actor );
2321 GestureReceivedFunctor functor( data );
2322 detector.DetectedSignal().Connect( &application, functor );
2324 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2326 ConstraintData constraintData;
2327 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2328 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2329 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2330 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2331 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2332 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2333 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2336 // Render and notify
2337 application.SendNotification();
2338 application.Render();
2340 renderController.Initialize();
2341 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2343 Vector2 screenPosition( 20.0f, 20.0f );
2344 Vector2 screenDisplacement( 1.0f, 1.0f );
2345 Vector2 screenVelocity( 1.3f, 4.0f );
2346 Vector2 localPosition( 21.0f, 21.0f );
2347 Vector2 localDisplacement( 0.5f, 0.5f );
2348 Vector2 localVelocity( 1.5f, 2.5f );
2350 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2351 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2353 // Render and notify
2354 application.SendNotification();
2355 application.Render();
2357 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2358 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2359 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2360 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2361 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2362 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2363 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2364 constraintData.Reset();
2368 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2370 TestApplication application;
2371 Integration::SetPanGesturePredictionMode(0);
2373 Actor actor = Actor::New();
2374 actor.SetSize(100.0f, 100.0f);
2375 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2376 Stage::GetCurrent().Add(actor);
2378 // Add a pan detector
2379 PanGestureDetector detector = PanGestureDetector::New();
2380 detector.Attach( actor );
2382 GestureReceivedFunctor functor( data );
2383 detector.DetectedSignal().Connect( &application, functor );
2385 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2387 ConstraintData constraintData;
2388 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2389 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2390 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2391 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2392 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2393 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2394 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2397 // Render and notify
2398 application.SendNotification();
2399 application.Render();
2401 Vector2 previousPosition( 20.0f, 20.0f );
2402 Vector2 currentPosition( 20.0f, 10.0f );
2403 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2404 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2405 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2407 Vector2 screenPosition( 100.0f, 20.0f );
2408 Vector2 localPosition( 110.0f, 110.0f );
2410 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2412 // Render and notify
2413 application.SendNotification();
2414 application.Render();
2416 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2417 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2418 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2419 constraintData.Reset();
2423 int UtcDaliPanGesturePropertyIndices(void)
2425 TestApplication application;
2426 PanGestureDetector detector = PanGestureDetector::New();
2428 Property::IndexContainer indices;
2429 detector.GetPropertyIndices( indices );
2430 DALI_TEST_CHECK( indices.Size() );
2431 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2435 int UtcDaliPanGestureLayerConsumesTouch(void)
2437 TestApplication application;
2439 Actor actor = Actor::New();
2440 actor.SetSize(100.0f, 100.0f);
2441 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2442 Stage::GetCurrent().Add(actor);
2444 // Add a pan detector
2445 PanGestureDetector detector = PanGestureDetector::New();
2446 detector.Attach( actor );
2448 GestureReceivedFunctor functor( data );
2449 detector.DetectedSignal().Connect( &application, functor );
2451 // Add a layer to overlap the actor
2452 Layer layer = Layer::New();
2453 layer.SetSize(100.0f, 100.0f);
2454 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2455 Stage::GetCurrent().Add( layer );
2458 // Render and notify
2459 application.SendNotification();
2460 application.Render();
2462 // Emit signals, should receive
2463 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2464 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2465 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2466 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2469 // Set layer to consume all touch
2470 layer.SetTouchConsumed( true );
2472 // Render and notify
2473 application.SendNotification();
2474 application.Render();
2476 // Emit the same signals again, should not receive
2477 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2478 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2479 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2480 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2486 int UtcDaliPanGestureNoTimeDiff(void)
2488 TestApplication application;
2490 Actor actor = Actor::New();
2491 actor.SetSize(100.0f, 100.0f);
2492 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2493 Stage::GetCurrent().Add(actor);
2495 // Add a pan detector
2496 PanGestureDetector detector = PanGestureDetector::New();
2497 detector.Attach( actor );
2499 GestureReceivedFunctor functor( data );
2500 detector.DetectedSignal().Connect( &application, functor );
2502 // Render and notify
2503 application.SendNotification();
2504 application.Render();
2506 // Emit signals, should receive
2507 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2508 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2509 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2510 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2511 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2512 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2513 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2514 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );