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