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