Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-HitTestAlgorithm.cpp
index 99d16c4..c178d40 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -40,11 +40,11 @@ bool IsActorHittableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType t
     case Dali::HitTestAlgorithm::CHECK_ACTOR:
     {
       // Check whether the actor is visible and not fully transparent.
-      if( actor.IsVisible()
-       && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
+      if( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE )
+       && actor.GetCurrentProperty< Vector4 >( Actor::Property::WORLD_COLOR ).a > 0.01f) // not FULLY_TRANSPARENT
       {
         // Check whether the actor has the specific name "HittableActor"
-        if(actor.GetName() == "HittableActor")
+        if(actor.GetProperty< std::string >( Actor::Property::NAME ) == "HittableActor")
         {
           hittable = true;
         }
@@ -53,7 +53,7 @@ bool IsActorHittableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType t
     }
     case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
     {
-      if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
+      if( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) ) // Actor is visible, if not visible then none of its children are visible.
       {
         hittable = true;
       }
@@ -77,9 +77,9 @@ bool DefaultIsActorTouchableFunction(Dali::Actor actor, Dali::HitTestAlgorithm::
   {
     case Dali::HitTestAlgorithm::CHECK_ACTOR:
     {
-      if( actor.IsVisible() &&
-          actor.IsSensitive() &&
-          actor.GetCurrentWorldColor().a > 0.01f)
+      if( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) &&
+          actor.GetProperty< bool >( Actor::Property::SENSITIVE ) &&
+          actor.GetCurrentProperty< Vector4 >( Actor::Property::WORLD_COLOR ).a > 0.01f)
       {
         hittable = true;
       }
@@ -87,8 +87,8 @@ bool DefaultIsActorTouchableFunction(Dali::Actor actor, Dali::HitTestAlgorithm::
     }
     case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
     {
-      if( actor.IsVisible() && // Actor is visible, if not visible then none of its children are visible.
-          actor.IsSensitive()) // Actor is sensitive, if insensitive none of its children should be hittable either.
+      if( actor.GetCurrentProperty< bool >( Actor::Property::VISIBLE ) && // Actor is visible, if not visible then none of its children are visible.
+          actor.GetProperty< bool >( Actor::Property::SENSITIVE )) // Actor is sensitive, if insensitive none of its children should be hittable either.
       {
         hittable = true;
       }
@@ -115,9 +115,9 @@ int UtcDaliHitTestAlgorithmWithFunctor(void)
   Stage stage = Stage::GetCurrent();
 
   Actor actor = Actor::New();
-  actor.SetSize(100.0f, 100.0f);
-  actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
-  actor.SetName("NonHittableActor");
+  actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
+  actor.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
+  actor.SetProperty( Actor::Property::NAME,"NonHittableActor");
   stage.Add(actor);
 
   // Render and notify
@@ -133,7 +133,7 @@ int UtcDaliHitTestAlgorithmWithFunctor(void)
   Dali::HitTestAlgorithm::HitTest( stage, screenCoordinates, results, IsActorHittableFunction );
   DALI_TEST_CHECK( results.actor != actor );
 
-  actor.SetName("HittableActor");
+  actor.SetProperty( Actor::Property::NAME,"HittableActor");
 
   results.actor = Actor();
   results.actorCoordinates = Vector2::ZERO;
@@ -145,96 +145,6 @@ int UtcDaliHitTestAlgorithmWithFunctor(void)
   END_TEST;
 }
 
-int UtcDaliHitTestAlgorithmWithFunctorOnRenderTask(void)
-{
-  TestApplication application;
-  tet_infoline("Testing Dali::HitTestAlgorithm functor, specific to a given render task");
-
-  Stage stage = Stage::GetCurrent();
-  Size stageSize = stage.GetSize();
-  RenderTaskList taskList = stage.GetRenderTaskList();
-
-  Actor actor[2];
-
-  for( int i=0; i<2; i++ )
-  {
-    actor[i] = Actor::New();
-    actor[i].SetSize(100.f, 100.f);
-    actor[i].SetParentOrigin(ParentOrigin::TOP_LEFT);
-    actor[i].SetAnchorPoint(AnchorPoint::TOP_LEFT);
-    actor[i].SetName("HittableActor");
-    stage.Add(actor[i]);
-  }
-  Vector2 position( 50.f, 40.f );
-  actor[1].SetPosition( position.x, position.y );
-
-  RenderTask renderTask[2];
-  renderTask[0] = taskList.GetTask( 0u );
-
-  FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width, stageSize.height, Pixel::A8, Image::NEVER);
-  renderTask[1] = taskList.CreateTask();
-  renderTask[1].SetSourceActor( actor[1] );
-  renderTask[1].SetExclusive( true );
-  renderTask[1].SetInputEnabled( true );
-  renderTask[1].SetTargetFrameBuffer( frameBufferImage );
-  renderTask[1].SetRefreshRate( RenderTask::REFRESH_ONCE );
-  renderTask[1].SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
-  application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
-
-  // Render and notify
-  application.SendNotification();
-  application.Render();
-  application.Render();
-  application.SendNotification();
-
-  // Perform a hit-test at the given screen coordinates with different render tasks
-
-  Dali::HitTestAlgorithm::Results results;
-  Vector2 screenCoordinates( 25.f, 25.f );
-
-  Dali::HitTestAlgorithm::HitTest( renderTask[0], screenCoordinates, results, IsActorHittableFunction );
-  DALI_TEST_CHECK( results.actor == actor[0] );
-  DALI_TEST_EQUALS( screenCoordinates, results.actorCoordinates, 0.1f, TEST_LOCATION );
-
-  results.actor = Actor();
-  results.actorCoordinates = Vector2::ZERO;
-  Dali::HitTestAlgorithm::HitTest( renderTask[1], screenCoordinates, results, IsActorHittableFunction );
-  DALI_TEST_CHECK( !results.actor );
-  DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
-
-  screenCoordinates.x = 80.f;
-  screenCoordinates.y = 70.f;
-
-  results.actor = Actor();
-  results.actorCoordinates = Vector2::ZERO;
-  Dali::HitTestAlgorithm::HitTest( renderTask[0], screenCoordinates, results, IsActorHittableFunction );
-  DALI_TEST_CHECK( results.actor == actor[0] );
-  DALI_TEST_EQUALS( screenCoordinates, results.actorCoordinates, 0.1f, TEST_LOCATION );
-
-  results.actor = Actor();
-  results.actorCoordinates = Vector2::ZERO;
-  Dali::HitTestAlgorithm::HitTest( renderTask[1], screenCoordinates, results, IsActorHittableFunction );
-  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 );
-  DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
-
-  results.actor = Actor();
-  results.actorCoordinates = Vector2::ZERO;
-  Dali::HitTestAlgorithm::HitTest( renderTask[1], screenCoordinates, results, IsActorHittableFunction );
-  DALI_TEST_CHECK( results.actor == actor[1]);
-  DALI_TEST_EQUALS( screenCoordinates - position, results.actorCoordinates, 0.1f, TEST_LOCATION );
-  END_TEST;
-}
-
-
 int UtcDaliHitTestAlgorithmOrtho01(void)
 {
   TestApplication application;
@@ -247,22 +157,22 @@ int UtcDaliHitTestAlgorithmOrtho01(void)
 
   Vector2 stageSize ( stage.GetSize() );
   cameraActor.SetOrthographicProjection( stageSize );
-  cameraActor.SetPosition(0.0f, 0.0f, 1600.0f);
+  cameraActor.SetProperty( Actor::Property::POSITION, Vector3(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.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);
+  blue.SetProperty( Actor::Property::NAME, "Blue" );
+  blue.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+  blue.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3(1.0f/3.0f, 1.0f/3.0f, 0.5f) );
+  blue.SetProperty( Actor::Property::SIZE, actorSize );
+  blue.SetProperty( Actor::Property::POSITION_Z, 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 );
+  green.SetProperty( Actor::Property::NAME, "Green" );
+  green.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+  green.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3(2.0f/3.0f, 2.0f/3.0f, 0.5f) );
+  green.SetProperty( Actor::Property::SIZE, actorSize );
 
   // Add the actors to the view
   stage.Add( blue );
@@ -303,22 +213,22 @@ int UtcDaliHitTestAlgorithmOrtho02(void)
   cameraActor.SetOrthographicProjection(-stageSize.x * 0.3f,  stageSize.x * 0.7f,
                                          stageSize.y * 0.3f, -stageSize.y * 0.7f,
                                          800.0f, 4895.0f);
-  cameraActor.SetPosition(0.0f, 0.0f, 1600.0f);
+  cameraActor.SetProperty( Actor::Property::POSITION, Vector3(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.SetName( "Blue" );
-  blue.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-  blue.SetParentOrigin( Vector3(0.2f, 0.2f, 0.5f) );
-  blue.SetSize( actorSize );
-  blue.SetZ(30.0f);
+  blue.SetProperty( Actor::Property::NAME, "Blue" );
+  blue.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+  blue.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3(0.2f, 0.2f, 0.5f) );
+  blue.SetProperty( Actor::Property::SIZE, actorSize );
+  blue.SetProperty( Actor::Property::POSITION_Z, 30.0f);
 
   Actor green = Actor::New( );
-  green.SetName( "Green" );
-  green.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-  green.SetParentOrigin( Vector3(0.4f, 0.4f, 0.5f) );
-  green.SetSize( actorSize );
+  green.SetProperty( Actor::Property::NAME, "Green" );
+  green.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+  green.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3(0.4f, 0.4f, 0.5f) );
+  green.SetProperty( Actor::Property::SIZE, actorSize );
 
   // Add the actors to the view
   stage.Add( blue );
@@ -361,58 +271,54 @@ int UtcDaliHitTestAlgorithmOrtho02(void)
   END_TEST;
 }
 
