2 * Copyright (c) 2019 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/render-task-list-integ.h>
25 #include <dali/integration-api/profiling.h>
26 #include <dali/integration-api/input-options.h>
27 #include <dali/internal/event/events/pan-gesture-event.h>
28 #include <dali-test-suite-utils.h>
29 #include <test-touch-utils.h>
33 void utc_dali_pan_gesture_detector_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_pan_gesture_detector_cleanup(void)
40 test_return_value = TET_PASS;
43 ///////////////////////////////////////////////////////////////////////////////
46 const int PAN_EVENT_TIME_DELTA = 8;
47 const int PAN_GESTURE_UPDATE_COUNT = 50;
49 // Stores data that is populated in the callback and will be read by the test cases
53 : functorCalled(false),
54 voidFunctorCalled(false),
55 receivedGesture(Gesture::Clear)
60 functorCalled = false;
61 voidFunctorCalled = false;
63 receivedGesture.state = Gesture::Clear;
64 receivedGesture.velocity = Vector2(0.0f, 0.0f);
65 receivedGesture.displacement = Vector2(0.0f, 0.0f);
66 receivedGesture.position = Vector2(0.0f, 0.0f);
67 receivedGesture.screenPosition = Vector2(0.0f, 0.0f);
68 receivedGesture.numberOfTouches = 0;
74 bool voidFunctorCalled;
75 PanGesture receivedGesture;
79 // Functor that sets the data when called
80 struct GestureReceivedFunctor
82 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
84 void operator()(Actor actor, const PanGesture& pan)
86 signalData.functorCalled = true;
87 signalData.receivedGesture = pan;
88 signalData.pannedActor = actor;
93 signalData.voidFunctorCalled = true;
96 SignalData& signalData;
99 // Functor that removes the gestured actor from stage
100 struct UnstageActorFunctor : public GestureReceivedFunctor
102 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
103 : GestureReceivedFunctor( data ),
104 stateToUnstage( stateToUnstage )
108 void operator()( Actor actor, const PanGesture& pan )
110 GestureReceivedFunctor::operator()( actor, pan );
112 if ( pan.state == stateToUnstage )
114 Stage::GetCurrent().Remove( actor );
118 Gesture::State& stateToUnstage;
121 // Functor for receiving a touch event
122 struct TouchEventFunctor
124 bool operator()(Actor actor, const TouchEvent& touch)
130 // Data for constraints
131 struct ConstraintData
139 Vector2 screenPosition;
140 Vector2 screenDisplacement;
141 Vector2 screenVelocity;
142 Vector2 localPosition;
143 Vector2 localDisplacement;
144 Vector2 localVelocity;
150 screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
156 // Constraint used with panning properties
159 PanConstraint( ConstraintData& data ) : constraintData(data) { }
161 void operator()( Vector3& current, const PropertyInputContainer& inputs )
163 constraintData.screenPosition = inputs[0]->GetVector2();
164 constraintData.screenDisplacement = inputs[1]->GetVector2();
165 constraintData.screenVelocity = inputs[2]->GetVector2();
166 constraintData.localPosition = inputs[3]->GetVector2();
167 constraintData.localDisplacement = inputs[4]->GetVector2();
168 constraintData.localVelocity = inputs[5]->GetVector2();
169 constraintData.panning = inputs[6]->GetBoolean();
170 constraintData.called = true;
171 current = Vector3::ZERO;
174 ConstraintData& constraintData;
177 // Generate a PanGesture
178 PanGesture GeneratePan( unsigned int time,
179 Gesture::State state,
180 Vector2 screenPosition,
181 Vector2 localPosition,
182 Vector2 screenDisplacement = Vector2::ONE,
183 Vector2 localDisplacement = Vector2::ONE,
184 Vector2 screenVelocity = Vector2::ONE,
185 Vector2 localVelocity = Vector2::ONE,
186 unsigned int numberOfTouches = 1 )
188 PanGesture pan( state );
192 pan.screenPosition = screenPosition;
193 pan.position = localPosition;
195 pan.screenDisplacement = screenDisplacement;
196 pan.displacement = localDisplacement;
198 pan.screenVelocity = screenVelocity;
199 pan.velocity = localVelocity;
201 pan.numberOfTouches = numberOfTouches;
208 ///////////////////////////////////////////////////////////////////////////////
210 // Positive test case for a method
211 int UtcDaliPanGestureDetectorConstructor(void)
213 TestApplication application;
215 PanGestureDetector detector;
216 DALI_TEST_CHECK(!detector);
220 int UtcDaliPanGestureDetectorCopyConstructorP(void)
222 TestApplication application;
224 PanGestureDetector detector = PanGestureDetector::New();
226 PanGestureDetector copy( detector );
227 DALI_TEST_CHECK( detector );
231 int UtcDaliPanGestureDetectorAssignmentOperatorP(void)
233 TestApplication application;
235 PanGestureDetector detector = PanGestureDetector::New();
237 PanGestureDetector assign;
239 DALI_TEST_CHECK( detector );
241 DALI_TEST_CHECK( detector == assign );
245 // Negative test case for a method
246 int UtcDaliPanGestureDetectorNew(void)
248 TestApplication application;
250 PanGestureDetector detector = PanGestureDetector::New();
252 DALI_TEST_CHECK(detector);
254 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
255 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
257 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
258 Actor actor = Actor::New();
259 actor.SetSize(100.0f, 100.0f);
260 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
261 detector.Attach(actor);
263 Stage::GetCurrent().Add(actor);
266 application.SendNotification();
267 application.Render();
269 // Use long press function for touch event
270 TestStartLongPress( application );
275 int UtcDaliPanGestureDetectorDownCast(void)
277 TestApplication application;
278 tet_infoline("Testing Dali::GestureDetector::DownCast()");
280 PanGestureDetector detector = PanGestureDetector::New();
282 BaseHandle object(detector);
284 PanGestureDetector detector2 = PanGestureDetector::DownCast(object);
285 DALI_TEST_CHECK(detector2);
287 PanGestureDetector detector3 = DownCast< PanGestureDetector >(object);
288 DALI_TEST_CHECK(detector3);
290 BaseHandle unInitializedObject;
291 PanGestureDetector detector4 = PanGestureDetector::DownCast(unInitializedObject);
292 DALI_TEST_CHECK(!detector4);
294 PanGestureDetector detector5 = DownCast< PanGestureDetector >(unInitializedObject);
295 DALI_TEST_CHECK(!detector5);
297 GestureDetector detector6 = PanGestureDetector::New();
298 PanGestureDetector detector7 = PanGestureDetector::DownCast(detector6);
299 DALI_TEST_CHECK(detector7);
303 int UtcDaliPanGestureSetMinimumTouchesRequired(void)
305 TestApplication application;
307 PanGestureDetector detector = PanGestureDetector::New();
309 unsigned int min = 2;
311 DALI_TEST_CHECK(min != detector.GetMinimumTouchesRequired());
313 detector.SetMinimumTouchesRequired(min);
315 DALI_TEST_EQUALS(min, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
317 // Attach an actor and change the minimum touches
319 Actor actor = Actor::New();
320 actor.SetSize(100.0f, 100.0f);
321 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
322 Stage::GetCurrent().Add(actor);
325 application.SendNotification();
326 application.Render();
329 GestureReceivedFunctor functor(data);
331 detector.Attach(actor);
332 detector.DetectedSignal().Connect(&application, functor);
334 detector.SetMinimumTouchesRequired(3);
336 // Create a second gesture detector that requires even less minimum touches
337 PanGestureDetector secondDetector = PanGestureDetector::New();
338 secondDetector.Attach(actor);
340 DALI_TEST_EQUALS(3, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
345 int UtcDaliPanGestureSetMaximumTouchesRequired(void)
347 TestApplication application;
349 PanGestureDetector detector = PanGestureDetector::New();
351 unsigned int max = 3;
353 DALI_TEST_CHECK(max != detector.GetMaximumTouchesRequired());
355 detector.SetMaximumTouchesRequired(max);
357 DALI_TEST_EQUALS(max, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
359 // Attach an actor and change the maximum touches
361 Actor actor = Actor::New();
362 actor.SetSize(100.0f, 100.0f);
363 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
364 Stage::GetCurrent().Add(actor);
367 application.SendNotification();
368 application.Render();
371 GestureReceivedFunctor functor(data);
373 detector.Attach(actor);
374 detector.DetectedSignal().Connect(&application, functor);
376 detector.SetMaximumTouchesRequired(4);
378 DALI_TEST_EQUALS(4, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
383 int UtcDaliPanGestureGetMinimumTouchesRequired(void)
385 TestApplication application;
387 PanGestureDetector detector = PanGestureDetector::New();
388 DALI_TEST_EQUALS(1u, detector.GetMinimumTouchesRequired(), TEST_LOCATION);
392 int UtcDaliPanGestureGetMaximumTouchesRequired(void)
394 TestApplication application;
396 PanGestureDetector detector = PanGestureDetector::New();
397 DALI_TEST_EQUALS(1u, detector.GetMaximumTouchesRequired(), TEST_LOCATION);
401 int UtcDaliPanGestureSignalReceptionNegative(void)
403 TestApplication application;
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 PanGestureDetector detector = PanGestureDetector::New();
418 detector.Attach(actor);
419 detector.DetectedSignal().Connect(&application, functor);
421 // Do a pan outside actor's area
423 TestStartPan( application, Vector2(110.0f, 110.0f), Vector2(121.0f, 121.0f), time );
425 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
427 // Continue pan into actor's area - we should still not receive the signal
429 TestMovePan( application, Vector2(20.0f, 20.0f), time );
431 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
433 // Stop panning - we should still not receive the signal
435 TestEndPan( application, Vector2(12.0f, 12.0f), time);
437 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
441 int UtcDaliPanGestureSignalReceptionDownMotionLeave(void)
443 TestApplication application;
445 Actor actor = Actor::New();
446 actor.SetSize(100.0f, 100.0f);
447 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
448 Stage::GetCurrent().Add(actor);
451 application.SendNotification();
452 application.Render();
455 GestureReceivedFunctor functor(data);
457 PanGestureDetector detector = PanGestureDetector::New();
458 detector.Attach(actor);
459 detector.DetectedSignal().Connect(&application, functor);
461 // Start pan within the actor's area
463 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
465 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
466 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
467 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
468 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
469 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
470 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
471 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
473 // Continue the pan within the actor's area - we should still receive the signal
476 TestMovePan( application, Vector2(26.0f, 4.0f), time );
477 time += TestGetFrameInterval();
479 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
480 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
481 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
482 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
483 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
484 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
485 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
487 // Pan Gesture leaves actor's area - we should still receive the signal
490 TestMovePan( application, Vector2(346.0f, 4.0f), time );
491 time += TestGetFrameInterval();
493 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
494 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
495 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
496 DALI_TEST_EQUALS(Vector2(320.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
497 DALI_TEST_EQUALS(Vector2(20.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
498 DALI_TEST_EQUALS(320.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
499 DALI_TEST_EQUALS(20.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
501 // Gesture ends - we would receive a finished state
504 TestEndPan( application, Vector2(314.0f, 4.0f), time );
506 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
507 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
508 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
509 DALI_TEST_EQUALS(Vector2(-32.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
510 DALI_TEST_EQUALS(Vector2(-2.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
511 DALI_TEST_EQUALS(32.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
512 DALI_TEST_EQUALS(2.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
516 int UtcDaliPanGestureSignalReceptionDownMotionUp(void)
518 TestApplication application;
520 Actor actor = Actor::New();
521 actor.SetSize(100.0f, 100.0f);
522 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
523 Stage::GetCurrent().Add(actor);
526 application.SendNotification();
527 application.Render();
530 GestureReceivedFunctor functor(data);
532 PanGestureDetector detector = PanGestureDetector::New();
533 detector.Attach(actor);
534 detector.DetectedSignal().Connect(&application, functor);
536 // Start pan within the actor's area
538 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
540 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
541 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
542 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
543 DALI_TEST_EQUALS(Vector2(16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
544 DALI_TEST_EQUALS(Vector2(0.5f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
545 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
546 DALI_TEST_EQUALS(0.5f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
548 // Continue the pan within the actor's area - we should still receive the signal
551 TestMovePan( application, Vector2(26.0f, 4.0f), time );
552 time += TestGetFrameInterval();
554 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
555 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
556 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
557 DALI_TEST_EQUALS(Vector2(0.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
558 DALI_TEST_EQUALS(Vector2(0.0f, -1.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
559 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
560 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
562 // Gesture ends within actor's area - we would receive a finished state
565 TestEndPan( application, Vector2(10.0f, 4.0f), time );
567 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
568 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
569 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
570 DALI_TEST_EQUALS(Vector2(-16.0f, 0.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION);
571 DALI_TEST_EQUALS(Vector2(-1.0f, 0.0f), data.receivedGesture.velocity, 0.01f, TEST_LOCATION);
572 DALI_TEST_EQUALS(16.0f, data.receivedGesture.GetDistance(), 0.01f, TEST_LOCATION);
573 DALI_TEST_EQUALS(1.0f, data.receivedGesture.GetSpeed(), 0.01f, TEST_LOCATION);
577 int UtcDaliPanGestureSignalReceptionDetach(void)
579 TestApplication application;
581 Actor actor = Actor::New();
582 actor.SetSize(100.0f, 100.0f);
583 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
584 Stage::GetCurrent().Add(actor);
587 application.SendNotification();
588 application.Render();
591 GestureReceivedFunctor functor(data);
593 PanGestureDetector detector = PanGestureDetector::New();
594 detector.Attach(actor);
595 detector.DetectedSignal().Connect(&application, functor);
597 // Start pan within the actor's area
599 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
600 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
602 // Continue the pan within the actor's area - we should still receive the signal
605 TestMovePan( application, Vector2(26.0f, 4.0f), time );
606 time += TestGetFrameInterval();
608 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
610 // Gesture ends within actor's area
613 TestEndPan( application, Vector2(10.0f, 4.0f), time );
614 time += TestGetFrameInterval();
616 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
619 detector.DetachAll();
621 // Ensure we are no longer signalled
624 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
625 TestMovePan( application, Vector2(26.0f, 4.0f), time );
626 time += TestGetFrameInterval();
627 TestEndPan( application, Vector2(10.0f, 4.0f), time );
629 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
633 int UtcDaliPanGestureSignalReceptionDetachWhilePanning(void)
635 TestApplication application;
637 Actor actor = Actor::New();
638 actor.SetSize(100.0f, 100.0f);
639 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
640 Stage::GetCurrent().Add(actor);
643 application.SendNotification();
644 application.Render();
647 GestureReceivedFunctor functor(data);
649 PanGestureDetector detector = PanGestureDetector::New();
650 detector.Attach(actor);
651 detector.DetectedSignal().Connect(&application, functor);
653 // Start pan within the actor's area
655 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
656 application.SendNotification();
658 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
660 // Continue the pan within the actor's area - we should still receive the signal
663 TestMovePan( application, Vector2(26.0f, 4.0f), time );
664 time += TestGetFrameInterval();
666 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
668 // Detach actor during the pan, we should not receive the next event
669 detector.DetachAll();
671 // Gesture ends within actor's area
674 TestEndPan( application, Vector2(10.0f, 4.0f), time );
676 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
680 int UtcDaliPanGestureSignalReceptionActorDestroyedWhilePanning(void)
682 TestApplication application;
685 GestureReceivedFunctor functor(data);
687 PanGestureDetector detector = PanGestureDetector::New();
688 detector.DetectedSignal().Connect(&application, functor);
690 // Attach a temporary actor to stop detector being removed from PanGestureProcessor when main actor
692 Actor tempActor = Actor::New();
693 tempActor.SetSize(100.0f, 100.0f);
694 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
695 Stage::GetCurrent().Add(tempActor);
696 detector.Attach(tempActor);
700 // Actor lifetime is scoped
702 Actor actor = Actor::New();
703 actor.SetSize(100.0f, 100.0f);
704 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
705 Stage::GetCurrent().Add(actor);
708 application.SendNotification();
709 application.Render();
711 detector.Attach(actor);
713 // Start pan within the actor's area
714 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
716 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
718 // Continue the pan within the actor's area - we should still receive the signal
721 TestMovePan( application, Vector2(26.0f, 4.0f), time );
722 time += TestGetFrameInterval();
724 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
726 // Remove the actor from stage and reset the data
727 Stage::GetCurrent().Remove(actor);
730 application.SendNotification();
731 application.Render();
734 // Actor should now have been destroyed
736 // Gesture ends within the area where the actor used to be
739 TestEndPan( application, Vector2(10.0f, 4.0f), time );
741 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
745 int UtcDaliPanGestureSignalReceptionRotatedActor(void)
747 TestApplication application;
749 Actor actor = Actor::New();
750 actor.SetSize(100.0f, 100.0f);
751 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
752 Stage::GetCurrent().Add(actor);
755 application.SendNotification();
756 application.Render();
759 GestureReceivedFunctor functor(data);
761 PanGestureDetector detector = PanGestureDetector::New();
762 detector.Attach(actor);
763 detector.DetectedSignal().Connect(&application, functor);
765 // Do an entire pan, only check finished value
767 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
771 TestEndPan( application, Vector2(25.0f, 28.0f), time );
773 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
774 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
776 // Rotate actor again and render a couple of times
777 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
778 application.SendNotification();
779 application.Render();
781 // Do an entire pan, only check finished value
782 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
786 TestEndPan( application, Vector2(25.0f, 28.0f), time );
788 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
789 DALI_TEST_EQUALS(Vector2(2.0f, -16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
791 // Rotate actor again and render a couple of times
792 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
793 application.SendNotification();
794 application.Render();
796 // Do an entire pan, only check finished value
797 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
801 TestEndPan( application, Vector2(25.0f, 28.0f), time );
803 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
804 DALI_TEST_EQUALS(Vector2(-16.0f, -2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
808 int UtcDaliPanGestureSignalReceptionChildHit(void)
810 TestApplication application;
812 Actor parent = Actor::New();
813 parent.SetSize(100.0f, 100.0f);
814 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
815 Stage::GetCurrent().Add(parent);
817 // Set child to completely cover parent.
818 // Change rotation of child to be different from parent so that we can check if our local coordinate
819 // conversion of the parent actor is correct.
820 Actor child = Actor::New();
821 child.SetSize(100.0f, 100.0f);
822 child.SetAnchorPoint(AnchorPoint::CENTER);
823 child.SetParentOrigin(ParentOrigin::CENTER);
824 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
827 TouchEventFunctor touchFunctor;
828 child.TouchedSignal().Connect(&application, touchFunctor);
831 application.SendNotification();
832 application.Render();
835 GestureReceivedFunctor functor(data);
837 PanGestureDetector detector = PanGestureDetector::New();
838 detector.Attach(parent);
839 detector.DetectedSignal().Connect(&application, functor);
841 // Do an entire pan, only check finished value - hits child area but parent should still receive it
843 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
847 TestEndPan( application, Vector2(25.0f, 28.0f), time );
849 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
850 DALI_TEST_EQUALS(true, parent == data.pannedActor, TEST_LOCATION);
851 DALI_TEST_EQUALS(Vector2(-2.0f, 16.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
853 // Attach child and generate same touch points to yield a different displacement
854 // (Also proves that you can detach and then re-attach another actor)
855 detector.Attach(child);
856 detector.Detach(parent);
858 // Do an entire pan, only check finished value
859 TestStartPan( application, Vector2( 11.0f, 12.0f ), Vector2( 27.0f, 12.0f ), time );
863 TestEndPan( application, Vector2(25.0f, 28.0f), time );
865 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
866 DALI_TEST_EQUALS(true, child == data.pannedActor, TEST_LOCATION);
867 DALI_TEST_EQUALS(Vector2(16.0f, 2.0f), data.receivedGesture.displacement, 0.01f, TEST_LOCATION); // Actor relative
871 int UtcDaliPanGestureSignalReceptionAttachDetachMany(void)
873 TestApplication application;
875 Actor first = Actor::New();
876 first.SetSize(100.0f, 100.0f);
877 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
878 Stage::GetCurrent().Add(first);
880 Actor second = Actor::New();
881 second.SetSize(100.0f, 100.0f);
883 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
884 Stage::GetCurrent().Add(second);
887 application.SendNotification();
888 application.Render();
891 GestureReceivedFunctor functor(data);
893 PanGestureDetector detector = PanGestureDetector::New();
894 detector.Attach(first);
895 detector.Attach(second);
896 detector.DetectedSignal().Connect(&application, functor);
898 DALI_TEST_EQUALS(Stage::GetCurrent().GetRootLayer(), first.GetParent(), TEST_LOCATION);
899 DALI_TEST_EQUALS(Stage::GetCurrent().GetRootLayer(), second.GetParent(), TEST_LOCATION);
901 // Start pan within second actor's area
903 TestStartPan( application, Vector2( 110.0f, 20.0f ), Vector2( 126.0f, 20.0f ), time );
905 DALI_TEST_EQUALS(Stage::GetCurrent().GetRootLayer(), first.GetParent(), TEST_LOCATION);
906 DALI_TEST_EQUALS(Stage::GetCurrent().GetRootLayer(), second.GetParent(), TEST_LOCATION);
908 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
909 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
911 // Pan moves into first actor's area - second actor should receive the pan
914 TestMovePan( application, Vector2(126.0f, 20.0f), time );
915 time += TestGetFrameInterval();
917 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
918 DALI_TEST_EQUALS(true, second == data.pannedActor, TEST_LOCATION);
920 // Detach the second actor during the pan, we should not receive the next event
921 detector.Detach(second);
923 // Gesture ends within actor's area
926 TestMovePan( application, Vector2(26.0f, 20.0f), time );
927 TestEndPan( application, Vector2(10.0f, 4.0f), time );
929 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
934 int UtcDaliPanGestureSignalReceptionActorBecomesUntouchable(void)
936 TestApplication application;
938 Actor actor = Actor::New();
939 actor.SetSize(100.0f, 100.0f);
940 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
941 Stage::GetCurrent().Add(actor);
944 application.SendNotification();
945 application.Render();
948 GestureReceivedFunctor functor(data);
950 PanGestureDetector detector = PanGestureDetector::New();
951 detector.Attach(actor);
952 detector.DetectedSignal().Connect(&application, functor);
954 // Start pan in actor's area
956 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
958 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
960 // Pan continues within actor's area
963 TestMovePan( application, Vector2(26.0f, 4.0f), time );
964 time += TestGetFrameInterval();
966 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
968 // Actor become invisible - actor should not receive the next pan
969 actor.SetVisible(false);
972 application.SendNotification();
973 application.Render();
975 // Gesture ends within actor's area
978 TestEndPan( application, Vector2(10.0f, 4.0f), time );
980 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
984 int UtcDaliPanGestureSignalReceptionMultipleDetectorsOnActor(void)
986 TestApplication application;
988 Actor actor = Actor::New();
989 actor.SetSize(100.0f, 100.0f);
990 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
991 Stage::GetCurrent().Add(actor);
993 Actor actor2 = Actor::New();
994 actor2.SetSize(100.0f, 100.0f);
995 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
996 Stage::GetCurrent().Add(actor2);
999 application.SendNotification();
1000 application.Render();
1002 // Attach actor to one detector
1003 SignalData firstData;
1004 GestureReceivedFunctor firstFunctor(firstData);
1005 PanGestureDetector firstDetector = PanGestureDetector::New();
1006 firstDetector.Attach(actor);
1007 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
1009 // Attach actor to another detector
1010 SignalData secondData;
1011 GestureReceivedFunctor secondFunctor(secondData);
1012 PanGestureDetector secondDetector = PanGestureDetector::New();
1013 secondDetector.Attach(actor);
1014 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
1016 // Add second actor to second detector, when we remove the actor, this will make sure that this
1017 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
1018 // functor should still not be called (which is what we're also testing).
1019 secondDetector.Attach(actor2);
1021 // Pan in actor's area - both detector's functors should be called
1022 uint32_t time = 100;
1023 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1025 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1026 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1028 // Pan continues in actor's area - both detector's functors should be called
1032 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1033 time += TestGetFrameInterval();
1035 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
1036 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1038 // Detach actor from firstDetector and emit pan on actor, only secondDetector's functor should be called.
1039 firstDetector.Detach(actor);
1043 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1045 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1046 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1048 // New pan on actor, only secondDetector has actor attached
1052 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1054 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1055 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1057 // Detach actor from secondDetector
1058 secondDetector.Detach(actor);
1062 TestMovePan( application, Vector2(10.0f, 20.0f), time );
1064 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
1065 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
1070 int UtcDaliPanGestureSignalReceptionEnsureCorrectSignalling(void)
1072 TestApplication application;
1074 Actor actor1 = Actor::New();
1075 actor1.SetSize(100.0f, 100.0f);
1076 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1077 Stage::GetCurrent().Add(actor1);
1079 GestureReceivedFunctor functor1(data1);
1080 PanGestureDetector detector1 = PanGestureDetector::New();
1081 detector1.Attach(actor1);
1082 detector1.DetectedSignal().Connect(&application, functor1);
1084 Actor actor2 = Actor::New();
1085 actor2.SetSize(100.0f, 100.0f);
1086 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
1087 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
1088 Stage::GetCurrent().Add(actor2);
1090 GestureReceivedFunctor functor2(data2);
1091 PanGestureDetector detector2 = PanGestureDetector::New();
1092 detector2.Attach(actor2);
1093 detector2.DetectedSignal().Connect(&application, functor2);
1095 // Render and notify
1096 application.SendNotification();
1097 application.Render();
1099 // Start pan in actor1's area, only data1 should be set
1100 uint32_t time = 100;
1101 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1103 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
1104 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
1108 int UtcDaliPanGestureSignalReceptionDifferentPossible(void)
1110 TestApplication application;
1112 Actor actor = Actor::New();
1113 actor.SetSize(100.0f, 100.0f);
1114 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1115 Stage::GetCurrent().Add(actor);
1117 // Render and notify
1118 application.SendNotification();
1119 application.Render();
1121 // Attach actor to detector
1123 GestureReceivedFunctor functor( data );
1124 PanGestureDetector detector = PanGestureDetector::New();
1125 detector.Attach(actor);
1126 detector.DetectedSignal().Connect( &application, functor );
1128 // Gesture possible in actor's area.
1129 // application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1130 uint32_t time = 100;
1131 TestStartLongPress( application, 10.0f, 20.0f, time );
1132 time += TestGetFrameInterval();
1134 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1136 // Move actor somewhere else
1137 actor.SetPosition( 100.0f, 100.0f );
1139 // Render and notify
1140 application.SendNotification();
1141 application.Render();
1143 // Emit Started event, we should not receive the long press.
1144 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1145 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1146 time += TestGetFrameInterval();
1148 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1150 // LongPress possible in empty area.
1151 TestStartLongPress( application, 10.0f, 20.0f, time );
1152 time += TestGetFrameInterval();
1154 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1156 // Move actor in to the long press position.
1157 actor.SetPosition( 0.0f, 0.0f );
1159 // Render and notify
1160 application.SendNotification();
1161 application.Render();
1163 // Emit Started event, we should not receive the long press.
1164 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1165 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1166 time += TestGetFrameInterval();
1168 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1170 // Normal long press in actor's area for completeness.
1171 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1172 TestEndPan( application, Vector2( 26.0f, 20.0f ), time );
1173 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1177 int UtcDaliPanGestureActorUnstaged(void)
1179 TestApplication application;
1181 Actor actor = Actor::New();
1182 actor.SetSize(100.0f, 100.0f);
1183 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1184 Stage::GetCurrent().Add(actor);
1186 // Render and notify
1187 application.SendNotification();
1188 application.Render();
1190 // State to remove actor in.
1191 Gesture::State stateToUnstage( Gesture::Started );
1193 // Attach actor to detector
1195 UnstageActorFunctor functor( data, stateToUnstage );
1196 PanGestureDetector detector = PanGestureDetector::New();
1197 detector.Attach(actor);
1198 detector.DetectedSignal().Connect( &application, functor );
1201 uint32_t time = 100;
1202 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1204 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1207 TestEndPan( application, Vector2(26.0f, 20.0f), time );
1209 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1212 // Render and notify
1213 application.SendNotification();
1214 application.Render();
1216 // Re-add actor to stage
1217 Stage::GetCurrent().Add(actor);
1219 // Render and notify
1220 application.SendNotification();
1221 application.Render();
1223 // Change state to Gesture::Continuing to remove
1224 stateToUnstage = Gesture::Continuing;
1227 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1229 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1232 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1233 time += TestGetFrameInterval();
1235 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1239 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1241 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1244 // Render and notify
1245 application.SendNotification();
1246 application.Render();
1248 // Re-add actor to stage
1249 Stage::GetCurrent().Add(actor);
1251 // Render and notify
1252 application.SendNotification();
1253 application.Render();
1255 // Change state to Gesture::Finished to remove
1256 stateToUnstage = Gesture::Finished;
1259 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1261 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1264 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1265 time += TestGetFrameInterval();
1267 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1270 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1272 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1273 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1277 int UtcDaliPanGestureActorStagedAndDestroyed(void)
1279 TestApplication application;
1281 Actor actor = Actor::New();
1282 actor.SetSize(100.0f, 100.0f);
1283 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1284 Stage::GetCurrent().Add(actor);
1286 // Create and add a second actor so that GestureDetector destruction does not come into play.
1287 Actor dummyActor( Actor::New() );
1288 dummyActor.SetSize( 100.0f, 100.0f );
1289 dummyActor.SetPosition( 100.0f, 100.0f );
1290 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1291 Stage::GetCurrent().Add(dummyActor);
1293 // Render and notify
1294 application.SendNotification();
1295 application.Render();
1297 // State to remove actor in.
1298 Gesture::State stateToUnstage( Gesture::Started );
1300 // Attach actor to detector
1302 UnstageActorFunctor functor( data, stateToUnstage );
1303 PanGestureDetector detector = PanGestureDetector::New();
1304 detector.Attach(actor);
1305 detector.Attach(dummyActor);
1306 detector.DetectedSignal().Connect( &application, functor );
1308 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1309 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1310 // position, we should still not be signalled.
1313 uint32_t time = 100;
1314 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1316 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1319 // Render and notify
1320 application.SendNotification();
1321 application.Render();
1323 // Re add to the stage, we should not be signalled
1324 Stage::GetCurrent().Add(actor);
1326 // Render and notify
1327 application.SendNotification();
1328 application.Render();
1330 // Continue signal emission
1331 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1332 time += TestGetFrameInterval();
1334 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1337 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1338 time += TestGetFrameInterval();
1340 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1343 // Here we delete an actor in started, we should not receive any subsequent signalling.
1346 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
1348 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1351 // Render and notify
1352 application.SendNotification();
1353 application.Render();
1355 // Delete actor as well
1358 // Render and notify
1359 application.SendNotification();
1360 application.Render();
1362 // Continue signal emission
1363 TestMovePan( application, Vector2(26.0f, 4.0f), time );
1364 time += TestGetFrameInterval();
1366 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1369 TestEndPan( application, Vector2(10.0f, 4.0f), time );
1371 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1375 int UtcDaliPanGestureAngleHandling(void)
1377 TestApplication application;
1379 PanGestureDetector detector = PanGestureDetector::New();
1380 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1382 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1383 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1385 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1387 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1389 tet_result( TET_PASS );
1397 tet_printf("%s, angle not added\n", TEST_LOCATION );
1398 tet_result( TET_FAIL );
1401 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Radian( Math::PI * 0.25 ) );
1402 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1404 // Remove something not in the container.
1405 detector.RemoveAngle( PanGestureDetector::DIRECTION_UP );
1406 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1408 detector.RemoveAngle( PanGestureDetector::DIRECTION_RIGHT );
1409 DALI_TEST_EQUALS( detector.GetAngleCount(), 1u, TEST_LOCATION );
1410 for ( size_t i = 0; i < detector.GetAngleCount(); i++)
1412 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1414 tet_printf("%s, angle not removed\n", TEST_LOCATION );
1415 tet_result( TET_FAIL );
1420 detector.ClearAngles();
1421 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1425 int UtcDaliPanGestureGetAngle(void)
1427 TestApplication application;
1429 PanGestureDetector detector = PanGestureDetector::New();
1430 DALI_TEST_EQUALS( detector.GetAngleCount(), 0, TEST_LOCATION );
1432 detector.AddAngle( PanGestureDetector::DIRECTION_LEFT );
1433 DALI_TEST_EQUALS( detector.GetAngleCount(), 1, TEST_LOCATION );
1435 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT );
1436 DALI_TEST_EQUALS( detector.GetAngleCount(), 2, TEST_LOCATION );
1438 detector.AddAngle( PanGestureDetector::DIRECTION_UP );
1439 DALI_TEST_EQUALS( detector.GetAngleCount(), 3, TEST_LOCATION );
1441 detector.AddAngle( PanGestureDetector::DIRECTION_DOWN );
1442 DALI_TEST_EQUALS( detector.GetAngleCount(), 4, TEST_LOCATION );
1444 DALI_TEST_EQUALS( detector.GetAngle(0).first, PanGestureDetector::DIRECTION_LEFT, TEST_LOCATION );
1445 DALI_TEST_EQUALS( detector.GetAngle(1).first, PanGestureDetector::DIRECTION_RIGHT, TEST_LOCATION );
1446 DALI_TEST_EQUALS( detector.GetAngle(2).first, PanGestureDetector::DIRECTION_UP, TEST_LOCATION );
1447 DALI_TEST_EQUALS( detector.GetAngle(3).first, PanGestureDetector::DIRECTION_DOWN, TEST_LOCATION );
1452 inline float RadiansToDegrees( float radian )
1454 return radian * 180.0f / Math::PI;
1457 int UtcDaliPanGestureAngleOutOfRange(void)
1459 TestApplication application;
1461 PanGestureDetector detector = PanGestureDetector::New();
1462 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1468 detector.AddAngle( Degree(180.0f) );
1469 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-180.0f) ), 0.000001, TEST_LOCATION );
1470 detector.ClearAngles();
1472 detector.AddAngle( Degree(190.0f) );
1473 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-170.0f) ), 0.000001, TEST_LOCATION );
1474 detector.ClearAngles();
1476 detector.AddAngle( Degree(-190.0f) );
1477 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(170.0f) ), 0.000001, TEST_LOCATION );
1478 detector.ClearAngles();
1480 detector.AddAngle( Degree(350.0f) );
1481 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1482 detector.ClearAngles();
1484 detector.AddAngle( Degree(-350.0f) );
1485 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1486 detector.ClearAngles();
1488 detector.AddAngle( Degree(370.0f) );
1489 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1490 detector.ClearAngles();
1492 detector.AddAngle( Degree(-370.0f) );
1493 DALI_TEST_EQUALS( detector.GetAngle(0).first, Radian( Degree(-10.0f) ), 0.000001, TEST_LOCATION );
1494 detector.ClearAngles();
1500 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 0.0f ) );
1501 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(0.0f) ), 0.000001, TEST_LOCATION );
1502 detector.ClearAngles();
1504 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -10.0f ) );
1505 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(10.0f) ), 0.000001, TEST_LOCATION );
1506 detector.ClearAngles();
1508 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( -181.0f ) );
1509 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1510 detector.ClearAngles();
1512 detector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 181.0f ) );
1513 DALI_TEST_EQUALS( detector.GetAngle(0).second, Radian( Degree(180.0f) ), 0.000001, TEST_LOCATION );
1514 detector.ClearAngles();
1518 int UtcDaliPanGestureAngleProcessing(void)
1520 TestApplication application;
1522 Actor parent = Actor::New();
1523 parent.SetSize(100.0f, 100.0f);
1524 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1525 Stage::GetCurrent().Add(parent);
1527 Actor child = Actor::New();
1528 child.SetSize(100.0f, 100.0f);
1529 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1532 // Render and notify
1533 application.SendNotification();
1534 application.Render();
1536 // Parent detector only requires up pans
1537 PanGestureDetector parentDetector = PanGestureDetector::New();
1538 parentDetector.Attach( parent );
1539 parentDetector.AddAngle( PanGestureDetector::DIRECTION_UP, Degree( 30.0f ) );
1540 SignalData parentData;
1541 GestureReceivedFunctor parentFunctor(parentData);
1542 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1544 // Child detector only requires right pans
1545 PanGestureDetector childDetector = PanGestureDetector::New();
1546 childDetector.Attach( child );
1547 childDetector.AddAngle( PanGestureDetector::DIRECTION_RIGHT, Degree( 30.0f ) );
1548 SignalData childData;
1549 GestureReceivedFunctor childFunctor(childData);
1550 childDetector.DetectedSignal().Connect(&application, childFunctor);
1552 // Generate an Up pan gesture, only parent should receive it.
1553 uint32_t time = 100;
1554 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1556 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1557 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1559 TestEndPan( application, Vector2(20.0f, 4.0f), time );
1560 time += TestGetFrameInterval();
1564 // Generate a Right pan gesture, only child should receive it.
1565 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1567 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1568 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1570 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1571 time += TestGetFrameInterval();
1575 // Generate a Down pan gesture, no one should receive it.
1576 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1578 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1579 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1581 TestEndPan( application, Vector2(20.0f, 36.0f), time );
1582 time += TestGetFrameInterval();
1586 // Generate a Left pan gesture, no one should receive it.
1587 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1589 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1590 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1592 TestEndPan( application, Vector2(4.0f, 20.0f), time );
1598 int UtcDaliPanGestureDirectionHandling(void)
1600 TestApplication application;
1602 PanGestureDetector detector = PanGestureDetector::New();
1603 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1605 detector.AddDirection( PanGestureDetector::DIRECTION_LEFT, Radian( Math::PI * 0.25 ) );
1606 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1608 for ( size_t i = 0; detector.GetAngleCount(); i++)
1610 if ( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_LEFT )
1612 tet_result( TET_PASS );
1621 tet_printf("%s, angle not added\n", TEST_LOCATION );
1622 tet_result( TET_FAIL );
1626 for( size_t i = 0; i < detector.GetAngleCount(); i++)
1628 if( detector.GetAngle(i).first == PanGestureDetector::DIRECTION_RIGHT )
1630 tet_result( TET_PASS );
1638 tet_printf("%s, angle not added\n", TEST_LOCATION );
1639 tet_result( TET_FAIL );
1642 // Remove something not in the container.
1643 detector.RemoveDirection( PanGestureDetector::DIRECTION_UP );
1644 DALI_TEST_EQUALS( detector.GetAngleCount(), 2u, TEST_LOCATION );
1646 detector.RemoveDirection( PanGestureDetector::DIRECTION_RIGHT );
1647 DALI_TEST_EQUALS( detector.GetAngleCount(), 0u, TEST_LOCATION );
1651 int UtcDaliPanGestureDirectionProcessing(void)
1653 TestApplication application;
1655 Actor parent = Actor::New();
1656 parent.SetSize(100.0f, 100.0f);
1657 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1658 Stage::GetCurrent().Add(parent);
1660 Actor child = Actor::New();
1661 child.SetSize(100.0f, 100.0f);
1662 child.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1665 // Render and notify
1666 application.SendNotification();
1667 application.Render();
1669 // Parent detector only requires vertical panning
1670 PanGestureDetector parentDetector = PanGestureDetector::New();
1671 parentDetector.Attach( parent );
1672 parentDetector.AddDirection( PanGestureDetector::DIRECTION_VERTICAL, Degree( 30.0f ) );
1673 SignalData parentData;
1674 GestureReceivedFunctor parentFunctor(parentData);
1675 parentDetector.DetectedSignal().Connect(&application, parentFunctor);
1677 // Child detector only requires horizontal panning
1678 PanGestureDetector childDetector = PanGestureDetector::New();
1679 childDetector.Attach( child );
1680 childDetector.AddDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 30.0f ) );
1681 SignalData childData;
1682 GestureReceivedFunctor childFunctor(childData);
1683 childDetector.DetectedSignal().Connect(&application, childFunctor);
1685 // Generate an Up pan gesture, only parent should receive it.
1686 uint32_t time = 100;
1687 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 4.0f ), time );
1689 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1690 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1692 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1693 time += TestGetFrameInterval();
1697 // Generate a Right pan gesture, only child should receive it.
1698 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 36.0f, 20.0f ), time );
1700 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1701 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1703 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1704 time += TestGetFrameInterval();
1708 // Generate a Down pan gesture, only parent should receive it.
1709 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 20.0f, 36.0f ), time );
1711 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1712 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1714 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1715 time += TestGetFrameInterval();
1719 // Generate a Left pan gesture, only child should receive it.
1720 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 20.0f ), time );
1722 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1723 DALI_TEST_EQUALS( true, childData.functorCalled, TEST_LOCATION );
1725 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1726 time += TestGetFrameInterval();
1730 // Generate a pan at -45 degrees, no one should receive it.
1731 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 9.0f, 31.0f ), time );
1733 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1734 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1736 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1737 time += TestGetFrameInterval();
1741 // Generate a pan at 45 degrees, no one should receive it.
1742 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 31.0f, 31.0f ), time );
1744 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1745 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1747 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1748 time += TestGetFrameInterval();
1752 // Generate a pan at -135 degrees, no one should receive it.
1753 TestStartPan( application, Vector2( 20.0f, 20.0f ), Vector2( 4.0f, 4.0f ), time );
1755 DALI_TEST_EQUALS( false, parentData.functorCalled, TEST_LOCATION );
1756 DALI_TEST_EQUALS( false, childData.functorCalled, TEST_LOCATION );
1758 TestEndPan( application, Vector2(20.0f, 20.0f), time );
1764 int UtcDaliPanGestureNoPredictionNoSmoothing(void)
1766 TestApplication application;
1767 Integration::SetPanGesturePredictionMode(0);
1768 Integration::SetPanGestureSmoothingMode(0);
1770 Actor actor = Actor::New();
1771 actor.SetSize(100.0f, 100.0f);
1772 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1773 Stage::GetCurrent().Add(actor);
1775 // Add a pan detector
1776 PanGestureDetector detector = PanGestureDetector::New();
1777 detector.Attach( actor );
1779 GestureReceivedFunctor functor( data );
1780 detector.DetectedSignal().Connect( &application, functor );
1782 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1784 ConstraintData constraintData;
1785 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1786 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1787 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1788 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1789 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1790 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1791 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1792 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1795 // Render and notify
1796 application.SendNotification();
1797 application.Render();
1799 Vector2 startPosition( 1.0f, 1.0f );
1800 Vector2 position( -14.0f, 1.0f );
1801 Vector2 direction(Vector2::XAXIS * -5.0f);
1802 uint32_t time = 100;
1804 TestStartPan( application, startPosition, position, time );
1806 for(int i = 0; i < 47; i++ )
1808 position += direction;
1809 TestMovePan( application, position, time );
1810 time += TestGetFrameInterval();
1811 application.SendNotification();
1812 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1815 TestEndPan( application, position, time );
1816 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1818 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1819 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1820 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1821 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * PAN_GESTURE_UPDATE_COUNT), 0.1f, TEST_LOCATION );
1823 constraintData.Reset();
1827 int UtcDaliPanGestureNoPredictionSmoothing(void)
1829 TestApplication application;
1830 Integration::SetPanGesturePredictionMode(0);
1831 Integration::SetPanGestureSmoothingMode(1);
1833 Actor actor = Actor::New();
1834 actor.SetSize(100.0f, 100.0f);
1835 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1836 Stage::GetCurrent().Add(actor);
1838 // Add a pan detector
1839 PanGestureDetector detector = PanGestureDetector::New();
1840 detector.Attach( actor );
1842 GestureReceivedFunctor functor( data );
1843 detector.DetectedSignal().Connect( &application, functor );
1845 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1847 ConstraintData constraintData;
1848 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1849 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1850 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1851 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1852 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1853 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1854 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1855 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1858 // Render and notify
1859 application.SendNotification();
1860 application.Render();
1862 Vector2 startPosition( 1.0f, 1.0f );
1863 Vector2 position( -14.0f, 1.0f );
1864 Vector2 direction(Vector2::XAXIS * -5.0f);
1865 uint32_t time = 100;
1867 TestStartPan( application, startPosition, position, time );
1869 for(int i = 0; i < 47; i++ )
1871 position += direction;
1872 TestMovePan( application, position, time );
1873 time += TestGetFrameInterval();
1874 application.SendNotification();
1875 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1878 TestEndPan( application, position, time );
1879 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1881 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1882 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1883 // Take into account resampling done when prediction is off.
1884 DALI_TEST_EQUALS( constraintData.screenPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
1885 DALI_TEST_EQUALS( constraintData.localPosition, startPosition + (direction * (PAN_GESTURE_UPDATE_COUNT - 0.25f)), 0.15f, TEST_LOCATION );
1887 constraintData.Reset();
1891 int UtcDaliPanGesturePredictionNoSmoothing(void)
1893 TestApplication application;
1894 Integration::SetPanGesturePredictionMode(1);
1895 Integration::SetPanGestureSmoothingMode(0);
1897 Actor actor = Actor::New();
1898 actor.SetSize(100.0f, 100.0f);
1899 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1900 Stage::GetCurrent().Add(actor);
1902 // Add a pan detector
1903 PanGestureDetector detector = PanGestureDetector::New();
1904 detector.Attach( actor );
1906 GestureReceivedFunctor functor( data );
1907 detector.DetectedSignal().Connect( &application, functor );
1909 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1911 ConstraintData constraintData;
1912 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1913 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1914 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1915 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1916 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1917 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1918 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1919 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1922 // Render and notify
1923 application.SendNotification();
1924 application.Render();
1926 Vector2 startPosition( 1.0f, 1.0f );
1927 Vector2 position( -1.0f, 1.0f );
1928 Vector2 direction(Vector2::XAXIS * -1.0f);
1929 uint32_t time = 100;
1931 TestStartPan( application, startPosition, position, time );
1933 for(int i = 0; i < 47; i++ )
1935 position += direction;
1936 TestMovePan( application, position, time );
1937 time += TestGetFrameInterval();
1938 application.SendNotification();
1939 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1942 TestEndPan( application, position, time );
1943 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
1945 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1946 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
1947 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
1948 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
1950 constraintData.Reset();
1954 int UtcDaliPanGesturePredictionSmoothing01(void)
1956 TestApplication application;
1957 Integration::SetPanGesturePredictionMode(1);
1958 Integration::SetPanGestureSmoothingMode(1);
1960 Actor actor = Actor::New();
1961 actor.SetSize(100.0f, 100.0f);
1962 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1963 Stage::GetCurrent().Add(actor);
1965 // Add a pan detector
1966 PanGestureDetector detector = PanGestureDetector::New();
1967 detector.Attach( actor );
1969 GestureReceivedFunctor functor( data );
1970 detector.DetectedSignal().Connect( &application, functor );
1972 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
1974 ConstraintData constraintData;
1975 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
1976 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
1977 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
1978 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
1979 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
1980 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
1981 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
1982 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
1985 // Render and notify
1986 application.SendNotification();
1987 application.Render();
1989 Vector2 startPosition( 1.0f, 1.0f );
1990 Vector2 position( -1.0f, 1.0f );
1991 Vector2 direction(Vector2::XAXIS * -1.0f);
1992 uint32_t time = 100;
1994 TestStartPan( application, startPosition, position, time );
1996 for(int i = 0; i < 47; i++ )
1998 position += direction;
1999 TestMovePan( application, position, time );
2000 time += TestGetFrameInterval();
2001 application.SendNotification();
2002 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2005 TestEndPan( application, position, time );
2006 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2008 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2009 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2010 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2011 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(1.0f, 1.0f) + (direction * PAN_GESTURE_UPDATE_COUNT), 10.0f, TEST_LOCATION );
2013 constraintData.Reset();
2017 int UtcDaliPanGesturePredictionSmoothing02(void)
2019 TestApplication application;
2020 Integration::SetPanGesturePredictionMode( 1 );
2021 Integration::SetPanGestureMaximumPredictionAmount( 1 );
2022 Integration::SetPanGesturePredictionAmountAdjustment( 2 );
2023 Integration::SetPanGestureSmoothingMode( 1 );
2024 Integration::SetPanGestureSmoothingAmount( 0.25f );
2026 Actor actor = Actor::New();
2027 actor.SetSize(100.0f, 100.0f);
2028 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2029 Stage::GetCurrent().Add(actor);
2031 // Add a pan detector
2032 PanGestureDetector detector = PanGestureDetector::New();
2033 detector.Attach( actor );
2035 GestureReceivedFunctor functor( data );
2036 detector.DetectedSignal().Connect( &application, functor );
2038 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2040 ConstraintData constraintData;
2041 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2042 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2043 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2044 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2045 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2046 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2047 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2048 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2051 // Render and notify
2052 application.SendNotification();
2053 application.Render();
2055 Vector2 startPosition( 2.0f, 2.0f );
2056 Vector2 position( 4.0f, 2.0f );
2057 Vector2 directionX(Vector2::XAXIS);
2058 Vector2 directionY(Vector2::YAXIS);
2059 uint32_t time = 100;
2061 TestStartPan( application, startPosition, position, time );
2063 for(int i = 0; i < 7; i++ )
2065 position += directionX;
2066 TestMovePan( application, position, time );
2067 time += TestGetFrameInterval();
2068 application.SendNotification();
2069 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2072 position += directionX * 10.0f;
2073 TestMovePan( application, position, time );
2074 time += TestGetFrameInterval();
2075 application.SendNotification();
2076 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2078 for(int i = 0; i < 2; i++ )
2080 position += ( directionX * -1.0f );
2081 TestMovePan( application, position, time );
2082 time += TestGetFrameInterval();
2083 application.SendNotification();
2084 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2087 for(int i = 0; i < 10; i++ )
2089 position += directionX;
2090 TestMovePan( application, position, time );
2091 time += TestGetFrameInterval();
2092 application.SendNotification();
2093 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2096 for(int i = 0; i < 10; i++ )
2098 position += directionY;
2099 TestMovePan( application, position, time );
2100 time += TestGetFrameInterval();
2101 application.SendNotification();
2102 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2105 TestEndPan( application, position, time );
2106 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2108 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2109 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2110 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2111 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2113 constraintData.Reset();
2117 int UtcDaliPanGesturePrediction2SmoothingMultiTap01(void)
2119 TestApplication application;
2121 Integration::SetPanGesturePredictionMode( 2 );
2122 Integration::SetPanGesturePredictionAmount( 57 );
2123 Integration::SetPanGestureSmoothingMode( 2 );
2124 Integration::SetPanGestureUseActualTimes( false );
2125 Integration::SetPanGestureInterpolationTimeRange( 10 );
2126 Integration::SetPanGestureScalarOnlyPredictionEnabled( false );
2127 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2128 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2129 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2130 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2131 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2133 Actor actor = Actor::New();
2134 actor.SetSize(100.0f, 100.0f);
2135 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2136 Stage::GetCurrent().Add(actor);
2138 // Add a pan detector
2139 PanGestureDetector detector = PanGestureDetector::New();
2140 detector.Attach( actor );
2142 GestureReceivedFunctor functor( data );
2143 detector.DetectedSignal().Connect( &application, functor );
2145 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2147 ConstraintData constraintData;
2148 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2149 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2150 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2151 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2152 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2153 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2154 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2155 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2158 // Render and notify
2159 application.SendNotification();
2160 application.Render();
2162 Vector2 startPosition( 2.0f, 2.0f );
2163 Vector2 position( -1.0f, 2.0f );
2164 Vector2 direction(Vector2::XAXIS * -1.0f);
2165 uint32_t time = 100;
2167 TestStartPan( application, startPosition, position, time );
2169 for(int i = 0; i < 27; i++ )
2171 position += direction;
2172 TestMovePan( application, position, time );
2173 time += TestGetFrameInterval();
2174 application.SendNotification();
2175 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2178 TestEndPan( application, position, time );
2179 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2181 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2182 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2183 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2184 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2186 constraintData.Reset();
2190 int UtcDaliPanGesturePrediction2SmoothingMultiTap02(void)
2192 TestApplication application;
2194 Integration::SetPanGesturePredictionMode( 2 );
2195 Integration::SetPanGestureSmoothingMode( 2 );
2196 Integration::SetPanGestureUseActualTimes( true );
2197 Integration::SetPanGestureInterpolationTimeRange( 10 );
2198 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2199 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2200 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2201 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2202 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2203 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2205 Integration::EnableProfiling( Integration::PROFILING_TYPE_PAN_GESTURE );
2207 Actor actor = Actor::New();
2208 actor.SetSize(100.0f, 100.0f);
2209 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2210 Stage::GetCurrent().Add(actor);
2212 // Add a pan detector
2213 PanGestureDetector detector = PanGestureDetector::New();
2214 detector.Attach( actor );
2216 GestureReceivedFunctor functor( data );
2217 detector.DetectedSignal().Connect( &application, functor );
2219 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2221 ConstraintData constraintData;
2222 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2223 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2224 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2225 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2226 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2227 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2228 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2229 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2232 // Render and notify
2233 application.SendNotification();
2234 application.Render();
2236 Vector2 startPosition( 2.0f, 2.0f );
2237 Vector2 position( 17.0f, 2.0f );
2238 Vector2 direction(Vector2::XAXIS * -1.0f);
2239 uint32_t time = 100;
2241 TestStartPan( application, startPosition, position, time );
2243 for(int i = 0; i < 10; i++ )
2245 position += direction;
2246 TestMovePan( application, position, time );
2247 time += TestGetFrameInterval();
2249 position += direction;
2250 TestMovePan( application, position, time );
2251 time += TestGetFrameInterval();
2253 position += direction;
2254 TestMovePan( application, position, time );
2255 time += TestGetFrameInterval();
2257 application.SendNotification();
2258 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2261 for(int i = 0; i < 10; i++ )
2263 application.SendNotification();
2264 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2267 for(int i = 0; i < 10; i++ )
2269 position += direction;
2270 TestMovePan( application, position, time );
2271 application.SendNotification();
2272 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2275 for(int i = 0; i < 10; i++ )
2277 position += direction;
2278 TestMovePan( application, position, time );
2279 time += TestGetFrameInterval();
2280 application.SendNotification();
2281 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2284 TestEndPan( application, position, time );
2285 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2287 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2288 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2289 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2290 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2292 constraintData.Reset();
2296 int UtcDaliPanGesturePrediction2Smoothing(void)
2298 TestApplication application;
2300 Integration::SetPanGesturePredictionMode( 2 );
2301 Integration::SetPanGesturePredictionAmount( 57 );
2302 Integration::SetPanGestureSmoothingMode( 1 );
2303 Integration::SetPanGestureUseActualTimes( false );
2304 Integration::SetPanGestureInterpolationTimeRange( 10 );
2305 Integration::SetPanGestureScalarOnlyPredictionEnabled( true );
2306 Integration::SetPanGestureTwoPointPredictionEnabled( true );
2307 Integration::SetPanGestureTwoPointInterpolatePastTime( 42 );
2308 Integration::SetPanGestureTwoPointVelocityBias( 0.35f );
2309 Integration::SetPanGestureTwoPointAccelerationBias( 0.10f );
2310 Integration::SetPanGestureMultitapSmoothingRange( 34 );
2312 Actor actor = Actor::New();
2313 actor.SetSize(100.0f, 100.0f);
2314 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2315 Stage::GetCurrent().Add(actor);
2317 // Add a pan detector
2318 PanGestureDetector detector = PanGestureDetector::New();
2319 detector.Attach( actor );
2321 GestureReceivedFunctor functor( data );
2322 detector.DetectedSignal().Connect( &application, functor );
2324 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2326 ConstraintData constraintData;
2327 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2328 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2329 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2330 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2331 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2332 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2333 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2334 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2337 // Render and notify
2338 application.SendNotification();
2339 application.Render();
2341 Vector2 startPosition( 2.0f, 2.0f );
2342 Vector2 position( 17.0f, 2.0f );
2343 Vector2 direction(Vector2::XAXIS * -1.0f);
2344 uint32_t time = 100;
2346 TestStartPan( application, startPosition, position, time );
2348 for(int i = 0; i < 10; i++ )
2350 position += direction;
2351 TestMovePan( application, position, time );
2352 time += TestGetFrameInterval();
2353 application.SendNotification();
2354 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2358 position += direction;
2359 TestMovePan( application, position, time );
2360 time += TestGetFrameInterval();
2362 position += direction;
2363 TestMovePan( application, position, time );
2364 time += TestGetFrameInterval();
2366 position += direction;
2367 TestMovePan( application, position, time );
2368 time += TestGetFrameInterval();
2370 application.SendNotification();
2371 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2373 for(int i = 0; i < 5; i++ )
2375 application.SendNotification();
2376 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2379 for(int i = 0; i < 10; i++ )
2381 position += direction;
2382 TestMovePan( application, position, time );
2383 time += TestGetFrameInterval();
2384 application.SendNotification();
2385 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2388 TestEndPan( application, position, time );
2389 application.Render(TestApplication::DEFAULT_RENDER_INTERVAL);
2391 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2392 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2393 DALI_TEST_EQUALS( constraintData.screenPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2394 DALI_TEST_EQUALS( constraintData.localPosition, Vector2(2.0f, 2.0f) + position, 10.0f, TEST_LOCATION );
2396 constraintData.Reset();
2400 int UtcDaliPanGestureSetProperties(void)
2402 TestApplication application;
2403 TestRenderController& renderController( application.GetRenderController() );
2404 Integration::SetPanGesturePredictionMode(0);
2405 Integration::SetPanGestureSmoothingMode(0);
2407 Actor actor = Actor::New();
2408 actor.SetSize(100.0f, 100.0f);
2409 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2410 Stage::GetCurrent().Add(actor);
2412 // Add a pan detector
2413 PanGestureDetector detector = PanGestureDetector::New();
2414 detector.Attach( actor );
2416 GestureReceivedFunctor functor( data );
2417 detector.DetectedSignal().Connect( &application, functor );
2419 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2420 Property::Index animatableGestureProperty = detector.RegisterProperty( "Dummy Property", Vector3::ZERO ); // For code coverage
2422 ConstraintData constraintData;
2423 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2424 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2425 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2426 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2427 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2428 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2429 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2430 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2431 constraint.AddSource( Source( detector, animatableGestureProperty ) );
2434 // Render and notify
2435 application.SendNotification();
2436 application.Render();
2438 renderController.Initialize();
2439 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), false, TEST_LOCATION );
2441 Vector2 screenPosition( 20.0f, 20.0f );
2442 Vector2 screenDisplacement( 1.0f, 1.0f );
2443 Vector2 screenVelocity( 1.3f, 4.0f );
2444 Vector2 localPosition( 21.0f, 21.0f );
2445 Vector2 localDisplacement( 0.5f, 0.5f );
2446 Vector2 localVelocity( 1.5f, 2.5f );
2448 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
2449 DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
2451 // Render and notify
2452 application.SendNotification();
2453 application.Render();
2455 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2456 DALI_TEST_EQUALS( constraintData.screenPosition, screenPosition, TEST_LOCATION );
2457 DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
2458 DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
2459 DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
2460 DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
2461 DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
2462 constraintData.Reset();
2466 int UtcDaliPanGestureSetPropertiesAlreadyPanning(void)
2468 TestApplication application;
2469 Integration::SetPanGesturePredictionMode(0);
2471 Actor actor = Actor::New();
2472 actor.SetSize(100.0f, 100.0f);
2473 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2474 Stage::GetCurrent().Add(actor);
2476 // Add a pan detector
2477 PanGestureDetector detector = PanGestureDetector::New();
2478 detector.Attach( actor );
2480 GestureReceivedFunctor functor( data );
2481 detector.DetectedSignal().Connect( &application, functor );
2483 Property::Index property = actor.RegisterProperty( "Dummy Property", Vector3::ZERO );
2485 ConstraintData constraintData;
2486 Constraint constraint = Constraint::New<Vector3>( actor, property, PanConstraint( constraintData ) );
2487 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_POSITION ) );
2488 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_DISPLACEMENT ) );
2489 constraint.AddSource( Source( detector, PanGestureDetector::Property::SCREEN_VELOCITY ) );
2490 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_POSITION ) );
2491 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_DISPLACEMENT ) );
2492 constraint.AddSource( Source( detector, PanGestureDetector::Property::LOCAL_VELOCITY ) );
2493 constraint.AddSource( Source( detector, PanGestureDetector::Property::PANNING ) );
2496 // Render and notify
2497 application.SendNotification();
2498 application.Render();
2500 Vector2 currentPosition( 20.0f, 4.0f );
2501 uint32_t time = 100;
2502 TestStartPan( application, Vector2( 20.0f, 20.0f ), currentPosition, time );
2503 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2505 Vector2 screenPosition( 100.0f, 20.0f );
2506 Vector2 localPosition( 110.0f, 110.0f );
2508 PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition ) );
2510 // Render and notify
2511 application.SendNotification();
2512 application.Render();
2514 DALI_TEST_EQUALS( constraintData.called, true, TEST_LOCATION );
2515 DALI_TEST_EQUALS( constraintData.screenPosition, currentPosition, 0.1, TEST_LOCATION );
2516 DALI_TEST_EQUALS( constraintData.localPosition, currentPosition, 0.1f, TEST_LOCATION );
2517 constraintData.Reset();
2521 int UtcDaliPanGesturePropertyIndices(void)
2523 TestApplication application;
2524 PanGestureDetector detector = PanGestureDetector::New();
2526 Property::IndexContainer indices;
2527 detector.GetPropertyIndices( indices );
2528 DALI_TEST_CHECK( indices.Size() );
2529 DALI_TEST_EQUALS( indices.Size(), detector.GetPropertyCount(), TEST_LOCATION );
2535 struct PropertyStringIndex
2537 const char * const name;
2538 const Property::Index index;
2539 const Property::Type type;
2540 const Property::Value value;
2543 const PropertyStringIndex PROPERTY_TABLE[] =
2545 { "screenPosition", PanGestureDetector::Property::SCREEN_POSITION, Property::VECTOR2, Vector2::ZERO },
2546 { "screenDisplacement", PanGestureDetector::Property::SCREEN_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2547 { "screenVelocity", PanGestureDetector::Property::SCREEN_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2548 { "localPosition", PanGestureDetector::Property::LOCAL_POSITION, Property::VECTOR2, Vector2::ZERO },
2549 { "localDisplacement", PanGestureDetector::Property::LOCAL_DISPLACEMENT, Property::VECTOR2, Vector2::ZERO },
2550 { "localVelocity", PanGestureDetector::Property::LOCAL_VELOCITY, Property::VECTOR2, Vector2::ZERO },
2551 { "panning", PanGestureDetector::Property::PANNING, Property::BOOLEAN, false },
2553 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
2554 } // unnamed namespace
2557 int UtcDaliPanGestureProperties(void)
2559 TestApplication application;
2560 PanGestureDetector detector = PanGestureDetector::New();
2562 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2564 DALI_TEST_EQUALS( detector.GetPropertyName( PROPERTY_TABLE[ i ].index ), std::string( PROPERTY_TABLE[ i ].name ), TEST_LOCATION );
2565 DALI_TEST_EQUALS( detector.GetPropertyIndex( PROPERTY_TABLE[ i ].name ), PROPERTY_TABLE[ i ].index, TEST_LOCATION );
2566 DALI_TEST_EQUALS( detector.GetPropertyType( PROPERTY_TABLE[ i ].index ), PROPERTY_TABLE[ i ].type, TEST_LOCATION );
2567 DALI_TEST_EQUALS( detector.IsPropertyWritable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2568 DALI_TEST_EQUALS( detector.IsPropertyAnimatable( PROPERTY_TABLE[ i ].index ), false, TEST_LOCATION );
2569 DALI_TEST_EQUALS( detector.IsPropertyAConstraintInput( PROPERTY_TABLE[ i ].index ), true, TEST_LOCATION );
2570 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2576 int UtcDaliPanGestureGetProperty(void)
2578 TestApplication application;
2579 PanGestureDetector detector = PanGestureDetector::New();
2581 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2583 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2585 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2586 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2588 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2590 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2591 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2598 int UtcDaliPanGestureGetPropertyWithSceneObject(void)
2600 TestApplication application;
2602 Actor actor = Actor::New();
2603 actor.SetSize(100.0f, 100.0f);
2604 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2605 Stage::GetCurrent().Add(actor);
2607 // Add a pan detector
2608 PanGestureDetector detector = PanGestureDetector::New();
2609 detector.Attach( actor );
2611 // Render and notify
2612 application.SendNotification();
2613 application.Render();
2615 for( unsigned int i = 0; i < PROPERTY_TABLE_COUNT; ++i )
2617 detector.SetProperty( PROPERTY_TABLE[ i ].index, Property::Value() ); // Just for Coverage
2619 if( PROPERTY_TABLE[ i ].type == Property::VECTOR2 )
2621 bool value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< bool >();
2622 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< bool >(), value, TEST_LOCATION );
2624 else if( PROPERTY_TABLE[ i ].type == Property::BOOLEAN )
2626 Vector2 value = detector.GetProperty( PROPERTY_TABLE[ i ].index ).Get< Vector2 >();
2627 DALI_TEST_EQUALS( PROPERTY_TABLE[ i ].value.Get< Vector2 >(), value, TEST_LOCATION );
2634 int UtcDaliPanGestureLayerConsumesTouch(void)
2636 TestApplication application;
2638 Actor actor = Actor::New();
2639 actor.SetSize(100.0f, 100.0f);
2640 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2641 Stage::GetCurrent().Add(actor);
2643 // Add a pan detector
2644 PanGestureDetector detector = PanGestureDetector::New();
2645 detector.Attach( actor );
2647 GestureReceivedFunctor functor( data );
2648 detector.DetectedSignal().Connect( &application, functor );
2650 // Add a layer to overlap the actor
2651 Layer layer = Layer::New();
2652 layer.SetSize(100.0f, 100.0f);
2653 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2654 Stage::GetCurrent().Add( layer );
2657 // Render and notify
2658 application.SendNotification();
2659 application.Render();
2661 // Emit signals, should receive
2662 uint32_t time = 100;
2663 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2664 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2665 time += TestGetFrameInterval();
2667 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2670 // Set layer to consume all touch
2671 layer.SetTouchConsumed( true );
2673 // Render and notify
2674 application.SendNotification();
2675 application.Render();
2677 // Emit the same signals again, should not receive
2678 TestStartPan( application, Vector2( 10.0f, 20.0f ), Vector2( 26.0f, 20.0f ), time );
2679 TestEndPan( application, Vector2(26.0f, 20.0f), time );
2681 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2687 int UtcDaliPanGestureNoTimeDiff(void)
2689 TestApplication application;
2691 Actor actor = Actor::New();
2692 actor.SetSize(100.0f, 100.0f);
2693 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2694 Stage::GetCurrent().Add(actor);
2696 // Add a pan detector
2697 PanGestureDetector detector = PanGestureDetector::New();
2698 detector.Attach( actor );
2700 GestureReceivedFunctor functor( data );
2701 detector.DetectedSignal().Connect( &application, functor );
2703 // Render and notify
2704 application.SendNotification();
2705 application.Render();
2707 // As normal helper function adds intervals between presses we must generate the sequence
2708 // using other helper functions
2709 TestStartLongPress( application, 10.0f, 20.0f, 100 ); // Used to send a down press event
2710 TestMovePan( application, Vector2(26.0f, 20.0f), 100 );
2711 TestMovePan( application, Vector2(26.0f, 20.0f), 100 ); // 2 motions required to trigger
2712 TestEndPan( application, Vector2(26.0f, 20.0f), 100 );
2714 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2715 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.x ) );
2716 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.velocity.y ) );
2717 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.x ) );
2718 DALI_TEST_CHECK( !std::isinf( data.receivedGesture.screenVelocity.y ) );