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