Hit test algorithm bug fix 71/43971/4
authorFerran Sole <ferran.sole@samsung.com>
Wed, 15 Jul 2015 16:44:15 +0000 (17:44 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Thu, 16 Jul 2015 09:05:49 +0000 (10:05 +0100)
Change-Id: Ia601bcd0f9c30106eaab1ed3ebc32711ae9e70e3

automated-tests/src/dali-devel/utc-Dali-HitTestAlgorithm.cpp
dali/internal/event/events/hit-test-algorithm-impl.cpp

index ecde51d..ae04a17 100644 (file)
@@ -274,9 +274,9 @@ int UtcDaliHitTestAlgorithmOrtho01(void)
   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 );
index 50457c2..da51fb7 100644 (file)
@@ -216,22 +216,16 @@ HitActor HitTestWithinLayer( Actor& actor,
             hit.x = hitPointLocal.x;
             hit.y = hitPointLocal.y;
             hit.distance = distance;
+            hit.depth = actor.GetHierarchyDepth() * Dali::Layer::TREE_DEPTH_MULTIPLIER;
 
             // Is this actor an Image Actor or contains a renderer?
             if ( ImageActor* imageActor = dynamic_cast< ImageActor* >( &actor ) )
             {
-              hit.depth = imageActor->GetDepthIndex();
+              hit.depth += imageActor->GetDepthIndex();
             }
-            else
+            else if ( actor.GetRendererCount() )
             {
-              if ( actor.GetRendererCount() )
-              {
-                hit.depth = actor.GetHierarchyDepth() * Dali::Layer::TREE_DEPTH_MULTIPLIER + actor.GetRendererAt( 0 ).GetDepthIndex();
-              }
-              else
-              {
-                hit.depth = 0;
-              }
+              hit.depth += actor.GetRendererAt( 0 ).GetDepthIndex();
             }
           }
         }
@@ -276,21 +270,16 @@ HitActor HitTestWithinLayer( Actor& actor,
                                                   layerIs3d) );
 
         bool updateChildHit = false;
-        // If our ray casting hit, then check then if the hit actor's depth is greater that the favorite, it will be preferred
         if ( currentHit.distance >= 0.0f )
         {
-          if ( currentHit.depth > childHit.depth )
+          if( layerIs3d )
           {
-            updateChildHit = true;
+            updateChildHit = ( ( currentHit.depth > childHit.depth ) ||
+                ( ( currentHit.depth == childHit.depth ) && ( currentHit.distance < childHit.distance ) ) );
           }
-
-          // In a 3D layer, if the hit actor's depth is equal to current favorite, then we check the distance and prefer the closer
-          else if ( layerIs3d && currentHit.depth == childHit.depth )
+          else
           {
-            if ( currentHit.distance < childHit.distance )
-            {
-              updateChildHit = true;
-            }
+            updateChildHit = currentHit.depth >= childHit.depth;
           }
         }