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 Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/object/property-input.h>
22 #include <dali/public-api/math/vector2.h>
23 #include <dali/public-api/math/vector3.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/math/quaternion.h>
26 #include <dali/public-api/math/matrix3.h>
27 #include <dali/public-api/math/matrix.h>
28 #include <dali/internal/common/buffer-index.h>
37 * These dummy values are used to handle PropertyInputImpl errors
39 static const bool DUMMY_BOOLEAN_VALUE( false );
40 static const float DUMMY_FLOAT_VALUE( 0.0f );
41 static const Vector2 DUMMY_VECTOR2_VALUE( 0.0f, 0.0f );
42 static const Vector3 DUMMY_VECTOR3_VALUE( 0.0f, 0.0f, 0.0f );
43 static const Vector4 DUMMY_VECTOR4_VALUE( 0.0f, 0.0f, 0.0f, 0.0f );
44 static const Matrix3 DUMMY_MATRIX3_VALUE;
45 static const Matrix DUMMY_MATRIX_VALUE;
46 static const Quaternion DUMMY_QUATERNION_VALUE( 1.0f, 0.0f, 0.0f, 0.0f );
49 * An abstract interface for receiving property values, and for querying whether
50 * a property value has changed i.e. whether a constraint needs to be reapplied.
52 class PropertyInputImpl
59 virtual ~PropertyInputImpl()
64 * Query the type of property input.
65 * @return The property type.
67 virtual Property::Type GetType() const = 0;
70 * Query the input value (for a constraint) has been initialized.
71 * @return True if initialized, otherwise the constraint should be skipped.
73 virtual bool InputInitialized() const = 0;
76 * Query the input value (for a constraint) has changed.
77 * @return True if the input value has changed.
79 virtual bool InputChanged() const = 0;
82 * Retrieve a boolean value.
83 * @pre GetType() returns Property::BOOLEAN.
84 * @param[in] bufferIndex The buffer to read from.
85 * @return The boolean value.
87 virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
89 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
90 return DUMMY_BOOLEAN_VALUE;
94 * Retrieve a float value.
95 * @pre GetType() returns Property::FLOAT.
96 * @param[in] bufferIndex The buffer to read from.
97 * @return The float value.
99 virtual const float& GetFloat( BufferIndex bufferIndex ) const
101 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
102 return DUMMY_FLOAT_VALUE;
106 * Retrieve a Vector2 value.
107 * @pre GetType() returns Property::VECTOR2.
108 * @param[in] bufferIndex The buffer to read from.
109 * @return The Vector2 value.
111 virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
113 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
114 return DUMMY_VECTOR2_VALUE;
118 * Retrieve a Vector3 value.
119 * @pre GetType() returns Property::VECTOR3.
120 * @param[in] bufferIndex The buffer to read from.
121 * @return The Vector3 value.
123 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
125 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
126 return DUMMY_VECTOR3_VALUE;
130 * Retrieve a Vector4 value.
131 * @pre GetType() returns Property::VECTOR4.
132 * @param[in] bufferIndex The buffer to read from.
133 * @return The Vector4 value.
135 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
137 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
138 return DUMMY_VECTOR4_VALUE;
142 * Retrieve a Quaternion value.
143 * @pre GetType() returns Property::Quaternion.
144 * @param[in] bufferIndex The buffer to read from.
145 * @return The Quaternion value.
147 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
149 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
150 return DUMMY_QUATERNION_VALUE;
154 * Retrieve a Matrix value.
155 * @pre GetType() returns Property::Matrix.
156 * @param[in] bufferIndex The buffer to read from.
157 * @return The Matrix value.
159 virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
161 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
162 return DUMMY_MATRIX3_VALUE;
166 * Retrieve a Matrix value.
167 * @pre GetType() returns Property::Matrix.
168 * @param[in] bufferIndex The buffer to read from.
169 * @return The Matrix value.
171 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
173 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
174 return DUMMY_MATRIX_VALUE;
177 // Accessors for Constraint functions
180 * Retrieve a boolean input for a constraint function.
181 * @note For inherited properties, this method should be overriden to return the value
182 * from the previous frame i.e. not from the current update buffer.
183 * @pre GetType() returns Property::BOOLEAN.
184 * @param[in] updateBufferIndex The current update buffer index.
185 * @return The boolean value.
187 virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
189 return GetBoolean( updateBufferIndex );
193 * Retrieve a float 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::FLOAT.
197 * @param[in] updateBufferIndex The current update buffer index.
198 * @return The float value.
200 virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
202 return GetFloat( updateBufferIndex );
206 * Retrieve a Vector2 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::VECTOR2.
210 * @param[in] updateBufferIndex The buffer to read from.
211 * @return The Vector2 value.
213 virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
215 return GetVector2( updateBufferIndex );
219 * Retrieve a Vector3 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::VECTOR3.
223 * @param[in] updateBufferIndex The buffer to read from.
224 * @return The Vector3 value.
226 virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
228 return GetVector3( updateBufferIndex );
232 * Retrieve a Vector4 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::VECTOR4.
236 * @param[in] updateBufferIndex The buffer to read from.
237 * @return The Vector4 value.
239 virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
241 return GetVector4( updateBufferIndex );
245 * Retrieve a Quaternion 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::Quaternion.
249 * @param[in] updateBufferIndex The buffer to read from.
250 * @return The Quaternion value.
252 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
254 return GetQuaternion( updateBufferIndex );
258 * Retrieve a Matrix3 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::Matrix.
262 * @param[in] updateBufferIndex The buffer to read from.
263 * @return The Matrix value.
265 virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
267 return GetMatrix3( updateBufferIndex );
271 * Retrieve a Matrix 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::Matrix.
275 * @param[in] updateBufferIndex The buffer to read from.
276 * @return The Matrix value.
278 virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
280 return GetMatrix( updateBufferIndex );
284 * Print the property value using a stream.
285 * @param[in] debugStream The output stream.
286 * @param[in] bufferIndex The buffer to read from.
288 void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
292 case Property::BOOLEAN:
294 debugStream << GetBoolean( bufferIndex );
298 case Property::FLOAT:
300 debugStream << GetFloat( bufferIndex );
304 case Property::VECTOR2:
306 debugStream << GetVector2( bufferIndex );
310 case Property::VECTOR3:
312 debugStream << GetVector3( bufferIndex );
316 case Property::VECTOR4:
318 debugStream << GetVector4( bufferIndex );
322 case Property::ROTATION:
324 debugStream << GetQuaternion( bufferIndex );
328 case Property::MATRIX:
330 debugStream << GetMatrix( bufferIndex );
334 case Property::MATRIX3:
336 debugStream << GetMatrix3( bufferIndex );
341 break; // print nothing
346 } // namespace Internal
350 #endif // __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__