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/pinch-gesture-event.h>
24 #include <dali/integration-api/system-overlay.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-touch-utils.h>
30 void utc_dali_pinch_gesture_detector_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_pinch_gesture_detector_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
44 // Stores data that is populated in the callback and will be read by the TET cases
48 : functorCalled(false),
49 voidFunctorCalled(false),
50 receivedGesture(Gesture::Started)
55 functorCalled = false;
56 voidFunctorCalled = false;
58 receivedGesture.state = Gesture::Started;
59 receivedGesture.scale = 0.0f;
60 receivedGesture.speed = 0.0f;
61 receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
62 receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
68 bool voidFunctorCalled;
69 PinchGesture receivedGesture;
73 // Functor that sets the data when called
74 struct GestureReceivedFunctor
76 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
78 void operator()(Actor actor, PinchGesture pinch)
80 signalData.functorCalled = true;
81 signalData.receivedGesture = pinch;
82 signalData.pinchedActor = actor;
87 signalData.voidFunctorCalled = true;
90 SignalData& signalData;
93 // Functor that removes the gestured actor from stage
94 struct UnstageActorFunctor : public GestureReceivedFunctor
96 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
97 : GestureReceivedFunctor( data ),
98 stateToUnstage( stateToUnstage )
102 void operator()( Actor actor, PinchGesture pinch )
104 GestureReceivedFunctor::operator()( actor, pinch );
106 if ( pinch.state == stateToUnstage )
108 Stage::GetCurrent().Remove( actor );
112 Gesture::State& stateToUnstage;
115 // Functor for receiving a touch event
116 struct TouchEventFunctor
118 bool operator()(Actor actor, const TouchEvent& touch)
124 // Generate a PinchGestureEvent to send to Core
125 Integration::PinchGestureEvent GeneratePinch(
126 Gesture::State state,
131 Integration::PinchGestureEvent pinch(state);
135 pinch.centerPoint = centerpoint;
142 ///////////////////////////////////////////////////////////////////////////////
144 int UtcDaliPinchGestureDetectorConstructor(void)
146 TestApplication application;
148 PinchGestureDetector detector;
149 DALI_TEST_CHECK(!detector);
153 int UtcDaliPinchGestureDetectorNew(void)
155 TestApplication application;
157 PinchGestureDetector detector = PinchGestureDetector::New();
159 DALI_TEST_CHECK(detector);
161 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
162 Actor actor = Actor::New();
163 actor.SetSize(100.0f, 100.0f);
164 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
165 Stage::GetCurrent().Add(actor);
168 application.SendNotification();
169 application.Render();
171 detector.Attach(actor);
173 Integration::TouchEvent touchEvent(1);
174 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
175 touchEvent.AddPoint(point);
176 application.ProcessEvent(touchEvent);
178 TouchPoint point2(1, TouchPoint::Down, 20.0f, 20.0f, 20.0f, 20.0f);
179 touchEvent.AddPoint(point2);
180 application.ProcessEvent(touchEvent);
184 int UtcDaliPinchGestureDetectorDownCast(void)
186 TestApplication application;
187 tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
189 PinchGestureDetector detector = PinchGestureDetector::New();
191 BaseHandle object(detector);
193 PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
194 DALI_TEST_CHECK(detector2);
196 PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
197 DALI_TEST_CHECK(detector3);
199 BaseHandle unInitializedObject;
200 PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
201 DALI_TEST_CHECK(!detector4);
203 PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
204 DALI_TEST_CHECK(!detector5);
206 GestureDetector detector6 = PinchGestureDetector::New();
207 PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
208 DALI_TEST_CHECK(detector7);
212 // Negative test case for a method
213 int UtcDaliPinchGestureSignalReceptionNegative(void)
215 TestApplication application;
217 Actor actor = Actor::New();
218 actor.SetSize(100.0f, 100.0f);
219 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
220 Stage::GetCurrent().Add(actor);
223 application.SendNotification();
224 application.Render();
227 GestureReceivedFunctor functor(data);
229 PinchGestureDetector detector = PinchGestureDetector::New();
230 detector.Attach(actor);
231 detector.DetectedSignal().Connect(&application, functor);
233 // Do a pinch outside actor's area
234 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 45.0f, Vector2(112.0f, 112.0f)));
235 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
237 // Continue pinch into actor's area - we should still not receive the signal
239 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 4.5f, 95.0f, Vector2(20.0f, 20.0f)));
240 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
242 // Stop pinching - we should still not receive the signal
244 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(12.0f, 12.0f)));
245 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
249 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
251 TestApplication application;
253 Actor actor = Actor::New();
254 actor.SetSize(100.0f, 100.0f);
255 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
256 Stage::GetCurrent().Add(actor);
259 application.SendNotification();
260 application.Render();
263 GestureReceivedFunctor functor(data);
265 PinchGestureDetector detector = PinchGestureDetector::New();
266 detector.Attach(actor);
267 detector.DetectedSignal().Connect(&application, functor);
269 // Start pan within the actor's area
270 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
271 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
272 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
273 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
274 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
275 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
277 // Continue the pan within the actor's area - we should still receive the signal
279 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 90.0f, Vector2(21.0f, 20.0f)));
280 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
281 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
282 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
283 DALI_TEST_EQUALS(90.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
284 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
286 // Pan Gesture leaves actor's area - we should still receive the signal
288 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 15.5f, Vector2(320.0f, 10.0f)));
289 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
290 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
291 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
292 DALI_TEST_EQUALS(15.5f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
293 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
295 // Gesture ends - we would receive a finished state
297 application.ProcessEvent(GeneratePinch(Gesture::Finished, 15.2f, 12.1f, Vector2(310.0f, 10.0f)));
298 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
299 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
300 DALI_TEST_EQUALS(15.2f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
301 DALI_TEST_EQUALS(12.1f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
302 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
306 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
308 TestApplication application;
310 Actor actor = Actor::New();
311 actor.SetSize(100.0f, 100.0f);
312 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
313 Stage::GetCurrent().Add(actor);
316 application.SendNotification();
317 application.Render();
320 GestureReceivedFunctor functor(data);
322 PinchGestureDetector detector = PinchGestureDetector::New();
323 detector.Attach(actor);
324 detector.DetectedSignal().Connect(&application, functor);
326 // Start pinch within the actor's area
327 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
328 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
329 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
330 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
331 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
332 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
334 // Continue the pinch within the actor's area - we should still receive the signal
336 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
337 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
338 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
339 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
340 DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
341 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
343 // Gesture ends within actor's area - we would receive a finished state
345 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
346 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
347 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
348 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
349 DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
350 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
354 int UtcDaliPinchGestureSignalReceptionCancelled(void)
356 TestApplication application;
358 Actor actor = Actor::New();
359 actor.SetSize(100.0f, 100.0f);
360 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
361 Stage::GetCurrent().Add(actor);
364 application.SendNotification();
365 application.Render();
368 GestureReceivedFunctor functor(data);
370 PinchGestureDetector detector = PinchGestureDetector::New();
371 detector.Attach(actor);
372 detector.DetectedSignal().Connect(&application, functor);
374 // Start pinch within the actor's area
375 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
376 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
377 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
380 // Continue the pinch within the actor's area - we should still receive the signal
382 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
383 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
384 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
386 // The gesture is cancelled
388 application.ProcessEvent(GeneratePinch(Gesture::Cancelled, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
389 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
390 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
394 int UtcDaliPinchGestureSignalReceptionDetach(void)
396 TestApplication application;
398 Actor actor = Actor::New();
399 actor.SetSize(100.0f, 100.0f);
400 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
401 Stage::GetCurrent().Add(actor);
404 application.SendNotification();
405 application.Render();
408 GestureReceivedFunctor functor(data);
410 PinchGestureDetector detector = PinchGestureDetector::New();
411 detector.Attach(actor);
412 detector.DetectedSignal().Connect(&application, functor);
414 // Start pinch within the actor's area
415 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
416 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
417 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
420 // Continue the pinch within the actor's area - we should still receive the signal
422 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
423 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
424 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
426 // Gesture ends within actor's area
428 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
429 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
430 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
433 detector.DetachAll();
435 // Ensure we are no longer signalled
437 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
438 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
439 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
440 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
444 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
446 TestApplication application;
448 Actor actor = Actor::New();
449 actor.SetSize(100.0f, 100.0f);
450 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
451 Stage::GetCurrent().Add(actor);
454 application.SendNotification();
455 application.Render();
458 GestureReceivedFunctor functor(data);
460 PinchGestureDetector detector = PinchGestureDetector::New();
461 detector.Attach(actor);
462 detector.DetectedSignal().Connect(&application, functor);
464 // Start pinch within the actor's area
465 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
466 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
467 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
469 // Continue the pinch within the actor's area - we should still receive the signal
471 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
472 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
473 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
475 // Detach actor during the pinch, we should not receive the next event
476 detector.DetachAll();
478 // Gesture ends within actor's area
480 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
481 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
485 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
487 TestApplication application;
490 GestureReceivedFunctor functor(data);
492 PinchGestureDetector detector = PinchGestureDetector::New();
493 detector.DetectedSignal().Connect(&application, functor);
495 // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
497 Actor tempActor = Actor::New();
498 tempActor.SetSize(100.0f, 100.0f);
499 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
500 Stage::GetCurrent().Add(tempActor);
501 detector.Attach(tempActor);
503 // Actor lifetime is scoped
505 Actor actor = Actor::New();
506 actor.SetSize(100.0f, 100.0f);
507 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
508 Stage::GetCurrent().Add(actor);
511 application.SendNotification();
512 application.Render();
514 detector.Attach(actor);
516 // Start pinch within the actor's area
517 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
518 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
519 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
521 // Continue the pinch within the actor's area - we should still receive the signal
523 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
524 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
525 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
527 // Remove the actor from stage and reset the data
528 Stage::GetCurrent().Remove(actor);
531 application.SendNotification();
532 application.Render();
535 // Actor should now have been destroyed
537 // Gesture ends within the area where the actor used to be
539 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
540 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
544 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
546 TestApplication application;
548 Actor actor = Actor::New();
549 actor.SetSize(100.0f, 100.0f);
550 actor.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
551 Stage::GetCurrent().Add(actor);
553 // Render and notify a couple of times
554 application.SendNotification();
555 application.Render();
558 GestureReceivedFunctor functor(data);
560 PinchGestureDetector detector = PinchGestureDetector::New();
561 detector.Attach(actor);
562 detector.DetectedSignal().Connect(&application, functor);
564 // Do an entire pinch, only check finished value
565 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
567 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
568 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
569 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
570 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
571 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
573 // Rotate actor again and render and notify
574 actor.SetRotation(Dali::Degree(180.0f), Vector3::ZAXIS);
575 application.SendNotification();
576 application.Render();
578 // Do an entire pinch, only check finished value
579 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
581 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
582 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
583 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
584 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
585 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
587 // Rotate actor again and render and notify
588 actor.SetRotation(Dali::Degree(270.0f), Vector3::ZAXIS);
589 application.SendNotification();
590 application.Render();
592 // Do an entire pinch, only check finished value
593 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
595 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
596 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
597 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
598 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
599 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
603 int UtcDaliPinchGestureSignalReceptionChildHit(void)
605 TestApplication application;
607 Actor parent = Actor::New();
608 parent.SetSize(100.0f, 100.0f);
609 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
610 Stage::GetCurrent().Add(parent);
612 // Set child to completely cover parent.
613 // Change rotation of child to be different from parent so that we can check if our local coordinate
614 // conversion of the parent actor is correct.
615 Actor child = Actor::New();
616 child.SetSize(100.0f, 100.0f);
617 child.SetAnchorPoint(AnchorPoint::CENTER);
618 child.SetParentOrigin(ParentOrigin::CENTER);
619 child.SetRotation(Dali::Degree(90.0f), Vector3::ZAXIS);
622 TouchEventFunctor touchFunctor;
623 child.TouchedSignal().Connect(&application, touchFunctor);
626 application.SendNotification();
627 application.Render();
630 GestureReceivedFunctor functor(data);
632 PinchGestureDetector detector = PinchGestureDetector::New();
633 detector.Attach(parent);
634 detector.DetectedSignal().Connect(&application, functor);
636 // Do an entire pan, only check finished value - hits child area but parent should still receive it
637 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
639 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
640 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
641 DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
642 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
643 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
644 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
646 // Attach child and generate same touch points to yield same results
647 // (Also proves that you can detach and then re-attach another actor)
648 detector.Attach(child);
649 detector.Detach(parent);
651 // Do an entire pan, only check finished value
652 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
654 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
655 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
656 DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
657 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
658 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
659 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
663 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
665 TestApplication application;
667 Actor first = Actor::New();
668 first.SetSize(100.0f, 100.0f);
669 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
670 Stage::GetCurrent().Add(first);
672 Actor second = Actor::New();
673 second.SetSize(100.0f, 100.0f);
675 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
676 Stage::GetCurrent().Add(second);
679 application.SendNotification();
680 application.Render();
683 GestureReceivedFunctor functor(data);
685 PinchGestureDetector detector = PinchGestureDetector::New();
686 detector.Attach(first);
687 detector.Attach(second);
688 detector.DetectedSignal().Connect(&application, functor);
690 // Start pinch within second actor's area
691 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
692 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
693 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
695 // Pinch moves into first actor's area - second actor should receive the pinch
697 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
698 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
699 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
701 // Detach the second actor during the pinch, we should not receive the next event
702 detector.Detach(second);
704 // Gesture ends within actor's area
706 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
707 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
711 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
713 TestApplication application;
715 Actor actor = Actor::New();
716 actor.SetSize(100.0f, 100.0f);
717 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
718 Stage::GetCurrent().Add(actor);
721 application.SendNotification();
722 application.Render();
725 GestureReceivedFunctor functor(data);
727 PinchGestureDetector detector = PinchGestureDetector::New();
728 detector.Attach(actor);
729 detector.DetectedSignal().Connect(&application, functor);
731 // Start pinch in actor's area
732 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
733 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
735 // Pan continues within actor's area
737 application.ProcessEvent(GeneratePinch(Gesture::Started, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
738 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
740 // Actor become invisible - actor should not receive the next pinch
741 actor.SetVisible(false);
744 application.SendNotification();
745 application.Render();
747 // Gesture ends within actor's area
749 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
750 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
754 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
756 TestApplication application;
758 Actor actor = Actor::New();
759 actor.SetSize(100.0f, 100.0f);
760 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
761 Stage::GetCurrent().Add(actor);
763 Actor actor2 = Actor::New();
764 actor2.SetSize(100.0f, 100.0f);
765 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
766 Stage::GetCurrent().Add(actor2);
769 application.SendNotification();
770 application.Render();
772 // Attach actor to one detector
773 SignalData firstData;
774 GestureReceivedFunctor firstFunctor(firstData);
775 PinchGestureDetector firstDetector = PinchGestureDetector::New();
776 firstDetector.Attach(actor);
777 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
779 // Attach actor to another detector
780 SignalData secondData;
781 GestureReceivedFunctor secondFunctor(secondData);
782 PinchGestureDetector secondDetector = PinchGestureDetector::New();
783 secondDetector.Attach(actor);
784 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
786 // Add second actor to second detector, when we remove the actor, this will make sure that this
787 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
788 // functor should still not be called (which is what we're also testing).
789 secondDetector.Attach(actor2);
791 // Pinch in actor's area - both detector's functors should be called
792 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
793 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
794 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
796 // Pinch continues in actor's area - both detector's functors should be called
799 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
800 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
801 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
803 // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
804 firstDetector.Detach(actor);
807 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
808 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
809 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
811 // New pinch on actor, only secondDetector has actor attached
814 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
815 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
816 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
818 // Detach actor from secondDetector
819 secondDetector.Detach(actor);
822 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
823 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
824 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
828 int UtcDaliPinchGestureSignalReceptionMultipleStarted(void)
830 // Should handle two started events gracefully.
832 TestApplication application;
834 Actor actor = Actor::New();
835 actor.SetSize(100.0f, 100.0f);
836 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
837 Stage::GetCurrent().Add(actor);
840 GestureReceivedFunctor functor(data);
842 PinchGestureDetector detector = PinchGestureDetector::New();
843 detector.Attach(actor);
844 detector.DetectedSignal().Connect(&application, functor);
847 application.SendNotification();
848 application.Render();
850 // Start pan in actor's area
851 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
852 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
854 // Send another start in actor's area
856 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
857 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
859 // Add a child actor to overlap actor and send another start in actor's area
860 Actor child = Actor::New();
861 child.SetSize(100.0f, 100.0f);
862 child.SetAnchorPoint(AnchorPoint::CENTER);
863 child.SetParentOrigin(ParentOrigin::CENTER);
866 TouchEventFunctor touchFunctor;
867 child.TouchedSignal().Connect(&application, touchFunctor);
870 application.SendNotification();
871 application.Render();
873 // Send another start in actor's area
875 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
876 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
878 // Send another start in actor's area
880 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
881 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
885 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
887 TestApplication application;
889 Actor actor1 = Actor::New();
890 actor1.SetSize(100.0f, 100.0f);
891 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
892 Stage::GetCurrent().Add(actor1);
894 GestureReceivedFunctor functor1(data1);
895 PinchGestureDetector detector1 = PinchGestureDetector::New();
896 detector1.Attach(actor1);
897 detector1.DetectedSignal().Connect(&application, functor1);
899 Actor actor2 = Actor::New();
900 actor2.SetSize(100.0f, 100.0f);
901 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
902 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
903 Stage::GetCurrent().Add(actor2);
905 GestureReceivedFunctor functor2(data2);
906 PinchGestureDetector detector2 = PinchGestureDetector::New();
907 detector2.Attach(actor2);
908 detector2.DetectedSignal().Connect(&application, functor2);
911 application.SendNotification();
912 application.Render();
914 // Start pan in actor1's area, only data1 should be set
915 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
916 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
917 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
921 int UtcDaliPinchGestureEmitIncorrectStateClear(void)
923 TestApplication application;
925 Actor actor = Actor::New();
926 actor.SetSize(100.0f, 100.0f);
927 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
928 Stage::GetCurrent().Add(actor);
931 application.SendNotification();
932 application.Render();
934 // Attach actor to detector
936 GestureReceivedFunctor functor( data );
937 PinchGestureDetector detector = PinchGestureDetector::New();
938 detector.Attach(actor);
939 detector.DetectedSignal().Connect( &application, functor );
944 application.ProcessEvent(GeneratePinch(Gesture::Clear, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
945 tet_result(TET_FAIL);
947 catch ( Dali::DaliException& e )
949 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
954 int UtcDaliPinchGestureEmitIncorrectStatePossible(void)
956 TestApplication application;
958 Actor actor = Actor::New();
959 actor.SetSize(100.0f, 100.0f);
960 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
961 Stage::GetCurrent().Add(actor);
964 application.SendNotification();
965 application.Render();
967 // Attach actor to detector
969 GestureReceivedFunctor functor( data );
970 PinchGestureDetector detector = PinchGestureDetector::New();
971 detector.Attach(actor);
972 detector.DetectedSignal().Connect( &application, functor );
974 // Try a Possible state
977 application.ProcessEvent(GeneratePinch(Gesture::Possible, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
978 tet_result(TET_FAIL);
980 catch ( Dali::DaliException& e )
982 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
987 int UtcDaliPinchGestureActorUnstaged(void)
989 TestApplication application;
991 Actor actor = Actor::New();
992 actor.SetSize(100.0f, 100.0f);
993 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
994 Stage::GetCurrent().Add(actor);
997 application.SendNotification();
998 application.Render();
1000 // State to remove actor in.
1001 Gesture::State stateToUnstage( Gesture::Started );
1003 // Attach actor to detector
1005 UnstageActorFunctor functor( data, stateToUnstage );
1006 PinchGestureDetector detector = PinchGestureDetector::New();
1007 detector.Attach(actor);
1008 detector.DetectedSignal().Connect( &application, functor );
1011 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1012 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1014 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1015 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1018 // Render and notify
1019 application.SendNotification();
1020 application.Render();
1022 // Re-add actor to stage
1023 Stage::GetCurrent().Add(actor);
1025 // Render and notify
1026 application.SendNotification();
1027 application.Render();
1029 // Change state to Gesture::Continuing to remove
1030 stateToUnstage = Gesture::Continuing;
1033 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1034 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1036 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1037 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1039 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1040 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1043 // Render and notify
1044 application.SendNotification();
1045 application.Render();
1047 // Re-add actor to stage
1048 Stage::GetCurrent().Add(actor);
1050 // Render and notify
1051 application.SendNotification();
1052 application.Render();
1054 // Change state to Gesture::Continuing to remove
1055 stateToUnstage = Gesture::Finished;
1058 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1059 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1061 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1062 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1064 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1065 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1066 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1070 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
1072 TestApplication application;
1074 Actor actor = Actor::New();
1075 actor.SetSize(100.0f, 100.0f);
1076 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1077 Stage::GetCurrent().Add(actor);
1079 // Create and add a second actor so that GestureDetector destruction does not come into play.
1080 Actor dummyActor( Actor::New() );
1081 dummyActor.SetSize( 100.0f, 100.0f );
1082 dummyActor.SetPosition( 100.0f, 100.0f );
1083 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1084 Stage::GetCurrent().Add(dummyActor);
1086 // Render and notify
1087 application.SendNotification();
1088 application.Render();
1090 // State to remove actor in.
1091 Gesture::State stateToUnstage( Gesture::Started );
1093 // Attach actor to detector
1095 UnstageActorFunctor functor( data, stateToUnstage );
1096 PinchGestureDetector detector = PinchGestureDetector::New();
1097 detector.Attach(actor);
1098 detector.Attach(dummyActor);
1099 detector.DetectedSignal().Connect( &application, functor );
1101 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1102 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1103 // position, we should still not be signalled.
1106 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1107 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1110 // Render and notify
1111 application.SendNotification();
1112 application.Render();
1114 // Re add to the stage, we should not be signalled
1115 Stage::GetCurrent().Add(actor);
1117 // Render and notify
1118 application.SendNotification();
1119 application.Render();
1121 // Continue signal emission
1122 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1123 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1125 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1126 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1129 // Here we delete an actor in started, we should not receive any subsequent signalling.
1132 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1133 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1136 // Render and notify
1137 application.SendNotification();
1138 application.Render();
1140 // Delete actor as well
1143 // Render and notify
1144 application.SendNotification();
1145 application.Render();
1147 // Continue signal emission
1148 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1149 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1151 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1152 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1156 int UtcDaliPinchGestureSystemOverlay(void)
1158 TestApplication application;
1159 Dali::Integration::Core& core = application.GetCore();
1160 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1161 systemOverlay.GetOverlayRenderTasks().CreateTask();
1163 Actor actor = Actor::New();
1164 actor.SetSize(100.0f, 100.0f);
1165 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1166 systemOverlay.Add(actor);
1168 // Render and notify
1169 application.SendNotification();
1170 application.Render();
1173 GestureReceivedFunctor functor(data);
1175 PinchGestureDetector detector = PinchGestureDetector::New();
1176 detector.Attach(actor);
1177 detector.DetectedSignal().Connect(&application, functor);
1179 Vector2 screenCoords( 50.0f, 50.0f );
1180 float scale ( 10.0f );
1181 float speed ( 50.0f );
1183 // Start pan within the actor's area
1184 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1185 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1189 int UtcDaliPinchGestureBehindTouchableSystemOverlay(void)
1191 TestApplication application;
1192 Dali::Integration::Core& core = application.GetCore();
1193 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1194 systemOverlay.GetOverlayRenderTasks().CreateTask();
1196 // SystemOverlay actor
1197 Actor systemOverlayActor = Actor::New();
1198 systemOverlayActor.SetSize(100.0f, 100.0f);
1199 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1200 systemOverlay.Add(systemOverlayActor);
1203 Actor stageActor = Actor::New();
1204 stageActor.SetSize(100.0f, 100.0f);
1205 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1206 Stage::GetCurrent().Add(stageActor);
1208 // Render and notify
1209 application.SendNotification();
1210 application.Render();
1212 // Set system-overlay actor to touchable
1213 TouchEventData touchData;
1214 TouchEventDataFunctor touchFunctor( touchData );
1215 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1217 // Set stage actor to receive the gesture
1219 GestureReceivedFunctor functor(data);
1221 PinchGestureDetector detector = PinchGestureDetector::New();
1222 detector.Attach(stageActor);
1223 detector.DetectedSignal().Connect(&application, functor);
1225 Vector2 screenCoords( 50.0f, 50.0f );
1226 float scale ( 10.0f );
1227 float speed ( 50.0f );
1229 // Start pinch within the two actors' area
1230 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1231 application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1232 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1233 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1238 // Do touch in the same area
1239 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1240 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1241 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1246 int UtcDaliPinchGestureTouchBehindGesturedSystemOverlay(void)
1248 TestApplication application;
1249 Dali::Integration::Core& core = application.GetCore();
1250 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1251 systemOverlay.GetOverlayRenderTasks().CreateTask();
1253 // SystemOverlay actor
1254 Actor systemOverlayActor = Actor::New();
1255 systemOverlayActor.SetSize(100.0f, 100.0f);
1256 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1257 systemOverlay.Add(systemOverlayActor);
1260 Actor stageActor = Actor::New();
1261 stageActor.SetSize(100.0f, 100.0f);
1262 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1263 Stage::GetCurrent().Add(stageActor);
1265 // Render and notify
1266 application.SendNotification();
1267 application.Render();
1269 // Set stage actor to touchable
1270 TouchEventData touchData;
1271 TouchEventDataFunctor touchFunctor( touchData );
1272 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1274 // Set system-overlay actor to have the gesture
1276 GestureReceivedFunctor functor(data);
1278 PinchGestureDetector detector = PinchGestureDetector::New();
1279 detector.Attach(systemOverlayActor);
1280 detector.DetectedSignal().Connect(&application, functor);
1282 Vector2 screenCoords( 50.0f, 50.0f );
1283 float scale ( 10.0f );
1284 float speed ( 50.0f );
1286 // Start pinch within the two actors' area
1287 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1288 application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1289 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1290 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1295 // Do touch in the same area
1296 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1297 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1298 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1303 int UtcDaliPinchGestureLayerConsumesTouch(void)
1305 TestApplication application;
1307 Actor actor = Actor::New();
1308 actor.SetSize(100.0f, 100.0f);
1309 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1310 Stage::GetCurrent().Add(actor);
1314 GestureReceivedFunctor functor(data);
1315 PinchGestureDetector detector = PinchGestureDetector::New();
1316 detector.Attach(actor);
1317 detector.DetectedSignal().Connect( &application, functor );
1319 // Add a layer to overlap the actor
1320 Layer layer = Layer::New();
1321 layer.SetSize(100.0f, 100.0f);
1322 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1323 Stage::GetCurrent().Add( layer );
1326 // Render and notify
1327 application.SendNotification();
1328 application.Render();
1330 Vector2 screenCoords( 50.0f, 50.0f );
1331 float scale ( 10.0f );
1332 float speed ( 50.0f );
1334 // Emit signals, should receive
1335 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1336 application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1337 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1340 // Set layer to consume all touch
1341 layer.SetTouchConsumed( true );
1343 // Render and notify
1344 application.SendNotification();
1345 application.Render();
1347 // Emit the same signals again, should not receive
1348 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1349 application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1350 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);