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 Vector2 DUMMY_VECTOR2_VALUE( 0.0f, 0.0f );
47 static const Vector3 DUMMY_VECTOR3_VALUE( 0.0f, 0.0f, 0.0f );
48 static const Vector4 DUMMY_VECTOR4_VALUE( 0.0f, 0.0f, 0.0f, 0.0f );
49 static const Matrix3 DUMMY_MATRIX3_VALUE;
50 static const Matrix DUMMY_MATRIX_VALUE;
51 static const Quaternion DUMMY_QUATERNION_VALUE( 1.0f, 0.0f, 0.0f, 0.0f );
54 * An abstract interface for receiving property values, and for querying whether
55 * a property value has changed i.e. whether a constraint needs to be reapplied.
57 class PropertyInputImpl
64 virtual ~PropertyInputImpl()
69 * Query the type of property input.
70 * @return The property type.
72 virtual Property::Type GetType() const = 0;
75 * Query the input value (for a constraint) has been initialized.
76 * @return True if initialized, otherwise the constraint should be skipped.
78 virtual bool InputInitialized() const = 0;
81 * Query the input value (for a constraint) has changed.
82 * @return True if the input value has changed.
84 virtual bool InputChanged() const = 0;
87 * Retrieve a boolean value.
88 * @pre GetType() returns Property::BOOLEAN.
89 * @param[in] bufferIndex The buffer to read from.
90 * @return The boolean value.
92 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
94 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
95 return DUMMY_BOOLEAN_VALUE;
99 * Retrieve a float value.
100 * @pre GetType() returns Property::FLOAT.
101 * @param[in] bufferIndex The buffer to read from.
102 * @return The float value.
104 virtual const float& GetFloat( BufferIndex bufferIndex ) const
106 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
107 return DUMMY_FLOAT_VALUE;
111 * Retrieve an integer value.
112 * @pre GetType() returns Property::INTEGER.
113 * @param[in] bufferIndex The buffer to read from.
114 * @return The integer value.
116 virtual const int& GetInteger( BufferIndex bufferIndex ) const
118 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
119 return DUMMY_INTEGER_VALUE;
123 * Retrieve a Vector2 value.
124 * @pre GetType() returns Property::VECTOR2.
125 * @param[in] bufferIndex The buffer to read from.
126 * @return The Vector2 value.
128 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
130 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
131 return DUMMY_VECTOR2_VALUE;
135 * Retrieve a Vector3 value.
136 * @pre GetType() returns Property::VECTOR3.
137 * @param[in] bufferIndex The buffer to read from.
138 * @return The Vector3 value.
140 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
142 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
143 return DUMMY_VECTOR3_VALUE;
147 * Retrieve a Vector4 value.
148 * @pre GetType() returns Property::VECTOR4.
149 * @param[in] bufferIndex The buffer to read from.
150 * @return The Vector4 value.
152 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
154 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
155 return DUMMY_VECTOR4_VALUE;
159 * Retrieve a Quaternion value.
160 * @pre GetType() returns Property::Quaternion.
161 * @param[in] bufferIndex The buffer to read from.
162 * @return The Quaternion value.
164 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
166 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
167 return DUMMY_QUATERNION_VALUE;
171 * Retrieve a Matrix value.
172 * @pre GetType() returns Property::Matrix.
173 * @param[in] bufferIndex The buffer to read from.
174 * @return The Matrix value.
176 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
178 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
179 return DUMMY_MATRIX3_VALUE;
183 * Retrieve a Matrix value.
184 * @pre GetType() returns Property::Matrix.
185 * @param[in] bufferIndex The buffer to read from.
186 * @return The Matrix value.
188 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
190 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
191 return DUMMY_MATRIX_VALUE;
194 // Accessors for Constraint functions
197 * Retrieve a boolean input for a constraint function.
198 * @note For inherited properties, this method should be overriden to return the value
199 * from the previous frame i.e. not from the current update buffer.
200 * @pre GetType() returns Property::BOOLEAN.
201 * @param[in] updateBufferIndex The current update buffer index.
202 * @return The boolean value.
204 virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
206 return GetBoolean( updateBufferIndex );
210 * Retrieve a float 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::FLOAT.
214 * @param[in] updateBufferIndex The current update buffer index.
215 * @return The float value.
217 virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
219 return GetFloat( 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 a Vector2 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::VECTOR2.
240 * @param[in] updateBufferIndex The buffer to read from.
241 * @return The Vector2 value.
243 virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
245 return GetVector2( updateBufferIndex );
249 * Retrieve a Vector3 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::VECTOR3.
253 * @param[in] updateBufferIndex The buffer to read from.
254 * @return The Vector3 value.
256 virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
258 return GetVector3( updateBufferIndex );
262 * Retrieve a Vector4 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::VECTOR4.
266 * @param[in] updateBufferIndex The buffer to read from.
267 * @return The Vector4 value.
269 virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
271 return GetVector4( updateBufferIndex );
275 * Retrieve a Quaternion 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::Quaternion.
279 * @param[in] updateBufferIndex The buffer to read from.
280 * @return The Quaternion value.
282 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
284 return GetQuaternion( updateBufferIndex );
288 * Retrieve a Matrix3 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::Matrix.
292 * @param[in] updateBufferIndex The buffer to read from.
293 * @return The Matrix value.
295 virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
297 return GetMatrix3( updateBufferIndex );
301 * Retrieve a Matrix 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::Matrix.
305 * @param[in] updateBufferIndex The buffer to read from.
306 * @return The Matrix value.
308 virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
310 return GetMatrix( updateBufferIndex );
314 * Print the property value using a stream.
315 * @param[in] debugStream The output stream.
316 * @param[in] bufferIndex The buffer to read from.
317 * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
319 void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
323 case Property::BOOLEAN:
325 debugStream << GetBoolean( bufferIndex );
329 case Property::FLOAT:
331 debugStream << GetFloat( bufferIndex );
335 case Property::INTEGER:
337 debugStream << GetInteger( bufferIndex );
341 case Property::VECTOR2:
343 debugStream << GetVector2( bufferIndex );
347 case Property::VECTOR3:
349 debugStream << GetVector3( bufferIndex );
353 case Property::VECTOR4:
355 debugStream << GetVector4( bufferIndex );
359 case Property::ROTATION:
361 debugStream << GetQuaternion( bufferIndex );
365 case Property::MATRIX:
367 debugStream << GetMatrix( bufferIndex );
371 case Property::MATRIX3:
373 debugStream << GetMatrix3( bufferIndex );
378 break; // print nothing
383 } // namespace Internal
387 #endif // __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__