2 * Copyright (c) 2022 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);
270 Integration::TouchEvent GenerateDoubleTouch(PointState::Type stateA, const Vector2& screenPositionA, PointState::Type stateB, const Vector2& screenPositionB, uint32_t time)
272 Integration::TouchEvent touchEvent;
273 Integration::Point point;
274 point.SetState(stateA);
275 point.SetDeviceId(4);
276 point.SetScreenPosition(screenPositionA);
277 point.SetDeviceClass(Device::Class::TOUCH);
278 point.SetDeviceSubclass(Device::Subclass::NONE);
279 touchEvent.points.push_back(point);
280 point.SetScreenPosition(screenPositionB);
281 point.SetState(stateB);
282 point.SetDeviceId(7);
283 point.SetDeviceClass(Device::Class::TOUCH);
284 point.SetDeviceSubclass(Device::Subclass::NONE);
285 touchEvent.points.push_back(point);
286 touchEvent.time = time;
292 ///////////////////////////////////////////////////////////////////////////////
294 int UtcDaliTouchEventNormalProcessing01(void)
296 TestApplication application;
298 Actor actor = Actor::New();
299 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
300 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
301 application.GetScene().Add(actor);
304 application.SendNotification();
305 application.Render();
307 // Connect to actor's touch signal
309 TouchEventFunctor functor(data);
310 actor.TouchedSignal().Connect(&application, functor);
312 Vector2 screenCoordinates(10.0f, 10.0f);
313 Vector2 localCoordinates;
314 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
316 // Emit a down signal
317 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
318 const TestPoint* point1 = &data.receivedTouch.GetPoint(0);
319 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
320 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
321 DALI_TEST_EQUALS(PointState::DOWN, point1->state, TEST_LOCATION);
322 DALI_TEST_EQUALS(screenCoordinates, point1->screen, TEST_LOCATION);
323 DALI_TEST_EQUALS(localCoordinates, point1->local, 0.1f, TEST_LOCATION);
326 // Emit a motion signal
327 screenCoordinates.x = screenCoordinates.y = 11.0f;
328 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
329 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, screenCoordinates));
330 const TestPoint* point2 = &data.receivedTouch.GetPoint(0);
331 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
332 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
333 DALI_TEST_EQUALS(PointState::MOTION, point2->state, TEST_LOCATION);
334 DALI_TEST_EQUALS(screenCoordinates, point2->screen, TEST_LOCATION);
335 DALI_TEST_EQUALS(localCoordinates, point2->local, 0.1f, TEST_LOCATION);
339 screenCoordinates.x = screenCoordinates.y = 12.0f;
340 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
341 application.ProcessEvent(GenerateSingleTouch(PointState::UP, screenCoordinates));
342 const TestPoint* point3 = &data.receivedTouch.GetPoint(0);
343 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
344 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
345 DALI_TEST_EQUALS(PointState::UP, point3->state, TEST_LOCATION);
346 DALI_TEST_EQUALS(screenCoordinates, point3->screen, TEST_LOCATION);
347 DALI_TEST_EQUALS(localCoordinates, point3->local, 0.1f, TEST_LOCATION);
350 // Emit a down signal where the actor is not present
351 screenCoordinates.x = screenCoordinates.y = 200.0f;
352 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
353 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
357 int UtcDaliTouchEventNormalProcessing02(void)
359 TestApplication application;
361 Actor actor = Actor::New();
362 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
363 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
364 application.GetScene().Add(actor);
367 application.SendNotification();
368 application.Render();
370 // Connect to actor's touched signal
371 HandleData handleData;
372 TouchEventHandleFunctor functor(handleData);
373 actor.TouchedSignal().Connect(&application, functor);
375 Vector2 screenCoordinates(10.0f, 10.0f);
376 Vector2 localCoordinates;
377 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
379 // Emit a down signal
380 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
381 DALI_TEST_EQUALS(true, handleData.signalReceived, TEST_LOCATION);
382 DALI_TEST_EQUALS(1u, handleData.receivedTouchHandle.GetPointCount(), TEST_LOCATION);
383 DALI_TEST_EQUALS(PointState::DOWN, handleData.receivedTouchHandle.GetState(0), TEST_LOCATION);
384 DALI_TEST_EQUALS(screenCoordinates, handleData.receivedTouchHandle.GetScreenPosition(0), TEST_LOCATION);
385 DALI_TEST_EQUALS(localCoordinates, handleData.receivedTouchHandle.GetLocalPosition(0), 0.1f, TEST_LOCATION);
390 int UtcDaliTouchEventAPINegative(void)
392 TestApplication application;
394 Actor actor = Actor::New();
395 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
396 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
397 application.GetScene().Add(actor);
400 application.SendNotification();
401 application.Render();
403 // Connect to actor's touched signal
404 OutOfBoundsData data;
405 OutOfBoundsFunctor functor(data, true);
406 actor.TouchedSignal().Connect(&application, functor);
408 Vector2 screenCoordinates(10.0f, 10.0f);
409 Vector2 localCoordinates;
410 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
412 // Emit a down signal
413 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
415 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
416 DALI_TEST_EQUALS(-1, data.point.deviceId, TEST_LOCATION);
417 DALI_TEST_EQUALS(PointState::FINISHED, data.point.state, TEST_LOCATION);
418 DALI_TEST_EQUALS(Vector2::ZERO, data.point.screen, TEST_LOCATION);
419 DALI_TEST_EQUALS(Vector2::ZERO, data.point.local, 0.1f, TEST_LOCATION);
420 DALI_TEST_CHECK(!data.point.hitActor);
425 int UtcDaliTouchEventOutsideCameraNearFarPlanes(void)
427 TestApplication application;
429 Integration::Scene scene = application.GetScene();
430 Vector2 sceneSize = scene.GetSize();
432 Actor actor = Actor::New();
433 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
434 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
435 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
439 application.SendNotification();
440 application.Render();
442 // Get the camera's near and far planes
443 RenderTaskList taskList = scene.GetRenderTaskList();
444 Dali::RenderTask task = taskList.GetTask(0);
445 CameraActor camera = task.GetCameraActor();
446 float nearPlane = camera.GetNearClippingPlane();
447 float farPlane = camera.GetFarClippingPlane();
449 // Calculate the current distance of the actor from the camera
450 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
451 float distance = (sceneSize.y * 0.5f) / tanHalfFov;
453 // Connect to actor's touched signal
455 TouchEventFunctor functor(data);
456 actor.TouchedSignal().Connect(&application, functor);
458 Vector2 screenCoordinates(sceneSize.x * 0.5f, sceneSize.y * 0.5f);
460 // Emit a down signal
461 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
462 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
465 // Emit a down signal where actor is just at the camera's near plane
466 actor.SetProperty(Actor::Property::POSITION_Z, distance - nearPlane);
469 application.SendNotification();
470 application.Render();
472 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
473 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
476 // Emit a down signal where actor is closer than the camera's near plane
477 actor.SetProperty(Actor::Property::POSITION_Z, (distance - nearPlane) + 1.0f);
480 application.SendNotification();
481 application.Render();
483 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
484 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
487 // Emit a down signal where actor is just at the camera's far plane
488 actor.SetProperty(Actor::Property::POSITION_Z, distance - farPlane);
491 application.SendNotification();
492 application.Render();
494 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
495 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
498 // Emit a down signal where actor is further than the camera's far plane
499 actor.SetProperty(Actor::Property::POSITION_Z, (distance - farPlane) - 1.0f);
502 application.SendNotification();
503 application.Render();
505 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
506 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
511 int UtcDaliTouchEventEmitEmpty(void)
513 TestApplication application;
517 // Emit an empty TouchEvent
518 Integration::TouchEvent event;
519 application.ProcessEvent(event);
520 tet_result(TET_FAIL);
522 catch(Dali::DaliException& e)
524 DALI_TEST_ASSERT(e, "!event.points.empty()", TEST_LOCATION);
529 int UtcDaliTouchEventInterrupted(void)
531 TestApplication application;
533 Actor actor = Actor::New();
534 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
535 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
536 application.GetScene().Add(actor);
539 application.SendNotification();
540 application.Render();
542 // Connect to actor's touched signal
544 TouchEventFunctor functor(data);
545 actor.TouchedSignal().Connect(&application, functor);
547 // Emit a down signal
548 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
549 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
550 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
553 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
554 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f /* Outside actor */)));
555 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
556 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
559 // Emit another interrupted signal, our signal handler should not be called.
560 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
561 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
565 int UtcDaliTouchEventParentConsumer(void)
567 TestApplication application;
568 Actor rootActor(application.GetScene().GetRootLayer());
570 Actor actor = Actor::New();
571 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
572 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
573 application.GetScene().Add(actor);
576 application.SendNotification();
577 application.Render();
579 // Connect to actor's touched signal
581 TouchEventFunctor functor(data, false);
582 actor.TouchedSignal().Connect(&application, functor);
584 // Connect to root actor's touched signal
586 TouchEventFunctor rootFunctor(rootData); // Consumes signal
587 rootActor.TouchedSignal().Connect(&application, rootFunctor);
589 Vector2 screenCoordinates(10.0f, 10.0f);
590 Vector2 actorCoordinates, rootCoordinates;
591 actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
592 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
594 // Emit a down signal
595 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, 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::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
601 DALI_TEST_EQUALS(PointState::DOWN, 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);
611 // Emit a motion signal
612 screenCoordinates.x = screenCoordinates.y = 11.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::MOTION, 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::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
621 DALI_TEST_EQUALS(PointState::MOTION, 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);
632 screenCoordinates.x = screenCoordinates.y = 12.0f;
633 actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
634 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
635 application.ProcessEvent(GenerateSingleTouch(PointState::UP, screenCoordinates));
636 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
637 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
638 DALI_TEST_EQUALS(1u, data.receivedTouch.GetPointCount(), TEST_LOCATION);
639 DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
640 DALI_TEST_EQUALS(PointState::UP, data.receivedTouch.points[0].state, TEST_LOCATION);
641 DALI_TEST_EQUALS(PointState::UP, rootData.receivedTouch.points[0].state, TEST_LOCATION);
642 DALI_TEST_EQUALS(screenCoordinates, data.receivedTouch.points[0].screen, TEST_LOCATION);
643 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
644 DALI_TEST_EQUALS(actorCoordinates, data.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
645 DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
646 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
647 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
651 // Emit a down signal where the actor is not present, will hit the root actor though
652 screenCoordinates.x = screenCoordinates.y = 200.0f;
653 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
654 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
655 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
656 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
657 DALI_TEST_EQUALS(1u, rootData.receivedTouch.GetPointCount(), TEST_LOCATION);
658 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
659 DALI_TEST_EQUALS(screenCoordinates, rootData.receivedTouch.points[0].screen, TEST_LOCATION);
660 DALI_TEST_EQUALS(rootCoordinates, rootData.receivedTouch.points[0].local, 0.1f, TEST_LOCATION);
661 DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
665 int UtcDaliTouchEventInterruptedParentConsumer(void)
667 TestApplication application;
668 Actor rootActor(application.GetScene().GetRootLayer());
670 Actor actor = Actor::New();
671 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
672 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
673 application.GetScene().Add(actor);
676 application.SendNotification();
677 application.Render();
679 // Connect to actor's touched signal
681 TouchEventFunctor functor(data, false);
682 actor.TouchedSignal().Connect(&application, functor);
684 // Connect to root actor's touched signal
686 TouchEventFunctor rootFunctor(rootData); // Consumes signal
687 rootActor.TouchedSignal().Connect(&application, rootFunctor);
689 // Emit a down signal
690 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
691 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
692 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
693 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
694 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
695 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
696 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
700 // Emit an interrupted signal
701 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
702 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
703 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
704 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
705 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
706 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
707 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
711 // Emit another down signal
712 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
713 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
714 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
715 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
716 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
720 // Remove actor from scene
721 application.GetScene().Remove(actor);
726 application.SendNotification();
727 application.Render();
729 // Emit an interrupted signal, only root actor's signal should be called.
730 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f /* Outside actor */)));
731 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
732 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
733 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
734 DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
738 // Emit another interrupted state, none of the signal's should be called.
739 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
740 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
741 DALI_TEST_EQUALS(false, rootData.functorCalled, TEST_LOCATION);
745 int UtcDaliTouchEventLeave(void)
747 TestApplication application;
749 Actor actor = Actor::New();
750 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
751 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
752 application.GetScene().Add(actor);
755 application.SendNotification();
756 application.Render();
758 // Connect to actor's touched signal
760 TouchEventFunctor functor(data);
761 actor.TouchedSignal().Connect(&application, functor);
763 // Set actor to require leave events
764 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
766 // Emit a down signal
767 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
768 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
769 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
772 // Emit a motion signal outside of actor, should be signalled with a Leave
773 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
774 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
775 DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
778 // Another motion outside of actor, no signalling
779 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(201.0f, 201.0f)));
780 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
783 // Another motion event inside actor, signalled with motion
784 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
785 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
786 DALI_TEST_EQUALS(PointState::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
789 // We do not want to listen to leave events anymore
790 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, false);
792 // Another motion event outside of actor, no signalling
793 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
794 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
799 int UtcDaliTouchEventLeaveParentConsumer(void)
801 TestApplication application;
802 Actor rootActor(application.GetScene().GetRootLayer());
804 Actor actor = Actor::New();
805 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
806 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
807 application.GetScene().Add(actor);
810 application.SendNotification();
811 application.Render();
813 // Connect to actor's touched signal
815 TouchEventFunctor functor(data, false);
816 actor.TouchedSignal().Connect(&application, functor);
818 // Connect to root actor's touched signal
820 TouchEventFunctor rootFunctor(rootData); // Consumes signal
821 rootActor.TouchedSignal().Connect(&application, rootFunctor);
823 // Set actor to require leave events
824 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
825 rootActor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
827 // Emit a down signal
828 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
829 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
830 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
831 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
832 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
833 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
834 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
838 // Emit a motion signal outside of actor, should be signalled with a Leave
839 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
840 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
841 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
842 DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
843 DALI_TEST_EQUALS(PointState::LEAVE, 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 // Another motion outside of actor, only rootActor signalled
850 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(201.0f, 201.0f)));
851 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
852 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
853 DALI_TEST_EQUALS(PointState::MOTION, rootData.receivedTouch.points[0].state, TEST_LOCATION);
854 DALI_TEST_CHECK(rootActor == rootData.receivedTouch.points[0].hitActor);
858 // Another motion event inside actor, signalled with motion
859 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
860 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
861 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
862 DALI_TEST_EQUALS(PointState::MOTION, data.receivedTouch.points[0].state, TEST_LOCATION);
863 DALI_TEST_EQUALS(PointState::MOTION, rootData.receivedTouch.points[0].state, TEST_LOCATION);
864 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
865 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
869 // We do not want to listen to leave events of actor anymore
870 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, false);
872 // Another motion event outside of root actor, only root signalled
873 Vector2 sceneSize(application.GetScene().GetSize());
874 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(sceneSize.width + 10.0f, sceneSize.height + 10.0f)));
875 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
876 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
877 DALI_TEST_EQUALS(PointState::LEAVE, rootData.receivedTouch.points[0].state, TEST_LOCATION);
881 int UtcDaliTouchEventActorBecomesInsensitive(void)
883 TestApplication application;
885 Actor actor = Actor::New();
886 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
887 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
888 application.GetScene().Add(actor);
891 application.SendNotification();
892 application.Render();
894 // Connect to actor's touched signal
896 TouchEventFunctor functor(data);
897 actor.TouchedSignal().Connect(&application, functor);
899 // Emit a down signal
900 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
901 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
902 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
905 // Change actor to insensitive
906 actor.SetProperty(Actor::Property::SENSITIVE, false);
908 // Emit a motion signal, signalled with an interrupted
909 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
910 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
911 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
916 int UtcDaliTouchEventActorBecomesInsensitiveParentConsumer(void)
918 TestApplication application;
919 Actor rootActor(application.GetScene().GetRootLayer());
921 Actor actor = Actor::New();
922 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
923 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
924 application.GetScene().Add(actor);
927 application.SendNotification();
928 application.Render();
930 // Connect to actor's touched signal
932 TouchEventFunctor functor(data, false);
933 actor.TouchedSignal().Connect(&application, functor);
935 // Connect to root actor's touched signal
937 TouchEventFunctor rootFunctor(rootData); // Consumes signal
938 rootActor.TouchedSignal().Connect(&application, rootFunctor);
940 // Emit a down signal
941 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
942 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
943 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
944 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
945 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
946 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
947 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
952 application.SendNotification();
953 application.Render();
955 // Make root actor insensitive
956 rootActor.SetProperty(Actor::Property::SENSITIVE, false);
958 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
959 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
960 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
961 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
962 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
963 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
967 int UtcDaliTouchEventActorBecomesUserInteractionDisabled(void)
969 TestApplication application;
971 Actor actor = Actor::New();
972 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
973 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
974 application.GetScene().Add(actor);
977 application.SendNotification();
978 application.Render();
980 // Connect to actor's touched signal
982 TouchEventFunctor functor(data);
983 actor.TouchedSignal().Connect(&application, functor);
985 // Emit a down signal
986 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
987 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
988 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
991 // Change actor to disable user interaction.
992 actor.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false);
994 // Emit a motion signal, signalled with an interrupted
995 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
996 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
997 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1002 int UtcDaliTouchEventMultipleLayers(void)
1004 TestApplication application;
1005 Actor rootActor(application.GetScene().GetRootLayer());
1007 // Connect to actor's touched signal
1009 TouchEventFunctor functor(data);
1011 Layer layer1(Layer::New());
1012 layer1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1013 layer1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1014 application.GetScene().Add(layer1);
1016 Actor actor1(Actor::New());
1017 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1018 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1019 actor1.SetProperty(Actor::Property::POSITION_Z, 1.0f); // Should hit actor1 in this layer
1022 // Render and notify
1023 application.SendNotification();
1024 application.Render();
1026 // Connect to layer1 and actor1
1027 layer1.TouchedSignal().Connect(&application, functor);
1028 actor1.TouchedSignal().Connect(&application, functor);
1030 // Hit in hittable area, actor1 should be hit
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 layer1 insensitive, nothing should be hit
1037 layer1.SetProperty(Actor::Property::SENSITIVE, false);
1038 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1039 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1042 // Make layer1 sensitive again, again actor1 will be hit
1043 layer1.SetProperty(Actor::Property::SENSITIVE, true);
1044 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1045 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1046 DALI_TEST_CHECK(data.touchedActor == actor1);
1049 // Make rootActor insensitive, nothing should be hit
1050 rootActor.SetProperty(Actor::Property::SENSITIVE, false);
1051 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1052 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1055 // Make rootActor sensitive
1056 rootActor.SetProperty(Actor::Property::SENSITIVE, true);
1058 // Add another layer
1059 Layer layer2(Layer::New());
1060 layer2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1061 layer2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1062 layer2.SetProperty(Actor::Property::POSITION_Z, 10.0f); // Should hit layer2 in this layer rather than actor2
1063 application.GetScene().Add(layer2);
1065 Actor actor2(Actor::New());
1066 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1067 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1070 // Render and notify
1071 application.SendNotification();
1072 application.Render();
1074 // Connect to layer2 and actor2
1075 layer2.TouchedSignal().Connect(&application, functor);
1076 actor2.TouchedSignal().Connect(&application, functor);
1078 // Emit an event, should hit layer2
1079 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1080 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1081 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1084 // Make layer2 insensitive, should hit actor1
1085 layer2.SetProperty(Actor::Property::SENSITIVE, false);
1086 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1087 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1088 DALI_TEST_CHECK(data.touchedActor == actor1);
1091 // Make layer2 sensitive again, should hit layer2
1092 layer2.SetProperty(Actor::Property::SENSITIVE, true);
1093 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1094 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1095 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1098 // Make layer2 invisible, render and notify
1099 layer2.SetProperty(Actor::Property::VISIBLE, false);
1100 application.SendNotification();
1101 application.Render();
1103 // Should hit actor1
1104 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1105 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1106 DALI_TEST_CHECK(data.touchedActor == actor1);
1109 // Make rootActor invisible, render and notify
1110 rootActor.SetProperty(Actor::Property::VISIBLE, false);
1111 application.SendNotification();
1112 application.Render();
1114 // Should not hit anything
1115 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1116 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1121 int UtcDaliTouchEventMultipleRenderTasks(void)
1123 TestApplication application;
1124 Integration::Scene scene(application.GetScene());
1125 Vector2 sceneSize(scene.GetSize());
1127 Actor actor = Actor::New();
1128 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1129 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1132 // Create render task
1133 Viewport viewport(sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f);
1134 RenderTask renderTask(application.GetScene().GetRenderTaskList().CreateTask());
1135 renderTask.SetViewport(viewport);
1136 renderTask.SetInputEnabled(true);
1138 // Render and notify
1139 application.SendNotification();
1140 application.Render();
1142 // Connect to actor's touched signal
1144 TouchEventFunctor functor(data);
1145 actor.TouchedSignal().Connect(&application, functor);
1147 // Emit a down signal
1148 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1149 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1152 // Ensure renderTask actor can be hit too.
1153 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1154 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1157 // Disable input on renderTask, should not be hittable
1158 renderTask.SetInputEnabled(false);
1159 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1160 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1165 int UtcDaliTouchEventMultipleRenderTasksWithChildLayer(void)
1167 TestApplication application;
1168 Integration::Scene scene(application.GetScene());
1169 Vector2 sceneSize(scene.GetSize());
1171 Actor actor = Actor::New();
1172 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1173 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1176 Layer layer = Layer::New();
1177 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1178 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1181 // Create render task
1182 Viewport viewport(sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f);
1183 RenderTask renderTask(application.GetScene().GetRenderTaskList().CreateTask());
1184 renderTask.SetViewport(viewport);
1185 renderTask.SetInputEnabled(true);
1186 renderTask.SetSourceActor(actor);
1188 // Render and notify
1189 application.SendNotification();
1190 application.Render();
1192 // Connect to layer's touched signal
1194 TouchEventFunctor functor(data);
1195 actor.TouchedSignal().Connect(&application, functor);
1196 layer.TouchedSignal().Connect(&application, functor);
1198 // Emit a down signal
1199 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1200 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1203 // Ensure renderTask actor can be hit too.
1204 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1205 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1208 // Disable input on renderTask, should not be hittable
1209 renderTask.SetInputEnabled(false);
1210 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
1211 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1216 int UtcDaliTouchEventOffscreenRenderTasks(void)
1218 TestApplication application;
1219 Integration::Scene scene(application.GetScene());
1220 Vector2 sceneSize(scene.GetSize());
1222 // FrameBufferImage for offscreen RenderTask
1223 FrameBuffer frameBuffer = FrameBuffer::New(sceneSize.width, sceneSize.height);
1225 // Create a renderable actor to display the FrameBufferImage
1226 Actor renderableActor = CreateRenderableActor(frameBuffer.GetColorTexture());
1227 renderableActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1228 renderableActor.SetProperty(Actor::Property::SIZE, Vector2(sceneSize.x, sceneSize.y));
1229 renderableActor.ScaleBy(Vector3(1.0f, -1.0f, 1.0f)); // FIXME
1230 scene.Add(renderableActor);
1232 Actor actor = Actor::New();
1233 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1234 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1236 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); // Ensure framebuffer connects
1238 scene.GetRenderTaskList().GetTask(0u).SetScreenToFrameBufferFunction(RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION);
1240 // Create a RenderTask
1241 RenderTask renderTask = scene.GetRenderTaskList().CreateTask();
1242 renderTask.SetSourceActor(actor);
1243 renderTask.SetFrameBuffer(frameBuffer);
1244 renderTask.SetInputEnabled(true);
1246 // Create another RenderTask
1247 RenderTask renderTask2(scene.GetRenderTaskList().CreateTask());
1248 renderTask2.SetInputEnabled(true);
1250 // Render and notify
1251 application.SendNotification();
1252 application.Render();
1254 // Connect to actor's touched signal
1256 TouchEventFunctor functor(data);
1257 actor.TouchedSignal().Connect(&application, functor);
1259 // Emit a down signal
1260 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1261 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1266 int UtcDaliTouchEventMultipleRenderableActors(void)
1268 TestApplication application;
1269 Integration::Scene scene(application.GetScene());
1270 Vector2 sceneSize(scene.GetSize());
1272 Actor parent = CreateRenderableActor();
1273 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1274 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1277 Actor actor = CreateRenderableActor();
1278 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1279 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1282 // Render and notify
1283 application.SendNotification();
1284 application.Render();
1286 // Connect to layer's touched signal
1288 TouchEventFunctor functor(data);
1289 parent.TouchedSignal().Connect(&application, functor);
1290 actor.TouchedSignal().Connect(&application, functor);
1292 // Emit a down signal
1293 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1294 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1295 DALI_TEST_CHECK(actor == data.touchedActor);
1299 int UtcDaliTouchEventActorRemovedInSignal(void)
1301 TestApplication application;
1303 Actor actor = Actor::New();
1304 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1305 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1306 application.GetScene().Add(actor);
1308 // Render and notify
1309 application.SendNotification();
1310 application.Render();
1312 // Connect to actor's touched signal
1314 RemoveActorFunctor functor(data);
1315 actor.TouchedSignal().Connect(&application, functor);
1317 // Register for leave events
1318 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
1320 // Emit a down signal
1321 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1322 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1325 // Re-add, render and notify
1326 application.GetScene().Add(actor);
1327 application.SendNotification();
1328 application.Render();
1330 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1331 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1332 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1335 // Emit a down signal
1336 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1337 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1340 // Render and notify
1341 application.SendNotification();
1342 application.Render();
1344 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1345 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1346 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1349 // Re-add actor back to scene, render and notify
1350 application.GetScene().Add(actor);
1351 application.SendNotification();
1352 application.Render();
1354 // Emit another down event
1355 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1356 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1359 // Completely delete the actor
1362 // Emit event, should not crash and should not receive an event.
1363 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(210.0f, 210.0f)));
1364 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1368 int UtcDaliTouchEventActorSignalNotConsumed(void)
1370 TestApplication application;
1372 Actor actor = Actor::New();
1373 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1374 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1375 application.GetScene().Add(actor);
1377 // Render and notify
1378 application.SendNotification();
1379 application.Render();
1381 // Connect to actor's touched signal
1383 TouchEventFunctor functor(data, false);
1384 actor.TouchedSignal().Connect(&application, functor);
1386 // Emit a down signal
1387 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1388 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1392 int UtcDaliTouchEventActorRemovedFromScene(void)
1394 TestApplication application;
1396 Actor actor = Actor::New();
1397 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1398 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1399 application.GetScene().Add(actor);
1401 // Render and notify
1402 application.SendNotification();
1403 application.Render();
1405 // Connect to actor's touched signal
1407 TouchEventFunctor functor(data);
1408 actor.TouchedSignal().Connect(&application, functor);
1410 // Emit a down signal
1411 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1412 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1415 // Remove actor from scene
1416 application.GetScene().Remove(actor);
1419 // Render and notify
1420 application.SendNotification();
1421 application.Render();
1423 // Emit a move at the same point, we should not be signalled.
1424 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
1425 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1430 int UtcDaliTouchEventLayerConsumesTouch(void)
1432 TestApplication application;
1434 Actor actor = Actor::New();
1435 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1436 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1437 application.GetScene().Add(actor);
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 // Add a layer to overlap the actor
1449 Layer layer = Layer::New();
1450 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1451 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1452 application.GetScene().Add(layer);
1455 // Render and notify
1456 application.SendNotification();
1457 application.Render();
1459 // Emit a few touch signals
1460 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1461 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(10.0f, 10.0f)));
1462 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1465 // Set layer to consume all touch
1466 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
1468 // Render and notify
1469 application.SendNotification();
1470 application.Render();
1472 // Emit the same signals again, should not receive
1473 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1474 application.ProcessEvent(GenerateSingleTouch(PointState::UP, Vector2(10.0f, 10.0f)));
1475 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1481 int UtcDaliTouchEventLeaveActorReadded(void)
1483 TestApplication application;
1484 Integration::Scene scene = application.GetScene();
1486 Actor actor = Actor::New();
1487 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1488 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1491 // Set actor to receive touch-events
1492 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
1494 // Render and notify
1495 application.SendNotification();
1496 application.Render();
1498 // Connect to actor's touched signal
1500 TouchEventFunctor functor(data);
1501 actor.TouchedSignal().Connect(&application, functor);
1503 // Emit a down and motion
1504 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1505 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(11.0f, 10.0f)));
1506 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1509 // Remove actor from scene and add again
1510 scene.Remove(actor);
1513 // Emit a motion within the actor's bounds
1514 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(12.0f, 10.0f)));
1515 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1518 // Emit a motion outside the actor's bounds
1519 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(200.0f, 200.0f)));
1520 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1521 DALI_TEST_EQUALS(PointState::LEAVE, data.receivedTouch.points[0].state, TEST_LOCATION);
1527 int UtcDaliTouchEventClippedActor(void)
1529 TestApplication application;
1530 Integration::Scene scene = application.GetScene();
1532 Actor actor = Actor::New();
1533 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1534 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1537 Actor clippingActor = Actor::New();
1538 clippingActor.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
1539 clippingActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1540 clippingActor.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN);
1541 scene.Add(clippingActor);
1543 // Add a child to the clipped region.
1544 Actor clippingChild = Actor::New();
1545 clippingChild.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
1546 clippingChild.SetProperty(Actor::Property::POSITION, Vector2(25.0f, 25.0f));
1547 clippingChild.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1548 clippingActor.Add(clippingChild);
1550 // Render and notify.
1551 application.SendNotification();
1552 application.Render();
1554 // Connect to actor's touch signal.
1556 TouchEventFunctor functor(data);
1557 actor.TouchedSignal().Connect(&application, functor);
1559 // Emit an event within clipped area - we should have a hit.
1560 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1561 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1564 // Emit an event within clipped child area - we should still have a hit.
1565 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
1566 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1569 // Now connect to the clippingChild's touch signal
1570 SignalData clippingChildData;
1571 TouchEventFunctor clippingChildFunctor(clippingChildData);
1572 clippingChild.TouchedSignal().Connect(&application, clippingChildFunctor);
1574 // Emit an event within clipped child area - no hit on actor, but hit on clipped child.
1575 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
1576 DALI_TEST_EQUALS(true, clippingChildData.functorCalled, TEST_LOCATION);
1577 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1579 clippingChildData.Reset();
1581 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1582 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(60.0f, 60.0f)));
1583 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1585 clippingChildData.Reset();
1587 // Emit an event inside part of the child which is within the clipped area, we should have a hit on the clipped child but not the actor.
1588 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(30.0f, 30.0f)));
1589 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1590 DALI_TEST_EQUALS(true, clippingChildData.functorCalled, TEST_LOCATION);
1592 clippingChildData.Reset();
1597 int UtcDaliTouchEventActorUnparented(void)
1599 TestApplication application;
1601 Actor actor = Actor::New();
1602 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1603 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1604 application.GetScene().Add(actor);
1606 // Render and notify
1607 application.SendNotification();
1608 application.Render();
1610 // Connect to actor's touched signal
1612 TouchEventFunctor functor(data);
1613 actor.TouchedSignal().Connect(&application, functor);
1615 // Emit a down signal
1616 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1617 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1618 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1619 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1622 // Render and notify
1623 application.SendNotification();
1624 application.Render();
1626 // Unparent the actor
1629 // Should receive an interrupted event
1630 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1631 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1635 int UtcDaliTouchEventParentRemovedFromScene(void)
1637 TestApplication application;
1639 Actor parent = Actor::New();
1640 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1641 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1642 application.GetScene().Add(parent);
1644 Actor actor = Actor::New();
1645 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1646 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1649 // Render and notify
1650 application.SendNotification();
1651 application.Render();
1653 // Connect to actor's touched signal
1655 TouchEventFunctor functor(data);
1656 actor.TouchedSignal().Connect(&application, functor);
1658 // Emit a down signal
1659 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1660 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1661 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1662 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1665 // Render and notify
1666 application.SendNotification();
1667 application.Render();
1669 // Unparent the parent of the touchable actor
1672 // Should receive an interrupted event
1673 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1674 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1678 int UtcDaliTouchEventActorRemovedFromSceneDifferentConsumer(void)
1680 TestApplication application;
1682 Actor parent = Actor::New();
1683 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1684 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1685 application.GetScene().Add(parent);
1687 Actor actor = Actor::New();
1688 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1689 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1692 // Render and notify
1693 application.SendNotification();
1694 application.Render();
1696 // Connect to actor's touched signal
1698 TouchEventFunctor functor(data, false /* Do not consume */);
1699 actor.TouchedSignal().Connect(&application, functor);
1701 // Connect to parent's touched signal
1702 SignalData parentData;
1703 TouchEventFunctor parentFunctor(parentData);
1704 parent.TouchedSignal().Connect(&application, parentFunctor);
1706 // Emit a down signal
1707 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1708 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1709 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1710 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1711 DALI_TEST_CHECK(actor == data.touchedActor);
1712 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1713 DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1714 DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
1715 DALI_TEST_CHECK(parent == parentData.touchedActor);
1719 // Render and notify
1720 application.SendNotification();
1721 application.Render();
1723 // Unparent the actor
1726 // Should receive an interrupted event for both actor & parent
1727 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1728 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1729 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1730 DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1734 // Readd actor to parent
1737 // Render and notify
1738 application.SendNotification();
1739 application.Render();
1741 // Emit a motion signal
1742 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(10.0f, 10.0f)));
1743 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1744 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1748 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1749 SignalData secondData;
1750 TouchEventFunctor secondFunctor(secondData /* Consume */);
1751 actor.TouchedSignal().Connect(&application, secondFunctor);
1753 // Unparent the actor
1756 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1757 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1758 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1759 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1760 DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1761 DALI_TEST_EQUALS(true, secondData.functorCalled, TEST_LOCATION);
1762 DALI_TEST_EQUALS(PointState::INTERRUPTED, secondData.receivedTouch.points[0].state, TEST_LOCATION);
1770 int UtcDaliTouchEventInterruptedDifferentConsumer(void)
1772 TestApplication application;
1773 Actor rootActor(application.GetScene().GetRootLayer());
1775 Actor parent = Actor::New();
1776 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1777 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1778 application.GetScene().Add(parent);
1780 Actor actor = Actor::New();
1781 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1782 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1785 // Render and notify
1786 application.SendNotification();
1787 application.Render();
1789 // Connect to actor's touched signal
1791 TouchEventFunctor functor(data, false /* Do not consume */);
1792 actor.TouchedSignal().Connect(&application, functor);
1794 // Connect to parent's touched signal
1795 SignalData parentData;
1796 TouchEventFunctor parentFunctor(parentData, false /* Do not consume */);
1797 parent.TouchedSignal().Connect(&application, parentFunctor);
1799 // Connect to root's touched signal and consume
1800 SignalData rootData;
1801 TouchEventFunctor rootFunctor(rootData);
1802 rootActor.TouchedSignal().Connect(&application, rootFunctor);
1804 // Emit a down signal
1805 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1806 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1807 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1808 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
1809 DALI_TEST_CHECK(actor == data.touchedActor);
1810 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1811 DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1812 DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
1813 DALI_TEST_CHECK(parent == parentData.touchedActor);
1814 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
1815 DALI_TEST_EQUALS(PointState::DOWN, rootData.receivedTouch.points[0].state, TEST_LOCATION);
1816 DALI_TEST_CHECK(actor == rootData.receivedTouch.points[0].hitActor);
1817 DALI_TEST_CHECK(rootActor == rootData.touchedActor);
1822 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1823 SignalData secondData;
1824 TouchEventFunctor secondFunctor(secondData /* Consume */);
1825 parent.TouchedSignal().Connect(&application, secondFunctor);
1827 // Emit an interrupted signal, all three should STILL be called
1828 application.ProcessEvent(GenerateSingleTouch(PointState::INTERRUPTED, Vector2(10.0f, 10.0f)));
1829 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1830 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
1831 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
1832 DALI_TEST_EQUALS(PointState::INTERRUPTED, parentData.receivedTouch.points[0].state, TEST_LOCATION);
1833 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
1834 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.receivedTouch.points[0].state, TEST_LOCATION);
1842 int UtcDaliTouchEventGetRadius(void)
1844 TestApplication application;
1846 Actor actor = Actor::New();
1847 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1848 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1849 application.GetScene().Add(actor);
1851 // Render and notify
1852 application.SendNotification();
1853 application.Render();
1855 // Connect to actor's touched signal
1857 TouchEventFunctor functor(data);
1858 actor.TouchedSignal().Connect(&application, functor);
1860 // Emit a down signal with an angle
1861 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1862 touchEvent.points[0].SetRadius(100.0f);
1863 application.ProcessEvent(touchEvent);
1864 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1865 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1866 DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].radius, TEST_LOCATION);
1867 DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].ellipseRadius.x, TEST_LOCATION);
1868 DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].ellipseRadius.y, TEST_LOCATION);
1873 int UtcDaliTouchEventGetEllipseRadius(void)
1875 TestApplication application;
1877 Actor actor = Actor::New();
1878 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1879 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1880 application.GetScene().Add(actor);
1882 // Render and notify
1883 application.SendNotification();
1884 application.Render();
1886 // Connect to actor's touched signal
1888 TouchEventFunctor functor(data);
1889 actor.TouchedSignal().Connect(&application, functor);
1891 // Emit a down signal with an angle
1892 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1893 touchEvent.points[0].SetRadius(100.0f, Vector2(20.0f, 10.0f));
1894 application.ProcessEvent(touchEvent);
1895 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1896 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1897 DALI_TEST_EQUALS(100.0f, data.receivedTouch.points[0].radius, TEST_LOCATION);
1898 DALI_TEST_EQUALS(20.0f, data.receivedTouch.points[0].ellipseRadius.x, TEST_LOCATION);
1899 DALI_TEST_EQUALS(10.0f, data.receivedTouch.points[0].ellipseRadius.y, TEST_LOCATION);
1904 int UtcDaliTouchEventGetAngle(void)
1906 TestApplication application;
1908 Actor actor = Actor::New();
1909 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1910 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1911 application.GetScene().Add(actor);
1913 // Render and notify
1914 application.SendNotification();
1915 application.Render();
1917 // Connect to actor's touched signal
1919 TouchEventFunctor functor(data);
1920 actor.TouchedSignal().Connect(&application, functor);
1922 // Emit a down signal with an angle
1923 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1924 touchEvent.points[0].SetAngle(Degree(90.0f));
1925 application.ProcessEvent(touchEvent);
1926 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1927 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1928 DALI_TEST_EQUALS(Degree(90.0f), data.receivedTouch.points[0].angle, TEST_LOCATION);
1933 int UtcDaliTouchEventGetPressure(void)
1935 TestApplication application;
1937 Actor actor = Actor::New();
1938 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1939 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1940 application.GetScene().Add(actor);
1942 // Render and notify
1943 application.SendNotification();
1944 application.Render();
1946 // Connect to actor's touched signal
1948 TouchEventFunctor functor(data);
1949 actor.TouchedSignal().Connect(&application, functor);
1951 // Emit a down signal with an angle
1952 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
1953 touchEvent.points[0].SetPressure(10.0f);
1954 application.ProcessEvent(touchEvent);
1955 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1956 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
1957 DALI_TEST_EQUALS(10.0f, data.receivedTouch.points[0].pressure, TEST_LOCATION);
1962 int UtcDaliTouchEventUsage(void)
1964 TestApplication application;
1966 Actor actor = Actor::New();
1967 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1968 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1969 application.GetScene().Add(actor);
1971 // Render and notify
1972 application.SendNotification();
1973 application.Render();
1975 // Connect to actor's touched signal
1977 TouchEventFunctor functor(data);
1978 actor.TouchedSignal().Connect(&application, functor);
1980 // Emit a down signal with an angle
1981 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
1982 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1987 int UtcDaliTouchEventGetDeviceAPINegative(void)
1989 TestApplication application;
1991 Actor actor = Actor::New();
1992 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1993 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1994 application.GetScene().Add(actor);
1996 // Render and notify
1997 application.SendNotification();
1998 application.Render();
2000 // Connect to actor's touched signal
2001 HandleData handleData;
2002 TouchEventHandleFunctor functor(handleData);
2003 actor.TouchedSignal().Connect(&application, functor);
2005 Vector2 screenCoordinates(10.0f, 10.0f);
2006 Vector2 localCoordinates;
2007 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
2009 // Emit a down signal
2010 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, screenCoordinates));
2012 TouchEvent data = handleData.receivedTouchHandle;
2013 DALI_TEST_EQUALS(data.GetDeviceClass(-1), Device::Class::NONE, TEST_LOCATION);
2014 DALI_TEST_EQUALS(data.GetDeviceSubclass(-1), Device::Subclass::NONE, TEST_LOCATION);
2018 int UtcDaliTouchEventGetMouseButtonPositive(void)
2020 TestApplication application;
2022 Actor actor = Actor::New();
2023 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2024 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2025 application.GetScene().Add(actor);
2027 // Render and notify
2028 application.SendNotification();
2029 application.Render();
2031 // Connect to actor's touched signal
2032 HandleData handleData;
2033 TouchEventHandleFunctor functor(handleData);
2034 actor.TouchedSignal().Connect(&application, functor);
2036 // Emit a down signal with MouseButton
2037 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
2038 touchEvent.points[0].SetMouseButton(static_cast<MouseButton::Type>(3));
2039 application.ProcessEvent(touchEvent);
2041 TouchEvent data = handleData.receivedTouchHandle;
2042 DALI_TEST_EQUALS(data.GetMouseButton(0), MouseButton::SECONDARY, TEST_LOCATION);
2047 int UtcDaliTouchEventGetMouseButtonNagative(void)
2049 TestApplication application;
2051 Actor actor = Actor::New();
2052 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2053 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2054 application.GetScene().Add(actor);
2056 // Render and notify
2057 application.SendNotification();
2058 application.Render();
2060 // Connect to actor's touched signal
2061 HandleData handleData;
2062 TouchEventHandleFunctor functor(handleData);
2063 actor.TouchedSignal().Connect(&application, functor);
2065 // Emit a down signal with MouseButton
2066 Integration::TouchEvent touchEvent = GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f));
2067 touchEvent.points[0].SetMouseButton(static_cast<MouseButton::Type>(2));
2068 application.ProcessEvent(touchEvent);
2070 TouchEvent data = handleData.receivedTouchHandle;
2071 DALI_TEST_EQUALS(data.GetMouseButton(0), MouseButton::TERTIARY, TEST_LOCATION);
2072 DALI_TEST_EQUALS(data.GetMouseButton(3), MouseButton::INVALID, TEST_LOCATION);
2077 int UtcDaliTouchEventCapturePropertySet(void)
2079 TestApplication application;
2081 Actor actor = Actor::New();
2082 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2083 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2084 application.GetScene().Add(actor);
2086 // Render and notify
2087 application.SendNotification();
2088 application.Render();
2090 // Connect to actor's touched signal
2092 TouchEventFunctor functor(data);
2093 actor.TouchedSignal().Connect(&application, functor);
2095 // Emit a down signal
2096 application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(10.0f, 10.0f)));
2097 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2100 // Now motion outside of actor, we should not receive the event
2101 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(110.0f, 110.0f)));
2102 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2105 // Up event, should receive an interrupted
2106 application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2107 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2108 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::INTERRUPTED, TEST_LOCATION);
2110 // Now set the capture property
2111 actor.SetProperty(DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START, true);
2113 // Emit a down signal
2114 application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(10.0f, 10.0f)));
2115 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2118 // Now motion outside of actor, we now SHOULD receive the event
2119 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(110.0f, 110.0f)));
2120 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2123 // Up event, we should receive it again, but as ended rather than interrupted
2124 application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2125 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2126 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::FINISHED, TEST_LOCATION);
2131 int UtcDaliTouchEventCapturePropertySetWithMultiTouch(void)
2133 TestApplication application;
2135 Actor actor = Actor::New();
2136 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2137 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2138 application.GetScene().Add(actor);
2140 // Render and notify
2141 application.SendNotification();
2142 application.Render();
2144 // Connect to actor's touched signal
2146 TouchEventFunctor functor(data);
2147 actor.TouchedSignal().Connect(&application, functor);
2149 // Now set the capture property
2150 actor.SetProperty(DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START, true);
2152 // Emit a down signal
2153 application.ProcessEvent(GenerateDoubleTouch(PointState::STARTED, Vector2(10.0f, 10.0f), PointState::STARTED, Vector2(15.0f, 15.0f), 200));
2154 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2157 // Now motion outside of actor, we now SHOULD receive the event
2158 application.ProcessEvent(GenerateDoubleTouch(PointState::MOTION, Vector2(110.0f, 110.0f), PointState::MOTION, Vector2(115.0f, 115.0f), 210));
2159 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2162 // Up event, we should receive it again, but as ended rather than interrupted
2163 application.ProcessEvent(GenerateDoubleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f), PointState::FINISHED, Vector2(115.0f, 115.0f), 220));
2164 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2165 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::FINISHED, TEST_LOCATION);
2166 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(1).state, PointState::FINISHED, TEST_LOCATION);
2171 int UtcDaliTouchEventIntegNewTouchEvent(void)
2173 uint32_t timestamp = 92858u;
2174 TouchPoint tp(1, PointState::STARTED, 34.4f, 123.89f, 5.0f, 7.0f);
2175 Dali::TouchEvent touchEvent = Integration::NewTouchEvent(timestamp, tp);
2177 DALI_TEST_EQUALS(touchEvent.GetPointCount(), 1u, TEST_LOCATION);
2178 DALI_TEST_EQUALS(touchEvent.GetState(0), PointState::STARTED, TEST_LOCATION);
2179 DALI_TEST_EQUALS(touchEvent.GetLocalPosition(0), Vector2(5.0f, 7.0f), TEST_LOCATION);
2180 DALI_TEST_EQUALS(touchEvent.GetScreenPosition(0), Vector2(34.4f, 123.89f), TEST_LOCATION);
2185 int UtcDaliTouchEventIntercept01(void)
2187 TestApplication application;
2189 Actor actor = Actor::New();
2190 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2191 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2192 application.GetScene().Add(actor);
2194 // Render and notify
2195 application.SendNotification();
2196 application.Render();
2198 // Connect to actor's intercept touched signal
2200 TouchEventFunctor functor(data, false /* Do not consume */);
2201 Dali::DevelActor::InterceptTouchedSignal(actor).Connect(&application, functor);
2203 // Emit a down signal
2204 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
2206 // It should be able to receive touch events by registering only InterceptTouchEvent.
2207 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2208 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2209 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2210 DALI_TEST_CHECK(actor == data.touchedActor);
2216 int UtcDaliTouchEventIntercept02(void)
2218 TestApplication application;
2220 Actor parent = Actor::New();
2221 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2222 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2223 application.GetScene().Add(parent);
2225 Actor actor = Actor::New();
2226 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2227 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2230 // Render and notify
2231 application.SendNotification();
2232 application.Render();
2234 // Connect to actor's touched signal
2236 TouchEventFunctor functor(data, false /* Do not consume */);
2237 actor.TouchedSignal().Connect(&application, functor);
2239 // Connect to parent's touched signal
2240 SignalData parentData;
2241 TouchEventFunctor parentFunctor(parentData, false /* Do not consume */);
2242 parent.TouchedSignal().Connect(&application, parentFunctor);
2244 // Emit a down signal
2245 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
2246 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2247 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2252 // Connect to parent's intercept touched signal
2253 SignalData interceptData;
2254 TouchEventFunctor interceptFunctor(interceptData, true /* Do intercept */);
2255 Dali::DevelActor::InterceptTouchedSignal(parent).Connect(&application, interceptFunctor);
2257 // Emit a down signal
2258 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
2260 // The actor gets interrupted. Because touch is intercepted by parent.
2261 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2262 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.receivedTouch.points[0].state, TEST_LOCATION);
2263 DALI_TEST_EQUALS(true, interceptData.functorCalled, TEST_LOCATION);
2264 DALI_TEST_EQUALS(PointState::DOWN, interceptData.receivedTouch.points[0].state, TEST_LOCATION);
2265 DALI_TEST_CHECK(actor == interceptData.receivedTouch.points[0].hitActor);
2266 DALI_TEST_CHECK(parent == interceptData.touchedActor);
2267 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
2268 DALI_TEST_EQUALS(PointState::DOWN, parentData.receivedTouch.points[0].state, TEST_LOCATION);
2269 DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
2270 DALI_TEST_CHECK(parent == parentData.touchedActor);
2272 interceptData.Reset();
2275 // Render and notify
2276 application.SendNotification();
2277 application.Render();
2279 // Emit a move signal
2280 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 20.0f)));
2282 // Since InterceptTouchEvent is not called because it has already been intercepted by the parent, only the parent will receive the touchEvent.
2283 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2284 DALI_TEST_EQUALS(false, interceptData.functorCalled, TEST_LOCATION);
2285 DALI_TEST_EQUALS(true, parentData.functorCalled, TEST_LOCATION);
2286 DALI_TEST_EQUALS(PointState::MOTION, parentData.receivedTouch.points[0].state, TEST_LOCATION);
2287 DALI_TEST_CHECK(actor == parentData.receivedTouch.points[0].hitActor);
2288 DALI_TEST_CHECK(parent == parentData.touchedActor);
2290 interceptData.Reset();
2297 int UtcDaliTouchEventIntercept03(void)
2299 TestApplication application;
2301 // Add a layer to overlap the actor
2302 Layer layer = Layer::New();
2303 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2304 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2305 application.GetScene().Add(layer);
2308 // Set layer to consume all touch
2309 layer.SetProperty(Layer::Property::CONSUMES_TOUCH, true);
2311 // Render and notify
2312 application.SendNotification();
2313 application.Render();
2315 Actor actor = Actor::New();
2316 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2317 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2320 // Render and notify
2321 application.SendNotification();
2322 application.Render();
2324 Actor rootActor(application.GetScene().GetRootLayer());
2326 // Connect to root actor's intercept touched signal
2327 SignalData sceneData;
2328 TouchEventFunctor sceneFunctor(sceneData);
2329 Dali::DevelActor::InterceptTouchedSignal(rootActor).Connect(&application, sceneFunctor);
2331 // Render and notify
2332 application.SendNotification();
2333 application.Render();
2335 // Emit a down signal
2336 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(10.0f, 10.0f)));
2338 // Even if the layer is touch consumed, the root actor must be able to intercept touch.
2339 DALI_TEST_EQUALS(true, sceneData.functorCalled, TEST_LOCATION);
2346 int UtcDaliTouchAreaOffset(void)
2348 TestApplication application;
2350 Actor actor = Actor::New();
2351 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2352 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2354 application.GetScene().Add(actor);
2356 // Render and notify
2357 application.SendNotification();
2358 application.Render();
2360 // Connect to actor's touched signal
2362 TouchEventFunctor functor(data, false /* Do not consume */);
2363 actor.TouchedSignal().Connect(&application, functor);
2365 // Emit a down signal
2366 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(110.0f, 110.0f)));
2367 // The actor touched signal is not called because the touch area is outside actor.
2368 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2371 // set a bigger touch area
2372 actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(-70, 70, 70, -70)); // left, right, bottom, top
2374 // Render and notify
2375 application.SendNotification();
2376 application.Render();
2378 // Emit a down signal
2379 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(150.0f, 150.0f)));
2380 // The actor touched signal is called because the touch area is inside touchArea.
2381 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2382 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2383 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2386 // set a offset touch area
2387 actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(50, 100, -50, 0)); // left, right, bottom, top
2389 // Render and notify
2390 application.SendNotification();
2391 application.Render();
2393 // Emit a down signal
2394 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(190.0f, 25.0f)));
2395 // The actor touched signal is called because the touch area is inside touchArea.
2396 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2397 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2398 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2401 // set a smaller touch area
2402 actor.SetProperty(DevelActor::Property::TOUCH_AREA_OFFSET, Rect<int>(50, 0, 0, 50));
2404 // Render and notify
2405 application.SendNotification();
2406 application.Render();
2408 // Emit a down signal
2409 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(40.0f, 40.0f)));
2410 // The actor touched signal is not called because the touch area is outside touchArea.
2411 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2414 // Emit a down signal
2415 application.ProcessEvent(GenerateSingleTouch(PointState::DOWN, Vector2(90.0f, 90.0f)));
2416 // The actor touched signal is called because the touch area is inside touchArea.
2417 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2418 DALI_TEST_EQUALS(PointState::DOWN, data.receivedTouch.points[0].state, TEST_LOCATION);
2419 DALI_TEST_CHECK(actor == data.receivedTouch.points[0].hitActor);
2425 int UtcDaliTouchEventAllowOnlyOwnTouchPropertySet(void)
2427 TestApplication application;
2429 Actor actor = Actor::New();
2430 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2431 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2432 application.GetScene().Add(actor);
2434 // Render and notify
2435 application.SendNotification();
2436 application.Render();
2438 // Connect to actor's touched signal
2440 TouchEventFunctor functor(data);
2441 actor.TouchedSignal().Connect(&application, functor);
2443 // Emit a down signal outside of actor, we should not receive the event
2444 application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(110.0f, 110.0f)));
2445 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2448 // Now motion inside of actor, we should receive the event
2449 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(80.0f, 80.0f)));
2450 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2453 // Up event, should not receive the event
2454 application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2455 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2458 // Now set the only allow own touch property
2459 actor.SetProperty(DevelActor::Property::ALLOW_ONLY_OWN_TOUCH, true);
2461 // Emit a down signal outside of actor, we should not receive the event
2462 application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(110.0f, 110.0f)));
2463 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2466 // Now motion inside of actor, we should NOT receive the event
2467 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(80.0f, 80.0f)));
2468 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2471 // Up event, should not receive the event
2472 application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2473 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2476 // Emit a down signal inside of actor, we should receive the event
2477 application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(10.0f, 10.0f)));
2478 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2481 // Now motion inside of actor, we should receive the event
2482 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(80.0f, 80.0f)));
2483 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2486 // Now motion outsize of actor, we should receive the event
2487 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(110.0f, 110.0f)));
2488 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2491 // Up event, should receive an interrupted
2492 application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(110.0f, 110.0f)));
2493 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2494 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::INTERRUPTED, TEST_LOCATION);
2500 int UtcDaliTouchEventDispatchTouchMotionPropertySet(void)
2502 TestApplication application;
2504 Actor actor = Actor::New();
2505 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2506 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
2507 application.GetScene().Add(actor);
2509 // Render and notify
2510 application.SendNotification();
2511 application.Render();
2513 // Connect to actor's touched signal
2515 TouchEventFunctor functor(data);
2516 actor.TouchedSignal().Connect(&application, functor);
2518 // Emit a down signal actor, we should receive the event
2519 application.ProcessEvent(GenerateSingleTouch(PointState::STARTED, Vector2(10.0f, 10.0f)));
2520 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2521 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::STARTED, TEST_LOCATION);
2524 // Emit a motion signal actor, we should receive the event
2525 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(20.0f, 20.0f)));
2526 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2527 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::MOTION, TEST_LOCATION);
2530 // Now set the dispatch touch motion property
2531 actor.SetProperty(DevelActor::Property::DISPATCH_TOUCH_MOTION, false);
2533 // Emit a motion signal actor, we should not receive the event
2534 application.ProcessEvent(GenerateSingleTouch(PointState::MOTION, Vector2(30.0f, 30.0f)));
2535 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
2538 // Up event, should receive the event
2539 application.ProcessEvent(GenerateSingleTouch(PointState::FINISHED, Vector2(40.0f, 40.0f)));
2540 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
2541 DALI_TEST_EQUALS(data.receivedTouch.GetPoint(0).state, PointState::FINISHED, TEST_LOCATION);