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