1 #ifndef __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__
2 #define __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
41 * These dummy values are used to handle PropertyInputImpl errors
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 );
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.
58 class PropertyInputImpl
65 virtual ~PropertyInputImpl()
70 * Query the type of property input.
71 * @return The property type.
73 virtual Property::Type GetType() const = 0;
76 * Query the input value (for a constraint) has been initialized.
77 * @return True if initialized, otherwise the constraint should be skipped.
79 virtual bool InputInitialized() const = 0;
82 * Query the input value (for a constraint) has changed.
83 * @return True if the input value has changed.
85 virtual bool InputChanged() const = 0;
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.
93 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
95 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
96 return DUMMY_BOOLEAN_VALUE;
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.
105 virtual const int& GetInteger( BufferIndex bufferIndex ) const
107 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
108 return DUMMY_INTEGER_VALUE;
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.
117 virtual const unsigned int& GetUnsignedInteger( BufferIndex bufferIndex ) const
119 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
120 return DUMMY_UNSIGNED_INTEGER_VALUE;
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.
129 virtual const float& GetFloat( BufferIndex bufferIndex ) const
131 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
132 return DUMMY_FLOAT_VALUE;
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.
141 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
143 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
144 return DUMMY_VECTOR2_VALUE;
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.
153 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
155 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
156 return DUMMY_VECTOR3_VALUE;
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.
165 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
167 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
168 return DUMMY_VECTOR4_VALUE;
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.
177 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
179 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
180 return DUMMY_QUATERNION_VALUE;
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.
189 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
191 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
192 return DUMMY_MATRIX3_VALUE;
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.
201 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
203 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
204 return DUMMY_MATRIX_VALUE;
207 // Accessors for Constraint functions
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.
217 virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
219 return GetBoolean( updateBufferIndex );
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.
230 virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
232 return GetInteger( updateBufferIndex );
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.
243 virtual const unsigned int& GetConstraintInputUnsignedInteger( BufferIndex updateBufferIndex ) const
245 return GetUnsignedInteger( updateBufferIndex );
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.
256 virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
258 return GetFloat( updateBufferIndex );
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.
269 virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
271 return GetVector2( updateBufferIndex );
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.
282 virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
284 return GetVector3( updateBufferIndex );
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.
295 virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
297 return GetVector4( updateBufferIndex );
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.
308 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
310 return GetQuaternion( updateBufferIndex );
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.
321 virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
323 return GetMatrix3( updateBufferIndex );
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.
334 virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
336 return GetMatrix( updateBufferIndex );
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.
345 void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
349 case Property::BOOLEAN:
351 debugStream << GetBoolean( bufferIndex );
355 case Property::INTEGER:
357 debugStream << GetInteger( bufferIndex );
361 case Property::UNSIGNED_INTEGER:
363 debugStream << GetUnsignedInteger( bufferIndex );
367 case Property::FLOAT:
369 debugStream << GetFloat( bufferIndex );
373 case Property::VECTOR2:
375 debugStream << GetVector2( bufferIndex );
379 case Property::VECTOR3:
381 debugStream << GetVector3( bufferIndex );
385 case Property::VECTOR4:
387 debugStream << GetVector4( bufferIndex );
391 case Property::ROTATION:
393 debugStream << GetQuaternion( bufferIndex );
397 case Property::MATRIX:
399 debugStream << GetMatrix( bufferIndex );
403 case Property::MATRIX3:
405 debugStream << GetMatrix3( bufferIndex );
410 break; // print nothing
415 } // namespace Internal
419 #endif // __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__