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