Refactor SceneGraphProperty handling code in event side to make RegisterProperty...
[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) 2018 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/actors/actor.h>
23 #include <dali/devel-api/events/hit-test-algorithm.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 class Layer;
33
34 /**
35  * This namespace is provided for application developers to do hit test for the actors.
36  */
37 namespace HitTestAlgorithm
38 {
39
40 struct Results
41 {
42   RenderTaskPtr renderTask;       ///< The render-task displaying the actor.
43   Dali::Actor   actor;            ///< The hit actor.
44   Vector2       actorCoordinates; ///< The actor coordinates.
45   Vector4       rayOrigin;        ///< The point of origin of the ray.
46   Vector4       rayDirection;     ///< The direction vector of the ray.
47 };
48
49 /**
50  * Interface used by the hit-test-algorithm to determine whether the actor is hittable or whether
51  * we walk down its hierarchy.
52  */
53 struct HitTestInterface
54 {
55   /**
56    * Called by the hit-test algorithm to determine whether the actor is hittable or not.
57    *
58    * @param[in] actor Raw pointer to an Actor object.
59    *
60    * @return true if actor is hittable, false otherwise.
61    */
62   virtual bool IsActorHittable( Actor* actor ) = 0;
63
64   /**
65    * Called by the hit-test algorithm to determine whether the algorithm should descend the actor's
66    * hierarchy (and hit-test its children as well).
67    *
68    * @param[in] actor Raw pointer to an Actor object.
69    *
70    * @return true if we should descend the actor's hierarchy, false otherwise.
71    */
72   virtual bool DescendActorHierarchy( Actor* actor ) = 0;
73
74   /**
75    * Called by the hit-test algorithm to determine whether the layer specified consumes the hit
76    * regardless of whether an actor in the layer requires it or not.
77    *
78    * @note If true is returned, then no layers behind this layer will be hit-test.
79    *
80    * @param[in] layer Raw pointer to a Layer object.
81    *
82    * @return true if the layer should consume the hit, false otherwise.
83    */
84   virtual bool DoesLayerConsumeHit( Layer* layer ) = 0;
85
86 protected:
87
88   /**
89    * Virtual destructor, no deletion through this interface
90    */
91   virtual ~HitTestInterface();
92
93 };
94
95 /**
96  * @copydoc Dali::HitTestAlgorithm::HitTest(Stage stage, const Vector2& screenCoordinates, Results& results, HitTestFunction func )
97  */
98 bool HitTest( Stage& stage, const Vector2& screenCoordinates, Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func );
99
100 /**
101  * Given screen coordinates, this method returns the hit actor & the local coordinates relative to the actor etc.
102  * @param[in] stage The stage.
103  * @param[in] screenCoordinates The screen coordinates.
104  * @param[out] results The results of the hit-test.
105  * @param[in] hitTestInterface Used to determine whether the actor is hit or whether we walk down its hierarchy
106  * @return true if something was hit
107  *
108  * <h3>Hit Test Algorithm:</h3>
109  *
110  * - The system overlay RenderTaskList is hit-tested first.
111  * - If no hit then the regular RenderTaskList is used to hit test the on stage actors.
112  * - The bulk of the hit test algorithm is described in Dali::Actor.
113  * - In each RenderTask's its viewing parameters (the view and projection matrices, and the viewport)
114  *   are used to build a picking ray into the scene which is used for our ray tests when hit testing
115  *   an actor within each layer.
116  * - If an actor is deemed to be hittable, then a quicker ray sphere test on the actor is performed
117  *   first to determine if the ray is in the actor's proximity.
118  * - If this is also successful, then a more accurate ray test is performed to see if we have a hit.
119  *
120  * @note Currently, we prefer a child hit over a parent (regardless of the distance from the
121  *       camera) unless the parent is a RenderableActor but this is subject to change.
122  */
123 bool HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results, HitTestInterface& hitTestInterface );
124
125 /**
126  * Default HitTest where we check if a touch is required.
127  *
128  * @param[in] stage The stage.
129  * @param[in] screenCoordinates The screen coordinates.
130  * @param[out] results The results of the hit-test.
131  * @return true if something was hit
132  *
133  * @see HitTest(Stage&, const Vector2&, Results&, HitTestInterface&)
134  */
135 bool HitTest( Stage& stage, const Vector2& screenCoordinates, Results& results );
136
137 /**
138  * Hit test specific to a given RenderTask
139  *
140  * @param[in] stage The stage.
141  * @param[in] renderTask The render task for hit test
142  * @param[in] screenCoordinates The screen coordinates.
143  * @param[out] results The results of the hit-test.
144  * @param[in] func The function to use in the hit-test algorithm.
145  * @return true if something was hit
146  */
147 bool HitTest( Stage& stage, RenderTask& renderTask, const Vector2& screenCoordinates,
148               Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func );
149
150
151 } // namespace HitTestAlgorithm
152
153 } // namespace Internal
154
155 } // namespace Dali
156
157 #endif // DALI_INTERNAL_HIT_TEST_ALGORITHM_H