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, const Vector2& screenPosition )
122 Integration::HoverEvent hoverEvent;
123 Integration::Point point;
124 point.SetState( static_cast< PointState::Type >( state ) );
125 point.SetScreenPosition( screenPosition );
126 hoverEvent.points.push_back( point );
132 ///////////////////////////////////////////////////////////////////////////////
134 int UtcDaliHoverNormalProcessing(void)
136 TestApplication application;
138 Actor actor = Actor::New();
139 actor.SetSize(100.0f, 100.0f);
140 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
141 Stage::GetCurrent().Add(actor);
144 application.SendNotification();
145 application.Render();
147 // Connect to actor's hovered signal
149 HoverEventFunctor functor( data );
150 actor.HoveredSignal().Connect( &application, functor );
152 Vector2 screenCoordinates( 10.0f, 10.0f );
153 Vector2 localCoordinates;
154 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
156 // Emit a started signal
157 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
158 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
159 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
160 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
161 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
162 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
164 TouchPoint point = data.hoverEvent.GetPoint(0);
165 DALI_TEST_EQUALS( TouchPoint::Started, point.state, TEST_LOCATION );
166 DALI_TEST_EQUALS( screenCoordinates, point.screen, TEST_LOCATION );
167 DALI_TEST_EQUALS( localCoordinates, point.local, 0.1f, TEST_LOCATION );
171 // Emit a motion signal
172 screenCoordinates.x = screenCoordinates.y = 11.0f;
173 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
174 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, screenCoordinates ) );
175 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
176 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
177 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
178 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
179 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
182 // Emit a finished signal
183 screenCoordinates.x = screenCoordinates.y = 12.0f;
184 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
185 application.ProcessEvent( GenerateSingleHover( TouchPoint::Finished, screenCoordinates ) );
186 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
187 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
188 DALI_TEST_EQUALS( TouchPoint::Finished, data.hoverEvent.points[0].state, TEST_LOCATION );
189 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
190 DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
193 // Emit a started signal where the actor is not present
194 screenCoordinates.x = screenCoordinates.y = 200.0f;
195 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
196 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
200 int UtcDaliHoverOutsideCameraNearFarPlanes(void)
202 TestApplication application;
204 Stage stage = Stage::GetCurrent();
205 Vector2 stageSize = stage.GetSize();
207 Actor actor = Actor::New();
208 actor.SetSize(100.0f, 100.0f);
209 actor.SetAnchorPoint(AnchorPoint::CENTER);
210 actor.SetParentOrigin(ParentOrigin::CENTER);
214 application.SendNotification();
215 application.Render();
217 // Get the camera's near and far planes
218 RenderTaskList taskList = stage.GetRenderTaskList();
219 Dali::RenderTask task = taskList.GetTask(0);
220 CameraActor camera = task.GetCameraActor();
221 float nearPlane = camera.GetNearClippingPlane();
222 float farPlane = camera.GetFarClippingPlane();
224 // Calculate the current distance of the actor from the camera
225 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
226 float distance = (stageSize.y * 0.5f) / tanHalfFov;
228 // Connect to actor's hovered signal
230 HoverEventFunctor functor( data );
231 actor.HoveredSignal().Connect( &application, functor );
233 Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
235 // Emit a started signal
236 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
237 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
240 // Emit a started signal where actor is just at the camera's near plane
241 actor.SetZ(distance - nearPlane);
244 application.SendNotification();
245 application.Render();
247 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
248 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
251 // Emit a started signal where actor is closer than the camera's near plane
252 actor.SetZ((distance - nearPlane) + 1.0f);
255 application.SendNotification();
256 application.Render();
258 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
259 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
262 // Emit a started signal where actor is just at the camera's far plane
263 actor.SetZ(distance - farPlane);
266 application.SendNotification();
267 application.Render();
269 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
270 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
273 // Emit a started signal where actor is further than the camera's far plane
274 actor.SetZ((distance - farPlane) - 1.0f);
277 application.SendNotification();
278 application.Render();
280 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
281 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
286 int UtcDaliHoverEmitEmpty(void)
288 TestApplication application;
292 // Emit an empty HoverEvent
293 Integration::HoverEvent event;
294 application.ProcessEvent( event );
295 tet_result( TET_FAIL );
297 catch ( Dali::DaliException& e )
299 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
304 int UtcDaliHoverInterrupted(void)
306 TestApplication application;
308 Actor actor = Actor::New();
309 actor.SetSize(100.0f, 100.0f);
310 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
311 Stage::GetCurrent().Add(actor);
314 application.SendNotification();
315 application.Render();
317 // Connect to actor's hovered signal
319 HoverEventFunctor functor( data );
320 actor.HoveredSignal().Connect( &application, functor );
322 // Emit a started signal
323 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
324 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
325 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
328 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
329 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
330 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
331 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
334 // Emit another interrupted signal, our signal handler should not be called.
335 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
336 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
340 int UtcDaliHoverParentConsumer(void)
342 TestApplication application;
343 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
345 Actor actor = Actor::New();
346 actor.SetSize(100.0f, 100.0f);
347 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
348 Stage::GetCurrent().Add(actor);
351 application.SendNotification();
352 application.Render();
354 // Connect to actor's hovered signal
356 HoverEventFunctor functor( data, false );
357 actor.HoveredSignal().Connect( &application, functor );
359 // Connect to root actor's hovered signal
361 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
362 rootActor.HoveredSignal().Connect( &application, rootFunctor );
364 Vector2 screenCoordinates( 10.0f, 10.0f );
365 Vector2 actorCoordinates, rootCoordinates;
366 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
367 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
369 // Emit a started signal
370 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
371 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
372 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
373 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
374 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
375 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
376 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
377 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
378 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
379 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
380 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
381 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
382 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
386 // Emit a motion signal
387 screenCoordinates.x = screenCoordinates.y = 11.0f;
388 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
389 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
390 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, screenCoordinates ) );
391 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
392 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
393 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
394 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
395 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
396 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
397 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
398 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
399 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
400 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
401 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
402 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
406 // Emit a finished signal
407 screenCoordinates.x = screenCoordinates.y = 12.0f;
408 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
409 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
410 application.ProcessEvent( GenerateSingleHover( TouchPoint::Finished, screenCoordinates ) );
411 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
412 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
413 DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
414 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
415 DALI_TEST_EQUALS( TouchPoint::Finished, data.hoverEvent.points[0].state, TEST_LOCATION );
416 DALI_TEST_EQUALS( TouchPoint::Finished, rootData.hoverEvent.points[0].state, TEST_LOCATION );
417 DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
418 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
419 DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
420 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
421 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
422 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
426 // Emit a started signal where the actor is not present, will hit the root actor though
427 screenCoordinates.x = screenCoordinates.y = 200.0f;
428 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
429 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
430 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
431 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
432 DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
433 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
434 DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
435 DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
436 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
440 int UtcDaliHoverInterruptedParentConsumer(void)
442 TestApplication application;
443 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
445 Actor actor = Actor::New();
446 actor.SetSize(100.0f, 100.0f);
447 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
448 Stage::GetCurrent().Add(actor);
451 application.SendNotification();
452 application.Render();
454 // Connect to actor's hovered signal
456 HoverEventFunctor functor( data, false );
457 actor.HoveredSignal().Connect( &application, functor );
459 // Connect to root actor's hovered signal
461 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
462 rootActor.HoveredSignal().Connect( &application, rootFunctor );
464 // Emit a started signal
465 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
466 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
467 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
468 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
469 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
470 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
471 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
475 // Emit an interrupted signal
476 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
477 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
478 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
479 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
480 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
481 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
482 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
486 // Emit another started signal
487 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
488 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
489 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
490 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
491 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
495 // Remove actor from Stage
496 Stage::GetCurrent().Remove( actor );
499 application.SendNotification();
500 application.Render();
502 // Emit an interrupted signal, only root actor's signal should be called.
503 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
504 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
505 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
506 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
507 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
511 // Emit another interrupted state, none of the signal's should be called.
512 application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
513 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
514 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
518 int UtcDaliHoverLeave(void)
520 TestApplication application;
522 Actor actor = Actor::New();
523 actor.SetSize(100.0f, 100.0f);
524 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
525 Stage::GetCurrent().Add(actor);
528 application.SendNotification();
529 application.Render();
531 // Connect to actor's hovered signal
533 HoverEventFunctor functor( data );
534 actor.HoveredSignal().Connect( &application, functor );
536 // Set actor to require leave events
537 actor.SetLeaveRequired( true );
539 // Emit a started signal
540 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
541 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
542 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
545 // Emit a motion signal outside of actor, should be signalled with a Leave
546 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
547 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
548 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
551 // Another motion outside of actor, no signalling
552 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
553 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
556 // Another motion event inside actor, signalled with motion
557 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
558 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
559 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
562 // We do not want to listen to leave events anymore
563 actor.SetLeaveRequired( false );
565 // Another motion event outside of actor, no signalling
566 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
567 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
572 int UtcDaliHoverLeaveParentConsumer(void)
574 TestApplication application;
575 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
577 Actor actor = Actor::New();
578 actor.SetSize(100.0f, 100.0f);
579 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
580 Stage::GetCurrent().Add(actor);
583 application.SendNotification();
584 application.Render();
586 // Connect to actor's hovered signal
588 HoverEventFunctor functor( data, false );
589 actor.HoveredSignal().Connect( &application, functor );
591 // Connect to root actor's hovered signal
593 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
594 rootActor.HoveredSignal().Connect( &application, rootFunctor );
596 // Set actor to require leave events
597 actor.SetLeaveRequired( true );
598 rootActor.SetLeaveRequired( true );
600 // Emit a started signal
601 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
602 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
603 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
604 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
605 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
606 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
607 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
611 // Emit a motion signal outside of actor, should be signalled with a Leave
612 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
613 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
614 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
615 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
616 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.hoverEvent.points[0].state, TEST_LOCATION );
617 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
618 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
622 // Another motion outside of actor, only rootActor signalled
623 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
624 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
625 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
626 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
627 DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
631 // Another motion event inside actor, signalled with motion
632 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
633 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
634 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
635 DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
636 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
637 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
638 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
642 // We do not want to listen to leave events of actor anymore
643 actor.SetLeaveRequired( false );
645 // Another motion event outside of root actor, only root signalled
646 Vector2 stageSize( Stage::GetCurrent().GetSize() );
647 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
648 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
649 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
650 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.hoverEvent.points[0].state, TEST_LOCATION );
654 int UtcDaliHoverActorBecomesInsensitive(void)
656 TestApplication application;
658 Actor actor = Actor::New();
659 actor.SetSize(100.0f, 100.0f);
660 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
661 Stage::GetCurrent().Add(actor);
664 application.SendNotification();
665 application.Render();
667 // Connect to actor's hovered signal
669 HoverEventFunctor functor( data );
670 actor.HoveredSignal().Connect( &application, functor );
672 // Emit a started signal
673 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
674 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
675 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
678 // Change actor to insensitive
679 actor.SetSensitive( false );
681 // Emit a motion signal, signalled with an interrupted
682 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
683 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
684 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
689 int UtcDaliHoverActorBecomesInsensitiveParentConsumer(void)
691 TestApplication application;
692 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
694 Actor actor = Actor::New();
695 actor.SetSize(100.0f, 100.0f);
696 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
697 Stage::GetCurrent().Add(actor);
700 application.SendNotification();
701 application.Render();
703 // Connect to actor's hovered signal
705 HoverEventFunctor functor( data, false );
706 actor.HoveredSignal().Connect( &application, functor );
708 // Connect to root actor's hovered signal
710 HoverEventFunctor rootFunctor( rootData ); // Consumes signal
711 rootActor.HoveredSignal().Connect( &application, rootFunctor );
713 // Emit a started signal
714 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
715 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
716 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
717 DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
718 DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
719 DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
720 DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
724 // Remove actor from Stage
725 Stage::GetCurrent().Remove( actor );
728 application.SendNotification();
729 application.Render();
731 // Make root actor insensitive
732 rootActor.SetSensitive( false );
734 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
735 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
736 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
737 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
738 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
742 int UtcDaliHoverMultipleLayers(void)
744 TestApplication application;
745 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
747 // Connect to actor's hovered signal
749 HoverEventFunctor functor( data );
751 Layer layer1 ( Layer::New() );
752 layer1.SetSize(100.0f, 100.0f);
753 layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
754 Stage::GetCurrent().Add( layer1 );
756 Actor actor1 ( Actor::New() );
757 actor1.SetSize( 100.0f, 100.0f );
758 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
759 actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
760 layer1.Add( actor1 );
763 application.SendNotification();
764 application.Render();
766 // Connect to layer1 and actor1
767 layer1.HoveredSignal().Connect( &application, functor );
768 actor1.HoveredSignal().Connect( &application, functor );
770 // Hit in hittable area, actor1 should be hit
771 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
772 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
773 DALI_TEST_CHECK( data.hoveredActor == actor1 );
776 // Make layer1 insensitive, nothing should be hit
777 layer1.SetSensitive( false );
778 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
779 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
782 // Make layer1 sensitive again, again actor1 will be hit
783 layer1.SetSensitive( true );
784 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
785 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
786 DALI_TEST_CHECK( data.hoveredActor == actor1 );
789 // Make rootActor insensitive, nothing should be hit
790 rootActor.SetSensitive( false );
791 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
792 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
795 // Make rootActor sensitive
796 rootActor.SetSensitive( true );
799 Layer layer2 ( Layer::New() );
800 layer2.SetSize(100.0f, 100.0f );
801 layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
802 layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
803 Stage::GetCurrent().Add( layer2 );
805 Actor actor2 ( Actor::New() );
806 actor2.SetSize(100.0f, 100.0f);
807 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
808 layer2.Add( actor2 );
811 application.SendNotification();
812 application.Render();
814 // Connect to layer2 and actor2
815 layer2.HoveredSignal().Connect( &application, functor );
816 actor2.HoveredSignal().Connect( &application, functor );
818 // Emit an event, should hit layer2
819 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
820 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
821 //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
824 // Make layer2 insensitive, should hit actor1
825 layer2.SetSensitive( false );
826 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
827 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
828 DALI_TEST_CHECK( data.hoveredActor == actor1 );
831 // Make layer2 sensitive again, should hit layer2
832 layer2.SetSensitive( true );
833 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
834 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
835 //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
838 // Make layer2 invisible, render and notify
839 layer2.SetVisible( false );
840 application.SendNotification();
841 application.Render();
844 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
845 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
846 DALI_TEST_CHECK( data.hoveredActor == actor1 );
849 // Make rootActor invisible, render and notify
850 rootActor.SetVisible( false );
851 application.SendNotification();
852 application.Render();
854 // Should not hit anything
855 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
856 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
861 int UtcDaliHoverMultipleRenderTasks(void)
863 TestApplication application;
864 Stage stage ( Stage::GetCurrent() );
865 Vector2 stageSize ( stage.GetSize() );
867 Actor actor = Actor::New();
868 actor.SetSize(100.0f, 100.0f);
869 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
872 // Create render task
873 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
874 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
875 renderTask.SetViewport( viewport );
876 renderTask.SetInputEnabled( true );
879 application.SendNotification();
880 application.Render();
882 // Connect to actor's hovered signal
884 HoverEventFunctor functor( data );
885 actor.HoveredSignal().Connect( &application, functor );
887 // Emit a started signal
888 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
889 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
892 // Ensure renderTask actor can be hit too.
893 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
894 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
897 // Disable input on renderTask, should not be hittable
898 renderTask.SetInputEnabled( false );
899 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
900 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
905 int UtcDaliHoverMultipleRenderTasksWithChildLayer(void)
907 TestApplication application;
908 Stage stage ( Stage::GetCurrent() );
909 Vector2 stageSize ( stage.GetSize() );
911 Actor actor = Actor::New();
912 actor.SetSize(100.0f, 100.0f);
913 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
916 Layer layer = Layer::New();
917 layer.SetSize(100.0f, 100.0f);
918 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
921 // Create render task
922 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
923 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
924 renderTask.SetViewport( viewport );
925 renderTask.SetInputEnabled( true );
926 renderTask.SetSourceActor( actor );
929 application.SendNotification();
930 application.Render();
932 // Connect to layer's hovered signal
934 HoverEventFunctor functor( data );
935 actor.HoveredSignal().Connect( &application, functor );
936 layer.HoveredSignal().Connect( &application, functor );
938 // Emit a started signal
939 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
940 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
943 // Ensure renderTask actor can be hit too.
944 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
945 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
948 // Disable input on renderTask, should not be hittable
949 renderTask.SetInputEnabled( false );
950 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
951 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
956 int UtcDaliHoverOffscreenRenderTasks(void)
958 TestApplication application;
959 Stage stage ( Stage::GetCurrent() );
960 Vector2 stageSize ( stage.GetSize() );
962 // FrameBufferImage for offscreen RenderTask
963 FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
965 // Create a renderable actor to display the FrameBufferImage
966 Actor renderableActor = CreateRenderableActor( frameBufferImage );
967 renderableActor.SetParentOrigin(ParentOrigin::CENTER);
968 renderableActor.SetSize( stageSize.x, stageSize.y );
969 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
970 stage.Add( renderableActor );
972 Actor actor = Actor::New();
973 actor.SetSize(100.0f, 100.0f);
974 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
976 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
978 stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
980 // Create a RenderTask
981 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
982 renderTask.SetSourceActor( actor );
983 renderTask.SetTargetFrameBuffer( frameBufferImage );
984 renderTask.SetInputEnabled( true );
986 // Create another RenderTask
987 RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
988 renderTask2.SetInputEnabled( true );
991 application.SendNotification();
992 application.Render();
994 // Connect to actor's hovered signal
996 HoverEventFunctor functor( data );
997 actor.HoveredSignal().Connect( &application, functor );
999 // Emit a started signal
1000 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1001 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1006 int UtcDaliHoverMultipleRenderableActors(void)
1008 TestApplication application;
1009 Stage stage ( Stage::GetCurrent() );
1010 Vector2 stageSize ( stage.GetSize() );
1012 Actor parent = CreateRenderableActor();
1013 parent.SetSize( 100.0f, 100.0f );
1014 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1017 Actor actor = CreateRenderableActor();
1018 actor.SetSize( 100.0f, 100.0f );
1019 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1022 // Render and notify
1023 application.SendNotification();
1024 application.Render();
1026 // Connect to layer's hovered signal
1028 HoverEventFunctor functor( data );
1029 parent.HoveredSignal().Connect( &application, functor );
1030 actor.HoveredSignal().Connect( &application, functor );
1032 // Emit a started signal
1033 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1034 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1035 DALI_TEST_CHECK( actor == data.hoveredActor );
1039 int UtcDaliHoverActorRemovedInSignal(void)
1041 TestApplication application;
1043 Actor actor = Actor::New();
1044 actor.SetSize(100.0f, 100.0f);
1045 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1046 Stage::GetCurrent().Add(actor);
1048 // Render and notify
1049 application.SendNotification();
1050 application.Render();
1052 // Connect to actor's hovered signal
1054 RemoveActorFunctor functor( data );
1055 actor.HoveredSignal().Connect( &application, functor );
1057 // Register for leave events
1058 actor.SetLeaveRequired( true );
1060 // Emit a started signal
1061 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1062 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1065 // Re-add, render and notify
1066 Stage::GetCurrent().Add(actor);
1067 application.SendNotification();
1068 application.Render();
1070 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1071 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1072 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1075 // Emit a started signal
1076 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1077 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1080 // Render and notify
1081 application.SendNotification();
1082 application.Render();
1084 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1085 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1086 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1089 // Re-add actor back to stage, render and notify
1090 Stage::GetCurrent().Add(actor);
1091 application.SendNotification();
1092 application.Render();
1094 // Emit another started event
1095 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1096 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1099 // Completely delete the actor
1102 // Emit event, should not crash and should not receive an event.
1103 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1104 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1108 int UtcDaliHoverActorSignalNotConsumed(void)
1110 TestApplication application;
1112 Actor actor = Actor::New();
1113 actor.SetSize(100.0f, 100.0f);
1114 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1115 Stage::GetCurrent().Add(actor);
1117 // Render and notify
1118 application.SendNotification();
1119 application.Render();
1121 // Connect to actor's hovered signal
1123 HoverEventFunctor functor( data, false );
1124 actor.HoveredSignal().Connect( &application, functor );
1126 // Emit a started signal
1127 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1128 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1132 int UtcDaliHoverActorUnStaged(void)
1134 TestApplication application;
1136 Actor actor = Actor::New();
1137 actor.SetSize(100.0f, 100.0f);
1138 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1139 Stage::GetCurrent().Add(actor);
1141 // Render and notify
1142 application.SendNotification();
1143 application.Render();
1145 // Connect to actor's hovered signal
1147 HoverEventFunctor functor( data );
1148 actor.HoveredSignal().Connect( &application, functor );
1150 // Emit a started signal
1151 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1152 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1155 // Remove actor from stage
1156 Stage::GetCurrent().Remove( actor );
1158 // Render and notify
1159 application.SendNotification();
1160 application.Render();
1162 // Emit a move at the same point, we should not be signalled.
1163 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1164 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1169 int UtcDaliHoverSystemOverlayActor(void)
1171 TestApplication application;
1172 Dali::Integration::Core& core( application.GetCore() );
1173 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1174 systemOverlay.GetOverlayRenderTasks().CreateTask();
1176 // Create an actor and add it to the system overlay.
1177 Actor systemActor = Actor::New();
1178 systemActor.SetSize(100.0f, 100.0f);
1179 systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1180 systemOverlay.Add( systemActor );
1182 // Create an actor and add it to the stage as per normal, same position and size as systemActor
1183 Actor actor = Actor::New();
1184 actor.SetSize(100.0f, 100.0f);
1185 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1186 Stage::GetCurrent().Add(actor);
1188 // Connect to the hover signals.
1190 HoverEventFunctor functor( data );
1191 systemActor.HoveredSignal().Connect( &application, functor );
1192 actor.HoveredSignal().Connect( &application, functor );
1194 // Render and notify
1195 application.SendNotification();
1196 application.Render();
1198 // Emit a started signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1199 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1200 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1201 DALI_TEST_CHECK( systemActor == data.hoveredActor );
1205 int UtcDaliHoverLeaveActorReadded(void)
1207 TestApplication application;
1208 Stage stage = Stage::GetCurrent();
1210 Actor actor = Actor::New();
1211 actor.SetSize(100.0f, 100.0f);
1212 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1215 // Set actor to receive hover-events
1216 actor.SetLeaveRequired( true );
1218 // Render and notify
1219 application.SendNotification();
1220 application.Render();
1222 // Connect to actor's hovered signal
1224 HoverEventFunctor functor( data );
1225 actor.HoveredSignal().Connect( &application, functor );
1227 // Emit a started and motion
1228 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1229 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1230 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1233 // Remove actor from stage and add again
1234 stage.Remove( actor );
1237 // Emit a motion within the actor's bounds
1238 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1239 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1242 // Emit a motion outside the actor's bounds
1243 application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1244 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1245 DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
1251 int UtcDaliHoverClippingActor(void)
1253 TestApplication application;
1254 Stage stage = Stage::GetCurrent();
1256 Actor actor = Actor::New();
1257 actor.SetSize( 100.0f, 100.0f );
1258 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1261 Actor clippingActor = Actor::New();
1262 clippingActor.SetSize( 50.0f, 50.0f );
1263 clippingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1264 clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1265 stage.Add( clippingActor );
1267 // Add a child to the clipped region.
1268 Actor clippingChild = Actor::New();
1269 clippingChild.SetSize( 50.0f, 50.0f );
1270 clippingChild.SetPosition( 25.0f, 25.0f );
1271 clippingChild.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1272 clippingActor.Add( clippingChild );
1274 // Render and notify.
1275 application.SendNotification();
1276 application.Render();
1278 // Connect to actor's hovered signal.
1280 HoverEventFunctor functor( data );
1281 actor.HoveredSignal().Connect( &application, functor );
1283 // Emit an event within clipped area - no hit.
1284 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1285 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1288 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1289 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 60.0f, 60.0f ) ) );
1290 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1293 clippingChild.HoveredSignal().Connect( &application, functor );
1295 // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1296 application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 30.0f, 30.0f ) ) );
1297 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );