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 ) );
182 const TouchPoint *point3 = &data.touchEvent.GetPoint(0);
183 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
184 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
185 DALI_TEST_EQUALS( TouchPoint::Up, point3->state, TEST_LOCATION );
186 DALI_TEST_EQUALS( screenCoordinates, point3->screen, TEST_LOCATION );
187 DALI_TEST_EQUALS( localCoordinates, point3->local, 0.1f, TEST_LOCATION );
190 // Emit a down signal where the actor is not present
191 screenCoordinates.x = screenCoordinates.y = 200.0f;
192 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
193 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
197 int UtcDaliTouchOutsideCameraNearFarPlanes(void)
199 TestApplication application;
201 Stage stage = Stage::GetCurrent();
202 Vector2 stageSize = stage.GetSize();
204 Actor actor = Actor::New();
205 actor.SetSize(100.0f, 100.0f);
206 actor.SetAnchorPoint(AnchorPoint::CENTER);
207 actor.SetParentOrigin(ParentOrigin::CENTER);
211 application.SendNotification();
212 application.Render();
214 // Get the camera's near and far planes
215 RenderTaskList taskList = stage.GetRenderTaskList();
216 Dali::RenderTask task = taskList.GetTask(0);
217 CameraActor camera = task.GetCameraActor();
218 float nearPlane = camera.GetNearClippingPlane();
219 float farPlane = camera.GetFarClippingPlane();
221 // Calculate the current distance of the actor from the camera
222 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
223 float distance = (stageSize.y * 0.5f) / tanHalfFov;
225 // Connect to actor's touched signal
227 TouchEventFunctor functor( data );
228 actor.TouchedSignal().Connect( &application, functor );
230 Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
232 // Emit a down signal
233 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
234 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
237 // Emit a down signal where actor is just at the camera's near plane
238 actor.SetZ(distance - nearPlane);
241 application.SendNotification();
242 application.Render();
244 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
245 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
248 // Emit a down signal where actor is closer than the camera's near plane
249 actor.SetZ((distance - nearPlane) + 1.0f);
252 application.SendNotification();
253 application.Render();
255 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
256 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
259 // Emit a down signal where actor is just at the camera's far plane
260 actor.SetZ(distance - farPlane);
263 application.SendNotification();
264 application.Render();
266 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
267 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
270 // Emit a down signal where actor is further than the camera's far plane
271 actor.SetZ((distance - farPlane) - 1.0f);
274 application.SendNotification();
275 application.Render();
277 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
278 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
283 int UtcDaliTouchEmitEmpty(void)
285 TestApplication application;
289 // Emit an empty TouchEvent
290 Integration::TouchEvent event;
291 application.ProcessEvent( event );
292 tet_result( TET_FAIL );
294 catch ( Dali::DaliException& e )
296 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
301 int UtcDaliTouchInterrupted(void)
303 TestApplication application;
305 Actor actor = Actor::New();
306 actor.SetSize(100.0f, 100.0f);
307 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
308 Stage::GetCurrent().Add(actor);
311 application.SendNotification();
312 application.Render();
314 // Connect to actor's touched signal
316 TouchEventFunctor functor( data );
317 actor.TouchedSignal().Connect( &application, functor );
319 // Emit a down signal
320 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
321 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
322 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
325 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
326 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
327 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
328 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
331 // Emit another interrupted signal, our signal handler should not be called.
332 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
333 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
337 int UtcDaliTouchParentConsumer(void)
339 TestApplication application;
340 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
342 Actor actor = Actor::New();
343 actor.SetSize(100.0f, 100.0f);
344 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
345 Stage::GetCurrent().Add(actor);
348 application.SendNotification();
349 application.Render();
351 // Connect to actor's touched signal
353 TouchEventFunctor functor( data, false );
354 actor.TouchedSignal().Connect( &application, functor );
356 // Connect to root actor's touched signal
358 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
359 rootActor.TouchedSignal().Connect( &application, rootFunctor );
361 Vector2 screenCoordinates( 10.0f, 10.0f );
362 Vector2 actorCoordinates, rootCoordinates;
363 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
364 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
366 // Emit a down signal
367 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
368 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
369 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
370 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
371 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
372 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
373 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
374 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
375 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
376 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
377 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
378 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
379 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
383 // Emit a motion signal
384 screenCoordinates.x = screenCoordinates.y = 11.0f;
385 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
386 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
387 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
388 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
389 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
390 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
391 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
392 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
393 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
394 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
395 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
396 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
397 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
398 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
399 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
404 screenCoordinates.x = screenCoordinates.y = 12.0f;
405 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
406 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
407 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
408 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
409 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
410 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
411 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
412 DALI_TEST_EQUALS( TouchPoint::Up, data.touchEvent.points[0].state, TEST_LOCATION );
413 DALI_TEST_EQUALS( TouchPoint::Up, rootData.touchEvent.points[0].state, TEST_LOCATION );
414 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
415 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
416 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
417 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
418 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
419 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
423 // Emit a down signal where the actor is not present, will hit the root actor though
424 screenCoordinates.x = screenCoordinates.y = 200.0f;
425 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
426 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
427 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
428 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
429 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
430 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
431 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
432 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
433 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
437 int UtcDaliTouchInterruptedParentConsumer(void)
439 TestApplication application;
440 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
442 Actor actor = Actor::New();
443 actor.SetSize(100.0f, 100.0f);
444 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
445 Stage::GetCurrent().Add(actor);
448 application.SendNotification();
449 application.Render();
451 // Connect to actor's touched signal
453 TouchEventFunctor functor( data, false );
454 actor.TouchedSignal().Connect( &application, functor );
456 // Connect to root actor's touched signal
458 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
459 rootActor.TouchedSignal().Connect( &application, rootFunctor );
461 // Emit a down signal
462 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
463 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
464 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
465 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
466 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
467 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
468 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
472 // Emit an interrupted signal
473 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
474 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
475 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
476 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
477 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
478 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
479 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
483 // Emit another down signal
484 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
485 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
486 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
487 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
488 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
492 // Remove actor from Stage
493 Stage::GetCurrent().Remove( actor );
498 application.SendNotification();
499 application.Render();
501 // Emit an interrupted signal, only root actor's signal should be called.
502 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
503 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
504 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
505 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
506 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
510 // Emit another interrupted state, none of the signal's should be called.
511 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
512 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
513 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
517 int UtcDaliTouchLeave(void)
519 TestApplication application;
521 Actor actor = Actor::New();
522 actor.SetSize(100.0f, 100.0f);
523 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
524 Stage::GetCurrent().Add(actor);
527 application.SendNotification();
528 application.Render();
530 // Connect to actor's touched signal
532 TouchEventFunctor functor( data );
533 actor.TouchedSignal().Connect( &application, functor );
535 // Set actor to require leave events
536 actor.SetLeaveRequired( true );
538 // Emit a down signal
539 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
540 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
541 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
544 // Emit a motion signal outside of actor, should be signalled with a Leave
545 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
546 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
547 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
550 // Another motion outside of actor, no signalling
551 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
552 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
555 // Another motion event inside actor, signalled with motion
556 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
557 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
558 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
561 // We do not want to listen to leave events anymore
562 actor.SetLeaveRequired( false );
564 // Another motion event outside of actor, no signalling
565 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
566 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
571 int UtcDaliTouchLeaveParentConsumer(void)
573 TestApplication application;
574 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
576 Actor actor = Actor::New();
577 actor.SetSize(100.0f, 100.0f);
578 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
579 Stage::GetCurrent().Add(actor);
582 application.SendNotification();
583 application.Render();
585 // Connect to actor's touched signal
587 TouchEventFunctor functor( data, false );
588 actor.TouchedSignal().Connect( &application, functor );
590 // Connect to root actor's touched signal
592 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
593 rootActor.TouchedSignal().Connect( &application, rootFunctor );
595 // Set actor to require leave events
596 actor.SetLeaveRequired( true );
597 rootActor.SetLeaveRequired( true );
599 // Emit a down signal
600 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
601 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
602 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
603 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
604 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
605 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
606 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
610 // Emit a motion signal outside of actor, should be signalled with a Leave
611 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
612 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
613 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
614 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
615 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.touchEvent.points[0].state, TEST_LOCATION );
616 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
617 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
621 // Another motion outside of actor, only rootActor signalled
622 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
623 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
624 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
625 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
626 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
630 // Another motion event inside actor, signalled with motion
631 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
632 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
633 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
634 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
635 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
636 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
637 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
641 // We do not want to listen to leave events of actor anymore
642 actor.SetLeaveRequired( false );
644 // Another motion event outside of root actor, only root signalled
645 Vector2 stageSize( Stage::GetCurrent().GetSize() );
646 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
647 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
648 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
649 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.touchEvent.points[0].state, TEST_LOCATION );
653 int UtcDaliTouchActorBecomesInsensitive(void)
655 TestApplication application;
657 Actor actor = Actor::New();
658 actor.SetSize(100.0f, 100.0f);
659 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
660 Stage::GetCurrent().Add(actor);
663 application.SendNotification();
664 application.Render();
666 // Connect to actor's touched signal
668 TouchEventFunctor functor( data );
669 actor.TouchedSignal().Connect( &application, functor );
671 // Emit a down signal
672 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
673 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
674 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
677 // Change actor to insensitive
678 actor.SetSensitive( false );
680 // Emit a motion signal, signalled with an interrupted
681 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
682 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
683 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
688 int UtcDaliTouchActorBecomesInsensitiveParentConsumer(void)
690 TestApplication application;
691 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
693 Actor actor = Actor::New();
694 actor.SetSize(100.0f, 100.0f);
695 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
696 Stage::GetCurrent().Add(actor);
699 application.SendNotification();
700 application.Render();
702 // Connect to actor's touched signal
704 TouchEventFunctor functor( data, false );
705 actor.TouchedSignal().Connect( &application, functor );
707 // Connect to root actor's touched signal
709 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
710 rootActor.TouchedSignal().Connect( &application, rootFunctor );
712 // Emit a down signal
713 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
714 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
715 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
716 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
717 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
718 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
719 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
724 application.SendNotification();
725 application.Render();
727 // Make root actor insensitive
728 rootActor.SetSensitive( false );
730 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
731 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
732 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
733 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
734 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
735 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
739 int UtcDaliTouchMultipleLayers(void)
741 TestApplication application;
742 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
744 // Connect to actor's touched signal
746 TouchEventFunctor functor( data );
748 Layer layer1 ( Layer::New() );
749 layer1.SetSize(100.0f, 100.0f);
750 layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
751 Stage::GetCurrent().Add( layer1 );
753 Actor actor1 ( Actor::New() );
754 actor1.SetSize( 100.0f, 100.0f );
755 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
756 actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
757 layer1.Add( actor1 );
760 application.SendNotification();
761 application.Render();
763 // Connect to layer1 and actor1
764 layer1.TouchedSignal().Connect( &application, functor );
765 actor1.TouchedSignal().Connect( &application, functor );
767 // Hit in hittable area, actor1 should be hit
768 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
769 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
770 DALI_TEST_CHECK( data.touchedActor == actor1 );
773 // Make layer1 insensitive, nothing should be hit
774 layer1.SetSensitive( false );
775 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
776 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
779 // Make layer1 sensitive again, again actor1 will be hit
780 layer1.SetSensitive( true );
781 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
782 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
783 DALI_TEST_CHECK( data.touchedActor == actor1 );
786 // Make rootActor insensitive, nothing should be hit
787 rootActor.SetSensitive( false );
788 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
789 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
792 // Make rootActor sensitive
793 rootActor.SetSensitive( true );
796 Layer layer2 ( Layer::New() );
797 layer2.SetSize(100.0f, 100.0f );
798 layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
799 layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
800 Stage::GetCurrent().Add( layer2 );
802 Actor actor2 ( Actor::New() );
803 actor2.SetSize(100.0f, 100.0f);
804 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
805 layer2.Add( actor2 );
808 application.SendNotification();
809 application.Render();
811 // Connect to layer2 and actor2
812 layer2.TouchedSignal().Connect( &application, functor );
813 actor2.TouchedSignal().Connect( &application, functor );
815 // Emit an event, should hit layer2
816 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
817 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
818 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
821 // Make layer2 insensitive, should hit actor1
822 layer2.SetSensitive( false );
823 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
824 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
825 DALI_TEST_CHECK( data.touchedActor == actor1 );
828 // Make layer2 sensitive again, should hit layer2
829 layer2.SetSensitive( true );
830 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
831 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
832 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
835 // Make layer2 invisible, render and notify
836 layer2.SetVisible( false );
837 application.SendNotification();
838 application.Render();
841 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
842 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
843 DALI_TEST_CHECK( data.touchedActor == actor1 );
846 // Make rootActor invisible, render and notify
847 rootActor.SetVisible( false );
848 application.SendNotification();
849 application.Render();
851 // Should not hit anything
852 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
853 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
858 int UtcDaliTouchMultipleRenderTasks(void)
860 TestApplication application;
861 Stage stage ( Stage::GetCurrent() );
862 Vector2 stageSize ( stage.GetSize() );
864 Actor actor = Actor::New();
865 actor.SetSize(100.0f, 100.0f);
866 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
869 // Create render task
870 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
871 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
872 renderTask.SetViewport( viewport );
873 renderTask.SetInputEnabled( true );
876 application.SendNotification();
877 application.Render();
879 // Connect to actor's touched signal
881 TouchEventFunctor functor( data );
882 actor.TouchedSignal().Connect( &application, functor );
884 // Emit a down signal
885 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
886 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
889 // Ensure renderTask actor can be hit too.
890 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
891 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
894 // Disable input on renderTask, should not be hittable
895 renderTask.SetInputEnabled( false );
896 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
897 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
902 int UtcDaliTouchMultipleRenderTasksWithChildLayer(void)
904 TestApplication application;
905 Stage stage ( Stage::GetCurrent() );
906 Vector2 stageSize ( stage.GetSize() );
908 Actor actor = Actor::New();
909 actor.SetSize(100.0f, 100.0f);
910 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
913 Layer layer = Layer::New();
914 layer.SetSize(100.0f, 100.0f);
915 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
918 // Create render task
919 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
920 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
921 renderTask.SetViewport( viewport );
922 renderTask.SetInputEnabled( true );
923 renderTask.SetSourceActor( actor );
926 application.SendNotification();
927 application.Render();
929 // Connect to layer's touched signal
931 TouchEventFunctor functor( data );
932 actor.TouchedSignal().Connect( &application, functor );
933 layer.TouchedSignal().Connect( &application, functor );
935 // Emit a down signal
936 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
937 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
940 // Ensure renderTask actor can be hit too.
941 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
942 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
945 // Disable input on renderTask, should not be hittable
946 renderTask.SetInputEnabled( false );
947 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
948 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
953 int UtcDaliTouchOffscreenRenderTasks(void)
955 TestApplication application;
956 Stage stage ( Stage::GetCurrent() );
957 Vector2 stageSize ( stage.GetSize() );
959 // FrameBufferImage for offscreen RenderTask
960 FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
962 // Create a renderable actor to display the FrameBufferImage
963 Actor renderableActor = CreateRenderableActor( frameBufferImage );
964 renderableActor.SetParentOrigin(ParentOrigin::CENTER);
965 renderableActor.SetSize( stageSize.x, stageSize.y );
966 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
967 stage.Add( renderableActor );
969 Actor actor = Actor::New();
970 actor.SetSize(100.0f, 100.0f);
971 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
973 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
975 stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
977 // Create a RenderTask
978 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
979 renderTask.SetSourceActor( actor );
980 renderTask.SetTargetFrameBuffer( frameBufferImage );
981 renderTask.SetInputEnabled( true );
983 // Create another RenderTask
984 RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
985 renderTask2.SetInputEnabled( true );
988 application.SendNotification();
989 application.Render();
991 // Connect to actor's touched signal
993 TouchEventFunctor functor( data );
994 actor.TouchedSignal().Connect( &application, functor );
996 // Emit a down signal
997 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
998 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1003 int UtcDaliTouchMultipleRenderableActors(void)
1005 TestApplication application;
1006 Stage stage ( Stage::GetCurrent() );
1007 Vector2 stageSize ( stage.GetSize() );
1009 Actor parent = CreateRenderableActor();
1010 parent.SetSize(100.0f, 100.0f);
1011 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1014 Actor actor = CreateRenderableActor();
1015 actor.SetSize(100.0f, 100.0f);
1016 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1019 // Render and notify
1020 application.SendNotification();
1021 application.Render();
1023 // Connect to layer's touched signal
1025 TouchEventFunctor functor( data );
1026 parent.TouchedSignal().Connect( &application, functor );
1027 actor.TouchedSignal().Connect( &application, functor );
1029 // Emit a down signal
1030 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1031 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1032 DALI_TEST_CHECK( actor == data.touchedActor );
1036 int UtcDaliTouchActorRemovedInSignal(void)
1038 TestApplication application;
1040 Actor actor = Actor::New();
1041 actor.SetSize(100.0f, 100.0f);
1042 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1043 Stage::GetCurrent().Add(actor);
1045 // Render and notify
1046 application.SendNotification();
1047 application.Render();
1049 // Connect to actor's touched signal
1051 RemoveActorFunctor functor( data );
1052 actor.TouchedSignal().Connect( &application, functor );
1054 // Register for leave events
1055 actor.SetLeaveRequired( true );
1057 // Emit a down signal
1058 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1059 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1062 // Re-add, render and notify
1063 Stage::GetCurrent().Add(actor);
1064 application.SendNotification();
1065 application.Render();
1067 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1068 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1069 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1072 // Emit a down signal
1073 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1074 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1077 // Render and notify
1078 application.SendNotification();
1079 application.Render();
1081 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1082 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1083 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1086 // Re-add actor back to stage, render and notify
1087 Stage::GetCurrent().Add(actor);
1088 application.SendNotification();
1089 application.Render();
1091 // Emit another down event
1092 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1093 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1096 // Completely delete the actor
1099 // Emit event, should not crash and should not receive an event.
1100 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1101 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1105 int UtcDaliTouchActorSignalNotConsumed(void)
1107 TestApplication application;
1109 Actor actor = Actor::New();
1110 actor.SetSize(100.0f, 100.0f);
1111 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1112 Stage::GetCurrent().Add(actor);
1114 // Render and notify
1115 application.SendNotification();
1116 application.Render();
1118 // Connect to actor's touched signal
1120 TouchEventFunctor functor( data, false );
1121 actor.TouchedSignal().Connect( &application, functor );
1123 // Emit a down signal
1124 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1125 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1129 int UtcDaliTouchActorUnStaged(void)
1131 TestApplication application;
1133 Actor actor = Actor::New();
1134 actor.SetSize(100.0f, 100.0f);
1135 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1136 Stage::GetCurrent().Add(actor);
1138 // Render and notify
1139 application.SendNotification();
1140 application.Render();
1142 // Connect to actor's touched signal
1144 TouchEventFunctor functor( data );
1145 actor.TouchedSignal().Connect( &application, functor );
1147 // Emit a down signal
1148 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1149 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1152 // Remove actor from stage
1153 Stage::GetCurrent().Remove( actor );
1156 // Render and notify
1157 application.SendNotification();
1158 application.Render();
1160 // Emit a move at the same point, we should not be signalled.
1161 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1162 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1167 int UtcDaliTouchSystemOverlayActor(void)
1169 TestApplication application;
1170 Dali::Integration::Core& core( application.GetCore() );
1171 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1172 systemOverlay.GetOverlayRenderTasks().CreateTask();
1174 // Create an actor and add it to the system overlay.
1175 Actor systemActor = Actor::New();
1176 systemActor.SetSize(100.0f, 100.0f);
1177 systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1178 systemOverlay.Add( systemActor );
1180 // Create an actor and add it to the stage as per normal, same position and size as systemActor
1181 Actor actor = Actor::New();
1182 actor.SetSize(100.0f, 100.0f);
1183 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1184 Stage::GetCurrent().Add(actor);
1186 // Connect to the touch signals.
1188 TouchEventFunctor functor( data );
1189 systemActor.TouchedSignal().Connect( &application, functor );
1190 actor.TouchedSignal().Connect( &application, functor );
1192 // Render and notify
1193 application.SendNotification();
1194 application.Render();
1196 // Emit a down signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1197 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1198 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1199 DALI_TEST_CHECK( systemActor == data.touchedActor );
1203 int UtcDaliTouchLayerConsumesTouch(void)
1205 TestApplication application;
1207 Actor actor = Actor::New();
1208 actor.SetSize(100.0f, 100.0f);
1209 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1210 Stage::GetCurrent().Add(actor);
1212 // Render and notify
1213 application.SendNotification();
1214 application.Render();
1216 // Connect to actor's touched signal
1218 TouchEventFunctor functor( data );
1219 actor.TouchedSignal().Connect( &application, functor );
1221 // Add a layer to overlap the actor
1222 Layer layer = Layer::New();
1223 layer.SetSize(100.0f, 100.0f);
1224 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1225 Stage::GetCurrent().Add( layer );
1228 // Render and notify
1229 application.SendNotification();
1230 application.Render();
1232 // Emit a few touch signals
1233 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1234 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1235 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1238 // Set layer to consume all touch
1239 layer.SetTouchConsumed( true );
1241 // Render and notify
1242 application.SendNotification();
1243 application.Render();
1245 // Emit the same signals again, should not receive
1246 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1247 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1248 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1254 int UtcDaliTouchLeaveActorReadded(void)
1256 TestApplication application;
1257 Stage stage = Stage::GetCurrent();
1259 Actor actor = Actor::New();
1260 actor.SetSize(100.0f, 100.0f);
1261 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1264 // Set actor to receive touch-events
1265 actor.SetLeaveRequired( true );
1267 // Render and notify
1268 application.SendNotification();
1269 application.Render();
1271 // Connect to actor's touched signal
1273 TouchEventFunctor functor( data );
1274 actor.TouchedSignal().Connect( &application, functor );
1276 // Emit a down and motion
1277 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1278 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1279 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1282 // Remove actor from stage and add again
1283 stage.Remove( actor );
1286 // Emit a motion within the actor's bounds
1287 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1288 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1291 // Emit a motion outside the actor's bounds
1292 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1293 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1294 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
1300 int UtcDaliTouchStencilNonRenderableActor(void)
1302 TestApplication application;
1303 Stage stage = Stage::GetCurrent();
1305 Actor actor = Actor::New();
1306 actor.SetSize(100.0f, 100.0f);
1307 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1310 Actor stencil = Actor::New();
1311 stencil.SetSize(50.0f, 50.0f);
1312 stencil.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1313 stencil.SetDrawMode( DrawMode::STENCIL );
1316 // Render and notify
1317 application.SendNotification();
1318 application.Render();
1320 // Connect to actor's touched signal
1322 TouchEventFunctor functor( data );
1323 actor.TouchedSignal().Connect( &application, functor );
1325 // Emit an event within stencil area
1326 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1327 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1330 // Emit an event outside the stencil area but within the actor area, we should have a hit!
1331 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 60.0f, 60.0f ) ) );
1332 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1338 int UtcDaliTouchActorUnstaged(void)
1340 TestApplication application;
1342 Actor actor = Actor::New();
1343 actor.SetSize(100.0f, 100.0f);
1344 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1345 Stage::GetCurrent().Add(actor);
1347 // Render and notify
1348 application.SendNotification();
1349 application.Render();
1351 // Connect to actor's touched signal
1353 TouchEventFunctor functor( data );
1354 actor.TouchedSignal().Connect( &application, functor );
1356 // Emit a down signal
1357 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1358 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1359 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1360 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1363 // Render and notify
1364 application.SendNotification();
1365 application.Render();
1367 // Unparent the actor
1370 // Should receive an interrupted event
1371 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1372 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1376 int UtcDaliTouchParentUnstaged(void)
1378 TestApplication application;
1380 Actor parent = Actor::New();
1381 parent.SetSize(100.0f, 100.0f);
1382 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1383 Stage::GetCurrent().Add(parent);
1385 Actor actor = Actor::New();
1386 actor.SetSize(100.0f, 100.0f);
1387 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1390 // Render and notify
1391 application.SendNotification();
1392 application.Render();
1394 // Connect to actor's touched signal
1396 TouchEventFunctor functor( data );
1397 actor.TouchedSignal().Connect( &application, functor );
1399 // Emit a down signal
1400 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1401 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1402 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1403 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1406 // Render and notify
1407 application.SendNotification();
1408 application.Render();
1410 // Unparent the parent of the touchable actor
1413 // Should receive an interrupted event
1414 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1415 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1419 int UtcDaliTouchActorUnstagedDifferentConsumer(void)
1421 TestApplication application;
1423 Actor parent = Actor::New();
1424 parent.SetSize(100.0f, 100.0f);
1425 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1426 Stage::GetCurrent().Add(parent);
1428 Actor actor = Actor::New();
1429 actor.SetSize(100.0f, 100.0f);
1430 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1433 // Render and notify
1434 application.SendNotification();
1435 application.Render();
1437 // Connect to actor's touched signal
1439 TouchEventFunctor functor( data, false /* Do not consume */ );
1440 actor.TouchedSignal().Connect( &application, functor );
1442 // Connect to parent's touched signal
1443 SignalData parentData;
1444 TouchEventFunctor parentFunctor( parentData );
1445 parent.TouchedSignal().Connect( &application, parentFunctor );
1447 // Emit a down signal
1448 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1449 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1450 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1451 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1452 DALI_TEST_CHECK( actor == data.touchedActor );
1453 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1454 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1455 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1456 DALI_TEST_CHECK( parent == parentData.touchedActor );
1460 // Render and notify
1461 application.SendNotification();
1462 application.Render();
1464 // Unparent the actor
1467 // Should receive an interrupted event for both actor & parent
1468 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1469 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1470 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1471 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1475 // Readd actor to parent
1478 // Render and notify
1479 application.SendNotification();
1480 application.Render();
1482 // Emit a motion signal
1483 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1484 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1485 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1489 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1490 SignalData secondData;
1491 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1492 actor.TouchedSignal().Connect( &application, secondFunctor );
1494 // Unparent the actor
1497 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1498 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1499 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1500 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1501 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1502 DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1503 DALI_TEST_EQUALS( TouchPoint::Interrupted, secondData.touchEvent.points[0].state, TEST_LOCATION );
1511 int UtcDaliTouchInterruptedDifferentConsumer(void)
1513 TestApplication application;
1514 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
1516 Actor parent = Actor::New();
1517 parent.SetSize(100.0f, 100.0f);
1518 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1519 Stage::GetCurrent().Add(parent);
1521 Actor actor = Actor::New();
1522 actor.SetSize(100.0f, 100.0f);
1523 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1526 // Render and notify
1527 application.SendNotification();
1528 application.Render();
1530 // Connect to actor's touched signal
1532 TouchEventFunctor functor( data, false /* Do not consume */ );
1533 actor.TouchedSignal().Connect( &application, functor );
1535 // Connect to parent's touched signal
1536 SignalData parentData;
1537 TouchEventFunctor parentFunctor( parentData, false /* Do not consume */ );
1538 parent.TouchedSignal().Connect( &application, parentFunctor );
1540 // Connect to root's touched signal and consume
1541 SignalData rootData;
1542 TouchEventFunctor rootFunctor( rootData );
1543 rootActor.TouchedSignal().Connect( &application, rootFunctor );
1545 // Emit a down signal
1546 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1547 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1548 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1549 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1550 DALI_TEST_CHECK( actor == data.touchedActor );
1551 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1552 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1553 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1554 DALI_TEST_CHECK( parent == parentData.touchedActor );
1555 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1556 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
1557 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
1558 DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1563 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1564 SignalData secondData;
1565 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1566 parent.TouchedSignal().Connect( &application, secondFunctor );
1568 // Emit an interrupted signal, all three should STILL be called
1569 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 10.0f, 10.0f ) ) );
1570 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1571 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1572 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1573 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1574 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1575 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );