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, const 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, const 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 UtcDaliPinchGestureDetectorCopyConstructorP(void)
155 TestApplication application;
157 PinchGestureDetector detector = PinchGestureDetector::New();;
159 PinchGestureDetector copy( detector );
160 DALI_TEST_CHECK( detector );
164 int UtcDaliPinchGestureDetectorAssignmentOperatorP(void)
166 TestApplication application;
168 PinchGestureDetector detector = PinchGestureDetector::New();;
170 PinchGestureDetector assign;
172 DALI_TEST_CHECK( detector );
174 DALI_TEST_CHECK( detector == assign );
178 int UtcDaliPinchGestureDetectorNew(void)
180 TestApplication application;
182 PinchGestureDetector detector = PinchGestureDetector::New();
184 DALI_TEST_CHECK(detector);
186 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
187 Actor actor = Actor::New();
188 actor.SetSize(100.0f, 100.0f);
189 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
190 Stage::GetCurrent().Add(actor);
193 application.SendNotification();
194 application.Render();
196 detector.Attach(actor);
198 Integration::TouchEvent touchEvent(1);
199 TouchPoint point(1, TouchPoint::Down, 20.0f, 20.0f);
200 touchEvent.AddPoint(point);
201 application.ProcessEvent(touchEvent);
203 TouchPoint point2(1, TouchPoint::Down, 20.0f, 20.0f, 20.0f, 20.0f);
204 touchEvent.AddPoint(point2);
205 application.ProcessEvent(touchEvent);
209 int UtcDaliPinchGestureDetectorDownCast(void)
211 TestApplication application;
212 tet_infoline("Testing Dali::PinchGestureDetector::DownCast()");
214 PinchGestureDetector detector = PinchGestureDetector::New();
216 BaseHandle object(detector);
218 PinchGestureDetector detector2 = PinchGestureDetector::DownCast(object);
219 DALI_TEST_CHECK(detector2);
221 PinchGestureDetector detector3 = DownCast< PinchGestureDetector >(object);
222 DALI_TEST_CHECK(detector3);
224 BaseHandle unInitializedObject;
225 PinchGestureDetector detector4 = PinchGestureDetector::DownCast(unInitializedObject);
226 DALI_TEST_CHECK(!detector4);
228 PinchGestureDetector detector5 = DownCast< PinchGestureDetector >(unInitializedObject);
229 DALI_TEST_CHECK(!detector5);
231 GestureDetector detector6 = PinchGestureDetector::New();
232 PinchGestureDetector detector7 = PinchGestureDetector::DownCast(detector6);
233 DALI_TEST_CHECK(detector7);
237 // Negative test case for a method
238 int UtcDaliPinchGestureSignalReceptionNegative(void)
240 TestApplication application;
242 Actor actor = Actor::New();
243 actor.SetSize(100.0f, 100.0f);
244 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
245 Stage::GetCurrent().Add(actor);
248 application.SendNotification();
249 application.Render();
252 GestureReceivedFunctor functor(data);
254 PinchGestureDetector detector = PinchGestureDetector::New();
255 detector.Attach(actor);
256 detector.DetectedSignal().Connect(&application, functor);
258 // Do a pinch outside actor's area
259 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 45.0f, Vector2(112.0f, 112.0f)));
260 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
262 // Continue pinch into actor's area - we should still not receive the signal
264 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 4.5f, 95.0f, Vector2(20.0f, 20.0f)));
265 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
267 // Stop pinching - we should still not receive the signal
269 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(12.0f, 12.0f)));
270 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
274 int UtcDaliPinchGestureSignalReceptionDownMotionLeave(void)
276 TestApplication application;
278 Actor actor = Actor::New();
279 actor.SetSize(100.0f, 100.0f);
280 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
281 Stage::GetCurrent().Add(actor);
284 application.SendNotification();
285 application.Render();
288 GestureReceivedFunctor functor(data);
290 PinchGestureDetector detector = PinchGestureDetector::New();
291 detector.Attach(actor);
292 detector.DetectedSignal().Connect(&application, functor);
294 // Start pan within the actor's area
295 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
296 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
297 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
298 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
299 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
300 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
302 // Continue the pan within the actor's area - we should still receive the signal
304 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 90.0f, Vector2(21.0f, 20.0f)));
305 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
306 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
307 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
308 DALI_TEST_EQUALS(90.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
309 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
311 // Pan Gesture leaves actor's area - we should still receive the signal
313 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 15.5f, Vector2(320.0f, 10.0f)));
314 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
315 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
316 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
317 DALI_TEST_EQUALS(15.5f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
318 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
320 // Gesture ends - we would receive a finished state
322 application.ProcessEvent(GeneratePinch(Gesture::Finished, 15.2f, 12.1f, Vector2(310.0f, 10.0f)));
323 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
324 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
325 DALI_TEST_EQUALS(15.2f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
326 DALI_TEST_EQUALS(12.1f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
327 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
331 int UtcDaliPinchGestureSignalReceptionDownMotionUp(void)
333 TestApplication application;
335 Actor actor = Actor::New();
336 actor.SetSize(100.0f, 100.0f);
337 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
338 Stage::GetCurrent().Add(actor);
341 application.SendNotification();
342 application.Render();
345 GestureReceivedFunctor functor(data);
347 PinchGestureDetector detector = PinchGestureDetector::New();
348 detector.Attach(actor);
349 detector.DetectedSignal().Connect(&application, functor);
351 // Start pinch within the actor's area
352 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
353 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
354 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
355 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
356 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
357 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
359 // Continue the pinch within the actor's area - we should still receive the signal
361 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
362 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
363 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
364 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
365 DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
366 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
368 // Gesture ends within actor's area - we would receive a finished state
370 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
371 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
372 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
373 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
374 DALI_TEST_EQUALS(25.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
375 DALI_TEST_EQUALS(Vector2(20.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
379 int UtcDaliPinchGestureSignalReceptionCancelled(void)
381 TestApplication application;
383 Actor actor = Actor::New();
384 actor.SetSize(100.0f, 100.0f);
385 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
386 Stage::GetCurrent().Add(actor);
389 application.SendNotification();
390 application.Render();
393 GestureReceivedFunctor functor(data);
395 PinchGestureDetector detector = PinchGestureDetector::New();
396 detector.Attach(actor);
397 detector.DetectedSignal().Connect(&application, functor);
399 // Start pinch within the actor's area
400 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
401 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
402 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
405 // Continue the pinch within the actor's area - we should still receive the signal
407 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
408 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
409 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
411 // The gesture is cancelled
413 application.ProcessEvent(GeneratePinch(Gesture::Cancelled, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
414 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
415 DALI_TEST_EQUALS(Gesture::Cancelled, data.receivedGesture.state, TEST_LOCATION);
419 int UtcDaliPinchGestureSignalReceptionDetach(void)
421 TestApplication application;
423 Actor actor = Actor::New();
424 actor.SetSize(100.0f, 100.0f);
425 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
426 Stage::GetCurrent().Add(actor);
429 application.SendNotification();
430 application.Render();
433 GestureReceivedFunctor functor(data);
435 PinchGestureDetector detector = PinchGestureDetector::New();
436 detector.Attach(actor);
437 detector.DetectedSignal().Connect(&application, functor);
439 // Start pinch within the actor's area
440 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
441 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
442 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
445 // Continue the pinch within the actor's area - we should still receive the signal
447 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
448 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
449 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
451 // Gesture ends within actor's area
453 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
454 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
455 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
458 detector.DetachAll();
460 // Ensure we are no longer signalled
462 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 20.0f)));
463 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
464 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
465 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
469 int UtcDaliPinchGestureSignalReceptionDetachWhilePinching(void)
471 TestApplication application;
473 Actor actor = Actor::New();
474 actor.SetSize(100.0f, 100.0f);
475 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
476 Stage::GetCurrent().Add(actor);
479 application.SendNotification();
480 application.Render();
483 GestureReceivedFunctor functor(data);
485 PinchGestureDetector detector = PinchGestureDetector::New();
486 detector.Attach(actor);
487 detector.DetectedSignal().Connect(&application, functor);
489 // Start pinch within the actor's area
490 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
491 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
492 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
494 // Continue the pinch within the actor's area - we should still receive the signal
496 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
497 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
498 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
500 // Detach actor during the pinch, we should not receive the next event
501 detector.DetachAll();
503 // Gesture ends within actor's area
505 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
506 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
510 int UtcDaliPinchGestureSignalReceptionActorDestroyedWhilePinching(void)
512 TestApplication application;
515 GestureReceivedFunctor functor(data);
517 PinchGestureDetector detector = PinchGestureDetector::New();
518 detector.DetectedSignal().Connect(&application, functor);
520 // Attach a temporary actor to stop detector being removed from PinchGestureProcessor when main actor
522 Actor tempActor = Actor::New();
523 tempActor.SetSize(100.0f, 100.0f);
524 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
525 Stage::GetCurrent().Add(tempActor);
526 detector.Attach(tempActor);
528 // Actor lifetime is scoped
530 Actor actor = Actor::New();
531 actor.SetSize(100.0f, 100.0f);
532 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
533 Stage::GetCurrent().Add(actor);
536 application.SendNotification();
537 application.Render();
539 detector.Attach(actor);
541 // Start pinch within the actor's area
542 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
543 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
544 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
546 // Continue the pinch within the actor's area - we should still receive the signal
548 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
549 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
550 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
552 // Remove the actor from stage and reset the data
553 Stage::GetCurrent().Remove(actor);
556 application.SendNotification();
557 application.Render();
560 // Actor should now have been destroyed
562 // Gesture ends within the area where the actor used to be
564 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 25.0f, Vector2(20.0f, 20.0f)));
565 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
569 int UtcDaliPinchGestureSignalReceptionRotatedActor(void)
571 TestApplication application;
573 Actor actor = Actor::New();
574 actor.SetSize(100.0f, 100.0f);
575 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
576 Stage::GetCurrent().Add(actor);
578 // Render and notify a couple of times
579 application.SendNotification();
580 application.Render();
583 GestureReceivedFunctor functor(data);
585 PinchGestureDetector detector = PinchGestureDetector::New();
586 detector.Attach(actor);
587 detector.DetectedSignal().Connect(&application, functor);
589 // Do an entire pinch, only check finished value
590 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
592 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
593 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
594 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
595 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
596 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
598 // Rotate actor again and render and notify
599 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
600 application.SendNotification();
601 application.Render();
603 // Do an entire pinch, only check finished value
604 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
606 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
607 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
608 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
609 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
610 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
612 // Rotate actor again and render and notify
613 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
614 application.SendNotification();
615 application.Render();
617 // Do an entire pinch, only check finished value
618 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
620 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
621 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
622 DALI_TEST_EQUALS(10.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
623 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
624 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
628 int UtcDaliPinchGestureSignalReceptionChildHit(void)
630 TestApplication application;
632 Actor parent = Actor::New();
633 parent.SetSize(100.0f, 100.0f);
634 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
635 Stage::GetCurrent().Add(parent);
637 // Set child to completely cover parent.
638 // Change rotation of child to be different from parent so that we can check if our local coordinate
639 // conversion of the parent actor is correct.
640 Actor child = Actor::New();
641 child.SetSize(100.0f, 100.0f);
642 child.SetAnchorPoint(AnchorPoint::CENTER);
643 child.SetParentOrigin(ParentOrigin::CENTER);
644 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
647 TouchEventFunctor touchFunctor;
648 child.TouchedSignal().Connect(&application, touchFunctor);
651 application.SendNotification();
652 application.Render();
655 GestureReceivedFunctor functor(data);
657 PinchGestureDetector detector = PinchGestureDetector::New();
658 detector.Attach(parent);
659 detector.DetectedSignal().Connect(&application, functor);
661 // Do an entire pan, only check finished value - hits child area but parent should still receive it
662 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
664 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
665 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
666 DALI_TEST_EQUALS(true, parent == data.pinchedActor, TEST_LOCATION);
667 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
668 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
669 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
671 // Attach child and generate same touch points to yield same results
672 // (Also proves that you can detach and then re-attach another actor)
673 detector.Attach(child);
674 detector.Detach(parent);
676 // Do an entire pan, only check finished value
677 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
679 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
680 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
681 DALI_TEST_EQUALS(true, child == data.pinchedActor, TEST_LOCATION);
682 DALI_TEST_EQUALS(5.0f, data.receivedGesture.scale, 0.01f, TEST_LOCATION);
683 DALI_TEST_EQUALS(50.0f, data.receivedGesture.speed, 0.01f, TEST_LOCATION);
684 DALI_TEST_EQUALS(Vector2(10.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
688 int UtcDaliPinchGestureSignalReceptionAttachDetachMany(void)
690 TestApplication application;
692 Actor first = Actor::New();
693 first.SetSize(100.0f, 100.0f);
694 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
695 Stage::GetCurrent().Add(first);
697 Actor second = Actor::New();
698 second.SetSize(100.0f, 100.0f);
700 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
701 Stage::GetCurrent().Add(second);
704 application.SendNotification();
705 application.Render();
708 GestureReceivedFunctor functor(data);
710 PinchGestureDetector detector = PinchGestureDetector::New();
711 detector.Attach(first);
712 detector.Attach(second);
713 detector.DetectedSignal().Connect(&application, functor);
715 // Start pinch within second actor's area
716 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
717 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
718 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
720 // Pinch moves into first actor's area - second actor should receive the pinch
722 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(10.0f, 10.0f)));
723 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
724 DALI_TEST_EQUALS(true, second == data.pinchedActor, TEST_LOCATION);
726 // Detach the second actor during the pinch, we should not receive the next event
727 detector.Detach(second);
729 // Gesture ends within actor's area
731 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(120.0f, 10.0f)));
732 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
736 int UtcDaliPinchGestureSignalReceptionActorBecomesUntouchable(void)
738 TestApplication application;
740 Actor actor = Actor::New();
741 actor.SetSize(100.0f, 100.0f);
742 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
743 Stage::GetCurrent().Add(actor);
746 application.SendNotification();
747 application.Render();
750 GestureReceivedFunctor functor(data);
752 PinchGestureDetector detector = PinchGestureDetector::New();
753 detector.Attach(actor);
754 detector.DetectedSignal().Connect(&application, functor);
756 // Start pinch in actor's area
757 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
758 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
760 // Pan continues within actor's area
762 application.ProcessEvent(GeneratePinch(Gesture::Started, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
763 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
765 // Actor become invisible - actor should not receive the next pinch
766 actor.SetVisible(false);
769 application.SendNotification();
770 application.Render();
772 // Gesture ends within actor's area
774 application.ProcessEvent(GeneratePinch(Gesture::Finished, 5.0f, 50.0f, Vector2(10.0f, 10.0f)));
775 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
779 int UtcDaliPinchGestureSignalReceptionMultipleDetectorsOnActor(void)
781 TestApplication application;
783 Actor actor = Actor::New();
784 actor.SetSize(100.0f, 100.0f);
785 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
786 Stage::GetCurrent().Add(actor);
788 Actor actor2 = Actor::New();
789 actor2.SetSize(100.0f, 100.0f);
790 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
791 Stage::GetCurrent().Add(actor2);
794 application.SendNotification();
795 application.Render();
797 // Attach actor to one detector
798 SignalData firstData;
799 GestureReceivedFunctor firstFunctor(firstData);
800 PinchGestureDetector firstDetector = PinchGestureDetector::New();
801 firstDetector.Attach(actor);
802 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
804 // Attach actor to another detector
805 SignalData secondData;
806 GestureReceivedFunctor secondFunctor(secondData);
807 PinchGestureDetector secondDetector = PinchGestureDetector::New();
808 secondDetector.Attach(actor);
809 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
811 // Add second actor to second detector, when we remove the actor, this will make sure that this
812 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
813 // functor should still not be called (which is what we're also testing).
814 secondDetector.Attach(actor2);
816 // Pinch in actor's area - both detector's functors should be called
817 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
818 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
819 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
821 // Pinch continues in actor's area - both detector's functors should be called
824 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
825 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
826 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
828 // Detach actor from firstDetector and emit pinch on actor, only secondDetector's functor should be called.
829 firstDetector.Detach(actor);
832 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
833 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
834 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
836 // New pinch on actor, only secondDetector has actor attached
839 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
840 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
841 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
843 // Detach actor from secondDetector
844 secondDetector.Detach(actor);
847 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
848 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
849 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
853 int UtcDaliPinchGestureSignalReceptionMultipleStarted(void)
855 // Should handle two started events gracefully.
857 TestApplication application;
859 Actor actor = Actor::New();
860 actor.SetSize(100.0f, 100.0f);
861 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
862 Stage::GetCurrent().Add(actor);
865 GestureReceivedFunctor functor(data);
867 PinchGestureDetector detector = PinchGestureDetector::New();
868 detector.Attach(actor);
869 detector.DetectedSignal().Connect(&application, functor);
872 application.SendNotification();
873 application.Render();
875 // Start pan in actor's area
876 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
877 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
879 // Send another start in actor's area
881 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
882 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
884 // Add a child actor to overlap actor and send another start in actor's area
885 Actor child = Actor::New();
886 child.SetSize(100.0f, 100.0f);
887 child.SetAnchorPoint(AnchorPoint::CENTER);
888 child.SetParentOrigin(ParentOrigin::CENTER);
891 TouchEventFunctor touchFunctor;
892 child.TouchedSignal().Connect(&application, touchFunctor);
895 application.SendNotification();
896 application.Render();
898 // Send another start in actor's area
900 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
901 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
903 // Send another start in actor's area
905 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
906 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
910 int UtcDaliPinchGestureSignalReceptionEnsureCorrectSignalling(void)
912 TestApplication application;
914 Actor actor1 = Actor::New();
915 actor1.SetSize(100.0f, 100.0f);
916 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
917 Stage::GetCurrent().Add(actor1);
919 GestureReceivedFunctor functor1(data1);
920 PinchGestureDetector detector1 = PinchGestureDetector::New();
921 detector1.Attach(actor1);
922 detector1.DetectedSignal().Connect(&application, functor1);
924 Actor actor2 = Actor::New();
925 actor2.SetSize(100.0f, 100.0f);
926 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
927 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
928 Stage::GetCurrent().Add(actor2);
930 GestureReceivedFunctor functor2(data2);
931 PinchGestureDetector detector2 = PinchGestureDetector::New();
932 detector2.Attach(actor2);
933 detector2.DetectedSignal().Connect(&application, functor2);
936 application.SendNotification();
937 application.Render();
939 // Start pan in actor1's area, only data1 should be set
940 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
941 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
942 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
946 int UtcDaliPinchGestureEmitIncorrectStateClear(void)
948 TestApplication application;
950 Actor actor = Actor::New();
951 actor.SetSize(100.0f, 100.0f);
952 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
953 Stage::GetCurrent().Add(actor);
956 application.SendNotification();
957 application.Render();
959 // Attach actor to detector
961 GestureReceivedFunctor functor( data );
962 PinchGestureDetector detector = PinchGestureDetector::New();
963 detector.Attach(actor);
964 detector.DetectedSignal().Connect( &application, functor );
969 application.ProcessEvent(GeneratePinch(Gesture::Clear, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
970 tet_result(TET_FAIL);
972 catch ( Dali::DaliException& e )
974 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
979 int UtcDaliPinchGestureEmitIncorrectStatePossible(void)
981 TestApplication application;
983 Actor actor = Actor::New();
984 actor.SetSize(100.0f, 100.0f);
985 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
986 Stage::GetCurrent().Add(actor);
989 application.SendNotification();
990 application.Render();
992 // Attach actor to detector
994 GestureReceivedFunctor functor( data );
995 PinchGestureDetector detector = PinchGestureDetector::New();
996 detector.Attach(actor);
997 detector.DetectedSignal().Connect( &application, functor );
999 // Try a Possible state
1002 application.ProcessEvent(GeneratePinch(Gesture::Possible, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1003 tet_result(TET_FAIL);
1005 catch ( Dali::DaliException& e )
1007 DALI_TEST_ASSERT( e, "false", TEST_LOCATION );
1012 int UtcDaliPinchGestureActorUnstaged(void)
1014 TestApplication application;
1016 Actor actor = Actor::New();
1017 actor.SetSize(100.0f, 100.0f);
1018 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1019 Stage::GetCurrent().Add(actor);
1021 // Render and notify
1022 application.SendNotification();
1023 application.Render();
1025 // State to remove actor in.
1026 Gesture::State stateToUnstage( Gesture::Started );
1028 // Attach actor to detector
1030 UnstageActorFunctor functor( data, stateToUnstage );
1031 PinchGestureDetector detector = PinchGestureDetector::New();
1032 detector.Attach(actor);
1033 detector.DetectedSignal().Connect( &application, functor );
1036 application.ProcessEvent(GeneratePinch(Gesture::Started, 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::Continuing;
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(false, data.functorCalled, TEST_LOCATION);
1068 // Render and notify
1069 application.SendNotification();
1070 application.Render();
1072 // Re-add actor to stage
1073 Stage::GetCurrent().Add(actor);
1075 // Render and notify
1076 application.SendNotification();
1077 application.Render();
1079 // Change state to Gesture::Continuing to remove
1080 stateToUnstage = Gesture::Finished;
1083 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1084 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1086 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1087 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1089 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1090 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1091 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
1095 int UtcDaliPinchGestureActorStagedAndDestroyed(void)
1097 TestApplication application;
1099 Actor actor = Actor::New();
1100 actor.SetSize(100.0f, 100.0f);
1101 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1102 Stage::GetCurrent().Add(actor);
1104 // Create and add a second actor so that GestureDetector destruction does not come into play.
1105 Actor dummyActor( Actor::New() );
1106 dummyActor.SetSize( 100.0f, 100.0f );
1107 dummyActor.SetPosition( 100.0f, 100.0f );
1108 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1109 Stage::GetCurrent().Add(dummyActor);
1111 // Render and notify
1112 application.SendNotification();
1113 application.Render();
1115 // State to remove actor in.
1116 Gesture::State stateToUnstage( Gesture::Started );
1118 // Attach actor to detector
1120 UnstageActorFunctor functor( data, stateToUnstage );
1121 PinchGestureDetector detector = PinchGestureDetector::New();
1122 detector.Attach(actor);
1123 detector.Attach(dummyActor);
1124 detector.DetectedSignal().Connect( &application, functor );
1126 // Here we are testing a Started actor which is removed in the Started callback, but then added back
1127 // before we get a continuing state. As we were removed from the stage, even if we're at the same
1128 // position, we should still not be signalled.
1131 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1132 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1135 // Render and notify
1136 application.SendNotification();
1137 application.Render();
1139 // Re add to the stage, we should not be signalled
1140 Stage::GetCurrent().Add(actor);
1142 // Render and notify
1143 application.SendNotification();
1144 application.Render();
1146 // Continue signal emission
1147 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1148 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1150 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1151 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1154 // Here we delete an actor in started, we should not receive any subsequent signalling.
1157 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1158 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1161 // Render and notify
1162 application.SendNotification();
1163 application.Render();
1165 // Delete actor as well
1168 // Render and notify
1169 application.SendNotification();
1170 application.Render();
1172 // Continue signal emission
1173 application.ProcessEvent(GeneratePinch(Gesture::Continuing, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1174 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1176 application.ProcessEvent(GeneratePinch(Gesture::Finished, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1177 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1181 int UtcDaliPinchGestureSystemOverlay(void)
1183 TestApplication application;
1184 Dali::Integration::Core& core = application.GetCore();
1185 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1186 systemOverlay.GetOverlayRenderTasks().CreateTask();
1188 Actor actor = Actor::New();
1189 actor.SetSize(100.0f, 100.0f);
1190 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1191 systemOverlay.Add(actor);
1193 // Render and notify
1194 application.SendNotification();
1195 application.Render();
1198 GestureReceivedFunctor functor(data);
1200 PinchGestureDetector detector = PinchGestureDetector::New();
1201 detector.Attach(actor);
1202 detector.DetectedSignal().Connect(&application, functor);
1204 Vector2 screenCoords( 50.0f, 50.0f );
1205 float scale ( 10.0f );
1206 float speed ( 50.0f );
1208 // Start pan within the actor's area
1209 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1210 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1214 int UtcDaliPinchGestureBehindTouchableSystemOverlay(void)
1216 TestApplication application;
1217 Dali::Integration::Core& core = application.GetCore();
1218 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1219 systemOverlay.GetOverlayRenderTasks().CreateTask();
1221 // SystemOverlay actor
1222 Actor systemOverlayActor = Actor::New();
1223 systemOverlayActor.SetSize(100.0f, 100.0f);
1224 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1225 systemOverlay.Add(systemOverlayActor);
1228 Actor stageActor = Actor::New();
1229 stageActor.SetSize(100.0f, 100.0f);
1230 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1231 Stage::GetCurrent().Add(stageActor);
1233 // Render and notify
1234 application.SendNotification();
1235 application.Render();
1237 // Set system-overlay actor to touchable
1238 TouchEventData touchData;
1239 TouchEventDataFunctor touchFunctor( touchData );
1240 systemOverlayActor.TouchedSignal().Connect(&application, touchFunctor);
1242 // Set stage actor to receive the gesture
1244 GestureReceivedFunctor functor(data);
1246 PinchGestureDetector detector = PinchGestureDetector::New();
1247 detector.Attach(stageActor);
1248 detector.DetectedSignal().Connect(&application, functor);
1250 Vector2 screenCoords( 50.0f, 50.0f );
1251 float scale ( 10.0f );
1252 float speed ( 50.0f );
1254 // Start pinch within the two actors' area
1255 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1256 application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1257 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1258 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1263 // Do touch in the same area
1264 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1265 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1266 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1271 int UtcDaliPinchGestureTouchBehindGesturedSystemOverlay(void)
1273 TestApplication application;
1274 Dali::Integration::Core& core = application.GetCore();
1275 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1276 systemOverlay.GetOverlayRenderTasks().CreateTask();
1278 // SystemOverlay actor
1279 Actor systemOverlayActor = Actor::New();
1280 systemOverlayActor.SetSize(100.0f, 100.0f);
1281 systemOverlayActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1282 systemOverlay.Add(systemOverlayActor);
1285 Actor stageActor = Actor::New();
1286 stageActor.SetSize(100.0f, 100.0f);
1287 stageActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1288 Stage::GetCurrent().Add(stageActor);
1290 // Render and notify
1291 application.SendNotification();
1292 application.Render();
1294 // Set stage actor to touchable
1295 TouchEventData touchData;
1296 TouchEventDataFunctor touchFunctor( touchData );
1297 stageActor.TouchedSignal().Connect(&application, touchFunctor);
1299 // Set system-overlay actor to have the gesture
1301 GestureReceivedFunctor functor(data);
1303 PinchGestureDetector detector = PinchGestureDetector::New();
1304 detector.Attach(systemOverlayActor);
1305 detector.DetectedSignal().Connect(&application, functor);
1307 Vector2 screenCoords( 50.0f, 50.0f );
1308 float scale ( 10.0f );
1309 float speed ( 50.0f );
1311 // Start pinch within the two actors' area
1312 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1313 application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1314 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1315 DALI_TEST_EQUALS( false, touchData.functorCalled, TEST_LOCATION );
1320 // Do touch in the same area
1321 application.ProcessEvent( touchFunctor.GenerateSingleTouch( TouchPoint::Down, screenCoords ) );
1322 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1323 DALI_TEST_EQUALS( true, touchData.functorCalled, TEST_LOCATION );
1328 int UtcDaliPinchGestureLayerConsumesTouch(void)
1330 TestApplication application;
1332 Actor actor = Actor::New();
1333 actor.SetSize(100.0f, 100.0f);
1334 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1335 Stage::GetCurrent().Add(actor);
1339 GestureReceivedFunctor functor(data);
1340 PinchGestureDetector detector = PinchGestureDetector::New();
1341 detector.Attach(actor);
1342 detector.DetectedSignal().Connect( &application, functor );
1344 // Add a layer to overlap the actor
1345 Layer layer = Layer::New();
1346 layer.SetSize(100.0f, 100.0f);
1347 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1348 Stage::GetCurrent().Add( layer );
1351 // Render and notify
1352 application.SendNotification();
1353 application.Render();
1355 Vector2 screenCoords( 50.0f, 50.0f );
1356 float scale ( 10.0f );
1357 float speed ( 50.0f );
1359 // Emit signals, should receive
1360 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1361 application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1362 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1365 // Set layer to consume all touch
1366 layer.SetTouchConsumed( true );
1368 // Render and notify
1369 application.SendNotification();
1370 application.Render();
1372 // Emit the same signals again, should not receive
1373 application.ProcessEvent( GeneratePinch( Gesture::Started, scale, speed, screenCoords ) );
1374 application.ProcessEvent( GeneratePinch( Gesture::Finished, scale, speed, screenCoords ) );
1375 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);