[4.0] Changed Update to reset only target properties each frame
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / property-accessor.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_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/common/dali-common.h>
23 #include <dali/internal/update/common/animatable-property.h>
24 #include <dali/internal/update/manager/transform-manager-property.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 /**
33  * A wrapper class for getting/setting a property.
34  * Animators use this instead of accessing properties directly.
35  */
36 template < typename PropertyType >
37 class PropertyAccessor
38 {
39 public:
40
41   /**
42    * Create a property component.
43    * @param [in] property The property to access.
44    */
45   PropertyAccessor( SceneGraph::PropertyBase* property )
46   : mProperty( dynamic_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) )
47   {
48   }
49
50   /**
51    * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
52    */
53   ~PropertyAccessor()
54   {
55   }
56
57   /**
58    * Query whether the accessor is set.
59    * @return True if set.
60    */
61   bool IsSet() const
62   {
63     return mProperty != NULL;
64   }
65
66   /**
67    * Reset the property accessor
68    * @post Calling any other PropertyAccessor is invalid.
69    */
70   void Reset()
71   {
72     mProperty = NULL;
73   }
74
75   /**
76    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
77    */
78   bool IsClean() const
79   {
80     return mProperty->IsClean();
81   }
82
83   /**
84    * Read access to the property.
85    * @param [in] bufferIndex The current update buffer index.
86    */
87   const PropertyType& Get( BufferIndex bufferIndex ) const
88   {
89     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Get() mProperty was NULL" );
90     return mProperty->Get( bufferIndex );
91   }
92
93   /**
94    * @copydoc AnimatableProperty<float>::Set()
95    */
96   void Set( BufferIndex bufferIndex, const PropertyType& value ) const
97   {
98     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Set() mProperty was NULL" );
99     mProperty->Set( bufferIndex, value );
100   }
101
102   /**
103    * @copydoc AnimatableProperty<float>::Bake()
104    */
105   void Bake( BufferIndex bufferIndex, const PropertyType& value ) const
106   {
107     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Bake() mProperty was NULL" );
108     mProperty->Bake( bufferIndex, value );
109   }
110
111 private:
112
113   // Undefined
114   PropertyAccessor(const PropertyAccessor& property);
115
116   // Undefined
117   PropertyAccessor& operator=(const PropertyAccessor& rhs);
118
119 private:
120
121   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
122 };
123
124
125
126 /**
127  * A wrapper class for getting/setting a property.
128  * Animators use this instead of accessing properties directly.
129  */
130 template <typename T>
131 class TransformManagerPropertyAccessor
132 {
133 public:
134
135   /**
136    * Create a property component.
137    * @param [in] property The property to access.
138    */
139   TransformManagerPropertyAccessor( SceneGraph::PropertyBase* property )
140   : mProperty( dynamic_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) )
141   {
142   }
143
144   /**
145    * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
146    */
147   ~TransformManagerPropertyAccessor()
148   {
149   }
150
151   /**
152    * Query whether the accessor is set.
153    * @return True if set.
154    */
155   bool IsSet() const
156   {
157     return mProperty != NULL;
158   }
159
160   /**
161    * Reset the property accessor
162    * @post Calling any other PropertyAccessor is invalid.
163    */
164   void Reset()
165   {
166     mProperty = NULL;
167   }
168
169   /**
170    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
171    */
172   bool IsClean() const
173   {
174     return mProperty->IsClean();
175   }
176
177   /**
178    * Read access to the property.
179    * @param [in] bufferIndex The current update buffer index.
180    * @return The value of the property
181    */
182   const T& Get( BufferIndex bufferIndex ) const
183   {
184     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Get() mProperty was NULL" );
185     return mProperty->Get( bufferIndex );
186   }
187
188   /**
189    * @copydoc AnimatableProperty<float>::Set()
190    */
191   void Set( BufferIndex bufferIndex, const T& value ) const
192   {
193     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Set() mProperty was NULL" );
194     mProperty->Set( bufferIndex, value );
195   }
196
197   /**
198    * @copydoc AnimatableProperty<float>::Bake()
199    */
200   void Bake( BufferIndex bufferIndex, const T& value ) const
201   {
202     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Bake() mProperty was NULL" );
203     mProperty->Bake( bufferIndex, value );
204   }
205
206 private:
207
208   // Undefined
209   TransformManagerPropertyAccessor(const TransformManagerPropertyAccessor& property);
210
211   // Undefined
212   TransformManagerPropertyAccessor& operator=(const TransformManagerPropertyAccessor& rhs);
213
214 private:
215
216   SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
217 };
218
219
220 template <typename T, unsigned int COMPONENT>
221 class TransformManagerPropertyComponentAccessor
222 {
223 public:
224
225   /**
226    * Create a property component.
227    * @param [in] property The property to access.
228    */
229   TransformManagerPropertyComponentAccessor( SceneGraph::PropertyBase* property )
230   : mProperty( dynamic_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) )
231   {
232   }
233
234   /**
235    * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
236    */
237   ~TransformManagerPropertyComponentAccessor()
238   {
239   }
240
241   /**
242    * Query whether the accessor is set.
243    * @return True if set.
244    */
245   bool IsSet() const
246   {
247     return mProperty != NULL;
248   }
249
250   /**
251    * Reset the property accessor
252    * @post Calling any other PropertyAccessor is invalid.
253    */
254   void Reset()
255   {
256     mProperty = NULL;
257   }
258
259   /**
260    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
261    */
262   bool IsClean() const
263   {
264     return mProperty->IsClean();
265   }
266
267   /**
268    * Read access to the property.
269    * @param [in] bufferIndex The current update buffer index.
270    * @return The value of the component of the property
271    */
272   const float& Get( BufferIndex bufferIndex ) const
273   {
274     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Get() mProperty was NULL" );
275     return mProperty->GetFloatComponent( COMPONENT );
276   }
277
278   /**
279    * @copydoc AnimatableProperty<float>::Set()
280    */
281   void Set( BufferIndex bufferIndex, const float& value ) const
282   {
283     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Set() mProperty was NULL" );
284     mProperty->SetFloatComponent( value, COMPONENT );
285   }
286
287   /**
288    * @copydoc AnimatableProperty<float>::Bake()
289    */
290   void Bake( BufferIndex bufferIndex, const float& value ) const
291   {
292     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Bake() mProperty was NULL" );
293     mProperty->BakeFloatComponent( value, COMPONENT );
294   }
295
296 private:
297
298   // Undefined
299   TransformManagerPropertyComponentAccessor(const TransformManagerPropertyComponentAccessor& property);
300
301   // Undefined
302   TransformManagerPropertyComponentAccessor& operator=(const TransformManagerPropertyComponentAccessor& rhs);
303
304 private:
305
306   SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
307 };
308
309 } // namespace Internal
310
311 } // namespace Dali
312
313 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H__