Doxygen grouping
[platform/core/uifw/dali-core.git] / dali / public-api / actors / layer.h
1 #ifndef __DALI_LAYER_H__
2 #define __DALI_LAYER_H__
3
4 /*
5  * Copyright (c) 2015 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/public-api/object/ref-object.h>
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/math/vector3.h>
26 #include <dali/public-api/images/frame-buffer-image.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali-core-actors
32  * @{
33  */
34
35 namespace Internal DALI_INTERNAL
36 {
37 class Layer;
38 }
39
40 /**
41  * @brief Rectangle describing area on screen that a layer can draw to.
42  *
43  * @see Dali::Layer::SetClippingBox()
44  */
45 typedef Rect<int> ClippingBox;
46
47 /**
48  * @brief Layers provide a mechanism for overlaying groups of actors on top of each other.
49  *
50  * When added to the stage, a layer can be ordered relative to other layers. The bottom
51  * layer is at depth zero. The stage provides a default layer for it's children.
52  *
53  * Layered actors inherit position etc. as normal, but are drawn in an order determined
54  * by the layers. The depth buffer is cleared before each layer is rendered unless depth
55  * test is disabled or there's no need for it based on the layers contents;
56  * actors in lower layers cannot obscure actors in higher layers.
57  *
58  * If depth test is disabled, there is no performance overhead from clearing the depth buffer.
59  *
60  * Actions
61  * | %Action Name    | %Layer method called |
62  * |-----------------|----------------------|
63  * | raise           | @ref Raise()         |
64  * | lower           | @ref Lower()         |
65  * | raise-to-top    | @ref RaiseToTop()    |
66  * | lower-to-bottom | @ref LowerToBottom() |
67  */
68 class DALI_IMPORT_API Layer : public Actor
69 {
70 public:
71
72   /**
73    * @brief An enumeration of properties belonging to the Layer class.
74    * Properties additional to Actor.
75    */
76   struct Property
77   {
78     enum
79     {
80       CLIPPING_ENABLE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "clipping-enable",  type bool
81       CLIPPING_BOX,                                                 ///< name "clipping-box",     type Rect<int>
82       BEHAVIOR,                                                     ///< name "behavior",         type String
83     };
84   };
85
86   /**
87    * @brief Enumeration for the behavior of the layer.
88    *
89    * Check each value to see how it affects the layer.
90    */
91   enum Behavior
92   {
93     /**
94      * @brief Layer doesn't make use of the depth test.
95      *
96      * This mode is expected to have better performance than the 3D mode.
97      * When using this mode any ordering would be with respect to depth-index property of Renderers.
98      */
99     LAYER_2D,
100
101     /**
102      * @brief Layer will use depth test and do several clears.
103      *
104      * When using this mode depth depth test will be used. A depth clear will happen for each distinct
105      * depth-index value in the layer, opaque renderers are drawn first and write to the depth buffer.
106      * Then transparent renderers are drawn with depth test enabled but depth write switched off.
107      */
108     LAYER_3D,
109   };
110
111   /*
112    * TREE_DEPTH_MULTIPLIER is used by the rendering sorting algorithm to decide which actors to render first.
113    * For 2D layers, this value will be multiplied to the actor depth in the tree and added to the depth index
114    * to obtain the value which will be used for ordering
115    */
116   enum TreeDepthMultiplier
117   {
118     TREE_DEPTH_MULTIPLIER = 10000,
119   };
120   /**
121    * @brief The sort function type.
122    *
123    * @param[in] position this is the actor translation from camera.
124    */
125   typedef float (*SortFunctionType)( const Vector3& position );
126
127   /**
128    * @brief Create an empty Layer handle.
129    *
130    * This can be initialised with Layer::New(...)
131    */
132   Layer();
133
134   /**
135    * @brief Create a Layer object.
136    *
137    * @return A handle to a newly allocated Layer
138    */
139   static Layer New();
140
141   /**
142    * @brief Downcast an Object handle to Layer.
143    *
144    * If handle points to a Layer the downcast produces valid
145    * handle. If not the returned handle is left uninitialized.
146    * @param[in] handle to An object
147    * @return handle to a Layer or an uninitialized handle
148    */
149   static Layer DownCast( BaseHandle handle );
150
151   /**
152    * @brief Destructor
153    *
154    * This is non-virtual since derived Handle types must not contain data or virtual methods.
155    */
156   ~Layer();
157
158   /**
159    * @brief Copy constructor
160    *
161    * @param [in] copy The actor to copy.
162    */
163   Layer(const Layer& copy);
164
165   /**
166    * @brief Assignment operator
167    *
168    * @param [in] rhs The actor to copy.
169    */
170   Layer& operator=(const Layer& rhs);
171
172   /**
173    * @brief Query the depth of the layer
174    *
175    * 0 is bottom most layer, higher number is on top
176    * @pre layer is on the stage
177    * If layer is not added to the stage, returns 0.
178    * @return the current depth of the layer.
179    */
180   unsigned int GetDepth() const;
181
182   /**
183    * @brief Increment the depth of the layer.
184    *
185    * @pre layer is on the stage
186    */
187   void Raise();
188
189   /**
190    * @brief Decrement the depth of the layer.
191    *
192    * @pre layer is on the stage
193    */
194   void Lower();
195
196   /**
197    * @brief Ensures the layers depth is greater than the target layer.
198    *
199    * If the layer already is above target layer its depth is not changed
200    * If the layer was below target, its new depth will be immediately above target
201    * Note! All layers between this layer and target get new depth values
202    * @pre layer is on the stage
203    * @pre target layer is on the stage
204    * @param target layer to get above of
205    */
206   void RaiseAbove( Layer target );
207
208   /**
209    * @brief Ensures the layers depth is less than the target layer.
210    *
211    * If the layer already is below the layer its depth is not changed
212    * If the layer was above target, its new depth will be immediately below target
213    * Note! All layers between this layer and target get new depth values
214    * @pre layer is on the stage
215    * @pre target layer is on the stage
216    * @param target layer to get below of
217    */
218   void LowerBelow( Layer target );
219
220   /**
221    * @brief Raises the layer to the top.
222    * @pre layer is on the stage
223    */
224   void RaiseToTop();
225
226   /**
227    * @brief Lowers the layer to the bottom.
228    * @pre layer is on the stage
229    */
230   void LowerToBottom();
231
232   /**
233    * @brief Moves the layer directly above the given layer.
234    *
235    * After the call this layers depth will be immediately above target
236    * Note! All layers between this layer and target get new depth values
237    * @pre layer is on the stage
238    * @pre target layer is on the stage
239    * @param target layer to get on top of
240    */
241   void MoveAbove( Layer target );
242
243   /**
244    * @brief Moves the layer directly below the given layer.
245    *
246    * After the call this layers depth will be immediately below target
247    * Note! All layers between this layer and target get new depth values
248    * @pre layer is on the stage
249    * @pre target layer is on the stage
250    * @param target layer to get below of
251    */
252   void MoveBelow( Layer target );
253
254   /**
255    * @brief Set the behavior of the layer
256    *
257    * @param[in] behavior The desired behavior
258    */
259   void SetBehavior( Behavior behavior );
260
261   /**
262    * @brief Get the behavior of the layer
263    *
264    * @return The behavior of the layer
265    */
266   Behavior GetBehavior() const;
267
268   /**
269    * @brief Sets whether clipping is enabled for a layer.
270    *
271    * Clipping is initially disabled; see also SetClippingBox().
272    * @param [in] enabled True if clipping is enabled.
273    *
274    * @note When clipping is enabled, the default clipping box is empty (0,0,0,0) which means everything is clipped.
275    */
276   void SetClipping(bool enabled);
277
278   /**
279    * @brief Query whether clipping is enabled for a layer.
280    * @return True if clipping is enabled.
281    */
282   bool IsClipping() const;
283
284   /**
285    * @brief Sets the clipping box of a layer, in window coordinates.
286    *
287    * The contents of the layer will not be visible outside this box, when clipping is
288    * enabled. The default clipping box is empty (0,0,0,0) which means everything is clipped.
289    * You can only do rectangular clipping using this API in window coordinates.
290    * For other kinds of clipping, @see Dali::Actor::SetDrawMode().
291    * @param [in] x The X-coordinate of the top-left corner of the box.
292    * @param [in] y The Y-coordinate of the top-left corner of the box.
293    * @param [in] width  The width of the box.
294    * @param [in] height The height of the box.
295    */
296   void SetClippingBox(int x, int y, int width, int height);
297
298   /**
299    * @brief Sets the clipping box of a layer, in window coordinates.
300    *
301    * The contents of the layer will not be visible outside this box, when clipping is
302    * enabled. The default clipping box is empty (0,0,0,0).
303    * @param [in] box The clipping box
304    */
305   void SetClippingBox(ClippingBox box);
306
307   /**
308    * @brief Retrieves the clipping box of a layer, in window coordinates.
309    *
310    * @return The clipping box
311    */
312   ClippingBox GetClippingBox() const;
313
314   // Depth test
315
316   /**
317    * @brief Whether to disable the depth test.
318    *
319    * 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.
320    * However, it's possible to disable the depth test by calling this method.
321    *
322    * @param[in] disable \e true disables depth test. \e false sets the default behavior.
323    */
324   void SetDepthTestDisabled( bool disable );
325
326   /**
327    * @brief Retrieves whether depth test is disabled.
328    *
329    * @return \e true if depth test is disabled.
330    */
331   bool IsDepthTestDisabled() const;
332
333   // Sorting
334
335   /**
336    * @brief This allows the user to specify the sort function that the layer should use.
337    *
338    * The sort function is used to determine the order in which the actors are drawn
339    * and input is processed on the actors in the layer.
340    *
341    * A function of the following type should be used:
342    * @code
343    *  float YourSortFunction(const Vector3& position);
344    * @endcode
345    *
346    * @note If the sort function returns a low number, the actor the data applies to will be
347    * drawn in front of an actor whose data yields a high value from the sort function.
348    *
349    * @note All child layers use the same sort function.  If a child layer is added to this
350    * layer then the sort function used by the child layer will also be the same.
351    *
352    * @param[in]  function  The sort function pointer
353   */
354   void SetSortFunction( SortFunctionType function );
355
356   /**
357    * @brief This allows the user to specify whether this layer should consume touch (including gestures).
358    *
359    * If set, any layers behind this layer will not be hit-test.
360    *
361    * @param[in]  consume  Whether the layer should consume touch (including gestures).
362    */
363   void SetTouchConsumed( bool consume );
364
365   /**
366    * @brief Retrieves whether the layer consumes touch (including gestures).
367    *
368    * @return true if consuming touch, false otherwise.
369    */
370   bool IsTouchConsumed() const;
371
372   /**
373    * @brief This allows the user to specify whether this layer should consume hover.
374    *
375    * If set, any layers behind this layer will not be hit-test.
376    *
377    * @param[in]  consume  Whether the layer should consume hover.
378    */
379   void SetHoverConsumed( bool consume );
380
381   /**
382    * @brief Retrieves whether the layer consumes hover.
383    *
384    * @return true if consuming hover, false otherwise.
385    */
386   bool IsHoverConsumed() const;
387
388 public: // Not intended for application developers
389
390   /**
391    * @brief This constructor is used by Dali New() methods.
392    *
393    * @param [in] Layer A pointer to a newly allocated Dali resource
394    */
395   explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
396 };
397
398 /**
399  * @}
400  */
401 } // namespace Dali
402
403 #endif //__DALI_LAYER_H__