2 * Copyright (c) 2020 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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
141 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
142 application.GetScene().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 Integration::Scene scene = application.GetScene();
206 Vector2 sceneSize = scene.GetSize();
208 Actor actor = Actor::New();
209 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
210 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
211 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
215 application.SendNotification();
216 application.Render();
218 // Get the camera's near and far planes
219 RenderTaskList taskList = scene.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 = (sceneSize.y * 0.5f) / tanHalfFov;
229 // Connect to actor's touched signal
231 TouchEventFunctor functor( data );
232 actor.TouchedSignal().Connect( &application, functor );
234 Vector2 screenCoordinates( sceneSize.x * 0.5f, sceneSize.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.SetProperty( Actor::Property::POSITION_Z, 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.SetProperty( Actor::Property::POSITION_Z, (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.SetProperty( Actor::Property::POSITION_Z, 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.SetProperty( Actor::Property::POSITION_Z, (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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
311 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
312 application.GetScene().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( application.GetScene().GetRootLayer() );
346 Actor actor = Actor::New();
347 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
348 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
349 application.GetScene().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( application.GetScene().GetRootLayer() );
446 Actor actor = Actor::New();
447 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
448 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
449 application.GetScene().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 scene
497 application.GetScene().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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
527 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
528 application.GetScene().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.SetProperty( Actor::Property::LEAVE_REQUIRED, 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.SetProperty( Actor::Property::LEAVE_REQUIRED, 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( application.GetScene().GetRootLayer() );
580 Actor actor = Actor::New();
581 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
582 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
583 application.GetScene().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.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
601 rootActor.SetProperty( Actor::Property::LEAVE_REQUIRED, 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.SetProperty( Actor::Property::LEAVE_REQUIRED, false );
648 // Another motion event outside of root actor, only root signalled
649 Vector2 sceneSize( application.GetScene().GetSize() );
650 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( sceneSize.width + 10.0f, sceneSize.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.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
663 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
664 application.GetScene().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.SetProperty( Actor::Property::SENSITIVE, 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( application.GetScene().GetRootLayer() );
697 Actor actor = Actor::New();
698 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
699 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
700 application.GetScene().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.SetProperty( Actor::Property::SENSITIVE, 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( application.GetScene().GetRootLayer() );
748 // Connect to actor's touched signal
750 TouchEventFunctor functor( data );
752 Layer layer1 ( Layer::New() );
753 layer1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
754 layer1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
755 application.GetScene().Add( layer1 );
757 Actor actor1 ( Actor::New() );
758 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
759 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
760 actor1.SetProperty( Actor::Property::POSITION_Z, 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.SetProperty( Actor::Property::SENSITIVE, 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.SetProperty( Actor::Property::SENSITIVE, 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.SetProperty( Actor::Property::SENSITIVE, 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.SetProperty( Actor::Property::SENSITIVE, true );
800 Layer layer2 ( Layer::New() );
801 layer2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
802 layer2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
803 layer2.SetProperty( Actor::Property::POSITION_Z, 10.0f ); // Should hit layer2 in this layer rather than actor2
804 application.GetScene().Add( layer2 );
806 Actor actor2 ( Actor::New() );
807 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
808 actor2.SetProperty( Actor::Property::ANCHOR_POINT,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.SetProperty( Actor::Property::SENSITIVE, 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.SetProperty( Actor::Property::SENSITIVE, 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.SetProperty( Actor::Property::VISIBLE, 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.SetProperty( Actor::Property::VISIBLE, 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 Integration::Scene scene ( application.GetScene() );
866 Vector2 sceneSize ( scene.GetSize() );
868 Actor actor = Actor::New();
869 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
870 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
873 // Create render task
874 Viewport viewport( sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f );
875 RenderTask renderTask ( application.GetScene().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 Integration::Scene scene ( application.GetScene() );
910 Vector2 sceneSize ( scene.GetSize() );
912 Actor actor = Actor::New();
913 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
914 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
917 Layer layer = Layer::New();
918 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
919 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
922 // Create render task
923 Viewport viewport( sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f );
924 RenderTask renderTask ( application.GetScene().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 Integration::Scene scene ( application.GetScene() );
961 Vector2 sceneSize ( scene.GetSize() );
963 // FrameBuffer for offscreen RenderTask
964 FrameBuffer frameBuffer = FrameBuffer::New( sceneSize.width, sceneSize.height );
966 // Create a renderable actor to display the FrameBufferImage
967 Actor renderableActor = CreateRenderableActor(frameBuffer.GetColorTexture());
968 renderableActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
969 renderableActor.SetProperty( Actor::Property::SIZE, Vector2( sceneSize.x, sceneSize.y ) );
970 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
971 scene.Add( renderableActor );
973 Actor actor = Actor::New();
974 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
975 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
977 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
979 scene.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
981 // Create a RenderTask
982 RenderTask renderTask = scene.GetRenderTaskList().CreateTask();
983 renderTask.SetSourceActor( actor );
984 renderTask.SetFrameBuffer( frameBuffer );
985 renderTask.SetInputEnabled( true );
987 // Create another RenderTask
988 RenderTask renderTask2( scene.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 UtcDaliTouchRenderTaskWithExclusiveActor(void)
1009 TestApplication application;
1010 auto scene = application.GetScene();
1011 auto sceneSize( scene.GetSize() );
1013 auto actor = CreateRenderableActor();
1014 actor.SetProperty( Actor::Property::SIZE, Vector2( sceneSize.x, sceneSize.y ) );
1017 auto renderTask = scene.GetRenderTaskList().CreateTask();
1018 renderTask.SetSourceActor( actor );
1019 renderTask.SetExclusive( true );
1021 // Render and notify
1022 application.SendNotification();
1023 application.Render();
1025 // Connect to actor's touched signal
1027 TouchEventFunctor functor( data );
1028 actor.TouchedSignal().Connect( &application, functor );
1030 // Emit a down signal
1031 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1032 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1038 int UtcDaliTouchMultipleRenderableActors(void)
1040 TestApplication application;
1041 Integration::Scene scene ( application.GetScene() );
1042 Vector2 sceneSize ( scene.GetSize() );
1044 Actor parent = CreateRenderableActor();
1045 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1046 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1049 Actor actor = CreateRenderableActor();
1050 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1051 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1054 // Render and notify
1055 application.SendNotification();
1056 application.Render();
1058 // Connect to layer's touched signal
1060 TouchEventFunctor functor( data );
1061 parent.TouchedSignal().Connect( &application, functor );
1062 actor.TouchedSignal().Connect( &application, functor );
1064 // Emit a down signal
1065 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1066 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1067 DALI_TEST_CHECK( actor == data.touchedActor );
1071 int UtcDaliTouchActorRemovedInSignal(void)
1073 TestApplication application;
1075 Actor actor = Actor::New();
1076 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1077 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1078 application.GetScene().Add(actor);
1080 // Render and notify
1081 application.SendNotification();
1082 application.Render();
1084 // Connect to actor's touched signal
1086 RemoveActorFunctor functor( data );
1087 actor.TouchedSignal().Connect( &application, functor );
1089 // Register for leave events
1090 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
1092 // Emit a down signal
1093 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1094 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1097 // Re-add, render and notify
1098 application.GetScene().Add(actor);
1099 application.SendNotification();
1100 application.Render();
1102 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1103 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1104 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1107 // Emit a down signal
1108 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1109 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1112 // Render and notify
1113 application.SendNotification();
1114 application.Render();
1116 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1117 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1118 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1121 // Re-add actor back to scene, render and notify
1122 application.GetScene().Add(actor);
1123 application.SendNotification();
1124 application.Render();
1126 // Emit another down event
1127 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1128 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1131 // Completely delete the actor
1134 // Emit event, should not crash and should not receive an event.
1135 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1136 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1140 int UtcDaliTouchActorSignalNotConsumed(void)
1142 TestApplication application;
1144 Actor actor = Actor::New();
1145 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1146 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1147 application.GetScene().Add(actor);
1149 // Render and notify
1150 application.SendNotification();
1151 application.Render();
1153 // Connect to actor's touched signal
1155 TouchEventFunctor functor( data, false );
1156 actor.TouchedSignal().Connect( &application, functor );
1158 // Emit a down signal
1159 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1160 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1164 int UtcDaliTouchActorRemovedFromScene(void)
1166 TestApplication application;
1168 Actor actor = Actor::New();
1169 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1170 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1171 application.GetScene().Add(actor);
1173 // Render and notify
1174 application.SendNotification();
1175 application.Render();
1177 // Connect to actor's touched signal
1179 TouchEventFunctor functor( data );
1180 actor.TouchedSignal().Connect( &application, functor );
1182 // Emit a down signal
1183 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1184 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1187 // Remove actor from scene
1188 application.GetScene().Remove( actor );
1191 // Render and notify
1192 application.SendNotification();
1193 application.Render();
1195 // Emit a move at the same point, we should not be signalled.
1196 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1197 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1202 int UtcDaliTouchLayerConsumesTouch(void)
1204 TestApplication application;
1206 Actor actor = Actor::New();
1207 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1208 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1209 application.GetScene().Add(actor);
1211 // Render and notify
1212 application.SendNotification();
1213 application.Render();
1215 // Connect to actor's touched signal
1217 TouchEventFunctor functor( data );
1218 actor.TouchedSignal().Connect( &application, functor );
1220 // Add a layer to overlap the actor
1221 Layer layer = Layer::New();
1222 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1223 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1224 application.GetScene().Add( layer );
1227 // Render and notify
1228 application.SendNotification();
1229 application.Render();
1231 // Emit a few touch signals
1232 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1233 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1234 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1237 // Set layer to consume all touch
1238 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1240 // Render and notify
1241 application.SendNotification();
1242 application.Render();
1244 // Emit the same signals again, should not receive
1245 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1246 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1247 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1253 int UtcDaliTouchLeaveActorReadded(void)
1255 TestApplication application;
1256 Integration::Scene scene = application.GetScene();
1258 Actor actor = Actor::New();
1259 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1260 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1263 // Set actor to receive touch-events
1264 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
1266 // Render and notify
1267 application.SendNotification();
1268 application.Render();
1270 // Connect to actor's touched signal
1272 TouchEventFunctor functor( data );
1273 actor.TouchedSignal().Connect( &application, functor );
1275 // Emit a down and motion
1276 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1277 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1278 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1281 // Remove actor from scene and add again
1282 scene.Remove( actor );
1285 // Emit a motion within the actor's bounds
1286 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1287 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1290 // Emit a motion outside the actor's bounds
1291 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1292 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1293 DALI_TEST_EQUALS( TouchPoint::Leave, data.touchEvent.points[0].state, TEST_LOCATION );
1299 int UtcDaliTouchClippingActor(void)
1301 TestApplication application;
1302 Integration::Scene scene = application.GetScene();
1304 Actor actor = Actor::New();
1305 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1306 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1309 Actor clippingActor = Actor::New();
1310 clippingActor.SetProperty( Actor::Property::SIZE, Vector2( 50.0f, 50.0f ) );
1311 clippingActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1312 clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1313 scene.Add( clippingActor );
1315 // Add a child to the clipped region.
1316 Actor clippingChild = Actor::New();
1317 clippingChild.SetProperty( Actor::Property::SIZE, Vector2( 50.0f, 50.0f ) );
1318 clippingChild.SetProperty( Actor::Property::POSITION, Vector2( 25.0f, 25.0f ));
1319 clippingChild.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1320 clippingActor.Add( clippingChild );
1322 // Render and notify.
1323 application.SendNotification();
1324 application.Render();
1326 // Connect to actor's touched signal.
1328 TouchEventFunctor functor( data );
1329 actor.TouchedSignal().Connect( &application, functor );
1331 // Emit an event within clipped area - no hit.
1332 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1333 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1336 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1337 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 60.0f, 60.0f ) ) );
1338 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1341 clippingChild.TouchedSignal().Connect( &application, functor );
1343 // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1344 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 30.0f, 30.0f ) ) );
1345 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1351 int UtcDaliTouchActorUnparented(void)
1353 TestApplication application;
1355 Actor actor = Actor::New();
1356 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1357 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1358 application.GetScene().Add(actor);
1360 // Render and notify
1361 application.SendNotification();
1362 application.Render();
1364 // Connect to actor's touched signal
1366 TouchEventFunctor functor( data );
1367 actor.TouchedSignal().Connect( &application, functor );
1369 // Emit a down signal
1370 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1371 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1372 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1373 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1376 // Render and notify
1377 application.SendNotification();
1378 application.Render();
1380 // Unparent the actor
1383 // Should receive an interrupted event
1384 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1385 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1389 int UtcDaliTouchParentRemovedFromScene(void)
1391 TestApplication application;
1393 Actor parent = Actor::New();
1394 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1395 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1396 application.GetScene().Add(parent);
1398 Actor actor = Actor::New();
1399 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1400 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1403 // Render and notify
1404 application.SendNotification();
1405 application.Render();
1407 // Connect to actor's touched signal
1409 TouchEventFunctor functor( data );
1410 actor.TouchedSignal().Connect( &application, functor );
1412 // Emit a down signal
1413 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1414 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1415 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1416 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1419 // Render and notify
1420 application.SendNotification();
1421 application.Render();
1423 // Unparent the parent of the touchable actor
1426 // Should receive an interrupted event
1427 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1428 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1432 int UtcDaliTouchActorRemovedFromSceneDifferentConsumer(void)
1434 TestApplication application;
1436 Actor parent = Actor::New();
1437 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1438 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1439 application.GetScene().Add(parent);
1441 Actor actor = Actor::New();
1442 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1443 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1446 // Render and notify
1447 application.SendNotification();
1448 application.Render();
1450 // Connect to actor's touched signal
1452 TouchEventFunctor functor( data, false /* Do not consume */ );
1453 actor.TouchedSignal().Connect( &application, functor );
1455 // Connect to parent's touched signal
1456 SignalData parentData;
1457 TouchEventFunctor parentFunctor( parentData );
1458 parent.TouchedSignal().Connect( &application, parentFunctor );
1460 // Emit a down signal
1461 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1462 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1463 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1464 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1465 DALI_TEST_CHECK( actor == data.touchedActor );
1466 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1467 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1468 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1469 DALI_TEST_CHECK( parent == parentData.touchedActor );
1473 // Render and notify
1474 application.SendNotification();
1475 application.Render();
1477 // Unparent the actor
1480 // Should receive an interrupted event for both actor & parent
1481 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1482 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1483 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1484 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1488 // Readd actor to parent
1491 // Render and notify
1492 application.SendNotification();
1493 application.Render();
1495 // Emit a motion signal
1496 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1497 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1498 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1502 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1503 SignalData secondData;
1504 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1505 actor.TouchedSignal().Connect( &application, secondFunctor );
1507 // Unparent the actor
1510 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1511 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1512 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1513 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1514 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1515 DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1516 DALI_TEST_EQUALS( TouchPoint::Interrupted, secondData.touchEvent.points[0].state, TEST_LOCATION );
1524 int UtcDaliTouchInterruptedDifferentConsumer(void)
1526 TestApplication application;
1527 Actor rootActor( application.GetScene().GetRootLayer() );
1529 Actor parent = Actor::New();
1530 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1531 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1532 application.GetScene().Add(parent);
1534 Actor actor = Actor::New();
1535 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1536 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1539 // Render and notify
1540 application.SendNotification();
1541 application.Render();
1543 // Connect to actor's touched signal
1545 TouchEventFunctor functor( data, false /* Do not consume */ );
1546 actor.TouchedSignal().Connect( &application, functor );
1548 // Connect to parent's touched signal
1549 SignalData parentData;
1550 TouchEventFunctor parentFunctor( parentData, false /* Do not consume */ );
1551 parent.TouchedSignal().Connect( &application, parentFunctor );
1553 // Connect to root's touched signal and consume
1554 SignalData rootData;
1555 TouchEventFunctor rootFunctor( rootData );
1556 rootActor.TouchedSignal().Connect( &application, rootFunctor );
1558 // Emit a down signal
1559 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1560 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1561 DALI_TEST_EQUALS( TouchPoint::Down, data.touchEvent.points[0].state, TEST_LOCATION );
1562 DALI_TEST_CHECK( actor == data.touchEvent.points[0].hitActor );
1563 DALI_TEST_CHECK( actor == data.touchedActor );
1564 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1565 DALI_TEST_EQUALS( TouchPoint::Down, parentData.touchEvent.points[0].state, TEST_LOCATION );
1566 DALI_TEST_CHECK( actor == parentData.touchEvent.points[0].hitActor );
1567 DALI_TEST_CHECK( parent == parentData.touchedActor );
1568 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1569 DALI_TEST_EQUALS( TouchPoint::Down, rootData.touchEvent.points[0].state, TEST_LOCATION );
1570 DALI_TEST_CHECK( actor == rootData.touchEvent.points[0].hitActor );
1571 DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1576 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1577 SignalData secondData;
1578 TouchEventFunctor secondFunctor( secondData /* Consume */ );
1579 parent.TouchedSignal().Connect( &application, secondFunctor );
1581 // Emit an interrupted signal, all three should STILL be called
1582 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 10.0f, 10.0f ) ) );
1583 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1584 DALI_TEST_EQUALS( TouchPoint::Interrupted, data.touchEvent.points[0].state, TEST_LOCATION );
1585 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1586 DALI_TEST_EQUALS( TouchPoint::Interrupted, parentData.touchEvent.points[0].state, TEST_LOCATION );
1587 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1588 DALI_TEST_EQUALS( TouchPoint::Interrupted, rootData.touchEvent.points[0].state, TEST_LOCATION );
1596 int UtcDaliTouchDataConvert(void)
1598 TestApplication application;
1600 Actor actor = Actor::New();
1601 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1602 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1603 application.GetScene().Add(actor);
1605 // Render and notify
1606 application.SendNotification();
1607 application.Render();
1609 // Connect to actor's touch signal
1611 TouchEventFunctor functor(data);
1612 actor.TouchedSignal().Connect(&application, functor);
1614 Vector2 screenCoordiantes(10.0f, 10.0f);
1615 Vector2 localCoordinates;
1616 actor.ScreenToLocal(localCoordinates.x, localCoordinates.y, screenCoordiantes.x, screenCoordiantes.y);
1618 // Emit a down signal
1619 application.ProcessEvent(GenerateSingleTouch(TouchPoint::Down, screenCoordiantes));
1620 Dali::TouchData touchData = Dali::DevelTouchData::Convert(data.touchEvent);
1622 DALI_TEST_EQUALS( 1u, touchData.GetPointCount(), TEST_LOCATION );
1623 DALI_TEST_EQUALS( screenCoordiantes, touchData.GetScreenPosition(0), TEST_LOCATION );
1624 DALI_TEST_EQUALS( localCoordinates, touchData.GetLocalPosition(0), 0.1f, TEST_LOCATION );
1625 DALI_TEST_EQUALS( PointState::DOWN, touchData.GetState(0), TEST_LOCATION );
1626 DALI_TEST_EQUALS( actor, touchData.GetHitActor(0), TEST_LOCATION );