/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
RenderTask renderTask[2];
renderTask[0] = taskList.GetTask( 0u );
- FrameBufferImage frameBufferImage = FrameBufferImage::New(stageSize.width, stageSize.height, Pixel::A8, Image::NEVER);
+ FrameBufferImage frameBufferImage = FrameBufferImage::New(stageSize.width, stageSize.height, Pixel::A8);
renderTask[1] = taskList.CreateTask();
renderTask[1].SetSourceActor( actor[1] );
renderTask[1].SetExclusive( true );
DALI_TEST_CHECK( results.actor == actor[1]);
DALI_TEST_EQUALS( screenCoordinates - position, results.actorCoordinates, 0.1f, TEST_LOCATION );
-
screenCoordinates.x = 120.f;
screenCoordinates.y = 130.f;
results.actor = Actor();
results.actorCoordinates = Vector2::ZERO;
Dali::HitTestAlgorithm::HitTest( renderTask[0], screenCoordinates, results, IsActorHittableFunction );
- DALI_TEST_CHECK( results.actor == actor[1] );
- DALI_TEST_EQUALS( screenCoordinates - position, results.actorCoordinates, 0.1f, TEST_LOCATION );
+ DALI_TEST_CHECK( !results.actor );
+ DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
results.actor = Actor();
results.actorCoordinates = Vector2::ZERO;
application.Render(10);
HitTestAlgorithm::Results results;
- HitTest(stage, Vector2( 240.0f, 400.0f ), results, &DefaultIsActorTouchableFunction);
- DALI_TEST_CHECK( results.actor == blue );
- DALI_TEST_EQUALS( results.actorCoordinates, actorSize * 5.0f/6.0f, TEST_LOCATION );
+ HitTest(stage, stageSize / 2.0f, results, &DefaultIsActorTouchableFunction);
+ DALI_TEST_CHECK( results.actor == green );
+ DALI_TEST_EQUALS( results.actorCoordinates, actorSize * 1.0f/6.0f, TEST_LOCATION );
HitTest(stage, stageSize / 3.0f, results, &DefaultIsActorTouchableFunction);
DALI_TEST_CHECK( results.actor == blue );
END_TEST;
}
-int UtcDaliHitTestAlgorithmStencil(void)
+int UtcDaliHitTestAlgorithmClippingActor(void)
{
TestApplication application;
tet_infoline("Testing Dali::HitTestAlgorithm with a stencil");
layer.SetName( "layer" );
stage.Add( layer );
- // Create a stencil and add that to the layer
- Actor stencil = ImageActor::New(Dali::BufferImage::WHITE() );
- stencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- stencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
- stencil.SetSize( 50.0f, 50.0f );
- stencil.SetDrawMode( DrawMode::STENCIL );
- stencil.SetName( "stencil" );
- layer.Add( stencil );
-
- // Create a renderable actor and add that to the layer
- Actor layerHitActor = ImageActor::New();
- layerHitActor.SetSize( 100.0f, 100.0f );
- layerHitActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- layerHitActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
- layerHitActor.SetName( "layerHitActor" );
- layer.Add( layerHitActor );
+ // Create a clipping actor and add it to the layer.
+ Actor clippingActor = CreateRenderableActor( Dali::BufferImage::WHITE() );
+ clippingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ clippingActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ clippingActor.SetSize( 50.0f, 50.0f );
+ clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+ clippingActor.SetName( "clippingActor" );
+ layer.Add( clippingActor );
+
+ // Create a renderable actor and add it to the clipping actor.
+ Actor childActor = CreateRenderableActor( Dali::BufferImage::WHITE() );
+ childActor.SetSize( 100.0f, 100.0f );
+ childActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+ childActor.SetParentOrigin( ParentOrigin::TOP_LEFT );
+ childActor.SetName( "childActor" );
+ clippingActor.Add( childActor );
// Render and notify
application.SendNotification();
application.Render();
- // Hit within stencil and actor
- {
- HitTestAlgorithm::Results results;
- HitTest(stage, Vector2( 10.0f, 10.0f ), results, &DefaultIsActorTouchableFunction);
- DALI_TEST_CHECK( results.actor == layerHitActor );
- tet_printf( "Hit: %s\n", ( results.actor ? results.actor.GetName().c_str() : "NULL" ) );
- }
+ // Hit within clippingActor and childActor.
+ HitTestAlgorithm::Results results;
+ HitTest( stage, Vector2( 10.0f, 10.0f ), results, &DefaultIsActorTouchableFunction );
+ DALI_TEST_CHECK( results.actor == childActor );
+ tet_printf( "Hit: %s\n", ( results.actor ? results.actor.GetName().c_str() : "NULL" ) );
- // Hit within actor but outside of stencil, should hit the root-layer
- {
- HitTestAlgorithm::Results results;
- HitTest(stage, Vector2( 60.0f, 60.0f ), results, &DefaultIsActorTouchableFunction);
- DALI_TEST_CHECK( results.actor == rootLayer );
- tet_printf( "Hit: %s\n", ( results.actor ? results.actor.GetName().c_str() : "NULL" ) );
- }
+ // Hit within childActor but outside of clippingActor, should hit the root-layer instead.
+ HitTest( stage, Vector2( 60.0f, 60.0f ), results, &DefaultIsActorTouchableFunction);
+ DALI_TEST_CHECK( results.actor == rootLayer );
+ tet_printf( "Hit: %s\n", ( results.actor ? results.actor.GetName().c_str() : "NULL" ) );
+
+ END_TEST;
+}
+
+int UtcDaliHitTestAlgorithmOverlay(void)
+{
+ TestApplication application;
+ tet_infoline("Testing Dali::HitTestAlgorithm with overlay actors");
+
+ Stage stage = Stage::GetCurrent();
+ RenderTaskList renderTaskList = stage.GetRenderTaskList();
+ RenderTask defaultRenderTask = renderTaskList.GetTask(0u);
+ Dali::CameraActor cameraActor = defaultRenderTask.GetCameraActor();
+
+ Vector2 stageSize ( stage.GetSize() );
+ cameraActor.SetOrthographicProjection( stageSize );
+ cameraActor.SetPosition(0.0f, 0.0f, 1600.0f);
+
+ Vector2 actorSize( stageSize * 0.5f );
+ // Create two actors with half the size of the stage and set them to be partially overlapping
+ Actor blue = Actor::New();
+ blue.SetDrawMode( DrawMode::OVERLAY_2D );
+ blue.SetName( "Blue" );
+ blue.SetAnchorPoint( AnchorPoint::CENTER );
+ blue.SetParentOrigin( Vector3(1.0f/3.0f, 1.0f/3.0f, 0.5f) );
+ blue.SetSize( actorSize );
+ blue.SetZ(30.0f);
+
+ Actor green = Actor::New( );
+ green.SetName( "Green" );
+ green.SetAnchorPoint( AnchorPoint::CENTER );
+ green.SetParentOrigin( Vector3(2.0f/3.0f, 2.0f/3.0f, 0.5f) );
+ green.SetSize( actorSize );
+
+ // Add the actors to the view
+ stage.Add( blue );
+ stage.Add( green );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render(0);
+ application.Render(10);
+
+ HitTestAlgorithm::Results results;
+
+ //Hit in the intersection. Should pick the blue actor since it is an overlay.
+ HitTest(stage, stageSize / 2.0f, results, &DefaultIsActorTouchableFunction);
+ DALI_TEST_CHECK( results.actor == blue );
+ DALI_TEST_EQUALS( results.actorCoordinates, actorSize * 5.0f/6.0f, TEST_LOCATION );
+
+ //Hit in the blue actor
+ HitTest(stage, stageSize / 3.0f, results, &DefaultIsActorTouchableFunction);
+ DALI_TEST_CHECK( results.actor == blue );
+ DALI_TEST_EQUALS( results.actorCoordinates, actorSize * 0.5f, TEST_LOCATION );
+
+ //Hit in the green actor
+ HitTest(stage, stageSize * 2.0f / 3.0f, results, &DefaultIsActorTouchableFunction);
+ DALI_TEST_CHECK( results.actor == green );
+ DALI_TEST_EQUALS( results.actorCoordinates, actorSize * 0.5f, TEST_LOCATION );
END_TEST;
}