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 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/internal/event/common/property-input-impl.h>
22 #include <dali/internal/update/common/double-buffered.h>
23 #include <dali/internal/update/common/property-base.h>
24 #include <dali/internal/update/common/scene-graph-buffers.h>
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/property.h>
27 #include <dali/public-api/object/property-input.h>
28 #include <dali/public-api/object/property-types.h>
40 class InheritedProperty;
43 * An inherited Vector3 property.
46 class InheritedProperty<Vector3> : public PropertyInputImpl
51 * Create an inherited property.
52 * @param [in] initialValue The initial value of the property.
54 InheritedProperty( const Vector3& initialValue )
55 : mValue( initialValue ),
56 mInheritedFlag( false ),
57 mReinheritedFlag( true )
64 virtual ~InheritedProperty()
69 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
71 virtual Dali::Property::Type GetType() const
73 return Dali::PropertyTypes::Get<Vector3>();
77 * Called once per Update (only) if the property did not need to be re-inherited.
78 * @param[in] updateBufferIndex The current update buffer index.
80 void CopyPrevious( BufferIndex updateBufferIndex )
82 if ( mReinheritedFlag )
84 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
86 mReinheritedFlag = false;
91 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
93 virtual bool IsClean() const
95 return ( false == mReinheritedFlag );
99 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
101 virtual bool InputInitialized() const
103 // A constraint cannot use the property until it has been inherited (at least once).
104 return mInheritedFlag;
108 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
109 * @note A constraint can only receive the inherited property from the previous frame.
111 virtual bool InputChanged() const
117 * @copydoc Dali::PropertyInput::GetVector3()
119 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
121 return mValue[ bufferIndex ];
125 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
127 virtual const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const
129 // For inherited properties, constraints work with the value from the previous frame.
130 // This is because constraints are applied to position etc, before world-position is calculated.
131 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
133 return mValue[ eventBufferIndex ];
137 * Set the property value. This will only persist for the current frame; the property
138 * will be reset with the base value, at the beginning of the next frame.
139 * @param[in] bufferIndex The buffer to write.
140 * @param[in] value The new property value.
142 void Set(BufferIndex bufferIndex, const Vector3& value)
144 mValue[bufferIndex] = value;
146 // The value has been inherited for the first time
147 mInheritedFlag = true;
149 mReinheritedFlag = true;
153 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
155 Vector3& Get(size_t bufferIndex)
157 return mValue[bufferIndex];
161 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
163 const Vector3& Get(size_t bufferIndex) const
165 return mValue[bufferIndex];
169 * Retrieve the property value.
170 * @param[in] bufferIndex The buffer to read.
171 * @return The property value.
173 const Vector3& operator[](size_t bufferIndex) const
175 return mValue[bufferIndex];
181 InheritedProperty(const InheritedProperty& property);
184 InheritedProperty& operator=(const InheritedProperty& rhs);
188 DoubleBuffered<Vector3> mValue; ///< The double-buffered property value
190 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
191 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
195 * An inherited Color property.
197 class InheritedColor : public PropertyInputImpl
202 * Create an inherited property.
203 * @param [in] initialValue The initial value of the property.
205 InheritedColor( const Vector4& initialValue )
206 : mValue( initialValue ),
207 mInheritedFlag( false ),
208 mReinheritedFlag( true )
213 * Virtual destructor.
215 virtual ~InheritedColor()
220 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
222 virtual Dali::Property::Type GetType() const
224 return Dali::PropertyTypes::Get<Vector4>();
228 * Called once per Update (only) if the property did not need to be re-inherited.
229 * @param[in] updateBufferIndex The current update buffer index.
231 void CopyPrevious( BufferIndex updateBufferIndex )
233 if ( mReinheritedFlag )
235 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
237 mReinheritedFlag = false;
242 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
244 virtual bool IsClean() const
246 return ( false == mReinheritedFlag );
250 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
252 virtual bool InputInitialized() const
254 // A constraint cannot use the property until it has been inherited (at least once).
255 return mInheritedFlag;
259 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
260 * @note A constraint can only receive the inherited property from the previous frame.
262 virtual bool InputChanged() const
268 * @copydoc Dali::PropertyInput::GetVector4()
270 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
272 return mValue[ bufferIndex ];
276 * @copydoc Dali::PropertyInput::GetConstraintInputVector4()
278 virtual const Vector4& GetConstraintInputVector4( BufferIndex bufferIndex ) const
280 // For inherited properties, constraints work with the value from the previous frame.
281 // This is because constraints are applied to position etc, before world-position is calculated.
282 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
284 return mValue[ eventBufferIndex ];
288 * Set the property value. This will only persist for the current frame; the property
289 * will be reset with the base value, at the beginning of the next frame.
290 * @param[in] bufferIndex The buffer to write.
291 * @param[in] value The new property value.
293 void Set(BufferIndex bufferIndex, const Vector4& value)
295 mValue[bufferIndex] = Clamp( value, 0.0f, 1.0f ); // color values are clamped between 0 and 1
297 // The value has been inherited for the first time
298 mInheritedFlag = true;
299 mReinheritedFlag = true;
303 * Set the property value. This will only persist for the current frame; the property
304 * will be reset with the base value, at the beginning of the next frame.
305 * @param[in] bufferIndex The buffer to write.
306 * @param[in] r The new red value.
307 * @param[in] g The new green value.
308 * @param[in] b The new blue value.
309 * @param[in] a The new alpha value.
311 void Set(BufferIndex bufferIndex, float r, float g, float b, float a )
313 mValue[bufferIndex].r = Clamp( r, 0.0f, 1.0f ); // color values are clamped between 0 and 1
314 mValue[bufferIndex].g = Clamp( g, 0.0f, 1.0f ); // color values are clamped between 0 and 1
315 mValue[bufferIndex].b = Clamp( b, 0.0f, 1.0f ); // color values are clamped between 0 and 1
316 mValue[bufferIndex].a = Clamp( a, 0.0f, 1.0f ); // color values are clamped between 0 and 1
318 // The value has been inherited for the first time
319 mInheritedFlag = true;
320 mReinheritedFlag = true;
324 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
326 Vector4& Get(size_t bufferIndex)
328 return mValue[bufferIndex];
332 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
334 const Vector4& Get(size_t bufferIndex) const
336 return mValue[bufferIndex];
340 * Retrieve the property value.
341 * @param[in] bufferIndex The buffer to read.
342 * @return The property value.
344 const Vector4& operator[](size_t bufferIndex) const
346 return mValue[bufferIndex];
352 InheritedColor(const InheritedColor& property);
354 InheritedColor& operator=(const InheritedColor& rhs);
358 DoubleBuffered<Vector4> mValue; ///< The double-buffered property value
360 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
361 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
366 * An inherited Quaternion property.
369 class InheritedProperty<Quaternion> : public PropertyInputImpl
374 * Create an inherited property.
375 * @param [in] initialValue The initial value of the property.
377 InheritedProperty( const Quaternion& initialValue )
378 : mValue( initialValue ),
379 mInheritedFlag( false ),
380 mReinheritedFlag( true )
385 * Virtual destructor.
387 virtual ~InheritedProperty()
392 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
394 virtual Dali::Property::Type GetType() const
396 return Dali::PropertyTypes::Get<Quaternion>();
400 * Called once per Update (only) if the property did not need to be re-inherited.
401 * @param[in] updateBufferIndex The current update buffer index.
403 void CopyPrevious( BufferIndex updateBufferIndex )
405 if ( mReinheritedFlag )
407 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
409 mReinheritedFlag = false;
414 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
416 virtual bool IsClean() const
418 return ( false == mReinheritedFlag );
422 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
424 virtual bool InputInitialized() const
426 // A constraint cannot use the property until it has been inherited (at least once).
427 return mInheritedFlag;
431 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
432 * @note A constraint can only receive the inherited property from the previous frame.
434 virtual bool InputChanged() const
440 * @copydoc Dali::PropertyInput::GetQuaternion()
442 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
444 return mValue[ bufferIndex ];
448 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
450 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const
452 // For inherited properties, constraints work with the value from the previous frame.
453 // This is because constraints are applied to position etc, before world-position is calculated.
454 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
456 return mValue[ eventBufferIndex ];
460 * Set the property value. This will only persist for the current frame; the property
461 * will be reset with the base value, at the beginning of the next frame.
462 * @param[in] bufferIndex The buffer to write.
463 * @param[in] value The new property value.
465 void Set(BufferIndex bufferIndex, const Quaternion& value)
467 mValue[bufferIndex] = value;
469 // The value has been inherited for the first time
470 mInheritedFlag = true;
472 mReinheritedFlag = true;
476 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
478 Quaternion& Get(size_t bufferIndex)
480 return mValue[bufferIndex];
484 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
486 const Quaternion& Get(size_t bufferIndex) const
488 return mValue[bufferIndex];
492 * Retrieve the property value.
493 * @param[in] bufferIndex The buffer to read.
494 * @return The property value.
496 const Quaternion& operator[](size_t bufferIndex) const
498 return mValue[bufferIndex];
507 InheritedProperty(const InheritedProperty& property);
510 InheritedProperty& operator=(const InheritedProperty& rhs);
514 DoubleBuffered<Quaternion> mValue; ///< The double-buffered property value
516 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
517 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
521 * An inherited Matrix property.
524 class InheritedProperty<Matrix> : public PropertyInputImpl
529 * Create an inherited property.
530 * @param [in] initialValue The initial value of the property.
532 InheritedProperty( const Matrix& initialValue )
533 : mValue( initialValue ),
534 mInheritedFlag( false ),
535 mReinheritedFlag( true )
540 * Virtual destructor.
542 virtual ~InheritedProperty()
547 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
549 virtual Dali::Property::Type GetType() const
551 return Dali::PropertyTypes::Get<Matrix>();
555 * Called once per Update (only) if the property did not need to be re-inherited.
556 * @param[in] updateBufferIndex The current update buffer index.
558 void CopyPrevious( BufferIndex updateBufferIndex )
560 if ( mReinheritedFlag )
562 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
564 mReinheritedFlag = false;
569 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
571 virtual bool IsClean() const
573 return ( false == mReinheritedFlag );
577 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
579 virtual bool InputInitialized() const
581 // A constraint cannot use the property until it has been inherited (at least once).
582 return mInheritedFlag;
586 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
587 * @note A constraint can only receive the inherited property from the previous frame.
589 virtual bool InputChanged() const
595 * @copydoc Dali::Internal::PropertyInputImpl::GetMatrix()
597 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
599 return mValue[ bufferIndex ];
603 * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
605 virtual const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const
607 // For inherited properties, constraints work with the value from the previous frame.
608 // This is because constraints are applied to position etc, before world-position is calculated.
609 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
611 return mValue[ eventBufferIndex ];
615 * @copydoc Dali::PropertyInput::GetQuaternion()
617 virtual const Quaternion& GetQuaternion() const
619 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
620 return DUMMY_QUATERNION_VALUE;
624 * @copydoc Dali::PropertyInput::GetQuaternion()
626 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
628 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
629 return DUMMY_QUATERNION_VALUE;
633 * Set the property value. This will only persist for the current frame; the property
634 * will be reset with the base value, at the beginning of the next frame.
635 * @param[in] bufferIndex The buffer to write.
636 * @param[in] value The new property value.
638 void Set(BufferIndex bufferIndex, const Matrix& value)
640 mValue[bufferIndex] = value;
642 // The value has been inherited for the first time
643 mInheritedFlag = true;
645 mReinheritedFlag = true;
649 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
651 Matrix& Get(size_t bufferIndex)
653 return mValue[bufferIndex];
657 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
659 const Matrix& Get(size_t bufferIndex) const
661 return mValue[bufferIndex];
665 * Retrieve the property value.
666 * @param[in] bufferIndex The buffer to read.
667 * @return The property value.
669 const Matrix& operator[](size_t bufferIndex) const
671 return mValue[bufferIndex];
674 void SetDirty(size_t bufferIndex)
676 mReinheritedFlag = true;
678 // The value has been inherited for the first time
679 mInheritedFlag = true;
688 InheritedProperty(const InheritedProperty& property);
691 InheritedProperty& operator=(const InheritedProperty& rhs);
695 DoubleBuffered<Matrix> mValue; ///< The double-buffered property value
697 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
698 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
702 } // namespace SceneGraph
704 } // namespace Internal
708 #endif // __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__