2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali/devel-api/events/gesture-devel.h>
25 #include <dali/devel-api/events/rotation-gesture.h>
26 #include <dali/devel-api/events/rotation-gesture-detector.h>
27 #include <dali-test-suite-utils.h>
28 #include <test-touch-utils.h>
32 void utc_dali_rotation_gesture_detector_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_rotation_gesture_detector_cleanup(void)
39 test_return_value = TET_PASS;
42 ///////////////////////////////////////////////////////////////////////////////
46 // Stores data that is populated in the callback and will be read by the TET cases
50 : functorCalled(false),
51 voidFunctorCalled(false),
52 receivedGesture(Gesture::Started)
57 functorCalled = false;
58 voidFunctorCalled = false;
60 receivedGesture.state = Gesture::Started;
61 receivedGesture.rotation = 0.0f;
62 receivedGesture.screenCenterPoint = Vector2(0.0f, 0.0f);
63 receivedGesture.localCenterPoint = Vector2(0.0f, 0.0f);
69 bool voidFunctorCalled;
70 RotationGesture receivedGesture;
74 // Functor that sets the data when called
75 struct GestureReceivedFunctor
77 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
79 void operator()(Actor actor, const RotationGesture& rotation)
81 signalData.functorCalled = true;
82 signalData.receivedGesture = rotation;
83 signalData.rotatedActor = actor;
88 signalData.voidFunctorCalled = true;
91 SignalData& signalData;
94 // Functor that removes the gestured actor from stage
95 struct UnstageActorFunctor : public GestureReceivedFunctor
97 UnstageActorFunctor( SignalData& data, Gesture::State& stateToUnstage )
98 : GestureReceivedFunctor( data ),
99 stateToUnstage( stateToUnstage )
103 void operator()( Actor actor, const RotationGesture& rotation )
105 GestureReceivedFunctor::operator()( actor, rotation );
107 if ( rotation.state == stateToUnstage )
109 Stage::GetCurrent().Remove( actor );
113 Gesture::State& stateToUnstage;
116 // Functor for receiving a touch event
117 struct TouchEventFunctor
119 bool operator()(Actor actor, const TouchEvent& touch)
127 ///////////////////////////////////////////////////////////////////////////////
129 int UtcDaliRotationGestureDetectorConstructor(void)
131 TestApplication application;
133 RotationGestureDetector detector;
134 DALI_TEST_CHECK(!detector);
138 int UtcDaliRotationGestureDetectorCopyConstructorP(void)
140 TestApplication application;
142 RotationGestureDetector detector = RotationGestureDetector::New();;
144 RotationGestureDetector copy( detector );
145 DALI_TEST_CHECK( detector );
149 int UtcDaliRotationGestureDetectorAssignmentOperatorP(void)
151 TestApplication application;
153 RotationGestureDetector detector = RotationGestureDetector::New();;
155 RotationGestureDetector assign;
157 DALI_TEST_CHECK( detector );
159 DALI_TEST_CHECK( detector == assign );
163 int UtcDaliRotationGestureDetectorNew(void)
165 TestApplication application;
167 RotationGestureDetector detector = RotationGestureDetector::New();
169 DALI_TEST_CHECK(detector);
171 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
172 Actor actor = Actor::New();
173 actor.SetSize(100.0f, 100.0f);
174 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
175 Stage::GetCurrent().Add(actor);
178 application.SendNotification();
179 application.Render();
181 detector.Attach(actor);
183 Integration::TouchEvent touchEvent(1);
184 Integration::Point point;
185 point.SetDeviceId( 1 );
186 point.SetState( PointState::DOWN );
187 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
188 touchEvent.AddPoint(point);
189 application.ProcessEvent(touchEvent);
191 Integration::Point point2;
192 point.SetDeviceId( 1 );
193 point.SetState( PointState::DOWN );
194 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
195 touchEvent.AddPoint(point2);
196 application.ProcessEvent(touchEvent);
200 int UtcDaliRotationGestureDetectorDownCast(void)
202 TestApplication application;
203 tet_infoline("Testing Dali::RotationGestureDetector::DownCast()");
205 RotationGestureDetector detector = RotationGestureDetector::New();
207 BaseHandle object(detector);
209 RotationGestureDetector detector2 = RotationGestureDetector::DownCast(object);
210 DALI_TEST_CHECK(detector2);
212 RotationGestureDetector detector3 = DownCast< RotationGestureDetector >(object);
213 DALI_TEST_CHECK(detector3);
215 BaseHandle unInitializedObject;
216 RotationGestureDetector detector4 = RotationGestureDetector::DownCast(unInitializedObject);
217 DALI_TEST_CHECK(!detector4);
219 RotationGestureDetector detector5 = DownCast< RotationGestureDetector >(unInitializedObject);
220 DALI_TEST_CHECK(!detector5);
222 GestureDetector detector6 = RotationGestureDetector::New();
223 RotationGestureDetector detector7 = RotationGestureDetector::DownCast(detector6);
224 DALI_TEST_CHECK(detector7);
228 // Negative test case for a method
229 int UtcDaliRotationGestureSignalReceptionNegative(void)
231 TestApplication application;
233 Actor actor = Actor::New();
234 actor.SetSize(100.0f, 100.0f);
235 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
236 Stage::GetCurrent().Add(actor);
239 application.SendNotification();
240 application.Render();
243 GestureReceivedFunctor functor(data);
245 RotationGestureDetector detector = RotationGestureDetector::New();
246 detector.Attach(actor);
247 detector.DetectedSignal().Connect(&application, functor);
249 // Do a rotation outside actor's area
250 TestStartRotation( application, Vector2( 112.0f, 62.0f ), Vector2( 112.0f, 162.0f ),
251 Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ), 100 );
253 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
255 // Continue rotation into actor's area - we should still not receive the signal
257 TestContinueRotation( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
258 Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
260 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
262 // Stop rotating - we should still not receive the signal
264 TestEndRotation( application, Vector2( 6.0f, 6.0f ), Vector2( 18.0f, 18.0f ),
265 Vector2( 10.0f, 8.0f ), Vector2( 14.0f, 16.0f ), 300 );
267 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
271 int UtcDaliRotationGestureSignalReceptionDownMotionLeave(void)
273 TestApplication application;
275 Actor actor = Actor::New();
276 actor.SetSize(100.0f, 100.0f);
277 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
278 Stage::GetCurrent().Add(actor);
281 application.SendNotification();
282 application.Render();
285 GestureReceivedFunctor functor(data);
287 RotationGestureDetector detector = RotationGestureDetector::New();
288 detector.Attach(actor);
289 detector.DetectedSignal().Connect(&application, functor);
291 // Start pan within the actor's area
292 TestStartRotation( application, Vector2( 5.0f, 5.0f ), Vector2( 20.0f, 20.0f ),
293 Vector2( 5.0f, 5.0f ), Vector2( 20.0f, 30.0f ), 100 );
294 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
295 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
296 DALI_TEST_EQUALS(0.244f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
297 DALI_TEST_EQUALS(Vector2(12.5f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
299 // Continue the pan within the actor's area - we should still receive the signal
301 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
302 Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 400 );
303 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
304 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
305 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
306 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
308 // Pan Gesture leaves actor's area - we should still receive the signal
310 TestContinueRotation( application, Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
311 Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ), 1000 );
312 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
313 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
314 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
315 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
317 // Gesture ends - we would receive a finished state
319 TestEndRotation( application, Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ),
320 Vector2( 305.0f, 10.0f ), Vector2( 315.0f, 10.0f ), 1500);
321 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
322 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
323 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
324 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
328 int UtcDaliRotationGestureSignalReceptionDownMotionUp(void)
330 TestApplication application;
332 Actor actor = Actor::New();
333 actor.SetSize(100.0f, 100.0f);
334 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
335 Stage::GetCurrent().Add(actor);
338 application.SendNotification();
339 application.Render();
342 GestureReceivedFunctor functor(data);
344 RotationGestureDetector detector = RotationGestureDetector::New();
345 detector.Attach(actor);
346 detector.DetectedSignal().Connect(&application, functor);
348 // Start rotation within the actor's area
349 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
350 Vector2( 10.0f, 20.0f ), Vector2( 31.0f, 29.0f ), 100 );
351 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
352 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
353 DALI_TEST_EQUALS(0.404892f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
354 DALI_TEST_EQUALS(Vector2(20.5f, 24.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
356 // Continue the rotation within the actor's area - we should still receive the signal
358 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
359 Vector2( 15.0f, 20.0f ), Vector2( 29.0f, 15.0f ), 500 );
360 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
361 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
362 DALI_TEST_EQUALS(-0.343024f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
363 DALI_TEST_EQUALS(Vector2(22.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
365 // Gesture ends within actor's area - we would receive a finished state
367 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
368 Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 15.0f ), 1000);
369 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
370 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
371 DALI_TEST_EQUALS(-0.463648f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
372 DALI_TEST_EQUALS(Vector2(24.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
376 int UtcDaliRotationGestureSignalReceptionDetach(void)
378 TestApplication application;
380 Actor actor = Actor::New();
381 actor.SetSize(100.0f, 100.0f);
382 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
383 Stage::GetCurrent().Add(actor);
386 application.SendNotification();
387 application.Render();
390 GestureReceivedFunctor functor(data);
392 RotationGestureDetector detector = RotationGestureDetector::New();
393 detector.Attach(actor);
394 detector.DetectedSignal().Connect(&application, functor);
396 // Start rotation within the actor's area
397 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
398 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
399 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
400 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
403 // Continue the rotation within the actor's area - we should still receive the signal
405 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
406 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
407 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
408 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
410 // Gesture ends within actor's area
412 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
413 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
414 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
415 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
418 detector.DetachAll();
420 // Ensure we are no longer signalled
422 TestGenerateRotation( application );
423 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
427 int UtcDaliRotationGestureSignalReceptionDetachWhileRotationing(void)
429 TestApplication application;
431 Actor actor = Actor::New();
432 actor.SetSize(100.0f, 100.0f);
433 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
434 Stage::GetCurrent().Add(actor);
437 application.SendNotification();
438 application.Render();
441 GestureReceivedFunctor functor(data);
443 RotationGestureDetector detector = RotationGestureDetector::New();
444 detector.Attach(actor);
445 detector.DetectedSignal().Connect(&application, functor);
447 // Start rotation within the actor's area
448 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
449 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
450 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
451 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
453 // Continue the rotation within the actor's area - we should still receive the signal
455 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
456 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
457 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
458 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
460 // Detach actor during the rotation, we should not receive the next event
461 detector.DetachAll();
463 // Gesture ends within actor's area
465 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
466 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
467 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
471 int UtcDaliRotationGestureSignalReceptionActorDestroyedWhileRotationing(void)
473 TestApplication application;
476 GestureReceivedFunctor functor(data);
478 RotationGestureDetector detector = RotationGestureDetector::New();
479 detector.DetectedSignal().Connect(&application, functor);
481 // Attach a temporary actor to stop detector being removed from RotationGestureProcessor when main actor
483 Actor tempActor = Actor::New();
484 tempActor.SetSize(100.0f, 100.0f);
485 tempActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
486 Stage::GetCurrent().Add(tempActor);
487 detector.Attach(tempActor);
489 // Actor lifetime is scoped
491 Actor actor = Actor::New();
492 actor.SetSize(100.0f, 100.0f);
493 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
494 Stage::GetCurrent().Add(actor);
497 application.SendNotification();
498 application.Render();
500 detector.Attach(actor);
502 // Start rotation within the actor's area
503 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
504 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
505 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
506 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
508 // Continue the rotation within the actor's area - we should still receive the signal
510 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
511 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
512 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
513 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
515 // Remove the actor from stage and reset the data
516 Stage::GetCurrent().Remove(actor);
519 application.SendNotification();
520 application.Render();
523 // Actor should now have been destroyed
525 // Gesture ends within the area where the actor used to be
527 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
528 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
529 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
533 int UtcDaliRotationGestureSignalReceptionRotatedActor(void)
535 TestApplication application;
537 Actor actor = Actor::New();
538 actor.SetSize(100.0f, 100.0f);
539 actor.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
540 Stage::GetCurrent().Add(actor);
542 // Render and notify a couple of times
543 application.SendNotification();
544 application.Render();
547 GestureReceivedFunctor functor(data);
549 RotationGestureDetector detector = RotationGestureDetector::New();
550 detector.Attach(actor);
551 detector.DetectedSignal().Connect(&application, functor);
553 // Do an entire rotation, only check finished value
554 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
555 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
557 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
558 Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 1000);
559 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
560 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
561 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
563 // Rotate actor again and render and notify
564 actor.SetOrientation(Dali::Degree(180.0f), Vector3::ZAXIS);
565 application.SendNotification();
566 application.Render();
568 // Do an entire rotation, only check finished value
569 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
570 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
572 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
573 Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 3000);
574 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
575 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
576 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
578 // Rotate actor again and render and notify
579 actor.SetOrientation(Dali::Degree(270.0f), Vector3::ZAXIS);
580 application.SendNotification();
581 application.Render();
583 // Do an entire rotation, only check finished value
584 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
585 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 4100 );
587 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
588 Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 5000);
589 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
590 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
591 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
595 int UtcDaliRotationGestureSignalReceptionChildHit(void)
597 TestApplication application;
599 Actor parent = Actor::New();
600 parent.SetSize(100.0f, 100.0f);
601 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
602 Stage::GetCurrent().Add(parent);
604 // Set child to completely cover parent.
605 // Change rotation of child to be different from parent so that we can check if our local coordinate
606 // conversion of the parent actor is correct.
607 Actor child = Actor::New();
608 child.SetSize(100.0f, 100.0f);
609 child.SetAnchorPoint(AnchorPoint::CENTER);
610 child.SetParentOrigin(ParentOrigin::CENTER);
611 child.SetOrientation(Dali::Degree(90.0f), Vector3::ZAXIS);
614 TouchEventFunctor touchFunctor;
615 child.TouchedSignal().Connect(&application, touchFunctor);
618 application.SendNotification();
619 application.Render();
622 GestureReceivedFunctor functor(data);
624 RotationGestureDetector detector = RotationGestureDetector::New();
625 detector.Attach(parent);
626 detector.DetectedSignal().Connect(&application, functor);
628 // Do an entire pan, only check finished value - hits child area but parent should still receive it
629 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
630 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
632 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
633 Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 25.0f ), 1000);
634 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
635 DALI_TEST_EQUALS(true, parent == data.rotatedActor, TEST_LOCATION);
636 DALI_TEST_EQUALS(0.463648f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
637 DALI_TEST_EQUALS(Vector2(24.0f, 22.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
639 // Attach child and generate same touch points to yield same results
640 // (Also proves that you can detach and then re-attach another actor)
641 detector.Attach(child);
642 detector.Detach(parent);
644 // Do an entire pan, only check finished value
645 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
646 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
648 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
649 Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 35.0f ), 3000);
650 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
651 DALI_TEST_EQUALS(true, child == data.rotatedActor, TEST_LOCATION);
652 DALI_TEST_EQUALS(0.982794f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
653 DALI_TEST_EQUALS(Vector2(24.0f, 27.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
657 int UtcDaliRotationGestureSignalReceptionAttachDetachMany(void)
659 TestApplication application;
661 Actor first = Actor::New();
662 first.SetSize(100.0f, 100.0f);
663 first.SetAnchorPoint(AnchorPoint::TOP_LEFT);
664 Stage::GetCurrent().Add(first);
666 Actor second = Actor::New();
667 second.SetSize(100.0f, 100.0f);
669 second.SetAnchorPoint(AnchorPoint::TOP_LEFT);
670 Stage::GetCurrent().Add(second);
673 application.SendNotification();
674 application.Render();
677 GestureReceivedFunctor functor(data);
679 RotationGestureDetector detector = RotationGestureDetector::New();
680 detector.Attach(first);
681 detector.Attach(second);
682 detector.DetectedSignal().Connect(&application, functor);
684 // Start rotation within second actor's area
685 TestStartRotation( application, Vector2( 102.0f, 20.0f ), Vector2( 138.0f, 20.0f ),
686 Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ), 100 );
687 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
688 DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
690 // Rotation moves into first actor's area - second actor should receive the rotation
692 TestContinueRotation( application, Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ),
693 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
694 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
695 DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
697 // Detach the second actor during the rotation, we should not receive the next event
698 detector.Detach(second);
700 // Gesture ends within actor's area
702 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
703 Vector2( 119.0f, 20.0f ), Vector2( 121.0f, 20.0f ), 3000);
704 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
708 int UtcDaliRotationGestureSignalReceptionActorBecomesUntouchable(void)
710 TestApplication application;
712 Actor actor = Actor::New();
713 actor.SetSize(100.0f, 100.0f);
714 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
715 Stage::GetCurrent().Add(actor);
718 application.SendNotification();
719 application.Render();
722 GestureReceivedFunctor functor(data);
724 RotationGestureDetector detector = RotationGestureDetector::New();
725 detector.Attach(actor);
726 detector.DetectedSignal().Connect(&application, functor);
728 // Start rotation in actor's area
729 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
730 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
731 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
733 // Pan continues within actor's area
735 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
736 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
737 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
739 // Actor become invisible - actor should not receive the next rotation
740 actor.SetVisible(false);
743 application.SendNotification();
744 application.Render();
746 // Gesture ends within actor's area
748 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
749 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
750 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
754 int UtcDaliRotationGestureSignalReceptionMultipleDetectorsOnActor(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 RotationGestureDetector firstDetector = RotationGestureDetector::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 RotationGestureDetector secondDetector = RotationGestureDetector::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 // Rotation in actor's area - both detector's functors should be called
792 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
793 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
794 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
795 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
797 // Rotation continues in actor's area - both detector's functors should be called
800 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
801 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
802 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
803 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
805 // Detach actor from firstDetector and emit rotation on actor, only secondDetector's functor should be called.
806 firstDetector.Detach(actor);
809 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
810 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
811 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
812 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
814 // New rotation on actor, only secondDetector has actor attached
817 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
818 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
819 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
820 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
822 // Detach actor from secondDetector
823 secondDetector.Detach(actor);
826 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
827 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
828 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
829 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
833 int UtcDaliRotationGestureSignalReceptionEnsureCorrectSignalling(void)
835 TestApplication application;
837 Actor actor1 = Actor::New();
838 actor1.SetSize(100.0f, 100.0f);
839 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
840 Stage::GetCurrent().Add(actor1);
842 GestureReceivedFunctor functor1(data1);
843 RotationGestureDetector detector1 = RotationGestureDetector::New();
844 detector1.Attach(actor1);
845 detector1.DetectedSignal().Connect(&application, functor1);
847 Actor actor2 = Actor::New();
848 actor2.SetSize(100.0f, 100.0f);
849 actor2.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
850 actor2.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
851 Stage::GetCurrent().Add(actor2);
853 GestureReceivedFunctor functor2(data2);
854 RotationGestureDetector detector2 = RotationGestureDetector::New();
855 detector2.Attach(actor2);
856 detector2.DetectedSignal().Connect(&application, functor2);
859 application.SendNotification();
860 application.Render();
862 // Start pan in actor1's area, only data1 should be set
863 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
864 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
865 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
866 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
870 int UtcDaliRotationGestureActorUnstaged(void)
872 TestApplication application;
874 Actor actor = Actor::New();
875 actor.SetSize(100.0f, 100.0f);
876 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
877 Stage::GetCurrent().Add(actor);
880 application.SendNotification();
881 application.Render();
883 // State to remove actor in.
884 Gesture::State stateToUnstage( Gesture::Started );
886 // Attach actor to detector
888 UnstageActorFunctor functor( data, stateToUnstage );
889 RotationGestureDetector detector = RotationGestureDetector::New();
890 detector.Attach(actor);
891 detector.DetectedSignal().Connect( &application, functor );
894 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
895 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
896 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
898 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
899 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
900 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
904 application.SendNotification();
905 application.Render();
907 // Re-add actor to stage
908 Stage::GetCurrent().Add(actor);
911 application.SendNotification();
912 application.Render();
914 // Change state to Gesture::Continuing to remove
915 stateToUnstage = Gesture::Continuing;
918 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
919 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
920 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
922 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
923 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
924 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
926 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
927 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
928 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
932 application.SendNotification();
933 application.Render();
935 // Re-add actor to stage
936 Stage::GetCurrent().Add(actor);
939 application.SendNotification();
940 application.Render();
942 // Change state to Gesture::Continuing to remove
943 stateToUnstage = Gesture::Finished;
946 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
947 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
948 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
950 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
951 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
952 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
954 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
955 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
956 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
957 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
961 int UtcDaliRotationGestureActorStagedAndDestroyed(void)
963 TestApplication application;
965 Actor actor = Actor::New();
966 actor.SetSize(100.0f, 100.0f);
967 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
968 Stage::GetCurrent().Add(actor);
970 // Create and add a second actor so that GestureDetector destruction does not come into play.
971 Actor dummyActor( Actor::New() );
972 dummyActor.SetSize( 100.0f, 100.0f );
973 dummyActor.SetPosition( 100.0f, 100.0f );
974 dummyActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
975 Stage::GetCurrent().Add(dummyActor);
978 application.SendNotification();
979 application.Render();
981 // State to remove actor in.
982 Gesture::State stateToUnstage( Gesture::Started );
984 // Attach actor to detector
986 UnstageActorFunctor functor( data, stateToUnstage );
987 RotationGestureDetector detector = RotationGestureDetector::New();
988 detector.Attach(actor);
989 detector.Attach(dummyActor);
990 detector.DetectedSignal().Connect( &application, functor );
992 // Here we are testing a Started actor which is removed in the Started callback, but then added back
993 // before we get a continuing state. As we were removed from the stage, even if we're at the same
994 // position, we should still not be signalled.
997 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
998 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
999 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1002 // Render and notify
1003 application.SendNotification();
1004 application.Render();
1006 // Re add to the stage, we should not be signalled
1007 Stage::GetCurrent().Add(actor);
1009 // Render and notify
1010 application.SendNotification();
1011 application.Render();
1013 // Continue signal emission
1014 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1015 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
1016 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1018 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1019 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1020 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1023 // Here we delete an actor in started, we should not receive any subsequent signalling.
1026 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1027 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1028 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1031 // Render and notify
1032 application.SendNotification();
1033 application.Render();
1035 // Delete actor as well
1038 // Render and notify
1039 application.SendNotification();
1040 application.Render();
1042 // Continue signal emission
1043 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1044 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
1045 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1047 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1048 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
1049 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1053 int UtcDaliRotationGestureLayerConsumesTouch(void)
1055 TestApplication application;
1057 Actor actor = Actor::New();
1058 actor.SetSize(100.0f, 100.0f);
1059 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1060 Stage::GetCurrent().Add(actor);
1064 GestureReceivedFunctor functor(data);
1065 RotationGestureDetector detector = RotationGestureDetector::New();
1066 detector.Attach(actor);
1067 detector.DetectedSignal().Connect( &application, functor );
1069 // Add a layer to overlap the actor
1070 Layer layer = Layer::New();
1071 layer.SetSize(100.0f, 100.0f);
1072 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1073 Stage::GetCurrent().Add( layer );
1076 // Render and notify
1077 application.SendNotification();
1078 application.Render();
1080 // Emit signals, should receive
1081 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1082 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1083 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1084 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1085 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1088 // Set layer to consume all touch
1089 layer.SetTouchConsumed( true );
1091 // Render and notify
1092 application.SendNotification();
1093 application.Render();
1095 // Emit the same signals again, should not receive
1096 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1097 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1098 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1099 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 2000);
1100 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);