2 * Copyright (c) 2019 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/render-task-list-integ.h>
24 #include <dali-test-suite-utils.h>
25 #include <dali/devel-api/events/touch-data-devel.h>
29 void utc_dali_touch_processing_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_touch_processing_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
44 // Stores data that is populated in the callback and will be read by the TET cases
48 : functorCalled( false ),
56 functorCalled = false;
59 touchEvent.points.clear();
65 TouchEvent touchEvent;
69 // Functor that sets the data when called
70 struct TouchEventFunctor
74 * @param[in] data Reference to the data to store callback information.
75 * @param[in] returnValue What the functor should return.
77 TouchEventFunctor( SignalData& data, bool returnValue = true )
79 returnValue( returnValue )
83 bool operator()( Actor actor, const TouchEvent& touchEvent )
85 signalData.functorCalled = true;
86 signalData.touchedActor = actor;
87 signalData.touchEvent = touchEvent;
92 SignalData& signalData;
96 // Functor that removes the actor when called.
97 struct RemoveActorFunctor : public TouchEventFunctor
101 * @param[in] data Reference to the data to store callback information.
102 * @param[in] returnValue What the functor should return.
104 RemoveActorFunctor( SignalData& data, bool returnValue = true )
105 : TouchEventFunctor( data, returnValue )
109 bool operator()( Actor actor, const TouchEvent& touchEvent )
111 Actor parent( actor.GetParent() );
114 parent.Remove( actor );
117 return TouchEventFunctor::operator()( actor, touchEvent );
121 Integration::TouchEvent GenerateSingleTouch( TouchPoint::State state, const Vector2& screenPosition )
123 Integration::TouchEvent touchEvent;
124 Integration::Point point;
125 point.SetState( static_cast< PointState::Type >( state ) );
126 point.SetScreenPosition( screenPosition );
127 touchEvent.points.push_back( point );
133 ///////////////////////////////////////////////////////////////////////////////
135 int UtcDaliTouchNormalProcessing(void)
137 TestApplication application;
139 Actor actor = Actor::New();
140 actor.SetSize(100.0f, 100.0f);
141 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
142 Stage::GetCurrent().Add(actor);
145 application.SendNotification();
146 application.Render();
148 // Connect to actor's touched signal
150 TouchEventFunctor functor( data );
151 actor.TouchedSignal().Connect( &application, functor );
153 Vector2 screenCoordinates( 10.0f, 10.0f );
154 Vector2 localCoordinates;
155 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
157 // Emit a down signal
158 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
159 const TouchPoint *point1 = &data.touchEvent.GetPoint(0);
160 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
161 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
162 DALI_TEST_EQUALS( TouchPoint::Down, point1->state, TEST_LOCATION );
163 DALI_TEST_EQUALS( screenCoordinates, point1->screen, TEST_LOCATION );
164 DALI_TEST_EQUALS( localCoordinates, point1->local, 0.1f, TEST_LOCATION );
167 // Emit a motion signal
168 screenCoordinates.x = screenCoordinates.y = 11.0f;
169 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
170 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
171 const TouchPoint *point2 = &data.touchEvent.GetPoint(0);
172 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
173 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
174 DALI_TEST_EQUALS( TouchPoint::Motion, point2->state, TEST_LOCATION );
175 DALI_TEST_EQUALS( screenCoordinates, point2->screen, TEST_LOCATION );
176 DALI_TEST_EQUALS( localCoordinates, point2->local, 0.1f, TEST_LOCATION );
180 screenCoordinates.x = screenCoordinates.y = 12.0f;
181 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
182 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
184 const TouchPoint *point3ptr = &data.touchEvent.GetPoint(0);
185 TouchPoint point3( point3ptr->deviceId, point3ptr->state, point3ptr->screen.x, point3ptr->screen.y, point3ptr->local.x, point3ptr->local.y );
187 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
188 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
189 DALI_TEST_EQUALS( TouchPoint::Up, point3.state, TEST_LOCATION );
190 DALI_TEST_EQUALS( screenCoordinates, point3.screen, TEST_LOCATION );
191 DALI_TEST_EQUALS( localCoordinates, point3.local, 0.1f, TEST_LOCATION );
194 // Emit a down signal where the actor is not present
195 screenCoordinates.x = screenCoordinates.y = 200.0f;
196 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
197 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
201 int UtcDaliTouchOutsideCameraNearFarPlanes(void)
203 TestApplication application;
205 Stage stage = Stage::GetCurrent();
206 Vector2 stageSize = stage.GetSize();
208 Actor actor = Actor::New();
209 actor.SetSize(100.0f, 100.0f);
210 actor.SetAnchorPoint(AnchorPoint::CENTER);
211 actor.SetParentOrigin(ParentOrigin::CENTER);
215 application.SendNotification();
216 application.Render();
218 // Get the camera's near and far planes
219 RenderTaskList taskList = stage.GetRenderTaskList();
220 Dali::RenderTask task = taskList.GetTask(0);
221 CameraActor camera = task.GetCameraActor();
222 float nearPlane = camera.GetNearClippingPlane();
223 float farPlane = camera.GetFarClippingPlane();
225 // Calculate the current distance of the actor from the camera
226 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
227 float distance = (stageSize.y * 0.5f) / tanHalfFov;
229 // Connect to actor's touched signal
231 TouchEventFunctor functor( data );
232 actor.TouchedSignal().Connect( &application, functor );
234 Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
236 // Emit a down signal
237 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
238 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
241 // Emit a down signal where actor is just at the camera's near plane
242 actor.SetZ(distance - nearPlane);
245 application.SendNotification();
246 application.Render();
248 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
249 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
252 // Emit a down signal where actor is closer than the camera's near plane
253 actor.SetZ((distance - nearPlane) + 1.0f);
256 application.SendNotification();
257 application.Render();
259 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
260 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
263 // Emit a down signal where actor is just at the camera's far plane
264 actor.SetZ(distance - farPlane);
267 application.SendNotification();
268 application.Render();
270 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
271 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
274 // Emit a down signal where actor is further than the camera's far plane
275 actor.SetZ((distance - farPlane) - 1.0f);
278 application.SendNotification();
279 application.Render();
281 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
282 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
287 int UtcDaliTouchEmitEmpty(void)
289 TestApplication application;
293 // Emit an empty TouchEvent
294 Integration::TouchEvent event;
295 application.ProcessEvent( event );
296 tet_result( TET_FAIL );
298 catch ( Dali::DaliException& e )
300 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
305 int UtcDaliTouchInterrupted(void)
307 TestApplication application;
309 Actor actor = Actor::New();
310 actor.SetSize(100.0f, 100.0f);
311 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
312 Stage::GetCurrent().Add(actor);
315 application.SendNotification();
316 application.Render();
318 // Connect to actor's touched signal
320 TouchEventFunctor functor( data );
321 actor.TouchedSignal().Connect( &application, functor );
323 // Emit a down signal
324 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
325 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
326 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
329 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
330 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
331 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
332 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
335 // Emit another interrupted signal, our signal handler should not be called.
336 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
337 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
341 int UtcDaliTouchParentConsumer(void)
343 TestApplication application;
344 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
346 Actor actor = Actor::New();
347 actor.SetSize(100.0f, 100.0f);
348 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
349 Stage::GetCurrent().Add(actor);
352 application.SendNotification();
353 application.Render();
355 // Connect to actor's touched signal
357 TouchEventFunctor functor( data, false );
358 actor.TouchedSignal().Connect( &application, functor );
360 // Connect to root actor's touched signal
362 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
363 rootActor.TouchedSignal().Connect( &application, rootFunctor );
365 Vector2 screenCoordinates( 10.0f, 10.0f );
366 Vector2 actorCoordinates, rootCoordinates;
367 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
368 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
370 // Emit a down signal
371 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
372 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
373 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
374 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
375 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
376 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
377 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
378 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
379 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
380 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
381 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
382 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
383 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
387 // Emit a motion signal
388 screenCoordinates.x = screenCoordinates.y = 11.0f;
389 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
390 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
391 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
392 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
393 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
394 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
395 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
396 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
397 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
398 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
399 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
400 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
401 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
402 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
403 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
408 screenCoordinates.x = screenCoordinates.y = 12.0f;
409 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
410 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
411 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
412 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
413 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
414 DALI_TEST_EQUALS( 1u, data.touchEvent.GetPointCount(), TEST_LOCATION );
415 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
416 DALI_TEST_EQUALS( TouchPoint::Up, data.touchEvent.points[0].state, TEST_LOCATION );
417 DALI_TEST_EQUALS( TouchPoint::Up, rootData.touchEvent.points[0].state, TEST_LOCATION );
418 DALI_TEST_EQUALS( screenCoordinates, data.touchEvent.points[0].screen, TEST_LOCATION );
419 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
420 DALI_TEST_EQUALS( actorCoordinates, data.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
421 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
422 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
423 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
427 // Emit a down signal where the actor is not present, will hit the root actor though
428 screenCoordinates.x = screenCoordinates.y = 200.0f;
429 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
430 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
431 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
432 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
433 DALI_TEST_EQUALS( 1u, rootData.touchEvent.GetPointCount(), TEST_LOCATION );
434 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
435 DALI_TEST_EQUALS( screenCoordinates, rootData.touchEvent.points[0].screen, TEST_LOCATION );
436 DALI_TEST_EQUALS( rootCoordinates, rootData.touchEvent.points[0].local, 0.1f, TEST_LOCATION );
437 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
441 int UtcDaliTouchInterruptedParentConsumer(void)
443 TestApplication application;
444 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
446 Actor actor = Actor::New();
447 actor.SetSize(100.0f, 100.0f);
448 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
449 Stage::GetCurrent().Add(actor);
452 application.SendNotification();
453 application.Render();
455 // Connect to actor's touched signal
457 TouchEventFunctor functor( data, false );
458 actor.TouchedSignal().Connect( &application, functor );
460 // Connect to root actor's touched signal
462 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
463 rootActor.TouchedSignal().Connect( &application, rootFunctor );
465 // Emit a down signal
466 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
467 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
468 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
469 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
470 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
471 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
472 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
476 // Emit an interrupted signal
477 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
478 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
479 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
480 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
481 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
482 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
483 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
487 // Emit another down signal
488 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
489 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
490 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
491 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
492 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
496 // Remove actor from Stage
497 Stage::GetCurrent().Remove( actor );
502 application.SendNotification();
503 application.Render();
505 // Emit an interrupted signal, only root actor's signal should be called.
506 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
507 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
508 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
509 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
510 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
514 // Emit another interrupted state, none of the signal's should be called.
515 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
516 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
517 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
521 int UtcDaliTouchLeave(void)
523 TestApplication application;
525 Actor actor = Actor::New();
526 actor.SetSize(100.0f, 100.0f);
527 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
528 Stage::GetCurrent().Add(actor);
531 application.SendNotification();
532 application.Render();
534 // Connect to actor's touched signal
536 TouchEventFunctor functor( data );
537 actor.TouchedSignal().Connect( &application, functor );
539 // Set actor to require leave events
540 actor.SetLeaveRequired( true );
542 // Emit a down signal
543 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
544 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
545 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
548 // Emit a motion signal outside of actor, should be signalled with a Leave
549 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
550 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
551 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
554 // Another motion outside of actor, no signalling
555 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
556 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
559 // Another motion event inside actor, signalled with motion
560 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
561 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
562 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
565 // We do not want to listen to leave events anymore
566 actor.SetLeaveRequired( false );
568 // Another motion event outside of actor, no signalling
569 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
570 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
575 int UtcDaliTouchLeaveParentConsumer(void)
577 TestApplication application;
578 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
580 Actor actor = Actor::New();
581 actor.SetSize(100.0f, 100.0f);
582 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
583 Stage::GetCurrent().Add(actor);
586 application.SendNotification();
587 application.Render();
589 // Connect to actor's touched signal
591 TouchEventFunctor functor( data, false );
592 actor.TouchedSignal().Connect( &application, functor );
594 // Connect to root actor's touched signal
596 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
597 rootActor.TouchedSignal().Connect( &application, rootFunctor );
599 // Set actor to require leave events
600 actor.SetLeaveRequired( true );
601 rootActor.SetLeaveRequired( true );
603 // Emit a down signal
604 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
605 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
606 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
607 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
608 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
609 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
610 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
614 // Emit a motion signal outside of actor, should be signalled with a Leave
615 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
616 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
617 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
618 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
619 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.touchEvent.points[0].state, TEST_LOCATION );
620 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
621 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
625 // Another motion outside of actor, only rootActor signalled
626 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
627 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
628 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
629 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
630 DALI_TEST_CHECK( rootActor == rootData.touchEvent.points[0].hitActor );
634 // Another motion event inside actor, signalled with motion
635 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
636 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
637 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
638 DALI_TEST_EQUALS( TouchPoint::Motion, data.touchEvent.points[0].state, TEST_LOCATION );
639 DALI_TEST_EQUALS( TouchPoint::Motion, rootData.touchEvent.points[0].state, TEST_LOCATION );
640 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
641 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
645 // We do not want to listen to leave events of actor anymore
646 actor.SetLeaveRequired( false );
648 // Another motion event outside of root actor, only root signalled
649 Vector2 stageSize( Stage::GetCurrent().GetSize() );
650 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
651 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
652 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
653 DALI_TEST_EQUALS( TouchPoint::Leave, rootData.touchEvent.points[0].state, TEST_LOCATION );
657 int UtcDaliTouchActorBecomesInsensitive(void)
659 TestApplication application;
661 Actor actor = Actor::New();
662 actor.SetSize(100.0f, 100.0f);
663 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
664 Stage::GetCurrent().Add(actor);
667 application.SendNotification();
668 application.Render();
670 // Connect to actor's touched signal
672 TouchEventFunctor functor( data );
673 actor.TouchedSignal().Connect( &application, functor );
675 // Emit a down signal
676 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
677 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
678 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
681 // Change actor to insensitive
682 actor.SetSensitive( false );
684 // Emit a motion signal, signalled with an interrupted
685 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
686 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
687 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
692 int UtcDaliTouchActorBecomesInsensitiveParentConsumer(void)
694 TestApplication application;
695 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
697 Actor actor = Actor::New();
698 actor.SetSize(100.0f, 100.0f);
699 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
700 Stage::GetCurrent().Add(actor);
703 application.SendNotification();
704 application.Render();
706 // Connect to actor's touched signal
708 TouchEventFunctor functor( data, false );
709 actor.TouchedSignal().Connect( &application, functor );
711 // Connect to root actor's touched signal
713 TouchEventFunctor rootFunctor( rootData ); // Consumes signal
714 rootActor.TouchedSignal().Connect( &application, rootFunctor );
716 // Emit a down signal
717 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
718 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
719 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
720 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
721 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
722 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
723 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
728 application.SendNotification();
729 application.Render();
731 // Make root actor insensitive
732 rootActor.SetSensitive( false );
734 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
735 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
736 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
737 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
738 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
739 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
743 int UtcDaliTouchMultipleLayers(void)
745 TestApplication application;
746 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
748 // Connect to actor's touched signal
750 TouchEventFunctor functor( data );
752 Layer layer1 ( Layer::New() );
753 layer1.SetSize(100.0f, 100.0f);
754 layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
755 Stage::GetCurrent().Add( layer1 );
757 Actor actor1 ( Actor::New() );
758 actor1.SetSize( 100.0f, 100.0f );
759 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
760 actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
761 layer1.Add( actor1 );
764 application.SendNotification();
765 application.Render();
767 // Connect to layer1 and actor1
768 layer1.TouchedSignal().Connect( &application, functor );
769 actor1.TouchedSignal().Connect( &application, functor );
771 // Hit in hittable area, actor1 should be hit
772 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
773 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
774 DALI_TEST_CHECK( data.touchedActor == actor1 );
777 // Make layer1 insensitive, nothing should be hit
778 layer1.SetSensitive( false );
779 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
780 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
783 // Make layer1 sensitive again, again actor1 will be hit
784 layer1.SetSensitive( true );
785 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
786 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
787 DALI_TEST_CHECK( data.touchedActor == actor1 );
790 // Make rootActor insensitive, nothing should be hit
791 rootActor.SetSensitive( false );
792 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
793 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
796 // Make rootActor sensitive
797 rootActor.SetSensitive( true );
800 Layer layer2 ( Layer::New() );
801 layer2.SetSize(100.0f, 100.0f );
802 layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
803 layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
804 Stage::GetCurrent().Add( layer2 );
806 Actor actor2 ( Actor::New() );
807 actor2.SetSize(100.0f, 100.0f);
808 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
809 layer2.Add( actor2 );
812 application.SendNotification();
813 application.Render();
815 // Connect to layer2 and actor2
816 layer2.TouchedSignal().Connect( &application, functor );
817 actor2.TouchedSignal().Connect( &application, functor );
819 // Emit an event, should hit layer2
820 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
821 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
822 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
825 // Make layer2 insensitive, should hit actor1
826 layer2.SetSensitive( false );
827 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
828 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
829 DALI_TEST_CHECK( data.touchedActor == actor1 );
832 // Make layer2 sensitive again, should hit layer2
833 layer2.SetSensitive( true );
834 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
835 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
836 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
839 // Make layer2 invisible, render and notify
840 layer2.SetVisible( false );
841 application.SendNotification();
842 application.Render();
845 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
846 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
847 DALI_TEST_CHECK( data.touchedActor == actor1 );
850 // Make rootActor invisible, render and notify
851 rootActor.SetVisible( false );
852 application.SendNotification();
853 application.Render();
855 // Should not hit anything
856 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
857 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
862 int UtcDaliTouchMultipleRenderTasks(void)
864 TestApplication application;
865 Stage stage ( Stage::GetCurrent() );
866 Vector2 stageSize ( stage.GetSize() );
868 Actor actor = Actor::New();
869 actor.SetSize(100.0f, 100.0f);
870 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
873 // Create render task
874 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
875 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
876 renderTask.SetViewport( viewport );
877 renderTask.SetInputEnabled( true );
880 application.SendNotification();
881 application.Render();
883 // Connect to actor's touched signal
885 TouchEventFunctor functor( data );
886 actor.TouchedSignal().Connect( &application, functor );
888 // Emit a down signal
889 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
890 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
893 // Ensure renderTask actor can be hit too.
894 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
895 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
898 // Disable input on renderTask, should not be hittable
899 renderTask.SetInputEnabled( false );
900 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
901 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
906 int UtcDaliTouchMultipleRenderTasksWithChildLayer(void)
908 TestApplication application;
909 Stage stage ( Stage::GetCurrent() );
910 Vector2 stageSize ( stage.GetSize() );
912 Actor actor = Actor::New();
913 actor.SetSize(100.0f, 100.0f);
914 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
917 Layer layer = Layer::New();
918 layer.SetSize(100.0f, 100.0f);
919 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
922 // Create render task
923 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
924 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
925 renderTask.SetViewport( viewport );
926 renderTask.SetInputEnabled( true );
927 renderTask.SetSourceActor( actor );
930 application.SendNotification();
931 application.Render();
933 // Connect to layer's touched signal
935 TouchEventFunctor functor( data );
936 actor.TouchedSignal().Connect( &application, functor );
937 layer.TouchedSignal().Connect( &application, functor );
939 // Emit a down signal
940 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
941 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
944 // Ensure renderTask actor can be hit too.
945 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
946 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
949 // Disable input on renderTask, should not be hittable
950 renderTask.SetInputEnabled( false );
951 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
952 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
957 int UtcDaliTouchOffscreenRenderTasks(void)
959 TestApplication application;
960 Stage stage ( Stage::GetCurrent() );
961 Vector2 stageSize ( stage.GetSize() );
963 // FrameBufferImage for offscreen RenderTask
964 FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
966 // Create a renderable actor to display the FrameBufferImage
967 Actor renderableActor = CreateRenderableActor( frameBufferImage );
968 renderableActor.SetParentOrigin(ParentOrigin::CENTER);
969 renderableActor.SetSize( stageSize.x, stageSize.y );
970 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
971 stage.Add( renderableActor );
973 Actor actor = Actor::New();
974 actor.SetSize(100.0f, 100.0f);
975 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
977 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
979 stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
981 // Create a RenderTask
982 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
983 renderTask.SetSourceActor( actor );
984 renderTask.SetTargetFrameBuffer( frameBufferImage );
985 renderTask.SetInputEnabled( true );
987 // Create another RenderTask
988 RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
989 renderTask2.SetInputEnabled( true );
992 application.SendNotification();
993 application.Render();
995 // Connect to actor's touched signal
997 TouchEventFunctor functor( data );
998 actor.TouchedSignal().Connect( &application, functor );
1000 // Emit a down signal
1001 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1002 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1007 int UtcDaliTouchMultipleRenderableActors(void)
1009 TestApplication application;
1010 Stage stage ( Stage::GetCurrent() );
1011 Vector2 stageSize ( stage.GetSize() );
1013 Actor parent = CreateRenderableActor();
1014 parent.SetSize(100.0f, 100.0f);
1015 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1018 Actor actor = CreateRenderableActor();
1019 actor.SetSize(100.0f, 100.0f);
1020 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1023 // Render and notify
1024 application.SendNotification();
1025 application.Render();
1027 // Connect to layer's touched signal
1029 TouchEventFunctor functor( data );
1030 parent.TouchedSignal().Connect( &application, functor );
1031 actor.TouchedSignal().Connect( &application, functor );
1033 // Emit a down signal
1034 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1035 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1036 DALI_TEST_CHECK( actor == data.touchedActor );
1040 int UtcDaliTouchActorRemovedInSignal(void)
1042 TestApplication application;
1044 Actor actor = Actor::New();
1045 actor.SetSize(100.0f, 100.0f);
1046 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1047 Stage::GetCurrent().Add(actor);
1049 // Render and notify
1050 application.SendNotification();
1051 application.Render();
1053 // Connect to actor's touched signal
1055 RemoveActorFunctor functor( data );
1056 actor.TouchedSignal().Connect( &application, functor );
1058 // Register for leave events
1059 actor.SetLeaveRequired( true );
1061 // Emit a down signal
1062 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1063 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1066 // Re-add, render and notify
1067 Stage::GetCurrent().Add(actor);
1068 application.SendNotification();
1069 application.Render();
1071 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1072 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1073 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1076 // Emit a down signal
1077 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1078 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1081 // Render and notify
1082 application.SendNotification();
1083 application.Render();
1085 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1086 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1087 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1090 // Re-add actor back to stage, render and notify
1091 Stage::GetCurrent().Add(actor);
1092 application.SendNotification();
1093 application.Render();
1095 // Emit another down event
1096 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1097 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1100 // Completely delete the actor
1103 // Emit event, should not crash and should not receive an event.
1104 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1105 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1109 int UtcDaliTouchActorSignalNotConsumed(void)
1111 TestApplication application;
1113 Actor actor = Actor::New();
1114 actor.SetSize(100.0f, 100.0f);
1115 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1116 Stage::GetCurrent().Add(actor);
1118 // Render and notify
1119 application.SendNotification();
1120 application.Render();
1122 // Connect to actor's touched signal
1124 TouchEventFunctor functor( data, false );
1125 actor.TouchedSignal().Connect( &application, functor );
1127 // Emit a down signal
1128 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1129 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1133 int UtcDaliTouchActorUnStaged(void)
1135 TestApplication application;
1137 Actor actor = Actor::New();
1138 actor.SetSize(100.0f, 100.0f);
1139 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1140 Stage::GetCurrent().Add(actor);
1142 // Render and notify
1143 application.SendNotification();
1144 application.Render();
1146 // Connect to actor's touched signal
1148 TouchEventFunctor functor( data );
1149 actor.TouchedSignal().Connect( &application, functor );
1151 // Emit a down signal
1152 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1153 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1156 // Remove actor from stage
1157 Stage::GetCurrent().Remove( actor );
1160 // Render and notify
1161 application.SendNotification();
1162 application.Render();
1164 // Emit a move at the same point, we should not be signalled.
1165 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1166 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1171 int UtcDaliTouchLayerConsumesTouch(void)
1173 TestApplication application;
1175 Actor actor = Actor::New();
1176 actor.SetSize(100.0f, 100.0f);
1177 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1178 Stage::GetCurrent().Add(actor);
1180 // Render and notify
1181 application.SendNotification();
1182 application.Render();
1184 // Connect to actor's touched signal
1186 TouchEventFunctor functor( data );
1187 actor.TouchedSignal().Connect( &application, functor );
1189 // Add a layer to overlap the actor
1190 Layer layer = Layer::New();
1191 layer.SetSize(100.0f, 100.0f);
1192 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1193 Stage::GetCurrent().Add( layer );
1196 // Render and notify
1197 application.SendNotification();
1198 application.Render();
1200 // Emit a few touch signals
1201 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1202 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1203 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1206 // Set layer to consume all touch
1207 layer.SetTouchConsumed( true );
1209 // Render and notify
1210 application.SendNotification();
1211 application.Render();
1213 // Emit the same signals again, should not receive
1214 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1215 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1216 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1222 int UtcDaliTouchLeaveActorReadded(void)
1224 TestApplication application;
1225 Stage stage = Stage::GetCurrent();
1227 Actor actor = Actor::New();
1228 actor.SetSize(100.0f, 100.0f);
1229 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1232 // Set actor to receive touch-events
1233 actor.SetLeaveRequired( true );
1235 // Render and notify
1236 application.SendNotification();
1237 application.Render();
1239 // Connect to actor's touched signal
1241 TouchEventFunctor functor( data );
1242 actor.TouchedSignal().Connect( &application, functor );
1244 // Emit a down and motion
1245 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1246 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1247 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1250 // Remove actor from stage and add again
1251 stage.Remove( actor );
1254 // Emit a motion within the actor's bounds
1255 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1256 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1259 // Emit a motion outside the actor's bounds
1260 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1261 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1262 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
1268 int UtcDaliTouchClippingActor(void)
1270 TestApplication application;
1271 Stage stage = Stage::GetCurrent();
1273 Actor actor = Actor::New();
1274 actor.SetSize( 100.0f, 100.0f );
1275 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1278 Actor clippingActor = Actor::New();
1279 clippingActor.SetSize( 50.0f, 50.0f );
1280 clippingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1281 clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1282 stage.Add( clippingActor );
1284 // Add a child to the clipped region.
1285 Actor clippingChild = Actor::New();
1286 clippingChild.SetSize( 50.0f, 50.0f );
1287 clippingChild.SetPosition( 25.0f, 25.0f );
1288 clippingChild.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1289 clippingActor.Add( clippingChild );
1291 // Render and notify.
1292 application.SendNotification();
1293 application.Render();
1295 // Connect to actor's touched signal.
1297 TouchEventFunctor functor( data );
1298 actor.TouchedSignal().Connect( &application, functor );
1300 // Emit an event within clipped area - no hit.
1301 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1302 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1305 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1306 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 60.0f, 60.0f ) ) );
1307 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1310 clippingChild.TouchedSignal().Connect( &application, functor );
1312 // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1313 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 30.0f, 30.0f ) ) );
1314 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1320 int UtcDaliTouchActorUnstaged(void)
1322 TestApplication application;
1324 Actor actor = Actor::New();
1325 actor.SetSize(100.0f, 100.0f);
1326 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1327 Stage::GetCurrent().Add(actor);
1329 // Render and notify
1330 application.SendNotification();
1331 application.Render();
1333 // Connect to actor's touched signal
1335 TouchEventFunctor functor( data );
1336 actor.TouchedSignal().Connect( &application, functor );
1338 // Emit a down signal
1339 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1340 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1341 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1342 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1345 // Render and notify
1346 application.SendNotification();
1347 application.Render();
1349 // Unparent the actor
1352 // Should receive an interrupted event
1353 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1354 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1358 int UtcDaliTouchParentUnstaged(void)
1360 TestApplication application;
1362 Actor parent = Actor::New();
1363 parent.SetSize(100.0f, 100.0f);
1364 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1365 Stage::GetCurrent().Add(parent);
1367 Actor actor = Actor::New();
1368 actor.SetSize(100.0f, 100.0f);
1369 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1372 // Render and notify
1373 application.SendNotification();
1374 application.Render();
1376 // Connect to actor's touched signal
1378 TouchEventFunctor functor( data );
1379 actor.TouchedSignal().Connect( &application, functor );
1381 // Emit a down signal
1382 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1383 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1384 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1385 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1388 // Render and notify
1389 application.SendNotification();
1390 application.Render();
1392 // Unparent the parent of the touchable actor
1395 // Should receive an interrupted event
1396 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1397 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1401 int UtcDaliTouchActorUnstagedDifferentConsumer(void)
1403 TestApplication application;
1405 Actor parent = Actor::New();
1406 parent.SetSize(100.0f, 100.0f);
1407 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1408 Stage::GetCurrent().Add(parent);
1410 Actor actor = Actor::New();
1411 actor.SetSize(100.0f, 100.0f);
1412 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1415 // Render and notify
1416 application.SendNotification();
1417 application.Render();
1419 // Connect to actor's touched signal
1421 TouchEventFunctor functor( data, false /* Do not consume */ );
1422 actor.TouchedSignal().Connect( &application, functor );
1424 // Connect to parent's touched signal
1425 SignalData parentData;
1426 TouchEventFunctor parentFunctor( parentData );
1427 parent.TouchedSignal().Connect( &application, parentFunctor );
1429 // Emit a down signal
1430 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1431 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1432 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1433 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1434 DALI_TEST_CHECK( actor == data.touchedActor );
1435 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1436 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1437 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1438 DALI_TEST_CHECK( parent == parentData.touchedActor );
1442 // Render and notify
1443 application.SendNotification();
1444 application.Render();
1446 // Unparent the actor
1449 // Should receive an interrupted event for both actor & parent
1450 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1451 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1452 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1453 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1457 // Readd actor to parent
1460 // Render and notify
1461 application.SendNotification();
1462 application.Render();
1464 // Emit a motion signal
1465 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1466 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1467 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1471 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1472 SignalData secondData;
1473 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1474 actor.TouchedSignal().Connect( &application, secondFunctor );
1476 // Unparent the actor
1479 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1480 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1481 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1482 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1483 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1484 DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1485 DALI_TEST_EQUALS( TouchPoint::Interrupted, secondData.touchEvent.points[0].state, TEST_LOCATION );
1493 int UtcDaliTouchInterruptedDifferentConsumer(void)
1495 TestApplication application;
1496 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
1498 Actor parent = Actor::New();
1499 parent.SetSize(100.0f, 100.0f);
1500 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1501 Stage::GetCurrent().Add(parent);
1503 Actor actor = Actor::New();
1504 actor.SetSize(100.0f, 100.0f);
1505 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1508 // Render and notify
1509 application.SendNotification();
1510 application.Render();
1512 // Connect to actor's touched signal
1514 TouchEventFunctor functor( data, false /* Do not consume */ );
1515 actor.TouchedSignal().Connect( &application, functor );
1517 // Connect to parent's touched signal
1518 SignalData parentData;
1519 TouchEventFunctor parentFunctor( parentData, false /* Do not consume */ );
1520 parent.TouchedSignal().Connect( &application, parentFunctor );
1522 // Connect to root's touched signal and consume
1523 SignalData rootData;
1524 TouchEventFunctor rootFunctor( rootData );
1525 rootActor.TouchedSignal().Connect( &application, rootFunctor );
1527 // Emit a down signal
1528 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1529 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1530 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1531 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1532 DALI_TEST_CHECK( actor == data.touchedActor );
1533 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1534 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1535 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1536 DALI_TEST_CHECK( parent == parentData.touchedActor );
1537 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1538 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
1539 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
1540 DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1545 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1546 SignalData secondData;
1547 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1548 parent.TouchedSignal().Connect( &application, secondFunctor );
1550 // Emit an interrupted signal, all three should STILL be called
1551 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 10.0f, 10.0f ) ) );
1552 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1553 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1554 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1555 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1556 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1557 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
1565 int UtcDaliTouchDataConvert(void)
1567 TestApplication application;
1569 Actor actor = Actor::New();
1570 actor.SetSize(100.0f, 100.0f);
1571 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1572 Stage::GetCurrent().Add(actor);
1574 // Render and notify
1575 application.SendNotification();
1576 application.Render();
1578 // Connect to actor's touch signal
1580 TouchEventFunctor functor(data);
1581 actor.TouchedSignal().Connect(&application, functor);
1583 Vector2 screenCoordiantes(10.0f, 10.0f);
1584 Vector2 localCoordinates;
1585 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordiantes.x, screenCoordiantes.y);
1587 // Emit a down signal
1588 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, screenCoordiantes));
1589 Dali::TouchData touchData = Dali::DevelTouchData::Convert(data.touchEvent);
1591 DALI_TEST_EQUALS( 1u, touchData.GetPointCount(), TEST_LOCATION );
1592 DALI_TEST_EQUALS( screenCoordiantes, touchData.GetScreenPosition(0), TEST_LOCATION );
1593 DALI_TEST_EQUALS( localCoordinates, touchData.GetLocalPosition(0), 0.1f, TEST_LOCATION );
1594 DALI_TEST_EQUALS( PointState::DOWN, touchData.GetState(0), TEST_LOCATION );
1595 DALI_TEST_EQUALS( actor, touchData.GetHitActor(0), TEST_LOCATION );