[dali_1.9.16] 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) 2020 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 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/ref-object.h>
26 #include <dali/public-api/actors/actor.h>
27 #include <dali/public-api/math/rect.h>
28 #include <dali/public-api/math/vector3.h>
29 #include <dali/public-api/images/frame-buffer-image.h>
30
31 namespace Dali
32 {
33 /**
34  * @addtogroup dali_core_actors
35  * @{
36  */
37
38 namespace Internal DALI_INTERNAL
39 {
40 class Layer;
41 }
42
43 /**
44  * @brief Rectangle describing area on screen that a layer can draw to.
45  *
46  * @SINCE_1_0.0
47  * @see Dali::Layer::SetClippingBox()
48  */
49 typedef Rect<int32_t> ClippingBox;
50
51 /**
52  * @brief Layers provide a mechanism for overlaying groups of actors on top of each other.
53  *
54  * When added to the stage, a layer can be ordered relative to other
55  * layers. The bottom layer is at depth zero. The stage provides a default
56  * layer for it's children (see Stage::GetRootLayer()).
57  *
58  * Layered actors inherit position etc. as normal, but are drawn in an order
59  * determined by the layers. In case of LAYER_3D, the depth buffer is cleared
60  * before each layer is rendered unless depth test is disabled or there's no
61  * need for it based on the layer's contents; actors in lower layers cannot
62  * obscure actors in higher layers.
63  *
64  * A layer has either LAYER_UI or LAYER_3D mode. LAYER_UI has better
65  * performance, the depth test is disabled, and a child actor hides its
66  * parent actor.  LAYER_3D uses the depth test, thus a close actor hides a
67  * farther one.  LAYER_UI is the default mode and recommended for general
68  * cases.  See Layer::Behavior and SetBehavior() for more information.
69  *
70  * Layer is a type of Actor, thus can have parent or children actors.  A
71  * layer influences rendering of its all descendant actors, until another
72  * layer appears in the actor tree and manages its own subtree.
73  *
74  * If depth test is disabled, there is no performance overhead from clearing
75  * the depth buffer.
76  *
77  * Actions
78  * | %Action Name    | %Layer method called |
79  * |-----------------|----------------------|
80  * | raise           | @ref Raise()         |
81  * | lower           | @ref Lower()         |
82  * | raiseToTop      | @ref RaiseToTop()    |
83  * | lowerToBottom   | @ref LowerToBottom() |
84  * @SINCE_1_0.0
85  */
86 class DALI_CORE_API Layer : public Actor
87 {
88 public:
89
90   /**
91    * @brief Enumeration for the instance of properties belonging to the Layer class.
92    *
93    * Properties additional to Actor.
94    * @SINCE_1_0.0
95    */
96   struct Property
97   {
98     /**
99      * @brief Enumeration for the instance of properties belonging to the Layer class.
100      *
101      * Properties additional to Actor.
102      * @SINCE_1_0.0
103      */
104     enum
105     {
106       CLIPPING_ENABLE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "clippingEnable",   type bool @SINCE_1_0.0
107       CLIPPING_BOX,                                                 ///< name "clippingBox",      type Rect<int32_t> @SINCE_1_0.0
108       BEHAVIOR,                                                     ///< name "behavior",         type integer or string @SINCE_1_0.0
109
110       /**
111        * @brief The current depth of the layer.
112        * @details Name "depth", type Property::INTEGER. Read-only
113        * @note 0 is the bottom most layer, higher number is on top.
114        * @note Layer should be on the stage. If layer is not added to the stage, the depth is 0.
115        * @SINCE_1_9.16
116        */
117       DEPTH,
118
119       /**
120        * @brief Whether to enable the depth test.
121        * @details Name "depthTest", type Property::BOOLEAN.
122        * @note By default a layer enables depth test if there is more than one opaque actor
123        * or if there is one opaque actor and one, or more, transparent actors in LAYER_3D mode.
124        * However, it's possible to disable the depth test by setting this property to False.
125        * @SINCE_1_9.16
126        */
127       DEPTH_TEST,
128
129       /**
130        * @brief Whether this layer should consume touch (including gestures).
131        * @details Name "consumesTouch", type Property::BOOLEAN.
132        * @note When this is True, any layers behind this layer will not be hit-test.
133        * @SINCE_1_9.16
134        */
135       CONSUMES_TOUCH,
136
137       /**
138        * @brief Whether this layer should consume hover (including gestures).
139        * @details Name "consumesHover", type Property::BOOLEAN.
140        * @note When this is True, any layers behind this layer will not be hit-test.
141        * @SINCE_1_9.16
142        */
143       CONSUMES_HOVER,
144     };
145   };
146
147   /**
148    * @brief Enumeration for the behavior of the layer.
149    *
150    * Check each value to see how it affects the layer.
151    * @SINCE_1_0.0
152    */
153   enum Behavior
154   {
155     /**
156      * @brief UI control rendering mode (default mode).
157      *
158      * This mode is designed for UI controls that can overlap. In this
159      * mode renderer order will be respective to the tree hierarchy of
160      * Actors.
161      *
162      * The rendering order is depth first, so for the following actor tree,
163      * A will be drawn first, then B, D, E, then C, F.  This ensures that
164      * overlapping actors are drawn as expected (whereas, with breadth first
165      * traversal, the actors would interleave).
166      *
167      * @code
168      *
169      *     Layer1 (parent)
170      *       |
171      *       A
172      *      / \
173      *     B   C
174      *    / \   \
175      *   D   E   F
176      *
177      * @endcode
178      *
179      * To change the order of sibling actors, use the Actor::Raise and
180      * Actor::Lower APIs. Within an actor, the Renderer depth index dictates
181      * the order the renderers are drawn.
182      *
183      * @SINCE_1_1.45
184      */
185     LAYER_UI,
186
187     /**
188      * @brief Layer will use depth test.
189      *
190      * This mode is designed for a 3 dimensional scene where actors in front
191      * of other actors will obscure them, i.e. the actors are sorted by the
192      * distance from the camera.
193      *
194      * When using this mode, a depth test will be used. A depth clear will
195      * happen for each layer, which means actors in a layer "above" other
196      * layers will be rendered in front of actors in those layers regardless
197      * of their Z positions (see Layer::Raise() and Layer::Lower()).
198      *
199      * Opaque renderers are drawn first and write to the depth buffer.  Then
200      * transparent renderers are drawn with depth test enabled but depth
201      * write switched off.  Transparent renderers are drawn based on their
202      * distance from the camera.  A renderer's DEPTH_INDEX property is used to
203      * offset the distance to the camera when ordering transparent renderers.
204      *
205      * This is useful if you want to define the draw order of two or more
206      * transparent renderers that are equal distance from the camera.  Unlike
207      * LAYER_UI, parent-child relationship does not affect rendering order at
208      * all.
209      *
210      * @SINCE_1_0.0
211      */
212     LAYER_3D
213
214   };
215
216   /**
217    * @DEPRECATED_1_2.26. Not intended for application use.
218    *
219    * @brief Enumeration for TREE_DEPTH_MULTIPLIER is used by the rendering sorting algorithm to decide which actors to render first.
220    * @SINCE_1_0.0
221    */
222   enum TreeDepthMultiplier
223   {
224     TREE_DEPTH_MULTIPLIER = 10000,
225   };
226
227   /**
228    * @brief The sort function type.
229    *
230    * @SINCE_1_0.0
231    * @param[in] position This is the actor translation from camera
232    */
233   typedef float (*SortFunctionType)( const Vector3& position );
234
235   /**
236    * @brief Creates an empty Layer handle.
237    *
238    * This can be initialized with Layer::New(...).
239    * @SINCE_1_0.0
240    */
241   Layer();
242
243   /**
244    * @brief Creates a Layer object.
245    *
246    * @SINCE_1_0.0
247    * @return A handle to a newly allocated Layer
248    */
249   static Layer New();
250
251   /**
252    * @brief Downcasts a handle to Layer handle.
253    *
254    * If handle points to a Layer, the downcast produces valid handle.
255    * If not, the returned handle is left uninitialized.
256    * @SINCE_1_0.0
257    * @param[in] handle Handle to an object
258    * @return Handle to a Layer or an uninitialized handle
259    */
260   static Layer DownCast( BaseHandle handle );
261
262   /**
263    * @brief Destructor.
264    *
265    * This is non-virtual since derived Handle types must not contain data or virtual methods.
266    * @SINCE_1_0.0
267    */
268   ~Layer();
269
270   /**
271    * @brief Copy constructor.
272    *
273    * @SINCE_1_0.0
274    * @param[in] copy The actor to copy
275    */
276   Layer(const Layer& copy);
277
278   /**
279    * @brief Assignment operator.
280    *
281    * @SINCE_1_0.0
282    * @param[in] rhs The actor to copy
283    * @return A reference to this
284    */
285   Layer& operator=(const Layer& rhs);
286
287   /**
288    * @brief Increments the depth of the layer.
289    *
290    * @SINCE_1_0.0
291    * @pre Layer is on the stage.
292    */
293   void Raise();
294
295   /**
296    * @brief Decrements the depth of the layer.
297    *
298    * @SINCE_1_0.0
299    * @pre Layer is on the stage.
300    */
301   void Lower();
302
303   /**
304    * @brief Ensures the layers depth is greater than the target layer.
305    *
306    * If the layer already is above the target layer, its depth is not changed.
307    * If the layer was below target, its new depth will be immediately above target.
308    * @SINCE_1_0.0
309    * @param target Layer to get above of
310    * @pre Layer is on the stage.
311    * @pre Target layer is on the stage.
312    * @note All layers between this layer and target get new depth values.
313    */
314   void RaiseAbove( Layer target );
315
316   /**
317    * @brief Ensures the layers depth is less than the target layer.
318    *
319    * If the layer already is below the target layer, its depth is not changed.
320    * If the layer was above target, its new depth will be immediately below target.
321    * @SINCE_1_0.0
322    * @param target Layer to get below of
323    * @pre Layer is on the stage.
324    * @pre Target layer is on the stage.
325    * @note All layers between this layer and target get new depth values.
326    */
327   void LowerBelow( Layer target );
328
329   /**
330    * @brief Raises the layer to the top.
331    * @SINCE_1_0.0
332    * @pre Layer is on the stage.
333    */
334   void RaiseToTop();
335
336   /**
337    * @brief Lowers the layer to the bottom.
338    * @SINCE_1_0.0
339    * @pre layer is on the stage.
340    */
341   void LowerToBottom();
342
343   /**
344    * @brief Moves the layer directly above the given layer.
345    *
346    * After the call, this layers depth will be immediately above target.
347    * @SINCE_1_0.0
348    * @param target Layer to get on top of
349    * @pre Layer is on the stage.
350    * @pre Target layer is on the stage.
351    * @note All layers between this layer and target get new depth values.
352    */
353   void MoveAbove( Layer target );
354
355   /**
356    * @brief Moves the layer directly below the given layer.
357    *
358    * After the call, this layers depth will be immediately below target.
359    * @SINCE_1_0.0
360    * @param target Layer to get below of
361    * @pre Layer is on the stage.
362    * @pre Target layer is on the stage.
363    * @note All layers between this layer and target get new depth values.
364    */
365   void MoveBelow( Layer target );
366
367   // Sorting
368
369   /**
370    * @brief This allows the user to specify the sort function that the layer should use.
371    *
372    * The sort function is used to determine the order in which the actors are drawn
373    * and input is processed on the actors in the layer.
374    *
375    * A function of the following type should be used:
376    * @code
377    *  float YourSortFunction(const Vector3& position);
378    * @endcode
379    *
380    * @SINCE_1_0.0
381    * @param[in] function The sort function pointer
382    * @note If the sort function returns a low number, the actor with the data will be
383    * drawn in front of an actor whose data yields a high value from the sort function.
384    *
385    * @note All child layers use the same sort function. If a child layer is added to this
386    * layer, then the sort function used by the child layer will also be the same.
387    *
388   */
389   void SetSortFunction( SortFunctionType function );
390
391   /**
392    * @brief Retrieves whether the layer consumes hover.
393    *
394    * @SINCE_1_0.0
395    * @return @c True if consuming hover, @c false otherwise
396    */
397   bool IsHoverConsumed() const;
398
399 public: // Not intended for application developers
400
401   /// @cond internal
402   /**
403    * @brief This constructor is used by Layer::New() methods.
404    *
405    * @SINCE_1_0.0
406    * @param[in] Layer A pointer to a newly allocated Dali resource
407    */
408   explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
409   /// @endcond
410 };
411
412 /**
413  * @}
414  */
415 } // namespace Dali
416
417 #endif // DALI_LAYER_H