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/integration-api/render-task-list-integ.h>
25 #include <dali-test-suite-utils.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 ///////////////////////////////////////////////////////////////////////////////
44 // Stores data that is populated in the callback and will be read by the TET cases
48 : functorCalled( false ),
56 functorCalled = false;
59 hoverEvent.points.clear();
65 HoverEvent hoverEvent;
69 // Functor that sets the data when called
70 struct HoverEventFunctor
74 * @param[in] data Reference to the data to store callback information.
75 * @param[in] returnValue What the functor should return.
77 HoverEventFunctor( SignalData& data, bool returnValue = true )
79 returnValue( returnValue )
83 bool operator()( Actor actor, const HoverEvent& hoverEvent )
85 signalData.functorCalled = true;
86 signalData.hoveredActor = actor;
87 signalData.hoverEvent = hoverEvent;
92 SignalData& signalData;
96 // Functor that removes the actor when called.
97 struct RemoveActorFunctor : public HoverEventFunctor
101 * @param[in] data Reference to the data to store callback information.
102 * @param[in] returnValue What the functor should return.
104 RemoveActorFunctor( SignalData& data, bool returnValue = true )
105 : HoverEventFunctor( data, returnValue )
109 bool operator()( Actor actor, const HoverEvent& hoverEvent )
111 Actor parent( actor.GetParent() );
114 parent.Remove( actor );
117 return HoverEventFunctor::operator()( actor, hoverEvent );
121 Integration::HoverEvent GenerateSingleHover( TouchPoint::State state, const Vector2& screenPosition )
123 Integration::HoverEvent hoverEvent;
124 Integration::Point point;
125 point.SetState( static_cast< PointState::Type >( state ) );
126 point.SetScreenPosition( screenPosition );
127 hoverEvent.points.push_back( point );
133 ///////////////////////////////////////////////////////////////////////////////
135 int UtcDaliHoverNormalProcessing(void)
137 TestApplication application;
139 Actor actor = Actor::New();
140 actor.SetSize(100.0f, 100.0f);
141 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
142 Stage::GetCurrent().Add(actor);
145 application.SendNotification();
146 application.Render();
148 // Connect to actor's hovered signal
150 HoverEventFunctor functor( data );
151 actor.HoveredSignal().Connect( &application, functor );
153 Vector2 screenCoordinates( 10.0f, 10.0f );
154 Vector2 localCoordinates;
155 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
157 // Emit a started signal
158 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
159 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
160 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
161 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
162 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
163 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
165 TouchPoint point = data.hoverEvent.GetPoint(0);
166 DALI_TEST_EQUALS( TouchPoint::Started, point.state, TEST_LOCATION );
167 DALI_TEST_EQUALS( screenCoordinates, point.screen, TEST_LOCATION );
168 DALI_TEST_EQUALS( localCoordinates, point.local, 0.1f, TEST_LOCATION );
172 // Emit a motion signal
173 screenCoordinates.x = screenCoordinates.y = 11.0f;
174 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
175 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, screenCoordinates ) );
176 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
177 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
178 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
179 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
180 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
183 // Emit a finished signal
184 screenCoordinates.x = screenCoordinates.y = 12.0f;
185 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
186 application.ProcessEvent( GenerateSingleHover( TouchPoint::Finished, screenCoordinates ) );
187 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
188 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
189 DALI_TEST_EQUALS( TouchPoint::Finished, data.hoverEvent.points[0].state, TEST_LOCATION );
190 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
191 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
194 // Emit a started signal where the actor is not present
195 screenCoordinates.x = screenCoordinates.y = 200.0f;
196 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
197 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
201 int UtcDaliHoverOutsideCameraNearFarPlanes(void)
203 TestApplication application;
205 Stage stage = Stage::GetCurrent();
206 Vector2 stageSize = stage.GetSize();
208 Actor actor = Actor::New();
209 actor.SetSize(100.0f, 100.0f);
210 actor.SetAnchorPoint(AnchorPoint::CENTER);
211 actor.SetParentOrigin(ParentOrigin::CENTER);
215 application.SendNotification();
216 application.Render();
218 // Get the camera's near and far planes
219 RenderTaskList taskList = stage.GetRenderTaskList();
220 Dali::RenderTask task = taskList.GetTask(0);
221 CameraActor camera = task.GetCameraActor();
222 float nearPlane = camera.GetNearClippingPlane();
223 float farPlane = camera.GetFarClippingPlane();
225 // Calculate the current distance of the actor from the camera
226 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
227 float distance = (stageSize.y * 0.5f) / tanHalfFov;
229 // Connect to actor's hovered signal
231 HoverEventFunctor functor( data );
232 actor.HoveredSignal().Connect( &application, functor );
234 Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
236 // Emit a started signal
237 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
238 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
241 // Emit a started signal where actor is just at the camera's near plane
242 actor.SetZ(distance - nearPlane);
245 application.SendNotification();
246 application.Render();
248 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
249 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
252 // Emit a started signal where actor is closer than the camera's near plane
253 actor.SetZ((distance - nearPlane) + 1.0f);
256 application.SendNotification();
257 application.Render();
259 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
260 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
263 // Emit a started signal where actor is just at the camera's far plane
264 actor.SetZ(distance - farPlane);
267 application.SendNotification();
268 application.Render();
270 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
271 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
274 // Emit a started signal where actor is further than the camera's far plane
275 actor.SetZ((distance - farPlane) - 1.0f);
278 application.SendNotification();
279 application.Render();
281 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
282 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
287 int UtcDaliHoverEmitEmpty(void)
289 TestApplication application;
293 // Emit an empty HoverEvent
294 Integration::HoverEvent event;
295 application.ProcessEvent( event );
296 tet_result( TET_FAIL );
298 catch ( Dali::DaliException& e )
300 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
305 int UtcDaliHoverInterrupted(void)
307 TestApplication application;
309 Actor actor = Actor::New();
310 actor.SetSize(100.0f, 100.0f);
311 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
312 Stage::GetCurrent().Add(actor);
315 application.SendNotification();
316 application.Render();
318 // Connect to actor's hovered signal
320 HoverEventFunctor functor( data );
321 actor.HoveredSignal().Connect( &application, functor );
323 // Emit a started signal
324 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
325 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
326 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
329 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
330 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
331 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
332 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
335 // Emit another interrupted signal, our signal handler should not be called.
336 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
337 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
341 int UtcDaliHoverParentConsumer(void)
343 TestApplication application;
344 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
346 Actor actor = Actor::New();
347 actor.SetSize(100.0f, 100.0f);
348 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
349 Stage::GetCurrent().Add(actor);
352 application.SendNotification();
353 application.Render();
355 // Connect to actor's hovered signal
357 HoverEventFunctor functor( data, false );
358 actor.HoveredSignal().Connect( &application, functor );
360 // Connect to root actor's hovered signal
362 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
363 rootActor.HoveredSignal().Connect( &application, rootFunctor );
365 Vector2 screenCoordinates( 10.0f, 10.0f );
366 Vector2 actorCoordinates, rootCoordinates;
367 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
368 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
370 // Emit a started signal
371 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
372 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
373 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
374 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
375 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
376 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
377 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
378 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
379 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
380 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
381 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
382 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
383 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
387 // Emit a motion signal
388 screenCoordinates.x = screenCoordinates.y = 11.0f;
389 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
390 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
391 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, screenCoordinates ) );
392 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
393 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
394 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
395 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
396 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
397 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
398 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
399 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
400 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
401 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
402 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
403 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
407 // Emit a finished signal
408 screenCoordinates.x = screenCoordinates.y = 12.0f;
409 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
410 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
411 application.ProcessEvent( GenerateSingleHover( TouchPoint::Finished, screenCoordinates ) );
412 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
413 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
414 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
415 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
416 DALI_TEST_EQUALS( TouchPoint::Finished, data.hoverEvent.points[0].state, TEST_LOCATION );
417 DALI_TEST_EQUALS( TouchPoint::Finished, rootData.hoverEvent.points[0].state, TEST_LOCATION );
418 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
419 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
420 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
421 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
422 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
423 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
427 // Emit a started signal where the actor is not present, will hit the root actor though
428 screenCoordinates.x = screenCoordinates.y = 200.0f;
429 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
430 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
431 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
432 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
433 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
434 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
435 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
436 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
437 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
441 int UtcDaliHoverInterruptedParentConsumer(void)
443 TestApplication application;
444 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
446 Actor actor = Actor::New();
447 actor.SetSize(100.0f, 100.0f);
448 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
449 Stage::GetCurrent().Add(actor);
452 application.SendNotification();
453 application.Render();
455 // Connect to actor's hovered signal
457 HoverEventFunctor functor( data, false );
458 actor.HoveredSignal().Connect( &application, functor );
460 // Connect to root actor's hovered signal
462 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
463 rootActor.HoveredSignal().Connect( &application, rootFunctor );
465 // Emit a started signal
466 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
467 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
468 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
469 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
470 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
471 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
472 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
476 // Emit an interrupted signal
477 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
478 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
479 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
480 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
481 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
482 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
483 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
487 // Emit another started signal
488 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
489 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
490 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
491 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
492 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
496 // Remove actor from Stage
497 Stage::GetCurrent().Remove( actor );
500 application.SendNotification();
501 application.Render();
503 // Emit an interrupted signal, only root actor's signal should be called.
504 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
505 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
506 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
507 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
508 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
512 // Emit another interrupted state, none of the signal's should be called.
513 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
514 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
515 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
519 int UtcDaliHoverLeave(void)
521 TestApplication application;
523 Actor actor = Actor::New();
524 actor.SetSize(100.0f, 100.0f);
525 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
526 Stage::GetCurrent().Add(actor);
529 application.SendNotification();
530 application.Render();
532 // Connect to actor's hovered signal
534 HoverEventFunctor functor( data );
535 actor.HoveredSignal().Connect( &application, functor );
537 // Set actor to require leave events
538 actor.SetLeaveRequired( true );
540 // Emit a started signal
541 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
542 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
543 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
546 // Emit a motion signal outside of actor, should be signalled with a Leave
547 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
548 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
549 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
552 // Another motion outside of actor, no signalling
553 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
554 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
557 // Another motion event inside actor, signalled with motion
558 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
559 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
560 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
563 // We do not want to listen to leave events anymore
564 actor.SetLeaveRequired( false );
566 // Another motion event outside of actor, no signalling
567 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
568 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
573 int UtcDaliHoverLeaveParentConsumer(void)
575 TestApplication application;
576 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
578 Actor actor = Actor::New();
579 actor.SetSize(100.0f, 100.0f);
580 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
581 Stage::GetCurrent().Add(actor);
584 application.SendNotification();
585 application.Render();
587 // Connect to actor's hovered signal
589 HoverEventFunctor functor( data, false );
590 actor.HoveredSignal().Connect( &application, functor );
592 // Connect to root actor's hovered signal
594 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
595 rootActor.HoveredSignal().Connect( &application, rootFunctor );
597 // Set actor to require leave events
598 actor.SetLeaveRequired( true );
599 rootActor.SetLeaveRequired( true );
601 // Emit a started signal
602 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
603 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
604 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
605 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
606 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
607 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
608 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
612 // Emit a motion signal outside of actor, should be signalled with a Leave
613 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
614 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
615 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
616 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
617 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.hoverEvent.points[0].state, TEST_LOCATION );
618 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
619 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
623 // Another motion outside of actor, only rootActor signalled
624 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
625 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
626 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
627 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
628 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
632 // Another motion event inside actor, signalled with motion
633 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
634 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
635 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
636 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
637 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
638 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
639 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
643 // We do not want to listen to leave events of actor anymore
644 actor.SetLeaveRequired( false );
646 // Another motion event outside of root actor, only root signalled
647 Vector2 stageSize( Stage::GetCurrent().GetSize() );
648 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
649 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
650 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
651 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.hoverEvent.points[0].state, TEST_LOCATION );
655 int UtcDaliHoverActorBecomesInsensitive(void)
657 TestApplication application;
659 Actor actor = Actor::New();
660 actor.SetSize(100.0f, 100.0f);
661 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
662 Stage::GetCurrent().Add(actor);
665 application.SendNotification();
666 application.Render();
668 // Connect to actor's hovered signal
670 HoverEventFunctor functor( data );
671 actor.HoveredSignal().Connect( &application, functor );
673 // Emit a started signal
674 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
675 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
676 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
679 // Change actor to insensitive
680 actor.SetSensitive( false );
682 // Emit a motion signal, signalled with an interrupted
683 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
684 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
685 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
690 int UtcDaliHoverActorBecomesInsensitiveParentConsumer(void)
692 TestApplication application;
693 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
695 Actor actor = Actor::New();
696 actor.SetSize(100.0f, 100.0f);
697 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
698 Stage::GetCurrent().Add(actor);
701 application.SendNotification();
702 application.Render();
704 // Connect to actor's hovered signal
706 HoverEventFunctor functor( data, false );
707 actor.HoveredSignal().Connect( &application, functor );
709 // Connect to root actor's hovered signal
711 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
712 rootActor.HoveredSignal().Connect( &application, rootFunctor );
714 // Emit a started signal
715 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
716 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
717 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
718 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
719 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
720 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
721 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
725 // Remove actor from Stage
726 Stage::GetCurrent().Remove( actor );
729 application.SendNotification();
730 application.Render();
732 // Make root actor insensitive
733 rootActor.SetSensitive( false );
735 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
736 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
737 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
738 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
739 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
743 int UtcDaliHoverMultipleLayers(void)
745 TestApplication application;
746 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
748 // Connect to actor's hovered signal
750 HoverEventFunctor functor( data );
752 Layer layer1 ( Layer::New() );
753 layer1.SetSize(100.0f, 100.0f);
754 layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
755 Stage::GetCurrent().Add( layer1 );
757 Actor actor1 ( Actor::New() );
758 actor1.SetSize( 100.0f, 100.0f );
759 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
760 actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
761 layer1.Add( actor1 );
764 application.SendNotification();
765 application.Render();
767 // Connect to layer1 and actor1
768 layer1.HoveredSignal().Connect( &application, functor );
769 actor1.HoveredSignal().Connect( &application, functor );
771 // Hit in hittable area, actor1 should be hit
772 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
773 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
774 DALI_TEST_CHECK( data.hoveredActor == actor1 );
777 // Make layer1 insensitive, nothing should be hit
778 layer1.SetSensitive( false );
779 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
780 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
783 // Make layer1 sensitive again, again actor1 will be hit
784 layer1.SetSensitive( true );
785 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
786 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
787 DALI_TEST_CHECK( data.hoveredActor == actor1 );
790 // Make rootActor insensitive, nothing should be hit
791 rootActor.SetSensitive( false );
792 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
793 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
796 // Make rootActor sensitive
797 rootActor.SetSensitive( true );
800 Layer layer2 ( Layer::New() );
801 layer2.SetSize(100.0f, 100.0f );
802 layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
803 layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
804 Stage::GetCurrent().Add( layer2 );
806 Actor actor2 ( Actor::New() );
807 actor2.SetSize(100.0f, 100.0f);
808 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
809 layer2.Add( actor2 );
812 application.SendNotification();
813 application.Render();
815 // Connect to layer2 and actor2
816 layer2.HoveredSignal().Connect( &application, functor );
817 actor2.HoveredSignal().Connect( &application, functor );
819 // Emit an event, should hit layer2
820 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
821 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
822 //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
825 // Make layer2 insensitive, should hit actor1
826 layer2.SetSensitive( false );
827 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
828 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
829 DALI_TEST_CHECK( data.hoveredActor == actor1 );
832 // Make layer2 sensitive again, should hit layer2
833 layer2.SetSensitive( true );
834 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
835 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
836 //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
839 // Make layer2 invisible, render and notify
840 layer2.SetVisible( false );
841 application.SendNotification();
842 application.Render();
845 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
846 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
847 DALI_TEST_CHECK( data.hoveredActor == actor1 );
850 // Make rootActor invisible, render and notify
851 rootActor.SetVisible( false );
852 application.SendNotification();
853 application.Render();
855 // Should not hit anything
856 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
857 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
862 int UtcDaliHoverMultipleRenderTasks(void)
864 TestApplication application;
865 Stage stage ( Stage::GetCurrent() );
866 Vector2 stageSize ( stage.GetSize() );
868 Actor actor = Actor::New();
869 actor.SetSize(100.0f, 100.0f);
870 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
873 // Create render task
874 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
875 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
876 renderTask.SetViewport( viewport );
877 renderTask.SetInputEnabled( true );
880 application.SendNotification();
881 application.Render();
883 // Connect to actor's hovered signal
885 HoverEventFunctor functor( data );
886 actor.HoveredSignal().Connect( &application, functor );
888 // Emit a started signal
889 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
890 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
893 // Ensure renderTask actor can be hit too.
894 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
895 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
898 // Disable input on renderTask, should not be hittable
899 renderTask.SetInputEnabled( false );
900 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
901 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
906 int UtcDaliHoverMultipleRenderTasksWithChildLayer(void)
908 TestApplication application;
909 Stage stage ( Stage::GetCurrent() );
910 Vector2 stageSize ( stage.GetSize() );
912 Actor actor = Actor::New();
913 actor.SetSize(100.0f, 100.0f);
914 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
917 Layer layer = Layer::New();
918 layer.SetSize(100.0f, 100.0f);
919 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
922 // Create render task
923 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
924 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
925 renderTask.SetViewport( viewport );
926 renderTask.SetInputEnabled( true );
927 renderTask.SetSourceActor( actor );
930 application.SendNotification();
931 application.Render();
933 // Connect to layer's hovered signal
935 HoverEventFunctor functor( data );
936 actor.HoveredSignal().Connect( &application, functor );
937 layer.HoveredSignal().Connect( &application, functor );
939 // Emit a started signal
940 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
941 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
944 // Ensure renderTask actor can be hit too.
945 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
946 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
949 // Disable input on renderTask, should not be hittable
950 renderTask.SetInputEnabled( false );
951 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
952 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
957 int UtcDaliHoverOffscreenRenderTasks(void)
959 TestApplication application;
960 Stage stage ( Stage::GetCurrent() );
961 Vector2 stageSize ( stage.GetSize() );
963 // FrameBufferImage for offscreen RenderTask
964 FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
966 // Create a renderable actor to display the FrameBufferImage
967 Actor renderableActor = CreateRenderableActor( frameBufferImage );
968 renderableActor.SetParentOrigin(ParentOrigin::CENTER);
969 renderableActor.SetSize( stageSize.x, stageSize.y );
970 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
971 stage.Add( renderableActor );
973 Actor actor = Actor::New();
974 actor.SetSize(100.0f, 100.0f);
975 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
977 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
979 stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
981 // Create a RenderTask
982 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
983 renderTask.SetSourceActor( actor );
984 renderTask.SetTargetFrameBuffer( frameBufferImage );
985 renderTask.SetInputEnabled( true );
987 // Create another RenderTask
988 RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
989 renderTask2.SetInputEnabled( true );
992 application.SendNotification();
993 application.Render();
995 // Connect to actor's hovered signal
997 HoverEventFunctor functor( data );
998 actor.HoveredSignal().Connect( &application, functor );
1000 // Emit a started signal
1001 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1002 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1007 int UtcDaliHoverMultipleRenderableActors(void)
1009 TestApplication application;
1010 Stage stage ( Stage::GetCurrent() );
1011 Vector2 stageSize ( stage.GetSize() );
1013 Actor parent = CreateRenderableActor();
1014 parent.SetSize( 100.0f, 100.0f );
1015 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1018 Actor actor = CreateRenderableActor();
1019 actor.SetSize( 100.0f, 100.0f );
1020 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1023 // Render and notify
1024 application.SendNotification();
1025 application.Render();
1027 // Connect to layer's hovered signal
1029 HoverEventFunctor functor( data );
1030 parent.HoveredSignal().Connect( &application, functor );
1031 actor.HoveredSignal().Connect( &application, functor );
1033 // Emit a started signal
1034 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1035 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1036 DALI_TEST_CHECK( actor == data.hoveredActor );
1040 int UtcDaliHoverActorRemovedInSignal(void)
1042 TestApplication application;
1044 Actor actor = Actor::New();
1045 actor.SetSize(100.0f, 100.0f);
1046 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1047 Stage::GetCurrent().Add(actor);
1049 // Render and notify
1050 application.SendNotification();
1051 application.Render();
1053 // Connect to actor's hovered signal
1055 RemoveActorFunctor functor( data );
1056 actor.HoveredSignal().Connect( &application, functor );
1058 // Register for leave events
1059 actor.SetLeaveRequired( true );
1061 // Emit a started signal
1062 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1063 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1066 // Re-add, render and notify
1067 Stage::GetCurrent().Add(actor);
1068 application.SendNotification();
1069 application.Render();
1071 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1072 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1073 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1076 // Emit a started signal
1077 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1078 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1081 // Render and notify
1082 application.SendNotification();
1083 application.Render();
1085 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1086 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1087 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1090 // Re-add actor back to stage, render and notify
1091 Stage::GetCurrent().Add(actor);
1092 application.SendNotification();
1093 application.Render();
1095 // Emit another started event
1096 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1097 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1100 // Completely delete the actor
1103 // Emit event, should not crash and should not receive an event.
1104 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1105 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1109 int UtcDaliHoverActorSignalNotConsumed(void)
1111 TestApplication application;
1113 Actor actor = Actor::New();
1114 actor.SetSize(100.0f, 100.0f);
1115 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1116 Stage::GetCurrent().Add(actor);
1118 // Render and notify
1119 application.SendNotification();
1120 application.Render();
1122 // Connect to actor's hovered signal
1124 HoverEventFunctor functor( data, false );
1125 actor.HoveredSignal().Connect( &application, functor );
1127 // Emit a started signal
1128 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1129 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1133 int UtcDaliHoverActorUnStaged(void)
1135 TestApplication application;
1137 Actor actor = Actor::New();
1138 actor.SetSize(100.0f, 100.0f);
1139 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1140 Stage::GetCurrent().Add(actor);
1142 // Render and notify
1143 application.SendNotification();
1144 application.Render();
1146 // Connect to actor's hovered signal
1148 HoverEventFunctor functor( data );
1149 actor.HoveredSignal().Connect( &application, functor );
1151 // Emit a started signal
1152 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1153 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1156 // Remove actor from stage
1157 Stage::GetCurrent().Remove( actor );
1159 // Render and notify
1160 application.SendNotification();
1161 application.Render();
1163 // Emit a move at the same point, we should not be signalled.
1164 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1165 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1170 int UtcDaliHoverSystemOverlayActor(void)
1172 TestApplication application;
1173 Dali::Integration::Core& core( application.GetCore() );
1174 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1176 Dali::RenderTaskList overlayRenderTaskList = Integration::RenderTaskList::New();
1177 Dali::Actor overlayRootActor = systemOverlay.GetDefaultRootActor();
1178 Dali::CameraActor overlayCameraActor = systemOverlay.GetDefaultCameraActor();
1179 Integration::RenderTaskList::CreateTask( overlayRenderTaskList, overlayRootActor, overlayCameraActor );
1180 systemOverlay.SetOverlayRenderTasks( overlayRenderTaskList );
1182 // Create an actor and add it to the system overlay.
1183 Actor systemActor = Actor::New();
1184 systemActor.SetSize(100.0f, 100.0f);
1185 systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1186 systemOverlay.Add( systemActor );
1188 // Create an actor and add it to the stage as per normal, same position and size as systemActor
1189 Actor actor = Actor::New();
1190 actor.SetSize(100.0f, 100.0f);
1191 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1192 Stage::GetCurrent().Add(actor);
1194 // Connect to the hover signals.
1196 HoverEventFunctor functor( data );
1197 systemActor.HoveredSignal().Connect( &application, functor );
1198 actor.HoveredSignal().Connect( &application, functor );
1200 // Render and notify
1201 application.SendNotification();
1202 application.Render();
1204 // Emit a started signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1205 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1206 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1207 DALI_TEST_CHECK( systemActor == data.hoveredActor );
1211 int UtcDaliHoverLeaveActorReadded(void)
1213 TestApplication application;
1214 Stage stage = Stage::GetCurrent();
1216 Actor actor = Actor::New();
1217 actor.SetSize(100.0f, 100.0f);
1218 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1221 // Set actor to receive hover-events
1222 actor.SetLeaveRequired( true );
1224 // Render and notify
1225 application.SendNotification();
1226 application.Render();
1228 // Connect to actor's hovered signal
1230 HoverEventFunctor functor( data );
1231 actor.HoveredSignal().Connect( &application, functor );
1233 // Emit a started and motion
1234 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1235 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1236 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1239 // Remove actor from stage and add again
1240 stage.Remove( actor );
1243 // Emit a motion within the actor's bounds
1244 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1245 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1248 // Emit a motion outside the actor's bounds
1249 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1250 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1251 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
1257 int UtcDaliHoverClippingActor(void)
1259 TestApplication application;
1260 Stage stage = Stage::GetCurrent();
1262 Actor actor = Actor::New();
1263 actor.SetSize( 100.0f, 100.0f );
1264 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1267 Actor clippingActor = Actor::New();
1268 clippingActor.SetSize( 50.0f, 50.0f );
1269 clippingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1270 clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1271 stage.Add( clippingActor );
1273 // Add a child to the clipped region.
1274 Actor clippingChild = Actor::New();
1275 clippingChild.SetSize( 50.0f, 50.0f );
1276 clippingChild.SetPosition( 25.0f, 25.0f );
1277 clippingChild.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1278 clippingActor.Add( clippingChild );
1280 // Render and notify.
1281 application.SendNotification();
1282 application.Render();
1284 // Connect to actor's hovered signal.
1286 HoverEventFunctor functor( data );
1287 actor.HoveredSignal().Connect( &application, functor );
1289 // Emit an event within clipped area - no hit.
1290 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1291 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1294 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1295 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 60.0f, 60.0f ) ) );
1296 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1299 clippingChild.HoveredSignal().Connect( &application, functor );
1301 // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1302 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 30.0f, 30.0f ) ) );
1303 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );