2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali/integration-api/render-task-list-integ.h>
24 #include <dali-test-suite-utils.h>
25 #include <dali/devel-api/actors/actor-devel.h>
29 void utc_dali_touch_data_processing_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_touch_data_processing_cleanup(void)
36 test_return_value = TET_PASS;
39 ///////////////////////////////////////////////////////////////////////////////
46 PointState::Type state;
51 Vector2 ellipseRadius;
54 Device::Class::Type deviceClass;
55 Device::Subclass::Type deviceSubclass;
58 : deviceId(-1), state(PointState::FINISHED), radius(0), pressure(0)
61 static const TestPoint ZERO;
64 const TestPoint TestPoint::ZERO;
67 // Stores data that is populated in the callback and will be read by the TET cases
71 : functorCalled( false ),
80 std::vector<TestPoint> points;
82 const TestPoint& GetPoint(size_t i)
84 if( i < points.size() )
88 return TestPoint::ZERO;
90 size_t GetPointCount()
98 functorCalled = false;
101 touchData.points.clear();
103 touchedActor.Reset();
107 TestTouchData touchData;
111 // Functor that sets the data when called
112 struct TouchDataFunctor
116 * @param[in] data Reference to the data to store callback information.
117 * @param[in] returnValue What the functor should return.
119 TouchDataFunctor( SignalData& data, bool returnValue = true )
120 : signalData( data ),
121 returnValue( returnValue )
125 bool operator()( Actor actor, const TouchData& touchData )
127 signalData.functorCalled = true;
128 signalData.touchedActor = actor;
130 signalData.touchData.time = touchData.GetTime();
131 signalData.touchData.points.clear();
133 for( size_t i=0; i<touchData.GetPointCount(); ++i )
136 p.deviceId = touchData.GetDeviceId(i);
137 p.state = touchData.GetState(i);
138 p.hitActor = touchData.GetHitActor(i);
139 p.local = touchData.GetLocalPosition(i);
140 p.screen = touchData.GetScreenPosition(i);
141 p.radius = touchData.GetRadius(i);
142 p.ellipseRadius = touchData.GetEllipseRadius(i);
143 p.pressure = touchData.GetPressure(i);
144 p.angle = touchData.GetAngle(i);
145 p.deviceClass = touchData.GetDeviceClass(i);
146 p.deviceSubclass = touchData.GetDeviceSubclass(i);
147 signalData.touchData.points.push_back(p);
153 SignalData& signalData;
163 : signalReceived(false)
168 struct TouchDataHandleFunctor
172 * @param[in] data Reference to the data to store callback information.
173 * @param[in] returnValue What the functor should return.
175 TouchDataHandleFunctor( HandleData& handleData, bool returnValue = true )
176 : handleData(handleData),
177 returnValue( returnValue )
181 bool operator()( Actor actor, const TouchData& someTouchData )
183 handleData.signalReceived = true;
184 TouchData handle(someTouchData);
185 handleData.touchData = handle;
189 HandleData& handleData;
194 // Functor that removes the actor when called.
195 struct RemoveActorFunctor : public TouchDataFunctor
199 * @param[in] data Reference to the data to store callback information.
200 * @param[in] returnValue What the functor should return.
202 RemoveActorFunctor( SignalData& data, bool returnValue = true )
203 : TouchDataFunctor( data, returnValue )
207 bool operator()( Actor actor, const TouchData& touchData )
209 Actor parent( actor.GetParent() );
212 parent.Remove( actor );
215 return TouchDataFunctor::operator()( actor, touchData );
219 struct OutOfBoundsData
225 :functorCalled(false)
230 // Functor that reads out of bounds data when called
231 struct OutOfBoundsFunctor
235 * @param[in] data Reference to the data to store callback information.
236 * @param[in] returnValue What the functor should return.
238 OutOfBoundsFunctor( OutOfBoundsData& data, bool returnValue = true )
239 : outOfBoundsData ( data ),
240 returnValue( returnValue )
244 bool operator()( Actor actor, const TouchData& touchData )
246 outOfBoundsData.functorCalled = true;
247 size_t count = touchData.GetPointCount();
249 // Read out of bounds data
250 outOfBoundsData.point.deviceId = touchData.GetDeviceId(count+1);
251 outOfBoundsData.point.state = touchData.GetState(count+1);
252 outOfBoundsData.point.hitActor = touchData.GetHitActor(count+1);
253 outOfBoundsData.point.local = touchData.GetLocalPosition(count+1);
254 outOfBoundsData.point.screen = touchData.GetScreenPosition(count+1);
259 OutOfBoundsData& outOfBoundsData;
263 struct TouchEventFunctor
267 * @param[in] functorCalled Reference to a boolean which is set to true if the touch event functor is called.
269 TouchEventFunctor( bool& functorCalled )
270 : functorCalled( functorCalled )
274 bool operator()( Actor actor, const TouchEvent& touch )
276 functorCalled = true;
283 Integration::TouchEvent GenerateSingleTouch( PointState::Type state, const Vector2& screenPosition )
285 Integration::TouchEvent touchEvent;
286 Integration::Point point;
287 point.SetState( state );
288 point.SetScreenPosition( screenPosition );
289 point.SetDeviceClass( Device::Class::TOUCH );
290 point.SetDeviceSubclass( Device::Subclass::NONE );
291 touchEvent.points.push_back( point );
297 ///////////////////////////////////////////////////////////////////////////////
299 int UtcDaliTouchDataNormalProcessing01(void)
301 TestApplication application;
303 Actor actor = Actor::New();
304 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
305 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
306 application.GetScene().Add(actor);
309 application.SendNotification();
310 application.Render();
312 // Connect to actor's touched signal
314 TouchDataFunctor functor( data );
315 actor.TouchSignal().Connect( &application, functor );
317 Vector2 screenCoordinates( 10.0f, 10.0f );
318 Vector2 localCoordinates;
319 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
321 // Emit a down signal
322 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
323 const TestPoint *point1 = &data.touchData.GetPoint(0);
324 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
325 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
326 DALI_TEST_EQUALS( PointState::DOWN, point1->state, TEST_LOCATION );
327 DALI_TEST_EQUALS( screenCoordinates, point1->screen, TEST_LOCATION );
328 DALI_TEST_EQUALS( localCoordinates, point1->local, 0.1f, TEST_LOCATION );
331 // Emit a motion signal
332 screenCoordinates.x = screenCoordinates.y = 11.0f;
333 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
334 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, screenCoordinates ) );
335 const TestPoint *point2 = &data.touchData.GetPoint(0);
336 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
337 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
338 DALI_TEST_EQUALS( PointState::MOTION, point2->state, TEST_LOCATION );
339 DALI_TEST_EQUALS( screenCoordinates, point2->screen, TEST_LOCATION );
340 DALI_TEST_EQUALS( localCoordinates, point2->local, 0.1f, TEST_LOCATION );
344 screenCoordinates.x = screenCoordinates.y = 12.0f;
345 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
346 application.ProcessEvent( GenerateSingleTouch( PointState::UP, screenCoordinates ) );
347 const TestPoint *point3 = &data.touchData.GetPoint(0);
348 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
349 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
350 DALI_TEST_EQUALS( PointState::UP, point3->state, TEST_LOCATION );
351 DALI_TEST_EQUALS( screenCoordinates, point3->screen, TEST_LOCATION );
352 DALI_TEST_EQUALS( localCoordinates, point3->local, 0.1f, TEST_LOCATION );
355 // Emit a down signal where the actor is not present
356 screenCoordinates.x = screenCoordinates.y = 200.0f;
357 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
358 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
363 int UtcDaliTouchDataNormalProcessing02(void)
365 TestApplication application;
367 Actor actor = Actor::New();
368 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
369 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
370 application.GetScene().Add(actor);
373 application.SendNotification();
374 application.Render();
376 // Connect to actor's touched signal
377 HandleData handleData;
378 TouchDataHandleFunctor functor( handleData );
379 actor.TouchSignal().Connect( &application, functor );
381 Vector2 screenCoordinates( 10.0f, 10.0f );
382 Vector2 localCoordinates;
383 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
385 // Emit a down signal
386 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
387 DALI_TEST_EQUALS( true, handleData.signalReceived, TEST_LOCATION );
388 DALI_TEST_EQUALS( 1u, handleData.touchData.GetPointCount(), TEST_LOCATION );
389 DALI_TEST_EQUALS( PointState::DOWN, handleData.touchData.GetState(0), TEST_LOCATION );
390 DALI_TEST_EQUALS( screenCoordinates, handleData.touchData.GetScreenPosition(0), TEST_LOCATION );
391 DALI_TEST_EQUALS( localCoordinates, handleData.touchData.GetLocalPosition(0), 0.1f, TEST_LOCATION );
397 int UtcDaliTouchDataAPINegative(void)
399 TestApplication application;
401 Actor actor = Actor::New();
402 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
403 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
404 application.GetScene().Add(actor);
407 application.SendNotification();
408 application.Render();
410 // Connect to actor's touched signal
411 OutOfBoundsData data;
412 OutOfBoundsFunctor functor( data, true );
413 actor.TouchSignal().Connect( &application, functor );
415 Vector2 screenCoordinates( 10.0f, 10.0f );
416 Vector2 localCoordinates;
417 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
419 // Emit a down signal
420 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
422 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
423 DALI_TEST_EQUALS( -1, data.point.deviceId, TEST_LOCATION );
424 DALI_TEST_EQUALS( PointState::FINISHED, data.point.state, TEST_LOCATION );
425 DALI_TEST_EQUALS( Vector2::ZERO, data.point.screen, TEST_LOCATION );
426 DALI_TEST_EQUALS( Vector2::ZERO, data.point.local, 0.1f, TEST_LOCATION );
427 DALI_TEST_CHECK( ! data.point.hitActor );
433 int UtcDaliTouchDataOutsideCameraNearFarPlanes(void)
435 TestApplication application;
437 Integration::Scene scene = application.GetScene();
438 Vector2 sceneSize = scene.GetSize();
440 Actor actor = Actor::New();
441 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
442 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::CENTER);
443 actor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
447 application.SendNotification();
448 application.Render();
450 // Get the camera's near and far planes
451 RenderTaskList taskList = scene.GetRenderTaskList();
452 Dali::RenderTask task = taskList.GetTask(0);
453 CameraActor camera = task.GetCameraActor();
454 float nearPlane = camera.GetNearClippingPlane();
455 float farPlane = camera.GetFarClippingPlane();
457 // Calculate the current distance of the actor from the camera
458 float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
459 float distance = (sceneSize.y * 0.5f) / tanHalfFov;
461 // Connect to actor's touched signal
463 TouchDataFunctor functor( data );
464 actor.TouchSignal().Connect( &application, functor );
466 Vector2 screenCoordinates( sceneSize.x * 0.5f, sceneSize.y * 0.5f );
468 // Emit a down signal
469 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
470 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
473 // Emit a down signal where actor is just at the camera's near plane
474 actor.SetProperty( Actor::Property::POSITION_Z, distance - nearPlane);
477 application.SendNotification();
478 application.Render();
480 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
481 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
484 // Emit a down signal where actor is closer than the camera's near plane
485 actor.SetProperty( Actor::Property::POSITION_Z, (distance - nearPlane) + 1.0f);
488 application.SendNotification();
489 application.Render();
491 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
492 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
495 // Emit a down signal where actor is just at the camera's far plane
496 actor.SetProperty( Actor::Property::POSITION_Z, distance - farPlane);
499 application.SendNotification();
500 application.Render();
502 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
503 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
506 // Emit a down signal where actor is further than the camera's far plane
507 actor.SetProperty( Actor::Property::POSITION_Z, (distance - farPlane) - 1.0f);
510 application.SendNotification();
511 application.Render();
513 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
514 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
519 int UtcDaliTouchDataEmitEmpty(void)
521 TestApplication application;
525 // Emit an empty TouchEvent
526 Integration::TouchEvent event;
527 application.ProcessEvent( event );
528 tet_result( TET_FAIL );
530 catch ( Dali::DaliException& e )
532 DALI_TEST_ASSERT( e, "!event.points.empty()", TEST_LOCATION );
537 int UtcDaliTouchDataInterrupted(void)
539 TestApplication application;
541 Actor actor = Actor::New();
542 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
543 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
544 application.GetScene().Add(actor);
547 application.SendNotification();
548 application.Render();
550 // Connect to actor's touched signal
552 TouchDataFunctor functor( data );
553 actor.TouchSignal().Connect( &application, functor );
555 // Emit a down signal
556 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
557 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
558 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
561 // Emit an interrupted signal, we should be signalled regardless of whether there is a hit or not.
562 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
563 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
564 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
567 // Emit another interrupted signal, our signal handler should not be called.
568 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
569 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
573 int UtcDaliTouchDataParentConsumer(void)
575 TestApplication application;
576 Actor rootActor( application.GetScene().GetRootLayer() );
578 Actor actor = Actor::New();
579 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
580 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
581 application.GetScene().Add(actor);
584 application.SendNotification();
585 application.Render();
587 // Connect to actor's touched signal
589 TouchDataFunctor functor( data, false );
590 actor.TouchSignal().Connect( &application, functor );
592 // Connect to root actor's touched signal
594 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
595 rootActor.TouchSignal().Connect( &application, rootFunctor );
597 Vector2 screenCoordinates( 10.0f, 10.0f );
598 Vector2 actorCoordinates, rootCoordinates;
599 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
600 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
602 // Emit a down signal
603 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
604 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
605 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
606 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
607 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
608 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
609 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
610 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
611 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
612 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
613 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
614 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
615 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
619 // Emit a motion signal
620 screenCoordinates.x = screenCoordinates.y = 11.0f;
621 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
622 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
623 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, screenCoordinates ) );
624 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
625 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
626 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
627 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
628 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
629 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
630 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
631 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
632 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
633 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
634 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
635 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
640 screenCoordinates.x = screenCoordinates.y = 12.0f;
641 actor.ScreenToLocal( actorCoordinates.x, actorCoordinates.y, screenCoordinates.x, screenCoordinates.y );
642 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
643 application.ProcessEvent( GenerateSingleTouch( PointState::UP, screenCoordinates ) );
644 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
645 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
646 DALI_TEST_EQUALS( 1u, data.touchData.GetPointCount(), TEST_LOCATION );
647 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
648 DALI_TEST_EQUALS( PointState::UP, data.touchData.points[0].state, TEST_LOCATION );
649 DALI_TEST_EQUALS( PointState::UP, rootData.touchData.points[0].state, TEST_LOCATION );
650 DALI_TEST_EQUALS( screenCoordinates, data.touchData.points[0].screen, TEST_LOCATION );
651 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
652 DALI_TEST_EQUALS( actorCoordinates, data.touchData.points[0].local, 0.1f, TEST_LOCATION );
653 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
654 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
655 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
659 // Emit a down signal where the actor is not present, will hit the root actor though
660 screenCoordinates.x = screenCoordinates.y = 200.0f;
661 rootActor.ScreenToLocal( rootCoordinates.x, rootCoordinates.y, screenCoordinates.x, screenCoordinates.y );
662 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
663 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
664 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
665 DALI_TEST_EQUALS( 1u, rootData.touchData.GetPointCount(), TEST_LOCATION );
666 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
667 DALI_TEST_EQUALS( screenCoordinates, rootData.touchData.points[0].screen, TEST_LOCATION );
668 DALI_TEST_EQUALS( rootCoordinates, rootData.touchData.points[0].local, 0.1f, TEST_LOCATION );
669 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
673 int UtcDaliTouchDataInterruptedParentConsumer(void)
675 TestApplication application;
676 Actor rootActor( application.GetScene().GetRootLayer() );
678 Actor actor = Actor::New();
679 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
680 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
681 application.GetScene().Add(actor);
684 application.SendNotification();
685 application.Render();
687 // Connect to actor's touched signal
689 TouchDataFunctor functor( data, false );
690 actor.TouchSignal().Connect( &application, functor );
692 // Connect to root actor's touched signal
694 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
695 rootActor.TouchSignal().Connect( &application, rootFunctor );
697 // Emit a down signal
698 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
699 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
700 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
701 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
702 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
703 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
704 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
708 // Emit an interrupted signal
709 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
710 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
711 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
712 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
713 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
714 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
715 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
719 // Emit another down signal
720 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
721 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
722 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
723 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
724 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
728 // Remove actor from scene
729 application.GetScene().Remove( actor );
734 application.SendNotification();
735 application.Render();
737 // Emit an interrupted signal, only root actor's signal should be called.
738 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f /* Outside actor */ ) ) );
739 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
740 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
741 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
742 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
746 // Emit another interrupted state, none of the signal's should be called.
747 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 200.0f, 200.0f ) ) );
748 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
749 DALI_TEST_EQUALS( false, rootData.functorCalled, TEST_LOCATION );
753 int UtcDaliTouchDataLeave(void)
755 TestApplication application;
757 Actor actor = Actor::New();
758 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
759 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
760 application.GetScene().Add(actor);
763 application.SendNotification();
764 application.Render();
766 // Connect to actor's touched signal
768 TouchDataFunctor functor( data );
769 actor.TouchSignal().Connect( &application, functor );
771 // Set actor to require leave events
772 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
774 // Emit a down signal
775 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
776 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
777 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
780 // Emit a motion signal outside of actor, should be signalled with a Leave
781 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
782 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
783 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
786 // Another motion outside of actor, no signalling
787 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 201.0f, 201.0f )) );
788 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
791 // Another motion event inside actor, signalled with motion
792 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 10.0f, 10.0f )) );
793 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
794 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
797 // We do not want to listen to leave events anymore
798 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, false );
800 // Another motion event outside of actor, no signalling
801 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
802 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
807 int UtcDaliTouchDataLeaveParentConsumer(void)
809 TestApplication application;
810 Actor rootActor( application.GetScene().GetRootLayer() );
812 Actor actor = Actor::New();
813 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
814 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
815 application.GetScene().Add(actor);
818 application.SendNotification();
819 application.Render();
821 // Connect to actor's touched signal
823 TouchDataFunctor functor( data, false );
824 actor.TouchSignal().Connect( &application, functor );
826 // Connect to root actor's touched signal
828 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
829 rootActor.TouchSignal().Connect( &application, rootFunctor );
831 // Set actor to require leave events
832 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
833 rootActor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
835 // Emit a down signal
836 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
837 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
838 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
839 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
840 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
841 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
842 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
846 // Emit a motion signal outside of actor, should be signalled with a Leave
847 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
848 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
849 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
850 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
851 DALI_TEST_EQUALS( PointState::LEAVE, rootData.touchData.points[0].state, TEST_LOCATION );
852 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
853 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
857 // Another motion outside of actor, only rootActor signalled
858 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 201.0f, 201.0f )) );
859 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
860 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
861 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
862 DALI_TEST_CHECK( rootActor == rootData.touchData.points[0].hitActor );
866 // Another motion event inside actor, signalled with motion
867 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 10.0f, 10.0f )) );
868 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
869 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
870 DALI_TEST_EQUALS( PointState::MOTION, data.touchData.points[0].state, TEST_LOCATION );
871 DALI_TEST_EQUALS( PointState::MOTION, rootData.touchData.points[0].state, TEST_LOCATION );
872 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
873 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
877 // We do not want to listen to leave events of actor anymore
878 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, false );
880 // Another motion event outside of root actor, only root signalled
881 Vector2 sceneSize( application.GetScene().GetSize() );
882 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( sceneSize.width + 10.0f, sceneSize.height + 10.0f )) );
883 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
884 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
885 DALI_TEST_EQUALS( PointState::LEAVE, rootData.touchData.points[0].state, TEST_LOCATION );
889 int UtcDaliTouchDataActorBecomesInsensitive(void)
891 TestApplication application;
893 Actor actor = Actor::New();
894 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
895 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
896 application.GetScene().Add(actor);
899 application.SendNotification();
900 application.Render();
902 // Connect to actor's touched signal
904 TouchDataFunctor functor( data );
905 actor.TouchSignal().Connect( &application, functor );
907 // Emit a down signal
908 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
909 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
910 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
913 // Change actor to insensitive
914 actor.SetProperty( Actor::Property::SENSITIVE, false );
916 // Emit a motion signal, signalled with an interrupted
917 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
918 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
919 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
924 int UtcDaliTouchDataActorBecomesInsensitiveParentConsumer(void)
926 TestApplication application;
927 Actor rootActor( application.GetScene().GetRootLayer() );
929 Actor actor = Actor::New();
930 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
931 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
932 application.GetScene().Add(actor);
935 application.SendNotification();
936 application.Render();
938 // Connect to actor's touched signal
940 TouchDataFunctor functor( data, false );
941 actor.TouchSignal().Connect( &application, functor );
943 // Connect to root actor's touched signal
945 TouchDataFunctor rootFunctor( rootData ); // Consumes signal
946 rootActor.TouchSignal().Connect( &application, rootFunctor );
948 // Emit a down signal
949 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
950 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
951 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
952 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
953 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
954 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
955 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
960 application.SendNotification();
961 application.Render();
963 // Make root actor insensitive
964 rootActor.SetProperty( Actor::Property::SENSITIVE, false );
966 // Emit a motion signal, signalled with an interrupted (should get interrupted even if within root actor)
967 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2 ( 200.0f, 200.0f )) );
968 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
969 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
970 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
971 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
975 int UtcDaliTouchDataMultipleLayers(void)
977 TestApplication application;
978 Actor rootActor( application.GetScene().GetRootLayer() );
980 // Connect to actor's touched signal
982 TouchDataFunctor functor( data );
984 Layer layer1 ( Layer::New() );
985 layer1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
986 layer1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
987 application.GetScene().Add( layer1 );
989 Actor actor1 ( Actor::New() );
990 actor1.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
991 actor1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
992 actor1.SetProperty( Actor::Property::POSITION_Z, 1.0f ); // Should hit actor1 in this layer
993 layer1.Add( actor1 );
996 application.SendNotification();
997 application.Render();
999 // Connect to layer1 and actor1
1000 layer1.TouchSignal().Connect( &application, functor );
1001 actor1.TouchSignal().Connect( &application, functor );
1003 // Hit in hittable area, actor1 should be hit
1004 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1005 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1006 DALI_TEST_CHECK( data.touchedActor == actor1 );
1009 // Make layer1 insensitive, nothing should be hit
1010 layer1.SetProperty( Actor::Property::SENSITIVE, false );
1011 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1012 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1015 // Make layer1 sensitive again, again actor1 will be hit
1016 layer1.SetProperty( Actor::Property::SENSITIVE, true );
1017 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1018 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1019 DALI_TEST_CHECK( data.touchedActor == actor1 );
1022 // Make rootActor insensitive, nothing should be hit
1023 rootActor.SetProperty( Actor::Property::SENSITIVE, false );
1024 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1025 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1028 // Make rootActor sensitive
1029 rootActor.SetProperty( Actor::Property::SENSITIVE, true );
1031 // Add another layer
1032 Layer layer2 ( Layer::New() );
1033 layer2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1034 layer2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1035 layer2.SetProperty( Actor::Property::POSITION_Z, 10.0f ); // Should hit layer2 in this layer rather than actor2
1036 application.GetScene().Add( layer2 );
1038 Actor actor2 ( Actor::New() );
1039 actor2.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1040 actor2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1041 layer2.Add( actor2 );
1043 // Render and notify
1044 application.SendNotification();
1045 application.Render();
1047 // Connect to layer2 and actor2
1048 layer2.TouchSignal().Connect( &application, functor );
1049 actor2.TouchSignal().Connect( &application, functor );
1051 // Emit an event, should hit layer2
1052 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1053 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1054 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1057 // Make layer2 insensitive, should hit actor1
1058 layer2.SetProperty( Actor::Property::SENSITIVE, false );
1059 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1060 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1061 DALI_TEST_CHECK( data.touchedActor == actor1 );
1064 // Make layer2 sensitive again, should hit layer2
1065 layer2.SetProperty( Actor::Property::SENSITIVE, true );
1066 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1067 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1068 //DALI_TEST_CHECK( data.touchedActor == layer2 ); // TODO: Uncomment this after removing renderable hack!
1071 // Make layer2 invisible, render and notify
1072 layer2.SetProperty( Actor::Property::VISIBLE, false );
1073 application.SendNotification();
1074 application.Render();
1076 // Should hit actor1
1077 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1078 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1079 DALI_TEST_CHECK( data.touchedActor == actor1 );
1082 // Make rootActor invisible, render and notify
1083 rootActor.SetProperty( Actor::Property::VISIBLE, false );
1084 application.SendNotification();
1085 application.Render();
1087 // Should not hit anything
1088 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1089 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1094 int UtcDaliTouchDataMultipleRenderTasks(void)
1096 TestApplication application;
1097 Integration::Scene scene ( application.GetScene() );
1098 Vector2 sceneSize ( scene.GetSize() );
1100 Actor actor = Actor::New();
1101 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1102 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1105 // Create render task
1106 Viewport viewport( sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f );
1107 RenderTask renderTask ( application.GetScene().GetRenderTaskList().CreateTask() );
1108 renderTask.SetViewport( viewport );
1109 renderTask.SetInputEnabled( true );
1111 // Render and notify
1112 application.SendNotification();
1113 application.Render();
1115 // Connect to actor's touched signal
1117 TouchDataFunctor functor( data );
1118 actor.TouchSignal().Connect( &application, functor );
1120 // Emit a down signal
1121 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1122 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1125 // Ensure renderTask actor can be hit too.
1126 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1127 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1130 // Disable input on renderTask, should not be hittable
1131 renderTask.SetInputEnabled( false );
1132 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1133 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1138 int UtcDaliTouchDataMultipleRenderTasksWithChildLayer(void)
1140 TestApplication application;
1141 Integration::Scene scene ( application.GetScene() );
1142 Vector2 sceneSize ( scene.GetSize() );
1144 Actor actor = Actor::New();
1145 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1146 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1149 Layer layer = Layer::New();
1150 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1151 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1154 // Create render task
1155 Viewport viewport( sceneSize.width * 0.5f, sceneSize.height * 0.5f, sceneSize.width * 0.5f, sceneSize.height * 0.5f );
1156 RenderTask renderTask ( application.GetScene().GetRenderTaskList().CreateTask() );
1157 renderTask.SetViewport( viewport );
1158 renderTask.SetInputEnabled( true );
1159 renderTask.SetSourceActor( actor );
1161 // Render and notify
1162 application.SendNotification();
1163 application.Render();
1165 // Connect to layer's touched signal
1167 TouchDataFunctor functor( data );
1168 actor.TouchSignal().Connect( &application, functor );
1169 layer.TouchSignal().Connect( &application, functor );
1171 // Emit a down signal
1172 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1173 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1176 // Ensure renderTask actor can be hit too.
1177 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1178 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1181 // Disable input on renderTask, should not be hittable
1182 renderTask.SetInputEnabled( false );
1183 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( viewport.x + 5.0f, viewport.y + 5.0f ) ) );
1184 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1189 int UtcDaliTouchDataOffscreenRenderTasks(void)
1191 TestApplication application;
1192 Integration::Scene scene ( application.GetScene() );
1193 Vector2 sceneSize ( scene.GetSize() );
1195 // FrameBufferImage for offscreen RenderTask
1196 FrameBuffer frameBuffer = FrameBuffer::New(sceneSize.width, sceneSize.height);
1198 // Create a renderable actor to display the FrameBufferImage
1199 Actor renderableActor = CreateRenderableActor(frameBuffer.GetColorTexture());
1200 renderableActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER);
1201 renderableActor.SetProperty( Actor::Property::SIZE, Vector2( sceneSize.x, sceneSize.y ) );
1202 renderableActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
1203 scene.Add( renderableActor );
1205 Actor actor = Actor::New();
1206 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1207 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1209 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); // Ensure framebuffer connects
1211 scene.GetRenderTaskList().GetTask( 0u ).SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
1213 // Create a RenderTask
1214 RenderTask renderTask = scene.GetRenderTaskList().CreateTask();
1215 renderTask.SetSourceActor( actor );
1216 renderTask.SetFrameBuffer(frameBuffer);
1217 renderTask.SetInputEnabled( true );
1219 // Create another RenderTask
1220 RenderTask renderTask2( scene.GetRenderTaskList().CreateTask() );
1221 renderTask2.SetInputEnabled( true );
1223 // Render and notify
1224 application.SendNotification();
1225 application.Render();
1227 // Connect to actor's touched signal
1229 TouchDataFunctor functor( data );
1230 actor.TouchSignal().Connect( &application, functor );
1232 // Emit a down signal
1233 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1234 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1239 int UtcDaliTouchDataMultipleRenderableActors(void)
1241 TestApplication application;
1242 Integration::Scene scene ( application.GetScene() );
1243 Vector2 sceneSize ( scene.GetSize() );
1245 Actor parent = CreateRenderableActor();
1246 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1247 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1250 Actor actor = CreateRenderableActor();
1251 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1252 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1255 // Render and notify
1256 application.SendNotification();
1257 application.Render();
1259 // Connect to layer's touched signal
1261 TouchDataFunctor functor( data );
1262 parent.TouchSignal().Connect( &application, functor );
1263 actor.TouchSignal().Connect( &application, functor );
1265 // Emit a down signal
1266 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1267 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1268 DALI_TEST_CHECK( actor == data.touchedActor );
1272 int UtcDaliTouchDataActorRemovedInSignal(void)
1274 TestApplication application;
1276 Actor actor = Actor::New();
1277 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1278 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1279 application.GetScene().Add(actor);
1281 // Render and notify
1282 application.SendNotification();
1283 application.Render();
1285 // Connect to actor's touched signal
1287 RemoveActorFunctor functor( data );
1288 actor.TouchSignal().Connect( &application, functor );
1290 // Register for leave events
1291 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
1293 // Emit a down signal
1294 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1295 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1298 // Re-add, render and notify
1299 application.GetScene().Add(actor);
1300 application.SendNotification();
1301 application.Render();
1303 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1304 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1305 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1308 // Emit a down signal
1309 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1310 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1313 // Render and notify
1314 application.SendNotification();
1315 application.Render();
1317 // Emit another signal outside of actor's area, should not get anything as the scene has changed.
1318 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1319 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1322 // Re-add actor back to scene, render and notify
1323 application.GetScene().Add(actor);
1324 application.SendNotification();
1325 application.Render();
1327 // Emit another down event
1328 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1329 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1332 // Completely delete the actor
1335 // Emit event, should not crash and should not receive an event.
1336 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 210.0f, 210.0f ) ) );
1337 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1341 int UtcDaliTouchDataActorSignalNotConsumed(void)
1343 TestApplication application;
1345 Actor actor = Actor::New();
1346 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1347 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1348 application.GetScene().Add(actor);
1350 // Render and notify
1351 application.SendNotification();
1352 application.Render();
1354 // Connect to actor's touched signal
1356 TouchDataFunctor functor( data, false );
1357 actor.TouchSignal().Connect( &application, functor );
1359 // Emit a down signal
1360 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1361 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1365 int UtcDaliTouchDataActorRemovedFromScene(void)
1367 TestApplication application;
1369 Actor actor = Actor::New();
1370 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1371 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1372 application.GetScene().Add(actor);
1374 // Render and notify
1375 application.SendNotification();
1376 application.Render();
1378 // Connect to actor's touched signal
1380 TouchDataFunctor functor( data );
1381 actor.TouchSignal().Connect( &application, functor );
1383 // Emit a down signal
1384 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1385 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1388 // Remove actor from scene
1389 application.GetScene().Remove( actor );
1392 // Render and notify
1393 application.SendNotification();
1394 application.Render();
1396 // Emit a move at the same point, we should not be signalled.
1397 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 10.0f, 10.0f ) ) );
1398 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1403 int UtcDaliTouchDataLayerConsumesTouch(void)
1405 TestApplication application;
1407 Actor actor = Actor::New();
1408 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1409 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1410 application.GetScene().Add(actor);
1412 // Render and notify
1413 application.SendNotification();
1414 application.Render();
1416 // Connect to actor's touched signal
1418 TouchDataFunctor functor( data );
1419 actor.TouchSignal().Connect( &application, functor );
1421 // Add a layer to overlap the actor
1422 Layer layer = Layer::New();
1423 layer.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1424 layer.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1425 application.GetScene().Add( layer );
1428 // Render and notify
1429 application.SendNotification();
1430 application.Render();
1432 // Emit a few touch signals
1433 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1434 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 10.0f, 10.0f ) ) );
1435 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1438 // Set layer to consume all touch
1439 layer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
1441 // Render and notify
1442 application.SendNotification();
1443 application.Render();
1445 // Emit the same signals again, should not receive
1446 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1447 application.ProcessEvent( GenerateSingleTouch( PointState::UP, Vector2( 10.0f, 10.0f ) ) );
1448 DALI_TEST_EQUALS(false, data.functorCalled, TEST_LOCATION);
1454 int UtcDaliTouchDataLeaveActorReadded(void)
1456 TestApplication application;
1457 Integration::Scene scene = application.GetScene();
1459 Actor actor = Actor::New();
1460 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1461 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1464 // Set actor to receive touch-events
1465 actor.SetProperty( Actor::Property::LEAVE_REQUIRED, true );
1467 // Render and notify
1468 application.SendNotification();
1469 application.Render();
1471 // Connect to actor's touched signal
1473 TouchDataFunctor functor( data );
1474 actor.TouchSignal().Connect( &application, functor );
1476 // Emit a down and motion
1477 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1478 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 11.0f, 10.0f ) ) );
1479 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1482 // Remove actor from scene and add again
1483 scene.Remove( actor );
1486 // Emit a motion within the actor's bounds
1487 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 12.0f, 10.0f ) ) );
1488 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1491 // Emit a motion outside the actor's bounds
1492 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 200.0f, 200.0f ) ) );
1493 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1494 DALI_TEST_EQUALS( PointState::LEAVE, data.touchData.points[0].state, TEST_LOCATION );
1500 int UtcDaliTouchDataClippedActor(void)
1502 TestApplication application;
1503 Integration::Scene scene = application.GetScene();
1505 Actor actor = Actor::New();
1506 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1507 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1510 Actor clippingActor = Actor::New();
1511 clippingActor.SetProperty( Actor::Property::SIZE, Vector2( 50.0f, 50.0f ) );
1512 clippingActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1513 clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1514 scene.Add( clippingActor );
1516 // Add a child to the clipped region.
1517 Actor clippingChild = Actor::New();
1518 clippingChild.SetProperty( Actor::Property::SIZE, Vector2( 50.0f, 50.0f ) );
1519 clippingChild.SetProperty( Actor::Property::POSITION, Vector2( 25.0f, 25.0f ));
1520 clippingChild.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1521 clippingActor.Add( clippingChild );
1523 // Render and notify.
1524 application.SendNotification();
1525 application.Render();
1527 // Connect to actor's touch signal.
1529 TouchDataFunctor functor( data );
1530 actor.TouchSignal().Connect( &application, functor );
1532 // Emit an event within clipped area - no hit.
1533 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1534 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
1537 // Emit an event outside the clipped area but within the actor area, we should have a hit.
1538 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 60.0f, 60.0f ) ) );
1539 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1542 clippingChild.TouchSignal().Connect( &application, functor );
1544 // Emit an event inside part of the child which is within the clipped area, we should have a hit.
1545 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 30.0f, 30.0f ) ) );
1546 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1552 int UtcDaliTouchDataActorUnparented(void)
1554 TestApplication application;
1556 Actor actor = Actor::New();
1557 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1558 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1559 application.GetScene().Add(actor);
1561 // Render and notify
1562 application.SendNotification();
1563 application.Render();
1565 // Connect to actor's touched signal
1567 TouchDataFunctor functor( data );
1568 actor.TouchSignal().Connect( &application, functor );
1570 // Emit a down signal
1571 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1572 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1573 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1574 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1577 // Render and notify
1578 application.SendNotification();
1579 application.Render();
1581 // Unparent the actor
1584 // Should receive an interrupted event
1585 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1586 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1590 int UtcDaliTouchDataParentRemovedFromScene(void)
1592 TestApplication application;
1594 Actor parent = Actor::New();
1595 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1596 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1597 application.GetScene().Add(parent);
1599 Actor actor = Actor::New();
1600 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1601 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1604 // Render and notify
1605 application.SendNotification();
1606 application.Render();
1608 // Connect to actor's touched signal
1610 TouchDataFunctor functor( data );
1611 actor.TouchSignal().Connect( &application, functor );
1613 // Emit a down signal
1614 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1615 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1616 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1617 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1620 // Render and notify
1621 application.SendNotification();
1622 application.Render();
1624 // Unparent the parent of the touchable actor
1627 // Should receive an interrupted event
1628 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1629 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1633 int UtcDaliTouchDataActorRemovedFromSceneDifferentConsumer(void)
1635 TestApplication application;
1637 Actor parent = Actor::New();
1638 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1639 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1640 application.GetScene().Add(parent);
1642 Actor actor = Actor::New();
1643 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1644 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1647 // Render and notify
1648 application.SendNotification();
1649 application.Render();
1651 // Connect to actor's touched signal
1653 TouchDataFunctor functor( data, false /* Do not consume */ );
1654 actor.TouchSignal().Connect( &application, functor );
1656 // Connect to parent's touched signal
1657 SignalData parentData;
1658 TouchDataFunctor parentFunctor( parentData );
1659 parent.TouchSignal().Connect( &application, parentFunctor );
1661 // Emit a down signal
1662 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1663 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1664 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1665 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1666 DALI_TEST_CHECK( actor == data.touchedActor );
1667 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1668 DALI_TEST_EQUALS( PointState::DOWN, parentData.touchData.points[0].state, TEST_LOCATION );
1669 DALI_TEST_CHECK( actor == parentData.touchData.points[0].hitActor );
1670 DALI_TEST_CHECK( parent == parentData.touchedActor );
1674 // Render and notify
1675 application.SendNotification();
1676 application.Render();
1678 // Unparent the actor
1681 // Should receive an interrupted event for both actor & parent
1682 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1683 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1684 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1685 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1689 // Readd actor to parent
1692 // Render and notify
1693 application.SendNotification();
1694 application.Render();
1696 // Emit a motion signal
1697 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 10.0f, 10.0f ) ) );
1698 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1699 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1703 // Parent is now consumer, connect again to the touched signal of the actor so that it becomes the consumer
1704 SignalData secondData;
1705 TouchDataFunctor secondFunctor( secondData /* Consume */ );
1706 actor.TouchSignal().Connect( &application, secondFunctor );
1708 // Unparent the actor
1711 // Should receive an interrupted event for both actor functors & the parent as well as it was last consumer
1712 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1713 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1714 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1715 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1716 DALI_TEST_EQUALS( true, secondData.functorCalled, TEST_LOCATION );
1717 DALI_TEST_EQUALS( PointState::INTERRUPTED, secondData.touchData.points[0].state, TEST_LOCATION );
1725 int UtcDaliTouchDataInterruptedDifferentConsumer(void)
1727 TestApplication application;
1728 Actor rootActor( application.GetScene().GetRootLayer() );
1730 Actor parent = Actor::New();
1731 parent.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1732 parent.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1733 application.GetScene().Add(parent);
1735 Actor actor = Actor::New();
1736 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1737 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1740 // Render and notify
1741 application.SendNotification();
1742 application.Render();
1744 // Connect to actor's touched signal
1746 TouchDataFunctor functor( data, false /* Do not consume */ );
1747 actor.TouchSignal().Connect( &application, functor );
1749 // Connect to parent's touched signal
1750 SignalData parentData;
1751 TouchDataFunctor parentFunctor( parentData, false /* Do not consume */ );
1752 parent.TouchSignal().Connect( &application, parentFunctor );
1754 // Connect to root's touched signal and consume
1755 SignalData rootData;
1756 TouchDataFunctor rootFunctor( rootData );
1757 rootActor.TouchSignal().Connect( &application, rootFunctor );
1759 // Emit a down signal
1760 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1761 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1762 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1763 DALI_TEST_CHECK( actor == data.touchData.points[0].hitActor );
1764 DALI_TEST_CHECK( actor == data.touchedActor );
1765 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1766 DALI_TEST_EQUALS( PointState::DOWN, parentData.touchData.points[0].state, TEST_LOCATION );
1767 DALI_TEST_CHECK( actor == parentData.touchData.points[0].hitActor );
1768 DALI_TEST_CHECK( parent == parentData.touchedActor );
1769 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1770 DALI_TEST_EQUALS( PointState::DOWN, rootData.touchData.points[0].state, TEST_LOCATION );
1771 DALI_TEST_CHECK( actor == rootData.touchData.points[0].hitActor );
1772 DALI_TEST_CHECK( rootActor == rootData.touchedActor );
1777 // Root is now consumer, connect to the touched signal of the parent so that it becomes the consumer
1778 SignalData secondData;
1779 TouchDataFunctor secondFunctor( secondData /* Consume */ );
1780 parent.TouchSignal().Connect( &application, secondFunctor );
1782 // Emit an interrupted signal, all three should STILL be called
1783 application.ProcessEvent( GenerateSingleTouch( PointState::INTERRUPTED, Vector2( 10.0f, 10.0f ) ) );
1784 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1785 DALI_TEST_EQUALS( PointState::INTERRUPTED, data.touchData.points[0].state, TEST_LOCATION );
1786 DALI_TEST_EQUALS( true, parentData.functorCalled, TEST_LOCATION );
1787 DALI_TEST_EQUALS( PointState::INTERRUPTED, parentData.touchData.points[0].state, TEST_LOCATION );
1788 DALI_TEST_EQUALS( true, rootData.functorCalled, TEST_LOCATION );
1789 DALI_TEST_EQUALS( PointState::INTERRUPTED, rootData.touchData.points[0].state, TEST_LOCATION );
1797 int UtcDaliTouchDataGetRadius(void)
1799 TestApplication application;
1801 Actor actor = Actor::New();
1802 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1803 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1804 application.GetScene().Add(actor);
1806 // Render and notify
1807 application.SendNotification();
1808 application.Render();
1810 // Connect to actor's touched signal
1812 TouchDataFunctor functor( data );
1813 actor.TouchSignal().Connect( &application, functor );
1815 // Emit a down signal with an angle
1816 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1817 touchEvent.points[ 0 ].SetRadius( 100.0f );
1818 application.ProcessEvent( touchEvent );
1819 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1820 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1821 DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].radius, TEST_LOCATION );
1822 DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].ellipseRadius.x, TEST_LOCATION );
1823 DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].ellipseRadius.y, TEST_LOCATION );
1828 int UtcDaliTouchDataGetEllipseRadius(void)
1830 TestApplication application;
1832 Actor actor = Actor::New();
1833 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1834 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1835 application.GetScene().Add(actor);
1837 // Render and notify
1838 application.SendNotification();
1839 application.Render();
1841 // Connect to actor's touched signal
1843 TouchDataFunctor functor( data );
1844 actor.TouchSignal().Connect( &application, functor );
1846 // Emit a down signal with an angle
1847 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1848 touchEvent.points[ 0 ].SetRadius( 100.0f, Vector2( 20.0f, 10.0f ) );
1849 application.ProcessEvent( touchEvent );
1850 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1851 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1852 DALI_TEST_EQUALS( 100.0f, data.touchData.points[0].radius, TEST_LOCATION );
1853 DALI_TEST_EQUALS( 20.0f, data.touchData.points[0].ellipseRadius.x, TEST_LOCATION );
1854 DALI_TEST_EQUALS( 10.0f, data.touchData.points[0].ellipseRadius.y, TEST_LOCATION );
1859 int UtcDaliTouchDataGetAngle(void)
1861 TestApplication application;
1863 Actor actor = Actor::New();
1864 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1865 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1866 application.GetScene().Add(actor);
1868 // Render and notify
1869 application.SendNotification();
1870 application.Render();
1872 // Connect to actor's touched signal
1874 TouchDataFunctor functor( data );
1875 actor.TouchSignal().Connect( &application, functor );
1877 // Emit a down signal with an angle
1878 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1879 touchEvent.points[ 0 ].SetAngle( Degree( 90.0f ) );
1880 application.ProcessEvent( touchEvent );
1881 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1882 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1883 DALI_TEST_EQUALS( Degree( 90.0f ), data.touchData.points[0].angle, TEST_LOCATION );
1888 int UtcDaliTouchDataGetPressure(void)
1890 TestApplication application;
1892 Actor actor = Actor::New();
1893 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1894 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1895 application.GetScene().Add(actor);
1897 // Render and notify
1898 application.SendNotification();
1899 application.Render();
1901 // Connect to actor's touched signal
1903 TouchDataFunctor functor( data );
1904 actor.TouchSignal().Connect( &application, functor );
1906 // Emit a down signal with an angle
1907 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1908 touchEvent.points[ 0 ].SetPressure( 10.0f );
1909 application.ProcessEvent( touchEvent );
1910 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1911 DALI_TEST_EQUALS( PointState::DOWN, data.touchData.points[0].state, TEST_LOCATION );
1912 DALI_TEST_EQUALS( 10.0f, data.touchData.points[0].pressure, TEST_LOCATION );
1917 int UtcDaliTouchDataAndEventUsage(void)
1919 TestApplication application;
1921 Actor actor = Actor::New();
1922 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1923 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1924 application.GetScene().Add(actor);
1926 // Render and notify
1927 application.SendNotification();
1928 application.Render();
1930 // Connect to actor's touched signal
1932 TouchDataFunctor functor( data );
1933 actor.TouchSignal().Connect( &application, functor );
1935 // Connect to actor's touched signal (OLD)
1936 bool touchEventFunctorCalled = false;
1937 TouchEventFunctor eventFunctor( touchEventFunctorCalled );
1938 actor.TouchedSignal().Connect( &application, eventFunctor );
1940 // Emit a down signal with an angle
1941 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) ) );
1942 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
1943 DALI_TEST_EQUALS( true, touchEventFunctorCalled, TEST_LOCATION );
1948 int UtcDaliTouchDataGetDeviceAPINegative(void)
1950 TestApplication application;
1952 Actor actor = Actor::New();
1953 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1954 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1955 application.GetScene().Add(actor);
1957 // Render and notify
1958 application.SendNotification();
1959 application.Render();
1961 // Connect to actor's touched signal
1962 HandleData handleData;
1963 TouchDataHandleFunctor functor( handleData );
1964 actor.TouchSignal().Connect( &application, functor );
1966 Vector2 screenCoordinates( 10.0f, 10.0f );
1967 Vector2 localCoordinates;
1968 actor.ScreenToLocal( localCoordinates.x, localCoordinates.y, screenCoordinates.x, screenCoordinates.y );
1970 // Emit a down signal
1971 application.ProcessEvent( GenerateSingleTouch( PointState::DOWN, screenCoordinates ) );
1973 TouchData data = handleData.touchData;
1974 DALI_TEST_EQUALS( data.GetDeviceClass( -1 ), Device::Class::NONE, TEST_LOCATION );
1975 DALI_TEST_EQUALS( data.GetDeviceSubclass( -1 ), Device::Subclass::NONE, TEST_LOCATION );
1979 int UtcDaliTouchDataGetMouseButtonPositive(void)
1981 TestApplication application;
1983 Actor actor = Actor::New();
1984 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
1985 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
1986 application.GetScene().Add(actor);
1988 // Render and notify
1989 application.SendNotification();
1990 application.Render();
1992 // Connect to actor's touched signal
1993 HandleData handleData;
1994 TouchDataHandleFunctor functor( handleData );
1995 actor.TouchSignal().Connect( &application, functor );
1997 // Emit a down signal with MouseButton
1998 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
1999 touchEvent.points[ 0 ].SetMouseButton( static_cast< MouseButton::Type >( 3 ) );
2000 application.ProcessEvent( touchEvent );
2002 TouchData data = handleData.touchData;
2003 DALI_TEST_EQUALS( data.GetMouseButton( 0 ), MouseButton::SECONDARY, TEST_LOCATION );
2008 int UtcDaliTouchDataGetMouseButtonNagative(void)
2010 TestApplication application;
2012 Actor actor = Actor::New();
2013 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2014 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2015 application.GetScene().Add(actor);
2017 // Render and notify
2018 application.SendNotification();
2019 application.Render();
2021 // Connect to actor's touched signal
2022 HandleData handleData;
2023 TouchDataHandleFunctor functor( handleData );
2024 actor.TouchSignal().Connect( &application, functor );
2026 // Emit a down signal with MouseButton
2027 Integration::TouchEvent touchEvent = GenerateSingleTouch( PointState::DOWN, Vector2( 10.0f, 10.0f ) );
2028 touchEvent.points[ 0 ].SetMouseButton( static_cast< MouseButton::Type >( 2 ) );
2029 application.ProcessEvent( touchEvent );
2031 TouchData data = handleData.touchData;
2032 DALI_TEST_EQUALS( data.GetMouseButton( 0 ), MouseButton::TERTIARY, TEST_LOCATION );
2033 DALI_TEST_EQUALS( data.GetMouseButton( 3 ), MouseButton::INVALID, TEST_LOCATION );
2038 int UtcDaliTouchDataCapturePropertySet(void)
2040 TestApplication application;
2042 Actor actor = Actor::New();
2043 actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
2044 actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
2045 application.GetScene().Add(actor);
2047 // Render and notify
2048 application.SendNotification();
2049 application.Render();
2051 // Connect to actor's touched signal
2053 TouchDataFunctor functor( data );
2054 actor.TouchSignal().Connect( &application, functor );
2056 // Emit a down signal
2057 application.ProcessEvent( GenerateSingleTouch( PointState::STARTED, Vector2( 10.0f, 10.0f ) ) );
2058 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2061 // Now motion outside of actor, we should not receive the event
2062 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 110.0f, 110.0f ) ) );
2063 DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
2066 // Up event, should receive an interrupted
2067 application.ProcessEvent( GenerateSingleTouch( PointState::FINISHED, Vector2( 110.0f, 110.0f ) ) );
2068 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2069 DALI_TEST_EQUALS( data.touchData.GetPoint(0).state, PointState::INTERRUPTED, TEST_LOCATION );
2071 // Now set the capture property
2072 actor.SetProperty( DevelActor::Property::CAPTURE_ALL_TOUCH_AFTER_START, true);
2074 // Emit a down signal
2075 application.ProcessEvent( GenerateSingleTouch( PointState::STARTED, Vector2( 10.0f, 10.0f ) ) );
2076 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2079 // Now motion outside of actor, we now SHOULD receive the event
2080 application.ProcessEvent( GenerateSingleTouch( PointState::MOTION, Vector2( 110.0f, 110.0f ) ) );
2081 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2084 // Up event, we should receive it again, but as ended rather than interrupted
2085 application.ProcessEvent( GenerateSingleTouch( PointState::FINISHED, Vector2( 110.0f, 110.0f ) ) );
2086 DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
2087 DALI_TEST_EQUALS( data.touchData.GetPoint(0).state, PointState::FINISHED, TEST_LOCATION );