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