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/render-task-list-integ.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 UtcDaliPanGestureAngleHandling(void)
1608 TestApplication application;
1610 PanGestureDetector detector = PanGestureDetector::New();
1611 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1613 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1614 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1616 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1618 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1620 tet_result( TET_PASS );
1628 tet_printf("%s, angle not added\n", TEST_LOCATION );
1629 tet_result( TET_FAIL );
1632 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1633 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1635 // Remove something not in the container.
1636 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1637 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1639 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1640 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1641 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1643 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1645 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1646 tet_result( TET_FAIL );
1651 detector.ClearAngles();
1652 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1656 int UtcDaliPanGestureGetAngle(void)
1658 TestApplication application;
1660 PanGestureDetector detector = PanGestureDetector::New();
1661 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1663 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1664 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1666 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1667 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1669 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1670 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1672 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1673 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1675 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1676 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1677 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1678 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1683 inline float RadiansToDegrees( float radian )
1685 return radian * 180.0f / Math::PI;
1688 int UtcDaliPanGestureAngleOutOfRange(void)
1690 TestApplication application;
1692 PanGestureDetector detector = PanGestureDetector::New();
1693 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1699 detector.AddAngle( Degree(180.0f) );
1700 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1701 detector.ClearAngles();
1703 detector.AddAngle( Degree(190.0f) );
1704 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1705 detector.ClearAngles();
1707 detector.AddAngle( Degree(-190.0f) );
1708 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1709 detector.ClearAngles();
1711 detector.AddAngle( Degree(350.0f) );
1712 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1713 detector.ClearAngles();
1715 detector.AddAngle( Degree(-350.0f) );
1716 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1717 detector.ClearAngles();
1719 detector.AddAngle( Degree(370.0f) );
1720 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1721 detector.ClearAngles();
1723 detector.AddAngle( Degree(-370.0f) );
1724 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1725 detector.ClearAngles();
1731 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1732 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1733 detector.ClearAngles();
1735 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1736 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1737 detector.ClearAngles();
1739 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1740 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1741 detector.ClearAngles();
1743 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1744 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1745 detector.ClearAngles();
1749 int UtcDaliPanGestureAngleProcessing(void)
1751 TestApplication application;
1753 Actor parent = Actor::New();
1754 parent.SetSize(100.0f, 100.0f);
1755 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1756 Stage::GetCurrent().Add(parent);
1758 Actor child = Actor::New();
1759 child.SetSize(100.0f, 100.0f);
1760 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1763 // Render and notify
1764 application.SendNotification();
1765 application.Render();
1767 // Parent detector only requires up pans
1768 PanGestureDetector parentDetector = PanGestureDetector::New();
1769 parentDetector.Attach( parent );
1770 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1771 SignalData parentData;
1772 GestureReceivedFunctor parentFunctor(parentData);
1773 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1775 // Child detector only requires right pans
1776 PanGestureDetector childDetector = PanGestureDetector::New();
1777 childDetector.Attach( child );
1778 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1779 SignalData childData;
1780 GestureReceivedFunctor childFunctor(childData);
1781 childDetector.DetectedSignal().Connect(&application, childFunctor);
1783 // Generate an Up pan gesture, only parent should receive it.
1784 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1785 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1786 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1787 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1788 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1792 // Generate a Right pan gesture, only child should receive it.
1793 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1794 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1795 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1796 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1797 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1801 // Generate a Down pan gesture, no one should receive it.
1802 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1803 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1804 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1805 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1806 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1810 // Generate a Left pan gesture, no one should receive it.
1811 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1812 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1813 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1814 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1815 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1821 int UtcDaliPanGestureDirectionHandling(void)
1823 TestApplication application;
1825 PanGestureDetector detector = PanGestureDetector::New();
1826 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1828 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1829 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1831 for ( size_t i = 0; detector.GetAngleCount(); i++)
1833 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1835 tet_result( TET_PASS );
1844 tet_printf("%s, angle not added\n", TEST_LOCATION );
1845 tet_result( TET_FAIL );
1849 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1851 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1853 tet_result( TET_PASS );
1861 tet_printf("%s, angle not added\n", TEST_LOCATION );
1862 tet_result( TET_FAIL );
1865 // Remove something not in the container.
1866 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1867 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1869 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1870 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1874 int UtcDaliPanGestureDirectionProcessing(void)
1876 TestApplication application;
1878 Actor parent = Actor::New();
1879 parent.SetSize(100.0f, 100.0f);
1880 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1881 Stage::GetCurrent().Add(parent);
1883 Actor child = Actor::New();
1884 child.SetSize(100.0f, 100.0f);
1885 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1888 // Render and notify
1889 application.SendNotification();
1890 application.Render();
1892 // Parent detector only requires vertical panning
1893 PanGestureDetector parentDetector = PanGestureDetector::New();
1894 parentDetector.Attach( parent );
1895 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1896 SignalData parentData;
1897 GestureReceivedFunctor parentFunctor(parentData);
1898 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1900 // Child detector only requires horizontal panning
1901 PanGestureDetector childDetector = PanGestureDetector::New();
1902 childDetector.Attach( child );
1903 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1904 SignalData childData;
1905 GestureReceivedFunctor childFunctor(childData);
1906 childDetector.DetectedSignal().Connect(&application, childFunctor);
1908 // Generate an Up pan gesture, only parent should receive it.
1909 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1910 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1911 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1912 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1913 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1917 // Generate a Right pan gesture, only child should receive it.
1918 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1919 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1920 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1921 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1922 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1926 // Generate a Down pan gesture, only parent should receive it.
1927 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1928 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1929 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1930 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1931 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1935 // Generate a Left pan gesture, only child should receive it.
1936 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1937 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1938 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1939 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1940 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1944 // Generate a pan at -45 degrees, no one should receive it.
1945 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1946 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1947 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1948 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1949 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1953 // Generate a pan at 45 degrees, no one should receive it.
1954 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1955 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
1956 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1957 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1958 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1962 // Generate a pan at 135 degrees, no one should receive it.
1963 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1964 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
1965 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1966 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1967 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1971 // Generate a pan at -135 degrees, no one should receive it.
1972 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1973 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
1974 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1975 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1976 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1982 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1984 TestApplication application;
1985 Integration::SetPanGesturePredictionMode(0);
1986 Integration::SetPanGestureSmoothingMode(0);
1988 Actor actor = Actor::New();
1989 actor.SetSize(100.0f, 100.0f);
1990 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1991 Stage::GetCurrent().Add(actor);
1993 // Add a pan detector
1994 PanGestureDetector detector = PanGestureDetector::New();
1995 detector.Attach( actor );
1997 GestureReceivedFunctor functor( data );
1998 detector.DetectedSignal().Connect( &application, functor );
2000 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2002 ConstraintData constraintData;
2003 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2004 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2005 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2006 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2007 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2008 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2009 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2010 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2013 // Render and notify
2014 application.SendNotification();
2015 application.Render();
2017 Vector2 direction(Vector2::XAXIS * -5.0f);
2018 Vector2 startPosition( 1.0f, 1.0f );
2019 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2020 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2021 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2022 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2023 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2025 constraintData.Reset();
2029 int UtcDaliPanGestureNoPredictionSmoothing(void)
2031 TestApplication application;
2032 Integration::SetPanGesturePredictionMode(0);
2033 Integration::SetPanGestureSmoothingMode(1);
2035 Actor actor = Actor::New();
2036 actor.SetSize(100.0f, 100.0f);
2037 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2038 Stage::GetCurrent().Add(actor);
2040 // Add a pan detector
2041 PanGestureDetector detector = PanGestureDetector::New();
2042 detector.Attach( actor );
2044 GestureReceivedFunctor functor( data );
2045 detector.DetectedSignal().Connect( &application, functor );
2047 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2049 ConstraintData constraintData;
2050 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2051 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2052 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2053 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2054 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2055 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2056 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2057 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2060 // Render and notify
2061 application.SendNotification();
2062 application.Render();
2064 Vector2 direction(Vector2::XAXIS * -5.0f);
2065 Vector2 previousPosition( 20.0f, 20.0f );
2066 Vector2 currentPosition( 20.0f, 10.0f );
2067 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2068 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2069 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2070 // Take into account resampling done when prediction is off.
2071 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2072 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2074 constraintData.Reset();
2078 int UtcDaliPanGesturePredictionNoSmoothing(void)
2080 TestApplication application;
2081 Integration::SetPanGesturePredictionMode(1);
2082 Integration::SetPanGestureSmoothingMode(0);
2084 Actor actor = Actor::New();
2085 actor.SetSize(100.0f, 100.0f);
2086 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2087 Stage::GetCurrent().Add(actor);
2089 // Add a pan detector
2090 PanGestureDetector detector = PanGestureDetector::New();
2091 detector.Attach( actor );
2093 GestureReceivedFunctor functor( data );
2094 detector.DetectedSignal().Connect( &application, functor );
2096 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2098 ConstraintData constraintData;
2099 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2100 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2101 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2102 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2103 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2104 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2105 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2106 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2109 // Render and notify
2110 application.SendNotification();
2111 application.Render();
2113 Vector2 direction(Vector2::XAXIS * -1.0f);
2114 Vector2 previousPosition( 20.0f, 20.0f );
2115 Vector2 currentPosition( 20.0f, 10.0f );
2116 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2117 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2118 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2119 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2120 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2122 constraintData.Reset();
2126 int UtcDaliPanGesturePredictionSmoothing01(void)
2128 TestApplication application;
2129 Integration::SetPanGesturePredictionMode(1);
2130 Integration::SetPanGestureSmoothingMode(1);
2132 Actor actor = Actor::New();
2133 actor.SetSize(100.0f, 100.0f);
2134 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2135 Stage::GetCurrent().Add(actor);
2137 // Add a pan detector
2138 PanGestureDetector detector = PanGestureDetector::New();
2139 detector.Attach( actor );
2141 GestureReceivedFunctor functor( data );
2142 detector.DetectedSignal().Connect( &application, functor );
2144 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2146 ConstraintData constraintData;
2147 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2148 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2149 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2150 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2151 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2152 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2153 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2154 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2157 // Render and notify
2158 application.SendNotification();
2159 application.Render();
2161 Vector2 direction(Vector2::XAXIS * -1.0f);
2162 Vector2 previousPosition( 20.0f, 20.0f );
2163 Vector2 currentPosition( 20.0f, 10.0f );
2164 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2165 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2166 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2167 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2168 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2170 constraintData.Reset();
2174 int UtcDaliPanGesturePredictionSmoothing02(void)
2176 TestApplication application;
2177 Integration::SetPanGesturePredictionMode( 1 );
2178 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2179 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2180 Integration::SetPanGestureSmoothingMode( 1 );
2181 Integration::SetPanGestureSmoothingAmount( 0.25f );
2183 Actor actor = Actor::New();
2184 actor.SetSize(100.0f, 100.0f);
2185 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2186 Stage::GetCurrent().Add(actor);
2188 // Add a pan detector
2189 PanGestureDetector detector = PanGestureDetector::New();
2190 detector.Attach( actor );
2192 GestureReceivedFunctor functor( data );
2193 detector.DetectedSignal().Connect( &application, functor );
2195 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2197 ConstraintData constraintData;
2198 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2199 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2200 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2201 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2202 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2203 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2204 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2205 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2208 // Render and notify
2209 application.SendNotification();
2210 application.Render();
2212 Vector2 directionX(Vector2::XAXIS);
2213 Vector2 directionY(Vector2::YAXIS);
2214 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), directionX, 10, 1, true, false);
2215 position = PerformSwipeGestureSwipe(application, position, directionX * 10.0f, 1, 1, false, false);
2216 position = PerformSwipeGestureSwipe(application, position, directionX * -1.0f, 2, 1, false, false);
2217 position = PerformSwipeGestureSwipe(application, position, directionX, 10, 1, false, true);
2218 position = PerformSwipeGestureSwipe(application, position, directionY, 10, 1, true, false);
2219 position = PerformSwipeGestureSwipe(application, position, directionY * -1.0f, 2, 1, false, false);
2220 position = PerformSwipeGestureSwipe(application, position, directionY, 10, 1, false, true);
2221 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2222 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2223 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2224 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2226 constraintData.Reset();
2230 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2232 TestApplication application;
2234 Integration::SetPanGesturePredictionMode( 2 );
2235 Integration::SetPanGesturePredictionAmount( 57 );
2236 Integration::SetPanGestureSmoothingMode( 2 );
2237 Integration::SetPanGestureUseActualTimes( false );
2238 Integration::SetPanGestureInterpolationTimeRange( 10 );
2239 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2240 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2241 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2242 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2243 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2244 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2246 Actor actor = Actor::New();
2247 actor.SetSize(100.0f, 100.0f);
2248 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2249 Stage::GetCurrent().Add(actor);
2251 // Add a pan detector
2252 PanGestureDetector detector = PanGestureDetector::New();
2253 detector.Attach( actor );
2255 GestureReceivedFunctor functor( data );
2256 detector.DetectedSignal().Connect( &application, functor );
2258 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2260 ConstraintData constraintData;
2261 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2262 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2263 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2264 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2265 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2266 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2267 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2268 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2271 // Render and notify
2272 application.SendNotification();
2273 application.Render();
2275 Vector2 direction(Vector2::XAXIS * -1.0f);
2276 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 1, true, true);
2277 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2278 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2279 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2280 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2282 constraintData.Reset();
2286 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2288 TestApplication application;
2290 Integration::SetPanGesturePredictionMode( 2 );
2291 Integration::SetPanGestureSmoothingMode( 2 );
2292 Integration::SetPanGestureUseActualTimes( true );
2293 Integration::SetPanGestureInterpolationTimeRange( 10 );
2294 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2295 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2296 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2297 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2298 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2299 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2301 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2303 Actor actor = Actor::New();
2304 actor.SetSize(100.0f, 100.0f);
2305 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2306 Stage::GetCurrent().Add(actor);
2308 // Add a pan detector
2309 PanGestureDetector detector = PanGestureDetector::New();
2310 detector.Attach( actor );
2312 GestureReceivedFunctor functor( data );
2313 detector.DetectedSignal().Connect( &application, functor );
2315 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2317 ConstraintData constraintData;
2318 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2319 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2320 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2321 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2322 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2323 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2324 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2325 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2328 // Render and notify
2329 application.SendNotification();
2330 application.Render();
2332 Vector2 direction(Vector2::XAXIS * -1.0f);
2333 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 3, true, false);
2334 position = PerformSwipeGestureSwipe(application, position, direction, 10, 0, false, false);
2335 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, false, 0);
2336 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, true);
2337 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2338 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2339 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2340 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2342 constraintData.Reset();
2346 int UtcDaliPanGesturePrediction2Smoothing(void)
2348 TestApplication application;
2350 Integration::SetPanGesturePredictionMode( 2 );
2351 Integration::SetPanGesturePredictionAmount( 57 );
2352 Integration::SetPanGestureSmoothingMode( 1 );
2353 Integration::SetPanGestureUseActualTimes( false );
2354 Integration::SetPanGestureInterpolationTimeRange( 10 );
2355 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2356 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2357 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2358 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2359 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2360 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2362 Actor actor = Actor::New();
2363 actor.SetSize(100.0f, 100.0f);
2364 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2365 Stage::GetCurrent().Add(actor);
2367 // Add a pan detector
2368 PanGestureDetector detector = PanGestureDetector::New();
2369 detector.Attach( actor );
2371 GestureReceivedFunctor functor( data );
2372 detector.DetectedSignal().Connect( &application, functor );
2374 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2376 ConstraintData constraintData;
2377 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2378 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2379 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2380 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2381 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2382 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2383 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2384 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2387 // Render and notify
2388 application.SendNotification();
2389 application.Render();
2391 Vector2 direction(Vector2::XAXIS * -1.0f);
2392 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 1, true, false);
2393 position = PerformSwipeGestureSwipe(application, position, direction, 1, 3, false, false);
2394 position = PerformSwipeGestureSwipe(application, position, direction, 5, 0, false, false);
2395 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, true);
2396 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2397 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2398 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2399 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2401 constraintData.Reset();
2405 int UtcDaliPanGestureSetProperties(void)
2407 TestApplication application;
2408 TestRenderController& renderController( application.GetRenderController() );
2409 Integration::SetPanGesturePredictionMode(0);
2410 Integration::SetPanGestureSmoothingMode(0);
2412 Actor actor = Actor::New();
2413 actor.SetSize(100.0f, 100.0f);
2414 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2415 Stage::GetCurrent().Add(actor);
2417 // Add a pan detector
2418 PanGestureDetector detector = PanGestureDetector::New();
2419 detector.Attach( actor );
2421 GestureReceivedFunctor functor( data );
2422 detector.DetectedSignal().Connect( &application, functor );
2424 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2425 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2427 ConstraintData constraintData;
2428 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2429 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2430 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2431 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2432 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2433 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2434 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2435 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2436 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2439 // Render and notify
2440 application.SendNotification();
2441 application.Render();
2443 renderController.Initialize();
2444 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2446 Vector2 screenPosition( 20.0f, 20.0f );
2447 Vector2 screenDisplacement( 1.0f, 1.0f );
2448 Vector2 screenVelocity( 1.3f, 4.0f );
2449 Vector2 localPosition( 21.0f, 21.0f );
2450 Vector2 localDisplacement( 0.5f, 0.5f );
2451 Vector2 localVelocity( 1.5f, 2.5f );
2453 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2454 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2456 // Render and notify
2457 application.SendNotification();
2458 application.Render();
2460 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2461 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2462 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2463 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2464 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2465 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2466 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2467 constraintData.Reset();
2471 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2473 TestApplication application;
2474 Integration::SetPanGesturePredictionMode(0);
2476 Actor actor = Actor::New();
2477 actor.SetSize(100.0f, 100.0f);
2478 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2479 Stage::GetCurrent().Add(actor);
2481 // Add a pan detector
2482 PanGestureDetector detector = PanGestureDetector::New();
2483 detector.Attach( actor );
2485 GestureReceivedFunctor functor( data );
2486 detector.DetectedSignal().Connect( &application, functor );
2488 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2490 ConstraintData constraintData;
2491 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2492 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2493 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2494 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2495 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2496 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2497 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2498 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2501 // Render and notify
2502 application.SendNotification();
2503 application.Render();
2505 Vector2 previousPosition( 20.0f, 20.0f );
2506 Vector2 currentPosition( 20.0f, 10.0f );
2507 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2508 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2509 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2511 Vector2 screenPosition( 100.0f, 20.0f );
2512 Vector2 localPosition( 110.0f, 110.0f );
2514 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2516 // Render and notify
2517 application.SendNotification();
2518 application.Render();
2520 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2521 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2522 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2523 constraintData.Reset();
2527 int UtcDaliPanGesturePropertyIndices(void)
2529 TestApplication application;
2530 PanGestureDetector detector = PanGestureDetector::New();
2532 Property::IndexContainer indices;
2533 detector.GetPropertyIndices( indices );
2534 DALI_TEST_CHECK( indices.Size() );
2535 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2541 struct PropertyStringIndex
2543 const char * const name;
2544 const Property::Index index;
2545 const Property::Type type;
2546 const Property::Value value;
2549 const PropertyStringIndex PROPERTY_TABLE[] =
2551 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2552 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2553 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2554 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2555 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2556 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2557 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2559 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2560 } // unnamed namespace
2563 int UtcDaliPanGestureProperties(void)
2565 TestApplication application;
2566 PanGestureDetector detector = PanGestureDetector::New();
2568 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2570 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2571 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2572 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2573 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2574 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2575 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2576 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2582 int UtcDaliPanGestureGetProperty(void)
2584 TestApplication application;
2585 PanGestureDetector detector = PanGestureDetector::New();
2587 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2589 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2591 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2592 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2594 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2596 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2597 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2604 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2606 TestApplication application;
2608 Actor actor = Actor::New();
2609 actor.SetSize(100.0f, 100.0f);
2610 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2611 Stage::GetCurrent().Add(actor);
2613 // Add a pan detector
2614 PanGestureDetector detector = PanGestureDetector::New();
2615 detector.Attach( actor );
2617 // Render and notify
2618 application.SendNotification();
2619 application.Render();
2621 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2623 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2625 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2627 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2628 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2630 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2632 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2633 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2640 int UtcDaliPanGestureLayerConsumesTouch(void)
2642 TestApplication application;
2644 Actor actor = Actor::New();
2645 actor.SetSize(100.0f, 100.0f);
2646 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2647 Stage::GetCurrent().Add(actor);
2649 // Add a pan detector
2650 PanGestureDetector detector = PanGestureDetector::New();
2651 detector.Attach( actor );
2653 GestureReceivedFunctor functor( data );
2654 detector.DetectedSignal().Connect( &application, functor );
2656 // Add a layer to overlap the actor
2657 Layer layer = Layer::New();
2658 layer.SetSize(100.0f, 100.0f);
2659 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2660 Stage::GetCurrent().Add( layer );
2663 // Render and notify
2664 application.SendNotification();
2665 application.Render();
2667 // Emit signals, should receive
2668 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2669 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2670 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2671 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2674 // Set layer to consume all touch
2675 layer.SetTouchConsumed( true );
2677 // Render and notify
2678 application.SendNotification();
2679 application.Render();
2681 // Emit the same signals again, should not receive
2682 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2683 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2684 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2685 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2691 int UtcDaliPanGestureNoTimeDiff(void)
2693 TestApplication application;
2695 Actor actor = Actor::New();
2696 actor.SetSize(100.0f, 100.0f);
2697 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2698 Stage::GetCurrent().Add(actor);
2700 // Add a pan detector
2701 PanGestureDetector detector = PanGestureDetector::New();
2702 detector.Attach( actor );
2704 GestureReceivedFunctor functor( data );
2705 detector.DetectedSignal().Connect( &application, functor );
2707 // Render and notify
2708 application.SendNotification();
2709 application.Render();
2711 // Emit signals, should receive
2712 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2713 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2714 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2715 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2716 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2717 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2718 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2719 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );