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 const int PAN_EVENT_TIME_DELTA = 8;
47 const int PAN_GESTURE_UPDATE_COUNT = 50;
49 // Stores data that is populated in the callback and will be read by the test cases
53 : functorCalled(false),
54 voidFunctorCalled(false),
55 receivedGesture(Gesture::Clear)
60 functorCalled = false;
61 voidFunctorCalled = false;
63 receivedGesture.state = Gesture::Clear;
64 receivedGesture.velocity = Vector2(0.0f, 0.0f);
65 receivedGesture.displacement = Vector2(0.0f, 0.0f);
66 receivedGesture.position = Vector2(0.0f, 0.0f);
67 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
68 receivedGesture.numberOfTouches = 0;
74 bool voidFunctorCalled;
75 PanGesture receivedGesture;
79 // Functor that sets the data when called
80 struct GestureReceivedFunctor
82 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
84 void operator()(Actor actor, const PanGesture& pan)
86 signalData.functorCalled = true;
87 signalData.receivedGesture = pan;
88 signalData.pannedActor = actor;
93 signalData.voidFunctorCalled = true;
96 SignalData& signalData;
99 // Functor that removes the gestured actor from stage
100 struct UnstageActorFunctor : public GestureReceivedFunctor
102 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
103 : GestureReceivedFunctor( data ),
104 stateToUnstage( stateToUnstage )
108 void operator()( Actor actor, const PanGesture& pan )
110 GestureReceivedFunctor::operator()( actor, pan );
112 if ( pan.state == stateToUnstage )
114 Stage::GetCurrent().Remove( actor );
118 Gesture::State& stateToUnstage;
121 // Functor for receiving a touch event
122 struct TouchEventFunctor
124 bool operator()(Actor actor, const TouchEvent& touch)
130 // Data for constraints
131 struct ConstraintData
139 Vector2 screenPosition;
140 Vector2 screenDisplacement;
141 Vector2 screenVelocity;
142 Vector2 localPosition;
143 Vector2 localDisplacement;
144 Vector2 localVelocity;
150 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
156 // Constraint used with panning properties
159 PanConstraint( ConstraintData& data ) : constraintData(data) { }
161 void operator()( Vector3& current, const PropertyInputContainer& inputs )
163 constraintData.screenPosition = inputs[0]->GetVector2();
164 constraintData.screenDisplacement = inputs[1]->GetVector2();
165 constraintData.screenVelocity = inputs[2]->GetVector2();
166 constraintData.localPosition = inputs[3]->GetVector2();
167 constraintData.localDisplacement = inputs[4]->GetVector2();
168 constraintData.localVelocity = inputs[5]->GetVector2();
169 constraintData.panning = inputs[6]->GetBoolean();
170 constraintData.called = true;
171 current = Vector3::ZERO;
174 ConstraintData& constraintData;
177 // Generate a PanGestureEvent to send to Core
178 Integration::PanGestureEvent GeneratePan(
179 Gesture::State state,
180 Vector2 previousPosition,
181 Vector2 currentPosition,
182 unsigned long timeDelta,
183 unsigned int numberOfTouches = 1,
184 unsigned int time = 1u)
186 Integration::PanGestureEvent pan(state);
188 pan.previousPosition = previousPosition;
189 pan.currentPosition = currentPosition;
190 pan.timeDelta = timeDelta;
191 pan.numberOfTouches = numberOfTouches;
197 // Generate a PanGesture
198 PanGesture GeneratePan( unsigned int time,
199 Gesture::State state,
200 Vector2 screenPosition,
201 Vector2 localPosition,
202 Vector2 screenDisplacement = Vector2::ONE,
203 Vector2 localDisplacement = Vector2::ONE,
204 Vector2 screenVelocity = Vector2::ONE,
205 Vector2 localVelocity = Vector2::ONE,
206 unsigned int numberOfTouches = 1 )
208 PanGesture pan( state );
212 pan.screenPosition = screenPosition;
213 pan.position = localPosition;
215 pan.screenDisplacement = screenDisplacement;
216 pan.displacement = localDisplacement;
218 pan.screenVelocity = screenVelocity;
219 pan.velocity = localVelocity;
221 pan.numberOfTouches = numberOfTouches;
227 * Helper to generate PanGestureEvent
229 * @param[in] application Application instance
230 * @param[in] state The Gesture State
231 * @param[in] pos The current position of touch.
233 static void SendPan(TestApplication& application, Gesture::State state, const Vector2& pos)
236 static int LastTime = 0;
238 if( (state == Gesture::Started) ||
239 (state == Gesture::Possible) )
245 application.ProcessEvent(GeneratePan(state, last, pos, PAN_EVENT_TIME_DELTA));
249 LastTime += PAN_EVENT_TIME_DELTA;
252 static Vector2 PerformSwipeGestureSwipe(TestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
254 // Now do a pan starting from (start) and heading (direction)
256 SendPan(application, Gesture::Possible, pos);
257 SendPan(application, Gesture::Started, pos);
258 application.SendNotification();
259 application.Render();
261 for(int i = 0;i<frames;i++)
263 pos += direction; // Move in this direction
264 SendPan(application, Gesture::Continuing, pos);
265 application.SendNotification();
266 application.Render();
271 SendPan(application, Gesture::Finished, pos);
272 application.SendNotification();
273 application.Render();
281 ///////////////////////////////////////////////////////////////////////////////
283 // Positive test case for a method
284 int UtcDaliPanGestureDetectorConstructor(void)
286 TestApplication application;
288 PanGestureDetector detector;
289 DALI_TEST_CHECK(!detector);
293 int UtcDaliPanGestureDetectorCopyConstructorP(void)
295 TestApplication application;
297 PanGestureDetector detector = PanGestureDetector::New();;
299 PanGestureDetector copy( detector );
300 DALI_TEST_CHECK( detector );
304 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
306 TestApplication application;
308 PanGestureDetector detector = PanGestureDetector::New();;
310 PanGestureDetector assign;
312 DALI_TEST_CHECK( detector );
314 DALI_TEST_CHECK( detector == assign );
318 // Negative test case for a method
319 int UtcDaliPanGestureDetectorNew(void)
321 TestApplication application;
323 PanGestureDetector detector = PanGestureDetector::New();
325 DALI_TEST_CHECK(detector);
327 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
328 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
330 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
331 Actor actor = Actor::New();
332 actor.SetSize(100.0f, 100.0f);
333 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
334 detector.Attach(actor);
336 Stage::GetCurrent().Add(actor);
339 application.SendNotification();
340 application.Render();
342 Integration::TouchEvent touchEvent(1);
343 Integration::Point point;
344 point.SetDeviceId( 1 );
345 point.SetState( PointState::DOWN );
346 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
347 touchEvent.AddPoint(point);
348 application.ProcessEvent(touchEvent);
352 int UtcDaliPanGestureDetectorDownCast(void)
354 TestApplication application;
355 tet_infoline("Testing Dali::GestureDetector::DownCast()");
357 PanGestureDetector detector = PanGestureDetector::New();
359 BaseHandle object(detector);
361 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
362 DALI_TEST_CHECK(detector2);
364 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
365 DALI_TEST_CHECK(detector3);
367 BaseHandle unInitializedObject;
368 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
369 DALI_TEST_CHECK(!detector4);
371 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
372 DALI_TEST_CHECK(!detector5);
374 GestureDetector detector6 = PanGestureDetector::New();
375 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
376 DALI_TEST_CHECK(detector7);
380 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
382 TestApplication application;
384 PanGestureDetector detector = PanGestureDetector::New();
386 unsigned int min = 2;
388 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
390 detector.SetMinimumTouchesRequired(min);
392 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
394 // Attach an actor and change the minimum touches
396 Actor actor = Actor::New();
397 actor.SetSize(100.0f, 100.0f);
398 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
399 Stage::GetCurrent().Add(actor);
402 application.SendNotification();
403 application.Render();
406 GestureReceivedFunctor functor(data);
408 detector.Attach(actor);
409 detector.DetectedSignal().Connect(&application, functor);
411 TestGestureManager& gestureManager = application.GetGestureManager();
412 gestureManager.Initialize();
414 detector.SetMinimumTouchesRequired(3);
416 // Gesture detection should have been updated only
417 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
418 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
419 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
422 gestureManager.Initialize();
424 // Create a second gesture detector that requires even less minimum touches
425 PanGestureDetector secondDetector = PanGestureDetector::New();
426 secondDetector.Attach(actor);
428 // Gesture detection should have been updated only
429 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
430 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
431 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
435 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
437 TestApplication application;
439 PanGestureDetector detector = PanGestureDetector::New();
441 unsigned int max = 3;
443 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
445 detector.SetMaximumTouchesRequired(max);
447 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
449 // Attach an actor and change the maximum touches
451 Actor actor = Actor::New();
452 actor.SetSize(100.0f, 100.0f);
453 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
454 Stage::GetCurrent().Add(actor);
457 application.SendNotification();
458 application.Render();
461 GestureReceivedFunctor functor(data);
463 detector.Attach(actor);
464 detector.DetectedSignal().Connect(&application, functor);
466 TestGestureManager& gestureManager = application.GetGestureManager();
467 gestureManager.Initialize();
469 detector.SetMaximumTouchesRequired(4);
471 // Gesture detection should have been updated only
472 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
473 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
474 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
477 gestureManager.Initialize();
479 // Create a second gesture detector that requires even less maximum touches
480 PanGestureDetector secondDetector = PanGestureDetector::New();
481 secondDetector.Attach(actor);
483 // Gesture detection should NOT have been updated
484 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
485 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
486 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
490 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
492 TestApplication application;
494 PanGestureDetector detector = PanGestureDetector::New();
495 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
499 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
501 TestApplication application;
503 PanGestureDetector detector = PanGestureDetector::New();
504 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
508 int UtcDaliPanGestureSignalReceptionNegative(void)
510 TestApplication application;
512 Actor actor = Actor::New();
513 actor.SetSize(100.0f, 100.0f);
514 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
515 Stage::GetCurrent().Add(actor);
518 application.SendNotification();
519 application.Render();
522 GestureReceivedFunctor functor(data);
524 PanGestureDetector detector = PanGestureDetector::New();
525 detector.Attach(actor);
526 detector.DetectedSignal().Connect(&application, functor);
528 // Do a pan outside actor's area
529 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
530 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
531 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
533 // Continue pan into actor's area - we should still not receive the signal
535 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
536 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
538 // Stop panning - we should still not receive the signal
540 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
541 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
545 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
547 TestApplication application;
549 Actor actor = Actor::New();
550 actor.SetSize(100.0f, 100.0f);
551 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
552 Stage::GetCurrent().Add(actor);
555 application.SendNotification();
556 application.Render();
559 GestureReceivedFunctor functor(data);
561 PanGestureDetector detector = PanGestureDetector::New();
562 detector.Attach(actor);
563 detector.DetectedSignal().Connect(&application, functor);
565 // Start pan within the actor's area
566 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
567 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
568 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
569 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
570 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
571 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
572 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
573 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
574 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
576 // Continue the pan within the actor's area - we should still receive the signal
578 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
579 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
580 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
581 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
582 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
583 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
584 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
585 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
587 // Pan Gesture leaves actor's area - we should still receive the signal
589 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
590 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
591 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
592 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
593 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
594 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
595 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
596 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
598 // Gesture ends - we would receive a finished state
600 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
601 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
602 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
603 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
604 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
605 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
606 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
607 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
611 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
613 TestApplication application;
615 Actor actor = Actor::New();
616 actor.SetSize(100.0f, 100.0f);
617 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
618 Stage::GetCurrent().Add(actor);
621 application.SendNotification();
622 application.Render();
625 GestureReceivedFunctor functor(data);
627 PanGestureDetector detector = PanGestureDetector::New();
628 detector.Attach(actor);
629 detector.DetectedSignal().Connect(&application, functor);
631 // Start pan within the actor's area
632 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
633 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
634 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
635 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
636 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
637 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
638 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
639 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
640 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
642 // Continue the pan within the actor's area - we should still receive the signal
644 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
645 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
646 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
647 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
648 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
649 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
650 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
651 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
653 // Gesture ends within actor's area - we would receive a finished state
655 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
656 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
657 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
658 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
659 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
660 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
661 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
662 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
666 int UtcDaliPanGestureSignalReceptionCancelled(void)
668 TestApplication application;
670 Actor actor = Actor::New();
671 actor.SetSize(100.0f, 100.0f);
672 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
673 Stage::GetCurrent().Add(actor);
676 application.SendNotification();
677 application.Render();
680 GestureReceivedFunctor functor(data);
682 PanGestureDetector detector = PanGestureDetector::New();
683 detector.Attach(actor);
684 detector.DetectedSignal().Connect(&application, functor);
686 // Start pan within the actor's area
687 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
688 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
689 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
690 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
692 // Continue the pan within the actor's area - we should still receive the signal
694 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
695 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
696 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
698 // The gesture is cancelled
700 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
701 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
702 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
706 int UtcDaliPanGestureSignalReceptionDetach(void)
708 TestApplication application;
710 Actor actor = Actor::New();
711 actor.SetSize(100.0f, 100.0f);
712 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
713 Stage::GetCurrent().Add(actor);
716 application.SendNotification();
717 application.Render();
720 GestureReceivedFunctor functor(data);
722 PanGestureDetector detector = PanGestureDetector::New();
723 detector.Attach(actor);
724 detector.DetectedSignal().Connect(&application, functor);
726 // Start pan within the actor's area
727 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
728 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
729 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
731 // Continue the pan within the actor's area - we should still receive the signal
733 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
734 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
736 // Gesture ends within actor's area
738 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
739 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
742 detector.DetachAll();
744 // Ensure we are no longer signalled
746 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
747 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
748 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
749 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
750 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
754 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
756 TestApplication application;
758 Actor actor = Actor::New();
759 actor.SetSize(100.0f, 100.0f);
760 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
761 Stage::GetCurrent().Add(actor);
764 application.SendNotification();
765 application.Render();
768 GestureReceivedFunctor functor(data);
770 PanGestureDetector detector = PanGestureDetector::New();
771 detector.Attach(actor);
772 detector.DetectedSignal().Connect(&application, functor);
774 // Start pan within the actor's area
775 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
776 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
777 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
779 // Continue the pan within the actor's area - we should still receive the signal
781 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
782 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
784 // Detach actor during the pan, we should not receive the next event
785 detector.DetachAll();
787 // Gesture ends within actor's area
789 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
790 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
794 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
796 TestApplication application;
799 GestureReceivedFunctor functor(data);
801 PanGestureDetector detector = PanGestureDetector::New();
802 detector.DetectedSignal().Connect(&application, functor);
804 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
806 Actor tempActor = Actor::New();
807 tempActor.SetSize(100.0f, 100.0f);
808 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
809 Stage::GetCurrent().Add(tempActor);
810 detector.Attach(tempActor);
812 // Actor lifetime is scoped
814 Actor actor = Actor::New();
815 actor.SetSize(100.0f, 100.0f);
816 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
817 Stage::GetCurrent().Add(actor);
820 application.SendNotification();
821 application.Render();
823 detector.Attach(actor);
825 // Start pan within the actor's area
826 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
827 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
828 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
830 // Continue the pan within the actor's area - we should still receive the signal
832 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
833 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
835 // Remove the actor from stage and reset the data
836 Stage::GetCurrent().Remove(actor);
839 application.SendNotification();
840 application.Render();
843 // Actor should now have been destroyed
845 // Gesture ends within the area where the actor used to be
847 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
848 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
852 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
854 TestApplication application;
856 Actor actor = Actor::New();
857 actor.SetSize(100.0f, 100.0f);
858 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
859 Stage::GetCurrent().Add(actor);
862 application.SendNotification();
863 application.Render();
866 GestureReceivedFunctor functor(data);
868 PanGestureDetector detector = PanGestureDetector::New();
869 detector.Attach(actor);
870 detector.DetectedSignal().Connect(&application, functor);
872 // Do an entire pan, only check finished value
873 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
874 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
876 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
877 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
878 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
880 // Rotate actor again and render a couple of times
881 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
882 application.SendNotification();
883 application.Render();
885 // Do an entire pan, only check finished value
886 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
887 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
889 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
890 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
891 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
893 // Rotate actor again and render a couple of times
894 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
895 application.SendNotification();
896 application.Render();
898 // Do an entire pan, only check finished value
899 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
900 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
902 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
903 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
904 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
908 int UtcDaliPanGestureSignalReceptionChildHit(void)
910 TestApplication application;
912 Actor parent = Actor::New();
913 parent.SetSize(100.0f, 100.0f);
914 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
915 Stage::GetCurrent().Add(parent);
917 // Set child to completely cover parent.
918 // Change rotation of child to be different from parent so that we can check if our local coordinate
919 // conversion of the parent actor is correct.
920 Actor child = Actor::New();
921 child.SetSize(100.0f, 100.0f);
922 child.SetAnchorPoint(AnchorPoint::CENTER);
923 child.SetParentOrigin(ParentOrigin::CENTER);
924 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
927 TouchEventFunctor touchFunctor;
928 child.TouchedSignal().Connect(&application, touchFunctor);
931 application.SendNotification();
932 application.Render();
935 GestureReceivedFunctor functor(data);
937 PanGestureDetector detector = PanGestureDetector::New();
938 detector.Attach(parent);
939 detector.DetectedSignal().Connect(&application, functor);
941 // Do an entire pan, only check finished value - hits child area but parent should still receive it
942 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
943 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
945 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
946 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
947 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
948 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
950 // Attach child and generate same touch points to yield a different displacement
951 // (Also proves that you can detach and then re-attach another actor)
952 detector.Attach(child);
953 detector.Detach(parent);
955 // Do an entire pan, only check finished value
956 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
957 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
959 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
960 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
961 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
962 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
966 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
968 TestApplication application;
970 Actor first = Actor::New();
971 first.SetSize(100.0f, 100.0f);
972 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
973 Stage::GetCurrent().Add(first);
975 Actor second = Actor::New();
976 second.SetSize(100.0f, 100.0f);
978 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
979 Stage::GetCurrent().Add(second);
982 application.SendNotification();
983 application.Render();
986 GestureReceivedFunctor functor(data);
988 PanGestureDetector detector = PanGestureDetector::New();
989 detector.Attach(first);
990 detector.Attach(second);
991 detector.DetectedSignal().Connect(&application, functor);
993 // Start pan within second actor's area
994 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
995 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
996 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
997 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
999 // Pan moves into first actor's area - second actor should receive the pan
1001 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1002 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1003 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1005 // Detach the second actor during the pan, we should not receive the next event
1006 detector.Detach(second);
1008 // Gesture ends within actor's area
1010 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1011 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1015 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1017 TestApplication application;
1019 Actor actor = Actor::New();
1020 actor.SetSize(100.0f, 100.0f);
1021 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1022 Stage::GetCurrent().Add(actor);
1024 // Render and notify
1025 application.SendNotification();
1026 application.Render();
1029 GestureReceivedFunctor functor(data);
1031 PanGestureDetector detector = PanGestureDetector::New();
1032 detector.Attach(actor);
1033 detector.DetectedSignal().Connect(&application, functor);
1035 // Start pan in actor's area
1036 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1037 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1038 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1040 // Pan continues within actor's area
1042 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1043 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1045 // Actor become invisible - actor should not receive the next pan
1046 actor.SetVisible(false);
1048 // Render and notify
1049 application.SendNotification();
1050 application.Render();
1052 // Gesture ends within actor's area
1054 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1055 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1059 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1061 TestApplication application;
1062 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1064 Actor first = Actor::New();
1065 first.SetSize(100.0f, 100.0f);
1066 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1067 Stage::GetCurrent().Add(first);
1069 Actor second = Actor::New();
1070 second.SetSize(100.0f, 100.0f);
1071 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1074 // Render and notify
1075 application.SendNotification();
1076 application.Render();
1079 GestureReceivedFunctor functor(data);
1081 PanGestureDetector firstDetector = PanGestureDetector::New();
1082 firstDetector.Attach(first);
1083 firstDetector.DetectedSignal().Connect(&application, functor);
1085 // secondDetector is scoped
1087 // Reset gestureManager statistics
1088 gestureManager.Initialize();
1090 PanGestureDetector secondDetector = PanGestureDetector::New();
1091 secondDetector.SetMinimumTouchesRequired(2);
1092 secondDetector.SetMaximumTouchesRequired(2);
1093 secondDetector.Attach(second);
1094 secondDetector.DetectedSignal().Connect(&application, functor);
1096 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1097 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1098 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1100 // Start pan within second actor's area
1101 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1102 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1103 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1104 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1106 // Two touch pan changes to single touch - we should receive a finished state
1108 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1109 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1110 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1111 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1113 // Pan continues as single touch gesture - we should not receive any gesture
1115 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1116 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1118 // Pan ends - still no signal
1120 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1121 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1123 // Single touch pan starts - first actor should be panned
1125 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1126 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1127 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1128 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1130 // Pan changes to double-touch - we should receive a finished state
1132 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1133 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1134 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1135 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1137 // Pan continues as double touch gesture - we should not receive any gesture
1139 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1140 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1142 // Pan ends - still no signal
1144 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1145 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1147 // Reset gesture manager statistics
1148 gestureManager.Initialize();
1151 // secondDetector has now been deleted. Gesture detection should have been updated only
1152 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1153 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1154 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1158 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1160 TestApplication application;
1162 Actor actor = Actor::New();
1163 actor.SetSize(100.0f, 100.0f);
1164 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1165 Stage::GetCurrent().Add(actor);
1167 Actor actor2 = Actor::New();
1168 actor2.SetSize(100.0f, 100.0f);
1169 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1170 Stage::GetCurrent().Add(actor2);
1172 // Render and notify
1173 application.SendNotification();
1174 application.Render();
1176 // Attach actor to one detector
1177 SignalData firstData;
1178 GestureReceivedFunctor firstFunctor(firstData);
1179 PanGestureDetector firstDetector = PanGestureDetector::New();
1180 firstDetector.Attach(actor);
1181 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1183 // Attach actor to another detector
1184 SignalData secondData;
1185 GestureReceivedFunctor secondFunctor(secondData);
1186 PanGestureDetector secondDetector = PanGestureDetector::New();
1187 secondDetector.Attach(actor);
1188 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1190 // Add second actor to second detector, when we remove the actor, this will make sure that this
1191 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1192 // functor should still not be called (which is what we're also testing).
1193 secondDetector.Attach(actor2);
1195 // Pan in actor's area - both detector's functors should be called
1196 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1197 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1198 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1199 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1201 // Pan continues in actor's area - both detector's functors should be called
1204 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1205 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1206 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1208 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1209 firstDetector.Detach(actor);
1212 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1213 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1214 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1216 // New pan on actor, only secondDetector has actor attached
1219 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1220 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1221 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1222 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1224 // Detach actor from secondDetector
1225 secondDetector.Detach(actor);
1228 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1229 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1230 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1234 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1236 // Should handle two started events gracefully.
1238 TestApplication application;
1240 Actor actor = Actor::New();
1241 actor.SetSize(100.0f, 100.0f);
1242 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1243 Stage::GetCurrent().Add(actor);
1246 GestureReceivedFunctor functor(data);
1248 PanGestureDetector detector = PanGestureDetector::New();
1249 detector.Attach(actor);
1250 detector.DetectedSignal().Connect(&application, functor);
1252 // Render and notify
1253 application.SendNotification();
1254 application.Render();
1256 // Start pan in actor's area
1257 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
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 // Send another start in actor's area
1263 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1264 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1266 // Add a child actor to overlap actor and send another start in actor's area
1267 Actor child = Actor::New();
1268 child.SetSize(100.0f, 100.0f);
1269 child.SetAnchorPoint(AnchorPoint::CENTER);
1270 child.SetParentOrigin(ParentOrigin::CENTER);
1273 TouchEventFunctor touchFunctor;
1274 child.TouchedSignal().Connect(&application, touchFunctor);
1276 // Render and notify
1277 application.SendNotification();
1278 application.Render();
1280 // Send another possible and start in actor's area
1282 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1283 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1284 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1286 // Send another start in actor's area
1288 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1289 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1290 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1294 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1296 TestApplication application;
1298 Actor actor1 = Actor::New();
1299 actor1.SetSize(100.0f, 100.0f);
1300 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1301 Stage::GetCurrent().Add(actor1);
1303 GestureReceivedFunctor functor1(data1);
1304 PanGestureDetector detector1 = PanGestureDetector::New();
1305 detector1.Attach(actor1);
1306 detector1.DetectedSignal().Connect(&application, functor1);
1308 Actor actor2 = Actor::New();
1309 actor2.SetSize(100.0f, 100.0f);
1310 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1311 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1312 Stage::GetCurrent().Add(actor2);
1314 GestureReceivedFunctor functor2(data2);
1315 PanGestureDetector detector2 = PanGestureDetector::New();
1316 detector2.Attach(actor2);
1317 detector2.DetectedSignal().Connect(&application, functor2);
1319 // Render and notify
1320 application.SendNotification();
1321 application.Render();
1323 // Start pan in actor1's area, only data1 should be set
1324 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1325 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1326 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1327 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1331 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1333 TestApplication application;
1335 Actor actor = Actor::New();
1336 actor.SetSize(100.0f, 100.0f);
1337 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1338 Stage::GetCurrent().Add(actor);
1340 // Render and notify
1341 application.SendNotification();
1342 application.Render();
1344 // Attach actor to detector
1346 GestureReceivedFunctor functor( data );
1347 PanGestureDetector detector = PanGestureDetector::New();
1348 detector.Attach(actor);
1349 detector.DetectedSignal().Connect( &application, functor );
1351 // Gesture possible in actor's area.
1352 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1353 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1355 // Move actor somewhere else
1356 actor.SetPosition( 100.0f, 100.0f );
1358 // Render and notify
1359 application.SendNotification();
1360 application.Render();
1362 // Emit Started event, we should not receive the long press.
1363 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1364 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1365 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1367 // LongPress possible in empty area.
1368 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1369 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1371 // Move actor in to the long press position.
1372 actor.SetPosition( 0.0f, 0.0f );
1374 // Render and notify
1375 application.SendNotification();
1376 application.Render();
1378 // Emit Started event, we should not receive the long press.
1379 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1380 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1381 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1383 // Normal long press in actor's area for completeness.
1384 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1385 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1386 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1387 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1391 int UtcDaliPanGestureEmitIncorrectState(void)
1393 TestApplication application;
1395 Actor actor = Actor::New();
1396 actor.SetSize(100.0f, 100.0f);
1397 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1398 Stage::GetCurrent().Add(actor);
1400 // Render and notify
1401 application.SendNotification();
1402 application.Render();
1404 // Attach actor to detector
1406 GestureReceivedFunctor functor( data );
1407 PanGestureDetector detector = PanGestureDetector::New();
1408 detector.Attach(actor);
1409 detector.DetectedSignal().Connect( &application, functor );
1411 // Try a Clear state
1414 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1415 tet_result(TET_FAIL);
1417 catch ( Dali::DaliException& e )
1419 DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
1424 int UtcDaliPanGestureActorUnstaged(void)
1426 TestApplication application;
1428 Actor actor = Actor::New();
1429 actor.SetSize(100.0f, 100.0f);
1430 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1431 Stage::GetCurrent().Add(actor);
1433 // Render and notify
1434 application.SendNotification();
1435 application.Render();
1437 // State to remove actor in.
1438 Gesture::State stateToUnstage( Gesture::Started );
1440 // Attach actor to detector
1442 UnstageActorFunctor functor( data, stateToUnstage );
1443 PanGestureDetector detector = PanGestureDetector::New();
1444 detector.Attach(actor);
1445 detector.DetectedSignal().Connect( &application, functor );
1448 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1449 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1450 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1452 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1453 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1456 // Render and notify
1457 application.SendNotification();
1458 application.Render();
1460 // Re-add actor to stage
1461 Stage::GetCurrent().Add(actor);
1463 // Render and notify
1464 application.SendNotification();
1465 application.Render();
1467 // Change state to Gesture::Continuing to remove
1468 stateToUnstage = Gesture::Continuing;
1471 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1472 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1473 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1475 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1476 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1478 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1479 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1482 // Render and notify
1483 application.SendNotification();
1484 application.Render();
1486 // Re-add actor to stage
1487 Stage::GetCurrent().Add(actor);
1489 // Render and notify
1490 application.SendNotification();
1491 application.Render();
1493 // Change state to Gesture::Finished to remove
1494 stateToUnstage = Gesture::Finished;
1497 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1498 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1499 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1501 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1502 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1504 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1505 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1506 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1510 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1512 TestApplication application;
1514 Actor actor = Actor::New();
1515 actor.SetSize(100.0f, 100.0f);
1516 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1517 Stage::GetCurrent().Add(actor);
1519 // Create and add a second actor so that GestureDetector destruction does not come into play.
1520 Actor dummyActor( Actor::New() );
1521 dummyActor.SetSize( 100.0f, 100.0f );
1522 dummyActor.SetPosition( 100.0f, 100.0f );
1523 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1524 Stage::GetCurrent().Add(dummyActor);
1526 // Render and notify
1527 application.SendNotification();
1528 application.Render();
1530 // State to remove actor in.
1531 Gesture::State stateToUnstage( Gesture::Started );
1533 // Attach actor to detector
1535 UnstageActorFunctor functor( data, stateToUnstage );
1536 PanGestureDetector detector = PanGestureDetector::New();
1537 detector.Attach(actor);
1538 detector.Attach(dummyActor);
1539 detector.DetectedSignal().Connect( &application, functor );
1541 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1542 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1543 // position, we should still not be signalled.
1546 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1547 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1548 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1551 // Render and notify
1552 application.SendNotification();
1553 application.Render();
1555 // Re add to the stage, we should not be signalled
1556 Stage::GetCurrent().Add(actor);
1558 // Render and notify
1559 application.SendNotification();
1560 application.Render();
1562 // Continue signal emission
1563 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1564 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1566 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1567 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1570 // Here we delete an actor in started, we should not receive any subsequent signalling.
1573 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1574 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1575 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1578 // Render and notify
1579 application.SendNotification();
1580 application.Render();
1582 // Delete actor as well
1585 // Render and notify
1586 application.SendNotification();
1587 application.Render();
1589 // Continue signal emission
1590 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1591 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1593 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1594 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1598 int UtcDaliPanGestureSystemOverlay(void)
1600 TestApplication application;
1601 Dali::Integration::Core& core = application.GetCore();
1602 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1603 systemOverlay.GetOverlayRenderTasks().CreateTask();
1605 Actor actor = Actor::New();
1606 actor.SetSize(100.0f, 100.0f);
1607 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1608 systemOverlay.Add(actor);
1610 // Render and notify
1611 application.SendNotification();
1612 application.Render();
1615 GestureReceivedFunctor functor(data);
1617 PanGestureDetector detector = PanGestureDetector::New();
1618 detector.Attach(actor);
1619 detector.DetectedSignal().Connect(&application, functor);
1621 Vector2 screenCoordsStart( 10.0f, 20.0f );
1622 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1624 // Start pan within the actor's area
1625 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1626 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1627 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1631 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1633 TestApplication application;
1634 Dali::Integration::Core& core = application.GetCore();
1635 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1636 systemOverlay.GetOverlayRenderTasks().CreateTask();
1638 // SystemOverlay actor
1639 Actor systemOverlayActor = Actor::New();
1640 systemOverlayActor.SetSize(100.0f, 100.0f);
1641 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1642 systemOverlay.Add(systemOverlayActor);
1645 Actor stageActor = Actor::New();
1646 stageActor.SetSize(100.0f, 100.0f);
1647 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1648 Stage::GetCurrent().Add(stageActor);
1650 // Render and notify
1651 application.SendNotification();
1652 application.Render();
1654 // Set system-overlay actor to touchable
1655 TouchEventData touchData;
1656 TouchEventDataFunctor touchFunctor( touchData );
1657 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1659 // Set stage actor to receive the gesture
1661 GestureReceivedFunctor functor(data);
1663 PanGestureDetector detector = PanGestureDetector::New();
1664 detector.Attach(stageActor);
1665 detector.DetectedSignal().Connect(&application, functor);
1667 Vector2 screenCoordsStart( 10.0f, 20.0f );
1668 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1670 // Start pan within the two actors' area
1671 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1672 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1673 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1674 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1675 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1680 // Do touch in the same area
1681 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoordsStart ) );
1682 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1683 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1688 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1690 TestApplication application;
1691 Dali::Integration::Core& core = application.GetCore();
1692 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1693 systemOverlay.GetOverlayRenderTasks().CreateTask();
1695 // SystemOverlay actor
1696 Actor systemOverlayActor = Actor::New();
1697 systemOverlayActor.SetSize(100.0f, 100.0f);
1698 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1699 systemOverlay.Add(systemOverlayActor);
1702 Actor stageActor = Actor::New();
1703 stageActor.SetSize(100.0f, 100.0f);
1704 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1705 Stage::GetCurrent().Add(stageActor);
1707 // Render and notify
1708 application.SendNotification();
1709 application.Render();
1711 // Set stage actor to touchable
1712 TouchEventData touchData;
1713 TouchEventDataFunctor touchFunctor( touchData );
1714 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1716 // Set system-overlay actor to have the gesture
1718 GestureReceivedFunctor functor(data);
1720 PanGestureDetector detector = PanGestureDetector::New();
1721 detector.Attach(systemOverlayActor);
1722 detector.DetectedSignal().Connect(&application, functor);
1724 Vector2 screenCoordsStart( 10.0f, 20.0f );
1725 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1727 // Start pan within the two actors' area
1728 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1729 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1730 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1731 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1732 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1737 // Do touch in the same area
1738 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoordsStart ) );
1739 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1740 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1745 int UtcDaliPanGestureAngleHandling(void)
1747 TestApplication application;
1749 PanGestureDetector detector = PanGestureDetector::New();
1750 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1752 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1753 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1755 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1757 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1759 tet_result( TET_PASS );
1767 tet_printf("%s, angle not added\n", TEST_LOCATION );
1768 tet_result( TET_FAIL );
1771 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1772 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1774 // Remove something not in the container.
1775 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1776 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1778 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1779 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1780 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1782 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1784 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1785 tet_result( TET_FAIL );
1790 detector.ClearAngles();
1791 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1795 int UtcDaliPanGestureGetAngle(void)
1797 TestApplication application;
1799 PanGestureDetector detector = PanGestureDetector::New();
1800 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1802 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1803 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1805 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1806 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1808 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1809 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1811 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1812 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1814 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1815 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1816 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1817 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1822 inline float RadiansToDegrees( float radian )
1824 return radian * 180.0f / Math::PI;
1827 int UtcDaliPanGestureAngleOutOfRange(void)
1829 TestApplication application;
1831 PanGestureDetector detector = PanGestureDetector::New();
1832 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1838 detector.AddAngle( Degree(180.0f) );
1839 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1840 detector.ClearAngles();
1842 detector.AddAngle( Degree(190.0f) );
1843 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1844 detector.ClearAngles();
1846 detector.AddAngle( Degree(-190.0f) );
1847 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1848 detector.ClearAngles();
1850 detector.AddAngle( Degree(350.0f) );
1851 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1852 detector.ClearAngles();
1854 detector.AddAngle( Degree(-350.0f) );
1855 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1856 detector.ClearAngles();
1858 detector.AddAngle( Degree(370.0f) );
1859 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1860 detector.ClearAngles();
1862 detector.AddAngle( Degree(-370.0f) );
1863 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1864 detector.ClearAngles();
1870 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1871 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1872 detector.ClearAngles();
1874 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1875 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1876 detector.ClearAngles();
1878 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1879 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1880 detector.ClearAngles();
1882 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1883 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1884 detector.ClearAngles();
1888 int UtcDaliPanGestureAngleProcessing(void)
1890 TestApplication application;
1892 Actor parent = Actor::New();
1893 parent.SetSize(100.0f, 100.0f);
1894 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1895 Stage::GetCurrent().Add(parent);
1897 Actor child = Actor::New();
1898 child.SetSize(100.0f, 100.0f);
1899 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1902 // Render and notify
1903 application.SendNotification();
1904 application.Render();
1906 // Parent detector only requires up pans
1907 PanGestureDetector parentDetector = PanGestureDetector::New();
1908 parentDetector.Attach( parent );
1909 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1910 SignalData parentData;
1911 GestureReceivedFunctor parentFunctor(parentData);
1912 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1914 // Child detector only requires right pans
1915 PanGestureDetector childDetector = PanGestureDetector::New();
1916 childDetector.Attach( child );
1917 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1918 SignalData childData;
1919 GestureReceivedFunctor childFunctor(childData);
1920 childDetector.DetectedSignal().Connect(&application, childFunctor);
1922 // Generate an Up pan gesture, only parent should receive it.
1923 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1924 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1925 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1926 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1927 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1931 // Generate a Right pan gesture, only child should receive it.
1932 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1933 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1934 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1935 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1936 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1940 // Generate a Down pan gesture, no one should receive it.
1941 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1942 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1943 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1944 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1945 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1949 // Generate a Left pan gesture, no one should receive it.
1950 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1951 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1952 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1953 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1954 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1960 int UtcDaliPanGestureDirectionHandling(void)
1962 TestApplication application;
1964 PanGestureDetector detector = PanGestureDetector::New();
1965 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1967 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1968 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1970 for ( size_t i = 0; detector.GetAngleCount(); i++)
1972 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1974 tet_result( TET_PASS );
1983 tet_printf("%s, angle not added\n", TEST_LOCATION );
1984 tet_result( TET_FAIL );
1988 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1990 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1992 tet_result( TET_PASS );
2000 tet_printf("%s, angle not added\n", TEST_LOCATION );
2001 tet_result( TET_FAIL );
2004 // Remove something not in the container.
2005 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
2006 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
2008 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
2009 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
2013 int UtcDaliPanGestureDirectionProcessing(void)
2015 TestApplication application;
2017 Actor parent = Actor::New();
2018 parent.SetSize(100.0f, 100.0f);
2019 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2020 Stage::GetCurrent().Add(parent);
2022 Actor child = Actor::New();
2023 child.SetSize(100.0f, 100.0f);
2024 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2027 // Render and notify
2028 application.SendNotification();
2029 application.Render();
2031 // Parent detector only requires vertical panning
2032 PanGestureDetector parentDetector = PanGestureDetector::New();
2033 parentDetector.Attach( parent );
2034 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
2035 SignalData parentData;
2036 GestureReceivedFunctor parentFunctor(parentData);
2037 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2039 // Child detector only requires horizontal panning
2040 PanGestureDetector childDetector = PanGestureDetector::New();
2041 childDetector.Attach( child );
2042 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2043 SignalData childData;
2044 GestureReceivedFunctor childFunctor(childData);
2045 childDetector.DetectedSignal().Connect(&application, childFunctor);
2047 // Generate an Up pan gesture, only parent 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(20.0f, 10.0f), 10 ) );
2050 DALI_TEST_EQUALS( true, 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 Right pan gesture, only child 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, 20.0f), 10 ) );
2059 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2060 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2061 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2065 // Generate a Down pan gesture, only parent 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(20.0f, 30.0f), 10 ) );
2068 DALI_TEST_EQUALS( true, 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 Left pan gesture, only child 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, 20.0f), 10 ) );
2077 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2078 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2079 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2083 // Generate a pan at -45 degrees, no one should receive it.
2084 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2085 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2086 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2087 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2088 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2092 // Generate a pan at 45 degrees, no one should receive it.
2093 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2094 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2095 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2096 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2097 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2101 // Generate a pan at 135 degrees, no one should receive it.
2102 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2103 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2104 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2105 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2106 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2110 // Generate a pan at -135 degrees, no one should receive it.
2111 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2112 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2113 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2114 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2115 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2121 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2123 TestApplication application;
2124 Integration::SetPanGesturePredictionMode(0);
2125 Integration::SetPanGestureSmoothingMode(0);
2127 Actor actor = Actor::New();
2128 actor.SetSize(100.0f, 100.0f);
2129 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2130 Stage::GetCurrent().Add(actor);
2132 // Add a pan detector
2133 PanGestureDetector detector = PanGestureDetector::New();
2134 detector.Attach( actor );
2136 GestureReceivedFunctor functor( data );
2137 detector.DetectedSignal().Connect( &application, functor );
2139 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2141 ConstraintData constraintData;
2142 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2143 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2144 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2145 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2146 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2147 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2148 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2149 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2152 // Render and notify
2153 application.SendNotification();
2154 application.Render();
2156 Vector2 direction(Vector2::XAXIS * -5.0f);
2157 Vector2 startPosition( 1.0f, 1.0f );
2158 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2159 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2160 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2161 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2162 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2164 constraintData.Reset();
2168 int UtcDaliPanGestureNoPredictionSmoothing(void)
2170 TestApplication application;
2171 Integration::SetPanGesturePredictionMode(0);
2172 Integration::SetPanGestureSmoothingMode(1);
2174 Actor actor = Actor::New();
2175 actor.SetSize(100.0f, 100.0f);
2176 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2177 Stage::GetCurrent().Add(actor);
2179 // Add a pan detector
2180 PanGestureDetector detector = PanGestureDetector::New();
2181 detector.Attach( actor );
2183 GestureReceivedFunctor functor( data );
2184 detector.DetectedSignal().Connect( &application, functor );
2186 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2188 ConstraintData constraintData;
2189 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2190 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2191 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2192 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2193 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2194 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2195 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2196 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2199 // Render and notify
2200 application.SendNotification();
2201 application.Render();
2203 Vector2 direction(Vector2::XAXIS * -5.0f);
2204 Vector2 previousPosition( 20.0f, 20.0f );
2205 Vector2 currentPosition( 20.0f, 10.0f );
2206 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2207 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2208 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2209 // Take into account resampling done when prediction is off.
2210 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2211 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2213 constraintData.Reset();
2217 int UtcDaliPanGesturePredictionNoSmoothing(void)
2219 TestApplication application;
2220 Integration::SetPanGesturePredictionMode(1);
2221 Integration::SetPanGestureSmoothingMode(0);
2223 Actor actor = Actor::New();
2224 actor.SetSize(100.0f, 100.0f);
2225 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2226 Stage::GetCurrent().Add(actor);
2228 // Add a pan detector
2229 PanGestureDetector detector = PanGestureDetector::New();
2230 detector.Attach( actor );
2232 GestureReceivedFunctor functor( data );
2233 detector.DetectedSignal().Connect( &application, functor );
2235 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2237 ConstraintData constraintData;
2238 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2239 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2240 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2241 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2242 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2243 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2244 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2245 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2248 // Render and notify
2249 application.SendNotification();
2250 application.Render();
2252 Vector2 direction(Vector2::XAXIS * -1.0f);
2253 Vector2 previousPosition( 20.0f, 20.0f );
2254 Vector2 currentPosition( 20.0f, 10.0f );
2255 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2256 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2257 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2258 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2259 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2261 constraintData.Reset();
2265 int UtcDaliPanGesturePredictionSmoothing(void)
2267 TestApplication application;
2268 Integration::SetPanGesturePredictionMode(1);
2269 Integration::SetPanGestureSmoothingMode(1);
2271 Actor actor = Actor::New();
2272 actor.SetSize(100.0f, 100.0f);
2273 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2274 Stage::GetCurrent().Add(actor);
2276 // Add a pan detector
2277 PanGestureDetector detector = PanGestureDetector::New();
2278 detector.Attach( actor );
2280 GestureReceivedFunctor functor( data );
2281 detector.DetectedSignal().Connect( &application, functor );
2283 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2285 ConstraintData constraintData;
2286 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2287 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2288 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2289 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2290 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2291 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2292 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2293 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2296 // Render and notify
2297 application.SendNotification();
2298 application.Render();
2300 Vector2 direction(Vector2::XAXIS * -1.0f);
2301 Vector2 previousPosition( 20.0f, 20.0f );
2302 Vector2 currentPosition( 20.0f, 10.0f );
2303 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2304 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2305 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2306 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2307 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2309 constraintData.Reset();
2313 int UtcDaliPanGestureSetProperties(void)
2315 TestApplication application;
2316 TestRenderController& renderController( application.GetRenderController() );
2317 Integration::SetPanGesturePredictionMode(0);
2318 Integration::SetPanGestureSmoothingMode(0);
2320 Actor actor = Actor::New();
2321 actor.SetSize(100.0f, 100.0f);
2322 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2323 Stage::GetCurrent().Add(actor);
2325 // Add a pan detector
2326 PanGestureDetector detector = PanGestureDetector::New();
2327 detector.Attach( actor );
2329 GestureReceivedFunctor functor( data );
2330 detector.DetectedSignal().Connect( &application, functor );
2332 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2333 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2335 ConstraintData constraintData;
2336 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2337 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2338 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2339 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2340 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2341 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2342 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2343 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2344 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2347 // Render and notify
2348 application.SendNotification();
2349 application.Render();
2351 renderController.Initialize();
2352 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2354 Vector2 screenPosition( 20.0f, 20.0f );
2355 Vector2 screenDisplacement( 1.0f, 1.0f );
2356 Vector2 screenVelocity( 1.3f, 4.0f );
2357 Vector2 localPosition( 21.0f, 21.0f );
2358 Vector2 localDisplacement( 0.5f, 0.5f );
2359 Vector2 localVelocity( 1.5f, 2.5f );
2361 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2362 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2364 // Render and notify
2365 application.SendNotification();
2366 application.Render();
2368 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2369 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2370 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2371 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2372 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2373 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2374 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2375 constraintData.Reset();
2379 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2381 TestApplication application;
2382 Integration::SetPanGesturePredictionMode(0);
2384 Actor actor = Actor::New();
2385 actor.SetSize(100.0f, 100.0f);
2386 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2387 Stage::GetCurrent().Add(actor);
2389 // Add a pan detector
2390 PanGestureDetector detector = PanGestureDetector::New();
2391 detector.Attach( actor );
2393 GestureReceivedFunctor functor( data );
2394 detector.DetectedSignal().Connect( &application, functor );
2396 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2398 ConstraintData constraintData;
2399 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2400 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2401 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2402 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2403 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2404 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2405 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2406 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2409 // Render and notify
2410 application.SendNotification();
2411 application.Render();
2413 Vector2 previousPosition( 20.0f, 20.0f );
2414 Vector2 currentPosition( 20.0f, 10.0f );
2415 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2416 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2417 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2419 Vector2 screenPosition( 100.0f, 20.0f );
2420 Vector2 localPosition( 110.0f, 110.0f );
2422 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2424 // Render and notify
2425 application.SendNotification();
2426 application.Render();
2428 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2429 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2430 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2431 constraintData.Reset();
2435 int UtcDaliPanGesturePropertyIndices(void)
2437 TestApplication application;
2438 PanGestureDetector detector = PanGestureDetector::New();
2440 Property::IndexContainer indices;
2441 detector.GetPropertyIndices( indices );
2442 DALI_TEST_CHECK( indices.Size() );
2443 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2449 struct PropertyStringIndex
2451 const char * const name;
2452 const Property::Index index;
2453 const Property::Type type;
2454 const Property::Value value;
2457 const PropertyStringIndex PROPERTY_TABLE[] =
2459 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2460 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2461 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2462 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2463 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2464 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2465 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2467 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2468 } // unnamed namespace
2471 int UtcDaliPanGestureProperties(void)
2473 TestApplication application;
2474 PanGestureDetector detector = PanGestureDetector::New();
2476 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2478 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2479 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2480 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2481 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2482 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2483 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2484 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2490 int UtcDaliPanGestureGetProperty(void)
2492 TestApplication application;
2493 PanGestureDetector detector = PanGestureDetector::New();
2495 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2497 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2499 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2500 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2502 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2504 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2505 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2512 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2514 TestApplication application;
2516 Actor actor = Actor::New();
2517 actor.SetSize(100.0f, 100.0f);
2518 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2519 Stage::GetCurrent().Add(actor);
2521 // Add a pan detector
2522 PanGestureDetector detector = PanGestureDetector::New();
2523 detector.Attach( actor );
2525 // Render and notify
2526 application.SendNotification();
2527 application.Render();
2529 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2531 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2533 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2535 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2536 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2538 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2540 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2541 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2548 int UtcDaliPanGestureLayerConsumesTouch(void)
2550 TestApplication application;
2552 Actor actor = Actor::New();
2553 actor.SetSize(100.0f, 100.0f);
2554 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2555 Stage::GetCurrent().Add(actor);
2557 // Add a pan detector
2558 PanGestureDetector detector = PanGestureDetector::New();
2559 detector.Attach( actor );
2561 GestureReceivedFunctor functor( data );
2562 detector.DetectedSignal().Connect( &application, functor );
2564 // Add a layer to overlap the actor
2565 Layer layer = Layer::New();
2566 layer.SetSize(100.0f, 100.0f);
2567 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2568 Stage::GetCurrent().Add( layer );
2571 // Render and notify
2572 application.SendNotification();
2573 application.Render();
2575 // Emit signals, should receive
2576 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2577 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2578 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2579 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2582 // Set layer to consume all touch
2583 layer.SetTouchConsumed( true );
2585 // Render and notify
2586 application.SendNotification();
2587 application.Render();
2589 // Emit the same signals again, should not receive
2590 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2591 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2592 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2593 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2599 int UtcDaliPanGestureNoTimeDiff(void)
2601 TestApplication application;
2603 Actor actor = Actor::New();
2604 actor.SetSize(100.0f, 100.0f);
2605 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2606 Stage::GetCurrent().Add(actor);
2608 // Add a pan detector
2609 PanGestureDetector detector = PanGestureDetector::New();
2610 detector.Attach( actor );
2612 GestureReceivedFunctor functor( data );
2613 detector.DetectedSignal().Connect( &application, functor );
2615 // Render and notify
2616 application.SendNotification();
2617 application.Render();
2619 // Emit signals, should receive
2620 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2621 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2622 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2623 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2624 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2625 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2626 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2627 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );