2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/integration-api/system-overlay.h>
26 #include <dali/integration-api/profiling.h>
27 #include <dali/integration-api/input-options.h>
28 #include <dali-test-suite-utils.h>
29 #include <test-touch-utils.h>
33 void utc_dali_pan_gesture_detector_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_pan_gesture_detector_cleanup(void)
40 test_return_value = TET_PASS;
43 ///////////////////////////////////////////////////////////////////////////////
46 typedef Dali::PanGestureDetector::AngleContainer::size_type AngleSizeType;
48 const int PAN_EVENT_TIME_DELTA = 8;
49 const int PAN_GESTURE_UPDATE_COUNT = 50;
51 // Stores data that is populated in the callback and will be read by the test cases
55 : functorCalled(false),
56 voidFunctorCalled(false),
57 receivedGesture(Gesture::Clear)
62 functorCalled = false;
63 voidFunctorCalled = false;
65 receivedGesture.state = Gesture::Clear;
66 receivedGesture.velocity = Vector2(0.0f, 0.0f);
67 receivedGesture.displacement = Vector2(0.0f, 0.0f);
68 receivedGesture.position = Vector2(0.0f, 0.0f);
69 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
70 receivedGesture.numberOfTouches = 0;
76 bool voidFunctorCalled;
77 PanGesture receivedGesture;
81 // Functor that sets the data when called
82 struct GestureReceivedFunctor
84 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
86 void operator()(Actor actor, const PanGesture& pan)
88 signalData.functorCalled = true;
89 signalData.receivedGesture = pan;
90 signalData.pannedActor = actor;
95 signalData.voidFunctorCalled = true;
98 SignalData& signalData;
101 // Functor that removes the gestured actor from stage
102 struct UnstageActorFunctor : public GestureReceivedFunctor
104 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
105 : GestureReceivedFunctor( data ),
106 stateToUnstage( stateToUnstage )
110 void operator()( Actor actor, const PanGesture& pan )
112 GestureReceivedFunctor::operator()( actor, pan );
114 if ( pan.state == stateToUnstage )
116 Stage::GetCurrent().Remove( actor );
120 Gesture::State& stateToUnstage;
123 // Functor for receiving a touch event
124 struct TouchEventFunctor
126 bool operator()(Actor actor, const TouchEvent& touch)
132 // Data for constraints
133 struct ConstraintData
140 Vector2 screenPosition;
141 Vector2 screenDisplacement;
142 Vector2 screenVelocity;
143 Vector2 localPosition;
144 Vector2 localDisplacement;
145 Vector2 localVelocity;
150 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
155 // Constraint used with panning properties
158 PanConstraint( ConstraintData& data ) : constraintData(data) { }
160 void operator()( Vector3& current, const PropertyInputContainer& inputs )
162 constraintData.screenPosition = inputs[0]->GetVector2();
163 constraintData.screenDisplacement = inputs[1]->GetVector2();
164 constraintData.screenVelocity = inputs[2]->GetVector2();
165 constraintData.localPosition = inputs[3]->GetVector2();
166 constraintData.localDisplacement = inputs[4]->GetVector2();
167 constraintData.localVelocity = inputs[5]->GetVector2();
168 constraintData.called = true;
169 current = Vector3::ZERO;
172 ConstraintData& constraintData;
175 // Generate a PanGestureEvent to send to Core
176 Integration::PanGestureEvent GeneratePan(
177 Gesture::State state,
178 Vector2 previousPosition,
179 Vector2 currentPosition,
180 unsigned long timeDelta,
181 unsigned int numberOfTouches = 1,
182 unsigned int time = 1u)
184 Integration::PanGestureEvent pan(state);
186 pan.previousPosition = previousPosition;
187 pan.currentPosition = currentPosition;
188 pan.timeDelta = timeDelta;
189 pan.numberOfTouches = numberOfTouches;
195 // Generate a PanGesture
196 PanGesture GeneratePan( unsigned int time,
197 Gesture::State state,
198 Vector2 screenPosition,
199 Vector2 localPosition,
200 Vector2 screenDisplacement = Vector2::ONE,
201 Vector2 localDisplacement = Vector2::ONE,
202 Vector2 screenVelocity = Vector2::ONE,
203 Vector2 localVelocity = Vector2::ONE,
204 unsigned int numberOfTouches = 1 )
206 PanGesture pan( state );
210 pan.screenPosition = screenPosition;
211 pan.position = localPosition;
213 pan.screenDisplacement = screenDisplacement;
214 pan.displacement = localDisplacement;
216 pan.screenVelocity = screenVelocity;
217 pan.velocity = localVelocity;
219 pan.numberOfTouches = numberOfTouches;
225 * Helper to generate PanGestureEvent
227 * @param[in] application Application instance
228 * @param[in] state The Gesture State
229 * @param[in] pos The current position of touch.
231 static void SendPan(TestApplication& application, Gesture::State state, const Vector2& pos)
234 static int LastTime = 0;
236 if( (state == Gesture::Started) ||
237 (state == Gesture::Possible) )
243 application.ProcessEvent(GeneratePan(state, last, pos, PAN_EVENT_TIME_DELTA));
247 LastTime += PAN_EVENT_TIME_DELTA;
250 static Vector2 PerformSwipeGestureSwipe(TestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
252 // Now do a pan starting from (start) and heading (direction)
254 SendPan(application, Gesture::Possible, pos);
255 SendPan(application, Gesture::Started, pos);
256 application.SendNotification();
257 application.Render();
259 for(int i = 0;i<frames;i++)
261 pos += direction; // Move in this direction
262 SendPan(application, Gesture::Continuing, pos);
263 application.SendNotification();
264 application.Render();
269 SendPan(application, Gesture::Finished, pos);
270 application.SendNotification();
271 application.Render();
279 ///////////////////////////////////////////////////////////////////////////////
281 // Positive test case for a method
282 int UtcDaliPanGestureDetectorConstructor(void)
284 TestApplication application;
286 PanGestureDetector detector;
287 DALI_TEST_CHECK(!detector);
292 // Negative test case for a method
293 int UtcDaliPanGestureDetectorNew(void)
295 TestApplication application;
297 PanGestureDetector detector = PanGestureDetector::New();
299 DALI_TEST_CHECK(detector);
301 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
302 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
304 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
305 Actor actor = Actor::New();
306 actor.SetSize(100.0f, 100.0f);
307 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
308 detector.Attach(actor);
310 Stage::GetCurrent().Add(actor);
313 application.SendNotification();
314 application.Render();
316 Integration::TouchEvent touchEvent(1);
317 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
318 touchEvent.AddPoint(point);
319 application.ProcessEvent(touchEvent);
323 int UtcDaliPanGestureDetectorDownCast(void)
325 TestApplication application;
326 tet_infoline("Testing Dali::GestureDetector::DownCast()");
328 PanGestureDetector detector = PanGestureDetector::New();
330 BaseHandle object(detector);
332 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
333 DALI_TEST_CHECK(detector2);
335 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
336 DALI_TEST_CHECK(detector3);
338 BaseHandle unInitializedObject;
339 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
340 DALI_TEST_CHECK(!detector4);
342 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
343 DALI_TEST_CHECK(!detector5);
345 GestureDetector detector6 = PanGestureDetector::New();
346 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
347 DALI_TEST_CHECK(detector7);
351 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
353 TestApplication application;
355 PanGestureDetector detector = PanGestureDetector::New();
357 unsigned int min = 2;
359 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
361 detector.SetMinimumTouchesRequired(min);
363 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
365 // Attach an actor and change the minimum touches
367 Actor actor = Actor::New();
368 actor.SetSize(100.0f, 100.0f);
369 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
370 Stage::GetCurrent().Add(actor);
373 application.SendNotification();
374 application.Render();
377 GestureReceivedFunctor functor(data);
379 detector.Attach(actor);
380 detector.DetectedSignal().Connect(&application, functor);
382 TestGestureManager& gestureManager = application.GetGestureManager();
383 gestureManager.Initialize();
385 detector.SetMinimumTouchesRequired(3);
387 // Gesture detection should have been updated only
388 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
389 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
390 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
393 gestureManager.Initialize();
395 // Create a second gesture detector that requires even less minimum touches
396 PanGestureDetector secondDetector = PanGestureDetector::New();
397 secondDetector.Attach(actor);
399 // Gesture detection should have been updated only
400 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
401 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
402 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
406 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
408 TestApplication application;
410 PanGestureDetector detector = PanGestureDetector::New();
412 unsigned int max = 3;
414 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
416 detector.SetMaximumTouchesRequired(max);
418 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
420 // Attach an actor and change the maximum touches
422 Actor actor = Actor::New();
423 actor.SetSize(100.0f, 100.0f);
424 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
425 Stage::GetCurrent().Add(actor);
428 application.SendNotification();
429 application.Render();
432 GestureReceivedFunctor functor(data);
434 detector.Attach(actor);
435 detector.DetectedSignal().Connect(&application, functor);
437 TestGestureManager& gestureManager = application.GetGestureManager();
438 gestureManager.Initialize();
440 detector.SetMaximumTouchesRequired(4);
442 // Gesture detection should have been updated only
443 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
444 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
445 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
448 gestureManager.Initialize();
450 // Create a second gesture detector that requires even less maximum touches
451 PanGestureDetector secondDetector = PanGestureDetector::New();
452 secondDetector.Attach(actor);
454 // Gesture detection should NOT have been updated
455 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
456 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
457 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
461 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
463 TestApplication application;
465 PanGestureDetector detector = PanGestureDetector::New();
466 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
470 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
472 TestApplication application;
474 PanGestureDetector detector = PanGestureDetector::New();
475 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
479 int UtcDaliPanGestureSignalReceptionNegative(void)
481 TestApplication application;
483 Actor actor = Actor::New();
484 actor.SetSize(100.0f, 100.0f);
485 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
486 Stage::GetCurrent().Add(actor);
489 application.SendNotification();
490 application.Render();
493 GestureReceivedFunctor functor(data);
495 PanGestureDetector detector = PanGestureDetector::New();
496 detector.Attach(actor);
497 detector.DetectedSignal().Connect(&application, functor);
499 // Do a pan outside actor's area
500 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
501 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
502 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
504 // Continue pan into actor's area - we should still not receive the signal
506 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
507 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
509 // Stop panning - we should still not receive the signal
511 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
512 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
516 int UtcDaliPanGestureSignalReceptionDownMotionLeave(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 // Start pan within the actor's area
537 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
538 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
539 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
540 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
541 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
542 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
543 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
544 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
545 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
547 // Continue the pan within the actor's area - we should still receive the signal
549 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
550 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
551 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
552 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
553 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
554 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
555 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
556 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
558 // Pan Gesture leaves actor's area - we should still receive the signal
560 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
561 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
562 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
563 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
564 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
565 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
566 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
569 // Gesture ends - we would receive a finished state
571 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
572 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
573 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
574 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
575 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
576 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
577 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
578 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
582 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
584 TestApplication application;
586 Actor actor = Actor::New();
587 actor.SetSize(100.0f, 100.0f);
588 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
589 Stage::GetCurrent().Add(actor);
592 application.SendNotification();
593 application.Render();
596 GestureReceivedFunctor functor(data);
598 PanGestureDetector detector = PanGestureDetector::New();
599 detector.Attach(actor);
600 detector.DetectedSignal().Connect(&application, functor);
602 // Start pan within the actor's area
603 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
604 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
605 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
606 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
607 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
608 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
609 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
610 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
611 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
613 // Continue the pan within the actor's area - we should still receive the signal
615 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
616 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
617 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
618 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
619 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
620 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
621 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
622 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
624 // Gesture ends within actor's area - we would receive a finished state
626 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
627 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
628 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
629 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
630 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
631 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
632 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
633 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
637 int UtcDaliPanGestureSignalReceptionCancelled(void)
639 TestApplication application;
641 Actor actor = Actor::New();
642 actor.SetSize(100.0f, 100.0f);
643 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
644 Stage::GetCurrent().Add(actor);
647 application.SendNotification();
648 application.Render();
651 GestureReceivedFunctor functor(data);
653 PanGestureDetector detector = PanGestureDetector::New();
654 detector.Attach(actor);
655 detector.DetectedSignal().Connect(&application, functor);
657 // Start pan within the actor's area
658 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
659 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
660 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
661 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
663 // Continue the pan within the actor's area - we should still receive the signal
665 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
666 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
667 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
669 // The gesture is cancelled
671 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
672 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
673 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
677 int UtcDaliPanGestureSignalReceptionDetach(void)
679 TestApplication application;
681 Actor actor = Actor::New();
682 actor.SetSize(100.0f, 100.0f);
683 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
684 Stage::GetCurrent().Add(actor);
687 application.SendNotification();
688 application.Render();
691 GestureReceivedFunctor functor(data);
693 PanGestureDetector detector = PanGestureDetector::New();
694 detector.Attach(actor);
695 detector.DetectedSignal().Connect(&application, functor);
697 // Start pan within the actor's area
698 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
699 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
700 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
702 // Continue the pan within the actor's area - we should still receive the signal
704 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
705 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
707 // Gesture ends within actor's area
709 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
710 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
713 detector.DetachAll();
715 // Ensure we are no longer signalled
717 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
718 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
719 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
720 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
721 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
725 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
727 TestApplication application;
729 Actor actor = Actor::New();
730 actor.SetSize(100.0f, 100.0f);
731 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
732 Stage::GetCurrent().Add(actor);
735 application.SendNotification();
736 application.Render();
739 GestureReceivedFunctor functor(data);
741 PanGestureDetector detector = PanGestureDetector::New();
742 detector.Attach(actor);
743 detector.DetectedSignal().Connect(&application, functor);
745 // Start pan within the actor's area
746 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
747 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
748 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
750 // Continue the pan within the actor's area - we should still receive the signal
752 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
753 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
755 // Detach actor during the pan, we should not receive the next event
756 detector.DetachAll();
758 // Gesture ends within actor's area
760 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
761 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
765 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
767 TestApplication application;
770 GestureReceivedFunctor functor(data);
772 PanGestureDetector detector = PanGestureDetector::New();
773 detector.DetectedSignal().Connect(&application, functor);
775 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
777 Actor tempActor = Actor::New();
778 tempActor.SetSize(100.0f, 100.0f);
779 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
780 Stage::GetCurrent().Add(tempActor);
781 detector.Attach(tempActor);
783 // Actor lifetime is scoped
785 Actor actor = Actor::New();
786 actor.SetSize(100.0f, 100.0f);
787 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
788 Stage::GetCurrent().Add(actor);
791 application.SendNotification();
792 application.Render();
794 detector.Attach(actor);
796 // Start pan within the actor's area
797 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
798 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
799 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
801 // Continue the pan within the actor's area - we should still receive the signal
803 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
804 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
806 // Remove the actor from stage and reset the data
807 Stage::GetCurrent().Remove(actor);
810 application.SendNotification();
811 application.Render();
814 // Actor should now have been destroyed
816 // Gesture ends within the area where the actor used to be
818 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
819 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
823 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
825 TestApplication application;
827 Actor actor = Actor::New();
828 actor.SetSize(100.0f, 100.0f);
829 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
830 Stage::GetCurrent().Add(actor);
833 application.SendNotification();
834 application.Render();
837 GestureReceivedFunctor functor(data);
839 PanGestureDetector detector = PanGestureDetector::New();
840 detector.Attach(actor);
841 detector.DetectedSignal().Connect(&application, functor);
843 // Do an entire pan, only check finished value
844 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
845 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
847 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
848 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
849 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
851 // Rotate actor again and render a couple of times
852 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
853 application.SendNotification();
854 application.Render();
856 // Do an entire pan, only check finished value
857 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
858 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
860 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
861 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
862 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
864 // Rotate actor again and render a couple of times
865 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
866 application.SendNotification();
867 application.Render();
869 // Do an entire pan, only check finished value
870 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
871 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
873 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
874 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
875 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
879 int UtcDaliPanGestureSignalReceptionChildHit(void)
881 TestApplication application;
883 Actor parent = Actor::New();
884 parent.SetSize(100.0f, 100.0f);
885 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
886 Stage::GetCurrent().Add(parent);
888 // Set child to completely cover parent.
889 // Change rotation of child to be different from parent so that we can check if our local coordinate
890 // conversion of the parent actor is correct.
891 Actor child = Actor::New();
892 child.SetSize(100.0f, 100.0f);
893 child.SetAnchorPoint(AnchorPoint::CENTER);
894 child.SetParentOrigin(ParentOrigin::CENTER);
895 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
898 TouchEventFunctor touchFunctor;
899 child.TouchedSignal().Connect(&application, touchFunctor);
902 application.SendNotification();
903 application.Render();
906 GestureReceivedFunctor functor(data);
908 PanGestureDetector detector = PanGestureDetector::New();
909 detector.Attach(parent);
910 detector.DetectedSignal().Connect(&application, functor);
912 // Do an entire pan, only check finished value - hits child area but parent should still receive it
913 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
914 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
916 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
917 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
918 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
919 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
921 // Attach child and generate same touch points to yield a different displacement
922 // (Also proves that you can detach and then re-attach another actor)
923 detector.Attach(child);
924 detector.Detach(parent);
926 // Do an entire pan, only check finished value
927 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
928 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
930 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
931 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
932 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
933 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
937 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
939 TestApplication application;
941 Actor first = Actor::New();
942 first.SetSize(100.0f, 100.0f);
943 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
944 Stage::GetCurrent().Add(first);
946 Actor second = Actor::New();
947 second.SetSize(100.0f, 100.0f);
949 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
950 Stage::GetCurrent().Add(second);
953 application.SendNotification();
954 application.Render();
957 GestureReceivedFunctor functor(data);
959 PanGestureDetector detector = PanGestureDetector::New();
960 detector.Attach(first);
961 detector.Attach(second);
962 detector.DetectedSignal().Connect(&application, functor);
964 // Start pan within second actor's area
965 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
966 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
967 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
968 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
970 // Pan moves into first actor's area - second actor should receive the pan
972 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
973 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
974 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
976 // Detach the second actor during the pan, we should not receive the next event
977 detector.Detach(second);
979 // Gesture ends within actor's area
981 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
982 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
986 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
988 TestApplication application;
990 Actor actor = Actor::New();
991 actor.SetSize(100.0f, 100.0f);
992 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
993 Stage::GetCurrent().Add(actor);
996 application.SendNotification();
997 application.Render();
1000 GestureReceivedFunctor functor(data);
1002 PanGestureDetector detector = PanGestureDetector::New();
1003 detector.Attach(actor);
1004 detector.DetectedSignal().Connect(&application, functor);
1006 // Start pan in actor's area
1007 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1008 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1009 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1011 // Pan continues within actor's area
1013 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1014 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1016 // Actor become invisible - actor should not receive the next pan
1017 actor.SetVisible(false);
1019 // Render and notify
1020 application.SendNotification();
1021 application.Render();
1023 // Gesture ends within actor's area
1025 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1026 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1030 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1032 TestApplication application;
1033 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1035 Actor first = Actor::New();
1036 first.SetSize(100.0f, 100.0f);
1037 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1038 Stage::GetCurrent().Add(first);
1040 Actor second = Actor::New();
1041 second.SetSize(100.0f, 100.0f);
1042 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1045 // Render and notify
1046 application.SendNotification();
1047 application.Render();
1050 GestureReceivedFunctor functor(data);
1052 PanGestureDetector firstDetector = PanGestureDetector::New();
1053 firstDetector.Attach(first);
1054 firstDetector.DetectedSignal().Connect(&application, functor);
1056 // secondDetector is scoped
1058 // Reset gestureManager statistics
1059 gestureManager.Initialize();
1061 PanGestureDetector secondDetector = PanGestureDetector::New();
1062 secondDetector.SetMinimumTouchesRequired(2);
1063 secondDetector.SetMaximumTouchesRequired(2);
1064 secondDetector.Attach(second);
1065 secondDetector.DetectedSignal().Connect(&application, functor);
1067 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1068 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1069 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1071 // Start pan within second actor's area
1072 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1073 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1074 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1075 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1077 // Two touch pan changes to single touch - we should receive a finished state
1079 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1080 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1081 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1082 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1084 // Pan continues as single touch gesture - we should not receive any gesture
1086 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1087 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1089 // Pan ends - still no signal
1091 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1092 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1094 // Single touch pan starts - first actor should be panned
1096 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1097 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1098 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1099 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1101 // Pan changes to double-touch - we should receive a finished state
1103 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1104 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1105 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1106 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1108 // Pan continues as double touch gesture - we should not receive any gesture
1110 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1111 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1113 // Pan ends - still no signal
1115 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1116 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1118 // Reset gesture manager statistics
1119 gestureManager.Initialize();
1122 // secondDetector has now been deleted. Gesture detection should have been updated only
1123 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1124 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1125 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1129 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1131 TestApplication application;
1133 Actor actor = Actor::New();
1134 actor.SetSize(100.0f, 100.0f);
1135 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1136 Stage::GetCurrent().Add(actor);
1138 Actor actor2 = Actor::New();
1139 actor2.SetSize(100.0f, 100.0f);
1140 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1141 Stage::GetCurrent().Add(actor2);
1143 // Render and notify
1144 application.SendNotification();
1145 application.Render();
1147 // Attach actor to one detector
1148 SignalData firstData;
1149 GestureReceivedFunctor firstFunctor(firstData);
1150 PanGestureDetector firstDetector = PanGestureDetector::New();
1151 firstDetector.Attach(actor);
1152 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1154 // Attach actor to another detector
1155 SignalData secondData;
1156 GestureReceivedFunctor secondFunctor(secondData);
1157 PanGestureDetector secondDetector = PanGestureDetector::New();
1158 secondDetector.Attach(actor);
1159 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1161 // Add second actor to second detector, when we remove the actor, this will make sure that this
1162 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1163 // functor should still not be called (which is what we're also testing).
1164 secondDetector.Attach(actor2);
1166 // Pan in actor's area - both detector's functors should be called
1167 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1168 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1169 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1170 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1172 // Pan continues in actor's area - both detector's functors should be called
1175 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1176 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1177 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1179 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1180 firstDetector.Detach(actor);
1183 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1184 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1185 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1187 // New pan on actor, only secondDetector has actor attached
1190 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1191 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1192 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1193 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1195 // Detach actor from secondDetector
1196 secondDetector.Detach(actor);
1199 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1200 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1201 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1205 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1207 // Should handle two started events gracefully.
1209 TestApplication application;
1211 Actor actor = Actor::New();
1212 actor.SetSize(100.0f, 100.0f);
1213 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1214 Stage::GetCurrent().Add(actor);
1217 GestureReceivedFunctor functor(data);
1219 PanGestureDetector detector = PanGestureDetector::New();
1220 detector.Attach(actor);
1221 detector.DetectedSignal().Connect(&application, functor);
1223 // Render and notify
1224 application.SendNotification();
1225 application.Render();
1227 // Start pan in actor's area
1228 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1229 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1230 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1232 // Send another start in actor's area
1234 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1235 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1237 // Add a child actor to overlap actor and send another start in actor's area
1238 Actor child = Actor::New();
1239 child.SetSize(100.0f, 100.0f);
1240 child.SetAnchorPoint(AnchorPoint::CENTER);
1241 child.SetParentOrigin(ParentOrigin::CENTER);
1244 TouchEventFunctor touchFunctor;
1245 child.TouchedSignal().Connect(&application, touchFunctor);
1247 // Render and notify
1248 application.SendNotification();
1249 application.Render();
1251 // Send another possible and start in actor's area
1253 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1254 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1255 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1257 // Send another start in actor's area
1259 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1260 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1261 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1265 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1267 TestApplication application;
1269 Actor actor1 = Actor::New();
1270 actor1.SetSize(100.0f, 100.0f);
1271 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1272 Stage::GetCurrent().Add(actor1);
1274 GestureReceivedFunctor functor1(data1);
1275 PanGestureDetector detector1 = PanGestureDetector::New();
1276 detector1.Attach(actor1);
1277 detector1.DetectedSignal().Connect(&application, functor1);
1279 Actor actor2 = Actor::New();
1280 actor2.SetSize(100.0f, 100.0f);
1281 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1282 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1283 Stage::GetCurrent().Add(actor2);
1285 GestureReceivedFunctor functor2(data2);
1286 PanGestureDetector detector2 = PanGestureDetector::New();
1287 detector2.Attach(actor2);
1288 detector2.DetectedSignal().Connect(&application, functor2);
1290 // Render and notify
1291 application.SendNotification();
1292 application.Render();
1294 // Start pan in actor1's area, only data1 should be set
1295 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1296 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1297 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1298 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1302 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1304 TestApplication application;
1306 Actor actor = Actor::New();
1307 actor.SetSize(100.0f, 100.0f);
1308 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1309 Stage::GetCurrent().Add(actor);
1311 // Render and notify
1312 application.SendNotification();
1313 application.Render();
1315 // Attach actor to detector
1317 GestureReceivedFunctor functor( data );
1318 PanGestureDetector detector = PanGestureDetector::New();
1319 detector.Attach(actor);
1320 detector.DetectedSignal().Connect( &application, functor );
1322 // Gesture possible in actor's area.
1323 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1324 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1326 // Move actor somewhere else
1327 actor.SetPosition( 100.0f, 100.0f );
1329 // Render and notify
1330 application.SendNotification();
1331 application.Render();
1333 // Emit Started event, we should not receive the long press.
1334 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1335 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1336 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1338 // LongPress possible in empty area.
1339 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1340 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1342 // Move actor in to the long press position.
1343 actor.SetPosition( 0.0f, 0.0f );
1345 // Render and notify
1346 application.SendNotification();
1347 application.Render();
1349 // Emit Started event, we should not receive the long press.
1350 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1351 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1352 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1354 // Normal long press in actor's area for completeness.
1355 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1356 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1357 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1358 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1362 int UtcDaliPanGestureEmitIncorrectState(void)
1364 TestApplication application;
1366 Actor actor = Actor::New();
1367 actor.SetSize(100.0f, 100.0f);
1368 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1369 Stage::GetCurrent().Add(actor);
1371 // Render and notify
1372 application.SendNotification();
1373 application.Render();
1375 // Attach actor to detector
1377 GestureReceivedFunctor functor( data );
1378 PanGestureDetector detector = PanGestureDetector::New();
1379 detector.Attach(actor);
1380 detector.DetectedSignal().Connect( &application, functor );
1382 // Try a Clear state
1385 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1386 tet_result(TET_FAIL);
1388 catch ( Dali::DaliException& e )
1390 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1395 int UtcDaliPanGestureActorUnstaged(void)
1397 TestApplication application;
1399 Actor actor = Actor::New();
1400 actor.SetSize(100.0f, 100.0f);
1401 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1402 Stage::GetCurrent().Add(actor);
1404 // Render and notify
1405 application.SendNotification();
1406 application.Render();
1408 // State to remove actor in.
1409 Gesture::State stateToUnstage( Gesture::Started );
1411 // Attach actor to detector
1413 UnstageActorFunctor functor( data, stateToUnstage );
1414 PanGestureDetector detector = PanGestureDetector::New();
1415 detector.Attach(actor);
1416 detector.DetectedSignal().Connect( &application, functor );
1419 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1420 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1421 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1423 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1424 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1427 // Render and notify
1428 application.SendNotification();
1429 application.Render();
1431 // Re-add actor to stage
1432 Stage::GetCurrent().Add(actor);
1434 // Render and notify
1435 application.SendNotification();
1436 application.Render();
1438 // Change state to Gesture::Continuing to remove
1439 stateToUnstage = Gesture::Continuing;
1442 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1443 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1444 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1446 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1447 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1449 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1450 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1453 // Render and notify
1454 application.SendNotification();
1455 application.Render();
1457 // Re-add actor to stage
1458 Stage::GetCurrent().Add(actor);
1460 // Render and notify
1461 application.SendNotification();
1462 application.Render();
1464 // Change state to Gesture::Finished to remove
1465 stateToUnstage = Gesture::Finished;
1468 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1469 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1470 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1472 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1473 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1475 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1476 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1477 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1481 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1483 TestApplication application;
1485 Actor actor = Actor::New();
1486 actor.SetSize(100.0f, 100.0f);
1487 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1488 Stage::GetCurrent().Add(actor);
1490 // Create and add a second actor so that GestureDetector destruction does not come into play.
1491 Actor dummyActor( Actor::New() );
1492 dummyActor.SetSize( 100.0f, 100.0f );
1493 dummyActor.SetPosition( 100.0f, 100.0f );
1494 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1495 Stage::GetCurrent().Add(dummyActor);
1497 // Render and notify
1498 application.SendNotification();
1499 application.Render();
1501 // State to remove actor in.
1502 Gesture::State stateToUnstage( Gesture::Started );
1504 // Attach actor to detector
1506 UnstageActorFunctor functor( data, stateToUnstage );
1507 PanGestureDetector detector = PanGestureDetector::New();
1508 detector.Attach(actor);
1509 detector.Attach(dummyActor);
1510 detector.DetectedSignal().Connect( &application, functor );
1512 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1513 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1514 // position, we should still not be signalled.
1517 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1518 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1519 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1522 // Render and notify
1523 application.SendNotification();
1524 application.Render();
1526 // Re add to the stage, we should not be signalled
1527 Stage::GetCurrent().Add(actor);
1529 // Render and notify
1530 application.SendNotification();
1531 application.Render();
1533 // Continue signal emission
1534 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1535 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1537 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1538 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1541 // Here we delete an actor in started, we should not receive any subsequent signalling.
1544 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1545 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1546 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1549 // Render and notify
1550 application.SendNotification();
1551 application.Render();
1553 // Delete actor as well
1556 // Render and notify
1557 application.SendNotification();
1558 application.Render();
1560 // Continue signal emission
1561 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1562 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1564 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1565 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1569 int UtcDaliPanGestureSystemOverlay(void)
1571 TestApplication application;
1572 Dali::Integration::Core& core = application.GetCore();
1573 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1574 systemOverlay.GetOverlayRenderTasks().CreateTask();
1576 Actor actor = Actor::New();
1577 actor.SetSize(100.0f, 100.0f);
1578 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1579 systemOverlay.Add(actor);
1581 // Render and notify
1582 application.SendNotification();
1583 application.Render();
1586 GestureReceivedFunctor functor(data);
1588 PanGestureDetector detector = PanGestureDetector::New();
1589 detector.Attach(actor);
1590 detector.DetectedSignal().Connect(&application, functor);
1592 Vector2 screenCoordsStart( 10.0f, 20.0f );
1593 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1595 // Start pan within the actor's area
1596 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1597 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1598 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1602 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1604 TestApplication application;
1605 Dali::Integration::Core& core = application.GetCore();
1606 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1607 systemOverlay.GetOverlayRenderTasks().CreateTask();
1609 // SystemOverlay actor
1610 Actor systemOverlayActor = Actor::New();
1611 systemOverlayActor.SetSize(100.0f, 100.0f);
1612 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1613 systemOverlay.Add(systemOverlayActor);
1616 Actor stageActor = Actor::New();
1617 stageActor.SetSize(100.0f, 100.0f);
1618 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1619 Stage::GetCurrent().Add(stageActor);
1621 // Render and notify
1622 application.SendNotification();
1623 application.Render();
1625 // Set system-overlay actor to touchable
1626 TouchEventData touchData;
1627 TouchEventDataFunctor touchFunctor( touchData );
1628 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1630 // Set stage actor to receive the gesture
1632 GestureReceivedFunctor functor(data);
1634 PanGestureDetector detector = PanGestureDetector::New();
1635 detector.Attach(stageActor);
1636 detector.DetectedSignal().Connect(&application, functor);
1638 Vector2 screenCoordsStart( 10.0f, 20.0f );
1639 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1641 // Start pan within the two actors' area
1642 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1643 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1644 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1645 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1646 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1651 // Do touch in the same area
1652 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1653 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1654 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1659 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1661 TestApplication application;
1662 Dali::Integration::Core& core = application.GetCore();
1663 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1664 systemOverlay.GetOverlayRenderTasks().CreateTask();
1666 // SystemOverlay actor
1667 Actor systemOverlayActor = Actor::New();
1668 systemOverlayActor.SetSize(100.0f, 100.0f);
1669 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1670 systemOverlay.Add(systemOverlayActor);
1673 Actor stageActor = Actor::New();
1674 stageActor.SetSize(100.0f, 100.0f);
1675 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1676 Stage::GetCurrent().Add(stageActor);
1678 // Render and notify
1679 application.SendNotification();
1680 application.Render();
1682 // Set stage actor to touchable
1683 TouchEventData touchData;
1684 TouchEventDataFunctor touchFunctor( touchData );
1685 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1687 // Set system-overlay actor to have the gesture
1689 GestureReceivedFunctor functor(data);
1691 PanGestureDetector detector = PanGestureDetector::New();
1692 detector.Attach(systemOverlayActor);
1693 detector.DetectedSignal().Connect(&application, functor);
1695 Vector2 screenCoordsStart( 10.0f, 20.0f );
1696 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1698 // Start pan within the two actors' area
1699 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1700 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1701 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1702 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1703 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1708 // Do touch in the same area
1709 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1710 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1711 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1716 int UtcDaliPanGestureAngleHandling(void)
1718 TestApplication application;
1720 PanGestureDetector detector = PanGestureDetector::New();
1721 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1722 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1724 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1725 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1726 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1728 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1730 tet_result( TET_PASS );
1734 if ( iter == endIter )
1736 tet_printf("%s, angle not added\n", TEST_LOCATION );
1737 tet_result( TET_FAIL );
1741 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1742 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1744 // Remove something not in the container.
1745 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1746 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1748 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1749 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1750 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1752 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1754 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1755 tet_result( TET_FAIL );
1760 detector.ClearAngles();
1761 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1765 inline float RadiansToDegrees( float radian )
1767 return radian * 180.0f / Math::PI;
1770 int UtcDaliPanGestureAngleOutOfRange(void)
1772 TestApplication application;
1774 PanGestureDetector detector = PanGestureDetector::New();
1775 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1776 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1782 detector.AddAngle( Degree(180.0f) );
1783 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1784 detector.ClearAngles();
1786 detector.AddAngle( Degree(190.0f) );
1787 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1788 detector.ClearAngles();
1790 detector.AddAngle( Degree(-190.0f) );
1791 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1792 detector.ClearAngles();
1794 detector.AddAngle( Degree(350.0f) );
1795 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1796 detector.ClearAngles();
1798 detector.AddAngle( Degree(-350.0f) );
1799 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1800 detector.ClearAngles();
1802 detector.AddAngle( Degree(370.0f) );
1803 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1804 detector.ClearAngles();
1806 detector.AddAngle( Degree(-370.0f) );
1807 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1808 detector.ClearAngles();
1814 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1815 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1816 detector.ClearAngles();
1818 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1819 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1820 detector.ClearAngles();
1822 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1823 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1824 detector.ClearAngles();
1826 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1827 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1828 detector.ClearAngles();
1832 int UtcDaliPanGestureAngleProcessing(void)
1834 TestApplication application;
1836 Actor parent = Actor::New();
1837 parent.SetSize(100.0f, 100.0f);
1838 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1839 Stage::GetCurrent().Add(parent);
1841 Actor child = Actor::New();
1842 child.SetSize(100.0f, 100.0f);
1843 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1846 // Render and notify
1847 application.SendNotification();
1848 application.Render();
1850 // Parent detector only requires up pans
1851 PanGestureDetector parentDetector = PanGestureDetector::New();
1852 parentDetector.Attach( parent );
1853 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1854 SignalData parentData;
1855 GestureReceivedFunctor parentFunctor(parentData);
1856 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1858 // Child detector only requires right pans
1859 PanGestureDetector childDetector = PanGestureDetector::New();
1860 childDetector.Attach( child );
1861 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1862 SignalData childData;
1863 GestureReceivedFunctor childFunctor(childData);
1864 childDetector.DetectedSignal().Connect(&application, childFunctor);
1866 // Generate an Up pan gesture, only parent should receive it.
1867 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1868 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1869 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1870 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1871 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1875 // Generate a Right pan gesture, only child should receive it.
1876 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1877 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1878 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1879 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1880 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1884 // Generate a Down pan gesture, no one should receive it.
1885 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1886 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1887 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1888 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1889 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1893 // Generate a Left pan gesture, no one should receive it.
1894 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1895 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1896 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1897 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1898 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1904 int UtcDaliPanGestureDirectionHandling(void)
1906 TestApplication application;
1908 PanGestureDetector detector = PanGestureDetector::New();
1909 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1910 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1912 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1913 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1914 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1916 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1918 tet_result( TET_PASS );
1922 if ( iter == endIter )
1924 tet_printf("%s, angle not added\n", TEST_LOCATION );
1925 tet_result( TET_FAIL );
1929 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1931 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1933 tet_result( TET_PASS );
1937 if ( iter == endIter )
1939 tet_printf("%s, angle not added\n", TEST_LOCATION );
1940 tet_result( TET_FAIL );
1944 // Remove something not in the container.
1945 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1946 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1948 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1949 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1953 int UtcDaliPanGestureDirectionProcessing(void)
1955 TestApplication application;
1957 Actor parent = Actor::New();
1958 parent.SetSize(100.0f, 100.0f);
1959 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1960 Stage::GetCurrent().Add(parent);
1962 Actor child = Actor::New();
1963 child.SetSize(100.0f, 100.0f);
1964 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1967 // Render and notify
1968 application.SendNotification();
1969 application.Render();
1971 // Parent detector only requires vertical panning
1972 PanGestureDetector parentDetector = PanGestureDetector::New();
1973 parentDetector.Attach( parent );
1974 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1975 SignalData parentData;
1976 GestureReceivedFunctor parentFunctor(parentData);
1977 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1979 // Child detector only requires horizontal panning
1980 PanGestureDetector childDetector = PanGestureDetector::New();
1981 childDetector.Attach( child );
1982 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1983 SignalData childData;
1984 GestureReceivedFunctor childFunctor(childData);
1985 childDetector.DetectedSignal().Connect(&application, childFunctor);
1987 // Generate an Up pan gesture, only parent should receive it.
1988 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1989 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1990 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1991 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1992 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1996 // Generate a Right pan gesture, only child should receive it.
1997 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1998 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1999 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2000 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2001 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2005 // Generate a Down pan gesture, only parent should receive it.
2006 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2007 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2008 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2009 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2010 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2014 // Generate a Left pan gesture, only child should receive it.
2015 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2016 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2017 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2018 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2019 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2023 // Generate a pan at -45 degrees, no one should receive it.
2024 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2025 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2026 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2027 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2028 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2032 // Generate a pan at 45 degrees, no one should receive it.
2033 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2034 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2035 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2036 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2037 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2041 // Generate a pan at 135 degrees, no one should receive it.
2042 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2043 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2044 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2045 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2046 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2050 // Generate a pan at -135 degrees, no one should receive it.
2051 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2052 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2053 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2054 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2055 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2061 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2063 TestApplication application;
2064 Integration::SetPanGesturePredictionMode(0);
2065 Integration::SetPanGestureSmoothingMode(0);
2067 Actor actor = Actor::New();
2068 actor.SetSize(100.0f, 100.0f);
2069 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2070 Stage::GetCurrent().Add(actor);
2072 // Add a pan detector
2073 PanGestureDetector detector = PanGestureDetector::New();
2074 detector.Attach( actor );
2076 GestureReceivedFunctor functor( data );
2077 detector.DetectedSignal().Connect( &application, functor );
2079 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2081 ConstraintData constraintData;
2082 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2083 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2084 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2085 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2086 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2087 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2088 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2091 // Render and notify
2092 application.SendNotification();
2093 application.Render();
2095 Vector2 direction(Vector2::XAXIS * -5.0f);
2096 Vector2 startPosition( 1.0f, 1.0f );
2097 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2098 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2099 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2100 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2101 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2103 constraintData.Reset();
2107 int UtcDaliPanGestureNoPredictionSmoothing(void)
2109 TestApplication application;
2110 Integration::SetPanGesturePredictionMode(0);
2111 Integration::SetPanGestureSmoothingMode(1);
2113 Actor actor = Actor::New();
2114 actor.SetSize(100.0f, 100.0f);
2115 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2116 Stage::GetCurrent().Add(actor);
2118 // Add a pan detector
2119 PanGestureDetector detector = PanGestureDetector::New();
2120 detector.Attach( actor );
2122 GestureReceivedFunctor functor( data );
2123 detector.DetectedSignal().Connect( &application, functor );
2125 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2127 ConstraintData constraintData;
2128 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2129 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2130 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2131 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2132 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2133 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2134 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2137 // Render and notify
2138 application.SendNotification();
2139 application.Render();
2141 Vector2 direction(Vector2::XAXIS * -5.0f);
2142 Vector2 previousPosition( 20.0f, 20.0f );
2143 Vector2 currentPosition( 20.0f, 10.0f );
2144 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2145 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2146 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2147 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2148 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2150 constraintData.Reset();
2154 int UtcDaliPanGesturePredictionNoSmoothing(void)
2156 TestApplication application;
2157 Integration::SetPanGesturePredictionMode(1);
2158 Integration::SetPanGestureSmoothingMode(0);
2160 Actor actor = Actor::New();
2161 actor.SetSize(100.0f, 100.0f);
2162 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2163 Stage::GetCurrent().Add(actor);
2165 // Add a pan detector
2166 PanGestureDetector detector = PanGestureDetector::New();
2167 detector.Attach( actor );
2169 GestureReceivedFunctor functor( data );
2170 detector.DetectedSignal().Connect( &application, functor );
2172 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2174 ConstraintData constraintData;
2175 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2176 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2177 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2178 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2179 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2180 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2181 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2184 // Render and notify
2185 application.SendNotification();
2186 application.Render();
2188 Vector2 direction(Vector2::XAXIS * -1.0f);
2189 Vector2 previousPosition( 20.0f, 20.0f );
2190 Vector2 currentPosition( 20.0f, 10.0f );
2191 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2192 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2193 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2194 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2195 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2197 constraintData.Reset();
2201 int UtcDaliPanGesturePredictionSmoothing(void)
2203 TestApplication application;
2204 Integration::SetPanGesturePredictionMode(1);
2205 Integration::SetPanGestureSmoothingMode(1);
2207 Actor actor = Actor::New();
2208 actor.SetSize(100.0f, 100.0f);
2209 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2210 Stage::GetCurrent().Add(actor);
2212 // Add a pan detector
2213 PanGestureDetector detector = PanGestureDetector::New();
2214 detector.Attach( actor );
2216 GestureReceivedFunctor functor( data );
2217 detector.DetectedSignal().Connect( &application, functor );
2219 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2221 ConstraintData constraintData;
2222 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2223 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2224 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2225 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2226 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2227 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2228 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2231 // Render and notify
2232 application.SendNotification();
2233 application.Render();
2235 Vector2 direction(Vector2::XAXIS * -1.0f);
2236 Vector2 previousPosition( 20.0f, 20.0f );
2237 Vector2 currentPosition( 20.0f, 10.0f );
2238 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2239 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2240 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2241 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2242 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2244 constraintData.Reset();
2248 int UtcDaliPanGestureSetProperties(void)
2250 TestApplication application;
2251 TestRenderController& renderController( application.GetRenderController() );
2252 Integration::SetPanGesturePredictionMode(0);
2253 Integration::SetPanGestureSmoothingMode(0);
2255 Actor actor = Actor::New();
2256 actor.SetSize(100.0f, 100.0f);
2257 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2258 Stage::GetCurrent().Add(actor);
2260 // Add a pan detector
2261 PanGestureDetector detector = PanGestureDetector::New();
2262 detector.Attach( actor );
2264 GestureReceivedFunctor functor( data );
2265 detector.DetectedSignal().Connect( &application, functor );
2267 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2269 ConstraintData constraintData;
2270 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2271 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2272 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2273 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2274 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2275 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2276 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2279 // Render and notify
2280 application.SendNotification();
2281 application.Render();
2283 renderController.Initialize();
2284 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2286 Vector2 screenPosition( 20.0f, 20.0f );
2287 Vector2 screenDisplacement( 1.0f, 1.0f );
2288 Vector2 screenVelocity( 1.3f, 4.0f );
2289 Vector2 localPosition( 21.0f, 21.0f );
2290 Vector2 localDisplacement( 0.5f, 0.5f );
2291 Vector2 localVelocity( 1.5f, 2.5f );
2293 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2294 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2296 // Render and notify
2297 application.SendNotification();
2298 application.Render();
2300 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2301 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2302 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2303 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2304 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2305 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2306 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2307 constraintData.Reset();
2311 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2313 TestApplication application;
2314 Integration::SetPanGesturePredictionMode(0);
2316 Actor actor = Actor::New();
2317 actor.SetSize(100.0f, 100.0f);
2318 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2319 Stage::GetCurrent().Add(actor);
2321 // Add a pan detector
2322 PanGestureDetector detector = PanGestureDetector::New();
2323 detector.Attach( actor );
2325 GestureReceivedFunctor functor( data );
2326 detector.DetectedSignal().Connect( &application, functor );
2328 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2330 ConstraintData constraintData;
2331 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2332 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2333 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2334 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2335 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2336 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2337 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2340 // Render and notify
2341 application.SendNotification();
2342 application.Render();
2344 Vector2 previousPosition( 20.0f, 20.0f );
2345 Vector2 currentPosition( 20.0f, 10.0f );
2346 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2347 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2348 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2350 Vector2 screenPosition( 100.0f, 20.0f );
2351 Vector2 localPosition( 110.0f, 110.0f );
2353 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2355 // Render and notify
2356 application.SendNotification();
2357 application.Render();
2359 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2360 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2361 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2362 constraintData.Reset();
2366 int UtcDaliPanGesturePropertyIndices(void)
2368 TestApplication application;
2369 PanGestureDetector detector = PanGestureDetector::New();
2371 Property::IndexContainer indices;
2372 detector.GetPropertyIndices( indices );
2373 DALI_TEST_CHECK( ! indices.empty() );
2374 DALI_TEST_EQUALS( indices.size(), detector.GetPropertyCount(), TEST_LOCATION );
2378 int UtcDaliPanGestureLayerConsumesTouch(void)
2380 TestApplication application;
2382 Actor actor = Actor::New();
2383 actor.SetSize(100.0f, 100.0f);
2384 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2385 Stage::GetCurrent().Add(actor);
2387 // Add a pan detector
2388 PanGestureDetector detector = PanGestureDetector::New();
2389 detector.Attach( actor );
2391 GestureReceivedFunctor functor( data );
2392 detector.DetectedSignal().Connect( &application, functor );
2394 // Add a layer to overlap the actor
2395 Layer layer = Layer::New();
2396 layer.SetSize(100.0f, 100.0f);
2397 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2398 Stage::GetCurrent().Add( layer );
2401 // Render and notify
2402 application.SendNotification();
2403 application.Render();
2405 // Emit signals, should receive
2406 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2407 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2408 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2409 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2412 // Set layer to consume all touch
2413 layer.SetTouchConsumed( true );
2415 // Render and notify
2416 application.SendNotification();
2417 application.Render();
2419 // Emit the same signals again, should not receive
2420 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2421 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2422 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2423 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2429 int UtcDaliPanGestureNoTimeDiff(void)
2431 TestApplication application;
2433 Actor actor = Actor::New();
2434 actor.SetSize(100.0f, 100.0f);
2435 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2436 Stage::GetCurrent().Add(actor);
2438 // Add a pan detector
2439 PanGestureDetector detector = PanGestureDetector::New();
2440 detector.Attach( actor );
2442 GestureReceivedFunctor functor( data );
2443 detector.DetectedSignal().Connect( &application, functor );
2445 // Render and notify
2446 application.SendNotification();
2447 application.Render();
2449 // Emit signals, should receive
2450 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2451 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2452 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2453 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2454 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2455 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2456 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2457 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );