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