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-test-suite-utils.h>
28 void utc_dali_pan_gesture_detector_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_pan_gesture_detector_cleanup(void)
35 test_return_value = TET_PASS;
38 ///////////////////////////////////////////////////////////////////////////////
41 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
44 // Stores data that is populated in the callback and will be read by the TET cases
48 : functorCalled(false),
49 voidFunctorCalled(false),
50 receivedGesture(Gesture::Clear)
55 functorCalled = false;
56 voidFunctorCalled = false;
58 receivedGesture.state = Gesture::Clear;
59 receivedGesture.velocity = Vector2(0.0f, 0.0f);
60 receivedGesture.displacement = Vector2(0.0f, 0.0f);
61 receivedGesture.position = Vector2(0.0f, 0.0f);
62 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
63 receivedGesture.numberOfTouches = 0;
69 bool voidFunctorCalled;
70 PanGesture receivedGesture;
74 // Functor that sets the data when called
75 struct GestureReceivedFunctor
77 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
79 void operator()(Actor actor, PanGesture pan)
81 signalData.functorCalled = true;
82 signalData.receivedGesture = pan;
83 signalData.pannedActor = actor;
88 signalData.voidFunctorCalled = true;
91 SignalData& signalData;
94 // Functor that removes the gestured actor from stage
95 struct UnstageActorFunctor : public GestureReceivedFunctor
97 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
98 : GestureReceivedFunctor( data ),
99 stateToUnstage( stateToUnstage )
103 void operator()( Actor actor, PanGesture pan )
105 GestureReceivedFunctor::operator()( actor, pan );
107 if ( pan.state == stateToUnstage )
109 Stage::GetCurrent().Remove( actor );
113 Gesture::State& stateToUnstage;
116 // Functor for receiving a touch event
117 struct TouchEventFunctor
119 bool operator()(Actor actor, const TouchEvent& touch)
125 // Data for constraints
126 struct ConstraintData
133 Vector2 screenPosition;
134 Vector2 screenDisplacement;
135 Vector2 localPosition;
136 Vector2 localDisplacement;
141 screenPosition = screenDisplacement = localPosition = localDisplacement = Vector2::ZERO;
146 // Constraint used with panning properties
149 PanConstraint( ConstraintData& data ) : constraintData(data) { }
151 Vector3 operator()(const Vector3& current,
152 const PropertyInput& screenPositionProperty,
153 const PropertyInput& screenDisplacementProperty,
154 const PropertyInput& localPositionProperty,
155 const PropertyInput& localDisplacementProperty)
157 constraintData.screenPosition = screenPositionProperty.GetVector2();
158 constraintData.screenDisplacement = screenDisplacementProperty.GetVector2();
159 constraintData.localPosition = localPositionProperty.GetVector2();
160 constraintData.localDisplacement = localDisplacementProperty.GetVector2();
161 constraintData.called = true;
162 return Vector3::ZERO;
165 ConstraintData& constraintData;
168 // Generate a PanGestureEvent to send to Core
169 Integration::PanGestureEvent GeneratePan(
170 Gesture::State state,
171 Vector2 previousPosition,
172 Vector2 currentPosition,
173 unsigned long timeDelta,
174 unsigned int numberOfTouches = 1,
175 unsigned int time = 1u)
177 Integration::PanGestureEvent pan(state);
179 pan.previousPosition = previousPosition;
180 pan.currentPosition = currentPosition;
181 pan.timeDelta = timeDelta;
182 pan.numberOfTouches = numberOfTouches;
188 // Generate a PanGesture
189 PanGesture GeneratePan( unsigned int time,
190 Gesture::State state,
191 Vector2 screenPosition,
192 Vector2 localPosition,
193 Vector2 screenDisplacement = Vector2::ONE,
194 Vector2 localDisplacement = Vector2::ONE,
195 Vector2 velocity = Vector2::ONE,
196 unsigned int numberOfTouches = 1 )
198 PanGesture pan( state );
202 pan.screenPosition = screenPosition;
203 pan.position = localPosition;
205 pan.screenDisplacement = screenDisplacement;
206 pan.displacement = localDisplacement;
208 pan.screenVelocity = pan.velocity = velocity;
209 pan.numberOfTouches = numberOfTouches;
216 ///////////////////////////////////////////////////////////////////////////////
218 // Positive test case for a method
219 int UtcDaliPanGestureDetectorConstructor(void)
221 TestApplication application;
223 PanGestureDetector detector;
224 DALI_TEST_CHECK(!detector);
229 // Negative test case for a method
230 int UtcDaliPanGestureDetectorNew(void)
232 TestApplication application;
234 PanGestureDetector detector = PanGestureDetector::New();
236 DALI_TEST_CHECK(detector);
238 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
239 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
241 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
242 Actor actor = Actor::New();
243 actor.SetSize(100.0f, 100.0f);
244 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
245 detector.Attach(actor);
247 Stage::GetCurrent().Add(actor);
250 application.SendNotification();
251 application.Render();
253 Integration::TouchEvent touchEvent(1);
254 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
255 touchEvent.AddPoint(point);
256 application.ProcessEvent(touchEvent);
260 int UtcDaliPanGestureDetectorDownCast(void)
262 TestApplication application;
263 tet_infoline("Testing Dali::GestureDetector::DownCast()");
265 PanGestureDetector detector = PanGestureDetector::New();
267 BaseHandle object(detector);
269 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
270 DALI_TEST_CHECK(detector2);
272 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
273 DALI_TEST_CHECK(detector3);
275 BaseHandle unInitializedObject;
276 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
277 DALI_TEST_CHECK(!detector4);
279 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
280 DALI_TEST_CHECK(!detector5);
282 GestureDetector detector6 = PanGestureDetector::New();
283 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
284 DALI_TEST_CHECK(detector7);
288 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
290 TestApplication application;
292 PanGestureDetector detector = PanGestureDetector::New();
294 unsigned int min = 2;
296 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
298 detector.SetMinimumTouchesRequired(min);
300 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
302 // Attach an actor and change the minimum touches
304 Actor actor = Actor::New();
305 actor.SetSize(100.0f, 100.0f);
306 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
307 Stage::GetCurrent().Add(actor);
310 application.SendNotification();
311 application.Render();
314 GestureReceivedFunctor functor(data);
316 detector.Attach(actor);
317 detector.DetectedSignal().Connect(&application, functor);
319 TestGestureManager& gestureManager = application.GetGestureManager();
320 gestureManager.Initialize();
322 detector.SetMinimumTouchesRequired(3);
324 // Gesture detection should have been updated only
325 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
326 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
327 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
330 gestureManager.Initialize();
332 // Create a second gesture detector that requires even less minimum touches
333 PanGestureDetector secondDetector = PanGestureDetector::New();
334 secondDetector.Attach(actor);
336 // Gesture detection should have been updated only
337 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
338 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
339 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
343 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
345 TestApplication application;
347 PanGestureDetector detector = PanGestureDetector::New();
349 unsigned int max = 3;
351 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
353 detector.SetMaximumTouchesRequired(max);
355 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
357 // Attach an actor and change the maximum touches
359 Actor actor = Actor::New();
360 actor.SetSize(100.0f, 100.0f);
361 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
362 Stage::GetCurrent().Add(actor);
365 application.SendNotification();
366 application.Render();
369 GestureReceivedFunctor functor(data);
371 detector.Attach(actor);
372 detector.DetectedSignal().Connect(&application, functor);
374 TestGestureManager& gestureManager = application.GetGestureManager();
375 gestureManager.Initialize();
377 detector.SetMaximumTouchesRequired(4);
379 // Gesture detection should have been updated only
380 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
381 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
382 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
385 gestureManager.Initialize();
387 // Create a second gesture detector that requires even less maximum touches
388 PanGestureDetector secondDetector = PanGestureDetector::New();
389 secondDetector.Attach(actor);
391 // Gesture detection should NOT have been updated
392 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
393 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
394 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
398 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
400 TestApplication application;
402 PanGestureDetector detector = PanGestureDetector::New();
403 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
407 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
409 TestApplication application;
411 PanGestureDetector detector = PanGestureDetector::New();
412 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
416 int UtcDaliPanGestureSignalReceptionNegative(void)
418 TestApplication application;
420 Actor actor = Actor::New();
421 actor.SetSize(100.0f, 100.0f);
422 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
423 Stage::GetCurrent().Add(actor);
426 application.SendNotification();
427 application.Render();
430 GestureReceivedFunctor functor(data);
432 PanGestureDetector detector = PanGestureDetector::New();
433 detector.Attach(actor);
434 detector.DetectedSignal().Connect(&application, functor);
436 // Do a pan outside actor's area
437 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
438 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
439 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
441 // Continue pan into actor's area - we should still not receive the signal
443 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
444 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
446 // Stop panning - we should still not receive the signal
448 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
449 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
453 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
455 TestApplication application;
457 Actor actor = Actor::New();
458 actor.SetSize(100.0f, 100.0f);
459 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
460 Stage::GetCurrent().Add(actor);
463 application.SendNotification();
464 application.Render();
467 GestureReceivedFunctor functor(data);
469 PanGestureDetector detector = PanGestureDetector::New();
470 detector.Attach(actor);
471 detector.DetectedSignal().Connect(&application, functor);
473 // Start pan within the actor's area
474 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
475 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
476 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
477 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
478 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
479 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
480 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
481 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
482 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
484 // Continue the pan within the actor's area - we should still receive the signal
486 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
487 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
488 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
489 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
490 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
491 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
492 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
493 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
495 // Pan Gesture leaves actor's area - we should still receive the signal
497 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
498 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
499 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
500 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
501 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
502 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
503 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
504 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
506 // Gesture ends - we would receive a finished state
508 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
509 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
510 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
511 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
512 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
513 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
514 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
515 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
519 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
521 TestApplication application;
523 Actor actor = Actor::New();
524 actor.SetSize(100.0f, 100.0f);
525 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
526 Stage::GetCurrent().Add(actor);
529 application.SendNotification();
530 application.Render();
533 GestureReceivedFunctor functor(data);
535 PanGestureDetector detector = PanGestureDetector::New();
536 detector.Attach(actor);
537 detector.DetectedSignal().Connect(&application, functor);
539 // Start pan within the actor's area
540 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
541 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
542 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
543 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
544 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
545 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
546 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
547 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
548 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
550 // Continue the pan within the actor's area - we should still receive the signal
552 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
553 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
554 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
555 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
556 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
557 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
558 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
559 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
561 // Gesture ends within actor's area - we would receive a finished state
563 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
564 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
565 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
566 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
567 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
568 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
569 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
570 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
574 int UtcDaliPanGestureSignalReceptionCancelled(void)
576 TestApplication application;
578 Actor actor = Actor::New();
579 actor.SetSize(100.0f, 100.0f);
580 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
581 Stage::GetCurrent().Add(actor);
584 application.SendNotification();
585 application.Render();
588 GestureReceivedFunctor functor(data);
590 PanGestureDetector detector = PanGestureDetector::New();
591 detector.Attach(actor);
592 detector.DetectedSignal().Connect(&application, functor);
594 // Start pan within the actor's area
595 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
596 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
597 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
598 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
600 // Continue the pan within the actor's area - we should still receive the signal
602 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
603 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
604 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
606 // The gesture is cancelled
608 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
609 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
610 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
614 int UtcDaliPanGestureSignalReceptionDetach(void)
616 TestApplication application;
618 Actor actor = Actor::New();
619 actor.SetSize(100.0f, 100.0f);
620 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
621 Stage::GetCurrent().Add(actor);
624 application.SendNotification();
625 application.Render();
628 GestureReceivedFunctor functor(data);
630 PanGestureDetector detector = PanGestureDetector::New();
631 detector.Attach(actor);
632 detector.DetectedSignal().Connect(&application, functor);
634 // Start pan within the actor's area
635 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
636 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
637 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
639 // Continue the pan within the actor's area - we should still receive the signal
641 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
642 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
644 // Gesture ends within actor's area
646 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
647 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
650 detector.DetachAll();
652 // Ensure we are no longer signalled
654 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
655 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
656 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
657 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
658 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
662 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
664 TestApplication application;
666 Actor actor = Actor::New();
667 actor.SetSize(100.0f, 100.0f);
668 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
669 Stage::GetCurrent().Add(actor);
672 application.SendNotification();
673 application.Render();
676 GestureReceivedFunctor functor(data);
678 PanGestureDetector detector = PanGestureDetector::New();
679 detector.Attach(actor);
680 detector.DetectedSignal().Connect(&application, functor);
682 // Start pan within the actor's area
683 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
684 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
685 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
687 // Continue the pan within the actor's area - we should still receive the signal
689 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
690 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
692 // Detach actor during the pan, we should not receive the next event
693 detector.DetachAll();
695 // Gesture ends within actor's area
697 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
698 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
702 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
704 TestApplication application;
707 GestureReceivedFunctor functor(data);
709 PanGestureDetector detector = PanGestureDetector::New();
710 detector.DetectedSignal().Connect(&application, functor);
712 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
714 Actor tempActor = Actor::New();
715 tempActor.SetSize(100.0f, 100.0f);
716 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
717 Stage::GetCurrent().Add(tempActor);
718 detector.Attach(tempActor);
720 // Actor lifetime is scoped
722 Actor actor = Actor::New();
723 actor.SetSize(100.0f, 100.0f);
724 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
725 Stage::GetCurrent().Add(actor);
728 application.SendNotification();
729 application.Render();
731 detector.Attach(actor);
733 // Start pan within the actor's area
734 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
735 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
736 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
738 // Continue the pan within the actor's area - we should still receive the signal
740 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
741 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
743 // Remove the actor from stage and reset the data
744 Stage::GetCurrent().Remove(actor);
747 application.SendNotification();
748 application.Render();
751 // Actor should now have been destroyed
753 // Gesture ends within the area where the actor used to be
755 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
756 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
760 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
762 TestApplication application;
764 Actor actor = Actor::New();
765 actor.SetSize(100.0f, 100.0f);
766 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
767 Stage::GetCurrent().Add(actor);
770 application.SendNotification();
771 application.Render();
774 GestureReceivedFunctor functor(data);
776 PanGestureDetector detector = PanGestureDetector::New();
777 detector.Attach(actor);
778 detector.DetectedSignal().Connect(&application, functor);
780 // Do an entire pan, only check finished value
781 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
782 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
784 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
785 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
786 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
788 // Rotate actor again and render a couple of times
789 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
790 application.SendNotification();
791 application.Render();
793 // Do an entire pan, only check finished value
794 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
795 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
797 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
798 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
799 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
801 // Rotate actor again and render a couple of times
802 actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
803 application.SendNotification();
804 application.Render();
806 // Do an entire pan, only check finished value
807 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
808 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
810 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
811 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
812 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
816 int UtcDaliPanGestureSignalReceptionChildHit(void)
818 TestApplication application;
820 Actor parent = Actor::New();
821 parent.SetSize(100.0f, 100.0f);
822 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
823 Stage::GetCurrent().Add(parent);
825 // Set child to completely cover parent.
826 // Change rotation of child to be different from parent so that we can check if our local coordinate
827 // conversion of the parent actor is correct.
828 Actor child = Actor::New();
829 child.SetSize(100.0f, 100.0f);
830 child.SetAnchorPoint(AnchorPoint::CENTER);
831 child.SetParentOrigin(ParentOrigin::CENTER);
832 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
835 TouchEventFunctor touchFunctor;
836 child.TouchedSignal().Connect(&application, touchFunctor);
839 application.SendNotification();
840 application.Render();
843 GestureReceivedFunctor functor(data);
845 PanGestureDetector detector = PanGestureDetector::New();
846 detector.Attach(parent);
847 detector.DetectedSignal().Connect(&application, functor);
849 // Do an entire pan, only check finished value - hits child area but parent should still receive it
850 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
851 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
853 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
854 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
855 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
856 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
858 // Attach child and generate same touch points to yield a different displacement
859 // (Also proves that you can detach and then re-attach another actor)
860 detector.Attach(child);
861 detector.Detach(parent);
863 // Do an entire pan, only check finished value
864 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
865 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
867 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
868 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
869 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
870 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
874 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
876 TestApplication application;
878 Actor first = Actor::New();
879 first.SetSize(100.0f, 100.0f);
880 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
881 Stage::GetCurrent().Add(first);
883 Actor second = Actor::New();
884 second.SetSize(100.0f, 100.0f);
886 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
887 Stage::GetCurrent().Add(second);
890 application.SendNotification();
891 application.Render();
894 GestureReceivedFunctor functor(data);
896 PanGestureDetector detector = PanGestureDetector::New();
897 detector.Attach(first);
898 detector.Attach(second);
899 detector.DetectedSignal().Connect(&application, functor);
901 // Start pan within second actor's area
902 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
903 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
904 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
905 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
907 // Pan moves into first actor's area - second actor should receive the pan
909 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
910 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
911 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
913 // Detach the second actor during the pan, we should not receive the next event
914 detector.Detach(second);
916 // Gesture ends within actor's area
918 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
919 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
923 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
925 TestApplication application;
927 Actor actor = Actor::New();
928 actor.SetSize(100.0f, 100.0f);
929 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
930 Stage::GetCurrent().Add(actor);
933 application.SendNotification();
934 application.Render();
937 GestureReceivedFunctor functor(data);
939 PanGestureDetector detector = PanGestureDetector::New();
940 detector.Attach(actor);
941 detector.DetectedSignal().Connect(&application, functor);
943 // Start pan in actor's area
944 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
945 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
946 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
948 // Pan continues within actor's area
950 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
951 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
953 // Actor become invisible - actor should not receive the next pan
954 actor.SetVisible(false);
957 application.SendNotification();
958 application.Render();
960 // Gesture ends within actor's area
962 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
963 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
967 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
969 TestApplication application;
970 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
972 Actor first = Actor::New();
973 first.SetSize(100.0f, 100.0f);
974 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
975 Stage::GetCurrent().Add(first);
977 Actor second = Actor::New();
978 second.SetSize(100.0f, 100.0f);
979 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
983 application.SendNotification();
984 application.Render();
987 GestureReceivedFunctor functor(data);
989 PanGestureDetector firstDetector = PanGestureDetector::New();
990 firstDetector.Attach(first);
991 firstDetector.DetectedSignal().Connect(&application, functor);
993 // secondDetector is scoped
995 // Reset gestureManager statistics
996 gestureManager.Initialize();
998 PanGestureDetector secondDetector = PanGestureDetector::New();
999 secondDetector.SetMinimumTouchesRequired(2);
1000 secondDetector.SetMaximumTouchesRequired(2);
1001 secondDetector.Attach(second);
1002 secondDetector.DetectedSignal().Connect(&application, functor);
1004 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1005 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1006 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1008 // Start pan within second actor's area
1009 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1010 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1011 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1012 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1014 // Two touch pan changes to single touch - we should receive a finished state
1016 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1017 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1018 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1019 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1021 // Pan continues as single touch gesture - we should not receive any gesture
1023 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1024 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1026 // Pan ends - still no signal
1028 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1029 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1031 // Single touch pan starts - first actor should be panned
1033 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1034 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1035 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1036 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1038 // Pan changes to double-touch - we should receive a finished state
1040 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1041 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1042 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1043 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1045 // Pan continues as double touch gesture - we should not receive any gesture
1047 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1048 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1050 // Pan ends - still no signal
1052 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1053 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1055 // Reset gesture manager statistics
1056 gestureManager.Initialize();
1059 // secondDetector has now been deleted. Gesture detection should have been updated only
1060 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1061 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1062 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1066 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1068 TestApplication application;
1070 Actor actor = Actor::New();
1071 actor.SetSize(100.0f, 100.0f);
1072 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1073 Stage::GetCurrent().Add(actor);
1075 Actor actor2 = Actor::New();
1076 actor2.SetSize(100.0f, 100.0f);
1077 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1078 Stage::GetCurrent().Add(actor2);
1080 // Render and notify
1081 application.SendNotification();
1082 application.Render();
1084 // Attach actor to one detector
1085 SignalData firstData;
1086 GestureReceivedFunctor firstFunctor(firstData);
1087 PanGestureDetector firstDetector = PanGestureDetector::New();
1088 firstDetector.Attach(actor);
1089 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1091 // Attach actor to another detector
1092 SignalData secondData;
1093 GestureReceivedFunctor secondFunctor(secondData);
1094 PanGestureDetector secondDetector = PanGestureDetector::New();
1095 secondDetector.Attach(actor);
1096 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1098 // Add second actor to second detector, when we remove the actor, this will make sure that this
1099 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1100 // functor should still not be called (which is what we're also testing).
1101 secondDetector.Attach(actor2);
1103 // Pan in actor's area - both detector's functors should be called
1104 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1105 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1106 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1107 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1109 // Pan continues in actor's area - both detector's functors should be called
1112 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1113 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1114 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1116 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1117 firstDetector.Detach(actor);
1120 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1121 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1122 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1124 // New pan on actor, only secondDetector has actor attached
1127 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1128 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1129 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1130 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1132 // Detach actor from secondDetector
1133 secondDetector.Detach(actor);
1136 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1137 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1138 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1142 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1144 // Should handle two started events gracefully.
1146 TestApplication application;
1148 Actor actor = Actor::New();
1149 actor.SetSize(100.0f, 100.0f);
1150 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1151 Stage::GetCurrent().Add(actor);
1154 GestureReceivedFunctor functor(data);
1156 PanGestureDetector detector = PanGestureDetector::New();
1157 detector.Attach(actor);
1158 detector.DetectedSignal().Connect(&application, functor);
1160 // Render and notify
1161 application.SendNotification();
1162 application.Render();
1164 // Start pan in actor's area
1165 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1166 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1167 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1169 // Send another start in actor's area
1171 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1172 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1174 // Add a child actor to overlap actor and send another start in actor's area
1175 Actor child = Actor::New();
1176 child.SetSize(100.0f, 100.0f);
1177 child.SetAnchorPoint(AnchorPoint::CENTER);
1178 child.SetParentOrigin(ParentOrigin::CENTER);
1181 TouchEventFunctor touchFunctor;
1182 child.TouchedSignal().Connect(&application, touchFunctor);
1184 // Render and notify
1185 application.SendNotification();
1186 application.Render();
1188 // Send another possible and start in actor's area
1190 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1191 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1192 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1194 // Send another start in actor's area
1196 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1197 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1198 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1202 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1204 TestApplication application;
1206 Actor actor1 = Actor::New();
1207 actor1.SetSize(100.0f, 100.0f);
1208 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1209 Stage::GetCurrent().Add(actor1);
1211 GestureReceivedFunctor functor1(data1);
1212 PanGestureDetector detector1 = PanGestureDetector::New();
1213 detector1.Attach(actor1);
1214 detector1.DetectedSignal().Connect(&application, functor1);
1216 Actor actor2 = Actor::New();
1217 actor2.SetSize(100.0f, 100.0f);
1218 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1219 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1220 Stage::GetCurrent().Add(actor2);
1222 GestureReceivedFunctor functor2(data2);
1223 PanGestureDetector detector2 = PanGestureDetector::New();
1224 detector2.Attach(actor2);
1225 detector2.DetectedSignal().Connect(&application, functor2);
1227 // Render and notify
1228 application.SendNotification();
1229 application.Render();
1231 // Start pan in actor1's area, only data1 should be set
1232 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1233 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1234 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1235 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1239 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1241 TestApplication application;
1243 Actor actor = Actor::New();
1244 actor.SetSize(100.0f, 100.0f);
1245 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1246 Stage::GetCurrent().Add(actor);
1248 // Render and notify
1249 application.SendNotification();
1250 application.Render();
1252 // Attach actor to detector
1254 GestureReceivedFunctor functor( data );
1255 PanGestureDetector detector = PanGestureDetector::New();
1256 detector.Attach(actor);
1257 detector.DetectedSignal().Connect( &application, functor );
1259 // Gesture possible in actor's area.
1260 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1261 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1263 // Move actor somewhere else
1264 actor.SetPosition( 100.0f, 100.0f );
1266 // Render and notify
1267 application.SendNotification();
1268 application.Render();
1270 // Emit Started event, we should not receive the long press.
1271 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1272 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1273 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1275 // LongPress possible in empty area.
1276 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1277 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1279 // Move actor in to the long press position.
1280 actor.SetPosition( 0.0f, 0.0f );
1282 // Render and notify
1283 application.SendNotification();
1284 application.Render();
1286 // Emit Started event, we should not receive the long press.
1287 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1288 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1289 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1291 // Normal long press in actor's area for completeness.
1292 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1293 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1294 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1295 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1299 int UtcDaliPanGestureEmitIncorrectState(void)
1301 TestApplication application;
1303 Actor actor = Actor::New();
1304 actor.SetSize(100.0f, 100.0f);
1305 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1306 Stage::GetCurrent().Add(actor);
1308 // Render and notify
1309 application.SendNotification();
1310 application.Render();
1312 // Attach actor to detector
1314 GestureReceivedFunctor functor( data );
1315 PanGestureDetector detector = PanGestureDetector::New();
1316 detector.Attach(actor);
1317 detector.DetectedSignal().Connect( &application, functor );
1319 // Try a Clear state
1322 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1323 tet_result(TET_FAIL);
1325 catch ( Dali::DaliException& e )
1327 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1332 int UtcDaliPanGestureActorUnstaged(void)
1334 TestApplication application;
1336 Actor actor = Actor::New();
1337 actor.SetSize(100.0f, 100.0f);
1338 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1339 Stage::GetCurrent().Add(actor);
1341 // Render and notify
1342 application.SendNotification();
1343 application.Render();
1345 // State to remove actor in.
1346 Gesture::State stateToUnstage( Gesture::Started );
1348 // Attach actor to detector
1350 UnstageActorFunctor functor( data, stateToUnstage );
1351 PanGestureDetector detector = PanGestureDetector::New();
1352 detector.Attach(actor);
1353 detector.DetectedSignal().Connect( &application, functor );
1356 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1357 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1358 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1360 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1361 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1364 // Render and notify
1365 application.SendNotification();
1366 application.Render();
1368 // Re-add actor to stage
1369 Stage::GetCurrent().Add(actor);
1371 // Render and notify
1372 application.SendNotification();
1373 application.Render();
1375 // Change state to Gesture::Continuing to remove
1376 stateToUnstage = Gesture::Continuing;
1379 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1380 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1381 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1383 application.ProcessEvent(GeneratePan(Gesture::Continuing, 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::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1387 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1390 // Render and notify
1391 application.SendNotification();
1392 application.Render();
1394 // Re-add actor to stage
1395 Stage::GetCurrent().Add(actor);
1397 // Render and notify
1398 application.SendNotification();
1399 application.Render();
1401 // Change state to Gesture::Finished to remove
1402 stateToUnstage = Gesture::Finished;
1405 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1406 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1407 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1409 application.ProcessEvent(GeneratePan(Gesture::Continuing, 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::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1413 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1414 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1418 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1420 TestApplication application;
1422 Actor actor = Actor::New();
1423 actor.SetSize(100.0f, 100.0f);
1424 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1425 Stage::GetCurrent().Add(actor);
1427 // Create and add a second actor so that GestureDetector destruction does not come into play.
1428 Actor dummyActor( Actor::New() );
1429 dummyActor.SetSize( 100.0f, 100.0f );
1430 dummyActor.SetPosition( 100.0f, 100.0f );
1431 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1432 Stage::GetCurrent().Add(dummyActor);
1434 // Render and notify
1435 application.SendNotification();
1436 application.Render();
1438 // State to remove actor in.
1439 Gesture::State stateToUnstage( Gesture::Started );
1441 // Attach actor to detector
1443 UnstageActorFunctor functor( data, stateToUnstage );
1444 PanGestureDetector detector = PanGestureDetector::New();
1445 detector.Attach(actor);
1446 detector.Attach(dummyActor);
1447 detector.DetectedSignal().Connect( &application, functor );
1449 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1450 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1451 // position, we should still not be signalled.
1454 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1455 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1456 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1459 // Render and notify
1460 application.SendNotification();
1461 application.Render();
1463 // Re add to the stage, we should not be signalled
1464 Stage::GetCurrent().Add(actor);
1466 // Render and notify
1467 application.SendNotification();
1468 application.Render();
1470 // Continue signal emission
1471 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1472 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1474 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1475 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1478 // Here we delete an actor in started, we should not receive any subsequent signalling.
1481 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1482 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1483 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1486 // Render and notify
1487 application.SendNotification();
1488 application.Render();
1490 // Delete actor as well
1493 // Render and notify
1494 application.SendNotification();
1495 application.Render();
1497 // Continue signal emission
1498 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1499 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1501 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1502 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1506 int UtcDaliPanGestureSystemOverlay(void)
1508 TestApplication application;
1509 Dali::Integration::Core& core = application.GetCore();
1510 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1511 systemOverlay.GetOverlayRenderTasks().CreateTask();
1513 Actor actor = Actor::New();
1514 actor.SetSize(100.0f, 100.0f);
1515 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1516 systemOverlay.Add(actor);
1518 // Render and notify
1519 application.SendNotification();
1520 application.Render();
1523 GestureReceivedFunctor functor(data);
1525 PanGestureDetector detector = PanGestureDetector::New();
1526 detector.Attach(actor);
1527 detector.DetectedSignal().Connect(&application, functor);
1529 Vector2 screenCoordsStart( 10.0f, 20.0f );
1530 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1532 // Start pan within the actor's area
1533 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1534 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1535 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1539 int UtcDaliPanGestureAngleHandling(void)
1541 TestApplication application;
1543 PanGestureDetector detector = PanGestureDetector::New();
1544 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1545 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1547 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1548 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1549 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1551 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1553 tet_result( TET_PASS );
1557 if ( iter == endIter )
1559 tet_printf("%s, angle not added\n", TEST_LOCATION );
1560 tet_result( TET_FAIL );
1564 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1565 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1567 // Remove something not in the container.
1568 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1569 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1571 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1572 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1573 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1575 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1577 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1578 tet_result( TET_FAIL );
1583 detector.ClearAngles();
1584 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1588 inline float RadiansToDegrees( float radian )
1590 return radian * 180.0f / Math::PI;
1593 int UtcDaliPanGestureAngleOutOfRange(void)
1595 TestApplication application;
1597 PanGestureDetector detector = PanGestureDetector::New();
1598 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1599 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1605 detector.AddAngle( Degree(180.0f) );
1606 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1607 detector.ClearAngles();
1609 detector.AddAngle( Degree(190.0f) );
1610 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1611 detector.ClearAngles();
1613 detector.AddAngle( Degree(-190.0f) );
1614 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1615 detector.ClearAngles();
1617 detector.AddAngle( Degree(350.0f) );
1618 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1619 detector.ClearAngles();
1621 detector.AddAngle( Degree(-350.0f) );
1622 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1623 detector.ClearAngles();
1625 detector.AddAngle( Degree(370.0f) );
1626 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1627 detector.ClearAngles();
1629 detector.AddAngle( Degree(-370.0f) );
1630 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1631 detector.ClearAngles();
1637 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1638 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1639 detector.ClearAngles();
1641 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1642 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1643 detector.ClearAngles();
1645 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1646 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1647 detector.ClearAngles();
1649 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1650 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1651 detector.ClearAngles();
1655 int UtcDaliPanGestureAngleProcessing(void)
1657 TestApplication application;
1659 Actor parent = Actor::New();
1660 parent.SetSize(100.0f, 100.0f);
1661 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1662 Stage::GetCurrent().Add(parent);
1664 Actor child = Actor::New();
1665 child.SetSize(100.0f, 100.0f);
1666 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1669 // Render and notify
1670 application.SendNotification();
1671 application.Render();
1673 // Parent detector only requires up pans
1674 PanGestureDetector parentDetector = PanGestureDetector::New();
1675 parentDetector.Attach( parent );
1676 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1677 SignalData parentData;
1678 GestureReceivedFunctor parentFunctor(parentData);
1679 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1681 // Child detector only requires right pans
1682 PanGestureDetector childDetector = PanGestureDetector::New();
1683 childDetector.Attach( child );
1684 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1685 SignalData childData;
1686 GestureReceivedFunctor childFunctor(childData);
1687 childDetector.DetectedSignal().Connect(&application, childFunctor);
1689 // Generate an Up pan gesture, only parent should receive it.
1690 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1691 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1692 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1693 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1694 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1698 // Generate a Right pan gesture, only child should receive it.
1699 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1700 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1701 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1702 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1703 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1707 // Generate a Down pan gesture, no one should receive it.
1708 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1709 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1710 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1711 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1712 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1716 // Generate a Left pan gesture, no one should receive it.
1717 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1718 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1719 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1720 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1721 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1727 int UtcDaliPanGestureDirectionHandling(void)
1729 TestApplication application;
1731 PanGestureDetector detector = PanGestureDetector::New();
1732 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1733 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1735 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1736 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1737 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1739 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1741 tet_result( TET_PASS );
1745 if ( iter == endIter )
1747 tet_printf("%s, angle not added\n", TEST_LOCATION );
1748 tet_result( TET_FAIL );
1752 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1754 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1756 tet_result( TET_PASS );
1760 if ( iter == endIter )
1762 tet_printf("%s, angle not added\n", TEST_LOCATION );
1763 tet_result( TET_FAIL );
1767 // Remove something not in the container.
1768 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1769 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1771 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1772 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1776 int UtcDaliPanGestureDirectionProcessing(void)
1778 TestApplication application;
1780 Actor parent = Actor::New();
1781 parent.SetSize(100.0f, 100.0f);
1782 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1783 Stage::GetCurrent().Add(parent);
1785 Actor child = Actor::New();
1786 child.SetSize(100.0f, 100.0f);
1787 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1790 // Render and notify
1791 application.SendNotification();
1792 application.Render();
1794 // Parent detector only requires vertical panning
1795 PanGestureDetector parentDetector = PanGestureDetector::New();
1796 parentDetector.Attach( parent );
1797 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1798 SignalData parentData;
1799 GestureReceivedFunctor parentFunctor(parentData);
1800 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1802 // Child detector only requires horizontal panning
1803 PanGestureDetector childDetector = PanGestureDetector::New();
1804 childDetector.Attach( child );
1805 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1806 SignalData childData;
1807 GestureReceivedFunctor childFunctor(childData);
1808 childDetector.DetectedSignal().Connect(&application, childFunctor);
1810 // Generate an Up pan gesture, only parent should receive it.
1811 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1812 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1813 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1814 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1815 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1819 // Generate a Right pan gesture, only child should receive it.
1820 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1821 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1822 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1823 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1824 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1828 // Generate a Down pan gesture, only parent should receive it.
1829 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1830 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1831 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1832 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1833 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1837 // Generate a Left pan gesture, only child should receive it.
1838 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1839 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1840 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1841 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1842 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1846 // Generate a pan at -45 degrees, no one should receive it.
1847 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1848 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1849 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1850 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1851 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1855 // Generate a pan at 45 degrees, no one should receive it.
1856 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1857 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
1858 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1859 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1860 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1864 // Generate a pan at 135 degrees, no one should receive it.
1865 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1866 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1867 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1868 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1869 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1873 // Generate a pan at -135 degrees, no one should receive it.
1874 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1875 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
1876 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1877 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1878 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1884 int UtcDaliPanGestureSetProperties(void)
1886 TestApplication application;
1887 TestRenderController& renderController( application.GetRenderController() );
1889 Actor actor = Actor::New();
1890 actor.SetSize(100.0f, 100.0f);
1891 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1892 Stage::GetCurrent().Add(actor);
1894 // Add a pan detector
1895 PanGestureDetector detector = PanGestureDetector::New();
1896 detector.Attach( actor );
1898 GestureReceivedFunctor functor( data );
1899 detector.DetectedSignal().Connect( &application, functor );
1901 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1903 ConstraintData constraintData;
1904 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
1905 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
1906 Source( detector, PanGestureDetector::LOCAL_POSITION ),
1907 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
1908 PanConstraint( constraintData ) ) );
1910 // Render and notify
1911 application.SendNotification();
1912 application.Render();
1914 renderController.Initialize();
1915 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
1917 Vector2 screenPosition( 20.0f, 20.0f );
1918 Vector2 screenDisplacement( 1.0f, 1.0f );
1919 Vector2 localPosition( 21.0f, 21.0f );
1920 Vector2 localDisplacement( 0.5f, 0.5f );
1922 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement ) );
1923 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
1925 // Render and notify
1926 application.SendNotification();
1927 application.Render();
1929 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1930 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
1931 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
1932 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
1933 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
1934 constraintData.Reset();
1938 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
1940 TestApplication application;
1942 Actor actor = Actor::New();
1943 actor.SetSize(100.0f, 100.0f);
1944 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1945 Stage::GetCurrent().Add(actor);
1947 // Add a pan detector
1948 PanGestureDetector detector = PanGestureDetector::New();
1949 detector.Attach( actor );
1951 GestureReceivedFunctor functor( data );
1952 detector.DetectedSignal().Connect( &application, functor );
1954 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1956 ConstraintData constraintData;
1957 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
1958 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
1959 Source( detector, PanGestureDetector::LOCAL_POSITION ),
1960 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
1961 PanConstraint( constraintData ) ) );
1963 // Render and notify
1964 application.SendNotification();
1965 application.Render();
1967 Vector2 previousPosition( 20.0f, 20.0f );
1968 Vector2 currentPosition( 20.0f, 10.0f );
1969 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
1970 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
1971 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1973 Vector2 screenPosition( 100.0f, 20.0f );
1974 Vector2 localPosition( 110.0f, 110.0f );
1976 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
1978 // Render and notify
1979 application.SendNotification();
1980 application.Render();
1982 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1983 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
1984 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
1985 constraintData.Reset();
1989 int UtcDaliPanGesturePropertyIndices(void)
1991 TestApplication application;
1992 PanGestureDetector detector = PanGestureDetector::New();
1994 Property::IndexContainer indices;
1995 detector.GetPropertyIndices( indices );
1996 DALI_TEST_CHECK( ! indices.empty() );
1997 DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );