2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali-test-suite-utils.h>
28 void utc_dali_touch_data_processing_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_touch_data_processing_cleanup(void)
35 test_return_value = TET_PASS;
38 ///////////////////////////////////////////////////////////////////////////////
45 PointState::Type state;
51 : deviceId(-1), state(PointState::FINISHED)
54 static const TestPoint ZERO;
57 const TestPoint TestPoint::ZERO;
60 // Stores data that is populated in the callback and will be read by the TET cases
64 : functorCalled( false ),
73 std::vector<TestPoint> points;
75 const TestPoint& GetPoint(size_t i)
77 if( i < points.size() )
81 return TestPoint::ZERO;
83 size_t GetPointCount()
91 functorCalled = false;
94 touchData.points.clear();
100 TestTouchData touchData;
104 // Functor that sets the data when called
105 struct TouchDataFunctor
109 * @param[in] data Reference to the data to store callback information.
110 * @param[in] returnValue What the functor should return.
112 TouchDataFunctor( SignalData& data, bool returnValue = true )
113 : signalData( data ),
114 returnValue( returnValue )
118 bool operator()( Actor actor, const TouchData& touchData )
120 signalData.functorCalled = true;
121 signalData.touchedActor = actor;
123 signalData.touchData.time = touchData.GetTime();
124 signalData.touchData.points.clear();
126 for( size_t i=0; i<touchData.GetPointCount(); ++i )
129 p.deviceId = touchData.GetDeviceId(i);
130 p.state = touchData.GetState(i);
131 p.hitActor = touchData.GetHitActor(i);
132 p.local = touchData.GetLocalPosition(i);
133 p.screen = touchData.GetScreenPosition(i);
134 signalData.touchData.points.push_back(p);
140 SignalData& signalData;
144 // Functor that removes the actor when called.
145 struct RemoveActorFunctor : public TouchDataFunctor
149 * @param[in] data Reference to the data to store callback information.
150 * @param[in] returnValue What the functor should return.
152 RemoveActorFunctor( SignalData& data, bool returnValue = true )
153 : TouchDataFunctor( data, returnValue )
157 bool operator()( Actor actor, const TouchData& touchData )
159 Actor parent( actor.GetParent() );
162 parent.Remove( actor );
165 return TouchDataFunctor::operator()( actor, touchData );
169 struct OutOfBoundsData
175 :functorCalled(false)
180 // Functor that reads out of bounds data when called
181 struct OutOfBoundsFunctor
185 * @param[in] data Reference to the data to store callback information.
186 * @param[in] returnValue What the functor should return.
188 OutOfBoundsFunctor( OutOfBoundsData& data, bool returnValue = true )
189 : outOfBoundsData ( data ),
190 returnValue( returnValue )
194 bool operator()( Actor actor, const TouchData& touchData )
196 outOfBoundsData.functorCalled = true;
197 size_t count = touchData.GetPointCount();
199 // Read out of bounds data
200 outOfBoundsData.point.deviceId = touchData.GetDeviceId(count+1);
201 outOfBoundsData.point.state = touchData.GetState(count+1);
202 outOfBoundsData.point.hitActor = touchData.GetHitActor(count+1);
203 outOfBoundsData.point.local = touchData.GetLocalPosition(count+1);
204 outOfBoundsData.point.screen = touchData.GetScreenPosition(count+1);
209 OutOfBoundsData& outOfBoundsData;
213 Integration::TouchEvent GenerateSingleTouch( TouchPoint::State state, Vector2 screenPosition )
215 Integration::TouchEvent touchEvent;
216 touchEvent.points.push_back( TouchPoint ( 0, state, screenPosition.x, screenPosition.y ) );
222 ///////////////////////////////////////////////////////////////////////////////
224 int UtcDaliTouchDataNormalProcessing(void)
226 TestApplication application;
228 Actor actor = Actor::New();
229 actor.SetSize(100.0f, 100.0f);
230 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
231 Stage::GetCurrent().Add(actor);
234 application.SendNotification();
235 application.Render();
237 // Connect to actor's touched signal
239 TouchDataFunctor functor( data );
240 actor.TouchSignal().Connect( &application, functor );
242 Vector2 screenCoordinates( 10.0f, 10.0f );
243 Vector2 localCoordinates;
244 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
246 // Emit a down signal
247 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
248 const TestPoint *point1 = &data.touchData.GetPoint(0);
249 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
250 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
251 DALI_TEST_EQUALS( PointState::DOWN, point1->state, TEST_LOCATION );
252 DALI_TEST_EQUALS( screenCoordinates, point1->screen, TEST_LOCATION );
253 DALI_TEST_EQUALS( localCoordinates, point1->local, 0.1f, TEST_LOCATION );
256 // Emit a motion signal
257 screenCoordinates.x = screenCoordinates.y = 11.0f;
258 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
259 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
260 const TestPoint *point2 = &data.touchData.GetPoint(0);
261 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
262 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
263 DALI_TEST_EQUALS( PointState::MOTION, point2->state, TEST_LOCATION );
264 DALI_TEST_EQUALS( screenCoordinates, point2->screen, TEST_LOCATION );
265 DALI_TEST_EQUALS( localCoordinates, point2->local, 0.1f, TEST_LOCATION );
269 screenCoordinates.x = screenCoordinates.y = 12.0f;
270 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
271 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
272 const TestPoint *point3 = &data.touchData.GetPoint(0);
273 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
274 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
275 DALI_TEST_EQUALS( PointState::UP, point3->state, TEST_LOCATION );
276 DALI_TEST_EQUALS( screenCoordinates, point3->screen, TEST_LOCATION );
277 DALI_TEST_EQUALS( localCoordinates, point3->local, 0.1f, TEST_LOCATION );
280 // Emit a down signal where the actor is not present
281 screenCoordinates.x = screenCoordinates.y = 200.0f;
282 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
283 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
288 int UtcDaliTouchDataAPINegative(void)
290 TestApplication application;
292 Actor actor = Actor::New();
293 actor.SetSize(100.0f, 100.0f);
294 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
295 Stage::GetCurrent().Add(actor);
298 application.SendNotification();
299 application.Render();
301 // Connect to actor's touched signal
302 OutOfBoundsData data;
303 OutOfBoundsFunctor functor( data, true );
304 actor.TouchSignal().Connect( &application, functor );
306 Vector2 screenCoordinates( 10.0f, 10.0f );
307 Vector2 localCoordinates;
308 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
310 // Emit a down signal
311 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
313 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
314 DALI_TEST_EQUALS( -1, data.point.deviceId, TEST_LOCATION );
315 DALI_TEST_EQUALS( PointState::FINISHED, data.point.state, TEST_LOCATION );
316 DALI_TEST_EQUALS( Vector2::ZERO, data.point.screen, TEST_LOCATION );
317 DALI_TEST_EQUALS( Vector2::ZERO, data.point.local, 0.1f, TEST_LOCATION );
318 DALI_TEST_CHECK( ! data.point.hitActor );
324 int UtcDaliTouchDataOutsideCameraNearFarPlanes(void)
326 TestApplication application;
328 Stage stage = Stage::GetCurrent();
329 Vector2 stageSize = stage.GetSize();
331 Actor actor = Actor::New();
332 actor.SetSize(100.0f, 100.0f);
333 actor.SetAnchorPoint(AnchorPoint::CENTER);
334 actor.SetParentOrigin(ParentOrigin::CENTER);
338 application.SendNotification();
339 application.Render();
341 // Get the camera's near and far planes
342 RenderTaskList taskList = stage.GetRenderTaskList();
343 Dali::RenderTask task = taskList.GetTask(0);
344 CameraActor camera = task.GetCameraActor();
345 float nearPlane = camera.GetNearClippingPlane();
346 float farPlane = camera.GetFarClippingPlane();
348 // Calculate the current distance of the actor from the camera
349 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
350 float distance = (stageSize.y * 0.5f) / tanHalfFov;
352 // Connect to actor's touched signal
354 TouchDataFunctor functor( data );
355 actor.TouchSignal().Connect( &application, functor );
357 Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );
359 // Emit a down signal
360 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
361 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
364 // Emit a down signal where actor is just at the camera's near plane
365 actor.SetZ(distance - nearPlane);
368 application.SendNotification();
369 application.Render();
371 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
372 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
375 // Emit a down signal where actor is closer than the camera's near plane
376 actor.SetZ((distance - nearPlane) + 1.0f);
379 application.SendNotification();
380 application.Render();
382 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
383 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
386 // Emit a down signal where actor is just at the camera's far plane
387 actor.SetZ(distance - farPlane);
390 application.SendNotification();
391 application.Render();
393 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
394 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
397 // Emit a down signal where actor is further than the camera's far plane
398 actor.SetZ((distance - farPlane) - 1.0f);
401 application.SendNotification();
402 application.Render();
404 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
405 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
410 int UtcDaliTouchDataEmitEmpty(void)
412 TestApplication application;
416 // Emit an empty TouchEvent
417 Integration::TouchEvent event;
418 application.ProcessEvent( event );
419 tet_result( TET_FAIL );
421 catch ( Dali::DaliException& e )
423 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
428 int UtcDaliTouchDataInterrupted(void)
430 TestApplication application;
432 Actor actor = Actor::New();
433 actor.SetSize(100.0f, 100.0f);
434 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
435 Stage::GetCurrent().Add(actor);
438 application.SendNotification();
439 application.Render();
441 // Connect to actor's touched signal
443 TouchDataFunctor functor( data );
444 actor.TouchSignal().Connect( &application, functor );
446 // Emit a down signal
447 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
448 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
449 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
452 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
453 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
454 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
455 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
458 // Emit another interrupted signal, our signal handler should not be called.
459 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
460 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
464 int UtcDaliTouchDataParentConsumer(void)
466 TestApplication application;
467 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
469 Actor actor = Actor::New();
470 actor.SetSize(100.0f, 100.0f);
471 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
472 Stage::GetCurrent().Add(actor);
475 application.SendNotification();
476 application.Render();
478 // Connect to actor's touched signal
480 TouchDataFunctor functor( data, false );
481 actor.TouchSignal().Connect( &application, functor );
483 // Connect to root actor's touched signal
485 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
486 rootActor.TouchSignal().Connect( &application, rootFunctor );
488 Vector2 screenCoordinates( 10.0f, 10.0f );
489 Vector2 actorCoordinates, rootCoordinates;
490 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
491 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
493 // Emit a down signal
494 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
495 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
496 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
497 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
498 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
499 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
500 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
501 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
502 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
503 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
504 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
505 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
506 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
510 // Emit a motion signal
511 screenCoordinates.x = screenCoordinates.y = 11.0f;
512 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
513 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
514 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, screenCoordinates ) );
515 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
516 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
517 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
518 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
519 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
520 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
521 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
522 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
523 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
524 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
525 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
526 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
531 screenCoordinates.x = screenCoordinates.y = 12.0f;
532 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
533 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
534 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, screenCoordinates ) );
535 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
536 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
537 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
538 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
539 DALI_TEST_EQUALS( PointState::UP, data.touchData.points[0].state, TEST_LOCATION );
540 DALI_TEST_EQUALS( PointState::UP, rootData.touchData.points[0].state, TEST_LOCATION );
541 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
542 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
543 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
544 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
545 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
546 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
550 // Emit a down signal where the actor is not present, will hit the root actor though
551 screenCoordinates.x = screenCoordinates.y = 200.0f;
552 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
553 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, screenCoordinates ) );
554 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
555 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
556 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
557 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
558 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
559 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
560 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
564 int UtcDaliTouchDataInterruptedParentConsumer(void)
566 TestApplication application;
567 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
569 Actor actor = Actor::New();
570 actor.SetSize(100.0f, 100.0f);
571 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
572 Stage::GetCurrent().Add(actor);
575 application.SendNotification();
576 application.Render();
578 // Connect to actor's touched signal
580 TouchDataFunctor functor( data, false );
581 actor.TouchSignal().Connect( &application, functor );
583 // Connect to root actor's touched signal
585 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
586 rootActor.TouchSignal().Connect( &application, rootFunctor );
588 // Emit a down signal
589 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
590 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
591 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
592 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
593 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
594 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
595 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
599 // Emit an interrupted signal
600 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
601 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
602 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
603 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
604 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
605 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
606 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
610 // Emit another down signal
611 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
612 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
613 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
614 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
615 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
619 // Remove actor from Stage
620 Stage::GetCurrent().Remove( actor );
625 application.SendNotification();
626 application.Render();
628 // Emit an interrupted signal, only root actor's signal should be called.
629 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
630 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
631 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
632 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
633 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
637 // Emit another interrupted state, none of the signal's should be called.
638 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 200.0f, 200.0f ) ) );
639 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
640 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
644 int UtcDaliTouchDataLeave(void)
646 TestApplication application;
648 Actor actor = Actor::New();
649 actor.SetSize(100.0f, 100.0f);
650 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
651 Stage::GetCurrent().Add(actor);
654 application.SendNotification();
655 application.Render();
657 // Connect to actor's touched signal
659 TouchDataFunctor functor( data );
660 actor.TouchSignal().Connect( &application, functor );
662 // Set actor to require leave events
663 actor.SetLeaveRequired( true );
665 // Emit a down signal
666 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
667 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
668 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
671 // Emit a motion signal outside of actor, should be signalled with a Leave
672 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
673 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
674 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
677 // Another motion outside of actor, no signalling
678 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
679 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
682 // Another motion event inside actor, signalled with motion
683 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
684 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
685 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
688 // We do not want to listen to leave events anymore
689 actor.SetLeaveRequired( false );
691 // Another motion event outside of actor, no signalling
692 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
693 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
698 int UtcDaliTouchDataLeaveParentConsumer(void)
700 TestApplication application;
701 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
703 Actor actor = Actor::New();
704 actor.SetSize(100.0f, 100.0f);
705 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
706 Stage::GetCurrent().Add(actor);
709 application.SendNotification();
710 application.Render();
712 // Connect to actor's touched signal
714 TouchDataFunctor functor( data, false );
715 actor.TouchSignal().Connect( &application, functor );
717 // Connect to root actor's touched signal
719 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
720 rootActor.TouchSignal().Connect( &application, rootFunctor );
722 // Set actor to require leave events
723 actor.SetLeaveRequired( true );
724 rootActor.SetLeaveRequired( true );
726 // Emit a down signal
727 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
728 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
729 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
730 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
731 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
732 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
733 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
737 // Emit a motion signal outside of actor, should be signalled with a Leave
738 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
739 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
740 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
741 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
742 DALI_TEST_EQUALS( PointState::LEAVE, rootData.touchData.points[0].state, TEST_LOCATION );
743 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
744 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
748 // Another motion outside of actor, only rootActor signalled
749 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 201.0f, 201.0f )) );
750 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
751 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
752 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
753 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
757 // Another motion event inside actor, signalled with motion
758 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 10.0f, 10.0f )) );
759 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
760 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
761 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
762 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
763 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
764 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
768 // We do not want to listen to leave events of actor anymore
769 actor.SetLeaveRequired( false );
771 // Another motion event outside of root actor, only root signalled
772 Vector2 stageSize( Stage::GetCurrent().GetSize() );
773 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( stageSize.width + 10.0f, stageSize.height + 10.0f )) );
774 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
775 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
776 DALI_TEST_EQUALS( PointState::LEAVE, rootData.touchData.points[0].state, TEST_LOCATION );
780 int UtcDaliTouchDataActorBecomesInsensitive(void)
782 TestApplication application;
784 Actor actor = Actor::New();
785 actor.SetSize(100.0f, 100.0f);
786 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
787 Stage::GetCurrent().Add(actor);
790 application.SendNotification();
791 application.Render();
793 // Connect to actor's touched signal
795 TouchDataFunctor functor( data );
796 actor.TouchSignal().Connect( &application, functor );
798 // Emit a down signal
799 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
800 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
801 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
804 // Change actor to insensitive
805 actor.SetSensitive( false );
807 // Emit a motion signal, signalled with an interrupted
808 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
809 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
810 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
815 int UtcDaliTouchDataActorBecomesInsensitiveParentConsumer(void)
817 TestApplication application;
818 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
820 Actor actor = Actor::New();
821 actor.SetSize(100.0f, 100.0f);
822 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
823 Stage::GetCurrent().Add(actor);
826 application.SendNotification();
827 application.Render();
829 // Connect to actor's touched signal
831 TouchDataFunctor functor( data, false );
832 actor.TouchSignal().Connect( &application, functor );
834 // Connect to root actor's touched signal
836 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
837 rootActor.TouchSignal().Connect( &application, rootFunctor );
839 // Emit a down signal
840 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
841 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
842 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
843 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
844 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
845 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
846 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
851 application.SendNotification();
852 application.Render();
854 // Make root actor insensitive
855 rootActor.SetSensitive( false );
857 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
858 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2 ( 200.0f, 200.0f )) );
859 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
860 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
861 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
862 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
866 int UtcDaliTouchDataMultipleLayers(void)
868 TestApplication application;
869 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
871 // Connect to actor's touched signal
873 TouchDataFunctor functor( data );
875 Layer layer1 ( Layer::New() );
876 layer1.SetSize(100.0f, 100.0f);
877 layer1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
878 Stage::GetCurrent().Add( layer1 );
880 Actor actor1 ( Actor::New() );
881 actor1.SetSize( 100.0f, 100.0f );
882 actor1.SetAnchorPoint(AnchorPoint::TOP_LEFT);
883 actor1.SetZ( 1.0f ); // Should hit actor1 in this layer
884 layer1.Add( actor1 );
887 application.SendNotification();
888 application.Render();
890 // Connect to layer1 and actor1
891 layer1.TouchSignal().Connect( &application, functor );
892 actor1.TouchSignal().Connect( &application, functor );
894 // Hit in hittable area, actor1 should be hit
895 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
896 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
897 DALI_TEST_CHECK( data.touchedActor == actor1 );
900 // Make layer1 insensitive, nothing should be hit
901 layer1.SetSensitive( false );
902 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
903 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
906 // Make layer1 sensitive again, again actor1 will be hit
907 layer1.SetSensitive( true );
908 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
909 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
910 DALI_TEST_CHECK( data.touchedActor == actor1 );
913 // Make rootActor insensitive, nothing should be hit
914 rootActor.SetSensitive( false );
915 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
916 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
919 // Make rootActor sensitive
920 rootActor.SetSensitive( true );
923 Layer layer2 ( Layer::New() );
924 layer2.SetSize(100.0f, 100.0f );
925 layer2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
926 layer2.SetZ( 10.0f ); // Should hit layer2 in this layer rather than actor2
927 Stage::GetCurrent().Add( layer2 );
929 Actor actor2 ( Actor::New() );
930 actor2.SetSize(100.0f, 100.0f);
931 actor2.SetAnchorPoint(AnchorPoint::TOP_LEFT);
932 layer2.Add( actor2 );
935 application.SendNotification();
936 application.Render();
938 // Connect to layer2 and actor2
939 layer2.TouchSignal().Connect( &application, functor );
940 actor2.TouchSignal().Connect( &application, functor );
942 // Emit an event, should hit layer2
943 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
944 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
945 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
948 // Make layer2 insensitive, should hit actor1
949 layer2.SetSensitive( false );
950 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
951 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
952 DALI_TEST_CHECK( data.touchedActor == actor1 );
955 // Make layer2 sensitive again, should hit layer2
956 layer2.SetSensitive( true );
957 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
958 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
959 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
962 // Make layer2 invisible, render and notify
963 layer2.SetVisible( false );
964 application.SendNotification();
965 application.Render();
968 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
969 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
970 DALI_TEST_CHECK( data.touchedActor == actor1 );
973 // Make rootActor invisible, render and notify
974 rootActor.SetVisible( false );
975 application.SendNotification();
976 application.Render();
978 // Should not hit anything
979 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
980 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
985 int UtcDaliTouchDataMultipleRenderTasks(void)
987 TestApplication application;
988 Stage stage ( Stage::GetCurrent() );
989 Vector2 stageSize ( stage.GetSize() );
991 Actor actor = Actor::New();
992 actor.SetSize(100.0f, 100.0f);
993 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
996 // Create render task
997 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
998 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
999 renderTask.SetViewport( viewport );
1000 renderTask.SetInputEnabled( true );
1002 // Render and notify
1003 application.SendNotification();
1004 application.Render();
1006 // Connect to actor's touched signal
1008 TouchDataFunctor functor( data );
1009 actor.TouchSignal().Connect( &application, functor );
1011 // Emit a down signal
1012 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1013 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1016 // Ensure renderTask actor can be hit too.
1017 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1018 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1021 // Disable input on renderTask, should not be hittable
1022 renderTask.SetInputEnabled( false );
1023 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1024 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1029 int UtcDaliTouchDataMultipleRenderTasksWithChildLayer(void)
1031 TestApplication application;
1032 Stage stage ( Stage::GetCurrent() );
1033 Vector2 stageSize ( stage.GetSize() );
1035 Actor actor = Actor::New();
1036 actor.SetSize(100.0f, 100.0f);
1037 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1040 Layer layer = Layer::New();
1041 layer.SetSize(100.0f, 100.0f);
1042 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1045 // Create render task
1046 Viewport viewport( stageSize.width * 0.5f, stageSize.height * 0.5f, stageSize.width * 0.5f, stageSize.height * 0.5f );
1047 RenderTask renderTask ( Stage::GetCurrent().GetRenderTaskList().CreateTask() );
1048 renderTask.SetViewport( viewport );
1049 renderTask.SetInputEnabled( true );
1050 renderTask.SetSourceActor( actor );
1052 // Render and notify
1053 application.SendNotification();
1054 application.Render();
1056 // Connect to layer's touched signal
1058 TouchDataFunctor functor( data );
1059 actor.TouchSignal().Connect( &application, functor );
1060 layer.TouchSignal().Connect( &application, functor );
1062 // Emit a down signal
1063 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1064 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1067 // Ensure renderTask actor can be hit too.
1068 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1069 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1072 // Disable input on renderTask, should not be hittable
1073 renderTask.SetInputEnabled( false );
1074 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1075 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1080 int UtcDaliTouchDataOffscreenRenderTasks(void)
1082 TestApplication application;
1083 Stage stage ( Stage::GetCurrent() );
1084 Vector2 stageSize ( stage.GetSize() );
1086 // FrameBufferImage for offscreen RenderTask
1087 FrameBufferImage frameBufferImage( FrameBufferImage::New( stageSize.width, stageSize.height, Pixel::RGBA8888 ) );
1089 // Create a renderable actor to display the FrameBufferImage
1090 Actor renderableActor = CreateRenderableActor( frameBufferImage );
1091 renderableActor.SetParentOrigin(ParentOrigin::CENTER);
1092 renderableActor.SetSize( stageSize.x, stageSize.y );
1093 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
1094 stage.Add( renderableActor );
1096 Actor actor = Actor::New();
1097 actor.SetSize(100.0f, 100.0f);
1098 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1100 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
1102 stage.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
1104 // Create a RenderTask
1105 RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
1106 renderTask.SetSourceActor( actor );
1107 renderTask.SetTargetFrameBuffer( frameBufferImage );
1108 renderTask.SetInputEnabled( true );
1110 // Create another RenderTask
1111 RenderTask renderTask2( stage.GetRenderTaskList().CreateTask() );
1112 renderTask2.SetInputEnabled( true );
1114 // Render and notify
1115 application.SendNotification();
1116 application.Render();
1118 // Connect to actor's touched signal
1120 TouchDataFunctor functor( data );
1121 actor.TouchSignal().Connect( &application, functor );
1123 // Emit a down signal
1124 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1125 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1130 int UtcDaliTouchDataMultipleRenderableActors(void)
1132 TestApplication application;
1133 Stage stage ( Stage::GetCurrent() );
1134 Vector2 stageSize ( stage.GetSize() );
1136 Actor parent = CreateRenderableActor();
1137 parent.SetSize(100.0f, 100.0f);
1138 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1141 Actor actor = CreateRenderableActor();
1142 actor.SetSize(100.0f, 100.0f);
1143 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1146 // Render and notify
1147 application.SendNotification();
1148 application.Render();
1150 // Connect to layer's touched signal
1152 TouchDataFunctor functor( data );
1153 parent.TouchSignal().Connect( &application, functor );
1154 actor.TouchSignal().Connect( &application, functor );
1156 // Emit a down signal
1157 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1158 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1159 DALI_TEST_CHECK( actor == data.touchedActor );
1163 int UtcDaliTouchDataActorRemovedInSignal(void)
1165 TestApplication application;
1167 Actor actor = Actor::New();
1168 actor.SetSize(100.0f, 100.0f);
1169 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1170 Stage::GetCurrent().Add(actor);
1172 // Render and notify
1173 application.SendNotification();
1174 application.Render();
1176 // Connect to actor's touched signal
1178 RemoveActorFunctor functor( data );
1179 actor.TouchSignal().Connect( &application, functor );
1181 // Register for leave events
1182 actor.SetLeaveRequired( true );
1184 // Emit a down signal
1185 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1186 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1189 // Re-add, render and notify
1190 Stage::GetCurrent().Add(actor);
1191 application.SendNotification();
1192 application.Render();
1194 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1195 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1196 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1199 // Emit a down signal
1200 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1201 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1204 // Render and notify
1205 application.SendNotification();
1206 application.Render();
1208 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1209 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1210 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1213 // Re-add actor back to stage, render and notify
1214 Stage::GetCurrent().Add(actor);
1215 application.SendNotification();
1216 application.Render();
1218 // Emit another down event
1219 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1220 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1223 // Completely delete the actor
1226 // Emit event, should not crash and should not receive an event.
1227 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 210.0f, 210.0f ) ) );
1228 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1232 int UtcDaliTouchDataActorSignalNotConsumed(void)
1234 TestApplication application;
1236 Actor actor = Actor::New();
1237 actor.SetSize(100.0f, 100.0f);
1238 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1239 Stage::GetCurrent().Add(actor);
1241 // Render and notify
1242 application.SendNotification();
1243 application.Render();
1245 // Connect to actor's touched signal
1247 TouchDataFunctor functor( data, false );
1248 actor.TouchSignal().Connect( &application, functor );
1250 // Emit a down signal
1251 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1252 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1256 int UtcDaliTouchDataActorUnStaged(void)
1258 TestApplication application;
1260 Actor actor = Actor::New();
1261 actor.SetSize(100.0f, 100.0f);
1262 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1263 Stage::GetCurrent().Add(actor);
1265 // Render and notify
1266 application.SendNotification();
1267 application.Render();
1269 // Connect to actor's touched signal
1271 TouchDataFunctor functor( data );
1272 actor.TouchSignal().Connect( &application, functor );
1274 // Emit a down signal
1275 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1276 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1279 // Remove actor from stage
1280 Stage::GetCurrent().Remove( actor );
1283 // Render and notify
1284 application.SendNotification();
1285 application.Render();
1287 // Emit a move at the same point, we should not be signalled.
1288 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1289 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1294 int UtcDaliTouchDataSystemOverlayActor(void)
1296 TestApplication application;
1297 Dali::Integration::Core& core( application.GetCore() );
1298 Dali::Integration::SystemOverlay& systemOverlay( core.GetSystemOverlay() );
1299 systemOverlay.GetOverlayRenderTasks().CreateTask();
1301 // Create an actor and add it to the system overlay.
1302 Actor systemActor = Actor::New();
1303 systemActor.SetSize(100.0f, 100.0f);
1304 systemActor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1305 systemOverlay.Add( systemActor );
1307 // Create an actor and add it to the stage as per normal, same position and size as systemActor
1308 Actor actor = Actor::New();
1309 actor.SetSize(100.0f, 100.0f);
1310 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1311 Stage::GetCurrent().Add(actor);
1313 // Connect to the touch signals.
1315 TouchDataFunctor functor( data );
1316 systemActor.TouchSignal().Connect( &application, functor );
1317 actor.TouchSignal().Connect( &application, functor );
1319 // Render and notify
1320 application.SendNotification();
1321 application.Render();
1323 // Emit a down signal, the system overlay is drawn last so is at the top, should hit the systemActor.
1324 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1325 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1326 DALI_TEST_CHECK( systemActor == data.touchedActor );
1330 int UtcDaliTouchDataLayerConsumesTouch(void)
1332 TestApplication application;
1334 Actor actor = Actor::New();
1335 actor.SetSize(100.0f, 100.0f);
1336 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1337 Stage::GetCurrent().Add(actor);
1339 // Render and notify
1340 application.SendNotification();
1341 application.Render();
1343 // Connect to actor's touched signal
1345 TouchDataFunctor functor( data );
1346 actor.TouchSignal().Connect( &application, functor );
1348 // Add a layer to overlap the actor
1349 Layer layer = Layer::New();
1350 layer.SetSize(100.0f, 100.0f);
1351 layer.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1352 Stage::GetCurrent().Add( layer );
1355 // Render and notify
1356 application.SendNotification();
1357 application.Render();
1359 // Emit a few touch signals
1360 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1361 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1362 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1365 // Set layer to consume all touch
1366 layer.SetTouchConsumed( true );
1368 // Render and notify
1369 application.SendNotification();
1370 application.Render();
1372 // Emit the same signals again, should not receive
1373 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1374 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Up, Vector2( 10.0f, 10.0f ) ) );
1375 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1381 int UtcDaliTouchDataLeaveActorReadded(void)
1383 TestApplication application;
1384 Stage stage = Stage::GetCurrent();
1386 Actor actor = Actor::New();
1387 actor.SetSize(100.0f, 100.0f);
1388 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1391 // Set actor to receive touch-events
1392 actor.SetLeaveRequired( true );
1394 // Render and notify
1395 application.SendNotification();
1396 application.Render();
1398 // Connect to actor's touched signal
1400 TouchDataFunctor functor( data );
1401 actor.TouchSignal().Connect( &application, functor );
1403 // Emit a down and motion
1404 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1405 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 11.0f, 10.0f ) ) );
1406 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1409 // Remove actor from stage and add again
1410 stage.Remove( actor );
1413 // Emit a motion within the actor's bounds
1414 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 12.0f, 10.0f ) ) );
1415 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1418 // Emit a motion outside the actor's bounds
1419 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 200.0f, 200.0f ) ) );
1420 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1421 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
1427 int UtcDaliTouchDataStencilNonRenderableActor(void)
1429 TestApplication application;
1430 Stage stage = Stage::GetCurrent();
1432 Actor actor = Actor::New();
1433 actor.SetSize(100.0f, 100.0f);
1434 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1437 Actor stencil = Actor::New();
1438 stencil.SetSize(50.0f, 50.0f);
1439 stencil.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1440 stencil.SetDrawMode( DrawMode::STENCIL );
1443 // Render and notify
1444 application.SendNotification();
1445 application.Render();
1447 // Connect to actor's touched signal
1449 TouchDataFunctor functor( data );
1450 actor.TouchSignal().Connect( &application, functor );
1452 // Emit an event within stencil area
1453 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1454 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1457 // Emit an event outside the stencil area but within the actor area, we should have a hit!
1458 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 60.0f, 60.0f ) ) );
1459 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1465 int UtcDaliTouchDataActorUnstaged(void)
1467 TestApplication application;
1469 Actor actor = Actor::New();
1470 actor.SetSize(100.0f, 100.0f);
1471 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1472 Stage::GetCurrent().Add(actor);
1474 // Render and notify
1475 application.SendNotification();
1476 application.Render();
1478 // Connect to actor's touched signal
1480 TouchDataFunctor functor( data );
1481 actor.TouchSignal().Connect( &application, functor );
1483 // Emit a down signal
1484 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1485 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1486 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1487 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1490 // Render and notify
1491 application.SendNotification();
1492 application.Render();
1494 // Unparent the actor
1497 // Should receive an interrupted event
1498 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1499 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1503 int UtcDaliTouchDataParentUnstaged(void)
1505 TestApplication application;
1507 Actor parent = Actor::New();
1508 parent.SetSize(100.0f, 100.0f);
1509 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1510 Stage::GetCurrent().Add(parent);
1512 Actor actor = Actor::New();
1513 actor.SetSize(100.0f, 100.0f);
1514 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1517 // Render and notify
1518 application.SendNotification();
1519 application.Render();
1521 // Connect to actor's touched signal
1523 TouchDataFunctor functor( data );
1524 actor.TouchSignal().Connect( &application, functor );
1526 // Emit a down signal
1527 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1528 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1529 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1530 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1533 // Render and notify
1534 application.SendNotification();
1535 application.Render();
1537 // Unparent the parent of the touchable actor
1540 // Should receive an interrupted event
1541 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1542 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1546 int UtcDaliTouchDataActorUnstagedDifferentConsumer(void)
1548 TestApplication application;
1550 Actor parent = Actor::New();
1551 parent.SetSize(100.0f, 100.0f);
1552 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1553 Stage::GetCurrent().Add(parent);
1555 Actor actor = Actor::New();
1556 actor.SetSize(100.0f, 100.0f);
1557 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1560 // Render and notify
1561 application.SendNotification();
1562 application.Render();
1564 // Connect to actor's touched signal
1566 TouchDataFunctor functor( data, false /* Do not consume */ );
1567 actor.TouchSignal().Connect( &application, functor );
1569 // Connect to parent's touched signal
1570 SignalData parentData;
1571 TouchDataFunctor parentFunctor( parentData );
1572 parent.TouchSignal().Connect( &application, parentFunctor );
1574 // Emit a down signal
1575 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1576 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1577 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1578 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1579 DALI_TEST_CHECK( actor == data.touchedActor );
1580 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1581 DALI_TEST_EQUALS( PointState::DOWN, parentData.touchData.points[0].state, TEST_LOCATION );
1582 DALI_TEST_CHECK( actor == parentData.touchData.points[0].hitActor );
1583 DALI_TEST_CHECK( parent == parentData.touchedActor );
1587 // Render and notify
1588 application.SendNotification();
1589 application.Render();
1591 // Unparent the actor
1594 // Should receive an interrupted event for both actor & parent
1595 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1596 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1597 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1598 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1602 // Readd actor to parent
1605 // Render and notify
1606 application.SendNotification();
1607 application.Render();
1609 // Emit a motion signal
1610 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Motion, Vector2( 10.0f, 10.0f ) ) );
1611 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1612 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1616 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1617 SignalData secondData;
1618 TouchDataFunctor secondFunctor( secondData /* Consume */ );
1619 actor.TouchSignal().Connect( &application, secondFunctor );
1621 // Unparent the actor
1624 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1625 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1626 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1627 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1628 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1629 DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1630 DALI_TEST_EQUALS( PointState::INTERRUPTED, secondData.touchData.points[0].state, TEST_LOCATION );
1638 int UtcDaliTouchDataInterruptedDifferentConsumer(void)
1640 TestApplication application;
1641 Actor rootActor( Stage::GetCurrent().GetRootLayer() );
1643 Actor parent = Actor::New();
1644 parent.SetSize(100.0f, 100.0f);
1645 parent.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1646 Stage::GetCurrent().Add(parent);
1648 Actor actor = Actor::New();
1649 actor.SetSize(100.0f, 100.0f);
1650 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1653 // Render and notify
1654 application.SendNotification();
1655 application.Render();
1657 // Connect to actor's touched signal
1659 TouchDataFunctor functor( data, false /* Do not consume */ );
1660 actor.TouchSignal().Connect( &application, functor );
1662 // Connect to parent's touched signal
1663 SignalData parentData;
1664 TouchDataFunctor parentFunctor( parentData, false /* Do not consume */ );
1665 parent.TouchSignal().Connect( &application, parentFunctor );
1667 // Connect to root's touched signal and consume
1668 SignalData rootData;
1669 TouchDataFunctor rootFunctor( rootData );
1670 rootActor.TouchSignal().Connect( &application, rootFunctor );
1672 // Emit a down signal
1673 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Down, Vector2( 10.0f, 10.0f ) ) );
1674 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1675 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1676 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1677 DALI_TEST_CHECK( actor == data.touchedActor );
1678 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1679 DALI_TEST_EQUALS( PointState::DOWN, parentData.touchData.points[0].state, TEST_LOCATION );
1680 DALI_TEST_CHECK( actor == parentData.touchData.points[0].hitActor );
1681 DALI_TEST_CHECK( parent == parentData.touchedActor );
1682 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1683 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
1684 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
1685 DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1690 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1691 SignalData secondData;
1692 TouchDataFunctor secondFunctor( secondData /* Consume */ );
1693 parent.TouchSignal().Connect( &application, secondFunctor );
1695 // Emit an interrupted signal, all three should STILL be called
1696 application.ProcessEvent( GenerateSingleTouch( TouchPoint::Interrupted, Vector2( 10.0f, 10.0f ) ) );
1697 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1698 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1699 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1700 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1701 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1702 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );