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