License conversion from Flora to Apache 2.0
[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::GetConstraintInputVector2()
112    */
113   const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
114   {
115     return mInput->GetConstraintInputVector2( updateBufferIndex );
116   }
117
118   /**
119    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3()
120    */
121   const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
122   {
123     return mInput->GetConstraintInputVector3( updateBufferIndex );
124   }
125
126   /**
127    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4()
128    */
129   const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
130   {
131     return mInput->GetConstraintInputVector4( updateBufferIndex );
132   }
133
134   /**
135    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion()
136    */
137   const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
138   {
139     return mInput->GetConstraintInputQuaternion( updateBufferIndex );
140   }
141
142   /**
143    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3()
144    */
145   const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
146   {
147     return mInput->GetConstraintInputMatrix3( updateBufferIndex );
148   }
149
150   /**
151    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
152    */
153   const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
154   {
155     return mInput->GetConstraintInputMatrix( updateBufferIndex );
156   }
157
158 public:
159
160   const PropertyInputImpl* mInput;
161 };
162
163 class PropertyInputComponentAccessor
164 {
165 public:
166
167   /**
168    * Create the PropertyInputComponentAccessor.
169    */
170   PropertyInputComponentAccessor()
171   : mInput( NULL ),
172     mComponentIndex( 0 )
173   {
174   }
175
176   /**
177    * Create the PropertyInputComponentAccessor.
178    */
179   PropertyInputComponentAccessor( const PropertyInputImpl* input, int componentIndex )
180   : mInput( input ),
181     mComponentIndex( componentIndex )
182   {
183   }
184
185   /**
186    * Copy from a PropertyInputAccessor
187    */
188   PropertyInputComponentAccessor( const PropertyInputAccessor& accessor )
189   : mInput( accessor.mInput ),
190     mComponentIndex( -1 )
191   {
192   }
193
194   /**
195    * Copy from a PropertyInputComponentAccessor
196    */
197   PropertyInputComponentAccessor( const PropertyInputComponentAccessor& accessor )
198   : mInput( accessor.mInput ),
199     mComponentIndex( accessor.mComponentIndex )
200   {
201   }
202
203   /**
204    * Assign from a PropertyInputComponentAccessor
205    */
206   PropertyInputComponentAccessor& operator=(const PropertyInputComponentAccessor& accessor)
207   {
208     mInput = accessor.mInput;
209     mComponentIndex = accessor.mComponentIndex;
210     return *this;
211   }
212
213   /**
214    * Set the property input.
215    */
216   void SetInput( const PropertyInputImpl& input, int componentIndex )
217   {
218     mInput = &input;
219     mComponentIndex = componentIndex;
220   }
221
222   /**
223    * Retrieve the property input.
224    */
225   const PropertyInputImpl* GetInput() const
226   {
227     return mInput;
228   }
229
230   /**
231    * @copydoc Dali::Internal::PropertyInputImpl::GetType()
232    */
233   Property::Type GetType() const
234   {
235     return mInput->GetType();
236   }
237
238   /**
239    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputBoolean()
240    */
241   const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
242   {
243     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
244
245     return mInput->GetConstraintInputBoolean( updateBufferIndex );
246   }
247
248   /**
249    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputFloat()
250    */
251   const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
252   {
253     // Invalid index is ok
254     if ( mComponentIndex < 0 )
255     {
256       // Not a Vector3 or Vector4 component, expecting float type
257       return mInput->GetConstraintInputFloat( updateBufferIndex );
258     }
259     else if ( PropertyTypes::Get< Vector3 >() == mInput->GetType() )
260     {
261       if ( 0 == mComponentIndex )
262       {
263         return mInput->GetConstraintInputVector3( updateBufferIndex ).x;
264       }
265       else if ( 1 == mComponentIndex )
266       {
267         return mInput->GetConstraintInputVector3( updateBufferIndex ).y;
268       }
269
270       DALI_ASSERT_DEBUG( 2 == mComponentIndex && "Invalid Vector3 component index" );
271       return mInput->GetConstraintInputVector3( updateBufferIndex ).z;
272     }
273
274     // Expecting Vector4
275     if ( 0 == mComponentIndex )
276     {
277       return mInput->GetConstraintInputVector4( updateBufferIndex ).x;
278     }
279     else if ( 1 == mComponentIndex )
280     {
281       return mInput->GetConstraintInputVector4( updateBufferIndex ).y;
282     }
283     else if ( 2 == mComponentIndex )
284     {
285       return mInput->GetConstraintInputVector4( updateBufferIndex ).y;
286     }
287
288     DALI_ASSERT_DEBUG( 3 == mComponentIndex && "Invalid Vector4 component index" );
289     return mInput->GetConstraintInputVector4( updateBufferIndex ).w;
290   }
291
292   /**
293    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector2()
294    */
295   const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
296   {
297     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
298
299     return mInput->GetConstraintInputVector2( updateBufferIndex );
300   }
301
302   /**
303    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3()
304    */
305   const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
306   {
307     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
308
309     return mInput->GetConstraintInputVector3( updateBufferIndex );
310   }
311
312   /**
313    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4()
314    */
315   const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
316   {
317     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
318
319     return mInput->GetConstraintInputVector4( updateBufferIndex );
320   }
321
322   /**
323    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion()
324    */
325   const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
326   {
327     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
328
329     return mInput->GetConstraintInputQuaternion( updateBufferIndex );
330   }
331
332   /**
333    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3()
334    */
335   const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
336   {
337     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
338
339     return mInput->GetConstraintInputMatrix3( updateBufferIndex );
340   }
341
342   /**
343    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
344    */
345   const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
346   {
347     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
348
349     return mInput->GetConstraintInputMatrix( updateBufferIndex );
350   }
351
352 public:
353
354   const PropertyInputImpl* mInput;
355   int mComponentIndex;
356 };
357
358 } // namespace Internal
359
360 } // namespace Dali
361
362 #endif // __DALI_PROPERTY_INPUT_ACCESSOR_H__