1 #ifndef DALI_INTERNAL_LAYER_H
2 #define DALI_INTERNAL_LAYER_H
5 * Copyright (c) 2021 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/internal/event/actors/actor-declarations.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24 #include <dali/public-api/actors/layer.h>
36 } // namespace SceneGraph
38 using ClippingBox = Dali::ClippingBox;
40 class Layer : public Actor
44 * @copydoc Dali::Layer::ZValue(const Vector3&, float)
46 * This is the default sorting function.
47 * It is useful for 2D user interfaces, and it's used to sort translucent renderers.
49 * Only the Z signed distance from the camera is considererd, lower values will be drawn on top.
51 * @param[in] position position of actor in view space
54 static float ZValue(const Vector3& position)
56 // inlined so we avoid a function call when sorting renderers
62 * @return A smart-pointer to the newly allocated Layer.
64 static LayerPtr New();
67 * Create a new root layer; this is typically owned by the stage.
68 * @param[in] layerList The layer will be added to this ordered list.
69 * @return A smart-pointer to the newly allocated Actor.
71 static LayerPtr NewRoot(LayerList& layerList);
74 * @copydoc Dali::Internal::Actor::OnInitialize
76 void OnInitialize() override;
79 * Query the current depth of the layer
81 unsigned int GetDepth() const;
84 * @copydoc Dali::Layer::Raise
89 * @copydoc Dali::Layer::Lower
94 * @copydoc Dali::Layer::RaiseAbove
96 void RaiseAbove(const Internal::Layer& target);
99 * @copydoc Dali::Layer::LowerBelow
101 void LowerBelow(const Internal::Layer& target);
104 * @copydoc Dali::Layer::RaiseToTop
109 * @copydoc Dali::Layer::LowerToBottom
111 void LowerToBottom();
114 * @copydoc Dali::Layer::MoveAbove
116 void MoveAbove(const Internal::Layer& target);
119 * @copydoc Dali::Layer::MoveAbove
121 void MoveBelow(const Internal::Layer& target);
124 * @copydoc Dali::Layer::SetClipping()
126 void SetClipping(bool enabled);
129 * @copydoc Dali::Layer::IsClipping()
131 bool IsClipping() const
133 return mIsClipping; // Actor-side has most up-to-date value
137 * @copydoc Dali::Layer::SetClippingBox()
139 void SetClippingBox(int x, int y, int width, int height);
142 * @copydoc Dali::Layer::GetClippingBox()
144 const Dali::ClippingBox& GetClippingBox() const
146 return mClippingBox; // Actor-side has most up-to-date value
150 * @copydoc Dali::Layer::SetBehavior()
152 void SetBehavior(Dali::Layer::Behavior behavior);
155 * @copydoc Dali::Layer::GetBehavior()
157 Dali::Layer::Behavior GetBehavior() const
163 * @copydoc Dali::Layer::SetDepthTestDisabled()
165 void SetDepthTestDisabled(bool disable);
168 * @copydoc Dali::Layer::IsDepthTestDisabled()
170 bool IsDepthTestDisabled() const;
173 * @copydoc Dali::Layer::SetSortFunction()
175 void SetSortFunction(Dali::Layer::SortFunctionType function);
178 * @copydoc Dali::Layer::SetTouchConsumed()
180 void SetTouchConsumed(bool consume);
183 * @copydoc Dali::Layer::IsTouchConsumed()
185 bool IsTouchConsumed() const;
188 * @copydoc Dali::Layer::SetHoverConsumed()
190 void SetHoverConsumed(bool consume);
193 * @copydoc Dali::Layer::IsHoverConsumed()
195 bool IsHoverConsumed() const;
198 * Helper function to get the scene object.
200 * @return the scene object for the layer.
202 const SceneGraph::Layer& GetSceneGraphLayer() const;
205 * @copydoc Dali::Internal::Actor::DoAction()
207 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
209 public: // Default property extensions from Object
211 * @copydoc Dali::Internal::Object::SetDefaultProperty()
213 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
216 * @copydoc Dali::Internal::Object::GetDefaultProperty()
218 Property::Value GetDefaultProperty(Property::Index index) const override;
221 * @copydoc Dali::Internal::Object::GetDefaultProperty()
223 Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
227 * Construct a new layer.
228 * @param[in] type Either Actor::LAYER or Actor::ROOT_LAYER if this is the root actor.
229 * @param[in] layer the scene graph layer
231 Layer(Actor::DerivedType type, const SceneGraph::Layer& layer);
234 * A reference counted object may only be deleted by calling Unreference()
238 private: // From Actor
242 void OnSceneConnectionInternal() override;
247 void OnSceneDisconnectionInternal() override;
250 LayerList* mLayerList; ///< Only valid when layer is on-scene
252 // These properties not animatable; the actor side has the most up-to-date values
253 ClippingBox mClippingBox; ///< The clipping box, in window coordinates
254 Dali::Layer::SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
256 Dali::Layer::Behavior mBehavior; ///< Behavior of the layer
258 bool mIsClipping : 1; ///< True when clipping is enabled
259 bool mDepthTestDisabled : 1; ///< Whether depth test is disabled.
260 bool mTouchConsumed : 1; ///< Whether we should consume touch (including gesture).
261 bool mHoverConsumed : 1; ///< Whether we should consume hover.
264 } // namespace Internal
266 // Helpers for public-api forwarding methods
268 inline Internal::Layer& GetImplementation(Dali::Layer& layer)
270 DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
272 BaseObject& handle = layer.GetBaseObject();
274 return static_cast<Internal::Layer&>(handle);
277 inline const Internal::Layer& GetImplementation(const Dali::Layer& layer)
279 DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
281 const BaseObject& handle = layer.GetBaseObject();
283 return static_cast<const Internal::Layer&>(handle);
288 #endif // DALI_INTERNAL_LAYER_H