Merge "Added animation and constraint support for UNSIGNED_INTEGER property type...
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-input-impl.h
1 #ifndef __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__
2 #define __DALI_INTERNAL_PROPERTY_INPUT_IMPL_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 // EXTERNAL INCLUDES
22 #include <iostream>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/property-input.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/public-api/math/quaternion.h>
30 #include <dali/public-api/math/matrix3.h>
31 #include <dali/public-api/math/matrix.h>
32 #include <dali/internal/common/buffer-index.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39
40 /**
41  * These dummy values are used to handle PropertyInputImpl errors
42  */
43 static const bool DUMMY_BOOLEAN_VALUE( false );
44 static const float DUMMY_FLOAT_VALUE( 0.0f );
45 static const int DUMMY_INTEGER_VALUE( 0 );
46 static const unsigned int DUMMY_UNSIGNED_INTEGER_VALUE( 0u );
47 static const Vector2 DUMMY_VECTOR2_VALUE( 0.0f, 0.0f );
48 static const Vector3 DUMMY_VECTOR3_VALUE( 0.0f, 0.0f, 0.0f );
49 static const Vector4 DUMMY_VECTOR4_VALUE( 0.0f, 0.0f, 0.0f, 0.0f );
50 static const Matrix3 DUMMY_MATRIX3_VALUE;
51 static const Matrix DUMMY_MATRIX_VALUE;
52 static const Quaternion DUMMY_QUATERNION_VALUE( 1.0f, 0.0f, 0.0f, 0.0f );
53
54 /**
55  * An abstract interface for receiving property values, and for querying whether
56  * a property value has changed i.e. whether a constraint needs to be reapplied.
57  */
58 class PropertyInputImpl
59 {
60 public:
61
62   /**
63    * Virtual destructor.
64    */
65   virtual ~PropertyInputImpl()
66   {
67   }
68
69   /**
70    * Query the type of property input.
71    * @return The property type.
72    */
73   virtual Property::Type GetType() const = 0;
74
75   /**
76    * Query the input value (for a constraint) has been initialized.
77    * @return True if initialized, otherwise the constraint should be skipped.
78    */
79   virtual bool InputInitialized() const = 0;
80
81   /**
82    * Query the input value (for a constraint) has changed.
83    * @return True if the input value has changed.
84    */
85   virtual bool InputChanged() const = 0;
86
87   /**
88    * Retrieve a boolean value.
89    * @pre GetType() returns Property::BOOLEAN.
90    * @param[in] bufferIndex The buffer to read from.
91    * @return The boolean value.
92    */
93   virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
94   {
95     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
96     return DUMMY_BOOLEAN_VALUE;
97   }
98
99   /**
100    * Retrieve an integer value.
101    * @pre GetType() returns Property::INTEGER.
102    * @param[in] bufferIndex The buffer to read from.
103    * @return The integer value.
104    */
105   virtual const int& GetInteger( BufferIndex bufferIndex ) const
106   {
107     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
108     return DUMMY_INTEGER_VALUE;
109   }
110
111   /**
112    * Retrieve an integer value.
113    * @pre GetType() returns Property::UNSIGNED_INTEGER.
114    * @param[in] bufferIndex The buffer to read from.
115    * @return The integer value.
116    */
117   virtual const unsigned int& GetUnsignedInteger( BufferIndex bufferIndex ) const
118   {
119     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
120     return DUMMY_UNSIGNED_INTEGER_VALUE;
121   }
122
123   /**
124    * Retrieve a float value.
125    * @pre GetType() returns Property::FLOAT.
126    * @param[in] bufferIndex The buffer to read from.
127    * @return The float value.
128    */
129   virtual const float& GetFloat( BufferIndex bufferIndex ) const
130   {
131     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
132     return DUMMY_FLOAT_VALUE;
133   }
134
135   /**
136    * Retrieve a Vector2 value.
137    * @pre GetType() returns Property::VECTOR2.
138    * @param[in] bufferIndex The buffer to read from.
139    * @return The Vector2 value.
140    */
141   virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
142   {
143     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
144     return DUMMY_VECTOR2_VALUE;
145   }
146
147   /**
148    * Retrieve a Vector3 value.
149    * @pre GetType() returns Property::VECTOR3.
150    * @param[in] bufferIndex The buffer to read from.
151    * @return The Vector3 value.
152    */
153   virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
154   {
155     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
156     return DUMMY_VECTOR3_VALUE;
157   }
158
159   /**
160    * Retrieve a Vector4 value.
161    * @pre GetType() returns Property::VECTOR4.
162    * @param[in] bufferIndex The buffer to read from.
163    * @return The Vector4 value.
164    */
165   virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
166   {
167     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
168     return DUMMY_VECTOR4_VALUE;
169   }
170
171   /**
172    * Retrieve a Quaternion value.
173    * @pre GetType() returns Property::Quaternion.
174    * @param[in] bufferIndex The buffer to read from.
175    * @return The Quaternion value.
176    */
177   virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
178   {
179     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
180     return DUMMY_QUATERNION_VALUE;
181   }
182
183   /**
184    * Retrieve a Matrix value.
185    * @pre GetType() returns Property::Matrix.
186    * @param[in] bufferIndex The buffer to read from.
187    * @return The Matrix value.
188    */
189   virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
190   {
191     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
192     return DUMMY_MATRIX3_VALUE;
193   }
194
195   /**
196    * Retrieve a Matrix value.
197    * @pre GetType() returns Property::Matrix.
198    * @param[in] bufferIndex The buffer to read from.
199    * @return The Matrix value.
200    */
201   virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
202   {
203     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
204     return DUMMY_MATRIX_VALUE;
205   }
206
207   // Accessors for Constraint functions
208
209   /**
210    * Retrieve a boolean input for a constraint function.
211    * @note For inherited properties, this method should be overriden to return the value
212    * from the previous frame i.e. not from the current update buffer.
213    * @pre GetType() returns Property::BOOLEAN.
214    * @param[in] updateBufferIndex The current update buffer index.
215    * @return The boolean value.
216    */
217   virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
218   {
219     return GetBoolean( updateBufferIndex );
220   }
221
222   /**
223    * Retrieve an integer input for a constraint function.
224    * @note For inherited properties, this method should be overriden to return the value
225    * from the previous frame i.e. not from the current update buffer.
226    * @pre GetType() returns Property::INTEGER.
227    * @param[in] updateBufferIndex The current update buffer index.
228    * @return The integer value.
229    */
230   virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
231   {
232     return GetInteger( updateBufferIndex );
233   }
234
235   /**
236    * Retrieve an unsigned integer input for a constraint function.
237    * @note For inherited properties, this method should be overriden to return the value
238    * from the previous frame i.e. not from the current update buffer.
239    * @pre GetType() returns Property::UNSIGNED_INTEGER.
240    * @param[in] updateBufferIndex The current update buffer index.
241    * @return The integer value.
242    */
243   virtual const unsigned int& GetConstraintInputUnsignedInteger( BufferIndex updateBufferIndex ) const
244   {
245     return GetUnsignedInteger( updateBufferIndex );
246   }
247
248   /**
249    * Retrieve a float input for a constraint function.
250    * @note For inherited properties, this method should be overriden to return the value
251    * from the previous frame i.e. not from the current update buffer.
252    * @pre GetType() returns Property::FLOAT.
253    * @param[in] updateBufferIndex The current update buffer index.
254    * @return The float value.
255    */
256   virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
257   {
258     return GetFloat( updateBufferIndex );
259   }
260
261   /**
262    * Retrieve a Vector2 input for a constraint function.
263    * @note For inherited properties, this method should be overriden to return the value
264    * from the previous frame i.e. not from the current update buffer.
265    * @pre GetType() returns Property::VECTOR2.
266    * @param[in] updateBufferIndex The buffer to read from.
267    * @return The Vector2 value.
268    */
269   virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
270   {
271     return GetVector2( updateBufferIndex );
272   }
273
274   /**
275    * Retrieve a Vector3 input for a constraint function.
276    * @note For inherited properties, this method should be overriden to return the value
277    * from the previous frame i.e. not from the current update buffer.
278    * @pre GetType() returns Property::VECTOR3.
279    * @param[in] updateBufferIndex The buffer to read from.
280    * @return The Vector3 value.
281    */
282   virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
283   {
284     return GetVector3( updateBufferIndex );
285   }
286
287   /**
288    * Retrieve a Vector4 input for a constraint function.
289    * @note For inherited properties, this method should be overriden to return the value
290    * from the previous frame i.e. not from the current update buffer.
291    * @pre GetType() returns Property::VECTOR4.
292    * @param[in] updateBufferIndex The buffer to read from.
293    * @return The Vector4 value.
294    */
295   virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
296   {
297     return GetVector4( updateBufferIndex );
298   }
299
300   /**
301    * Retrieve a Quaternion input for a constraint function.
302    * @note For inherited properties, this method should be overriden to return the value
303    * from the previous frame i.e. not from the current update buffer.
304    * @pre GetType() returns Property::Quaternion.
305    * @param[in] updateBufferIndex The buffer to read from.
306    * @return The Quaternion value.
307    */
308   virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
309   {
310     return GetQuaternion( updateBufferIndex );
311   }
312
313   /**
314    * Retrieve a Matrix3 input for a constraint function.
315    * @note For inherited properties, this method should be overriden to return the value
316    * from the previous frame i.e. not from the current update buffer.
317    * @pre GetType() returns Property::Matrix.
318    * @param[in] updateBufferIndex The buffer to read from.
319    * @return The Matrix value.
320    */
321   virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
322   {
323     return GetMatrix3( updateBufferIndex );
324   }
325
326   /**
327    * Retrieve a Matrix input for a constraint function.
328    * @note For inherited properties, this method should be overriden to return the value
329    * from the previous frame i.e. not from the current update buffer.
330    * @pre GetType() returns Property::Matrix.
331    * @param[in] updateBufferIndex The buffer to read from.
332    * @return The Matrix value.
333    */
334   virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
335   {
336     return GetMatrix( updateBufferIndex );
337   }
338
339   /**
340    * Print the property value using a stream.
341    * @param[in] debugStream The output stream.
342    * @param[in] bufferIndex The buffer to read from.
343    * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
344    */
345   void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
346   {
347     switch ( GetType() )
348     {
349       case Property::BOOLEAN:
350       {
351         debugStream << GetBoolean( bufferIndex );
352         break;
353       }
354
355       case Property::INTEGER:
356       {
357         debugStream << GetInteger( bufferIndex );
358         break;
359       }
360
361       case Property::UNSIGNED_INTEGER:
362       {
363         debugStream << GetUnsignedInteger( bufferIndex );
364         break;
365       }
366
367       case Property::FLOAT:
368       {
369         debugStream << GetFloat( bufferIndex );
370         break;
371       }
372
373       case Property::VECTOR2:
374       {
375         debugStream << GetVector2( bufferIndex );
376         break;
377       }
378
379       case Property::VECTOR3:
380       {
381         debugStream << GetVector3( bufferIndex );
382         break;
383       }
384
385       case Property::VECTOR4:
386       {
387         debugStream << GetVector4( bufferIndex );
388         break;
389       }
390
391       case Property::ROTATION:
392       {
393         debugStream << GetQuaternion( bufferIndex );
394         break;
395       }
396
397       case Property::MATRIX:
398       {
399         debugStream << GetMatrix( bufferIndex );
400         break;
401       }
402
403       case Property::MATRIX3:
404       {
405         debugStream << GetMatrix3( bufferIndex );
406         break;
407       }
408
409       default:
410         break; // print nothing
411     }
412   }
413 };
414
415 } // namespace Internal
416
417 } // namespace Dali
418
419 #endif // __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__