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 * @addtogroup dali_core_actors
35 namespace Internal DALI_INTERNAL
41 * @brief Rectangle describing area on screen that a layer can draw to.
44 * @see Dali::Layer::SetClippingBox()
46 typedef Rect<int> ClippingBox;
49 * @brief Layers provide a mechanism for overlaying groups of actors on top of each other.
51 * When added to the stage, a layer can be ordered relative to other layers. The bottom
52 * layer is at depth zero. The stage provides a default layer for it's children.
54 * Layered actors inherit position etc. as normal, but are drawn in an order determined
55 * by the layers. The depth buffer is cleared before each layer is rendered unless depth
56 * test is disabled or there's no need for it based on the layers contents;
57 * actors in lower layers cannot obscure actors in higher layers.
59 * If depth test is disabled, there is no performance overhead from clearing the depth buffer.
62 * | %Action Name | %Layer method called |
63 * |-----------------|----------------------|
64 * | raise | @ref Raise() |
65 * | lower | @ref Lower() |
66 * | raiseToTop | @ref RaiseToTop() |
67 * | lowerToBottom | @ref LowerToBottom() |
70 class DALI_IMPORT_API Layer : public Actor
75 * @brief An enumeration of properties belonging to the Layer class.
76 * Properties additional to Actor.
83 CLIPPING_ENABLE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "clippingEnable", type bool @SINCE_1_0.0
84 CLIPPING_BOX, ///< name "clippingBox", type Rect<int> @SINCE_1_0.0
85 BEHAVIOR, ///< name "behavior", type String @SINCE_1_0.0
90 * @brief Enumeration for the behavior of the layer.
92 * Check each value to see how it affects the layer.
98 * @brief Layer doesn't make use of the depth test.
100 * This mode is expected to have better performance than the 3D mode.
101 * When using this mode any ordering would be with respect to depthIndex property of Renderers.
107 * @brief Layer will use depth test and do several clears.
109 * When using this mode depth depth test will be used. A depth clear will happen for each distinct
110 * depth-index value in the layer, opaque renderers are drawn first and write to the depth buffer.
111 * Then transparent renderers are drawn with depth test enabled but depth write switched off.
118 * TREE_DEPTH_MULTIPLIER is used by the rendering sorting algorithm to decide which actors to render first.
119 * For 2D layers, this value will be multiplied to the actor depth in the tree and added to the depth index
120 * to obtain the value which will be used for ordering
122 enum TreeDepthMultiplier
124 TREE_DEPTH_MULTIPLIER = 10000,
127 * @brief The sort function type.
130 * @param[in] position this is the actor translation from camera.
132 typedef float (*SortFunctionType)( const Vector3& position );
135 * @brief Create an empty Layer handle.
137 * This can be initialised with Layer::New(...)
143 * @brief Create a Layer object.
146 * @return A handle to a newly allocated Layer
151 * @brief Downcast an Object handle to Layer.
153 * If handle points to a Layer the downcast produces valid
154 * handle. If not the returned handle is left uninitialized.
156 * @param[in] handle to An object
157 * @return handle to a Layer or an uninitialized handle
159 static Layer DownCast( BaseHandle handle );
164 * This is non-virtual since derived Handle types must not contain data or virtual methods.
170 * @brief Copy constructor
173 * @param [in] copy The actor to copy.
175 Layer(const Layer& copy);
178 * @brief Assignment operator
181 * @param [in] rhs The actor to copy.
183 Layer& operator=(const Layer& rhs);
186 * @brief Query the depth of the layer
188 * 0 is bottom most layer, higher number is on top
190 * @return the current depth of the layer.
191 * @pre layer is on the stage
192 * If layer is not added to the stage, returns 0.
194 unsigned int GetDepth() const;
197 * @brief Increment the depth of the layer.
200 * @pre layer is on the stage
205 * @brief Decrement the depth of the layer.
208 * @pre layer is on the stage
213 * @brief Ensures the layers depth is greater than the target layer.
215 * If the layer already is above target layer its depth is not changed
216 * If the layer was below target, its new depth will be immediately above target
217 * Note! All layers between this layer and target get new depth values
219 * @param target layer to get above of
220 * @pre layer is on the stage
221 * @pre target layer is on the stage
223 void RaiseAbove( Layer target );
226 * @brief Ensures the layers depth is less than the target layer.
228 * If the layer already is below the layer its depth is not changed
229 * If the layer was above target, its new depth will be immediately below target
230 * Note! All layers between this layer and target get new depth values
232 * @param target layer to get below of
233 * @pre layer is on the stage
234 * @pre target layer is on the stage
236 void LowerBelow( Layer target );
239 * @brief Raises the layer to the top.
241 * @pre layer is on the stage
246 * @brief Lowers the layer to the bottom.
248 * @pre layer is on the stage
250 void LowerToBottom();
253 * @brief Moves the layer directly above the given layer.
255 * After the call this layers depth will be immediately above target
256 * Note! All layers between this layer and target get new depth values
258 * @param target layer to get on top of
259 * @pre layer is on the stage
260 * @pre target layer is on the stage
262 void MoveAbove( Layer target );
265 * @brief Moves the layer directly below the given layer.
267 * After the call this layers depth will be immediately below target
268 * Note! All layers between this layer and target get new depth values
270 * @param target layer to get below of
271 * @pre layer is on the stage
272 * @pre target layer is on the stage
274 void MoveBelow( Layer target );
277 * @brief Set the behavior of the layer
280 * @param[in] behavior The desired behavior
282 void SetBehavior( Behavior behavior );
285 * @brief Get the behavior of the layer
288 * @return The behavior of the layer
290 Behavior GetBehavior() const;
293 * @brief Sets whether clipping is enabled for a layer.
295 * Clipping is initially disabled; see also SetClippingBox().
297 * @param [in] enabled True if clipping is enabled.
299 * @note When clipping is enabled, the default clipping box is empty (0,0,0,0) which means everything is clipped.
301 void SetClipping(bool enabled);
304 * @brief Query whether clipping is enabled for a layer.
306 * @return True if clipping is enabled.
308 bool IsClipping() const;
311 * @brief Sets the clipping box of a layer, in window coordinates.
313 * The contents of the layer will not be visible outside this box, when clipping is
314 * enabled. The default clipping box is empty (0,0,0,0) which means everything is clipped.
315 * You can only do rectangular clipping using this API in window coordinates.
316 * For other kinds of clipping, @see Dali::Actor::SetDrawMode().
318 * @param [in] x The X-coordinate of the top-left corner of the box.
319 * @param [in] y The Y-coordinate of the top-left corner of the box.
320 * @param [in] width The width of the box.
321 * @param [in] height The height of the box.
323 void SetClippingBox(int x, int y, int width, int height);
326 * @brief Sets the clipping box of a layer, in window coordinates.
328 * The contents of the layer will not be visible outside this box, when clipping is
329 * enabled. The default clipping box is empty (0,0,0,0).
331 * @param [in] box The clipping box
333 void SetClippingBox(ClippingBox box);
336 * @brief Retrieves the clipping box of a layer, in window coordinates.
339 * @return The clipping box
341 ClippingBox GetClippingBox() const;
346 * @brief Whether to disable the depth test.
348 * 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.
349 * However, it's possible to disable the depth test by calling this method.
352 * @param[in] disable \e true disables depth test. \e false sets the default behavior.
354 void SetDepthTestDisabled( bool disable );
357 * @brief Retrieves whether depth test is disabled.
360 * @return \e true if depth test is disabled.
362 bool IsDepthTestDisabled() const;
367 * @brief This allows the user to specify the sort function that the layer should use.
369 * The sort function is used to determine the order in which the actors are drawn
370 * and input is processed on the actors in the layer.
372 * A function of the following type should be used:
374 * float YourSortFunction(const Vector3& position);
378 * @param[in] function The sort function pointer
379 * @note If the sort function returns a low number, the actor the data applies to will be
380 * drawn in front of an actor whose data yields a high value from the sort function.
382 * @note All child layers use the same sort function. If a child layer is added to this
383 * layer then the sort function used by the child layer will also be the same.
386 void SetSortFunction( SortFunctionType function );
389 * @brief This allows the user to specify whether this layer should consume touch (including gestures).
391 * If set, any layers behind this layer will not be hit-test.
394 * @param[in] consume Whether the layer should consume touch (including gestures).
396 void SetTouchConsumed( bool consume );
399 * @brief Retrieves whether the layer consumes touch (including gestures).
402 * @return true if consuming touch, false otherwise.
404 bool IsTouchConsumed() const;
407 * @brief This allows the user to specify whether this layer should consume hover.
409 * If set, any layers behind this layer will not be hit-test.
412 * @param[in] consume Whether the layer should consume hover.
414 void SetHoverConsumed( bool consume );
417 * @brief Retrieves whether the layer consumes hover.
420 * @return true if consuming hover, false otherwise.
422 bool IsHoverConsumed() const;
424 public: // Not intended for application developers
427 * @brief This constructor is used by Dali New() methods.
430 * @param [in] Layer A pointer to a newly allocated Dali resource
432 explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
440 #endif //__DALI_LAYER_H__