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