[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / property-component-accessor.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_ACCESSOR_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_ACCESSOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/internal/update/common/animatable-property.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 /**
31  * A wrapper class for getting/setting a float component of another property.
32  * Animators use this instead of accessing properties directly.
33  */
34 template < typename PropertyType >
35 class PropertyComponentAccessorX
36 {
37 public:
38
39   /**
40    * Create a property component.
41    * @param [in] property The property which holds a float component.
42    */
43   PropertyComponentAccessorX( SceneGraph::PropertyBase* property )
44   : mProperty( dynamic_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) )
45   {
46   }
47
48   /**
49    * Non-virtual destructor; PropertyComponentAccessorX is not suitable as a base class.
50    */
51   ~PropertyComponentAccessorX()
52   {
53   }
54
55   /**
56    * Query whether the accessor is set.
57    * @return True if set.
58    */
59   bool IsSet() const
60   {
61     return mProperty != NULL;
62   }
63
64   /**
65    * Reset the property accessor
66    * @post Calling any other PropertyComponentAccessorX is invalid.
67    */
68   void Reset()
69   {
70     mProperty = NULL;
71   }
72
73   /**
74    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
75    */
76   bool IsClean() const
77   {
78     return mProperty->IsClean();
79   }
80
81   /**
82    * Read access to the property.
83    * @param [in] bufferIndex The current update buffer index.
84    */
85   const float& Get( BufferIndex bufferIndex ) const
86   {
87     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorX::Get() mProperty was NULL" );
88     return mProperty->Get( bufferIndex ).x; // X Component only!
89   }
90
91   /**
92    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
93    */
94   void Set( BufferIndex bufferIndex, float value ) const
95   {
96     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorX::Set() mProperty was NULL" );
97     mProperty->SetX( bufferIndex, value );
98   }
99
100   /**
101    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
102    */
103   void Bake( BufferIndex bufferIndex, float value ) const
104   {
105     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorX::Bake() mProperty was NULL" );
106     mProperty->BakeX( bufferIndex, value );
107   }
108
109 private:
110
111   // Undefined
112   PropertyComponentAccessorX(const PropertyComponentAccessorX& property);
113
114   // Undefined
115   PropertyComponentAccessorX& operator=(const PropertyComponentAccessorX& rhs);
116
117 private:
118
119   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
120 };
121
122 /**
123  * A wrapper class for getting/setting a float component of another property.
124  * Animators use this instead of accessing properties directly.
125  */
126 template < typename PropertyType >
127 class PropertyComponentAccessorY
128 {
129 public:
130
131   /**
132    * Create a property component.
133    * @param [in] property The property which holds a float component.
134    */
135   PropertyComponentAccessorY( SceneGraph::PropertyBase* property )
136   : mProperty( dynamic_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) )
137   {
138   }
139
140   /**
141    * Non-virtual destructor; PropertyComponentAccessorY is not suitable as a base class.
142    */
143   ~PropertyComponentAccessorY()
144   {
145   }
146
147   /**
148    * Query whether the accessor is set.
149    * @return True if set.
150    */
151   bool IsSet() const
152   {
153     return mProperty != NULL;
154   }
155
156   /**
157    * Reset the property accessor
158    * @post Calling any other PropertyComponentAccessorY is invalid.
159    */
160   void Reset()
161   {
162     mProperty = NULL;
163   }
164
165   /**
166    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
167    */
168   bool IsClean() const
169   {
170     return mProperty->IsClean();
171   }
172
173   /**
174    * Read access to the property.
175    * @param [in] bufferIndex The current update buffer index.
176    */
177   const float& Get( BufferIndex bufferIndex ) const
178   {
179     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorY::Get() mProperty was NULL" );
180     return mProperty->Get( bufferIndex ).y; // Y Component only!
181   }
182
183   /**
184    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
185    */
186   void Set( BufferIndex bufferIndex, float value ) const
187   {
188     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorY::Set() mProperty was NULL" );
189     mProperty->SetY( bufferIndex, value );
190   }
191
192   /**
193    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
194    */
195   void Bake( BufferIndex bufferIndex, float value ) const
196   {
197     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorY::Bake() mProperty was NULL" );
198     mProperty->BakeY( bufferIndex, value );
199   }
200
201 private:
202
203   // Undefined
204   PropertyComponentAccessorY(const PropertyComponentAccessorY& property);
205
206   // Undefined
207   PropertyComponentAccessorY& operator=(const PropertyComponentAccessorY& rhs);
208
209 private:
210
211   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
212 };
213
214 /**
215  * A wrapper class for getting/setting a float component of another property.
216  * Animators use this instead of accessing properties directly.
217  */
218 template < typename PropertyType >
219 class PropertyComponentAccessorZ
220 {
221 public:
222
223   /**
224    * Create a property component.
225    * @param [in] property The property which holds a float component.
226    */
227   PropertyComponentAccessorZ( SceneGraph::PropertyBase* property )
228   : mProperty( dynamic_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) )
229   {
230   }
231
232   /**
233    * Non-virtual destructor; PropertyComponentAccessorZ is not suitable as a base class.
234    */
235   ~PropertyComponentAccessorZ()
236   {
237   }
238
239   /**
240    * Query whether the accessor is set.
241    * @return True if set.
242    */
243   bool IsSet() const
244   {
245     return mProperty != NULL;
246   }
247
248   /**
249    * Reset the property accessor
250    * @post Calling any other PropertyComponentAccessorZ is invalid.
251    */
252   void Reset()
253   {
254     mProperty = NULL;
255   }
256
257   /**
258    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
259    */
260   bool IsClean() const
261   {
262     return mProperty->IsClean();
263   }
264
265   /**
266    * Read access to the property.
267    * @param [in] bufferIndex The current update buffer index.
268    */
269   const float& Get( BufferIndex bufferIndex ) const
270   {
271     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorZ::Get() mProperty was NULL" );
272     return mProperty->Get( bufferIndex ).z; // Z Component only!
273   }
274
275   /**
276    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
277    */
278   void Set( BufferIndex bufferIndex, float value ) const
279   {
280     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorZ::Set() mProperty was NULL" );
281     mProperty->SetZ( bufferIndex, value );
282   }
283
284   /**
285    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
286    */
287   void Bake( BufferIndex bufferIndex, float value ) const
288   {
289     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorZ::Bake() mProperty was NULL" );
290     mProperty->BakeZ( bufferIndex, value );
291   }
292
293 private:
294
295   // Undefined
296   PropertyComponentAccessorZ(const PropertyComponentAccessorZ& property);
297
298   // Undefined
299   PropertyComponentAccessorZ& operator=(const PropertyComponentAccessorZ& rhs);
300
301 private:
302
303   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
304 };
305
306 /**
307  * A wrapper class for getting/setting a float component of another property.
308  * Animators use this instead of accessing properties directly.
309  */
310 template < typename PropertyType >
311 class PropertyComponentAccessorW
312 {
313 public:
314
315   /**
316    * Create a property component.
317    * @param [in] property The property which holds a float component.
318    */
319   PropertyComponentAccessorW( SceneGraph::PropertyBase* property )
320   : mProperty( dynamic_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) )
321   {
322   }
323
324   /**
325    * Non-virtual destructor; PropertyComponentAccessorW is not suitable as a base class.
326    */
327   ~PropertyComponentAccessorW()
328   {
329   }
330
331   /**
332    * Query whether the accessor is set.
333    * @return True if set.
334    */
335   bool IsSet() const
336   {
337     return mProperty != NULL;
338   }
339
340   /**
341    * Reset the property accessor
342    * @post Calling any other PropertyComponentAccessorW is invalid.
343    */
344   void Reset()
345   {
346     mProperty = NULL;
347   }
348
349   /**
350    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
351    */
352   bool IsClean() const
353   {
354     return mProperty->IsClean();
355   }
356
357   /**
358    * Read access to the property.
359    * @param [in] bufferIndex The current update buffer index.
360    */
361   const float& Get( BufferIndex bufferIndex ) const
362   {
363     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorW::Get() mProperty was NULL" );
364     return mProperty->Get( bufferIndex ).w; // W Component only!
365   }
366
367   /**
368    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
369    */
370   void Set( BufferIndex bufferIndex, float value ) const
371   {
372     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorW::Set() mProperty was NULL" );
373     mProperty->SetW( bufferIndex, value );
374   }
375
376   /**
377    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
378    */
379   void Bake( BufferIndex bufferIndex, float value ) const
380   {
381     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyComponentAccessorW::Bake() mProperty was NULL" );
382     mProperty->BakeW( bufferIndex, value );
383   }
384
385 private:
386
387   // Undefined
388   PropertyComponentAccessorW(const PropertyComponentAccessorW& property);
389
390   // Undefined
391   PropertyComponentAccessorW& operator=(const PropertyComponentAccessorW& rhs);
392
393 private:
394
395   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
396 };
397
398 } // namespace Internal
399
400 } // namespace Dali
401
402 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_ACCESSOR_H__