2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/dali.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali-test-suite-utils.h>
29 void utc_dali_pan_gesture_detector_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_pan_gesture_detector_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
42 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
45 // Stores data that is populated in the callback and will be read by the TET cases
49 : functorCalled(false),
50 voidFunctorCalled(false),
51 receivedGesture(Gesture::Clear)
56 functorCalled = false;
57 voidFunctorCalled = false;
59 receivedGesture.state = Gesture::Clear;
60 receivedGesture.velocity = Vector2(0.0f, 0.0f);
61 receivedGesture.displacement = Vector2(0.0f, 0.0f);
62 receivedGesture.position = Vector2(0.0f, 0.0f);
63 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
64 receivedGesture.numberOfTouches = 0;
70 bool voidFunctorCalled;
71 PanGesture receivedGesture;
75 // Functor that sets the data when called
76 struct GestureReceivedFunctor
78 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
80 void operator()(Actor actor, PanGesture pan)
82 signalData.functorCalled = true;
83 signalData.receivedGesture = pan;
84 signalData.pannedActor = actor;
89 signalData.voidFunctorCalled = true;
92 SignalData& signalData;
95 // Functor that removes the gestured actor from stage
96 struct UnstageActorFunctor : public GestureReceivedFunctor
98 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
99 : GestureReceivedFunctor( data ),
100 stateToUnstage( stateToUnstage )
104 void operator()( Actor actor, PanGesture pan )
106 GestureReceivedFunctor::operator()( actor, pan );
108 if ( pan.state == stateToUnstage )
110 Stage::GetCurrent().Remove( actor );
114 Gesture::State& stateToUnstage;
117 // Functor for receiving a touch event
118 struct TouchEventFunctor
120 bool operator()(Actor actor, const TouchEvent& touch)
126 // Data for constraints
127 struct ConstraintData
134 Vector2 screenPosition;
135 Vector2 screenDisplacement;
136 Vector2 localPosition;
137 Vector2 localDisplacement;
142 screenPosition = screenDisplacement = localPosition = localDisplacement = Vector2::ZERO;
147 // Constraint used with panning properties
150 PanConstraint( ConstraintData& data ) : constraintData(data) { }
152 Vector3 operator()(const Vector3& current,
153 const PropertyInput& screenPositionProperty,
154 const PropertyInput& screenDisplacementProperty,
155 const PropertyInput& localPositionProperty,
156 const PropertyInput& localDisplacementProperty)
158 constraintData.screenPosition = screenPositionProperty.GetVector2();
159 constraintData.screenDisplacement = screenDisplacementProperty.GetVector2();
160 constraintData.localPosition = localPositionProperty.GetVector2();
161 constraintData.localDisplacement = localDisplacementProperty.GetVector2();
162 constraintData.called = true;
163 return Vector3::ZERO;
166 ConstraintData& constraintData;
169 // Generate a PanGestureEvent to send to Core
170 Integration::PanGestureEvent GeneratePan(
171 Gesture::State state,
172 Vector2 previousPosition,
173 Vector2 currentPosition,
174 unsigned long timeDelta,
175 unsigned int numberOfTouches = 1,
176 unsigned int time = 1u)
178 Integration::PanGestureEvent pan(state);
180 pan.previousPosition = previousPosition;
181 pan.currentPosition = currentPosition;
182 pan.timeDelta = timeDelta;
183 pan.numberOfTouches = numberOfTouches;
189 // Generate a PanGesture
190 PanGesture GeneratePan( unsigned int time,
191 Gesture::State state,
192 Vector2 screenPosition,
193 Vector2 localPosition,
194 Vector2 screenDisplacement = Vector2::ONE,
195 Vector2 localDisplacement = Vector2::ONE,
196 Vector2 velocity = Vector2::ONE,
197 unsigned int numberOfTouches = 1 )
199 PanGesture pan( state );
203 pan.screenPosition = screenPosition;
204 pan.position = localPosition;
206 pan.screenDisplacement = screenDisplacement;
207 pan.displacement = localDisplacement;
209 pan.screenVelocity = pan.velocity = velocity;
210 pan.numberOfTouches = numberOfTouches;
217 ///////////////////////////////////////////////////////////////////////////////
219 // Positive test case for a method
220 int UtcDaliPanGestureDetectorConstructor(void)
222 TestApplication application;
224 PanGestureDetector detector;
225 DALI_TEST_CHECK(!detector);
230 // Negative test case for a method
231 int UtcDaliPanGestureDetectorNew(void)
233 TestApplication application;
235 PanGestureDetector detector = PanGestureDetector::New();
237 DALI_TEST_CHECK(detector);
239 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
240 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
242 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
243 Actor actor = Actor::New();
244 actor.SetSize(100.0f, 100.0f);
245 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
246 detector.Attach(actor);
248 Stage::GetCurrent().Add(actor);
251 application.SendNotification();
252 application.Render();
254 Integration::TouchEvent touchEvent(1);
255 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
256 touchEvent.AddPoint(point);
257 application.ProcessEvent(touchEvent);
261 int UtcDaliPanGestureDetectorDownCast(void)
263 TestApplication application;
264 tet_infoline("Testing Dali::GestureDetector::DownCast()");
266 PanGestureDetector detector = PanGestureDetector::New();
268 BaseHandle object(detector);
270 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
271 DALI_TEST_CHECK(detector2);
273 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
274 DALI_TEST_CHECK(detector3);
276 BaseHandle unInitializedObject;
277 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
278 DALI_TEST_CHECK(!detector4);
280 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
281 DALI_TEST_CHECK(!detector5);
283 GestureDetector detector6 = PanGestureDetector::New();
284 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
285 DALI_TEST_CHECK(detector7);
289 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
291 TestApplication application;
293 PanGestureDetector detector = PanGestureDetector::New();
295 unsigned int min = 2;
297 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
299 detector.SetMinimumTouchesRequired(min);
301 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
303 // Attach an actor and change the minimum touches
305 Actor actor = Actor::New();
306 actor.SetSize(100.0f, 100.0f);
307 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
308 Stage::GetCurrent().Add(actor);
311 application.SendNotification();
312 application.Render();
315 GestureReceivedFunctor functor(data);
317 detector.Attach(actor);
318 detector.DetectedSignal().Connect(&application, functor);
320 TestGestureManager& gestureManager = application.GetGestureManager();
321 gestureManager.Initialize();
323 detector.SetMinimumTouchesRequired(3);
325 // Gesture detection should have been updated only
326 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
327 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
328 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
331 gestureManager.Initialize();
333 // Create a second gesture detector that requires even less minimum touches
334 PanGestureDetector secondDetector = PanGestureDetector::New();
335 secondDetector.Attach(actor);
337 // Gesture detection should have been updated only
338 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
339 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
340 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
344 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
346 TestApplication application;
348 PanGestureDetector detector = PanGestureDetector::New();
350 unsigned int max = 3;
352 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
354 detector.SetMaximumTouchesRequired(max);
356 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
358 // Attach an actor and change the maximum touches
360 Actor actor = Actor::New();
361 actor.SetSize(100.0f, 100.0f);
362 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
363 Stage::GetCurrent().Add(actor);
366 application.SendNotification();
367 application.Render();
370 GestureReceivedFunctor functor(data);
372 detector.Attach(actor);
373 detector.DetectedSignal().Connect(&application, functor);
375 TestGestureManager& gestureManager = application.GetGestureManager();
376 gestureManager.Initialize();
378 detector.SetMaximumTouchesRequired(4);
380 // Gesture detection should have been updated only
381 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
382 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
383 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
386 gestureManager.Initialize();
388 // Create a second gesture detector that requires even less maximum touches
389 PanGestureDetector secondDetector = PanGestureDetector::New();
390 secondDetector.Attach(actor);
392 // Gesture detection should NOT have been updated
393 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
394 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
395 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
399 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
401 TestApplication application;
403 PanGestureDetector detector = PanGestureDetector::New();
404 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
408 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
410 TestApplication application;
412 PanGestureDetector detector = PanGestureDetector::New();
413 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
417 int UtcDaliPanGestureSignalReceptionNegative(void)
419 TestApplication application;
421 Actor actor = Actor::New();
422 actor.SetSize(100.0f, 100.0f);
423 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
424 Stage::GetCurrent().Add(actor);
427 application.SendNotification();
428 application.Render();
431 GestureReceivedFunctor functor(data);
433 PanGestureDetector detector = PanGestureDetector::New();
434 detector.Attach(actor);
435 detector.DetectedSignal().Connect(&application, functor);
437 // Do a pan outside actor's area
438 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
439 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
440 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
442 // Continue pan into actor's area - we should still not receive the signal
444 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
445 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
447 // Stop panning - we should still not receive the signal
449 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
450 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
454 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
456 TestApplication application;
458 Actor actor = Actor::New();
459 actor.SetSize(100.0f, 100.0f);
460 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
461 Stage::GetCurrent().Add(actor);
464 application.SendNotification();
465 application.Render();
468 GestureReceivedFunctor functor(data);
470 PanGestureDetector detector = PanGestureDetector::New();
471 detector.Attach(actor);
472 detector.DetectedSignal().Connect(&application, functor);
474 // Start pan within the actor's area
475 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
476 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
477 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
478 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
479 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
480 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
481 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
482 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
483 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
485 // Continue the pan within the actor's area - we should still receive the signal
487 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
488 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
489 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
490 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
491 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
492 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
493 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
494 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
496 // Pan Gesture leaves actor's area - we should still receive the signal
498 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
499 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
500 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
501 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
502 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
503 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
504 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
505 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
507 // Gesture ends - we would receive a finished state
509 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
510 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
511 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
512 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
513 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
514 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
515 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
516 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
520 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
522 TestApplication application;
524 Actor actor = Actor::New();
525 actor.SetSize(100.0f, 100.0f);
526 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
527 Stage::GetCurrent().Add(actor);
530 application.SendNotification();
531 application.Render();
534 GestureReceivedFunctor functor(data);
536 PanGestureDetector detector = PanGestureDetector::New();
537 detector.Attach(actor);
538 detector.DetectedSignal().Connect(&application, functor);
540 // Start pan within the actor's area
541 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
542 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
543 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
544 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
545 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
546 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
547 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
548 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
549 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
551 // Continue the pan within the actor's area - we should still receive the signal
553 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
554 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
555 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
556 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
557 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
558 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
559 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
562 // Gesture ends within actor's area - we would receive a finished state
564 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
565 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
566 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
567 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
568 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
569 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
570 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
571 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
575 int UtcDaliPanGestureSignalReceptionCancelled(void)
577 TestApplication application;
579 Actor actor = Actor::New();
580 actor.SetSize(100.0f, 100.0f);
581 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
582 Stage::GetCurrent().Add(actor);
585 application.SendNotification();
586 application.Render();
589 GestureReceivedFunctor functor(data);
591 PanGestureDetector detector = PanGestureDetector::New();
592 detector.Attach(actor);
593 detector.DetectedSignal().Connect(&application, functor);
595 // Start pan within the actor's area
596 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
597 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
598 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
599 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
601 // Continue the pan within the actor's area - we should still receive the signal
603 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
604 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
605 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
607 // The gesture is cancelled
609 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
610 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
611 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
615 int UtcDaliPanGestureSignalReceptionDetach(void)
617 TestApplication application;
619 Actor actor = Actor::New();
620 actor.SetSize(100.0f, 100.0f);
621 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
622 Stage::GetCurrent().Add(actor);
625 application.SendNotification();
626 application.Render();
629 GestureReceivedFunctor functor(data);
631 PanGestureDetector detector = PanGestureDetector::New();
632 detector.Attach(actor);
633 detector.DetectedSignal().Connect(&application, functor);
635 // Start pan within the actor's area
636 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
637 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
638 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
640 // Continue the pan within the actor's area - we should still receive the signal
642 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
643 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
645 // Gesture ends within actor's area
647 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
648 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
651 detector.DetachAll();
653 // Ensure we are no longer signalled
655 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
656 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
657 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
658 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
659 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
663 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
665 TestApplication application;
667 Actor actor = Actor::New();
668 actor.SetSize(100.0f, 100.0f);
669 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
670 Stage::GetCurrent().Add(actor);
673 application.SendNotification();
674 application.Render();
677 GestureReceivedFunctor functor(data);
679 PanGestureDetector detector = PanGestureDetector::New();
680 detector.Attach(actor);
681 detector.DetectedSignal().Connect(&application, functor);
683 // Start pan within the actor's area
684 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
685 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
686 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
688 // Continue the pan within the actor's area - we should still receive the signal
690 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
691 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
693 // Detach actor during the pan, we should not receive the next event
694 detector.DetachAll();
696 // Gesture ends within actor's area
698 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
699 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
703 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
705 TestApplication application;
708 GestureReceivedFunctor functor(data);
710 PanGestureDetector detector = PanGestureDetector::New();
711 detector.DetectedSignal().Connect(&application, functor);
713 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
715 Actor tempActor = Actor::New();
716 tempActor.SetSize(100.0f, 100.0f);
717 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
718 Stage::GetCurrent().Add(tempActor);
719 detector.Attach(tempActor);
721 // Actor lifetime is scoped
723 Actor actor = Actor::New();
724 actor.SetSize(100.0f, 100.0f);
725 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
726 Stage::GetCurrent().Add(actor);
729 application.SendNotification();
730 application.Render();
732 detector.Attach(actor);
734 // Start pan within the actor's area
735 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
736 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
737 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
739 // Continue the pan within the actor's area - we should still receive the signal
741 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
742 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
744 // Remove the actor from stage and reset the data
745 Stage::GetCurrent().Remove(actor);
748 application.SendNotification();
749 application.Render();
752 // Actor should now have been destroyed
754 // Gesture ends within the area where the actor used to be
756 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
757 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
761 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
763 TestApplication application;
765 Actor actor = Actor::New();
766 actor.SetSize(100.0f, 100.0f);
767 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
768 Stage::GetCurrent().Add(actor);
771 application.SendNotification();
772 application.Render();
775 GestureReceivedFunctor functor(data);
777 PanGestureDetector detector = PanGestureDetector::New();
778 detector.Attach(actor);
779 detector.DetectedSignal().Connect(&application, functor);
781 // Do an entire pan, only check finished value
782 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
783 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
785 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
786 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
787 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
789 // Rotate actor again and render a couple of times
790 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
791 application.SendNotification();
792 application.Render();
794 // Do an entire pan, only check finished value
795 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
796 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
798 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
799 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
800 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
802 // Rotate actor again and render a couple of times
803 actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
804 application.SendNotification();
805 application.Render();
807 // Do an entire pan, only check finished value
808 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
809 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
811 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
812 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
813 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
817 int UtcDaliPanGestureSignalReceptionChildHit(void)
819 TestApplication application;
821 Actor parent = Actor::New();
822 parent.SetSize(100.0f, 100.0f);
823 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
824 Stage::GetCurrent().Add(parent);
826 // Set child to completely cover parent.
827 // Change rotation of child to be different from parent so that we can check if our local coordinate
828 // conversion of the parent actor is correct.
829 Actor child = Actor::New();
830 child.SetSize(100.0f, 100.0f);
831 child.SetAnchorPoint(AnchorPoint::CENTER);
832 child.SetParentOrigin(ParentOrigin::CENTER);
833 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
836 TouchEventFunctor touchFunctor;
837 child.TouchedSignal().Connect(&application, touchFunctor);
840 application.SendNotification();
841 application.Render();
844 GestureReceivedFunctor functor(data);
846 PanGestureDetector detector = PanGestureDetector::New();
847 detector.Attach(parent);
848 detector.DetectedSignal().Connect(&application, functor);
850 // Do an entire pan, only check finished value - hits child area but parent should still receive it
851 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
852 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
854 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
855 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
856 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
857 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
859 // Attach child and generate same touch points to yield a different displacement
860 // (Also proves that you can detach and then re-attach another actor)
861 detector.Attach(child);
862 detector.Detach(parent);
864 // Do an entire pan, only check finished value
865 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
866 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
868 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
869 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
870 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
871 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
875 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
877 TestApplication application;
879 Actor first = Actor::New();
880 first.SetSize(100.0f, 100.0f);
881 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
882 Stage::GetCurrent().Add(first);
884 Actor second = Actor::New();
885 second.SetSize(100.0f, 100.0f);
887 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
888 Stage::GetCurrent().Add(second);
891 application.SendNotification();
892 application.Render();
895 GestureReceivedFunctor functor(data);
897 PanGestureDetector detector = PanGestureDetector::New();
898 detector.Attach(first);
899 detector.Attach(second);
900 detector.DetectedSignal().Connect(&application, functor);
902 // Start pan within second actor's area
903 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
904 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
905 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
906 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
908 // Pan moves into first actor's area - second actor should receive the pan
910 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
911 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
912 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
914 // Detach the second actor during the pan, we should not receive the next event
915 detector.Detach(second);
917 // Gesture ends within actor's area
919 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
920 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
924 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
926 TestApplication application;
928 Actor actor = Actor::New();
929 actor.SetSize(100.0f, 100.0f);
930 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
931 Stage::GetCurrent().Add(actor);
934 application.SendNotification();
935 application.Render();
938 GestureReceivedFunctor functor(data);
940 PanGestureDetector detector = PanGestureDetector::New();
941 detector.Attach(actor);
942 detector.DetectedSignal().Connect(&application, functor);
944 // Start pan in actor's area
945 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
946 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
947 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
949 // Pan continues within actor's area
951 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
952 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
954 // Actor become invisible - actor should not receive the next pan
955 actor.SetVisible(false);
958 application.SendNotification();
959 application.Render();
961 // Gesture ends within actor's area
963 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
964 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
968 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
970 TestApplication application;
971 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
973 Actor first = Actor::New();
974 first.SetSize(100.0f, 100.0f);
975 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
976 Stage::GetCurrent().Add(first);
978 Actor second = Actor::New();
979 second.SetSize(100.0f, 100.0f);
980 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
984 application.SendNotification();
985 application.Render();
988 GestureReceivedFunctor functor(data);
990 PanGestureDetector firstDetector = PanGestureDetector::New();
991 firstDetector.Attach(first);
992 firstDetector.DetectedSignal().Connect(&application, functor);
994 // secondDetector is scoped
996 // Reset gestureManager statistics
997 gestureManager.Initialize();
999 PanGestureDetector secondDetector = PanGestureDetector::New();
1000 secondDetector.SetMinimumTouchesRequired(2);
1001 secondDetector.SetMaximumTouchesRequired(2);
1002 secondDetector.Attach(second);
1003 secondDetector.DetectedSignal().Connect(&application, functor);
1005 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1006 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1007 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1009 // Start pan within second actor's area
1010 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1011 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1012 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1013 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1015 // Two touch pan changes to single touch - we should receive a finished state
1017 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1018 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1019 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1020 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1022 // Pan continues as single touch gesture - we should not receive any gesture
1024 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1025 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1027 // Pan ends - still no signal
1029 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1030 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1032 // Single touch pan starts - first actor should be panned
1034 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1035 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1036 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1037 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1039 // Pan changes to double-touch - we should receive a finished state
1041 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1042 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1043 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1044 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1046 // Pan continues as double touch gesture - we should not receive any gesture
1048 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1049 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1051 // Pan ends - still no signal
1053 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1054 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1056 // Reset gesture manager statistics
1057 gestureManager.Initialize();
1060 // secondDetector has now been deleted. Gesture detection should have been updated only
1061 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1062 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1063 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1067 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1069 TestApplication application;
1071 Actor actor = Actor::New();
1072 actor.SetSize(100.0f, 100.0f);
1073 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1074 Stage::GetCurrent().Add(actor);
1076 Actor actor2 = Actor::New();
1077 actor2.SetSize(100.0f, 100.0f);
1078 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1079 Stage::GetCurrent().Add(actor2);
1081 // Render and notify
1082 application.SendNotification();
1083 application.Render();
1085 // Attach actor to one detector
1086 SignalData firstData;
1087 GestureReceivedFunctor firstFunctor(firstData);
1088 PanGestureDetector firstDetector = PanGestureDetector::New();
1089 firstDetector.Attach(actor);
1090 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1092 // Attach actor to another detector
1093 SignalData secondData;
1094 GestureReceivedFunctor secondFunctor(secondData);
1095 PanGestureDetector secondDetector = PanGestureDetector::New();
1096 secondDetector.Attach(actor);
1097 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1099 // Add second actor to second detector, when we remove the actor, this will make sure that this
1100 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1101 // functor should still not be called (which is what we're also testing).
1102 secondDetector.Attach(actor2);
1104 // Pan in actor's area - both detector's functors should be called
1105 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1106 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1107 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1108 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1110 // Pan continues in actor's area - both detector's functors should be called
1113 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1114 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1115 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1117 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1118 firstDetector.Detach(actor);
1121 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1122 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1123 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1125 // New pan on actor, only secondDetector has actor attached
1128 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1129 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1130 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1131 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1133 // Detach actor from secondDetector
1134 secondDetector.Detach(actor);
1137 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1138 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1139 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1143 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1145 // Should handle two started events gracefully.
1147 TestApplication application;
1149 Actor actor = Actor::New();
1150 actor.SetSize(100.0f, 100.0f);
1151 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1152 Stage::GetCurrent().Add(actor);
1155 GestureReceivedFunctor functor(data);
1157 PanGestureDetector detector = PanGestureDetector::New();
1158 detector.Attach(actor);
1159 detector.DetectedSignal().Connect(&application, functor);
1161 // Render and notify
1162 application.SendNotification();
1163 application.Render();
1165 // Start pan in actor's area
1166 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1167 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1168 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1170 // Send another start in actor's area
1172 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1173 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1175 // Add a child actor to overlap actor and send another start in actor's area
1176 Actor child = Actor::New();
1177 child.SetSize(100.0f, 100.0f);
1178 child.SetAnchorPoint(AnchorPoint::CENTER);
1179 child.SetParentOrigin(ParentOrigin::CENTER);
1182 TouchEventFunctor touchFunctor;
1183 child.TouchedSignal().Connect(&application, touchFunctor);
1185 // Render and notify
1186 application.SendNotification();
1187 application.Render();
1189 // Send another possible and start in actor's area
1191 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1192 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1193 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1195 // Send another start in actor's area
1197 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1198 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1199 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1203 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1205 TestApplication application;
1207 Actor actor1 = Actor::New();
1208 actor1.SetSize(100.0f, 100.0f);
1209 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1210 Stage::GetCurrent().Add(actor1);
1212 GestureReceivedFunctor functor1(data1);
1213 PanGestureDetector detector1 = PanGestureDetector::New();
1214 detector1.Attach(actor1);
1215 detector1.DetectedSignal().Connect(&application, functor1);
1217 Actor actor2 = Actor::New();
1218 actor2.SetSize(100.0f, 100.0f);
1219 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1220 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1221 Stage::GetCurrent().Add(actor2);
1223 GestureReceivedFunctor functor2(data2);
1224 PanGestureDetector detector2 = PanGestureDetector::New();
1225 detector2.Attach(actor2);
1226 detector2.DetectedSignal().Connect(&application, functor2);
1228 // Render and notify
1229 application.SendNotification();
1230 application.Render();
1232 // Start pan in actor1's area, only data1 should be set
1233 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1234 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1235 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1236 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1240 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1242 TestApplication application;
1244 Actor actor = Actor::New();
1245 actor.SetSize(100.0f, 100.0f);
1246 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1247 Stage::GetCurrent().Add(actor);
1249 // Render and notify
1250 application.SendNotification();
1251 application.Render();
1253 // Attach actor to detector
1255 GestureReceivedFunctor functor( data );
1256 PanGestureDetector detector = PanGestureDetector::New();
1257 detector.Attach(actor);
1258 detector.DetectedSignal().Connect( &application, functor );
1260 // Gesture possible in actor's area.
1261 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1262 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1264 // Move actor somewhere else
1265 actor.SetPosition( 100.0f, 100.0f );
1267 // Render and notify
1268 application.SendNotification();
1269 application.Render();
1271 // Emit Started event, we should not receive the long press.
1272 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1273 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1274 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1276 // LongPress possible in empty area.
1277 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1278 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1280 // Move actor in to the long press position.
1281 actor.SetPosition( 0.0f, 0.0f );
1283 // Render and notify
1284 application.SendNotification();
1285 application.Render();
1287 // Emit Started event, we should not receive the long press.
1288 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1289 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1290 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1292 // Normal long press in actor's area for completeness.
1293 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1294 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1295 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1296 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1300 int UtcDaliPanGestureEmitIncorrectState(void)
1302 TestApplication application;
1304 Actor actor = Actor::New();
1305 actor.SetSize(100.0f, 100.0f);
1306 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1307 Stage::GetCurrent().Add(actor);
1309 // Render and notify
1310 application.SendNotification();
1311 application.Render();
1313 // Attach actor to detector
1315 GestureReceivedFunctor functor( data );
1316 PanGestureDetector detector = PanGestureDetector::New();
1317 detector.Attach(actor);
1318 detector.DetectedSignal().Connect( &application, functor );
1320 // Try a Clear state
1323 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1324 tet_result(TET_FAIL);
1326 catch ( Dali::DaliException& e )
1328 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1333 int UtcDaliPanGestureActorUnstaged(void)
1335 TestApplication application;
1337 Actor actor = Actor::New();
1338 actor.SetSize(100.0f, 100.0f);
1339 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1340 Stage::GetCurrent().Add(actor);
1342 // Render and notify
1343 application.SendNotification();
1344 application.Render();
1346 // State to remove actor in.
1347 Gesture::State stateToUnstage( Gesture::Started );
1349 // Attach actor to detector
1351 UnstageActorFunctor functor( data, stateToUnstage );
1352 PanGestureDetector detector = PanGestureDetector::New();
1353 detector.Attach(actor);
1354 detector.DetectedSignal().Connect( &application, functor );
1357 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1358 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1359 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1361 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1362 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1365 // Render and notify
1366 application.SendNotification();
1367 application.Render();
1369 // Re-add actor to stage
1370 Stage::GetCurrent().Add(actor);
1372 // Render and notify
1373 application.SendNotification();
1374 application.Render();
1376 // Change state to Gesture::Continuing to remove
1377 stateToUnstage = Gesture::Continuing;
1380 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1381 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1382 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1384 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1385 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1387 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1388 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1391 // Render and notify
1392 application.SendNotification();
1393 application.Render();
1395 // Re-add actor to stage
1396 Stage::GetCurrent().Add(actor);
1398 // Render and notify
1399 application.SendNotification();
1400 application.Render();
1402 // Change state to Gesture::Finished to remove
1403 stateToUnstage = Gesture::Finished;
1406 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1407 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1408 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1410 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1411 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1413 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1414 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1415 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1419 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1421 TestApplication application;
1423 Actor actor = Actor::New();
1424 actor.SetSize(100.0f, 100.0f);
1425 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1426 Stage::GetCurrent().Add(actor);
1428 // Create and add a second actor so that GestureDetector destruction does not come into play.
1429 Actor dummyActor( Actor::New() );
1430 dummyActor.SetSize( 100.0f, 100.0f );
1431 dummyActor.SetPosition( 100.0f, 100.0f );
1432 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1433 Stage::GetCurrent().Add(dummyActor);
1435 // Render and notify
1436 application.SendNotification();
1437 application.Render();
1439 // State to remove actor in.
1440 Gesture::State stateToUnstage( Gesture::Started );
1442 // Attach actor to detector
1444 UnstageActorFunctor functor( data, stateToUnstage );
1445 PanGestureDetector detector = PanGestureDetector::New();
1446 detector.Attach(actor);
1447 detector.Attach(dummyActor);
1448 detector.DetectedSignal().Connect( &application, functor );
1450 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1451 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1452 // position, we should still not be signalled.
1455 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1456 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1457 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1460 // Render and notify
1461 application.SendNotification();
1462 application.Render();
1464 // Re add to the stage, we should not be signalled
1465 Stage::GetCurrent().Add(actor);
1467 // Render and notify
1468 application.SendNotification();
1469 application.Render();
1471 // Continue signal emission
1472 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1473 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1475 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1476 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1479 // Here we delete an actor in started, we should not receive any subsequent signalling.
1482 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1483 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1484 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1487 // Render and notify
1488 application.SendNotification();
1489 application.Render();
1491 // Delete actor as well
1494 // Render and notify
1495 application.SendNotification();
1496 application.Render();
1498 // Continue signal emission
1499 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1500 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1502 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1503 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1507 int UtcDaliPanGestureSystemOverlay(void)
1509 TestApplication application;
1510 Dali::Integration::Core& core = application.GetCore();
1511 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1512 systemOverlay.GetOverlayRenderTasks().CreateTask();
1514 Actor actor = Actor::New();
1515 actor.SetSize(100.0f, 100.0f);
1516 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1517 systemOverlay.Add(actor);
1519 // Render and notify
1520 application.SendNotification();
1521 application.Render();
1524 GestureReceivedFunctor functor(data);
1526 PanGestureDetector detector = PanGestureDetector::New();
1527 detector.Attach(actor);
1528 detector.DetectedSignal().Connect(&application, functor);
1530 Vector2 screenCoordsStart( 10.0f, 20.0f );
1531 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1533 // Start pan within the actor's area
1534 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1535 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1536 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1540 int UtcDaliPanGestureAngleHandling(void)
1542 TestApplication application;
1544 PanGestureDetector detector = PanGestureDetector::New();
1545 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1546 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1548 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1549 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1550 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1552 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1554 tet_result( TET_PASS );
1558 if ( iter == endIter )
1560 tet_printf("%s, angle not added\n", TEST_LOCATION );
1561 tet_result( TET_FAIL );
1565 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1566 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1568 // Remove something not in the container.
1569 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1570 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1572 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1573 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1574 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1576 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1578 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1579 tet_result( TET_FAIL );
1584 detector.ClearAngles();
1585 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1589 inline float RadiansToDegrees( float radian )
1591 return radian * 180.0f / Math::PI;
1594 int UtcDaliPanGestureAngleOutOfRange(void)
1596 TestApplication application;
1598 PanGestureDetector detector = PanGestureDetector::New();
1599 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1600 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1606 detector.AddAngle( Degree(180.0f) );
1607 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1608 detector.ClearAngles();
1610 detector.AddAngle( Degree(190.0f) );
1611 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1612 detector.ClearAngles();
1614 detector.AddAngle( Degree(-190.0f) );
1615 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1616 detector.ClearAngles();
1618 detector.AddAngle( Degree(350.0f) );
1619 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1620 detector.ClearAngles();
1622 detector.AddAngle( Degree(-350.0f) );
1623 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1624 detector.ClearAngles();
1626 detector.AddAngle( Degree(370.0f) );
1627 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1628 detector.ClearAngles();
1630 detector.AddAngle( Degree(-370.0f) );
1631 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1632 detector.ClearAngles();
1638 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1639 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1640 detector.ClearAngles();
1642 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1643 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1644 detector.ClearAngles();
1646 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1647 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1648 detector.ClearAngles();
1650 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1651 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1652 detector.ClearAngles();
1656 int UtcDaliPanGestureAngleProcessing(void)
1658 TestApplication application;
1660 Actor parent = Actor::New();
1661 parent.SetSize(100.0f, 100.0f);
1662 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1663 Stage::GetCurrent().Add(parent);
1665 Actor child = Actor::New();
1666 child.SetSize(100.0f, 100.0f);
1667 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1670 // Render and notify
1671 application.SendNotification();
1672 application.Render();
1674 // Parent detector only requires up pans
1675 PanGestureDetector parentDetector = PanGestureDetector::New();
1676 parentDetector.Attach( parent );
1677 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1678 SignalData parentData;
1679 GestureReceivedFunctor parentFunctor(parentData);
1680 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1682 // Child detector only requires right pans
1683 PanGestureDetector childDetector = PanGestureDetector::New();
1684 childDetector.Attach( child );
1685 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1686 SignalData childData;
1687 GestureReceivedFunctor childFunctor(childData);
1688 childDetector.DetectedSignal().Connect(&application, childFunctor);
1690 // Generate an Up pan gesture, only parent should receive it.
1691 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1692 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1693 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1694 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1695 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1699 // Generate a Right pan gesture, only child should receive it.
1700 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1701 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1702 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1703 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1704 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1708 // Generate a Down pan gesture, no one should receive it.
1709 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1710 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1711 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1712 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1713 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1717 // Generate a Left pan gesture, no one should receive it.
1718 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1719 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1720 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1721 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1722 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1728 int UtcDaliPanGestureDirectionHandling(void)
1730 TestApplication application;
1732 PanGestureDetector detector = PanGestureDetector::New();
1733 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1734 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1736 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1737 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1738 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1740 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1742 tet_result( TET_PASS );
1746 if ( iter == endIter )
1748 tet_printf("%s, angle not added\n", TEST_LOCATION );
1749 tet_result( TET_FAIL );
1753 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1755 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1757 tet_result( TET_PASS );
1761 if ( iter == endIter )
1763 tet_printf("%s, angle not added\n", TEST_LOCATION );
1764 tet_result( TET_FAIL );
1768 // Remove something not in the container.
1769 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1770 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1772 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1773 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1777 int UtcDaliPanGestureDirectionProcessing(void)
1779 TestApplication application;
1781 Actor parent = Actor::New();
1782 parent.SetSize(100.0f, 100.0f);
1783 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1784 Stage::GetCurrent().Add(parent);
1786 Actor child = Actor::New();
1787 child.SetSize(100.0f, 100.0f);
1788 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1791 // Render and notify
1792 application.SendNotification();
1793 application.Render();
1795 // Parent detector only requires vertical panning
1796 PanGestureDetector parentDetector = PanGestureDetector::New();
1797 parentDetector.Attach( parent );
1798 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1799 SignalData parentData;
1800 GestureReceivedFunctor parentFunctor(parentData);
1801 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1803 // Child detector only requires horizontal panning
1804 PanGestureDetector childDetector = PanGestureDetector::New();
1805 childDetector.Attach( child );
1806 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1807 SignalData childData;
1808 GestureReceivedFunctor childFunctor(childData);
1809 childDetector.DetectedSignal().Connect(&application, childFunctor);
1811 // Generate an Up pan gesture, only parent should receive it.
1812 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1813 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1814 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1815 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1816 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1820 // Generate a Right pan gesture, only child should receive it.
1821 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1822 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1823 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1824 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1825 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1829 // Generate a Down pan gesture, only parent should receive it.
1830 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1831 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1832 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1833 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1834 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1838 // Generate a Left pan gesture, only child should receive it.
1839 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1840 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1841 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1842 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1843 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1847 // Generate a pan at -45 degrees, no one should receive it.
1848 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1849 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1850 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1851 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1852 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1856 // Generate a pan at 45 degrees, no one should receive it.
1857 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1858 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
1859 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1860 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1861 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1865 // Generate a pan at 135 degrees, no one should receive it.
1866 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1867 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1868 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1869 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1870 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1874 // Generate a pan at -135 degrees, no one should receive it.
1875 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1876 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
1877 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1878 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1879 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1885 int UtcDaliPanGestureSetProperties(void)
1887 TestApplication application;
1888 TestRenderController& renderController( application.GetRenderController() );
1890 Actor actor = Actor::New();
1891 actor.SetSize(100.0f, 100.0f);
1892 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1893 Stage::GetCurrent().Add(actor);
1895 // Add a pan detector
1896 PanGestureDetector detector = PanGestureDetector::New();
1897 detector.Attach( actor );
1899 GestureReceivedFunctor functor( data );
1900 detector.DetectedSignal().Connect( &application, functor );
1902 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1904 ConstraintData constraintData;
1905 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
1906 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
1907 Source( detector, PanGestureDetector::LOCAL_POSITION ),
1908 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
1909 PanConstraint( constraintData ) ) );
1911 // Render and notify
1912 application.SendNotification();
1913 application.Render();
1915 renderController.Initialize();
1916 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
1918 Vector2 screenPosition( 20.0f, 20.0f );
1919 Vector2 screenDisplacement( 1.0f, 1.0f );
1920 Vector2 localPosition( 21.0f, 21.0f );
1921 Vector2 localDisplacement( 0.5f, 0.5f );
1923 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement ) );
1924 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
1926 // Render and notify
1927 application.SendNotification();
1928 application.Render();
1930 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1931 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
1932 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
1933 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
1934 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
1935 constraintData.Reset();
1939 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
1941 TestApplication application;
1943 Actor actor = Actor::New();
1944 actor.SetSize(100.0f, 100.0f);
1945 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1946 Stage::GetCurrent().Add(actor);
1948 // Add a pan detector
1949 PanGestureDetector detector = PanGestureDetector::New();
1950 detector.Attach( actor );
1952 GestureReceivedFunctor functor( data );
1953 detector.DetectedSignal().Connect( &application, functor );
1955 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1957 ConstraintData constraintData;
1958 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
1959 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
1960 Source( detector, PanGestureDetector::LOCAL_POSITION ),
1961 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
1962 PanConstraint( constraintData ) ) );
1964 // Render and notify
1965 application.SendNotification();
1966 application.Render();
1968 Vector2 previousPosition( 20.0f, 20.0f );
1969 Vector2 currentPosition( 20.0f, 10.0f );
1970 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
1971 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
1972 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1974 Vector2 screenPosition( 100.0f, 20.0f );
1975 Vector2 localPosition( 110.0f, 110.0f );
1977 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
1979 // Render and notify
1980 application.SendNotification();
1981 application.Render();
1983 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1984 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
1985 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
1986 constraintData.Reset();
1990 int UtcDaliPanGesturePropertyIndices(void)
1992 TestApplication application;
1993 PanGestureDetector detector = PanGestureDetector::New();
1995 Property::IndexContainer indices;
1996 detector.GetPropertyIndices( indices );
1997 DALI_TEST_CHECK( ! indices.empty() );
1998 DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );