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