1 #ifndef DALI_INTERNAL_HIT_TEST_ALGORITHM_H
2 #define DALI_INTERNAL_HIT_TEST_ALGORITHM_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
36 * This namespace is provided for application developers to do hit test for the actors.
38 namespace HitTestAlgorithm
43 RenderTaskPtr renderTask; ///< The render-task displaying the actor.
44 Dali::Actor actor; ///< The hit actor.
45 Vector2 actorCoordinates; ///< The actor coordinates.
46 Vector4 rayOrigin; ///< The point of origin of the ray.
47 Vector4 rayDirection; ///< The direction vector of the ray.
51 * Interface used by the hit-test-algorithm to determine whether the actor is hittable or whether
52 * we walk down its hierarchy.
54 struct HitTestInterface
57 * Called by the hit-test algorithm to determine whether the actor is hittable or not.
59 * @param[in] actor Raw pointer to an Actor object.
61 * @return true if actor is hittable, false otherwise.
63 virtual bool IsActorHittable( Actor* actor ) = 0;
66 * Called by the hit-test algorithm to determine whether the algorithm should descend the actor's
67 * hierarchy (and hit-test its children as well).
69 * @param[in] actor Raw pointer to an Actor object.
71 * @return true if we should descend the actor's hierarchy, false otherwise.
73 virtual bool DescendActorHierarchy( Actor* actor ) = 0;
76 * Called by the hit-test algorithm to determine whether the layer specified consumes the hit
77 * regardless of whether an actor in the layer requires it or not.
79 * @note If true is returned, then no layers behind this layer will be hit-test.
81 * @param[in] layer Raw pointer to a Layer object.
83 * @return true if the layer should consume the hit, false otherwise.
85 virtual bool DoesLayerConsumeHit( Layer* layer ) = 0;
90 * Virtual destructor, no deletion through this interface
92 virtual ~HitTestInterface();
97 * Hit test specific to a given scene.
99 * @param[in] sceneSize The size of the scene.
100 * @param[in] renderTaskList The render task list of the scene.
101 * @param[in] layerList The layer list of the scene.
102 * @param[in] screenCoordinates The screen coordinates.
103 * @param[out] results The results of the hit-test.
104 * @param[in] func The function to use in the hit-test algorithm.
105 * @return true if something was hit
107 * @see HitTest(Stage&, const Vector2&, Results&, HitTestInterface&)
109 bool HitTest( const Vector2& sceneSize, RenderTaskList& renderTaskList, LayerList& layerList, const Vector2& screenCoordinates,
110 Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func );
113 * Given screen coordinates, this method returns the hit actor & the local coordinates relative to the actor etc.
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] hitTestInterface Used to determine whether the actor is hit or whether we walk down its hierarchy
120 * @return true if something was hit
122 * <h3>Hit Test Algorithm:</h3>
124 * - The regular RenderTaskList is used to hit test the on scene actors.
125 * - The bulk of the hit test algorithm is described in Dali::Actor.
126 * - In each RenderTask's its viewing parameters (the view and projection matrices, and the viewport)
127 * are used to build a picking ray into the scene which is used for our ray tests when hit testing
128 * an actor within each layer.
129 * - If an actor is deemed to be hittable, then a quicker ray sphere test on the actor is performed
130 * first to determine if the ray is in the actor's proximity.
131 * - If this is also successful, then a more accurate ray test is performed to see if we have a hit.
133 * @note Currently, we prefer a child hit over a parent (regardless of the distance from the
134 * camera) unless the parent is a RenderableActor but this is subject to change.
136 bool HitTest( const Vector2& sceneSize, RenderTaskList& renderTaskList, LayerList& layerList, const Vector2& screenCoordinates,
137 Results& results, HitTestInterface& hitTestInterface );
140 * Default HitTest where we check if a touch is required.
142 * @param[in] sceneSize The size of the scene.
143 * @param[in] renderTaskList The render task list of the scene.
144 * @param[in] layerList The layer list of the scene.
145 * @param[in] screenCoordinates The screen coordinates.
146 * @param[out] results The results of the hit-test.
147 * @return true if something was hit
149 * @see HitTest(Stage&, const Vector2&, Results&, HitTestInterface&)
151 bool HitTest( const Vector2& sceneSize, RenderTaskList& renderTaskList, LayerList& layerList, const Vector2& screenCoordinates, Results& results );
153 } // namespace HitTestAlgorithm
155 } // namespace Internal
159 #endif // DALI_INTERNAL_HIT_TEST_ALGORITHM_H