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