[dali_1.3.49] Merge branch 'devel/master'
[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) 2018 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   /**
216    * @copydoc Dali::Internal::Object::SetDefaultProperty()
217    */
218   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
219
220   /**
221    * @copydoc Dali::Internal::Object::GetDefaultProperty()
222    */
223   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
224
225   /**
226    * @copydoc Dali::Internal::Object::GetDefaultProperty()
227    */
228   virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
229
230 protected:
231
232   /**
233    * Construct a new layer.
234    * @param[in] type Either Actor::LAYER or Actor::ROOT_LAYER if this is the root actor.
235    * @param[in] layer the scene graph layer
236    */
237   Layer( Actor::DerivedType type, const SceneGraph::Layer& layer );
238
239   /**
240    * A reference counted object may only be deleted by calling Unreference()
241    */
242   virtual ~Layer();
243
244 private: // From Actor
245
246   /**
247    * From Actor.
248    */
249   virtual void OnStageConnectionInternal();
250
251   /**
252    * From Actor.
253    */
254   virtual void OnStageDisconnectionInternal();
255
256 private:
257
258   LayerList* mLayerList; ///< Only valid when layer is on-stage
259
260   // These properties not animatable; the actor side has the most up-to-date values
261   ClippingBox mClippingBox;                     ///< The clipping box, in window coordinates
262   Dali::Layer::SortFunctionType mSortFunction;  ///< Used to sort semi-transparent geometry
263
264   Dali::Layer::Behavior mBehavior;              ///< Behavior of the layer
265
266   bool mIsClipping:1;                           ///< True when clipping is enabled
267   bool mDepthTestDisabled:1;                    ///< Whether depth test is disabled.
268   bool mTouchConsumed:1;                        ///< Whether we should consume touch (including gesture).
269   bool mHoverConsumed:1;                        ///< Whether we should consume hover.
270
271 };
272
273 } // namespace Internal
274
275 // Helpers for public-api forwarding methods
276
277 inline Internal::Layer& GetImplementation(Dali::Layer& layer)
278 {
279   DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
280
281   BaseObject& handle = layer.GetBaseObject();
282
283   return static_cast<Internal::Layer&>(handle);
284 }
285
286 inline const Internal::Layer& GetImplementation(const Dali::Layer& layer)
287 {
288   DALI_ASSERT_ALWAYS(layer && "Layer handle is empty");
289
290   const BaseObject& handle = layer.GetBaseObject();
291
292   return static_cast<const Internal::Layer&>(handle);
293 }
294
295 } // namespace Dali
296
297
298 #endif // DALI_INTERNAL_LAYER_H