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