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/events/touch-data-integ.h>
24 #include <dali/integration-api/render-task-list-integ.h>
25 #include <dali-test-suite-utils.h>
26 #include <dali/devel-api/actors/actor-devel.h>
30 void utc_dali_touch_data_processing_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_touch_data_processing_cleanup(void)
37 test_return_value = TET_PASS;
40 ///////////////////////////////////////////////////////////////////////////////
47 PointState::Type state;
52 Vector2 ellipseRadius;
55 Device::Class::Type deviceClass;
56 Device::Subclass::Type deviceSubclass;
59 : deviceId(-1), state(PointState::FINISHED), radius(0), pressure(0)
62 static const TestPoint ZERO;
65 const TestPoint TestPoint::ZERO;
68 // Stores data that is populated in the callback and will be read by the TET cases
72 : functorCalled( false ),
81 std::vector<TestPoint> points;
83 const TestPoint& GetPoint(size_t i)
85 if( i < points.size() )
89 return TestPoint::ZERO;
91 size_t GetPointCount()
99 functorCalled = false;
102 touchData.points.clear();
104 touchedActor.Reset();
108 TestTouchData touchData;
112 // Functor that sets the data when called
113 struct TouchDataFunctor
117 * @param[in] data Reference to the data to store callback information.
118 * @param[in] returnValue What the functor should return.
120 TouchDataFunctor( SignalData& data, bool returnValue = true )
121 : signalData( data ),
122 returnValue( returnValue )
126 bool operator()( Actor actor, const TouchData& touchData )
128 signalData.functorCalled = true;
129 signalData.touchedActor = actor;
131 signalData.touchData.time = touchData.GetTime();
132 signalData.touchData.points.clear();
134 for( size_t i=0; i<touchData.GetPointCount(); ++i )
137 p.deviceId = touchData.GetDeviceId(i);
138 p.state = touchData.GetState(i);
139 p.hitActor = touchData.GetHitActor(i);
140 p.local = touchData.GetLocalPosition(i);
141 p.screen = touchData.GetScreenPosition(i);
142 p.radius = touchData.GetRadius(i);
143 p.ellipseRadius = touchData.GetEllipseRadius(i);
144 p.pressure = touchData.GetPressure(i);
145 p.angle = touchData.GetAngle(i);
146 p.deviceClass = touchData.GetDeviceClass(i);
147 p.deviceSubclass = touchData.GetDeviceSubclass(i);
148 signalData.touchData.points.push_back(p);
154 SignalData& signalData;
164 : signalReceived(false)
169 struct TouchDataHandleFunctor
173 * @param[in] data Reference to the data to store callback information.
174 * @param[in] returnValue What the functor should return.
176 TouchDataHandleFunctor( HandleData& handleData, bool returnValue = true )
177 : handleData(handleData),
178 returnValue( returnValue )
182 bool operator()( Actor actor, const TouchData& someTouchData )
184 handleData.signalReceived = true;
185 TouchData handle(someTouchData);
186 handleData.touchData = handle;
190 HandleData& handleData;
195 // Functor that removes the actor when called.
196 struct RemoveActorFunctor : public TouchDataFunctor
200 * @param[in] data Reference to the data to store callback information.
201 * @param[in] returnValue What the functor should return.
203 RemoveActorFunctor( SignalData& data, bool returnValue = true )
204 : TouchDataFunctor( data, returnValue )
208 bool operator()( Actor actor, const TouchData& touchData )
210 Actor parent( actor.GetParent() );
213 parent.Remove( actor );
216 return TouchDataFunctor::operator()( actor, touchData );
220 struct OutOfBoundsData
226 :functorCalled(false)
231 // Functor that reads out of bounds data when called
232 struct OutOfBoundsFunctor
236 * @param[in] data Reference to the data to store callback information.
237 * @param[in] returnValue What the functor should return.
239 OutOfBoundsFunctor( OutOfBoundsData& data, bool returnValue = true )
240 : outOfBoundsData ( data ),
241 returnValue( returnValue )
245 bool operator()( Actor actor, const TouchData& touchData )
247 outOfBoundsData.functorCalled = true;
248 size_t count = touchData.GetPointCount();
250 // Read out of bounds data
251 outOfBoundsData.point.deviceId = touchData.GetDeviceId(count+1);
252 outOfBoundsData.point.state = touchData.GetState(count+1);
253 outOfBoundsData.point.hitActor = touchData.GetHitActor(count+1);
254 outOfBoundsData.point.local = touchData.GetLocalPosition(count+1);
255 outOfBoundsData.point.screen = touchData.GetScreenPosition(count+1);
260 OutOfBoundsData& outOfBoundsData;
264 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition )
266 Integration::TouchEvent touchEvent;
267 Integration::Point point;
268 point.SetState( state );
269 point.SetScreenPosition( screenPosition );
270 point.SetDeviceClass( Device::Class::TOUCH );
271 point.SetDeviceSubclass( Device::Subclass::NONE );
272 touchEvent.points.push_back( point );
278 ///////////////////////////////////////////////////////////////////////////////
280 int UtcDaliTouchDataNormalProcessing01(void)
282 TestApplication application;
284 Actor actor = Actor::New();
285 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
286 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
287 application.GetScene().Add(actor);
290 application.SendNotification();
291 application.Render();
293 // Connect to actor's touch signal
295 TouchDataFunctor functor( data );
296 actor.TouchSignal().Connect( &application, functor );
298 Vector2 screenCoordinates( 10.0f, 10.0f );
299 Vector2 localCoordinates;
300 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
302 // Emit a down signal
303 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
304 const TestPoint *point1 = &data.touchData.GetPoint(0);
305 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
306 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
307 DALI_TEST_EQUALS( PointState::DOWN, point1->state, TEST_LOCATION );
308 DALI_TEST_EQUALS( screenCoordinates, point1->screen, TEST_LOCATION );
309 DALI_TEST_EQUALS( localCoordinates, point1->local, 0.1f, TEST_LOCATION );
312 // Emit a motion signal
313 screenCoordinates.x = screenCoordinates.y = 11.0f;
314 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
315 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, screenCoordinates ) );
316 const TestPoint *point2 = &data.touchData.GetPoint(0);
317 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
318 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
319 DALI_TEST_EQUALS( PointState::MOTION, point2->state, TEST_LOCATION );
320 DALI_TEST_EQUALS( screenCoordinates, point2->screen, TEST_LOCATION );
321 DALI_TEST_EQUALS( localCoordinates, point2->local, 0.1f, TEST_LOCATION );
325 screenCoordinates.x = screenCoordinates.y = 12.0f;
326 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
327 application.ProcessEvent( GenerateSingleTouch( PointState::UP, screenCoordinates ) );
328 const TestPoint *point3 = &data.touchData.GetPoint(0);
329 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
330 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
331 DALI_TEST_EQUALS( PointState::UP, point3->state, TEST_LOCATION );
332 DALI_TEST_EQUALS( screenCoordinates, point3->screen, TEST_LOCATION );
333 DALI_TEST_EQUALS( localCoordinates, point3->local, 0.1f, TEST_LOCATION );
336 // Emit a down signal where the actor is not present
337 screenCoordinates.x = screenCoordinates.y = 200.0f;
338 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
339 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
344 int UtcDaliTouchDataNormalProcessing02(void)
346 TestApplication application;
348 Actor actor = Actor::New();
349 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
350 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
351 application.GetScene().Add(actor);
354 application.SendNotification();
355 application.Render();
357 // Connect to actor's touched signal
358 HandleData handleData;
359 TouchDataHandleFunctor functor( handleData );
360 actor.TouchSignal().Connect( &application, functor );
362 Vector2 screenCoordinates( 10.0f, 10.0f );
363 Vector2 localCoordinates;
364 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
366 // Emit a down signal
367 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
368 DALI_TEST_EQUALS( true, handleData.signalReceived, TEST_LOCATION );
369 DALI_TEST_EQUALS( 1u, handleData.touchData.GetPointCount(), TEST_LOCATION );
370 DALI_TEST_EQUALS( PointState::DOWN, handleData.touchData.GetState(0), TEST_LOCATION );
371 DALI_TEST_EQUALS( screenCoordinates, handleData.touchData.GetScreenPosition(0), TEST_LOCATION );
372 DALI_TEST_EQUALS( localCoordinates, handleData.touchData.GetLocalPosition(0), 0.1f, TEST_LOCATION );
378 int UtcDaliTouchDataAPINegative(void)
380 TestApplication application;
382 Actor actor = Actor::New();
383 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
384 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
385 application.GetScene().Add(actor);
388 application.SendNotification();
389 application.Render();
391 // Connect to actor's touched signal
392 OutOfBoundsData data;
393 OutOfBoundsFunctor functor( data, true );
394 actor.TouchSignal().Connect( &application, functor );
396 Vector2 screenCoordinates( 10.0f, 10.0f );
397 Vector2 localCoordinates;
398 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
400 // Emit a down signal
401 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
403 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
404 DALI_TEST_EQUALS( -1, data.point.deviceId, TEST_LOCATION );
405 DALI_TEST_EQUALS( PointState::FINISHED, data.point.state, TEST_LOCATION );
406 DALI_TEST_EQUALS( Vector2::ZERO, data.point.screen, TEST_LOCATION );
407 DALI_TEST_EQUALS( Vector2::ZERO, data.point.local, 0.1f, TEST_LOCATION );
408 DALI_TEST_CHECK( ! data.point.hitActor );
414 int UtcDaliTouchDataOutsideCameraNearFarPlanes(void)
416 TestApplication application;
418 Integration::Scene scene = application.GetScene();
419 Vector2 sceneSize = scene.GetSize();
421 Actor actor = Actor::New();
422 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
423 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
424 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
428 application.SendNotification();
429 application.Render();
431 // Get the camera's near and far planes
432 RenderTaskList taskList = scene.GetRenderTaskList();
433 Dali::RenderTask task = taskList.GetTask(0);
434 CameraActor camera = task.GetCameraActor();
435 float nearPlane = camera.GetNearClippingPlane();
436 float farPlane = camera.GetFarClippingPlane();
438 // Calculate the current distance of the actor from the camera
439 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
440 float distance = (sceneSize.y * 0.5f) / tanHalfFov;
442 // Connect to actor's touched signal
444 TouchDataFunctor functor( data );
445 actor.TouchSignal().Connect( &application, functor );
447 Vector2 screenCoordinates( sceneSize.x * 0.5f, sceneSize.y * 0.5f );
449 // Emit a down signal
450 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
451 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
454 // Emit a down signal where actor is just at the camera's near plane
455 actor.SetProperty( Actor::Property::POSITION_Z, distance - nearPlane);
458 application.SendNotification();
459 application.Render();
461 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
462 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
465 // Emit a down signal where actor is closer than the camera's near plane
466 actor.SetProperty( Actor::Property::POSITION_Z, (distance - nearPlane) + 1.0f);
469 application.SendNotification();
470 application.Render();
472 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
473 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
476 // Emit a down signal where actor is just at the camera's far plane
477 actor.SetProperty( Actor::Property::POSITION_Z, distance - farPlane);
480 application.SendNotification();
481 application.Render();
483 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
484 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
487 // Emit a down signal where actor is further than the camera's far plane
488 actor.SetProperty( Actor::Property::POSITION_Z, (distance - farPlane) - 1.0f);
491 application.SendNotification();
492 application.Render();
494 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
495 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
500 int UtcDaliTouchDataEmitEmpty(void)
502 TestApplication application;
506 // Emit an empty TouchEvent
507 Integration::TouchEvent event;
508 application.ProcessEvent( event );
509 tet_result( TET_FAIL );
511 catch ( Dali::DaliException& e )
513 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
518 int UtcDaliTouchDataInterrupted(void)
520 TestApplication application;
522 Actor actor = Actor::New();
523 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
524 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
525 application.GetScene().Add(actor);
528 application.SendNotification();
529 application.Render();
531 // Connect to actor's touched signal
533 TouchDataFunctor functor( data );
534 actor.TouchSignal().Connect( &application, functor );
536 // Emit a down signal
537 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
538 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
539 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
542 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
543 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
544 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
545 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
548 // Emit another interrupted signal, our signal handler should not be called.
549 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
550 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
554 int UtcDaliTouchDataParentConsumer(void)
556 TestApplication application;
557 Actor rootActor( application.GetScene().GetRootLayer() );
559 Actor actor = Actor::New();
560 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
561 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
562 application.GetScene().Add(actor);
565 application.SendNotification();
566 application.Render();
568 // Connect to actor's touched signal
570 TouchDataFunctor functor( data, false );
571 actor.TouchSignal().Connect( &application, functor );
573 // Connect to root actor's touched signal
575 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
576 rootActor.TouchSignal().Connect( &application, rootFunctor );
578 Vector2 screenCoordinates( 10.0f, 10.0f );
579 Vector2 actorCoordinates, rootCoordinates;
580 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
581 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
583 // Emit a down signal
584 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
585 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
586 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
587 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
588 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
589 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
590 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
591 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
592 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
593 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
594 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
595 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
596 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
600 // Emit a motion signal
601 screenCoordinates.x = screenCoordinates.y = 11.0f;
602 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
603 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
604 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, screenCoordinates ) );
605 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
606 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
607 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
608 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
609 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
610 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
611 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
612 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
613 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
614 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
615 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
616 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
621 screenCoordinates.x = screenCoordinates.y = 12.0f;
622 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
623 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
624 application.ProcessEvent( GenerateSingleTouch( PointState::UP, screenCoordinates ) );
625 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
626 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
627 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
628 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
629 DALI_TEST_EQUALS( PointState::UP, data.touchData.points[0].state, TEST_LOCATION );
630 DALI_TEST_EQUALS( PointState::UP, rootData.touchData.points[0].state, TEST_LOCATION );
631 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
632 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
633 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
634 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
635 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
636 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
640 // Emit a down signal where the actor is not present, will hit the root actor though
641 screenCoordinates.x = screenCoordinates.y = 200.0f;
642 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
643 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
644 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
645 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
646 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
647 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
648 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
649 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
650 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
654 int UtcDaliTouchDataInterruptedParentConsumer(void)
656 TestApplication application;
657 Actor rootActor( application.GetScene().GetRootLayer() );
659 Actor actor = Actor::New();
660 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
661 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
662 application.GetScene().Add(actor);
665 application.SendNotification();
666 application.Render();
668 // Connect to actor's touched signal
670 TouchDataFunctor functor( data, false );
671 actor.TouchSignal().Connect( &application, functor );
673 // Connect to root actor's touched signal
675 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
676 rootActor.TouchSignal().Connect( &application, rootFunctor );
678 // Emit a down signal
679 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
680 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
681 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
682 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
683 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
684 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
685 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
689 // Emit an interrupted signal
690 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
691 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
692 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
693 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
694 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
695 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
696 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
700 // Emit another down signal
701 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
702 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
703 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
704 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
705 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
709 // Remove actor from scene
710 application.GetScene().Remove( actor );
715 application.SendNotification();
716 application.Render();
718 // Emit an interrupted signal, only root actor's signal should be called.
719 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
720 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
721 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
722 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
723 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
727 // Emit another interrupted state, none of the signal's should be called.
728 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
729 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
730 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
734 int UtcDaliTouchDataLeave(void)
736 TestApplication application;
738 Actor actor = Actor::New();
739 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
740 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
741 application.GetScene().Add(actor);
744 application.SendNotification();
745 application.Render();
747 // Connect to actor's touched signal
749 TouchDataFunctor functor( data );
750 actor.TouchSignal().Connect( &application, functor );
752 // Set actor to require leave events
753 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
755 // Emit a down signal
756 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
757 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
758 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
761 // Emit a motion signal outside of actor, should be signalled with a Leave
762 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
763 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
764 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
767 // Another motion outside of actor, no signalling
768 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 201.0f, 201.0f )) );
769 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
772 // Another motion event inside actor, signalled with motion
773 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 10.0f, 10.0f )) );
774 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
775 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
778 // We do not want to listen to leave events anymore
779 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, false );
781 // Another motion event outside of actor, no signalling
782 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
783 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
788 int UtcDaliTouchDataLeaveParentConsumer(void)
790 TestApplication application;
791 Actor rootActor( application.GetScene().GetRootLayer() );
793 Actor actor = Actor::New();
794 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
795 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
796 application.GetScene().Add(actor);
799 application.SendNotification();
800 application.Render();
802 // Connect to actor's touched signal
804 TouchDataFunctor functor( data, false );
805 actor.TouchSignal().Connect( &application, functor );
807 // Connect to root actor's touched signal
809 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
810 rootActor.TouchSignal().Connect( &application, rootFunctor );
812 // Set actor to require leave events
813 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
814 rootActor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
816 // Emit a down signal
817 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
818 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
819 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
820 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
821 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
822 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
823 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
827 // Emit a motion signal outside of actor, should be signalled with a Leave
828 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
829 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
830 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
831 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
832 DALI_TEST_EQUALS( PointState::LEAVE, rootData.touchData.points[0].state, TEST_LOCATION );
833 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
834 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
838 // Another motion outside of actor, only rootActor signalled
839 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 201.0f, 201.0f )) );
840 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
841 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
842 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
843 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
847 // Another motion event inside actor, signalled with motion
848 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 10.0f, 10.0f )) );
849 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
850 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
851 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
852 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
853 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
854 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
858 // We do not want to listen to leave events of actor anymore
859 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, false );
861 // Another motion event outside of root actor, only root signalled
862 Vector2 sceneSize( application.GetScene().GetSize() );
863 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( sceneSize.width + 10.0f, sceneSize.height + 10.0f )) );
864 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
865 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
866 DALI_TEST_EQUALS( PointState::LEAVE, rootData.touchData.points[0].state, TEST_LOCATION );
870 int UtcDaliTouchDataActorBecomesInsensitive(void)
872 TestApplication application;
874 Actor actor = Actor::New();
875 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
876 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
877 application.GetScene().Add(actor);
880 application.SendNotification();
881 application.Render();
883 // Connect to actor's touched signal
885 TouchDataFunctor functor( data );
886 actor.TouchSignal().Connect( &application, functor );
888 // Emit a down signal
889 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
890 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
891 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
894 // Change actor to insensitive
895 actor.SetProperty( Actor::Property::SENSITIVE, false );
897 // Emit a motion signal, signalled with an interrupted
898 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
899 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
900 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
905 int UtcDaliTouchDataActorBecomesInsensitiveParentConsumer(void)
907 TestApplication application;
908 Actor rootActor( application.GetScene().GetRootLayer() );
910 Actor actor = Actor::New();
911 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
912 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
913 application.GetScene().Add(actor);
916 application.SendNotification();
917 application.Render();
919 // Connect to actor's touched signal
921 TouchDataFunctor functor( data, false );
922 actor.TouchSignal().Connect( &application, functor );
924 // Connect to root actor's touched signal
926 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
927 rootActor.TouchSignal().Connect( &application, rootFunctor );
929 // Emit a down signal
930 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
931 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
932 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
933 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
934 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
935 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
936 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
941 application.SendNotification();
942 application.Render();
944 // Make root actor insensitive
945 rootActor.SetProperty( Actor::Property::SENSITIVE, false );
947 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
948 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
949 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
950 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
951 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
952 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
956 int UtcDaliTouchDataMultipleLayers(void)
958 TestApplication application;
959 Actor rootActor( application.GetScene().GetRootLayer() );
961 // Connect to actor's touched signal
963 TouchDataFunctor functor( data );
965 Layer layer1 ( Layer::New() );
966 layer1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
967 layer1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
968 application.GetScene().Add( layer1 );
970 Actor actor1 ( Actor::New() );
971 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
972 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
973 actor1.SetProperty( Actor::Property::POSITION_Z, 1.0f ); // Should hit actor1 in this layer
974 layer1.Add( actor1 );
977 application.SendNotification();
978 application.Render();
980 // Connect to layer1 and actor1
981 layer1.TouchSignal().Connect( &application, functor );
982 actor1.TouchSignal().Connect( &application, functor );
984 // Hit in hittable area, actor1 should be hit
985 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
986 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
987 DALI_TEST_CHECK( data.touchedActor == actor1 );
990 // Make layer1 insensitive, nothing should be hit
991 layer1.SetProperty( Actor::Property::SENSITIVE, false );
992 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
993 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
996 // Make layer1 sensitive again, again actor1 will be hit
997 layer1.SetProperty( Actor::Property::SENSITIVE, true );
998 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
999 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1000 DALI_TEST_CHECK( data.touchedActor == actor1 );
1003 // Make rootActor insensitive, nothing should be hit
1004 rootActor.SetProperty( Actor::Property::SENSITIVE, false );
1005 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1006 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1009 // Make rootActor sensitive
1010 rootActor.SetProperty( Actor::Property::SENSITIVE, true );
1012 // Add another layer
1013 Layer layer2 ( Layer::New() );
1014 layer2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1015 layer2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1016 layer2.SetProperty( Actor::Property::POSITION_Z, 10.0f ); // Should hit layer2 in this layer rather than actor2
1017 application.GetScene().Add( layer2 );
1019 Actor actor2 ( Actor::New() );
1020 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1021 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1022 layer2.Add( actor2 );
1024 // Render and notify
1025 application.SendNotification();
1026 application.Render();
1028 // Connect to layer2 and actor2
1029 layer2.TouchSignal().Connect( &application, functor );
1030 actor2.TouchSignal().Connect( &application, functor );
1032 // Emit an event, should hit layer2
1033 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1034 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1035 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1038 // Make layer2 insensitive, should hit actor1
1039 layer2.SetProperty( Actor::Property::SENSITIVE, false );
1040 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1041 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1042 DALI_TEST_CHECK( data.touchedActor == actor1 );
1045 // Make layer2 sensitive again, should hit layer2
1046 layer2.SetProperty( Actor::Property::SENSITIVE, true );
1047 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1048 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1049 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1052 // Make layer2 invisible, render and notify
1053 layer2.SetProperty( Actor::Property::VISIBLE, false );
1054 application.SendNotification();
1055 application.Render();
1057 // Should hit actor1
1058 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1059 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1060 DALI_TEST_CHECK( data.touchedActor == actor1 );
1063 // Make rootActor invisible, render and notify
1064 rootActor.SetProperty( Actor::Property::VISIBLE, false );
1065 application.SendNotification();
1066 application.Render();
1068 // Should not hit anything
1069 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1070 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1075 int UtcDaliTouchDataMultipleRenderTasks(void)
1077 TestApplication application;
1078 Integration::Scene scene ( application.GetScene() );
1079 Vector2 sceneSize ( scene.GetSize() );
1081 Actor actor = Actor::New();
1082 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1083 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1086 // Create render task
1087 Viewport viewport( sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f );
1088 RenderTask renderTask ( application.GetScene().GetRenderTaskList().CreateTask() );
1089 renderTask.SetViewport( viewport );
1090 renderTask.SetInputEnabled( true );
1092 // Render and notify
1093 application.SendNotification();
1094 application.Render();
1096 // Connect to actor's touched signal
1098 TouchDataFunctor functor( data );
1099 actor.TouchSignal().Connect( &application, functor );
1101 // Emit a down signal
1102 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1103 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1106 // Ensure renderTask actor can be hit too.
1107 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1108 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1111 // Disable input on renderTask, should not be hittable
1112 renderTask.SetInputEnabled( false );
1113 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1114 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1119 int UtcDaliTouchDataMultipleRenderTasksWithChildLayer(void)
1121 TestApplication application;
1122 Integration::Scene scene ( application.GetScene() );
1123 Vector2 sceneSize ( scene.GetSize() );
1125 Actor actor = Actor::New();
1126 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1127 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1130 Layer layer = Layer::New();
1131 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1132 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1135 // Create render task
1136 Viewport viewport( sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f );
1137 RenderTask renderTask ( application.GetScene().GetRenderTaskList().CreateTask() );
1138 renderTask.SetViewport( viewport );
1139 renderTask.SetInputEnabled( true );
1140 renderTask.SetSourceActor( actor );
1142 // Render and notify
1143 application.SendNotification();
1144 application.Render();
1146 // Connect to layer's touched signal
1148 TouchDataFunctor functor( data );
1149 actor.TouchSignal().Connect( &application, functor );
1150 layer.TouchSignal().Connect( &application, functor );
1152 // Emit a down signal
1153 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1154 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1157 // Ensure renderTask actor can be hit too.
1158 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1159 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1162 // Disable input on renderTask, should not be hittable
1163 renderTask.SetInputEnabled( false );
1164 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1165 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1170 int UtcDaliTouchDataOffscreenRenderTasks(void)
1172 TestApplication application;
1173 Integration::Scene scene ( application.GetScene() );
1174 Vector2 sceneSize ( scene.GetSize() );
1176 // FrameBufferImage for offscreen RenderTask
1177 FrameBuffer frameBuffer = FrameBuffer::New(sceneSize.width, sceneSize.height);
1179 // Create a renderable actor to display the FrameBufferImage
1180 Actor renderableActor = CreateRenderableActor(frameBuffer.GetColorTexture());
1181 renderableActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1182 renderableActor.SetProperty( Actor::Property::SIZE, Vector2( sceneSize.x, sceneSize.y ) );
1183 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
1184 scene.Add( renderableActor );
1186 Actor actor = Actor::New();
1187 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1188 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1190 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
1192 scene.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
1194 // Create a RenderTask
1195 RenderTask renderTask = scene.GetRenderTaskList().CreateTask();
1196 renderTask.SetSourceActor( actor );
1197 renderTask.SetFrameBuffer(frameBuffer);
1198 renderTask.SetInputEnabled( true );
1200 // Create another RenderTask
1201 RenderTask renderTask2( scene.GetRenderTaskList().CreateTask() );
1202 renderTask2.SetInputEnabled( true );
1204 // Render and notify
1205 application.SendNotification();
1206 application.Render();
1208 // Connect to actor's touched signal
1210 TouchDataFunctor functor( data );
1211 actor.TouchSignal().Connect( &application, functor );
1213 // Emit a down signal
1214 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1215 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1220 int UtcDaliTouchDataMultipleRenderableActors(void)
1222 TestApplication application;
1223 Integration::Scene scene ( application.GetScene() );
1224 Vector2 sceneSize ( scene.GetSize() );
1226 Actor parent = CreateRenderableActor();
1227 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1228 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1231 Actor actor = CreateRenderableActor();
1232 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1233 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1236 // Render and notify
1237 application.SendNotification();
1238 application.Render();
1240 // Connect to layer's touched signal
1242 TouchDataFunctor functor( data );
1243 parent.TouchSignal().Connect( &application, functor );
1244 actor.TouchSignal().Connect( &application, functor );
1246 // Emit a down signal
1247 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1248 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1249 DALI_TEST_CHECK( actor == data.touchedActor );
1253 int UtcDaliTouchDataActorRemovedInSignal(void)
1255 TestApplication application;
1257 Actor actor = Actor::New();
1258 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1259 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1260 application.GetScene().Add(actor);
1262 // Render and notify
1263 application.SendNotification();
1264 application.Render();
1266 // Connect to actor's touched signal
1268 RemoveActorFunctor functor( data );
1269 actor.TouchSignal().Connect( &application, functor );
1271 // Register for leave events
1272 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
1274 // Emit a down signal
1275 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1276 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1279 // Re-add, render and notify
1280 application.GetScene().Add(actor);
1281 application.SendNotification();
1282 application.Render();
1284 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1285 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1286 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1289 // Emit a down signal
1290 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1291 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1294 // Render and notify
1295 application.SendNotification();
1296 application.Render();
1298 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1299 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1300 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1303 // Re-add actor back to scene, render and notify
1304 application.GetScene().Add(actor);
1305 application.SendNotification();
1306 application.Render();
1308 // Emit another down event
1309 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1310 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1313 // Completely delete the actor
1316 // Emit event, should not crash and should not receive an event.
1317 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1318 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1322 int UtcDaliTouchDataActorSignalNotConsumed(void)
1324 TestApplication application;
1326 Actor actor = Actor::New();
1327 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1328 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1329 application.GetScene().Add(actor);
1331 // Render and notify
1332 application.SendNotification();
1333 application.Render();
1335 // Connect to actor's touched signal
1337 TouchDataFunctor functor( data, false );
1338 actor.TouchSignal().Connect( &application, functor );
1340 // Emit a down signal
1341 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1342 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1346 int UtcDaliTouchDataActorRemovedFromScene(void)
1348 TestApplication application;
1350 Actor actor = Actor::New();
1351 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1352 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1353 application.GetScene().Add(actor);
1355 // Render and notify
1356 application.SendNotification();
1357 application.Render();
1359 // Connect to actor's touched signal
1361 TouchDataFunctor functor( data );
1362 actor.TouchSignal().Connect( &application, functor );
1364 // Emit a down signal
1365 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1366 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1369 // Remove actor from scene
1370 application.GetScene().Remove( actor );
1373 // Render and notify
1374 application.SendNotification();
1375 application.Render();
1377 // Emit a move at the same point, we should not be signalled.
1378 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 10.0f, 10.0f ) ) );
1379 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1384 int UtcDaliTouchDataLayerConsumesTouch(void)
1386 TestApplication application;
1388 Actor actor = Actor::New();
1389 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1390 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1391 application.GetScene().Add(actor);
1393 // Render and notify
1394 application.SendNotification();
1395 application.Render();
1397 // Connect to actor's touched signal
1399 TouchDataFunctor functor( data );
1400 actor.TouchSignal().Connect( &application, functor );
1402 // Add a layer to overlap the actor
1403 Layer layer = Layer::New();
1404 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1405 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1406 application.GetScene().Add( layer );
1409 // Render and notify
1410 application.SendNotification();
1411 application.Render();
1413 // Emit a few touch signals
1414 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1415 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 10.0f, 10.0f ) ) );
1416 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1419 // Set layer to consume all touch
1420 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1422 // Render and notify
1423 application.SendNotification();
1424 application.Render();
1426 // Emit the same signals again, should not receive
1427 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1428 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 10.0f, 10.0f ) ) );
1429 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1435 int UtcDaliTouchDataLeaveActorReadded(void)
1437 TestApplication application;
1438 Integration::Scene scene = application.GetScene();
1440 Actor actor = Actor::New();
1441 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1442 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1445 // Set actor to receive touch-events
1446 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
1448 // Render and notify
1449 application.SendNotification();
1450 application.Render();
1452 // Connect to actor's touched signal
1454 TouchDataFunctor functor( data );
1455 actor.TouchSignal().Connect( &application, functor );
1457 // Emit a down and motion
1458 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1459 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 11.0f, 10.0f ) ) );
1460 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1463 // Remove actor from scene and add again
1464 scene.Remove( actor );
1467 // Emit a motion within the actor's bounds
1468 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 12.0f, 10.0f ) ) );
1469 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1472 // Emit a motion outside the actor's bounds
1473 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 200.0f, 200.0f ) ) );
1474 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1475 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
1481 int UtcDaliTouchDataClippedActor(void)
1483 TestApplication application;
1484 Integration::Scene scene = application.GetScene();
1486 Actor actor = Actor::New();
1487 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1488 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1491 Actor clippingActor = Actor::New();
1492 clippingActor.SetProperty( Actor::Property::SIZE, Vector2( 50.0f, 50.0f ) );
1493 clippingActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1494 clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1495 scene.Add( clippingActor );
1497 // Add a child to the clipped region.
1498 Actor clippingChild = Actor::New();
1499 clippingChild.SetProperty( Actor::Property::SIZE, Vector2( 50.0f, 50.0f ) );
1500 clippingChild.SetProperty( Actor::Property::POSITION, Vector2( 25.0f, 25.0f ));
1501 clippingChild.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1502 clippingActor.Add( clippingChild );
1504 // Render and notify.
1505 application.SendNotification();
1506 application.Render();
1508 // Connect to actor's touch signal.
1510 TouchDataFunctor functor( data );
1511 actor.TouchSignal().Connect( &application, functor );
1513 // Emit an event within clipped area - no hit.
1514 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1515 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1518 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1519 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 60.0f, 60.0f ) ) );
1520 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1523 clippingChild.TouchSignal().Connect( &application, functor );
1525 // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1526 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 30.0f, 30.0f ) ) );
1527 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1533 int UtcDaliTouchDataActorUnparented(void)
1535 TestApplication application;
1537 Actor actor = Actor::New();
1538 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1539 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1540 application.GetScene().Add(actor);
1542 // Render and notify
1543 application.SendNotification();
1544 application.Render();
1546 // Connect to actor's touched signal
1548 TouchDataFunctor functor( data );
1549 actor.TouchSignal().Connect( &application, functor );
1551 // Emit a down signal
1552 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1553 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1554 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1555 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1558 // Render and notify
1559 application.SendNotification();
1560 application.Render();
1562 // Unparent the actor
1565 // Should receive an interrupted event
1566 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1567 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1571 int UtcDaliTouchDataParentRemovedFromScene(void)
1573 TestApplication application;
1575 Actor parent = Actor::New();
1576 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1577 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1578 application.GetScene().Add(parent);
1580 Actor actor = Actor::New();
1581 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1582 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1585 // Render and notify
1586 application.SendNotification();
1587 application.Render();
1589 // Connect to actor's touched signal
1591 TouchDataFunctor functor( data );
1592 actor.TouchSignal().Connect( &application, functor );
1594 // Emit a down signal
1595 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1596 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1597 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1598 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1601 // Render and notify
1602 application.SendNotification();
1603 application.Render();
1605 // Unparent the parent of the touchable actor
1608 // Should receive an interrupted event
1609 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1610 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1614 int UtcDaliTouchDataActorRemovedFromSceneDifferentConsumer(void)
1616 TestApplication application;
1618 Actor parent = Actor::New();
1619 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1620 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1621 application.GetScene().Add(parent);
1623 Actor actor = Actor::New();
1624 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1625 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1628 // Render and notify
1629 application.SendNotification();
1630 application.Render();
1632 // Connect to actor's touched signal
1634 TouchDataFunctor functor( data, false /* Do not consume */ );
1635 actor.TouchSignal().Connect( &application, functor );
1637 // Connect to parent's touched signal
1638 SignalData parentData;
1639 TouchDataFunctor parentFunctor( parentData );
1640 parent.TouchSignal().Connect( &application, parentFunctor );
1642 // Emit a down signal
1643 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1644 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1645 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1646 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1647 DALI_TEST_CHECK( actor == data.touchedActor );
1648 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1649 DALI_TEST_EQUALS( PointState::DOWN, parentData.touchData.points[0].state, TEST_LOCATION );
1650 DALI_TEST_CHECK( actor == parentData.touchData.points[0].hitActor );
1651 DALI_TEST_CHECK( parent == parentData.touchedActor );
1655 // Render and notify
1656 application.SendNotification();
1657 application.Render();
1659 // Unparent the actor
1662 // Should receive an interrupted event for both actor & parent
1663 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1664 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1665 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1666 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1670 // Readd actor to parent
1673 // Render and notify
1674 application.SendNotification();
1675 application.Render();
1677 // Emit a motion signal
1678 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 10.0f, 10.0f ) ) );
1679 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1680 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1684 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1685 SignalData secondData;
1686 TouchDataFunctor secondFunctor( secondData /* Consume */ );
1687 actor.TouchSignal().Connect( &application, secondFunctor );
1689 // Unparent the actor
1692 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1693 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1694 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1695 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1696 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1697 DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1698 DALI_TEST_EQUALS( PointState::INTERRUPTED, secondData.touchData.points[0].state, TEST_LOCATION );
1706 int UtcDaliTouchDataInterruptedDifferentConsumer(void)
1708 TestApplication application;
1709 Actor rootActor( application.GetScene().GetRootLayer() );
1711 Actor parent = Actor::New();
1712 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1713 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1714 application.GetScene().Add(parent);
1716 Actor actor = Actor::New();
1717 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1718 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1721 // Render and notify
1722 application.SendNotification();
1723 application.Render();
1725 // Connect to actor's touched signal
1727 TouchDataFunctor functor( data, false /* Do not consume */ );
1728 actor.TouchSignal().Connect( &application, functor );
1730 // Connect to parent's touched signal
1731 SignalData parentData;
1732 TouchDataFunctor parentFunctor( parentData, false /* Do not consume */ );
1733 parent.TouchSignal().Connect( &application, parentFunctor );
1735 // Connect to root's touched signal and consume
1736 SignalData rootData;
1737 TouchDataFunctor rootFunctor( rootData );
1738 rootActor.TouchSignal().Connect( &application, rootFunctor );
1740 // Emit a down signal
1741 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1742 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1743 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1744 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1745 DALI_TEST_CHECK( actor == data.touchedActor );
1746 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1747 DALI_TEST_EQUALS( PointState::DOWN, parentData.touchData.points[0].state, TEST_LOCATION );
1748 DALI_TEST_CHECK( actor == parentData.touchData.points[0].hitActor );
1749 DALI_TEST_CHECK( parent == parentData.touchedActor );
1750 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1751 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
1752 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
1753 DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1758 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1759 SignalData secondData;
1760 TouchDataFunctor secondFunctor( secondData /* Consume */ );
1761 parent.TouchSignal().Connect( &application, secondFunctor );
1763 // Emit an interrupted signal, all three should STILL be called
1764 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) ) );
1765 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1766 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1767 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1768 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1769 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1770 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
1778 int UtcDaliTouchDataGetRadius(void)
1780 TestApplication application;
1782 Actor actor = Actor::New();
1783 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1784 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1785 application.GetScene().Add(actor);
1787 // Render and notify
1788 application.SendNotification();
1789 application.Render();
1791 // Connect to actor's touched signal
1793 TouchDataFunctor functor( data );
1794 actor.TouchSignal().Connect( &application, functor );
1796 // Emit a down signal with an angle
1797 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1798 touchEvent.points[ 0 ].SetRadius( 100.0f );
1799 application.ProcessEvent( touchEvent );
1800 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1801 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1802 DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].radius, TEST_LOCATION );
1803 DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].ellipseRadius.x, TEST_LOCATION );
1804 DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].ellipseRadius.y, TEST_LOCATION );
1809 int UtcDaliTouchDataGetEllipseRadius(void)
1811 TestApplication application;
1813 Actor actor = Actor::New();
1814 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1815 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1816 application.GetScene().Add(actor);
1818 // Render and notify
1819 application.SendNotification();
1820 application.Render();
1822 // Connect to actor's touched signal
1824 TouchDataFunctor functor( data );
1825 actor.TouchSignal().Connect( &application, functor );
1827 // Emit a down signal with an angle
1828 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1829 touchEvent.points[ 0 ].SetRadius( 100.0f, Vector2( 20.0f, 10.0f ) );
1830 application.ProcessEvent( touchEvent );
1831 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1832 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1833 DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].radius, TEST_LOCATION );
1834 DALI_TEST_EQUALS( 20.0f, data.touchData.points[0].ellipseRadius.x, TEST_LOCATION );
1835 DALI_TEST_EQUALS( 10.0f, data.touchData.points[0].ellipseRadius.y, TEST_LOCATION );
1840 int UtcDaliTouchDataGetAngle(void)
1842 TestApplication application;
1844 Actor actor = Actor::New();
1845 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1846 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1847 application.GetScene().Add(actor);
1849 // Render and notify
1850 application.SendNotification();
1851 application.Render();
1853 // Connect to actor's touched signal
1855 TouchDataFunctor functor( data );
1856 actor.TouchSignal().Connect( &application, functor );
1858 // Emit a down signal with an angle
1859 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1860 touchEvent.points[ 0 ].SetAngle( Degree( 90.0f ) );
1861 application.ProcessEvent( touchEvent );
1862 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1863 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1864 DALI_TEST_EQUALS( Degree( 90.0f ), data.touchData.points[0].angle, TEST_LOCATION );
1869 int UtcDaliTouchDataGetPressure(void)
1871 TestApplication application;
1873 Actor actor = Actor::New();
1874 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1875 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1876 application.GetScene().Add(actor);
1878 // Render and notify
1879 application.SendNotification();
1880 application.Render();
1882 // Connect to actor's touched signal
1884 TouchDataFunctor functor( data );
1885 actor.TouchSignal().Connect( &application, functor );
1887 // Emit a down signal with an angle
1888 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1889 touchEvent.points[ 0 ].SetPressure( 10.0f );
1890 application.ProcessEvent( touchEvent );
1891 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1892 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1893 DALI_TEST_EQUALS( 10.0f, data.touchData.points[0].pressure, TEST_LOCATION );
1898 int UtcDaliTouchDataUsage(void)
1900 TestApplication application;
1902 Actor actor = Actor::New();
1903 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1904 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1905 application.GetScene().Add(actor);
1907 // Render and notify
1908 application.SendNotification();
1909 application.Render();
1911 // Connect to actor's touched signal
1913 TouchDataFunctor functor( data );
1914 actor.TouchSignal().Connect( &application, functor );
1917 // Emit a down signal with an angle
1918 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1919 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1925 int UtcDaliTouchDataGetDeviceAPINegative(void)
1927 TestApplication application;
1929 Actor actor = Actor::New();
1930 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1931 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1932 application.GetScene().Add(actor);
1934 // Render and notify
1935 application.SendNotification();
1936 application.Render();
1938 // Connect to actor's touched signal
1939 HandleData handleData;
1940 TouchDataHandleFunctor functor( handleData );
1941 actor.TouchSignal().Connect( &application, functor );
1943 Vector2 screenCoordinates( 10.0f, 10.0f );
1944 Vector2 localCoordinates;
1945 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
1947 // Emit a down signal
1948 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
1950 TouchData data = handleData.touchData;
1951 DALI_TEST_EQUALS( data.GetDeviceClass( -1 ), Device::Class::NONE, TEST_LOCATION );
1952 DALI_TEST_EQUALS( data.GetDeviceSubclass( -1 ), Device::Subclass::NONE, TEST_LOCATION );
1956 int UtcDaliTouchDataGetMouseButtonPositive(void)
1958 TestApplication application;
1960 Actor actor = Actor::New();
1961 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1962 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1963 application.GetScene().Add(actor);
1965 // Render and notify
1966 application.SendNotification();
1967 application.Render();
1969 // Connect to actor's touched signal
1970 HandleData handleData;
1971 TouchDataHandleFunctor functor( handleData );
1972 actor.TouchSignal().Connect( &application, functor );
1974 // Emit a down signal with MouseButton
1975 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1976 touchEvent.points[ 0 ].SetMouseButton( static_cast< MouseButton::Type >( 3 ) );
1977 application.ProcessEvent( touchEvent );
1979 TouchData data = handleData.touchData;
1980 DALI_TEST_EQUALS( data.GetMouseButton( 0 ), MouseButton::SECONDARY, TEST_LOCATION );
1985 int UtcDaliTouchDataGetMouseButtonNagative(void)
1987 TestApplication application;
1989 Actor actor = Actor::New();
1990 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1991 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1992 application.GetScene().Add(actor);
1994 // Render and notify
1995 application.SendNotification();
1996 application.Render();
1998 // Connect to actor's touched signal
1999 HandleData handleData;
2000 TouchDataHandleFunctor functor( handleData );
2001 actor.TouchSignal().Connect( &application, functor );
2003 // Emit a down signal with MouseButton
2004 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
2005 touchEvent.points[ 0 ].SetMouseButton( static_cast< MouseButton::Type >( 2 ) );
2006 application.ProcessEvent( touchEvent );
2008 TouchData data = handleData.touchData;
2009 DALI_TEST_EQUALS( data.GetMouseButton( 0 ), MouseButton::TERTIARY, TEST_LOCATION );
2010 DALI_TEST_EQUALS( data.GetMouseButton( 3 ), MouseButton::INVALID, TEST_LOCATION );
2015 int UtcDaliTouchDataCapturePropertySet(void)
2017 TestApplication application;
2019 Actor actor = Actor::New();
2020 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2021 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2022 application.GetScene().Add(actor);
2024 // Render and notify
2025 application.SendNotification();
2026 application.Render();
2028 // Connect to actor's touched signal
2030 TouchDataFunctor functor( data );
2031 actor.TouchSignal().Connect( &application, functor );
2033 // Emit a down signal
2034 application.ProcessEvent( GenerateSingleTouch( PointState::STARTED, Vector2( 10.0f, 10.0f ) ) );
2035 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2038 // Now motion outside of actor, we should not receive the event
2039 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 110.0f, 110.0f ) ) );
2040 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
2043 // Up event, should receive an interrupted
2044 application.ProcessEvent( GenerateSingleTouch( PointState::FINISHED, Vector2( 110.0f, 110.0f ) ) );
2045 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2046 DALI_TEST_EQUALS( data.touchData.GetPoint(0).state, PointState::INTERRUPTED, TEST_LOCATION );
2048 // Now set the capture property
2049 actor.SetProperty( DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START, true);
2051 // Emit a down signal
2052 application.ProcessEvent( GenerateSingleTouch( PointState::STARTED, Vector2( 10.0f, 10.0f ) ) );
2053 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2056 // Now motion outside of actor, we now SHOULD receive the event
2057 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 110.0f, 110.0f ) ) );
2058 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2061 // Up event, we should receive it again, but as ended rather than interrupted
2062 application.ProcessEvent( GenerateSingleTouch( PointState::FINISHED, Vector2( 110.0f, 110.0f ) ) );
2063 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2064 DALI_TEST_EQUALS( data.touchData.GetPoint(0).state, PointState::FINISHED, TEST_LOCATION );
2069 int UtcDaliTouchDataIntegNewTouchData(void)
2071 uint32_t timestamp = 92858u;
2072 TouchPoint tp(1, TouchPoint::State::Started, 34.4f, 123.89f, 5.0f, 7.0f);
2073 Dali::TouchData touchData = Integration::NewTouchData(timestamp, tp);
2075 DALI_TEST_EQUALS(touchData.GetPointCount(), 1u, TEST_LOCATION);
2076 DALI_TEST_EQUALS(touchData.GetState(0), PointState::Type::STARTED, TEST_LOCATION );
2077 DALI_TEST_EQUALS(touchData.GetLocalPosition(0), Vector2(5.0f, 7.0f), TEST_LOCATION );
2078 DALI_TEST_EQUALS(touchData.GetScreenPosition(0), Vector2(34.4f, 123.89f), TEST_LOCATION );