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.
21 #include <dali/dali.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali/integration-api/profiling.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
31 void utc_dali_pan_gesture_detector_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_pan_gesture_detector_cleanup(void)
38 test_return_value = TET_PASS;
41 ///////////////////////////////////////////////////////////////////////////////
44 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
47 // Stores data that is populated in the callback and will be read by the test cases
51 : functorCalled(false),
52 voidFunctorCalled(false),
53 receivedGesture(Gesture::Clear)
58 functorCalled = false;
59 voidFunctorCalled = false;
61 receivedGesture.state = Gesture::Clear;
62 receivedGesture.velocity = Vector2(0.0f, 0.0f);
63 receivedGesture.displacement = Vector2(0.0f, 0.0f);
64 receivedGesture.position = Vector2(0.0f, 0.0f);
65 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
66 receivedGesture.numberOfTouches = 0;
72 bool voidFunctorCalled;
73 PanGesture receivedGesture;
77 // Functor that sets the data when called
78 struct GestureReceivedFunctor
80 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
82 void operator()(Actor actor, PanGesture pan)
84 signalData.functorCalled = true;
85 signalData.receivedGesture = pan;
86 signalData.pannedActor = actor;
91 signalData.voidFunctorCalled = true;
94 SignalData& signalData;
97 // Functor that removes the gestured actor from stage
98 struct UnstageActorFunctor : public GestureReceivedFunctor
100 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
101 : GestureReceivedFunctor( data ),
102 stateToUnstage( stateToUnstage )
106 void operator()( Actor actor, PanGesture pan )
108 GestureReceivedFunctor::operator()( actor, pan );
110 if ( pan.state == stateToUnstage )
112 Stage::GetCurrent().Remove( actor );
116 Gesture::State& stateToUnstage;
119 // Functor for receiving a touch event
120 struct TouchEventFunctor
122 bool operator()(Actor actor, const TouchEvent& touch)
128 // Data for constraints
129 struct ConstraintData
136 Vector2 screenPosition;
137 Vector2 screenDisplacement;
138 Vector2 localPosition;
139 Vector2 localDisplacement;
144 screenPosition = screenDisplacement = localPosition = localDisplacement = Vector2::ZERO;
149 // Constraint used with panning properties
152 PanConstraint( ConstraintData& data ) : constraintData(data) { }
154 Vector3 operator()(const Vector3& current,
155 const PropertyInput& screenPositionProperty,
156 const PropertyInput& screenDisplacementProperty,
157 const PropertyInput& localPositionProperty,
158 const PropertyInput& localDisplacementProperty)
160 constraintData.screenPosition = screenPositionProperty.GetVector2();
161 constraintData.screenDisplacement = screenDisplacementProperty.GetVector2();
162 constraintData.localPosition = localPositionProperty.GetVector2();
163 constraintData.localDisplacement = localDisplacementProperty.GetVector2();
164 constraintData.called = true;
165 return Vector3::ZERO;
168 ConstraintData& constraintData;
171 // Generate a PanGestureEvent to send to Core
172 Integration::PanGestureEvent GeneratePan(
173 Gesture::State state,
174 Vector2 previousPosition,
175 Vector2 currentPosition,
176 unsigned long timeDelta,
177 unsigned int numberOfTouches = 1,
178 unsigned int time = 1u)
180 Integration::PanGestureEvent pan(state);
182 pan.previousPosition = previousPosition;
183 pan.currentPosition = currentPosition;
184 pan.timeDelta = timeDelta;
185 pan.numberOfTouches = numberOfTouches;
191 // Generate a PanGesture
192 PanGesture GeneratePan( unsigned int time,
193 Gesture::State state,
194 Vector2 screenPosition,
195 Vector2 localPosition,
196 Vector2 screenDisplacement = Vector2::ONE,
197 Vector2 localDisplacement = Vector2::ONE,
198 Vector2 velocity = Vector2::ONE,
199 unsigned int numberOfTouches = 1 )
201 PanGesture pan( state );
205 pan.screenPosition = screenPosition;
206 pan.position = localPosition;
208 pan.screenDisplacement = screenDisplacement;
209 pan.displacement = localDisplacement;
211 pan.screenVelocity = pan.velocity = velocity;
212 pan.numberOfTouches = numberOfTouches;
219 ///////////////////////////////////////////////////////////////////////////////
221 // Positive test case for a method
222 int UtcDaliPanGestureDetectorConstructor(void)
224 TestApplication application;
226 PanGestureDetector detector;
227 DALI_TEST_CHECK(!detector);
232 // Negative test case for a method
233 int UtcDaliPanGestureDetectorNew(void)
235 TestApplication application;
237 PanGestureDetector detector = PanGestureDetector::New();
239 DALI_TEST_CHECK(detector);
241 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
242 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
244 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
245 Actor actor = Actor::New();
246 actor.SetSize(100.0f, 100.0f);
247 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
248 detector.Attach(actor);
250 Stage::GetCurrent().Add(actor);
253 application.SendNotification();
254 application.Render();
256 Integration::TouchEvent touchEvent(1);
257 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
258 touchEvent.AddPoint(point);
259 application.ProcessEvent(touchEvent);
263 int UtcDaliPanGestureDetectorDownCast(void)
265 TestApplication application;
266 tet_infoline("Testing Dali::GestureDetector::DownCast()");
268 PanGestureDetector detector = PanGestureDetector::New();
270 BaseHandle object(detector);
272 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
273 DALI_TEST_CHECK(detector2);
275 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
276 DALI_TEST_CHECK(detector3);
278 BaseHandle unInitializedObject;
279 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
280 DALI_TEST_CHECK(!detector4);
282 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
283 DALI_TEST_CHECK(!detector5);
285 GestureDetector detector6 = PanGestureDetector::New();
286 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
287 DALI_TEST_CHECK(detector7);
291 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
293 TestApplication application;
295 PanGestureDetector detector = PanGestureDetector::New();
297 unsigned int min = 2;
299 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
301 detector.SetMinimumTouchesRequired(min);
303 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
305 // Attach an actor and change the minimum touches
307 Actor actor = Actor::New();
308 actor.SetSize(100.0f, 100.0f);
309 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
310 Stage::GetCurrent().Add(actor);
313 application.SendNotification();
314 application.Render();
317 GestureReceivedFunctor functor(data);
319 detector.Attach(actor);
320 detector.DetectedSignal().Connect(&application, functor);
322 TestGestureManager& gestureManager = application.GetGestureManager();
323 gestureManager.Initialize();
325 detector.SetMinimumTouchesRequired(3);
327 // Gesture detection should have been updated only
328 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
329 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
330 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
333 gestureManager.Initialize();
335 // Create a second gesture detector that requires even less minimum touches
336 PanGestureDetector secondDetector = PanGestureDetector::New();
337 secondDetector.Attach(actor);
339 // Gesture detection should have been updated only
340 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
341 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
342 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
346 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
348 TestApplication application;
350 PanGestureDetector detector = PanGestureDetector::New();
352 unsigned int max = 3;
354 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
356 detector.SetMaximumTouchesRequired(max);
358 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
360 // Attach an actor and change the maximum touches
362 Actor actor = Actor::New();
363 actor.SetSize(100.0f, 100.0f);
364 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
365 Stage::GetCurrent().Add(actor);
368 application.SendNotification();
369 application.Render();
372 GestureReceivedFunctor functor(data);
374 detector.Attach(actor);
375 detector.DetectedSignal().Connect(&application, functor);
377 TestGestureManager& gestureManager = application.GetGestureManager();
378 gestureManager.Initialize();
380 detector.SetMaximumTouchesRequired(4);
382 // Gesture detection should have been updated only
383 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
384 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
385 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
388 gestureManager.Initialize();
390 // Create a second gesture detector that requires even less maximum touches
391 PanGestureDetector secondDetector = PanGestureDetector::New();
392 secondDetector.Attach(actor);
394 // Gesture detection should NOT have been updated
395 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
396 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
397 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
401 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
403 TestApplication application;
405 PanGestureDetector detector = PanGestureDetector::New();
406 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
410 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
412 TestApplication application;
414 PanGestureDetector detector = PanGestureDetector::New();
415 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
419 int UtcDaliPanGestureSignalReceptionNegative(void)
421 TestApplication application;
423 Actor actor = Actor::New();
424 actor.SetSize(100.0f, 100.0f);
425 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
426 Stage::GetCurrent().Add(actor);
429 application.SendNotification();
430 application.Render();
433 GestureReceivedFunctor functor(data);
435 PanGestureDetector detector = PanGestureDetector::New();
436 detector.Attach(actor);
437 detector.DetectedSignal().Connect(&application, functor);
439 // Do a pan outside actor's area
440 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
441 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
442 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
444 // Continue pan into actor's area - we should still not receive the signal
446 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
447 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
449 // Stop panning - we should still not receive the signal
451 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
452 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
456 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
458 TestApplication application;
460 Actor actor = Actor::New();
461 actor.SetSize(100.0f, 100.0f);
462 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
463 Stage::GetCurrent().Add(actor);
466 application.SendNotification();
467 application.Render();
470 GestureReceivedFunctor functor(data);
472 PanGestureDetector detector = PanGestureDetector::New();
473 detector.Attach(actor);
474 detector.DetectedSignal().Connect(&application, functor);
476 // Start pan within the actor's area
477 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
478 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
479 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
480 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
481 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
482 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
483 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
484 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
485 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
487 // Continue the pan within the actor's area - we should still receive the signal
489 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
490 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
491 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
492 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
493 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
494 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
495 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
496 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
498 // Pan Gesture leaves actor's area - we should still receive the signal
500 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
501 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
502 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
503 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
504 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
505 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
506 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
507 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
509 // Gesture ends - we would receive a finished state
511 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
512 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
513 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
514 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
515 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
516 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
517 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
518 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
522 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
524 TestApplication application;
526 Actor actor = Actor::New();
527 actor.SetSize(100.0f, 100.0f);
528 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
529 Stage::GetCurrent().Add(actor);
532 application.SendNotification();
533 application.Render();
536 GestureReceivedFunctor functor(data);
538 PanGestureDetector detector = PanGestureDetector::New();
539 detector.Attach(actor);
540 detector.DetectedSignal().Connect(&application, functor);
542 // Start pan within the actor's area
543 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
544 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
545 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
546 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
547 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
548 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
549 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
550 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
551 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
553 // Continue the pan within the actor's area - we should still receive the signal
555 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
556 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
557 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
558 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
559 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
561 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
562 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
564 // Gesture ends within actor's area - we would receive a finished state
566 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
567 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
569 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
570 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
571 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
572 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
573 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
577 int UtcDaliPanGestureSignalReceptionCancelled(void)
579 TestApplication application;
581 Actor actor = Actor::New();
582 actor.SetSize(100.0f, 100.0f);
583 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
584 Stage::GetCurrent().Add(actor);
587 application.SendNotification();
588 application.Render();
591 GestureReceivedFunctor functor(data);
593 PanGestureDetector detector = PanGestureDetector::New();
594 detector.Attach(actor);
595 detector.DetectedSignal().Connect(&application, functor);
597 // Start pan within the actor's area
598 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
599 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
600 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
601 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
603 // Continue the pan within the actor's area - we should still receive the signal
605 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
606 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
607 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
609 // The gesture is cancelled
611 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
612 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
613 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
617 int UtcDaliPanGestureSignalReceptionDetach(void)
619 TestApplication application;
621 Actor actor = Actor::New();
622 actor.SetSize(100.0f, 100.0f);
623 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
624 Stage::GetCurrent().Add(actor);
627 application.SendNotification();
628 application.Render();
631 GestureReceivedFunctor functor(data);
633 PanGestureDetector detector = PanGestureDetector::New();
634 detector.Attach(actor);
635 detector.DetectedSignal().Connect(&application, functor);
637 // Start pan within the actor's area
638 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
639 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
640 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
642 // Continue the pan within the actor's area - we should still receive the signal
644 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
645 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
647 // Gesture ends within actor's area
649 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
650 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
653 detector.DetachAll();
655 // Ensure we are no longer signalled
657 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
658 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
659 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
660 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
661 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
665 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
667 TestApplication application;
669 Actor actor = Actor::New();
670 actor.SetSize(100.0f, 100.0f);
671 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
672 Stage::GetCurrent().Add(actor);
675 application.SendNotification();
676 application.Render();
679 GestureReceivedFunctor functor(data);
681 PanGestureDetector detector = PanGestureDetector::New();
682 detector.Attach(actor);
683 detector.DetectedSignal().Connect(&application, functor);
685 // Start pan within the actor's area
686 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
687 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
688 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
690 // Continue the pan within the actor's area - we should still receive the signal
692 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
693 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
695 // Detach actor during the pan, we should not receive the next event
696 detector.DetachAll();
698 // Gesture ends within actor's area
700 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
701 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
705 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
707 TestApplication application;
710 GestureReceivedFunctor functor(data);
712 PanGestureDetector detector = PanGestureDetector::New();
713 detector.DetectedSignal().Connect(&application, functor);
715 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
717 Actor tempActor = Actor::New();
718 tempActor.SetSize(100.0f, 100.0f);
719 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
720 Stage::GetCurrent().Add(tempActor);
721 detector.Attach(tempActor);
723 // Actor lifetime is scoped
725 Actor actor = Actor::New();
726 actor.SetSize(100.0f, 100.0f);
727 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
728 Stage::GetCurrent().Add(actor);
731 application.SendNotification();
732 application.Render();
734 detector.Attach(actor);
736 // Start pan within the actor's area
737 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
738 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
739 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
741 // Continue the pan within the actor's area - we should still receive the signal
743 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
744 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
746 // Remove the actor from stage and reset the data
747 Stage::GetCurrent().Remove(actor);
750 application.SendNotification();
751 application.Render();
754 // Actor should now have been destroyed
756 // Gesture ends within the area where the actor used to be
758 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
759 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
763 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
765 TestApplication application;
767 Actor actor = Actor::New();
768 actor.SetSize(100.0f, 100.0f);
769 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
770 Stage::GetCurrent().Add(actor);
773 application.SendNotification();
774 application.Render();
777 GestureReceivedFunctor functor(data);
779 PanGestureDetector detector = PanGestureDetector::New();
780 detector.Attach(actor);
781 detector.DetectedSignal().Connect(&application, functor);
783 // Do an entire pan, only check finished value
784 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
785 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
787 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
788 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
789 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
791 // Rotate actor again and render a couple of times
792 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
793 application.SendNotification();
794 application.Render();
796 // Do an entire pan, only check finished value
797 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
798 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
800 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
801 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
802 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
804 // Rotate actor again and render a couple of times
805 actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
806 application.SendNotification();
807 application.Render();
809 // Do an entire pan, only check finished value
810 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
811 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
813 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
814 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
815 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
819 int UtcDaliPanGestureSignalReceptionChildHit(void)
821 TestApplication application;
823 Actor parent = Actor::New();
824 parent.SetSize(100.0f, 100.0f);
825 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
826 Stage::GetCurrent().Add(parent);
828 // Set child to completely cover parent.
829 // Change rotation of child to be different from parent so that we can check if our local coordinate
830 // conversion of the parent actor is correct.
831 Actor child = Actor::New();
832 child.SetSize(100.0f, 100.0f);
833 child.SetAnchorPoint(AnchorPoint::CENTER);
834 child.SetParentOrigin(ParentOrigin::CENTER);
835 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
838 TouchEventFunctor touchFunctor;
839 child.TouchedSignal().Connect(&application, touchFunctor);
842 application.SendNotification();
843 application.Render();
846 GestureReceivedFunctor functor(data);
848 PanGestureDetector detector = PanGestureDetector::New();
849 detector.Attach(parent);
850 detector.DetectedSignal().Connect(&application, functor);
852 // Do an entire pan, only check finished value - hits child area but parent should still receive it
853 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
854 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
856 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
857 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
858 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
859 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
861 // Attach child and generate same touch points to yield a different displacement
862 // (Also proves that you can detach and then re-attach another actor)
863 detector.Attach(child);
864 detector.Detach(parent);
866 // Do an entire pan, only check finished value
867 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
868 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
870 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
871 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
872 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
873 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
877 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
879 TestApplication application;
881 Actor first = Actor::New();
882 first.SetSize(100.0f, 100.0f);
883 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
884 Stage::GetCurrent().Add(first);
886 Actor second = Actor::New();
887 second.SetSize(100.0f, 100.0f);
889 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
890 Stage::GetCurrent().Add(second);
893 application.SendNotification();
894 application.Render();
897 GestureReceivedFunctor functor(data);
899 PanGestureDetector detector = PanGestureDetector::New();
900 detector.Attach(first);
901 detector.Attach(second);
902 detector.DetectedSignal().Connect(&application, functor);
904 // Start pan within second actor's area
905 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
906 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
907 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
908 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
910 // Pan moves into first actor's area - second actor should receive the pan
912 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
913 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
914 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
916 // Detach the second actor during the pan, we should not receive the next event
917 detector.Detach(second);
919 // Gesture ends within actor's area
921 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
922 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
926 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
928 TestApplication application;
930 Actor actor = Actor::New();
931 actor.SetSize(100.0f, 100.0f);
932 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
933 Stage::GetCurrent().Add(actor);
936 application.SendNotification();
937 application.Render();
940 GestureReceivedFunctor functor(data);
942 PanGestureDetector detector = PanGestureDetector::New();
943 detector.Attach(actor);
944 detector.DetectedSignal().Connect(&application, functor);
946 // Start pan in actor's area
947 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
948 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
949 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
951 // Pan continues within actor's area
953 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
954 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
956 // Actor become invisible - actor should not receive the next pan
957 actor.SetVisible(false);
960 application.SendNotification();
961 application.Render();
963 // Gesture ends within actor's area
965 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
966 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
970 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
972 TestApplication application;
973 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
975 Actor first = Actor::New();
976 first.SetSize(100.0f, 100.0f);
977 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
978 Stage::GetCurrent().Add(first);
980 Actor second = Actor::New();
981 second.SetSize(100.0f, 100.0f);
982 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
986 application.SendNotification();
987 application.Render();
990 GestureReceivedFunctor functor(data);
992 PanGestureDetector firstDetector = PanGestureDetector::New();
993 firstDetector.Attach(first);
994 firstDetector.DetectedSignal().Connect(&application, functor);
996 // secondDetector is scoped
998 // Reset gestureManager statistics
999 gestureManager.Initialize();
1001 PanGestureDetector secondDetector = PanGestureDetector::New();
1002 secondDetector.SetMinimumTouchesRequired(2);
1003 secondDetector.SetMaximumTouchesRequired(2);
1004 secondDetector.Attach(second);
1005 secondDetector.DetectedSignal().Connect(&application, functor);
1007 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1008 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1009 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1011 // Start pan within second actor's area
1012 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1013 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1014 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1015 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1017 // Two touch pan changes to single touch - we should receive a finished state
1019 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1020 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1021 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1022 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1024 // Pan continues as single touch gesture - we should not receive any gesture
1026 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1027 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1029 // Pan ends - still no signal
1031 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1032 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1034 // Single touch pan starts - first actor should be panned
1036 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1037 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1038 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1039 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1041 // Pan changes to double-touch - we should receive a finished state
1043 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1044 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1045 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1046 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1048 // Pan continues as double touch gesture - we should not receive any gesture
1050 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1051 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1053 // Pan ends - still no signal
1055 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1056 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1058 // Reset gesture manager statistics
1059 gestureManager.Initialize();
1062 // secondDetector has now been deleted. Gesture detection should have been updated only
1063 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1064 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1065 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1069 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1071 TestApplication application;
1073 Actor actor = Actor::New();
1074 actor.SetSize(100.0f, 100.0f);
1075 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1076 Stage::GetCurrent().Add(actor);
1078 Actor actor2 = Actor::New();
1079 actor2.SetSize(100.0f, 100.0f);
1080 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1081 Stage::GetCurrent().Add(actor2);
1083 // Render and notify
1084 application.SendNotification();
1085 application.Render();
1087 // Attach actor to one detector
1088 SignalData firstData;
1089 GestureReceivedFunctor firstFunctor(firstData);
1090 PanGestureDetector firstDetector = PanGestureDetector::New();
1091 firstDetector.Attach(actor);
1092 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1094 // Attach actor to another detector
1095 SignalData secondData;
1096 GestureReceivedFunctor secondFunctor(secondData);
1097 PanGestureDetector secondDetector = PanGestureDetector::New();
1098 secondDetector.Attach(actor);
1099 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1101 // Add second actor to second detector, when we remove the actor, this will make sure that this
1102 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1103 // functor should still not be called (which is what we're also testing).
1104 secondDetector.Attach(actor2);
1106 // Pan in actor's area - both detector's functors should be called
1107 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1108 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1109 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1110 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1112 // Pan continues in actor's area - both detector's functors should be called
1115 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1116 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1117 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1119 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1120 firstDetector.Detach(actor);
1123 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1124 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1125 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1127 // New pan on actor, only secondDetector has actor attached
1130 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1131 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1132 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1133 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1135 // Detach actor from secondDetector
1136 secondDetector.Detach(actor);
1139 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1140 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1141 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1145 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1147 // Should handle two started events gracefully.
1149 TestApplication application;
1151 Actor actor = Actor::New();
1152 actor.SetSize(100.0f, 100.0f);
1153 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1154 Stage::GetCurrent().Add(actor);
1157 GestureReceivedFunctor functor(data);
1159 PanGestureDetector detector = PanGestureDetector::New();
1160 detector.Attach(actor);
1161 detector.DetectedSignal().Connect(&application, functor);
1163 // Render and notify
1164 application.SendNotification();
1165 application.Render();
1167 // Start pan in actor's area
1168 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1169 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1170 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1172 // Send another start in actor's area
1174 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1175 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1177 // Add a child actor to overlap actor and send another start in actor's area
1178 Actor child = Actor::New();
1179 child.SetSize(100.0f, 100.0f);
1180 child.SetAnchorPoint(AnchorPoint::CENTER);
1181 child.SetParentOrigin(ParentOrigin::CENTER);
1184 TouchEventFunctor touchFunctor;
1185 child.TouchedSignal().Connect(&application, touchFunctor);
1187 // Render and notify
1188 application.SendNotification();
1189 application.Render();
1191 // Send another possible and start in actor's area
1193 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1194 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1195 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1197 // Send another start in actor's area
1199 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1200 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1201 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1205 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1207 TestApplication application;
1209 Actor actor1 = Actor::New();
1210 actor1.SetSize(100.0f, 100.0f);
1211 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1212 Stage::GetCurrent().Add(actor1);
1214 GestureReceivedFunctor functor1(data1);
1215 PanGestureDetector detector1 = PanGestureDetector::New();
1216 detector1.Attach(actor1);
1217 detector1.DetectedSignal().Connect(&application, functor1);
1219 Actor actor2 = Actor::New();
1220 actor2.SetSize(100.0f, 100.0f);
1221 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1222 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1223 Stage::GetCurrent().Add(actor2);
1225 GestureReceivedFunctor functor2(data2);
1226 PanGestureDetector detector2 = PanGestureDetector::New();
1227 detector2.Attach(actor2);
1228 detector2.DetectedSignal().Connect(&application, functor2);
1230 // Render and notify
1231 application.SendNotification();
1232 application.Render();
1234 // Start pan in actor1's area, only data1 should be set
1235 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1236 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1237 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1238 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1242 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1244 TestApplication application;
1246 Actor actor = Actor::New();
1247 actor.SetSize(100.0f, 100.0f);
1248 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1249 Stage::GetCurrent().Add(actor);
1251 // Render and notify
1252 application.SendNotification();
1253 application.Render();
1255 // Attach actor to detector
1257 GestureReceivedFunctor functor( data );
1258 PanGestureDetector detector = PanGestureDetector::New();
1259 detector.Attach(actor);
1260 detector.DetectedSignal().Connect( &application, functor );
1262 // Gesture possible in actor's area.
1263 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1264 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1266 // Move actor somewhere else
1267 actor.SetPosition( 100.0f, 100.0f );
1269 // Render and notify
1270 application.SendNotification();
1271 application.Render();
1273 // Emit Started event, we should not receive the long press.
1274 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1275 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1276 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1278 // LongPress possible in empty area.
1279 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1280 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1282 // Move actor in to the long press position.
1283 actor.SetPosition( 0.0f, 0.0f );
1285 // Render and notify
1286 application.SendNotification();
1287 application.Render();
1289 // Emit Started event, we should not receive the long press.
1290 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1291 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1292 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1294 // Normal long press in actor's area for completeness.
1295 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1296 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1297 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1298 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1302 int UtcDaliPanGestureEmitIncorrectState(void)
1304 TestApplication application;
1306 Actor actor = Actor::New();
1307 actor.SetSize(100.0f, 100.0f);
1308 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1309 Stage::GetCurrent().Add(actor);
1311 // Render and notify
1312 application.SendNotification();
1313 application.Render();
1315 // Attach actor to detector
1317 GestureReceivedFunctor functor( data );
1318 PanGestureDetector detector = PanGestureDetector::New();
1319 detector.Attach(actor);
1320 detector.DetectedSignal().Connect( &application, functor );
1322 // Try a Clear state
1325 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1326 tet_result(TET_FAIL);
1328 catch ( Dali::DaliException& e )
1330 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1335 int UtcDaliPanGestureActorUnstaged(void)
1337 TestApplication application;
1339 Actor actor = Actor::New();
1340 actor.SetSize(100.0f, 100.0f);
1341 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1342 Stage::GetCurrent().Add(actor);
1344 // Render and notify
1345 application.SendNotification();
1346 application.Render();
1348 // State to remove actor in.
1349 Gesture::State stateToUnstage( Gesture::Started );
1351 // Attach actor to detector
1353 UnstageActorFunctor functor( data, stateToUnstage );
1354 PanGestureDetector detector = PanGestureDetector::New();
1355 detector.Attach(actor);
1356 detector.DetectedSignal().Connect( &application, functor );
1359 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1360 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1361 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1363 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1364 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1367 // Render and notify
1368 application.SendNotification();
1369 application.Render();
1371 // Re-add actor to stage
1372 Stage::GetCurrent().Add(actor);
1374 // Render and notify
1375 application.SendNotification();
1376 application.Render();
1378 // Change state to Gesture::Continuing to remove
1379 stateToUnstage = Gesture::Continuing;
1382 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1383 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1384 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1386 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1387 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1389 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1390 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1393 // Render and notify
1394 application.SendNotification();
1395 application.Render();
1397 // Re-add actor to stage
1398 Stage::GetCurrent().Add(actor);
1400 // Render and notify
1401 application.SendNotification();
1402 application.Render();
1404 // Change state to Gesture::Finished to remove
1405 stateToUnstage = Gesture::Finished;
1408 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1409 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1410 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1412 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1413 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1415 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1416 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1417 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1421 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1423 TestApplication application;
1425 Actor actor = Actor::New();
1426 actor.SetSize(100.0f, 100.0f);
1427 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1428 Stage::GetCurrent().Add(actor);
1430 // Create and add a second actor so that GestureDetector destruction does not come into play.
1431 Actor dummyActor( Actor::New() );
1432 dummyActor.SetSize( 100.0f, 100.0f );
1433 dummyActor.SetPosition( 100.0f, 100.0f );
1434 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1435 Stage::GetCurrent().Add(dummyActor);
1437 // Render and notify
1438 application.SendNotification();
1439 application.Render();
1441 // State to remove actor in.
1442 Gesture::State stateToUnstage( Gesture::Started );
1444 // Attach actor to detector
1446 UnstageActorFunctor functor( data, stateToUnstage );
1447 PanGestureDetector detector = PanGestureDetector::New();
1448 detector.Attach(actor);
1449 detector.Attach(dummyActor);
1450 detector.DetectedSignal().Connect( &application, functor );
1452 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1453 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1454 // position, we should still not be signalled.
1457 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1458 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1459 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1462 // Render and notify
1463 application.SendNotification();
1464 application.Render();
1466 // Re add to the stage, we should not be signalled
1467 Stage::GetCurrent().Add(actor);
1469 // Render and notify
1470 application.SendNotification();
1471 application.Render();
1473 // Continue signal emission
1474 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1475 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1477 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1478 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1481 // Here we delete an actor in started, we should not receive any subsequent signalling.
1484 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1485 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1486 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1489 // Render and notify
1490 application.SendNotification();
1491 application.Render();
1493 // Delete actor as well
1496 // Render and notify
1497 application.SendNotification();
1498 application.Render();
1500 // Continue signal emission
1501 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1502 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1504 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1505 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1509 int UtcDaliPanGestureSystemOverlay(void)
1511 TestApplication application;
1512 Dali::Integration::Core& core = application.GetCore();
1513 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1514 systemOverlay.GetOverlayRenderTasks().CreateTask();
1516 Actor actor = Actor::New();
1517 actor.SetSize(100.0f, 100.0f);
1518 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1519 systemOverlay.Add(actor);
1521 // Render and notify
1522 application.SendNotification();
1523 application.Render();
1526 GestureReceivedFunctor functor(data);
1528 PanGestureDetector detector = PanGestureDetector::New();
1529 detector.Attach(actor);
1530 detector.DetectedSignal().Connect(&application, functor);
1532 Vector2 screenCoordsStart( 10.0f, 20.0f );
1533 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1535 // Start pan within the actor's area
1536 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1537 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1538 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1542 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1544 TestApplication application;
1545 Dali::Integration::Core& core = application.GetCore();
1546 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1547 systemOverlay.GetOverlayRenderTasks().CreateTask();
1549 // SystemOverlay actor
1550 Actor systemOverlayActor = Actor::New();
1551 systemOverlayActor.SetSize(100.0f, 100.0f);
1552 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1553 systemOverlay.Add(systemOverlayActor);
1556 Actor stageActor = Actor::New();
1557 stageActor.SetSize(100.0f, 100.0f);
1558 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1559 Stage::GetCurrent().Add(stageActor);
1561 // Render and notify
1562 application.SendNotification();
1563 application.Render();
1565 // Set system-overlay actor to touchable
1566 TouchEventData touchData;
1567 TouchEventDataFunctor touchFunctor( touchData );
1568 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1570 // Set stage actor to receive the gesture
1572 GestureReceivedFunctor functor(data);
1574 PanGestureDetector detector = PanGestureDetector::New();
1575 detector.Attach(stageActor);
1576 detector.DetectedSignal().Connect(&application, functor);
1578 Vector2 screenCoordsStart( 10.0f, 20.0f );
1579 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1581 // Start pan within the two actors' area
1582 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1583 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1584 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1585 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1586 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1591 // Do touch in the same area
1592 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1593 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1594 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1599 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1601 TestApplication application;
1602 Dali::Integration::Core& core = application.GetCore();
1603 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1604 systemOverlay.GetOverlayRenderTasks().CreateTask();
1606 // SystemOverlay actor
1607 Actor systemOverlayActor = Actor::New();
1608 systemOverlayActor.SetSize(100.0f, 100.0f);
1609 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1610 systemOverlay.Add(systemOverlayActor);
1613 Actor stageActor = Actor::New();
1614 stageActor.SetSize(100.0f, 100.0f);
1615 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1616 Stage::GetCurrent().Add(stageActor);
1618 // Render and notify
1619 application.SendNotification();
1620 application.Render();
1622 // Set stage actor to touchable
1623 TouchEventData touchData;
1624 TouchEventDataFunctor touchFunctor( touchData );
1625 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1627 // Set system-overlay actor to have the gesture
1629 GestureReceivedFunctor functor(data);
1631 PanGestureDetector detector = PanGestureDetector::New();
1632 detector.Attach(systemOverlayActor);
1633 detector.DetectedSignal().Connect(&application, functor);
1635 Vector2 screenCoordsStart( 10.0f, 20.0f );
1636 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1638 // Start pan within the two actors' area
1639 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1640 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1641 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1642 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1643 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1648 // Do touch in the same area
1649 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1650 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1651 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1656 int UtcDaliPanGestureAngleHandling(void)
1658 TestApplication application;
1660 PanGestureDetector detector = PanGestureDetector::New();
1661 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1662 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1664 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1665 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1666 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1668 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1670 tet_result( TET_PASS );
1674 if ( iter == endIter )
1676 tet_printf("%s, angle not added\n", TEST_LOCATION );
1677 tet_result( TET_FAIL );
1681 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1682 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1684 // Remove something not in the container.
1685 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1686 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1688 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1689 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1690 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1692 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1694 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1695 tet_result( TET_FAIL );
1700 detector.ClearAngles();
1701 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1705 inline float RadiansToDegrees( float radian )
1707 return radian * 180.0f / Math::PI;
1710 int UtcDaliPanGestureAngleOutOfRange(void)
1712 TestApplication application;
1714 PanGestureDetector detector = PanGestureDetector::New();
1715 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1716 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1722 detector.AddAngle( Degree(180.0f) );
1723 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1724 detector.ClearAngles();
1726 detector.AddAngle( Degree(190.0f) );
1727 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1728 detector.ClearAngles();
1730 detector.AddAngle( Degree(-190.0f) );
1731 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1732 detector.ClearAngles();
1734 detector.AddAngle( Degree(350.0f) );
1735 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1736 detector.ClearAngles();
1738 detector.AddAngle( Degree(-350.0f) );
1739 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1740 detector.ClearAngles();
1742 detector.AddAngle( Degree(370.0f) );
1743 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1744 detector.ClearAngles();
1746 detector.AddAngle( Degree(-370.0f) );
1747 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1748 detector.ClearAngles();
1754 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1755 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1756 detector.ClearAngles();
1758 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1759 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1760 detector.ClearAngles();
1762 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1763 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1764 detector.ClearAngles();
1766 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1767 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1768 detector.ClearAngles();
1772 int UtcDaliPanGestureAngleProcessing(void)
1774 TestApplication application;
1776 Actor parent = Actor::New();
1777 parent.SetSize(100.0f, 100.0f);
1778 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1779 Stage::GetCurrent().Add(parent);
1781 Actor child = Actor::New();
1782 child.SetSize(100.0f, 100.0f);
1783 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1786 // Render and notify
1787 application.SendNotification();
1788 application.Render();
1790 // Parent detector only requires up pans
1791 PanGestureDetector parentDetector = PanGestureDetector::New();
1792 parentDetector.Attach( parent );
1793 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1794 SignalData parentData;
1795 GestureReceivedFunctor parentFunctor(parentData);
1796 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1798 // Child detector only requires right pans
1799 PanGestureDetector childDetector = PanGestureDetector::New();
1800 childDetector.Attach( child );
1801 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1802 SignalData childData;
1803 GestureReceivedFunctor childFunctor(childData);
1804 childDetector.DetectedSignal().Connect(&application, childFunctor);
1806 // Generate an Up pan gesture, only parent should receive it.
1807 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1808 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1809 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1810 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1811 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1815 // Generate a Right pan gesture, only child should receive it.
1816 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1817 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1818 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1819 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1820 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1824 // Generate a Down pan gesture, no one should receive it.
1825 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1826 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1827 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1828 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1829 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1833 // Generate a Left pan gesture, no one should receive it.
1834 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1835 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1836 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1837 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1838 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1844 int UtcDaliPanGestureDirectionHandling(void)
1846 TestApplication application;
1848 PanGestureDetector detector = PanGestureDetector::New();
1849 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1850 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1852 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1853 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1854 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1856 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1858 tet_result( TET_PASS );
1862 if ( iter == endIter )
1864 tet_printf("%s, angle not added\n", TEST_LOCATION );
1865 tet_result( TET_FAIL );
1869 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1871 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1873 tet_result( TET_PASS );
1877 if ( iter == endIter )
1879 tet_printf("%s, angle not added\n", TEST_LOCATION );
1880 tet_result( TET_FAIL );
1884 // Remove something not in the container.
1885 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1886 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1888 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1889 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1893 int UtcDaliPanGestureDirectionProcessing(void)
1895 TestApplication application;
1897 Actor parent = Actor::New();
1898 parent.SetSize(100.0f, 100.0f);
1899 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1900 Stage::GetCurrent().Add(parent);
1902 Actor child = Actor::New();
1903 child.SetSize(100.0f, 100.0f);
1904 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1907 // Render and notify
1908 application.SendNotification();
1909 application.Render();
1911 // Parent detector only requires vertical panning
1912 PanGestureDetector parentDetector = PanGestureDetector::New();
1913 parentDetector.Attach( parent );
1914 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1915 SignalData parentData;
1916 GestureReceivedFunctor parentFunctor(parentData);
1917 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1919 // Child detector only requires horizontal panning
1920 PanGestureDetector childDetector = PanGestureDetector::New();
1921 childDetector.Attach( child );
1922 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1923 SignalData childData;
1924 GestureReceivedFunctor childFunctor(childData);
1925 childDetector.DetectedSignal().Connect(&application, childFunctor);
1927 // Generate an Up pan gesture, only parent should receive it.
1928 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1929 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1930 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1931 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1932 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1936 // Generate a Right pan gesture, only child should receive it.
1937 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1938 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1939 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1940 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1941 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1945 // Generate a Down pan gesture, only parent should receive it.
1946 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1947 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1948 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1949 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1950 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1954 // Generate a Left pan gesture, only child should receive it.
1955 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1956 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1957 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1958 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1959 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1963 // Generate a pan at -45 degrees, no one should receive it.
1964 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1965 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1966 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1967 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1968 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1972 // Generate a pan at 45 degrees, no one should receive it.
1973 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1974 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
1975 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1976 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1977 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1981 // Generate a pan at 135 degrees, no one should receive it.
1982 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1983 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1984 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1985 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1986 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1990 // Generate a pan at -135 degrees, no one should receive it.
1991 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1992 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
1993 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1994 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1995 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2001 int UtcDaliPanGestureSetProperties(void)
2003 TestApplication application;
2004 TestRenderController& renderController( application.GetRenderController() );
2005 Integration::SetPanGesturePredictionMode(0);
2007 Actor actor = Actor::New();
2008 actor.SetSize(100.0f, 100.0f);
2009 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2010 Stage::GetCurrent().Add(actor);
2012 // Add a pan detector
2013 PanGestureDetector detector = PanGestureDetector::New();
2014 detector.Attach( actor );
2016 GestureReceivedFunctor functor( data );
2017 detector.DetectedSignal().Connect( &application, functor );
2019 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2021 ConstraintData constraintData;
2022 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2023 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2024 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2025 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2026 PanConstraint( constraintData ) ) );
2028 // Render and notify
2029 application.SendNotification();
2030 application.Render();
2032 renderController.Initialize();
2033 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2035 Vector2 screenPosition( 20.0f, 20.0f );
2036 Vector2 screenDisplacement( 1.0f, 1.0f );
2037 Vector2 localPosition( 21.0f, 21.0f );
2038 Vector2 localDisplacement( 0.5f, 0.5f );
2040 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement ) );
2041 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2043 // Render and notify
2044 application.SendNotification();
2045 application.Render();
2047 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2048 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2049 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2050 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2051 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2052 constraintData.Reset();
2056 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2058 TestApplication application;
2059 Integration::SetPanGesturePredictionMode(0);
2061 Actor actor = Actor::New();
2062 actor.SetSize(100.0f, 100.0f);
2063 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2064 Stage::GetCurrent().Add(actor);
2066 // Add a pan detector
2067 PanGestureDetector detector = PanGestureDetector::New();
2068 detector.Attach( actor );
2070 GestureReceivedFunctor functor( data );
2071 detector.DetectedSignal().Connect( &application, functor );
2073 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2075 ConstraintData constraintData;
2076 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2077 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2078 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2079 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2080 PanConstraint( constraintData ) ) );
2082 // Render and notify
2083 application.SendNotification();
2084 application.Render();
2086 Vector2 previousPosition( 20.0f, 20.0f );
2087 Vector2 currentPosition( 20.0f, 10.0f );
2088 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2089 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2090 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2092 Vector2 screenPosition( 100.0f, 20.0f );
2093 Vector2 localPosition( 110.0f, 110.0f );
2095 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2097 // Render and notify
2098 application.SendNotification();
2099 application.Render();
2101 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2102 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2103 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2104 constraintData.Reset();
2108 int UtcDaliPanGesturePropertyIndices(void)
2110 TestApplication application;
2111 PanGestureDetector detector = PanGestureDetector::New();
2113 Property::IndexContainer indices;
2114 detector.GetPropertyIndices( indices );
2115 DALI_TEST_CHECK( ! indices.empty() );
2116 DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );