Fix hit test API to tell if it succeeds or not, clarify test case 85/33285/1
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 7 Jan 2015 18:44:16 +0000 (18:44 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 7 Jan 2015 18:44:16 +0000 (18:44 +0000)
Change-Id: I57e141c099c20461c6b7658bf4a27fd28af3d911

automated-tests/src/dali-unmanaged/utc-Dali-RenderTask.cpp
dali/internal/event/events/hit-test-algorithm-impl.cpp
dali/internal/event/events/hit-test-algorithm-impl.h
dali/public-api/events/hit-test-algorithm.cpp
dali/public-api/events/hit-test-algorithm.h

index 5710e4d..30da463 100644 (file)
@@ -102,28 +102,35 @@ int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
 
   Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
   Dali::HitTestAlgorithm::Results results;
-  Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
-  DALI_TEST_CHECK( !results.actor);
+  DALI_TEST_CHECK( !results.actor );
+  DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
+  // miss expected, results not changed
+  DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
+  DALI_TEST_CHECK( !results.actor );
   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
 
   screenCoordinates.x = stageSize.x * 0.265f;
   screenCoordinates.y = stageSize.y * 0.33f;
   results.actor = Actor();
   results.actorCoordinates = Vector2::ZERO;
-  Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
-  DALI_TEST_CHECK( results.actor  == offscreenActor);
+  // hit expected, results changed
+  DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
+  DALI_TEST_CHECK( results.actor  == offscreenActor );
   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
 
   screenCoordinates.x = stageSize.x * 0.435f;
   screenCoordinates.y = stageSize.y * 0.52f;
-  Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
-  DALI_TEST_CHECK( results.actor  == offscreenActor);
-  DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
+  // hit expected, results changed
+  DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
+  DALI_TEST_CHECK( results.actor  == offscreenActor );
+  const Vector2 expectedCoordinates = (screenCoordinates-offset)/scale;
+  DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
 
   screenCoordinates.x = stageSize.x * 0.65f;
   screenCoordinates.y = stageSize.y * 0.95f;
-  Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
-  DALI_TEST_CHECK( !results.actor);
-  DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
+  // miss expected, results not changed
+  DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
+  DALI_TEST_CHECK( results.actor  == offscreenActor );
+  DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
   END_TEST;
 }
index 51eeeec..b3eb5ad 100644 (file)
@@ -495,8 +495,9 @@ bool HitTestForEachRenderTask( LayerList& layers,
 
 } // unnamed namespace
 
-void HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func )
+bool HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func )
 {
+  bool wasHit( false );
   // Hit-test the regular on-stage actors
   RenderTaskList& taskList = stage.GetRenderTaskList();
   LayerList& layerList = stage.GetLayerList();
@@ -507,12 +508,14 @@ void HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgor
   {
     results.actor = hitTestResults.actor;
     results.actorCoordinates = hitTestResults.actorCoordinates;
+    wasHit = true;
   }
+  return wasHit;
 }
 
-void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results, HitTestInterface& hitTestInterface )
+bool HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results, HitTestInterface& hitTestInterface )
 {
-  bool hit = false;
+  bool wasHit( false );
 
   // Hit-test the system-overlay actors first
   SystemOverlay* systemOverlay = stage.GetSystemOverlayInternal();
@@ -522,35 +525,40 @@ void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results,
     RenderTaskList& overlayTaskList = systemOverlay->GetOverlayRenderTasks();
     LayerList& overlayLayerList = systemOverlay->GetLayerList();
 
-    hit = HitTestForEachRenderTask( overlayLayerList, overlayTaskList, screenCoordinates, results, hitTestInterface );
+    wasHit = HitTestForEachRenderTask( overlayLayerList, overlayTaskList, screenCoordinates, results, hitTestInterface );
   }
 
   // Hit-test the regular on-stage actors
-  if ( !hit )
+  if ( !wasHit )
   {
     RenderTaskList& taskList = stage.GetRenderTaskList();
     LayerList& layerList = stage.GetLayerList();
 
-    HitTestForEachRenderTask( layerList, taskList, screenCoordinates, results, hitTestInterface );
+    wasHit = HitTestForEachRenderTask( layerList, taskList, screenCoordinates, results, hitTestInterface );
   }
+  return wasHit;
 }
 
-void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results )
+bool HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results )
 {
   ActorTouchableCheck actorTouchableCheck;
-  HitTest( stage, screenCoordinates, results, actorTouchableCheck );
+  return HitTest( stage, screenCoordinates, results, actorTouchableCheck );
 }
 
-void HitTest( Stage& stage, RenderTask& renderTask, const Vector2& screenCoordinates,
+bool HitTest( Stage& stage, RenderTask& renderTask, const Vector2& screenCoordinates,
               Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func )
 {
+  bool wasHit( false );
   Results hitTestResults;
+
   HitTestFunctionWrapper hitTestFunctionWrapper( func );
   if ( HitTestRenderTask( stage.GetLayerList(), renderTask, screenCoordinates, hitTestResults, hitTestFunctionWrapper ) )
   {
     results.actor = hitTestResults.actor;
     results.actorCoordinates = hitTestResults.actorCoordinates;
+    wasHit = true;
   }
+  return wasHit;
 }
 
 } // namespace HitTestAlgorithm
index 1225900..51ca403 100644 (file)
@@ -86,7 +86,7 @@ struct HitTestInterface
 /**
  * @copydoc Dali::HitTestAlgorithm::HitTest(Stage stage, const Vector2& screenCoordinates, Results& results, HitTestFunction func )
  */
-void HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func );
+bool HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func );
 
 /**
  * Given screen coordinates, this method returns the hit actor & the local coordinates relative to the actor etc.
@@ -94,6 +94,7 @@ void HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgor
  * @param[in] screenCoordinates The screen coordinates.
  * @param[out] results The results of the hit-test.
  * @param[in] hitTestInterface Used to determine whether the actor is hit or whether we walk down its hierarchy
+ * @return true if something was hit
  *
  * <h3>Hit Test Algorithm:</h3>
  *
@@ -110,7 +111,7 @@ void HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgor
  * @note Currently, we prefer a child hit over a parent (regardless of the distance from the
  *       camera) unless the parent is a RenderableActor but this is subject to change.
  */
-void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results, HitTestInterface& hitTestInterface );
+bool HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results, HitTestInterface& hitTestInterface );
 
 /**
  * Default HitTest where we check if a touch is required.
@@ -118,10 +119,11 @@ void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results,
  * @param[in] stage The stage.
  * @param[in] screenCoordinates The screen coordinates.
  * @param[out] results The results of the hit-test.
+ * @return true if something was hit
  *
  * @see HitTest(Stage&, const Vector2&, Results&, HitTestInterface&)
  */
-void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results );
+bool HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results );
 
 /**
  * Hit test specific to a given RenderTask
@@ -131,8 +133,9 @@ void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results )
  * @param[in] screenCoordinates The screen coordinates.
  * @param[out] results The results of the hit-test.
  * @param[in] func The function to use in the hit-test algorithm.
+ * @return true if something was hit
  */
-void HitTest( Stage& stage, RenderTask& renderTask, const Vector2& screenCoordinates,
+bool HitTest( Stage& stage, RenderTask& renderTask, const Vector2& screenCoordinates,
               Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func );
 
 } // namespace HitTestAlgorithm
index 3603acc..c8b1870 100644 (file)
@@ -29,15 +29,15 @@ namespace Dali
 namespace HitTestAlgorithm
 {
 
-void HitTest( Stage stage, const Vector2& screenCoordinates, Results& results, HitTestFunction func )
+bool HitTest( Stage stage, const Vector2& screenCoordinates, Results& results, HitTestFunction func )
 {
-  Internal::HitTestAlgorithm::HitTest( GetImplementation(stage), screenCoordinates, results, func );
+  return Internal::HitTestAlgorithm::HitTest( GetImplementation(stage), screenCoordinates, results, func );
 }
 
-void HitTest( RenderTask& renderTask, const Vector2& screenCoordinates, Results& results, HitTestFunction func )
+bool HitTest( RenderTask& renderTask, const Vector2& screenCoordinates, Results& results, HitTestFunction func )
 {
   Stage stage = Stage::GetCurrent();
-  Internal::HitTestAlgorithm::HitTest( GetImplementation( stage ), GetImplementation(renderTask), screenCoordinates, results, func );
+  return Internal::HitTestAlgorithm::HitTest( GetImplementation( stage ), GetImplementation(renderTask), screenCoordinates, results, func );
 }
 
 } // namespace HitTestAlgorithm
index fd79c0b..715ba87 100644 (file)
@@ -139,20 +139,22 @@ typedef bool (*HitTestFunction)(Actor actor, TraverseType type);
  *
  * @param[in] stage The stage.
  * @param[in] screenCoordinates The screen coordinates.
- * @param[out] results The results of the hit-test.
+ * @param[out] results The results of the hit-test, only modified if something is hit
  * @param[in] func The function to use in the hit-test algorithm.
+ * @return true if something was hit
  */
-DALI_IMPORT_API void HitTest( Stage stage, const Vector2& screenCoordinates, Results& results, HitTestFunction func );
+DALI_IMPORT_API bool HitTest( Stage stage, const Vector2& screenCoordinates, Results& results, HitTestFunction func );
 
 /**
  * @brief Hit test specific to a given RenderTask.
  *
  * @param[in] renderTask The render task for hit test
  * @param[in] screenCoordinates The screen coordinates.
- * @param[out] results The results of the hit-test.
+ * @param[out] results The results of the hit-test, only modified if something is hit
  * @param[in] func The function to use in the hit-test algorithm.
+ * @return true if something was hit
  */
-DALI_IMPORT_API void HitTest( RenderTask& renderTask, const Vector2& screenCoordinates, Results& results, HitTestFunction func );
+DALI_IMPORT_API bool HitTest( RenderTask& renderTask, const Vector2& screenCoordinates, Results& results, HitTestFunction func );
 
 } // namespace HitTestAlgorithm