Remove deprecated APIs in Tizen 3.0
[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) 2018 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 String @SINCE_1_0.0
109     };
110   };
111
112   /**
113    * @brief Enumeration for the behavior of the layer.
114    *
115    * Check each value to see how it affects the layer.
116    * @SINCE_1_0.0
117    */
118   enum Behavior
119   {
120     /**
121      * @brief UI control rendering mode (default mode).
122      *
123      * This mode is designed for UI controls that can overlap. In this
124      * mode renderer order will be respective to the tree hierarchy of
125      * Actors.
126      *
127      * The rendering order is depth first, so for the following actor tree,
128      * A will be drawn first, then B, D, E, then C, F.  This ensures that
129      * overlapping actors are drawn as expected (whereas, with breadth first
130      * traversal, the actors would interleave).
131      *
132      * @code
133      *
134      *     Layer1 (parent)
135      *       |
136      *       A
137      *      / \
138      *     B   C
139      *    / \   \
140      *   D   E   F
141      *
142      * @endcode
143      *
144      * To change the order of sibling actors, use the Actor::Raise and
145      * Actor::Lower APIs. Within an actor, the Renderer depth index dictates
146      * the order the renderers are drawn.
147      *
148      * @SINCE_1_1.45
149      */
150     LAYER_UI,
151
152     /**
153      * @brief Layer will use depth test.
154      *
155      * This mode is designed for a 3 dimensional scene where actors in front
156      * of other actors will obscure them, i.e. the actors are sorted by the
157      * distance from the camera.
158      *
159      * When using this mode, a depth test will be used. A depth clear will
160      * happen for each layer, which means actors in a layer "above" other
161      * layers will be rendered in front of actors in those layers regardless
162      * of their Z positions (see Layer::Raise() and Layer::Lower()).
163      *
164      * Opaque renderers are drawn first and write to the depth buffer.  Then
165      * transparent renderers are drawn with depth test enabled but depth
166      * write switched off.  Transparent renderers are drawn based on their
167      * distance from the camera.  A renderer's DEPTH_INDEX property is used to
168      * offset the distance to the camera when ordering transparent renderers.
169      *
170      * This is useful if you want to define the draw order of two or more
171      * transparent renderers that are equal distance from the camera.  Unlike
172      * LAYER_UI, parent-child relationship does not affect rendering order at
173      * all.
174      *
175      * @SINCE_1_0.0
176      */
177     LAYER_3D
178
179   };
180
181   /**
182    * @DEPRECATED_1_2.26. Not intended for application use.
183    *
184    * @brief Enumeration for TREE_DEPTH_MULTIPLIER is used by the rendering sorting algorithm to decide which actors to render first.
185    * @SINCE_1_0.0
186    */
187   enum TreeDepthMultiplier
188   {
189     TREE_DEPTH_MULTIPLIER = 10000,
190   };
191
192   /**
193    * @brief The sort function type.
194    *
195    * @SINCE_1_0.0
196    * @param[in] position This is the actor translation from camera
197    */
198   typedef float (*SortFunctionType)( const Vector3& position );
199
200   /**
201    * @brief Creates an empty Layer handle.
202    *
203    * This can be initialized with Layer::New(...).
204    * @SINCE_1_0.0
205    */
206   Layer();
207
208   /**
209    * @brief Creates a Layer object.
210    *
211    * @SINCE_1_0.0
212    * @return A handle to a newly allocated Layer
213    */
214   static Layer New();
215
216   /**
217    * @brief Downcasts a handle to Layer handle.
218    *
219    * If handle points to a Layer, the downcast produces valid handle.
220    * If not, the returned handle is left uninitialized.
221    * @SINCE_1_0.0
222    * @param[in] handle Handle to an object
223    * @return Handle to a Layer or an uninitialized handle
224    */
225   static Layer DownCast( BaseHandle handle );
226
227   /**
228    * @brief Destructor.
229    *
230    * This is non-virtual since derived Handle types must not contain data or virtual methods.
231    * @SINCE_1_0.0
232    */
233   ~Layer();
234
235   /**
236    * @brief Copy constructor.
237    *
238    * @SINCE_1_0.0
239    * @param[in] copy The actor to copy
240    */
241   Layer(const Layer& copy);
242
243   /**
244    * @brief Assignment operator.
245    *
246    * @SINCE_1_0.0
247    * @param[in] rhs The actor to copy
248    * @return A reference to this
249    */
250   Layer& operator=(const Layer& rhs);
251
252   /**
253    * @brief Queries the depth of the layer.
254    *
255    * 0 is the bottom most layer, higher number is on top.
256    * @SINCE_1_0.0
257    * @return The current depth of the layer
258    * @pre Layer is on the stage.
259    * If layer is not added to the stage, returns 0.
260    */
261   uint32_t GetDepth() const;
262
263   /**
264    * @brief Increments the depth of the layer.
265    *
266    * @SINCE_1_0.0
267    * @pre Layer is on the stage.
268    */
269   void Raise();
270
271   /**
272    * @brief Decrements the depth of the layer.
273    *
274    * @SINCE_1_0.0
275    * @pre Layer is on the stage.
276    */
277   void Lower();
278
279   /**
280    * @brief Ensures the layers depth is greater than the target layer.
281    *
282    * If the layer already is above the target layer, its depth is not changed.
283    * If the layer was below target, its new depth will be immediately above target.
284    * @SINCE_1_0.0
285    * @param target Layer to get above of
286    * @pre Layer is on the stage.
287    * @pre Target layer is on the stage.
288    * @note All layers between this layer and target get new depth values.
289    */
290   void RaiseAbove( Layer target );
291
292   /**
293    * @brief Ensures the layers depth is less than the target layer.
294    *
295    * If the layer already is below the target layer, its depth is not changed.
296    * If the layer was above target, its new depth will be immediately below target.
297    * @SINCE_1_0.0
298    * @param target Layer to get below of
299    * @pre Layer is on the stage.
300    * @pre Target layer is on the stage.
301    * @note All layers between this layer and target get new depth values.
302    */
303   void LowerBelow( Layer target );
304
305   /**
306    * @brief Raises the layer to the top.
307    * @SINCE_1_0.0
308    * @pre Layer is on the stage.
309    */
310   void RaiseToTop();
311
312   /**
313    * @brief Lowers the layer to the bottom.
314    * @SINCE_1_0.0
315    * @pre layer is on the stage.
316    */
317   void LowerToBottom();
318
319   /**
320    * @brief Moves the layer directly above the given layer.
321    *
322    * After the call, this layers depth will be immediately above target.
323    * @SINCE_1_0.0
324    * @param target Layer to get on top of
325    * @pre Layer is on the stage.
326    * @pre Target layer is on the stage.
327    * @note All layers between this layer and target get new depth values.
328    */
329   void MoveAbove( Layer target );
330
331   /**
332    * @brief Moves the layer directly below the given layer.
333    *
334    * After the call, this layers depth will be immediately below target.
335    * @SINCE_1_0.0
336    * @param target Layer to get below of
337    * @pre Layer is on the stage.
338    * @pre Target layer is on the stage.
339    * @note All layers between this layer and target get new depth values.
340    */
341   void MoveBelow( Layer target );
342
343   /**
344    * @brief Sets the behavior of the layer.
345    *
346    * @SINCE_1_0.0
347    * @param[in] behavior The desired behavior
348    */
349   void SetBehavior( Behavior behavior );
350
351   /**
352    * @brief Gets the behavior of the layer.
353    *
354    * @SINCE_1_0.0
355    * @return The behavior of the layer
356    */
357   Behavior GetBehavior() const;
358
359   /**
360    * @brief Sets whether clipping is enabled for a layer.
361    *
362    * Clipping is initially disabled; see also SetClippingBox().
363    * @SINCE_1_0.0
364    * @param[in] enabled True if clipping is enabled
365    *
366    * @note When clipping is enabled, the default clipping box is empty (0,0,0,0), which means everything is clipped.
367    */
368   void SetClipping(bool enabled);
369
370   /**
371    * @brief Queries whether clipping is enabled for a layer.
372    * @SINCE_1_0.0
373    * @return True if clipping is enabled
374    */
375   bool IsClipping() const;
376
377   /**
378    * @brief Sets the clipping box of a layer, in window coordinates.
379    *
380    * The contents of the layer will not be visible outside this box, when clipping is
381    * enabled. The default clipping box is empty (0,0,0,0) which means everything is clipped.
382    * You can only do rectangular clipping using this API in window coordinates.
383    * @SINCE_1_0.0
384    * @param[in] x The X-coordinate of the top-left corner of the box
385    * @param[in] y The Y-coordinate of the top-left corner of the box
386    * @param[in] width The width of the box
387    * @param[in] height The height of the box
388    */
389   void SetClippingBox(int32_t x, int32_t y, int32_t width, int32_t height);
390
391   /**
392    * @brief Sets the clipping box of a layer in window coordinates.
393    *
394    * The contents of the layer will not be visible outside this box when clipping is
395    * enabled. The default clipping box is empty (0,0,0,0).
396    * @SINCE_1_0.0
397    * @param[in] box The clipping box
398    */
399   void SetClippingBox(ClippingBox box);
400
401   /**
402    * @brief Retrieves the clipping box of a layer in window coordinates.
403    *
404    * @SINCE_1_0.0
405    * @return The clipping box
406    */
407   ClippingBox GetClippingBox() const;
408
409   // Depth test
410
411   /**
412    * @brief Whether to disable the depth test.
413    *
414    * 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 in LAYER_3D mode.
415    * However, it's possible to disable the depth test by calling this method.
416    *
417    * @SINCE_1_0.0
418    * @param[in] disable \e True disables depth test. \e false sets the default behavior
419    */
420   void SetDepthTestDisabled( bool disable );
421
422   /**
423    * @brief Retrieves whether depth test is disabled.
424    *
425    * @SINCE_1_0.0
426    * @return \e True if depth test is disabled
427    */
428   bool IsDepthTestDisabled() const;
429
430   // Sorting
431
432   /**
433    * @brief This allows the user to specify the sort function that the layer should use.
434    *
435    * The sort function is used to determine the order in which the actors are drawn
436    * and input is processed on the actors in the layer.
437    *
438    * A function of the following type should be used:
439    * @code
440    *  float YourSortFunction(const Vector3& position);
441    * @endcode
442    *
443    * @SINCE_1_0.0
444    * @param[in] function The sort function pointer
445    * @note If the sort function returns a low number, the actor with the data will be
446    * drawn in front of an actor whose data yields a high value from the sort function.
447    *
448    * @note All child layers use the same sort function. If a child layer is added to this
449    * layer, then the sort function used by the child layer will also be the same.
450    *
451   */
452   void SetSortFunction( SortFunctionType function );
453
454   /**
455    * @brief This allows the user to specify whether this layer should consume touch (including gestures).
456    *
457    * If set, any layers behind this layer will not be hit-test.
458    *
459    * @SINCE_1_0.0
460    * @param[in] consume Whether the layer should consume touch (including gestures)
461    */
462   void SetTouchConsumed( bool consume );
463
464   /**
465    * @brief Retrieves whether the layer consumes touch (including gestures).
466    *
467    * @SINCE_1_0.0
468    * @return @c True if consuming touch, @c false otherwise
469    */
470   bool IsTouchConsumed() const;
471
472   /**
473    * @brief This allows the user to specify whether this layer should consume hover.
474    *
475    * If set, any layers behind this layer will not be hit-test.
476    *
477    * @SINCE_1_0.0
478    * @param[in] consume Whether the layer should consume hover
479    */
480   void SetHoverConsumed( bool consume );
481
482   /**
483    * @brief Retrieves whether the layer consumes hover.
484    *
485    * @SINCE_1_0.0
486    * @return @c True if consuming hover, @c false otherwise
487    */
488   bool IsHoverConsumed() const;
489
490 public: // Not intended for application developers
491
492   /// @cond internal
493   /**
494    * @brief This constructor is used by Layer::New() methods.
495    *
496    * @SINCE_1_0.0
497    * @param[in] Layer A pointer to a newly allocated Dali resource
498    */
499   explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
500   /// @endcond
501 };
502
503 /**
504  * @}
505  */
506 } // namespace Dali
507
508 #endif // DALI_LAYER_H