1 #ifndef __DALI_LAYER_H__
2 #define __DALI_LAYER_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
28 namespace Dali DALI_IMPORT_API
31 namespace Internal DALI_INTERNAL
37 * @brief Rectangle describing area on screen that a layer can draw to.
39 * @see Dali::Layer::SetClippingBox()
41 typedef Rect<int> ClippingBox;
44 * @brief Layers provide a mechanism for overlaying groups of actors on top of each other.
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.
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.
54 * If depth test is disabled, there is no performance overhead from clearing the depth buffer.
56 class DALI_IMPORT_API Layer : public Actor
60 // Default Properties additional to Actor
61 static const Property::Index CLIPPING_ENABLE; ///< name "clipping-enable", type BOOLEAN
62 static const Property::Index CLIPPING_BOX; ///< name "clipping-box", type RECTANGLE
65 static const char* const ACTION_RAISE; ///< name "raise"
66 static const char* const ACTION_LOWER; ///< name "lower"
67 static const char* const ACTION_RAISE_TO_TOP; ///< name "raise-to-top"
68 static const char* const ACTION_LOWER_TO_BOTTOM; ///< name "lower-to-bottom"
71 * @brief The sort function type.
73 * The position value is the actor translation from camera.
74 * The sortModifier is the user value that can be used to sort coplanar actors/nodes. This value is
75 * the one set by calling RenderableActor::SetSortModifier().
77 * A high return value means that the actor will be positioned further away by the sort algorithm.
78 * @see RenderableActor::SetSortModifier
80 typedef float (*SortFunctionType)(const Vector3& position, float sortModifier);
83 * @brief Create an empty Layer handle.
85 * This can be initialised with Layer::New(...)
90 * @brief Create a Layer object.
92 * @return A handle to a newly allocated Layer
97 * @brief Downcast an Object handle to Layer.
99 * If handle points to a Layer the downcast produces valid
100 * handle. If not the returned handle is left uninitialized.
101 * @param[in] handle to An object
102 * @return handle to a Layer or an uninitialized handle
104 static Layer DownCast( BaseHandle handle );
109 * This is non-virtual since derived Handle types must not contain data or virtual methods.
114 * @copydoc Dali::BaseHandle::operator=
116 using BaseHandle::operator=;
119 * @brief Query the depth of the layer
121 * 0 is bottom most layer, higher number is on top
122 * @pre layer is on the stage
123 * If layer is not added to the stage, returns 0.
124 * @return the current depth of the layer.
126 unsigned int GetDepth() const;
129 * @brief Increment the depth of the layer.
131 * @pre layer is on the stage
136 * @brief Decrement the depth of the layer.
138 * @pre layer is on the stage
143 * @brief Ensures the layers depth is greater than the target layer.
145 * If the layer already is above target layer its depth is not changed
146 * If the layer was below target, its new depth will be immediately above target
147 * Note! All layers between this layer and target get new depth values
148 * @pre layer is on the stage
149 * @pre target layer is on the stage
150 * @param target layer to get above of
152 void RaiseAbove( Layer target );
155 * @brief Ensures the layers depth is less than the target layer.
157 * If the layer already is below the layer its depth is not changed
158 * If the layer was above target, its new depth will be immediately below target
159 * Note! All layers between this layer and target get new depth values
160 * @pre layer is on the stage
161 * @pre target layer is on the stage
162 * @param target layer to get below of
164 void LowerBelow( Layer target );
167 * @brief Raises the layer to the top.
168 * @pre layer is on the stage
173 * @brief Lowers the layer to the bottom.
174 * @pre layer is on the stage
176 void LowerToBottom();
179 * @brief Moves the layer directly above the given layer.
181 * After the call this layers depth will be immediately above target
182 * Note! All layers between this layer and target get new depth values
183 * @pre layer is on the stage
184 * @pre target layer is on the stage
185 * @param target layer to get on top of
187 void MoveAbove( Layer target );
190 * @brief Moves the layer directly below the given layer.
192 * After the call this layers depth will be immediately below 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 below of
198 void MoveBelow( Layer target );
201 * @brief Sets whether clipping is enabled for a layer.
203 * Clipping is initially disabled; see also SetClippingBox().
204 * @param [in] enabled True if clipping is enabled.
206 void SetClipping(bool enabled);
209 * @brief Query whether clipping is enabled for a layer.
210 * @return True if clipping is enabled.
212 bool IsClipping() const;
215 * @brief Sets the clipping box of a layer, in window coordinates.
217 * The contents of the layer will not be visible outside this box, when clipping is
218 * enabled. The default clipping box is empty (0,0,0,0).
219 * This has the limitation that it only applies to rectangles on a window.
220 * For other kinds of clipping, @see Dali::Actor::SetDrawMode().
221 * @param [in] x The X-coordinate of the lower-left corner.
222 * @param [in] y The Y-coordinate of the lower-left corner.
223 * @param [in] width The width of the box.
224 * @param [in] height The height of the box.
226 void SetClippingBox(int x, int y, int width, int height);
229 * @brief Sets the clipping box of a layer, in window coordinates.
231 * The contents of the layer will not be visible outside this box, when clipping is
232 * enabled. The default clipping box is empty (0,0,0,0).
233 * @param [in] box The clipping box
235 void SetClippingBox(ClippingBox box);
238 * @brief Retrieves the clipping box of a layer, in window coordinates.
240 * @return The clipping box
242 ClippingBox GetClippingBox() const;
247 * @brief Whether to disable the depth test.
249 * 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.
250 * However, it's possible to disable the depth test by calling this method.
252 * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
254 void SetDepthTestDisabled( bool disable );
257 * @brief Retrieves whether depth test is disabled.
259 * @return \e true if depth test is disabled.
261 bool IsDepthTestDisabled() const;
266 * @brief This sort function sorts translucent actors according to the Z-value in view space.
268 * This is useful for 2D user interfaces.
270 * This is the default sorting function.
272 * We return a negative z value as in our translation, a low z means that it should
273 * be sorted further away and a high z means that it should be closer.
274 * @param[in] position position of actor in view space
275 * @param[in] sortModifier additional sort modifer
278 static float ZValue(const Vector3& position, float sortModifier);
281 * @brief This allows the user to specify the sort function that the layer should use.
283 * The sort function is used to determine the order in which the actors are drawn
284 * and input is processed on the actors in the layer.
286 * A function of the following type should be used:
288 * float YourSortFunction(const Vector3& position, float sortModifier);
291 * @note If the sort function returns a low number, the actor the data applies to will be
292 * drawn in front of an actor whose data yields a high value from the sort function.
294 * @note All child layers use the same sort function. If a child layer is added to this
295 * layer then the sort function used by the child layer will also be the same.
297 * @param[in] function The sort function pointer
299 void SetSortFunction( SortFunctionType function );
302 * @brief This allows the user to specify whether this layer should consume touch (including gestures).
304 * If set, any layers behind this layer will not be hit-test.
306 * @param[in] consume Whether the layer should consume touch (including gestures).
308 void SetTouchConsumed( bool consume );
311 * @brief Retrieves whether the layer consumes touch (including gestures).
313 * @return true if consuming touch, false otherwise.
315 bool IsTouchConsumed() const;
317 public: // Not intended for application developers
320 * @brief This constructor is used by Dali New() methods.
322 * @param [in] Layer A pointer to a newly allocated Dali resource
324 explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
329 #endif //__DALI_LAYER_H__