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/render-task-list-integ.h>
27 #include <dali/integration-api/profiling.h>
28 #include <dali/integration-api/input-options.h>
29 #include <dali-test-suite-utils.h>
30 #include <test-touch-utils.h>
34 void utc_dali_pan_gesture_detector_startup(void)
36 test_return_value = TET_UNDEF;
39 void utc_dali_pan_gesture_detector_cleanup(void)
41 test_return_value = TET_PASS;
44 ///////////////////////////////////////////////////////////////////////////////
47 const int PAN_EVENT_TIME_DELTA = 8;
48 const int PAN_GESTURE_UPDATE_COUNT = 50;
50 // Stores data that is populated in the callback and will be read by the test cases
54 : functorCalled(false),
55 voidFunctorCalled(false),
56 receivedGesture(Gesture::Clear)
61 functorCalled = false;
62 voidFunctorCalled = false;
64 receivedGesture.state = Gesture::Clear;
65 receivedGesture.velocity = Vector2(0.0f, 0.0f);
66 receivedGesture.displacement = Vector2(0.0f, 0.0f);
67 receivedGesture.position = Vector2(0.0f, 0.0f);
68 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
69 receivedGesture.numberOfTouches = 0;
75 bool voidFunctorCalled;
76 PanGesture receivedGesture;
80 // Functor that sets the data when called
81 struct GestureReceivedFunctor
83 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
85 void operator()(Actor actor, const PanGesture& pan)
87 signalData.functorCalled = true;
88 signalData.receivedGesture = pan;
89 signalData.pannedActor = actor;
94 signalData.voidFunctorCalled = true;
97 SignalData& signalData;
100 // Functor that removes the gestured actor from stage
101 struct UnstageActorFunctor : public GestureReceivedFunctor
103 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
104 : GestureReceivedFunctor( data ),
105 stateToUnstage( stateToUnstage )
109 void operator()( Actor actor, const PanGesture& pan )
111 GestureReceivedFunctor::operator()( actor, pan );
113 if ( pan.state == stateToUnstage )
115 Stage::GetCurrent().Remove( actor );
119 Gesture::State& stateToUnstage;
122 // Functor for receiving a touch event
123 struct TouchEventFunctor
125 bool operator()(Actor actor, const TouchEvent& touch)
131 // Data for constraints
132 struct ConstraintData
140 Vector2 screenPosition;
141 Vector2 screenDisplacement;
142 Vector2 screenVelocity;
143 Vector2 localPosition;
144 Vector2 localDisplacement;
145 Vector2 localVelocity;
151 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
157 // Constraint used with panning properties
160 PanConstraint( ConstraintData& data ) : constraintData(data) { }
162 void operator()( Vector3& current, const PropertyInputContainer& inputs )
164 constraintData.screenPosition = inputs[0]->GetVector2();
165 constraintData.screenDisplacement = inputs[1]->GetVector2();
166 constraintData.screenVelocity = inputs[2]->GetVector2();
167 constraintData.localPosition = inputs[3]->GetVector2();
168 constraintData.localDisplacement = inputs[4]->GetVector2();
169 constraintData.localVelocity = inputs[5]->GetVector2();
170 constraintData.panning = inputs[6]->GetBoolean();
171 constraintData.called = true;
172 current = Vector3::ZERO;
175 ConstraintData& constraintData;
178 // Generate a PanGestureEvent to send to Core
179 Integration::PanGestureEvent GeneratePan(
180 Gesture::State state,
181 Vector2 previousPosition,
182 Vector2 currentPosition,
183 unsigned long timeDelta,
184 unsigned int numberOfTouches = 1,
185 unsigned int time = 1u)
187 Integration::PanGestureEvent pan(state);
189 pan.previousPosition = previousPosition;
190 pan.currentPosition = currentPosition;
191 pan.timeDelta = timeDelta;
192 pan.numberOfTouches = numberOfTouches;
198 // Generate a PanGesture
199 PanGesture GeneratePan( unsigned int time,
200 Gesture::State state,
201 Vector2 screenPosition,
202 Vector2 localPosition,
203 Vector2 screenDisplacement = Vector2::ONE,
204 Vector2 localDisplacement = Vector2::ONE,
205 Vector2 screenVelocity = Vector2::ONE,
206 Vector2 localVelocity = Vector2::ONE,
207 unsigned int numberOfTouches = 1 )
209 PanGesture pan( state );
213 pan.screenPosition = screenPosition;
214 pan.position = localPosition;
216 pan.screenDisplacement = screenDisplacement;
217 pan.displacement = localDisplacement;
219 pan.screenVelocity = screenVelocity;
220 pan.velocity = localVelocity;
222 pan.numberOfTouches = numberOfTouches;
228 * Helper to generate PanGestureEvent
230 * @param[in] application Application instance
231 * @param[in] state The Gesture State
232 * @param[in] pos The current position of touch.
234 static void SendPan(TestApplication& application, Gesture::State state, const Vector2& pos)
237 static int LastTime = 0;
239 if( (state == Gesture::Started) ||
240 (state == Gesture::Possible) )
246 application.ProcessEvent(GeneratePan(state, last, pos, PAN_EVENT_TIME_DELTA));
250 LastTime += PAN_EVENT_TIME_DELTA;
253 static Vector2 PerformSwipeGestureSwipe(TestApplication& application, Vector2 startPosition, Vector2 direction, int frames, int eventsPerFrame,
254 bool start, bool finish, unsigned int renderInterval = TestApplication::DEFAULT_RENDER_INTERVAL)
256 // Now do a pan starting from (start) and heading (direction)
257 Vector2 pos(startPosition);
261 SendPan(application, Gesture::Possible, pos);
262 SendPan(application, Gesture::Started, pos);
263 application.SendNotification();
264 application.Render(renderInterval);
267 for(int i = 0;i<frames;i++)
269 for( int j = 0; j < eventsPerFrame; j++ )
271 pos += direction; // Move in this direction
272 SendPan(application, Gesture::Continuing, pos);
274 application.SendNotification();
275 application.Render(renderInterval);
280 SendPan(application, Gesture::Finished, pos);
281 application.SendNotification();
282 application.Render(renderInterval);
290 ///////////////////////////////////////////////////////////////////////////////
292 // Positive test case for a method
293 int UtcDaliPanGestureDetectorConstructor(void)
295 TestApplication application;
297 PanGestureDetector detector;
298 DALI_TEST_CHECK(!detector);
302 int UtcDaliPanGestureDetectorCopyConstructorP(void)
304 TestApplication application;
306 PanGestureDetector detector = PanGestureDetector::New();
308 PanGestureDetector copy( detector );
309 DALI_TEST_CHECK( detector );
313 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
315 TestApplication application;
317 PanGestureDetector detector = PanGestureDetector::New();
319 PanGestureDetector assign;
321 DALI_TEST_CHECK( detector );
323 DALI_TEST_CHECK( detector == assign );
327 // Negative test case for a method
328 int UtcDaliPanGestureDetectorNew(void)
330 TestApplication application;
332 PanGestureDetector detector = PanGestureDetector::New();
334 DALI_TEST_CHECK(detector);
336 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
337 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
339 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
340 Actor actor = Actor::New();
341 actor.SetSize(100.0f, 100.0f);
342 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
343 detector.Attach(actor);
345 Stage::GetCurrent().Add(actor);
348 application.SendNotification();
349 application.Render();
351 Integration::TouchEvent touchEvent(1);
352 Integration::Point point;
353 point.SetDeviceId( 1 );
354 point.SetState( PointState::DOWN );
355 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
356 touchEvent.AddPoint(point);
357 application.ProcessEvent(touchEvent);
361 int UtcDaliPanGestureDetectorDownCast(void)
363 TestApplication application;
364 tet_infoline("Testing Dali::GestureDetector::DownCast()");
366 PanGestureDetector detector = PanGestureDetector::New();
368 BaseHandle object(detector);
370 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
371 DALI_TEST_CHECK(detector2);
373 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
374 DALI_TEST_CHECK(detector3);
376 BaseHandle unInitializedObject;
377 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
378 DALI_TEST_CHECK(!detector4);
380 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
381 DALI_TEST_CHECK(!detector5);
383 GestureDetector detector6 = PanGestureDetector::New();
384 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
385 DALI_TEST_CHECK(detector7);
389 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
391 TestApplication application;
393 PanGestureDetector detector = PanGestureDetector::New();
395 unsigned int min = 2;
397 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
399 detector.SetMinimumTouchesRequired(min);
401 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
403 // Attach an actor and change the minimum touches
405 Actor actor = Actor::New();
406 actor.SetSize(100.0f, 100.0f);
407 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
408 Stage::GetCurrent().Add(actor);
411 application.SendNotification();
412 application.Render();
415 GestureReceivedFunctor functor(data);
417 detector.Attach(actor);
418 detector.DetectedSignal().Connect(&application, functor);
420 TestGestureManager& gestureManager = application.GetGestureManager();
421 gestureManager.Initialize();
423 detector.SetMinimumTouchesRequired(3);
425 // Gesture detection should have been updated only
426 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
427 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
428 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
431 gestureManager.Initialize();
433 // Create a second gesture detector that requires even less minimum touches
434 PanGestureDetector secondDetector = PanGestureDetector::New();
435 secondDetector.Attach(actor);
437 // Gesture detection should have been updated only
438 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
439 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
440 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
444 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
446 TestApplication application;
448 PanGestureDetector detector = PanGestureDetector::New();
450 unsigned int max = 3;
452 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
454 detector.SetMaximumTouchesRequired(max);
456 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
458 // Attach an actor and change the maximum touches
460 Actor actor = Actor::New();
461 actor.SetSize(100.0f, 100.0f);
462 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
463 Stage::GetCurrent().Add(actor);
466 application.SendNotification();
467 application.Render();
470 GestureReceivedFunctor functor(data);
472 detector.Attach(actor);
473 detector.DetectedSignal().Connect(&application, functor);
475 TestGestureManager& gestureManager = application.GetGestureManager();
476 gestureManager.Initialize();
478 detector.SetMaximumTouchesRequired(4);
480 // Gesture detection should have been updated only
481 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
482 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
483 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
486 gestureManager.Initialize();
488 // Create a second gesture detector that requires even less maximum touches
489 PanGestureDetector secondDetector = PanGestureDetector::New();
490 secondDetector.Attach(actor);
492 // Gesture detection should NOT have been updated
493 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
494 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
495 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
499 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
501 TestApplication application;
503 PanGestureDetector detector = PanGestureDetector::New();
504 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
508 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
510 TestApplication application;
512 PanGestureDetector detector = PanGestureDetector::New();
513 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
517 int UtcDaliPanGestureSignalReceptionNegative(void)
519 TestApplication application;
521 Actor actor = Actor::New();
522 actor.SetSize(100.0f, 100.0f);
523 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
524 Stage::GetCurrent().Add(actor);
527 application.SendNotification();
528 application.Render();
531 GestureReceivedFunctor functor(data);
533 PanGestureDetector detector = PanGestureDetector::New();
534 detector.Attach(actor);
535 detector.DetectedSignal().Connect(&application, functor);
537 // Do a pan outside actor's area
538 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
539 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 110.0f), Vector2(112.0f, 112.0f), 10));
540 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
542 // Continue pan into actor's area - we should still not receive the signal
544 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(112.0f, 112.0f), Vector2(20.0f, 20.0f), 10));
545 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
547 // Stop panning - we should still not receive the signal
549 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(12.0f, 12.0f), 10));
550 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
554 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
556 TestApplication application;
558 Actor actor = Actor::New();
559 actor.SetSize(100.0f, 100.0f);
560 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
561 Stage::GetCurrent().Add(actor);
564 application.SendNotification();
565 application.Render();
568 GestureReceivedFunctor functor(data);
570 PanGestureDetector detector = PanGestureDetector::New();
571 detector.Attach(actor);
572 detector.DetectedSignal().Connect(&application, functor);
574 // Start pan within the actor's area
575 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
576 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
577 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
578 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
579 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
580 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
581 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
582 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
583 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
585 // Continue the pan within the actor's area - we should still receive the signal
587 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
588 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
589 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
590 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
591 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
592 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
593 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
594 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
596 // Pan Gesture leaves actor's area - we should still receive the signal
598 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(320.0f, 10.0f), 10));
599 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
600 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
601 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
602 DALI_TEST_EQUALS(Vector2(300.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
603 DALI_TEST_EQUALS(Vector2(30.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
604 DALI_TEST_EQUALS(300.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
605 DALI_TEST_EQUALS(30.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
607 // Gesture ends - we would receive a finished state
609 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(320.0f, 10.0f), Vector2(310.0f, 10.0f), 10));
610 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
611 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
612 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
613 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
614 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
615 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
616 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
620 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
622 TestApplication application;
624 Actor actor = Actor::New();
625 actor.SetSize(100.0f, 100.0f);
626 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
627 Stage::GetCurrent().Add(actor);
630 application.SendNotification();
631 application.Render();
634 GestureReceivedFunctor functor(data);
636 PanGestureDetector detector = PanGestureDetector::New();
637 detector.Attach(actor);
638 detector.DetectedSignal().Connect(&application, functor);
640 // Start pan within the actor's area
641 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
642 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
643 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
644 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
645 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
646 DALI_TEST_EQUALS(Vector2(10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
647 DALI_TEST_EQUALS(Vector2(1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
648 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
649 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
651 // Continue the pan within the actor's area - we should still receive the signal
653 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
654 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
655 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
656 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
657 DALI_TEST_EQUALS(Vector2(0.0f, -10.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
658 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
659 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
660 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
662 // Gesture ends within actor's area - we would receive a finished state
664 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
665 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
666 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
667 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
668 DALI_TEST_EQUALS(Vector2(-10.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
669 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
670 DALI_TEST_EQUALS(10.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
671 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
675 int UtcDaliPanGestureSignalReceptionCancelled(void)
677 TestApplication application;
679 Actor actor = Actor::New();
680 actor.SetSize(100.0f, 100.0f);
681 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
682 Stage::GetCurrent().Add(actor);
685 application.SendNotification();
686 application.Render();
689 GestureReceivedFunctor functor(data);
691 PanGestureDetector detector = PanGestureDetector::New();
692 detector.Attach(actor);
693 detector.DetectedSignal().Connect(&application, functor);
695 // Start pan within the actor's area
696 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
697 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
698 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
699 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
701 // Continue the pan within the actor's area - we should still receive the signal
703 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
704 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
705 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
707 // The gesture is cancelled
709 application.ProcessEvent(GeneratePan(Gesture::Cancelled, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
710 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
711 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
715 int UtcDaliPanGestureSignalReceptionDetach(void)
717 TestApplication application;
719 Actor actor = Actor::New();
720 actor.SetSize(100.0f, 100.0f);
721 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
722 Stage::GetCurrent().Add(actor);
725 application.SendNotification();
726 application.Render();
729 GestureReceivedFunctor functor(data);
731 PanGestureDetector detector = PanGestureDetector::New();
732 detector.Attach(actor);
733 detector.DetectedSignal().Connect(&application, functor);
735 // Start pan within the actor's area
736 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
737 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
738 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
740 // Continue the pan within the actor's area - we should still receive the signal
742 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
743 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
745 // Gesture ends within actor's area
747 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
748 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
751 detector.DetachAll();
753 // Ensure we are no longer signalled
755 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
756 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
757 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
758 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
759 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
763 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
765 TestApplication application;
767 Actor actor = Actor::New();
768 actor.SetSize(100.0f, 100.0f);
769 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
770 Stage::GetCurrent().Add(actor);
773 application.SendNotification();
774 application.Render();
777 GestureReceivedFunctor functor(data);
779 PanGestureDetector detector = PanGestureDetector::New();
780 detector.Attach(actor);
781 detector.DetectedSignal().Connect(&application, functor);
783 // Start pan within the actor's area
784 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
785 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
786 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
788 // Continue the pan within the actor's area - we should still receive the signal
790 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
791 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
793 // Detach actor during the pan, we should not receive the next event
794 detector.DetachAll();
796 // Gesture ends within actor's area
798 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
799 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
803 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
805 TestApplication application;
808 GestureReceivedFunctor functor(data);
810 PanGestureDetector detector = PanGestureDetector::New();
811 detector.DetectedSignal().Connect(&application, functor);
813 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
815 Actor tempActor = Actor::New();
816 tempActor.SetSize(100.0f, 100.0f);
817 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
818 Stage::GetCurrent().Add(tempActor);
819 detector.Attach(tempActor);
821 // Actor lifetime is scoped
823 Actor actor = Actor::New();
824 actor.SetSize(100.0f, 100.0f);
825 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
826 Stage::GetCurrent().Add(actor);
829 application.SendNotification();
830 application.Render();
832 detector.Attach(actor);
834 // Start pan within the actor's area
835 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
836 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
837 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
839 // Continue the pan within the actor's area - we should still receive the signal
841 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
842 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
844 // Remove the actor from stage and reset the data
845 Stage::GetCurrent().Remove(actor);
848 application.SendNotification();
849 application.Render();
852 // Actor should now have been destroyed
854 // Gesture ends within the area where the actor used to be
856 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
857 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
861 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
863 TestApplication application;
865 Actor actor = Actor::New();
866 actor.SetSize(100.0f, 100.0f);
867 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
868 Stage::GetCurrent().Add(actor);
871 application.SendNotification();
872 application.Render();
875 GestureReceivedFunctor functor(data);
877 PanGestureDetector detector = PanGestureDetector::New();
878 detector.Attach(actor);
879 detector.DetectedSignal().Connect(&application, functor);
881 // Do an entire pan, only check finished value
882 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
883 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
885 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
886 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
887 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
889 // Rotate actor again and render a couple of times
890 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
891 application.SendNotification();
892 application.Render();
894 // Do an entire pan, only check finished value
895 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
896 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
898 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
899 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
900 DALI_TEST_EQUALS(Vector2(-5.0f, -8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
902 // Rotate actor again and render a couple of times
903 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
904 application.SendNotification();
905 application.Render();
907 // Do an entire pan, only check finished value
908 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
909 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
911 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
912 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
913 DALI_TEST_EQUALS(Vector2(-8.0f, 5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
917 int UtcDaliPanGestureSignalReceptionChildHit(void)
919 TestApplication application;
921 Actor parent = Actor::New();
922 parent.SetSize(100.0f, 100.0f);
923 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
924 Stage::GetCurrent().Add(parent);
926 // Set child to completely cover parent.
927 // Change rotation of child to be different from parent so that we can check if our local coordinate
928 // conversion of the parent actor is correct.
929 Actor child = Actor::New();
930 child.SetSize(100.0f, 100.0f);
931 child.SetAnchorPoint(AnchorPoint::CENTER);
932 child.SetParentOrigin(ParentOrigin::CENTER);
933 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
936 TouchEventFunctor touchFunctor;
937 child.TouchedSignal().Connect(&application, touchFunctor);
940 application.SendNotification();
941 application.Render();
944 GestureReceivedFunctor functor(data);
946 PanGestureDetector detector = PanGestureDetector::New();
947 detector.Attach(parent);
948 detector.DetectedSignal().Connect(&application, functor);
950 // Do an entire pan, only check finished value - hits child area but parent should still receive it
951 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
952 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
954 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
955 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
956 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
957 DALI_TEST_EQUALS(Vector2(5.0f, 8.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
959 // Attach child and generate same touch points to yield a different displacement
960 // (Also proves that you can detach and then re-attach another actor)
961 detector.Attach(child);
962 detector.Detach(parent);
964 // Do an entire pan, only check finished value
965 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
966 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(11.0f, 12.0f), Vector2(22.0f, 12.0f), 10));
968 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(22.0f, 12.0f), Vector2(27.0f, 20.0f), 10));
969 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
970 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
971 DALI_TEST_EQUALS(Vector2(8.0f, -5.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
975 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
977 TestApplication application;
979 Actor first = Actor::New();
980 first.SetSize(100.0f, 100.0f);
981 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
982 Stage::GetCurrent().Add(first);
984 Actor second = Actor::New();
985 second.SetSize(100.0f, 100.0f);
987 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
988 Stage::GetCurrent().Add(second);
991 application.SendNotification();
992 application.Render();
995 GestureReceivedFunctor functor(data);
997 PanGestureDetector detector = PanGestureDetector::New();
998 detector.Attach(first);
999 detector.Attach(second);
1000 detector.DetectedSignal().Connect(&application, functor);
1002 // Start pan within second actor's area
1003 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
1004 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(110.0f, 20.0f), Vector2(120.0f, 20.0f), 10));
1005 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1006 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1008 // Pan moves into first actor's area - second actor should receive the pan
1010 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(120.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1011 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1012 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1014 // Detach the second actor during the pan, we should not receive the next event
1015 detector.Detach(second);
1017 // Gesture ends within actor's area
1019 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1020 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1024 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
1026 TestApplication application;
1028 Actor actor = Actor::New();
1029 actor.SetSize(100.0f, 100.0f);
1030 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1031 Stage::GetCurrent().Add(actor);
1033 // Render and notify
1034 application.SendNotification();
1035 application.Render();
1038 GestureReceivedFunctor functor(data);
1040 PanGestureDetector detector = PanGestureDetector::New();
1041 detector.Attach(actor);
1042 detector.DetectedSignal().Connect(&application, functor);
1044 // Start pan in actor's area
1045 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1046 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1047 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1049 // Pan continues within actor's area
1051 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1052 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1054 // Actor become invisible - actor should not receive the next pan
1055 actor.SetVisible(false);
1057 // Render and notify
1058 application.SendNotification();
1059 application.Render();
1061 // Gesture ends within actor's area
1063 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 10.0f), Vector2(10.0f, 10.0f), 10));
1064 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1068 int UtcDaliPanGestureSignalReceptionMultipleGestureDetectors(void)
1070 TestApplication application;
1071 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
1073 Actor first = Actor::New();
1074 first.SetSize(100.0f, 100.0f);
1075 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1076 Stage::GetCurrent().Add(first);
1078 Actor second = Actor::New();
1079 second.SetSize(100.0f, 100.0f);
1080 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1083 // Render and notify
1084 application.SendNotification();
1085 application.Render();
1088 GestureReceivedFunctor functor(data);
1090 PanGestureDetector firstDetector = PanGestureDetector::New();
1091 firstDetector.Attach(first);
1092 firstDetector.DetectedSignal().Connect(&application, functor);
1094 // secondDetector is scoped
1096 // Reset gestureManager statistics
1097 gestureManager.Initialize();
1099 PanGestureDetector secondDetector = PanGestureDetector::New();
1100 secondDetector.SetMinimumTouchesRequired(2);
1101 secondDetector.SetMaximumTouchesRequired(2);
1102 secondDetector.Attach(second);
1103 secondDetector.DetectedSignal().Connect(&application, functor);
1105 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1106 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1107 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1109 // Start pan within second actor's area
1110 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1111 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10, 2));
1112 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1113 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1115 // Two touch pan changes to single touch - we should receive a finished state
1117 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10));
1118 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1119 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1120 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
1122 // Pan continues as single touch gesture - we should not receive any gesture
1124 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1125 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1127 // Pan ends - still no signal
1129 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1130 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1132 // Single touch pan starts - first actor should be panned
1134 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1135 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1136 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1137 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1139 // Pan changes to double-touch - we should receive a finished state
1141 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10, 2));
1142 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1143 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
1144 DALI_TEST_EQUALS(true, first == data.pannedActor, TEST_LOCATION);
1146 // Pan continues as double touch gesture - we should not receive any gesture
1148 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 10.0f), Vector2(30.0f, 10.0f), 10));
1149 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1151 // Pan ends - still no signal
1153 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(30.0f, 10.0f), Vector2(30.0f, 20.0f), 10));
1154 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1156 // Reset gesture manager statistics
1157 gestureManager.Initialize();
1160 // secondDetector has now been deleted. Gesture detection should have been updated only
1161 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
1162 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
1163 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
1167 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
1169 TestApplication application;
1171 Actor actor = Actor::New();
1172 actor.SetSize(100.0f, 100.0f);
1173 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1174 Stage::GetCurrent().Add(actor);
1176 Actor actor2 = Actor::New();
1177 actor2.SetSize(100.0f, 100.0f);
1178 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1179 Stage::GetCurrent().Add(actor2);
1181 // Render and notify
1182 application.SendNotification();
1183 application.Render();
1185 // Attach actor to one detector
1186 SignalData firstData;
1187 GestureReceivedFunctor firstFunctor(firstData);
1188 PanGestureDetector firstDetector = PanGestureDetector::New();
1189 firstDetector.Attach(actor);
1190 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1192 // Attach actor to another detector
1193 SignalData secondData;
1194 GestureReceivedFunctor secondFunctor(secondData);
1195 PanGestureDetector secondDetector = PanGestureDetector::New();
1196 secondDetector.Attach(actor);
1197 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1199 // Add second actor to second detector, when we remove the actor, this will make sure that this
1200 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1201 // functor should still not be called (which is what we're also testing).
1202 secondDetector.Attach(actor2);
1204 // Pan in actor's area - both detector's functors should be called
1205 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1206 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1207 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1208 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1210 // Pan continues in actor's area - both detector's functors should be called
1213 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1214 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1215 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1217 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1218 firstDetector.Detach(actor);
1221 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1222 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1223 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1225 // New pan on actor, only secondDetector has actor attached
1228 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1229 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1230 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1231 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1233 // Detach actor from secondDetector
1234 secondDetector.Detach(actor);
1237 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10));
1238 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1239 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1243 int UtcDaliPanGestureSignalReceptionMultipleStarted(void)
1245 // Should handle two started events gracefully.
1247 TestApplication application;
1249 Actor actor = Actor::New();
1250 actor.SetSize(100.0f, 100.0f);
1251 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1252 Stage::GetCurrent().Add(actor);
1255 GestureReceivedFunctor functor(data);
1257 PanGestureDetector detector = PanGestureDetector::New();
1258 detector.Attach(actor);
1259 detector.DetectedSignal().Connect(&application, functor);
1261 // Render and notify
1262 application.SendNotification();
1263 application.Render();
1265 // Start pan in actor's area
1266 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1267 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1268 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1270 // Send another start in actor's area
1272 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1273 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1275 // Add a child actor to overlap actor and send another start in actor's area
1276 Actor child = Actor::New();
1277 child.SetSize(100.0f, 100.0f);
1278 child.SetAnchorPoint(AnchorPoint::CENTER);
1279 child.SetParentOrigin(ParentOrigin::CENTER);
1282 TouchEventFunctor touchFunctor;
1283 child.TouchedSignal().Connect(&application, touchFunctor);
1285 // Render and notify
1286 application.SendNotification();
1287 application.Render();
1289 // Send another possible and start in actor's area
1291 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1292 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1293 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1295 // Send another start in actor's area
1297 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1298 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1299 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1303 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1305 TestApplication application;
1307 Actor actor1 = Actor::New();
1308 actor1.SetSize(100.0f, 100.0f);
1309 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1310 Stage::GetCurrent().Add(actor1);
1312 GestureReceivedFunctor functor1(data1);
1313 PanGestureDetector detector1 = PanGestureDetector::New();
1314 detector1.Attach(actor1);
1315 detector1.DetectedSignal().Connect(&application, functor1);
1317 Actor actor2 = Actor::New();
1318 actor2.SetSize(100.0f, 100.0f);
1319 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1320 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1321 Stage::GetCurrent().Add(actor2);
1323 GestureReceivedFunctor functor2(data2);
1324 PanGestureDetector detector2 = PanGestureDetector::New();
1325 detector2.Attach(actor2);
1326 detector2.DetectedSignal().Connect(&application, functor2);
1328 // Render and notify
1329 application.SendNotification();
1330 application.Render();
1332 // Start pan in actor1's area, only data1 should be set
1333 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1334 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1335 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1336 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1340 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1342 TestApplication application;
1344 Actor actor = Actor::New();
1345 actor.SetSize(100.0f, 100.0f);
1346 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1347 Stage::GetCurrent().Add(actor);
1349 // Render and notify
1350 application.SendNotification();
1351 application.Render();
1353 // Attach actor to detector
1355 GestureReceivedFunctor functor( data );
1356 PanGestureDetector detector = PanGestureDetector::New();
1357 detector.Attach(actor);
1358 detector.DetectedSignal().Connect( &application, functor );
1360 // Gesture possible in actor's area.
1361 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1362 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1364 // Move actor somewhere else
1365 actor.SetPosition( 100.0f, 100.0f );
1367 // Render and notify
1368 application.SendNotification();
1369 application.Render();
1371 // Emit Started event, we should not receive the long press.
1372 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1373 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1374 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1376 // LongPress possible in empty area.
1377 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1378 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1380 // Move actor in to the long press position.
1381 actor.SetPosition( 0.0f, 0.0f );
1383 // Render and notify
1384 application.SendNotification();
1385 application.Render();
1387 // Emit Started event, we should not receive the long press.
1388 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1389 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1390 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1392 // Normal long press in actor's area for completeness.
1393 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1394 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1395 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1396 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1400 int UtcDaliPanGestureEmitIncorrectState(void)
1402 TestApplication application;
1404 Actor actor = Actor::New();
1405 actor.SetSize(100.0f, 100.0f);
1406 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1407 Stage::GetCurrent().Add(actor);
1409 // Render and notify
1410 application.SendNotification();
1411 application.Render();
1413 // Attach actor to detector
1415 GestureReceivedFunctor functor( data );
1416 PanGestureDetector detector = PanGestureDetector::New();
1417 detector.Attach(actor);
1418 detector.DetectedSignal().Connect( &application, functor );
1420 // Try a Clear state
1423 application.ProcessEvent(GeneratePan(Gesture::Clear, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1424 tet_result(TET_FAIL);
1426 catch ( Dali::DaliException& e )
1428 DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
1433 int UtcDaliPanGestureActorUnstaged(void)
1435 TestApplication application;
1437 Actor actor = Actor::New();
1438 actor.SetSize(100.0f, 100.0f);
1439 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1440 Stage::GetCurrent().Add(actor);
1442 // Render and notify
1443 application.SendNotification();
1444 application.Render();
1446 // State to remove actor in.
1447 Gesture::State stateToUnstage( Gesture::Started );
1449 // Attach actor to detector
1451 UnstageActorFunctor functor( data, stateToUnstage );
1452 PanGestureDetector detector = PanGestureDetector::New();
1453 detector.Attach(actor);
1454 detector.DetectedSignal().Connect( &application, functor );
1457 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1458 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1459 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1461 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1462 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1465 // Render and notify
1466 application.SendNotification();
1467 application.Render();
1469 // Re-add actor to stage
1470 Stage::GetCurrent().Add(actor);
1472 // Render and notify
1473 application.SendNotification();
1474 application.Render();
1476 // Change state to Gesture::Continuing to remove
1477 stateToUnstage = Gesture::Continuing;
1480 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1481 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1482 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1484 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1485 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1487 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1488 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1491 // Render and notify
1492 application.SendNotification();
1493 application.Render();
1495 // Re-add actor to stage
1496 Stage::GetCurrent().Add(actor);
1498 // Render and notify
1499 application.SendNotification();
1500 application.Render();
1502 // Change state to Gesture::Finished to remove
1503 stateToUnstage = Gesture::Finished;
1506 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1507 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1508 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1510 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1511 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1513 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1514 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1515 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1519 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1521 TestApplication application;
1523 Actor actor = Actor::New();
1524 actor.SetSize(100.0f, 100.0f);
1525 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1526 Stage::GetCurrent().Add(actor);
1528 // Create and add a second actor so that GestureDetector destruction does not come into play.
1529 Actor dummyActor( Actor::New() );
1530 dummyActor.SetSize( 100.0f, 100.0f );
1531 dummyActor.SetPosition( 100.0f, 100.0f );
1532 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1533 Stage::GetCurrent().Add(dummyActor);
1535 // Render and notify
1536 application.SendNotification();
1537 application.Render();
1539 // State to remove actor in.
1540 Gesture::State stateToUnstage( Gesture::Started );
1542 // Attach actor to detector
1544 UnstageActorFunctor functor( data, stateToUnstage );
1545 PanGestureDetector detector = PanGestureDetector::New();
1546 detector.Attach(actor);
1547 detector.Attach(dummyActor);
1548 detector.DetectedSignal().Connect( &application, functor );
1550 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1551 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1552 // position, we should still not be signalled.
1555 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1556 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1557 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1560 // Render and notify
1561 application.SendNotification();
1562 application.Render();
1564 // Re add to the stage, we should not be signalled
1565 Stage::GetCurrent().Add(actor);
1567 // Render and notify
1568 application.SendNotification();
1569 application.Render();
1571 // Continue signal emission
1572 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1573 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1575 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1576 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1579 // Here we delete an actor in started, we should not receive any subsequent signalling.
1582 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1583 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1584 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1587 // Render and notify
1588 application.SendNotification();
1589 application.Render();
1591 // Delete actor as well
1594 // Render and notify
1595 application.SendNotification();
1596 application.Render();
1598 // Continue signal emission
1599 application.ProcessEvent(GeneratePan(Gesture::Continuing, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1600 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1602 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1603 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1607 int UtcDaliPanGestureSystemOverlay(void)
1609 TestApplication application;
1610 Dali::Integration::Core& core = application.GetCore();
1611 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1613 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1614 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1615 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1616 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1617 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1619 Actor actor = Actor::New();
1620 actor.SetSize(100.0f, 100.0f);
1621 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1622 systemOverlay.Add(actor);
1624 // Render and notify
1625 application.SendNotification();
1626 application.Render();
1629 GestureReceivedFunctor functor(data);
1631 PanGestureDetector detector = PanGestureDetector::New();
1632 detector.Attach(actor);
1633 detector.DetectedSignal().Connect(&application, functor);
1635 Vector2 screenCoordsStart( 10.0f, 20.0f );
1636 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1638 // Start pan within the actor's area
1639 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1640 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1641 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1645 int UtcDaliPanGestureBehindTouchableSystemOverlay(void)
1647 TestApplication application;
1648 Dali::Integration::Core& core = application.GetCore();
1649 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1651 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1652 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1653 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1654 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1655 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1657 // SystemOverlay actor
1658 Actor systemOverlayActor = Actor::New();
1659 systemOverlayActor.SetSize(100.0f, 100.0f);
1660 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1661 systemOverlay.Add(systemOverlayActor);
1664 Actor stageActor = Actor::New();
1665 stageActor.SetSize(100.0f, 100.0f);
1666 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1667 Stage::GetCurrent().Add(stageActor);
1669 // Render and notify
1670 application.SendNotification();
1671 application.Render();
1673 // Set system-overlay actor to touchable
1674 TouchEventData touchData;
1675 TouchEventDataFunctor touchFunctor( touchData );
1676 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1678 // Set stage actor to receive the gesture
1680 GestureReceivedFunctor functor(data);
1682 PanGestureDetector detector = PanGestureDetector::New();
1683 detector.Attach(stageActor);
1684 detector.DetectedSignal().Connect(&application, functor);
1686 Vector2 screenCoordsStart( 10.0f, 20.0f );
1687 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1689 // Start pan within the two actors' area
1690 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1691 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1692 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1693 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1694 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1699 // Do touch in the same area
1700 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoordsStart ) );
1701 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1702 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1707 int UtcDaliPanGestureTouchBehindGesturedSystemOverlay(void)
1709 TestApplication application;
1710 Dali::Integration::Core& core = application.GetCore();
1711 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1713 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1714 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1715 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1716 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1717 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1719 // SystemOverlay actor
1720 Actor systemOverlayActor = Actor::New();
1721 systemOverlayActor.SetSize(100.0f, 100.0f);
1722 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1723 systemOverlay.Add(systemOverlayActor);
1726 Actor stageActor = Actor::New();
1727 stageActor.SetSize(100.0f, 100.0f);
1728 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1729 Stage::GetCurrent().Add(stageActor);
1731 // Render and notify
1732 application.SendNotification();
1733 application.Render();
1735 // Set stage actor to touchable
1736 TouchEventData touchData;
1737 TouchEventDataFunctor touchFunctor( touchData );
1738 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1740 // Set system-overlay actor to have the gesture
1742 GestureReceivedFunctor functor(data);
1744 PanGestureDetector detector = PanGestureDetector::New();
1745 detector.Attach(systemOverlayActor);
1746 detector.DetectedSignal().Connect(&application, functor);
1748 Vector2 screenCoordsStart( 10.0f, 20.0f );
1749 Vector2 screenCoordsEnd( 20.0f, 20.0f );
1751 // Start pan within the two actors' area
1752 application.ProcessEvent( GeneratePan( Gesture::Possible, screenCoordsStart, screenCoordsEnd, 10 ) );
1753 application.ProcessEvent( GeneratePan( Gesture::Started, screenCoordsStart, screenCoordsEnd, 10 ) );
1754 application.ProcessEvent( GeneratePan( Gesture::Finished, screenCoordsStart, screenCoordsEnd, 10 ) );
1755 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1756 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1761 // Do touch in the same area
1762 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoordsStart ) );
1763 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1764 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1769 int UtcDaliPanGestureAngleHandling(void)
1771 TestApplication application;
1773 PanGestureDetector detector = PanGestureDetector::New();
1774 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1776 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1777 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1779 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1781 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1783 tet_result( TET_PASS );
1791 tet_printf("%s, angle not added\n", TEST_LOCATION );
1792 tet_result( TET_FAIL );
1795 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1796 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1798 // Remove something not in the container.
1799 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1800 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1802 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1803 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1804 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1806 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1808 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1809 tet_result( TET_FAIL );
1814 detector.ClearAngles();
1815 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1819 int UtcDaliPanGestureGetAngle(void)
1821 TestApplication application;
1823 PanGestureDetector detector = PanGestureDetector::New();
1824 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1826 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1827 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1829 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1830 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1832 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1833 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1835 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1836 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1838 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1839 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1840 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1841 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1846 inline float RadiansToDegrees( float radian )
1848 return radian * 180.0f / Math::PI;
1851 int UtcDaliPanGestureAngleOutOfRange(void)
1853 TestApplication application;
1855 PanGestureDetector detector = PanGestureDetector::New();
1856 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1862 detector.AddAngle( Degree(180.0f) );
1863 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1864 detector.ClearAngles();
1866 detector.AddAngle( Degree(190.0f) );
1867 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1868 detector.ClearAngles();
1870 detector.AddAngle( Degree(-190.0f) );
1871 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1872 detector.ClearAngles();
1874 detector.AddAngle( Degree(350.0f) );
1875 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1876 detector.ClearAngles();
1878 detector.AddAngle( Degree(-350.0f) );
1879 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1880 detector.ClearAngles();
1882 detector.AddAngle( Degree(370.0f) );
1883 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1884 detector.ClearAngles();
1886 detector.AddAngle( Degree(-370.0f) );
1887 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1888 detector.ClearAngles();
1894 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1895 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1896 detector.ClearAngles();
1898 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1899 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1900 detector.ClearAngles();
1902 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1903 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1904 detector.ClearAngles();
1906 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1907 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1908 detector.ClearAngles();
1912 int UtcDaliPanGestureAngleProcessing(void)
1914 TestApplication application;
1916 Actor parent = Actor::New();
1917 parent.SetSize(100.0f, 100.0f);
1918 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1919 Stage::GetCurrent().Add(parent);
1921 Actor child = Actor::New();
1922 child.SetSize(100.0f, 100.0f);
1923 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1926 // Render and notify
1927 application.SendNotification();
1928 application.Render();
1930 // Parent detector only requires up pans
1931 PanGestureDetector parentDetector = PanGestureDetector::New();
1932 parentDetector.Attach( parent );
1933 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1934 SignalData parentData;
1935 GestureReceivedFunctor parentFunctor(parentData);
1936 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1938 // Child detector only requires right pans
1939 PanGestureDetector childDetector = PanGestureDetector::New();
1940 childDetector.Attach( child );
1941 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1942 SignalData childData;
1943 GestureReceivedFunctor childFunctor(childData);
1944 childDetector.DetectedSignal().Connect(&application, childFunctor);
1946 // Generate an Up pan gesture, only parent should receive it.
1947 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1948 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
1949 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1950 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1951 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1955 // Generate a Right pan gesture, only child should receive it.
1956 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1957 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
1958 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1959 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1960 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1964 // Generate a Down pan gesture, no one should receive it.
1965 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1966 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
1967 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1968 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1969 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1973 // Generate a Left pan gesture, no one should receive it.
1974 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
1975 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
1976 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1977 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1978 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
1984 int UtcDaliPanGestureDirectionHandling(void)
1986 TestApplication application;
1988 PanGestureDetector detector = PanGestureDetector::New();
1989 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1991 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1992 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1994 for ( size_t i = 0; detector.GetAngleCount(); i++)
1996 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1998 tet_result( TET_PASS );
2007 tet_printf("%s, angle not added\n", TEST_LOCATION );
2008 tet_result( TET_FAIL );
2012 for( size_t i = 0; i < detector.GetAngleCount(); i++)
2014 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
2016 tet_result( TET_PASS );
2024 tet_printf("%s, angle not added\n", TEST_LOCATION );
2025 tet_result( TET_FAIL );
2028 // Remove something not in the container.
2029 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
2030 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
2032 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
2033 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
2037 int UtcDaliPanGestureDirectionProcessing(void)
2039 TestApplication application;
2041 Actor parent = Actor::New();
2042 parent.SetSize(100.0f, 100.0f);
2043 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2044 Stage::GetCurrent().Add(parent);
2046 Actor child = Actor::New();
2047 child.SetSize(100.0f, 100.0f);
2048 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2051 // Render and notify
2052 application.SendNotification();
2053 application.Render();
2055 // Parent detector only requires vertical panning
2056 PanGestureDetector parentDetector = PanGestureDetector::New();
2057 parentDetector.Attach( parent );
2058 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
2059 SignalData parentData;
2060 GestureReceivedFunctor parentFunctor(parentData);
2061 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
2063 // Child detector only requires horizontal panning
2064 PanGestureDetector childDetector = PanGestureDetector::New();
2065 childDetector.Attach( child );
2066 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
2067 SignalData childData;
2068 GestureReceivedFunctor childFunctor(childData);
2069 childDetector.DetectedSignal().Connect(&application, childFunctor);
2071 // Generate an Up pan gesture, only parent should receive it.
2072 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2073 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 10.0f), 10 ) );
2074 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2075 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2076 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2080 // Generate a Right pan gesture, only child should receive it.
2081 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2082 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 20.0f), 10 ) );
2083 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2084 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2085 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2089 // Generate a Down pan gesture, only parent should receive it.
2090 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2091 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(20.0f, 30.0f), 10 ) );
2092 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
2093 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2094 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2098 // Generate a Left pan gesture, only child should receive it.
2099 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2100 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 20.0f), 10 ) );
2101 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2102 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
2103 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2107 // Generate a pan at -45 degrees, no one should receive it.
2108 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2109 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2110 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2111 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2112 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2116 // Generate a pan at 45 degrees, no one should receive it.
2117 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2118 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(30.0f, 30.0f), 10 ) );
2119 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2120 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2121 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2125 // Generate a pan at 135 degrees, no one should receive it.
2126 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2127 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 30.0f), 10 ) );
2128 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2129 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2130 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2134 // Generate a pan at -135 degrees, no one should receive it.
2135 application.ProcessEvent( GeneratePan( Gesture::Possible, Vector2(20.0f, 20.0f), Vector2(20.0f, 20.0f), 10 ) );
2136 application.ProcessEvent( GeneratePan( Gesture::Started, Vector2(20.0f, 20.0f), Vector2(10.0f, 10.0f), 10 ) );
2137 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
2138 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
2139 application.ProcessEvent( GeneratePan( Gesture::Finished, Vector2(20.0f, 30.0f), Vector2(20.0f, 20.0f), 10 ) );
2145 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
2147 TestApplication application;
2148 Integration::SetPanGesturePredictionMode(0);
2149 Integration::SetPanGestureSmoothingMode(0);
2151 Actor actor = Actor::New();
2152 actor.SetSize(100.0f, 100.0f);
2153 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2154 Stage::GetCurrent().Add(actor);
2156 // Add a pan detector
2157 PanGestureDetector detector = PanGestureDetector::New();
2158 detector.Attach( actor );
2160 GestureReceivedFunctor functor( data );
2161 detector.DetectedSignal().Connect( &application, functor );
2163 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2165 ConstraintData constraintData;
2166 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2167 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2168 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2169 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2170 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2171 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2172 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2173 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2176 // Render and notify
2177 application.SendNotification();
2178 application.Render();
2180 Vector2 direction(Vector2::XAXIS * -5.0f);
2181 Vector2 startPosition( 1.0f, 1.0f );
2182 PerformSwipeGestureSwipe(application, startPosition, direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2183 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2184 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2185 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2186 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
2188 constraintData.Reset();
2192 int UtcDaliPanGestureNoPredictionSmoothing(void)
2194 TestApplication application;
2195 Integration::SetPanGesturePredictionMode(0);
2196 Integration::SetPanGestureSmoothingMode(1);
2198 Actor actor = Actor::New();
2199 actor.SetSize(100.0f, 100.0f);
2200 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2201 Stage::GetCurrent().Add(actor);
2203 // Add a pan detector
2204 PanGestureDetector detector = PanGestureDetector::New();
2205 detector.Attach( actor );
2207 GestureReceivedFunctor functor( data );
2208 detector.DetectedSignal().Connect( &application, functor );
2210 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2212 ConstraintData constraintData;
2213 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2214 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2215 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2216 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2217 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2218 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2219 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2220 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2223 // Render and notify
2224 application.SendNotification();
2225 application.Render();
2227 Vector2 direction(Vector2::XAXIS * -5.0f);
2228 Vector2 previousPosition( 20.0f, 20.0f );
2229 Vector2 currentPosition( 20.0f, 10.0f );
2230 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2231 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2232 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2233 // Take into account resampling done when prediction is off.
2234 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2235 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
2237 constraintData.Reset();
2241 int UtcDaliPanGesturePredictionNoSmoothing(void)
2243 TestApplication application;
2244 Integration::SetPanGesturePredictionMode(1);
2245 Integration::SetPanGestureSmoothingMode(0);
2247 Actor actor = Actor::New();
2248 actor.SetSize(100.0f, 100.0f);
2249 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2250 Stage::GetCurrent().Add(actor);
2252 // Add a pan detector
2253 PanGestureDetector detector = PanGestureDetector::New();
2254 detector.Attach( actor );
2256 GestureReceivedFunctor functor( data );
2257 detector.DetectedSignal().Connect( &application, functor );
2259 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2261 ConstraintData constraintData;
2262 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2263 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2264 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2265 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2266 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2267 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2268 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2269 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2272 // Render and notify
2273 application.SendNotification();
2274 application.Render();
2276 Vector2 direction(Vector2::XAXIS * -1.0f);
2277 Vector2 previousPosition( 20.0f, 20.0f );
2278 Vector2 currentPosition( 20.0f, 10.0f );
2279 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2280 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2281 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2282 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2283 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2285 constraintData.Reset();
2289 int UtcDaliPanGesturePredictionSmoothing01(void)
2291 TestApplication application;
2292 Integration::SetPanGesturePredictionMode(1);
2293 Integration::SetPanGestureSmoothingMode(1);
2295 Actor actor = Actor::New();
2296 actor.SetSize(100.0f, 100.0f);
2297 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2298 Stage::GetCurrent().Add(actor);
2300 // Add a pan detector
2301 PanGestureDetector detector = PanGestureDetector::New();
2302 detector.Attach( actor );
2304 GestureReceivedFunctor functor( data );
2305 detector.DetectedSignal().Connect( &application, functor );
2307 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2309 ConstraintData constraintData;
2310 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2311 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2312 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2313 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2314 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2315 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2316 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2317 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2320 // Render and notify
2321 application.SendNotification();
2322 application.Render();
2324 Vector2 direction(Vector2::XAXIS * -1.0f);
2325 Vector2 previousPosition( 20.0f, 20.0f );
2326 Vector2 currentPosition( 20.0f, 10.0f );
2327 PerformSwipeGestureSwipe(application, Vector2(1.0f, 1.0f), direction, PAN_GESTURE_UPDATE_COUNT, 1, true, true);
2328 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2329 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2330 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2331 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2333 constraintData.Reset();
2337 int UtcDaliPanGesturePredictionSmoothing02(void)
2339 TestApplication application;
2340 Integration::SetPanGesturePredictionMode( 1 );
2341 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2342 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2343 Integration::SetPanGestureSmoothingMode( 1 );
2344 Integration::SetPanGestureSmoothingAmount( 0.25f );
2346 Actor actor = Actor::New();
2347 actor.SetSize(100.0f, 100.0f);
2348 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2349 Stage::GetCurrent().Add(actor);
2351 // Add a pan detector
2352 PanGestureDetector detector = PanGestureDetector::New();
2353 detector.Attach( actor );
2355 GestureReceivedFunctor functor( data );
2356 detector.DetectedSignal().Connect( &application, functor );
2358 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2360 ConstraintData constraintData;
2361 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2362 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2363 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2364 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2365 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2366 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2367 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2368 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2371 // Render and notify
2372 application.SendNotification();
2373 application.Render();
2375 Vector2 directionX(Vector2::XAXIS);
2376 Vector2 directionY(Vector2::YAXIS);
2377 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), directionX, 10, 1, true, false);
2378 position = PerformSwipeGestureSwipe(application, position, directionX * 10.0f, 1, 1, false, false);
2379 position = PerformSwipeGestureSwipe(application, position, directionX * -1.0f, 2, 1, false, false);
2380 position = PerformSwipeGestureSwipe(application, position, directionX, 10, 1, false, true);
2381 position = PerformSwipeGestureSwipe(application, position, directionY, 10, 1, true, false);
2382 position = PerformSwipeGestureSwipe(application, position, directionY * -1.0f, 2, 1, false, false);
2383 position = PerformSwipeGestureSwipe(application, position, directionY, 10, 1, false, true);
2384 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2385 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2386 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2387 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2389 constraintData.Reset();
2393 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2395 TestApplication application;
2397 Integration::SetPanGesturePredictionMode( 2 );
2398 Integration::SetPanGesturePredictionAmount( 57 );
2399 Integration::SetPanGestureSmoothingMode( 2 );
2400 Integration::SetPanGestureUseActualTimes( false );
2401 Integration::SetPanGestureInterpolationTimeRange( 10 );
2402 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2403 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2404 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2405 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2406 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2407 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2409 Actor actor = Actor::New();
2410 actor.SetSize(100.0f, 100.0f);
2411 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2412 Stage::GetCurrent().Add(actor);
2414 // Add a pan detector
2415 PanGestureDetector detector = PanGestureDetector::New();
2416 detector.Attach( actor );
2418 GestureReceivedFunctor functor( data );
2419 detector.DetectedSignal().Connect( &application, functor );
2421 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2423 ConstraintData constraintData;
2424 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2425 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2426 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2427 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2428 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2429 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2430 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2431 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2434 // Render and notify
2435 application.SendNotification();
2436 application.Render();
2438 Vector2 direction(Vector2::XAXIS * -1.0f);
2439 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 1, true, true);
2440 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2441 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2442 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2443 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2445 constraintData.Reset();
2449 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2451 TestApplication application;
2453 Integration::SetPanGesturePredictionMode( 2 );
2454 Integration::SetPanGestureSmoothingMode( 2 );
2455 Integration::SetPanGestureUseActualTimes( true );
2456 Integration::SetPanGestureInterpolationTimeRange( 10 );
2457 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2458 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2459 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2460 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2461 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2462 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2464 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2466 Actor actor = Actor::New();
2467 actor.SetSize(100.0f, 100.0f);
2468 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2469 Stage::GetCurrent().Add(actor);
2471 // Add a pan detector
2472 PanGestureDetector detector = PanGestureDetector::New();
2473 detector.Attach( actor );
2475 GestureReceivedFunctor functor( data );
2476 detector.DetectedSignal().Connect( &application, functor );
2478 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2480 ConstraintData constraintData;
2481 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2482 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2483 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2484 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2485 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2486 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2487 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2488 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2491 // Render and notify
2492 application.SendNotification();
2493 application.Render();
2495 Vector2 direction(Vector2::XAXIS * -1.0f);
2496 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 3, true, false);
2497 position = PerformSwipeGestureSwipe(application, position, direction, 10, 0, false, false);
2498 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, false, 0);
2499 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, true);
2500 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2501 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2502 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2503 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2505 constraintData.Reset();
2509 int UtcDaliPanGesturePrediction2Smoothing(void)
2511 TestApplication application;
2513 Integration::SetPanGesturePredictionMode( 2 );
2514 Integration::SetPanGesturePredictionAmount( 57 );
2515 Integration::SetPanGestureSmoothingMode( 1 );
2516 Integration::SetPanGestureUseActualTimes( false );
2517 Integration::SetPanGestureInterpolationTimeRange( 10 );
2518 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2519 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2520 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2521 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2522 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2523 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2525 Actor actor = Actor::New();
2526 actor.SetSize(100.0f, 100.0f);
2527 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2528 Stage::GetCurrent().Add(actor);
2530 // Add a pan detector
2531 PanGestureDetector detector = PanGestureDetector::New();
2532 detector.Attach( actor );
2534 GestureReceivedFunctor functor( data );
2535 detector.DetectedSignal().Connect( &application, functor );
2537 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2539 ConstraintData constraintData;
2540 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2541 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2542 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2543 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2544 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2545 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2546 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2547 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2550 // Render and notify
2551 application.SendNotification();
2552 application.Render();
2554 Vector2 direction(Vector2::XAXIS * -1.0f);
2555 Vector2 position = PerformSwipeGestureSwipe(application, Vector2(2.0f, 2.0f), direction, 10, 1, true, false);
2556 position = PerformSwipeGestureSwipe(application, position, direction, 1, 3, false, false);
2557 position = PerformSwipeGestureSwipe(application, position, direction, 5, 0, false, false);
2558 position = PerformSwipeGestureSwipe(application, position, direction, 10, 1, false, true);
2559 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2560 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2561 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2562 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2564 constraintData.Reset();
2568 int UtcDaliPanGestureSetProperties(void)
2570 TestApplication application;
2571 TestRenderController& renderController( application.GetRenderController() );
2572 Integration::SetPanGesturePredictionMode(0);
2573 Integration::SetPanGestureSmoothingMode(0);
2575 Actor actor = Actor::New();
2576 actor.SetSize(100.0f, 100.0f);
2577 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2578 Stage::GetCurrent().Add(actor);
2580 // Add a pan detector
2581 PanGestureDetector detector = PanGestureDetector::New();
2582 detector.Attach( actor );
2584 GestureReceivedFunctor functor( data );
2585 detector.DetectedSignal().Connect( &application, functor );
2587 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2588 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2590 ConstraintData constraintData;
2591 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2592 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2593 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2594 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2595 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2596 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2597 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2598 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2599 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2602 // Render and notify
2603 application.SendNotification();
2604 application.Render();
2606 renderController.Initialize();
2607 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2609 Vector2 screenPosition( 20.0f, 20.0f );
2610 Vector2 screenDisplacement( 1.0f, 1.0f );
2611 Vector2 screenVelocity( 1.3f, 4.0f );
2612 Vector2 localPosition( 21.0f, 21.0f );
2613 Vector2 localDisplacement( 0.5f, 0.5f );
2614 Vector2 localVelocity( 1.5f, 2.5f );
2616 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2617 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2619 // Render and notify
2620 application.SendNotification();
2621 application.Render();
2623 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2624 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2625 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2626 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2627 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2628 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2629 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2630 constraintData.Reset();
2634 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2636 TestApplication application;
2637 Integration::SetPanGesturePredictionMode(0);
2639 Actor actor = Actor::New();
2640 actor.SetSize(100.0f, 100.0f);
2641 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2642 Stage::GetCurrent().Add(actor);
2644 // Add a pan detector
2645 PanGestureDetector detector = PanGestureDetector::New();
2646 detector.Attach( actor );
2648 GestureReceivedFunctor functor( data );
2649 detector.DetectedSignal().Connect( &application, functor );
2651 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2653 ConstraintData constraintData;
2654 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2655 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2656 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2657 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2658 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2659 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2660 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2661 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2664 // Render and notify
2665 application.SendNotification();
2666 application.Render();
2668 Vector2 previousPosition( 20.0f, 20.0f );
2669 Vector2 currentPosition( 20.0f, 10.0f );
2670 application.ProcessEvent( GeneratePan( Gesture::Possible, previousPosition, previousPosition, 10 ) );
2671 application.ProcessEvent( GeneratePan( Gesture::Started, previousPosition, currentPosition, 10 ) );
2672 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2674 Vector2 screenPosition( 100.0f, 20.0f );
2675 Vector2 localPosition( 110.0f, 110.0f );
2677 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2679 // Render and notify
2680 application.SendNotification();
2681 application.Render();
2683 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2684 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2685 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2686 constraintData.Reset();
2690 int UtcDaliPanGesturePropertyIndices(void)
2692 TestApplication application;
2693 PanGestureDetector detector = PanGestureDetector::New();
2695 Property::IndexContainer indices;
2696 detector.GetPropertyIndices( indices );
2697 DALI_TEST_CHECK( indices.Size() );
2698 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2704 struct PropertyStringIndex
2706 const char * const name;
2707 const Property::Index index;
2708 const Property::Type type;
2709 const Property::Value value;
2712 const PropertyStringIndex PROPERTY_TABLE[] =
2714 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2715 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2716 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2717 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2718 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2719 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2720 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2722 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2723 } // unnamed namespace
2726 int UtcDaliPanGestureProperties(void)
2728 TestApplication application;
2729 PanGestureDetector detector = PanGestureDetector::New();
2731 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2733 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2734 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2735 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2736 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2737 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2738 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2739 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2745 int UtcDaliPanGestureGetProperty(void)
2747 TestApplication application;
2748 PanGestureDetector detector = PanGestureDetector::New();
2750 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2752 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2754 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2755 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2757 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2759 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2760 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2767 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2769 TestApplication application;
2771 Actor actor = Actor::New();
2772 actor.SetSize(100.0f, 100.0f);
2773 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2774 Stage::GetCurrent().Add(actor);
2776 // Add a pan detector
2777 PanGestureDetector detector = PanGestureDetector::New();
2778 detector.Attach( actor );
2780 // Render and notify
2781 application.SendNotification();
2782 application.Render();
2784 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2786 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2788 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2790 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2791 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2793 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2795 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2796 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2803 int UtcDaliPanGestureLayerConsumesTouch(void)
2805 TestApplication application;
2807 Actor actor = Actor::New();
2808 actor.SetSize(100.0f, 100.0f);
2809 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2810 Stage::GetCurrent().Add(actor);
2812 // Add a pan detector
2813 PanGestureDetector detector = PanGestureDetector::New();
2814 detector.Attach( actor );
2816 GestureReceivedFunctor functor( data );
2817 detector.DetectedSignal().Connect( &application, functor );
2819 // Add a layer to overlap the actor
2820 Layer layer = Layer::New();
2821 layer.SetSize(100.0f, 100.0f);
2822 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2823 Stage::GetCurrent().Add( layer );
2826 // Render and notify
2827 application.SendNotification();
2828 application.Render();
2830 // Emit signals, should receive
2831 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2832 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2833 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2834 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2837 // Set layer to consume all touch
2838 layer.SetTouchConsumed( true );
2840 // Render and notify
2841 application.SendNotification();
2842 application.Render();
2844 // Emit the same signals again, should not receive
2845 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2846 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2847 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
2848 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2854 int UtcDaliPanGestureNoTimeDiff(void)
2856 TestApplication application;
2858 Actor actor = Actor::New();
2859 actor.SetSize(100.0f, 100.0f);
2860 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2861 Stage::GetCurrent().Add(actor);
2863 // Add a pan detector
2864 PanGestureDetector detector = PanGestureDetector::New();
2865 detector.Attach( actor );
2867 GestureReceivedFunctor functor( data );
2868 detector.DetectedSignal().Connect( &application, functor );
2870 // Render and notify
2871 application.SendNotification();
2872 application.Render();
2874 // Emit signals, should receive
2875 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2876 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2877 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 0));
2878 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2879 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2880 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2881 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2882 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );