Merge "Added api function to specify speed factor of an animation" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / property-input-accessor.h
1 #ifndef __DALI_PROPERTY_INPUT_ACCESSOR_H__
2 #define __DALI_PROPERTY_INPUT_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/object/property-types.h>
23 #include <dali/internal/event/common/property-input-impl.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 class PropertyInputAccessor
32 {
33 public:
34
35   /**
36    * Create the PropertyInputAccessor.
37    */
38   PropertyInputAccessor()
39   : mInput( NULL )
40   {
41   }
42
43   /**
44    * Create the PropertyInputAccessor.
45    */
46   PropertyInputAccessor( const PropertyInputImpl* input, int /*componentIndex*/ )
47   : mInput( input )
48   {
49   }
50
51   /**
52    * Copy from a PropertyInputAccessor
53    */
54   PropertyInputAccessor( const PropertyInputAccessor& accessor )
55   : mInput( accessor.mInput )
56   {
57   }
58
59   /**
60    * Copy from a PropertyInputAccessor
61    */
62   PropertyInputAccessor& operator=(const PropertyInputAccessor& accessor)
63   {
64     mInput = accessor.mInput;
65
66     return *this;
67   }
68
69   /**
70    * Set the property input.
71    */
72   void SetInput( const PropertyInputImpl& input, int componentIndex )
73   {
74     DALI_ASSERT_DEBUG( componentIndex < 0 && "Did not expect a valid component index" );
75     mInput = &input;
76   }
77
78   /**
79    * Retrieve the property input.
80    */
81   const PropertyInputImpl* GetInput() const
82   {
83     return mInput;
84   }
85
86   /**
87    * @copydoc Dali::Internal::PropertyInputImpl::GetType()
88    */
89   Property::Type GetType() const
90   {
91     return mInput->GetType();
92   }
93
94   /**
95    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputBoolean()
96    */
97   const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
98   {
99     return mInput->GetConstraintInputBoolean( updateBufferIndex );
100   }
101
102   /**
103    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputFloat()
104    */
105   const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
106   {
107     return mInput->GetConstraintInputFloat( updateBufferIndex );
108   }
109
110   /**
111    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputInteger() const
112    */
113   const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
114   {
115     return mInput->GetConstraintInputInteger( updateBufferIndex );
116   }
117
118   /**
119    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector2()
120    */
121   const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
122   {
123     return mInput->GetConstraintInputVector2( updateBufferIndex );
124   }
125
126   /**
127    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3()
128    */
129   const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
130   {
131     return mInput->GetConstraintInputVector3( updateBufferIndex );
132   }
133
134   /**
135    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4()
136    */
137   const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
138   {
139     return mInput->GetConstraintInputVector4( updateBufferIndex );
140   }
141
142   /**
143    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion()
144    */
145   const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
146   {
147     return mInput->GetConstraintInputQuaternion( updateBufferIndex );
148   }
149
150   /**
151    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3()
152    */
153   const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
154   {
155     return mInput->GetConstraintInputMatrix3( updateBufferIndex );
156   }
157
158   /**
159    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
160    */
161   const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
162   {
163     return mInput->GetConstraintInputMatrix( updateBufferIndex );
164   }
165
166 public:
167
168   const PropertyInputImpl* mInput;
169 };
170
171 class PropertyInputComponentAccessor
172 {
173 public:
174
175   /**
176    * Create the PropertyInputComponentAccessor.
177    */
178   PropertyInputComponentAccessor()
179   : mInput( NULL ),
180     mComponentIndex( 0 )
181   {
182   }
183
184   /**
185    * Create the PropertyInputComponentAccessor.
186    */
187   PropertyInputComponentAccessor( const PropertyInputImpl* input, int componentIndex )
188   : mInput( input ),
189     mComponentIndex( componentIndex )
190   {
191   }
192
193   /**
194    * Copy from a PropertyInputAccessor
195    */
196   PropertyInputComponentAccessor( const PropertyInputAccessor& accessor )
197   : mInput( accessor.mInput ),
198     mComponentIndex( -1 )
199   {
200   }
201
202   /**
203    * Copy from a PropertyInputComponentAccessor
204    */
205   PropertyInputComponentAccessor( const PropertyInputComponentAccessor& accessor )
206   : mInput( accessor.mInput ),
207     mComponentIndex( accessor.mComponentIndex )
208   {
209   }
210
211   /**
212    * Assign from a PropertyInputComponentAccessor
213    */
214   PropertyInputComponentAccessor& operator=(const PropertyInputComponentAccessor& accessor)
215   {
216     mInput = accessor.mInput;
217     mComponentIndex = accessor.mComponentIndex;
218     return *this;
219   }
220
221   /**
222    * Set the property input.
223    */
224   void SetInput( const PropertyInputImpl& input, int componentIndex )
225   {
226     mInput = &input;
227     mComponentIndex = componentIndex;
228   }
229
230   /**
231    * Retrieve the property input.
232    */
233   const PropertyInputImpl* GetInput() const
234   {
235     return mInput;
236   }
237
238   /**
239    * @copydoc Dali::Internal::PropertyInputImpl::GetType()
240    */
241   Property::Type GetType() const
242   {
243     return mInput->GetType();
244   }
245
246   /**
247    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputBoolean()
248    */
249   const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
250   {
251     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
252
253     return mInput->GetConstraintInputBoolean( updateBufferIndex );
254   }
255
256   /**
257    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputFloat()
258    */
259   const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
260   {
261     // Invalid index is ok
262     if ( mComponentIndex < 0 )
263     {
264       // Not a Vector3 or Vector4 component, expecting float type
265       return mInput->GetConstraintInputFloat( updateBufferIndex );
266     }
267     else if ( PropertyTypes::Get< Vector3 >() == mInput->GetType() )
268     {
269       if ( 0 == mComponentIndex )
270       {
271         return mInput->GetConstraintInputVector3( updateBufferIndex ).x;
272       }
273       else if ( 1 == mComponentIndex )
274       {
275         return mInput->GetConstraintInputVector3( updateBufferIndex ).y;
276       }
277
278       DALI_ASSERT_DEBUG( 2 == mComponentIndex && "Invalid Vector3 component index" );
279       return mInput->GetConstraintInputVector3( updateBufferIndex ).z;
280     }
281
282     // Expecting Vector4
283     if ( 0 == mComponentIndex )
284     {
285       return mInput->GetConstraintInputVector4( updateBufferIndex ).x;
286     }
287     else if ( 1 == mComponentIndex )
288     {
289       return mInput->GetConstraintInputVector4( updateBufferIndex ).y;
290     }
291     else if ( 2 == mComponentIndex )
292     {
293       return mInput->GetConstraintInputVector4( updateBufferIndex ).y;
294     }
295
296     DALI_ASSERT_DEBUG( 3 == mComponentIndex && "Invalid Vector4 component index" );
297     return mInput->GetConstraintInputVector4( updateBufferIndex ).w;
298   }
299
300   /**
301    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputInteger() const
302    */
303   const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
304   {
305     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
306
307     return mInput->GetConstraintInputInteger( updateBufferIndex );
308   }
309
310   /**
311    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector2()
312    */
313   const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
314   {
315     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
316
317     return mInput->GetConstraintInputVector2( updateBufferIndex );
318   }
319
320   /**
321    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3()
322    */
323   const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
324   {
325     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
326
327     return mInput->GetConstraintInputVector3( updateBufferIndex );
328   }
329
330   /**
331    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4()
332    */
333   const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
334   {
335     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
336
337     return mInput->GetConstraintInputVector4( updateBufferIndex );
338   }
339
340   /**
341    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion()
342    */
343   const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
344   {
345     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
346
347     return mInput->GetConstraintInputQuaternion( updateBufferIndex );
348   }
349
350   /**
351    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3()
352    */
353   const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
354   {
355     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
356
357     return mInput->GetConstraintInputMatrix3( updateBufferIndex );
358   }
359
360   /**
361    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
362    */
363   const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
364   {
365     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
366
367     return mInput->GetConstraintInputMatrix( updateBufferIndex );
368   }
369
370 public:
371
372   const PropertyInputImpl* mInput;
373   int mComponentIndex;
374 };
375
376 } // namespace Internal
377
378 } // namespace Dali
379
380 #endif // __DALI_PROPERTY_INPUT_ACCESSOR_H__