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 * An abstract interface for receiving property values, and for querying whether
42 * a property value has changed i.e. whether a constraint needs to be reapplied.
44 class PropertyInputImpl
51 virtual ~PropertyInputImpl()
56 * Query the type of property input.
57 * @return The property type.
59 virtual Property::Type GetType() const = 0;
62 * Query the input value (for a constraint) has been initialized.
63 * @return True if initialized, otherwise the constraint should be skipped.
65 virtual bool InputInitialized() const = 0;
68 * Query the input value (for a constraint) has changed.
69 * @return True if the input value has changed.
71 virtual bool InputChanged() const = 0;
74 * Retrieve a boolean value.
75 * @pre GetType() returns Property::BOOLEAN.
76 * @param[in] bufferIndex The buffer to read from.
77 * @return The boolean value.
79 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
81 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
82 // the return will never be executed due to assert above so just keep the compiler happy
83 return reinterpret_cast<const bool&>(*this);
87 * Retrieve an integer value.
88 * @pre GetType() returns Property::INTEGER.
89 * @param[in] bufferIndex The buffer to read from.
90 * @return The integer value.
92 virtual const int& GetInteger( BufferIndex bufferIndex ) const
94 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
95 // the return will never be executed due to assert above so just keep the compiler happy
96 return reinterpret_cast<const int&>(*this);
100 * Retrieve a float value.
101 * @pre GetType() returns Property::FLOAT.
102 * @param[in] bufferIndex The buffer to read from.
103 * @return The float value.
105 virtual const float& GetFloat( BufferIndex bufferIndex ) const
107 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
108 // the return will never be executed due to assert above so just keep the compiler happy
109 return reinterpret_cast<const float&>(*this);
113 * Retrieve a Vector2 value.
114 * @pre GetType() returns Property::VECTOR2.
115 * @param[in] bufferIndex The buffer to read from.
116 * @return The Vector2 value.
118 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
120 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
121 // the return will never be executed due to assert above so just keep the compiler happy
122 return reinterpret_cast<const Vector2&>(*this);
126 * Retrieve a Vector3 value.
127 * @pre GetType() returns Property::VECTOR3.
128 * @param[in] bufferIndex The buffer to read from.
129 * @return The Vector3 value.
131 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
133 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
134 // the return will never be executed due to assert above so just keep the compiler happy
135 return reinterpret_cast<const Vector3&>(*this);
139 * Retrieve a Vector4 value.
140 * @pre GetType() returns Property::VECTOR4.
141 * @param[in] bufferIndex The buffer to read from.
142 * @return The Vector4 value.
144 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
146 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
147 // the return will never be executed due to assert above so just keep the compiler happy
148 return reinterpret_cast<const Vector4&>(*this);
152 * Retrieve a Quaternion value.
153 * @pre GetType() returns Property::Quaternion.
154 * @param[in] bufferIndex The buffer to read from.
155 * @return The Quaternion value.
157 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
159 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
160 // the return will never be executed due to assert above so just keep the compiler happy
161 return reinterpret_cast<const Quaternion&>(*this);
165 * Retrieve a Matrix value.
166 * @pre GetType() returns Property::Matrix.
167 * @param[in] bufferIndex The buffer to read from.
168 * @return The Matrix value.
170 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
172 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
173 // the return will never be executed due to assert above so just keep the compiler happy
174 return reinterpret_cast<const Matrix3&>(*this);
178 * Retrieve a Matrix value.
179 * @pre GetType() returns Property::Matrix.
180 * @param[in] bufferIndex The buffer to read from.
181 * @return The Matrix value.
183 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
185 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
186 // the return will never be executed due to assert above so just keep the compiler happy
187 return reinterpret_cast<const Matrix&>(*this);
190 // Accessors for Constraint functions
193 * Retrieve a boolean input for a constraint function.
194 * @note For inherited properties, this method should be overriden to return the value
195 * from the previous frame i.e. not from the current update buffer.
196 * @pre GetType() returns Property::BOOLEAN.
197 * @param[in] updateBufferIndex The current update buffer index.
198 * @return The boolean value.
200 virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
202 return GetBoolean( updateBufferIndex );
206 * Retrieve an integer input for a constraint function.
207 * @note For inherited properties, this method should be overriden to return the value
208 * from the previous frame i.e. not from the current update buffer.
209 * @pre GetType() returns Property::INTEGER.
210 * @param[in] updateBufferIndex The current update buffer index.
211 * @return The integer value.
213 virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
215 return GetInteger( updateBufferIndex );
219 * Retrieve a float input for a constraint function.
220 * @note For inherited properties, this method should be overriden to return the value
221 * from the previous frame i.e. not from the current update buffer.
222 * @pre GetType() returns Property::FLOAT.
223 * @param[in] updateBufferIndex The current update buffer index.
224 * @return The float value.
226 virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
228 return GetFloat( updateBufferIndex );
232 * Retrieve a Vector2 input for a constraint function.
233 * @note For inherited properties, this method should be overriden to return the value
234 * from the previous frame i.e. not from the current update buffer.
235 * @pre GetType() returns Property::VECTOR2.
236 * @param[in] updateBufferIndex The buffer to read from.
237 * @return The Vector2 value.
239 virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
241 return GetVector2( updateBufferIndex );
245 * Retrieve a Vector3 input for a constraint function.
246 * @note For inherited properties, this method should be overriden to return the value
247 * from the previous frame i.e. not from the current update buffer.
248 * @pre GetType() returns Property::VECTOR3.
249 * @param[in] updateBufferIndex The buffer to read from.
250 * @return The Vector3 value.
252 virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
254 return GetVector3( updateBufferIndex );
258 * Retrieve a Vector4 input for a constraint function.
259 * @note For inherited properties, this method should be overriden to return the value
260 * from the previous frame i.e. not from the current update buffer.
261 * @pre GetType() returns Property::VECTOR4.
262 * @param[in] updateBufferIndex The buffer to read from.
263 * @return The Vector4 value.
265 virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
267 return GetVector4( updateBufferIndex );
271 * Retrieve a Quaternion input for a constraint function.
272 * @note For inherited properties, this method should be overriden to return the value
273 * from the previous frame i.e. not from the current update buffer.
274 * @pre GetType() returns Property::Quaternion.
275 * @param[in] updateBufferIndex The buffer to read from.
276 * @return The Quaternion value.
278 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
280 return GetQuaternion( updateBufferIndex );
284 * Retrieve a Matrix3 input for a constraint function.
285 * @note For inherited properties, this method should be overriden to return the value
286 * from the previous frame i.e. not from the current update buffer.
287 * @pre GetType() returns Property::Matrix.
288 * @param[in] updateBufferIndex The buffer to read from.
289 * @return The Matrix value.
291 virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
293 return GetMatrix3( updateBufferIndex );
297 * Retrieve a Matrix input for a constraint function.
298 * @note For inherited properties, this method should be overriden to return the value
299 * from the previous frame i.e. not from the current update buffer.
300 * @pre GetType() returns Property::Matrix.
301 * @param[in] updateBufferIndex The buffer to read from.
302 * @return The Matrix value.
304 virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
306 return GetMatrix( updateBufferIndex );
310 * Print the property value using a stream.
311 * @param[in] debugStream The output stream.
312 * @param[in] bufferIndex The buffer to read from.
313 * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
315 void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
319 case Property::BOOLEAN:
321 debugStream << GetBoolean( bufferIndex );
325 case Property::INTEGER:
327 debugStream << GetInteger( bufferIndex );
331 case Property::FLOAT:
333 debugStream << GetFloat( 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__