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.
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>
38 * These dummy values are used to handle PropertyInputImpl errors
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 );
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.
54 class PropertyInputImpl
61 virtual ~PropertyInputImpl()
66 * Query the type of property input.
67 * @return The property type.
69 virtual Property::Type GetType() const = 0;
72 * Query the input value (for a constraint) has been initialized.
73 * @return True if initialized, otherwise the constraint should be skipped.
75 virtual bool InputInitialized() const = 0;
78 * Query the input value (for a constraint) has changed.
79 * @return True if the input value has changed.
81 virtual bool InputChanged() const = 0;
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.
89 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
91 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
92 return DUMMY_BOOLEAN_VALUE;
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.
101 virtual const float& GetFloat( BufferIndex bufferIndex ) const
103 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
104 return DUMMY_FLOAT_VALUE;
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.
113 virtual const int& GetInteger( BufferIndex bufferIndex ) const
115 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
116 return DUMMY_INTEGER_VALUE;
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.
125 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
127 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
128 return DUMMY_VECTOR2_VALUE;
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.
137 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
139 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
140 return DUMMY_VECTOR3_VALUE;
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.
149 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
151 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
152 return DUMMY_VECTOR4_VALUE;
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.
161 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
163 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
164 return DUMMY_QUATERNION_VALUE;
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.
173 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
175 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
176 return DUMMY_MATRIX3_VALUE;
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.
185 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
187 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
188 return DUMMY_MATRIX_VALUE;
191 // Accessors for Constraint functions
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.
201 virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
203 return GetBoolean( updateBufferIndex );
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.
214 virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
216 return GetFloat( updateBufferIndex );
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.
227 virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
229 return GetInteger( updateBufferIndex );
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.
240 virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
242 return GetVector2( updateBufferIndex );
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.
253 virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
255 return GetVector3( updateBufferIndex );
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.
266 virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
268 return GetVector4( updateBufferIndex );
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.
279 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
281 return GetQuaternion( updateBufferIndex );
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.
292 virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
294 return GetMatrix3( updateBufferIndex );
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.
305 virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
307 return GetMatrix( updateBufferIndex );
311 * Print the property value using a stream.
312 * @param[in] debugStream The output stream.
313 * @param[in] bufferIndex The buffer to read from.
315 void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
319 case Property::BOOLEAN:
321 debugStream << GetBoolean( bufferIndex );
325 case Property::FLOAT:
327 debugStream << GetFloat( bufferIndex );
331 case Property::INTEGER:
333 debugStream << GetInteger( bufferIndex );
337 case Property::VECTOR2:
339 debugStream << GetVector2( bufferIndex );
343 case Property::VECTOR3:
345 debugStream << GetVector3( bufferIndex );
349 case Property::VECTOR4:
351 debugStream << GetVector4( bufferIndex );
355 case Property::ROTATION:
357 debugStream << GetQuaternion( bufferIndex );
361 case Property::MATRIX:
363 debugStream << GetMatrix( bufferIndex );
367 case Property::MATRIX3:
369 debugStream << GetMatrix3( bufferIndex );
374 break; // print nothing
379 } // namespace Internal
383 #endif // __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__