1 #ifndef DALI_INTERNAL_LAYER_H
2 #define DALI_INTERNAL_LAYER_H
5 * Copyright (c) 2018 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/actors/layer.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24 #include <dali/internal/event/actors/actor-declarations.h>
40 typedef Dali::ClippingBox ClippingBox;
42 class Layer : public Actor
47 * @copydoc Dali::Layer::ZValue(const Vector3&, float)
49 * This is the default sorting function.
50 * It is useful for 2D user interfaces, and it's used to sort translucent renderers.
52 * Only the Z signed distance from the camera is considererd, lower values will be drawn on top.
54 * @param[in] position position of actor in view space
57 static float ZValue(const Vector3& position)
59 // inlined so we avoid a function call when sorting renderers
65 * @return A smart-pointer to the newly allocated Layer.
67 static LayerPtr New();
70 * Create a new root layer; this is typically owned by the stage.
71 * @param[in] layerList The layer will be added to this ordered list.
72 * @return A smart-pointer to the newly allocated Actor.
74 static LayerPtr NewRoot( LayerList& layerList );
77 * @copydoc Dali::Internal::Actor::OnInitialize
82 * Query the current depth of the layer
84 unsigned int GetDepth() const;
87 * @copydoc Dali::Layer::Raise
92 * @copydoc Dali::Layer::Lower
97 * @copydoc Dali::Layer::RaiseAbove
99 void RaiseAbove( const Internal::Layer& target );
102 * @copydoc Dali::Layer::LowerBelow
104 void LowerBelow( const Internal::Layer& target );
107 * @copydoc Dali::Layer::RaiseToTop
112 * @copydoc Dali::Layer::LowerToBottom
114 void LowerToBottom();
117 * @copydoc Dali::Layer::MoveAbove
119 void MoveAbove( const Internal::Layer& target );
122 * @copydoc Dali::Layer::MoveAbove
124 void MoveBelow( const Internal::Layer& target );
127 * @copydoc Dali::Layer::SetClipping()
129 void SetClipping(bool enabled);
132 * @copydoc Dali::Layer::IsClipping()
134 bool IsClipping() const
136 return mIsClipping; // Actor-side has most up-to-date value
140 * @copydoc Dali::Layer::SetClippingBox()
142 void SetClippingBox(int x, int y, int width, int height);
145 * @copydoc Dali::Layer::GetClippingBox()
147 const Dali::ClippingBox& GetClippingBox() const
149 return mClippingBox; // Actor-side has most up-to-date value
153 * @copydoc Dali::Layer::SetBehavior()
155 void SetBehavior( Dali::Layer::Behavior behavior );
158 * @copydoc Dali::Layer::GetBehavior()
160 Dali::Layer::Behavior GetBehavior() const
166 * @copydoc Dali::Layer::SetDepthTestDisabled()
168 void SetDepthTestDisabled( bool disable );
171 * @copydoc Dali::Layer::IsDepthTestDisabled()
173 bool IsDepthTestDisabled() const;
176 * @copydoc Dali::Layer::SetSortFunction()
178 void SetSortFunction(Dali::Layer::SortFunctionType function);
181 * @copydoc Dali::Layer::SetTouchConsumed()
183 void SetTouchConsumed( bool consume );
186 * @copydoc Dali::Layer::IsTouchConsumed()
188 bool IsTouchConsumed() const;
191 * @copydoc Dali::Layer::SetHoverConsumed()
193 void SetHoverConsumed( bool consume );
196 * @copydoc Dali::Layer::IsHoverConsumed()
198 bool IsHoverConsumed() const;
201 * Helper function to get the scene object.
202 * This should only be called by Stage
203 * @return the scene object for the layer.
205 const SceneGraph::Layer& GetSceneLayerOnStage() const;
208 * @copydoc Dali::Internal::Actor::DoAction()
210 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
212 public: // Default property extensions from Object
215 * @copydoc Dali::Internal::Object::SetDefaultProperty()
217 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
220 * @copydoc Dali::Internal::Object::GetDefaultProperty()
222 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
225 * @copydoc Dali::Internal::Object::GetDefaultProperty()
227 virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
232 * Construct a new layer.
233 * @param[in] type Either Actor::LAYER or Actor::ROOT_LAYER if this is the root actor.
234 * @param[in] layer the scene graph layer
236 Layer( Actor::DerivedType type, const SceneGraph::Layer& layer );
239 * A reference counted object may only be deleted by calling Unreference()
243 private: // From Actor
248 virtual void OnStageConnectionInternal();
253 virtual void OnStageDisconnectionInternal();
257 LayerList* mLayerList; ///< Only valid when layer is on-stage
259 // These properties not animatable; the actor side has the most up-to-date values
260 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
261 Dali::Layer::SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
263 Dali::Layer::Behavior mBehavior; ///< Behavior of the layer
265 bool mIsClipping:1; ///< True when clipping is enabled
266 bool mDepthTestDisabled:1; ///< Whether depth test is disabled.
267 bool mTouchConsumed:1; ///< Whether we should consume touch (including gesture).
268 bool mHoverConsumed:1; ///< Whether we should consume hover.
272 } // namespace Internal
274 // Helpers for public-api forwarding methods
276 inline Internal::Layer& GetImplementation(Dali::Layer& layer)
278 DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
280 BaseObject& handle = layer.GetBaseObject();
282 return static_cast<Internal::Layer&>(handle);
285 inline const Internal::Layer& GetImplementation(const Dali::Layer& layer)
287 DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
289 const BaseObject& handle = layer.GetBaseObject();
291 return static_cast<const Internal::Layer&>(handle);
297 #endif // DALI_INTERNAL_LAYER_H