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