2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/hover-event-integ.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali-test-suite-utils.h>
28 void utc_dali_hover_processing_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_hover_processing_cleanup(void)
35 test_return_value = TET_PASS;
38 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled( false ),
55 functorCalled = false;
58 hoverEvent.points.clear();
64 HoverEvent hoverEvent;
68 // Functor that sets the data when called
69 struct HoverEventFunctor
73 * @param[in] data Reference to the data to store callback information.
74 * @param[in] returnValue What the functor should return.
76 HoverEventFunctor( SignalData& data, bool returnValue = true )
78 returnValue( returnValue )
82 bool operator()( Actor actor, const HoverEvent& hoverEvent )
84 signalData.functorCalled = true;
85 signalData.hoveredActor = actor;
86 signalData.hoverEvent = hoverEvent;
91 SignalData& signalData;
95 // Functor that removes the actor when called.
96 struct RemoveActorFunctor : public HoverEventFunctor
100 * @param[in] data Reference to the data to store callback information.
101 * @param[in] returnValue What the functor should return.
103 RemoveActorFunctor( SignalData& data, bool returnValue = true )
104 : HoverEventFunctor( data, returnValue )
108 bool operator()( Actor actor, const HoverEvent& hoverEvent )
110 Actor parent( actor.GetParent() );
113 parent.Remove( actor );
116 return HoverEventFunctor::operator()( actor, hoverEvent );
120 Integration::HoverEvent GenerateSingleHover( TouchPoint::State state, Vector2 screenPosition )
122 Integration::HoverEvent hoverEvent;
123 hoverEvent.points.push_back( TouchPoint ( 0, state, screenPosition.x, screenPosition.y ) );
129 ///////////////////////////////////////////////////////////////////////////////
131 int UtcDaliHoverNormalProcessing(void)
133 TestApplication application;
135 Actor actor = Actor::New();
136 actor.SetSize(100.0f, 100.0f);
137 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
138 Stage::GetCurrent().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( TouchPoint::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( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
158 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
159 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
161 TouchPoint point = data.hoverEvent.GetPoint(0);
162 DALI_TEST_EQUALS( TouchPoint::Started, point.state, TEST_LOCATION );
163 DALI_TEST_EQUALS( screenCoordinates, point.screen, TEST_LOCATION );
164 DALI_TEST_EQUALS( localCoordinates, point.local, 0.1f, TEST_LOCATION );
168 // Emit a motion signal
169 screenCoordinates.x = screenCoordinates.y = 11.0f;
170 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
171 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, screenCoordinates ) );
172 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
173 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
174 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
175 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
176 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
179 // Emit a finished signal
180 screenCoordinates.x = screenCoordinates.y = 12.0f;
181 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
182 application.ProcessEvent( GenerateSingleHover( TouchPoint::Finished, screenCoordinates ) );
183 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
184 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
185 DALI_TEST_EQUALS( TouchPoint::Finished, data.hoverEvent.points[0].state, TEST_LOCATION );
186 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
187 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
190 // Emit a started signal where the actor is not present
191 screenCoordinates.x = screenCoordinates.y = 200.0f;
192 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
193 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
197 int UtcDaliHoverOutsideCameraNearFarPlanes(void)
199 TestApplication application;
201 Stage stage = Stage::GetCurrent();
202 Vector2 stageSize = stage.GetSize();
204 Actor actor = Actor::New();
205 actor.SetSize(100.0f, 100.0f);
206 actor.SetAnchorPoint(AnchorPoint::CENTER);
207 actor.SetParentOrigin(ParentOrigin::CENTER);
211 application.SendNotification();
212 application.Render();
214 // Get the camera's near and far planes
215 RenderTaskList taskList = stage.GetRenderTaskList();
216 Dali::RenderTask task = taskList.GetTask(0);
217 CameraActor camera = task.GetCameraActor();
218 float nearPlane = camera.GetNearClippingPlane();
219 float farPlane = camera.GetFarClippingPlane();
221 // Calculate the current distance of the actor from the camera
222 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
223 float distance = (stageSize.y * 0.5f) / tanHalfFov;
225 // Connect to actor's hovered signal
227 HoverEventFunctor functor( data );
228 actor.HoveredSignal().Connect( &application, functor );
230 Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
232 // Emit a started signal
233 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
234 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
237 // Emit a started signal where actor is just at the camera's near plane
238 actor.SetZ(distance - nearPlane);
241 application.SendNotification();
242 application.Render();
244 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
245 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
248 // Emit a started signal where actor is closer than the camera's near plane
249 actor.SetZ((distance - nearPlane) + 1.0f);
252 application.SendNotification();
253 application.Render();
255 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
256 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
259 // Emit a started signal where actor is just at the camera's far plane
260 actor.SetZ(distance - farPlane);
263 application.SendNotification();
264 application.Render();
266 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
267 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
270 // Emit a started signal where actor is further than the camera's far plane
271 actor.SetZ((distance - farPlane) - 1.0f);
274 application.SendNotification();
275 application.Render();
277 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
278 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
283 int UtcDaliHoverEmitEmpty(void)
285 TestApplication application;
289 // Emit an empty HoverEvent
290 Integration::HoverEvent event;
291 application.ProcessEvent( event );
292 tet_result( TET_FAIL );
294 catch ( Dali::DaliException& e )
296 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
301 int UtcDaliHoverInterrupted(void)
303 TestApplication application;
305 Actor actor = Actor::New();
306 actor.SetSize(100.0f, 100.0f);
307 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
308 Stage::GetCurrent().Add(actor);
311 application.SendNotification();
312 application.Render();
314 // Connect to actor's hovered signal
316 HoverEventFunctor functor( data );
317 actor.HoveredSignal().Connect( &application, functor );
319 // Emit a started signal
320 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
321 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
322 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
325 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
326 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
327 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
328 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
331 // Emit another interrupted signal, our signal handler should not be called.
332 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
333 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
337 int UtcDaliHoverParentConsumer(void)
339 TestApplication application;
340 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
342 Actor actor = Actor::New();
343 actor.SetSize(100.0f, 100.0f);
344 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
345 Stage::GetCurrent().Add(actor);
348 application.SendNotification();
349 application.Render();
351 // Connect to actor's hovered signal
353 HoverEventFunctor functor( data, false );
354 actor.HoveredSignal().Connect( &application, functor );
356 // Connect to root actor's hovered signal
358 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
359 rootActor.HoveredSignal().Connect( &application, rootFunctor );
361 Vector2 screenCoordinates( 10.0f, 10.0f );
362 Vector2 actorCoordinates, rootCoordinates;
363 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
364 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
366 // Emit a started signal
367 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
368 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
369 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
370 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
371 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
372 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
373 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
374 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
375 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
376 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
377 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
378 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
379 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
383 // Emit a motion signal
384 screenCoordinates.x = screenCoordinates.y = 11.0f;
385 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
386 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
387 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, 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( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
393 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
394 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
395 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
396 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
397 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
398 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
399 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
403 // Emit a finished signal
404 screenCoordinates.x = screenCoordinates.y = 12.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( TouchPoint::Finished, 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( TouchPoint::Finished, data.hoverEvent.points[0].state, TEST_LOCATION );
413 DALI_TEST_EQUALS( TouchPoint::Finished, rootData.hoverEvent.points[0].state, TEST_LOCATION );
414 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
415 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
416 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
417 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
418 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
419 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
423 // Emit a started signal where the actor is not present, will hit the root actor though
424 screenCoordinates.x = screenCoordinates.y = 200.0f;
425 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
426 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
427 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
428 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
429 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
430 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
431 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
432 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
433 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
437 int UtcDaliHoverInterruptedParentConsumer(void)
439 TestApplication application;
440 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
442 Actor actor = Actor::New();
443 actor.SetSize(100.0f, 100.0f);
444 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
445 Stage::GetCurrent().Add(actor);
448 application.SendNotification();
449 application.Render();
451 // Connect to actor's hovered signal
453 HoverEventFunctor functor( data, false );
454 actor.HoveredSignal().Connect( &application, functor );
456 // Connect to root actor's hovered signal
458 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
459 rootActor.HoveredSignal().Connect( &application, rootFunctor );
461 // Emit a started signal
462 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
463 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
464 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
465 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
466 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
467 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
468 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
472 // Emit an interrupted signal
473 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
474 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
475 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
476 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
477 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
478 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
479 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
483 // Emit another started signal
484 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
485 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
486 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
487 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
488 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
492 // Remove actor from Stage
493 Stage::GetCurrent().Remove( actor );
496 application.SendNotification();
497 application.Render();
499 // Emit an interrupted signal, only root actor's signal should be called.
500 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
501 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
502 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
503 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
504 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
508 // Emit another interrupted state, none of the signal's should be called.
509 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
510 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
511 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
515 int UtcDaliHoverLeave(void)
517 TestApplication application;
519 Actor actor = Actor::New();
520 actor.SetSize(100.0f, 100.0f);
521 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
522 Stage::GetCurrent().Add(actor);
525 application.SendNotification();
526 application.Render();
528 // Connect to actor's hovered signal
530 HoverEventFunctor functor( data );
531 actor.HoveredSignal().Connect( &application, functor );
533 // Set actor to require leave events
534 actor.SetLeaveRequired( true );
536 // Emit a started signal
537 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
538 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
539 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
542 // Emit a motion signal outside of actor, should be signalled with a Leave
543 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
544 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
545 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
548 // Another motion outside of actor, no signalling
549 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
550 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
553 // Another motion event inside actor, signalled with motion
554 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
555 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
556 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
559 // We do not want to listen to leave events anymore
560 actor.SetLeaveRequired( false );
562 // Another motion event outside of actor, no signalling
563 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
564 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
569 int UtcDaliHoverLeaveParentConsumer(void)
571 TestApplication application;
572 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
574 Actor actor = Actor::New();
575 actor.SetSize(100.0f, 100.0f);
576 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
577 Stage::GetCurrent().Add(actor);
580 application.SendNotification();
581 application.Render();
583 // Connect to actor's hovered signal
585 HoverEventFunctor functor( data, false );
586 actor.HoveredSignal().Connect( &application, functor );
588 // Connect to root actor's hovered signal
590 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
591 rootActor.HoveredSignal().Connect( &application, rootFunctor );
593 // Set actor to require leave events
594 actor.SetLeaveRequired( true );
595 rootActor.SetLeaveRequired( true );
597 // Emit a started signal
598 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
599 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
600 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
601 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
602 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
603 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
604 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
608 // Emit a motion signal outside of actor, should be signalled with a Leave
609 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
610 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
611 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
612 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
613 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.hoverEvent.points[0].state, TEST_LOCATION );
614 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
615 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
619 // Another motion outside of actor, only rootActor signalled
620 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
621 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
622 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
623 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
624 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
628 // Another motion event inside actor, signalled with motion
629 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
630 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
631 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
632 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
633 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
634 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
635 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
639 // We do not want to listen to leave events of actor anymore
640 actor.SetLeaveRequired( false );
642 // Another motion event outside of root actor, only root signalled
643 Vector2 stageSize( Stage::GetCurrent().GetSize() );
644 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
645 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
646 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
647 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.hoverEvent.points[0].state, TEST_LOCATION );
651 int UtcDaliHoverActorBecomesInsensitive(void)
653 TestApplication application;
655 Actor actor = Actor::New();
656 actor.SetSize(100.0f, 100.0f);
657 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
658 Stage::GetCurrent().Add(actor);
661 application.SendNotification();
662 application.Render();
664 // Connect to actor's hovered signal
666 HoverEventFunctor functor( data );
667 actor.HoveredSignal().Connect( &application, functor );
669 // Emit a started signal
670 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
671 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
672 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
675 // Change actor to insensitive
676 actor.SetSensitive( false );
678 // Emit a motion signal, signalled with an interrupted
679 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
680 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
681 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
686 int UtcDaliHoverActorBecomesInsensitiveParentConsumer(void)
688 TestApplication application;
689 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
691 Actor actor = Actor::New();
692 actor.SetSize(100.0f, 100.0f);
693 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
694 Stage::GetCurrent().Add(actor);
697 application.SendNotification();
698 application.Render();
700 // Connect to actor's hovered signal
702 HoverEventFunctor functor( data, false );
703 actor.HoveredSignal().Connect( &application, functor );
705 // Connect to root actor's hovered signal
707 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
708 rootActor.HoveredSignal().Connect( &application, rootFunctor );
710 // Emit a started signal
711 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
712 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
713 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
714 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
715 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
716 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
717 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
721 // Remove actor from Stage
722 Stage::GetCurrent().Remove( actor );
725 application.SendNotification();
726 application.Render();
728 // Make root actor insensitive
729 rootActor.SetSensitive( false );
731 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
732 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
733 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
734 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
735 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
739 int UtcDaliHoverMultipleLayers(void)
741 TestApplication application;
742 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
744 // Connect to actor's hovered signal
746 HoverEventFunctor functor( data );
748 Layer layer1 ( Layer::New() );
749 layer1.SetSize(100.0f, 100.0f);
750 layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
751 Stage::GetCurrent().Add( layer1 );
753 Actor actor1 ( Actor::New() );
754 actor1.SetSize( 100.0f, 100.0f );
755 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
756 actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
757 layer1.Add( actor1 );
760 application.SendNotification();
761 application.Render();
763 // Connect to layer1 and actor1
764 layer1.HoveredSignal().Connect( &application, functor );
765 actor1.HoveredSignal().Connect( &application, functor );
767 // Hit in hittable area, actor1 should be hit
768 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
769 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
770 DALI_TEST_CHECK( data.hoveredActor == actor1 );
773 // Make layer1 insensitive, nothing should be hit
774 layer1.SetSensitive( false );
775 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
776 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
779 // Make layer1 sensitive again, again actor1 will be hit
780 layer1.SetSensitive( true );
781 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
782 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
783 DALI_TEST_CHECK( data.hoveredActor == actor1 );
786 // Make rootActor insensitive, nothing should be hit
787 rootActor.SetSensitive( false );
788 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
789 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
792 // Make rootActor sensitive
793 rootActor.SetSensitive( true );
796 Layer layer2 ( Layer::New() );
797 layer2.SetSize(100.0f, 100.0f );
798 layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
799 layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
800 Stage::GetCurrent().Add( layer2 );
802 Actor actor2 ( Actor::New() );
803 actor2.SetSize(100.0f, 100.0f);
804 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
805 layer2.Add( actor2 );
808 application.SendNotification();
809 application.Render();
811 // Connect to layer2 and actor2
812 layer2.HoveredSignal().Connect( &application, functor );
813 actor2.HoveredSignal().Connect( &application, functor );
815 // Emit an event, should hit layer2
816 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
817 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
818 //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
821 // Make layer2 insensitive, should hit actor1
822 layer2.SetSensitive( false );
823 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
824 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
825 DALI_TEST_CHECK( data.hoveredActor == actor1 );
828 // Make layer2 sensitive again, should hit layer2
829 layer2.SetSensitive( true );
830 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
831 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
832 //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
835 // Make layer2 invisible, render and notify
836 layer2.SetVisible( false );
837 application.SendNotification();
838 application.Render();
841 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
842 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
843 DALI_TEST_CHECK( data.hoveredActor == actor1 );
846 // Make rootActor invisible, render and notify
847 rootActor.SetVisible( false );
848 application.SendNotification();
849 application.Render();
851 // Should not hit anything
852 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
853 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
858 int UtcDaliHoverMultipleRenderTasks(void)
860 TestApplication application;
861 Stage stage ( Stage::GetCurrent() );
862 Vector2 stageSize ( stage.GetSize() );
864 Actor actor = Actor::New();
865 actor.SetSize(100.0f, 100.0f);
866 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
869 // Create render task
870 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
871 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
872 renderTask.SetViewport( viewport );
873 renderTask.SetInputEnabled( true );
876 application.SendNotification();
877 application.Render();
879 // Connect to actor's hovered signal
881 HoverEventFunctor functor( data );
882 actor.HoveredSignal().Connect( &application, functor );
884 // Emit a started signal
885 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
886 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
889 // Ensure renderTask actor can be hit too.
890 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
891 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
894 // Disable input on renderTask, should not be hittable
895 renderTask.SetInputEnabled( false );
896 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
897 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
902 int UtcDaliHoverMultipleRenderTasksWithChildLayer(void)
904 TestApplication application;
905 Stage stage ( Stage::GetCurrent() );
906 Vector2 stageSize ( stage.GetSize() );
908 Actor actor = Actor::New();
909 actor.SetSize(100.0f, 100.0f);
910 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
913 Layer layer = Layer::New();
914 layer.SetSize(100.0f, 100.0f);
915 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
918 // Create render task
919 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
920 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
921 renderTask.SetViewport( viewport );
922 renderTask.SetInputEnabled( true );
923 renderTask.SetSourceActor( actor );
926 application.SendNotification();
927 application.Render();
929 // Connect to layer's hovered signal
931 HoverEventFunctor functor( data );
932 actor.HoveredSignal().Connect( &application, functor );
933 layer.HoveredSignal().Connect( &application, functor );
935 // Emit a started signal
936 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
937 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
940 // Ensure renderTask actor can be hit too.
941 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
942 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
945 // Disable input on renderTask, should not be hittable
946 renderTask.SetInputEnabled( false );
947 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
948 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
953 int UtcDaliHoverOffscreenRenderTasks(void)
955 TestApplication application;
956 Stage stage ( Stage::GetCurrent() );
957 Vector2 stageSize ( stage.GetSize() );
959 // FrameBufferImage for offscreen RenderTask
960 FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
962 // Create a renderable actor to display the FrameBufferImage
963 Actor renderableActor = CreateRenderableActor( frameBufferImage );
964 renderableActor.SetParentOrigin(ParentOrigin::CENTER);
965 renderableActor.SetSize( stageSize.x, stageSize.y );
966 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
967 stage.Add( renderableActor );
969 Actor actor = Actor::New();
970 actor.SetSize(100.0f, 100.0f);
971 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
973 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
975 stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
977 // Create a RenderTask
978 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
979 renderTask.SetSourceActor( actor );
980 renderTask.SetTargetFrameBuffer( frameBufferImage );
981 renderTask.SetInputEnabled( true );
983 // Create another RenderTask
984 RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
985 renderTask2.SetInputEnabled( true );
988 application.SendNotification();
989 application.Render();
991 // Connect to actor's hovered signal
993 HoverEventFunctor functor( data );
994 actor.HoveredSignal().Connect( &application, functor );
996 // Emit a started signal
997 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
998 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1003 int UtcDaliHoverMultipleRenderableActors(void)
1005 TestApplication application;
1006 Stage stage ( Stage::GetCurrent() );
1007 Vector2 stageSize ( stage.GetSize() );
1009 Actor parent = CreateRenderableActor();
1010 parent.SetSize( 100.0f, 100.0f );
1011 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1014 Actor actor = CreateRenderableActor();
1015 actor.SetSize( 100.0f, 100.0f );
1016 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1019 // Render and notify
1020 application.SendNotification();
1021 application.Render();
1023 // Connect to layer's hovered signal
1025 HoverEventFunctor functor( data );
1026 parent.HoveredSignal().Connect( &application, functor );
1027 actor.HoveredSignal().Connect( &application, functor );
1029 // Emit a started signal
1030 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1031 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1032 DALI_TEST_CHECK( actor == data.hoveredActor );
1036 int UtcDaliHoverActorRemovedInSignal(void)
1038 TestApplication application;
1040 Actor actor = Actor::New();
1041 actor.SetSize(100.0f, 100.0f);
1042 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1043 Stage::GetCurrent().Add(actor);
1045 // Render and notify
1046 application.SendNotification();
1047 application.Render();
1049 // Connect to actor's hovered signal
1051 RemoveActorFunctor functor( data );
1052 actor.HoveredSignal().Connect( &application, functor );
1054 // Register for leave events
1055 actor.SetLeaveRequired( true );
1057 // Emit a started signal
1058 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1059 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1062 // Re-add, render and notify
1063 Stage::GetCurrent().Add(actor);
1064 application.SendNotification();
1065 application.Render();
1067 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1068 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1069 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1072 // Emit a started signal
1073 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1074 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1077 // Render and notify
1078 application.SendNotification();
1079 application.Render();
1081 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1082 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1083 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1086 // Re-add actor back to stage, render and notify
1087 Stage::GetCurrent().Add(actor);
1088 application.SendNotification();
1089 application.Render();
1091 // Emit another started event
1092 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1093 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1096 // Completely delete the actor
1099 // Emit event, should not crash and should not receive an event.
1100 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1101 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1105 int UtcDaliHoverActorSignalNotConsumed(void)
1107 TestApplication application;
1109 Actor actor = Actor::New();
1110 actor.SetSize(100.0f, 100.0f);
1111 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1112 Stage::GetCurrent().Add(actor);
1114 // Render and notify
1115 application.SendNotification();
1116 application.Render();
1118 // Connect to actor's hovered signal
1120 HoverEventFunctor functor( data, false );
1121 actor.HoveredSignal().Connect( &application, functor );
1123 // Emit a started signal
1124 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1125 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1129 int UtcDaliHoverActorUnStaged(void)
1131 TestApplication application;
1133 Actor actor = Actor::New();
1134 actor.SetSize(100.0f, 100.0f);
1135 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1136 Stage::GetCurrent().Add(actor);
1138 // Render and notify
1139 application.SendNotification();
1140 application.Render();
1142 // Connect to actor's hovered signal
1144 HoverEventFunctor functor( data );
1145 actor.HoveredSignal().Connect( &application, functor );
1147 // Emit a started signal
1148 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1149 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1152 // Remove actor from stage
1153 Stage::GetCurrent().Remove( actor );
1155 // Render and notify
1156 application.SendNotification();
1157 application.Render();
1159 // Emit a move at the same point, we should not be signalled.
1160 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1161 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1166 int UtcDaliHoverSystemOverlayActor(void)
1168 TestApplication application;
1169 Dali::Integration::Core& core( application.GetCore() );
1170 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1171 systemOverlay.GetOverlayRenderTasks().CreateTask();
1173 // Create an actor and add it to the system overlay.
1174 Actor systemActor = Actor::New();
1175 systemActor.SetSize(100.0f, 100.0f);
1176 systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1177 systemOverlay.Add( systemActor );
1179 // Create an actor and add it to the stage as per normal, same position and size as systemActor
1180 Actor actor = Actor::New();
1181 actor.SetSize(100.0f, 100.0f);
1182 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1183 Stage::GetCurrent().Add(actor);
1185 // Connect to the hover signals.
1187 HoverEventFunctor functor( data );
1188 systemActor.HoveredSignal().Connect( &application, functor );
1189 actor.HoveredSignal().Connect( &application, functor );
1191 // Render and notify
1192 application.SendNotification();
1193 application.Render();
1195 // Emit a started signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1196 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1197 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1198 DALI_TEST_CHECK( systemActor == data.hoveredActor );
1202 int UtcDaliHoverLeaveActorReadded(void)
1204 TestApplication application;
1205 Stage stage = Stage::GetCurrent();
1207 Actor actor = Actor::New();
1208 actor.SetSize(100.0f, 100.0f);
1209 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1212 // Set actor to receive hover-events
1213 actor.SetLeaveRequired( true );
1215 // Render and notify
1216 application.SendNotification();
1217 application.Render();
1219 // Connect to actor's hovered signal
1221 HoverEventFunctor functor( data );
1222 actor.HoveredSignal().Connect( &application, functor );
1224 // Emit a started and motion
1225 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1226 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1227 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1230 // Remove actor from stage and add again
1231 stage.Remove( actor );
1234 // Emit a motion within the actor's bounds
1235 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1236 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1239 // Emit a motion outside the actor's bounds
1240 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1241 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1242 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
1249 int UtcDaliHoverStencilNonRenderableActor(void)
1251 TestApplication application;
1252 Stage stage = Stage::GetCurrent();
1254 Actor actor = Actor::New();
1255 actor.SetSize(100.0f, 100.0f);
1256 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1259 Actor stencil = Actor::New();
1260 stencil.SetSize(50.0f, 50.0f);
1261 stencil.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1262 stencil.SetDrawMode( DrawMode::STENCIL );
1265 // Render and notify
1266 application.SendNotification();
1267 application.Render();
1269 // Connect to actor's hovered signal
1271 HoverEventFunctor functor( data );
1272 actor.HoveredSignal().Connect( &application, functor );
1274 // Emit an event within stencil area
1275 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1276 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1279 // Emit an event outside the stencil area but within the actor area, we should have a hit!
1280 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 60.0f, 60.0f ) ) );
1281 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );