2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali-test-suite-utils.h>
28 void utc_dali_touch_processing_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_touch_processing_cleanup(void)
35 test_return_value = TET_PASS;
38 ///////////////////////////////////////////////////////////////////////////////
43 // Stores data that is populated in the callback and will be read by the TET cases
47 : functorCalled( false ),
55 functorCalled = false;
58 touchEvent.points.clear();
64 TouchEvent touchEvent;
68 // Functor that sets the data when called
69 struct TouchEventFunctor
73 * @param[in] data Reference to the data to store callback information.
74 * @param[in] returnValue What the functor should return.
76 TouchEventFunctor( SignalData& data, bool returnValue = true )
78 returnValue( returnValue )
82 bool operator()( Actor actor, const TouchEvent& touchEvent )
84 signalData.functorCalled = true;
85 signalData.touchedActor = actor;
86 signalData.touchEvent = touchEvent;
91 SignalData& signalData;
95 // Functor that removes the actor when called.
96 struct RemoveActorFunctor : public TouchEventFunctor
100 * @param[in] data Reference to the data to store callback information.
101 * @param[in] returnValue What the functor should return.
103 RemoveActorFunctor( SignalData& data, bool returnValue = true )
104 : TouchEventFunctor( data, returnValue )
108 bool operator()( Actor actor, const TouchEvent& touchEvent )
110 Actor parent( actor.GetParent() );
113 parent.Remove( actor );
116 return TouchEventFunctor::operator()( actor, touchEvent );
120 Integration::TouchEvent GenerateSingleTouch( TouchPoint::State state, Vector2 screenPosition )
122 Integration::TouchEvent touchEvent;
123 touchEvent.points.push_back( TouchPoint ( 0, state, screenPosition.x, screenPosition.y ) );
129 ///////////////////////////////////////////////////////////////////////////////
131 int UtcDaliTouchNormalProcessing(void)
133 TestApplication application;
135 Actor actor = Actor::New();
136 actor.SetSize(100.0f, 100.0f);
137 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
138 Stage::GetCurrent().Add(actor);
141 application.SendNotification();
142 application.Render();
144 // Connect to actor's touched signal
146 TouchEventFunctor functor( data );
147 actor.TouchedSignal().Connect( &application, functor );
149 Vector2 screenCoordinates( 10.0f, 10.0f );
150 Vector2 localCoordinates;
151 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
153 // Emit a down signal
154 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
155 const TouchPoint *point1 = &data.touchEvent.GetPoint(0);
156 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
157 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
158 DALI_TEST_EQUALS( TouchPoint::Down, point1->state, TEST_LOCATION );
159 DALI_TEST_EQUALS( screenCoordinates, point1->screen, TEST_LOCATION );
160 DALI_TEST_EQUALS( localCoordinates, point1->local, 0.1f, TEST_LOCATION );
163 // Emit a motion signal
164 screenCoordinates.x = screenCoordinates.y = 11.0f;
165 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
166 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
167 const TouchPoint *point2 = &data.touchEvent.GetPoint(0);
168 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
169 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
170 DALI_TEST_EQUALS( TouchPoint::Motion, point2->state, TEST_LOCATION );
171 DALI_TEST_EQUALS( screenCoordinates, point2->screen, TEST_LOCATION );
172 DALI_TEST_EQUALS( localCoordinates, point2->local, 0.1f, TEST_LOCATION );
176 screenCoordinates.x = screenCoordinates.y = 12.0f;
177 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
178 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
179 const TouchPoint *point3 = &data.touchEvent.GetPoint(0);
180 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
181 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
182 DALI_TEST_EQUALS( TouchPoint::Up, point3->state, TEST_LOCATION );
183 DALI_TEST_EQUALS( screenCoordinates, point3->screen, TEST_LOCATION );
184 DALI_TEST_EQUALS( localCoordinates, point3->local, 0.1f, TEST_LOCATION );
187 // Emit a down signal where the actor is not present
188 screenCoordinates.x = screenCoordinates.y = 200.0f;
189 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
190 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
194 int UtcDaliTouchOutsideCameraNearFarPlanes(void)
196 TestApplication application;
198 Stage stage = Stage::GetCurrent();
199 Vector2 stageSize = stage.GetSize();
201 Actor actor = Actor::New();
202 actor.SetSize(100.0f, 100.0f);
203 actor.SetAnchorPoint(AnchorPoint::CENTER);
204 actor.SetParentOrigin(ParentOrigin::CENTER);
208 application.SendNotification();
209 application.Render();
211 // Get the camera's near and far planes
212 RenderTaskList taskList = stage.GetRenderTaskList();
213 Dali::RenderTask task = taskList.GetTask(0);
214 CameraActor camera = task.GetCameraActor();
215 float nearPlane = camera.GetNearClippingPlane();
216 float farPlane = camera.GetFarClippingPlane();
218 // Calculate the current distance of the actor from the camera
219 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
220 float distance = (stageSize.y * 0.5f) / tanHalfFov;
222 // Connect to actor's touched signal
224 TouchEventFunctor functor( data );
225 actor.TouchedSignal().Connect( &application, functor );
227 Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
229 // Emit a down signal
230 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
231 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
234 // Emit a down signal where actor is just at the camera's near plane
235 actor.SetZ(distance - nearPlane);
238 application.SendNotification();
239 application.Render();
241 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
242 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
245 // Emit a down signal where actor is closer than the camera's near plane
246 actor.SetZ((distance - nearPlane) + 1.0f);
249 application.SendNotification();
250 application.Render();
252 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
253 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
256 // Emit a down signal where actor is just at the camera's far plane
257 actor.SetZ(distance - farPlane);
260 application.SendNotification();
261 application.Render();
263 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
264 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
267 // Emit a down signal where actor is further than the camera's far plane
268 actor.SetZ((distance - farPlane) - 1.0f);
271 application.SendNotification();
272 application.Render();
274 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
275 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
280 int UtcDaliTouchEmitEmpty(void)
282 TestApplication application;
286 // Emit an empty TouchEvent
287 Integration::TouchEvent event;
288 application.ProcessEvent( event );
289 tet_result( TET_FAIL );
291 catch ( Dali::DaliException& e )
293 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
298 int UtcDaliTouchInterrupted(void)
300 TestApplication application;
302 Actor actor = Actor::New();
303 actor.SetSize(100.0f, 100.0f);
304 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
305 Stage::GetCurrent().Add(actor);
308 application.SendNotification();
309 application.Render();
311 // Connect to actor's touched signal
313 TouchEventFunctor functor( data );
314 actor.TouchedSignal().Connect( &application, functor );
316 // Emit a down signal
317 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
318 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
319 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
322 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
323 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
324 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
325 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
328 // Emit another interrupted signal, our signal handler should not be called.
329 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
330 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
334 int UtcDaliTouchParentConsumer(void)
336 TestApplication application;
337 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
339 Actor actor = Actor::New();
340 actor.SetSize(100.0f, 100.0f);
341 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
342 Stage::GetCurrent().Add(actor);
345 application.SendNotification();
346 application.Render();
348 // Connect to actor's touched signal
350 TouchEventFunctor functor( data, false );
351 actor.TouchedSignal().Connect( &application, functor );
353 // Connect to root actor's touched signal
355 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
356 rootActor.TouchedSignal().Connect( &application, rootFunctor );
358 Vector2 screenCoordinates( 10.0f, 10.0f );
359 Vector2 actorCoordinates, rootCoordinates;
360 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
361 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
363 // Emit a down signal
364 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
365 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
366 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
367 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
368 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
369 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
370 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
371 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
372 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
373 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
374 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
375 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
376 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
380 // Emit a motion signal
381 screenCoordinates.x = screenCoordinates.y = 11.0f;
382 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
383 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
384 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
385 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
386 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
387 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
388 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
389 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
390 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
391 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
392 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
393 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
394 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
395 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
396 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
401 screenCoordinates.x = screenCoordinates.y = 12.0f;
402 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
403 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
404 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
405 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
406 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
407 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
408 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
409 DALI_TEST_EQUALS( TouchPoint::Up, data.touchEvent.points[0].state, TEST_LOCATION );
410 DALI_TEST_EQUALS( TouchPoint::Up, rootData.touchEvent.points[0].state, TEST_LOCATION );
411 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
412 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
413 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
414 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
415 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
416 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
420 // Emit a down signal where the actor is not present, will hit the root actor though
421 screenCoordinates.x = screenCoordinates.y = 200.0f;
422 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
423 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
424 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
425 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
426 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
427 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
428 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
429 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
430 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
434 int UtcDaliTouchInterruptedParentConsumer(void)
436 TestApplication application;
437 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
439 Actor actor = Actor::New();
440 actor.SetSize(100.0f, 100.0f);
441 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
442 Stage::GetCurrent().Add(actor);
445 application.SendNotification();
446 application.Render();
448 // Connect to actor's touched signal
450 TouchEventFunctor functor( data, false );
451 actor.TouchedSignal().Connect( &application, functor );
453 // Connect to root actor's touched signal
455 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
456 rootActor.TouchedSignal().Connect( &application, rootFunctor );
458 // Emit a down signal
459 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
460 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
461 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
462 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
463 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
464 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
465 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
469 // Emit an interrupted signal
470 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
471 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
472 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
473 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
474 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
475 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
476 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
480 // Emit another down signal
481 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
482 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
483 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
484 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
485 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
489 // Remove actor from Stage
490 Stage::GetCurrent().Remove( actor );
495 application.SendNotification();
496 application.Render();
498 // Emit an interrupted signal, only root actor's signal should be called.
499 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
500 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
501 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
502 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
503 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
507 // Emit another interrupted state, none of the signal's should be called.
508 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
509 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
510 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
514 int UtcDaliTouchLeave(void)
516 TestApplication application;
518 Actor actor = Actor::New();
519 actor.SetSize(100.0f, 100.0f);
520 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
521 Stage::GetCurrent().Add(actor);
524 application.SendNotification();
525 application.Render();
527 // Connect to actor's touched signal
529 TouchEventFunctor functor( data );
530 actor.TouchedSignal().Connect( &application, functor );
532 // Set actor to require leave events
533 actor.SetLeaveRequired( true );
535 // Emit a down signal
536 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
537 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
538 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
541 // Emit a motion signal outside of actor, should be signalled with a Leave
542 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
543 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
544 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
547 // Another motion outside of actor, no signalling
548 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
549 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
552 // Another motion event inside actor, signalled with motion
553 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
554 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
555 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
558 // We do not want to listen to leave events anymore
559 actor.SetLeaveRequired( false );
561 // Another motion event outside of actor, no signalling
562 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
563 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
568 int UtcDaliTouchLeaveParentConsumer(void)
570 TestApplication application;
571 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
573 Actor actor = Actor::New();
574 actor.SetSize(100.0f, 100.0f);
575 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
576 Stage::GetCurrent().Add(actor);
579 application.SendNotification();
580 application.Render();
582 // Connect to actor's touched signal
584 TouchEventFunctor functor( data, false );
585 actor.TouchedSignal().Connect( &application, functor );
587 // Connect to root actor's touched signal
589 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
590 rootActor.TouchedSignal().Connect( &application, rootFunctor );
592 // Set actor to require leave events
593 actor.SetLeaveRequired( true );
594 rootActor.SetLeaveRequired( true );
596 // Emit a down signal
597 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
598 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
599 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
600 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
601 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
602 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
603 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
607 // Emit a motion signal outside of actor, should be signalled with a Leave
608 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
609 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
610 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
611 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
612 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.touchEvent.points[0].state, TEST_LOCATION );
613 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
614 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
618 // Another motion outside of actor, only rootActor signalled
619 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
620 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
621 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
622 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
623 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
627 // Another motion event inside actor, signalled with motion
628 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
629 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
630 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
631 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
632 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
633 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
634 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
638 // We do not want to listen to leave events of actor anymore
639 actor.SetLeaveRequired( false );
641 // Another motion event outside of root actor, only root signalled
642 Vector2 stageSize( Stage::GetCurrent().GetSize() );
643 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
644 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
645 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
646 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.touchEvent.points[0].state, TEST_LOCATION );
650 int UtcDaliTouchActorBecomesInsensitive(void)
652 TestApplication application;
654 Actor actor = Actor::New();
655 actor.SetSize(100.0f, 100.0f);
656 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
657 Stage::GetCurrent().Add(actor);
660 application.SendNotification();
661 application.Render();
663 // Connect to actor's touched signal
665 TouchEventFunctor functor( data );
666 actor.TouchedSignal().Connect( &application, functor );
668 // Emit a down signal
669 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
670 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
671 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
674 // Change actor to insensitive
675 actor.SetSensitive( false );
677 // Emit a motion signal, signalled with an interrupted
678 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
679 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
680 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
685 int UtcDaliTouchActorBecomesInsensitiveParentConsumer(void)
687 TestApplication application;
688 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
690 Actor actor = Actor::New();
691 actor.SetSize(100.0f, 100.0f);
692 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
693 Stage::GetCurrent().Add(actor);
696 application.SendNotification();
697 application.Render();
699 // Connect to actor's touched signal
701 TouchEventFunctor functor( data, false );
702 actor.TouchedSignal().Connect( &application, functor );
704 // Connect to root actor's touched signal
706 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
707 rootActor.TouchedSignal().Connect( &application, rootFunctor );
709 // Emit a down signal
710 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
711 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
712 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
713 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
714 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
715 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
716 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
721 application.SendNotification();
722 application.Render();
724 // Make root actor insensitive
725 rootActor.SetSensitive( false );
727 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
728 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
729 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
730 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
731 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
732 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
736 int UtcDaliTouchMultipleLayers(void)
738 TestApplication application;
739 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
741 // Connect to actor's touched signal
743 TouchEventFunctor functor( data );
745 Layer layer1 ( Layer::New() );
746 layer1.SetSize(100.0f, 100.0f);
747 layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
748 Stage::GetCurrent().Add( layer1 );
750 Actor actor1 ( Actor::New() );
751 actor1.SetSize( 100.0f, 100.0f );
752 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
753 actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
754 layer1.Add( actor1 );
757 application.SendNotification();
758 application.Render();
760 // Connect to layer1 and actor1
761 layer1.TouchedSignal().Connect( &application, functor );
762 actor1.TouchedSignal().Connect( &application, functor );
764 // Hit in hittable area, actor1 should be hit
765 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
766 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
767 DALI_TEST_CHECK( data.touchedActor == actor1 );
770 // Make layer1 insensitive, nothing should be hit
771 layer1.SetSensitive( false );
772 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
773 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
776 // Make layer1 sensitive again, again actor1 will be hit
777 layer1.SetSensitive( true );
778 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
779 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
780 DALI_TEST_CHECK( data.touchedActor == actor1 );
783 // Make rootActor insensitive, nothing should be hit
784 rootActor.SetSensitive( false );
785 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
786 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
789 // Make rootActor sensitive
790 rootActor.SetSensitive( true );
793 Layer layer2 ( Layer::New() );
794 layer2.SetSize(100.0f, 100.0f );
795 layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
796 layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
797 Stage::GetCurrent().Add( layer2 );
799 Actor actor2 ( Actor::New() );
800 actor2.SetSize(100.0f, 100.0f);
801 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
802 layer2.Add( actor2 );
805 application.SendNotification();
806 application.Render();
808 // Connect to layer2 and actor2
809 layer2.TouchedSignal().Connect( &application, functor );
810 actor2.TouchedSignal().Connect( &application, functor );
812 // Emit an event, should hit layer2
813 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
814 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
815 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
818 // Make layer2 insensitive, should hit actor1
819 layer2.SetSensitive( false );
820 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
821 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
822 DALI_TEST_CHECK( data.touchedActor == actor1 );
825 // Make layer2 sensitive again, should hit layer2
826 layer2.SetSensitive( true );
827 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
828 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
829 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
832 // Make layer2 invisible, render and notify
833 layer2.SetVisible( false );
834 application.SendNotification();
835 application.Render();
838 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
839 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
840 DALI_TEST_CHECK( data.touchedActor == actor1 );
843 // Make rootActor invisible, render and notify
844 rootActor.SetVisible( false );
845 application.SendNotification();
846 application.Render();
848 // Should not hit anything
849 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
850 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
855 int UtcDaliTouchMultipleRenderTasks(void)
857 TestApplication application;
858 Stage stage ( Stage::GetCurrent() );
859 Vector2 stageSize ( stage.GetSize() );
861 Actor actor = Actor::New();
862 actor.SetSize(100.0f, 100.0f);
863 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
866 // Create render task
867 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
868 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
869 renderTask.SetViewport( viewport );
870 renderTask.SetInputEnabled( true );
873 application.SendNotification();
874 application.Render();
876 // Connect to actor's touched signal
878 TouchEventFunctor functor( data );
879 actor.TouchedSignal().Connect( &application, functor );
881 // Emit a down signal
882 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
883 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
886 // Ensure renderTask actor can be hit too.
887 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
888 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
891 // Disable input on renderTask, should not be hittable
892 renderTask.SetInputEnabled( false );
893 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
894 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
899 int UtcDaliTouchMultipleRenderTasksWithChildLayer(void)
901 TestApplication application;
902 Stage stage ( Stage::GetCurrent() );
903 Vector2 stageSize ( stage.GetSize() );
905 Actor actor = Actor::New();
906 actor.SetSize(100.0f, 100.0f);
907 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
910 Layer layer = Layer::New();
911 layer.SetSize(100.0f, 100.0f);
912 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
915 // Create render task
916 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
917 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
918 renderTask.SetViewport( viewport );
919 renderTask.SetInputEnabled( true );
920 renderTask.SetSourceActor( actor );
923 application.SendNotification();
924 application.Render();
926 // Connect to layer's touched signal
928 TouchEventFunctor functor( data );
929 actor.TouchedSignal().Connect( &application, functor );
930 layer.TouchedSignal().Connect( &application, functor );
932 // Emit a down signal
933 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
934 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
937 // Ensure renderTask actor can be hit too.
938 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
939 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
942 // Disable input on renderTask, should not be hittable
943 renderTask.SetInputEnabled( false );
944 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
945 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
950 int UtcDaliTouchOffscreenRenderTasks(void)
952 TestApplication application;
953 Stage stage ( Stage::GetCurrent() );
954 Vector2 stageSize ( stage.GetSize() );
956 // FrameBufferImage for offscreen RenderTask
957 FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
959 // Create a renderable actor to display the FrameBufferImage
960 Actor renderableActor = CreateRenderableActor( frameBufferImage );
961 renderableActor.SetParentOrigin(ParentOrigin::CENTER);
962 renderableActor.SetSize( stageSize.x, stageSize.y );
963 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
964 stage.Add( renderableActor );
966 Actor actor = Actor::New();
967 actor.SetSize(100.0f, 100.0f);
968 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
970 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
972 stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
974 // Create a RenderTask
975 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
976 renderTask.SetSourceActor( actor );
977 renderTask.SetTargetFrameBuffer( frameBufferImage );
978 renderTask.SetInputEnabled( true );
980 // Create another RenderTask
981 RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
982 renderTask2.SetInputEnabled( true );
985 application.SendNotification();
986 application.Render();
988 // Connect to actor's touched signal
990 TouchEventFunctor functor( data );
991 actor.TouchedSignal().Connect( &application, functor );
993 // Emit a down signal
994 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
995 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1000 int UtcDaliTouchMultipleRenderableActors(void)
1002 TestApplication application;
1003 Stage stage ( Stage::GetCurrent() );
1004 Vector2 stageSize ( stage.GetSize() );
1006 Actor parent = CreateRenderableActor();
1007 parent.SetSize(100.0f, 100.0f);
1008 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1011 Actor actor = CreateRenderableActor();
1012 actor.SetSize(100.0f, 100.0f);
1013 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1016 // Render and notify
1017 application.SendNotification();
1018 application.Render();
1020 // Connect to layer's touched signal
1022 TouchEventFunctor functor( data );
1023 parent.TouchedSignal().Connect( &application, functor );
1024 actor.TouchedSignal().Connect( &application, functor );
1026 // Emit a down signal
1027 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1028 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1029 DALI_TEST_CHECK( actor == data.touchedActor );
1033 int UtcDaliTouchActorRemovedInSignal(void)
1035 TestApplication application;
1037 Actor actor = Actor::New();
1038 actor.SetSize(100.0f, 100.0f);
1039 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1040 Stage::GetCurrent().Add(actor);
1042 // Render and notify
1043 application.SendNotification();
1044 application.Render();
1046 // Connect to actor's touched signal
1048 RemoveActorFunctor functor( data );
1049 actor.TouchedSignal().Connect( &application, functor );
1051 // Register for leave events
1052 actor.SetLeaveRequired( true );
1054 // Emit a down signal
1055 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1056 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1059 // Re-add, render and notify
1060 Stage::GetCurrent().Add(actor);
1061 application.SendNotification();
1062 application.Render();
1064 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1065 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1066 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1069 // Emit a down signal
1070 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1071 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1074 // Render and notify
1075 application.SendNotification();
1076 application.Render();
1078 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1079 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1080 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1083 // Re-add actor back to stage, render and notify
1084 Stage::GetCurrent().Add(actor);
1085 application.SendNotification();
1086 application.Render();
1088 // Emit another down event
1089 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1090 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1093 // Completely delete the actor
1096 // Emit event, should not crash and should not receive an event.
1097 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1098 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1102 int UtcDaliTouchActorSignalNotConsumed(void)
1104 TestApplication application;
1106 Actor actor = Actor::New();
1107 actor.SetSize(100.0f, 100.0f);
1108 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1109 Stage::GetCurrent().Add(actor);
1111 // Render and notify
1112 application.SendNotification();
1113 application.Render();
1115 // Connect to actor's touched signal
1117 TouchEventFunctor functor( data, false );
1118 actor.TouchedSignal().Connect( &application, functor );
1120 // Emit a down signal
1121 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1122 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1126 int UtcDaliTouchActorUnStaged(void)
1128 TestApplication application;
1130 Actor actor = Actor::New();
1131 actor.SetSize(100.0f, 100.0f);
1132 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1133 Stage::GetCurrent().Add(actor);
1135 // Render and notify
1136 application.SendNotification();
1137 application.Render();
1139 // Connect to actor's touched signal
1141 TouchEventFunctor functor( data );
1142 actor.TouchedSignal().Connect( &application, functor );
1144 // Emit a down signal
1145 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1146 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1149 // Remove actor from stage
1150 Stage::GetCurrent().Remove( actor );
1153 // Render and notify
1154 application.SendNotification();
1155 application.Render();
1157 // Emit a move at the same point, we should not be signalled.
1158 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1159 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1164 int UtcDaliTouchSystemOverlayActor(void)
1166 TestApplication application;
1167 Dali::Integration::Core& core( application.GetCore() );
1168 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1169 systemOverlay.GetOverlayRenderTasks().CreateTask();
1171 // Create an actor and add it to the system overlay.
1172 Actor systemActor = Actor::New();
1173 systemActor.SetSize(100.0f, 100.0f);
1174 systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1175 systemOverlay.Add( systemActor );
1177 // Create an actor and add it to the stage as per normal, same position and size as systemActor
1178 Actor actor = Actor::New();
1179 actor.SetSize(100.0f, 100.0f);
1180 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1181 Stage::GetCurrent().Add(actor);
1183 // Connect to the touch signals.
1185 TouchEventFunctor functor( data );
1186 systemActor.TouchedSignal().Connect( &application, functor );
1187 actor.TouchedSignal().Connect( &application, functor );
1189 // Render and notify
1190 application.SendNotification();
1191 application.Render();
1193 // Emit a down signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1194 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1195 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1196 DALI_TEST_CHECK( systemActor == data.touchedActor );
1200 int UtcDaliTouchLayerConsumesTouch(void)
1202 TestApplication application;
1204 Actor actor = Actor::New();
1205 actor.SetSize(100.0f, 100.0f);
1206 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1207 Stage::GetCurrent().Add(actor);
1209 // Render and notify
1210 application.SendNotification();
1211 application.Render();
1213 // Connect to actor's touched signal
1215 TouchEventFunctor functor( data );
1216 actor.TouchedSignal().Connect( &application, functor );
1218 // Add a layer to overlap the actor
1219 Layer layer = Layer::New();
1220 layer.SetSize(100.0f, 100.0f);
1221 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1222 Stage::GetCurrent().Add( layer );
1225 // Render and notify
1226 application.SendNotification();
1227 application.Render();
1229 // Emit a few touch signals
1230 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1231 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1232 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1235 // Set layer to consume all touch
1236 layer.SetTouchConsumed( true );
1238 // Render and notify
1239 application.SendNotification();
1240 application.Render();
1242 // Emit the same signals again, should not receive
1243 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1244 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1245 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1251 int UtcDaliTouchLeaveActorReadded(void)
1253 TestApplication application;
1254 Stage stage = Stage::GetCurrent();
1256 Actor actor = Actor::New();
1257 actor.SetSize(100.0f, 100.0f);
1258 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1261 // Set actor to receive touch-events
1262 actor.SetLeaveRequired( true );
1264 // Render and notify
1265 application.SendNotification();
1266 application.Render();
1268 // Connect to actor's touched signal
1270 TouchEventFunctor functor( data );
1271 actor.TouchedSignal().Connect( &application, functor );
1273 // Emit a down and motion
1274 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1275 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1276 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1279 // Remove actor from stage and add again
1280 stage.Remove( actor );
1283 // Emit a motion within the actor's bounds
1284 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1285 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1288 // Emit a motion outside the actor's bounds
1289 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1290 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1291 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
1297 int UtcDaliTouchStencilNonRenderableActor(void)
1299 TestApplication application;
1300 Stage stage = Stage::GetCurrent();
1302 Actor actor = Actor::New();
1303 actor.SetSize(100.0f, 100.0f);
1304 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1307 Actor stencil = Actor::New();
1308 stencil.SetSize(50.0f, 50.0f);
1309 stencil.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1310 stencil.SetDrawMode( DrawMode::STENCIL );
1313 // Render and notify
1314 application.SendNotification();
1315 application.Render();
1317 // Connect to actor's touched signal
1319 TouchEventFunctor functor( data );
1320 actor.TouchedSignal().Connect( &application, functor );
1322 // Emit an event within stencil area
1323 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1324 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1327 // Emit an event outside the stencil area but within the actor area, we should have a hit!
1328 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 60.0f, 60.0f ) ) );
1329 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1335 int UtcDaliTouchActorUnstaged(void)
1337 TestApplication application;
1339 Actor actor = Actor::New();
1340 actor.SetSize(100.0f, 100.0f);
1341 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1342 Stage::GetCurrent().Add(actor);
1344 // Render and notify
1345 application.SendNotification();
1346 application.Render();
1348 // Connect to actor's touched signal
1350 TouchEventFunctor functor( data );
1351 actor.TouchedSignal().Connect( &application, functor );
1353 // Emit a down signal
1354 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1355 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1356 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1357 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1360 // Render and notify
1361 application.SendNotification();
1362 application.Render();
1364 // Unparent the actor
1367 // Should receive an interrupted event
1368 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1369 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1373 int UtcDaliTouchParentUnstaged(void)
1375 TestApplication application;
1377 Actor parent = Actor::New();
1378 parent.SetSize(100.0f, 100.0f);
1379 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1380 Stage::GetCurrent().Add(parent);
1382 Actor actor = Actor::New();
1383 actor.SetSize(100.0f, 100.0f);
1384 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1387 // Render and notify
1388 application.SendNotification();
1389 application.Render();
1391 // Connect to actor's touched signal
1393 TouchEventFunctor functor( data );
1394 actor.TouchedSignal().Connect( &application, functor );
1396 // Emit a down signal
1397 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1398 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1399 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1400 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1403 // Render and notify
1404 application.SendNotification();
1405 application.Render();
1407 // Unparent the parent of the touchable actor
1410 // Should receive an interrupted event
1411 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1412 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1416 int UtcDaliTouchActorUnstagedDifferentConsumer(void)
1418 TestApplication application;
1420 Actor parent = Actor::New();
1421 parent.SetSize(100.0f, 100.0f);
1422 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1423 Stage::GetCurrent().Add(parent);
1425 Actor actor = Actor::New();
1426 actor.SetSize(100.0f, 100.0f);
1427 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1430 // Render and notify
1431 application.SendNotification();
1432 application.Render();
1434 // Connect to actor's touched signal
1436 TouchEventFunctor functor( data, false /* Do not consume */ );
1437 actor.TouchedSignal().Connect( &application, functor );
1439 // Connect to parent's touched signal
1440 SignalData parentData;
1441 TouchEventFunctor parentFunctor( parentData );
1442 parent.TouchedSignal().Connect( &application, parentFunctor );
1444 // Emit a down signal
1445 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1446 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1447 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1448 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1449 DALI_TEST_CHECK( actor == data.touchedActor );
1450 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1451 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1452 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1453 DALI_TEST_CHECK( parent == parentData.touchedActor );
1457 // Render and notify
1458 application.SendNotification();
1459 application.Render();
1461 // Unparent the actor
1464 // Should receive an interrupted event for both actor & parent
1465 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1466 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1467 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1468 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1472 // Readd actor to parent
1475 // Render and notify
1476 application.SendNotification();
1477 application.Render();
1479 // Emit a motion signal
1480 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1481 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1482 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1486 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1487 SignalData secondData;
1488 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1489 actor.TouchedSignal().Connect( &application, secondFunctor );
1491 // Unparent the actor
1494 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1495 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1496 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1497 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1498 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1499 DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1500 DALI_TEST_EQUALS( TouchPoint::Interrupted, secondData.touchEvent.points[0].state, TEST_LOCATION );
1508 int UtcDaliTouchInterruptedDifferentConsumer(void)
1510 TestApplication application;
1511 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
1513 Actor parent = Actor::New();
1514 parent.SetSize(100.0f, 100.0f);
1515 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1516 Stage::GetCurrent().Add(parent);
1518 Actor actor = Actor::New();
1519 actor.SetSize(100.0f, 100.0f);
1520 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1523 // Render and notify
1524 application.SendNotification();
1525 application.Render();
1527 // Connect to actor's touched signal
1529 TouchEventFunctor functor( data, false /* Do not consume */ );
1530 actor.TouchedSignal().Connect( &application, functor );
1532 // Connect to parent's touched signal
1533 SignalData parentData;
1534 TouchEventFunctor parentFunctor( parentData, false /* Do not consume */ );
1535 parent.TouchedSignal().Connect( &application, parentFunctor );
1537 // Connect to root's touched signal and consume
1538 SignalData rootData;
1539 TouchEventFunctor rootFunctor( rootData );
1540 rootActor.TouchedSignal().Connect( &application, rootFunctor );
1542 // Emit a down signal
1543 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1544 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1545 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1546 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1547 DALI_TEST_CHECK( actor == data.touchedActor );
1548 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1549 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1550 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1551 DALI_TEST_CHECK( parent == parentData.touchedActor );
1552 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1553 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
1554 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
1555 DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1560 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1561 SignalData secondData;
1562 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1563 parent.TouchedSignal().Connect( &application, secondFunctor );
1565 // Emit an interrupted signal, all three should STILL be called
1566 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 10.0f, 10.0f ) ) );
1567 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1568 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1569 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1570 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1571 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1572 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );