2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali/integration-api/events/touch-event-integ.h>
22 #include <dali/integration-api/events/pan-gesture-event.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali/integration-api/profiling.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-touch-utils.h>
30 void utc_dali_pan_gesture_detector_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_pan_gesture_detector_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
43 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
46 // Stores data that is populated in the callback and will be read by the test cases
50 : functorCalled(false),
51 voidFunctorCalled(false),
52 receivedGesture(Gesture::Clear)
57 functorCalled = false;
58 voidFunctorCalled = false;
60 receivedGesture.state = Gesture::Clear;
61 receivedGesture.velocity = Vector2(0.0f, 0.0f);
62 receivedGesture.displacement = Vector2(0.0f, 0.0f);
63 receivedGesture.position = Vector2(0.0f, 0.0f);
64 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
65 receivedGesture.numberOfTouches = 0;
71 bool voidFunctorCalled;
72 PanGesture receivedGesture;
76 // Functor that sets the data when called
77 struct GestureReceivedFunctor
79 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
81 void operator()(Actor actor, PanGesture pan)
83 signalData.functorCalled = true;
84 signalData.receivedGesture = pan;
85 signalData.pannedActor = actor;
90 signalData.voidFunctorCalled = true;
93 SignalData& signalData;
96 // Functor that removes the gestured actor from stage
97 struct UnstageActorFunctor : public GestureReceivedFunctor
99 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
100 : GestureReceivedFunctor( data ),
101 stateToUnstage( stateToUnstage )
105 void operator()( Actor actor, PanGesture pan )
107 GestureReceivedFunctor::operator()( actor, pan );
109 if ( pan.state == stateToUnstage )
111 Stage::GetCurrent().Remove( actor );
115 Gesture::State& stateToUnstage;
118 // Functor for receiving a touch event
119 struct TouchEventFunctor
121 bool operator()(Actor actor, const TouchEvent& touch)
127 // Data for constraints
128 struct ConstraintData
135 Vector2 screenPosition;
136 Vector2 screenDisplacement;
137 Vector2 localPosition;
138 Vector2 localDisplacement;
143 screenPosition = screenDisplacement = localPosition = localDisplacement = Vector2::ZERO;
148 // Constraint used with panning properties
151 PanConstraint( ConstraintData& data ) : constraintData(data) { }
153 Vector3 operator()(const Vector3& current,
154 const PropertyInput& screenPositionProperty,
155 const PropertyInput& screenDisplacementProperty,
156 const PropertyInput& localPositionProperty,
157 const PropertyInput& localDisplacementProperty)
159 constraintData.screenPosition = screenPositionProperty.GetVector2();
160 constraintData.screenDisplacement = screenDisplacementProperty.GetVector2();
161 constraintData.localPosition = localPositionProperty.GetVector2();
162 constraintData.localDisplacement = localDisplacementProperty.GetVector2();
163 constraintData.called = true;
164 return Vector3::ZERO;
167 ConstraintData& constraintData;
170 // Generate a PanGestureEvent to send to Core
171 Integration::PanGestureEvent GeneratePan(
172 Gesture::State state,
173 Vector2 previousPosition,
174 Vector2 currentPosition,
175 unsigned long timeDelta,
176 unsigned int numberOfTouches = 1,
177 unsigned int time = 1u)
179 Integration::PanGestureEvent pan(state);
181 pan.previousPosition = previousPosition;
182 pan.currentPosition = currentPosition;
183 pan.timeDelta = timeDelta;
184 pan.numberOfTouches = numberOfTouches;
190 // Generate a PanGesture
191 PanGesture GeneratePan( unsigned int time,
192 Gesture::State state,
193 Vector2 screenPosition,
194 Vector2 localPosition,
195 Vector2 screenDisplacement = Vector2::ONE,
196 Vector2 localDisplacement = Vector2::ONE,
197 Vector2 velocity = Vector2::ONE,
198 unsigned int numberOfTouches = 1 )
200 PanGesture pan( state );
204 pan.screenPosition = screenPosition;
205 pan.position = localPosition;
207 pan.screenDisplacement = screenDisplacement;
208 pan.displacement = localDisplacement;
210 pan.screenVelocity = pan.velocity = velocity;
211 pan.numberOfTouches = numberOfTouches;
218 ///////////////////////////////////////////////////////////////////////////////
220 // Positive test case for a method
221 int UtcDaliPanGestureDetectorConstructor(void)
223 TestApplication application;
225 PanGestureDetector detector;
226 DALI_TEST_CHECK(!detector);
231 // Negative test case for a method
232 int UtcDaliPanGestureDetectorNew(void)
234 TestApplication application;
236 PanGestureDetector detector = PanGestureDetector::New();
238 DALI_TEST_CHECK(detector);
240 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
241 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
243 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
244 Actor actor = Actor::New();
245 actor.SetSize(100.0f, 100.0f);
246 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
247 detector.Attach(actor);
249 Stage::GetCurrent().Add(actor);
252 application.SendNotification();
253 application.Render();
255 Integration::TouchEvent touchEvent(1);
256 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
257 touchEvent.AddPoint(point);
258 application.ProcessEvent(touchEvent);
262 int UtcDaliPanGestureDetectorDownCast(void)
264 TestApplication application;
265 tet_infoline("Testing Dali::GestureDetector::DownCast()");
267 PanGestureDetector detector = PanGestureDetector::New();
269 BaseHandle object(detector);
271 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
272 DALI_TEST_CHECK(detector2);
274 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
275 DALI_TEST_CHECK(detector3);
277 BaseHandle unInitializedObject;
278 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
279 DALI_TEST_CHECK(!detector4);
281 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
282 DALI_TEST_CHECK(!detector5);
284 GestureDetector detector6 = PanGestureDetector::New();
285 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
286 DALI_TEST_CHECK(detector7);
290 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
292 TestApplication application;
294 PanGestureDetector detector = PanGestureDetector::New();
296 unsigned int min = 2;
298 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
300 detector.SetMinimumTouchesRequired(min);
302 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
304 // Attach an actor and change the minimum touches
306 Actor actor = Actor::New();
307 actor.SetSize(100.0f, 100.0f);
308 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
309 Stage::GetCurrent().Add(actor);
312 application.SendNotification();
313 application.Render();
316 GestureReceivedFunctor functor(data);
318 detector.Attach(actor);
319 detector.DetectedSignal().Connect(&application, functor);
321 TestGestureManager& gestureManager = application.GetGestureManager();
322 gestureManager.Initialize();
324 detector.SetMinimumTouchesRequired(3);
326 // Gesture detection should have been updated only
327 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
328 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
329 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
332 gestureManager.Initialize();
334 // Create a second gesture detector that requires even less minimum touches
335 PanGestureDetector secondDetector = PanGestureDetector::New();
336 secondDetector.Attach(actor);
338 // Gesture detection should have been updated only
339 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
340 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
341 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
345 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
347 TestApplication application;
349 PanGestureDetector detector = PanGestureDetector::New();
351 unsigned int max = 3;
353 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
355 detector.SetMaximumTouchesRequired(max);
357 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
359 // Attach an actor and change the maximum touches
361 Actor actor = Actor::New();
362 actor.SetSize(100.0f, 100.0f);
363 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
364 Stage::GetCurrent().Add(actor);
367 application.SendNotification();
368 application.Render();
371 GestureReceivedFunctor functor(data);
373 detector.Attach(actor);
374 detector.DetectedSignal().Connect(&application, functor);
376 TestGestureManager& gestureManager = application.GetGestureManager();
377 gestureManager.Initialize();
379 detector.SetMaximumTouchesRequired(4);
381 // Gesture detection should have been updated only
382 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
383 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
384 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
387 gestureManager.Initialize();
389 // Create a second gesture detector that requires even less maximum touches
390 PanGestureDetector secondDetector = PanGestureDetector::New();
391 secondDetector.Attach(actor);
393 // Gesture detection should NOT have been updated
394 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
395 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
396 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
400 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
402 TestApplication application;
404 PanGestureDetector detector = PanGestureDetector::New();
405 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
409 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
411 TestApplication application;
413 PanGestureDetector detector = PanGestureDetector::New();
414 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
418 int UtcDaliPanGestureSignalReceptionNegative(void)
420 TestApplication application;
422 Actor actor = Actor::New();
423 actor.SetSize(100.0f, 100.0f);
424 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
425 Stage::GetCurrent().Add(actor);
428 application.SendNotification();
429 application.Render();
432 GestureReceivedFunctor functor(data);
434 PanGestureDetector detector = PanGestureDetector::New();
435 detector.Attach(actor);
436 detector.DetectedSignal().Connect(&application, functor);
438 // Do a pan outside actor's area
439 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
440 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
441 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
443 // Continue pan into actor's area - we should still not receive the signal
445 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
446 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
448 // Stop panning - we should still not receive the signal
450 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
451 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
455 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
457 TestApplication application;
459 Actor actor = Actor::New();
460 actor.SetSize(100.0f, 100.0f);
461 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
462 Stage::GetCurrent().Add(actor);
465 application.SendNotification();
466 application.Render();
469 GestureReceivedFunctor functor(data);
471 PanGestureDetector detector = PanGestureDetector::New();
472 detector.Attach(actor);
473 detector.DetectedSignal().Connect(&application, functor);
475 // Start pan within the actor's area
476 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
477 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
478 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
479 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
480 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
481 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
482 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
483 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
484 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
486 // Continue the pan within the actor's area - we should still receive the signal
488 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
489 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
490 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
491 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
492 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
493 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
494 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
495 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
497 // Pan Gesture leaves actor's area - we should still receive the signal
499 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
500 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
501 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
502 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
503 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
504 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
505 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
506 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
508 // Gesture ends - we would receive a finished state
510 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
511 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
512 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
513 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
514 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
515 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
516 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
517 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
521 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
523 TestApplication application;
525 Actor actor = Actor::New();
526 actor.SetSize(100.0f, 100.0f);
527 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
528 Stage::GetCurrent().Add(actor);
531 application.SendNotification();
532 application.Render();
535 GestureReceivedFunctor functor(data);
537 PanGestureDetector detector = PanGestureDetector::New();
538 detector.Attach(actor);
539 detector.DetectedSignal().Connect(&application, functor);
541 // Start pan within the actor's area
542 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
543 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
544 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
545 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
546 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
547 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
548 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
549 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
550 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
552 // Continue the pan within the actor's area - we should still receive the signal
554 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
555 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
556 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
557 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
558 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
559 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
561 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
563 // Gesture ends within actor's area - we would receive a finished state
565 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
566 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
567 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
568 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
569 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
570 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
571 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
572 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
576 int UtcDaliPanGestureSignalReceptionCancelled(void)
578 TestApplication application;
580 Actor actor = Actor::New();
581 actor.SetSize(100.0f, 100.0f);
582 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
583 Stage::GetCurrent().Add(actor);
586 application.SendNotification();
587 application.Render();
590 GestureReceivedFunctor functor(data);
592 PanGestureDetector detector = PanGestureDetector::New();
593 detector.Attach(actor);
594 detector.DetectedSignal().Connect(&application, functor);
596 // Start pan within the actor's area
597 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
598 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
599 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
600 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
602 // Continue the pan within the actor's area - we should still receive the signal
604 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
605 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
606 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
608 // The gesture is cancelled
610 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
611 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
616 int UtcDaliPanGestureSignalReceptionDetach(void)
618 TestApplication application;
620 Actor actor = Actor::New();
621 actor.SetSize(100.0f, 100.0f);
622 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
623 Stage::GetCurrent().Add(actor);
626 application.SendNotification();
627 application.Render();
630 GestureReceivedFunctor functor(data);
632 PanGestureDetector detector = PanGestureDetector::New();
633 detector.Attach(actor);
634 detector.DetectedSignal().Connect(&application, functor);
636 // Start pan within the actor's area
637 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
638 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
639 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
641 // Continue the pan within the actor's area - we should still receive the signal
643 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
644 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
646 // Gesture ends within actor's area
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);
652 detector.DetachAll();
654 // Ensure we are no longer signalled
656 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
657 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
658 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
659 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
660 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
664 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
666 TestApplication application;
668 Actor actor = Actor::New();
669 actor.SetSize(100.0f, 100.0f);
670 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
671 Stage::GetCurrent().Add(actor);
674 application.SendNotification();
675 application.Render();
678 GestureReceivedFunctor functor(data);
680 PanGestureDetector detector = PanGestureDetector::New();
681 detector.Attach(actor);
682 detector.DetectedSignal().Connect(&application, functor);
684 // Start pan within the actor's area
685 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
686 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
687 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
689 // Continue the pan within the actor's area - we should still receive the signal
691 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
692 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
694 // Detach actor during the pan, we should not receive the next event
695 detector.DetachAll();
697 // Gesture ends within actor's area
699 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
700 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
704 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
706 TestApplication application;
709 GestureReceivedFunctor functor(data);
711 PanGestureDetector detector = PanGestureDetector::New();
712 detector.DetectedSignal().Connect(&application, functor);
714 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
716 Actor tempActor = Actor::New();
717 tempActor.SetSize(100.0f, 100.0f);
718 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
719 Stage::GetCurrent().Add(tempActor);
720 detector.Attach(tempActor);
722 // Actor lifetime is scoped
724 Actor actor = Actor::New();
725 actor.SetSize(100.0f, 100.0f);
726 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
727 Stage::GetCurrent().Add(actor);
730 application.SendNotification();
731 application.Render();
733 detector.Attach(actor);
735 // Start pan within the actor's area
736 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
737 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
738 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
740 // Continue the pan within the actor's area - we should still receive the signal
742 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
743 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
745 // Remove the actor from stage and reset the data
746 Stage::GetCurrent().Remove(actor);
749 application.SendNotification();
750 application.Render();
753 // Actor should now have been destroyed
755 // Gesture ends within the area where the actor used to be
757 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
758 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
762 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
764 TestApplication application;
766 Actor actor = Actor::New();
767 actor.SetSize(100.0f, 100.0f);
768 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
769 Stage::GetCurrent().Add(actor);
772 application.SendNotification();
773 application.Render();
776 GestureReceivedFunctor functor(data);
778 PanGestureDetector detector = PanGestureDetector::New();
779 detector.Attach(actor);
780 detector.DetectedSignal().Connect(&application, functor);
782 // Do an entire pan, only check finished value
783 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
784 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
786 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
787 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
788 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
790 // Rotate actor again and render a couple of times
791 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
792 application.SendNotification();
793 application.Render();
795 // Do an entire pan, only check finished value
796 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
797 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
799 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
800 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
801 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
803 // Rotate actor again and render a couple of times
804 actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
805 application.SendNotification();
806 application.Render();
808 // Do an entire pan, only check finished value
809 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
810 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
812 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
813 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
814 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
818 int UtcDaliPanGestureSignalReceptionChildHit(void)
820 TestApplication application;
822 Actor parent = Actor::New();
823 parent.SetSize(100.0f, 100.0f);
824 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
825 Stage::GetCurrent().Add(parent);
827 // Set child to completely cover parent.
828 // Change rotation of child to be different from parent so that we can check if our local coordinate
829 // conversion of the parent actor is correct.
830 Actor child = Actor::New();
831 child.SetSize(100.0f, 100.0f);
832 child.SetAnchorPoint(AnchorPoint::CENTER);
833 child.SetParentOrigin(ParentOrigin::CENTER);
834 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
837 TouchEventFunctor touchFunctor;
838 child.TouchedSignal().Connect(&application, touchFunctor);
841 application.SendNotification();
842 application.Render();
845 GestureReceivedFunctor functor(data);
847 PanGestureDetector detector = PanGestureDetector::New();
848 detector.Attach(parent);
849 detector.DetectedSignal().Connect(&application, functor);
851 // Do an entire pan, only check finished value - hits child area but parent should still receive it
852 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
853 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
855 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
856 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
857 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
858 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
860 // Attach child and generate same touch points to yield a different displacement
861 // (Also proves that you can detach and then re-attach another actor)
862 detector.Attach(child);
863 detector.Detach(parent);
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(true, child == data.pannedActor, TEST_LOCATION);
872 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
876 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
878 TestApplication application;
880 Actor first = Actor::New();
881 first.SetSize(100.0f, 100.0f);
882 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
883 Stage::GetCurrent().Add(first);
885 Actor second = Actor::New();
886 second.SetSize(100.0f, 100.0f);
888 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
889 Stage::GetCurrent().Add(second);
892 application.SendNotification();
893 application.Render();
896 GestureReceivedFunctor functor(data);
898 PanGestureDetector detector = PanGestureDetector::New();
899 detector.Attach(first);
900 detector.Attach(second);
901 detector.DetectedSignal().Connect(&application, functor);
903 // Start pan within second actor's area
904 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
905 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
906 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
907 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
909 // Pan moves into first actor's area - second actor should receive the pan
911 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
912 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
913 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
915 // Detach the second actor during the pan, we should not receive the next event
916 detector.Detach(second);
918 // Gesture ends within actor's area
920 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
921 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
925 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
927 TestApplication application;
929 Actor actor = Actor::New();
930 actor.SetSize(100.0f, 100.0f);
931 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
932 Stage::GetCurrent().Add(actor);
935 application.SendNotification();
936 application.Render();
939 GestureReceivedFunctor functor(data);
941 PanGestureDetector detector = PanGestureDetector::New();
942 detector.Attach(actor);
943 detector.DetectedSignal().Connect(&application, functor);
945 // Start pan in actor's area
946 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
947 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
948 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
950 // Pan continues within actor's area
952 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
953 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
955 // Actor become invisible - actor should not receive the next pan
956 actor.SetVisible(false);
959 application.SendNotification();
960 application.Render();
962 // Gesture ends within actor's area
964 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
965 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
969 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
971 TestApplication application;
972 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
974 Actor first = Actor::New();
975 first.SetSize(100.0f, 100.0f);
976 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
977 Stage::GetCurrent().Add(first);
979 Actor second = Actor::New();
980 second.SetSize(100.0f, 100.0f);
981 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
985 application.SendNotification();
986 application.Render();
989 GestureReceivedFunctor functor(data);
991 PanGestureDetector firstDetector = PanGestureDetector::New();
992 firstDetector.Attach(first);
993 firstDetector.DetectedSignal().Connect(&application, functor);
995 // secondDetector is scoped
997 // Reset gestureManager statistics
998 gestureManager.Initialize();
1000 PanGestureDetector secondDetector = PanGestureDetector::New();
1001 secondDetector.SetMinimumTouchesRequired(2);
1002 secondDetector.SetMaximumTouchesRequired(2);
1003 secondDetector.Attach(second);
1004 secondDetector.DetectedSignal().Connect(&application, functor);
1006 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1007 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1008 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1010 // Start pan within second actor's area
1011 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1012 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1013 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1014 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1016 // Two touch pan changes to single touch - we should receive a finished state
1018 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1019 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1020 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1021 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1023 // Pan continues as single touch gesture - we should not receive any gesture
1025 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1026 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1028 // Pan ends - still no signal
1030 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1031 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1033 // Single touch pan starts - first actor should be panned
1035 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1036 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1037 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1038 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1040 // Pan changes to double-touch - we should receive a finished state
1042 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1043 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1044 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1045 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1047 // Pan continues as double touch gesture - we should not receive any gesture
1049 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1050 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1052 // Pan ends - still no signal
1054 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1055 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1057 // Reset gesture manager statistics
1058 gestureManager.Initialize();
1061 // secondDetector has now been deleted. Gesture detection should have been updated only
1062 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1063 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1064 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1068 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1070 TestApplication application;
1072 Actor actor = Actor::New();
1073 actor.SetSize(100.0f, 100.0f);
1074 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1075 Stage::GetCurrent().Add(actor);
1077 Actor actor2 = Actor::New();
1078 actor2.SetSize(100.0f, 100.0f);
1079 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1080 Stage::GetCurrent().Add(actor2);
1082 // Render and notify
1083 application.SendNotification();
1084 application.Render();
1086 // Attach actor to one detector
1087 SignalData firstData;
1088 GestureReceivedFunctor firstFunctor(firstData);
1089 PanGestureDetector firstDetector = PanGestureDetector::New();
1090 firstDetector.Attach(actor);
1091 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1093 // Attach actor to another detector
1094 SignalData secondData;
1095 GestureReceivedFunctor secondFunctor(secondData);
1096 PanGestureDetector secondDetector = PanGestureDetector::New();
1097 secondDetector.Attach(actor);
1098 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1100 // Add second actor to second detector, when we remove the actor, this will make sure that this
1101 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1102 // functor should still not be called (which is what we're also testing).
1103 secondDetector.Attach(actor2);
1105 // Pan in actor's area - both detector's functors should be called
1106 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1107 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1108 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1109 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1111 // Pan continues in actor's area - both detector's functors should be called
1114 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1115 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1116 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1118 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1119 firstDetector.Detach(actor);
1122 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1123 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1124 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1126 // New pan on actor, only secondDetector has actor attached
1129 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1130 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1131 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1132 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1134 // Detach actor from secondDetector
1135 secondDetector.Detach(actor);
1138 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1139 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1140 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1144 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1146 // Should handle two started events gracefully.
1148 TestApplication application;
1150 Actor actor = Actor::New();
1151 actor.SetSize(100.0f, 100.0f);
1152 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1153 Stage::GetCurrent().Add(actor);
1156 GestureReceivedFunctor functor(data);
1158 PanGestureDetector detector = PanGestureDetector::New();
1159 detector.Attach(actor);
1160 detector.DetectedSignal().Connect(&application, functor);
1162 // Render and notify
1163 application.SendNotification();
1164 application.Render();
1166 // Start pan in actor's area
1167 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1168 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1169 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1171 // Send another start in actor's area
1173 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1174 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1176 // Add a child actor to overlap actor and send another start in actor's area
1177 Actor child = Actor::New();
1178 child.SetSize(100.0f, 100.0f);
1179 child.SetAnchorPoint(AnchorPoint::CENTER);
1180 child.SetParentOrigin(ParentOrigin::CENTER);
1183 TouchEventFunctor touchFunctor;
1184 child.TouchedSignal().Connect(&application, touchFunctor);
1186 // Render and notify
1187 application.SendNotification();
1188 application.Render();
1190 // Send another possible and start in actor's area
1192 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1193 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1194 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1196 // Send another start in actor's area
1198 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1199 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1200 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1204 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1206 TestApplication application;
1208 Actor actor1 = Actor::New();
1209 actor1.SetSize(100.0f, 100.0f);
1210 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1211 Stage::GetCurrent().Add(actor1);
1213 GestureReceivedFunctor functor1(data1);
1214 PanGestureDetector detector1 = PanGestureDetector::New();
1215 detector1.Attach(actor1);
1216 detector1.DetectedSignal().Connect(&application, functor1);
1218 Actor actor2 = Actor::New();
1219 actor2.SetSize(100.0f, 100.0f);
1220 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1221 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1222 Stage::GetCurrent().Add(actor2);
1224 GestureReceivedFunctor functor2(data2);
1225 PanGestureDetector detector2 = PanGestureDetector::New();
1226 detector2.Attach(actor2);
1227 detector2.DetectedSignal().Connect(&application, functor2);
1229 // Render and notify
1230 application.SendNotification();
1231 application.Render();
1233 // Start pan in actor1's area, only data1 should be set
1234 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1235 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1236 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1237 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1241 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1243 TestApplication application;
1245 Actor actor = Actor::New();
1246 actor.SetSize(100.0f, 100.0f);
1247 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1248 Stage::GetCurrent().Add(actor);
1250 // Render and notify
1251 application.SendNotification();
1252 application.Render();
1254 // Attach actor to detector
1256 GestureReceivedFunctor functor( data );
1257 PanGestureDetector detector = PanGestureDetector::New();
1258 detector.Attach(actor);
1259 detector.DetectedSignal().Connect( &application, functor );
1261 // Gesture possible in actor's area.
1262 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1263 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1265 // Move actor somewhere else
1266 actor.SetPosition( 100.0f, 100.0f );
1268 // Render and notify
1269 application.SendNotification();
1270 application.Render();
1272 // Emit Started event, we should not receive the long press.
1273 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1274 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1275 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1277 // LongPress possible in empty area.
1278 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1279 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1281 // Move actor in to the long press position.
1282 actor.SetPosition( 0.0f, 0.0f );
1284 // Render and notify
1285 application.SendNotification();
1286 application.Render();
1288 // Emit Started event, we should not receive the long press.
1289 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1290 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1291 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1293 // Normal long press in actor's area for completeness.
1294 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1295 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1296 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1297 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1301 int UtcDaliPanGestureEmitIncorrectState(void)
1303 TestApplication application;
1305 Actor actor = Actor::New();
1306 actor.SetSize(100.0f, 100.0f);
1307 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1308 Stage::GetCurrent().Add(actor);
1310 // Render and notify
1311 application.SendNotification();
1312 application.Render();
1314 // Attach actor to detector
1316 GestureReceivedFunctor functor( data );
1317 PanGestureDetector detector = PanGestureDetector::New();
1318 detector.Attach(actor);
1319 detector.DetectedSignal().Connect( &application, functor );
1321 // Try a Clear state
1324 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1325 tet_result(TET_FAIL);
1327 catch ( Dali::DaliException& e )
1329 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1334 int UtcDaliPanGestureActorUnstaged(void)
1336 TestApplication application;
1338 Actor actor = Actor::New();
1339 actor.SetSize(100.0f, 100.0f);
1340 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1341 Stage::GetCurrent().Add(actor);
1343 // Render and notify
1344 application.SendNotification();
1345 application.Render();
1347 // State to remove actor in.
1348 Gesture::State stateToUnstage( Gesture::Started );
1350 // Attach actor to detector
1352 UnstageActorFunctor functor( data, stateToUnstage );
1353 PanGestureDetector detector = PanGestureDetector::New();
1354 detector.Attach(actor);
1355 detector.DetectedSignal().Connect( &application, functor );
1358 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1359 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1360 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1362 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1363 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1366 // Render and notify
1367 application.SendNotification();
1368 application.Render();
1370 // Re-add actor to stage
1371 Stage::GetCurrent().Add(actor);
1373 // Render and notify
1374 application.SendNotification();
1375 application.Render();
1377 // Change state to Gesture::Continuing to remove
1378 stateToUnstage = Gesture::Continuing;
1381 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1382 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1383 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1385 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1386 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1388 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1389 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1392 // Render and notify
1393 application.SendNotification();
1394 application.Render();
1396 // Re-add actor to stage
1397 Stage::GetCurrent().Add(actor);
1399 // Render and notify
1400 application.SendNotification();
1401 application.Render();
1403 // Change state to Gesture::Finished to remove
1404 stateToUnstage = Gesture::Finished;
1407 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1408 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1409 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1411 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1412 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1414 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1415 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1416 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1420 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1422 TestApplication application;
1424 Actor actor = Actor::New();
1425 actor.SetSize(100.0f, 100.0f);
1426 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1427 Stage::GetCurrent().Add(actor);
1429 // Create and add a second actor so that GestureDetector destruction does not come into play.
1430 Actor dummyActor( Actor::New() );
1431 dummyActor.SetSize( 100.0f, 100.0f );
1432 dummyActor.SetPosition( 100.0f, 100.0f );
1433 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1434 Stage::GetCurrent().Add(dummyActor);
1436 // Render and notify
1437 application.SendNotification();
1438 application.Render();
1440 // State to remove actor in.
1441 Gesture::State stateToUnstage( Gesture::Started );
1443 // Attach actor to detector
1445 UnstageActorFunctor functor( data, stateToUnstage );
1446 PanGestureDetector detector = PanGestureDetector::New();
1447 detector.Attach(actor);
1448 detector.Attach(dummyActor);
1449 detector.DetectedSignal().Connect( &application, functor );
1451 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1452 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1453 // position, we should still not be signalled.
1456 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1457 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1458 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1461 // Render and notify
1462 application.SendNotification();
1463 application.Render();
1465 // Re add to the stage, we should not be signalled
1466 Stage::GetCurrent().Add(actor);
1468 // Render and notify
1469 application.SendNotification();
1470 application.Render();
1472 // Continue signal emission
1473 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1474 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1476 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1477 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1480 // Here we delete an actor in started, we should not receive any subsequent signalling.
1483 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1484 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1485 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1488 // Render and notify
1489 application.SendNotification();
1490 application.Render();
1492 // Delete actor as well
1495 // Render and notify
1496 application.SendNotification();
1497 application.Render();
1499 // Continue signal emission
1500 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1501 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1503 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1504 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1508 int UtcDaliPanGestureSystemOverlay(void)
1510 TestApplication application;
1511 Dali::Integration::Core& core = application.GetCore();
1512 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1513 systemOverlay.GetOverlayRenderTasks().CreateTask();
1515 Actor actor = Actor::New();
1516 actor.SetSize(100.0f, 100.0f);
1517 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1518 systemOverlay.Add(actor);
1520 // Render and notify
1521 application.SendNotification();
1522 application.Render();
1525 GestureReceivedFunctor functor(data);
1527 PanGestureDetector detector = PanGestureDetector::New();
1528 detector.Attach(actor);
1529 detector.DetectedSignal().Connect(&application, functor);
1531 Vector2 screenCoordsStart( 10.0f, 20.0f );
1532 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1534 // Start pan within the actor's area
1535 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1536 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1537 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1541 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1543 TestApplication application;
1544 Dali::Integration::Core& core = application.GetCore();
1545 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1546 systemOverlay.GetOverlayRenderTasks().CreateTask();
1548 // SystemOverlay actor
1549 Actor systemOverlayActor = Actor::New();
1550 systemOverlayActor.SetSize(100.0f, 100.0f);
1551 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1552 systemOverlay.Add(systemOverlayActor);
1555 Actor stageActor = Actor::New();
1556 stageActor.SetSize(100.0f, 100.0f);
1557 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1558 Stage::GetCurrent().Add(stageActor);
1560 // Render and notify
1561 application.SendNotification();
1562 application.Render();
1564 // Set system-overlay actor to touchable
1565 TouchEventData touchData;
1566 TouchEventDataFunctor touchFunctor( touchData );
1567 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1569 // Set stage actor to receive the gesture
1571 GestureReceivedFunctor functor(data);
1573 PanGestureDetector detector = PanGestureDetector::New();
1574 detector.Attach(stageActor);
1575 detector.DetectedSignal().Connect(&application, functor);
1577 Vector2 screenCoordsStart( 10.0f, 20.0f );
1578 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1580 // Start pan within the two actors' area
1581 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1582 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1583 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1584 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1585 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1590 // Do touch in the same area
1591 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1592 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1593 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1598 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1600 TestApplication application;
1601 Dali::Integration::Core& core = application.GetCore();
1602 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1603 systemOverlay.GetOverlayRenderTasks().CreateTask();
1605 // SystemOverlay actor
1606 Actor systemOverlayActor = Actor::New();
1607 systemOverlayActor.SetSize(100.0f, 100.0f);
1608 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1609 systemOverlay.Add(systemOverlayActor);
1612 Actor stageActor = Actor::New();
1613 stageActor.SetSize(100.0f, 100.0f);
1614 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1615 Stage::GetCurrent().Add(stageActor);
1617 // Render and notify
1618 application.SendNotification();
1619 application.Render();
1621 // Set stage actor to touchable
1622 TouchEventData touchData;
1623 TouchEventDataFunctor touchFunctor( touchData );
1624 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1626 // Set system-overlay actor to have the gesture
1628 GestureReceivedFunctor functor(data);
1630 PanGestureDetector detector = PanGestureDetector::New();
1631 detector.Attach(systemOverlayActor);
1632 detector.DetectedSignal().Connect(&application, functor);
1634 Vector2 screenCoordsStart( 10.0f, 20.0f );
1635 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1637 // Start pan within the two actors' area
1638 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1639 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1640 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1641 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1642 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1647 // Do touch in the same area
1648 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1649 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1650 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1655 int UtcDaliPanGestureAngleHandling(void)
1657 TestApplication application;
1659 PanGestureDetector detector = PanGestureDetector::New();
1660 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1661 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1663 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1664 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1665 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1667 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1669 tet_result( TET_PASS );
1673 if ( iter == endIter )
1675 tet_printf("%s, angle not added\n", TEST_LOCATION );
1676 tet_result( TET_FAIL );
1680 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1681 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1683 // Remove something not in the container.
1684 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1685 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1687 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1688 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1689 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1691 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1693 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1694 tet_result( TET_FAIL );
1699 detector.ClearAngles();
1700 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1704 inline float RadiansToDegrees( float radian )
1706 return radian * 180.0f / Math::PI;
1709 int UtcDaliPanGestureAngleOutOfRange(void)
1711 TestApplication application;
1713 PanGestureDetector detector = PanGestureDetector::New();
1714 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1715 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1721 detector.AddAngle( Degree(180.0f) );
1722 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1723 detector.ClearAngles();
1725 detector.AddAngle( Degree(190.0f) );
1726 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1727 detector.ClearAngles();
1729 detector.AddAngle( Degree(-190.0f) );
1730 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1731 detector.ClearAngles();
1733 detector.AddAngle( Degree(350.0f) );
1734 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1735 detector.ClearAngles();
1737 detector.AddAngle( Degree(-350.0f) );
1738 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1739 detector.ClearAngles();
1741 detector.AddAngle( Degree(370.0f) );
1742 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1743 detector.ClearAngles();
1745 detector.AddAngle( Degree(-370.0f) );
1746 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1747 detector.ClearAngles();
1753 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1754 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1755 detector.ClearAngles();
1757 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1758 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1759 detector.ClearAngles();
1761 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1762 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1763 detector.ClearAngles();
1765 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1766 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1767 detector.ClearAngles();
1771 int UtcDaliPanGestureAngleProcessing(void)
1773 TestApplication application;
1775 Actor parent = Actor::New();
1776 parent.SetSize(100.0f, 100.0f);
1777 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1778 Stage::GetCurrent().Add(parent);
1780 Actor child = Actor::New();
1781 child.SetSize(100.0f, 100.0f);
1782 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1785 // Render and notify
1786 application.SendNotification();
1787 application.Render();
1789 // Parent detector only requires up pans
1790 PanGestureDetector parentDetector = PanGestureDetector::New();
1791 parentDetector.Attach( parent );
1792 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1793 SignalData parentData;
1794 GestureReceivedFunctor parentFunctor(parentData);
1795 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1797 // Child detector only requires right pans
1798 PanGestureDetector childDetector = PanGestureDetector::New();
1799 childDetector.Attach( child );
1800 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1801 SignalData childData;
1802 GestureReceivedFunctor childFunctor(childData);
1803 childDetector.DetectedSignal().Connect(&application, childFunctor);
1805 // Generate an Up pan gesture, only parent should receive it.
1806 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1807 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1808 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1809 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1810 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1814 // Generate a Right pan gesture, only child should receive it.
1815 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1816 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1817 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1818 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1819 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1823 // Generate a Down pan gesture, no one should receive it.
1824 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1825 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1826 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1827 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1828 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1832 // Generate a Left pan gesture, no one should receive it.
1833 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1834 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1835 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1836 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1837 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1843 int UtcDaliPanGestureDirectionHandling(void)
1845 TestApplication application;
1847 PanGestureDetector detector = PanGestureDetector::New();
1848 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1849 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1851 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1852 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1853 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1855 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1857 tet_result( TET_PASS );
1861 if ( iter == endIter )
1863 tet_printf("%s, angle not added\n", TEST_LOCATION );
1864 tet_result( TET_FAIL );
1868 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1870 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1872 tet_result( TET_PASS );
1876 if ( iter == endIter )
1878 tet_printf("%s, angle not added\n", TEST_LOCATION );
1879 tet_result( TET_FAIL );
1883 // Remove something not in the container.
1884 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1885 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1887 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1888 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1892 int UtcDaliPanGestureDirectionProcessing(void)
1894 TestApplication application;
1896 Actor parent = Actor::New();
1897 parent.SetSize(100.0f, 100.0f);
1898 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1899 Stage::GetCurrent().Add(parent);
1901 Actor child = Actor::New();
1902 child.SetSize(100.0f, 100.0f);
1903 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1906 // Render and notify
1907 application.SendNotification();
1908 application.Render();
1910 // Parent detector only requires vertical panning
1911 PanGestureDetector parentDetector = PanGestureDetector::New();
1912 parentDetector.Attach( parent );
1913 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1914 SignalData parentData;
1915 GestureReceivedFunctor parentFunctor(parentData);
1916 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1918 // Child detector only requires horizontal panning
1919 PanGestureDetector childDetector = PanGestureDetector::New();
1920 childDetector.Attach( child );
1921 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1922 SignalData childData;
1923 GestureReceivedFunctor childFunctor(childData);
1924 childDetector.DetectedSignal().Connect(&application, childFunctor);
1926 // Generate an Up pan gesture, only parent should receive it.
1927 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1928 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1929 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1930 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1931 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1935 // Generate a Right pan gesture, only child should receive it.
1936 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1937 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1938 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1939 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1940 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1944 // Generate a Down pan gesture, only parent should receive it.
1945 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1946 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1947 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1948 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1949 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1953 // Generate a Left pan gesture, only child should receive it.
1954 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1955 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1956 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1957 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1958 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1962 // Generate a pan at -45 degrees, no one should receive it.
1963 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1964 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1965 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1966 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1967 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1971 // Generate a pan at 45 degrees, no one should receive it.
1972 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1973 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
1974 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1975 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1976 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1980 // Generate a pan at 135 degrees, no one should receive it.
1981 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1982 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1983 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1984 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1985 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1989 // Generate a pan at -135 degrees, no one should receive it.
1990 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1991 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
1992 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1993 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1994 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2000 int UtcDaliPanGestureSetProperties(void)
2002 TestApplication application;
2003 TestRenderController& renderController( application.GetRenderController() );
2004 Integration::SetPanGesturePredictionMode(0);
2006 Actor actor = Actor::New();
2007 actor.SetSize(100.0f, 100.0f);
2008 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2009 Stage::GetCurrent().Add(actor);
2011 // Add a pan detector
2012 PanGestureDetector detector = PanGestureDetector::New();
2013 detector.Attach( actor );
2015 GestureReceivedFunctor functor( data );
2016 detector.DetectedSignal().Connect( &application, functor );
2018 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2020 ConstraintData constraintData;
2021 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2022 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2023 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2024 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2025 PanConstraint( constraintData ) ) );
2027 // Render and notify
2028 application.SendNotification();
2029 application.Render();
2031 renderController.Initialize();
2032 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2034 Vector2 screenPosition( 20.0f, 20.0f );
2035 Vector2 screenDisplacement( 1.0f, 1.0f );
2036 Vector2 localPosition( 21.0f, 21.0f );
2037 Vector2 localDisplacement( 0.5f, 0.5f );
2039 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement ) );
2040 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2042 // Render and notify
2043 application.SendNotification();
2044 application.Render();
2046 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2047 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2048 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2049 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2050 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2051 constraintData.Reset();
2055 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2057 TestApplication application;
2058 Integration::SetPanGesturePredictionMode(0);
2060 Actor actor = Actor::New();
2061 actor.SetSize(100.0f, 100.0f);
2062 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2063 Stage::GetCurrent().Add(actor);
2065 // Add a pan detector
2066 PanGestureDetector detector = PanGestureDetector::New();
2067 detector.Attach( actor );
2069 GestureReceivedFunctor functor( data );
2070 detector.DetectedSignal().Connect( &application, functor );
2072 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2074 ConstraintData constraintData;
2075 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2076 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2077 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2078 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2079 PanConstraint( constraintData ) ) );
2081 // Render and notify
2082 application.SendNotification();
2083 application.Render();
2085 Vector2 previousPosition( 20.0f, 20.0f );
2086 Vector2 currentPosition( 20.0f, 10.0f );
2087 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2088 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2089 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2091 Vector2 screenPosition( 100.0f, 20.0f );
2092 Vector2 localPosition( 110.0f, 110.0f );
2094 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2096 // Render and notify
2097 application.SendNotification();
2098 application.Render();
2100 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2101 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2102 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2103 constraintData.Reset();
2107 int UtcDaliPanGesturePropertyIndices(void)
2109 TestApplication application;
2110 PanGestureDetector detector = PanGestureDetector::New();
2112 Property::IndexContainer indices;
2113 detector.GetPropertyIndices( indices );
2114 DALI_TEST_CHECK( ! indices.empty() );
2115 DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );