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