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 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
340 touchEvent.AddPoint(point);
341 application.ProcessEvent(touchEvent);
345 int UtcDaliPanGestureDetectorDownCast(void)
347 TestApplication application;
348 tet_infoline("Testing Dali::GestureDetector::DownCast()");
350 PanGestureDetector detector = PanGestureDetector::New();
352 BaseHandle object(detector);
354 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
355 DALI_TEST_CHECK(detector2);
357 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
358 DALI_TEST_CHECK(detector3);
360 BaseHandle unInitializedObject;
361 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
362 DALI_TEST_CHECK(!detector4);
364 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
365 DALI_TEST_CHECK(!detector5);
367 GestureDetector detector6 = PanGestureDetector::New();
368 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
369 DALI_TEST_CHECK(detector7);
373 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
375 TestApplication application;
377 PanGestureDetector detector = PanGestureDetector::New();
379 unsigned int min = 2;
381 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
383 detector.SetMinimumTouchesRequired(min);
385 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
387 // Attach an actor and change the minimum touches
389 Actor actor = Actor::New();
390 actor.SetSize(100.0f, 100.0f);
391 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
392 Stage::GetCurrent().Add(actor);
395 application.SendNotification();
396 application.Render();
399 GestureReceivedFunctor functor(data);
401 detector.Attach(actor);
402 detector.DetectedSignal().Connect(&application, functor);
404 TestGestureManager& gestureManager = application.GetGestureManager();
405 gestureManager.Initialize();
407 detector.SetMinimumTouchesRequired(3);
409 // Gesture detection should have been updated only
410 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
411 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
412 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
415 gestureManager.Initialize();
417 // Create a second gesture detector that requires even less minimum touches
418 PanGestureDetector secondDetector = PanGestureDetector::New();
419 secondDetector.Attach(actor);
421 // Gesture detection should have been updated only
422 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
423 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
424 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
428 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
430 TestApplication application;
432 PanGestureDetector detector = PanGestureDetector::New();
434 unsigned int max = 3;
436 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
438 detector.SetMaximumTouchesRequired(max);
440 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
442 // Attach an actor and change the maximum touches
444 Actor actor = Actor::New();
445 actor.SetSize(100.0f, 100.0f);
446 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
447 Stage::GetCurrent().Add(actor);
450 application.SendNotification();
451 application.Render();
454 GestureReceivedFunctor functor(data);
456 detector.Attach(actor);
457 detector.DetectedSignal().Connect(&application, functor);
459 TestGestureManager& gestureManager = application.GetGestureManager();
460 gestureManager.Initialize();
462 detector.SetMaximumTouchesRequired(4);
464 // Gesture detection should have been updated only
465 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
466 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
467 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
470 gestureManager.Initialize();
472 // Create a second gesture detector that requires even less maximum touches
473 PanGestureDetector secondDetector = PanGestureDetector::New();
474 secondDetector.Attach(actor);
476 // Gesture detection should NOT have been updated
477 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
478 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
479 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
483 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
485 TestApplication application;
487 PanGestureDetector detector = PanGestureDetector::New();
488 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
492 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
494 TestApplication application;
496 PanGestureDetector detector = PanGestureDetector::New();
497 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
501 int UtcDaliPanGestureSignalReceptionNegative(void)
503 TestApplication application;
505 Actor actor = Actor::New();
506 actor.SetSize(100.0f, 100.0f);
507 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
508 Stage::GetCurrent().Add(actor);
511 application.SendNotification();
512 application.Render();
515 GestureReceivedFunctor functor(data);
517 PanGestureDetector detector = PanGestureDetector::New();
518 detector.Attach(actor);
519 detector.DetectedSignal().Connect(&application, functor);
521 // Do a pan outside actor's area
522 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
523 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
524 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
526 // Continue pan into actor's area - we should still not receive the signal
528 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
529 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
531 // Stop panning - we should still not receive the signal
533 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
534 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
538 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
540 TestApplication application;
542 Actor actor = Actor::New();
543 actor.SetSize(100.0f, 100.0f);
544 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
545 Stage::GetCurrent().Add(actor);
548 application.SendNotification();
549 application.Render();
552 GestureReceivedFunctor functor(data);
554 PanGestureDetector detector = PanGestureDetector::New();
555 detector.Attach(actor);
556 detector.DetectedSignal().Connect(&application, functor);
558 // Start pan within the actor's area
559 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
560 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
561 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
562 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
563 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
564 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
565 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
566 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
569 // Continue the pan within the actor's area - we should still receive the signal
571 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
572 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
573 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
574 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
575 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
576 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
577 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
578 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
580 // Pan Gesture leaves actor's area - we should still receive the signal
582 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
583 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
584 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
585 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
586 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
587 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
588 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
589 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
591 // Gesture ends - we would receive a finished state
593 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
594 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
595 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
596 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
597 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
598 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
599 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
600 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
604 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
606 TestApplication application;
608 Actor actor = Actor::New();
609 actor.SetSize(100.0f, 100.0f);
610 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
611 Stage::GetCurrent().Add(actor);
614 application.SendNotification();
615 application.Render();
618 GestureReceivedFunctor functor(data);
620 PanGestureDetector detector = PanGestureDetector::New();
621 detector.Attach(actor);
622 detector.DetectedSignal().Connect(&application, functor);
624 // Start pan within the actor's area
625 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
626 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
627 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
628 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
629 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
630 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
631 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
632 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
633 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
635 // Continue the pan within the actor's area - we should still receive the signal
637 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
638 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
639 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
640 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
641 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
642 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
643 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
644 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
646 // Gesture ends within actor's area - we would receive a finished state
648 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
649 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
650 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
651 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
652 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
653 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
654 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
655 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
659 int UtcDaliPanGestureSignalReceptionCancelled(void)
661 TestApplication application;
663 Actor actor = Actor::New();
664 actor.SetSize(100.0f, 100.0f);
665 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
666 Stage::GetCurrent().Add(actor);
669 application.SendNotification();
670 application.Render();
673 GestureReceivedFunctor functor(data);
675 PanGestureDetector detector = PanGestureDetector::New();
676 detector.Attach(actor);
677 detector.DetectedSignal().Connect(&application, functor);
679 // Start pan within the actor's area
680 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
681 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
682 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
683 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
685 // Continue the pan within the actor's area - we should still receive the signal
687 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
688 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
689 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
691 // The gesture is cancelled
693 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
694 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
695 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
699 int UtcDaliPanGestureSignalReceptionDetach(void)
701 TestApplication application;
703 Actor actor = Actor::New();
704 actor.SetSize(100.0f, 100.0f);
705 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
706 Stage::GetCurrent().Add(actor);
709 application.SendNotification();
710 application.Render();
713 GestureReceivedFunctor functor(data);
715 PanGestureDetector detector = PanGestureDetector::New();
716 detector.Attach(actor);
717 detector.DetectedSignal().Connect(&application, functor);
719 // Start pan within the actor's area
720 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
721 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
722 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
724 // Continue the pan within the actor's area - we should still receive the signal
726 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
727 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
729 // Gesture ends within actor's area
731 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
732 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
735 detector.DetachAll();
737 // Ensure we are no longer signalled
739 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
740 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
741 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
742 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
743 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
747 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
749 TestApplication application;
751 Actor actor = Actor::New();
752 actor.SetSize(100.0f, 100.0f);
753 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
754 Stage::GetCurrent().Add(actor);
757 application.SendNotification();
758 application.Render();
761 GestureReceivedFunctor functor(data);
763 PanGestureDetector detector = PanGestureDetector::New();
764 detector.Attach(actor);
765 detector.DetectedSignal().Connect(&application, functor);
767 // Start pan within the actor's area
768 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
769 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
770 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
772 // Continue the pan within the actor's area - we should still receive the signal
774 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
775 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
777 // Detach actor during the pan, we should not receive the next event
778 detector.DetachAll();
780 // Gesture ends within actor's area
782 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
783 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
787 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
789 TestApplication application;
792 GestureReceivedFunctor functor(data);
794 PanGestureDetector detector = PanGestureDetector::New();
795 detector.DetectedSignal().Connect(&application, functor);
797 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
799 Actor tempActor = Actor::New();
800 tempActor.SetSize(100.0f, 100.0f);
801 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
802 Stage::GetCurrent().Add(tempActor);
803 detector.Attach(tempActor);
805 // Actor lifetime is scoped
807 Actor actor = Actor::New();
808 actor.SetSize(100.0f, 100.0f);
809 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
810 Stage::GetCurrent().Add(actor);
813 application.SendNotification();
814 application.Render();
816 detector.Attach(actor);
818 // Start pan within the actor's area
819 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
820 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
821 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
823 // Continue the pan within the actor's area - we should still receive the signal
825 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
826 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
828 // Remove the actor from stage and reset the data
829 Stage::GetCurrent().Remove(actor);
832 application.SendNotification();
833 application.Render();
836 // Actor should now have been destroyed
838 // Gesture ends within the area where the actor used to be
840 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
841 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
845 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
847 TestApplication application;
849 Actor actor = Actor::New();
850 actor.SetSize(100.0f, 100.0f);
851 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
852 Stage::GetCurrent().Add(actor);
855 application.SendNotification();
856 application.Render();
859 GestureReceivedFunctor functor(data);
861 PanGestureDetector detector = PanGestureDetector::New();
862 detector.Attach(actor);
863 detector.DetectedSignal().Connect(&application, functor);
865 // Do an entire pan, only check finished value
866 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
867 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
869 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
870 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
871 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
873 // Rotate actor again and render a couple of times
874 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
875 application.SendNotification();
876 application.Render();
878 // Do an entire pan, only check finished value
879 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
880 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
882 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
883 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
884 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
886 // Rotate actor again and render a couple of times
887 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
888 application.SendNotification();
889 application.Render();
891 // Do an entire pan, only check finished value
892 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
893 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
895 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
896 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
897 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
901 int UtcDaliPanGestureSignalReceptionChildHit(void)
903 TestApplication application;
905 Actor parent = Actor::New();
906 parent.SetSize(100.0f, 100.0f);
907 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
908 Stage::GetCurrent().Add(parent);
910 // Set child to completely cover parent.
911 // Change rotation of child to be different from parent so that we can check if our local coordinate
912 // conversion of the parent actor is correct.
913 Actor child = Actor::New();
914 child.SetSize(100.0f, 100.0f);
915 child.SetAnchorPoint(AnchorPoint::CENTER);
916 child.SetParentOrigin(ParentOrigin::CENTER);
917 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
920 TouchEventFunctor touchFunctor;
921 child.TouchedSignal().Connect(&application, touchFunctor);
924 application.SendNotification();
925 application.Render();
928 GestureReceivedFunctor functor(data);
930 PanGestureDetector detector = PanGestureDetector::New();
931 detector.Attach(parent);
932 detector.DetectedSignal().Connect(&application, functor);
934 // Do an entire pan, only check finished value - hits child area but parent should still receive it
935 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
936 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
938 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
939 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
940 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
941 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
943 // Attach child and generate same touch points to yield a different displacement
944 // (Also proves that you can detach and then re-attach another actor)
945 detector.Attach(child);
946 detector.Detach(parent);
948 // Do an entire pan, only check finished value
949 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
950 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
952 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
953 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
954 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
955 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
959 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
961 TestApplication application;
963 Actor first = Actor::New();
964 first.SetSize(100.0f, 100.0f);
965 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
966 Stage::GetCurrent().Add(first);
968 Actor second = Actor::New();
969 second.SetSize(100.0f, 100.0f);
971 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
972 Stage::GetCurrent().Add(second);
975 application.SendNotification();
976 application.Render();
979 GestureReceivedFunctor functor(data);
981 PanGestureDetector detector = PanGestureDetector::New();
982 detector.Attach(first);
983 detector.Attach(second);
984 detector.DetectedSignal().Connect(&application, functor);
986 // Start pan within second actor's area
987 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
988 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
989 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
990 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
992 // Pan moves into first actor's area - second actor should receive the pan
994 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
995 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
996 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
998 // Detach the second actor during the pan, we should not receive the next event
999 detector.Detach(second);
1001 // Gesture ends within actor's area
1003 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1004 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1008 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1010 TestApplication application;
1012 Actor actor = Actor::New();
1013 actor.SetSize(100.0f, 100.0f);
1014 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1015 Stage::GetCurrent().Add(actor);
1017 // Render and notify
1018 application.SendNotification();
1019 application.Render();
1022 GestureReceivedFunctor functor(data);
1024 PanGestureDetector detector = PanGestureDetector::New();
1025 detector.Attach(actor);
1026 detector.DetectedSignal().Connect(&application, functor);
1028 // Start pan in actor's area
1029 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1030 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1031 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1033 // Pan continues within actor's area
1035 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1036 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1038 // Actor become invisible - actor should not receive the next pan
1039 actor.SetVisible(false);
1041 // Render and notify
1042 application.SendNotification();
1043 application.Render();
1045 // Gesture ends within actor's area
1047 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1048 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1052 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1054 TestApplication application;
1055 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1057 Actor first = Actor::New();
1058 first.SetSize(100.0f, 100.0f);
1059 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1060 Stage::GetCurrent().Add(first);
1062 Actor second = Actor::New();
1063 second.SetSize(100.0f, 100.0f);
1064 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1067 // Render and notify
1068 application.SendNotification();
1069 application.Render();
1072 GestureReceivedFunctor functor(data);
1074 PanGestureDetector firstDetector = PanGestureDetector::New();
1075 firstDetector.Attach(first);
1076 firstDetector.DetectedSignal().Connect(&application, functor);
1078 // secondDetector is scoped
1080 // Reset gestureManager statistics
1081 gestureManager.Initialize();
1083 PanGestureDetector secondDetector = PanGestureDetector::New();
1084 secondDetector.SetMinimumTouchesRequired(2);
1085 secondDetector.SetMaximumTouchesRequired(2);
1086 secondDetector.Attach(second);
1087 secondDetector.DetectedSignal().Connect(&application, functor);
1089 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1090 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1091 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1093 // Start pan within second actor's area
1094 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1095 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1096 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1097 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1099 // Two touch pan changes to single touch - we should receive a finished state
1101 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1102 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1103 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1104 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1106 // Pan continues as single touch gesture - we should not receive any gesture
1108 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1109 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1111 // Pan ends - still no signal
1113 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1114 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1116 // Single touch pan starts - first actor should be panned
1118 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1119 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1120 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1121 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1123 // Pan changes to double-touch - we should receive a finished state
1125 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1126 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1127 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1128 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1130 // Pan continues as double touch gesture - we should not receive any gesture
1132 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1133 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1135 // Pan ends - still no signal
1137 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1138 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1140 // Reset gesture manager statistics
1141 gestureManager.Initialize();
1144 // secondDetector has now been deleted. Gesture detection should have been updated only
1145 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1146 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1147 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1151 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1153 TestApplication application;
1155 Actor actor = Actor::New();
1156 actor.SetSize(100.0f, 100.0f);
1157 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1158 Stage::GetCurrent().Add(actor);
1160 Actor actor2 = Actor::New();
1161 actor2.SetSize(100.0f, 100.0f);
1162 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1163 Stage::GetCurrent().Add(actor2);
1165 // Render and notify
1166 application.SendNotification();
1167 application.Render();
1169 // Attach actor to one detector
1170 SignalData firstData;
1171 GestureReceivedFunctor firstFunctor(firstData);
1172 PanGestureDetector firstDetector = PanGestureDetector::New();
1173 firstDetector.Attach(actor);
1174 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1176 // Attach actor to another detector
1177 SignalData secondData;
1178 GestureReceivedFunctor secondFunctor(secondData);
1179 PanGestureDetector secondDetector = PanGestureDetector::New();
1180 secondDetector.Attach(actor);
1181 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1183 // Add second actor to second detector, when we remove the actor, this will make sure that this
1184 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1185 // functor should still not be called (which is what we're also testing).
1186 secondDetector.Attach(actor2);
1188 // Pan in actor's area - both detector's functors should be called
1189 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1190 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1191 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1192 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1194 // Pan continues in actor's area - both detector's functors should be called
1197 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1198 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1199 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1201 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1202 firstDetector.Detach(actor);
1205 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1206 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1207 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1209 // New pan on actor, only secondDetector has actor attached
1212 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1213 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1214 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1215 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1217 // Detach actor from secondDetector
1218 secondDetector.Detach(actor);
1221 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1222 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1223 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1227 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1229 // Should handle two started events gracefully.
1231 TestApplication application;
1233 Actor actor = Actor::New();
1234 actor.SetSize(100.0f, 100.0f);
1235 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1236 Stage::GetCurrent().Add(actor);
1239 GestureReceivedFunctor functor(data);
1241 PanGestureDetector detector = PanGestureDetector::New();
1242 detector.Attach(actor);
1243 detector.DetectedSignal().Connect(&application, functor);
1245 // Render and notify
1246 application.SendNotification();
1247 application.Render();
1249 // Start pan in actor's area
1250 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1251 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1252 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1254 // Send another start in actor's area
1256 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1257 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1259 // Add a child actor to overlap actor and send another start in actor's area
1260 Actor child = Actor::New();
1261 child.SetSize(100.0f, 100.0f);
1262 child.SetAnchorPoint(AnchorPoint::CENTER);
1263 child.SetParentOrigin(ParentOrigin::CENTER);
1266 TouchEventFunctor touchFunctor;
1267 child.TouchedSignal().Connect(&application, touchFunctor);
1269 // Render and notify
1270 application.SendNotification();
1271 application.Render();
1273 // Send another possible and start in actor's area
1275 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1276 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1277 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1279 // Send another start in actor's area
1281 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1282 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1283 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1287 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1289 TestApplication application;
1291 Actor actor1 = Actor::New();
1292 actor1.SetSize(100.0f, 100.0f);
1293 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1294 Stage::GetCurrent().Add(actor1);
1296 GestureReceivedFunctor functor1(data1);
1297 PanGestureDetector detector1 = PanGestureDetector::New();
1298 detector1.Attach(actor1);
1299 detector1.DetectedSignal().Connect(&application, functor1);
1301 Actor actor2 = Actor::New();
1302 actor2.SetSize(100.0f, 100.0f);
1303 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1304 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1305 Stage::GetCurrent().Add(actor2);
1307 GestureReceivedFunctor functor2(data2);
1308 PanGestureDetector detector2 = PanGestureDetector::New();
1309 detector2.Attach(actor2);
1310 detector2.DetectedSignal().Connect(&application, functor2);
1312 // Render and notify
1313 application.SendNotification();
1314 application.Render();
1316 // Start pan in actor1's area, only data1 should be set
1317 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1318 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1319 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1320 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1324 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1326 TestApplication application;
1328 Actor actor = Actor::New();
1329 actor.SetSize(100.0f, 100.0f);
1330 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1331 Stage::GetCurrent().Add(actor);
1333 // Render and notify
1334 application.SendNotification();
1335 application.Render();
1337 // Attach actor to detector
1339 GestureReceivedFunctor functor( data );
1340 PanGestureDetector detector = PanGestureDetector::New();
1341 detector.Attach(actor);
1342 detector.DetectedSignal().Connect( &application, functor );
1344 // Gesture possible in actor's area.
1345 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1346 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1348 // Move actor somewhere else
1349 actor.SetPosition( 100.0f, 100.0f );
1351 // Render and notify
1352 application.SendNotification();
1353 application.Render();
1355 // Emit Started event, we should not receive the long press.
1356 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1357 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1358 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1360 // LongPress possible in empty area.
1361 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1362 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1364 // Move actor in to the long press position.
1365 actor.SetPosition( 0.0f, 0.0f );
1367 // Render and notify
1368 application.SendNotification();
1369 application.Render();
1371 // Emit Started event, we should not receive the long press.
1372 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1373 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1374 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1376 // Normal long press in actor's area for completeness.
1377 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1378 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1379 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1380 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1384 int UtcDaliPanGestureEmitIncorrectState(void)
1386 TestApplication application;
1388 Actor actor = Actor::New();
1389 actor.SetSize(100.0f, 100.0f);
1390 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1391 Stage::GetCurrent().Add(actor);
1393 // Render and notify
1394 application.SendNotification();
1395 application.Render();
1397 // Attach actor to detector
1399 GestureReceivedFunctor functor( data );
1400 PanGestureDetector detector = PanGestureDetector::New();
1401 detector.Attach(actor);
1402 detector.DetectedSignal().Connect( &application, functor );
1404 // Try a Clear state
1407 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1408 tet_result(TET_FAIL);
1410 catch ( Dali::DaliException& e )
1412 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1417 int UtcDaliPanGestureActorUnstaged(void)
1419 TestApplication application;
1421 Actor actor = Actor::New();
1422 actor.SetSize(100.0f, 100.0f);
1423 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1424 Stage::GetCurrent().Add(actor);
1426 // Render and notify
1427 application.SendNotification();
1428 application.Render();
1430 // State to remove actor in.
1431 Gesture::State stateToUnstage( Gesture::Started );
1433 // Attach actor to detector
1435 UnstageActorFunctor functor( data, stateToUnstage );
1436 PanGestureDetector detector = PanGestureDetector::New();
1437 detector.Attach(actor);
1438 detector.DetectedSignal().Connect( &application, functor );
1441 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1442 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1443 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1445 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1446 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1449 // Render and notify
1450 application.SendNotification();
1451 application.Render();
1453 // Re-add actor to stage
1454 Stage::GetCurrent().Add(actor);
1456 // Render and notify
1457 application.SendNotification();
1458 application.Render();
1460 // Change state to Gesture::Continuing to remove
1461 stateToUnstage = Gesture::Continuing;
1464 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1465 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1466 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1468 application.ProcessEvent(GeneratePan(Gesture::Continuing, 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::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1472 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1475 // Render and notify
1476 application.SendNotification();
1477 application.Render();
1479 // Re-add actor to stage
1480 Stage::GetCurrent().Add(actor);
1482 // Render and notify
1483 application.SendNotification();
1484 application.Render();
1486 // Change state to Gesture::Finished to remove
1487 stateToUnstage = Gesture::Finished;
1490 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1491 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1492 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1494 application.ProcessEvent(GeneratePan(Gesture::Continuing, 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::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1498 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1499 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1503 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1505 TestApplication application;
1507 Actor actor = Actor::New();
1508 actor.SetSize(100.0f, 100.0f);
1509 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1510 Stage::GetCurrent().Add(actor);
1512 // Create and add a second actor so that GestureDetector destruction does not come into play.
1513 Actor dummyActor( Actor::New() );
1514 dummyActor.SetSize( 100.0f, 100.0f );
1515 dummyActor.SetPosition( 100.0f, 100.0f );
1516 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1517 Stage::GetCurrent().Add(dummyActor);
1519 // Render and notify
1520 application.SendNotification();
1521 application.Render();
1523 // State to remove actor in.
1524 Gesture::State stateToUnstage( Gesture::Started );
1526 // Attach actor to detector
1528 UnstageActorFunctor functor( data, stateToUnstage );
1529 PanGestureDetector detector = PanGestureDetector::New();
1530 detector.Attach(actor);
1531 detector.Attach(dummyActor);
1532 detector.DetectedSignal().Connect( &application, functor );
1534 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1535 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1536 // position, we should still not be signalled.
1539 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1540 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1541 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1544 // Render and notify
1545 application.SendNotification();
1546 application.Render();
1548 // Re add to the stage, we should not be signalled
1549 Stage::GetCurrent().Add(actor);
1551 // Render and notify
1552 application.SendNotification();
1553 application.Render();
1555 // Continue signal emission
1556 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1557 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1559 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1560 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1563 // Here we delete an actor in started, we should not receive any subsequent signalling.
1566 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1567 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1568 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1571 // Render and notify
1572 application.SendNotification();
1573 application.Render();
1575 // Delete actor as well
1578 // Render and notify
1579 application.SendNotification();
1580 application.Render();
1582 // Continue signal emission
1583 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1584 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1586 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1587 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1591 int UtcDaliPanGestureSystemOverlay(void)
1593 TestApplication application;
1594 Dali::Integration::Core& core = application.GetCore();
1595 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1596 systemOverlay.GetOverlayRenderTasks().CreateTask();
1598 Actor actor = Actor::New();
1599 actor.SetSize(100.0f, 100.0f);
1600 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1601 systemOverlay.Add(actor);
1603 // Render and notify
1604 application.SendNotification();
1605 application.Render();
1608 GestureReceivedFunctor functor(data);
1610 PanGestureDetector detector = PanGestureDetector::New();
1611 detector.Attach(actor);
1612 detector.DetectedSignal().Connect(&application, functor);
1614 Vector2 screenCoordsStart( 10.0f, 20.0f );
1615 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1617 // Start pan within the actor's area
1618 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1619 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1620 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1624 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1626 TestApplication application;
1627 Dali::Integration::Core& core = application.GetCore();
1628 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1629 systemOverlay.GetOverlayRenderTasks().CreateTask();
1631 // SystemOverlay actor
1632 Actor systemOverlayActor = Actor::New();
1633 systemOverlayActor.SetSize(100.0f, 100.0f);
1634 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1635 systemOverlay.Add(systemOverlayActor);
1638 Actor stageActor = Actor::New();
1639 stageActor.SetSize(100.0f, 100.0f);
1640 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1641 Stage::GetCurrent().Add(stageActor);
1643 // Render and notify
1644 application.SendNotification();
1645 application.Render();
1647 // Set system-overlay actor to touchable
1648 TouchEventData touchData;
1649 TouchEventDataFunctor touchFunctor( touchData );
1650 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1652 // Set stage actor to receive the gesture
1654 GestureReceivedFunctor functor(data);
1656 PanGestureDetector detector = PanGestureDetector::New();
1657 detector.Attach(stageActor);
1658 detector.DetectedSignal().Connect(&application, functor);
1660 Vector2 screenCoordsStart( 10.0f, 20.0f );
1661 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1663 // Start pan within the two actors' area
1664 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1665 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1666 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1667 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1668 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1673 // Do touch in the same area
1674 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1675 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1676 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1681 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1683 TestApplication application;
1684 Dali::Integration::Core& core = application.GetCore();
1685 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1686 systemOverlay.GetOverlayRenderTasks().CreateTask();
1688 // SystemOverlay actor
1689 Actor systemOverlayActor = Actor::New();
1690 systemOverlayActor.SetSize(100.0f, 100.0f);
1691 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1692 systemOverlay.Add(systemOverlayActor);
1695 Actor stageActor = Actor::New();
1696 stageActor.SetSize(100.0f, 100.0f);
1697 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1698 Stage::GetCurrent().Add(stageActor);
1700 // Render and notify
1701 application.SendNotification();
1702 application.Render();
1704 // Set stage actor to touchable
1705 TouchEventData touchData;
1706 TouchEventDataFunctor touchFunctor( touchData );
1707 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1709 // Set system-overlay actor to have the gesture
1711 GestureReceivedFunctor functor(data);
1713 PanGestureDetector detector = PanGestureDetector::New();
1714 detector.Attach(systemOverlayActor);
1715 detector.DetectedSignal().Connect(&application, functor);
1717 Vector2 screenCoordsStart( 10.0f, 20.0f );
1718 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1720 // Start pan within the two actors' area
1721 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1722 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1723 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1724 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1725 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1730 // Do touch in the same area
1731 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1732 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1733 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1738 int UtcDaliPanGestureAngleHandling(void)
1740 TestApplication application;
1742 PanGestureDetector detector = PanGestureDetector::New();
1743 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1745 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1746 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1748 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1750 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1752 tet_result( TET_PASS );
1760 tet_printf("%s, angle not added\n", TEST_LOCATION );
1761 tet_result( TET_FAIL );
1764 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1765 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1767 // Remove something not in the container.
1768 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1769 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1771 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1772 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1773 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1775 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1777 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1778 tet_result( TET_FAIL );
1783 detector.ClearAngles();
1784 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1788 int UtcDaliPanGestureGetAngle(void)
1790 TestApplication application;
1792 PanGestureDetector detector = PanGestureDetector::New();
1793 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1795 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1796 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1798 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1799 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1801 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1802 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1804 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1805 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1807 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1808 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1809 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1810 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1815 inline float RadiansToDegrees( float radian )
1817 return radian * 180.0f / Math::PI;
1820 int UtcDaliPanGestureAngleOutOfRange(void)
1822 TestApplication application;
1824 PanGestureDetector detector = PanGestureDetector::New();
1825 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1831 detector.AddAngle( Degree(180.0f) );
1832 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1833 detector.ClearAngles();
1835 detector.AddAngle( Degree(190.0f) );
1836 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1837 detector.ClearAngles();
1839 detector.AddAngle( Degree(-190.0f) );
1840 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1841 detector.ClearAngles();
1843 detector.AddAngle( Degree(350.0f) );
1844 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1845 detector.ClearAngles();
1847 detector.AddAngle( Degree(-350.0f) );
1848 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1849 detector.ClearAngles();
1851 detector.AddAngle( Degree(370.0f) );
1852 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1853 detector.ClearAngles();
1855 detector.AddAngle( Degree(-370.0f) );
1856 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1857 detector.ClearAngles();
1863 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1864 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1865 detector.ClearAngles();
1867 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1868 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1869 detector.ClearAngles();
1871 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1872 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1873 detector.ClearAngles();
1875 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1876 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1877 detector.ClearAngles();
1881 int UtcDaliPanGestureAngleProcessing(void)
1883 TestApplication application;
1885 Actor parent = Actor::New();
1886 parent.SetSize(100.0f, 100.0f);
1887 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1888 Stage::GetCurrent().Add(parent);
1890 Actor child = Actor::New();
1891 child.SetSize(100.0f, 100.0f);
1892 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1895 // Render and notify
1896 application.SendNotification();
1897 application.Render();
1899 // Parent detector only requires up pans
1900 PanGestureDetector parentDetector = PanGestureDetector::New();
1901 parentDetector.Attach( parent );
1902 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1903 SignalData parentData;
1904 GestureReceivedFunctor parentFunctor(parentData);
1905 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1907 // Child detector only requires right pans
1908 PanGestureDetector childDetector = PanGestureDetector::New();
1909 childDetector.Attach( child );
1910 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1911 SignalData childData;
1912 GestureReceivedFunctor childFunctor(childData);
1913 childDetector.DetectedSignal().Connect(&application, childFunctor);
1915 // Generate an Up pan gesture, only parent should receive it.
1916 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1917 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1918 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1919 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1920 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1924 // Generate a Right pan gesture, only child should receive it.
1925 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1926 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1927 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1928 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1929 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1933 // Generate a Down pan gesture, no one should receive it.
1934 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1935 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1936 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1937 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1938 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1942 // Generate a Left pan gesture, no one should receive it.
1943 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1944 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1945 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1946 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1947 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1953 int UtcDaliPanGestureDirectionHandling(void)
1955 TestApplication application;
1957 PanGestureDetector detector = PanGestureDetector::New();
1958 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1960 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1961 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1963 for ( size_t i = 0; detector.GetAngleCount(); i++)
1965 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1967 tet_result( TET_PASS );
1976 tet_printf("%s, angle not added\n", TEST_LOCATION );
1977 tet_result( TET_FAIL );
1981 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1983 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1985 tet_result( TET_PASS );
1993 tet_printf("%s, angle not added\n", TEST_LOCATION );
1994 tet_result( TET_FAIL );
1997 // Remove something not in the container.
1998 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1999 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
2001 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
2002 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
2006 int UtcDaliPanGestureDirectionProcessing(void)
2008 TestApplication application;
2010 Actor parent = Actor::New();
2011 parent.SetSize(100.0f, 100.0f);
2012 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2013 Stage::GetCurrent().Add(parent);
2015 Actor child = Actor::New();
2016 child.SetSize(100.0f, 100.0f);
2017 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2020 // Render and notify
2021 application.SendNotification();
2022 application.Render();
2024 // Parent detector only requires vertical panning
2025 PanGestureDetector parentDetector = PanGestureDetector::New();
2026 parentDetector.Attach( parent );
2027 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
2028 SignalData parentData;
2029 GestureReceivedFunctor parentFunctor(parentData);
2030 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2032 // Child detector only requires horizontal panning
2033 PanGestureDetector childDetector = PanGestureDetector::New();
2034 childDetector.Attach( child );
2035 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2036 SignalData childData;
2037 GestureReceivedFunctor childFunctor(childData);
2038 childDetector.DetectedSignal().Connect(&application, childFunctor);
2040 // Generate an Up pan gesture, only parent should receive it.
2041 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2042 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
2043 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2044 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2045 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2049 // Generate a Right pan gesture, only child should receive it.
2050 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2051 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2052 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2053 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2054 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2058 // Generate a Down pan gesture, only parent should receive it.
2059 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2060 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2061 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2062 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2063 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2067 // Generate a Left pan gesture, only child should receive it.
2068 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2069 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2070 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2071 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2072 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2076 // Generate a pan at -45 degrees, no one should receive it.
2077 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2078 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2079 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2080 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2081 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2085 // Generate a pan at 45 degrees, no one should receive it.
2086 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2087 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2088 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2089 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2090 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2094 // Generate a pan at 135 degrees, no one should receive it.
2095 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2096 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2097 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2098 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2099 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2103 // Generate a pan at -135 degrees, no one should receive it.
2104 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2105 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2106 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2107 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2108 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2114 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2116 TestApplication application;
2117 Integration::SetPanGesturePredictionMode(0);
2118 Integration::SetPanGestureSmoothingMode(0);
2120 Actor actor = Actor::New();
2121 actor.SetSize(100.0f, 100.0f);
2122 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2123 Stage::GetCurrent().Add(actor);
2125 // Add a pan detector
2126 PanGestureDetector detector = PanGestureDetector::New();
2127 detector.Attach( actor );
2129 GestureReceivedFunctor functor( data );
2130 detector.DetectedSignal().Connect( &application, functor );
2132 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2134 ConstraintData constraintData;
2135 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2136 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2137 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2138 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2139 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2140 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2141 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2144 // Render and notify
2145 application.SendNotification();
2146 application.Render();
2148 Vector2 direction(Vector2::XAXIS * -5.0f);
2149 Vector2 startPosition( 1.0f, 1.0f );
2150 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2151 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2152 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2153 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2154 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2156 constraintData.Reset();
2160 int UtcDaliPanGestureNoPredictionSmoothing(void)
2162 TestApplication application;
2163 Integration::SetPanGesturePredictionMode(0);
2164 Integration::SetPanGestureSmoothingMode(1);
2166 Actor actor = Actor::New();
2167 actor.SetSize(100.0f, 100.0f);
2168 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2169 Stage::GetCurrent().Add(actor);
2171 // Add a pan detector
2172 PanGestureDetector detector = PanGestureDetector::New();
2173 detector.Attach( actor );
2175 GestureReceivedFunctor functor( data );
2176 detector.DetectedSignal().Connect( &application, functor );
2178 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2180 ConstraintData constraintData;
2181 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2182 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2183 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2184 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2185 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2186 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2187 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2190 // Render and notify
2191 application.SendNotification();
2192 application.Render();
2194 Vector2 direction(Vector2::XAXIS * -5.0f);
2195 Vector2 previousPosition( 20.0f, 20.0f );
2196 Vector2 currentPosition( 20.0f, 10.0f );
2197 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2198 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2199 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2200 // Take into account resampling done when prediction is off.
2201 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2202 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2204 constraintData.Reset();
2208 int UtcDaliPanGesturePredictionNoSmoothing(void)
2210 TestApplication application;
2211 Integration::SetPanGesturePredictionMode(1);
2212 Integration::SetPanGestureSmoothingMode(0);
2214 Actor actor = Actor::New();
2215 actor.SetSize(100.0f, 100.0f);
2216 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2217 Stage::GetCurrent().Add(actor);
2219 // Add a pan detector
2220 PanGestureDetector detector = PanGestureDetector::New();
2221 detector.Attach( actor );
2223 GestureReceivedFunctor functor( data );
2224 detector.DetectedSignal().Connect( &application, functor );
2226 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2228 ConstraintData constraintData;
2229 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2230 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2231 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2232 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2233 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2234 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2235 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2238 // Render and notify
2239 application.SendNotification();
2240 application.Render();
2242 Vector2 direction(Vector2::XAXIS * -1.0f);
2243 Vector2 previousPosition( 20.0f, 20.0f );
2244 Vector2 currentPosition( 20.0f, 10.0f );
2245 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2246 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2247 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2248 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2249 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2251 constraintData.Reset();
2255 int UtcDaliPanGesturePredictionSmoothing(void)
2257 TestApplication application;
2258 Integration::SetPanGesturePredictionMode(1);
2259 Integration::SetPanGestureSmoothingMode(1);
2261 Actor actor = Actor::New();
2262 actor.SetSize(100.0f, 100.0f);
2263 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2264 Stage::GetCurrent().Add(actor);
2266 // Add a pan detector
2267 PanGestureDetector detector = PanGestureDetector::New();
2268 detector.Attach( actor );
2270 GestureReceivedFunctor functor( data );
2271 detector.DetectedSignal().Connect( &application, functor );
2273 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2275 ConstraintData constraintData;
2276 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2277 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2278 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2279 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2280 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2281 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2282 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2285 // Render and notify
2286 application.SendNotification();
2287 application.Render();
2289 Vector2 direction(Vector2::XAXIS * -1.0f);
2290 Vector2 previousPosition( 20.0f, 20.0f );
2291 Vector2 currentPosition( 20.0f, 10.0f );
2292 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2293 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2294 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2295 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2296 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2298 constraintData.Reset();
2302 int UtcDaliPanGestureSetProperties(void)
2304 TestApplication application;
2305 TestRenderController& renderController( application.GetRenderController() );
2306 Integration::SetPanGesturePredictionMode(0);
2307 Integration::SetPanGestureSmoothingMode(0);
2309 Actor actor = Actor::New();
2310 actor.SetSize(100.0f, 100.0f);
2311 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2312 Stage::GetCurrent().Add(actor);
2314 // Add a pan detector
2315 PanGestureDetector detector = PanGestureDetector::New();
2316 detector.Attach( actor );
2318 GestureReceivedFunctor functor( data );
2319 detector.DetectedSignal().Connect( &application, functor );
2321 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2323 ConstraintData constraintData;
2324 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2325 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2326 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2327 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2328 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2329 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2330 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2333 // Render and notify
2334 application.SendNotification();
2335 application.Render();
2337 renderController.Initialize();
2338 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2340 Vector2 screenPosition( 20.0f, 20.0f );
2341 Vector2 screenDisplacement( 1.0f, 1.0f );
2342 Vector2 screenVelocity( 1.3f, 4.0f );
2343 Vector2 localPosition( 21.0f, 21.0f );
2344 Vector2 localDisplacement( 0.5f, 0.5f );
2345 Vector2 localVelocity( 1.5f, 2.5f );
2347 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2348 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2350 // Render and notify
2351 application.SendNotification();
2352 application.Render();
2354 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2355 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2356 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2357 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2358 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2359 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2360 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2361 constraintData.Reset();
2365 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2367 TestApplication application;
2368 Integration::SetPanGesturePredictionMode(0);
2370 Actor actor = Actor::New();
2371 actor.SetSize(100.0f, 100.0f);
2372 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2373 Stage::GetCurrent().Add(actor);
2375 // Add a pan detector
2376 PanGestureDetector detector = PanGestureDetector::New();
2377 detector.Attach( actor );
2379 GestureReceivedFunctor functor( data );
2380 detector.DetectedSignal().Connect( &application, functor );
2382 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2384 ConstraintData constraintData;
2385 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2386 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2387 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2388 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2389 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2390 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2391 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2394 // Render and notify
2395 application.SendNotification();
2396 application.Render();
2398 Vector2 previousPosition( 20.0f, 20.0f );
2399 Vector2 currentPosition( 20.0f, 10.0f );
2400 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2401 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2402 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2404 Vector2 screenPosition( 100.0f, 20.0f );
2405 Vector2 localPosition( 110.0f, 110.0f );
2407 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2409 // Render and notify
2410 application.SendNotification();
2411 application.Render();
2413 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2414 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2415 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2416 constraintData.Reset();
2420 int UtcDaliPanGesturePropertyIndices(void)
2422 TestApplication application;
2423 PanGestureDetector detector = PanGestureDetector::New();
2425 Property::IndexContainer indices;
2426 detector.GetPropertyIndices( indices );
2427 DALI_TEST_CHECK( indices.Size() );
2428 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2432 int UtcDaliPanGestureLayerConsumesTouch(void)
2434 TestApplication application;
2436 Actor actor = Actor::New();
2437 actor.SetSize(100.0f, 100.0f);
2438 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2439 Stage::GetCurrent().Add(actor);
2441 // Add a pan detector
2442 PanGestureDetector detector = PanGestureDetector::New();
2443 detector.Attach( actor );
2445 GestureReceivedFunctor functor( data );
2446 detector.DetectedSignal().Connect( &application, functor );
2448 // Add a layer to overlap the actor
2449 Layer layer = Layer::New();
2450 layer.SetSize(100.0f, 100.0f);
2451 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2452 Stage::GetCurrent().Add( layer );
2455 // Render and notify
2456 application.SendNotification();
2457 application.Render();
2459 // Emit signals, should receive
2460 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2461 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2462 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2463 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2466 // Set layer to consume all touch
2467 layer.SetTouchConsumed( true );
2469 // Render and notify
2470 application.SendNotification();
2471 application.Render();
2473 // Emit the same signals again, should not receive
2474 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2475 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2476 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2477 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2483 int UtcDaliPanGestureNoTimeDiff(void)
2485 TestApplication application;
2487 Actor actor = Actor::New();
2488 actor.SetSize(100.0f, 100.0f);
2489 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2490 Stage::GetCurrent().Add(actor);
2492 // Add a pan detector
2493 PanGestureDetector detector = PanGestureDetector::New();
2494 detector.Attach( actor );
2496 GestureReceivedFunctor functor( data );
2497 detector.DetectedSignal().Connect( &application, functor );
2499 // Render and notify
2500 application.SendNotification();
2501 application.Render();
2503 // Emit signals, should receive
2504 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2505 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2506 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2507 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2508 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2509 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2510 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2511 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );