[3.0] Clipping API feature in Actor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-HoverProcessing.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
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>
25
26 using namespace Dali;
27
28 void utc_dali_hover_processing_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_hover_processing_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 ///////////////////////////////////////////////////////////////////////////////
39
40 namespace
41 {
42
43 // Stores data that is populated in the callback and will be read by the TET cases
44 struct SignalData
45 {
46   SignalData()
47   : functorCalled( false ),
48     hoverEvent(),
49     hoveredActor()
50   {
51   }
52
53   void Reset()
54   {
55     functorCalled = false;
56
57     hoverEvent.time = 0u;
58     hoverEvent.points.clear();
59
60     hoveredActor.Reset();
61   }
62
63   bool functorCalled;
64   HoverEvent hoverEvent;
65   Actor hoveredActor;
66 };
67
68 // Functor that sets the data when called
69 struct HoverEventFunctor
70 {
71   /**
72    * Constructor.
73    * @param[in]  data         Reference to the data to store callback information.
74    * @param[in]  returnValue  What the functor should return.
75    */
76   HoverEventFunctor( SignalData& data, bool returnValue = true )
77   : signalData( data ),
78     returnValue( returnValue )
79   {
80   }
81
82   bool operator()( Actor actor, const HoverEvent& hoverEvent )
83   {
84     signalData.functorCalled = true;
85     signalData.hoveredActor = actor;
86     signalData.hoverEvent = hoverEvent;
87
88     return returnValue;
89   }
90
91   SignalData& signalData;
92   bool returnValue;
93 };
94
95 // Functor that removes the actor when called.
96 struct RemoveActorFunctor : public HoverEventFunctor
97 {
98   /**
99    * Constructor.
100    * @param[in]  data         Reference to the data to store callback information.
101    * @param[in]  returnValue  What the functor should return.
102    */
103   RemoveActorFunctor( SignalData& data, bool returnValue = true )
104   : HoverEventFunctor( data, returnValue )
105   {
106   }
107
108   bool operator()( Actor actor, const HoverEvent& hoverEvent )
109   {
110     Actor parent( actor.GetParent() );
111     if ( parent )
112     {
113       parent.Remove( actor );
114     }
115
116     return HoverEventFunctor::operator()( actor, hoverEvent );
117   }
118 };
119
120 Integration::HoverEvent GenerateSingleHover( TouchPoint::State state, const Vector2& screenPosition )
121 {
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 );
127   return hoverEvent;
128 }
129
130 } // anon namespace
131
132 ///////////////////////////////////////////////////////////////////////////////
133
134 int UtcDaliHoverNormalProcessing(void)
135 {
136   TestApplication application;
137
138   Actor actor = Actor::New();
139   actor.SetSize(100.0f, 100.0f);
140   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
141   Stage::GetCurrent().Add(actor);
142
143   // Render and notify
144   application.SendNotification();
145   application.Render();
146
147   // Connect to actor's hovered signal
148   SignalData data;
149   HoverEventFunctor functor( data );
150   actor.HoveredSignal().Connect( &application, functor );
151
152   Vector2 screenCoordinates( 10.0f, 10.0f );
153   Vector2 localCoordinates;
154   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
155
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 );
163
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 );
168
169   data.Reset();
170
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 );
180   data.Reset();
181
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 );
191   data.Reset();
192
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 );
197   END_TEST;
198 }
199
200 int UtcDaliHoverOutsideCameraNearFarPlanes(void)
201 {
202   TestApplication application;
203
204   Stage stage = Stage::GetCurrent();
205   Vector2 stageSize = stage.GetSize();
206
207   Actor actor = Actor::New();
208   actor.SetSize(100.0f, 100.0f);
209   actor.SetAnchorPoint(AnchorPoint::CENTER);
210   actor.SetParentOrigin(ParentOrigin::CENTER);
211   stage.Add(actor);
212
213   // Render and notify
214   application.SendNotification();
215   application.Render();
216
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();
223
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;
227
228   // Connect to actor's hovered signal
229   SignalData data;
230   HoverEventFunctor functor( data );
231   actor.HoveredSignal().Connect( &application, functor );
232
233   Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
234
235   // Emit a started signal
236   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
237   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
238   data.Reset();
239
240   // Emit a started signal where actor is just at the camera's near plane
241   actor.SetZ(distance - nearPlane);
242
243   // Render and notify
244   application.SendNotification();
245   application.Render();
246
247   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
248   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
249   data.Reset();
250
251   // Emit a started signal where actor is closer than the camera's near plane
252   actor.SetZ((distance - nearPlane) + 1.0f);
253
254   // Render and notify
255   application.SendNotification();
256   application.Render();
257
258   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
259   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
260   data.Reset();
261
262   // Emit a started signal where actor is just at the camera's far plane
263   actor.SetZ(distance - farPlane);
264
265   // Render and notify
266   application.SendNotification();
267   application.Render();
268
269   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
270   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
271   data.Reset();
272
273   // Emit a started signal where actor is further than the camera's far plane
274   actor.SetZ((distance - farPlane) - 1.0f);
275
276   // Render and notify
277   application.SendNotification();
278   application.Render();
279
280   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
281   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
282   data.Reset();
283   END_TEST;
284 }
285
286 int UtcDaliHoverEmitEmpty(void)
287 {
288   TestApplication application;
289
290   try
291   {
292     // Emit an empty HoverEvent
293     Integration::HoverEvent event;
294     application.ProcessEvent( event );
295     tet_result( TET_FAIL );
296   }
297   catch ( Dali::DaliException& e )
298   {
299     DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
300   }
301   END_TEST;
302 }
303
304 int UtcDaliHoverInterrupted(void)
305 {
306   TestApplication application;
307
308   Actor actor = Actor::New();
309   actor.SetSize(100.0f, 100.0f);
310   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
311   Stage::GetCurrent().Add(actor);
312
313   // Render and notify
314   application.SendNotification();
315   application.Render();
316
317   // Connect to actor's hovered signal
318   SignalData data;
319   HoverEventFunctor functor( data );
320   actor.HoveredSignal().Connect( &application, functor );
321
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 );
326   data.Reset();
327
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 );
332   data.Reset();
333
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 );
337   END_TEST;
338 }
339
340 int UtcDaliHoverParentConsumer(void)
341 {
342   TestApplication application;
343   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
344
345   Actor actor = Actor::New();
346   actor.SetSize(100.0f, 100.0f);
347   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
348   Stage::GetCurrent().Add(actor);
349
350   // Render and notify
351   application.SendNotification();
352   application.Render();
353
354   // Connect to actor's hovered signal
355   SignalData data;
356   HoverEventFunctor functor( data, false );
357   actor.HoveredSignal().Connect( &application, functor );
358
359   // Connect to root actor's hovered signal
360   SignalData rootData;
361   HoverEventFunctor rootFunctor( rootData ); // Consumes signal
362   rootActor.HoveredSignal().Connect( &application, rootFunctor );
363
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 );
368
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 );
383   data.Reset();
384   rootData.Reset();
385
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 );
403   data.Reset();
404   rootData.Reset();
405
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 );
423   data.Reset();
424   rootData.Reset();
425
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 );
437   END_TEST;
438 }
439
440 int UtcDaliHoverInterruptedParentConsumer(void)
441 {
442   TestApplication application;
443   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
444
445   Actor actor = Actor::New();
446   actor.SetSize(100.0f, 100.0f);
447   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
448   Stage::GetCurrent().Add(actor);
449
450   // Render and notify
451   application.SendNotification();
452   application.Render();
453
454   // Connect to actor's hovered signal
455   SignalData data;
456   HoverEventFunctor functor( data, false );
457   actor.HoveredSignal().Connect( &application, functor );
458
459   // Connect to root actor's hovered signal
460   SignalData rootData;
461   HoverEventFunctor rootFunctor( rootData ); // Consumes signal
462   rootActor.HoveredSignal().Connect( &application, rootFunctor );
463
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 );
472   data.Reset();
473   rootData.Reset();
474
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 );
483   data.Reset();
484   rootData.Reset();
485
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 );
492   data.Reset();
493   rootData.Reset();
494
495   // Remove actor from Stage
496   Stage::GetCurrent().Remove( actor );
497
498   // Render and notify
499   application.SendNotification();
500   application.Render();
501
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 );
508   data.Reset();
509   rootData.Reset();
510
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 );
515   END_TEST;
516 }
517
518 int UtcDaliHoverLeave(void)
519 {
520   TestApplication application;
521
522   Actor actor = Actor::New();
523   actor.SetSize(100.0f, 100.0f);
524   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
525   Stage::GetCurrent().Add(actor);
526
527   // Render and notify
528   application.SendNotification();
529   application.Render();
530
531   // Connect to actor's hovered signal
532   SignalData data;
533   HoverEventFunctor functor( data );
534   actor.HoveredSignal().Connect( &application, functor );
535
536   // Set actor to require leave events
537   actor.SetLeaveRequired( true );
538
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 );
543   data.Reset();
544
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 );
549   data.Reset();
550
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 );
554   data.Reset();
555
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 );
560   data.Reset();
561
562   // We do not want to listen to leave events anymore
563   actor.SetLeaveRequired( false );
564
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 );
568   data.Reset();
569   END_TEST;
570 }
571
572 int UtcDaliHoverLeaveParentConsumer(void)
573 {
574   TestApplication application;
575   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
576
577   Actor actor = Actor::New();
578   actor.SetSize(100.0f, 100.0f);
579   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
580   Stage::GetCurrent().Add(actor);
581
582   // Render and notify
583   application.SendNotification();
584   application.Render();
585
586   // Connect to actor's hovered signal
587   SignalData data;
588   HoverEventFunctor functor( data, false );
589   actor.HoveredSignal().Connect( &application, functor );
590
591   // Connect to root actor's hovered signal
592   SignalData rootData;
593   HoverEventFunctor rootFunctor( rootData ); // Consumes signal
594   rootActor.HoveredSignal().Connect( &application, rootFunctor );
595
596   // Set actor to require leave events
597   actor.SetLeaveRequired( true );
598   rootActor.SetLeaveRequired( true );
599
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 );
608   data.Reset();
609   rootData.Reset();
610
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 );
619   data.Reset();
620   rootData.Reset();
621
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 );
628   data.Reset();
629   rootData.Reset();
630
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 );
639   data.Reset();
640   rootData.Reset();
641
642   // We do not want to listen to leave events of actor anymore
643   actor.SetLeaveRequired( false );
644
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 );
651   END_TEST;
652 }
653
654 int UtcDaliHoverActorBecomesInsensitive(void)
655 {
656   TestApplication application;
657
658   Actor actor = Actor::New();
659   actor.SetSize(100.0f, 100.0f);
660   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
661   Stage::GetCurrent().Add(actor);
662
663   // Render and notify
664   application.SendNotification();
665   application.Render();
666
667   // Connect to actor's hovered signal
668   SignalData data;
669   HoverEventFunctor functor( data );
670   actor.HoveredSignal().Connect( &application, functor );
671
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 );
676   data.Reset();
677
678   // Change actor to insensitive
679   actor.SetSensitive( false );
680
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 );
685   data.Reset();
686   END_TEST;
687 }
688
689 int UtcDaliHoverActorBecomesInsensitiveParentConsumer(void)
690 {
691   TestApplication application;
692   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
693
694   Actor actor = Actor::New();
695   actor.SetSize(100.0f, 100.0f);
696   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
697   Stage::GetCurrent().Add(actor);
698
699   // Render and notify
700   application.SendNotification();
701   application.Render();
702
703   // Connect to actor's hovered signal
704   SignalData data;
705   HoverEventFunctor functor( data, false );
706   actor.HoveredSignal().Connect( &application, functor );
707
708   // Connect to root actor's hovered signal
709   SignalData rootData;
710   HoverEventFunctor rootFunctor( rootData ); // Consumes signal
711   rootActor.HoveredSignal().Connect( &application, rootFunctor );
712
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 );
721   data.Reset();
722   rootData.Reset();
723
724   // Remove actor from Stage
725   Stage::GetCurrent().Remove( actor );
726
727   // Render and notify
728   application.SendNotification();
729   application.Render();
730
731   // Make root actor insensitive
732   rootActor.SetSensitive( false );
733
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 );
739   END_TEST;
740 }
741
742 int UtcDaliHoverMultipleLayers(void)
743 {
744   TestApplication application;
745   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
746
747   // Connect to actor's hovered signal
748   SignalData data;
749   HoverEventFunctor functor( data );
750
751   Layer layer1 ( Layer::New() );
752   layer1.SetSize(100.0f, 100.0f);
753   layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
754   Stage::GetCurrent().Add( layer1 );
755
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 );
761
762   // Render and notify
763   application.SendNotification();
764   application.Render();
765
766   // Connect to layer1 and actor1
767   layer1.HoveredSignal().Connect( &application, functor );
768   actor1.HoveredSignal().Connect( &application, functor );
769
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 );
774   data.Reset();
775
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 );
780   data.Reset();
781
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 );
787   data.Reset();
788
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 );
793   data.Reset();
794
795   // Make rootActor sensitive
796   rootActor.SetSensitive( true );
797
798   // Add another layer
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 );
804
805   Actor actor2 ( Actor::New() );
806   actor2.SetSize(100.0f, 100.0f);
807   actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
808   layer2.Add( actor2 );
809
810   // Render and notify
811   application.SendNotification();
812   application.Render();
813
814   // Connect to layer2 and actor2
815   layer2.HoveredSignal().Connect( &application, functor );
816   actor2.HoveredSignal().Connect( &application, functor );
817
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!
822   data.Reset();
823
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 );
829   data.Reset();
830
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!
836   data.Reset();
837
838   // Make layer2 invisible, render and notify
839   layer2.SetVisible( false );
840   application.SendNotification();
841   application.Render();
842
843   // Should hit actor1
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 );
847   data.Reset();
848
849   // Make rootActor invisible, render and notify
850   rootActor.SetVisible( false );
851   application.SendNotification();
852   application.Render();
853
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 );
857   data.Reset();
858   END_TEST;
859 }
860
861 int UtcDaliHoverMultipleRenderTasks(void)
862 {
863   TestApplication application;
864   Stage stage ( Stage::GetCurrent() );
865   Vector2 stageSize ( stage.GetSize() );
866
867   Actor actor = Actor::New();
868   actor.SetSize(100.0f, 100.0f);
869   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
870   stage.Add(actor);
871
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 );
877
878   // Render and notify
879   application.SendNotification();
880   application.Render();
881
882   // Connect to actor's hovered signal
883   SignalData data;
884   HoverEventFunctor functor( data );
885   actor.HoveredSignal().Connect( &application, functor );
886
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 );
890   data.Reset();
891
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 );
895   data.Reset();
896
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 );
901   data.Reset();
902   END_TEST;
903 }
904
905 int UtcDaliHoverMultipleRenderTasksWithChildLayer(void)
906 {
907   TestApplication application;
908   Stage stage ( Stage::GetCurrent() );
909   Vector2 stageSize ( stage.GetSize() );
910
911   Actor actor = Actor::New();
912   actor.SetSize(100.0f, 100.0f);
913   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
914   stage.Add(actor);
915
916   Layer layer = Layer::New();
917   layer.SetSize(100.0f, 100.0f);
918   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
919   actor.Add(layer);
920
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 );
927
928   // Render and notify
929   application.SendNotification();
930   application.Render();
931
932   // Connect to layer's hovered signal
933   SignalData data;
934   HoverEventFunctor functor( data );
935   actor.HoveredSignal().Connect( &application, functor );
936   layer.HoveredSignal().Connect( &application, functor );
937
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 );
941   data.Reset();
942
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 );
946   data.Reset();
947
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 );
952   data.Reset();
953   END_TEST;
954 }
955
956 int UtcDaliHoverOffscreenRenderTasks(void)
957 {
958   TestApplication application;
959   Stage stage ( Stage::GetCurrent() );
960   Vector2 stageSize ( stage.GetSize() );
961
962   // FrameBufferImage for offscreen RenderTask
963   FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
964
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 );
971
972   Actor actor = Actor::New();
973   actor.SetSize(100.0f, 100.0f);
974   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
975   stage.Add( actor );
976   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
977
978   stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
979
980   // Create a RenderTask
981   RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
982   renderTask.SetSourceActor( actor );
983   renderTask.SetTargetFrameBuffer( frameBufferImage );
984   renderTask.SetInputEnabled( true );
985
986   // Create another RenderTask
987   RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
988   renderTask2.SetInputEnabled( true );
989
990   // Render and notify
991   application.SendNotification();
992   application.Render();
993
994   // Connect to actor's hovered signal
995   SignalData data;
996   HoverEventFunctor functor( data );
997   actor.HoveredSignal().Connect( &application, functor );
998
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 );
1002   data.Reset();
1003   END_TEST;
1004 }
1005
1006 int UtcDaliHoverMultipleRenderableActors(void)
1007 {
1008   TestApplication application;
1009   Stage stage ( Stage::GetCurrent() );
1010   Vector2 stageSize ( stage.GetSize() );
1011
1012   Actor parent = CreateRenderableActor();
1013   parent.SetSize( 100.0f, 100.0f );
1014   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1015   stage.Add(parent);
1016
1017   Actor actor = CreateRenderableActor();
1018   actor.SetSize( 100.0f, 100.0f );
1019   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1020   parent.Add(actor);
1021
1022   // Render and notify
1023   application.SendNotification();
1024   application.Render();
1025
1026   // Connect to layer's hovered signal
1027   SignalData data;
1028   HoverEventFunctor functor( data );
1029   parent.HoveredSignal().Connect( &application, functor );
1030   actor.HoveredSignal().Connect( &application, functor );
1031
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 );
1036   END_TEST;
1037 }
1038
1039 int UtcDaliHoverActorRemovedInSignal(void)
1040 {
1041   TestApplication application;
1042
1043   Actor actor = Actor::New();
1044   actor.SetSize(100.0f, 100.0f);
1045   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1046   Stage::GetCurrent().Add(actor);
1047
1048   // Render and notify
1049   application.SendNotification();
1050   application.Render();
1051
1052   // Connect to actor's hovered signal
1053   SignalData data;
1054   RemoveActorFunctor functor( data );
1055   actor.HoveredSignal().Connect( &application, functor );
1056
1057   // Register for leave events
1058   actor.SetLeaveRequired( true );
1059
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 );
1063   data.Reset();
1064
1065   // Re-add, render and notify
1066   Stage::GetCurrent().Add(actor);
1067   application.SendNotification();
1068   application.Render();
1069
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 );
1073   data.Reset();
1074
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 );
1078   data.Reset();
1079
1080   // Render and notify
1081   application.SendNotification();
1082   application.Render();
1083
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 );
1087   data.Reset();
1088
1089   // Re-add actor back to stage, render and notify
1090   Stage::GetCurrent().Add(actor);
1091   application.SendNotification();
1092   application.Render();
1093
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 );
1097   data.Reset();
1098
1099   // Completely delete the actor
1100   actor.Reset();
1101
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 );
1105   END_TEST;
1106 }
1107
1108 int UtcDaliHoverActorSignalNotConsumed(void)
1109 {
1110   TestApplication application;
1111
1112   Actor actor = Actor::New();
1113   actor.SetSize(100.0f, 100.0f);
1114   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1115   Stage::GetCurrent().Add(actor);
1116
1117   // Render and notify
1118   application.SendNotification();
1119   application.Render();
1120
1121   // Connect to actor's hovered signal
1122   SignalData data;
1123   HoverEventFunctor functor( data, false );
1124   actor.HoveredSignal().Connect( &application, functor );
1125
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 );
1129   END_TEST;
1130 }
1131
1132 int UtcDaliHoverActorUnStaged(void)
1133 {
1134   TestApplication application;
1135
1136   Actor actor = Actor::New();
1137   actor.SetSize(100.0f, 100.0f);
1138   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1139   Stage::GetCurrent().Add(actor);
1140
1141   // Render and notify
1142   application.SendNotification();
1143   application.Render();
1144
1145   // Connect to actor's hovered signal
1146   SignalData data;
1147   HoverEventFunctor functor( data );
1148   actor.HoveredSignal().Connect( &application, functor );
1149
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 );
1153   data.Reset();
1154
1155   // Remove actor from stage
1156   Stage::GetCurrent().Remove( actor );
1157
1158   // Render and notify
1159   application.SendNotification();
1160   application.Render();
1161
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 );
1165   data.Reset();
1166   END_TEST;
1167 }
1168
1169 int UtcDaliHoverSystemOverlayActor(void)
1170 {
1171   TestApplication application;
1172   Dali::Integration::Core& core( application.GetCore() );
1173   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1174   systemOverlay.GetOverlayRenderTasks().CreateTask();
1175
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 );
1181
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);
1187
1188   // Connect to the hover signals.
1189   SignalData data;
1190   HoverEventFunctor functor( data );
1191   systemActor.HoveredSignal().Connect( &application, functor );
1192   actor.HoveredSignal().Connect( &application, functor );
1193
1194   // Render and notify
1195   application.SendNotification();
1196   application.Render();
1197
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 );
1202   END_TEST;
1203 }
1204
1205 int UtcDaliHoverLeaveActorReadded(void)
1206 {
1207   TestApplication application;
1208   Stage stage = Stage::GetCurrent();
1209
1210   Actor actor = Actor::New();
1211   actor.SetSize(100.0f, 100.0f);
1212   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1213   stage.Add(actor);
1214
1215   // Set actor to receive hover-events
1216   actor.SetLeaveRequired( true );
1217
1218   // Render and notify
1219   application.SendNotification();
1220   application.Render();
1221
1222   // Connect to actor's hovered signal
1223   SignalData data;
1224   HoverEventFunctor functor( data );
1225   actor.HoveredSignal().Connect( &application, functor );
1226
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 );
1231   data.Reset();
1232
1233   // Remove actor from stage and add again
1234   stage.Remove( actor );
1235   stage.Add( actor );
1236
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 );
1240   data.Reset();
1241
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 );
1246   data.Reset();
1247
1248   END_TEST;
1249 }
1250
1251 int UtcDaliHoverClippingActor(void)
1252 {
1253   TestApplication application;
1254   Stage stage = Stage::GetCurrent();
1255
1256   Actor actor = Actor::New();
1257   actor.SetSize( 100.0f, 100.0f );
1258   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1259   stage.Add( actor );
1260
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 );
1266
1267   // Render and notify.
1268   application.SendNotification();
1269   application.Render();
1270
1271   // Connect to actor's hovered signal.
1272   SignalData data;
1273   HoverEventFunctor functor( data );
1274   actor.HoveredSignal().Connect( &application, functor );
1275
1276   // Emit an event within clipped area.
1277   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1278   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1279   data.Reset();
1280
1281   // Emit an event outside the clipped area but within the actor area, we should have a hit.
1282   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 60.0f, 60.0f ) ) );
1283   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1284   data.Reset();
1285
1286   END_TEST;
1287 }