Merge "Merge branch 'devel/new_mesh' into devel/master" into devel/master
[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, Vector2 screenPosition )
121 {
122   Integration::HoverEvent hoverEvent;
123   hoverEvent.points.push_back( TouchPoint ( 0, state, screenPosition.x, screenPosition.y ) );
124   return hoverEvent;
125 }
126
127 } // anon namespace
128
129 ///////////////////////////////////////////////////////////////////////////////
130
131 int UtcDaliHoverNormalProcessing(void)
132 {
133   TestApplication application;
134
135   Actor actor = Actor::New();
136   actor.SetSize(100.0f, 100.0f);
137   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
138   Stage::GetCurrent().Add(actor);
139
140   // Render and notify
141   application.SendNotification();
142   application.Render();
143
144   // Connect to actor's hovered signal
145   SignalData data;
146   HoverEventFunctor functor( data );
147   actor.HoveredSignal().Connect( &application, functor );
148
149   Vector2 screenCoordinates( 10.0f, 10.0f );
150   Vector2 localCoordinates;
151   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
152
153   // Emit a started signal
154   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
155   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
156   DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
157   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
158   DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
159   DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
160
161   TouchPoint point = data.hoverEvent.GetPoint(0);
162   DALI_TEST_EQUALS( TouchPoint::Started, point.state, TEST_LOCATION );
163   DALI_TEST_EQUALS( screenCoordinates, point.screen, TEST_LOCATION );
164   DALI_TEST_EQUALS( localCoordinates, point.local, 0.1f, TEST_LOCATION );
165
166   data.Reset();
167
168   // Emit a motion signal
169   screenCoordinates.x = screenCoordinates.y = 11.0f;
170   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
171   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, screenCoordinates ) );
172   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
173   DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
174   DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
175   DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
176   DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
177   data.Reset();
178
179   // Emit a finished signal
180   screenCoordinates.x = screenCoordinates.y = 12.0f;
181   actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
182   application.ProcessEvent( GenerateSingleHover( TouchPoint::Finished, screenCoordinates ) );
183   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
184   DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
185   DALI_TEST_EQUALS( TouchPoint::Finished, data.hoverEvent.points[0].state, TEST_LOCATION );
186   DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
187   DALI_TEST_EQUALS( localCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
188   data.Reset();
189
190   // Emit a started signal where the actor is not present
191   screenCoordinates.x = screenCoordinates.y = 200.0f;
192   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
193   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
194   END_TEST;
195 }
196
197 int UtcDaliHoverOutsideCameraNearFarPlanes(void)
198 {
199   TestApplication application;
200
201   Stage stage = Stage::GetCurrent();
202   Vector2 stageSize = stage.GetSize();
203
204   Actor actor = Actor::New();
205   actor.SetSize(100.0f, 100.0f);
206   actor.SetAnchorPoint(AnchorPoint::CENTER);
207   actor.SetParentOrigin(ParentOrigin::CENTER);
208   stage.Add(actor);
209
210   // Render and notify
211   application.SendNotification();
212   application.Render();
213
214   // Get the camera's near and far planes
215   RenderTaskList taskList = stage.GetRenderTaskList();
216   Dali::RenderTask task = taskList.GetTask(0);
217   CameraActor camera = task.GetCameraActor();
218   float nearPlane = camera.GetNearClippingPlane();
219   float farPlane = camera.GetFarClippingPlane();
220
221   // Calculate the current distance of the actor from the camera
222   float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
223   float distance = (stageSize.y * 0.5f) / tanHalfFov;
224
225   // Connect to actor's hovered signal
226   SignalData data;
227   HoverEventFunctor functor( data );
228   actor.HoveredSignal().Connect( &application, functor );
229
230   Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
231
232   // Emit a started signal
233   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
234   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
235   data.Reset();
236
237   // Emit a started signal where actor is just at the camera's near plane
238   actor.SetZ(distance - nearPlane);
239
240   // Render and notify
241   application.SendNotification();
242   application.Render();
243
244   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
245   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
246   data.Reset();
247
248   // Emit a started signal where actor is closer than the camera's near plane
249   actor.SetZ((distance - nearPlane) + 1.0f);
250
251   // Render and notify
252   application.SendNotification();
253   application.Render();
254
255   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
256   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
257   data.Reset();
258
259   // Emit a started signal where actor is just at the camera's far plane
260   actor.SetZ(distance - farPlane);
261
262   // Render and notify
263   application.SendNotification();
264   application.Render();
265
266   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
267   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
268   data.Reset();
269
270   // Emit a started signal where actor is further than the camera's far plane
271   actor.SetZ((distance - farPlane) - 1.0f);
272
273   // Render and notify
274   application.SendNotification();
275   application.Render();
276
277   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
278   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
279   data.Reset();
280   END_TEST;
281 }
282
283 int UtcDaliHoverEmitEmpty(void)
284 {
285   TestApplication application;
286
287   try
288   {
289     // Emit an empty HoverEvent
290     Integration::HoverEvent event;
291     application.ProcessEvent( event );
292     tet_result( TET_FAIL );
293   }
294   catch ( Dali::DaliException& e )
295   {
296     DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
297   }
298   END_TEST;
299 }
300
301 int UtcDaliHoverInterrupted(void)
302 {
303   TestApplication application;
304
305   Actor actor = Actor::New();
306   actor.SetSize(100.0f, 100.0f);
307   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
308   Stage::GetCurrent().Add(actor);
309
310   // Render and notify
311   application.SendNotification();
312   application.Render();
313
314   // Connect to actor's hovered signal
315   SignalData data;
316   HoverEventFunctor functor( data );
317   actor.HoveredSignal().Connect( &application, functor );
318
319   // Emit a started signal
320   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
321   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
322   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
323   data.Reset();
324
325   // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
326   application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
327   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
328   DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
329   data.Reset();
330
331   // Emit another interrupted signal, our signal handler should not be called.
332   application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
333   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
334   END_TEST;
335 }
336
337 int UtcDaliHoverParentConsumer(void)
338 {
339   TestApplication application;
340   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
341
342   Actor actor = Actor::New();
343   actor.SetSize(100.0f, 100.0f);
344   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
345   Stage::GetCurrent().Add(actor);
346
347   // Render and notify
348   application.SendNotification();
349   application.Render();
350
351   // Connect to actor's hovered signal
352   SignalData data;
353   HoverEventFunctor functor( data, false );
354   actor.HoveredSignal().Connect( &application, functor );
355
356   // Connect to root actor's hovered signal
357   SignalData rootData;
358   HoverEventFunctor rootFunctor( rootData ); // Consumes signal
359   rootActor.HoveredSignal().Connect( &application, rootFunctor );
360
361   Vector2 screenCoordinates( 10.0f, 10.0f );
362   Vector2 actorCoordinates, rootCoordinates;
363   actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
364   rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
365
366   // Emit a started signal
367   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
368   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
369   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
370   DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
371   DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
372   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
373   DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
374   DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
375   DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
376   DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
377   DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
378   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
379   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
380   data.Reset();
381   rootData.Reset();
382
383   // Emit a motion signal
384   screenCoordinates.x = screenCoordinates.y = 11.0f;
385   actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
386   rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
387   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, screenCoordinates ) );
388   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
389   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
390   DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
391   DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
392   DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
393   DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
394   DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
395   DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
396   DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
397   DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
398   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
399   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
400   data.Reset();
401   rootData.Reset();
402
403   // Emit a finished signal
404   screenCoordinates.x = screenCoordinates.y = 12.0f;
405   actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
406   rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
407   application.ProcessEvent( GenerateSingleHover( TouchPoint::Finished, screenCoordinates ) );
408   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
409   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
410   DALI_TEST_EQUALS( 1u, data.hoverEvent.GetPointCount(), TEST_LOCATION );
411   DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
412   DALI_TEST_EQUALS( TouchPoint::Finished, data.hoverEvent.points[0].state, TEST_LOCATION );
413   DALI_TEST_EQUALS( TouchPoint::Finished, rootData.hoverEvent.points[0].state, TEST_LOCATION );
414   DALI_TEST_EQUALS( screenCoordinates, data.hoverEvent.points[0].screen, TEST_LOCATION );
415   DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
416   DALI_TEST_EQUALS( actorCoordinates, data.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
417   DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
418   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
419   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
420   data.Reset();
421   rootData.Reset();
422
423   // Emit a started signal where the actor is not present, will hit the root actor though
424   screenCoordinates.x = screenCoordinates.y = 200.0f;
425   rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
426   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
427   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
428   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
429   DALI_TEST_EQUALS( 1u, rootData.hoverEvent.GetPointCount(), TEST_LOCATION );
430   DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
431   DALI_TEST_EQUALS( screenCoordinates, rootData.hoverEvent.points[0].screen, TEST_LOCATION );
432   DALI_TEST_EQUALS( rootCoordinates, rootData.hoverEvent.points[0].local, 0.1f, TEST_LOCATION );
433   DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
434   END_TEST;
435 }
436
437 int UtcDaliHoverInterruptedParentConsumer(void)
438 {
439   TestApplication application;
440   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
441
442   Actor actor = Actor::New();
443   actor.SetSize(100.0f, 100.0f);
444   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
445   Stage::GetCurrent().Add(actor);
446
447   // Render and notify
448   application.SendNotification();
449   application.Render();
450
451   // Connect to actor's hovered signal
452   SignalData data;
453   HoverEventFunctor functor( data, false );
454   actor.HoveredSignal().Connect( &application, functor );
455
456   // Connect to root actor's hovered signal
457   SignalData rootData;
458   HoverEventFunctor rootFunctor( rootData ); // Consumes signal
459   rootActor.HoveredSignal().Connect( &application, rootFunctor );
460
461   // Emit a started signal
462   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
463   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
464   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
465   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
466   DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
467   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
468   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
469   data.Reset();
470   rootData.Reset();
471
472   // Emit an interrupted signal
473   application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
474   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
475   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
476   DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
477   DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
478   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
479   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
480   data.Reset();
481   rootData.Reset();
482
483   // Emit another started signal
484   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
485   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
486   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
487   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
488   DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
489   data.Reset();
490   rootData.Reset();
491
492   // Remove actor from Stage
493   Stage::GetCurrent().Remove( actor );
494
495   // Render and notify
496   application.SendNotification();
497   application.Render();
498
499   // Emit an interrupted signal, only root actor's signal should be called.
500   application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
501   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
502   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
503   DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
504   DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
505   data.Reset();
506   rootData.Reset();
507
508   // Emit another interrupted state, none of the signal's should be called.
509   application.ProcessEvent( GenerateSingleHover( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
510   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
511   DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
512   END_TEST;
513 }
514
515 int UtcDaliHoverLeave(void)
516 {
517   TestApplication application;
518
519   Actor actor = Actor::New();
520   actor.SetSize(100.0f, 100.0f);
521   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
522   Stage::GetCurrent().Add(actor);
523
524   // Render and notify
525   application.SendNotification();
526   application.Render();
527
528   // Connect to actor's hovered signal
529   SignalData data;
530   HoverEventFunctor functor( data );
531   actor.HoveredSignal().Connect( &application, functor );
532
533   // Set actor to require leave events
534   actor.SetLeaveRequired( true );
535
536   // Emit a started signal
537   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
538   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
539   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
540   data.Reset();
541
542   // Emit a motion signal outside of actor, should be signalled with a Leave
543   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
544   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
545   DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
546   data.Reset();
547
548   // Another motion outside of actor, no signalling
549   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
550   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
551   data.Reset();
552
553   // Another motion event inside actor, signalled with motion
554   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
555   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
556   DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
557   data.Reset();
558
559   // We do not want to listen to leave events anymore
560   actor.SetLeaveRequired( false );
561
562   // Another motion event outside of actor, no signalling
563   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
564   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
565   data.Reset();
566   END_TEST;
567 }
568
569 int UtcDaliHoverLeaveParentConsumer(void)
570 {
571   TestApplication application;
572   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
573
574   Actor actor = Actor::New();
575   actor.SetSize(100.0f, 100.0f);
576   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
577   Stage::GetCurrent().Add(actor);
578
579   // Render and notify
580   application.SendNotification();
581   application.Render();
582
583   // Connect to actor's hovered signal
584   SignalData data;
585   HoverEventFunctor functor( data, false );
586   actor.HoveredSignal().Connect( &application, functor );
587
588   // Connect to root actor's hovered signal
589   SignalData rootData;
590   HoverEventFunctor rootFunctor( rootData ); // Consumes signal
591   rootActor.HoveredSignal().Connect( &application, rootFunctor );
592
593   // Set actor to require leave events
594   actor.SetLeaveRequired( true );
595   rootActor.SetLeaveRequired( true );
596
597   // Emit a started signal
598   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
599   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
600   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
601   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
602   DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
603   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
604   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
605   data.Reset();
606   rootData.Reset();
607
608   // Emit a motion signal outside of actor, should be signalled with a Leave
609   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
610   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
611   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
612   DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
613   DALI_TEST_EQUALS( TouchPoint::Leave, rootData.hoverEvent.points[0].state, TEST_LOCATION );
614   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
615   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
616   data.Reset();
617   rootData.Reset();
618
619   // Another motion outside of actor, only rootActor signalled
620   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
621   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
622   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
623   DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
624   DALI_TEST_CHECK( rootActor == rootData.hoverEvent.points[0].hitActor );
625   data.Reset();
626   rootData.Reset();
627
628   // Another motion event inside actor, signalled with motion
629   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
630   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
631   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
632   DALI_TEST_EQUALS( TouchPoint::Motion, data.hoverEvent.points[0].state, TEST_LOCATION );
633   DALI_TEST_EQUALS( TouchPoint::Motion, rootData.hoverEvent.points[0].state, TEST_LOCATION );
634   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
635   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
636   data.Reset();
637   rootData.Reset();
638
639   // We do not want to listen to leave events of actor anymore
640   actor.SetLeaveRequired( false );
641
642   // Another motion event outside of root actor, only root signalled
643   Vector2 stageSize( Stage::GetCurrent().GetSize() );
644   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
645   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
646   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
647   DALI_TEST_EQUALS( TouchPoint::Leave, rootData.hoverEvent.points[0].state, TEST_LOCATION );
648   END_TEST;
649 }
650
651 int UtcDaliHoverActorBecomesInsensitive(void)
652 {
653   TestApplication application;
654
655   Actor actor = Actor::New();
656   actor.SetSize(100.0f, 100.0f);
657   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
658   Stage::GetCurrent().Add(actor);
659
660   // Render and notify
661   application.SendNotification();
662   application.Render();
663
664   // Connect to actor's hovered signal
665   SignalData data;
666   HoverEventFunctor functor( data );
667   actor.HoveredSignal().Connect( &application, functor );
668
669   // Emit a started signal
670   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
671   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
672   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
673   data.Reset();
674
675   // Change actor to insensitive
676   actor.SetSensitive( false );
677
678   // Emit a motion signal, signalled with an interrupted
679   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
680   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
681   DALI_TEST_EQUALS( TouchPoint::Interrupted, data.hoverEvent.points[0].state, TEST_LOCATION );
682   data.Reset();
683   END_TEST;
684 }
685
686 int UtcDaliHoverActorBecomesInsensitiveParentConsumer(void)
687 {
688   TestApplication application;
689   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
690
691   Actor actor = Actor::New();
692   actor.SetSize(100.0f, 100.0f);
693   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
694   Stage::GetCurrent().Add(actor);
695
696   // Render and notify
697   application.SendNotification();
698   application.Render();
699
700   // Connect to actor's hovered signal
701   SignalData data;
702   HoverEventFunctor functor( data, false );
703   actor.HoveredSignal().Connect( &application, functor );
704
705   // Connect to root actor's hovered signal
706   SignalData rootData;
707   HoverEventFunctor rootFunctor( rootData ); // Consumes signal
708   rootActor.HoveredSignal().Connect( &application, rootFunctor );
709
710   // Emit a started signal
711   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
712   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
713   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
714   DALI_TEST_EQUALS( TouchPoint::Started, data.hoverEvent.points[0].state, TEST_LOCATION );
715   DALI_TEST_EQUALS( TouchPoint::Started, rootData.hoverEvent.points[0].state, TEST_LOCATION );
716   DALI_TEST_CHECK( actor == data.hoverEvent.points[0].hitActor );
717   DALI_TEST_CHECK( actor == rootData.hoverEvent.points[0].hitActor );
718   data.Reset();
719   rootData.Reset();
720
721   // Remove actor from Stage
722   Stage::GetCurrent().Remove( actor );
723
724   // Render and notify
725   application.SendNotification();
726   application.Render();
727
728   // Make root actor insensitive
729   rootActor.SetSensitive( false );
730
731   // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
732   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
733   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
734   DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
735   DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.hoverEvent.points[0].state, TEST_LOCATION );
736   END_TEST;
737 }
738
739 int UtcDaliHoverMultipleLayers(void)
740 {
741   TestApplication application;
742   Actor rootActor( Stage::GetCurrent().GetRootLayer() );
743
744   // Connect to actor's hovered signal
745   SignalData data;
746   HoverEventFunctor functor( data );
747
748   Layer layer1 ( Layer::New() );
749   layer1.SetSize(100.0f, 100.0f);
750   layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
751   Stage::GetCurrent().Add( layer1 );
752
753   Actor actor1 ( Actor::New() );
754   actor1.SetSize( 100.0f, 100.0f );
755   actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
756   actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
757   layer1.Add( actor1 );
758
759   // Render and notify
760   application.SendNotification();
761   application.Render();
762
763   // Connect to layer1 and actor1
764   layer1.HoveredSignal().Connect( &application, functor );
765   actor1.HoveredSignal().Connect( &application, functor );
766
767   // Hit in hittable area, actor1 should be hit
768   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
769   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
770   DALI_TEST_CHECK( data.hoveredActor == actor1 );
771   data.Reset();
772
773   // Make layer1 insensitive, nothing should be hit
774   layer1.SetSensitive( false );
775   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
776   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
777   data.Reset();
778
779   // Make layer1 sensitive again, again actor1 will be hit
780   layer1.SetSensitive( true );
781   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
782   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
783   DALI_TEST_CHECK( data.hoveredActor == actor1 );
784   data.Reset();
785
786   // Make rootActor insensitive, nothing should be hit
787   rootActor.SetSensitive( false );
788   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
789   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
790   data.Reset();
791
792   // Make rootActor sensitive
793   rootActor.SetSensitive( true );
794
795   // Add another layer
796   Layer layer2 ( Layer::New() );
797   layer2.SetSize(100.0f, 100.0f );
798   layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
799   layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
800   Stage::GetCurrent().Add( layer2 );
801
802   Actor actor2 ( Actor::New() );
803   actor2.SetSize(100.0f, 100.0f);
804   actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
805   layer2.Add( actor2 );
806
807   // Render and notify
808   application.SendNotification();
809   application.Render();
810
811   // Connect to layer2 and actor2
812   layer2.HoveredSignal().Connect( &application, functor );
813   actor2.HoveredSignal().Connect( &application, functor );
814
815   // Emit an event, should hit layer2
816   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
817   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
818   //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
819   data.Reset();
820
821   // Make layer2 insensitive, should hit actor1
822   layer2.SetSensitive( false );
823   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
824   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
825   DALI_TEST_CHECK( data.hoveredActor == actor1 );
826   data.Reset();
827
828   // Make layer2 sensitive again, should hit layer2
829   layer2.SetSensitive( true );
830   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
831   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
832   //DALI_TEST_CHECK( data.hoveredActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
833   data.Reset();
834
835   // Make layer2 invisible, render and notify
836   layer2.SetVisible( false );
837   application.SendNotification();
838   application.Render();
839
840   // Should hit actor1
841   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
842   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
843   DALI_TEST_CHECK( data.hoveredActor == actor1 );
844   data.Reset();
845
846   // Make rootActor invisible, render and notify
847   rootActor.SetVisible( false );
848   application.SendNotification();
849   application.Render();
850
851   // Should not hit anything
852   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
853   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
854   data.Reset();
855   END_TEST;
856 }
857
858 int UtcDaliHoverMultipleRenderTasks(void)
859 {
860   TestApplication application;
861   Stage stage ( Stage::GetCurrent() );
862   Vector2 stageSize ( stage.GetSize() );
863
864   Actor actor = Actor::New();
865   actor.SetSize(100.0f, 100.0f);
866   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
867   stage.Add(actor);
868
869   // Create render task
870   Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
871   RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
872   renderTask.SetViewport( viewport );
873   renderTask.SetInputEnabled( true );
874
875   // Render and notify
876   application.SendNotification();
877   application.Render();
878
879   // Connect to actor's hovered signal
880   SignalData data;
881   HoverEventFunctor functor( data );
882   actor.HoveredSignal().Connect( &application, functor );
883
884   // Emit a started signal
885   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
886   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
887   data.Reset();
888
889   // Ensure renderTask actor can be hit too.
890   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
891   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
892   data.Reset();
893
894   // Disable input on renderTask, should not be hittable
895   renderTask.SetInputEnabled( false );
896   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
897   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
898   data.Reset();
899   END_TEST;
900 }
901
902 int UtcDaliHoverMultipleRenderTasksWithChildLayer(void)
903 {
904   TestApplication application;
905   Stage stage ( Stage::GetCurrent() );
906   Vector2 stageSize ( stage.GetSize() );
907
908   Actor actor = Actor::New();
909   actor.SetSize(100.0f, 100.0f);
910   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
911   stage.Add(actor);
912
913   Layer layer = Layer::New();
914   layer.SetSize(100.0f, 100.0f);
915   layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
916   actor.Add(layer);
917
918   // Create render task
919   Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
920   RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
921   renderTask.SetViewport( viewport );
922   renderTask.SetInputEnabled( true );
923   renderTask.SetSourceActor( actor );
924
925   // Render and notify
926   application.SendNotification();
927   application.Render();
928
929   // Connect to layer's hovered signal
930   SignalData data;
931   HoverEventFunctor functor( data );
932   actor.HoveredSignal().Connect( &application, functor );
933   layer.HoveredSignal().Connect( &application, functor );
934
935   // Emit a started signal
936   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
937   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
938   data.Reset();
939
940   // Ensure renderTask actor can be hit too.
941   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
942   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
943   data.Reset();
944
945   // Disable input on renderTask, should not be hittable
946   renderTask.SetInputEnabled( false );
947   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
948   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
949   data.Reset();
950   END_TEST;
951 }
952
953 int UtcDaliHoverOffscreenRenderTasks(void)
954 {
955   TestApplication application;
956   Stage stage ( Stage::GetCurrent() );
957   Vector2 stageSize ( stage.GetSize() );
958
959   // FrameBufferImage for offscreen RenderTask
960   FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
961
962   // Create an image actor to display the FrameBufferImage
963   ImageActor imageActor ( ImageActor::New( frameBufferImage ) );
964   imageActor.SetParentOrigin(ParentOrigin::CENTER);
965   imageActor.SetSize( stageSize.x, stageSize.y );
966   imageActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
967   stage.Add( imageActor );
968
969   Actor actor = Actor::New();
970   actor.SetSize(100.0f, 100.0f);
971   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
972   stage.Add( actor );
973   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
974
975   stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
976
977   // Create a RenderTask
978   RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
979   renderTask.SetSourceActor( actor );
980   renderTask.SetTargetFrameBuffer( frameBufferImage );
981   renderTask.SetInputEnabled( true );
982
983   // Create another RenderTask
984   RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
985   renderTask2.SetInputEnabled( true );
986
987   // Render and notify
988   application.SendNotification();
989   application.Render();
990
991   // Connect to actor's hovered signal
992   SignalData data;
993   HoverEventFunctor functor( data );
994   actor.HoveredSignal().Connect( &application, functor );
995
996   // Emit a started signal
997   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
998   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
999   data.Reset();
1000   END_TEST;
1001 }
1002
1003 int UtcDaliHoverMultipleRenderableActors(void)
1004 {
1005   TestApplication application;
1006   Stage stage ( Stage::GetCurrent() );
1007   Vector2 stageSize ( stage.GetSize() );
1008
1009   ImageActor parent = ImageActor::New();
1010   parent.SetSize( 100.0f, 100.0f );
1011   parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1012   stage.Add(parent);
1013
1014   ImageActor actor = ImageActor::New();
1015   actor.SetSize( 100.0f, 100.0f );
1016   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1017   actor.SetSortModifier( 1.0f );
1018   parent.Add(actor);
1019
1020   // Render and notify
1021   application.SendNotification();
1022   application.Render();
1023
1024   // Connect to layer's hovered signal
1025   SignalData data;
1026   HoverEventFunctor functor( data );
1027   parent.HoveredSignal().Connect( &application, functor );
1028   actor.HoveredSignal().Connect( &application, functor );
1029
1030   // Emit a started signal
1031   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1032   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1033   DALI_TEST_CHECK( actor == data.hoveredActor );
1034   END_TEST;
1035 }
1036
1037 int UtcDaliHoverActorRemovedInSignal(void)
1038 {
1039   TestApplication application;
1040
1041   Actor actor = Actor::New();
1042   actor.SetSize(100.0f, 100.0f);
1043   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1044   Stage::GetCurrent().Add(actor);
1045
1046   // Render and notify
1047   application.SendNotification();
1048   application.Render();
1049
1050   // Connect to actor's hovered signal
1051   SignalData data;
1052   RemoveActorFunctor functor( data );
1053   actor.HoveredSignal().Connect( &application, functor );
1054
1055   // Register for leave events
1056   actor.SetLeaveRequired( true );
1057
1058   // Emit a started signal
1059   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1060   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1061   data.Reset();
1062
1063   // Re-add, render and notify
1064   Stage::GetCurrent().Add(actor);
1065   application.SendNotification();
1066   application.Render();
1067
1068   // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1069   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1070   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1071   data.Reset();
1072
1073   // Emit a started signal
1074   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1075   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1076   data.Reset();
1077
1078   // Render and notify
1079   application.SendNotification();
1080   application.Render();
1081
1082   // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1083   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1084   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1085   data.Reset();
1086
1087   // Re-add actor back to stage, render and notify
1088   Stage::GetCurrent().Add(actor);
1089   application.SendNotification();
1090   application.Render();
1091
1092   // Emit another started event
1093   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1094   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1095   data.Reset();
1096
1097   // Completely delete the actor
1098   actor.Reset();
1099
1100   // Emit event, should not crash and should not receive an event.
1101   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1102   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1103   END_TEST;
1104 }
1105
1106 int UtcDaliHoverActorSignalNotConsumed(void)
1107 {
1108   TestApplication application;
1109
1110   Actor actor = Actor::New();
1111   actor.SetSize(100.0f, 100.0f);
1112   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1113   Stage::GetCurrent().Add(actor);
1114
1115   // Render and notify
1116   application.SendNotification();
1117   application.Render();
1118
1119   // Connect to actor's hovered signal
1120   SignalData data;
1121   HoverEventFunctor functor( data, false );
1122   actor.HoveredSignal().Connect( &application, functor );
1123
1124   // Emit a started signal
1125   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1126   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1127   END_TEST;
1128 }
1129
1130 int UtcDaliHoverActorUnStaged(void)
1131 {
1132   TestApplication application;
1133
1134   Actor actor = Actor::New();
1135   actor.SetSize(100.0f, 100.0f);
1136   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1137   Stage::GetCurrent().Add(actor);
1138
1139   // Render and notify
1140   application.SendNotification();
1141   application.Render();
1142
1143   // Connect to actor's hovered signal
1144   SignalData data;
1145   HoverEventFunctor functor( data );
1146   actor.HoveredSignal().Connect( &application, functor );
1147
1148   // Emit a started signal
1149   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1150   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1151   data.Reset();
1152
1153   // Remove actor from stage
1154   Stage::GetCurrent().Remove( actor );
1155
1156   // Render and notify
1157   application.SendNotification();
1158   application.Render();
1159
1160   // Emit a move at the same point, we should not be signalled.
1161   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1162   DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1163   data.Reset();
1164   END_TEST;
1165 }
1166
1167 int UtcDaliHoverSystemOverlayActor(void)
1168 {
1169   TestApplication application;
1170   Dali::Integration::Core& core( application.GetCore() );
1171   Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1172   systemOverlay.GetOverlayRenderTasks().CreateTask();
1173
1174   // Create an actor and add it to the system overlay.
1175   Actor systemActor = Actor::New();
1176   systemActor.SetSize(100.0f, 100.0f);
1177   systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1178   systemOverlay.Add( systemActor );
1179
1180   // Create an actor and add it to the stage as per normal, same position and size as systemActor
1181   Actor actor = Actor::New();
1182   actor.SetSize(100.0f, 100.0f);
1183   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1184   Stage::GetCurrent().Add(actor);
1185
1186   // Connect to the hover signals.
1187   SignalData data;
1188   HoverEventFunctor functor( data );
1189   systemActor.HoveredSignal().Connect( &application, functor );
1190   actor.HoveredSignal().Connect( &application, functor );
1191
1192   // Render and notify
1193   application.SendNotification();
1194   application.Render();
1195
1196   // Emit a started signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1197   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1198   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1199   DALI_TEST_CHECK( systemActor == data.hoveredActor );
1200   END_TEST;
1201 }
1202
1203 int UtcDaliHoverLeaveActorReadded(void)
1204 {
1205   TestApplication application;
1206   Stage stage = Stage::GetCurrent();
1207
1208   Actor actor = Actor::New();
1209   actor.SetSize(100.0f, 100.0f);
1210   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1211   stage.Add(actor);
1212
1213   // Set actor to receive hover-events
1214   actor.SetLeaveRequired( true );
1215
1216   // Render and notify
1217   application.SendNotification();
1218   application.Render();
1219
1220   // Connect to actor's hovered signal
1221   SignalData data;
1222   HoverEventFunctor functor( data );
1223   actor.HoveredSignal().Connect( &application, functor );
1224
1225   // Emit a started and motion
1226   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1227   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1228   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1229   data.Reset();
1230
1231   // Remove actor from stage and add again
1232   stage.Remove( actor );
1233   stage.Add( actor );
1234
1235   // Emit a motion within the actor's bounds
1236   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1237   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1238   data.Reset();
1239
1240   // Emit a motion outside the actor's bounds
1241   application.ProcessEvent( GenerateSingleHover( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1242   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1243   DALI_TEST_EQUALS( TouchPoint::Leave, data.hoverEvent.points[0].state, TEST_LOCATION );
1244   data.Reset();
1245
1246   END_TEST;
1247 }
1248
1249
1250 int UtcDaliHoverStencilNonRenderableActor(void)
1251 {
1252   TestApplication application;
1253   Stage stage = Stage::GetCurrent();
1254
1255   Actor actor = Actor::New();
1256   actor.SetSize(100.0f, 100.0f);
1257   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1258   stage.Add(actor);
1259
1260   Actor stencil = Actor::New();
1261   stencil.SetSize(50.0f, 50.0f);
1262   stencil.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1263   stencil.SetDrawMode( DrawMode::STENCIL );
1264   stage.Add(stencil);
1265
1266   // Render and notify
1267   application.SendNotification();
1268   application.Render();
1269
1270   // Connect to actor's hovered signal
1271   SignalData data;
1272   HoverEventFunctor functor( data );
1273   actor.HoveredSignal().Connect( &application, functor );
1274
1275   // Emit an event within stencil area
1276   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 10.0f, 10.0f ) ) );
1277   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1278   data.Reset();
1279
1280   // Emit an event outside the stencil area but within the actor area, we should have a hit!
1281   application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, Vector2( 60.0f, 60.0f ) ) );
1282   DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1283   data.Reset();
1284
1285   END_TEST;
1286 }