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, const Vector2& screenPosition )
122 Integration::TouchEvent touchEvent;
123 Integration::Point point;
124 point.SetState( static_cast< PointState::Type >( state ) );
125 point.SetScreenPosition( screenPosition );
126 touchEvent.points.push_back( point );
132 ///////////////////////////////////////////////////////////////////////////////
134 int UtcDaliTouchNormalProcessing(void)
136 TestApplication application;
138 Actor actor = Actor::New();
139 actor.SetSize(100.0f, 100.0f);
140 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
141 Stage::GetCurrent().Add(actor);
144 application.SendNotification();
145 application.Render();
147 // Connect to actor's touched signal
149 TouchEventFunctor functor( data );
150 actor.TouchedSignal().Connect( &application, functor );
152 Vector2 screenCoordinates( 10.0f, 10.0f );
153 Vector2 localCoordinates;
154 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
156 // Emit a down signal
157 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
158 const TouchPoint *point1 = &data.touchEvent.GetPoint(0);
159 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
160 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
161 DALI_TEST_EQUALS( TouchPoint::Down, point1->state, TEST_LOCATION );
162 DALI_TEST_EQUALS( screenCoordinates, point1->screen, TEST_LOCATION );
163 DALI_TEST_EQUALS( localCoordinates, point1->local, 0.1f, TEST_LOCATION );
166 // Emit a motion signal
167 screenCoordinates.x = screenCoordinates.y = 11.0f;
168 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
169 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
170 const TouchPoint *point2 = &data.touchEvent.GetPoint(0);
171 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
172 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
173 DALI_TEST_EQUALS( TouchPoint::Motion, point2->state, TEST_LOCATION );
174 DALI_TEST_EQUALS( screenCoordinates, point2->screen, TEST_LOCATION );
175 DALI_TEST_EQUALS( localCoordinates, point2->local, 0.1f, TEST_LOCATION );
179 screenCoordinates.x = screenCoordinates.y = 12.0f;
180 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
181 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
183 const TouchPoint *point3ptr = &data.touchEvent.GetPoint(0);
184 TouchPoint point3( point3ptr->deviceId, point3ptr->state, point3ptr->screen.x, point3ptr->screen.y, point3ptr->local.x, point3ptr->local.y );
186 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
187 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
188 DALI_TEST_EQUALS( TouchPoint::Up, point3.state, TEST_LOCATION );
189 DALI_TEST_EQUALS( screenCoordinates, point3.screen, TEST_LOCATION );
190 DALI_TEST_EQUALS( localCoordinates, point3.local, 0.1f, TEST_LOCATION );
193 // Emit a down signal where the actor is not present
194 screenCoordinates.x = screenCoordinates.y = 200.0f;
195 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
196 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
200 int UtcDaliTouchOutsideCameraNearFarPlanes(void)
202 TestApplication application;
204 Stage stage = Stage::GetCurrent();
205 Vector2 stageSize = stage.GetSize();
207 Actor actor = Actor::New();
208 actor.SetSize(100.0f, 100.0f);
209 actor.SetAnchorPoint(AnchorPoint::CENTER);
210 actor.SetParentOrigin(ParentOrigin::CENTER);
214 application.SendNotification();
215 application.Render();
217 // Get the camera's near and far planes
218 RenderTaskList taskList = stage.GetRenderTaskList();
219 Dali::RenderTask task = taskList.GetTask(0);
220 CameraActor camera = task.GetCameraActor();
221 float nearPlane = camera.GetNearClippingPlane();
222 float farPlane = camera.GetFarClippingPlane();
224 // Calculate the current distance of the actor from the camera
225 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
226 float distance = (stageSize.y * 0.5f) / tanHalfFov;
228 // Connect to actor's touched signal
230 TouchEventFunctor functor( data );
231 actor.TouchedSignal().Connect( &application, functor );
233 Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
235 // Emit a down signal
236 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
237 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
240 // Emit a down signal where actor is just at the camera's near plane
241 actor.SetZ(distance - nearPlane);
244 application.SendNotification();
245 application.Render();
247 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
248 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
251 // Emit a down signal where actor is closer than the camera's near plane
252 actor.SetZ((distance - nearPlane) + 1.0f);
255 application.SendNotification();
256 application.Render();
258 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
259 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
262 // Emit a down signal where actor is just at the camera's far plane
263 actor.SetZ(distance - farPlane);
266 application.SendNotification();
267 application.Render();
269 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
270 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
273 // Emit a down signal where actor is further than the camera's far plane
274 actor.SetZ((distance - farPlane) - 1.0f);
277 application.SendNotification();
278 application.Render();
280 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
281 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
286 int UtcDaliTouchEmitEmpty(void)
288 TestApplication application;
292 // Emit an empty TouchEvent
293 Integration::TouchEvent event;
294 application.ProcessEvent( event );
295 tet_result( TET_FAIL );
297 catch ( Dali::DaliException& e )
299 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
304 int UtcDaliTouchInterrupted(void)
306 TestApplication application;
308 Actor actor = Actor::New();
309 actor.SetSize(100.0f, 100.0f);
310 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
311 Stage::GetCurrent().Add(actor);
314 application.SendNotification();
315 application.Render();
317 // Connect to actor's touched signal
319 TouchEventFunctor functor( data );
320 actor.TouchedSignal().Connect( &application, functor );
322 // Emit a down signal
323 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
324 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
325 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
328 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
329 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
330 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
331 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
334 // Emit another interrupted signal, our signal handler should not be called.
335 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
336 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
340 int UtcDaliTouchParentConsumer(void)
342 TestApplication application;
343 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
345 Actor actor = Actor::New();
346 actor.SetSize(100.0f, 100.0f);
347 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
348 Stage::GetCurrent().Add(actor);
351 application.SendNotification();
352 application.Render();
354 // Connect to actor's touched signal
356 TouchEventFunctor functor( data, false );
357 actor.TouchedSignal().Connect( &application, functor );
359 // Connect to root actor's touched signal
361 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
362 rootActor.TouchedSignal().Connect( &application, rootFunctor );
364 Vector2 screenCoordinates( 10.0f, 10.0f );
365 Vector2 actorCoordinates, rootCoordinates;
366 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
367 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
369 // Emit a down signal
370 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
371 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
372 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
373 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
374 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
375 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
376 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
377 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
378 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
379 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
380 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
381 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
382 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
386 // Emit a motion signal
387 screenCoordinates.x = screenCoordinates.y = 11.0f;
388 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
389 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
390 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
391 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
392 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
393 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
394 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
395 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
396 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
397 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
398 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
399 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
400 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
401 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
402 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
407 screenCoordinates.x = screenCoordinates.y = 12.0f;
408 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
409 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
410 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
411 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
412 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
413 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
414 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
415 DALI_TEST_EQUALS( TouchPoint::Up, data.touchEvent.points[0].state, TEST_LOCATION );
416 DALI_TEST_EQUALS( TouchPoint::Up, rootData.touchEvent.points[0].state, TEST_LOCATION );
417 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
418 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
419 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
420 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
421 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
422 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
426 // Emit a down signal where the actor is not present, will hit the root actor though
427 screenCoordinates.x = screenCoordinates.y = 200.0f;
428 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
429 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
430 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
431 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
432 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
433 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
434 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
435 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
436 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
440 int UtcDaliTouchInterruptedParentConsumer(void)
442 TestApplication application;
443 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
445 Actor actor = Actor::New();
446 actor.SetSize(100.0f, 100.0f);
447 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
448 Stage::GetCurrent().Add(actor);
451 application.SendNotification();
452 application.Render();
454 // Connect to actor's touched signal
456 TouchEventFunctor functor( data, false );
457 actor.TouchedSignal().Connect( &application, functor );
459 // Connect to root actor's touched signal
461 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
462 rootActor.TouchedSignal().Connect( &application, rootFunctor );
464 // Emit a down signal
465 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
466 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
467 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
468 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
469 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
470 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
471 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
475 // Emit an interrupted signal
476 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
477 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
478 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
479 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
480 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
481 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
482 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
486 // Emit another down signal
487 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
488 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
489 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
490 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
491 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
495 // Remove actor from Stage
496 Stage::GetCurrent().Remove( actor );
501 application.SendNotification();
502 application.Render();
504 // Emit an interrupted signal, only root actor's signal should be called.
505 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
506 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
507 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
508 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
509 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
513 // Emit another interrupted state, none of the signal's should be called.
514 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
515 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
516 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
520 int UtcDaliTouchLeave(void)
522 TestApplication application;
524 Actor actor = Actor::New();
525 actor.SetSize(100.0f, 100.0f);
526 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
527 Stage::GetCurrent().Add(actor);
530 application.SendNotification();
531 application.Render();
533 // Connect to actor's touched signal
535 TouchEventFunctor functor( data );
536 actor.TouchedSignal().Connect( &application, functor );
538 // Set actor to require leave events
539 actor.SetLeaveRequired( true );
541 // Emit a down signal
542 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
543 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
544 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
547 // Emit a motion signal outside of actor, should be signalled with a Leave
548 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
549 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
550 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
553 // Another motion outside of actor, no signalling
554 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
555 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
558 // Another motion event inside actor, signalled with motion
559 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
560 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
561 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
564 // We do not want to listen to leave events anymore
565 actor.SetLeaveRequired( false );
567 // Another motion event outside of actor, no signalling
568 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
569 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
574 int UtcDaliTouchLeaveParentConsumer(void)
576 TestApplication application;
577 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
579 Actor actor = Actor::New();
580 actor.SetSize(100.0f, 100.0f);
581 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
582 Stage::GetCurrent().Add(actor);
585 application.SendNotification();
586 application.Render();
588 // Connect to actor's touched signal
590 TouchEventFunctor functor( data, false );
591 actor.TouchedSignal().Connect( &application, functor );
593 // Connect to root actor's touched signal
595 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
596 rootActor.TouchedSignal().Connect( &application, rootFunctor );
598 // Set actor to require leave events
599 actor.SetLeaveRequired( true );
600 rootActor.SetLeaveRequired( true );
602 // Emit a down signal
603 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
604 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
606 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
607 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
608 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
609 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
613 // Emit a motion signal outside of actor, should be signalled with a Leave
614 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
615 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
616 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
617 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
618 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.touchEvent.points[0].state, TEST_LOCATION );
619 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
620 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
624 // Another motion outside of actor, only rootActor signalled
625 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
626 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
627 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
628 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
629 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
633 // Another motion event inside actor, signalled with motion
634 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
635 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
636 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
637 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
638 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
639 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
640 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
644 // We do not want to listen to leave events of actor anymore
645 actor.SetLeaveRequired( false );
647 // Another motion event outside of root actor, only root signalled
648 Vector2 stageSize( Stage::GetCurrent().GetSize() );
649 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
650 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
651 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
652 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.touchEvent.points[0].state, TEST_LOCATION );
656 int UtcDaliTouchActorBecomesInsensitive(void)
658 TestApplication application;
660 Actor actor = Actor::New();
661 actor.SetSize(100.0f, 100.0f);
662 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
663 Stage::GetCurrent().Add(actor);
666 application.SendNotification();
667 application.Render();
669 // Connect to actor's touched signal
671 TouchEventFunctor functor( data );
672 actor.TouchedSignal().Connect( &application, functor );
674 // Emit a down signal
675 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
676 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
677 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
680 // Change actor to insensitive
681 actor.SetSensitive( false );
683 // Emit a motion signal, signalled with an interrupted
684 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
685 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
686 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
691 int UtcDaliTouchActorBecomesInsensitiveParentConsumer(void)
693 TestApplication application;
694 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
696 Actor actor = Actor::New();
697 actor.SetSize(100.0f, 100.0f);
698 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
699 Stage::GetCurrent().Add(actor);
702 application.SendNotification();
703 application.Render();
705 // Connect to actor's touched signal
707 TouchEventFunctor functor( data, false );
708 actor.TouchedSignal().Connect( &application, functor );
710 // Connect to root actor's touched signal
712 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
713 rootActor.TouchedSignal().Connect( &application, rootFunctor );
715 // Emit a down signal
716 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
717 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
718 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
719 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
720 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
721 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
722 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
727 application.SendNotification();
728 application.Render();
730 // Make root actor insensitive
731 rootActor.SetSensitive( false );
733 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
734 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
735 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
736 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
737 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
738 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
742 int UtcDaliTouchMultipleLayers(void)
744 TestApplication application;
745 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
747 // Connect to actor's touched signal
749 TouchEventFunctor functor( data );
751 Layer layer1 ( Layer::New() );
752 layer1.SetSize(100.0f, 100.0f);
753 layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
754 Stage::GetCurrent().Add( layer1 );
756 Actor actor1 ( Actor::New() );
757 actor1.SetSize( 100.0f, 100.0f );
758 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
759 actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
760 layer1.Add( actor1 );
763 application.SendNotification();
764 application.Render();
766 // Connect to layer1 and actor1
767 layer1.TouchedSignal().Connect( &application, functor );
768 actor1.TouchedSignal().Connect( &application, functor );
770 // Hit in hittable area, actor1 should be hit
771 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
772 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
773 DALI_TEST_CHECK( data.touchedActor == actor1 );
776 // Make layer1 insensitive, nothing should be hit
777 layer1.SetSensitive( false );
778 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
779 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
782 // Make layer1 sensitive again, again actor1 will be hit
783 layer1.SetSensitive( true );
784 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
785 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
786 DALI_TEST_CHECK( data.touchedActor == actor1 );
789 // Make rootActor insensitive, nothing should be hit
790 rootActor.SetSensitive( false );
791 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
792 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
795 // Make rootActor sensitive
796 rootActor.SetSensitive( true );
799 Layer layer2 ( Layer::New() );
800 layer2.SetSize(100.0f, 100.0f );
801 layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
802 layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
803 Stage::GetCurrent().Add( layer2 );
805 Actor actor2 ( Actor::New() );
806 actor2.SetSize(100.0f, 100.0f);
807 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
808 layer2.Add( actor2 );
811 application.SendNotification();
812 application.Render();
814 // Connect to layer2 and actor2
815 layer2.TouchedSignal().Connect( &application, functor );
816 actor2.TouchedSignal().Connect( &application, functor );
818 // Emit an event, should hit layer2
819 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
820 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
821 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
824 // Make layer2 insensitive, should hit actor1
825 layer2.SetSensitive( false );
826 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
827 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
828 DALI_TEST_CHECK( data.touchedActor == actor1 );
831 // Make layer2 sensitive again, should hit layer2
832 layer2.SetSensitive( true );
833 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
834 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
835 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
838 // Make layer2 invisible, render and notify
839 layer2.SetVisible( false );
840 application.SendNotification();
841 application.Render();
844 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
845 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
846 DALI_TEST_CHECK( data.touchedActor == actor1 );
849 // Make rootActor invisible, render and notify
850 rootActor.SetVisible( false );
851 application.SendNotification();
852 application.Render();
854 // Should not hit anything
855 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
856 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
861 int UtcDaliTouchMultipleRenderTasks(void)
863 TestApplication application;
864 Stage stage ( Stage::GetCurrent() );
865 Vector2 stageSize ( stage.GetSize() );
867 Actor actor = Actor::New();
868 actor.SetSize(100.0f, 100.0f);
869 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
872 // Create render task
873 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
874 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
875 renderTask.SetViewport( viewport );
876 renderTask.SetInputEnabled( true );
879 application.SendNotification();
880 application.Render();
882 // Connect to actor's touched signal
884 TouchEventFunctor functor( data );
885 actor.TouchedSignal().Connect( &application, functor );
887 // Emit a down signal
888 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
889 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
892 // Ensure renderTask actor can be hit too.
893 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
894 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
897 // Disable input on renderTask, should not be hittable
898 renderTask.SetInputEnabled( false );
899 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
900 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
905 int UtcDaliTouchMultipleRenderTasksWithChildLayer(void)
907 TestApplication application;
908 Stage stage ( Stage::GetCurrent() );
909 Vector2 stageSize ( stage.GetSize() );
911 Actor actor = Actor::New();
912 actor.SetSize(100.0f, 100.0f);
913 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
916 Layer layer = Layer::New();
917 layer.SetSize(100.0f, 100.0f);
918 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
921 // Create render task
922 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
923 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
924 renderTask.SetViewport( viewport );
925 renderTask.SetInputEnabled( true );
926 renderTask.SetSourceActor( actor );
929 application.SendNotification();
930 application.Render();
932 // Connect to layer's touched signal
934 TouchEventFunctor functor( data );
935 actor.TouchedSignal().Connect( &application, functor );
936 layer.TouchedSignal().Connect( &application, functor );
938 // Emit a down signal
939 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
940 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
943 // Ensure renderTask actor can be hit too.
944 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
945 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
948 // Disable input on renderTask, should not be hittable
949 renderTask.SetInputEnabled( false );
950 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
951 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
956 int UtcDaliTouchOffscreenRenderTasks(void)
958 TestApplication application;
959 Stage stage ( Stage::GetCurrent() );
960 Vector2 stageSize ( stage.GetSize() );
962 // FrameBufferImage for offscreen RenderTask
963 FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
965 // Create a renderable actor to display the FrameBufferImage
966 Actor renderableActor = CreateRenderableActor( frameBufferImage );
967 renderableActor.SetParentOrigin(ParentOrigin::CENTER);
968 renderableActor.SetSize( stageSize.x, stageSize.y );
969 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
970 stage.Add( renderableActor );
972 Actor actor = Actor::New();
973 actor.SetSize(100.0f, 100.0f);
974 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
976 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
978 stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
980 // Create a RenderTask
981 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
982 renderTask.SetSourceActor( actor );
983 renderTask.SetTargetFrameBuffer( frameBufferImage );
984 renderTask.SetInputEnabled( true );
986 // Create another RenderTask
987 RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
988 renderTask2.SetInputEnabled( true );
991 application.SendNotification();
992 application.Render();
994 // Connect to actor's touched signal
996 TouchEventFunctor functor( data );
997 actor.TouchedSignal().Connect( &application, functor );
999 // Emit a down signal
1000 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1001 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1006 int UtcDaliTouchMultipleRenderableActors(void)
1008 TestApplication application;
1009 Stage stage ( Stage::GetCurrent() );
1010 Vector2 stageSize ( stage.GetSize() );
1012 Actor parent = CreateRenderableActor();
1013 parent.SetSize(100.0f, 100.0f);
1014 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1017 Actor actor = CreateRenderableActor();
1018 actor.SetSize(100.0f, 100.0f);
1019 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1022 // Render and notify
1023 application.SendNotification();
1024 application.Render();
1026 // Connect to layer's touched signal
1028 TouchEventFunctor functor( data );
1029 parent.TouchedSignal().Connect( &application, functor );
1030 actor.TouchedSignal().Connect( &application, functor );
1032 // Emit a down signal
1033 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1034 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1035 DALI_TEST_CHECK( actor == data.touchedActor );
1039 int UtcDaliTouchActorRemovedInSignal(void)
1041 TestApplication application;
1043 Actor actor = Actor::New();
1044 actor.SetSize(100.0f, 100.0f);
1045 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1046 Stage::GetCurrent().Add(actor);
1048 // Render and notify
1049 application.SendNotification();
1050 application.Render();
1052 // Connect to actor's touched signal
1054 RemoveActorFunctor functor( data );
1055 actor.TouchedSignal().Connect( &application, functor );
1057 // Register for leave events
1058 actor.SetLeaveRequired( true );
1060 // Emit a down signal
1061 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1062 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1065 // Re-add, render and notify
1066 Stage::GetCurrent().Add(actor);
1067 application.SendNotification();
1068 application.Render();
1070 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1071 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1072 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1075 // Emit a down signal
1076 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1077 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1080 // Render and notify
1081 application.SendNotification();
1082 application.Render();
1084 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1085 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1086 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1089 // Re-add actor back to stage, render and notify
1090 Stage::GetCurrent().Add(actor);
1091 application.SendNotification();
1092 application.Render();
1094 // Emit another down event
1095 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1096 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1099 // Completely delete the actor
1102 // Emit event, should not crash and should not receive an event.
1103 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1104 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1108 int UtcDaliTouchActorSignalNotConsumed(void)
1110 TestApplication application;
1112 Actor actor = Actor::New();
1113 actor.SetSize(100.0f, 100.0f);
1114 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1115 Stage::GetCurrent().Add(actor);
1117 // Render and notify
1118 application.SendNotification();
1119 application.Render();
1121 // Connect to actor's touched signal
1123 TouchEventFunctor functor( data, false );
1124 actor.TouchedSignal().Connect( &application, functor );
1126 // Emit a down signal
1127 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1128 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1132 int UtcDaliTouchActorUnStaged(void)
1134 TestApplication application;
1136 Actor actor = Actor::New();
1137 actor.SetSize(100.0f, 100.0f);
1138 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1139 Stage::GetCurrent().Add(actor);
1141 // Render and notify
1142 application.SendNotification();
1143 application.Render();
1145 // Connect to actor's touched signal
1147 TouchEventFunctor functor( data );
1148 actor.TouchedSignal().Connect( &application, functor );
1150 // Emit a down signal
1151 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1152 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1155 // Remove actor from stage
1156 Stage::GetCurrent().Remove( actor );
1159 // Render and notify
1160 application.SendNotification();
1161 application.Render();
1163 // Emit a move at the same point, we should not be signalled.
1164 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1165 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1170 int UtcDaliTouchSystemOverlayActor(void)
1172 TestApplication application;
1173 Dali::Integration::Core& core( application.GetCore() );
1174 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1175 systemOverlay.GetOverlayRenderTasks().CreateTask();
1177 // Create an actor and add it to the system overlay.
1178 Actor systemActor = Actor::New();
1179 systemActor.SetSize(100.0f, 100.0f);
1180 systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1181 systemOverlay.Add( systemActor );
1183 // Create an actor and add it to the stage as per normal, same position and size as systemActor
1184 Actor actor = Actor::New();
1185 actor.SetSize(100.0f, 100.0f);
1186 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1187 Stage::GetCurrent().Add(actor);
1189 // Connect to the touch signals.
1191 TouchEventFunctor functor( data );
1192 systemActor.TouchedSignal().Connect( &application, functor );
1193 actor.TouchedSignal().Connect( &application, functor );
1195 // Render and notify
1196 application.SendNotification();
1197 application.Render();
1199 // Emit a down signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1200 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1201 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1202 DALI_TEST_CHECK( systemActor == data.touchedActor );
1206 int UtcDaliTouchLayerConsumesTouch(void)
1208 TestApplication application;
1210 Actor actor = Actor::New();
1211 actor.SetSize(100.0f, 100.0f);
1212 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1213 Stage::GetCurrent().Add(actor);
1215 // Render and notify
1216 application.SendNotification();
1217 application.Render();
1219 // Connect to actor's touched signal
1221 TouchEventFunctor functor( data );
1222 actor.TouchedSignal().Connect( &application, functor );
1224 // Add a layer to overlap the actor
1225 Layer layer = Layer::New();
1226 layer.SetSize(100.0f, 100.0f);
1227 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1228 Stage::GetCurrent().Add( layer );
1231 // Render and notify
1232 application.SendNotification();
1233 application.Render();
1235 // Emit a few touch signals
1236 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1237 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1238 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1241 // Set layer to consume all touch
1242 layer.SetTouchConsumed( true );
1244 // Render and notify
1245 application.SendNotification();
1246 application.Render();
1248 // Emit the same signals again, should not receive
1249 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1250 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1251 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1257 int UtcDaliTouchLeaveActorReadded(void)
1259 TestApplication application;
1260 Stage stage = Stage::GetCurrent();
1262 Actor actor = Actor::New();
1263 actor.SetSize(100.0f, 100.0f);
1264 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1267 // Set actor to receive touch-events
1268 actor.SetLeaveRequired( true );
1270 // Render and notify
1271 application.SendNotification();
1272 application.Render();
1274 // Connect to actor's touched signal
1276 TouchEventFunctor functor( data );
1277 actor.TouchedSignal().Connect( &application, functor );
1279 // Emit a down and motion
1280 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1281 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1282 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1285 // Remove actor from stage and add again
1286 stage.Remove( actor );
1289 // Emit a motion within the actor's bounds
1290 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1291 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1294 // Emit a motion outside the actor's bounds
1295 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1296 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1297 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
1303 int UtcDaliTouchClippingActor(void)
1305 TestApplication application;
1306 Stage stage = Stage::GetCurrent();
1308 Actor actor = Actor::New();
1309 actor.SetSize( 100.0f, 100.0f );
1310 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1313 Actor clippingActor = Actor::New();
1314 clippingActor.SetSize( 50.0f, 50.0f );
1315 clippingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1316 clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1317 stage.Add( clippingActor );
1319 // Render and notify.
1320 application.SendNotification();
1321 application.Render();
1323 // Connect to actor's touched signal.
1325 TouchEventFunctor functor( data );
1326 actor.TouchedSignal().Connect( &application, functor );
1328 // Emit an event within clipped area.
1329 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1330 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1333 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1334 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 60.0f, 60.0f ) ) );
1335 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1341 int UtcDaliTouchActorUnstaged(void)
1343 TestApplication application;
1345 Actor actor = Actor::New();
1346 actor.SetSize(100.0f, 100.0f);
1347 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1348 Stage::GetCurrent().Add(actor);
1350 // Render and notify
1351 application.SendNotification();
1352 application.Render();
1354 // Connect to actor's touched signal
1356 TouchEventFunctor functor( data );
1357 actor.TouchedSignal().Connect( &application, functor );
1359 // Emit a down signal
1360 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1361 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1362 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1363 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1366 // Render and notify
1367 application.SendNotification();
1368 application.Render();
1370 // Unparent the actor
1373 // Should receive an interrupted event
1374 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1375 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1379 int UtcDaliTouchParentUnstaged(void)
1381 TestApplication application;
1383 Actor parent = Actor::New();
1384 parent.SetSize(100.0f, 100.0f);
1385 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1386 Stage::GetCurrent().Add(parent);
1388 Actor actor = Actor::New();
1389 actor.SetSize(100.0f, 100.0f);
1390 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1393 // Render and notify
1394 application.SendNotification();
1395 application.Render();
1397 // Connect to actor's touched signal
1399 TouchEventFunctor functor( data );
1400 actor.TouchedSignal().Connect( &application, functor );
1402 // Emit a down signal
1403 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1404 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1405 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1406 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1409 // Render and notify
1410 application.SendNotification();
1411 application.Render();
1413 // Unparent the parent of the touchable actor
1416 // Should receive an interrupted event
1417 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1418 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1422 int UtcDaliTouchActorUnstagedDifferentConsumer(void)
1424 TestApplication application;
1426 Actor parent = Actor::New();
1427 parent.SetSize(100.0f, 100.0f);
1428 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1429 Stage::GetCurrent().Add(parent);
1431 Actor actor = Actor::New();
1432 actor.SetSize(100.0f, 100.0f);
1433 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1436 // Render and notify
1437 application.SendNotification();
1438 application.Render();
1440 // Connect to actor's touched signal
1442 TouchEventFunctor functor( data, false /* Do not consume */ );
1443 actor.TouchedSignal().Connect( &application, functor );
1445 // Connect to parent's touched signal
1446 SignalData parentData;
1447 TouchEventFunctor parentFunctor( parentData );
1448 parent.TouchedSignal().Connect( &application, parentFunctor );
1450 // Emit a down signal
1451 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1452 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1453 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1454 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1455 DALI_TEST_CHECK( actor == data.touchedActor );
1456 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1457 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1458 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1459 DALI_TEST_CHECK( parent == parentData.touchedActor );
1463 // Render and notify
1464 application.SendNotification();
1465 application.Render();
1467 // Unparent the actor
1470 // Should receive an interrupted event for both actor & parent
1471 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1472 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1473 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1474 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1478 // Readd actor to parent
1481 // Render and notify
1482 application.SendNotification();
1483 application.Render();
1485 // Emit a motion signal
1486 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1487 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1488 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1492 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1493 SignalData secondData;
1494 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1495 actor.TouchedSignal().Connect( &application, secondFunctor );
1497 // Unparent the actor
1500 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1501 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1502 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1503 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1504 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1505 DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1506 DALI_TEST_EQUALS( TouchPoint::Interrupted, secondData.touchEvent.points[0].state, TEST_LOCATION );
1514 int UtcDaliTouchInterruptedDifferentConsumer(void)
1516 TestApplication application;
1517 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
1519 Actor parent = Actor::New();
1520 parent.SetSize(100.0f, 100.0f);
1521 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1522 Stage::GetCurrent().Add(parent);
1524 Actor actor = Actor::New();
1525 actor.SetSize(100.0f, 100.0f);
1526 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1529 // Render and notify
1530 application.SendNotification();
1531 application.Render();
1533 // Connect to actor's touched signal
1535 TouchEventFunctor functor( data, false /* Do not consume */ );
1536 actor.TouchedSignal().Connect( &application, functor );
1538 // Connect to parent's touched signal
1539 SignalData parentData;
1540 TouchEventFunctor parentFunctor( parentData, false /* Do not consume */ );
1541 parent.TouchedSignal().Connect( &application, parentFunctor );
1543 // Connect to root's touched signal and consume
1544 SignalData rootData;
1545 TouchEventFunctor rootFunctor( rootData );
1546 rootActor.TouchedSignal().Connect( &application, rootFunctor );
1548 // Emit a down signal
1549 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1550 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1551 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1552 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1553 DALI_TEST_CHECK( actor == data.touchedActor );
1554 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1555 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1556 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1557 DALI_TEST_CHECK( parent == parentData.touchedActor );
1558 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1559 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
1560 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
1561 DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1566 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1567 SignalData secondData;
1568 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1569 parent.TouchedSignal().Connect( &application, secondFunctor );
1571 // Emit an interrupted signal, all three should STILL be called
1572 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 10.0f, 10.0f ) ) );
1573 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1574 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1575 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1576 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1577 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1578 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );