Conversion to Apache 2.0 license
[platform/core/uifw/dali-core.git] / dali / internal / event / events / hit-test-algorithm-impl.h
1 #ifndef __DALI_INTERNAL_HIT_TEST_ALGORITHM_H__
2 #define __DALI_INTERNAL_HIT_TEST_ALGORITHM_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/events/hit-test-algorithm.h>
23 #include <dali/public-api/render-tasks/render-task.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 /**
32  * This namespace is provided for application developers to do hit test for the actors.
33  */
34 namespace HitTestAlgorithm
35 {
36
37 struct Results
38 {
39   Dali::RenderTask renderTask;       ///< The render-task displaying the actor.
40   Dali::Actor      actor;            ///< The hit actor.
41   Vector2          actorCoordinates; ///< The actor coordinates.
42   Vector4          rayOrigin;        ///< The point of origin of the ray.
43   Vector4          rayDirection;     ///< The direction vector of the ray.
44 };
45
46 /**
47  * Interface used by the hit-test-algorithm to determine whether the actor is hittable or whether
48  * we walk down its hierarchy.
49  */
50 struct HitTestInterface
51 {
52   /**
53    * Called by the hit-test algorithm to determine whether the actor is hittable or not.
54    * @param[in] actor Raw pointer to an Actor object.
55    */
56   virtual bool IsActorHittable( Actor* actor ) = 0;
57
58   /**
59    * Called by the hit-test algorithm to determine whether the algorithm should descend the actor's
60    * hierarchy (and hit-test its children as well).
61    * @param[in] actor Raw pointer to an Actor object.
62    */
63   virtual bool DescendActorHierarchy( Actor* actor ) = 0;
64 };
65
66 /**
67  * @copydoc Dali::HitTestAlgorithm::HitTest(Stage stage, const Vector2& screenCoordinates, Results& results, HitTestFunction func )
68  */
69 void HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func );
70
71 /**
72  * Given screen coordinates, this method returns the hit actor & the local coordinates relative to the actor etc.
73  * @param[in] stage The stage.
74  * @param[in] screenCoordinates The screen coordinates.
75  * @param[out] results The results of the hit-test.
76  * @param[in] hitTestInterface Used to determine whether the actor is hit or whether we walk down its hierarchy
77  *
78  * <h3>Hit Test Algorithm:</h3>
79  *
80  * - The system overlay RenderTaskList is hit-tested first.
81  * - If no hit then the regular RenderTaskList is used to hit test the on stage actors.
82  * - The bulk of the hit test algorithm is described in Dali::Actor.
83  * - In each RenderTask's its viewing parameters (the view and projection matrices, and the viewport)
84  *   are used to build a picking ray into the scene which is used for our ray tests when hit testing
85  *   an actor within each layer.
86  * - If an actor is deemed to be hittable, then a quicker ray sphere test on the actor is performed
87  *   first to determine if the ray is in the actor's proximity.
88  * - If this is also successful, then a more accurate ray test is performed to see if we have a hit.
89  *
90  * @note Currently, we prefer a child hit over a parent (regardless of the distance from the
91  *       camera) unless the parent is a RenderableActor but this is subject to change.
92  */
93 void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results, HitTestInterface& hitTestInterface );
94
95 /**
96  * Default HitTest where we check if a touch is required.
97  *
98  * @param[in] stage The stage.
99  * @param[in] screenCoordinates The screen coordinates.
100  * @param[out] results The results of the hit-test.
101  *
102  * @see HitTest(Stage&, const Vector2&, Results&, HitTestInterface&)
103  */
104 void HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results );
105
106 /**
107  * Hit test specific to a given RenderTask
108  *
109  * @param[in] stage The stage.
110  * @param[in] renderTask The render task for hit test
111  * @param[in] screenCoordinates The screen coordinates.
112  * @param[out] results The results of the hit-test.
113  * @param[in] func The function to use in the hit-test algorithm.
114  */
115 void HitTest( Stage& stage, RenderTask& renderTask, const Vector2& screenCoordinates,
116               Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func );
117
118 } // namespace HitTestAlgorithm
119
120 } // namespace Internal
121
122 } // namespace Dali
123
124 #endif // __DALI_INTERNAL_HIT_TEST_ALGORITHM_H__