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 startPosition, Vector2 direction, int frames, int eventsPerFrame,
253 bool start, bool finish, unsigned int renderInterval = TestApplication::DEFAULT_RENDER_INTERVAL)
255 // Now do a pan starting from (start) and heading (direction)
256 Vector2 pos(startPosition);
260 SendPan(application, Gesture::Possible, pos);
261 SendPan(application, Gesture::Started, pos);
262 application.SendNotification();
263 application.Render(renderInterval);
266 for(int i = 0;i<frames;i++)
268 for( int j = 0; j < eventsPerFrame; j++ )
270 pos += direction; // Move in this direction
271 SendPan(application, Gesture::Continuing, pos);
273 application.SendNotification();
274 application.Render(renderInterval);
279 SendPan(application, Gesture::Finished, pos);
280 application.SendNotification();
281 application.Render(renderInterval);
289 ///////////////////////////////////////////////////////////////////////////////
291 // Positive test case for a method
292 int UtcDaliPanGestureDetectorConstructor(void)
294 TestApplication application;
296 PanGestureDetector detector;
297 DALI_TEST_CHECK(!detector);
301 int UtcDaliPanGestureDetectorCopyConstructorP(void)
303 TestApplication application;
305 PanGestureDetector detector = PanGestureDetector::New();
307 PanGestureDetector copy( detector );
308 DALI_TEST_CHECK( detector );
312 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
314 TestApplication application;
316 PanGestureDetector detector = PanGestureDetector::New();
318 PanGestureDetector assign;
320 DALI_TEST_CHECK( detector );
322 DALI_TEST_CHECK( detector == assign );
326 // Negative test case for a method
327 int UtcDaliPanGestureDetectorNew(void)
329 TestApplication application;
331 PanGestureDetector detector = PanGestureDetector::New();
333 DALI_TEST_CHECK(detector);
335 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
336 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
338 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
339 Actor actor = Actor::New();
340 actor.SetSize(100.0f, 100.0f);
341 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
342 detector.Attach(actor);
344 Stage::GetCurrent().Add(actor);
347 application.SendNotification();
348 application.Render();
350 Integration::TouchEvent touchEvent(1);
351 Integration::Point point;
352 point.SetDeviceId( 1 );
353 point.SetState( PointState::DOWN );
354 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
355 touchEvent.AddPoint(point);
356 application.ProcessEvent(touchEvent);
360 int UtcDaliPanGestureDetectorDownCast(void)
362 TestApplication application;
363 tet_infoline("Testing Dali::GestureDetector::DownCast()");
365 PanGestureDetector detector = PanGestureDetector::New();
367 BaseHandle object(detector);
369 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
370 DALI_TEST_CHECK(detector2);
372 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
373 DALI_TEST_CHECK(detector3);
375 BaseHandle unInitializedObject;
376 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
377 DALI_TEST_CHECK(!detector4);
379 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
380 DALI_TEST_CHECK(!detector5);
382 GestureDetector detector6 = PanGestureDetector::New();
383 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
384 DALI_TEST_CHECK(detector7);
388 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
390 TestApplication application;
392 PanGestureDetector detector = PanGestureDetector::New();
394 unsigned int min = 2;
396 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
398 detector.SetMinimumTouchesRequired(min);
400 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
402 // Attach an actor and change the minimum touches
404 Actor actor = Actor::New();
405 actor.SetSize(100.0f, 100.0f);
406 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
407 Stage::GetCurrent().Add(actor);
410 application.SendNotification();
411 application.Render();
414 GestureReceivedFunctor functor(data);
416 detector.Attach(actor);
417 detector.DetectedSignal().Connect(&application, functor);
419 TestGestureManager& gestureManager = application.GetGestureManager();
420 gestureManager.Initialize();
422 detector.SetMinimumTouchesRequired(3);
424 // Gesture detection should have been updated only
425 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
426 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
427 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
430 gestureManager.Initialize();
432 // Create a second gesture detector that requires even less minimum touches
433 PanGestureDetector secondDetector = PanGestureDetector::New();
434 secondDetector.Attach(actor);
436 // Gesture detection should have been updated only
437 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
438 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
439 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
443 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
445 TestApplication application;
447 PanGestureDetector detector = PanGestureDetector::New();
449 unsigned int max = 3;
451 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
453 detector.SetMaximumTouchesRequired(max);
455 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
457 // Attach an actor and change the maximum touches
459 Actor actor = Actor::New();
460 actor.SetSize(100.0f, 100.0f);
461 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
462 Stage::GetCurrent().Add(actor);
465 application.SendNotification();
466 application.Render();
469 GestureReceivedFunctor functor(data);
471 detector.Attach(actor);
472 detector.DetectedSignal().Connect(&application, functor);
474 TestGestureManager& gestureManager = application.GetGestureManager();
475 gestureManager.Initialize();
477 detector.SetMaximumTouchesRequired(4);
479 // Gesture detection should have been updated only
480 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
481 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
482 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
485 gestureManager.Initialize();
487 // Create a second gesture detector that requires even less maximum touches
488 PanGestureDetector secondDetector = PanGestureDetector::New();
489 secondDetector.Attach(actor);
491 // Gesture detection should NOT have been updated
492 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
493 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
494 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
498 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
500 TestApplication application;
502 PanGestureDetector detector = PanGestureDetector::New();
503 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
507 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
509 TestApplication application;
511 PanGestureDetector detector = PanGestureDetector::New();
512 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
516 int UtcDaliPanGestureSignalReceptionNegative(void)
518 TestApplication application;
520 Actor actor = Actor::New();
521 actor.SetSize(100.0f, 100.0f);
522 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
523 Stage::GetCurrent().Add(actor);
526 application.SendNotification();
527 application.Render();
530 GestureReceivedFunctor functor(data);
532 PanGestureDetector detector = PanGestureDetector::New();
533 detector.Attach(actor);
534 detector.DetectedSignal().Connect(&application, functor);
536 // Do a pan outside actor's area
537 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
538 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
539 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
541 // Continue pan into actor's area - we should still not receive the signal
543 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
544 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
546 // Stop panning - we should still not receive the signal
548 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
549 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
553 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
555 TestApplication application;
557 Actor actor = Actor::New();
558 actor.SetSize(100.0f, 100.0f);
559 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
560 Stage::GetCurrent().Add(actor);
563 application.SendNotification();
564 application.Render();
567 GestureReceivedFunctor functor(data);
569 PanGestureDetector detector = PanGestureDetector::New();
570 detector.Attach(actor);
571 detector.DetectedSignal().Connect(&application, functor);
573 // Start pan within the actor's area
574 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
575 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
576 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
577 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
578 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
579 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
580 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
581 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
582 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
584 // Continue the pan within the actor's area - we should still receive the signal
586 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
587 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
588 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
589 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
590 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
591 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
592 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
593 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
595 // Pan Gesture leaves actor's area - we should still receive the signal
597 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
598 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
599 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
600 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
601 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
602 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
603 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
604 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
606 // Gesture ends - we would receive a finished state
608 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
609 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
610 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
611 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
612 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
613 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
614 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
615 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
619 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
621 TestApplication application;
623 Actor actor = Actor::New();
624 actor.SetSize(100.0f, 100.0f);
625 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
626 Stage::GetCurrent().Add(actor);
629 application.SendNotification();
630 application.Render();
633 GestureReceivedFunctor functor(data);
635 PanGestureDetector detector = PanGestureDetector::New();
636 detector.Attach(actor);
637 detector.DetectedSignal().Connect(&application, functor);
639 // Start pan within the actor's area
640 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
641 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
642 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
643 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
644 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
645 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
646 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
647 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
648 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
650 // Continue the pan within the actor's area - we should still receive the signal
652 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
653 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
654 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
655 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
656 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
657 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
658 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
659 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
661 // Gesture ends within actor's area - we would receive a finished state
663 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
664 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
665 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
666 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
667 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
668 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
669 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
670 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
674 int UtcDaliPanGestureSignalReceptionCancelled(void)
676 TestApplication application;
678 Actor actor = Actor::New();
679 actor.SetSize(100.0f, 100.0f);
680 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
681 Stage::GetCurrent().Add(actor);
684 application.SendNotification();
685 application.Render();
688 GestureReceivedFunctor functor(data);
690 PanGestureDetector detector = PanGestureDetector::New();
691 detector.Attach(actor);
692 detector.DetectedSignal().Connect(&application, functor);
694 // Start pan within the actor's area
695 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
696 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
697 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
698 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
700 // Continue the pan within the actor's area - we should still receive the signal
702 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
703 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
704 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
706 // The gesture is cancelled
708 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
709 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
710 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
714 int UtcDaliPanGestureSignalReceptionDetach(void)
716 TestApplication application;
718 Actor actor = Actor::New();
719 actor.SetSize(100.0f, 100.0f);
720 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
721 Stage::GetCurrent().Add(actor);
724 application.SendNotification();
725 application.Render();
728 GestureReceivedFunctor functor(data);
730 PanGestureDetector detector = PanGestureDetector::New();
731 detector.Attach(actor);
732 detector.DetectedSignal().Connect(&application, functor);
734 // Start pan within the actor's area
735 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
736 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
737 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
739 // Continue the pan within the actor's area - we should still receive the signal
741 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
742 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
744 // Gesture ends within actor's area
746 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
747 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
750 detector.DetachAll();
752 // Ensure we are no longer signalled
754 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
755 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
756 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
757 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
758 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
762 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
764 TestApplication application;
766 Actor actor = Actor::New();
767 actor.SetSize(100.0f, 100.0f);
768 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
769 Stage::GetCurrent().Add(actor);
772 application.SendNotification();
773 application.Render();
776 GestureReceivedFunctor functor(data);
778 PanGestureDetector detector = PanGestureDetector::New();
779 detector.Attach(actor);
780 detector.DetectedSignal().Connect(&application, functor);
782 // Start pan within the actor's area
783 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
784 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
785 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
787 // Continue the pan within the actor's area - we should still receive the signal
789 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
790 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
792 // Detach actor during the pan, we should not receive the next event
793 detector.DetachAll();
795 // Gesture ends within actor's area
797 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
798 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
802 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
804 TestApplication application;
807 GestureReceivedFunctor functor(data);
809 PanGestureDetector detector = PanGestureDetector::New();
810 detector.DetectedSignal().Connect(&application, functor);
812 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
814 Actor tempActor = Actor::New();
815 tempActor.SetSize(100.0f, 100.0f);
816 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
817 Stage::GetCurrent().Add(tempActor);
818 detector.Attach(tempActor);
820 // Actor lifetime is scoped
822 Actor actor = Actor::New();
823 actor.SetSize(100.0f, 100.0f);
824 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
825 Stage::GetCurrent().Add(actor);
828 application.SendNotification();
829 application.Render();
831 detector.Attach(actor);
833 // Start pan within the actor's area
834 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
835 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
836 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
838 // Continue the pan within the actor's area - we should still receive the signal
840 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
841 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
843 // Remove the actor from stage and reset the data
844 Stage::GetCurrent().Remove(actor);
847 application.SendNotification();
848 application.Render();
851 // Actor should now have been destroyed
853 // Gesture ends within the area where the actor used to be
855 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
856 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
860 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
862 TestApplication application;
864 Actor actor = Actor::New();
865 actor.SetSize(100.0f, 100.0f);
866 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
867 Stage::GetCurrent().Add(actor);
870 application.SendNotification();
871 application.Render();
874 GestureReceivedFunctor functor(data);
876 PanGestureDetector detector = PanGestureDetector::New();
877 detector.Attach(actor);
878 detector.DetectedSignal().Connect(&application, functor);
880 // Do an entire pan, only check finished value
881 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
882 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
884 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
885 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
886 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
888 // Rotate actor again and render a couple of times
889 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
890 application.SendNotification();
891 application.Render();
893 // Do an entire pan, only check finished value
894 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
895 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
897 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
898 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
899 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
901 // Rotate actor again and render a couple of times
902 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
903 application.SendNotification();
904 application.Render();
906 // Do an entire pan, only check finished value
907 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
908 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
910 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
911 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
912 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
916 int UtcDaliPanGestureSignalReceptionChildHit(void)
918 TestApplication application;
920 Actor parent = Actor::New();
921 parent.SetSize(100.0f, 100.0f);
922 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
923 Stage::GetCurrent().Add(parent);
925 // Set child to completely cover parent.
926 // Change rotation of child to be different from parent so that we can check if our local coordinate
927 // conversion of the parent actor is correct.
928 Actor child = Actor::New();
929 child.SetSize(100.0f, 100.0f);
930 child.SetAnchorPoint(AnchorPoint::CENTER);
931 child.SetParentOrigin(ParentOrigin::CENTER);
932 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
935 TouchEventFunctor touchFunctor;
936 child.TouchedSignal().Connect(&application, touchFunctor);
939 application.SendNotification();
940 application.Render();
943 GestureReceivedFunctor functor(data);
945 PanGestureDetector detector = PanGestureDetector::New();
946 detector.Attach(parent);
947 detector.DetectedSignal().Connect(&application, functor);
949 // Do an entire pan, only check finished value - hits child area but parent should still receive it
950 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
951 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
953 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
954 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
955 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
956 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
958 // Attach child and generate same touch points to yield a different displacement
959 // (Also proves that you can detach and then re-attach another actor)
960 detector.Attach(child);
961 detector.Detach(parent);
963 // Do an entire pan, only check finished value
964 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
965 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
967 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
968 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
969 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
970 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
974 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
976 TestApplication application;
978 Actor first = Actor::New();
979 first.SetSize(100.0f, 100.0f);
980 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
981 Stage::GetCurrent().Add(first);
983 Actor second = Actor::New();
984 second.SetSize(100.0f, 100.0f);
986 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
987 Stage::GetCurrent().Add(second);
990 application.SendNotification();
991 application.Render();
994 GestureReceivedFunctor functor(data);
996 PanGestureDetector detector = PanGestureDetector::New();
997 detector.Attach(first);
998 detector.Attach(second);
999 detector.DetectedSignal().Connect(&application, functor);
1001 // Start pan within second actor's area
1002 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
1003 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
1004 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1005 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1007 // Pan moves into first actor's area - second actor should receive the pan
1009 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1010 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1011 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1013 // Detach the second actor during the pan, we should not receive the next event
1014 detector.Detach(second);
1016 // Gesture ends within actor's area
1018 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1019 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1023 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1025 TestApplication application;
1027 Actor actor = Actor::New();
1028 actor.SetSize(100.0f, 100.0f);
1029 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1030 Stage::GetCurrent().Add(actor);
1032 // Render and notify
1033 application.SendNotification();
1034 application.Render();
1037 GestureReceivedFunctor functor(data);
1039 PanGestureDetector detector = PanGestureDetector::New();
1040 detector.Attach(actor);
1041 detector.DetectedSignal().Connect(&application, functor);
1043 // Start pan in actor's area
1044 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1045 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1046 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1048 // Pan continues within actor's area
1050 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1051 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1053 // Actor become invisible - actor should not receive the next pan
1054 actor.SetVisible(false);
1056 // Render and notify
1057 application.SendNotification();
1058 application.Render();
1060 // Gesture ends within actor's area
1062 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1063 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1067 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1069 TestApplication application;
1070 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1072 Actor first = Actor::New();
1073 first.SetSize(100.0f, 100.0f);
1074 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1075 Stage::GetCurrent().Add(first);
1077 Actor second = Actor::New();
1078 second.SetSize(100.0f, 100.0f);
1079 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1082 // Render and notify
1083 application.SendNotification();
1084 application.Render();
1087 GestureReceivedFunctor functor(data);
1089 PanGestureDetector firstDetector = PanGestureDetector::New();
1090 firstDetector.Attach(first);
1091 firstDetector.DetectedSignal().Connect(&application, functor);
1093 // secondDetector is scoped
1095 // Reset gestureManager statistics
1096 gestureManager.Initialize();
1098 PanGestureDetector secondDetector = PanGestureDetector::New();
1099 secondDetector.SetMinimumTouchesRequired(2);
1100 secondDetector.SetMaximumTouchesRequired(2);
1101 secondDetector.Attach(second);
1102 secondDetector.DetectedSignal().Connect(&application, functor);
1104 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1105 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1106 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1108 // Start pan within second actor's area
1109 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1110 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1111 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1112 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1114 // Two touch pan changes to single touch - we should receive a finished state
1116 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1117 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1118 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1119 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1121 // Pan continues as single touch gesture - we should not receive any gesture
1123 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1124 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1126 // Pan ends - still no signal
1128 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1129 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1131 // Single touch pan starts - first actor should be panned
1133 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1134 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1135 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1136 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1138 // Pan changes to double-touch - we should receive a finished state
1140 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1141 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1142 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1143 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1145 // Pan continues as double touch gesture - we should not receive any gesture
1147 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1148 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1150 // Pan ends - still no signal
1152 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1153 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1155 // Reset gesture manager statistics
1156 gestureManager.Initialize();
1159 // secondDetector has now been deleted. Gesture detection should have been updated only
1160 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1161 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1162 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1166 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1168 TestApplication application;
1170 Actor actor = Actor::New();
1171 actor.SetSize(100.0f, 100.0f);
1172 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1173 Stage::GetCurrent().Add(actor);
1175 Actor actor2 = Actor::New();
1176 actor2.SetSize(100.0f, 100.0f);
1177 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1178 Stage::GetCurrent().Add(actor2);
1180 // Render and notify
1181 application.SendNotification();
1182 application.Render();
1184 // Attach actor to one detector
1185 SignalData firstData;
1186 GestureReceivedFunctor firstFunctor(firstData);
1187 PanGestureDetector firstDetector = PanGestureDetector::New();
1188 firstDetector.Attach(actor);
1189 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1191 // Attach actor to another detector
1192 SignalData secondData;
1193 GestureReceivedFunctor secondFunctor(secondData);
1194 PanGestureDetector secondDetector = PanGestureDetector::New();
1195 secondDetector.Attach(actor);
1196 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1198 // Add second actor to second detector, when we remove the actor, this will make sure that this
1199 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1200 // functor should still not be called (which is what we're also testing).
1201 secondDetector.Attach(actor2);
1203 // Pan in actor's area - both detector's functors should be called
1204 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1205 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1206 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1207 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1209 // Pan continues in actor's area - both detector's functors should be called
1212 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1213 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1214 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1216 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1217 firstDetector.Detach(actor);
1220 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1221 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1222 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1224 // New pan on actor, only secondDetector has actor attached
1227 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1228 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1229 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1230 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1232 // Detach actor from secondDetector
1233 secondDetector.Detach(actor);
1236 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1237 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1238 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1242 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1244 // Should handle two started events gracefully.
1246 TestApplication application;
1248 Actor actor = Actor::New();
1249 actor.SetSize(100.0f, 100.0f);
1250 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1251 Stage::GetCurrent().Add(actor);
1254 GestureReceivedFunctor functor(data);
1256 PanGestureDetector detector = PanGestureDetector::New();
1257 detector.Attach(actor);
1258 detector.DetectedSignal().Connect(&application, functor);
1260 // Render and notify
1261 application.SendNotification();
1262 application.Render();
1264 // Start pan in actor's area
1265 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1266 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1267 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1269 // Send another start in actor's area
1271 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1272 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1274 // Add a child actor to overlap actor and send another start in actor's area
1275 Actor child = Actor::New();
1276 child.SetSize(100.0f, 100.0f);
1277 child.SetAnchorPoint(AnchorPoint::CENTER);
1278 child.SetParentOrigin(ParentOrigin::CENTER);
1281 TouchEventFunctor touchFunctor;
1282 child.TouchedSignal().Connect(&application, touchFunctor);
1284 // Render and notify
1285 application.SendNotification();
1286 application.Render();
1288 // Send another possible and start in actor's area
1290 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1291 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1292 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1294 // Send another start in actor's area
1296 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1297 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1298 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1302 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1304 TestApplication application;
1306 Actor actor1 = Actor::New();
1307 actor1.SetSize(100.0f, 100.0f);
1308 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1309 Stage::GetCurrent().Add(actor1);
1311 GestureReceivedFunctor functor1(data1);
1312 PanGestureDetector detector1 = PanGestureDetector::New();
1313 detector1.Attach(actor1);
1314 detector1.DetectedSignal().Connect(&application, functor1);
1316 Actor actor2 = Actor::New();
1317 actor2.SetSize(100.0f, 100.0f);
1318 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1319 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1320 Stage::GetCurrent().Add(actor2);
1322 GestureReceivedFunctor functor2(data2);
1323 PanGestureDetector detector2 = PanGestureDetector::New();
1324 detector2.Attach(actor2);
1325 detector2.DetectedSignal().Connect(&application, functor2);
1327 // Render and notify
1328 application.SendNotification();
1329 application.Render();
1331 // Start pan in actor1's area, only data1 should be set
1332 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1333 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1334 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1335 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1339 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1341 TestApplication application;
1343 Actor actor = Actor::New();
1344 actor.SetSize(100.0f, 100.0f);
1345 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1346 Stage::GetCurrent().Add(actor);
1348 // Render and notify
1349 application.SendNotification();
1350 application.Render();
1352 // Attach actor to detector
1354 GestureReceivedFunctor functor( data );
1355 PanGestureDetector detector = PanGestureDetector::New();
1356 detector.Attach(actor);
1357 detector.DetectedSignal().Connect( &application, functor );
1359 // Gesture possible in actor's area.
1360 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1361 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1363 // Move actor somewhere else
1364 actor.SetPosition( 100.0f, 100.0f );
1366 // Render and notify
1367 application.SendNotification();
1368 application.Render();
1370 // Emit Started event, we should not receive the long press.
1371 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1372 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1373 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1375 // LongPress possible in empty area.
1376 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1377 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1379 // Move actor in to the long press position.
1380 actor.SetPosition( 0.0f, 0.0f );
1382 // Render and notify
1383 application.SendNotification();
1384 application.Render();
1386 // Emit Started event, we should not receive the long press.
1387 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1388 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1389 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1391 // Normal long press in actor's area for completeness.
1392 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1393 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1394 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1395 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1399 int UtcDaliPanGestureEmitIncorrectState(void)
1401 TestApplication application;
1403 Actor actor = Actor::New();
1404 actor.SetSize(100.0f, 100.0f);
1405 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1406 Stage::GetCurrent().Add(actor);
1408 // Render and notify
1409 application.SendNotification();
1410 application.Render();
1412 // Attach actor to detector
1414 GestureReceivedFunctor functor( data );
1415 PanGestureDetector detector = PanGestureDetector::New();
1416 detector.Attach(actor);
1417 detector.DetectedSignal().Connect( &application, functor );
1419 // Try a Clear state
1422 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1423 tet_result(TET_FAIL);
1425 catch ( Dali::DaliException& e )
1427 DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
1432 int UtcDaliPanGestureActorUnstaged(void)
1434 TestApplication application;
1436 Actor actor = Actor::New();
1437 actor.SetSize(100.0f, 100.0f);
1438 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1439 Stage::GetCurrent().Add(actor);
1441 // Render and notify
1442 application.SendNotification();
1443 application.Render();
1445 // State to remove actor in.
1446 Gesture::State stateToUnstage( Gesture::Started );
1448 // Attach actor to detector
1450 UnstageActorFunctor functor( data, stateToUnstage );
1451 PanGestureDetector detector = PanGestureDetector::New();
1452 detector.Attach(actor);
1453 detector.DetectedSignal().Connect( &application, functor );
1456 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1457 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1458 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1460 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1461 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1464 // Render and notify
1465 application.SendNotification();
1466 application.Render();
1468 // Re-add actor to stage
1469 Stage::GetCurrent().Add(actor);
1471 // Render and notify
1472 application.SendNotification();
1473 application.Render();
1475 // Change state to Gesture::Continuing to remove
1476 stateToUnstage = Gesture::Continuing;
1479 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1480 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1481 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1483 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1484 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1486 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1487 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1490 // Render and notify
1491 application.SendNotification();
1492 application.Render();
1494 // Re-add actor to stage
1495 Stage::GetCurrent().Add(actor);
1497 // Render and notify
1498 application.SendNotification();
1499 application.Render();
1501 // Change state to Gesture::Finished to remove
1502 stateToUnstage = Gesture::Finished;
1505 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1506 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1507 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1509 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1510 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1512 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1513 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1514 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1518 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1520 TestApplication application;
1522 Actor actor = Actor::New();
1523 actor.SetSize(100.0f, 100.0f);
1524 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1525 Stage::GetCurrent().Add(actor);
1527 // Create and add a second actor so that GestureDetector destruction does not come into play.
1528 Actor dummyActor( Actor::New() );
1529 dummyActor.SetSize( 100.0f, 100.0f );
1530 dummyActor.SetPosition( 100.0f, 100.0f );
1531 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1532 Stage::GetCurrent().Add(dummyActor);
1534 // Render and notify
1535 application.SendNotification();
1536 application.Render();
1538 // State to remove actor in.
1539 Gesture::State stateToUnstage( Gesture::Started );
1541 // Attach actor to detector
1543 UnstageActorFunctor functor( data, stateToUnstage );
1544 PanGestureDetector detector = PanGestureDetector::New();
1545 detector.Attach(actor);
1546 detector.Attach(dummyActor);
1547 detector.DetectedSignal().Connect( &application, functor );
1549 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1550 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1551 // position, we should still not be signalled.
1554 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1555 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1556 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1559 // Render and notify
1560 application.SendNotification();
1561 application.Render();
1563 // Re add to the stage, we should not be signalled
1564 Stage::GetCurrent().Add(actor);
1566 // Render and notify
1567 application.SendNotification();
1568 application.Render();
1570 // Continue signal emission
1571 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1572 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1574 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1575 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1578 // Here we delete an actor in started, we should not receive any subsequent signalling.
1581 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1582 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1583 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1586 // Render and notify
1587 application.SendNotification();
1588 application.Render();
1590 // Delete actor as well
1593 // Render and notify
1594 application.SendNotification();
1595 application.Render();
1597 // Continue signal emission
1598 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1599 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1601 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1602 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1606 int UtcDaliPanGestureSystemOverlay(void)
1608 TestApplication application;
1609 Dali::Integration::Core& core = application.GetCore();
1610 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1611 systemOverlay.GetOverlayRenderTasks().CreateTask();
1613 Actor actor = Actor::New();
1614 actor.SetSize(100.0f, 100.0f);
1615 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1616 systemOverlay.Add(actor);
1618 // Render and notify
1619 application.SendNotification();
1620 application.Render();
1623 GestureReceivedFunctor functor(data);
1625 PanGestureDetector detector = PanGestureDetector::New();
1626 detector.Attach(actor);
1627 detector.DetectedSignal().Connect(&application, functor);
1629 Vector2 screenCoordsStart( 10.0f, 20.0f );
1630 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1632 // Start pan within the actor's area
1633 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1634 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1635 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1639 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1641 TestApplication application;
1642 Dali::Integration::Core& core = application.GetCore();
1643 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1644 systemOverlay.GetOverlayRenderTasks().CreateTask();
1646 // SystemOverlay actor
1647 Actor systemOverlayActor = Actor::New();
1648 systemOverlayActor.SetSize(100.0f, 100.0f);
1649 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1650 systemOverlay.Add(systemOverlayActor);
1653 Actor stageActor = Actor::New();
1654 stageActor.SetSize(100.0f, 100.0f);
1655 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1656 Stage::GetCurrent().Add(stageActor);
1658 // Render and notify
1659 application.SendNotification();
1660 application.Render();
1662 // Set system-overlay actor to touchable
1663 TouchEventData touchData;
1664 TouchEventDataFunctor touchFunctor( touchData );
1665 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1667 // Set stage actor to receive the gesture
1669 GestureReceivedFunctor functor(data);
1671 PanGestureDetector detector = PanGestureDetector::New();
1672 detector.Attach(stageActor);
1673 detector.DetectedSignal().Connect(&application, functor);
1675 Vector2 screenCoordsStart( 10.0f, 20.0f );
1676 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1678 // Start pan within the two actors' area
1679 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1680 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1681 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1682 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1683 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1688 // Do touch in the same area
1689 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoordsStart ) );
1690 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1691 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1696 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1698 TestApplication application;
1699 Dali::Integration::Core& core = application.GetCore();
1700 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1701 systemOverlay.GetOverlayRenderTasks().CreateTask();
1703 // SystemOverlay actor
1704 Actor systemOverlayActor = Actor::New();
1705 systemOverlayActor.SetSize(100.0f, 100.0f);
1706 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1707 systemOverlay.Add(systemOverlayActor);
1710 Actor stageActor = Actor::New();
1711 stageActor.SetSize(100.0f, 100.0f);
1712 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1713 Stage::GetCurrent().Add(stageActor);
1715 // Render and notify
1716 application.SendNotification();
1717 application.Render();
1719 // Set stage actor to touchable
1720 TouchEventData touchData;
1721 TouchEventDataFunctor touchFunctor( touchData );
1722 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1724 // Set system-overlay actor to have the gesture
1726 GestureReceivedFunctor functor(data);
1728 PanGestureDetector detector = PanGestureDetector::New();
1729 detector.Attach(systemOverlayActor);
1730 detector.DetectedSignal().Connect(&application, functor);
1732 Vector2 screenCoordsStart( 10.0f, 20.0f );
1733 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1735 // Start pan within the two actors' area
1736 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1737 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1738 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1739 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1740 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1745 // Do touch in the same area
1746 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoordsStart ) );
1747 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1748 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1753 int UtcDaliPanGestureAngleHandling(void)
1755 TestApplication application;
1757 PanGestureDetector detector = PanGestureDetector::New();
1758 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1760 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1761 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1763 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1765 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1767 tet_result( TET_PASS );
1775 tet_printf("%s, angle not added\n", TEST_LOCATION );
1776 tet_result( TET_FAIL );
1779 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1780 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1782 // Remove something not in the container.
1783 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1784 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1786 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1787 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1788 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1790 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1792 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1793 tet_result( TET_FAIL );
1798 detector.ClearAngles();
1799 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1803 int UtcDaliPanGestureGetAngle(void)
1805 TestApplication application;
1807 PanGestureDetector detector = PanGestureDetector::New();
1808 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1810 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1811 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1813 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1814 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1816 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1817 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1819 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1820 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1822 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1823 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1824 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1825 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1830 inline float RadiansToDegrees( float radian )
1832 return radian * 180.0f / Math::PI;
1835 int UtcDaliPanGestureAngleOutOfRange(void)
1837 TestApplication application;
1839 PanGestureDetector detector = PanGestureDetector::New();
1840 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1846 detector.AddAngle( Degree(180.0f) );
1847 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1848 detector.ClearAngles();
1850 detector.AddAngle( Degree(190.0f) );
1851 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1852 detector.ClearAngles();
1854 detector.AddAngle( Degree(-190.0f) );
1855 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1856 detector.ClearAngles();
1858 detector.AddAngle( Degree(350.0f) );
1859 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1860 detector.ClearAngles();
1862 detector.AddAngle( Degree(-350.0f) );
1863 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1864 detector.ClearAngles();
1866 detector.AddAngle( Degree(370.0f) );
1867 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1868 detector.ClearAngles();
1870 detector.AddAngle( Degree(-370.0f) );
1871 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1872 detector.ClearAngles();
1878 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1879 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1880 detector.ClearAngles();
1882 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1883 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1884 detector.ClearAngles();
1886 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1887 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1888 detector.ClearAngles();
1890 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1891 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1892 detector.ClearAngles();
1896 int UtcDaliPanGestureAngleProcessing(void)
1898 TestApplication application;
1900 Actor parent = Actor::New();
1901 parent.SetSize(100.0f, 100.0f);
1902 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1903 Stage::GetCurrent().Add(parent);
1905 Actor child = Actor::New();
1906 child.SetSize(100.0f, 100.0f);
1907 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1910 // Render and notify
1911 application.SendNotification();
1912 application.Render();
1914 // Parent detector only requires up pans
1915 PanGestureDetector parentDetector = PanGestureDetector::New();
1916 parentDetector.Attach( parent );
1917 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1918 SignalData parentData;
1919 GestureReceivedFunctor parentFunctor(parentData);
1920 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1922 // Child detector only requires right pans
1923 PanGestureDetector childDetector = PanGestureDetector::New();
1924 childDetector.Attach( child );
1925 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1926 SignalData childData;
1927 GestureReceivedFunctor childFunctor(childData);
1928 childDetector.DetectedSignal().Connect(&application, childFunctor);
1930 // Generate an Up pan gesture, only parent should receive it.
1931 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1932 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1933 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1934 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1935 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1939 // Generate a Right pan gesture, only child should receive it.
1940 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1941 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1942 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1943 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1944 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1948 // Generate a Down pan gesture, no one should receive it.
1949 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1950 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1951 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1952 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1953 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1957 // Generate a Left pan gesture, no one should receive it.
1958 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1959 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1960 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1961 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1962 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1968 int UtcDaliPanGestureDirectionHandling(void)
1970 TestApplication application;
1972 PanGestureDetector detector = PanGestureDetector::New();
1973 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1975 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1976 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1978 for ( size_t i = 0; detector.GetAngleCount(); i++)
1980 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1982 tet_result( TET_PASS );
1991 tet_printf("%s, angle not added\n", TEST_LOCATION );
1992 tet_result( TET_FAIL );
1996 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1998 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
2000 tet_result( TET_PASS );
2008 tet_printf("%s, angle not added\n", TEST_LOCATION );
2009 tet_result( TET_FAIL );
2012 // Remove something not in the container.
2013 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
2014 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
2016 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
2017 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
2021 int UtcDaliPanGestureDirectionProcessing(void)
2023 TestApplication application;
2025 Actor parent = Actor::New();
2026 parent.SetSize(100.0f, 100.0f);
2027 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2028 Stage::GetCurrent().Add(parent);
2030 Actor child = Actor::New();
2031 child.SetSize(100.0f, 100.0f);
2032 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2035 // Render and notify
2036 application.SendNotification();
2037 application.Render();
2039 // Parent detector only requires vertical panning
2040 PanGestureDetector parentDetector = PanGestureDetector::New();
2041 parentDetector.Attach( parent );
2042 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
2043 SignalData parentData;
2044 GestureReceivedFunctor parentFunctor(parentData);
2045 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2047 // Child detector only requires horizontal panning
2048 PanGestureDetector childDetector = PanGestureDetector::New();
2049 childDetector.Attach( child );
2050 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2051 SignalData childData;
2052 GestureReceivedFunctor childFunctor(childData);
2053 childDetector.DetectedSignal().Connect(&application, childFunctor);
2055 // Generate an Up pan gesture, only parent should receive it.
2056 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2057 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
2058 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2059 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2060 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2064 // Generate a Right pan gesture, only child should receive it.
2065 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2066 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2067 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2068 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2069 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2073 // Generate a Down pan gesture, only parent should receive it.
2074 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2075 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2076 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2077 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2078 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2082 // Generate a Left pan gesture, only child should receive it.
2083 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2084 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2085 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2086 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2087 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2091 // Generate a pan at -45 degrees, no one should receive it.
2092 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2093 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2094 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2095 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2096 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2100 // Generate a pan at 45 degrees, no one should receive it.
2101 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2102 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2103 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2104 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2105 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2109 // Generate a pan at 135 degrees, no one should receive it.
2110 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2111 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2112 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2113 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2114 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2118 // Generate a pan at -135 degrees, no one should receive it.
2119 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2120 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2121 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2122 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2123 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2129 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2131 TestApplication application;
2132 Integration::SetPanGesturePredictionMode(0);
2133 Integration::SetPanGestureSmoothingMode(0);
2135 Actor actor = Actor::New();
2136 actor.SetSize(100.0f, 100.0f);
2137 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2138 Stage::GetCurrent().Add(actor);
2140 // Add a pan detector
2141 PanGestureDetector detector = PanGestureDetector::New();
2142 detector.Attach( actor );
2144 GestureReceivedFunctor functor( data );
2145 detector.DetectedSignal().Connect( &application, functor );
2147 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2149 ConstraintData constraintData;
2150 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2151 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2152 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2153 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2154 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2155 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2156 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2157 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2160 // Render and notify
2161 application.SendNotification();
2162 application.Render();
2164 Vector2 direction(Vector2::XAXIS * -5.0f);
2165 Vector2 startPosition( 1.0f, 1.0f );
2166 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2167 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2168 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2169 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2170 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2172 constraintData.Reset();
2176 int UtcDaliPanGestureNoPredictionSmoothing(void)
2178 TestApplication application;
2179 Integration::SetPanGesturePredictionMode(0);
2180 Integration::SetPanGestureSmoothingMode(1);
2182 Actor actor = Actor::New();
2183 actor.SetSize(100.0f, 100.0f);
2184 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2185 Stage::GetCurrent().Add(actor);
2187 // Add a pan detector
2188 PanGestureDetector detector = PanGestureDetector::New();
2189 detector.Attach( actor );
2191 GestureReceivedFunctor functor( data );
2192 detector.DetectedSignal().Connect( &application, functor );
2194 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2196 ConstraintData constraintData;
2197 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2198 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2199 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2200 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2201 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2202 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2203 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2204 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2207 // Render and notify
2208 application.SendNotification();
2209 application.Render();
2211 Vector2 direction(Vector2::XAXIS * -5.0f);
2212 Vector2 previousPosition( 20.0f, 20.0f );
2213 Vector2 currentPosition( 20.0f, 10.0f );
2214 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2215 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2216 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2217 // Take into account resampling done when prediction is off.
2218 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2219 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2221 constraintData.Reset();
2225 int UtcDaliPanGesturePredictionNoSmoothing(void)
2227 TestApplication application;
2228 Integration::SetPanGesturePredictionMode(1);
2229 Integration::SetPanGestureSmoothingMode(0);
2231 Actor actor = Actor::New();
2232 actor.SetSize(100.0f, 100.0f);
2233 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2234 Stage::GetCurrent().Add(actor);
2236 // Add a pan detector
2237 PanGestureDetector detector = PanGestureDetector::New();
2238 detector.Attach( actor );
2240 GestureReceivedFunctor functor( data );
2241 detector.DetectedSignal().Connect( &application, functor );
2243 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2245 ConstraintData constraintData;
2246 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2247 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2248 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2249 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2250 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2251 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2252 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2253 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2256 // Render and notify
2257 application.SendNotification();
2258 application.Render();
2260 Vector2 direction(Vector2::XAXIS * -1.0f);
2261 Vector2 previousPosition( 20.0f, 20.0f );
2262 Vector2 currentPosition( 20.0f, 10.0f );
2263 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2264 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2265 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2266 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2267 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2269 constraintData.Reset();
2273 int UtcDaliPanGesturePredictionSmoothing01(void)
2275 TestApplication application;
2276 Integration::SetPanGesturePredictionMode(1);
2277 Integration::SetPanGestureSmoothingMode(1);
2279 Actor actor = Actor::New();
2280 actor.SetSize(100.0f, 100.0f);
2281 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2282 Stage::GetCurrent().Add(actor);
2284 // Add a pan detector
2285 PanGestureDetector detector = PanGestureDetector::New();
2286 detector.Attach( actor );
2288 GestureReceivedFunctor functor( data );
2289 detector.DetectedSignal().Connect( &application, functor );
2291 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2293 ConstraintData constraintData;
2294 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2295 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2296 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2297 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2298 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2299 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2300 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2301 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2304 // Render and notify
2305 application.SendNotification();
2306 application.Render();
2308 Vector2 direction(Vector2::XAXIS * -1.0f);
2309 Vector2 previousPosition( 20.0f, 20.0f );
2310 Vector2 currentPosition( 20.0f, 10.0f );
2311 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2312 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2313 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2314 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2315 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2317 constraintData.Reset();
2321 int UtcDaliPanGesturePredictionSmoothing02(void)
2323 TestApplication application;
2324 Integration::SetPanGesturePredictionMode( 1 );
2325 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2326 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2327 Integration::SetPanGestureSmoothingMode( 1 );
2328 Integration::SetPanGestureSmoothingAmount( 0.25f );
2330 Actor actor = Actor::New();
2331 actor.SetSize(100.0f, 100.0f);
2332 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2333 Stage::GetCurrent().Add(actor);
2335 // Add a pan detector
2336 PanGestureDetector detector = PanGestureDetector::New();
2337 detector.Attach( actor );
2339 GestureReceivedFunctor functor( data );
2340 detector.DetectedSignal().Connect( &application, functor );
2342 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2344 ConstraintData constraintData;
2345 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2346 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2347 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2348 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2349 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2350 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2351 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2352 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2355 // Render and notify
2356 application.SendNotification();
2357 application.Render();
2359 Vector2 directionX(Vector2::XAXIS);
2360 Vector2 directionY(Vector2::YAXIS);
2361 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), directionX, 10, 1, true, false);
2362 position = PerformSwipeGestureSwipe(application, position, directionX * 10.0f, 1, 1, false, false);
2363 position = PerformSwipeGestureSwipe(application, position, directionX * -1.0f, 2, 1, false, false);
2364 position = PerformSwipeGestureSwipe(application, position, directionX, 10, 1, false, true);
2365 position = PerformSwipeGestureSwipe(application, position, directionY, 10, 1, true, false);
2366 position = PerformSwipeGestureSwipe(application, position, directionY * -1.0f, 2, 1, false, false);
2367 position = PerformSwipeGestureSwipe(application, position, directionY, 10, 1, false, true);
2368 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2369 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2370 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2371 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2373 constraintData.Reset();
2377 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2379 TestApplication application;
2381 Integration::SetPanGesturePredictionMode( 2 );
2382 Integration::SetPanGesturePredictionAmount( 57 );
2383 Integration::SetPanGestureSmoothingMode( 2 );
2384 Integration::SetPanGestureUseActualTimes( false );
2385 Integration::SetPanGestureInterpolationTimeRange( 10 );
2386 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2387 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2388 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2389 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2390 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2391 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2393 Actor actor = Actor::New();
2394 actor.SetSize(100.0f, 100.0f);
2395 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2396 Stage::GetCurrent().Add(actor);
2398 // Add a pan detector
2399 PanGestureDetector detector = PanGestureDetector::New();
2400 detector.Attach( actor );
2402 GestureReceivedFunctor functor( data );
2403 detector.DetectedSignal().Connect( &application, functor );
2405 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2407 ConstraintData constraintData;
2408 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2409 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2410 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2411 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2412 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2413 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2414 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2415 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2418 // Render and notify
2419 application.SendNotification();
2420 application.Render();
2422 Vector2 direction(Vector2::XAXIS * -1.0f);
2423 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 1, true, true);
2424 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2425 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2426 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2427 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2429 constraintData.Reset();
2433 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2435 TestApplication application;
2437 Integration::SetPanGesturePredictionMode( 2 );
2438 Integration::SetPanGestureSmoothingMode( 2 );
2439 Integration::SetPanGestureUseActualTimes( true );
2440 Integration::SetPanGestureInterpolationTimeRange( 10 );
2441 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2442 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2443 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2444 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2445 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2446 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2448 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2450 Actor actor = Actor::New();
2451 actor.SetSize(100.0f, 100.0f);
2452 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2453 Stage::GetCurrent().Add(actor);
2455 // Add a pan detector
2456 PanGestureDetector detector = PanGestureDetector::New();
2457 detector.Attach( actor );
2459 GestureReceivedFunctor functor( data );
2460 detector.DetectedSignal().Connect( &application, functor );
2462 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2464 ConstraintData constraintData;
2465 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2466 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2467 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2468 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2469 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2470 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2471 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2472 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2475 // Render and notify
2476 application.SendNotification();
2477 application.Render();
2479 Vector2 direction(Vector2::XAXIS * -1.0f);
2480 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 3, true, false);
2481 position = PerformSwipeGestureSwipe(application, position, direction, 10, 0, false, false);
2482 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, false, 0);
2483 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, true);
2484 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2485 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2486 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2487 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2489 constraintData.Reset();
2493 int UtcDaliPanGesturePrediction2Smoothing(void)
2495 TestApplication application;
2497 Integration::SetPanGesturePredictionMode( 2 );
2498 Integration::SetPanGesturePredictionAmount( 57 );
2499 Integration::SetPanGestureSmoothingMode( 1 );
2500 Integration::SetPanGestureUseActualTimes( false );
2501 Integration::SetPanGestureInterpolationTimeRange( 10 );
2502 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2503 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2504 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2505 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2506 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2507 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2509 Actor actor = Actor::New();
2510 actor.SetSize(100.0f, 100.0f);
2511 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2512 Stage::GetCurrent().Add(actor);
2514 // Add a pan detector
2515 PanGestureDetector detector = PanGestureDetector::New();
2516 detector.Attach( actor );
2518 GestureReceivedFunctor functor( data );
2519 detector.DetectedSignal().Connect( &application, functor );
2521 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2523 ConstraintData constraintData;
2524 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2525 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2526 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2527 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2528 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2529 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2530 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2531 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2534 // Render and notify
2535 application.SendNotification();
2536 application.Render();
2538 Vector2 direction(Vector2::XAXIS * -1.0f);
2539 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 1, true, false);
2540 position = PerformSwipeGestureSwipe(application, position, direction, 1, 3, false, false);
2541 position = PerformSwipeGestureSwipe(application, position, direction, 5, 0, false, false);
2542 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, true);
2543 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2544 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2545 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2546 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2548 constraintData.Reset();
2552 int UtcDaliPanGestureSetProperties(void)
2554 TestApplication application;
2555 TestRenderController& renderController( application.GetRenderController() );
2556 Integration::SetPanGesturePredictionMode(0);
2557 Integration::SetPanGestureSmoothingMode(0);
2559 Actor actor = Actor::New();
2560 actor.SetSize(100.0f, 100.0f);
2561 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2562 Stage::GetCurrent().Add(actor);
2564 // Add a pan detector
2565 PanGestureDetector detector = PanGestureDetector::New();
2566 detector.Attach( actor );
2568 GestureReceivedFunctor functor( data );
2569 detector.DetectedSignal().Connect( &application, functor );
2571 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2572 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2574 ConstraintData constraintData;
2575 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2576 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2577 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2578 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2579 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2580 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2581 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2582 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2583 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2586 // Render and notify
2587 application.SendNotification();
2588 application.Render();
2590 renderController.Initialize();
2591 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2593 Vector2 screenPosition( 20.0f, 20.0f );
2594 Vector2 screenDisplacement( 1.0f, 1.0f );
2595 Vector2 screenVelocity( 1.3f, 4.0f );
2596 Vector2 localPosition( 21.0f, 21.0f );
2597 Vector2 localDisplacement( 0.5f, 0.5f );
2598 Vector2 localVelocity( 1.5f, 2.5f );
2600 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2601 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2603 // Render and notify
2604 application.SendNotification();
2605 application.Render();
2607 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2608 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2609 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2610 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2611 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2612 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2613 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2614 constraintData.Reset();
2618 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2620 TestApplication application;
2621 Integration::SetPanGesturePredictionMode(0);
2623 Actor actor = Actor::New();
2624 actor.SetSize(100.0f, 100.0f);
2625 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2626 Stage::GetCurrent().Add(actor);
2628 // Add a pan detector
2629 PanGestureDetector detector = PanGestureDetector::New();
2630 detector.Attach( actor );
2632 GestureReceivedFunctor functor( data );
2633 detector.DetectedSignal().Connect( &application, functor );
2635 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2637 ConstraintData constraintData;
2638 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2639 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2640 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2641 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2642 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2643 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2644 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2645 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2648 // Render and notify
2649 application.SendNotification();
2650 application.Render();
2652 Vector2 previousPosition( 20.0f, 20.0f );
2653 Vector2 currentPosition( 20.0f, 10.0f );
2654 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2655 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2656 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2658 Vector2 screenPosition( 100.0f, 20.0f );
2659 Vector2 localPosition( 110.0f, 110.0f );
2661 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2663 // Render and notify
2664 application.SendNotification();
2665 application.Render();
2667 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2668 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2669 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2670 constraintData.Reset();
2674 int UtcDaliPanGesturePropertyIndices(void)
2676 TestApplication application;
2677 PanGestureDetector detector = PanGestureDetector::New();
2679 Property::IndexContainer indices;
2680 detector.GetPropertyIndices( indices );
2681 DALI_TEST_CHECK( indices.Size() );
2682 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2688 struct PropertyStringIndex
2690 const char * const name;
2691 const Property::Index index;
2692 const Property::Type type;
2693 const Property::Value value;
2696 const PropertyStringIndex PROPERTY_TABLE[] =
2698 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2699 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2700 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2701 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2702 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2703 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2704 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2706 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2707 } // unnamed namespace
2710 int UtcDaliPanGestureProperties(void)
2712 TestApplication application;
2713 PanGestureDetector detector = PanGestureDetector::New();
2715 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2717 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2718 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2719 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2720 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2721 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2722 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2723 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2729 int UtcDaliPanGestureGetProperty(void)
2731 TestApplication application;
2732 PanGestureDetector detector = PanGestureDetector::New();
2734 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2736 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2738 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2739 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2741 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2743 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2744 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2751 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2753 TestApplication application;
2755 Actor actor = Actor::New();
2756 actor.SetSize(100.0f, 100.0f);
2757 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2758 Stage::GetCurrent().Add(actor);
2760 // Add a pan detector
2761 PanGestureDetector detector = PanGestureDetector::New();
2762 detector.Attach( actor );
2764 // Render and notify
2765 application.SendNotification();
2766 application.Render();
2768 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2770 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2772 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2774 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2775 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2777 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2779 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2780 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2787 int UtcDaliPanGestureLayerConsumesTouch(void)
2789 TestApplication application;
2791 Actor actor = Actor::New();
2792 actor.SetSize(100.0f, 100.0f);
2793 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2794 Stage::GetCurrent().Add(actor);
2796 // Add a pan detector
2797 PanGestureDetector detector = PanGestureDetector::New();
2798 detector.Attach( actor );
2800 GestureReceivedFunctor functor( data );
2801 detector.DetectedSignal().Connect( &application, functor );
2803 // Add a layer to overlap the actor
2804 Layer layer = Layer::New();
2805 layer.SetSize(100.0f, 100.0f);
2806 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2807 Stage::GetCurrent().Add( layer );
2810 // Render and notify
2811 application.SendNotification();
2812 application.Render();
2814 // Emit signals, should receive
2815 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2816 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2817 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2818 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2821 // Set layer to consume all touch
2822 layer.SetTouchConsumed( true );
2824 // Render and notify
2825 application.SendNotification();
2826 application.Render();
2828 // Emit the same signals again, should not receive
2829 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2830 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2831 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2832 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2838 int UtcDaliPanGestureNoTimeDiff(void)
2840 TestApplication application;
2842 Actor actor = Actor::New();
2843 actor.SetSize(100.0f, 100.0f);
2844 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2845 Stage::GetCurrent().Add(actor);
2847 // Add a pan detector
2848 PanGestureDetector detector = PanGestureDetector::New();
2849 detector.Attach( actor );
2851 GestureReceivedFunctor functor( data );
2852 detector.DetectedSignal().Connect( &application, functor );
2854 // Render and notify
2855 application.SendNotification();
2856 application.Render();
2858 // Emit signals, should receive
2859 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2860 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2861 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2862 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2863 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2864 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2865 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2866 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );