2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/events/hover-event-devel.h>
20 #include <dali/integration-api/events/hover-event-integ.h>
21 #include <dali/integration-api/render-task-list-integ.h>
22 #include <dali/public-api/dali-core.h>
29 void utc_dali_hover_processing_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_hover_processing_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled(false),
55 functorCalled = false;
61 HoverEvent hoverEvent;
65 // Functor that sets the data when called
66 struct HoverEventFunctor
70 * @param[in] data Reference to the data to store callback information.
71 * @param[in] returnValue What the functor should return.
73 HoverEventFunctor(SignalData& data, bool returnValue = true)
75 returnValue(returnValue)
79 bool operator()(Actor actor, const HoverEvent& hoverEvent)
81 signalData.functorCalled = true;
82 signalData.hoveredActor = actor;
83 signalData.hoverEvent = hoverEvent;
88 SignalData& signalData;
92 // Functor that removes the actor when called.
93 struct RemoveActorFunctor : public HoverEventFunctor
97 * @param[in] data Reference to the data to store callback information.
98 * @param[in] returnValue What the functor should return.
100 RemoveActorFunctor(SignalData& data, bool returnValue = true)
101 : HoverEventFunctor(data, returnValue)
105 bool operator()(Actor actor, const HoverEvent& hoverEvent)
107 Actor parent(actor.GetParent());
110 parent.Remove(actor);
113 return HoverEventFunctor::operator()(actor, hoverEvent);
117 Integration::HoverEvent GenerateSingleHover(PointState::Type state, const Vector2& screenPosition)
119 Integration::HoverEvent hoverEvent;
120 Integration::Point point;
121 point.SetState(state);
122 point.SetScreenPosition(screenPosition);
123 hoverEvent.points.push_back(point);
129 ///////////////////////////////////////////////////////////////////////////////
131 int UtcDaliHoverNormalProcessing(void)
133 TestApplication application;
135 Actor actor = Actor::New();
136 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
137 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
138 application.GetScene().Add(actor);
141 application.SendNotification();
142 application.Render();
144 // Connect to actor's hovered signal
146 HoverEventFunctor functor(data);
147 actor.HoveredSignal().Connect(&application, functor);
149 Vector2 screenCoordinates(10.0f, 10.0f);
150 Vector2 localCoordinates;
151 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
153 // Emit a started signal
154 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
155 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
156 DALI_TEST_EQUALS(1u, data.hoverEvent.GetPointCount(), TEST_LOCATION);
157 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
158 DALI_TEST_EQUALS(screenCoordinates, data.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
159 DALI_TEST_EQUALS(localCoordinates, data.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
160 DALI_TEST_EQUALS(0, data.hoverEvent.GetDeviceId(0), TEST_LOCATION);
161 DALI_TEST_EQUALS(0u, data.hoverEvent.GetTime(), TEST_LOCATION);
162 DALI_TEST_EQUALS(actor, data.hoverEvent.GetHitActor(0), TEST_LOCATION);
163 DALI_TEST_EQUALS(-1, data.hoverEvent.GetDeviceId(1), TEST_LOCATION);
164 DALI_TEST_EQUALS(PointState::FINISHED, data.hoverEvent.GetState(1), TEST_LOCATION);
165 DALI_TEST_EQUALS(Vector2::ZERO, data.hoverEvent.GetScreenPosition(1), 0.1f, TEST_LOCATION);
166 DALI_TEST_EQUALS(Vector2::ZERO, data.hoverEvent.GetLocalPosition(1), 0.1f, TEST_LOCATION);
167 DALI_TEST_EQUALS(Dali::Actor(), data.hoverEvent.GetHitActor(1), TEST_LOCATION);
170 // Emit a motion signal
171 screenCoordinates.x = screenCoordinates.y = 11.0f;
172 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
173 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, screenCoordinates));
174 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
175 DALI_TEST_EQUALS(1u, data.hoverEvent.GetPointCount(), TEST_LOCATION);
176 DALI_TEST_EQUALS(PointState::MOTION, data.hoverEvent.GetState(0), TEST_LOCATION);
177 DALI_TEST_EQUALS(screenCoordinates, data.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
178 DALI_TEST_EQUALS(localCoordinates, data.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
179 DALI_TEST_EQUALS(0, data.hoverEvent.GetDeviceId(0), TEST_LOCATION);
180 DALI_TEST_EQUALS(0u, data.hoverEvent.GetTime(), TEST_LOCATION);
181 DALI_TEST_EQUALS(actor, data.hoverEvent.GetHitActor(0), TEST_LOCATION);
182 DALI_TEST_EQUALS(-1, data.hoverEvent.GetDeviceId(1), TEST_LOCATION);
183 DALI_TEST_EQUALS(PointState::FINISHED, data.hoverEvent.GetState(1), TEST_LOCATION);
184 DALI_TEST_EQUALS(Vector2::ZERO, data.hoverEvent.GetScreenPosition(1), 0.1f, TEST_LOCATION);
185 DALI_TEST_EQUALS(Vector2::ZERO, data.hoverEvent.GetLocalPosition(1), 0.1f, TEST_LOCATION);
186 DALI_TEST_EQUALS(Dali::Actor(), data.hoverEvent.GetHitActor(1), TEST_LOCATION);
189 // Emit a finished signal
190 screenCoordinates.x = screenCoordinates.y = 12.0f;
191 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y);
192 application.ProcessEvent(GenerateSingleHover(PointState::FINISHED, screenCoordinates));
193 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
194 DALI_TEST_EQUALS(1u, data.hoverEvent.GetPointCount(), TEST_LOCATION);
195 DALI_TEST_EQUALS(PointState::FINISHED, data.hoverEvent.GetState(0), TEST_LOCATION);
196 DALI_TEST_EQUALS(screenCoordinates, data.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
197 DALI_TEST_EQUALS(localCoordinates, data.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
198 DALI_TEST_EQUALS(0, data.hoverEvent.GetDeviceId(0), TEST_LOCATION);
199 DALI_TEST_EQUALS(0u, data.hoverEvent.GetTime(), TEST_LOCATION);
200 DALI_TEST_EQUALS(actor, data.hoverEvent.GetHitActor(0), TEST_LOCATION);
201 DALI_TEST_EQUALS(-1, data.hoverEvent.GetDeviceId(1), TEST_LOCATION);
202 DALI_TEST_EQUALS(PointState::FINISHED, data.hoverEvent.GetState(1), TEST_LOCATION);
203 DALI_TEST_EQUALS(Vector2::ZERO, data.hoverEvent.GetScreenPosition(1), 0.1f, TEST_LOCATION);
204 DALI_TEST_EQUALS(Vector2::ZERO, data.hoverEvent.GetLocalPosition(1), 0.1f, TEST_LOCATION);
205 DALI_TEST_EQUALS(Dali::Actor(), data.hoverEvent.GetHitActor(1), TEST_LOCATION);
208 // Emit a started signal where the actor is not present
209 screenCoordinates.x = screenCoordinates.y = 200.0f;
210 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
211 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
212 DALI_TEST_CHECK(!data.hoverEvent);
217 int UtcDaliHoverOutsideCameraNearFarPlanes(void)
219 TestApplication application;
221 Integration::Scene stage = application.GetScene();
222 Vector2 stageSize = stage.GetSize();
224 Actor actor = Actor::New();
225 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
226 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
227 actor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
231 application.SendNotification();
232 application.Render();
234 // Get the camera's near and far planes
235 RenderTaskList taskList = stage.GetRenderTaskList();
236 Dali::RenderTask task = taskList.GetTask(0);
237 CameraActor camera = task.GetCameraActor();
238 float nearPlane = camera.GetNearClippingPlane();
239 float farPlane = camera.GetFarClippingPlane();
241 // Calculate the current distance of the actor from the camera
242 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
243 float distance = (stageSize.y * 0.5f) / tanHalfFov;
245 // Connect to actor's hovered signal
247 HoverEventFunctor functor(data);
248 actor.HoveredSignal().Connect(&application, functor);
250 Vector2 screenCoordinates(stageSize.x * 0.5f, stageSize.y * 0.5f);
252 // Emit a started signal
253 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
254 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
257 // Emit a started signal where actor is just at the camera's near plane
258 actor.SetProperty(Actor::Property::POSITION_Z, distance - nearPlane);
261 application.SendNotification();
262 application.Render();
264 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
265 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
268 // Emit a started signal where actor is closer than the camera's near plane
269 actor.SetProperty(Actor::Property::POSITION_Z, (distance - nearPlane) + 1.0f);
272 application.SendNotification();
273 application.Render();
275 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
276 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
279 // Emit a started signal where actor is just at the camera's far plane
280 actor.SetProperty(Actor::Property::POSITION_Z, distance - farPlane);
283 application.SendNotification();
284 application.Render();
286 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
287 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
290 // Emit a started signal where actor is further than the camera's far plane
291 actor.SetProperty(Actor::Property::POSITION_Z, (distance - farPlane) - 1.0f);
294 application.SendNotification();
295 application.Render();
297 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
298 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
303 int UtcDaliHoverEmitEmpty(void)
305 TestApplication application;
309 // Emit an empty HoverEvent
310 Integration::HoverEvent event;
311 application.ProcessEvent(event);
312 tet_result(TET_FAIL);
314 catch(Dali::DaliException& e)
316 DALI_TEST_ASSERT(e, "!event.points.empty()", TEST_LOCATION);
321 int UtcDaliHoverInterrupted(void)
323 TestApplication application;
325 Actor actor = Actor::New();
326 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
327 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
328 application.GetScene().Add(actor);
331 application.SendNotification();
332 application.Render();
334 // Connect to actor's hovered signal
336 HoverEventFunctor functor(data);
337 actor.HoveredSignal().Connect(&application, functor);
339 // Emit a started signal
340 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
341 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
342 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
345 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
346 application.ProcessEvent(GenerateSingleHover(PointState::INTERRUPTED, Vector2(200.0f, 200.0f /* Outside actor */)));
347 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
348 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.hoverEvent.GetState(0), TEST_LOCATION);
351 // Emit another interrupted signal, our signal handler should not be called.
352 application.ProcessEvent(GenerateSingleHover(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
353 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
357 int UtcDaliHoverParentConsumer(void)
359 TestApplication application;
360 Actor rootActor(application.GetScene().GetRootLayer());
362 Actor actor = Actor::New();
363 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
364 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
365 application.GetScene().Add(actor);
368 application.SendNotification();
369 application.Render();
371 // Connect to actor's hovered signal
373 HoverEventFunctor functor(data, false);
374 actor.HoveredSignal().Connect(&application, functor);
376 // Connect to root actor's hovered signal
378 HoverEventFunctor rootFunctor(rootData); // Consumes signal
379 rootActor.HoveredSignal().Connect(&application, rootFunctor);
381 Vector2 screenCoordinates(10.0f, 10.0f);
382 Vector2 actorCoordinates, rootCoordinates;
383 actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
384 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
386 // Emit a started signal
387 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
388 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
389 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
390 DALI_TEST_EQUALS(1u, data.hoverEvent.GetPointCount(), TEST_LOCATION);
391 DALI_TEST_EQUALS(1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION);
392 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
393 DALI_TEST_EQUALS(PointState::STARTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
394 DALI_TEST_EQUALS(screenCoordinates, data.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
395 DALI_TEST_EQUALS(screenCoordinates, rootData.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
396 DALI_TEST_EQUALS(actorCoordinates, data.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
397 DALI_TEST_EQUALS(rootCoordinates, rootData.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
398 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
399 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
403 // Emit a motion signal
404 screenCoordinates.x = screenCoordinates.y = 11.0f;
405 actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
406 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
407 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, screenCoordinates));
408 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
409 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
410 DALI_TEST_EQUALS(1u, data.hoverEvent.GetPointCount(), TEST_LOCATION);
411 DALI_TEST_EQUALS(1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION);
412 DALI_TEST_EQUALS(PointState::MOTION, data.hoverEvent.GetState(0), TEST_LOCATION);
413 DALI_TEST_EQUALS(PointState::MOTION, rootData.hoverEvent.GetState(0), TEST_LOCATION);
414 DALI_TEST_EQUALS(screenCoordinates, data.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
415 DALI_TEST_EQUALS(screenCoordinates, rootData.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
416 DALI_TEST_EQUALS(actorCoordinates, data.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
417 DALI_TEST_EQUALS(rootCoordinates, rootData.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
418 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
419 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
423 // Emit a finished signal
424 screenCoordinates.x = screenCoordinates.y = 12.0f;
425 actor.ScreenToLocal(actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y);
426 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
427 application.ProcessEvent(GenerateSingleHover(PointState::FINISHED, screenCoordinates));
428 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
429 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
430 DALI_TEST_EQUALS(1u, data.hoverEvent.GetPointCount(), TEST_LOCATION);
431 DALI_TEST_EQUALS(1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION);
432 DALI_TEST_EQUALS(PointState::FINISHED, data.hoverEvent.GetState(0), TEST_LOCATION);
433 DALI_TEST_EQUALS(PointState::FINISHED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
434 DALI_TEST_EQUALS(screenCoordinates, data.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
435 DALI_TEST_EQUALS(screenCoordinates, rootData.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
436 DALI_TEST_EQUALS(actorCoordinates, data.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
437 DALI_TEST_EQUALS(rootCoordinates, rootData.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
438 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
439 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
443 // Emit a started signal where the actor is not present, will hit the root actor though
444 screenCoordinates.x = screenCoordinates.y = 200.0f;
445 rootActor.ScreenToLocal(rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y);
446 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, screenCoordinates));
447 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
448 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
449 DALI_TEST_EQUALS(1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION);
450 DALI_TEST_EQUALS(PointState::STARTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
451 DALI_TEST_EQUALS(screenCoordinates, rootData.hoverEvent.GetScreenPosition(0), TEST_LOCATION);
452 DALI_TEST_EQUALS(rootCoordinates, rootData.hoverEvent.GetLocalPosition(0), 0.1f, TEST_LOCATION);
453 DALI_TEST_CHECK(rootActor == rootData.hoverEvent.GetHitActor(0));
457 int UtcDaliHoverInterruptedParentConsumer(void)
459 TestApplication application;
460 Actor rootActor(application.GetScene().GetRootLayer());
462 Actor actor = Actor::New();
463 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
464 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
465 application.GetScene().Add(actor);
468 application.SendNotification();
469 application.Render();
471 // Connect to actor's hovered signal
473 HoverEventFunctor functor(data, false);
474 actor.HoveredSignal().Connect(&application, functor);
476 // Connect to root actor's hovered signal
478 HoverEventFunctor rootFunctor(rootData); // Consumes signal
479 rootActor.HoveredSignal().Connect(&application, rootFunctor);
481 // Emit a started signal
482 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
483 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
484 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
485 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
486 DALI_TEST_EQUALS(PointState::STARTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
487 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
488 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
492 // Emit an interrupted signal
493 application.ProcessEvent(GenerateSingleHover(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
494 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
495 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
496 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.hoverEvent.GetState(0), TEST_LOCATION);
497 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
498 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
499 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
503 // Emit another started signal
504 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
505 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
506 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
507 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
508 DALI_TEST_EQUALS(PointState::STARTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
512 // Remove actor from Stage
513 application.GetScene().Remove(actor);
516 application.SendNotification();
517 application.Render();
519 // Emit an interrupted signal, only root actor's signal should be called.
520 application.ProcessEvent(GenerateSingleHover(PointState::INTERRUPTED, Vector2(200.0f, 200.0f /* Outside actor */)));
521 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
522 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
523 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
524 DALI_TEST_CHECK(rootActor == rootData.hoverEvent.GetHitActor(0));
528 // Emit another interrupted state, none of the signal's should be called.
529 application.ProcessEvent(GenerateSingleHover(PointState::INTERRUPTED, Vector2(200.0f, 200.0f)));
530 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
531 DALI_TEST_EQUALS(false, rootData.functorCalled, TEST_LOCATION);
535 int UtcDaliHoverLeave(void)
537 TestApplication application;
539 Actor actor = Actor::New();
540 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
541 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
542 application.GetScene().Add(actor);
545 application.SendNotification();
546 application.Render();
548 // Connect to actor's hovered signal
550 HoverEventFunctor functor(data);
551 actor.HoveredSignal().Connect(&application, functor);
553 // Set actor to require leave events
554 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
556 // Emit a started signal
557 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
558 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
559 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
562 // Emit a motion signal outside of actor, should be signalled with a Leave
563 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(200.0f, 200.0f)));
564 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
565 DALI_TEST_EQUALS(PointState::LEAVE, data.hoverEvent.GetState(0), TEST_LOCATION);
568 // Another motion outside of actor, no signalling
569 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(201.0f, 201.0f)));
570 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
573 // Another motion event inside actor, signalled with motion
574 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(10.0f, 10.0f)));
575 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
576 DALI_TEST_EQUALS(PointState::MOTION, data.hoverEvent.GetState(0), TEST_LOCATION);
579 // We do not want to listen to leave events anymore
580 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, false);
582 // Another motion event outside of actor, no signalling
583 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(200.0f, 200.0f)));
584 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
589 int UtcDaliHoverLeaveParentConsumer(void)
591 TestApplication application;
592 Actor rootActor(application.GetScene().GetRootLayer());
594 Actor actor = Actor::New();
595 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
596 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
597 application.GetScene().Add(actor);
600 application.SendNotification();
601 application.Render();
603 // Connect to actor's hovered signal
605 HoverEventFunctor functor(data, false);
606 actor.HoveredSignal().Connect(&application, functor);
608 // Connect to root actor's hovered signal
610 HoverEventFunctor rootFunctor(rootData); // Consumes signal
611 rootActor.HoveredSignal().Connect(&application, rootFunctor);
613 // Set actor to require leave events
614 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
615 rootActor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
617 // Emit a started signal
618 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
619 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
620 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
621 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
622 DALI_TEST_EQUALS(PointState::STARTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
623 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
624 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
628 // Emit a motion signal outside of actor, should be signalled with a Leave
629 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(200.0f, 200.0f)));
630 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
631 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
632 DALI_TEST_EQUALS(PointState::LEAVE, data.hoverEvent.GetState(0), TEST_LOCATION);
633 DALI_TEST_EQUALS(PointState::LEAVE, rootData.hoverEvent.GetState(0), TEST_LOCATION);
634 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
635 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
639 // Another motion outside of actor, only rootActor signalled
640 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(201.0f, 201.0f)));
641 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
642 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
643 DALI_TEST_EQUALS(PointState::MOTION, rootData.hoverEvent.GetState(0), TEST_LOCATION);
644 DALI_TEST_CHECK(rootActor == rootData.hoverEvent.GetHitActor(0));
648 // Another motion event inside actor, signalled with motion
649 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(10.0f, 10.0f)));
650 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
651 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
652 DALI_TEST_EQUALS(PointState::MOTION, data.hoverEvent.GetState(0), TEST_LOCATION);
653 DALI_TEST_EQUALS(PointState::MOTION, rootData.hoverEvent.GetState(0), TEST_LOCATION);
654 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
655 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
659 // We do not want to listen to leave events of actor anymore
660 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, false);
662 // Another motion event outside of root actor, only root signalled
663 Vector2 stageSize(application.GetScene().GetSize());
664 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(stageSize.width + 10.0f, stageSize.height + 10.0f)));
665 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
666 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
667 DALI_TEST_EQUALS(PointState::LEAVE, rootData.hoverEvent.GetState(0), TEST_LOCATION);
671 int UtcDaliHoverActorBecomesInsensitive(void)
673 TestApplication application;
675 Actor actor = Actor::New();
676 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
677 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
678 application.GetScene().Add(actor);
681 application.SendNotification();
682 application.Render();
684 // Connect to actor's hovered signal
686 HoverEventFunctor functor(data);
687 actor.HoveredSignal().Connect(&application, functor);
689 // Emit a started signal
690 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
691 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
692 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
695 // Change actor to insensitive
696 actor.SetProperty(Actor::Property::SENSITIVE, false);
698 // Emit a motion signal, signalled with an interrupted
699 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(200.0f, 200.0f)));
700 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
701 DALI_TEST_EQUALS(PointState::INTERRUPTED, data.hoverEvent.GetState(0), TEST_LOCATION);
706 int UtcDaliHoverActorBecomesInsensitiveParentConsumer(void)
708 TestApplication application;
709 Actor rootActor(application.GetScene().GetRootLayer());
711 Actor actor = Actor::New();
712 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
713 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
714 application.GetScene().Add(actor);
717 application.SendNotification();
718 application.Render();
720 // Connect to actor's hovered signal
722 HoverEventFunctor functor(data, false);
723 actor.HoveredSignal().Connect(&application, functor);
725 // Connect to root actor's hovered signal
727 HoverEventFunctor rootFunctor(rootData); // Consumes signal
728 rootActor.HoveredSignal().Connect(&application, rootFunctor);
730 // Emit a started signal
731 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
732 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
733 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
734 DALI_TEST_EQUALS(PointState::STARTED, data.hoverEvent.GetState(0), TEST_LOCATION);
735 DALI_TEST_EQUALS(PointState::STARTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
736 DALI_TEST_CHECK(actor == data.hoverEvent.GetHitActor(0));
737 DALI_TEST_CHECK(actor == rootData.hoverEvent.GetHitActor(0));
741 // Remove actor from Stage
742 application.GetScene().Remove(actor);
745 application.SendNotification();
746 application.Render();
748 // Make root actor insensitive
749 rootActor.SetProperty(Actor::Property::SENSITIVE, false);
751 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
752 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(200.0f, 200.0f)));
753 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
754 DALI_TEST_EQUALS(true, rootData.functorCalled, TEST_LOCATION);
755 DALI_TEST_EQUALS(PointState::INTERRUPTED, rootData.hoverEvent.GetState(0), TEST_LOCATION);
759 int UtcDaliHoverMultipleLayers(void)
761 TestApplication application;
762 Actor rootActor(application.GetScene().GetRootLayer());
764 // Connect to actor's hovered signal
766 HoverEventFunctor functor(data);
768 Layer layer1(Layer::New());
769 layer1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
770 layer1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
771 application.GetScene().Add(layer1);
773 Actor actor1(Actor::New());
774 actor1.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
775 actor1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
776 actor1.SetProperty(Actor::Property::POSITION_Z, 1.0f); // Should hit actor1 in this layer
780 application.SendNotification();
781 application.Render();
783 // Connect to layer1 and actor1
784 layer1.HoveredSignal().Connect(&application, functor);
785 actor1.HoveredSignal().Connect(&application, functor);
787 // Hit in hittable area, actor1 should be hit
788 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
789 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
790 DALI_TEST_CHECK(data.hoveredActor == actor1);
793 // Make layer1 insensitive, nothing should be hit
794 layer1.SetProperty(Actor::Property::SENSITIVE, false);
795 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
796 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
799 // Make layer1 sensitive again, again actor1 will be hit
800 layer1.SetProperty(Actor::Property::SENSITIVE, true);
801 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
802 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
803 DALI_TEST_CHECK(data.hoveredActor == actor1);
806 // Make rootActor insensitive, nothing should be hit
807 rootActor.SetProperty(Actor::Property::SENSITIVE, false);
808 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
809 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
812 // Make rootActor sensitive
813 rootActor.SetProperty(Actor::Property::SENSITIVE, true);
816 Layer layer2(Layer::New());
817 layer2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
818 layer2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
819 layer2.SetProperty(Actor::Property::POSITION_Z, 10.0f); // Should hit layer2 in this layer rather than actor2
820 application.GetScene().Add(layer2);
822 Actor actor2(Actor::New());
823 actor2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
824 actor2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
828 application.SendNotification();
829 application.Render();
831 // Connect to layer2 and actor2
832 layer2.HoveredSignal().Connect(&application, functor);
833 actor2.HoveredSignal().Connect(&application, functor);
835 // Emit an event, should hit layer2
836 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
837 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
838 //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
841 // Make layer2 insensitive, should hit actor1
842 layer2.SetProperty(Actor::Property::SENSITIVE, false);
843 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
844 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
845 DALI_TEST_CHECK(data.hoveredActor == actor1);
848 // Make layer2 sensitive again, should hit layer2
849 layer2.SetProperty(Actor::Property::SENSITIVE, true);
850 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
851 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
852 //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
855 // Make layer2 invisible, render and notify
856 layer2.SetProperty(Actor::Property::VISIBLE, false);
857 application.SendNotification();
858 application.Render();
861 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
862 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
863 DALI_TEST_CHECK(data.hoveredActor == actor1);
866 // Make rootActor invisible, render and notify
867 rootActor.SetProperty(Actor::Property::VISIBLE, false);
868 application.SendNotification();
869 application.Render();
871 // Should not hit anything
872 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
873 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
878 int UtcDaliHoverMultipleRenderTasks(void)
880 TestApplication application;
881 Integration::Scene stage(application.GetScene());
882 Vector2 stageSize(stage.GetSize());
884 Actor actor = Actor::New();
885 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
886 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
889 // Create render task
890 Viewport viewport(stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f);
891 RenderTask renderTask(application.GetScene().GetRenderTaskList().CreateTask());
892 renderTask.SetViewport(viewport);
893 renderTask.SetInputEnabled(true);
896 application.SendNotification();
897 application.Render();
899 // Connect to actor's hovered signal
901 HoverEventFunctor functor(data);
902 actor.HoveredSignal().Connect(&application, functor);
904 // Emit a started signal
905 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
906 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
909 // Ensure renderTask actor can be hit too.
910 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
911 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
914 // Disable input on renderTask, should not be hittable
915 renderTask.SetInputEnabled(false);
916 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
917 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
922 int UtcDaliHoverMultipleRenderTasksWithChildLayer(void)
924 TestApplication application;
925 Integration::Scene stage(application.GetScene());
926 Vector2 stageSize(stage.GetSize());
928 Actor actor = Actor::New();
929 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
930 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
933 Layer layer = Layer::New();
934 layer.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
935 layer.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
938 // Create render task
939 Viewport viewport(stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f);
940 RenderTask renderTask(application.GetScene().GetRenderTaskList().CreateTask());
941 renderTask.SetViewport(viewport);
942 renderTask.SetInputEnabled(true);
943 renderTask.SetSourceActor(actor);
946 application.SendNotification();
947 application.Render();
949 // Connect to layer's hovered signal
951 HoverEventFunctor functor(data);
952 actor.HoveredSignal().Connect(&application, functor);
953 layer.HoveredSignal().Connect(&application, functor);
955 // Emit a started signal
956 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
957 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
960 // Ensure renderTask actor can be hit too.
961 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
962 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
965 // Disable input on renderTask, should not be hittable
966 renderTask.SetInputEnabled(false);
967 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(viewport.x + 5.0f, viewport.y + 5.0f)));
968 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
973 int UtcDaliHoverOffscreenRenderTasks(void)
975 TestApplication application;
976 Integration::Scene stage(application.GetScene());
977 Vector2 stageSize(stage.GetSize());
979 // FrameBufferImage for offscreen RenderTask
980 FrameBuffer frameBuffer = FrameBuffer::New(stageSize.width, stageSize.height);
982 // Create a renderable actor to display the FrameBufferImage
983 Actor renderableActor = CreateRenderableActor(frameBuffer.GetColorTexture());
984 renderableActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
985 renderableActor.SetProperty(Actor::Property::SIZE, Vector2(stageSize.x, stageSize.y));
986 renderableActor.ScaleBy(Vector3(1.0f, -1.0f, 1.0f)); // FIXME
987 stage.Add(renderableActor);
989 Actor actor = Actor::New();
990 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
991 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
993 application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); // Ensure framebuffer connects
995 stage.GetRenderTaskList().GetTask(0u).SetScreenToFrameBufferFunction(RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION);
997 // Create a RenderTask
998 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
999 renderTask.SetSourceActor(actor);
1000 renderTask.SetFrameBuffer(frameBuffer);
1001 renderTask.SetInputEnabled(true);
1003 // Create another RenderTask
1004 RenderTask renderTask2(stage.GetRenderTaskList().CreateTask());
1005 renderTask2.SetInputEnabled(true);
1007 // Render and notify
1008 application.SendNotification();
1009 application.Render();
1011 // Connect to actor's hovered signal
1013 HoverEventFunctor functor(data);
1014 actor.HoveredSignal().Connect(&application, functor);
1016 // Emit a started signal
1017 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1018 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1023 int UtcDaliHoverMultipleRenderableActors(void)
1025 TestApplication application;
1026 Integration::Scene stage(application.GetScene());
1027 Vector2 stageSize(stage.GetSize());
1029 Actor parent = CreateRenderableActor();
1030 parent.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1031 parent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1034 Actor actor = CreateRenderableActor();
1035 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1036 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1039 // Render and notify
1040 application.SendNotification();
1041 application.Render();
1043 // Connect to layer's hovered signal
1045 HoverEventFunctor functor(data);
1046 parent.HoveredSignal().Connect(&application, functor);
1047 actor.HoveredSignal().Connect(&application, functor);
1049 // Emit a started signal
1050 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1051 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1052 DALI_TEST_CHECK(actor == data.hoveredActor);
1056 int UtcDaliHoverActorRemovedInSignal(void)
1058 TestApplication application;
1060 Actor actor = Actor::New();
1061 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1062 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1063 application.GetScene().Add(actor);
1065 // Render and notify
1066 application.SendNotification();
1067 application.Render();
1069 // Connect to actor's hovered signal
1071 RemoveActorFunctor functor(data);
1072 actor.HoveredSignal().Connect(&application, functor);
1074 // Register for leave events
1075 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
1077 // Emit a started signal
1078 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1079 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1082 // Re-add, render and notify
1083 application.GetScene().Add(actor);
1084 application.SendNotification();
1085 application.Render();
1087 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1088 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(210.0f, 210.0f)));
1089 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1092 // Emit a started signal
1093 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1094 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1097 // Render and notify
1098 application.SendNotification();
1099 application.Render();
1101 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1102 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(210.0f, 210.0f)));
1103 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1106 // Re-add actor back to stage, render and notify
1107 application.GetScene().Add(actor);
1108 application.SendNotification();
1109 application.Render();
1111 // Emit another started event
1112 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1113 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1116 // Completely delete the actor
1119 // Emit event, should not crash and should not receive an event.
1120 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(210.0f, 210.0f)));
1121 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1125 int UtcDaliHoverActorSignalNotConsumed(void)
1127 TestApplication application;
1129 Actor actor = Actor::New();
1130 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1131 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1132 application.GetScene().Add(actor);
1134 // Render and notify
1135 application.SendNotification();
1136 application.Render();
1138 // Connect to actor's hovered signal
1140 HoverEventFunctor functor(data, false);
1141 actor.HoveredSignal().Connect(&application, functor);
1143 // Emit a started signal
1144 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1145 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1149 int UtcDaliHoverActorUnStaged(void)
1151 TestApplication application;
1153 Actor actor = Actor::New();
1154 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1155 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1156 application.GetScene().Add(actor);
1158 // Render and notify
1159 application.SendNotification();
1160 application.Render();
1162 // Connect to actor's hovered signal
1164 HoverEventFunctor functor(data);
1165 actor.HoveredSignal().Connect(&application, functor);
1167 // Emit a started signal
1168 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1169 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1172 // Remove actor from stage
1173 application.GetScene().Remove(actor);
1175 // Render and notify
1176 application.SendNotification();
1177 application.Render();
1179 // Emit a move at the same point, we should not be signalled.
1180 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(10.0f, 10.0f)));
1181 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1186 int UtcDaliHoverLeaveActorReadded(void)
1188 TestApplication application;
1189 Integration::Scene stage = application.GetScene();
1191 Actor actor = Actor::New();
1192 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1193 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1196 // Set actor to receive hover-events
1197 actor.SetProperty(Actor::Property::LEAVE_REQUIRED, true);
1199 // Render and notify
1200 application.SendNotification();
1201 application.Render();
1203 // Connect to actor's hovered signal
1205 HoverEventFunctor functor(data);
1206 actor.HoveredSignal().Connect(&application, functor);
1208 // Emit a started and motion
1209 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1210 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(11.0f, 10.0f)));
1211 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1214 // Remove actor from stage and add again
1215 stage.Remove(actor);
1218 // Emit a motion within the actor's bounds
1219 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(12.0f, 10.0f)));
1220 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1223 // Emit a motion outside the actor's bounds
1224 application.ProcessEvent(GenerateSingleHover(PointState::MOTION, Vector2(200.0f, 200.0f)));
1225 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1226 DALI_TEST_EQUALS(PointState::LEAVE, data.hoverEvent.GetState(0), TEST_LOCATION);
1232 int UtcDaliHoverClippingActor(void)
1234 TestApplication application;
1235 Integration::Scene stage = application.GetScene();
1237 Actor actor = Actor::New();
1238 actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1239 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1242 Actor clippingActor = Actor::New();
1243 clippingActor.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
1244 clippingActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1245 clippingActor.SetProperty(Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN);
1246 stage.Add(clippingActor);
1248 // Add a child to the clipped region.
1249 Actor clippingChild = Actor::New();
1250 clippingChild.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
1251 clippingChild.SetProperty(Actor::Property::POSITION, Vector2(25.0f, 25.0f));
1252 clippingChild.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1253 clippingActor.Add(clippingChild);
1255 // Render and notify.
1256 application.SendNotification();
1257 application.Render();
1259 // Connect to actor's hovered signal.
1261 HoverEventFunctor functor(data);
1262 actor.HoveredSignal().Connect(&application, functor);
1264 // Emit an event within clipped area - no hit.
1265 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(10.0f, 10.0f)));
1266 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1269 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1270 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(60.0f, 60.0f)));
1271 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1274 clippingChild.HoveredSignal().Connect(&application, functor);
1276 // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1277 application.ProcessEvent(GenerateSingleHover(PointState::STARTED, Vector2(30.0f, 30.0f)));
1278 DALI_TEST_EQUALS(true, data.functorCalled, TEST_LOCATION);
1284 int UtcDaliHoverEventCreate(void)
1286 TestApplication application;
1288 Dali::HoverEvent hoverEvent = DevelHoverEvent::New(100);
1289 DALI_TEST_CHECK(hoverEvent);
1291 // Emit a started signal
1292 DALI_TEST_EQUALS(100, hoverEvent.GetTime(), TEST_LOCATION);
1293 DALI_TEST_EQUALS(0, hoverEvent.GetPointCount(), TEST_LOCATION);