1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_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/internal/event/common/property-input-impl.h>
23 #include <dali/internal/update/common/double-buffered.h>
24 #include <dali/internal/update/common/property-base.h>
25 #include <dali/internal/update/common/scene-graph-buffers.h>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/object/property.h>
28 #include <dali/public-api/object/property-input.h>
29 #include <dali/public-api/object/property-types.h>
41 class InheritedProperty;
44 * An inherited Vector3 property.
47 class InheritedProperty<Vector3> : public PropertyInputImpl
52 * Create an inherited property.
53 * @param [in] initialValue The initial value of the property.
55 InheritedProperty( const Vector3& initialValue )
56 : mValue( initialValue ),
57 mInheritedFlag( false ),
58 mReinheritedFlag( true )
65 virtual ~InheritedProperty()
70 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
72 virtual Dali::Property::Type GetType() const
74 return Dali::PropertyTypes::Get<Vector3>();
78 * Called once per Update (only) if the property did not need to be re-inherited.
79 * @param[in] updateBufferIndex The current update buffer index.
81 void CopyPrevious( BufferIndex updateBufferIndex )
83 if ( mReinheritedFlag )
85 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
87 mReinheritedFlag = false;
92 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
94 virtual bool IsClean() const
96 return ( false == mReinheritedFlag );
100 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
102 virtual bool InputInitialized() const
104 // A constraint cannot use the property until it has been inherited (at least once).
105 return mInheritedFlag;
109 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
110 * @note A constraint can only receive the inherited property from the previous frame.
112 virtual bool InputChanged() const
118 * @copydoc Dali::PropertyInput::GetVector3()
120 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
122 return mValue[ bufferIndex ];
126 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
128 virtual const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const
130 // For inherited properties, constraints work with the value from the previous frame.
131 // This is because constraints are applied to position etc, before world-position is calculated.
132 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
134 return mValue[ eventBufferIndex ];
138 * Set the property value. This will only persist for the current frame; the property
139 * will be reset with the base value, at the beginning of the next frame.
140 * @param[in] bufferIndex The buffer to write.
141 * @param[in] value The new property value.
143 void Set(BufferIndex bufferIndex, const Vector3& value)
145 mValue[bufferIndex] = value;
147 // The value has been inherited for the first time
148 mInheritedFlag = true;
150 mReinheritedFlag = true;
154 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
156 Vector3& Get(size_t bufferIndex)
158 return mValue[bufferIndex];
162 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
164 const Vector3& Get(size_t bufferIndex) const
166 return mValue[bufferIndex];
170 * Retrieve the property value.
171 * @param[in] bufferIndex The buffer to read.
172 * @return The property value.
174 const Vector3& operator[](size_t bufferIndex) const
176 return mValue[bufferIndex];
182 InheritedProperty(const InheritedProperty& property);
185 InheritedProperty& operator=(const InheritedProperty& rhs);
189 DoubleBuffered<Vector3> mValue; ///< The double-buffered property value
191 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
192 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
196 * An inherited Color property.
198 class InheritedColor : public PropertyInputImpl
203 * Create an inherited property.
204 * @param [in] initialValue The initial value of the property.
206 InheritedColor( const Vector4& initialValue )
207 : mValue( initialValue ),
208 mInheritedFlag( false ),
209 mReinheritedFlag( true )
214 * Virtual destructor.
216 virtual ~InheritedColor()
221 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
223 virtual Dali::Property::Type GetType() const
225 return Dali::PropertyTypes::Get<Vector4>();
229 * Called once per Update (only) if the property did not need to be re-inherited.
230 * @param[in] updateBufferIndex The current update buffer index.
232 void CopyPrevious( BufferIndex updateBufferIndex )
234 if ( mReinheritedFlag )
236 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
238 mReinheritedFlag = false;
243 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
245 virtual bool IsClean() const
247 return ( false == mReinheritedFlag );
251 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
253 virtual bool InputInitialized() const
255 // A constraint cannot use the property until it has been inherited (at least once).
256 return mInheritedFlag;
260 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
261 * @note A constraint can only receive the inherited property from the previous frame.
263 virtual bool InputChanged() const
269 * @copydoc Dali::PropertyInput::GetVector4()
271 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
273 return mValue[ bufferIndex ];
277 * @copydoc Dali::PropertyInput::GetConstraintInputVector4()
279 virtual const Vector4& GetConstraintInputVector4( BufferIndex bufferIndex ) const
281 // For inherited properties, constraints work with the value from the previous frame.
282 // This is because constraints are applied to position etc, before world-position is calculated.
283 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
285 return mValue[ eventBufferIndex ];
289 * Set the property value. This will only persist for the current frame; the property
290 * will be reset with the base value, at the beginning of the next frame.
291 * @param[in] bufferIndex The buffer to write.
292 * @param[in] value The new property value.
294 void Set(BufferIndex bufferIndex, const Vector4& value)
296 mValue[bufferIndex] = Clamp( value, 0.0f, 1.0f ); // color values are clamped between 0 and 1
298 // The value has been inherited for the first time
299 mInheritedFlag = true;
300 mReinheritedFlag = true;
304 * Set the property value. This will only persist for the current frame; the property
305 * will be reset with the base value, at the beginning of the next frame.
306 * @param[in] bufferIndex The buffer to write.
307 * @param[in] r The new red value.
308 * @param[in] g The new green value.
309 * @param[in] b The new blue value.
310 * @param[in] a The new alpha value.
312 void Set(BufferIndex bufferIndex, float r, float g, float b, float a )
314 mValue[bufferIndex].r = Clamp( r, 0.0f, 1.0f ); // color values are clamped between 0 and 1
315 mValue[bufferIndex].g = Clamp( g, 0.0f, 1.0f ); // color values are clamped between 0 and 1
316 mValue[bufferIndex].b = Clamp( b, 0.0f, 1.0f ); // color values are clamped between 0 and 1
317 mValue[bufferIndex].a = Clamp( a, 0.0f, 1.0f ); // color values are clamped between 0 and 1
319 // The value has been inherited for the first time
320 mInheritedFlag = true;
321 mReinheritedFlag = true;
325 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
327 Vector4& Get(size_t bufferIndex)
329 return mValue[bufferIndex];
333 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
335 const Vector4& Get(size_t bufferIndex) const
337 return mValue[bufferIndex];
341 * Retrieve the property value.
342 * @param[in] bufferIndex The buffer to read.
343 * @return The property value.
345 const Vector4& operator[](size_t bufferIndex) const
347 return mValue[bufferIndex];
353 InheritedColor(const InheritedColor& property);
355 InheritedColor& operator=(const InheritedColor& rhs);
359 DoubleBuffered<Vector4> mValue; ///< The double-buffered property value
361 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
362 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
367 * An inherited Quaternion property.
370 class InheritedProperty<Quaternion> : public PropertyInputImpl
375 * Create an inherited property.
376 * @param [in] initialValue The initial value of the property.
378 InheritedProperty( const Quaternion& initialValue )
379 : mValue( initialValue ),
380 mInheritedFlag( false ),
381 mReinheritedFlag( true )
386 * Virtual destructor.
388 virtual ~InheritedProperty()
393 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
395 virtual Dali::Property::Type GetType() const
397 return Dali::PropertyTypes::Get<Quaternion>();
401 * Called once per Update (only) if the property did not need to be re-inherited.
402 * @param[in] updateBufferIndex The current update buffer index.
404 void CopyPrevious( BufferIndex updateBufferIndex )
406 if ( mReinheritedFlag )
408 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
410 mReinheritedFlag = false;
415 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
417 virtual bool IsClean() const
419 return ( false == mReinheritedFlag );
423 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
425 virtual bool InputInitialized() const
427 // A constraint cannot use the property until it has been inherited (at least once).
428 return mInheritedFlag;
432 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
433 * @note A constraint can only receive the inherited property from the previous frame.
435 virtual bool InputChanged() const
441 * @copydoc Dali::PropertyInput::GetQuaternion()
443 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
445 return mValue[ bufferIndex ];
449 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
451 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const
453 // For inherited properties, constraints work with the value from the previous frame.
454 // This is because constraints are applied to position etc, before world-position is calculated.
455 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
457 return mValue[ eventBufferIndex ];
461 * Set the property value. This will only persist for the current frame; the property
462 * will be reset with the base value, at the beginning of the next frame.
463 * @param[in] bufferIndex The buffer to write.
464 * @param[in] value The new property value.
466 void Set(BufferIndex bufferIndex, const Quaternion& value)
468 mValue[bufferIndex] = value;
470 // The value has been inherited for the first time
471 mInheritedFlag = true;
473 mReinheritedFlag = true;
477 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
479 Quaternion& Get(size_t bufferIndex)
481 return mValue[bufferIndex];
485 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
487 const Quaternion& Get(size_t bufferIndex) const
489 return mValue[bufferIndex];
493 * Retrieve the property value.
494 * @param[in] bufferIndex The buffer to read.
495 * @return The property value.
497 const Quaternion& operator[](size_t bufferIndex) const
499 return mValue[bufferIndex];
508 InheritedProperty(const InheritedProperty& property);
511 InheritedProperty& operator=(const InheritedProperty& rhs);
515 DoubleBuffered<Quaternion> mValue; ///< The double-buffered property value
517 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
518 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
522 * An inherited Matrix property.
525 class InheritedProperty<Matrix> : public PropertyInputImpl
530 * Create an inherited property.
531 * @param [in] initialValue The initial value of the property.
533 InheritedProperty( const Matrix& initialValue )
534 : mValue( initialValue ),
535 mInheritedFlag( false ),
536 mReinheritedFlag( true )
541 * Virtual destructor.
543 virtual ~InheritedProperty()
548 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
550 virtual Dali::Property::Type GetType() const
552 return Dali::PropertyTypes::Get<Matrix>();
556 * Called once per Update (only) if the property did not need to be re-inherited.
557 * @param[in] updateBufferIndex The current update buffer index.
559 void CopyPrevious( BufferIndex updateBufferIndex )
561 if ( mReinheritedFlag )
563 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
565 mReinheritedFlag = false;
570 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
572 virtual bool IsClean() const
574 return ( false == mReinheritedFlag );
578 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
580 virtual bool InputInitialized() const
582 // A constraint cannot use the property until it has been inherited (at least once).
583 return mInheritedFlag;
587 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
588 * @note A constraint can only receive the inherited property from the previous frame.
590 virtual bool InputChanged() const
596 * @copydoc Dali::Internal::PropertyInputImpl::GetMatrix()
598 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
600 return mValue[ bufferIndex ];
604 * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
606 virtual const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const
608 // For inherited properties, constraints work with the value from the previous frame.
609 // This is because constraints are applied to position etc, before world-position is calculated.
610 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
612 return mValue[ eventBufferIndex ];
616 * @copydoc Dali::PropertyInput::GetQuaternion()
618 virtual const Quaternion& GetQuaternion() const
620 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
621 return DUMMY_QUATERNION_VALUE;
625 * @copydoc Dali::PropertyInput::GetQuaternion()
627 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
629 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
630 return DUMMY_QUATERNION_VALUE;
634 * Set the property value. This will only persist for the current frame; the property
635 * will be reset with the base value, at the beginning of the next frame.
636 * @param[in] bufferIndex The buffer to write.
637 * @param[in] value The new property value.
639 void Set(BufferIndex bufferIndex, const Matrix& value)
641 mValue[bufferIndex] = value;
643 // The value has been inherited for the first time
644 mInheritedFlag = true;
646 mReinheritedFlag = true;
650 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
652 Matrix& Get(size_t bufferIndex)
654 return mValue[bufferIndex];
658 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
660 const Matrix& Get(size_t bufferIndex) const
662 return mValue[bufferIndex];
666 * Retrieve the property value.
667 * @param[in] bufferIndex The buffer to read.
668 * @return The property value.
670 const Matrix& operator[](size_t bufferIndex) const
672 return mValue[bufferIndex];
675 void SetDirty(size_t bufferIndex)
677 mReinheritedFlag = true;
679 // The value has been inherited for the first time
680 mInheritedFlag = true;
689 InheritedProperty(const InheritedProperty& property);
692 InheritedProperty& operator=(const InheritedProperty& rhs);
696 DoubleBuffered<Matrix> mValue; ///< The double-buffered property value
698 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
699 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
703 } // namespace SceneGraph
705 } // namespace Internal
709 #endif // __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__