-int UtcDaliHitTestAlgorithmStencil(void)
+int UtcDaliHitTestAlgorithmClippingActor(void)
 {
   TestApplication application;
   tet_infoline("Testing Dali::HitTestAlgorithm with a stencil");
 
   Stage stage = Stage::GetCurrent();
   Actor rootLayer = stage.GetRootLayer();
-  rootLayer.SetName( "RootLayer" );
+  rootLayer.SetProperty( Actor::Property::NAME, "RootLayer" );
 
   // Create a layer
   Layer layer = Layer::New();
-  layer.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-  layer.SetParentOrigin( ParentOrigin::TOP_LEFT );
-  layer.SetName( "layer" );
+  layer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+  layer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  layer.SetProperty( Actor::Property::NAME, "layer" );
   stage.Add( layer );
 
-  // Create a stencil and add that to the layer
-  Actor stencil = CreateRenderableActor(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 = CreateRenderableActor( Dali::BufferImage::WHITE() );
-  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();
+  clippingActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+  clippingActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  clippingActor.SetProperty( Actor::Property::SIZE, Vector2( 50.0f, 50.0f ) );
+  clippingActor.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+  clippingActor.SetProperty( Actor::Property::NAME, "clippingActor" );
+  layer.Add( clippingActor );
+
+  // Create a renderable actor and add it to the clipping actor.
+  Actor childActor = CreateRenderableActor();
+  childActor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
+  childActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+  childActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  childActor.SetProperty( Actor::Property::NAME, "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.GetProperty< std::string >( Actor::Property::NAME ).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.GetProperty< std::string >( Actor::Property::NAME ).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" ) );
-  }
   END_TEST;
 }
 
@@ -428,23 +334,23 @@ int UtcDaliHitTestAlgorithmOverlay(void)
 
   Vector2 stageSize ( stage.GetSize() );
   cameraActor.SetOrthographicProjection( stageSize );
-  cameraActor.SetPosition(0.0f, 0.0f, 1600.0f);
+  cameraActor.SetProperty( Actor::Property::POSITION, Vector3(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);
+  blue.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
+  blue.SetProperty( Actor::Property::NAME, "Blue" );
+  blue.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+  blue.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3(1.0f/3.0f, 1.0f/3.0f, 0.5f) );
+  blue.SetProperty( Actor::Property::SIZE, actorSize );
+  blue.SetProperty( Actor::Property::POSITION_Z, 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 );
+  green.SetProperty( Actor::Property::NAME, "Green" );
+  green.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+  green.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3(2.0f/3.0f, 2.0f/3.0f, 0.5f) );
+  green.SetProperty( Actor::Property::SIZE, actorSize );
 
   // Add the actors to the view
   stage.Add( blue );