Moved more actor methods into relayouter
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / layer-impl.h
1 #ifndef DALI_INTERNAL_LAYER_H
2 #define DALI_INTERNAL_LAYER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class LayerList;
31
32 namespace SceneGraph
33 {
34 class UpdateManager;
35 class Layer;
36 } // namespace SceneGraph
37
38 using ClippingBox = Dali::ClippingBox;
39
40 class Layer : public Actor
41 {
42 public:
43   /**
44    * @copydoc Dali::Layer::ZValue(const Vector3&, float)
45    *
46    * This is the default sorting function.
47    * It is useful for 2D user interfaces, and it's used to sort translucent renderers.
48    *
49    * Only the Z signed distance from the camera is considererd, lower values will be drawn on top.
50    *
51    * @param[in] position     position of actor in view space
52    * @return depth
53    */
54   static float ZValue(const Vector3& position)
55   {
56     // inlined so we avoid a function call when sorting renderers
57     return position.z;
58   }
59
60   /**
61    * Create a new Layer.
62    * @return A smart-pointer to the newly allocated Layer.
63    */
64   static LayerPtr New();
65
66   /**
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.
70    */
71   static LayerPtr NewRoot(LayerList& layerList);
72
73   /**
74    * @copydoc Dali::Internal::Actor::OnInitialize
75    */
76   void OnInitialize() override;
77
78   /**
79    * Query the current depth of the layer
80    */
81   unsigned int GetDepth() const;
82
83   /**
84    * @copydoc Dali::Layer::Raise
85    */
86   void Raise();
87
88   /**
89    * @copydoc Dali::Layer::Lower
90    */
91   void Lower();
92
93   /**
94    * @copydoc Dali::Layer::RaiseAbove
95    */
96   void RaiseAbove(const Internal::Layer& target);
97
98   /**
99    * @copydoc Dali::Layer::LowerBelow
100    */
101   void LowerBelow(const Internal::Layer& target);
102
103   /**
104    * @copydoc Dali::Layer::RaiseToTop
105    */
106   void RaiseToTop();
107
108   /**
109    * @copydoc Dali::Layer::LowerToBottom
110    */
111   void LowerToBottom();
112
113   /**
114    * @copydoc Dali::Layer::MoveAbove
115    */
116   void MoveAbove(const Internal::Layer& target);
117
118   /**
119    * @copydoc Dali::Layer::MoveAbove
120    */
121   void MoveBelow(const Internal::Layer& target);
122
123   /**
124    * @copydoc Dali::Layer::SetClipping()
125    */
126   void SetClipping(bool enabled);
127
128   /**
129    * @copydoc Dali::Layer::IsClipping()
130    */
131   bool IsClipping() const
132   {
133     return mIsClipping; // Actor-side has most up-to-date value
134   }
135
136   /**
137    * @copydoc Dali::Layer::SetClippingBox()
138    */
139   void SetClippingBox(int x, int y, int width, int height);
140
141   /**
142    * @copydoc Dali::Layer::GetClippingBox()
143    */
144   const Dali::ClippingBox& GetClippingBox() const
145   {
146     return mClippingBox; // Actor-side has most up-to-date value
147   }
148
149   /**
150    * @copydoc Dali::Layer::SetBehavior()
151    */
152   void SetBehavior(Dali::Layer::Behavior behavior);
153
154   /**
155    * @copydoc Dali::Layer::GetBehavior()
156    */
157   Dali::Layer::Behavior GetBehavior() const
158   {
159     return mBehavior;
160   }
161
162   /**
163    * @copydoc Dali::Layer::SetDepthTestDisabled()
164    */
165   void SetDepthTestDisabled(bool disable);
166
167   /**
168    * @copydoc Dali::Layer::IsDepthTestDisabled()
169    */
170   bool IsDepthTestDisabled() const;
171
172   /**
173    * @copydoc Dali::Layer::SetSortFunction()
174    */
175   void SetSortFunction(Dali::Layer::SortFunctionType function);
176
177   /**
178    * @copydoc Dali::Layer::SetTouchConsumed()
179    */
180   void SetTouchConsumed(bool consume);
181
182   /**
183    * @copydoc Dali::Layer::IsTouchConsumed()
184    */
185   bool IsTouchConsumed() const;
186
187   /**
188    * @copydoc Dali::Layer::SetHoverConsumed()
189    */
190   void SetHoverConsumed(bool consume);
191
192   /**
193    * @copydoc Dali::Layer::IsHoverConsumed()
194    */
195   bool IsHoverConsumed() const;
196
197   /**
198    * Helper function to get the scene object.
199    *
200    * @return the scene object for the layer.
201    */
202   const SceneGraph::Layer& GetSceneGraphLayer() const;
203
204   /**
205    * @copydoc Dali::Internal::Actor::DoAction()
206    */
207   static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
208
209 public: // Default property extensions from Object
210   /**
211    * @copydoc Dali::Internal::Object::SetDefaultProperty()
212    */
213   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
214
215   /**
216    * @copydoc Dali::Internal::Object::GetDefaultProperty()
217    */
218   Property::Value GetDefaultProperty(Property::Index index) const override;
219
220   /**
221    * @copydoc Dali::Internal::Object::GetDefaultProperty()
222    */
223   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
224
225 protected:
226   /**
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
230    */
231   Layer(Actor::DerivedType type, const SceneGraph::Layer& layer);
232
233   /**
234    * A reference counted object may only be deleted by calling Unreference()
235    */
236   ~Layer() override;
237
238 private: // From Actor
239   /**
240    * From Actor.
241    */
242   void OnSceneConnectionInternal() override;
243
244   /**
245    * From Actor.
246    */
247   void OnSceneDisconnectionInternal() override;
248
249 private:
250   LayerList* mLayerList; ///< Only valid when layer is on-scene
251
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
255
256   Dali::Layer::Behavior mBehavior; ///< Behavior of the layer
257
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.
262 };
263
264 } // namespace Internal
265
266 // Helpers for public-api forwarding methods
267
268 inline Internal::Layer& GetImplementation(Dali::Layer& layer)
269 {
270   DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
271
272   BaseObject& handle = layer.GetBaseObject();
273
274   return static_cast<Internal::Layer&>(handle);
275 }
276
277 inline const Internal::Layer& GetImplementation(const Dali::Layer& layer)
278 {
279   DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
280
281   const BaseObject& handle = layer.GetBaseObject();
282
283   return static_cast<const Internal::Layer&>(handle);
284 }
285
286 } // namespace Dali
287
288 #endif // DALI_INTERNAL_LAYER_H