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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/events/tap-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali/integration-api/render-task-list-integ.h>
26 #include <dali-test-suite-utils.h>
27 #include <test-touch-utils.h>
31 void utc_dali_tap_gesture_detector_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_tap_gesture_detector_cleanup(void)
38 test_return_value = TET_PASS;
41 ///////////////////////////////////////////////////////////////////////////////
45 // Stores data that is populated in the callback and will be read by the TET cases
49 : functorCalled(false),
50 voidFunctorCalled(false)
55 functorCalled = false;
56 voidFunctorCalled = false;
58 receivedGesture.numberOfTaps = 0u;
59 receivedGesture.numberOfTouches = 0u;
60 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
61 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
67 bool voidFunctorCalled;
68 TapGesture receivedGesture;
72 // Functor that sets the data when called
73 struct GestureReceivedFunctor
75 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
77 void operator()(Actor actor, const TapGesture& tap)
79 signalData.functorCalled = true;
80 signalData.receivedGesture = tap;
81 signalData.tappedActor = actor;
86 signalData.voidFunctorCalled = true;
89 SignalData& signalData;
92 // Functor that removes the gestured actor from stage
93 struct UnstageActorFunctor : public GestureReceivedFunctor
95 UnstageActorFunctor( SignalData& data ) : GestureReceivedFunctor( data ) { }
97 void operator()(Actor actor, const TapGesture& tap)
99 GestureReceivedFunctor::operator()( actor, tap );
100 Stage::GetCurrent().Remove( actor );
104 // Functor for receiving a touch event
105 struct TouchEventFunctor
107 bool operator()(Actor actor, const TouchEvent& touch)
110 unsigned int points = touch.GetPointCount();
113 const TouchPoint& touchPoint = touch.GetPoint(0);
114 tet_printf("Touch Point state = %d\n", touchPoint.state);
120 // Generate a TapGestureEvent to send to Core
121 Integration::TapGestureEvent GenerateTap(
122 Gesture::State state,
123 unsigned int numberOfTaps,
124 unsigned int numberOfTouches,
127 Integration::TapGestureEvent tap( state );
129 tap.numberOfTaps = numberOfTaps;
130 tap.numberOfTouches = numberOfTouches;
138 ///////////////////////////////////////////////////////////////////////////////
141 // Positive test case for a method
142 int UtcDaliTapGestureDetectorConstructor(void)
144 TestApplication application;
146 TapGestureDetector detector;
147 DALI_TEST_CHECK(!detector);
151 int UtcDaliTapGestureDetectorCopyConstructorP(void)
153 TestApplication application;
155 TapGestureDetector detector = TapGestureDetector::New();
157 TapGestureDetector copy( detector );
158 DALI_TEST_CHECK( detector );
162 int UtcDaliTapGestureDetectorAssignmentOperatorP(void)
164 TestApplication application;
166 TapGestureDetector detector = TapGestureDetector::New();;
168 TapGestureDetector assign;
170 DALI_TEST_CHECK( detector );
172 DALI_TEST_CHECK( detector == assign );
176 int UtcDaliTapGestureDetectorNew(void)
178 TestApplication application;
180 TapGestureDetector detector = TapGestureDetector::New();
181 DALI_TEST_CHECK(detector);
182 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
183 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
185 TapGestureDetector detector2 = TapGestureDetector::New( 5u );
186 DALI_TEST_CHECK(detector2);
187 DALI_TEST_EQUALS(5u, detector2.GetMinimumTapsRequired(), TEST_LOCATION);
188 DALI_TEST_EQUALS(5u, detector2.GetMaximumTapsRequired(), TEST_LOCATION);
190 //Scoped test to test destructor
192 TapGestureDetector detector3 = TapGestureDetector::New();
193 DALI_TEST_CHECK(detector3);
196 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
197 Actor actor = Actor::New();
198 actor.SetSize(100.0f, 100.0f);
199 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
200 Stage::GetCurrent().Add(actor);
203 application.SendNotification();
204 application.Render();
206 detector.Attach(actor);
208 TouchEventFunctor touchFunctor;
209 actor.TouchedSignal().Connect( &application, touchFunctor );
211 Integration::TouchEvent touchEvent(1);
212 Integration::Point point;
213 point.SetDeviceId( 1 );
214 point.SetState( PointState::DOWN );
215 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
216 touchEvent.AddPoint(point);
217 application.ProcessEvent(touchEvent);
220 application.SendNotification();
221 application.Render();
223 // For line coverage, Initialise default constructor
224 TouchEvent touchEvent2;
228 int UtcDaliTapGestureDetectorDownCast(void)
230 TestApplication application;
231 tet_infoline("Testing Dali::TapGestureDetector::DownCast()");
233 TapGestureDetector detector = TapGestureDetector::New();
235 BaseHandle object(detector);
237 TapGestureDetector detector2 = TapGestureDetector::DownCast(object);
238 DALI_TEST_CHECK(detector2);
240 TapGestureDetector detector3 = DownCast< TapGestureDetector >(object);
241 DALI_TEST_CHECK(detector3);
243 BaseHandle unInitializedObject;
244 TapGestureDetector detector4 = TapGestureDetector::DownCast(unInitializedObject);
245 DALI_TEST_CHECK(!detector4);
247 TapGestureDetector detector5 = DownCast< TapGestureDetector >(unInitializedObject);
248 DALI_TEST_CHECK(!detector5);
250 GestureDetector detector6 = TapGestureDetector::New();
251 TapGestureDetector detector7 = TapGestureDetector::DownCast(detector6);
252 DALI_TEST_CHECK(detector7);
256 int UtcDaliTapGestureSetTapsRequired(void)
258 TestApplication application;
260 TapGestureDetector detector = TapGestureDetector::New();
262 const unsigned int minTaps = 3;
263 const unsigned int maxTaps = 7;
265 DALI_TEST_CHECK( minTaps != detector.GetMinimumTapsRequired() );
266 DALI_TEST_CHECK( maxTaps != detector.GetMaximumTapsRequired() );
268 detector.SetMinimumTapsRequired( minTaps );
269 detector.SetMaximumTapsRequired( maxTaps );
271 DALI_TEST_EQUALS( minTaps, detector.GetMinimumTapsRequired(), TEST_LOCATION );
272 DALI_TEST_EQUALS( maxTaps, detector.GetMaximumTapsRequired(), TEST_LOCATION );
274 // Attach an actor and change the required touches
276 Actor actor = Actor::New();
277 actor.SetSize(100.0f, 100.0f);
278 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
279 Stage::GetCurrent().Add(actor);
282 application.SendNotification();
283 application.Render();
286 GestureReceivedFunctor functor(data);
288 detector.Attach(actor);
289 detector.DetectedSignal().Connect( &application, functor );
291 // Ensure signal is emitted if minimum taps received
292 application.ProcessEvent(GenerateTap(Gesture::Possible, minTaps, 1u, Vector2(50.0f, 50.0f)));
293 application.ProcessEvent(GenerateTap(Gesture::Started, minTaps, 1u, Vector2(50.0f, 50.0f)));
294 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
295 DALI_TEST_EQUALS( minTaps, data.receivedGesture.numberOfTaps, TEST_LOCATION );
298 // Ensure signal is emitted if maximum taps received
299 application.ProcessEvent(GenerateTap(Gesture::Possible, maxTaps, 1u, Vector2(50.0f, 50.0f)));
300 application.ProcessEvent(GenerateTap(Gesture::Started, maxTaps, 1u, Vector2(50.0f, 50.0f)));
301 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
302 DALI_TEST_EQUALS( maxTaps, data.receivedGesture.numberOfTaps, TEST_LOCATION );
305 // Ensure signal is NOT emitted if outside the range
306 application.ProcessEvent(GenerateTap(Gesture::Possible, minTaps - 1, 1u, Vector2(50.0f, 50.0f)));
307 application.ProcessEvent(GenerateTap(Gesture::Started, minTaps - 1, 1u, Vector2(50.0f, 50.0f)));
308 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
310 application.ProcessEvent(GenerateTap(Gesture::Possible, maxTaps + 1, 1u, Vector2(50.0f, 50.0f)));
311 application.ProcessEvent(GenerateTap(Gesture::Started, maxTaps + 1, 1u, Vector2(50.0f, 50.0f)));
312 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
315 TestGestureManager& gestureManager = application.GetGestureManager();
316 gestureManager.Initialize();
318 detector.SetMinimumTapsRequired(4);
320 // Gesture detection should have been updated only
321 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
322 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
323 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
326 gestureManager.Initialize();
328 detector.SetMaximumTapsRequired(maxTaps);
330 // Gesture detection should NOT have been updated
331 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
332 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
333 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
336 gestureManager.Initialize();
338 // Create a second gesture detector that requires even less maximum touches
339 TapGestureDetector secondDetector = TapGestureDetector::New();
340 secondDetector.Attach(actor);
342 // Gesture detection should have been updated
343 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
344 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
345 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
348 gestureManager.Initialize();
350 // Delete the second detector so that our detection is updated again
351 secondDetector.Reset();
352 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
353 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
354 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
356 // Set the minimum to be greater than the maximum, should Assert
359 detector.SetMinimumTapsRequired( maxTaps );
360 detector.SetMaximumTapsRequired( minTaps );
361 DALI_TEST_CHECK( false ); // Should not get here
363 catch ( DaliException& e )
365 DALI_TEST_CHECK( true );
371 int UtcDaliTapGestureSetTapsRequiredMinMaxCheck(void)
373 TestApplication application;
375 // Attach an actor and change the required touches
377 Actor actor = Actor::New();
378 actor.SetSize(100.0f, 100.0f);
379 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
380 Stage::GetCurrent().Add(actor);
383 application.SendNotification();
384 application.Render();
386 // Set the minimum to be greater than the maximum, should Assert
390 TapGestureDetector detector = TapGestureDetector::New();
391 detector.SetMinimumTapsRequired( 7u );
392 detector.SetMaximumTapsRequired( 3u );
393 detector.Attach(actor);
394 DALI_TEST_CHECK( false ); // Should not get here
396 catch ( DaliException& e )
398 DALI_TEST_CHECK( true );
404 int UtcDaliTapGestureGetTapsRequired(void)
406 TestApplication application;
408 TapGestureDetector detector = TapGestureDetector::New();
409 DALI_TEST_EQUALS(1u, detector.GetMinimumTapsRequired(), TEST_LOCATION);
410 DALI_TEST_EQUALS(1u, detector.GetMaximumTapsRequired(), TEST_LOCATION);
414 int UtcDaliTapGestureSignalReceptionNegative(void)
416 TestApplication application;
418 Actor actor = Actor::New();
419 actor.SetSize(100.0f, 100.0f);
420 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
421 Stage::GetCurrent().Add(actor);
424 application.SendNotification();
425 application.Render();
428 GestureReceivedFunctor functor(data);
430 TapGestureDetector detector = TapGestureDetector::New();
431 detector.Attach(actor);
432 detector.DetectedSignal().Connect( &application, functor );
434 // Do a tap outside actor's area
435 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(112.0f, 112.0f)));
436 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(112.0f, 112.0f)));
437 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
441 int UtcDaliTapGestureSignalReceptionPositive(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 TapGestureDetector detector = TapGestureDetector::New();
458 detector.Attach(actor);
459 detector.DetectedSignal().Connect( &application, functor );
461 // Do a tap inside actor's area
462 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
463 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
464 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
465 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
466 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
467 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
471 int UtcDaliTapGestureSignalReceptionDetach(void)
473 TestApplication application;
475 Actor actor = Actor::New();
476 actor.SetSize(100.0f, 100.0f);
477 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
478 Stage::GetCurrent().Add(actor);
481 application.SendNotification();
482 application.Render();
485 GestureReceivedFunctor functor(data);
487 TapGestureDetector detector = TapGestureDetector::New();
488 detector.Attach(actor);
489 detector.DetectedSignal().Connect(&application, functor);
491 // Start tap within the actor's area
492 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
493 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
494 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
495 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
496 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
497 DALI_TEST_EQUALS( Vector2(20.0f, 20.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
499 // repeat the tap within the actor's area - we should still receive the signal
501 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
502 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
503 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
504 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
505 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
506 DALI_TEST_EQUALS( Vector2(50.0f, 50.0f), data.receivedGesture.localPoint, 0.1, TEST_LOCATION);
509 detector.DetachAll();
511 // Ensure we are no longer signalled
513 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
514 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
515 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
516 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
517 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
518 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
522 int UtcDaliTapGestureSignalReceptionActorDestroyedWhileTapping(void)
524 TestApplication application;
527 GestureReceivedFunctor functor(data);
529 TapGestureDetector detector = TapGestureDetector::New();
530 detector.DetectedSignal().Connect(&application, functor);
532 // Actor lifetime is scoped
534 Actor actor = Actor::New();
535 actor.SetSize(100.0f, 100.0f);
536 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
537 Stage::GetCurrent().Add(actor);
540 application.SendNotification();
541 application.Render();
543 detector.Attach(actor);
545 // Start tap within the actor's area
546 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
547 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
548 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
550 // Remove the actor from stage and reset the data
551 Stage::GetCurrent().Remove(actor);
554 application.SendNotification();
555 application.Render();
558 // Actor should now have been destroyed
561 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 20.0f)));
562 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 20.0f)));
563 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
567 int UtcDaliTapGestureSignalReceptionRotatedActor(void)
569 TestApplication application;
571 Actor actor = Actor::New();
572 actor.SetSize(100.0f, 100.0f);
573 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
574 Stage::GetCurrent().Add(actor);
577 application.SendNotification();
578 application.Render();
581 GestureReceivedFunctor functor(data);
583 TapGestureDetector detector = TapGestureDetector::New();
584 detector.Attach(actor);
585 detector.DetectedSignal().Connect(&application, functor);
587 // Do tap, only check finished value
588 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
589 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
590 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
591 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
592 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
593 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
595 // Rotate actor again and render
596 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
597 application.SendNotification();
598 application.Render();
600 // Do tap, should still receive event
602 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(5.0f, 5.0f)));
603 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(5.0f, 5.0f)));
604 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
605 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTaps, TEST_LOCATION);
606 DALI_TEST_EQUALS(1u, data.receivedGesture.numberOfTouches, TEST_LOCATION);
607 DALI_TEST_EQUALS( Vector2(5.0f, 5.0f), data.receivedGesture.screenPoint, 0.1, TEST_LOCATION);
609 // Rotate actor again and render
610 actor.SetOrientation(Dali::Degree(90.0f), Vector3::YAXIS);
611 application.SendNotification();
612 application.Render();
614 // Do tap, inside the actor's area (area if it is not rotated), Should not receive the event
616 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(70.0f, 70.0f)));
617 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(70.0f, 70.0f)));
618 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
622 int UtcDaliTapGestureSignalReceptionChildHit(void)
624 TestApplication application;
626 Actor parent = Actor::New();
627 parent.SetSize(100.0f, 100.0f);
628 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
629 Stage::GetCurrent().Add(parent);
631 // Set child to completely cover parent.
632 // Change rotation of child to be different from parent so that we can check if our local coordinate
633 // conversion of the parent actor is correct.
634 Actor child = Actor::New();
635 child.SetSize(100.0f, 100.0f);
636 child.SetAnchorPoint(AnchorPoint::CENTER);
637 child.SetParentOrigin(ParentOrigin::CENTER);
638 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
641 TouchEventFunctor touchFunctor;
642 child.TouchedSignal().Connect(&application, touchFunctor);
645 application.SendNotification();
646 application.Render();
649 GestureReceivedFunctor functor(data);
651 TapGestureDetector detector = TapGestureDetector::New();
652 detector.Attach(parent);
653 detector.DetectedSignal().Connect(&application, functor);
655 // Do tap - hits child area but parent should still receive it
656 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 50.0f)));
657 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 50.0f)));
658 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
659 DALI_TEST_EQUALS(true, parent == data.tappedActor, TEST_LOCATION);
660 DALI_TEST_EQUALS(Vector2(50.0f, 50.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
662 // Attach child and generate same touch points
663 // (Also proves that you can detach and then re-attach another actor)
664 detector.Attach(child);
665 detector.Detach(parent);
667 // Do an entire tap, only check finished value
669 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(51.0f, 51.0f)));
670 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(51.0f, 51.0f)));
671 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
672 DALI_TEST_EQUALS(true, child == data.tappedActor, TEST_LOCATION);
673 DALI_TEST_EQUALS(Vector2(51.0f, 51.0f), data.receivedGesture.screenPoint, 0.01f, TEST_LOCATION);
677 int UtcDaliTapGestureSignalReceptionAttachDetachMany(void)
679 TestApplication application;
681 Actor first = Actor::New();
682 first.SetSize(100.0f, 100.0f);
683 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
684 Stage::GetCurrent().Add(first);
686 Actor second = Actor::New();
687 second.SetSize(100.0f, 100.0f);
689 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
690 Stage::GetCurrent().Add(second);
693 application.SendNotification();
694 application.Render();
697 GestureReceivedFunctor functor(data);
699 TapGestureDetector detector = TapGestureDetector::New();
700 detector.Attach(first);
701 detector.Attach(second);
702 detector.DetectedSignal().Connect(&application, functor);
704 // Tap within second actor's area
705 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
706 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
707 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
708 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
710 // Tap within first actor's area
712 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
713 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
714 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
715 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
717 // Detach the second actor
718 detector.Detach(second);
720 // second actor shouldn't receive event
722 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(120.0f, 10.0f)));
723 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(120.0f, 10.0f)));
724 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
726 // first actor should continue receiving event
728 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(20.0f, 10.0f)));
729 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(20.0f, 10.0f)));
730 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
734 int UtcDaliTapGestureSignalReceptionActorBecomesUntouchable(void)
736 TestApplication application;
738 Actor actor = Actor::New();
739 actor.SetSize(100.0f, 100.0f);
740 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
741 Stage::GetCurrent().Add(actor);
744 application.SendNotification();
745 application.Render();
748 GestureReceivedFunctor functor(data);
750 TapGestureDetector detector = TapGestureDetector::New();
751 detector.Attach(actor);
752 detector.DetectedSignal().Connect(&application, functor);
754 // Tap in actor's area
755 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
756 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
757 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
759 // Actor become invisible - actor should not receive the next pan
760 actor.SetVisible(false);
763 application.SendNotification();
764 application.Render();
766 // Tap in the same area, shouldn't receive event
768 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
769 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
770 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
774 int UtcDaliTapGestureSignalReceptionMultipleGestureDetectors(void)
776 TestApplication application;
777 Dali::TestGestureManager& gestureManager = application.GetGestureManager();
779 Actor first = Actor::New();
780 first.SetSize(100.0f, 100.0f);
781 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
782 Stage::GetCurrent().Add(first);
784 Actor second = Actor::New();
785 second.SetSize(100.0f, 100.0f);
786 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
791 application.SendNotification();
792 application.Render();
795 GestureReceivedFunctor functor(data);
797 TapGestureDetector firstDetector = TapGestureDetector::New();
798 firstDetector.Attach(first);
799 firstDetector.DetectedSignal().Connect(&application, functor);
801 // secondDetector is scoped
803 // Reset gestureManager statistics
804 gestureManager.Initialize();
806 TapGestureDetector secondDetector = TapGestureDetector::New( 2 );
807 secondDetector.Attach(second);
808 secondDetector.DetectedSignal().Connect(&application, functor);
810 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
811 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
812 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
814 // Tap within second actor's area
815 application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 1u, Vector2(150.0f, 10.0f)));
816 application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 1u, Vector2(150.0f, 10.0f)));
817 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
818 DALI_TEST_EQUALS(true, second == data.tappedActor, TEST_LOCATION);
820 // Tap continues as single touch gesture - we should not receive any gesture
822 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(150.0f, 10.0f)));
823 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(150.0f, 10.0f)));
824 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
826 // Single touch tap starts - first actor should be panned
828 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
829 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
830 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
831 DALI_TEST_EQUALS(true, first == data.tappedActor, TEST_LOCATION);
833 // Pan changes to double-touch - we shouldn't receive event
835 application.ProcessEvent(GenerateTap(Gesture::Possible, 2u, 2u, Vector2(50.0f, 10.0f)));
836 application.ProcessEvent(GenerateTap(Gesture::Started, 2u, 2u, Vector2(50.0f, 10.0f)));
837 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
839 // Reset gesture manager statistics
840 gestureManager.Initialize();
843 // secondDetector has now been deleted. Gesture detection should have been updated only
844 DALI_TEST_EQUALS(true, gestureManager.WasCalled(TestGestureManager::UpdateType), TEST_LOCATION);
845 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::RegisterType), TEST_LOCATION);
846 DALI_TEST_EQUALS(false, gestureManager.WasCalled(TestGestureManager::UnregisterType), TEST_LOCATION);
850 int UtcDaliTapGestureSignalReceptionMultipleDetectorsOnActor(void)
852 TestApplication application;
854 Actor actor = Actor::New();
855 actor.SetSize(100.0f, 100.0f);
856 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
857 Stage::GetCurrent().Add(actor);
860 application.SendNotification();
861 application.Render();
863 // Attach actor to one detector
864 SignalData firstData;
865 GestureReceivedFunctor firstFunctor(firstData);
866 TapGestureDetector firstDetector = TapGestureDetector::New();
867 firstDetector.Attach(actor);
868 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
870 // Attach actor to another detector
871 SignalData secondData;
872 GestureReceivedFunctor secondFunctor(secondData);
873 TapGestureDetector secondDetector = TapGestureDetector::New();
874 secondDetector.Attach(actor);
875 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
877 // Tap in actor's area - both detector's functors should be called
878 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
879 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
880 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
881 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
885 int UtcDaliTapGestureSignalReceptionDifferentPossible(void)
887 TestApplication application;
889 Actor actor = Actor::New();
890 actor.SetSize(100.0f, 100.0f);
891 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
892 Stage::GetCurrent().Add(actor);
895 application.SendNotification();
896 application.Render();
898 // Attach actor to detector
900 GestureReceivedFunctor functor( data );
901 TapGestureDetector detector = TapGestureDetector::New();
902 detector.Attach(actor);
903 detector.DetectedSignal().Connect( &application, functor );
905 // Gesture possible in actor's area.
906 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
907 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
909 // Move actor somewhere else
910 actor.SetPosition( 100.0f, 100.0f );
913 application.SendNotification();
914 application.Render();
916 // Emit Started event, we should not receive the tap.
917 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
918 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
920 // Tap possible in empty area.
921 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
922 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
924 // Move actor in to the tap position.
925 actor.SetPosition( 0.0f, 0.0f );
928 application.SendNotification();
929 application.Render();
931 // Emit Started event, we should not receive the tap.
932 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
933 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
935 // Normal tap in actor's area for completeness.
936 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
937 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
938 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
942 int UtcDaliTapGestureEmitIncorrectStateClear(void)
944 TestApplication application;
946 Actor actor = Actor::New();
947 actor.SetSize(100.0f, 100.0f);
948 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
949 Stage::GetCurrent().Add(actor);
952 application.SendNotification();
953 application.Render();
955 // Attach actor to detector
957 GestureReceivedFunctor functor( data );
958 TapGestureDetector detector = TapGestureDetector::New();
959 detector.Attach(actor);
960 detector.DetectedSignal().Connect( &application, functor );
965 application.ProcessEvent(GenerateTap(Gesture::Clear, 1u, 1u, Vector2(50.0f, 10.0f)));
966 tet_result(TET_FAIL);
968 catch ( Dali::DaliException& e )
970 DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
975 int UtcDaliTapGestureEmitIncorrectStateContinuing(void)
977 TestApplication application;
979 Actor actor = Actor::New();
980 actor.SetSize(100.0f, 100.0f);
981 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
982 Stage::GetCurrent().Add(actor);
985 application.SendNotification();
986 application.Render();
988 // Attach actor to detector
990 GestureReceivedFunctor functor( data );
991 TapGestureDetector detector = TapGestureDetector::New();
992 detector.Attach(actor);
993 detector.DetectedSignal().Connect( &application, functor );
995 // Try a Continuing state
998 application.ProcessEvent(GenerateTap(Gesture::Continuing, 1u, 1u, Vector2(50.0f, 10.0f)));
999 tet_result(TET_FAIL);
1001 catch ( Dali::DaliException& e )
1003 DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
1008 int UtcDaliTapGestureEmitIncorrectStateFinished(void)
1010 TestApplication application;
1012 Actor actor = Actor::New();
1013 actor.SetSize(100.0f, 100.0f);
1014 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1015 Stage::GetCurrent().Add(actor);
1017 // Render and notify
1018 application.SendNotification();
1019 application.Render();
1021 // Attach actor to detector
1023 GestureReceivedFunctor functor( data );
1024 TapGestureDetector detector = TapGestureDetector::New();
1025 detector.Attach(actor);
1026 detector.DetectedSignal().Connect( &application, functor );
1028 // Try a Finished state
1031 application.ProcessEvent(GenerateTap(Gesture::Finished, 1u, 1u, Vector2(50.0f, 10.0f)));
1032 tet_result(TET_FAIL);
1034 catch ( Dali::DaliException& e )
1036 DALI_TEST_ASSERT( e, "Incorrect state", TEST_LOCATION );
1041 int UtcDaliTapGestureActorUnstaged(void)
1043 TestApplication application;
1045 Actor actor = Actor::New();
1046 actor.SetSize(100.0f, 100.0f);
1047 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1048 Stage::GetCurrent().Add(actor);
1050 // Render and notify
1051 application.SendNotification();
1052 application.Render();
1054 // Attach actor to detector
1056 UnstageActorFunctor functor( data );
1057 TapGestureDetector detector = TapGestureDetector::New();
1058 detector.Attach(actor);
1059 detector.DetectedSignal().Connect( &application, functor );
1061 // Tap in Actor's area, actor removed in signal handler, should be handled gracefully.
1062 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1063 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1064 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1065 tet_result( TET_PASS ); // If we get here, then the actor removal on signal handler was handled gracefully.
1069 int UtcDaliTapGestureRepeatedState(void)
1071 TestApplication application;
1073 Actor actor = Actor::New();
1074 actor.SetSize(100.0f, 100.0f);
1075 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1076 Stage::GetCurrent().Add(actor);
1078 // Render and notify
1079 application.SendNotification();
1080 application.Render();
1082 // Attach actor to detector
1084 GestureReceivedFunctor functor( data );
1085 TapGestureDetector detector = TapGestureDetector::New();
1086 detector.Attach(actor);
1087 detector.DetectedSignal().Connect( &application, functor );
1089 // Emit two possibles
1090 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1091 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1092 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1094 // Send a couple of Started states, only first one should be received.
1095 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1096 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1098 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1099 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1101 // Send a couple of cancelled states, no reception
1102 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1103 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1104 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1108 int UtcDaliTapGesturePossibleCancelled(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 TapGestureDetector detector = TapGestureDetector::New();
1125 detector.Attach(actor);
1126 detector.DetectedSignal().Connect( &application, functor );
1128 // Emit a possible and then a cancelled, no reception
1129 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1130 application.ProcessEvent(GenerateTap(Gesture::Cancelled, 1u, 1u, Vector2(50.0f, 10.0f)));
1131 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1135 int UtcDaliTapGestureDetectorRemovedWhilePossible(void)
1137 TestApplication application;
1139 Actor actor = Actor::New();
1140 actor.SetSize(100.0f, 100.0f);
1141 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1142 Stage::GetCurrent().Add(actor);
1144 // Render and notify
1145 application.SendNotification();
1146 application.Render();
1148 // Attach actor to detector
1150 GestureReceivedFunctor functor( data );
1151 TapGestureDetector detector = TapGestureDetector::New();
1152 detector.Attach(actor);
1153 detector.DetectedSignal().Connect( &application, functor );
1156 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1158 // Detach actor and send a Started state, no signal.
1159 detector.DetachAll();
1160 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1161 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1165 int UtcDaliTapGestureActorRemovedWhilePossible(void)
1167 TestApplication application;
1169 Actor actor = Actor::New();
1170 actor.SetSize(100.0f, 100.0f);
1171 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1172 Stage::GetCurrent().Add(actor);
1174 // Render and notify
1175 application.SendNotification();
1176 application.Render();
1178 // Attach actor to detector
1180 GestureReceivedFunctor functor( data );
1181 TapGestureDetector detector = TapGestureDetector::New();
1182 detector.Attach(actor);
1183 detector.DetectedSignal().Connect( &application, functor );
1186 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1188 // Remove, render and delete actor
1189 Stage::GetCurrent().Remove(actor);
1190 application.SendNotification();
1191 application.Render();
1194 // Send a Started state, no signal.
1195 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1196 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1200 int UtcDaliTapGestureSystemOverlay(void)
1202 TestApplication application;
1203 Dali::Integration::Core& core = application.GetCore();
1204 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1206 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1207 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1208 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1209 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1210 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1212 Actor actor = Actor::New();
1213 actor.SetSize(100.0f, 100.0f);
1214 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1215 systemOverlay.Add(actor);
1217 // Render and notify
1218 application.SendNotification();
1219 application.Render();
1222 GestureReceivedFunctor functor(data);
1224 TapGestureDetector detector = TapGestureDetector::New();
1225 detector.Attach(actor);
1226 detector.DetectedSignal().Connect(&application, functor);
1228 Vector2 screenCoords( 50.0f, 50.0f );
1230 // Do a tap inside actor's area
1231 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1232 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1233 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1237 int UtcDaliTapGestureBehindTouchableSystemOverlay(void)
1239 TestApplication application;
1240 Dali::Integration::Core& core = application.GetCore();
1241 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1243 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1244 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1245 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1246 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1247 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1249 // SystemOverlay actor
1250 Actor systemOverlayActor = Actor::New();
1251 systemOverlayActor.SetSize(100.0f, 100.0f);
1252 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1253 systemOverlay.Add(systemOverlayActor);
1256 Actor stageActor = Actor::New();
1257 stageActor.SetSize(100.0f, 100.0f);
1258 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1259 Stage::GetCurrent().Add(stageActor);
1261 // Render and notify
1262 application.SendNotification();
1263 application.Render();
1265 // Set system-overlay actor to touchable
1266 TouchEventData touchData;
1267 TouchEventDataFunctor touchFunctor( touchData );
1268 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1270 // Set stage actor to receive the gesture
1272 GestureReceivedFunctor functor(data);
1274 TapGestureDetector detector = TapGestureDetector::New();
1275 detector.Attach(stageActor);
1276 detector.DetectedSignal().Connect(&application, functor);
1278 Vector2 screenCoords( 50.0f, 50.0f );
1280 // Do a tap inside both actors' area
1281 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1282 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1283 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1284 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1289 // Do touch in the same area
1290 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1291 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1292 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1297 int UtcDaliTapGestureTouchBehindGesturedSystemOverlay(void)
1299 TestApplication application;
1300 Dali::Integration::Core& core = application.GetCore();
1301 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1303 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1304 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1305 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1306 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1307 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1309 // SystemOverlay actor
1310 Actor systemOverlayActor = Actor::New();
1311 systemOverlayActor.SetSize(100.0f, 100.0f);
1312 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1313 systemOverlay.Add(systemOverlayActor);
1316 Actor stageActor = Actor::New();
1317 stageActor.SetSize(100.0f, 100.0f);
1318 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1319 Stage::GetCurrent().Add(stageActor);
1321 // Render and notify
1322 application.SendNotification();
1323 application.Render();
1325 // Set stage actor to touchable
1326 TouchEventData touchData;
1327 TouchEventDataFunctor touchFunctor( touchData );
1328 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1330 // Set system-overlay actor to have the gesture
1332 GestureReceivedFunctor functor(data);
1334 TapGestureDetector detector = TapGestureDetector::New();
1335 detector.Attach(systemOverlayActor);
1336 detector.DetectedSignal().Connect(&application, functor);
1338 Vector2 screenCoords( 50.0f, 50.0f );
1340 // Do a tap inside both actors' area
1341 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1342 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1343 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1344 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1349 // Do touch in the same area
1350 application.ProcessEvent( touchFunctor.GenerateSingleTouch( PointState::DOWN, screenCoords ) );
1351 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1352 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1357 int UtcDaliTapGestureLayerConsumesTouch(void)
1359 TestApplication application;
1361 Actor actor = Actor::New();
1362 actor.SetSize(100.0f, 100.0f);
1363 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1364 Stage::GetCurrent().Add(actor);
1368 GestureReceivedFunctor functor(data);
1369 TapGestureDetector detector = TapGestureDetector::New();
1370 detector.Attach(actor);
1371 detector.DetectedSignal().Connect( &application, functor );
1373 // Add a layer to overlap the actor
1374 Layer layer = Layer::New();
1375 layer.SetSize(100.0f, 100.0f);
1376 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1377 Stage::GetCurrent().Add( layer );
1380 // Render and notify
1381 application.SendNotification();
1382 application.Render();
1384 Vector2 screenCoords( 50.0f, 50.0f );
1386 // Emit signals, should receive
1387 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1388 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1389 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1392 // Set layer to consume all touch
1393 layer.SetTouchConsumed( true );
1395 // Render and notify
1396 application.SendNotification();
1397 application.Render();
1399 // Emit the same signals again, should not receive
1400 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, screenCoords ) );
1401 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, screenCoords ) );
1402 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);