Merge "Fixed SizeMode not updating size on renderable in some cases" into tizen
[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) 2014 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 namespace Internal DALI_INTERNAL
32 {
33 class Layer;
34 }
35
36 /**
37  * @brief Rectangle describing area on screen that a layer can draw to.
38  *
39  * @see Dali::Layer::SetClippingBox()
40  */
41 typedef Rect<int> ClippingBox;
42
43 /**
44  * @brief Layers provide a mechanism for overlaying groups of actors on top of each other.
45  *
46  * When added to the stage, a layer can be ordered relative to other layers. The bottom
47  * layer is at depth zero. The stage provides a default layer for it's children.
48  *
49  * Layered actors inherit position etc. as normal, but are drawn in an order determined
50  * by the layers. The depth buffer is cleared before each layer is rendered unless depth
51  * test is disabled or there's no need for it based on the layers contents;
52  * actors in lower layers cannot obscure actors in higher layers.
53  *
54  * If depth test is disabled, there is no performance overhead from clearing the depth buffer.
55  *
56  * Actions
57  * | %Action Name    | %Layer method called |
58  * |-----------------|----------------------|
59  * | raise           | @ref Raise()         |
60  * | lower           | @ref Lower()         |
61  * | raise-to-top    | @ref RaiseToTop()    |
62  * | lower-to-bottom | @ref LowerToBottom() |
63  */
64 class DALI_IMPORT_API Layer : public Actor
65 {
66 public:
67
68   // Default Properties additional to Actor
69   static const Property::Index CLIPPING_ENABLE; ///< name "clipping-enable",  type BOOLEAN
70   static const Property::Index CLIPPING_BOX;    ///< name "clipping-box",     type RECTANGLE
71
72   /**
73    * @brief The sort function type.
74    *
75    * The position value is the actor translation from camera.
76    * The sortModifier is the user value that can be used to sort coplanar actors/nodes. This value is
77    * the one set by calling RenderableActor::SetSortModifier().
78    *
79    * A high return value means that the actor will be positioned further away by the sort algorithm.
80    * @see RenderableActor::SetSortModifier
81    */
82   typedef float (*SortFunctionType)(const Vector3& position, float sortModifier);
83
84   /**
85    * @brief Create an empty Layer handle.
86    *
87    * This can be initialised with Layer::New(...)
88    */
89   Layer();
90
91   /**
92    * @brief Create a Layer object.
93    *
94    * @return A handle to a newly allocated Layer
95    */
96   static Layer New();
97
98   /**
99    * @brief Downcast an Object handle to Layer.
100    *
101    * If handle points to a Layer the downcast produces valid
102    * handle. If not the returned handle is left uninitialized.
103    * @param[in] handle to An object
104    * @return handle to a Layer or an uninitialized handle
105    */
106   static Layer DownCast( BaseHandle handle );
107
108   /**
109    * @brief Destructor
110    *
111    * This is non-virtual since derived Handle types must not contain data or virtual methods.
112    */
113   ~Layer();
114
115   /**
116    * @brief Copy constructor
117    *
118    * @param [in] copy The actor to copy.
119    */
120   Layer(const Layer& copy);
121
122   /**
123    * @brief Assignment operator
124    *
125    * @param [in] rhs The actor to copy.
126    */
127   Layer& operator=(const Layer& rhs);
128
129   /**
130    * @brief Query the depth of the layer
131    *
132    * 0 is bottom most layer, higher number is on top
133    * @pre layer is on the stage
134    * If layer is not added to the stage, returns 0.
135    * @return the current depth of the layer.
136    */
137   unsigned int GetDepth() const;
138
139   /**
140    * @brief Increment the depth of the layer.
141    *
142    * @pre layer is on the stage
143    */
144   void Raise();
145
146   /**
147    * @brief Decrement the depth of the layer.
148    *
149    * @pre layer is on the stage
150    */
151   void Lower();
152
153   /**
154    * @brief Ensures the layers depth is greater than the target layer.
155    *
156    * If the layer already is above target layer its depth is not changed
157    * If the layer was below target, its new depth will be immediately above target
158    * Note! All layers between this layer and target get new depth values
159    * @pre layer is on the stage
160    * @pre target layer is on the stage
161    * @param target layer to get above of
162    */
163   void RaiseAbove( Layer target );
164
165   /**
166    * @brief Ensures the layers depth is less than the target layer.
167    *
168    * If the layer already is below the layer its depth is not changed
169    * If the layer was above target, its new depth will be immediately below target
170    * Note! All layers between this layer and target get new depth values
171    * @pre layer is on the stage
172    * @pre target layer is on the stage
173    * @param target layer to get below of
174    */
175   void LowerBelow( Layer target );
176
177   /**
178    * @brief Raises the layer to the top.
179    * @pre layer is on the stage
180    */
181   void RaiseToTop();
182
183   /**
184    * @brief Lowers the layer to the bottom.
185    * @pre layer is on the stage
186    */
187   void LowerToBottom();
188
189   /**
190    * @brief Moves the layer directly above the given layer.
191    *
192    * After the call this layers depth will be immediately above target
193    * Note! All layers between this layer and target get new depth values
194    * @pre layer is on the stage
195    * @pre target layer is on the stage
196    * @param target layer to get on top of
197    */
198   void MoveAbove( Layer target );
199
200   /**
201    * @brief Moves the layer directly below the given layer.
202    *
203    * After the call this layers depth will be immediately below target
204    * Note! All layers between this layer and target get new depth values
205    * @pre layer is on the stage
206    * @pre target layer is on the stage
207    * @param target layer to get below of
208    */
209   void MoveBelow( Layer target );
210
211   /**
212    * @brief Sets whether clipping is enabled for a layer.
213    *
214    * Clipping is initially disabled; see also SetClippingBox().
215    * @param [in] enabled True if clipping is enabled.
216    *
217    * @note When clipping is enabled, the default clipping box is empty (0,0,0,0) which means everything is clipped.
218    */
219   void SetClipping(bool enabled);
220
221   /**
222    * @brief Query whether clipping is enabled for a layer.
223    * @return True if clipping is enabled.
224    */
225   bool IsClipping() const;
226
227   /**
228    * @brief Sets the clipping box of a layer, in window coordinates.
229    *
230    * The contents of the layer will not be visible outside this box, when clipping is
231    * enabled. The default clipping box is empty (0,0,0,0) which means everything is clipped.
232    * You can only do rectangular clipping using this API in window coordinates.
233    * For other kinds of clipping, @see Dali::Actor::SetDrawMode().
234    * @param [in] x The X-coordinate of the top-left corner of the box.
235    * @param [in] y The Y-coordinate of the top-left corner of the box.
236    * @param [in] width  The width of the box.
237    * @param [in] height The height of the box.
238    */
239   void SetClippingBox(int x, int y, int width, int height);
240
241   /**
242    * @brief Sets the clipping box of a layer, in window coordinates.
243    *
244    * The contents of the layer will not be visible outside this box, when clipping is
245    * enabled. The default clipping box is empty (0,0,0,0).
246    * @param [in] box The clipping box
247    */
248   void SetClippingBox(ClippingBox box);
249
250   /**
251    * @brief Retrieves the clipping box of a layer, in window coordinates.
252    *
253    * @return The clipping box
254    */
255   ClippingBox GetClippingBox() const;
256
257   // Depth test
258
259   /**
260    * @brief Whether to disable the depth test.
261    *
262    * 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.
263    * However, it's possible to disable the depth test by calling this method.
264    *
265    * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
266    */
267   void SetDepthTestDisabled( bool disable );
268
269   /**
270    * @brief Retrieves whether depth test is disabled.
271    *
272    * @return \e true if depth test is disabled.
273    */
274   bool IsDepthTestDisabled() const;
275
276   // Sorting
277
278   /**
279    * @brief This sort function sorts translucent actors according to the Z-value in view space.
280    *
281    * This is useful for 2D user interfaces.
282    *
283    * This is the default sorting function.
284    *
285    * We return a negative z value as in our translation, a low z means that it should
286    * be sorted further away and a high z means that it should be closer.
287    * @param[in] position     position of actor in view space
288    * @param[in] sortModifier additional sort modifer
289    * @return depth
290    */
291   static float ZValue(const Vector3& position, float sortModifier);
292
293   /**
294    * @brief This allows the user to specify the sort function that the layer should use.
295    *
296    * The sort function is used to determine the order in which the actors are drawn
297    * and input is processed on the actors in the layer.
298    *
299    * A function of the following type should be used:
300    * @code
301    *  float YourSortFunction(const Vector3& position, float sortModifier);
302    * @endcode
303    *
304    * @note If the sort function returns a low number, the actor the data applies to will be
305    * drawn in front of an actor whose data yields a high value from the sort function.
306    *
307    * @note All child layers use the same sort function.  If a child layer is added to this
308    * layer then the sort function used by the child layer will also be the same.
309    *
310    * @param[in]  function  The sort function pointer
311   */
312   void SetSortFunction( SortFunctionType function );
313
314   /**
315    * @brief This allows the user to specify whether this layer should consume touch (including gestures).
316    *
317    * If set, any layers behind this layer will not be hit-test.
318    *
319    * @param[in]  consume  Whether the layer should consume touch (including gestures).
320    */
321   void SetTouchConsumed( bool consume );
322
323   /**
324    * @brief Retrieves whether the layer consumes touch (including gestures).
325    *
326    * @return true if consuming touch, false otherwise.
327    */
328   bool IsTouchConsumed() const;
329
330   /**
331    * @brief This allows the user to specify whether this layer should consume hover.
332    *
333    * If set, any layers behind this layer will not be hit-test.
334    *
335    * @param[in]  consume  Whether the layer should consume hover.
336    */
337   void SetHoverConsumed( bool consume );
338
339   /**
340    * @brief Retrieves whether the layer consumes hover.
341    *
342    * @return true if consuming hover, false otherwise.
343    */
344   bool IsHoverConsumed() const;
345
346 public: // Not intended for application developers
347
348   /**
349    * @brief This constructor is used by Dali New() methods.
350    *
351    * @param [in] Layer A pointer to a newly allocated Dali resource
352    */
353   explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
354 };
355
356 } // namespace Dali
357
358 #endif //__DALI_LAYER_H__