(HitTest) Added API to layer so that it can consume all touch if required
[platform/core/uifw/dali-core.git] / capi / dali / public-api / actors / layer.h
1 #ifndef __DALI_LAYER_H__
2 #define __DALI_LAYER_H__
3
4 /*
5  * Copyright (c) 2014 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 /**
22  * @addtogroup CAPI_DALI_ACTORS_MODULE
23  * @{
24  */
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/object/ref-object.h>
28 #include <dali/public-api/actors/actor.h>
29 #include <dali/public-api/math/rect.h>
30 #include <dali/public-api/math/vector3.h>
31 #include <dali/public-api/images/frame-buffer-image.h>
32
33 namespace Dali DALI_IMPORT_API
34 {
35
36 namespace Internal DALI_INTERNAL
37 {
38 class Layer;
39 }
40
41 /**
42  * @brief Rectangle describing area on screen that a layer can draw to.
43  *
44  * @see Dali::Layer::SetClippingBox()
45  */
46 typedef Rect<int> ClippingBox;
47
48 /**
49  * @brief Layers provide a mechanism for overlaying groups of actors on top of each other.
50  *
51  * When added to the stage, a layer can be ordered relative to other layers. The bottom
52  * layer is at depth zero. The stage provides a default layer for it's children.
53  *
54  * Layered actors inherit position etc. as normal, but are drawn in an order determined
55  * by the layers. The depth buffer is cleared before each layer is rendered unless depth
56  * test is disabled or there's no need for it based on the layers contents;
57  * actors in lower layers cannot obscure actors in higher layers.
58  *
59  * If depth test is disabled, there is no performance overhead from clearing the depth buffer.
60  */
61 class DALI_IMPORT_API Layer : public Actor
62 {
63 public:
64
65   // Default Properties additional to Actor
66   static const Property::Index CLIPPING_ENABLE; ///< name "clipping-enable",  type BOOLEAN
67   static const Property::Index CLIPPING_BOX;    ///< name "clipping-box",     type RECTANGLE
68
69   // Action Names
70   static const char* const ACTION_RAISE;           ///< name "raise"
71   static const char* const ACTION_LOWER;           ///< name "lower"
72   static const char* const ACTION_RAISE_TO_TOP;    ///< name "raise-to-top"
73   static const char* const ACTION_LOWER_TO_BOTTOM; ///< name "lower-to-bottom"
74
75   /**
76    * @brief The sort function type.
77    *
78    * The position value is the actor translation from camera.
79    * The sortModifier is the user value that can be used to sort coplanar actors/nodes. This value is
80    * the one set by calling RenderableActor::SetSortModifier().
81    *
82    * A high return value means that the actor will be positioned further away by the sort algorithm.
83    * @see RenderableActor::SetSortModifier
84    */
85   typedef float (*SortFunctionType)(const Vector3& position, float sortModifier);
86
87   /**
88    * @brief Create an empty Layer handle.
89    *
90    * This can be initialised with Layer::New(...)
91    */
92   Layer();
93
94   /**
95    * @brief Create a Layer object.
96    *
97    * @return A handle to a newly allocated Layer
98    */
99   static Layer New();
100
101   /**
102    * @brief Downcast an Object handle to Layer.
103    *
104    * If handle points to a Layer the downcast produces valid
105    * handle. If not the returned handle is left uninitialized.
106    * @param[in] handle to An object
107    * @return handle to a Layer or an uninitialized handle
108    */
109   static Layer DownCast( BaseHandle handle );
110
111   /**
112    * @brief Virtual destructor.
113    *
114    * Dali::Object derived classes typically do not contain member data.
115    */
116   virtual ~Layer();
117
118   /**
119    * @copydoc Dali::BaseHandle::operator=
120    */
121   using BaseHandle::operator=;
122
123   /**
124    * @brief Query the depth of the layer
125    *
126    * 0 is bottom most layer, higher number is on top
127    * @pre layer is on the stage
128    * If layer is not added to the stage, returns 0.
129    * @return the current depth of the layer.
130    */
131   unsigned int GetDepth() const;
132
133   /**
134    * @brief Increment the depth of the layer.
135    *
136    * @pre layer is on the stage
137    */
138   void Raise();
139
140   /**
141    * @brief Decrement the depth of the layer.
142    *
143    * @pre layer is on the stage
144    */
145   void Lower();
146
147   /**
148    * @brief Ensures the layers depth is greater than the target layer.
149    *
150    * If the layer already is above target layer its depth is not changed
151    * If the layer was below target, its new depth will be immediately above target
152    * Note! All layers between this layer and target get new depth values
153    * @pre layer is on the stage
154    * @pre target layer is on the stage
155    * @param target layer to get above of
156    */
157   void RaiseAbove( Layer target );
158
159   /**
160    * @brief Ensures the layers depth is less than the target layer.
161    *
162    * If the layer already is below the layer its depth is not changed
163    * If the layer was above target, its new depth will be immediately below target
164    * Note! All layers between this layer and target get new depth values
165    * @pre layer is on the stage
166    * @pre target layer is on the stage
167    * @param target layer to get below of
168    */
169   void LowerBelow( Layer target );
170
171   /**
172    * @brief Raises the layer to the top.
173    * @pre layer is on the stage
174    */
175   void RaiseToTop();
176
177   /**
178    * @brief Lowers the layer to the bottom.
179    * @pre layer is on the stage
180    */
181   void LowerToBottom();
182
183   /**
184    * @brief Moves the layer directly above the given layer.
185    *
186    * After the call this layers depth will be immediately above target
187    * Note! All layers between this layer and target get new depth values
188    * @pre layer is on the stage
189    * @pre target layer is on the stage
190    * @param target layer to get on top of
191    */
192   void MoveAbove( Layer target );
193
194   /**
195    * @brief Moves the layer directly below the given layer.
196    *
197    * After the call this layers depth will be immediately below target
198    * Note! All layers between this layer and target get new depth values
199    * @pre layer is on the stage
200    * @pre target layer is on the stage
201    * @param target layer to get below of
202    */
203   void MoveBelow( Layer target );
204
205   /**
206    * @brief Sets whether clipping is enabled for a layer.
207    *
208    * Clipping is initially disabled; see also SetClippingBox().
209    * @param [in] enabled True if clipping is enabled.
210    */
211   void SetClipping(bool enabled);
212
213   /**
214    * @brief Query whether clipping is enabled for a layer.
215    * @return True if clipping is enabled.
216    */
217   bool IsClipping() const;
218
219   /**
220    * @brief Sets the clipping box of a layer, in window coordinates.
221    *
222    * The contents of the layer will not be visible outside this box, when clipping is
223    * enabled. The default clipping box is empty (0,0,0,0).
224    * This has the limitation that it only applies to rectangles on a window.
225    * For other kinds of clipping, @see Dali::Actor::SetDrawMode().
226    * @param [in] x The X-coordinate of the lower-left corner.
227    * @param [in] y The Y-coordinate of the lower-left corner.
228    * @param [in] width  The width of the box.
229    * @param [in] height The height of the box.
230    */
231   void SetClippingBox(int x, int y, int width, int height);
232
233   /**
234    * @brief Sets the clipping box of a layer, in window coordinates.
235    *
236    * The contents of the layer will not be visible outside this box, when clipping is
237    * enabled. The default clipping box is empty (0,0,0,0).
238    * @param [in] box The clipping box
239    */
240   void SetClippingBox(ClippingBox box);
241
242   /**
243    * @brief Retrieves the clipping box of a layer, in window coordinates.
244    *
245    * @return The clipping box
246    */
247   ClippingBox GetClippingBox() const;
248
249   // Depth test
250
251   /**
252    * @brief Whether to disable the depth test.
253    *
254    * By default a layer enables depth test if there is more than one opaque actor or if there is one opaque actor and one, or more, transparent actors.
255    * However, it's possible to disable the depth test by calling this method.
256    *
257    * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
258    */
259   void SetDepthTestDisabled( bool disable );
260
261   /**
262    * @brief Retrieves whether depth test is disabled.
263    *
264    * @return \e true if depth test is disabled.
265    */
266   bool IsDepthTestDisabled() const;
267
268   // Sorting
269
270   /**
271    * @brief This sort function sorts translucent actors according to the Z-value in view space.
272    *
273    * This is useful for 2D user interfaces.
274    *
275    * This is the default sorting function.
276    *
277    * We return a negative z value as in our translation, a low z means that it should
278    * be sorted further away and a high z means that it should be closer.
279    * @param[in] position     position of actor in view space
280    * @param[in] sortModifier additional sort modifer
281    * @return depth
282    */
283   static float ZValue(const Vector3& position, float sortModifier);
284
285   /**
286    * @brief This allows the user to specify the sort function that the layer should use.
287    *
288    * The sort function is used to determine the order in which the actors are drawn
289    * and input is processed on the actors in the layer.
290    *
291    * A function of the following type should be used:
292    * @code
293    *  float YourSortFunction(const Vector3& position, float sortModifier);
294    * @endcode
295    *
296    * @note If the sort function returns a low number, the actor the data applies to will be
297    * drawn in front of an actor whose data yields a high value from the sort function.
298    *
299    * @note All child layers use the same sort function.  If a child layer is added to this
300    * layer then the sort function used by the child layer will also be the same.
301    *
302    * @param[in]  function  The sort function pointer
303   */
304   void SetSortFunction( SortFunctionType function );
305
306   /**
307    * @brief This allows the user to specify whether this layer should consume touch (including gestures).
308    *
309    * If set, any layers behind this layer will not be hit-test.
310    *
311    * @param[in]  consume  Whether the layer should consume touch (including gestures).
312    */
313   void SetTouchConsumed( bool consume );
314
315   /**
316    * @brief Retrieves whether the layer consumes touch (including gestures).
317    *
318    * @return true if consuming touch, false otherwise.
319    */
320   bool IsTouchConsumed() const;
321
322 public: // Not intended for application developers
323
324   /**
325    * @brief This constructor is used by Dali New() methods.
326    *
327    * @param [in] Layer A pointer to a newly allocated Dali resource
328    */
329   explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
330 };
331
332 } // namespace Dali
333
334 /**
335  * @}
336  */
337 #endif //__DALI_LAYER_H__