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, 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, 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 Vector3 operator()(const Vector3& current,
161 const PropertyInput& screenPositionProperty,
162 const PropertyInput& screenDisplacementProperty,
163 const PropertyInput& screenVelocityProperty,
164 const PropertyInput& localPositionProperty,
165 const PropertyInput& localDisplacementProperty,
166 const PropertyInput& localVelocityProperty)
168 constraintData.screenPosition = screenPositionProperty.GetVector2();
169 constraintData.screenDisplacement = screenDisplacementProperty.GetVector2();
170 constraintData.screenVelocity = screenVelocityProperty.GetVector2();
171 constraintData.localPosition = localPositionProperty.GetVector2();
172 constraintData.localDisplacement = localDisplacementProperty.GetVector2();
173 constraintData.localVelocity = localVelocityProperty.GetVector2();
174 constraintData.called = true;
175 return Vector3::ZERO;
178 ConstraintData& constraintData;
181 // Generate a PanGestureEvent to send to Core
182 Integration::PanGestureEvent GeneratePan(
183 Gesture::State state,
184 Vector2 previousPosition,
185 Vector2 currentPosition,
186 unsigned long timeDelta,
187 unsigned int numberOfTouches = 1,
188 unsigned int time = 1u)
190 Integration::PanGestureEvent pan(state);
192 pan.previousPosition = previousPosition;
193 pan.currentPosition = currentPosition;
194 pan.timeDelta = timeDelta;
195 pan.numberOfTouches = numberOfTouches;
201 // Generate a PanGesture
202 PanGesture GeneratePan( unsigned int time,
203 Gesture::State state,
204 Vector2 screenPosition,
205 Vector2 localPosition,
206 Vector2 screenDisplacement = Vector2::ONE,
207 Vector2 localDisplacement = Vector2::ONE,
208 Vector2 screenVelocity = Vector2::ONE,
209 Vector2 localVelocity = Vector2::ONE,
210 unsigned int numberOfTouches = 1 )
212 PanGesture pan( state );
216 pan.screenPosition = screenPosition;
217 pan.position = localPosition;
219 pan.screenDisplacement = screenDisplacement;
220 pan.displacement = localDisplacement;
222 pan.screenVelocity = screenVelocity;
223 pan.velocity = localVelocity;
225 pan.numberOfTouches = numberOfTouches;
231 * Helper to generate PanGestureEvent
233 * @param[in] application Application instance
234 * @param[in] state The Gesture State
235 * @param[in] pos The current position of touch.
237 static void SendPan(TestApplication& application, Gesture::State state, const Vector2& pos)
240 static int LastTime = 0;
242 if( (state == Gesture::Started) ||
243 (state == Gesture::Possible) )
249 application.ProcessEvent(GeneratePan(state, last, pos, PAN_EVENT_TIME_DELTA));
253 LastTime += PAN_EVENT_TIME_DELTA;
256 static Vector2 PerformSwipeGestureSwipe(TestApplication& application, Vector2 start, Vector2 direction, int frames, bool finish = true)
258 // Now do a pan starting from (start) and heading (direction)
260 SendPan(application, Gesture::Possible, pos);
261 SendPan(application, Gesture::Started, pos);
262 application.SendNotification();
263 application.Render();
265 for(int i = 0;i<frames;i++)
267 pos += direction; // Move in this direction
268 SendPan(application, Gesture::Continuing, pos);
269 application.SendNotification();
270 application.Render();
275 SendPan(application, Gesture::Finished, pos);
276 application.SendNotification();
277 application.Render();
285 ///////////////////////////////////////////////////////////////////////////////
287 // Positive test case for a method
288 int UtcDaliPanGestureDetectorConstructor(void)
290 TestApplication application;
292 PanGestureDetector detector;
293 DALI_TEST_CHECK(!detector);
298 // Negative test case for a method
299 int UtcDaliPanGestureDetectorNew(void)
301 TestApplication application;
303 PanGestureDetector detector = PanGestureDetector::New();
305 DALI_TEST_CHECK(detector);
307 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
308 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
310 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
311 Actor actor = Actor::New();
312 actor.SetSize(100.0f, 100.0f);
313 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
314 detector.Attach(actor);
316 Stage::GetCurrent().Add(actor);
319 application.SendNotification();
320 application.Render();
322 Integration::TouchEvent touchEvent(1);
323 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
324 touchEvent.AddPoint(point);
325 application.ProcessEvent(touchEvent);
329 int UtcDaliPanGestureDetectorDownCast(void)
331 TestApplication application;
332 tet_infoline("Testing Dali::GestureDetector::DownCast()");
334 PanGestureDetector detector = PanGestureDetector::New();
336 BaseHandle object(detector);
338 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
339 DALI_TEST_CHECK(detector2);
341 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
342 DALI_TEST_CHECK(detector3);
344 BaseHandle unInitializedObject;
345 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
346 DALI_TEST_CHECK(!detector4);
348 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
349 DALI_TEST_CHECK(!detector5);
351 GestureDetector detector6 = PanGestureDetector::New();
352 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
353 DALI_TEST_CHECK(detector7);
357 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
359 TestApplication application;
361 PanGestureDetector detector = PanGestureDetector::New();
363 unsigned int min = 2;
365 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
367 detector.SetMinimumTouchesRequired(min);
369 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
371 // Attach an actor and change the minimum touches
373 Actor actor = Actor::New();
374 actor.SetSize(100.0f, 100.0f);
375 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
376 Stage::GetCurrent().Add(actor);
379 application.SendNotification();
380 application.Render();
383 GestureReceivedFunctor functor(data);
385 detector.Attach(actor);
386 detector.DetectedSignal().Connect(&application, functor);
388 TestGestureManager& gestureManager = application.GetGestureManager();
389 gestureManager.Initialize();
391 detector.SetMinimumTouchesRequired(3);
393 // Gesture detection should have been updated only
394 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
395 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
396 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
399 gestureManager.Initialize();
401 // Create a second gesture detector that requires even less minimum touches
402 PanGestureDetector secondDetector = PanGestureDetector::New();
403 secondDetector.Attach(actor);
405 // Gesture detection should have been updated only
406 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
407 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
408 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
412 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
414 TestApplication application;
416 PanGestureDetector detector = PanGestureDetector::New();
418 unsigned int max = 3;
420 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
422 detector.SetMaximumTouchesRequired(max);
424 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
426 // Attach an actor and change the maximum touches
428 Actor actor = Actor::New();
429 actor.SetSize(100.0f, 100.0f);
430 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
431 Stage::GetCurrent().Add(actor);
434 application.SendNotification();
435 application.Render();
438 GestureReceivedFunctor functor(data);
440 detector.Attach(actor);
441 detector.DetectedSignal().Connect(&application, functor);
443 TestGestureManager& gestureManager = application.GetGestureManager();
444 gestureManager.Initialize();
446 detector.SetMaximumTouchesRequired(4);
448 // Gesture detection should have been updated only
449 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
450 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
451 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
454 gestureManager.Initialize();
456 // Create a second gesture detector that requires even less maximum touches
457 PanGestureDetector secondDetector = PanGestureDetector::New();
458 secondDetector.Attach(actor);
460 // Gesture detection should NOT have been updated
461 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
462 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
463 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
467 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
469 TestApplication application;
471 PanGestureDetector detector = PanGestureDetector::New();
472 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
476 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
478 TestApplication application;
480 PanGestureDetector detector = PanGestureDetector::New();
481 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
485 int UtcDaliPanGestureSignalReceptionNegative(void)
487 TestApplication application;
489 Actor actor = Actor::New();
490 actor.SetSize(100.0f, 100.0f);
491 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
492 Stage::GetCurrent().Add(actor);
495 application.SendNotification();
496 application.Render();
499 GestureReceivedFunctor functor(data);
501 PanGestureDetector detector = PanGestureDetector::New();
502 detector.Attach(actor);
503 detector.DetectedSignal().Connect(&application, functor);
505 // Do a pan outside actor's area
506 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
507 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
508 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
510 // Continue pan into actor's area - we should still not receive the signal
512 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
513 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
515 // Stop panning - we should still not receive the signal
517 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
518 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
522 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
524 TestApplication application;
526 Actor actor = Actor::New();
527 actor.SetSize(100.0f, 100.0f);
528 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
529 Stage::GetCurrent().Add(actor);
532 application.SendNotification();
533 application.Render();
536 GestureReceivedFunctor functor(data);
538 PanGestureDetector detector = PanGestureDetector::New();
539 detector.Attach(actor);
540 detector.DetectedSignal().Connect(&application, functor);
542 // Start pan within the actor's area
543 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
544 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
545 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
546 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
547 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
548 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
549 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
550 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
551 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
553 // Continue the pan within the actor's area - we should still receive the signal
555 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
556 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
557 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
558 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
559 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
561 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
562 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
564 // Pan Gesture leaves actor's area - we should still receive the signal
566 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
567 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
569 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
570 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
571 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
572 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
573 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
575 // Gesture ends - we would receive a finished state
577 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
578 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
579 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
580 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
581 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
582 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
583 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
584 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
588 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
590 TestApplication application;
592 Actor actor = Actor::New();
593 actor.SetSize(100.0f, 100.0f);
594 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
595 Stage::GetCurrent().Add(actor);
598 application.SendNotification();
599 application.Render();
602 GestureReceivedFunctor functor(data);
604 PanGestureDetector detector = PanGestureDetector::New();
605 detector.Attach(actor);
606 detector.DetectedSignal().Connect(&application, functor);
608 // Start pan within the actor's area
609 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
610 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
611 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
612 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
613 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
614 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
615 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
616 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
617 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
619 // Continue the pan within the actor's area - we should still receive the signal
621 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
622 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
623 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
624 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
625 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
626 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
627 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
628 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
630 // Gesture ends within actor's area - we would receive a finished state
632 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
633 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
634 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
635 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
636 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
637 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
638 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
639 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
643 int UtcDaliPanGestureSignalReceptionCancelled(void)
645 TestApplication application;
647 Actor actor = Actor::New();
648 actor.SetSize(100.0f, 100.0f);
649 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
650 Stage::GetCurrent().Add(actor);
653 application.SendNotification();
654 application.Render();
657 GestureReceivedFunctor functor(data);
659 PanGestureDetector detector = PanGestureDetector::New();
660 detector.Attach(actor);
661 detector.DetectedSignal().Connect(&application, functor);
663 // Start pan within the actor's area
664 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
665 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
666 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
667 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
669 // Continue the pan within the actor's area - we should still receive the signal
671 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
672 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
673 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
675 // The gesture is cancelled
677 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
678 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
679 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
683 int UtcDaliPanGestureSignalReceptionDetach(void)
685 TestApplication application;
687 Actor actor = Actor::New();
688 actor.SetSize(100.0f, 100.0f);
689 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
690 Stage::GetCurrent().Add(actor);
693 application.SendNotification();
694 application.Render();
697 GestureReceivedFunctor functor(data);
699 PanGestureDetector detector = PanGestureDetector::New();
700 detector.Attach(actor);
701 detector.DetectedSignal().Connect(&application, functor);
703 // Start pan within the actor's area
704 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
705 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
706 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
708 // Continue the pan within the actor's area - we should still receive the signal
710 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
711 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
713 // Gesture ends within actor's area
715 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
716 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
719 detector.DetachAll();
721 // Ensure we are no longer signalled
723 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
724 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
725 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
726 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
727 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
731 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
733 TestApplication application;
735 Actor actor = Actor::New();
736 actor.SetSize(100.0f, 100.0f);
737 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
738 Stage::GetCurrent().Add(actor);
741 application.SendNotification();
742 application.Render();
745 GestureReceivedFunctor functor(data);
747 PanGestureDetector detector = PanGestureDetector::New();
748 detector.Attach(actor);
749 detector.DetectedSignal().Connect(&application, functor);
751 // Start pan within the actor's area
752 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
753 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
754 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
756 // Continue the pan within the actor's area - we should still receive the signal
758 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
759 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
761 // Detach actor during the pan, we should not receive the next event
762 detector.DetachAll();
764 // Gesture ends within actor's area
766 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
767 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
771 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
773 TestApplication application;
776 GestureReceivedFunctor functor(data);
778 PanGestureDetector detector = PanGestureDetector::New();
779 detector.DetectedSignal().Connect(&application, functor);
781 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
783 Actor tempActor = Actor::New();
784 tempActor.SetSize(100.0f, 100.0f);
785 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
786 Stage::GetCurrent().Add(tempActor);
787 detector.Attach(tempActor);
789 // Actor lifetime is scoped
791 Actor actor = Actor::New();
792 actor.SetSize(100.0f, 100.0f);
793 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
794 Stage::GetCurrent().Add(actor);
797 application.SendNotification();
798 application.Render();
800 detector.Attach(actor);
802 // Start pan within the actor's area
803 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
804 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
805 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
807 // Continue the pan within the actor's area - we should still receive the signal
809 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
810 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
812 // Remove the actor from stage and reset the data
813 Stage::GetCurrent().Remove(actor);
816 application.SendNotification();
817 application.Render();
820 // Actor should now have been destroyed
822 // Gesture ends within the area where the actor used to be
824 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
825 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
829 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
831 TestApplication application;
833 Actor actor = Actor::New();
834 actor.SetSize(100.0f, 100.0f);
835 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
836 Stage::GetCurrent().Add(actor);
839 application.SendNotification();
840 application.Render();
843 GestureReceivedFunctor functor(data);
845 PanGestureDetector detector = PanGestureDetector::New();
846 detector.Attach(actor);
847 detector.DetectedSignal().Connect(&application, functor);
849 // Do an entire pan, only check finished value
850 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
851 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
853 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
854 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
855 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
857 // Rotate actor again and render a couple of times
858 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
859 application.SendNotification();
860 application.Render();
862 // Do an entire pan, only check finished value
863 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
864 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
866 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
867 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
868 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
870 // Rotate actor again and render a couple of times
871 actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
872 application.SendNotification();
873 application.Render();
875 // Do an entire pan, only check finished value
876 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
877 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
879 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
880 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
881 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
885 int UtcDaliPanGestureSignalReceptionChildHit(void)
887 TestApplication application;
889 Actor parent = Actor::New();
890 parent.SetSize(100.0f, 100.0f);
891 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
892 Stage::GetCurrent().Add(parent);
894 // Set child to completely cover parent.
895 // Change rotation of child to be different from parent so that we can check if our local coordinate
896 // conversion of the parent actor is correct.
897 Actor child = Actor::New();
898 child.SetSize(100.0f, 100.0f);
899 child.SetAnchorPoint(AnchorPoint::CENTER);
900 child.SetParentOrigin(ParentOrigin::CENTER);
901 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
904 TouchEventFunctor touchFunctor;
905 child.TouchedSignal().Connect(&application, touchFunctor);
908 application.SendNotification();
909 application.Render();
912 GestureReceivedFunctor functor(data);
914 PanGestureDetector detector = PanGestureDetector::New();
915 detector.Attach(parent);
916 detector.DetectedSignal().Connect(&application, functor);
918 // Do an entire pan, only check finished value - hits child area but parent should still receive it
919 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
920 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
922 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
923 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
924 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
925 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
927 // Attach child and generate same touch points to yield a different displacement
928 // (Also proves that you can detach and then re-attach another actor)
929 detector.Attach(child);
930 detector.Detach(parent);
932 // Do an entire pan, only check finished value
933 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
934 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
936 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
937 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
938 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
939 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
943 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
945 TestApplication application;
947 Actor first = Actor::New();
948 first.SetSize(100.0f, 100.0f);
949 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
950 Stage::GetCurrent().Add(first);
952 Actor second = Actor::New();
953 second.SetSize(100.0f, 100.0f);
955 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
956 Stage::GetCurrent().Add(second);
959 application.SendNotification();
960 application.Render();
963 GestureReceivedFunctor functor(data);
965 PanGestureDetector detector = PanGestureDetector::New();
966 detector.Attach(first);
967 detector.Attach(second);
968 detector.DetectedSignal().Connect(&application, functor);
970 // Start pan within second actor's area
971 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
972 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
973 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
974 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
976 // Pan moves into first actor's area - second actor should receive the pan
978 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
979 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
980 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
982 // Detach the second actor during the pan, we should not receive the next event
983 detector.Detach(second);
985 // Gesture ends within actor's area
987 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
988 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
992 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
994 TestApplication application;
996 Actor actor = Actor::New();
997 actor.SetSize(100.0f, 100.0f);
998 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
999 Stage::GetCurrent().Add(actor);
1001 // Render and notify
1002 application.SendNotification();
1003 application.Render();
1006 GestureReceivedFunctor functor(data);
1008 PanGestureDetector detector = PanGestureDetector::New();
1009 detector.Attach(actor);
1010 detector.DetectedSignal().Connect(&application, functor);
1012 // Start pan in actor's area
1013 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1014 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1015 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1017 // Pan continues within actor's area
1019 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1020 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1022 // Actor become invisible - actor should not receive the next pan
1023 actor.SetVisible(false);
1025 // Render and notify
1026 application.SendNotification();
1027 application.Render();
1029 // Gesture ends within actor's area
1031 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1032 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1036 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1038 TestApplication application;
1039 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1041 Actor first = Actor::New();
1042 first.SetSize(100.0f, 100.0f);
1043 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1044 Stage::GetCurrent().Add(first);
1046 Actor second = Actor::New();
1047 second.SetSize(100.0f, 100.0f);
1048 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1051 // Render and notify
1052 application.SendNotification();
1053 application.Render();
1056 GestureReceivedFunctor functor(data);
1058 PanGestureDetector firstDetector = PanGestureDetector::New();
1059 firstDetector.Attach(first);
1060 firstDetector.DetectedSignal().Connect(&application, functor);
1062 // secondDetector is scoped
1064 // Reset gestureManager statistics
1065 gestureManager.Initialize();
1067 PanGestureDetector secondDetector = PanGestureDetector::New();
1068 secondDetector.SetMinimumTouchesRequired(2);
1069 secondDetector.SetMaximumTouchesRequired(2);
1070 secondDetector.Attach(second);
1071 secondDetector.DetectedSignal().Connect(&application, functor);
1073 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1074 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1075 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1077 // Start pan within second actor's area
1078 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1079 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1080 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1081 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1083 // Two touch pan changes to single touch - we should receive a finished state
1085 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1086 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1087 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1088 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1090 // Pan continues as single touch gesture - we should not receive any gesture
1092 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1093 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1095 // Pan ends - still no signal
1097 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1098 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1100 // Single touch pan starts - first actor should be panned
1102 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1103 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1104 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1105 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1107 // Pan changes to double-touch - we should receive a finished state
1109 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1110 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1111 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1112 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1114 // Pan continues as double touch gesture - we should not receive any gesture
1116 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1117 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1119 // Pan ends - still no signal
1121 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1122 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1124 // Reset gesture manager statistics
1125 gestureManager.Initialize();
1128 // secondDetector has now been deleted. Gesture detection should have been updated only
1129 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1130 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1131 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1135 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1137 TestApplication application;
1139 Actor actor = Actor::New();
1140 actor.SetSize(100.0f, 100.0f);
1141 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1142 Stage::GetCurrent().Add(actor);
1144 Actor actor2 = Actor::New();
1145 actor2.SetSize(100.0f, 100.0f);
1146 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1147 Stage::GetCurrent().Add(actor2);
1149 // Render and notify
1150 application.SendNotification();
1151 application.Render();
1153 // Attach actor to one detector
1154 SignalData firstData;
1155 GestureReceivedFunctor firstFunctor(firstData);
1156 PanGestureDetector firstDetector = PanGestureDetector::New();
1157 firstDetector.Attach(actor);
1158 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1160 // Attach actor to another detector
1161 SignalData secondData;
1162 GestureReceivedFunctor secondFunctor(secondData);
1163 PanGestureDetector secondDetector = PanGestureDetector::New();
1164 secondDetector.Attach(actor);
1165 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1167 // Add second actor to second detector, when we remove the actor, this will make sure that this
1168 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1169 // functor should still not be called (which is what we're also testing).
1170 secondDetector.Attach(actor2);
1172 // Pan in actor's area - both detector's functors should be called
1173 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1174 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1175 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1176 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1178 // Pan continues in actor's area - both detector's functors should be called
1181 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1182 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1183 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1185 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1186 firstDetector.Detach(actor);
1189 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1190 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1191 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1193 // New pan on actor, only secondDetector has actor attached
1196 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1197 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1198 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1199 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1201 // Detach actor from secondDetector
1202 secondDetector.Detach(actor);
1205 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1206 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1207 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1211 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1213 // Should handle two started events gracefully.
1215 TestApplication application;
1217 Actor actor = Actor::New();
1218 actor.SetSize(100.0f, 100.0f);
1219 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1220 Stage::GetCurrent().Add(actor);
1223 GestureReceivedFunctor functor(data);
1225 PanGestureDetector detector = PanGestureDetector::New();
1226 detector.Attach(actor);
1227 detector.DetectedSignal().Connect(&application, functor);
1229 // Render and notify
1230 application.SendNotification();
1231 application.Render();
1233 // Start pan in actor's area
1234 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1235 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1236 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1238 // Send another start in actor's area
1240 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1241 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1243 // Add a child actor to overlap actor and send another start in actor's area
1244 Actor child = Actor::New();
1245 child.SetSize(100.0f, 100.0f);
1246 child.SetAnchorPoint(AnchorPoint::CENTER);
1247 child.SetParentOrigin(ParentOrigin::CENTER);
1250 TouchEventFunctor touchFunctor;
1251 child.TouchedSignal().Connect(&application, touchFunctor);
1253 // Render and notify
1254 application.SendNotification();
1255 application.Render();
1257 // Send another possible and 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);
1263 // Send another start in actor's area
1265 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1266 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1267 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1271 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1273 TestApplication application;
1275 Actor actor1 = Actor::New();
1276 actor1.SetSize(100.0f, 100.0f);
1277 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1278 Stage::GetCurrent().Add(actor1);
1280 GestureReceivedFunctor functor1(data1);
1281 PanGestureDetector detector1 = PanGestureDetector::New();
1282 detector1.Attach(actor1);
1283 detector1.DetectedSignal().Connect(&application, functor1);
1285 Actor actor2 = Actor::New();
1286 actor2.SetSize(100.0f, 100.0f);
1287 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1288 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1289 Stage::GetCurrent().Add(actor2);
1291 GestureReceivedFunctor functor2(data2);
1292 PanGestureDetector detector2 = PanGestureDetector::New();
1293 detector2.Attach(actor2);
1294 detector2.DetectedSignal().Connect(&application, functor2);
1296 // Render and notify
1297 application.SendNotification();
1298 application.Render();
1300 // Start pan in actor1's area, only data1 should be set
1301 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1302 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1303 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1304 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1308 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1310 TestApplication application;
1312 Actor actor = Actor::New();
1313 actor.SetSize(100.0f, 100.0f);
1314 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1315 Stage::GetCurrent().Add(actor);
1317 // Render and notify
1318 application.SendNotification();
1319 application.Render();
1321 // Attach actor to detector
1323 GestureReceivedFunctor functor( data );
1324 PanGestureDetector detector = PanGestureDetector::New();
1325 detector.Attach(actor);
1326 detector.DetectedSignal().Connect( &application, functor );
1328 // Gesture possible in actor's area.
1329 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1330 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1332 // Move actor somewhere else
1333 actor.SetPosition( 100.0f, 100.0f );
1335 // Render and notify
1336 application.SendNotification();
1337 application.Render();
1339 // Emit Started event, we should not receive the long press.
1340 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1341 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1342 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1344 // LongPress possible in empty area.
1345 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1346 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1348 // Move actor in to the long press position.
1349 actor.SetPosition( 0.0f, 0.0f );
1351 // Render and notify
1352 application.SendNotification();
1353 application.Render();
1355 // Emit Started event, we should not receive the long press.
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(false, data.functorCalled, TEST_LOCATION);
1360 // Normal long press in actor's area for completeness.
1361 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1362 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1363 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1364 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1368 int UtcDaliPanGestureEmitIncorrectState(void)
1370 TestApplication application;
1372 Actor actor = Actor::New();
1373 actor.SetSize(100.0f, 100.0f);
1374 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1375 Stage::GetCurrent().Add(actor);
1377 // Render and notify
1378 application.SendNotification();
1379 application.Render();
1381 // Attach actor to detector
1383 GestureReceivedFunctor functor( data );
1384 PanGestureDetector detector = PanGestureDetector::New();
1385 detector.Attach(actor);
1386 detector.DetectedSignal().Connect( &application, functor );
1388 // Try a Clear state
1391 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1392 tet_result(TET_FAIL);
1394 catch ( Dali::DaliException& e )
1396 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1401 int UtcDaliPanGestureActorUnstaged(void)
1403 TestApplication application;
1405 Actor actor = Actor::New();
1406 actor.SetSize(100.0f, 100.0f);
1407 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1408 Stage::GetCurrent().Add(actor);
1410 // Render and notify
1411 application.SendNotification();
1412 application.Render();
1414 // State to remove actor in.
1415 Gesture::State stateToUnstage( Gesture::Started );
1417 // Attach actor to detector
1419 UnstageActorFunctor functor( data, stateToUnstage );
1420 PanGestureDetector detector = PanGestureDetector::New();
1421 detector.Attach(actor);
1422 detector.DetectedSignal().Connect( &application, functor );
1425 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1426 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1427 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1429 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1430 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1433 // Render and notify
1434 application.SendNotification();
1435 application.Render();
1437 // Re-add actor to stage
1438 Stage::GetCurrent().Add(actor);
1440 // Render and notify
1441 application.SendNotification();
1442 application.Render();
1444 // Change state to Gesture::Continuing to remove
1445 stateToUnstage = Gesture::Continuing;
1448 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1449 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1450 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1452 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1453 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1455 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1456 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1459 // Render and notify
1460 application.SendNotification();
1461 application.Render();
1463 // Re-add actor to stage
1464 Stage::GetCurrent().Add(actor);
1466 // Render and notify
1467 application.SendNotification();
1468 application.Render();
1470 // Change state to Gesture::Finished to remove
1471 stateToUnstage = Gesture::Finished;
1474 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1475 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1476 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1478 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1479 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1481 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1482 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1483 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1487 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1489 TestApplication application;
1491 Actor actor = Actor::New();
1492 actor.SetSize(100.0f, 100.0f);
1493 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1494 Stage::GetCurrent().Add(actor);
1496 // Create and add a second actor so that GestureDetector destruction does not come into play.
1497 Actor dummyActor( Actor::New() );
1498 dummyActor.SetSize( 100.0f, 100.0f );
1499 dummyActor.SetPosition( 100.0f, 100.0f );
1500 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1501 Stage::GetCurrent().Add(dummyActor);
1503 // Render and notify
1504 application.SendNotification();
1505 application.Render();
1507 // State to remove actor in.
1508 Gesture::State stateToUnstage( Gesture::Started );
1510 // Attach actor to detector
1512 UnstageActorFunctor functor( data, stateToUnstage );
1513 PanGestureDetector detector = PanGestureDetector::New();
1514 detector.Attach(actor);
1515 detector.Attach(dummyActor);
1516 detector.DetectedSignal().Connect( &application, functor );
1518 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1519 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1520 // position, we should still not be signalled.
1523 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1524 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1525 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1528 // Render and notify
1529 application.SendNotification();
1530 application.Render();
1532 // Re add to the stage, we should not be signalled
1533 Stage::GetCurrent().Add(actor);
1535 // Render and notify
1536 application.SendNotification();
1537 application.Render();
1539 // Continue signal emission
1540 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1541 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1543 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1544 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1547 // Here we delete an actor in started, we should not receive any subsequent signalling.
1550 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1551 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1552 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1555 // Render and notify
1556 application.SendNotification();
1557 application.Render();
1559 // Delete actor as well
1562 // Render and notify
1563 application.SendNotification();
1564 application.Render();
1566 // Continue signal emission
1567 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1568 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1570 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1571 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1575 int UtcDaliPanGestureSystemOverlay(void)
1577 TestApplication application;
1578 Dali::Integration::Core& core = application.GetCore();
1579 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1580 systemOverlay.GetOverlayRenderTasks().CreateTask();
1582 Actor actor = Actor::New();
1583 actor.SetSize(100.0f, 100.0f);
1584 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1585 systemOverlay.Add(actor);
1587 // Render and notify
1588 application.SendNotification();
1589 application.Render();
1592 GestureReceivedFunctor functor(data);
1594 PanGestureDetector detector = PanGestureDetector::New();
1595 detector.Attach(actor);
1596 detector.DetectedSignal().Connect(&application, functor);
1598 Vector2 screenCoordsStart( 10.0f, 20.0f );
1599 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1601 // Start pan within the actor's area
1602 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1603 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1604 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1608 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1610 TestApplication application;
1611 Dali::Integration::Core& core = application.GetCore();
1612 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1613 systemOverlay.GetOverlayRenderTasks().CreateTask();
1615 // SystemOverlay actor
1616 Actor systemOverlayActor = Actor::New();
1617 systemOverlayActor.SetSize(100.0f, 100.0f);
1618 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1619 systemOverlay.Add(systemOverlayActor);
1622 Actor stageActor = Actor::New();
1623 stageActor.SetSize(100.0f, 100.0f);
1624 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1625 Stage::GetCurrent().Add(stageActor);
1627 // Render and notify
1628 application.SendNotification();
1629 application.Render();
1631 // Set system-overlay actor to touchable
1632 TouchEventData touchData;
1633 TouchEventDataFunctor touchFunctor( touchData );
1634 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1636 // Set stage actor to receive the gesture
1638 GestureReceivedFunctor functor(data);
1640 PanGestureDetector detector = PanGestureDetector::New();
1641 detector.Attach(stageActor);
1642 detector.DetectedSignal().Connect(&application, functor);
1644 Vector2 screenCoordsStart( 10.0f, 20.0f );
1645 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1647 // Start pan within the two actors' area
1648 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1649 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1650 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1651 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1652 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1657 // Do touch in the same area
1658 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1659 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1660 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1665 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1667 TestApplication application;
1668 Dali::Integration::Core& core = application.GetCore();
1669 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1670 systemOverlay.GetOverlayRenderTasks().CreateTask();
1672 // SystemOverlay actor
1673 Actor systemOverlayActor = Actor::New();
1674 systemOverlayActor.SetSize(100.0f, 100.0f);
1675 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1676 systemOverlay.Add(systemOverlayActor);
1679 Actor stageActor = Actor::New();
1680 stageActor.SetSize(100.0f, 100.0f);
1681 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1682 Stage::GetCurrent().Add(stageActor);
1684 // Render and notify
1685 application.SendNotification();
1686 application.Render();
1688 // Set stage actor to touchable
1689 TouchEventData touchData;
1690 TouchEventDataFunctor touchFunctor( touchData );
1691 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1693 // Set system-overlay actor to have the gesture
1695 GestureReceivedFunctor functor(data);
1697 PanGestureDetector detector = PanGestureDetector::New();
1698 detector.Attach(systemOverlayActor);
1699 detector.DetectedSignal().Connect(&application, functor);
1701 Vector2 screenCoordsStart( 10.0f, 20.0f );
1702 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1704 // Start pan within the two actors' area
1705 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1706 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1707 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1708 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1709 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1714 // Do touch in the same area
1715 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoordsStart ) );
1716 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1717 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1722 int UtcDaliPanGestureAngleHandling(void)
1724 TestApplication application;
1726 PanGestureDetector detector = PanGestureDetector::New();
1727 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1728 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1730 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1731 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1732 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1734 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1736 tet_result( TET_PASS );
1740 if ( iter == endIter )
1742 tet_printf("%s, angle not added\n", TEST_LOCATION );
1743 tet_result( TET_FAIL );
1747 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1748 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1750 // Remove something not in the container.
1751 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1752 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1754 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1755 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(1), TEST_LOCATION );
1756 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1758 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1760 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1761 tet_result( TET_FAIL );
1766 detector.ClearAngles();
1767 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1771 inline float RadiansToDegrees( float radian )
1773 return radian * 180.0f / Math::PI;
1776 int UtcDaliPanGestureAngleOutOfRange(void)
1778 TestApplication application;
1780 PanGestureDetector detector = PanGestureDetector::New();
1781 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1782 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1788 detector.AddAngle( Degree(180.0f) );
1789 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1790 detector.ClearAngles();
1792 detector.AddAngle( Degree(190.0f) );
1793 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1794 detector.ClearAngles();
1796 detector.AddAngle( Degree(-190.0f) );
1797 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1798 detector.ClearAngles();
1800 detector.AddAngle( Degree(350.0f) );
1801 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1802 detector.ClearAngles();
1804 detector.AddAngle( Degree(-350.0f) );
1805 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1806 detector.ClearAngles();
1808 detector.AddAngle( Degree(370.0f) );
1809 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1810 detector.ClearAngles();
1812 detector.AddAngle( Degree(-370.0f) );
1813 DALI_TEST_EQUALS( angles.begin()->first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1814 detector.ClearAngles();
1820 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1821 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1822 detector.ClearAngles();
1824 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1825 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1826 detector.ClearAngles();
1828 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1829 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1830 detector.ClearAngles();
1832 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1833 DALI_TEST_EQUALS( angles.begin()->second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1834 detector.ClearAngles();
1838 int UtcDaliPanGestureAngleProcessing(void)
1840 TestApplication application;
1842 Actor parent = Actor::New();
1843 parent.SetSize(100.0f, 100.0f);
1844 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1845 Stage::GetCurrent().Add(parent);
1847 Actor child = Actor::New();
1848 child.SetSize(100.0f, 100.0f);
1849 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1852 // Render and notify
1853 application.SendNotification();
1854 application.Render();
1856 // Parent detector only requires up pans
1857 PanGestureDetector parentDetector = PanGestureDetector::New();
1858 parentDetector.Attach( parent );
1859 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1860 SignalData parentData;
1861 GestureReceivedFunctor parentFunctor(parentData);
1862 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1864 // Child detector only requires right pans
1865 PanGestureDetector childDetector = PanGestureDetector::New();
1866 childDetector.Attach( child );
1867 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1868 SignalData childData;
1869 GestureReceivedFunctor childFunctor(childData);
1870 childDetector.DetectedSignal().Connect(&application, childFunctor);
1872 // Generate an Up pan gesture, only parent should receive it.
1873 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1874 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1875 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1876 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1877 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1881 // Generate a Right pan gesture, only child should receive it.
1882 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1883 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1884 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1885 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1886 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1890 // Generate a Down pan gesture, no one should receive it.
1891 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1892 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1893 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1894 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1895 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1899 // Generate a Left pan gesture, no one should receive it.
1900 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1901 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1902 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1903 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1904 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1910 int UtcDaliPanGestureDirectionHandling(void)
1912 TestApplication application;
1914 PanGestureDetector detector = PanGestureDetector::New();
1915 const PanGestureDetector::AngleContainer& angles( detector.GetAngles() );
1916 DALI_TEST_EQUALS( angles.empty(), true, TEST_LOCATION );
1918 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1919 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1920 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1922 if ( iter->first == PanGestureDetector::DIRECTION_LEFT )
1924 tet_result( TET_PASS );
1928 if ( iter == endIter )
1930 tet_printf("%s, angle not added\n", TEST_LOCATION );
1931 tet_result( TET_FAIL );
1935 for ( PanGestureDetector::AngleContainer::const_iterator iter = angles.begin(), endIter = angles.end(); iter != endIter; ++iter )
1937 if ( iter->first == PanGestureDetector::DIRECTION_RIGHT )
1939 tet_result( TET_PASS );
1943 if ( iter == endIter )
1945 tet_printf("%s, angle not added\n", TEST_LOCATION );
1946 tet_result( TET_FAIL );
1950 // Remove something not in the container.
1951 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1952 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(2), TEST_LOCATION );
1954 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1955 DALI_TEST_EQUALS( angles.size(), static_cast<AngleSizeType>(0), TEST_LOCATION );
1959 int UtcDaliPanGestureDirectionProcessing(void)
1961 TestApplication application;
1963 Actor parent = Actor::New();
1964 parent.SetSize(100.0f, 100.0f);
1965 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1966 Stage::GetCurrent().Add(parent);
1968 Actor child = Actor::New();
1969 child.SetSize(100.0f, 100.0f);
1970 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1973 // Render and notify
1974 application.SendNotification();
1975 application.Render();
1977 // Parent detector only requires vertical panning
1978 PanGestureDetector parentDetector = PanGestureDetector::New();
1979 parentDetector.Attach( parent );
1980 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1981 SignalData parentData;
1982 GestureReceivedFunctor parentFunctor(parentData);
1983 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1985 // Child detector only requires horizontal panning
1986 PanGestureDetector childDetector = PanGestureDetector::New();
1987 childDetector.Attach( child );
1988 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1989 SignalData childData;
1990 GestureReceivedFunctor childFunctor(childData);
1991 childDetector.DetectedSignal().Connect(&application, childFunctor);
1993 // Generate an Up pan gesture, only parent should receive it.
1994 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1995 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1996 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1997 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1998 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2002 // Generate a Right pan gesture, only child should receive it.
2003 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2004 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2005 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2006 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2007 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2011 // Generate a Down pan gesture, only parent should receive it.
2012 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2013 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2014 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2015 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2016 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2020 // Generate a Left pan gesture, only child should receive it.
2021 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2022 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2023 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2024 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2025 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2029 // Generate a pan at -45 degrees, no one should receive it.
2030 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2031 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2032 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2033 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2034 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2038 // Generate a pan at 45 degrees, no one should receive it.
2039 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2040 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2041 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2042 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2043 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2047 // Generate a pan at 135 degrees, no one should receive it.
2048 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2049 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2050 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2051 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2052 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2056 // Generate a pan at -135 degrees, no one should receive it.
2057 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2058 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2059 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2060 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2061 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2067 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2069 TestApplication application;
2070 Integration::SetPanGesturePredictionMode(0);
2071 Integration::SetPanGestureSmoothingMode(0);
2073 Actor actor = Actor::New();
2074 actor.SetSize(100.0f, 100.0f);
2075 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2076 Stage::GetCurrent().Add(actor);
2078 // Add a pan detector
2079 PanGestureDetector detector = PanGestureDetector::New();
2080 detector.Attach( actor );
2082 GestureReceivedFunctor functor( data );
2083 detector.DetectedSignal().Connect( &application, functor );
2085 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2087 ConstraintData constraintData;
2088 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2089 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2090 Source( detector, PanGestureDetector::SCREEN_VELOCITY ),
2091 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2092 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2093 Source( detector, PanGestureDetector::LOCAL_VELOCITY ),
2094 PanConstraint( constraintData ) ) );
2096 // Render and notify
2097 application.SendNotification();
2098 application.Render();
2100 Vector2 direction(Vector2::XAXIS * -5.0f);
2101 Vector2 startPosition( 1.0f, 1.0f );
2102 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, true);
2103 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2104 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2105 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2106 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2108 constraintData.Reset();
2112 int UtcDaliPanGestureNoPredictionSmoothing(void)
2114 TestApplication application;
2115 Integration::SetPanGesturePredictionMode(0);
2116 Integration::SetPanGestureSmoothingMode(1);
2118 Actor actor = Actor::New();
2119 actor.SetSize(100.0f, 100.0f);
2120 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2121 Stage::GetCurrent().Add(actor);
2123 // Add a pan detector
2124 PanGestureDetector detector = PanGestureDetector::New();
2125 detector.Attach( actor );
2127 GestureReceivedFunctor functor( data );
2128 detector.DetectedSignal().Connect( &application, functor );
2130 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2132 ConstraintData constraintData;
2133 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2134 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2135 Source( detector, PanGestureDetector::SCREEN_VELOCITY ),
2136 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2137 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2138 Source( detector, PanGestureDetector::LOCAL_VELOCITY ),
2139 PanConstraint( constraintData ) ) );
2141 // Render and notify
2142 application.SendNotification();
2143 application.Render();
2145 Vector2 direction(Vector2::XAXIS * -5.0f);
2146 Vector2 previousPosition( 20.0f, 20.0f );
2147 Vector2 currentPosition( 20.0f, 10.0f );
2148 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2149 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2150 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2151 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2152 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2154 constraintData.Reset();
2158 int UtcDaliPanGesturePredictionNoSmoothing(void)
2160 TestApplication application;
2161 Integration::SetPanGesturePredictionMode(1);
2162 Integration::SetPanGestureSmoothingMode(0);
2164 Actor actor = Actor::New();
2165 actor.SetSize(100.0f, 100.0f);
2166 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2167 Stage::GetCurrent().Add(actor);
2169 // Add a pan detector
2170 PanGestureDetector detector = PanGestureDetector::New();
2171 detector.Attach( actor );
2173 GestureReceivedFunctor functor( data );
2174 detector.DetectedSignal().Connect( &application, functor );
2176 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2178 ConstraintData constraintData;
2179 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2180 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2181 Source( detector, PanGestureDetector::SCREEN_VELOCITY ),
2182 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2183 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2184 Source( detector, PanGestureDetector::LOCAL_VELOCITY ),
2185 PanConstraint( constraintData ) ) );
2187 // Render and notify
2188 application.SendNotification();
2189 application.Render();
2191 Vector2 direction(Vector2::XAXIS * -5.0f);
2192 Vector2 previousPosition( 20.0f, 20.0f );
2193 Vector2 currentPosition( 20.0f, 10.0f );
2194 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2195 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2196 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2197 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2198 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2200 constraintData.Reset();
2204 int UtcDaliPanGesturePredictionSmoothing(void)
2206 TestApplication application;
2207 Integration::SetPanGesturePredictionMode(1);
2208 Integration::SetPanGestureSmoothingMode(1);
2210 Actor actor = Actor::New();
2211 actor.SetSize(100.0f, 100.0f);
2212 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2213 Stage::GetCurrent().Add(actor);
2215 // Add a pan detector
2216 PanGestureDetector detector = PanGestureDetector::New();
2217 detector.Attach( actor );
2219 GestureReceivedFunctor functor( data );
2220 detector.DetectedSignal().Connect( &application, functor );
2222 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2224 ConstraintData constraintData;
2225 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2226 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2227 Source( detector, PanGestureDetector::SCREEN_VELOCITY ),
2228 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2229 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2230 Source( detector, PanGestureDetector::LOCAL_VELOCITY ),
2231 PanConstraint( constraintData ) ) );
2233 // Render and notify
2234 application.SendNotification();
2235 application.Render();
2237 Vector2 direction(Vector2::XAXIS * -5.0f);
2238 Vector2 previousPosition( 20.0f, 20.0f );
2239 Vector2 currentPosition( 20.0f, 10.0f );
2240 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, true);
2241 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2242 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2243 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2244 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2246 constraintData.Reset();
2250 int UtcDaliPanGestureSetProperties(void)
2252 TestApplication application;
2253 TestRenderController& renderController( application.GetRenderController() );
2254 Integration::SetPanGesturePredictionMode(0);
2255 Integration::SetPanGestureSmoothingMode(0);
2257 Actor actor = Actor::New();
2258 actor.SetSize(100.0f, 100.0f);
2259 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2260 Stage::GetCurrent().Add(actor);
2262 // Add a pan detector
2263 PanGestureDetector detector = PanGestureDetector::New();
2264 detector.Attach( actor );
2266 GestureReceivedFunctor functor( data );
2267 detector.DetectedSignal().Connect( &application, functor );
2269 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2271 ConstraintData constraintData;
2272 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2273 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2274 Source( detector, PanGestureDetector::SCREEN_VELOCITY ),
2275 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2276 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2277 Source( detector, PanGestureDetector::LOCAL_VELOCITY ),
2278 PanConstraint( constraintData ) ) );
2280 // Render and notify
2281 application.SendNotification();
2282 application.Render();
2284 renderController.Initialize();
2285 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2287 Vector2 screenPosition( 20.0f, 20.0f );
2288 Vector2 screenDisplacement( 1.0f, 1.0f );
2289 Vector2 screenVelocity( 1.3f, 4.0f );
2290 Vector2 localPosition( 21.0f, 21.0f );
2291 Vector2 localDisplacement( 0.5f, 0.5f );
2292 Vector2 localVelocity( 1.5f, 2.5f );
2294 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2295 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2297 // Render and notify
2298 application.SendNotification();
2299 application.Render();
2301 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2302 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2303 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2304 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2305 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2306 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2307 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2308 constraintData.Reset();
2312 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2314 TestApplication application;
2315 Integration::SetPanGesturePredictionMode(0);
2317 Actor actor = Actor::New();
2318 actor.SetSize(100.0f, 100.0f);
2319 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2320 Stage::GetCurrent().Add(actor);
2322 // Add a pan detector
2323 PanGestureDetector detector = PanGestureDetector::New();
2324 detector.Attach( actor );
2326 GestureReceivedFunctor functor( data );
2327 detector.DetectedSignal().Connect( &application, functor );
2329 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2331 ConstraintData constraintData;
2332 actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
2333 Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
2334 Source( detector, PanGestureDetector::SCREEN_VELOCITY ),
2335 Source( detector, PanGestureDetector::LOCAL_POSITION ),
2336 Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
2337 Source( detector, PanGestureDetector::LOCAL_VELOCITY ),
2338 PanConstraint( constraintData ) ) );
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 ) );