2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/integration-api/system-overlay.h>
26 #include <dali/integration-api/profiling.h>
27 #include <dali/integration-api/input-options.h>
28 #include <dali-test-suite-utils.h>
29 #include <test-touch-utils.h>
33 void utc_dali_pan_gesture_detector_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_pan_gesture_detector_cleanup(void)
40 test_return_value = TET_PASS;
43 ///////////////////////////////////////////////////////////////////////////////
46 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
48 const int PAN_EVENT_TIME_DELTA = 8;
49 const int PAN_GESTURE_UPDATE_COUNT = 50;
51 // Stores data that is populated in the callback and will be read by the test cases
55 : functorCalled(false),
56 voidFunctorCalled(false),
57 receivedGesture(Gesture::Clear)
62 functorCalled = false;
63 voidFunctorCalled = false;
65 receivedGesture.state = Gesture::Clear;
66 receivedGesture.velocity = Vector2(0.0f, 0.0f);
67 receivedGesture.displacement = Vector2(0.0f, 0.0f);
68 receivedGesture.position = Vector2(0.0f, 0.0f);
69 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
70 receivedGesture.numberOfTouches = 0;
76 bool voidFunctorCalled;
77 PanGesture receivedGesture;
81 // Functor that sets the data when called
82 struct GestureReceivedFunctor
84 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
86 void operator()(Actor actor, const PanGesture& pan)
88 signalData.functorCalled = true;
89 signalData.receivedGesture = pan;
90 signalData.pannedActor = actor;
95 signalData.voidFunctorCalled = true;
98 SignalData& signalData;
101 // Functor that removes the gestured actor from stage
102 struct UnstageActorFunctor : public GestureReceivedFunctor
104 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
105 : GestureReceivedFunctor( data ),
106 stateToUnstage( stateToUnstage )
110 void operator()( Actor actor, const PanGesture& pan )
112 GestureReceivedFunctor::operator()( actor, pan );
114 if ( pan.state == stateToUnstage )
116 Stage::GetCurrent().Remove( actor );
120 Gesture::State& stateToUnstage;
123 // Functor for receiving a touch event
124 struct TouchEventFunctor
126 bool operator()(Actor actor, const TouchEvent& touch)
132 // Data for constraints
133 struct ConstraintData
140 Vector2 screenPosition;
141 Vector2 screenDisplacement;
142 Vector2 screenVelocity;
143 Vector2 localPosition;
144 Vector2 localDisplacement;
145 Vector2 localVelocity;
150 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
155 // Constraint used with panning properties
158 PanConstraint( ConstraintData& data ) : constraintData(data) { }
160 void operator()( Vector3& current, const PropertyInputContainer& inputs )
162 constraintData.screenPosition = inputs[0]->GetVector2();
163 constraintData.screenDisplacement = inputs[1]->GetVector2();
164 constraintData.screenVelocity = inputs[2]->GetVector2();
165 constraintData.localPosition = inputs[3]->GetVector2();
166 constraintData.localDisplacement = inputs[4]->GetVector2();
167 constraintData.localVelocity = inputs[5]->GetVector2();
168 constraintData.called = true;
169 current = Vector3::ZERO;
172 ConstraintData& constraintData;
175 // Generate a PanGestureEvent to send to Core
176 Integration::PanGestureEvent GeneratePan(
177 Gesture::State state,
178 Vector2 previousPosition,
179 Vector2 currentPosition,
180 unsigned long timeDelta,
181 unsigned int numberOfTouches = 1,
182 unsigned int time = 1u)
184 Integration::PanGestureEvent pan(state);
186 pan.previousPosition = previousPosition;
187 pan.currentPosition = currentPosition;
188 pan.timeDelta = timeDelta;
189 pan.numberOfTouches = numberOfTouches;
195 // Generate a PanGesture
196 PanGesture GeneratePan( unsigned int time,
197 Gesture::State state,
198 Vector2 screenPosition,
199 Vector2 localPosition,
200 Vector2 screenDisplacement = Vector2::ONE,
201 Vector2 localDisplacement = Vector2::ONE,
202 Vector2 screenVelocity = Vector2::ONE,
203 Vector2 localVelocity = Vector2::ONE,
204 unsigned int numberOfTouches = 1 )
206 PanGesture pan( state );
210 pan.screenPosition = screenPosition;
211 pan.position = localPosition;
213 pan.screenDisplacement = screenDisplacement;
214 pan.displacement = localDisplacement;
216 pan.screenVelocity = screenVelocity;
217 pan.velocity = localVelocity;
219 pan.numberOfTouches = numberOfTouches;
225 * Helper to generate PanGestureEvent
227 * @param[in] application Application instance
228 * @param[in] state The Gesture State
229 * @param[in] pos The current position of touch.
231 static void SendPan(TestApplication& application, Gesture::State state, const Vector2& pos)
234 static int LastTime = 0;
236 if( (state == Gesture::Started) ||
237 (state == Gesture::Possible) )
243 application.ProcessEvent(GeneratePan(state, last, pos, PAN_EVENT_TIME_DELTA));
247 LastTime += PAN_EVENT_TIME_DELTA;
250 static Vector2 PerformSwipeGestureSwipe(TestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
252 // Now do a pan starting from (start) and heading (direction)
254 SendPan(application, Gesture::Possible, pos);
255 SendPan(application, Gesture::Started, pos);
256 application.SendNotification();
257 application.Render();
259 for(int i = 0;i<frames;i++)
261 pos += direction; // Move in this direction
262 SendPan(application, Gesture::Continuing, pos);
263 application.SendNotification();
264 application.Render();
269 SendPan(application, Gesture::Finished, pos);
270 application.SendNotification();
271 application.Render();
279 ///////////////////////////////////////////////////////////////////////////////
281 // Positive test case for a method
282 int UtcDaliPanGestureDetectorConstructor(void)
284 TestApplication application;
286 PanGestureDetector detector;
287 DALI_TEST_CHECK(!detector);
291 int UtcDaliPanGestureDetectorCopyConstructorP(void)
293 TestApplication application;
295 PanGestureDetector detector = PanGestureDetector::New();;
297 PanGestureDetector copy( detector );
298 DALI_TEST_CHECK( detector );
302 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
304 TestApplication application;
306 PanGestureDetector detector = PanGestureDetector::New();;
308 PanGestureDetector copy = detector;
309 DALI_TEST_CHECK( detector );
311 DALI_TEST_CHECK( detector == copy );
315 // Negative test case for a method
316 int UtcDaliPanGestureDetectorNew(void)
318 TestApplication application;
320 PanGestureDetector detector = PanGestureDetector::New();
322 DALI_TEST_CHECK(detector);
324 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
325 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
327 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
328 Actor actor = Actor::New();
329 actor.SetSize(100.0f, 100.0f);
330 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
331 detector.Attach(actor);
333 Stage::GetCurrent().Add(actor);
336 application.SendNotification();
337 application.Render();
339 Integration::TouchEvent touchEvent(1);
340 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
341 touchEvent.AddPoint(point);
342 application.ProcessEvent(touchEvent);
346 int UtcDaliPanGestureDetectorDownCast(void)
348 TestApplication application;
349 tet_infoline("Testing Dali::GestureDetector::DownCast()");
351 PanGestureDetector detector = PanGestureDetector::New();
353 BaseHandle object(detector);
355 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
356 DALI_TEST_CHECK(detector2);
358 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
359 DALI_TEST_CHECK(detector3);
361 BaseHandle unInitializedObject;
362 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
363 DALI_TEST_CHECK(!detector4);
365 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
366 DALI_TEST_CHECK(!detector5);
368 GestureDetector detector6 = PanGestureDetector::New();
369 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
370 DALI_TEST_CHECK(detector7);
374 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
376 TestApplication application;
378 PanGestureDetector detector = PanGestureDetector::New();
380 unsigned int min = 2;
382 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
384 detector.SetMinimumTouchesRequired(min);
386 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
388 // Attach an actor and change the minimum touches
390 Actor actor = Actor::New();
391 actor.SetSize(100.0f, 100.0f);
392 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
393 Stage::GetCurrent().Add(actor);
396 application.SendNotification();
397 application.Render();
400 GestureReceivedFunctor functor(data);
402 detector.Attach(actor);
403 detector.DetectedSignal().Connect(&application, functor);
405 TestGestureManager& gestureManager = application.GetGestureManager();
406 gestureManager.Initialize();
408 detector.SetMinimumTouchesRequired(3);
410 // Gesture detection should have been updated only
411 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
412 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
413 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
416 gestureManager.Initialize();
418 // Create a second gesture detector that requires even less minimum touches
419 PanGestureDetector secondDetector = PanGestureDetector::New();
420 secondDetector.Attach(actor);
422 // Gesture detection should have been updated only
423 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
424 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
425 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
429 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
431 TestApplication application;
433 PanGestureDetector detector = PanGestureDetector::New();
435 unsigned int max = 3;
437 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
439 detector.SetMaximumTouchesRequired(max);
441 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
443 // Attach an actor and change the maximum touches
445 Actor actor = Actor::New();
446 actor.SetSize(100.0f, 100.0f);
447 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
448 Stage::GetCurrent().Add(actor);
451 application.SendNotification();
452 application.Render();
455 GestureReceivedFunctor functor(data);
457 detector.Attach(actor);
458 detector.DetectedSignal().Connect(&application, functor);
460 TestGestureManager& gestureManager = application.GetGestureManager();
461 gestureManager.Initialize();
463 detector.SetMaximumTouchesRequired(4);
465 // Gesture detection should have been updated only
466 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
467 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
468 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
471 gestureManager.Initialize();
473 // Create a second gesture detector that requires even less maximum touches
474 PanGestureDetector secondDetector = PanGestureDetector::New();
475 secondDetector.Attach(actor);
477 // Gesture detection should NOT have been updated
478 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
479 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
480 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
484 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
486 TestApplication application;
488 PanGestureDetector detector = PanGestureDetector::New();
489 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
493 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
495 TestApplication application;
497 PanGestureDetector detector = PanGestureDetector::New();
498 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
502 int UtcDaliPanGestureSignalReceptionNegative(void)
504 TestApplication application;
506 Actor actor = Actor::New();
507 actor.SetSize(100.0f, 100.0f);
508 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
509 Stage::GetCurrent().Add(actor);
512 application.SendNotification();
513 application.Render();
516 GestureReceivedFunctor functor(data);
518 PanGestureDetector detector = PanGestureDetector::New();
519 detector.Attach(actor);
520 detector.DetectedSignal().Connect(&application, functor);
522 // Do a pan outside actor's area
523 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
524 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
525 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
527 // Continue pan into actor's area - we should still not receive the signal
529 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
530 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
532 // Stop panning - we should still not receive the signal
534 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
535 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
539 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
541 TestApplication application;
543 Actor actor = Actor::New();
544 actor.SetSize(100.0f, 100.0f);
545 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
546 Stage::GetCurrent().Add(actor);
549 application.SendNotification();
550 application.Render();
553 GestureReceivedFunctor functor(data);
555 PanGestureDetector detector = PanGestureDetector::New();
556 detector.Attach(actor);
557 detector.DetectedSignal().Connect(&application, functor);
559 // Start pan within the actor's area
560 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
561 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
562 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
563 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
564 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
565 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
566 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
568 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
570 // Continue the pan within the actor's area - we should still receive the signal
572 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
573 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
574 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
575 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
576 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
577 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
578 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
579 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
581 // Pan Gesture leaves actor's area - we should still receive the signal
583 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
584 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
585 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
586 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
587 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
588 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
589 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
590 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
592 // Gesture ends - we would receive a finished state
594 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
595 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
596 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
597 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
598 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
599 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
600 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
601 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
605 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
607 TestApplication application;
609 Actor actor = Actor::New();
610 actor.SetSize(100.0f, 100.0f);
611 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
612 Stage::GetCurrent().Add(actor);
615 application.SendNotification();
616 application.Render();
619 GestureReceivedFunctor functor(data);
621 PanGestureDetector detector = PanGestureDetector::New();
622 detector.Attach(actor);
623 detector.DetectedSignal().Connect(&application, functor);
625 // Start pan within the actor's area
626 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
627 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
628 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
629 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
630 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
631 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
632 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
633 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
634 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
636 // Continue the pan within the actor's area - we should still receive the signal
638 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
639 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
640 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
641 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
642 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
643 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
644 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
645 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
647 // Gesture ends within actor's area - we would receive a finished state
649 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
650 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
651 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
652 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
653 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
654 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
655 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
656 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
660 int UtcDaliPanGestureSignalReceptionCancelled(void)
662 TestApplication application;
664 Actor actor = Actor::New();
665 actor.SetSize(100.0f, 100.0f);
666 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
667 Stage::GetCurrent().Add(actor);
670 application.SendNotification();
671 application.Render();
674 GestureReceivedFunctor functor(data);
676 PanGestureDetector detector = PanGestureDetector::New();
677 detector.Attach(actor);
678 detector.DetectedSignal().Connect(&application, functor);
680 // Start pan within the actor's area
681 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
682 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
683 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
684 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
686 // Continue the pan within the actor's area - we should still receive the signal
688 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
689 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
690 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
692 // The gesture is cancelled
694 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
695 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
696 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
700 int UtcDaliPanGestureSignalReceptionDetach(void)
702 TestApplication application;
704 Actor actor = Actor::New();
705 actor.SetSize(100.0f, 100.0f);
706 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
707 Stage::GetCurrent().Add(actor);
710 application.SendNotification();
711 application.Render();
714 GestureReceivedFunctor functor(data);
716 PanGestureDetector detector = PanGestureDetector::New();
717 detector.Attach(actor);
718 detector.DetectedSignal().Connect(&application, functor);
720 // Start pan within the actor's area
721 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
722 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
723 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
725 // Continue the pan within the actor's area - we should still receive the signal
727 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
728 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
730 // Gesture ends within actor's area
732 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
733 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
736 detector.DetachAll();
738 // Ensure we are no longer signalled
740 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
741 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
742 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
743 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
744 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
748 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
750 TestApplication application;
752 Actor actor = Actor::New();
753 actor.SetSize(100.0f, 100.0f);
754 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
755 Stage::GetCurrent().Add(actor);
758 application.SendNotification();
759 application.Render();
762 GestureReceivedFunctor functor(data);
764 PanGestureDetector detector = PanGestureDetector::New();
765 detector.Attach(actor);
766 detector.DetectedSignal().Connect(&application, functor);
768 // Start pan within the actor's area
769 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
770 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
771 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
773 // Continue the pan within the actor's area - we should still receive the signal
775 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
776 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
778 // Detach actor during the pan, we should not receive the next event
779 detector.DetachAll();
781 // Gesture ends within actor's area
783 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
784 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
788 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
790 TestApplication application;
793 GestureReceivedFunctor functor(data);
795 PanGestureDetector detector = PanGestureDetector::New();
796 detector.DetectedSignal().Connect(&application, functor);
798 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
800 Actor tempActor = Actor::New();
801 tempActor.SetSize(100.0f, 100.0f);
802 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
803 Stage::GetCurrent().Add(tempActor);
804 detector.Attach(tempActor);
806 // Actor lifetime is scoped
808 Actor actor = Actor::New();
809 actor.SetSize(100.0f, 100.0f);
810 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
811 Stage::GetCurrent().Add(actor);
814 application.SendNotification();
815 application.Render();
817 detector.Attach(actor);
819 // Start pan within the actor's area
820 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
821 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
822 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
824 // Continue the pan within the actor's area - we should still receive the signal
826 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
827 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
829 // Remove the actor from stage and reset the data
830 Stage::GetCurrent().Remove(actor);
833 application.SendNotification();
834 application.Render();
837 // Actor should now have been destroyed
839 // Gesture ends within the area where the actor used to be
841 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
842 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
846 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
848 TestApplication application;
850 Actor actor = Actor::New();
851 actor.SetSize(100.0f, 100.0f);
852 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
853 Stage::GetCurrent().Add(actor);
856 application.SendNotification();
857 application.Render();
860 GestureReceivedFunctor functor(data);
862 PanGestureDetector detector = PanGestureDetector::New();
863 detector.Attach(actor);
864 detector.DetectedSignal().Connect(&application, functor);
866 // Do an entire pan, only check finished value
867 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
868 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
870 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
871 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
872 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
874 // Rotate actor again and render a couple of times
875 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
876 application.SendNotification();
877 application.Render();
879 // Do an entire pan, only check finished value
880 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
881 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
883 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
884 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
885 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
887 // Rotate actor again and render a couple of times
888 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
889 application.SendNotification();
890 application.Render();
892 // Do an entire pan, only check finished value
893 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
894 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
896 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
897 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
898 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
902 int UtcDaliPanGestureSignalReceptionChildHit(void)
904 TestApplication application;
906 Actor parent = Actor::New();
907 parent.SetSize(100.0f, 100.0f);
908 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
909 Stage::GetCurrent().Add(parent);
911 // Set child to completely cover parent.
912 // Change rotation of child to be different from parent so that we can check if our local coordinate
913 // conversion of the parent actor is correct.
914 Actor child = Actor::New();
915 child.SetSize(100.0f, 100.0f);
916 child.SetAnchorPoint(AnchorPoint::CENTER);
917 child.SetParentOrigin(ParentOrigin::CENTER);
918 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
921 TouchEventFunctor touchFunctor;
922 child.TouchedSignal().Connect(&application, touchFunctor);
925 application.SendNotification();
926 application.Render();
929 GestureReceivedFunctor functor(data);
931 PanGestureDetector detector = PanGestureDetector::New();
932 detector.Attach(parent);
933 detector.DetectedSignal().Connect(&application, functor);
935 // Do an entire pan, only check finished value - hits child area but parent should still receive it
936 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
937 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
939 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
940 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
941 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
942 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
944 // Attach child and generate same touch points to yield a different displacement
945 // (Also proves that you can detach and then re-attach another actor)
946 detector.Attach(child);
947 detector.Detach(parent);
949 // Do an entire pan, only check finished value
950 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
951 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
953 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
954 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
955 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
956 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
960 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
962 TestApplication application;
964 Actor first = Actor::New();
965 first.SetSize(100.0f, 100.0f);
966 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
967 Stage::GetCurrent().Add(first);
969 Actor second = Actor::New();
970 second.SetSize(100.0f, 100.0f);
972 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
973 Stage::GetCurrent().Add(second);
976 application.SendNotification();
977 application.Render();
980 GestureReceivedFunctor functor(data);
982 PanGestureDetector detector = PanGestureDetector::New();
983 detector.Attach(first);
984 detector.Attach(second);
985 detector.DetectedSignal().Connect(&application, functor);
987 // Start pan within second actor's area
988 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
989 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
990 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
991 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
993 // Pan moves into first actor's area - second actor should receive the pan
995 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
996 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
997 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
999 // Detach the second actor during the pan, we should not receive the next event
1000 detector.Detach(second);
1002 // Gesture ends within actor's area
1004 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1005 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1009 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1011 TestApplication application;
1013 Actor actor = Actor::New();
1014 actor.SetSize(100.0f, 100.0f);
1015 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1016 Stage::GetCurrent().Add(actor);
1018 // Render and notify
1019 application.SendNotification();
1020 application.Render();
1023 GestureReceivedFunctor functor(data);
1025 PanGestureDetector detector = PanGestureDetector::New();
1026 detector.Attach(actor);
1027 detector.DetectedSignal().Connect(&application, functor);
1029 // Start pan in actor's area
1030 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1031 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1032 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1034 // Pan continues within actor's area
1036 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1037 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1039 // Actor become invisible - actor should not receive the next pan
1040 actor.SetVisible(false);
1042 // Render and notify
1043 application.SendNotification();
1044 application.Render();
1046 // Gesture ends within actor's area
1048 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1049 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1053 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1055 TestApplication application;
1056 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1058 Actor first = Actor::New();
1059 first.SetSize(100.0f, 100.0f);
1060 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1061 Stage::GetCurrent().Add(first);
1063 Actor second = Actor::New();
1064 second.SetSize(100.0f, 100.0f);
1065 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1068 // Render and notify
1069 application.SendNotification();
1070 application.Render();
1073 GestureReceivedFunctor functor(data);
1075 PanGestureDetector firstDetector = PanGestureDetector::New();
1076 firstDetector.Attach(first);
1077 firstDetector.DetectedSignal().Connect(&application, functor);
1079 // secondDetector is scoped
1081 // Reset gestureManager statistics
1082 gestureManager.Initialize();
1084 PanGestureDetector secondDetector = PanGestureDetector::New();
1085 secondDetector.SetMinimumTouchesRequired(2);
1086 secondDetector.SetMaximumTouchesRequired(2);
1087 secondDetector.Attach(second);
1088 secondDetector.DetectedSignal().Connect(&application, functor);
1090 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1091 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1092 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1094 // Start pan within second actor's area
1095 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1096 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1097 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1098 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1100 // Two touch pan changes to single touch - we should receive a finished state
1102 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1103 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1104 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1105 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1107 // Pan continues as single touch gesture - we should not receive any gesture
1109 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1110 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1112 // Pan ends - still no signal
1114 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1115 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1117 // Single touch pan starts - first actor should be panned
1119 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1120 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1121 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1122 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1124 // Pan changes to double-touch - we should receive a finished state
1126 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1127 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1128 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1129 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1131 // Pan continues as double touch gesture - we should not receive any gesture
1133 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1134 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1136 // Pan ends - still no signal
1138 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1139 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1141 // Reset gesture manager statistics
1142 gestureManager.Initialize();
1145 // secondDetector has now been deleted. Gesture detection should have been updated only
1146 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1147 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1148 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1152 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1154 TestApplication application;
1156 Actor actor = Actor::New();
1157 actor.SetSize(100.0f, 100.0f);
1158 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1159 Stage::GetCurrent().Add(actor);
1161 Actor actor2 = Actor::New();
1162 actor2.SetSize(100.0f, 100.0f);
1163 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1164 Stage::GetCurrent().Add(actor2);
1166 // Render and notify
1167 application.SendNotification();
1168 application.Render();
1170 // Attach actor to one detector
1171 SignalData firstData;
1172 GestureReceivedFunctor firstFunctor(firstData);
1173 PanGestureDetector firstDetector = PanGestureDetector::New();
1174 firstDetector.Attach(actor);
1175 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1177 // Attach actor to another detector
1178 SignalData secondData;
1179 GestureReceivedFunctor secondFunctor(secondData);
1180 PanGestureDetector secondDetector = PanGestureDetector::New();
1181 secondDetector.Attach(actor);
1182 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1184 // Add second actor to second detector, when we remove the actor, this will make sure that this
1185 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1186 // functor should still not be called (which is what we're also testing).
1187 secondDetector.Attach(actor2);
1189 // Pan in actor's area - both detector's functors should be called
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, firstData.functorCalled, TEST_LOCATION);
1193 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1195 // Pan continues in actor's area - both detector's functors should be called
1198 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1199 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1200 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1202 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1203 firstDetector.Detach(actor);
1206 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1207 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1208 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1210 // New pan on actor, only secondDetector has actor attached
1213 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1214 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1215 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1216 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1218 // Detach actor from secondDetector
1219 secondDetector.Detach(actor);
1222 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1223 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1224 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1228 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1230 // Should handle two started events gracefully.
1232 TestApplication application;
1234 Actor actor = Actor::New();
1235 actor.SetSize(100.0f, 100.0f);
1236 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1237 Stage::GetCurrent().Add(actor);
1240 GestureReceivedFunctor functor(data);
1242 PanGestureDetector detector = PanGestureDetector::New();
1243 detector.Attach(actor);
1244 detector.DetectedSignal().Connect(&application, functor);
1246 // Render and notify
1247 application.SendNotification();
1248 application.Render();
1250 // Start pan in actor's area
1251 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1252 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1253 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1255 // Send another start in actor's area
1257 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1258 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1260 // Add a child actor to overlap actor and send another start in actor's area
1261 Actor child = Actor::New();
1262 child.SetSize(100.0f, 100.0f);
1263 child.SetAnchorPoint(AnchorPoint::CENTER);
1264 child.SetParentOrigin(ParentOrigin::CENTER);
1267 TouchEventFunctor touchFunctor;
1268 child.TouchedSignal().Connect(&application, touchFunctor);
1270 // Render and notify
1271 application.SendNotification();
1272 application.Render();
1274 // Send another possible and start in actor's area
1276 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1277 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1278 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1280 // Send another start in actor's area
1282 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1283 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1284 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1288 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1290 TestApplication application;
1292 Actor actor1 = Actor::New();
1293 actor1.SetSize(100.0f, 100.0f);
1294 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1295 Stage::GetCurrent().Add(actor1);
1297 GestureReceivedFunctor functor1(data1);
1298 PanGestureDetector detector1 = PanGestureDetector::New();
1299 detector1.Attach(actor1);
1300 detector1.DetectedSignal().Connect(&application, functor1);
1302 Actor actor2 = Actor::New();
1303 actor2.SetSize(100.0f, 100.0f);
1304 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1305 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1306 Stage::GetCurrent().Add(actor2);
1308 GestureReceivedFunctor functor2(data2);
1309 PanGestureDetector detector2 = PanGestureDetector::New();
1310 detector2.Attach(actor2);
1311 detector2.DetectedSignal().Connect(&application, functor2);
1313 // Render and notify
1314 application.SendNotification();
1315 application.Render();
1317 // Start pan in actor1's area, only data1 should be set
1318 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1319 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1320 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1321 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1325 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1327 TestApplication application;
1329 Actor actor = Actor::New();
1330 actor.SetSize(100.0f, 100.0f);
1331 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1332 Stage::GetCurrent().Add(actor);
1334 // Render and notify
1335 application.SendNotification();
1336 application.Render();
1338 // Attach actor to detector
1340 GestureReceivedFunctor functor( data );
1341 PanGestureDetector detector = PanGestureDetector::New();
1342 detector.Attach(actor);
1343 detector.DetectedSignal().Connect( &application, functor );
1345 // Gesture possible in actor's area.
1346 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1347 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1349 // Move actor somewhere else
1350 actor.SetPosition( 100.0f, 100.0f );
1352 // Render and notify
1353 application.SendNotification();
1354 application.Render();
1356 // Emit Started event, we should not receive the long press.
1357 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1358 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1359 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1361 // LongPress possible in empty area.
1362 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1363 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1365 // Move actor in to the long press position.
1366 actor.SetPosition( 0.0f, 0.0f );
1368 // Render and notify
1369 application.SendNotification();
1370 application.Render();
1372 // Emit Started event, we should not receive the long press.
1373 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1374 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1375 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1377 // Normal long press in actor's area for completeness.
1378 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1379 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1380 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1381 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1385 int UtcDaliPanGestureEmitIncorrectState(void)
1387 TestApplication application;
1389 Actor actor = Actor::New();
1390 actor.SetSize(100.0f, 100.0f);
1391 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1392 Stage::GetCurrent().Add(actor);
1394 // Render and notify
1395 application.SendNotification();
1396 application.Render();
1398 // Attach actor to detector
1400 GestureReceivedFunctor functor( data );
1401 PanGestureDetector detector = PanGestureDetector::New();
1402 detector.Attach(actor);
1403 detector.DetectedSignal().Connect( &application, functor );
1405 // Try a Clear state
1408 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1409 tet_result(TET_FAIL);
1411 catch ( Dali::DaliException& e )
1413 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1418 int UtcDaliPanGestureActorUnstaged(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 // Render and notify
1428 application.SendNotification();
1429 application.Render();
1431 // State to remove actor in.
1432 Gesture::State stateToUnstage( Gesture::Started );
1434 // Attach actor to detector
1436 UnstageActorFunctor functor( data, stateToUnstage );
1437 PanGestureDetector detector = PanGestureDetector::New();
1438 detector.Attach(actor);
1439 detector.DetectedSignal().Connect( &application, functor );
1442 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1443 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1444 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1446 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1447 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1450 // Render and notify
1451 application.SendNotification();
1452 application.Render();
1454 // Re-add actor to stage
1455 Stage::GetCurrent().Add(actor);
1457 // Render and notify
1458 application.SendNotification();
1459 application.Render();
1461 // Change state to Gesture::Continuing to remove
1462 stateToUnstage = Gesture::Continuing;
1465 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1466 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1467 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1469 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1470 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1472 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1473 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1476 // Render and notify
1477 application.SendNotification();
1478 application.Render();
1480 // Re-add actor to stage
1481 Stage::GetCurrent().Add(actor);
1483 // Render and notify
1484 application.SendNotification();
1485 application.Render();
1487 // Change state to Gesture::Finished to remove
1488 stateToUnstage = Gesture::Finished;
1491 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1492 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1493 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1495 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1496 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1498 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1499 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1500 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1504 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1506 TestApplication application;
1508 Actor actor = Actor::New();
1509 actor.SetSize(100.0f, 100.0f);
1510 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1511 Stage::GetCurrent().Add(actor);
1513 // Create and add a second actor so that GestureDetector destruction does not come into play.
1514 Actor dummyActor( Actor::New() );
1515 dummyActor.SetSize( 100.0f, 100.0f );
1516 dummyActor.SetPosition( 100.0f, 100.0f );
1517 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1518 Stage::GetCurrent().Add(dummyActor);
1520 // Render and notify
1521 application.SendNotification();
1522 application.Render();
1524 // State to remove actor in.
1525 Gesture::State stateToUnstage( Gesture::Started );
1527 // Attach actor to detector
1529 UnstageActorFunctor functor( data, stateToUnstage );
1530 PanGestureDetector detector = PanGestureDetector::New();
1531 detector.Attach(actor);
1532 detector.Attach(dummyActor);
1533 detector.DetectedSignal().Connect( &application, functor );
1535 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1536 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1537 // position, we should still not be signalled.
1540 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1541 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1542 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1545 // Render and notify
1546 application.SendNotification();
1547 application.Render();
1549 // Re add to the stage, we should not be signalled
1550 Stage::GetCurrent().Add(actor);
1552 // Render and notify
1553 application.SendNotification();
1554 application.Render();
1556 // Continue signal emission
1557 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1558 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1560 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1561 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1564 // Here we delete an actor in started, we should not receive any subsequent signalling.
1567 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1568 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1569 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1572 // Render and notify
1573 application.SendNotification();
1574 application.Render();
1576 // Delete actor as well
1579 // Render and notify
1580 application.SendNotification();
1581 application.Render();
1583 // Continue signal emission
1584 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1585 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1587 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1588 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1592 int UtcDaliPanGestureSystemOverlay(void)
1594 TestApplication application;
1595 Dali::Integration::Core& core = application.GetCore();
1596 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1597 systemOverlay.GetOverlayRenderTasks().CreateTask();
1599 Actor actor = Actor::New();
1600 actor.SetSize(100.0f, 100.0f);
1601 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1602 systemOverlay.Add(actor);
1604 // Render and notify
1605 application.SendNotification();
1606 application.Render();
1609 GestureReceivedFunctor functor(data);
1611 PanGestureDetector detector = PanGestureDetector::New();
1612 detector.Attach(actor);
1613 detector.DetectedSignal().Connect(&application, functor);
1615 Vector2 screenCoordsStart( 10.0f, 20.0f );
1616 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1618 // Start pan within the actor's area
1619 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1620 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1621 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1625 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1627 TestApplication application;
1628 Dali::Integration::Core& core = application.GetCore();
1629 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1630 systemOverlay.GetOverlayRenderTasks().CreateTask();
1632 // SystemOverlay actor
1633 Actor systemOverlayActor = Actor::New();
1634 systemOverlayActor.SetSize(100.0f, 100.0f);
1635 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1636 systemOverlay.Add(systemOverlayActor);
1639 Actor stageActor = Actor::New();
1640 stageActor.SetSize(100.0f, 100.0f);
1641 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1642 Stage::GetCurrent().Add(stageActor);
1644 // Render and notify
1645 application.SendNotification();
1646 application.Render();
1648 // Set system-overlay actor to touchable
1649 TouchEventData touchData;
1650 TouchEventDataFunctor touchFunctor( touchData );
1651 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1653 // Set stage actor to receive the gesture
1655 GestureReceivedFunctor functor(data);
1657 PanGestureDetector detector = PanGestureDetector::New();
1658 detector.Attach(stageActor);
1659 detector.DetectedSignal().Connect(&application, functor);
1661 Vector2 screenCoordsStart( 10.0f, 20.0f );
1662 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1664 // Start pan within the two actors' area
1665 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1666 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1667 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1668 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1669 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1674 // Do touch in the same area
1675 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1676 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1677 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1682 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1684 TestApplication application;
1685 Dali::Integration::Core& core = application.GetCore();
1686 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1687 systemOverlay.GetOverlayRenderTasks().CreateTask();
1689 // SystemOverlay actor
1690 Actor systemOverlayActor = Actor::New();
1691 systemOverlayActor.SetSize(100.0f, 100.0f);
1692 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1693 systemOverlay.Add(systemOverlayActor);
1696 Actor stageActor = Actor::New();
1697 stageActor.SetSize(100.0f, 100.0f);
1698 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1699 Stage::GetCurrent().Add(stageActor);
1701 // Render and notify
1702 application.SendNotification();
1703 application.Render();
1705 // Set stage actor to touchable
1706 TouchEventData touchData;
1707 TouchEventDataFunctor touchFunctor( touchData );
1708 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1710 // Set system-overlay actor to have the gesture
1712 GestureReceivedFunctor functor(data);
1714 PanGestureDetector detector = PanGestureDetector::New();
1715 detector.Attach(systemOverlayActor);
1716 detector.DetectedSignal().Connect(&application, functor);
1718 Vector2 screenCoordsStart( 10.0f, 20.0f );
1719 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1721 // Start pan within the two actors' area
1722 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1723 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1724 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1725 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1726 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1731 // Do touch in the same area
1732 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1733 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1734 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1739 int UtcDaliPanGestureAngleHandling(void)
1741 TestApplication application;
1743 PanGestureDetector detector = PanGestureDetector::New();
1744 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1745 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1747 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1748 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1749 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1751 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1753 tet_result( TET_PASS );
1757 if ( iter == endIter )
1759 tet_printf("%s, angle not added\n", TEST_LOCATION );
1760 tet_result( TET_FAIL );
1764 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1765 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1767 // Remove something not in the container.
1768 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1769 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1771 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1772 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1773 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1775 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1777 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1778 tet_result( TET_FAIL );
1783 detector.ClearAngles();
1784 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1788 inline float RadiansToDegrees( float radian )
1790 return radian * 180.0f / Math::PI;
1793 int UtcDaliPanGestureAngleOutOfRange(void)
1795 TestApplication application;
1797 PanGestureDetector detector = PanGestureDetector::New();
1798 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1799 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1805 detector.AddAngle( Degree(180.0f) );
1806 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1807 detector.ClearAngles();
1809 detector.AddAngle( Degree(190.0f) );
1810 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1811 detector.ClearAngles();
1813 detector.AddAngle( Degree(-190.0f) );
1814 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1815 detector.ClearAngles();
1817 detector.AddAngle( Degree(350.0f) );
1818 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1819 detector.ClearAngles();
1821 detector.AddAngle( Degree(-350.0f) );
1822 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1823 detector.ClearAngles();
1825 detector.AddAngle( Degree(370.0f) );
1826 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1827 detector.ClearAngles();
1829 detector.AddAngle( Degree(-370.0f) );
1830 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1831 detector.ClearAngles();
1837 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1838 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1839 detector.ClearAngles();
1841 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1842 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1843 detector.ClearAngles();
1845 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1846 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1847 detector.ClearAngles();
1849 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1850 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1851 detector.ClearAngles();
1855 int UtcDaliPanGestureAngleProcessing(void)
1857 TestApplication application;
1859 Actor parent = Actor::New();
1860 parent.SetSize(100.0f, 100.0f);
1861 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1862 Stage::GetCurrent().Add(parent);
1864 Actor child = Actor::New();
1865 child.SetSize(100.0f, 100.0f);
1866 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1869 // Render and notify
1870 application.SendNotification();
1871 application.Render();
1873 // Parent detector only requires up pans
1874 PanGestureDetector parentDetector = PanGestureDetector::New();
1875 parentDetector.Attach( parent );
1876 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1877 SignalData parentData;
1878 GestureReceivedFunctor parentFunctor(parentData);
1879 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1881 // Child detector only requires right pans
1882 PanGestureDetector childDetector = PanGestureDetector::New();
1883 childDetector.Attach( child );
1884 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1885 SignalData childData;
1886 GestureReceivedFunctor childFunctor(childData);
1887 childDetector.DetectedSignal().Connect(&application, childFunctor);
1889 // Generate an Up pan gesture, only parent should receive it.
1890 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1891 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1892 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1893 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1894 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1898 // Generate a Right pan gesture, only child should receive it.
1899 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1900 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1901 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1902 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1903 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1907 // Generate a Down pan gesture, no one should receive it.
1908 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1909 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1910 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1911 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1912 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1916 // Generate a Left pan gesture, no one should receive it.
1917 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1918 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1919 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1920 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1921 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1927 int UtcDaliPanGestureDirectionHandling(void)
1929 TestApplication application;
1931 PanGestureDetector detector = PanGestureDetector::New();
1932 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1933 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1935 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1936 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1937 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1939 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1941 tet_result( TET_PASS );
1945 if ( iter == endIter )
1947 tet_printf("%s, angle not added\n", TEST_LOCATION );
1948 tet_result( TET_FAIL );
1952 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1954 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1956 tet_result( TET_PASS );
1960 if ( iter == endIter )
1962 tet_printf("%s, angle not added\n", TEST_LOCATION );
1963 tet_result( TET_FAIL );
1967 // Remove something not in the container.
1968 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1969 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1971 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1972 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1976 int UtcDaliPanGestureDirectionProcessing(void)
1978 TestApplication application;
1980 Actor parent = Actor::New();
1981 parent.SetSize(100.0f, 100.0f);
1982 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1983 Stage::GetCurrent().Add(parent);
1985 Actor child = Actor::New();
1986 child.SetSize(100.0f, 100.0f);
1987 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1990 // Render and notify
1991 application.SendNotification();
1992 application.Render();
1994 // Parent detector only requires vertical panning
1995 PanGestureDetector parentDetector = PanGestureDetector::New();
1996 parentDetector.Attach( parent );
1997 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1998 SignalData parentData;
1999 GestureReceivedFunctor parentFunctor(parentData);
2000 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2002 // Child detector only requires horizontal panning
2003 PanGestureDetector childDetector = PanGestureDetector::New();
2004 childDetector.Attach( child );
2005 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2006 SignalData childData;
2007 GestureReceivedFunctor childFunctor(childData);
2008 childDetector.DetectedSignal().Connect(&application, childFunctor);
2010 // Generate an Up pan gesture, only parent should receive it.
2011 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2012 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
2013 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2014 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2015 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2019 // Generate a Right pan gesture, only child should receive it.
2020 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2021 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2022 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2023 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2024 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2028 // Generate a Down pan gesture, only parent should receive it.
2029 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2030 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2031 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2032 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2033 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2037 // Generate a Left pan gesture, only child should receive it.
2038 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2039 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2040 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2041 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2042 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2046 // Generate a pan at -45 degrees, no one should receive it.
2047 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2048 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2049 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2050 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2051 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2055 // Generate a pan at 45 degrees, no one should receive it.
2056 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2057 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2058 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2059 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2060 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2064 // Generate a pan at 135 degrees, no one should receive it.
2065 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2066 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2067 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2068 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2069 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2073 // Generate a pan at -135 degrees, no one should receive it.
2074 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2075 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2076 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2077 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2078 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2084 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2086 TestApplication application;
2087 Integration::SetPanGesturePredictionMode(0);
2088 Integration::SetPanGestureSmoothingMode(0);
2090 Actor actor = Actor::New();
2091 actor.SetSize(100.0f, 100.0f);
2092 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2093 Stage::GetCurrent().Add(actor);
2095 // Add a pan detector
2096 PanGestureDetector detector = PanGestureDetector::New();
2097 detector.Attach( actor );
2099 GestureReceivedFunctor functor( data );
2100 detector.DetectedSignal().Connect( &application, functor );
2102 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2104 ConstraintData constraintData;
2105 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2106 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2107 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2108 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2109 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2110 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2111 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2114 // Render and notify
2115 application.SendNotification();
2116 application.Render();
2118 Vector2 direction(Vector2::XAXIS * -5.0f);
2119 Vector2 startPosition( 1.0f, 1.0f );
2120 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2121 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2122 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2123 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2124 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2126 constraintData.Reset();
2130 int UtcDaliPanGestureNoPredictionSmoothing(void)
2132 TestApplication application;
2133 Integration::SetPanGesturePredictionMode(0);
2134 Integration::SetPanGestureSmoothingMode(1);
2136 Actor actor = Actor::New();
2137 actor.SetSize(100.0f, 100.0f);
2138 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2139 Stage::GetCurrent().Add(actor);
2141 // Add a pan detector
2142 PanGestureDetector detector = PanGestureDetector::New();
2143 detector.Attach( actor );
2145 GestureReceivedFunctor functor( data );
2146 detector.DetectedSignal().Connect( &application, functor );
2148 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2150 ConstraintData constraintData;
2151 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2152 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2153 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2154 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2155 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2156 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2157 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2160 // Render and notify
2161 application.SendNotification();
2162 application.Render();
2164 Vector2 direction(Vector2::XAXIS * -5.0f);
2165 Vector2 previousPosition( 20.0f, 20.0f );
2166 Vector2 currentPosition( 20.0f, 10.0f );
2167 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2168 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2169 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2170 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2171 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2173 constraintData.Reset();
2177 int UtcDaliPanGesturePredictionNoSmoothing(void)
2179 TestApplication application;
2180 Integration::SetPanGesturePredictionMode(1);
2181 Integration::SetPanGestureSmoothingMode(0);
2183 Actor actor = Actor::New();
2184 actor.SetSize(100.0f, 100.0f);
2185 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2186 Stage::GetCurrent().Add(actor);
2188 // Add a pan detector
2189 PanGestureDetector detector = PanGestureDetector::New();
2190 detector.Attach( actor );
2192 GestureReceivedFunctor functor( data );
2193 detector.DetectedSignal().Connect( &application, functor );
2195 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2197 ConstraintData constraintData;
2198 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2199 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2200 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2201 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2202 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2203 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2204 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2207 // Render and notify
2208 application.SendNotification();
2209 application.Render();
2211 Vector2 direction(Vector2::XAXIS * -1.0f);
2212 Vector2 previousPosition( 20.0f, 20.0f );
2213 Vector2 currentPosition( 20.0f, 10.0f );
2214 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2215 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2216 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2217 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2218 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2220 constraintData.Reset();
2224 int UtcDaliPanGesturePredictionSmoothing(void)
2226 TestApplication application;
2227 Integration::SetPanGesturePredictionMode(1);
2228 Integration::SetPanGestureSmoothingMode(1);
2230 Actor actor = Actor::New();
2231 actor.SetSize(100.0f, 100.0f);
2232 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2233 Stage::GetCurrent().Add(actor);
2235 // Add a pan detector
2236 PanGestureDetector detector = PanGestureDetector::New();
2237 detector.Attach( actor );
2239 GestureReceivedFunctor functor( data );
2240 detector.DetectedSignal().Connect( &application, functor );
2242 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2244 ConstraintData constraintData;
2245 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2246 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2247 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2248 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2249 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2250 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2251 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2254 // Render and notify
2255 application.SendNotification();
2256 application.Render();
2258 Vector2 direction(Vector2::XAXIS * -1.0f);
2259 Vector2 previousPosition( 20.0f, 20.0f );
2260 Vector2 currentPosition( 20.0f, 10.0f );
2261 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2262 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2263 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2264 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2265 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2267 constraintData.Reset();
2271 int UtcDaliPanGestureSetProperties(void)
2273 TestApplication application;
2274 TestRenderController& renderController( application.GetRenderController() );
2275 Integration::SetPanGesturePredictionMode(0);
2276 Integration::SetPanGestureSmoothingMode(0);
2278 Actor actor = Actor::New();
2279 actor.SetSize(100.0f, 100.0f);
2280 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2281 Stage::GetCurrent().Add(actor);
2283 // Add a pan detector
2284 PanGestureDetector detector = PanGestureDetector::New();
2285 detector.Attach( actor );
2287 GestureReceivedFunctor functor( data );
2288 detector.DetectedSignal().Connect( &application, functor );
2290 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2292 ConstraintData constraintData;
2293 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2294 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2295 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2296 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2297 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2298 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2299 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2302 // Render and notify
2303 application.SendNotification();
2304 application.Render();
2306 renderController.Initialize();
2307 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2309 Vector2 screenPosition( 20.0f, 20.0f );
2310 Vector2 screenDisplacement( 1.0f, 1.0f );
2311 Vector2 screenVelocity( 1.3f, 4.0f );
2312 Vector2 localPosition( 21.0f, 21.0f );
2313 Vector2 localDisplacement( 0.5f, 0.5f );
2314 Vector2 localVelocity( 1.5f, 2.5f );
2316 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2317 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2319 // Render and notify
2320 application.SendNotification();
2321 application.Render();
2323 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2324 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2325 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2326 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2327 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2328 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2329 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2330 constraintData.Reset();
2334 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2336 TestApplication application;
2337 Integration::SetPanGesturePredictionMode(0);
2339 Actor actor = Actor::New();
2340 actor.SetSize(100.0f, 100.0f);
2341 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2342 Stage::GetCurrent().Add(actor);
2344 // Add a pan detector
2345 PanGestureDetector detector = PanGestureDetector::New();
2346 detector.Attach( actor );
2348 GestureReceivedFunctor functor( data );
2349 detector.DetectedSignal().Connect( &application, functor );
2351 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2353 ConstraintData constraintData;
2354 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2355 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2356 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2357 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2358 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2359 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2360 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2363 // Render and notify
2364 application.SendNotification();
2365 application.Render();
2367 Vector2 previousPosition( 20.0f, 20.0f );
2368 Vector2 currentPosition( 20.0f, 10.0f );
2369 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2370 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2371 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2373 Vector2 screenPosition( 100.0f, 20.0f );
2374 Vector2 localPosition( 110.0f, 110.0f );
2376 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2378 // Render and notify
2379 application.SendNotification();
2380 application.Render();
2382 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2383 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2384 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2385 constraintData.Reset();
2389 int UtcDaliPanGesturePropertyIndices(void)
2391 TestApplication application;
2392 PanGestureDetector detector = PanGestureDetector::New();
2394 Property::IndexContainer indices;
2395 detector.GetPropertyIndices( indices );
2396 DALI_TEST_CHECK( ! indices.empty() );
2397 DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );
2401 int UtcDaliPanGestureLayerConsumesTouch(void)
2403 TestApplication application;
2405 Actor actor = Actor::New();
2406 actor.SetSize(100.0f, 100.0f);
2407 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2408 Stage::GetCurrent().Add(actor);
2410 // Add a pan detector
2411 PanGestureDetector detector = PanGestureDetector::New();
2412 detector.Attach( actor );
2414 GestureReceivedFunctor functor( data );
2415 detector.DetectedSignal().Connect( &application, functor );
2417 // Add a layer to overlap the actor
2418 Layer layer = Layer::New();
2419 layer.SetSize(100.0f, 100.0f);
2420 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2421 Stage::GetCurrent().Add( layer );
2424 // Render and notify
2425 application.SendNotification();
2426 application.Render();
2428 // Emit signals, should receive
2429 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2430 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2431 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2432 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2435 // Set layer to consume all touch
2436 layer.SetTouchConsumed( true );
2438 // Render and notify
2439 application.SendNotification();
2440 application.Render();
2442 // Emit the same signals again, should not receive
2443 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2444 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2445 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2446 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2452 int UtcDaliPanGestureNoTimeDiff(void)
2454 TestApplication application;
2456 Actor actor = Actor::New();
2457 actor.SetSize(100.0f, 100.0f);
2458 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2459 Stage::GetCurrent().Add(actor);
2461 // Add a pan detector
2462 PanGestureDetector detector = PanGestureDetector::New();
2463 detector.Attach( actor );
2465 GestureReceivedFunctor functor( data );
2466 detector.DetectedSignal().Connect( &application, functor );
2468 // Render and notify
2469 application.SendNotification();
2470 application.Render();
2472 // Emit signals, should receive
2473 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2474 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2475 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2476 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2477 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2478 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2479 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2480 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );