5 * Copyright (c) 2016 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 (see Stage::GetRootLayer()).
54 * Layered actors inherit position etc. as normal, but are drawn in an order determined
55 * by the layers. In case of LAYER_3D, 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 * A layer has either LAYER_2D or LAYER_3D mode. LAYER_2D has better performance,
60 * the depth test is disabled, and a child actor hides its parent actor.
61 * LAYER_3D uses the depth test, thus a close actor hides a farther one.
62 * LAYER_2D is the default mode and recommended for general cases.
63 * See Layer::Behavior and SetBehavior() for more information.
65 * Layer is a type of Actor, thus can have parent or children actors.
66 * A layer influences rendering of its all descendant actors,
67 * until another layer appears in the actor tree and manages its own subtree.
69 * If depth test is disabled, there is no performance overhead from clearing the depth buffer.
72 * | %Action Name | %Layer method called |
73 * |-----------------|----------------------|
74 * | raise | @ref Raise() |
75 * | lower | @ref Lower() |
76 * | raiseToTop | @ref RaiseToTop() |
77 * | lowerToBottom | @ref LowerToBottom() |
80 class DALI_IMPORT_API Layer : public Actor
85 * @brief An enumeration of properties belonging to the Layer class.
87 * Properties additional to Actor.
93 * @brief An enumeration of properties belonging to the Layer class.
95 * Properties additional to Actor.
100 CLIPPING_ENABLE = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "clippingEnable", type bool @SINCE_1_0.0
101 CLIPPING_BOX, ///< name "clippingBox", type Rect<int> @SINCE_1_0.0
102 BEHAVIOR, ///< name "behavior", type String @SINCE_1_0.0
107 * @brief Enumeration for the behavior of the layer.
109 * Check each value to see how it affects the layer.
115 * @DEPRECATED_1_1.45, use LAYER_UI instead
116 * @brief UI control rendering mode
123 * @brief UI control rendering mode (default mode).
125 * This mode is designed for UI controls. In this mode renderer order will be respective to tree hierarchy of Actors.
126 * This mode is expected to have better performance than LAYER_3D as renderers can be sorted more efficiently.
128 * For the following actor tree the rendering order will be A first, then B & C and finally D,E,F regardless of their
130 * Rendering order between siblings, such as D, E & F or B & C, is determined based on the renderers depth index.
131 * In UI we don't normally expect overlap. If you have two overlapped actors, make them parent-child to guarantee order of all renderers.
150 * @brief Layer will use depth test.
152 * When using this mode depth test will be used. A depth clear will happen for each layer,
153 * which means actors in a layer "above" other layers will be rendered in front of actors in
154 * those layers regardless of their Z positions (see Layer::Raise() and Layer::Lower()).
155 * Opaque renderers are drawn first and write to the depth buffer.
156 * Then transparent renderers are drawn with depth test enabled but depth write switched off.
157 * Transparent renderers are drawn based on their distance from the camera.
158 * A renderers DEPTH_INDEX property is used to offset the distance to the camera when ordering transparent renderers.
159 * This is useful if you want to define the draw order of two or more transparent renderers that are
160 * equal distance from the camera.
161 * Unlike LAYER_UI, parent-child relationship does not affect rendering order at all.
170 * @brief TREE_DEPTH_MULTIPLIER is used by the rendering sorting algorithm to decide which actors to render first.
173 enum TreeDepthMultiplier
175 TREE_DEPTH_MULTIPLIER = 10000,
178 * @brief The sort function type
181 * @param[in] position This is the actor translation from camera.
183 typedef float (*SortFunctionType)( const Vector3& position );
186 * @brief Create an empty Layer handle.
188 * This can be initialised with Layer::New(...).
194 * @brief Create a Layer object.
197 * @return A handle to a newly allocated Layer
202 * @brief Downcast a handle to Layer handle.
204 * If handle points to a Layer the downcast produces valid
205 * handle. If not the returned handle is left uninitialized.
207 * @param[in] handle Handle to An object
208 * @return Handle to a Layer or an uninitialized handle
210 static Layer DownCast( BaseHandle handle );
215 * This is non-virtual since derived Handle types must not contain data or virtual methods.
221 * @brief Copy constructor
224 * @param [in] copy The actor to copy
226 Layer(const Layer& copy);
229 * @brief Assignment operator
232 * @param [in] rhs The actor to copy
233 * @return A reference to this
235 Layer& operator=(const Layer& rhs);
238 * @brief Query the depth of the layer
240 * 0 is bottom most layer, higher number is on top.
242 * @return The current depth of the layer
243 * @pre Layer is on the stage.
244 * If layer is not added to the stage, returns 0.
246 unsigned int GetDepth() const;
249 * @brief Increment the depth of the layer.
252 * @pre Layer is on the stage.
257 * @brief Decrement the depth of the layer.
260 * @pre Layer is on the stage.
265 * @brief Ensures the layers depth is greater than the target layer.
267 * If the layer already is above the target layer its depth is not changed.
268 * If the layer was below target, its new depth will be immediately above target.
270 * @param target Layer to get above of
271 * @pre Layer is on the stage.
272 * @pre Target layer is on the stage.
273 * @note All layers between this layer and target get new depth values.
275 void RaiseAbove( Layer target );
278 * @brief Ensures the layers depth is less than the target layer.
280 * If the layer already is below the target layer its depth is not changed.
281 * If the layer was above target, its new depth will be immediately below target.
283 * @param target Layer to get below of
284 * @pre Layer is on the stage.
285 * @pre Target layer is on the stage.
286 * @note All layers between this layer and target get new depth values.
288 void LowerBelow( Layer target );
291 * @brief Raises the layer to the top.
293 * @pre Layer is on the stage.
298 * @brief Lowers the layer to the bottom.
300 * @pre layer is on the stage.
302 void LowerToBottom();
305 * @brief Moves the layer directly above the given layer.
307 * After the call this layers depth will be immediately above target.
309 * @param target Layer to get on top of
310 * @pre Layer is on the stage.
311 * @pre Target layer is on the stage.
312 * @note All layers between this layer and target get new depth values.
314 void MoveAbove( Layer target );
317 * @brief Moves the layer directly below the given layer.
319 * After the call this layers depth will be immediately below target.
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.
326 void MoveBelow( Layer target );
329 * @brief Set the behavior of the layer.
332 * @param[in] behavior The desired behavior
334 void SetBehavior( Behavior behavior );
337 * @brief Get the behavior of the layer.
340 * @return The behavior of the layer
342 Behavior GetBehavior() const;
345 * @brief Sets whether clipping is enabled for a layer.
347 * Clipping is initially disabled; see also SetClippingBox().
349 * @param [in] enabled True if clipping is enabled.
351 * @note When clipping is enabled, the default clipping box is empty (0,0,0,0) which means everything is clipped.
353 void SetClipping(bool enabled);
356 * @brief Query whether clipping is enabled for a layer.
358 * @return True if clipping is enabled.
360 bool IsClipping() const;
363 * @brief Sets the clipping box of a layer, in window coordinates.
365 * The contents of the layer will not be visible outside this box, when clipping is
366 * enabled. The default clipping box is empty (0,0,0,0) which means everything is clipped.
367 * You can only do rectangular clipping using this API in window coordinates.
369 * @param [in] x The X-coordinate of the top-left corner of the box
370 * @param [in] y The Y-coordinate of the top-left corner of the box
371 * @param [in] width The width of the box
372 * @param [in] height The height of the box
374 void SetClippingBox(int x, int y, int width, int height);
377 * @brief Sets the clipping box of a layer, in window coordinates.
379 * The contents of the layer will not be visible outside this box, when clipping is
380 * enabled. The default clipping box is empty (0,0,0,0).
382 * @param [in] box The clipping box
384 void SetClippingBox(ClippingBox box);
387 * @brief Retrieves the clipping box of a layer, in window coordinates.
390 * @return The clipping box
392 ClippingBox GetClippingBox() const;
397 * @brief Whether to disable the depth test.
399 * 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 in LAYER_3D mode.
400 * However, it's possible to disable the depth test by calling this method.
403 * @param[in] disable \e True disables depth test. \e false sets the default behavior.
405 void SetDepthTestDisabled( bool disable );
408 * @brief Retrieves whether depth test is disabled.
411 * @return \e True if depth test is disabled.
413 bool IsDepthTestDisabled() const;
418 * @brief This allows the user to specify the sort function that the layer should use.
420 * The sort function is used to determine the order in which the actors are drawn
421 * and input is processed on the actors in the layer.
423 * A function of the following type should be used:
425 * float YourSortFunction(const Vector3& position);
429 * @param[in] function The sort function pointer
430 * @note If the sort function returns a low number, the actor with the data will be
431 * drawn in front of an actor whose data yields a high value from the sort function.
433 * @note All child layers use the same sort function. If a child layer is added to this
434 * layer then the sort function used by the child layer will also be the same.
437 void SetSortFunction( SortFunctionType function );
440 * @brief This allows the user to specify whether this layer should consume touch (including gestures).
442 * If set, any layers behind this layer will not be hit-test.
445 * @param[in] consume Whether the layer should consume touch (including gestures).
447 void SetTouchConsumed( bool consume );
450 * @brief Retrieves whether the layer consumes touch (including gestures).
453 * @return True if consuming touch, false otherwise.
455 bool IsTouchConsumed() const;
458 * @brief This allows the user to specify whether this layer should consume hover.
460 * If set, any layers behind this layer will not be hit-test.
463 * @param[in] consume Whether the layer should consume hover.
465 void SetHoverConsumed( bool consume );
468 * @brief Retrieves whether the layer consumes hover.
471 * @return True if consuming hover, false otherwise.
473 bool IsHoverConsumed() const;
475 public: // Not intended for application developers
479 * @brief This constructor is used by Layer::New() methods.
482 * @param [in] Layer A pointer to a newly allocated Dali resource
484 explicit DALI_INTERNAL Layer(Internal::Layer* Layer);
492 #endif // DALI_LAYER_H