cf566154a9b9394a4d2e1121581095bea71a8d8a
[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) 2017 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 typedef Dali::ClippingBox 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    * @param[in] manager The update manager to install a root node with.
73    * @return A smart-pointer to the newly allocated Actor.
74    */
75   static LayerPtr NewRoot( LayerList& layerList, SceneGraph::UpdateManager& manager );
76
77   /**
78    * @copydoc Dali::Internal::Actor::OnInitialize
79    */
80   void OnInitialize();
81
82   /**
83    * Query the current depth of the layer
84    */
85   unsigned int GetDepth() const;
86
87   /**
88    * @copydoc Dali::Layer::Raise
89    */
90   void Raise();
91
92   /**
93    * @copydoc Dali::Layer::Lower
94    */
95   void Lower();
96
97   /**
98    * @copydoc Dali::Layer::RaiseAbove
99    */
100   void RaiseAbove( const Internal::Layer& target );
101
102   /**
103    * @copydoc Dali::Layer::LowerBelow
104    */
105   void LowerBelow( const Internal::Layer& target );
106
107   /**
108    * @copydoc Dali::Layer::RaiseToTop
109    */
110   void RaiseToTop();
111
112   /**
113    * @copydoc Dali::Layer::LowerToBottom
114    */
115   void LowerToBottom();
116
117   /**
118    * @copydoc Dali::Layer::MoveAbove
119    */
120   void MoveAbove( const Internal::Layer& target );
121
122   /**
123    * @copydoc Dali::Layer::MoveAbove
124    */
125   void MoveBelow( const Internal::Layer& target );
126
127   /**
128    * @copydoc Dali::Layer::SetClipping()
129    */
130   void SetClipping(bool enabled);
131
132   /**
133    * @copydoc Dali::Layer::IsClipping()
134    */
135   bool IsClipping() const
136   {
137     return mIsClipping; // Actor-side has most up-to-date value
138   }
139
140   /**
141    * @copydoc Dali::Layer::SetClippingBox()
142    */
143   void SetClippingBox(int x, int y, int width, int height);
144
145   /**
146    * @copydoc Dali::Layer::GetClippingBox()
147    */
148   const Dali::ClippingBox& GetClippingBox() const
149   {
150     return mClippingBox; // Actor-side has most up-to-date value
151   }
152
153   /**
154    * @copydoc Dali::Layer::SetBehavior()
155    */
156   void SetBehavior( Dali::Layer::Behavior behavior );
157
158   /**
159    * @copydoc Dali::Layer::GetBehavior()
160    */
161   Dali::Layer::Behavior GetBehavior() const
162   {
163     return mBehavior;
164   }
165
166   /**
167    * @copydoc Dali::Layer::SetDepthTestDisabled()
168    */
169   void SetDepthTestDisabled( bool disable );
170
171   /**
172    * @copydoc Dali::Layer::IsDepthTestDisabled()
173    */
174   bool IsDepthTestDisabled() const;
175
176   /**
177    * @copydoc Dali::Layer::SetSortFunction()
178    */
179   void SetSortFunction(Dali::Layer::SortFunctionType function);
180
181   /**
182    * @copydoc Dali::Layer::SetTouchConsumed()
183    */
184   void SetTouchConsumed( bool consume );
185
186   /**
187    * @copydoc Dali::Layer::IsTouchConsumed()
188    */
189   bool IsTouchConsumed() const;
190
191   /**
192    * @copydoc Dali::Layer::SetHoverConsumed()
193    */
194   void SetHoverConsumed( bool consume );
195
196   /**
197    * @copydoc Dali::Layer::IsHoverConsumed()
198    */
199   bool IsHoverConsumed() const;
200
201   /**
202    * Helper function to get the scene object.
203    * This should only be called by Stage
204    * @return the scene object for the layer.
205    */
206   const SceneGraph::Layer& GetSceneLayerOnStage() const;
207
208   /**
209    * @copydoc Dali::Internal::Actor::DoAction()
210    */
211   static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
212
213 public: // Default property extensions from Object
214   /**
215    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
216    */
217   virtual unsigned int GetDefaultPropertyCount() const;
218
219   /**
220    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
221    */
222   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
223
224   /**
225    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
226    */
227   virtual const char* GetDefaultPropertyName(Property::Index index) const;
228
229   /**
230    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
231    */
232   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
233
234   /**
235    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
236    */
237   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
238
239   /**
240    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
241    */
242   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
243
244   /**
245    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
246    */
247   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
248
249   /**
250    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
251    */
252   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
253
254   /**
255    * @copydoc Dali::Internal::Object::SetDefaultProperty()
256    */
257   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
258
259   /**
260    * @copydoc Dali::Internal::Object::GetDefaultProperty()
261    */
262   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
263
264   /**
265    * @copydoc Dali::Internal::Object::GetDefaultProperty()
266    */
267   virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
268
269 protected:
270
271   /**
272    * Construct a new layer.
273    * @param[in] type Either Actor::LAYER or Actor::ROOT_LAYER if this is the root actor.
274    */
275   Layer( Actor::DerivedType type );
276
277   /**
278    * A reference counted object may only be deleted by calling Unreference()
279    */
280   virtual ~Layer();
281
282 private: // From Actor
283
284   /**
285    * From Actor; create a node to represent the layer in the scene-graph.
286    * @return A newly allocated layer node.
287    */
288   virtual SceneGraph::Node* CreateNode() const;
289
290   /**
291    * From Actor.
292    */
293   virtual void OnStageConnectionInternal();
294
295   /**
296    * From Actor.
297    */
298   virtual void OnStageDisconnectionInternal();
299
300 private:
301
302   LayerList* mLayerList; ///< Only valid when layer is on-stage
303
304   // These properties not animatable; the actor side has the most up-to-date values
305   ClippingBox mClippingBox;                     ///< The clipping box, in window coordinates
306   Dali::Layer::SortFunctionType mSortFunction;  ///< Used to sort semi-transparent geometry
307
308   Dali::Layer::Behavior mBehavior;              ///< Behavior of the layer
309
310   bool mIsClipping:1;                           ///< True when clipping is enabled
311   bool mDepthTestDisabled:1;                    ///< Whether depth test is disabled.
312   bool mTouchConsumed:1;                        ///< Whether we should consume touch (including gesture).
313   bool mHoverConsumed:1;                        ///< Whether we should consume hover.
314
315 };
316
317 } // namespace Internal
318
319 // Helpers for public-api forwarding methods
320
321 inline Internal::Layer& GetImplementation(Dali::Layer& layer)
322 {
323   DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
324
325   BaseObject& handle = layer.GetBaseObject();
326
327   return static_cast<Internal::Layer&>(handle);
328 }
329
330 inline const Internal::Layer& GetImplementation(const Dali::Layer& layer)
331 {
332   DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
333
334   const BaseObject& handle = layer.GetBaseObject();
335
336   return static_cast<const Internal::Layer&>(handle);
337 }
338
339 } // namespace Dali
340
341
342 #endif // DALI_INTERNAL_LAYER_H