2 * Copyright (c) 2021 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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/actors/actor-devel.h>
20 #include <dali/integration-api/events/touch-event-integ.h>
21 #include <dali/integration-api/render-task-list-integ.h>
22 #include <dali/public-api/dali-core.h>
24 #include <test-touch-event-utils.h>
30 void utc_dali_rotation_gesture_detector_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_rotation_gesture_detector_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled(false),
48 voidFunctorCalled(false),
55 functorCalled = false;
56 voidFunctorCalled = false;
58 receivedGesture.Reset();
64 bool voidFunctorCalled;
65 RotationGesture receivedGesture;
69 // Functor that sets the data when called
70 struct GestureReceivedFunctor
72 GestureReceivedFunctor(SignalData& data)
77 void operator()(Actor actor, const RotationGesture& rotation)
79 signalData.functorCalled = true;
80 signalData.receivedGesture = rotation;
81 signalData.rotatedActor = actor;
86 signalData.voidFunctorCalled = true;
89 SignalData& signalData;
92 // Functor that removes the gestured actor from stage
93 struct UnstageActorFunctor : public GestureReceivedFunctor
95 UnstageActorFunctor(SignalData& data, GestureState& stateToUnstage, Integration::Scene scene)
96 : GestureReceivedFunctor(data),
97 stateToUnstage(stateToUnstage),
102 void operator()(Actor actor, const RotationGesture& rotation)
104 GestureReceivedFunctor::operator()(actor, rotation);
106 if(rotation.GetState() == stateToUnstage)
112 GestureState& stateToUnstage;
113 Integration::Scene scene;
118 ///////////////////////////////////////////////////////////////////////////////
120 int UtcDaliRotationGestureDetectorConstructor(void)
122 TestApplication application;
124 RotationGestureDetector detector;
125 DALI_TEST_CHECK(!detector);
129 int UtcDaliRotationGestureDetectorCopyConstructorP(void)
131 TestApplication application;
133 RotationGestureDetector detector = RotationGestureDetector::New();
136 RotationGestureDetector copy(detector);
137 DALI_TEST_CHECK(detector);
141 int UtcDaliRotationGestureDetectorAssignmentOperatorP(void)
143 TestApplication application;
145 RotationGestureDetector detector = RotationGestureDetector::New();
148 RotationGestureDetector assign;
150 DALI_TEST_CHECK(detector);
152 DALI_TEST_CHECK(detector == assign);
156 int UtcDaliRotationGestureDetectorNew(void)
158 TestApplication application;
160 RotationGestureDetector detector = RotationGestureDetector::New();
162 DALI_TEST_CHECK(detector);
164 // Attach an actor and emit a touch event on the actor to ensure complete line coverage
165 Actor actor = Actor::New();
166 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
167 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
168 application.GetScene().Add(actor);
171 application.SendNotification();
172 application.Render();
174 detector.Attach(actor);
176 Integration::TouchEvent touchEvent(1);
177 Integration::Point point;
178 point.SetDeviceId(1);
179 point.SetState(PointState::DOWN);
180 point.SetScreenPosition(Vector2(20.0f, 20.0f));
181 touchEvent.AddPoint(point);
182 application.ProcessEvent(touchEvent);
184 Integration::Point point2;
185 point.SetDeviceId(1);
186 point.SetState(PointState::DOWN);
187 point.SetScreenPosition(Vector2(20.0f, 20.0f));
188 touchEvent.AddPoint(point2);
189 application.ProcessEvent(touchEvent);
193 int UtcDaliRotationGestureDetectorDownCast(void)
195 TestApplication application;
196 tet_infoline("Testing Dali::RotationGestureDetector::DownCast()");
198 RotationGestureDetector detector = RotationGestureDetector::New();
200 BaseHandle object(detector);
202 RotationGestureDetector detector2 = RotationGestureDetector::DownCast(object);
203 DALI_TEST_CHECK(detector2);
205 RotationGestureDetector detector3 = DownCast<RotationGestureDetector>(object);
206 DALI_TEST_CHECK(detector3);
208 BaseHandle unInitializedObject;
209 RotationGestureDetector detector4 = RotationGestureDetector::DownCast(unInitializedObject);
210 DALI_TEST_CHECK(!detector4);
212 RotationGestureDetector detector5 = DownCast<RotationGestureDetector>(unInitializedObject);
213 DALI_TEST_CHECK(!detector5);
215 GestureDetector detector6 = RotationGestureDetector::New();
216 RotationGestureDetector detector7 = RotationGestureDetector::DownCast(detector6);
217 DALI_TEST_CHECK(detector7);
221 // Negative test case for a method
222 int UtcDaliRotationGestureSignalReceptionNegative(void)
224 TestApplication application;
226 Actor actor = Actor::New();
227 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
228 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
229 application.GetScene().Add(actor);
232 application.SendNotification();
233 application.Render();
236 GestureReceivedFunctor functor(data);
238 RotationGestureDetector detector = RotationGestureDetector::New();
239 detector.Attach(actor);
240 detector.DetectedSignal().Connect(&application, functor);
242 // Do a rotation outside actor's area
243 TestStartRotation(application, Vector2(112.0f, 62.0f), Vector2(112.0f, 162.0f), Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), 100);
245 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
247 // Continue rotation into actor's area - we should still not receive the signal
249 TestContinueRotation(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
251 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
253 // Stop rotating - we should still not receive the signal
255 TestEndRotation(application, Vector2(6.0f, 6.0f), Vector2(18.0f, 18.0f), Vector2(10.0f, 8.0f), Vector2(14.0f, 16.0f), 300);
257 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
261 int UtcDaliRotationGestureSignalReceptionDownMotionLeave(void)
263 TestApplication application;
265 Actor actor = Actor::New();
266 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
267 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
268 application.GetScene().Add(actor);
271 application.SendNotification();
272 application.Render();
275 GestureReceivedFunctor functor(data);
277 RotationGestureDetector detector = RotationGestureDetector::New();
278 detector.Attach(actor);
279 detector.DetectedSignal().Connect(&application, functor);
281 // Start rotation within the actor's area
282 TestStartRotation(application, Vector2(5.0f, 5.0f), Vector2(20.0f, 20.0f), Vector2(5.0f, 5.0f), Vector2(20.0f, 30.0f), 100);
283 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
284 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
285 DALI_TEST_EQUALS(0.244f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
286 DALI_TEST_EQUALS(Vector2(12.5f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
287 DALI_TEST_EQUALS(Vector2(12.48f, 17.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
289 // Continue the rotation within the actor's area - we should still receive the signal
291 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), 400);
292 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
293 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
294 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
295 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
296 DALI_TEST_EQUALS(Vector2(21.0f, 20.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
298 // Rotation Gesture leaves actor's area - we should still receive the signal
300 TestContinueRotation(application, Vector2(17.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), 1000);
301 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
302 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
303 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
304 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
305 DALI_TEST_EQUALS(Vector2(320.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
307 // Gesture ends - we would receive a finished state
309 TestEndRotation(application, Vector2(300.0f, 10.0f), Vector2(340.0f, 10.0f), Vector2(305.0f, 10.0f), Vector2(315.0f, 10.0f), 1500);
310 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
311 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
312 DALI_TEST_EQUALS(-0.785398f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
313 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
314 DALI_TEST_EQUALS(Vector2(310.0f, 10.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
318 int UtcDaliRotationGestureSignalReceptionDownMotionUp(void)
320 TestApplication application;
322 Actor actor = Actor::New();
323 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
324 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
325 application.GetScene().Add(actor);
328 application.SendNotification();
329 application.Render();
332 GestureReceivedFunctor functor(data);
334 RotationGestureDetector detector = RotationGestureDetector::New();
335 detector.Attach(actor);
336 detector.DetectedSignal().Connect(&application, functor);
338 // Start rotation within the actor's area
339 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(31.0f, 29.0f), 100);
340 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
341 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
342 DALI_TEST_EQUALS(0.404892f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
343 DALI_TEST_EQUALS(Vector2(20.5f, 24.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
344 DALI_TEST_EQUALS(Vector2(20.5f, 24.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
346 // Continue the rotation within the actor's area - we should still receive the signal
348 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(29.0f, 15.0f), 500);
349 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
350 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
351 DALI_TEST_EQUALS(-0.343024f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
352 DALI_TEST_EQUALS(Vector2(22.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
353 DALI_TEST_EQUALS(Vector2(22.0f, 17.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
355 // Gesture ends within actor's area - we would receive a finished state
357 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(29.0f, 15.0f), 1000);
358 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
359 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
360 DALI_TEST_EQUALS(-0.463648f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
361 DALI_TEST_EQUALS(Vector2(24.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
362 DALI_TEST_EQUALS(Vector2(24.0f, 17.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
366 int UtcDaliRotationGestureSignalReceptionDetach(void)
368 TestApplication application;
370 Actor actor = Actor::New();
371 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
372 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
373 application.GetScene().Add(actor);
376 application.SendNotification();
377 application.Render();
380 GestureReceivedFunctor functor(data);
382 RotationGestureDetector detector = RotationGestureDetector::New();
383 detector.Attach(actor);
384 detector.DetectedSignal().Connect(&application, functor);
386 // Start rotation within the actor's area
387 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
388 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
389 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
391 // Continue the rotation within the actor's area - we should still receive the signal
393 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
394 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
395 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
397 // Gesture ends within actor's area
399 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
400 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
401 DALI_TEST_EQUALS(GestureState::FINISHED, data.receivedGesture.GetState(), TEST_LOCATION);
404 detector.DetachAll();
406 // Ensure we are no longer signalled
408 TestGenerateRotation(application);
409 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
413 int UtcDaliRotationGestureSignalReceptionDetachWhileRotationing(void)
415 TestApplication application;
417 Actor actor = Actor::New();
418 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
419 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
420 application.GetScene().Add(actor);
423 application.SendNotification();
424 application.Render();
427 GestureReceivedFunctor functor(data);
429 RotationGestureDetector detector = RotationGestureDetector::New();
430 detector.Attach(actor);
431 detector.DetectedSignal().Connect(&application, functor);
433 // Start rotation within the actor's area
434 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
435 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
436 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
438 // Continue the rotation within the actor's area - we should still receive the signal
440 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
441 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
442 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
444 // Detach actor during the rotation, we should not receive the next event
445 detector.DetachAll();
447 // Gesture ends within actor's area
449 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
450 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
454 int UtcDaliRotationGestureSignalReceptionActorDestroyedWhileRotationing(void)
456 TestApplication application;
459 GestureReceivedFunctor functor(data);
461 RotationGestureDetector detector = RotationGestureDetector::New();
462 detector.DetectedSignal().Connect(&application, functor);
464 // Attach a temporary actor to stop detector being removed from RotationGestureProcessor when main actor
466 Actor tempActor = Actor::New();
467 tempActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
468 tempActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
469 application.GetScene().Add(tempActor);
470 detector.Attach(tempActor);
472 // Actor lifetime is scoped
474 Actor actor = Actor::New();
475 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
476 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
477 application.GetScene().Add(actor);
480 application.SendNotification();
481 application.Render();
483 detector.Attach(actor);
485 // Start rotation within the actor's area
486 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
487 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
488 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
490 // Continue the rotation within the actor's area - we should still receive the signal
492 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
493 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
494 DALI_TEST_EQUALS(GestureState::CONTINUING, data.receivedGesture.GetState(), TEST_LOCATION);
496 // Remove the actor from stage and reset the data
497 application.GetScene().Remove(actor);
500 application.SendNotification();
501 application.Render();
504 // Actor should now have been destroyed
506 // Gesture ends within the area where the actor used to be
508 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
509 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
513 int UtcDaliRotationGestureSignalReceptionRotatedActor(void)
515 TestApplication application;
517 Actor actor = Actor::New();
518 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
519 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
520 application.GetScene().Add(actor);
522 // Render and notify a couple of times
523 application.SendNotification();
524 application.Render();
527 GestureReceivedFunctor functor(data);
529 RotationGestureDetector detector = RotationGestureDetector::New();
530 detector.Attach(actor);
531 detector.DetectedSignal().Connect(&application, functor);
533 // Do an entire rotation, only check finished value
534 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
536 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(27.0f, 15.0f), 1000);
537 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
538 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
539 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
540 DALI_TEST_EQUALS(Vector2(67.5f, 27.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
542 // Rotate actor again and render and notify
543 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(180.0f), Vector3::ZAXIS));
544 application.SendNotification();
545 application.Render();
547 // Do an entire rotation, only check finished value
548 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
550 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(27.0f, 15.0f), 3000);
551 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
552 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
553 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
554 DALI_TEST_EQUALS(Vector2(27.0f, 32.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
556 // Rotate actor again and render and notify
557 actor.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(270.0f), Vector3::ZAXIS));
558 application.SendNotification();
559 application.Render();
561 // Do an entire rotation, only check finished value
562 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 4100);
564 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(27.0f, 15.0f), 5000);
565 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
566 DALI_TEST_EQUALS(-0.558599f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
567 DALI_TEST_EQUALS(Vector2(23.0f, 17.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
568 DALI_TEST_EQUALS(Vector2(32.5f, 73.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
572 int UtcDaliRotationGestureSignalReceptionChildHit(void)
574 TestApplication application;
576 Actor parent = Actor::New();
577 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
578 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
579 application.GetScene().Add(parent);
581 // Set child to completely cover parent.
582 // Change rotation of child to be different from parent so that we can check if our local coordinate
583 // conversion of the parent actor is correct.
584 Actor child = Actor::New();
585 child.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
586 child.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
587 child.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
588 child.SetProperty(Actor::Property::ORIENTATION, Quaternion(Dali::Degree(90.0f), Vector3::ZAXIS));
592 application.SendNotification();
593 application.Render();
596 GestureReceivedFunctor functor(data);
598 RotationGestureDetector detector = RotationGestureDetector::New();
599 detector.Attach(parent);
600 detector.DetectedSignal().Connect(&application, functor);
602 // Do an entire pan, only check finished value - hits child area but parent should still receive it
603 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
605 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(29.0f, 25.0f), 1000);
606 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
607 DALI_TEST_EQUALS(true, parent == data.rotatedActor, TEST_LOCATION);
608 DALI_TEST_EQUALS(0.463648f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
609 DALI_TEST_EQUALS(Vector2(24.0f, 22.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
610 DALI_TEST_EQUALS(Vector2(24.0f, 22.5f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
612 // Attach child and generate same touch points to yield same results
613 // (Also proves that you can detach and then re-attach another actor)
614 detector.Attach(child);
615 detector.Detach(parent);
617 // Do an entire pan, only check finished value
618 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 2100);
620 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(29.0f, 35.0f), 3000);
621 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
622 DALI_TEST_EQUALS(true, child == data.rotatedActor, TEST_LOCATION);
623 DALI_TEST_EQUALS(0.982794f, data.receivedGesture.GetRotation().radian, 0.01f, TEST_LOCATION);
624 DALI_TEST_EQUALS(Vector2(24.0f, 27.5f), data.receivedGesture.GetScreenCenterPoint(), 0.01f, TEST_LOCATION);
625 DALI_TEST_EQUALS(Vector2(27.5f, 76.0f), data.receivedGesture.GetLocalCenterPoint(), 0.01f, TEST_LOCATION);
629 int UtcDaliRotationGestureSignalReceptionAttachDetachMany(void)
631 TestApplication application;
633 Actor first = Actor::New();
634 first.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
635 first.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
636 application.GetScene().Add(first);
638 Actor second = Actor::New();
639 second.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
640 second.SetProperty(Actor::Property::POSITION_X, 100.0f);
641 second.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
642 application.GetScene().Add(second);
645 application.SendNotification();
646 application.Render();
649 GestureReceivedFunctor functor(data);
651 RotationGestureDetector detector = RotationGestureDetector::New();
652 detector.Attach(first);
653 detector.Attach(second);
654 detector.DetectedSignal().Connect(&application, functor);
656 // Start rotation within second actor's area
657 TestStartRotation(application, Vector2(102.0f, 20.0f), Vector2(138.0f, 20.0f), Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), 100);
658 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
659 DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
661 // Rotation moves into first actor's area - second actor should receive the rotation
663 TestContinueRotation(application, Vector2(110.0f, 20.0f), Vector2(130.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
664 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
665 DALI_TEST_EQUALS(true, second == data.rotatedActor, TEST_LOCATION);
667 // Detach the second actor during the rotation, we should not receive the next event
668 detector.Detach(second);
670 // Gesture ends within actor's area
672 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(119.0f, 20.0f), Vector2(121.0f, 20.0f), 3000);
673 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
677 int UtcDaliRotationGestureSignalReceptionActorBecomesUntouchable(void)
679 TestApplication application;
681 Actor actor = Actor::New();
682 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
683 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
684 application.GetScene().Add(actor);
687 application.SendNotification();
688 application.Render();
691 GestureReceivedFunctor functor(data);
693 RotationGestureDetector detector = RotationGestureDetector::New();
694 detector.Attach(actor);
695 detector.DetectedSignal().Connect(&application, functor);
697 // Start rotation in actor's area
698 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
699 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
701 // Rotation continues within actor's area
703 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
704 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
706 // Actor become invisible - actor should not receive the next rotation
707 actor.SetProperty(Actor::Property::VISIBLE, false);
710 application.SendNotification();
711 application.Render();
713 // Gesture ends within actor's area
715 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
716 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
720 int UtcDaliRotationGestureSignalReceptionMultipleDetectorsOnActor(void)
722 TestApplication application;
724 Actor actor = Actor::New();
725 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
726 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
727 application.GetScene().Add(actor);
729 Actor actor2 = Actor::New();
730 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
731 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
732 application.GetScene().Add(actor2);
735 application.SendNotification();
736 application.Render();
738 // Attach actor to one detector
739 SignalData firstData;
740 GestureReceivedFunctor firstFunctor(firstData);
741 RotationGestureDetector firstDetector = RotationGestureDetector::New();
742 firstDetector.Attach(actor);
743 firstDetector.DetectedSignal().Connect(&application, firstFunctor);
745 // Attach actor to another detector
746 SignalData secondData;
747 GestureReceivedFunctor secondFunctor(secondData);
748 RotationGestureDetector secondDetector = RotationGestureDetector::New();
749 secondDetector.Attach(actor);
750 secondDetector.DetectedSignal().Connect(&application, secondFunctor);
752 // Add second actor to second detector, when we remove the actor, this will make sure that this
753 // gesture detector is not removed from the GestureDetectorProcessor. In this scenario, the
754 // functor should still not be called (which is what we're also testing).
755 secondDetector.Attach(actor2);
757 // Rotation in actor's area - both detector's functors should be called
758 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
759 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
760 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
762 // Rotation continues in actor's area - both detector's functors should be called
765 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
766 DALI_TEST_EQUALS(true, firstData.functorCalled, TEST_LOCATION);
767 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
769 // Detach actor from firstDetector and emit rotation on actor, only secondDetector's functor should be called.
770 firstDetector.Detach(actor);
773 TestEndRotation(application, Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
774 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
775 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
777 // New rotation on actor, only secondDetector has actor attached
780 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
781 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
782 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
784 // Detach actor from secondDetector
785 secondDetector.Detach(actor);
788 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
789 DALI_TEST_EQUALS(false, firstData.functorCalled, TEST_LOCATION);
790 DALI_TEST_EQUALS(false, secondData.functorCalled, TEST_LOCATION);
794 int UtcDaliRotationGestureSignalReceptionEnsureCorrectSignalling(void)
796 TestApplication application;
798 Actor actor1 = Actor::New();
799 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
800 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
801 application.GetScene().Add(actor1);
803 GestureReceivedFunctor functor1(data1);
804 RotationGestureDetector detector1 = RotationGestureDetector::New();
805 detector1.Attach(actor1);
806 detector1.DetectedSignal().Connect(&application, functor1);
808 Actor actor2 = Actor::New();
809 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
810 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
811 actor2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_RIGHT);
812 application.GetScene().Add(actor2);
814 GestureReceivedFunctor functor2(data2);
815 RotationGestureDetector detector2 = RotationGestureDetector::New();
816 detector2.Attach(actor2);
817 detector2.DetectedSignal().Connect(&application, functor2);
820 application.SendNotification();
821 application.Render();
823 // Start pan in actor1's area, only data1 should be set
824 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
825 DALI_TEST_EQUALS(true, data1.functorCalled, TEST_LOCATION);
826 DALI_TEST_EQUALS(false, data2.functorCalled, TEST_LOCATION);
830 int UtcDaliRotationGestureActorUnstaged(void)
832 TestApplication application;
834 Actor actor = Actor::New();
835 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
836 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
837 application.GetScene().Add(actor);
840 application.SendNotification();
841 application.Render();
843 // State to remove actor in.
844 GestureState stateToUnstage(GestureState::STARTED);
846 // Attach actor to detector
848 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
849 RotationGestureDetector detector = RotationGestureDetector::New();
850 detector.Attach(actor);
851 detector.DetectedSignal().Connect(&application, functor);
854 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
855 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
857 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
858 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
862 application.SendNotification();
863 application.Render();
865 // Re-add actor to stage
866 application.GetScene().Add(actor);
869 application.SendNotification();
870 application.Render();
872 // Change state to GestureState::CONTINUING to remove
873 stateToUnstage = GestureState::CONTINUING;
876 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
877 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
879 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
880 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
882 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
883 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
887 application.SendNotification();
888 application.Render();
890 // Re-add actor to stage
891 application.GetScene().Add(actor);
894 application.SendNotification();
895 application.Render();
897 // Change state to GestureState::CONTINUING to remove
898 stateToUnstage = GestureState::FINISHED;
901 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
902 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
904 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
905 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
907 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
908 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
909 tet_result(TET_PASS); // If we get here then we have handled actor stage removal gracefully.
913 int UtcDaliRotationGestureActorStagedAndDestroyed(void)
915 TestApplication application;
917 Actor actor = Actor::New();
918 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
919 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
920 application.GetScene().Add(actor);
922 // Create and add a second actor so that GestureDetector destruction does not come into play.
923 Actor dummyActor(Actor::New());
924 dummyActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
925 dummyActor.SetProperty(Actor::Property::POSITION, Vector2(100.0f, 100.0f));
926 dummyActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
927 application.GetScene().Add(dummyActor);
930 application.SendNotification();
931 application.Render();
933 // State to remove actor in.
934 GestureState stateToUnstage(GestureState::STARTED);
936 // Attach actor to detector
938 UnstageActorFunctor functor(data, stateToUnstage, application.GetScene());
939 RotationGestureDetector detector = RotationGestureDetector::New();
940 detector.Attach(actor);
941 detector.Attach(dummyActor);
942 detector.DetectedSignal().Connect(&application, functor);
944 // Here we are testing a STARTED actor which is removed in the STARTED callback, but then added back
945 // before we get a continuing state. As we were removed from the stage, even if we're at the same
946 // position, we should still not be signalled.
949 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
950 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
954 application.SendNotification();
955 application.Render();
957 // Re add to the stage, we should not be signalled
958 application.GetScene().Add(actor);
961 application.SendNotification();
962 application.Render();
964 // Continue signal emission
965 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
966 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
968 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
969 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
972 // Here we delete an actor in started, we should not receive any subsequent signalling.
975 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
976 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
980 application.SendNotification();
981 application.Render();
983 // Delete actor as well
987 application.SendNotification();
988 application.Render();
990 // Continue signal emission
991 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 2000);
992 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
994 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 3000);
995 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
999 int UtcDaliRotationGestureLayerConsumesTouch(void)
1001 TestApplication application;
1003 Actor actor = Actor::New();
1004 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1005 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1006 application.GetScene().Add(actor);
1010 GestureReceivedFunctor functor(data);
1011 RotationGestureDetector detector = RotationGestureDetector::New();
1012 detector.Attach(actor);
1013 detector.DetectedSignal().Connect(&application, functor);
1015 // Add a layer to overlap the actor
1016 Layer layer = Layer::New();
1017 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1018 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1019 application.GetScene().Add(layer);
1022 // Render and notify
1023 application.SendNotification();
1024 application.Render();
1026 // Emit signals, should receive
1027 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1028 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1029 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1032 // Set layer to consume all touch
1033 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
1035 // Render and notify
1036 application.SendNotification();
1037 application.Render();
1039 // Emit the same signals again, should not receive
1040 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 1500);
1041 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 2000);
1042 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1048 int UtcDaliRotationGestureInterruptedWhenTouchConsumed(void)
1050 TestApplication application;
1052 Actor actor = Actor::New();
1053 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1054 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1055 application.GetScene().Add(actor);
1057 bool consume = false;
1058 TouchEventFunctorConsumeSetter touchFunctor(consume);
1059 actor.TouchedSignal().Connect(&application, touchFunctor);
1061 // Render and notify
1062 application.SendNotification();
1063 application.Render();
1066 GestureReceivedFunctor functor(data);
1068 RotationGestureDetector detector = RotationGestureDetector::New();
1069 detector.Attach(actor);
1070 detector.DetectedSignal().Connect(&application, functor);
1072 // Start gesture within the actor's area, we should receive the rotation as the touch is NOT being consumed
1073 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1075 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1076 DALI_TEST_EQUALS(GestureState::STARTED, data.receivedGesture.GetState(), TEST_LOCATION);
1079 // Continue the gesture within the actor's area, but now the touch consumes thus cancelling the gesture
1082 TestContinueRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(15.0f, 20.0f), Vector2(25.0f, 20.0f), 500);
1083 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1084 DALI_TEST_EQUALS(GestureState::CANCELLED, data.receivedGesture.GetState(), TEST_LOCATION);
1087 // Start another rotation, we should not even get the callback this time
1088 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1089 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1094 int UtcDaliRotationGestureDisableDetectionDuringRotationN(void)
1096 // Crash sometimes occurred when gesture-recognizer was deleted internally during a signal when the attached actor was detached
1098 TestApplication application;
1100 Actor actor = Actor::New();
1101 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1102 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1103 application.GetScene().Add(actor);
1106 RotationGestureDetector detector = RotationGestureDetector::New();
1107 bool functorCalled = false;
1108 detector.Attach(actor);
1109 detector.DetectedSignal().Connect(
1111 [&detector, &functorCalled](Actor actor, const RotationGesture& gesture) {
1112 if(gesture.GetState() == GestureState::FINISHED)
1114 detector.Detach(actor);
1115 functorCalled = true;
1119 // Render and notify
1120 application.SendNotification();
1121 application.Render();
1123 // Try the gesture, should not crash
1126 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1127 TestContinueRotation(application, Vector2(112.0f, 100.0f), Vector2(112.0f, 124.0f), Vector2(5.0f, 5.0f), Vector2(35.0f, 35.0f), 200);
1128 TestEndRotation(application, Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), Vector2(19.0f, 20.0f), Vector2(21.0f, 20.0f), 1000);
1130 DALI_TEST_CHECK(true); // No crash, test has passed
1131 DALI_TEST_EQUALS(functorCalled, true, TEST_LOCATION);
1135 DALI_TEST_CHECK(false); // If we crash, the test has failed
1141 int UtcDaliRotationGestureWhenGesturePropargation(void)
1143 TestApplication application;
1145 Actor parentActor = Actor::New();
1146 parentActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1147 parentActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1149 Actor childActor = Actor::New();
1150 childActor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1151 childActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1153 parentActor.Add(childActor);
1154 application.GetScene().Add(parentActor);
1156 // Render and notify
1157 application.SendNotification();
1158 application.Render();
1161 GestureReceivedFunctor pFunctor(pData);
1163 RotationGestureDetector parentDetector = RotationGestureDetector::New();
1164 parentDetector.Attach(parentActor);
1165 parentDetector.DetectedSignal().Connect(&application, pFunctor);
1168 GestureReceivedFunctor cFunctor(cData);
1170 RotationGestureDetector childDetector = RotationGestureDetector::New();
1171 childDetector.Attach(childActor);
1172 childDetector.DetectedSignal().Connect(&application, cFunctor);
1174 // Start gesture within the actor's area, we receive the gesture not parent actor but child actor.
1175 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 100);
1176 TestEndRotation(application, Vector2(6.0f, 6.0f), Vector2(18.0f, 18.0f), Vector2(10.0f, 8.0f), Vector2(14.0f, 16.0f), 300);
1177 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1178 DALI_TEST_EQUALS(false, pData.functorCalled, TEST_LOCATION);
1182 // If GesturePropargation is set, a gesture event is to pass over to the parent.
1183 Dali::DevelActor::SetNeedGesturePropagation(childActor, true);
1185 // So now the parent got the gesture event.
1186 TestStartRotation(application, Vector2(2.0f, 20.0f), Vector2(38.0f, 20.0f), Vector2(10.0f, 20.0f), Vector2(30.0f, 20.0f), 700);
1187 TestEndRotation(application, Vector2(6.0f, 6.0f), Vector2(18.0f, 18.0f), Vector2(10.0f, 8.0f), Vector2(14.0f, 16.0f), 900);
1188 DALI_TEST_EQUALS(true, cData.functorCalled, TEST_LOCATION);
1189 DALI_TEST_EQUALS(true, pData.functorCalled, TEST_LOCATION);