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(), 0, TEST_LOCATION );
1745 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1746 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, 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(), 2, TEST_LOCATION );
1767 // Remove something not in the container.
1768 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1769 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1771 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1772 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, 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(), 0, TEST_LOCATION );
1788 inline float RadiansToDegrees( float radian )
1790 return radian * 180.0f / Math::PI;
1793 int UtcDaliPanGestureAngleOutOfRange(void)
1795 TestApplication application;
1797 PanGestureDetector detector = PanGestureDetector::New();
1798 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1804 detector.AddAngle( Degree(180.0f) );
1805 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1806 detector.ClearAngles();
1808 detector.AddAngle( Degree(190.0f) );
1809 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1810 detector.ClearAngles();
1812 detector.AddAngle( Degree(-190.0f) );
1813 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1814 detector.ClearAngles();
1816 detector.AddAngle( Degree(350.0f) );
1817 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1818 detector.ClearAngles();
1820 detector.AddAngle( Degree(-350.0f) );
1821 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1822 detector.ClearAngles();
1824 detector.AddAngle( Degree(370.0f) );
1825 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1826 detector.ClearAngles();
1828 detector.AddAngle( Degree(-370.0f) );
1829 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1830 detector.ClearAngles();
1836 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1837 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1838 detector.ClearAngles();
1840 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1841 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1842 detector.ClearAngles();
1844 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1845 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1846 detector.ClearAngles();
1848 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1849 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1850 detector.ClearAngles();
1854 int UtcDaliPanGestureAngleProcessing(void)
1856 TestApplication application;
1858 Actor parent = Actor::New();
1859 parent.SetSize(100.0f, 100.0f);
1860 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1861 Stage::GetCurrent().Add(parent);
1863 Actor child = Actor::New();
1864 child.SetSize(100.0f, 100.0f);
1865 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1868 // Render and notify
1869 application.SendNotification();
1870 application.Render();
1872 // Parent detector only requires up pans
1873 PanGestureDetector parentDetector = PanGestureDetector::New();
1874 parentDetector.Attach( parent );
1875 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1876 SignalData parentData;
1877 GestureReceivedFunctor parentFunctor(parentData);
1878 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1880 // Child detector only requires right pans
1881 PanGestureDetector childDetector = PanGestureDetector::New();
1882 childDetector.Attach( child );
1883 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1884 SignalData childData;
1885 GestureReceivedFunctor childFunctor(childData);
1886 childDetector.DetectedSignal().Connect(&application, childFunctor);
1888 // Generate an Up pan gesture, only parent should receive it.
1889 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1890 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1891 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1892 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1893 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1897 // Generate a Right pan gesture, only child should receive it.
1898 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1899 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1900 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1901 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1902 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1906 // Generate a Down pan gesture, no one should receive it.
1907 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1908 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1909 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1910 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1911 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1915 // Generate a Left pan gesture, no one 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(10.0f, 20.0f), 10 ) );
1918 DALI_TEST_EQUALS( false, 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 ) );
1926 int UtcDaliPanGestureDirectionHandling(void)
1928 TestApplication application;
1930 PanGestureDetector detector = PanGestureDetector::New();
1931 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1933 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1934 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1936 for ( size_t i = 0; detector.GetAngleCount(); i++)
1938 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1940 tet_result( TET_PASS );
1949 tet_printf("%s, angle not added\n", TEST_LOCATION );
1950 tet_result( TET_FAIL );
1954 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1956 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1958 tet_result( TET_PASS );
1966 tet_printf("%s, angle not added\n", TEST_LOCATION );
1967 tet_result( TET_FAIL );
1970 // Remove something not in the container.
1971 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1972 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1974 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1975 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1979 int UtcDaliPanGestureDirectionProcessing(void)
1981 TestApplication application;
1983 Actor parent = Actor::New();
1984 parent.SetSize(100.0f, 100.0f);
1985 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1986 Stage::GetCurrent().Add(parent);
1988 Actor child = Actor::New();
1989 child.SetSize(100.0f, 100.0f);
1990 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1993 // Render and notify
1994 application.SendNotification();
1995 application.Render();
1997 // Parent detector only requires vertical panning
1998 PanGestureDetector parentDetector = PanGestureDetector::New();
1999 parentDetector.Attach( parent );
2000 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
2001 SignalData parentData;
2002 GestureReceivedFunctor parentFunctor(parentData);
2003 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2005 // Child detector only requires horizontal panning
2006 PanGestureDetector childDetector = PanGestureDetector::New();
2007 childDetector.Attach( child );
2008 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2009 SignalData childData;
2010 GestureReceivedFunctor childFunctor(childData);
2011 childDetector.DetectedSignal().Connect(&application, childFunctor);
2013 // Generate an Up pan gesture, only parent should receive it.
2014 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2015 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
2016 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2017 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2018 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2022 // Generate a Right pan gesture, only child should receive it.
2023 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2024 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2025 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2026 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2027 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2031 // Generate a Down pan gesture, only parent should receive it.
2032 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2033 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2034 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2035 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2036 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2040 // Generate a Left pan gesture, only child 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(10.0f, 20.0f), 10 ) );
2043 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2044 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2045 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2049 // Generate a pan at -45 degrees, no one 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(10.0f, 30.0f), 10 ) );
2052 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2053 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2054 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2058 // Generate a pan at 45 degrees, no one 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(30.0f, 30.0f), 10 ) );
2061 DALI_TEST_EQUALS( false, 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 pan at 135 degrees, no one 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, 30.0f), 10 ) );
2070 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2071 DALI_TEST_EQUALS( false, 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 -135 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, 10.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 ) );
2087 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2089 TestApplication application;
2090 Integration::SetPanGesturePredictionMode(0);
2091 Integration::SetPanGestureSmoothingMode(0);
2093 Actor actor = Actor::New();
2094 actor.SetSize(100.0f, 100.0f);
2095 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2096 Stage::GetCurrent().Add(actor);
2098 // Add a pan detector
2099 PanGestureDetector detector = PanGestureDetector::New();
2100 detector.Attach( actor );
2102 GestureReceivedFunctor functor( data );
2103 detector.DetectedSignal().Connect( &application, functor );
2105 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2107 ConstraintData constraintData;
2108 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2109 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2110 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2111 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2112 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2113 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2114 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2117 // Render and notify
2118 application.SendNotification();
2119 application.Render();
2121 Vector2 direction(Vector2::XAXIS * -5.0f);
2122 Vector2 startPosition( 1.0f, 1.0f );
2123 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2124 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2125 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2126 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2127 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2129 constraintData.Reset();
2133 int UtcDaliPanGestureNoPredictionSmoothing(void)
2135 TestApplication application;
2136 Integration::SetPanGesturePredictionMode(0);
2137 Integration::SetPanGestureSmoothingMode(1);
2139 Actor actor = Actor::New();
2140 actor.SetSize(100.0f, 100.0f);
2141 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2142 Stage::GetCurrent().Add(actor);
2144 // Add a pan detector
2145 PanGestureDetector detector = PanGestureDetector::New();
2146 detector.Attach( actor );
2148 GestureReceivedFunctor functor( data );
2149 detector.DetectedSignal().Connect( &application, functor );
2151 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2153 ConstraintData constraintData;
2154 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2155 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2156 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2157 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2158 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2159 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2160 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2163 // Render and notify
2164 application.SendNotification();
2165 application.Render();
2167 Vector2 direction(Vector2::XAXIS * -5.0f);
2168 Vector2 previousPosition( 20.0f, 20.0f );
2169 Vector2 currentPosition( 20.0f, 10.0f );
2170 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2171 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2172 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2173 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2174 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2176 constraintData.Reset();
2180 int UtcDaliPanGesturePredictionNoSmoothing(void)
2182 TestApplication application;
2183 Integration::SetPanGesturePredictionMode(1);
2184 Integration::SetPanGestureSmoothingMode(0);
2186 Actor actor = Actor::New();
2187 actor.SetSize(100.0f, 100.0f);
2188 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2189 Stage::GetCurrent().Add(actor);
2191 // Add a pan detector
2192 PanGestureDetector detector = PanGestureDetector::New();
2193 detector.Attach( actor );
2195 GestureReceivedFunctor functor( data );
2196 detector.DetectedSignal().Connect( &application, functor );
2198 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2200 ConstraintData constraintData;
2201 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2202 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2203 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2204 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2205 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2206 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2207 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2210 // Render and notify
2211 application.SendNotification();
2212 application.Render();
2214 Vector2 direction(Vector2::XAXIS * -1.0f);
2215 Vector2 previousPosition( 20.0f, 20.0f );
2216 Vector2 currentPosition( 20.0f, 10.0f );
2217 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2218 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2219 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2220 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2221 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2223 constraintData.Reset();
2227 int UtcDaliPanGesturePredictionSmoothing(void)
2229 TestApplication application;
2230 Integration::SetPanGesturePredictionMode(1);
2231 Integration::SetPanGestureSmoothingMode(1);
2233 Actor actor = Actor::New();
2234 actor.SetSize(100.0f, 100.0f);
2235 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2236 Stage::GetCurrent().Add(actor);
2238 // Add a pan detector
2239 PanGestureDetector detector = PanGestureDetector::New();
2240 detector.Attach( actor );
2242 GestureReceivedFunctor functor( data );
2243 detector.DetectedSignal().Connect( &application, functor );
2245 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2247 ConstraintData constraintData;
2248 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2249 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2250 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2251 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2252 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2253 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2254 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2257 // Render and notify
2258 application.SendNotification();
2259 application.Render();
2261 Vector2 direction(Vector2::XAXIS * -1.0f);
2262 Vector2 previousPosition( 20.0f, 20.0f );
2263 Vector2 currentPosition( 20.0f, 10.0f );
2264 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2265 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2266 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2267 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2268 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2270 constraintData.Reset();
2274 int UtcDaliPanGestureSetProperties(void)
2276 TestApplication application;
2277 TestRenderController& renderController( application.GetRenderController() );
2278 Integration::SetPanGesturePredictionMode(0);
2279 Integration::SetPanGestureSmoothingMode(0);
2281 Actor actor = Actor::New();
2282 actor.SetSize(100.0f, 100.0f);
2283 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2284 Stage::GetCurrent().Add(actor);
2286 // Add a pan detector
2287 PanGestureDetector detector = PanGestureDetector::New();
2288 detector.Attach( actor );
2290 GestureReceivedFunctor functor( data );
2291 detector.DetectedSignal().Connect( &application, functor );
2293 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2295 ConstraintData constraintData;
2296 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2297 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2298 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2299 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2300 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2301 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2302 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2305 // Render and notify
2306 application.SendNotification();
2307 application.Render();
2309 renderController.Initialize();
2310 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2312 Vector2 screenPosition( 20.0f, 20.0f );
2313 Vector2 screenDisplacement( 1.0f, 1.0f );
2314 Vector2 screenVelocity( 1.3f, 4.0f );
2315 Vector2 localPosition( 21.0f, 21.0f );
2316 Vector2 localDisplacement( 0.5f, 0.5f );
2317 Vector2 localVelocity( 1.5f, 2.5f );
2319 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2320 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2322 // Render and notify
2323 application.SendNotification();
2324 application.Render();
2326 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2327 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2328 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2329 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2330 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2331 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2332 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2333 constraintData.Reset();
2337 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2339 TestApplication application;
2340 Integration::SetPanGesturePredictionMode(0);
2342 Actor actor = Actor::New();
2343 actor.SetSize(100.0f, 100.0f);
2344 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2345 Stage::GetCurrent().Add(actor);
2347 // Add a pan detector
2348 PanGestureDetector detector = PanGestureDetector::New();
2349 detector.Attach( actor );
2351 GestureReceivedFunctor functor( data );
2352 detector.DetectedSignal().Connect( &application, functor );
2354 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2356 ConstraintData constraintData;
2357 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2358 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2359 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2360 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2361 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2362 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2363 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2366 // Render and notify
2367 application.SendNotification();
2368 application.Render();
2370 Vector2 previousPosition( 20.0f, 20.0f );
2371 Vector2 currentPosition( 20.0f, 10.0f );
2372 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2373 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2374 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2376 Vector2 screenPosition( 100.0f, 20.0f );
2377 Vector2 localPosition( 110.0f, 110.0f );
2379 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2381 // Render and notify
2382 application.SendNotification();
2383 application.Render();
2385 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2386 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2387 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2388 constraintData.Reset();
2392 int UtcDaliPanGesturePropertyIndices(void)
2394 TestApplication application;
2395 PanGestureDetector detector = PanGestureDetector::New();
2397 Property::IndexContainer indices;
2398 detector.GetPropertyIndices( indices );
2399 DALI_TEST_CHECK( indices.Size() );
2400 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2404 int UtcDaliPanGestureLayerConsumesTouch(void)
2406 TestApplication application;
2408 Actor actor = Actor::New();
2409 actor.SetSize(100.0f, 100.0f);
2410 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2411 Stage::GetCurrent().Add(actor);
2413 // Add a pan detector
2414 PanGestureDetector detector = PanGestureDetector::New();
2415 detector.Attach( actor );
2417 GestureReceivedFunctor functor( data );
2418 detector.DetectedSignal().Connect( &application, functor );
2420 // Add a layer to overlap the actor
2421 Layer layer = Layer::New();
2422 layer.SetSize(100.0f, 100.0f);
2423 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2424 Stage::GetCurrent().Add( layer );
2427 // Render and notify
2428 application.SendNotification();
2429 application.Render();
2431 // Emit signals, should receive
2432 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2433 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2434 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2435 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2438 // Set layer to consume all touch
2439 layer.SetTouchConsumed( true );
2441 // Render and notify
2442 application.SendNotification();
2443 application.Render();
2445 // Emit the same signals again, should not receive
2446 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2447 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2448 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2449 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2455 int UtcDaliPanGestureNoTimeDiff(void)
2457 TestApplication application;
2459 Actor actor = Actor::New();
2460 actor.SetSize(100.0f, 100.0f);
2461 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2462 Stage::GetCurrent().Add(actor);
2464 // Add a pan detector
2465 PanGestureDetector detector = PanGestureDetector::New();
2466 detector.Attach( actor );
2468 GestureReceivedFunctor functor( data );
2469 detector.DetectedSignal().Connect( &application, functor );
2471 // Render and notify
2472 application.SendNotification();
2473 application.Render();
2475 // Emit signals, should receive
2476 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2477 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2478 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2479 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2480 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2481 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2482 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2483 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );