2 * Copyright (c) 2020 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, Integration::Scene scene )
98 : GestureReceivedFunctor( data ),
99 stateToUnstage( stateToUnstage ),
104 void operator()( Actor actor, const RotationGesture& rotation )
106 GestureReceivedFunctor::operator()( actor, rotation );
108 if ( rotation.state == stateToUnstage )
110 scene.Remove( actor );
114 Gesture::State& stateToUnstage;
115 Integration::Scene scene;
118 // Functor for receiving a touch event
119 struct TouchEventFunctor
121 bool operator()(Actor actor, const TouchEvent& touch)
129 ///////////////////////////////////////////////////////////////////////////////
131 int UtcDaliRotationGestureDetectorConstructor(void)
133 TestApplication application;
135 RotationGestureDetector detector;
136 DALI_TEST_CHECK(!detector);
140 int UtcDaliRotationGestureDetectorCopyConstructorP(void)
142 TestApplication application;
144 RotationGestureDetector detector = RotationGestureDetector::New();;
146 RotationGestureDetector copy( detector );
147 DALI_TEST_CHECK( detector );
151 int UtcDaliRotationGestureDetectorAssignmentOperatorP(void)
153 TestApplication application;
155 RotationGestureDetector detector = RotationGestureDetector::New();;
157 RotationGestureDetector assign;
159 DALI_TEST_CHECK( detector );
161 DALI_TEST_CHECK( detector == assign );
165 int UtcDaliRotationGestureDetectorNew(void)
167 TestApplication application;
169 RotationGestureDetector detector = RotationGestureDetector::New();
171 DALI_TEST_CHECK(detector);
173 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
174 Actor actor = Actor::New();
175 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
176 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
177 application.GetScene().Add(actor);
180 application.SendNotification();
181 application.Render();
183 detector.Attach(actor);
185 Integration::TouchEvent touchEvent(1);
186 Integration::Point point;
187 point.SetDeviceId( 1 );
188 point.SetState( PointState::DOWN );
189 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
190 touchEvent.AddPoint(point);
191 application.ProcessEvent(touchEvent);
193 Integration::Point point2;
194 point.SetDeviceId( 1 );
195 point.SetState( PointState::DOWN );
196 point.SetScreenPosition( Vector2( 20.0f, 20.0f ) );
197 touchEvent.AddPoint(point2);
198 application.ProcessEvent(touchEvent);
202 int UtcDaliRotationGestureDetectorDownCast(void)
204 TestApplication application;
205 tet_infoline("Testing Dali::RotationGestureDetector::DownCast()");
207 RotationGestureDetector detector = RotationGestureDetector::New();
209 BaseHandle object(detector);
211 RotationGestureDetector detector2 = RotationGestureDetector::DownCast(object);
212 DALI_TEST_CHECK(detector2);
214 RotationGestureDetector detector3 = DownCast< RotationGestureDetector >(object);
215 DALI_TEST_CHECK(detector3);
217 BaseHandle unInitializedObject;
218 RotationGestureDetector detector4 = RotationGestureDetector::DownCast(unInitializedObject);
219 DALI_TEST_CHECK(!detector4);
221 RotationGestureDetector detector5 = DownCast< RotationGestureDetector >(unInitializedObject);
222 DALI_TEST_CHECK(!detector5);
224 GestureDetector detector6 = RotationGestureDetector::New();
225 RotationGestureDetector detector7 = RotationGestureDetector::DownCast(detector6);
226 DALI_TEST_CHECK(detector7);
230 // Negative test case for a method
231 int UtcDaliRotationGestureSignalReceptionNegative(void)
233 TestApplication application;
235 Actor actor = Actor::New();
236 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
237 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
238 application.GetScene().Add(actor);
241 application.SendNotification();
242 application.Render();
245 GestureReceivedFunctor functor(data);
247 RotationGestureDetector detector = RotationGestureDetector::New();
248 detector.Attach(actor);
249 detector.DetectedSignal().Connect(&application, functor);
251 // Do a rotation outside actor's area
252 TestStartRotation( application, Vector2( 112.0f, 62.0f ), Vector2( 112.0f, 162.0f ),
253 Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ), 100 );
255 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
257 // Continue rotation into actor's area - we should still not receive the signal
259 TestContinueRotation( application, Vector2( 112.0f, 100.0f ), Vector2( 112.0f, 124.0f ),
260 Vector2( 5.0f, 5.0f ), Vector2( 35.0f, 35.0f ), 200 );
262 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
264 // Stop rotating - we should still not receive the signal
266 TestEndRotation( application, Vector2( 6.0f, 6.0f ), Vector2( 18.0f, 18.0f ),
267 Vector2( 10.0f, 8.0f ), Vector2( 14.0f, 16.0f ), 300 );
269 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
273 int UtcDaliRotationGestureSignalReceptionDownMotionLeave(void)
275 TestApplication application;
277 Actor actor = Actor::New();
278 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
279 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
280 application.GetScene().Add(actor);
283 application.SendNotification();
284 application.Render();
287 GestureReceivedFunctor functor(data);
289 RotationGestureDetector detector = RotationGestureDetector::New();
290 detector.Attach(actor);
291 detector.DetectedSignal().Connect(&application, functor);
293 // Start pan within the actor's area
294 TestStartRotation( application, Vector2( 5.0f, 5.0f ), Vector2( 20.0f, 20.0f ),
295 Vector2( 5.0f, 5.0f ), Vector2( 20.0f, 30.0f ), 100 );
296 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
297 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
298 DALI_TEST_EQUALS(0.244f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
299 DALI_TEST_EQUALS(Vector2(12.5f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
301 // Continue the pan within the actor's area - we should still receive the signal
303 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
304 Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 400 );
305 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
306 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
307 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
308 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
310 // Pan Gesture leaves actor's area - we should still receive the signal
312 TestContinueRotation( application, Vector2( 17.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
313 Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ), 1000 );
314 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
315 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
316 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
317 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
319 // Gesture ends - we would receive a finished state
321 TestEndRotation( application, Vector2( 300.0f, 10.0f ), Vector2( 340.0f, 10.0f ),
322 Vector2( 305.0f, 10.0f ), Vector2( 315.0f, 10.0f ), 1500);
323 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
324 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
325 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
326 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
330 int UtcDaliRotationGestureSignalReceptionDownMotionUp(void)
332 TestApplication application;
334 Actor actor = Actor::New();
335 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
336 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
337 application.GetScene().Add(actor);
340 application.SendNotification();
341 application.Render();
344 GestureReceivedFunctor functor(data);
346 RotationGestureDetector detector = RotationGestureDetector::New();
347 detector.Attach(actor);
348 detector.DetectedSignal().Connect(&application, functor);
350 // Start rotation within the actor's area
351 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
352 Vector2( 10.0f, 20.0f ), Vector2( 31.0f, 29.0f ), 100 );
353 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
354 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
355 DALI_TEST_EQUALS(0.404892f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
356 DALI_TEST_EQUALS(Vector2(20.5f, 24.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
358 // Continue the rotation within the actor's area - we should still receive the signal
360 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
361 Vector2( 15.0f, 20.0f ), Vector2( 29.0f, 15.0f ), 500 );
362 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
363 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
364 DALI_TEST_EQUALS(-0.343024f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
365 DALI_TEST_EQUALS(Vector2(22.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
367 // Gesture ends within actor's area - we would receive a finished state
369 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
370 Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 15.0f ), 1000);
371 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
372 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
373 DALI_TEST_EQUALS(-0.463648f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
374 DALI_TEST_EQUALS(Vector2(24.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
378 int UtcDaliRotationGestureSignalReceptionDetach(void)
380 TestApplication application;
382 Actor actor = Actor::New();
383 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
384 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
385 application.GetScene().Add(actor);
388 application.SendNotification();
389 application.Render();
392 GestureReceivedFunctor functor(data);
394 RotationGestureDetector detector = RotationGestureDetector::New();
395 detector.Attach(actor);
396 detector.DetectedSignal().Connect(&application, functor);
398 // Start rotation within the actor's area
399 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
400 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
401 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
402 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
405 // Continue the rotation within the actor's area - we should still receive the signal
407 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
408 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
409 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
410 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
412 // Gesture ends within actor's area
414 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
415 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
416 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
417 DALI_TEST_EQUALS(Gesture::Finished, data.receivedGesture.state, TEST_LOCATION);
420 detector.DetachAll();
422 // Ensure we are no longer signalled
424 TestGenerateRotation( application );
425 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
429 int UtcDaliRotationGestureSignalReceptionDetachWhileRotationing(void)
431 TestApplication application;
433 Actor actor = Actor::New();
434 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
435 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
436 application.GetScene().Add(actor);
439 application.SendNotification();
440 application.Render();
443 GestureReceivedFunctor functor(data);
445 RotationGestureDetector detector = RotationGestureDetector::New();
446 detector.Attach(actor);
447 detector.DetectedSignal().Connect(&application, functor);
449 // Start rotation within the actor's area
450 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
451 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
452 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
453 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
455 // Continue the rotation within the actor's area - we should still receive the signal
457 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
458 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
459 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
460 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
462 // Detach actor during the rotation, we should not receive the next event
463 detector.DetachAll();
465 // Gesture ends within actor's area
467 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
468 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
469 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
473 int UtcDaliRotationGestureSignalReceptionActorDestroyedWhileRotationing(void)
475 TestApplication application;
478 GestureReceivedFunctor functor(data);
480 RotationGestureDetector detector = RotationGestureDetector::New();
481 detector.DetectedSignal().Connect(&application, functor);
483 // Attach a temporary actor to stop detector being removed from RotationGestureProcessor when main actor
485 Actor tempActor = Actor::New();
486 tempActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
487 tempActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
488 application.GetScene().Add(tempActor);
489 detector.Attach(tempActor);
491 // Actor lifetime is scoped
493 Actor actor = Actor::New();
494 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
495 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
496 application.GetScene().Add(actor);
499 application.SendNotification();
500 application.Render();
502 detector.Attach(actor);
504 // Start rotation within the actor's area
505 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
506 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
507 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
508 DALI_TEST_EQUALS(Gesture::Started, data.receivedGesture.state, TEST_LOCATION);
510 // Continue the rotation within the actor's area - we should still receive the signal
512 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
513 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
514 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
515 DALI_TEST_EQUALS(Gesture::Continuing, data.receivedGesture.state, TEST_LOCATION);
517 // Remove the actor from stage and reset the data
518 application.GetScene().Remove(actor);
521 application.SendNotification();
522 application.Render();
525 // Actor should now have been destroyed
527 // Gesture ends within the area where the actor used to be
529 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
530 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
531 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
535 int UtcDaliRotationGestureSignalReceptionRotatedActor(void)
537 TestApplication application;
539 Actor actor = Actor::New();
540 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
541 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
542 application.GetScene().Add(actor);
544 // Render and notify a couple of times
545 application.SendNotification();
546 application.Render();
549 GestureReceivedFunctor functor(data);
551 RotationGestureDetector detector = RotationGestureDetector::New();
552 detector.Attach(actor);
553 detector.DetectedSignal().Connect(&application, functor);
555 // Do an entire rotation, only check finished value
556 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
557 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
559 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
560 Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 1000);
561 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
562 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
563 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
565 // Rotate actor again and render and notify
566 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS) );
567 application.SendNotification();
568 application.Render();
570 // Do an entire rotation, only check finished value
571 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
572 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
574 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
575 Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 3000);
576 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
577 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
578 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
580 // Rotate actor again and render and notify
581 actor.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS) );
582 application.SendNotification();
583 application.Render();
585 // Do an entire rotation, only check finished value
586 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
587 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 4100 );
589 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
590 Vector2( 19.0f, 20.0f ), Vector2( 27.0f, 15.0f ), 5000);
591 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
592 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
593 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
597 int UtcDaliRotationGestureSignalReceptionChildHit(void)
599 TestApplication application;
601 Actor parent = Actor::New();
602 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
603 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
604 application.GetScene().Add(parent);
606 // Set child to completely cover parent.
607 // Change rotation of child to be different from parent so that we can check if our local coordinate
608 // conversion of the parent actor is correct.
609 Actor child = Actor::New();
610 child.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
611 child.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
612 child.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
613 child.SetProperty( Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS) );
616 TouchEventFunctor touchFunctor;
617 child.TouchedSignal().Connect(&application, touchFunctor);
620 application.SendNotification();
621 application.Render();
624 GestureReceivedFunctor functor(data);
626 RotationGestureDetector detector = RotationGestureDetector::New();
627 detector.Attach(parent);
628 detector.DetectedSignal().Connect(&application, functor);
630 // Do an entire pan, only check finished value - hits child area but parent should still receive it
631 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
632 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
634 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
635 Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 25.0f ), 1000);
636 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
637 DALI_TEST_EQUALS(true, parent == data.rotatedActor, TEST_LOCATION);
638 DALI_TEST_EQUALS(0.463648f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
639 DALI_TEST_EQUALS(Vector2(24.0f, 22.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
641 // Attach child and generate same touch points to yield same results
642 // (Also proves that you can detach and then re-attach another actor)
643 detector.Attach(child);
644 detector.Detach(parent);
646 // Do an entire pan, only check finished value
647 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
648 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 2100 );
650 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
651 Vector2( 19.0f, 20.0f ), Vector2( 29.0f, 35.0f ), 3000);
652 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
653 DALI_TEST_EQUALS(true, child == data.rotatedActor, TEST_LOCATION);
654 DALI_TEST_EQUALS(0.982794f, data.receivedGesture.rotation.radian, 0.01f, TEST_LOCATION);
655 DALI_TEST_EQUALS(Vector2(24.0f, 27.5f), data.receivedGesture.screenCenterPoint, 0.01f, TEST_LOCATION);
659 int UtcDaliRotationGestureSignalReceptionAttachDetachMany(void)
661 TestApplication application;
663 Actor first = Actor::New();
664 first.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
665 first.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
666 application.GetScene().Add(first);
668 Actor second = Actor::New();
669 second.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
670 second.SetProperty( Actor::Property::POSITION_X, 100.0f);
671 second.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
672 application.GetScene().Add(second);
675 application.SendNotification();
676 application.Render();
679 GestureReceivedFunctor functor(data);
681 RotationGestureDetector detector = RotationGestureDetector::New();
682 detector.Attach(first);
683 detector.Attach(second);
684 detector.DetectedSignal().Connect(&application, functor);
686 // Start rotation within second actor's area
687 TestStartRotation( application, Vector2( 102.0f, 20.0f ), Vector2( 138.0f, 20.0f ),
688 Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ), 100 );
689 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
690 DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
692 // Rotation moves into first actor's area - second actor should receive the rotation
694 TestContinueRotation( application, Vector2( 110.0f, 20.0f ), Vector2( 130.0f, 20.0f ),
695 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
696 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
697 DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
699 // Detach the second actor during the rotation, we should not receive the next event
700 detector.Detach(second);
702 // Gesture ends within actor's area
704 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
705 Vector2( 119.0f, 20.0f ), Vector2( 121.0f, 20.0f ), 3000);
706 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
710 int UtcDaliRotationGestureSignalReceptionActorBecomesUntouchable(void)
712 TestApplication application;
714 Actor actor = Actor::New();
715 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
716 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
717 application.GetScene().Add(actor);
720 application.SendNotification();
721 application.Render();
724 GestureReceivedFunctor functor(data);
726 RotationGestureDetector detector = RotationGestureDetector::New();
727 detector.Attach(actor);
728 detector.DetectedSignal().Connect(&application, functor);
730 // Start rotation in actor's area
731 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
732 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
733 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
735 // Pan continues within actor's area
737 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
738 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
739 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
741 // Actor become invisible - actor should not receive the next rotation
742 actor.SetProperty( Actor::Property::VISIBLE,false);
745 application.SendNotification();
746 application.Render();
748 // Gesture ends within actor's area
750 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
751 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
752 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
756 int UtcDaliRotationGestureSignalReceptionMultipleDetectorsOnActor(void)
758 TestApplication application;
760 Actor actor = Actor::New();
761 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
762 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
763 application.GetScene().Add(actor);
765 Actor actor2 = Actor::New();
766 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
767 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
768 application.GetScene().Add(actor2);
771 application.SendNotification();
772 application.Render();
774 // Attach actor to one detector
775 SignalData firstData;
776 GestureReceivedFunctor firstFunctor(firstData);
777 RotationGestureDetector firstDetector = RotationGestureDetector::New();
778 firstDetector.Attach(actor);
779 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
781 // Attach actor to another detector
782 SignalData secondData;
783 GestureReceivedFunctor secondFunctor(secondData);
784 RotationGestureDetector secondDetector = RotationGestureDetector::New();
785 secondDetector.Attach(actor);
786 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
788 // Add second actor to second detector, when we remove the actor, this will make sure that this
789 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
790 // functor should still not be called (which is what we're also testing).
791 secondDetector.Attach(actor2);
793 // Rotation in actor's area - both detector's functors should be called
794 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
795 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
796 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
797 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
799 // Rotation continues in actor's area - both detector's functors should be called
802 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
803 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
804 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
805 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
807 // Detach actor from firstDetector and emit rotation on actor, only secondDetector's functor should be called.
808 firstDetector.Detach(actor);
811 TestEndRotation( application, Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ),
812 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
813 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
814 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
816 // New rotation on actor, only secondDetector has actor attached
819 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
820 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
821 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
822 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
824 // Detach actor from secondDetector
825 secondDetector.Detach(actor);
828 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
829 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
830 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
831 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
835 int UtcDaliRotationGestureSignalReceptionEnsureCorrectSignalling(void)
837 TestApplication application;
839 Actor actor1 = Actor::New();
840 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
841 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
842 application.GetScene().Add(actor1);
844 GestureReceivedFunctor functor1(data1);
845 RotationGestureDetector detector1 = RotationGestureDetector::New();
846 detector1.Attach(actor1);
847 detector1.DetectedSignal().Connect(&application, functor1);
849 Actor actor2 = Actor::New();
850 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
851 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::BOTTOM_RIGHT);
852 actor2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::BOTTOM_RIGHT);
853 application.GetScene().Add(actor2);
855 GestureReceivedFunctor functor2(data2);
856 RotationGestureDetector detector2 = RotationGestureDetector::New();
857 detector2.Attach(actor2);
858 detector2.DetectedSignal().Connect(&application, functor2);
861 application.SendNotification();
862 application.Render();
864 // Start pan in actor1's area, only data1 should be set
865 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
866 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
867 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
868 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
872 int UtcDaliRotationGestureActorUnstaged(void)
874 TestApplication application;
876 Actor actor = Actor::New();
877 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
878 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
879 application.GetScene().Add(actor);
882 application.SendNotification();
883 application.Render();
885 // State to remove actor in.
886 Gesture::State stateToUnstage( Gesture::Started );
888 // Attach actor to detector
890 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
891 RotationGestureDetector detector = RotationGestureDetector::New();
892 detector.Attach(actor);
893 detector.DetectedSignal().Connect( &application, functor );
896 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
897 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
898 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
900 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
901 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
902 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
906 application.SendNotification();
907 application.Render();
909 // Re-add actor to stage
910 application.GetScene().Add(actor);
913 application.SendNotification();
914 application.Render();
916 // Change state to Gesture::Continuing to remove
917 stateToUnstage = Gesture::Continuing;
920 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
921 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
922 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
924 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
925 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
926 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
928 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
929 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
930 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
934 application.SendNotification();
935 application.Render();
937 // Re-add actor to stage
938 application.GetScene().Add(actor);
941 application.SendNotification();
942 application.Render();
944 // Change state to Gesture::Continuing to remove
945 stateToUnstage = Gesture::Finished;
948 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
949 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
950 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
952 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
953 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
954 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
956 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
957 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
958 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
959 tet_result( TET_PASS ); // If we get here then we have handled actor stage removal gracefully.
963 int UtcDaliRotationGestureActorStagedAndDestroyed(void)
965 TestApplication application;
967 Actor actor = Actor::New();
968 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
969 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
970 application.GetScene().Add(actor);
972 // Create and add a second actor so that GestureDetector destruction does not come into play.
973 Actor dummyActor( Actor::New() );
974 dummyActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
975 dummyActor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
976 dummyActor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
977 application.GetScene().Add(dummyActor);
980 application.SendNotification();
981 application.Render();
983 // State to remove actor in.
984 Gesture::State stateToUnstage( Gesture::Started );
986 // Attach actor to detector
988 UnstageActorFunctor functor( data, stateToUnstage, application.GetScene() );
989 RotationGestureDetector detector = RotationGestureDetector::New();
990 detector.Attach(actor);
991 detector.Attach(dummyActor);
992 detector.DetectedSignal().Connect( &application, functor );
994 // Here we are testing a Started actor which is removed in the Started callback, but then added back
995 // before we get a continuing state. As we were removed from the stage, even if we're at the same
996 // position, we should still not be signalled.
999 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1000 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1001 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1004 // Render and notify
1005 application.SendNotification();
1006 application.Render();
1008 // Re add to the stage, we should not be signalled
1009 application.GetScene().Add(actor);
1011 // Render and notify
1012 application.SendNotification();
1013 application.Render();
1015 // Continue signal emission
1016 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1017 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 500 );
1018 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1020 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1021 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1022 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1025 // Here we delete an actor in started, we should not receive any subsequent signalling.
1028 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1029 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1030 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1033 // Render and notify
1034 application.SendNotification();
1035 application.Render();
1037 // Delete actor as well
1040 // Render and notify
1041 application.SendNotification();
1042 application.Render();
1044 // Continue signal emission
1045 TestContinueRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1046 Vector2( 15.0f, 20.0f ), Vector2( 25.0f, 20.0f ), 2000 );
1047 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1049 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1050 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 3000);
1051 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1055 int UtcDaliRotationGestureLayerConsumesTouch(void)
1057 TestApplication application;
1059 Actor actor = Actor::New();
1060 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1061 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1062 application.GetScene().Add(actor);
1066 GestureReceivedFunctor functor(data);
1067 RotationGestureDetector detector = RotationGestureDetector::New();
1068 detector.Attach(actor);
1069 detector.DetectedSignal().Connect( &application, functor );
1071 // Add a layer to overlap the actor
1072 Layer layer = Layer::New();
1073 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1074 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1075 application.GetScene().Add( layer );
1078 // Render and notify
1079 application.SendNotification();
1080 application.Render();
1082 // Emit signals, should receive
1083 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1084 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 100 );
1085 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1086 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 1000);
1087 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1090 // Set layer to consume all touch
1091 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1093 // Render and notify
1094 application.SendNotification();
1095 application.Render();
1097 // Emit the same signals again, should not receive
1098 TestStartRotation( application, Vector2( 2.0f, 20.0f ), Vector2( 38.0f, 20.0f ),
1099 Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ), 1500 );
1100 TestEndRotation( application, Vector2( 10.0f, 20.0f ), Vector2( 30.0f, 20.0f ),
1101 Vector2( 19.0f, 20.0f ), Vector2( 21.0f, 20.0f ), 2000);
1102 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);