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.
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/events/touch-integ.h>
22 #include <dali/integration-api/render-task-list-integ.h>
23 #include <dali/public-api/dali-core.h>
30 void utc_dali_touch_processing_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_touch_processing_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
47 PointState::Type state{PointState::FINISHED};
52 Vector2 ellipseRadius;
55 Device::Class::Type deviceClass{Device::Class::NONE};
56 Device::Subclass::Type deviceSubclass{Device::Subclass::NONE};
58 TestPoint() = default;
59 static const TestPoint ZERO;
62 const TestPoint TestPoint::ZERO;
64 // Stores data that is populated in the callback and will be read by the TET cases
68 : functorCalled(false),
77 std::vector<TestPoint> points;
79 const TestPoint& GetPoint(size_t i)
85 return TestPoint::ZERO;
87 size_t GetPointCount()
95 functorCalled = false;
97 receivedTouch.time = 0u;
98 receivedTouch.points.clear();
100 touchedActor.Reset();
104 TestTouchEvent receivedTouch;
108 // Functor that sets the data when called
109 struct TouchEventFunctor
113 * @param[in] data Reference to the data to store callback information.
114 * @param[in] returnValue What the functor should return.
116 TouchEventFunctor(SignalData& data, bool returnValue = true)
118 returnValue(returnValue)
122 bool operator()(Actor actor, const TouchEvent& touch)
124 signalData.functorCalled = true;
125 signalData.touchedActor = actor;
127 signalData.receivedTouch.time = touch.GetTime();
128 signalData.receivedTouch.points.clear();
130 for(size_t i = 0; i < touch.GetPointCount(); ++i)
133 p.deviceId = touch.GetDeviceId(i);
134 p.state = touch.GetState(i);
135 p.hitActor = touch.GetHitActor(i);
136 p.local = touch.GetLocalPosition(i);
137 p.screen = touch.GetScreenPosition(i);
138 p.radius = touch.GetRadius(i);
139 p.ellipseRadius = touch.GetEllipseRadius(i);
140 p.pressure = touch.GetPressure(i);
141 p.angle = touch.GetAngle(i);
142 p.deviceClass = touch.GetDeviceClass(i);
143 p.deviceSubclass = touch.GetDeviceSubclass(i);
144 signalData.receivedTouch.points.push_back(p);
150 SignalData& signalData;
157 TouchEvent receivedTouchHandle;
160 : signalReceived(false)
165 struct TouchEventHandleFunctor
169 * @param[in] data Reference to the data to store callback information.
170 * @param[in] returnValue What the functor should return.
172 TouchEventHandleFunctor(HandleData& handleData, bool returnValue = true)
173 : handleData(handleData),
174 returnValue(returnValue)
178 bool operator()(Actor actor, const TouchEvent& someTouchEvent)
180 handleData.signalReceived = true;
181 handleData.receivedTouchHandle = someTouchEvent;
185 HandleData& handleData;
189 // Functor that removes the actor when called.
190 struct RemoveActorFunctor : public TouchEventFunctor
194 * @param[in] data Reference to the data to store callback information.
195 * @param[in] returnValue What the functor should return.
197 RemoveActorFunctor(SignalData& data, bool returnValue = true)
198 : TouchEventFunctor(data, returnValue)
202 bool operator()(Actor actor, const TouchEvent& touch)
204 Actor parent(actor.GetParent());
207 parent.Remove(actor);
210 return TouchEventFunctor::operator()(actor, touch);
214 struct OutOfBoundsData
220 : functorCalled(false)
225 // Functor that reads out of bounds data when called
226 struct OutOfBoundsFunctor
230 * @param[in] data Reference to the data to store callback information.
231 * @param[in] returnValue What the functor should return.
233 OutOfBoundsFunctor(OutOfBoundsData& data, bool returnValue = true)
234 : outOfBoundsData(data),
235 returnValue(returnValue)
239 bool operator()(Actor actor, const TouchEvent& touch)
241 outOfBoundsData.functorCalled = true;
242 size_t count = touch.GetPointCount();
244 // Read out of bounds data
245 outOfBoundsData.point.deviceId = touch.GetDeviceId(count + 1);
246 outOfBoundsData.point.state = touch.GetState(count + 1);
247 outOfBoundsData.point.hitActor = touch.GetHitActor(count + 1);
248 outOfBoundsData.point.local = touch.GetLocalPosition(count + 1);
249 outOfBoundsData.point.screen = touch.GetScreenPosition(count + 1);
254 OutOfBoundsData& outOfBoundsData;
258 Integration::TouchEvent GenerateSingleTouch(PointState::Type state, const Vector2& screenPosition)
260 Integration::TouchEvent touchEvent;
261 Integration::Point point;
262 point.SetState(state);
263 point.SetScreenPosition(screenPosition);
264 point.SetDeviceClass(Device::Class::TOUCH);
265 point.SetDeviceSubclass(Device::Subclass::NONE);
266 touchEvent.points.push_back(point);
272 ///////////////////////////////////////////////////////////////////////////////
274 int UtcDaliTouchEventNormalProcessing01(void)
276 TestApplication application;
278 Actor actor = Actor::New();
279 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
280 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
281 application.GetScene().Add(actor);
284 application.SendNotification();
285 application.Render();
287 // Connect to actor's touch signal
289 TouchEventFunctor functor(data);
290 actor.TouchedSignal().Connect(&application, functor);
292 Vector2 screenCoordinates(10.0f, 10.0f);
293 Vector2 localCoordinates;
294 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
296 // Emit a down signal
297 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
298 const TestPoint* point1 = &data.receivedTouch.GetPoint(0);
299 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
300 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
301 DALI_TEST_EQUALS(PointState::DOWN, point1->state, TEST_LOCATION);
302 DALI_TEST_EQUALS(screenCoordinates, point1->screen, TEST_LOCATION);
303 DALI_TEST_EQUALS(localCoordinates, point1->local, 0.1f, TEST_LOCATION);
306 // Emit a motion signal
307 screenCoordinates.x = screenCoordinates.y = 11.0f;
308 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
309 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
310 const TestPoint* point2 = &data.receivedTouch.GetPoint(0);
311 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
312 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
313 DALI_TEST_EQUALS(PointState::MOTION, point2->state, TEST_LOCATION);
314 DALI_TEST_EQUALS(screenCoordinates, point2->screen, TEST_LOCATION);
315 DALI_TEST_EQUALS(localCoordinates, point2->local, 0.1f, TEST_LOCATION);
319 screenCoordinates.x = screenCoordinates.y = 12.0f;
320 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
321 application.ProcessEvent(GenerateSingleTouch(PointState::UP, screenCoordinates));
322 const TestPoint* point3 = &data.receivedTouch.GetPoint(0);
323 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
324 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
325 DALI_TEST_EQUALS(PointState::UP, point3->state, TEST_LOCATION);
326 DALI_TEST_EQUALS(screenCoordinates, point3->screen, TEST_LOCATION);
327 DALI_TEST_EQUALS(localCoordinates, point3->local, 0.1f, TEST_LOCATION);
330 // Emit a down signal where the actor is not present
331 screenCoordinates.x = screenCoordinates.y = 200.0f;
332 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
333 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
337 int UtcDaliTouchEventNormalProcessing02(void)
339 TestApplication application;
341 Actor actor = Actor::New();
342 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
343 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
344 application.GetScene().Add(actor);
347 application.SendNotification();
348 application.Render();
350 // Connect to actor's touched signal
351 HandleData handleData;
352 TouchEventHandleFunctor functor(handleData);
353 actor.TouchedSignal().Connect(&application, functor);
355 Vector2 screenCoordinates(10.0f, 10.0f);
356 Vector2 localCoordinates;
357 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
359 // Emit a down signal
360 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
361 DALI_TEST_EQUALS(true, handleData.signalReceived, TEST_LOCATION);
362 DALI_TEST_EQUALS(1u, handleData.receivedTouchHandle.GetPointCount(), TEST_LOCATION);
363 DALI_TEST_EQUALS(PointState::DOWN, handleData.receivedTouchHandle.GetState(0), TEST_LOCATION);
364 DALI_TEST_EQUALS(screenCoordinates, handleData.receivedTouchHandle.GetScreenPosition(0), TEST_LOCATION);
365 DALI_TEST_EQUALS(localCoordinates, handleData.receivedTouchHandle.GetLocalPosition(0), 0.1f, TEST_LOCATION);
370 int UtcDaliTouchEventAPINegative(void)
372 TestApplication application;
374 Actor actor = Actor::New();
375 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
376 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
377 application.GetScene().Add(actor);
380 application.SendNotification();
381 application.Render();
383 // Connect to actor's touched signal
384 OutOfBoundsData data;
385 OutOfBoundsFunctor functor(data, true);
386 actor.TouchedSignal().Connect(&application, functor);
388 Vector2 screenCoordinates(10.0f, 10.0f);
389 Vector2 localCoordinates;
390 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
392 // Emit a down signal
393 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
395 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
396 DALI_TEST_EQUALS(-1, data.point.deviceId, TEST_LOCATION);
397 DALI_TEST_EQUALS(PointState::FINISHED, data.point.state, TEST_LOCATION);
398 DALI_TEST_EQUALS(Vector2::ZERO, data.point.screen, TEST_LOCATION);
399 DALI_TEST_EQUALS(Vector2::ZERO, data.point.local, 0.1f, TEST_LOCATION);
400 DALI_TEST_CHECK(!data.point.hitActor);
405 int UtcDaliTouchEventOutsideCameraNearFarPlanes(void)
407 TestApplication application;
409 Integration::Scene scene = application.GetScene();
410 Vector2 sceneSize = scene.GetSize();
412 Actor actor = Actor::New();
413 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
414 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
415 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
419 application.SendNotification();
420 application.Render();
422 // Get the camera's near and far planes
423 RenderTaskList taskList = scene.GetRenderTaskList();
424 Dali::RenderTask task = taskList.GetTask(0);
425 CameraActor camera = task.GetCameraActor();
426 float nearPlane = camera.GetNearClippingPlane();
427 float farPlane = camera.GetFarClippingPlane();
429 // Calculate the current distance of the actor from the camera
430 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
431 float distance = (sceneSize.y * 0.5f) / tanHalfFov;
433 // Connect to actor's touched signal
435 TouchEventFunctor functor(data);
436 actor.TouchedSignal().Connect(&application, functor);
438 Vector2 screenCoordinates(sceneSize.x * 0.5f, sceneSize.y * 0.5f);
440 // Emit a down signal
441 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
442 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
445 // Emit a down signal where actor is just at the camera's near plane
446 actor.SetProperty(Actor::Property::POSITION_Z, distance - nearPlane);
449 application.SendNotification();
450 application.Render();
452 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
453 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
456 // Emit a down signal where actor is closer than the camera's near plane
457 actor.SetProperty(Actor::Property::POSITION_Z, (distance - nearPlane) + 1.0f);
460 application.SendNotification();
461 application.Render();
463 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
464 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
467 // Emit a down signal where actor is just at the camera's far plane
468 actor.SetProperty(Actor::Property::POSITION_Z, distance - farPlane);
471 application.SendNotification();
472 application.Render();
474 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
475 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
478 // Emit a down signal where actor is further than the camera's far plane
479 actor.SetProperty(Actor::Property::POSITION_Z, (distance - farPlane) - 1.0f);
482 application.SendNotification();
483 application.Render();
485 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
486 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
491 int UtcDaliTouchEventEmitEmpty(void)
493 TestApplication application;
497 // Emit an empty TouchEvent
498 Integration::TouchEvent event;
499 application.ProcessEvent(event);
500 tet_result(TET_FAIL);
502 catch(Dali::DaliException& e)
504 DALI_TEST_ASSERT(e, "!event.points.empty()", TEST_LOCATION);
509 int UtcDaliTouchEventInterrupted(void)
511 TestApplication application;
513 Actor actor = Actor::New();
514 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
515 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
516 application.GetScene().Add(actor);
519 application.SendNotification();
520 application.Render();
522 // Connect to actor's touched signal
524 TouchEventFunctor functor(data);
525 actor.TouchedSignal().Connect(&application, functor);
527 // Emit a down signal
528 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
529 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
530 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
533 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
534 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f /* Outside actor */)));
535 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
536 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
539 // Emit another interrupted signal, our signal handler should not be called.
540 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
541 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
545 int UtcDaliTouchEventParentConsumer(void)
547 TestApplication application;
548 Actor rootActor(application.GetScene().GetRootLayer());
550 Actor actor = Actor::New();
551 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
552 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
553 application.GetScene().Add(actor);
556 application.SendNotification();
557 application.Render();
559 // Connect to actor's touched signal
561 TouchEventFunctor functor(data, false);
562 actor.TouchedSignal().Connect(&application, functor);
564 // Connect to root actor's touched signal
566 TouchEventFunctor rootFunctor(rootData); // Consumes signal
567 rootActor.TouchedSignal().Connect(&application, rootFunctor);
569 Vector2 screenCoordinates(10.0f, 10.0f);
570 Vector2 actorCoordinates, rootCoordinates;
571 actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
572 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
574 // Emit a down signal
575 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
576 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
577 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
578 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
579 DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
580 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
581 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
582 DALI_TEST_EQUALS(screenCoordinates, data.receivedTouch.points[0].screen, TEST_LOCATION);
583 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
584 DALI_TEST_EQUALS(actorCoordinates, data.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
585 DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
586 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
587 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
591 // Emit a motion signal
592 screenCoordinates.x = screenCoordinates.y = 11.0f;
593 actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
594 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
595 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
596 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
597 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
598 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
599 DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
600 DALI_TEST_EQUALS(PointState::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
601 DALI_TEST_EQUALS(PointState::MOTION, rootData.receivedTouch.points[0].state, TEST_LOCATION);
602 DALI_TEST_EQUALS(screenCoordinates, data.receivedTouch.points[0].screen, TEST_LOCATION);
603 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
604 DALI_TEST_EQUALS(actorCoordinates, data.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
605 DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
606 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
607 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
612 screenCoordinates.x = screenCoordinates.y = 12.0f;
613 actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
614 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
615 application.ProcessEvent(GenerateSingleTouch(PointState::UP, screenCoordinates));
616 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
617 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
618 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
619 DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
620 DALI_TEST_EQUALS(PointState::UP, data.receivedTouch.points[0].state, TEST_LOCATION);
621 DALI_TEST_EQUALS(PointState::UP, rootData.receivedTouch.points[0].state, TEST_LOCATION);
622 DALI_TEST_EQUALS(screenCoordinates, data.receivedTouch.points[0].screen, TEST_LOCATION);
623 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
624 DALI_TEST_EQUALS(actorCoordinates, data.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
625 DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
626 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
627 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
631 // Emit a down signal where the actor is not present, will hit the root actor though
632 screenCoordinates.x = screenCoordinates.y = 200.0f;
633 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
634 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
635 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
636 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
637 DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
638 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
639 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
640 DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
641 DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
645 int UtcDaliTouchEventInterruptedParentConsumer(void)
647 TestApplication application;
648 Actor rootActor(application.GetScene().GetRootLayer());
650 Actor actor = Actor::New();
651 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
652 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
653 application.GetScene().Add(actor);
656 application.SendNotification();
657 application.Render();
659 // Connect to actor's touched signal
661 TouchEventFunctor functor(data, false);
662 actor.TouchedSignal().Connect(&application, functor);
664 // Connect to root actor's touched signal
666 TouchEventFunctor rootFunctor(rootData); // Consumes signal
667 rootActor.TouchedSignal().Connect(&application, rootFunctor);
669 // Emit a down signal
670 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
671 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
672 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
673 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
674 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
675 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
676 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
680 // Emit an interrupted signal
681 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
682 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
683 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
684 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
685 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
686 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
687 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
691 // Emit another down signal
692 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
693 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
694 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
695 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
696 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
700 // Remove actor from scene
701 application.GetScene().Remove(actor);
706 application.SendNotification();
707 application.Render();
709 // Emit an interrupted signal, only root actor's signal should be called.
710 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f /* Outside actor */)));
711 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
712 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
713 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
714 DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
718 // Emit another interrupted state, none of the signal's should be called.
719 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
720 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
721 DALI_TEST_EQUALS(false, rootData.functorCalled, TEST_LOCATION);
725 int UtcDaliTouchEventLeave(void)
727 TestApplication application;
729 Actor actor = Actor::New();
730 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
731 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
732 application.GetScene().Add(actor);
735 application.SendNotification();
736 application.Render();
738 // Connect to actor's touched signal
740 TouchEventFunctor functor(data);
741 actor.TouchedSignal().Connect(&application, functor);
743 // Set actor to require leave events
744 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
746 // Emit a down signal
747 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
748 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
749 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
752 // Emit a motion signal outside of actor, should be signalled with a Leave
753 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
754 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
755 DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
758 // Another motion outside of actor, no signalling
759 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(201.0f, 201.0f)));
760 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
763 // Another motion event inside actor, signalled with motion
764 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
765 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
766 DALI_TEST_EQUALS(PointState::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
769 // We do not want to listen to leave events anymore
770 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, false);
772 // Another motion event outside of actor, no signalling
773 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
774 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
779 int UtcDaliTouchEventLeaveParentConsumer(void)
781 TestApplication application;
782 Actor rootActor(application.GetScene().GetRootLayer());
784 Actor actor = Actor::New();
785 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
786 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
787 application.GetScene().Add(actor);
790 application.SendNotification();
791 application.Render();
793 // Connect to actor's touched signal
795 TouchEventFunctor functor(data, false);
796 actor.TouchedSignal().Connect(&application, functor);
798 // Connect to root actor's touched signal
800 TouchEventFunctor rootFunctor(rootData); // Consumes signal
801 rootActor.TouchedSignal().Connect(&application, rootFunctor);
803 // Set actor to require leave events
804 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
805 rootActor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
807 // Emit a down signal
808 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
809 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
810 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
811 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
812 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
813 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
814 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
818 // Emit a motion signal outside of actor, should be signalled with a Leave
819 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
820 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
821 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
822 DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
823 DALI_TEST_EQUALS(PointState::LEAVE, rootData.receivedTouch.points[0].state, TEST_LOCATION);
824 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
825 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
829 // Another motion outside of actor, only rootActor signalled
830 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(201.0f, 201.0f)));
831 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
832 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
833 DALI_TEST_EQUALS(PointState::MOTION, rootData.receivedTouch.points[0].state, TEST_LOCATION);
834 DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
838 // Another motion event inside actor, signalled with motion
839 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
840 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
841 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
842 DALI_TEST_EQUALS(PointState::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
843 DALI_TEST_EQUALS(PointState::MOTION, rootData.receivedTouch.points[0].state, TEST_LOCATION);
844 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
845 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
849 // We do not want to listen to leave events of actor anymore
850 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, false);
852 // Another motion event outside of root actor, only root signalled
853 Vector2 sceneSize(application.GetScene().GetSize());
854 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(sceneSize.width + 10.0f, sceneSize.height + 10.0f)));
855 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
856 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
857 DALI_TEST_EQUALS(PointState::LEAVE, rootData.receivedTouch.points[0].state, TEST_LOCATION);
861 int UtcDaliTouchEventActorBecomesInsensitive(void)
863 TestApplication application;
865 Actor actor = Actor::New();
866 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
867 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
868 application.GetScene().Add(actor);
871 application.SendNotification();
872 application.Render();
874 // Connect to actor's touched signal
876 TouchEventFunctor functor(data);
877 actor.TouchedSignal().Connect(&application, functor);
879 // Emit a down signal
880 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
881 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
882 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
885 // Change actor to insensitive
886 actor.SetProperty(Actor::Property::SENSITIVE, false);
888 // Emit a motion signal, signalled with an interrupted
889 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
890 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
891 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
896 int UtcDaliTouchEventActorBecomesInsensitiveParentConsumer(void)
898 TestApplication application;
899 Actor rootActor(application.GetScene().GetRootLayer());
901 Actor actor = Actor::New();
902 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
903 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
904 application.GetScene().Add(actor);
907 application.SendNotification();
908 application.Render();
910 // Connect to actor's touched signal
912 TouchEventFunctor functor(data, false);
913 actor.TouchedSignal().Connect(&application, functor);
915 // Connect to root actor's touched signal
917 TouchEventFunctor rootFunctor(rootData); // Consumes signal
918 rootActor.TouchedSignal().Connect(&application, rootFunctor);
920 // Emit a down signal
921 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
922 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
923 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
924 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
925 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
926 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
927 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
932 application.SendNotification();
933 application.Render();
935 // Make root actor insensitive
936 rootActor.SetProperty(Actor::Property::SENSITIVE, false);
938 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
939 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
940 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
941 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
942 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
943 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
947 int UtcDaliTouchEventMultipleLayers(void)
949 TestApplication application;
950 Actor rootActor(application.GetScene().GetRootLayer());
952 // Connect to actor's touched signal
954 TouchEventFunctor functor(data);
956 Layer layer1(Layer::New());
957 layer1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
958 layer1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
959 application.GetScene().Add(layer1);
961 Actor actor1(Actor::New());
962 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
963 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
964 actor1.SetProperty(Actor::Property::POSITION_Z, 1.0f); // Should hit actor1 in this layer
968 application.SendNotification();
969 application.Render();
971 // Connect to layer1 and actor1
972 layer1.TouchedSignal().Connect(&application, functor);
973 actor1.TouchedSignal().Connect(&application, functor);
975 // Hit in hittable area, actor1 should be hit
976 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
977 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
978 DALI_TEST_CHECK(data.touchedActor == actor1);
981 // Make layer1 insensitive, nothing should be hit
982 layer1.SetProperty(Actor::Property::SENSITIVE, false);
983 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
984 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
987 // Make layer1 sensitive again, again actor1 will be hit
988 layer1.SetProperty(Actor::Property::SENSITIVE, true);
989 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
990 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
991 DALI_TEST_CHECK(data.touchedActor == actor1);
994 // Make rootActor insensitive, nothing should be hit
995 rootActor.SetProperty(Actor::Property::SENSITIVE, false);
996 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
997 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1000 // Make rootActor sensitive
1001 rootActor.SetProperty(Actor::Property::SENSITIVE, true);
1003 // Add another layer
1004 Layer layer2(Layer::New());
1005 layer2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1006 layer2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1007 layer2.SetProperty(Actor::Property::POSITION_Z, 10.0f); // Should hit layer2 in this layer rather than actor2
1008 application.GetScene().Add(layer2);
1010 Actor actor2(Actor::New());
1011 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1012 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1015 // Render and notify
1016 application.SendNotification();
1017 application.Render();
1019 // Connect to layer2 and actor2
1020 layer2.TouchedSignal().Connect(&application, functor);
1021 actor2.TouchedSignal().Connect(&application, functor);
1023 // Emit an event, should hit layer2
1024 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1025 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1026 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1029 // Make layer2 insensitive, should hit actor1
1030 layer2.SetProperty(Actor::Property::SENSITIVE, false);
1031 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1032 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1033 DALI_TEST_CHECK(data.touchedActor == actor1);
1036 // Make layer2 sensitive again, should hit layer2
1037 layer2.SetProperty(Actor::Property::SENSITIVE, true);
1038 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1039 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1040 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1043 // Make layer2 invisible, render and notify
1044 layer2.SetProperty(Actor::Property::VISIBLE, false);
1045 application.SendNotification();
1046 application.Render();
1048 // Should hit actor1
1049 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1050 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1051 DALI_TEST_CHECK(data.touchedActor == actor1);
1054 // Make rootActor invisible, render and notify
1055 rootActor.SetProperty(Actor::Property::VISIBLE, false);
1056 application.SendNotification();
1057 application.Render();
1059 // Should not hit anything
1060 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1061 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1066 int UtcDaliTouchEventMultipleRenderTasks(void)
1068 TestApplication application;
1069 Integration::Scene scene(application.GetScene());
1070 Vector2 sceneSize(scene.GetSize());
1072 Actor actor = Actor::New();
1073 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1074 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1077 // Create render task
1078 Viewport viewport(sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f);
1079 RenderTask renderTask(application.GetScene().GetRenderTaskList().CreateTask());
1080 renderTask.SetViewport(viewport);
1081 renderTask.SetInputEnabled(true);
1083 // Render and notify
1084 application.SendNotification();
1085 application.Render();
1087 // Connect to actor's touched signal
1089 TouchEventFunctor functor(data);
1090 actor.TouchedSignal().Connect(&application, functor);
1092 // Emit a down signal
1093 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1094 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1097 // Ensure renderTask actor can be hit too.
1098 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1099 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1102 // Disable input on renderTask, should not be hittable
1103 renderTask.SetInputEnabled(false);
1104 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1105 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1110 int UtcDaliTouchEventMultipleRenderTasksWithChildLayer(void)
1112 TestApplication application;
1113 Integration::Scene scene(application.GetScene());
1114 Vector2 sceneSize(scene.GetSize());
1116 Actor actor = Actor::New();
1117 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1118 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1121 Layer layer = Layer::New();
1122 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1123 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1126 // Create render task
1127 Viewport viewport(sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f);
1128 RenderTask renderTask(application.GetScene().GetRenderTaskList().CreateTask());
1129 renderTask.SetViewport(viewport);
1130 renderTask.SetInputEnabled(true);
1131 renderTask.SetSourceActor(actor);
1133 // Render and notify
1134 application.SendNotification();
1135 application.Render();
1137 // Connect to layer's touched signal
1139 TouchEventFunctor functor(data);
1140 actor.TouchedSignal().Connect(&application, functor);
1141 layer.TouchedSignal().Connect(&application, functor);
1143 // Emit a down signal
1144 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1145 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1148 // Ensure renderTask actor can be hit too.
1149 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1150 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1153 // Disable input on renderTask, should not be hittable
1154 renderTask.SetInputEnabled(false);
1155 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1156 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1161 int UtcDaliTouchEventOffscreenRenderTasks(void)
1163 TestApplication application;
1164 Integration::Scene scene(application.GetScene());
1165 Vector2 sceneSize(scene.GetSize());
1167 // FrameBufferImage for offscreen RenderTask
1168 FrameBuffer frameBuffer = FrameBuffer::New(sceneSize.width, sceneSize.height);
1170 // Create a renderable actor to display the FrameBufferImage
1171 Actor renderableActor = CreateRenderableActor(frameBuffer.GetColorTexture());
1172 renderableActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1173 renderableActor.SetProperty(Actor::Property::SIZE, Vector2(sceneSize.x, sceneSize.y));
1174 renderableActor.ScaleBy(Vector3(1.0f, -1.0f, 1.0f)); // FIXME
1175 scene.Add(renderableActor);
1177 Actor actor = Actor::New();
1178 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1179 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1181 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); // Ensure framebuffer connects
1183 scene.GetRenderTaskList().GetTask(0u).SetScreenToFrameBufferFunction(RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION);
1185 // Create a RenderTask
1186 RenderTask renderTask = scene.GetRenderTaskList().CreateTask();
1187 renderTask.SetSourceActor(actor);
1188 renderTask.SetFrameBuffer(frameBuffer);
1189 renderTask.SetInputEnabled(true);
1191 // Create another RenderTask
1192 RenderTask renderTask2(scene.GetRenderTaskList().CreateTask());
1193 renderTask2.SetInputEnabled(true);
1195 // Render and notify
1196 application.SendNotification();
1197 application.Render();
1199 // Connect to actor's touched signal
1201 TouchEventFunctor functor(data);
1202 actor.TouchedSignal().Connect(&application, functor);
1204 // Emit a down signal
1205 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1206 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1211 int UtcDaliTouchEventMultipleRenderableActors(void)
1213 TestApplication application;
1214 Integration::Scene scene(application.GetScene());
1215 Vector2 sceneSize(scene.GetSize());
1217 Actor parent = CreateRenderableActor();
1218 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1219 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1222 Actor actor = CreateRenderableActor();
1223 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1224 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1227 // Render and notify
1228 application.SendNotification();
1229 application.Render();
1231 // Connect to layer's touched signal
1233 TouchEventFunctor functor(data);
1234 parent.TouchedSignal().Connect(&application, functor);
1235 actor.TouchedSignal().Connect(&application, functor);
1237 // Emit a down signal
1238 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1239 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1240 DALI_TEST_CHECK(actor == data.touchedActor);
1244 int UtcDaliTouchEventActorRemovedInSignal(void)
1246 TestApplication application;
1248 Actor actor = Actor::New();
1249 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1250 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1251 application.GetScene().Add(actor);
1253 // Render and notify
1254 application.SendNotification();
1255 application.Render();
1257 // Connect to actor's touched signal
1259 RemoveActorFunctor functor(data);
1260 actor.TouchedSignal().Connect(&application, functor);
1262 // Register for leave events
1263 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
1265 // Emit a down signal
1266 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1267 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1270 // Re-add, render and notify
1271 application.GetScene().Add(actor);
1272 application.SendNotification();
1273 application.Render();
1275 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1276 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1277 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1280 // Emit a down signal
1281 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1282 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1285 // Render and notify
1286 application.SendNotification();
1287 application.Render();
1289 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1290 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1291 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1294 // Re-add actor back to scene, render and notify
1295 application.GetScene().Add(actor);
1296 application.SendNotification();
1297 application.Render();
1299 // Emit another down event
1300 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1301 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1304 // Completely delete the actor
1307 // Emit event, should not crash and should not receive an event.
1308 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1309 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1313 int UtcDaliTouchEventActorSignalNotConsumed(void)
1315 TestApplication application;
1317 Actor actor = Actor::New();
1318 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1319 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1320 application.GetScene().Add(actor);
1322 // Render and notify
1323 application.SendNotification();
1324 application.Render();
1326 // Connect to actor's touched signal
1328 TouchEventFunctor functor(data, false);
1329 actor.TouchedSignal().Connect(&application, functor);
1331 // Emit a down signal
1332 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1333 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1337 int UtcDaliTouchEventActorRemovedFromScene(void)
1339 TestApplication application;
1341 Actor actor = Actor::New();
1342 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1343 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1344 application.GetScene().Add(actor);
1346 // Render and notify
1347 application.SendNotification();
1348 application.Render();
1350 // Connect to actor's touched signal
1352 TouchEventFunctor functor(data);
1353 actor.TouchedSignal().Connect(&application, functor);
1355 // Emit a down signal
1356 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1357 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1360 // Remove actor from scene
1361 application.GetScene().Remove(actor);
1364 // Render and notify
1365 application.SendNotification();
1366 application.Render();
1368 // Emit a move at the same point, we should not be signalled.
1369 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
1370 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1375 int UtcDaliTouchEventLayerConsumesTouch(void)
1377 TestApplication application;
1379 Actor actor = Actor::New();
1380 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1381 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1382 application.GetScene().Add(actor);
1384 // Render and notify
1385 application.SendNotification();
1386 application.Render();
1388 // Connect to actor's touched signal
1390 TouchEventFunctor functor(data);
1391 actor.TouchedSignal().Connect(&application, functor);
1393 // Add a layer to overlap the actor
1394 Layer layer = Layer::New();
1395 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1396 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1397 application.GetScene().Add(layer);
1400 // Render and notify
1401 application.SendNotification();
1402 application.Render();
1404 // Emit a few touch signals
1405 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1406 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(10.0f, 10.0f)));
1407 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1410 // Set layer to consume all touch
1411 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
1413 // Render and notify
1414 application.SendNotification();
1415 application.Render();
1417 // Emit the same signals again, should not receive
1418 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1419 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(10.0f, 10.0f)));
1420 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1426 int UtcDaliTouchEventLeaveActorReadded(void)
1428 TestApplication application;
1429 Integration::Scene scene = application.GetScene();
1431 Actor actor = Actor::New();
1432 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1433 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1436 // Set actor to receive touch-events
1437 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
1439 // Render and notify
1440 application.SendNotification();
1441 application.Render();
1443 // Connect to actor's touched signal
1445 TouchEventFunctor functor(data);
1446 actor.TouchedSignal().Connect(&application, functor);
1448 // Emit a down and motion
1449 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1450 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(11.0f, 10.0f)));
1451 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1454 // Remove actor from scene and add again
1455 scene.Remove(actor);
1458 // Emit a motion within the actor's bounds
1459 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(12.0f, 10.0f)));
1460 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1463 // Emit a motion outside the actor's bounds
1464 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
1465 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1466 DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
1472 int UtcDaliTouchEventClippedActor(void)
1474 TestApplication application;
1475 Integration::Scene scene = application.GetScene();
1477 Actor actor = Actor::New();
1478 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1479 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1482 Actor clippingActor = Actor::New();
1483 clippingActor.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
1484 clippingActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1485 clippingActor.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN);
1486 scene.Add(clippingActor);
1488 // Add a child to the clipped region.
1489 Actor clippingChild = Actor::New();
1490 clippingChild.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
1491 clippingChild.SetProperty(Actor::Property::POSITION, Vector2(25.0f, 25.0f));
1492 clippingChild.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1493 clippingActor.Add(clippingChild);
1495 // Render and notify.
1496 application.SendNotification();
1497 application.Render();
1499 // Connect to actor's touch signal.
1501 TouchEventFunctor functor(data);
1502 actor.TouchedSignal().Connect(&application, functor);
1504 // Emit an event within clipped area - no hit.
1505 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1506 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1509 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1510 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(60.0f, 60.0f)));
1511 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1514 clippingChild.TouchedSignal().Connect(&application, functor);
1516 // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1517 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(30.0f, 30.0f)));
1518 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1524 int UtcDaliTouchEventActorUnparented(void)
1526 TestApplication application;
1528 Actor actor = Actor::New();
1529 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1530 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1531 application.GetScene().Add(actor);
1533 // Render and notify
1534 application.SendNotification();
1535 application.Render();
1537 // Connect to actor's touched signal
1539 TouchEventFunctor functor(data);
1540 actor.TouchedSignal().Connect(&application, functor);
1542 // Emit a down signal
1543 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1544 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1545 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1546 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1549 // Render and notify
1550 application.SendNotification();
1551 application.Render();
1553 // Unparent the actor
1556 // Should receive an interrupted event
1557 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1558 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1562 int UtcDaliTouchEventParentRemovedFromScene(void)
1564 TestApplication application;
1566 Actor parent = Actor::New();
1567 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1568 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1569 application.GetScene().Add(parent);
1571 Actor actor = Actor::New();
1572 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1573 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1576 // Render and notify
1577 application.SendNotification();
1578 application.Render();
1580 // Connect to actor's touched signal
1582 TouchEventFunctor functor(data);
1583 actor.TouchedSignal().Connect(&application, functor);
1585 // Emit a down signal
1586 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1587 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1588 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1589 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1592 // Render and notify
1593 application.SendNotification();
1594 application.Render();
1596 // Unparent the parent of the touchable actor
1599 // Should receive an interrupted event
1600 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1601 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1605 int UtcDaliTouchEventActorRemovedFromSceneDifferentConsumer(void)
1607 TestApplication application;
1609 Actor parent = Actor::New();
1610 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1611 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1612 application.GetScene().Add(parent);
1614 Actor actor = Actor::New();
1615 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1616 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1619 // Render and notify
1620 application.SendNotification();
1621 application.Render();
1623 // Connect to actor's touched signal
1625 TouchEventFunctor functor(data, false /* Do not consume */);
1626 actor.TouchedSignal().Connect(&application, functor);
1628 // Connect to parent's touched signal
1629 SignalData parentData;
1630 TouchEventFunctor parentFunctor(parentData);
1631 parent.TouchedSignal().Connect(&application, parentFunctor);
1633 // Emit a down signal
1634 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1635 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1636 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1637 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1638 DALI_TEST_CHECK(actor == data.touchedActor);
1639 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1640 DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1641 DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
1642 DALI_TEST_CHECK(parent == parentData.touchedActor);
1646 // Render and notify
1647 application.SendNotification();
1648 application.Render();
1650 // Unparent the actor
1653 // Should receive an interrupted event for both actor & parent
1654 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1655 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1656 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1657 DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1661 // Readd actor to parent
1664 // Render and notify
1665 application.SendNotification();
1666 application.Render();
1668 // Emit a motion signal
1669 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
1670 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1671 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1675 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1676 SignalData secondData;
1677 TouchEventFunctor secondFunctor(secondData /* Consume */);
1678 actor.TouchedSignal().Connect(&application, secondFunctor);
1680 // Unparent the actor
1683 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1684 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1685 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1686 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1687 DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1688 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1689 DALI_TEST_EQUALS(PointState::INTERRUPTED, secondData.receivedTouch.points[0].state, TEST_LOCATION);
1697 int UtcDaliTouchEventInterruptedDifferentConsumer(void)
1699 TestApplication application;
1700 Actor rootActor(application.GetScene().GetRootLayer());
1702 Actor parent = Actor::New();
1703 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1704 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1705 application.GetScene().Add(parent);
1707 Actor actor = Actor::New();
1708 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1709 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1712 // Render and notify
1713 application.SendNotification();
1714 application.Render();
1716 // Connect to actor's touched signal
1718 TouchEventFunctor functor(data, false /* Do not consume */);
1719 actor.TouchedSignal().Connect(&application, functor);
1721 // Connect to parent's touched signal
1722 SignalData parentData;
1723 TouchEventFunctor parentFunctor(parentData, false /* Do not consume */);
1724 parent.TouchedSignal().Connect(&application, parentFunctor);
1726 // Connect to root's touched signal and consume
1727 SignalData rootData;
1728 TouchEventFunctor rootFunctor(rootData);
1729 rootActor.TouchedSignal().Connect(&application, rootFunctor);
1731 // Emit a down signal
1732 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1733 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1734 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1735 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1736 DALI_TEST_CHECK(actor == data.touchedActor);
1737 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1738 DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1739 DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
1740 DALI_TEST_CHECK(parent == parentData.touchedActor);
1741 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
1742 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
1743 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
1744 DALI_TEST_CHECK(rootActor == rootData.touchedActor);
1749 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1750 SignalData secondData;
1751 TouchEventFunctor secondFunctor(secondData /* Consume */);
1752 parent.TouchedSignal().Connect(&application, secondFunctor);
1754 // Emit an interrupted signal, all three should STILL be called
1755 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(10.0f, 10.0f)));
1756 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1757 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1758 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1759 DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1760 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
1761 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
1769 int UtcDaliTouchEventGetRadius(void)
1771 TestApplication application;
1773 Actor actor = Actor::New();
1774 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1775 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1776 application.GetScene().Add(actor);
1778 // Render and notify
1779 application.SendNotification();
1780 application.Render();
1782 // Connect to actor's touched signal
1784 TouchEventFunctor functor(data);
1785 actor.TouchedSignal().Connect(&application, functor);
1787 // Emit a down signal with an angle
1788 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1789 touchEvent.points[0].SetRadius(100.0f);
1790 application.ProcessEvent(touchEvent);
1791 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1792 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1793 DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].radius, TEST_LOCATION);
1794 DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].ellipseRadius.x, TEST_LOCATION);
1795 DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].ellipseRadius.y, TEST_LOCATION);
1800 int UtcDaliTouchEventGetEllipseRadius(void)
1802 TestApplication application;
1804 Actor actor = Actor::New();
1805 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1806 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1807 application.GetScene().Add(actor);
1809 // Render and notify
1810 application.SendNotification();
1811 application.Render();
1813 // Connect to actor's touched signal
1815 TouchEventFunctor functor(data);
1816 actor.TouchedSignal().Connect(&application, functor);
1818 // Emit a down signal with an angle
1819 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1820 touchEvent.points[0].SetRadius(100.0f, Vector2(20.0f, 10.0f));
1821 application.ProcessEvent(touchEvent);
1822 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1823 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1824 DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].radius, TEST_LOCATION);
1825 DALI_TEST_EQUALS(20.0f, data.receivedTouch.points[0].ellipseRadius.x, TEST_LOCATION);
1826 DALI_TEST_EQUALS(10.0f, data.receivedTouch.points[0].ellipseRadius.y, TEST_LOCATION);
1831 int UtcDaliTouchEventGetAngle(void)
1833 TestApplication application;
1835 Actor actor = Actor::New();
1836 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1837 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1838 application.GetScene().Add(actor);
1840 // Render and notify
1841 application.SendNotification();
1842 application.Render();
1844 // Connect to actor's touched signal
1846 TouchEventFunctor functor(data);
1847 actor.TouchedSignal().Connect(&application, functor);
1849 // Emit a down signal with an angle
1850 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1851 touchEvent.points[0].SetAngle(Degree(90.0f));
1852 application.ProcessEvent(touchEvent);
1853 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1854 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1855 DALI_TEST_EQUALS(Degree(90.0f), data.receivedTouch.points[0].angle, TEST_LOCATION);
1860 int UtcDaliTouchEventGetPressure(void)
1862 TestApplication application;
1864 Actor actor = Actor::New();
1865 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1866 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1867 application.GetScene().Add(actor);
1869 // Render and notify
1870 application.SendNotification();
1871 application.Render();
1873 // Connect to actor's touched signal
1875 TouchEventFunctor functor(data);
1876 actor.TouchedSignal().Connect(&application, functor);
1878 // Emit a down signal with an angle
1879 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1880 touchEvent.points[0].SetPressure(10.0f);
1881 application.ProcessEvent(touchEvent);
1882 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1883 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1884 DALI_TEST_EQUALS(10.0f, data.receivedTouch.points[0].pressure, TEST_LOCATION);
1889 int UtcDaliTouchEventUsage(void)
1891 TestApplication application;
1893 Actor actor = Actor::New();
1894 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1895 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1896 application.GetScene().Add(actor);
1898 // Render and notify
1899 application.SendNotification();
1900 application.Render();
1902 // Connect to actor's touched signal
1904 TouchEventFunctor functor(data);
1905 actor.TouchedSignal().Connect(&application, functor);
1907 // Emit a down signal with an angle
1908 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1909 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1914 int UtcDaliTouchEventGetDeviceAPINegative(void)
1916 TestApplication application;
1918 Actor actor = Actor::New();
1919 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1920 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1921 application.GetScene().Add(actor);
1923 // Render and notify
1924 application.SendNotification();
1925 application.Render();
1927 // Connect to actor's touched signal
1928 HandleData handleData;
1929 TouchEventHandleFunctor functor(handleData);
1930 actor.TouchedSignal().Connect(&application, functor);
1932 Vector2 screenCoordinates(10.0f, 10.0f);
1933 Vector2 localCoordinates;
1934 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
1936 // Emit a down signal
1937 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
1939 TouchEvent data = handleData.receivedTouchHandle;
1940 DALI_TEST_EQUALS(data.GetDeviceClass(-1), Device::Class::NONE, TEST_LOCATION);
1941 DALI_TEST_EQUALS(data.GetDeviceSubclass(-1), Device::Subclass::NONE, TEST_LOCATION);
1945 int UtcDaliTouchEventGetMouseButtonPositive(void)
1947 TestApplication application;
1949 Actor actor = Actor::New();
1950 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1951 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1952 application.GetScene().Add(actor);
1954 // Render and notify
1955 application.SendNotification();
1956 application.Render();
1958 // Connect to actor's touched signal
1959 HandleData handleData;
1960 TouchEventHandleFunctor functor(handleData);
1961 actor.TouchedSignal().Connect(&application, functor);
1963 // Emit a down signal with MouseButton
1964 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1965 touchEvent.points[0].SetMouseButton(static_cast<MouseButton::Type>(3));
1966 application.ProcessEvent(touchEvent);
1968 TouchEvent data = handleData.receivedTouchHandle;
1969 DALI_TEST_EQUALS(data.GetMouseButton(0), MouseButton::SECONDARY, TEST_LOCATION);
1974 int UtcDaliTouchEventGetMouseButtonNagative(void)
1976 TestApplication application;
1978 Actor actor = Actor::New();
1979 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1980 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1981 application.GetScene().Add(actor);
1983 // Render and notify
1984 application.SendNotification();
1985 application.Render();
1987 // Connect to actor's touched signal
1988 HandleData handleData;
1989 TouchEventHandleFunctor functor(handleData);
1990 actor.TouchedSignal().Connect(&application, functor);
1992 // Emit a down signal with MouseButton
1993 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1994 touchEvent.points[0].SetMouseButton(static_cast<MouseButton::Type>(2));
1995 application.ProcessEvent(touchEvent);
1997 TouchEvent data = handleData.receivedTouchHandle;
1998 DALI_TEST_EQUALS(data.GetMouseButton(0), MouseButton::TERTIARY, TEST_LOCATION);
1999 DALI_TEST_EQUALS(data.GetMouseButton(3), MouseButton::INVALID, TEST_LOCATION);
2004 int UtcDaliTouchEventCapturePropertySet(void)
2006 TestApplication application;
2008 Actor actor = Actor::New();
2009 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2010 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2011 application.GetScene().Add(actor);
2013 // Render and notify
2014 application.SendNotification();
2015 application.Render();
2017 // Connect to actor's touched signal
2019 TouchEventFunctor functor(data);
2020 actor.TouchedSignal().Connect(&application, functor);
2022 // Emit a down signal
2023 application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(10.0f, 10.0f)));
2024 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2027 // Now motion outside of actor, we should not receive the event
2028 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(110.0f, 110.0f)));
2029 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2032 // Up event, should receive an interrupted
2033 application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2034 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2035 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::INTERRUPTED, TEST_LOCATION);
2037 // Now set the capture property
2038 actor.SetProperty(DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START, true);
2040 // Emit a down signal
2041 application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(10.0f, 10.0f)));
2042 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2045 // Now motion outside of actor, we now SHOULD receive the event
2046 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(110.0f, 110.0f)));
2047 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2050 // Up event, we should receive it again, but as ended rather than interrupted
2051 application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2052 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2053 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::FINISHED, TEST_LOCATION);
2058 int UtcDaliTouchEventIntegNewTouchEvent(void)
2060 uint32_t timestamp = 92858u;
2061 TouchPoint tp(1, PointState::STARTED, 34.4f, 123.89f, 5.0f, 7.0f);
2062 Dali::TouchEvent touchEvent = Integration::NewTouchEvent(timestamp, tp);
2064 DALI_TEST_EQUALS(touchEvent.GetPointCount(), 1u, TEST_LOCATION);
2065 DALI_TEST_EQUALS(touchEvent.GetState(0), PointState::STARTED, TEST_LOCATION);
2066 DALI_TEST_EQUALS(touchEvent.GetLocalPosition(0), Vector2(5.0f, 7.0f), TEST_LOCATION);
2067 DALI_TEST_EQUALS(touchEvent.GetScreenPosition(0), Vector2(34.4f, 123.89f), TEST_LOCATION);
2073 int UtcDaliTouchEventIntercept(void)
2075 TestApplication application;
2077 Actor parent = Actor::New();
2078 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2079 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2080 application.GetScene().Add(parent);
2082 Actor actor = Actor::New();
2083 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2084 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2087 // Render and notify
2088 application.SendNotification();
2089 application.Render();
2091 // Connect to actor's touched signal
2093 TouchEventFunctor functor(data, false /* Do not consume */);
2094 actor.TouchedSignal().Connect(&application, functor);
2097 // Connect to parent's touched signal
2098 SignalData parentData;
2099 TouchEventFunctor parentFunctor(parentData, false /* Do not consume */);
2100 parent.TouchedSignal().Connect(&application, parentFunctor);
2101 // Connect to parent's intercept touched signal
2102 SignalData interceptData;
2103 TouchEventFunctor interceptFunctor(interceptData, true /* Do intercept */);
2104 Dali::DevelActor::InterceptTouchedSignal(parent).Connect(&application, interceptFunctor);
2106 // Emit a down signal
2107 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
2108 // The actor touched signal is not called because the touch is intercepted in the parent.
2109 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2110 DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION);
2111 DALI_TEST_EQUALS(PointState::DOWN, interceptData.receivedTouch.points[0].state, TEST_LOCATION);
2112 DALI_TEST_CHECK(actor == interceptData.receivedTouch.points[0].hitActor);
2113 DALI_TEST_CHECK(parent == interceptData.touchedActor);
2114 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
2115 DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
2116 DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
2117 DALI_TEST_CHECK(parent == parentData.touchedActor);
2124 int UtcDaliTouchArea(void)
2126 TestApplication application;
2128 Actor actor = Actor::New();
2129 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2130 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2132 application.GetScene().Add(actor);
2134 // Render and notify
2135 application.SendNotification();
2136 application.Render();
2138 // Connect to actor's touched signal
2140 TouchEventFunctor functor(data, false /* Do not consume */);
2141 actor.TouchedSignal().Connect(&application, functor);
2143 // Emit a down signal
2144 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(110.0f, 110.0f)));
2145 // The actor touched signal is not called because the touch area is outside actor.
2146 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2149 // set a bigger touch area
2150 actor.SetProperty(DevelActor::Property::TOUCH_AREA, Vector2(200.0f, 200.0f));
2152 // Render and notify
2153 application.SendNotification();
2154 application.Render();
2156 // Emit a down signal
2157 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(110.0f, 110.0f)));
2158 // The actor touched signal is called because the touch area is inside touchArea.
2159 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2160 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2161 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2164 // set a smaller touch area
2165 actor.SetProperty(DevelActor::Property::TOUCH_AREA, Vector2(50.0f, 50.0f));
2167 // Render and notify
2168 application.SendNotification();
2169 application.Render();
2171 // Emit a down signal
2172 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(80.0f, 80.0f)));
2173 // The actor touched signal is not called because the touch area is outside touchArea.
2174 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2177 // Emit a down signal
2178 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(30.0f, 30.0f)));
2179 // The actor touched signal is called because the touch area is inside touchArea.
2180 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2181 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2182 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);