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 assign;
310 DALI_TEST_CHECK( detector );
312 DALI_TEST_CHECK( detector == assign );
316 // Negative test case for a method
317 int UtcDaliPanGestureDetectorNew(void)
319 TestApplication application;
321 PanGestureDetector detector = PanGestureDetector::New();
323 DALI_TEST_CHECK(detector);
325 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
326 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
328 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
329 Actor actor = Actor::New();
330 actor.SetSize(100.0f, 100.0f);
331 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
332 detector.Attach(actor);
334 Stage::GetCurrent().Add(actor);
337 application.SendNotification();
338 application.Render();
340 Integration::TouchEvent touchEvent(1);
341 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
342 touchEvent.AddPoint(point);
343 application.ProcessEvent(touchEvent);
347 int UtcDaliPanGestureDetectorDownCast(void)
349 TestApplication application;
350 tet_infoline("Testing Dali::GestureDetector::DownCast()");
352 PanGestureDetector detector = PanGestureDetector::New();
354 BaseHandle object(detector);
356 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
357 DALI_TEST_CHECK(detector2);
359 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
360 DALI_TEST_CHECK(detector3);
362 BaseHandle unInitializedObject;
363 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
364 DALI_TEST_CHECK(!detector4);
366 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
367 DALI_TEST_CHECK(!detector5);
369 GestureDetector detector6 = PanGestureDetector::New();
370 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
371 DALI_TEST_CHECK(detector7);
375 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
377 TestApplication application;
379 PanGestureDetector detector = PanGestureDetector::New();
381 unsigned int min = 2;
383 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
385 detector.SetMinimumTouchesRequired(min);
387 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
389 // Attach an actor and change the minimum touches
391 Actor actor = Actor::New();
392 actor.SetSize(100.0f, 100.0f);
393 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
394 Stage::GetCurrent().Add(actor);
397 application.SendNotification();
398 application.Render();
401 GestureReceivedFunctor functor(data);
403 detector.Attach(actor);
404 detector.DetectedSignal().Connect(&application, functor);
406 TestGestureManager& gestureManager = application.GetGestureManager();
407 gestureManager.Initialize();
409 detector.SetMinimumTouchesRequired(3);
411 // Gesture detection should have been updated only
412 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
413 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
414 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
417 gestureManager.Initialize();
419 // Create a second gesture detector that requires even less minimum touches
420 PanGestureDetector secondDetector = PanGestureDetector::New();
421 secondDetector.Attach(actor);
423 // Gesture detection should have been updated only
424 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
425 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
426 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
430 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
432 TestApplication application;
434 PanGestureDetector detector = PanGestureDetector::New();
436 unsigned int max = 3;
438 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
440 detector.SetMaximumTouchesRequired(max);
442 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
444 // Attach an actor and change the maximum touches
446 Actor actor = Actor::New();
447 actor.SetSize(100.0f, 100.0f);
448 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
449 Stage::GetCurrent().Add(actor);
452 application.SendNotification();
453 application.Render();
456 GestureReceivedFunctor functor(data);
458 detector.Attach(actor);
459 detector.DetectedSignal().Connect(&application, functor);
461 TestGestureManager& gestureManager = application.GetGestureManager();
462 gestureManager.Initialize();
464 detector.SetMaximumTouchesRequired(4);
466 // Gesture detection should have been updated only
467 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
468 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
469 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
472 gestureManager.Initialize();
474 // Create a second gesture detector that requires even less maximum touches
475 PanGestureDetector secondDetector = PanGestureDetector::New();
476 secondDetector.Attach(actor);
478 // Gesture detection should NOT have been updated
479 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
480 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
481 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
485 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
487 TestApplication application;
489 PanGestureDetector detector = PanGestureDetector::New();
490 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
494 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
496 TestApplication application;
498 PanGestureDetector detector = PanGestureDetector::New();
499 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
503 int UtcDaliPanGestureSignalReceptionNegative(void)
505 TestApplication application;
507 Actor actor = Actor::New();
508 actor.SetSize(100.0f, 100.0f);
509 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
510 Stage::GetCurrent().Add(actor);
513 application.SendNotification();
514 application.Render();
517 GestureReceivedFunctor functor(data);
519 PanGestureDetector detector = PanGestureDetector::New();
520 detector.Attach(actor);
521 detector.DetectedSignal().Connect(&application, functor);
523 // Do a pan outside actor's area
524 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
525 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
526 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
528 // Continue pan into actor's area - we should still not receive the signal
530 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
531 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
533 // Stop panning - we should still not receive the signal
535 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
536 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
540 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
542 TestApplication application;
544 Actor actor = Actor::New();
545 actor.SetSize(100.0f, 100.0f);
546 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
547 Stage::GetCurrent().Add(actor);
550 application.SendNotification();
551 application.Render();
554 GestureReceivedFunctor functor(data);
556 PanGestureDetector detector = PanGestureDetector::New();
557 detector.Attach(actor);
558 detector.DetectedSignal().Connect(&application, functor);
560 // Start pan within the actor's area
561 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
562 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
563 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
564 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
565 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
566 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
568 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
569 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
571 // Continue the pan within the actor's area - we should still receive the signal
573 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
574 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
575 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
576 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
577 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
578 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
579 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
580 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
582 // Pan Gesture leaves actor's area - we should still receive the signal
584 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
585 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
586 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
587 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
588 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
589 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
590 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
591 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
593 // Gesture ends - we would receive a finished state
595 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
596 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
597 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
598 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
599 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
600 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
601 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
602 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
606 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
608 TestApplication application;
610 Actor actor = Actor::New();
611 actor.SetSize(100.0f, 100.0f);
612 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
613 Stage::GetCurrent().Add(actor);
616 application.SendNotification();
617 application.Render();
620 GestureReceivedFunctor functor(data);
622 PanGestureDetector detector = PanGestureDetector::New();
623 detector.Attach(actor);
624 detector.DetectedSignal().Connect(&application, functor);
626 // Start pan within the actor's area
627 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
628 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
629 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
630 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
631 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
632 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
633 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
634 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
635 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
637 // Continue the pan within the actor's area - we should still receive the signal
639 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
640 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
641 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
642 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
643 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
644 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
645 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
646 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
648 // Gesture ends within actor's area - we would receive a finished state
650 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
651 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
652 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
653 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
654 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
655 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
656 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
657 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
661 int UtcDaliPanGestureSignalReceptionCancelled(void)
663 TestApplication application;
665 Actor actor = Actor::New();
666 actor.SetSize(100.0f, 100.0f);
667 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
668 Stage::GetCurrent().Add(actor);
671 application.SendNotification();
672 application.Render();
675 GestureReceivedFunctor functor(data);
677 PanGestureDetector detector = PanGestureDetector::New();
678 detector.Attach(actor);
679 detector.DetectedSignal().Connect(&application, functor);
681 // Start pan within the actor's area
682 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
683 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
684 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
685 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
687 // Continue the pan within the actor's area - we should still receive the signal
689 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
690 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
691 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
693 // The gesture is cancelled
695 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
696 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
697 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
701 int UtcDaliPanGestureSignalReceptionDetach(void)
703 TestApplication application;
705 Actor actor = Actor::New();
706 actor.SetSize(100.0f, 100.0f);
707 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
708 Stage::GetCurrent().Add(actor);
711 application.SendNotification();
712 application.Render();
715 GestureReceivedFunctor functor(data);
717 PanGestureDetector detector = PanGestureDetector::New();
718 detector.Attach(actor);
719 detector.DetectedSignal().Connect(&application, functor);
721 // Start pan within the actor's area
722 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
723 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
724 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
726 // Continue the pan within the actor's area - we should still receive the signal
728 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
729 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
731 // Gesture ends within actor's area
733 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
734 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
737 detector.DetachAll();
739 // Ensure we are no longer signalled
741 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
742 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
743 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
744 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
745 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
749 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
751 TestApplication application;
753 Actor actor = Actor::New();
754 actor.SetSize(100.0f, 100.0f);
755 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
756 Stage::GetCurrent().Add(actor);
759 application.SendNotification();
760 application.Render();
763 GestureReceivedFunctor functor(data);
765 PanGestureDetector detector = PanGestureDetector::New();
766 detector.Attach(actor);
767 detector.DetectedSignal().Connect(&application, functor);
769 // Start pan within the actor's area
770 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
771 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
772 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
774 // Continue the pan within the actor's area - we should still receive the signal
776 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
777 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
779 // Detach actor during the pan, we should not receive the next event
780 detector.DetachAll();
782 // Gesture ends within actor's area
784 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
785 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
789 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
791 TestApplication application;
794 GestureReceivedFunctor functor(data);
796 PanGestureDetector detector = PanGestureDetector::New();
797 detector.DetectedSignal().Connect(&application, functor);
799 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
801 Actor tempActor = Actor::New();
802 tempActor.SetSize(100.0f, 100.0f);
803 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
804 Stage::GetCurrent().Add(tempActor);
805 detector.Attach(tempActor);
807 // Actor lifetime is scoped
809 Actor actor = Actor::New();
810 actor.SetSize(100.0f, 100.0f);
811 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
812 Stage::GetCurrent().Add(actor);
815 application.SendNotification();
816 application.Render();
818 detector.Attach(actor);
820 // Start pan within the actor's area
821 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
822 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
823 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
825 // Continue the pan within the actor's area - we should still receive the signal
827 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
828 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
830 // Remove the actor from stage and reset the data
831 Stage::GetCurrent().Remove(actor);
834 application.SendNotification();
835 application.Render();
838 // Actor should now have been destroyed
840 // Gesture ends within the area where the actor used to be
842 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
843 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
847 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
849 TestApplication application;
851 Actor actor = Actor::New();
852 actor.SetSize(100.0f, 100.0f);
853 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
854 Stage::GetCurrent().Add(actor);
857 application.SendNotification();
858 application.Render();
861 GestureReceivedFunctor functor(data);
863 PanGestureDetector detector = PanGestureDetector::New();
864 detector.Attach(actor);
865 detector.DetectedSignal().Connect(&application, functor);
867 // Do an entire pan, only check finished value
868 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
869 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
871 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
872 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
873 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
875 // Rotate actor again and render a couple of times
876 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
877 application.SendNotification();
878 application.Render();
880 // Do an entire pan, only check finished value
881 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
882 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
884 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
885 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
886 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
888 // Rotate actor again and render a couple of times
889 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
890 application.SendNotification();
891 application.Render();
893 // Do an entire pan, only check finished value
894 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
895 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
897 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
898 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
899 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
903 int UtcDaliPanGestureSignalReceptionChildHit(void)
905 TestApplication application;
907 Actor parent = Actor::New();
908 parent.SetSize(100.0f, 100.0f);
909 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
910 Stage::GetCurrent().Add(parent);
912 // Set child to completely cover parent.
913 // Change rotation of child to be different from parent so that we can check if our local coordinate
914 // conversion of the parent actor is correct.
915 Actor child = Actor::New();
916 child.SetSize(100.0f, 100.0f);
917 child.SetAnchorPoint(AnchorPoint::CENTER);
918 child.SetParentOrigin(ParentOrigin::CENTER);
919 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
922 TouchEventFunctor touchFunctor;
923 child.TouchedSignal().Connect(&application, touchFunctor);
926 application.SendNotification();
927 application.Render();
930 GestureReceivedFunctor functor(data);
932 PanGestureDetector detector = PanGestureDetector::New();
933 detector.Attach(parent);
934 detector.DetectedSignal().Connect(&application, functor);
936 // Do an entire pan, only check finished value - hits child area but parent should still receive it
937 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
938 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
940 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
941 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
942 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
943 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
945 // Attach child and generate same touch points to yield a different displacement
946 // (Also proves that you can detach and then re-attach another actor)
947 detector.Attach(child);
948 detector.Detach(parent);
950 // Do an entire pan, only check finished value
951 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
952 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
954 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
955 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
956 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
957 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
961 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
963 TestApplication application;
965 Actor first = Actor::New();
966 first.SetSize(100.0f, 100.0f);
967 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
968 Stage::GetCurrent().Add(first);
970 Actor second = Actor::New();
971 second.SetSize(100.0f, 100.0f);
973 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
974 Stage::GetCurrent().Add(second);
977 application.SendNotification();
978 application.Render();
981 GestureReceivedFunctor functor(data);
983 PanGestureDetector detector = PanGestureDetector::New();
984 detector.Attach(first);
985 detector.Attach(second);
986 detector.DetectedSignal().Connect(&application, functor);
988 // Start pan within second actor's area
989 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
990 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
991 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
992 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
994 // Pan moves into first actor's area - second actor should receive the pan
996 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
997 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
998 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1000 // Detach the second actor during the pan, we should not receive the next event
1001 detector.Detach(second);
1003 // Gesture ends within actor's area
1005 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1006 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1010 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1012 TestApplication application;
1014 Actor actor = Actor::New();
1015 actor.SetSize(100.0f, 100.0f);
1016 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1017 Stage::GetCurrent().Add(actor);
1019 // Render and notify
1020 application.SendNotification();
1021 application.Render();
1024 GestureReceivedFunctor functor(data);
1026 PanGestureDetector detector = PanGestureDetector::New();
1027 detector.Attach(actor);
1028 detector.DetectedSignal().Connect(&application, functor);
1030 // Start pan in actor's area
1031 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1032 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1033 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1035 // Pan continues within actor's area
1037 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1038 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1040 // Actor become invisible - actor should not receive the next pan
1041 actor.SetVisible(false);
1043 // Render and notify
1044 application.SendNotification();
1045 application.Render();
1047 // Gesture ends within actor's area
1049 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1050 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1054 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1056 TestApplication application;
1057 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1059 Actor first = Actor::New();
1060 first.SetSize(100.0f, 100.0f);
1061 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1062 Stage::GetCurrent().Add(first);
1064 Actor second = Actor::New();
1065 second.SetSize(100.0f, 100.0f);
1066 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1069 // Render and notify
1070 application.SendNotification();
1071 application.Render();
1074 GestureReceivedFunctor functor(data);
1076 PanGestureDetector firstDetector = PanGestureDetector::New();
1077 firstDetector.Attach(first);
1078 firstDetector.DetectedSignal().Connect(&application, functor);
1080 // secondDetector is scoped
1082 // Reset gestureManager statistics
1083 gestureManager.Initialize();
1085 PanGestureDetector secondDetector = PanGestureDetector::New();
1086 secondDetector.SetMinimumTouchesRequired(2);
1087 secondDetector.SetMaximumTouchesRequired(2);
1088 secondDetector.Attach(second);
1089 secondDetector.DetectedSignal().Connect(&application, functor);
1091 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1092 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1093 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1095 // Start pan within second actor's area
1096 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1097 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1098 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1099 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1101 // Two touch pan changes to single touch - we should receive a finished state
1103 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1104 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1105 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1106 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1108 // Pan continues as single touch gesture - we should not receive any gesture
1110 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1111 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1113 // Pan ends - still no signal
1115 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1116 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1118 // Single touch pan starts - first actor should be panned
1120 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1121 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1122 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1123 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1125 // Pan changes to double-touch - we should receive a finished state
1127 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1128 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1129 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1130 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1132 // Pan continues as double touch gesture - we should not receive any gesture
1134 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1135 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1137 // Pan ends - still no signal
1139 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1140 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1142 // Reset gesture manager statistics
1143 gestureManager.Initialize();
1146 // secondDetector has now been deleted. Gesture detection should have been updated only
1147 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1148 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1149 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1153 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1155 TestApplication application;
1157 Actor actor = Actor::New();
1158 actor.SetSize(100.0f, 100.0f);
1159 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1160 Stage::GetCurrent().Add(actor);
1162 Actor actor2 = Actor::New();
1163 actor2.SetSize(100.0f, 100.0f);
1164 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1165 Stage::GetCurrent().Add(actor2);
1167 // Render and notify
1168 application.SendNotification();
1169 application.Render();
1171 // Attach actor to one detector
1172 SignalData firstData;
1173 GestureReceivedFunctor firstFunctor(firstData);
1174 PanGestureDetector firstDetector = PanGestureDetector::New();
1175 firstDetector.Attach(actor);
1176 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1178 // Attach actor to another detector
1179 SignalData secondData;
1180 GestureReceivedFunctor secondFunctor(secondData);
1181 PanGestureDetector secondDetector = PanGestureDetector::New();
1182 secondDetector.Attach(actor);
1183 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1185 // Add second actor to second detector, when we remove the actor, this will make sure that this
1186 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1187 // functor should still not be called (which is what we're also testing).
1188 secondDetector.Attach(actor2);
1190 // Pan in actor's area - both detector's functors should be called
1191 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1192 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1193 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1194 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1196 // Pan continues in actor's area - both detector's functors should be called
1199 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1200 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1201 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1203 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1204 firstDetector.Detach(actor);
1207 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1208 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1209 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1211 // New pan on actor, only secondDetector has actor attached
1214 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1215 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1216 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1217 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1219 // Detach actor from secondDetector
1220 secondDetector.Detach(actor);
1223 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1224 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1225 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1229 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1231 // Should handle two started events gracefully.
1233 TestApplication application;
1235 Actor actor = Actor::New();
1236 actor.SetSize(100.0f, 100.0f);
1237 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1238 Stage::GetCurrent().Add(actor);
1241 GestureReceivedFunctor functor(data);
1243 PanGestureDetector detector = PanGestureDetector::New();
1244 detector.Attach(actor);
1245 detector.DetectedSignal().Connect(&application, functor);
1247 // Render and notify
1248 application.SendNotification();
1249 application.Render();
1251 // Start pan in actor's area
1252 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1253 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1254 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1256 // Send another start in actor's area
1258 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1259 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1261 // Add a child actor to overlap actor and send another start in actor's area
1262 Actor child = Actor::New();
1263 child.SetSize(100.0f, 100.0f);
1264 child.SetAnchorPoint(AnchorPoint::CENTER);
1265 child.SetParentOrigin(ParentOrigin::CENTER);
1268 TouchEventFunctor touchFunctor;
1269 child.TouchedSignal().Connect(&application, touchFunctor);
1271 // Render and notify
1272 application.SendNotification();
1273 application.Render();
1275 // Send another possible and start in actor's area
1277 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1278 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1279 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1281 // Send another start in actor's area
1283 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1284 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1285 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1289 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1291 TestApplication application;
1293 Actor actor1 = Actor::New();
1294 actor1.SetSize(100.0f, 100.0f);
1295 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1296 Stage::GetCurrent().Add(actor1);
1298 GestureReceivedFunctor functor1(data1);
1299 PanGestureDetector detector1 = PanGestureDetector::New();
1300 detector1.Attach(actor1);
1301 detector1.DetectedSignal().Connect(&application, functor1);
1303 Actor actor2 = Actor::New();
1304 actor2.SetSize(100.0f, 100.0f);
1305 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1306 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1307 Stage::GetCurrent().Add(actor2);
1309 GestureReceivedFunctor functor2(data2);
1310 PanGestureDetector detector2 = PanGestureDetector::New();
1311 detector2.Attach(actor2);
1312 detector2.DetectedSignal().Connect(&application, functor2);
1314 // Render and notify
1315 application.SendNotification();
1316 application.Render();
1318 // Start pan in actor1's area, only data1 should be set
1319 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1320 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1321 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1322 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1326 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1328 TestApplication application;
1330 Actor actor = Actor::New();
1331 actor.SetSize(100.0f, 100.0f);
1332 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1333 Stage::GetCurrent().Add(actor);
1335 // Render and notify
1336 application.SendNotification();
1337 application.Render();
1339 // Attach actor to detector
1341 GestureReceivedFunctor functor( data );
1342 PanGestureDetector detector = PanGestureDetector::New();
1343 detector.Attach(actor);
1344 detector.DetectedSignal().Connect( &application, functor );
1346 // Gesture possible in actor's area.
1347 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1348 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1350 // Move actor somewhere else
1351 actor.SetPosition( 100.0f, 100.0f );
1353 // Render and notify
1354 application.SendNotification();
1355 application.Render();
1357 // Emit Started event, we should not receive the long press.
1358 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1359 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1360 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1362 // LongPress possible in empty area.
1363 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1364 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1366 // Move actor in to the long press position.
1367 actor.SetPosition( 0.0f, 0.0f );
1369 // Render and notify
1370 application.SendNotification();
1371 application.Render();
1373 // Emit Started event, we should not receive the long press.
1374 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1375 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1376 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1378 // Normal long press in actor's area for completeness.
1379 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1380 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1381 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1382 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1386 int UtcDaliPanGestureEmitIncorrectState(void)
1388 TestApplication application;
1390 Actor actor = Actor::New();
1391 actor.SetSize(100.0f, 100.0f);
1392 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1393 Stage::GetCurrent().Add(actor);
1395 // Render and notify
1396 application.SendNotification();
1397 application.Render();
1399 // Attach actor to detector
1401 GestureReceivedFunctor functor( data );
1402 PanGestureDetector detector = PanGestureDetector::New();
1403 detector.Attach(actor);
1404 detector.DetectedSignal().Connect( &application, functor );
1406 // Try a Clear state
1409 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1410 tet_result(TET_FAIL);
1412 catch ( Dali::DaliException& e )
1414 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1419 int UtcDaliPanGestureActorUnstaged(void)
1421 TestApplication application;
1423 Actor actor = Actor::New();
1424 actor.SetSize(100.0f, 100.0f);
1425 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1426 Stage::GetCurrent().Add(actor);
1428 // Render and notify
1429 application.SendNotification();
1430 application.Render();
1432 // State to remove actor in.
1433 Gesture::State stateToUnstage( Gesture::Started );
1435 // Attach actor to detector
1437 UnstageActorFunctor functor( data, stateToUnstage );
1438 PanGestureDetector detector = PanGestureDetector::New();
1439 detector.Attach(actor);
1440 detector.DetectedSignal().Connect( &application, functor );
1443 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1444 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1445 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1447 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1448 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1451 // Render and notify
1452 application.SendNotification();
1453 application.Render();
1455 // Re-add actor to stage
1456 Stage::GetCurrent().Add(actor);
1458 // Render and notify
1459 application.SendNotification();
1460 application.Render();
1462 // Change state to Gesture::Continuing to remove
1463 stateToUnstage = Gesture::Continuing;
1466 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1467 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1468 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1470 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1471 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1473 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1474 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1477 // Render and notify
1478 application.SendNotification();
1479 application.Render();
1481 // Re-add actor to stage
1482 Stage::GetCurrent().Add(actor);
1484 // Render and notify
1485 application.SendNotification();
1486 application.Render();
1488 // Change state to Gesture::Finished to remove
1489 stateToUnstage = Gesture::Finished;
1492 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1493 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1494 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1496 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1497 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1499 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1500 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1501 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1505 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1507 TestApplication application;
1509 Actor actor = Actor::New();
1510 actor.SetSize(100.0f, 100.0f);
1511 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1512 Stage::GetCurrent().Add(actor);
1514 // Create and add a second actor so that GestureDetector destruction does not come into play.
1515 Actor dummyActor( Actor::New() );
1516 dummyActor.SetSize( 100.0f, 100.0f );
1517 dummyActor.SetPosition( 100.0f, 100.0f );
1518 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1519 Stage::GetCurrent().Add(dummyActor);
1521 // Render and notify
1522 application.SendNotification();
1523 application.Render();
1525 // State to remove actor in.
1526 Gesture::State stateToUnstage( Gesture::Started );
1528 // Attach actor to detector
1530 UnstageActorFunctor functor( data, stateToUnstage );
1531 PanGestureDetector detector = PanGestureDetector::New();
1532 detector.Attach(actor);
1533 detector.Attach(dummyActor);
1534 detector.DetectedSignal().Connect( &application, functor );
1536 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1537 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1538 // position, we should still not be signalled.
1541 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1542 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1543 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1546 // Render and notify
1547 application.SendNotification();
1548 application.Render();
1550 // Re add to the stage, we should not be signalled
1551 Stage::GetCurrent().Add(actor);
1553 // Render and notify
1554 application.SendNotification();
1555 application.Render();
1557 // Continue signal emission
1558 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1559 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1561 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1562 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1565 // Here we delete an actor in started, we should not receive any subsequent signalling.
1568 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1569 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1570 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1573 // Render and notify
1574 application.SendNotification();
1575 application.Render();
1577 // Delete actor as well
1580 // Render and notify
1581 application.SendNotification();
1582 application.Render();
1584 // Continue signal emission
1585 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1586 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1588 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1589 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1593 int UtcDaliPanGestureSystemOverlay(void)
1595 TestApplication application;
1596 Dali::Integration::Core& core = application.GetCore();
1597 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1598 systemOverlay.GetOverlayRenderTasks().CreateTask();
1600 Actor actor = Actor::New();
1601 actor.SetSize(100.0f, 100.0f);
1602 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1603 systemOverlay.Add(actor);
1605 // Render and notify
1606 application.SendNotification();
1607 application.Render();
1610 GestureReceivedFunctor functor(data);
1612 PanGestureDetector detector = PanGestureDetector::New();
1613 detector.Attach(actor);
1614 detector.DetectedSignal().Connect(&application, functor);
1616 Vector2 screenCoordsStart( 10.0f, 20.0f );
1617 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1619 // Start pan within the actor's area
1620 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1621 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1622 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1626 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1628 TestApplication application;
1629 Dali::Integration::Core& core = application.GetCore();
1630 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1631 systemOverlay.GetOverlayRenderTasks().CreateTask();
1633 // SystemOverlay actor
1634 Actor systemOverlayActor = Actor::New();
1635 systemOverlayActor.SetSize(100.0f, 100.0f);
1636 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1637 systemOverlay.Add(systemOverlayActor);
1640 Actor stageActor = Actor::New();
1641 stageActor.SetSize(100.0f, 100.0f);
1642 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1643 Stage::GetCurrent().Add(stageActor);
1645 // Render and notify
1646 application.SendNotification();
1647 application.Render();
1649 // Set system-overlay actor to touchable
1650 TouchEventData touchData;
1651 TouchEventDataFunctor touchFunctor( touchData );
1652 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1654 // Set stage actor to receive the gesture
1656 GestureReceivedFunctor functor(data);
1658 PanGestureDetector detector = PanGestureDetector::New();
1659 detector.Attach(stageActor);
1660 detector.DetectedSignal().Connect(&application, functor);
1662 Vector2 screenCoordsStart( 10.0f, 20.0f );
1663 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1665 // Start pan within the two actors' area
1666 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1667 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1668 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1669 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1670 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1675 // Do touch in the same area
1676 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1677 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1678 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1683 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1685 TestApplication application;
1686 Dali::Integration::Core& core = application.GetCore();
1687 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1688 systemOverlay.GetOverlayRenderTasks().CreateTask();
1690 // SystemOverlay actor
1691 Actor systemOverlayActor = Actor::New();
1692 systemOverlayActor.SetSize(100.0f, 100.0f);
1693 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1694 systemOverlay.Add(systemOverlayActor);
1697 Actor stageActor = Actor::New();
1698 stageActor.SetSize(100.0f, 100.0f);
1699 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1700 Stage::GetCurrent().Add(stageActor);
1702 // Render and notify
1703 application.SendNotification();
1704 application.Render();
1706 // Set stage actor to touchable
1707 TouchEventData touchData;
1708 TouchEventDataFunctor touchFunctor( touchData );
1709 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1711 // Set system-overlay actor to have the gesture
1713 GestureReceivedFunctor functor(data);
1715 PanGestureDetector detector = PanGestureDetector::New();
1716 detector.Attach(systemOverlayActor);
1717 detector.DetectedSignal().Connect(&application, functor);
1719 Vector2 screenCoordsStart( 10.0f, 20.0f );
1720 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1722 // Start pan within the two actors' area
1723 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1724 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1725 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1726 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1727 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1732 // Do touch in the same area
1733 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1734 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1735 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1740 int UtcDaliPanGestureAngleHandling(void)
1742 TestApplication application;
1744 PanGestureDetector detector = PanGestureDetector::New();
1745 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1746 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1748 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1749 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1750 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1752 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1754 tet_result( TET_PASS );
1758 if ( iter == endIter )
1760 tet_printf("%s, angle not added\n", TEST_LOCATION );
1761 tet_result( TET_FAIL );
1765 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1766 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1768 // Remove something not in the container.
1769 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1770 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1772 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1773 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1774 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1776 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1778 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1779 tet_result( TET_FAIL );
1784 detector.ClearAngles();
1785 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1789 inline float RadiansToDegrees( float radian )
1791 return radian * 180.0f / Math::PI;
1794 int UtcDaliPanGestureAngleOutOfRange(void)
1796 TestApplication application;
1798 PanGestureDetector detector = PanGestureDetector::New();
1799 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1800 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1806 detector.AddAngle( Degree(180.0f) );
1807 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1808 detector.ClearAngles();
1810 detector.AddAngle( Degree(190.0f) );
1811 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1812 detector.ClearAngles();
1814 detector.AddAngle( Degree(-190.0f) );
1815 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1816 detector.ClearAngles();
1818 detector.AddAngle( Degree(350.0f) );
1819 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1820 detector.ClearAngles();
1822 detector.AddAngle( Degree(-350.0f) );
1823 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1824 detector.ClearAngles();
1826 detector.AddAngle( Degree(370.0f) );
1827 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1828 detector.ClearAngles();
1830 detector.AddAngle( Degree(-370.0f) );
1831 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1832 detector.ClearAngles();
1838 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1839 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1840 detector.ClearAngles();
1842 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1843 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1844 detector.ClearAngles();
1846 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1847 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1848 detector.ClearAngles();
1850 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1851 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1852 detector.ClearAngles();
1856 int UtcDaliPanGestureAngleProcessing(void)
1858 TestApplication application;
1860 Actor parent = Actor::New();
1861 parent.SetSize(100.0f, 100.0f);
1862 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1863 Stage::GetCurrent().Add(parent);
1865 Actor child = Actor::New();
1866 child.SetSize(100.0f, 100.0f);
1867 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1870 // Render and notify
1871 application.SendNotification();
1872 application.Render();
1874 // Parent detector only requires up pans
1875 PanGestureDetector parentDetector = PanGestureDetector::New();
1876 parentDetector.Attach( parent );
1877 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1878 SignalData parentData;
1879 GestureReceivedFunctor parentFunctor(parentData);
1880 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1882 // Child detector only requires right pans
1883 PanGestureDetector childDetector = PanGestureDetector::New();
1884 childDetector.Attach( child );
1885 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1886 SignalData childData;
1887 GestureReceivedFunctor childFunctor(childData);
1888 childDetector.DetectedSignal().Connect(&application, childFunctor);
1890 // Generate an Up pan gesture, only parent should receive it.
1891 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1892 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1893 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1894 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1895 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1899 // Generate a Right pan gesture, only child should receive it.
1900 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1901 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1902 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1903 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1904 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1908 // Generate a Down pan gesture, no one should receive it.
1909 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1910 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1911 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1912 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1913 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1917 // Generate a Left pan gesture, no one should receive it.
1918 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1919 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1920 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1921 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1922 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1928 int UtcDaliPanGestureDirectionHandling(void)
1930 TestApplication application;
1932 PanGestureDetector detector = PanGestureDetector::New();
1933 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1934 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1936 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1937 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1938 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1940 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1942 tet_result( TET_PASS );
1946 if ( iter == endIter )
1948 tet_printf("%s, angle not added\n", TEST_LOCATION );
1949 tet_result( TET_FAIL );
1953 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1955 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1957 tet_result( TET_PASS );
1961 if ( iter == endIter )
1963 tet_printf("%s, angle not added\n", TEST_LOCATION );
1964 tet_result( TET_FAIL );
1968 // Remove something not in the container.
1969 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1970 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1972 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1973 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1977 int UtcDaliPanGestureDirectionProcessing(void)
1979 TestApplication application;
1981 Actor parent = Actor::New();
1982 parent.SetSize(100.0f, 100.0f);
1983 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1984 Stage::GetCurrent().Add(parent);
1986 Actor child = Actor::New();
1987 child.SetSize(100.0f, 100.0f);
1988 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1991 // Render and notify
1992 application.SendNotification();
1993 application.Render();
1995 // Parent detector only requires vertical panning
1996 PanGestureDetector parentDetector = PanGestureDetector::New();
1997 parentDetector.Attach( parent );
1998 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1999 SignalData parentData;
2000 GestureReceivedFunctor parentFunctor(parentData);
2001 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2003 // Child detector only requires horizontal panning
2004 PanGestureDetector childDetector = PanGestureDetector::New();
2005 childDetector.Attach( child );
2006 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2007 SignalData childData;
2008 GestureReceivedFunctor childFunctor(childData);
2009 childDetector.DetectedSignal().Connect(&application, childFunctor);
2011 // Generate an Up pan gesture, only parent should receive it.
2012 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2013 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
2014 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2015 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2016 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2020 // Generate a Right pan gesture, only child should receive it.
2021 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2022 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2023 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2024 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2025 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2029 // Generate a Down pan gesture, only parent should receive it.
2030 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2031 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2032 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2033 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2034 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2038 // Generate a Left pan gesture, only child should receive it.
2039 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2040 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2041 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2042 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2043 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2047 // Generate a pan at -45 degrees, no one should receive it.
2048 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2049 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2050 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2051 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2052 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2056 // Generate a pan at 45 degrees, no one should receive it.
2057 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2058 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2059 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2060 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2061 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2065 // Generate a pan at 135 degrees, no one should receive it.
2066 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2067 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2068 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2069 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2070 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2074 // Generate a pan at -135 degrees, no one should receive it.
2075 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2076 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2077 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2078 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2079 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2085 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2087 TestApplication application;
2088 Integration::SetPanGesturePredictionMode(0);
2089 Integration::SetPanGestureSmoothingMode(0);
2091 Actor actor = Actor::New();
2092 actor.SetSize(100.0f, 100.0f);
2093 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2094 Stage::GetCurrent().Add(actor);
2096 // Add a pan detector
2097 PanGestureDetector detector = PanGestureDetector::New();
2098 detector.Attach( actor );
2100 GestureReceivedFunctor functor( data );
2101 detector.DetectedSignal().Connect( &application, functor );
2103 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2105 ConstraintData constraintData;
2106 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2107 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2108 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2109 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2110 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2111 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2112 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2115 // Render and notify
2116 application.SendNotification();
2117 application.Render();
2119 Vector2 direction(Vector2::XAXIS * -5.0f);
2120 Vector2 startPosition( 1.0f, 1.0f );
2121 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2122 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2123 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2124 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2125 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2127 constraintData.Reset();
2131 int UtcDaliPanGestureNoPredictionSmoothing(void)
2133 TestApplication application;
2134 Integration::SetPanGesturePredictionMode(0);
2135 Integration::SetPanGestureSmoothingMode(1);
2137 Actor actor = Actor::New();
2138 actor.SetSize(100.0f, 100.0f);
2139 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2140 Stage::GetCurrent().Add(actor);
2142 // Add a pan detector
2143 PanGestureDetector detector = PanGestureDetector::New();
2144 detector.Attach( actor );
2146 GestureReceivedFunctor functor( data );
2147 detector.DetectedSignal().Connect( &application, functor );
2149 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2151 ConstraintData constraintData;
2152 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2153 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2154 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2155 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2156 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2157 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2158 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2161 // Render and notify
2162 application.SendNotification();
2163 application.Render();
2165 Vector2 direction(Vector2::XAXIS * -5.0f);
2166 Vector2 previousPosition( 20.0f, 20.0f );
2167 Vector2 currentPosition( 20.0f, 10.0f );
2168 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2169 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2170 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2171 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2172 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2174 constraintData.Reset();
2178 int UtcDaliPanGesturePredictionNoSmoothing(void)
2180 TestApplication application;
2181 Integration::SetPanGesturePredictionMode(1);
2182 Integration::SetPanGestureSmoothingMode(0);
2184 Actor actor = Actor::New();
2185 actor.SetSize(100.0f, 100.0f);
2186 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2187 Stage::GetCurrent().Add(actor);
2189 // Add a pan detector
2190 PanGestureDetector detector = PanGestureDetector::New();
2191 detector.Attach( actor );
2193 GestureReceivedFunctor functor( data );
2194 detector.DetectedSignal().Connect( &application, functor );
2196 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2198 ConstraintData constraintData;
2199 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2200 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2201 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2202 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2203 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2204 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2205 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2208 // Render and notify
2209 application.SendNotification();
2210 application.Render();
2212 Vector2 direction(Vector2::XAXIS * -1.0f);
2213 Vector2 previousPosition( 20.0f, 20.0f );
2214 Vector2 currentPosition( 20.0f, 10.0f );
2215 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2216 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2217 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2218 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2219 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2221 constraintData.Reset();
2225 int UtcDaliPanGesturePredictionSmoothing(void)
2227 TestApplication application;
2228 Integration::SetPanGesturePredictionMode(1);
2229 Integration::SetPanGestureSmoothingMode(1);
2231 Actor actor = Actor::New();
2232 actor.SetSize(100.0f, 100.0f);
2233 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2234 Stage::GetCurrent().Add(actor);
2236 // Add a pan detector
2237 PanGestureDetector detector = PanGestureDetector::New();
2238 detector.Attach( actor );
2240 GestureReceivedFunctor functor( data );
2241 detector.DetectedSignal().Connect( &application, functor );
2243 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2245 ConstraintData constraintData;
2246 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2247 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2248 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2249 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2250 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2251 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2252 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2255 // Render and notify
2256 application.SendNotification();
2257 application.Render();
2259 Vector2 direction(Vector2::XAXIS * -1.0f);
2260 Vector2 previousPosition( 20.0f, 20.0f );
2261 Vector2 currentPosition( 20.0f, 10.0f );
2262 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2263 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2264 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2265 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2266 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2268 constraintData.Reset();
2272 int UtcDaliPanGestureSetProperties(void)
2274 TestApplication application;
2275 TestRenderController& renderController( application.GetRenderController() );
2276 Integration::SetPanGesturePredictionMode(0);
2277 Integration::SetPanGestureSmoothingMode(0);
2279 Actor actor = Actor::New();
2280 actor.SetSize(100.0f, 100.0f);
2281 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2282 Stage::GetCurrent().Add(actor);
2284 // Add a pan detector
2285 PanGestureDetector detector = PanGestureDetector::New();
2286 detector.Attach( actor );
2288 GestureReceivedFunctor functor( data );
2289 detector.DetectedSignal().Connect( &application, functor );
2291 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2293 ConstraintData constraintData;
2294 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2295 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2296 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2297 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2298 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2299 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2300 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2303 // Render and notify
2304 application.SendNotification();
2305 application.Render();
2307 renderController.Initialize();
2308 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2310 Vector2 screenPosition( 20.0f, 20.0f );
2311 Vector2 screenDisplacement( 1.0f, 1.0f );
2312 Vector2 screenVelocity( 1.3f, 4.0f );
2313 Vector2 localPosition( 21.0f, 21.0f );
2314 Vector2 localDisplacement( 0.5f, 0.5f );
2315 Vector2 localVelocity( 1.5f, 2.5f );
2317 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2318 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2320 // Render and notify
2321 application.SendNotification();
2322 application.Render();
2324 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2325 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2326 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2327 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2328 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2329 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2330 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2331 constraintData.Reset();
2335 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2337 TestApplication application;
2338 Integration::SetPanGesturePredictionMode(0);
2340 Actor actor = Actor::New();
2341 actor.SetSize(100.0f, 100.0f);
2342 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2343 Stage::GetCurrent().Add(actor);
2345 // Add a pan detector
2346 PanGestureDetector detector = PanGestureDetector::New();
2347 detector.Attach( actor );
2349 GestureReceivedFunctor functor( data );
2350 detector.DetectedSignal().Connect( &application, functor );
2352 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2354 ConstraintData constraintData;
2355 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2356 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2357 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2358 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2359 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2360 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2361 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2364 // Render and notify
2365 application.SendNotification();
2366 application.Render();
2368 Vector2 previousPosition( 20.0f, 20.0f );
2369 Vector2 currentPosition( 20.0f, 10.0f );
2370 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2371 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2372 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2374 Vector2 screenPosition( 100.0f, 20.0f );
2375 Vector2 localPosition( 110.0f, 110.0f );
2377 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2379 // Render and notify
2380 application.SendNotification();
2381 application.Render();
2383 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2384 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2385 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2386 constraintData.Reset();
2390 int UtcDaliPanGesturePropertyIndices(void)
2392 TestApplication application;
2393 PanGestureDetector detector = PanGestureDetector::New();
2395 Property::IndexContainer indices;
2396 detector.GetPropertyIndices( indices );
2397 DALI_TEST_CHECK( ! indices.empty() );
2398 DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );
2402 int UtcDaliPanGestureLayerConsumesTouch(void)
2404 TestApplication application;
2406 Actor actor = Actor::New();
2407 actor.SetSize(100.0f, 100.0f);
2408 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2409 Stage::GetCurrent().Add(actor);
2411 // Add a pan detector
2412 PanGestureDetector detector = PanGestureDetector::New();
2413 detector.Attach( actor );
2415 GestureReceivedFunctor functor( data );
2416 detector.DetectedSignal().Connect( &application, functor );
2418 // Add a layer to overlap the actor
2419 Layer layer = Layer::New();
2420 layer.SetSize(100.0f, 100.0f);
2421 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2422 Stage::GetCurrent().Add( layer );
2425 // Render and notify
2426 application.SendNotification();
2427 application.Render();
2429 // Emit signals, should receive
2430 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2431 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2432 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2433 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2436 // Set layer to consume all touch
2437 layer.SetTouchConsumed( true );
2439 // Render and notify
2440 application.SendNotification();
2441 application.Render();
2443 // Emit the same signals again, should not receive
2444 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2445 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2446 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2447 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2453 int UtcDaliPanGestureNoTimeDiff(void)
2455 TestApplication application;
2457 Actor actor = Actor::New();
2458 actor.SetSize(100.0f, 100.0f);
2459 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2460 Stage::GetCurrent().Add(actor);
2462 // Add a pan detector
2463 PanGestureDetector detector = PanGestureDetector::New();
2464 detector.Attach( actor );
2466 GestureReceivedFunctor functor( data );
2467 detector.DetectedSignal().Connect( &application, functor );
2469 // Render and notify
2470 application.SendNotification();
2471 application.Render();
2473 // Emit signals, should receive
2474 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2475 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2476 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2477 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2478 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2479 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2480 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2481 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );