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 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 );
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.
53 class PropertyInputImpl
60 virtual ~PropertyInputImpl()
65 * Query the type of property input.
66 * @return The property type.
68 virtual Property::Type GetType() const = 0;
71 * Query the input value (for a constraint) has been initialized.
72 * @return True if initialized, otherwise the constraint should be skipped.
74 virtual bool InputInitialized() const = 0;
77 * Query the input value (for a constraint) has changed.
78 * @return True if the input value has changed.
80 virtual bool InputChanged() const = 0;
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.
88 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
90 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
91 return DUMMY_BOOLEAN_VALUE;
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.
100 virtual const float& GetFloat( BufferIndex bufferIndex ) const
102 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
103 return DUMMY_FLOAT_VALUE;
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.
112 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
114 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
115 return DUMMY_VECTOR2_VALUE;
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.
124 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
126 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
127 return DUMMY_VECTOR3_VALUE;
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.
136 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
138 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
139 return DUMMY_VECTOR4_VALUE;
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.
148 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
150 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
151 return DUMMY_QUATERNION_VALUE;
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.
160 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
162 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
163 return DUMMY_MATRIX3_VALUE;
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.
172 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
174 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
175 return DUMMY_MATRIX_VALUE;
178 // Accessors for Constraint functions
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.
188 virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
190 return GetBoolean( updateBufferIndex );
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.
201 virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
203 return GetFloat( updateBufferIndex );
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.
214 virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
216 return GetVector2( updateBufferIndex );
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.
227 virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
229 return GetVector3( updateBufferIndex );
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.
240 virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
242 return GetVector4( updateBufferIndex );
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.
253 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
255 return GetQuaternion( updateBufferIndex );
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.
266 virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
268 return GetMatrix3( updateBufferIndex );
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.
279 virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
281 return GetMatrix( updateBufferIndex );
285 * Print the property value using a stream.
286 * @param[in] debugStream The output stream.
287 * @param[in] bufferIndex The buffer to read from.
289 void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
293 case Property::BOOLEAN:
295 debugStream << GetBoolean( bufferIndex );
299 case Property::FLOAT:
301 debugStream << GetFloat( bufferIndex );
305 case Property::VECTOR2:
307 debugStream << GetVector2( bufferIndex );
311 case Property::VECTOR3:
313 debugStream << GetVector3( bufferIndex );
317 case Property::VECTOR4:
319 debugStream << GetVector4( bufferIndex );
323 case Property::ROTATION:
325 debugStream << GetQuaternion( bufferIndex );
329 case Property::MATRIX:
331 debugStream << GetMatrix( bufferIndex );
335 case Property::MATRIX3:
337 debugStream << GetMatrix3( bufferIndex );
342 break; // print nothing
347 } // namespace Internal
351 #endif // __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__