1 #ifndef __DALI_LAYER_H__
2 #define __DALI_LAYER_H__
5 * Copyright (c) 2015 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>
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.
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() |
64 class DALI_IMPORT_API Layer : public Actor
69 * @brief An enumeration of properties belonging to the Layer class.
70 * Properties additional to Actor.
76 CLIPPING_ENABLE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "clipping-enable", type bool
77 CLIPPING_BOX, ///< name "clipping-box", type Rect<int>
82 * @brief The sort function type.
84 * @param[in] position this is the actor translation from camera.
86 typedef float (*SortFunctionType)( const Vector3& position );
89 * @brief Create an empty Layer handle.
91 * This can be initialised with Layer::New(...)
96 * @brief Create a Layer object.
98 * @return A handle to a newly allocated Layer
103 * @brief Downcast an Object handle to Layer.
105 * If handle points to a Layer the downcast produces valid
106 * handle. If not the returned handle is left uninitialized.
107 * @param[in] handle to An object
108 * @return handle to a Layer or an uninitialized handle
110 static Layer DownCast( BaseHandle handle );
115 * This is non-virtual since derived Handle types must not contain data or virtual methods.
120 * @brief Copy constructor
122 * @param [in] copy The actor to copy.
124 Layer(const Layer& copy);
127 * @brief Assignment operator
129 * @param [in] rhs The actor to copy.
131 Layer& operator=(const Layer& rhs);
134 * @brief Query the depth of the layer
136 * 0 is bottom most layer, higher number is on top
137 * @pre layer is on the stage
138 * If layer is not added to the stage, returns 0.
139 * @return the current depth of the layer.
141 unsigned int GetDepth() const;
144 * @brief Increment the depth of the layer.
146 * @pre layer is on the stage
151 * @brief Decrement the depth of the layer.
153 * @pre layer is on the stage
158 * @brief Ensures the layers depth is greater than the target layer.
160 * If the layer already is above target layer its depth is not changed
161 * If the layer was below target, its new depth will be immediately above target
162 * Note! All layers between this layer and target get new depth values
163 * @pre layer is on the stage
164 * @pre target layer is on the stage
165 * @param target layer to get above of
167 void RaiseAbove( Layer target );
170 * @brief Ensures the layers depth is less than the target layer.
172 * If the layer already is below the layer its depth is not changed
173 * If the layer was above target, its new depth will be immediately below target
174 * Note! All layers between this layer and target get new depth values
175 * @pre layer is on the stage
176 * @pre target layer is on the stage
177 * @param target layer to get below of
179 void LowerBelow( Layer target );
182 * @brief Raises the layer to the top.
183 * @pre layer is on the stage
188 * @brief Lowers the layer to the bottom.
189 * @pre layer is on the stage
191 void LowerToBottom();
194 * @brief Moves the layer directly above the given layer.
196 * After the call this layers depth will be immediately above target
197 * Note! All layers between this layer and target get new depth values
198 * @pre layer is on the stage
199 * @pre target layer is on the stage
200 * @param target layer to get on top of
202 void MoveAbove( Layer target );
205 * @brief Moves the layer directly below the given layer.
207 * After the call this layers depth will be immediately below target
208 * Note! All layers between this layer and target get new depth values
209 * @pre layer is on the stage
210 * @pre target layer is on the stage
211 * @param target layer to get below of
213 void MoveBelow( Layer target );
216 * @brief Sets whether clipping is enabled for a layer.
218 * Clipping is initially disabled; see also SetClippingBox().
219 * @param [in] enabled True if clipping is enabled.
221 * @note When clipping is enabled, the default clipping box is empty (0,0,0,0) which means everything is clipped.
223 void SetClipping(bool enabled);
226 * @brief Query whether clipping is enabled for a layer.
227 * @return True if clipping is enabled.
229 bool IsClipping() const;
232 * @brief Sets the clipping box of a layer, in window coordinates.
234 * The contents of the layer will not be visible outside this box, when clipping is
235 * enabled. The default clipping box is empty (0,0,0,0) which means everything is clipped.
236 * You can only do rectangular clipping using this API in window coordinates.
237 * For other kinds of clipping, @see Dali::Actor::SetDrawMode().
238 * @param [in] x The X-coordinate of the top-left corner of the box.
239 * @param [in] y The Y-coordinate of the top-left corner of the box.
240 * @param [in] width The width of the box.
241 * @param [in] height The height of the box.
243 void SetClippingBox(int x, int y, int width, int height);
246 * @brief Sets the clipping box of a layer, in window coordinates.
248 * The contents of the layer will not be visible outside this box, when clipping is
249 * enabled. The default clipping box is empty (0,0,0,0).
250 * @param [in] box The clipping box
252 void SetClippingBox(ClippingBox box);
255 * @brief Retrieves the clipping box of a layer, in window coordinates.
257 * @return The clipping box
259 ClippingBox GetClippingBox() const;
264 * @brief Whether to disable the depth test.
266 * 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.
267 * However, it's possible to disable the depth test by calling this method.
269 * @param[in] disable \e true disables depth test. \e false sets the default behaviour.
271 void SetDepthTestDisabled( bool disable );
274 * @brief Retrieves whether depth test is disabled.
276 * @return \e true if depth test is disabled.
278 bool IsDepthTestDisabled() const;
283 * @brief This allows the user to specify the sort function that the layer should use.
285 * The sort function is used to determine the order in which the actors are drawn
286 * and input is processed on the actors in the layer.
288 * A function of the following type should be used:
290 * float YourSortFunction(const Vector3& position);
293 * @note If the sort function returns a low number, the actor the data applies to will be
294 * drawn in front of an actor whose data yields a high value from the sort function.
296 * @note All child layers use the same sort function. If a child layer is added to this
297 * layer then the sort function used by the child layer will also be the same.
299 * @param[in] function The sort function pointer
301 void SetSortFunction( SortFunctionType function );
304 * @brief This allows the user to specify whether this layer should consume touch (including gestures).
306 * If set, any layers behind this layer will not be hit-test.
308 * @param[in] consume Whether the layer should consume touch (including gestures).
310 void SetTouchConsumed( bool consume );
313 * @brief Retrieves whether the layer consumes touch (including gestures).
315 * @return true if consuming touch, false otherwise.
317 bool IsTouchConsumed() const;
320 * @brief This allows the user to specify whether this layer should consume hover.
322 * If set, any layers behind this layer will not be hit-test.
324 * @param[in] consume Whether the layer should consume hover.
326 void SetHoverConsumed( bool consume );
329 * @brief Retrieves whether the layer consumes hover.
331 * @return true if consuming hover, false otherwise.
333 bool IsHoverConsumed() const;
335 public: // Not intended for application developers
338 * @brief This constructor is used by Dali New() methods.
340 * @param [in] Layer A pointer to a newly allocated Dali resource
342 explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
347 #endif //__DALI_LAYER_H__