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