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 * An inherited Vector3 property.
43 class InheritedVector3 : public PropertyInputImpl
48 * Create an inherited Vector3.
52 mInheritedFlag( false ),
53 mReinheritedFlag( true )
58 * Create an inherited Vector3.
59 * @param [in] initialValue The initial value of the property.
61 InheritedVector3( const Vector3& initialValue )
62 : mValue( initialValue ),
63 mInheritedFlag( false ),
64 mReinheritedFlag( true )
70 virtual ~InheritedVector3()
75 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
77 virtual Dali::Property::Type GetType() const
79 return Dali::PropertyTypes::Get<Vector3>();
83 * Called once per Update (only) if the property did not need to be re-inherited.
84 * @param[in] updateBufferIndex The current update buffer index.
86 void CopyPrevious( BufferIndex updateBufferIndex )
88 if ( mReinheritedFlag )
90 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
92 mReinheritedFlag = false;
97 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
99 virtual bool IsClean() const
101 return ( false == mReinheritedFlag );
105 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
107 virtual bool InputInitialized() const
109 // A constraint cannot use the property until it has been inherited (at least once).
110 return mInheritedFlag;
114 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
115 * @note A constraint can only receive the inherited property from the previous frame.
117 virtual bool InputChanged() const
123 * @copydoc Dali::PropertyInput::GetVector3()
125 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
127 return mValue[ bufferIndex ];
131 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
133 virtual const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const
135 // For inherited properties, constraints work with the value from the previous frame.
136 // This is because constraints are applied to position etc, before world-position is calculated.
137 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
139 return mValue[ eventBufferIndex ];
143 * Set the property value. This will only persist for the current frame; the property
144 * will be reset with the base value, at the beginning of the next frame.
145 * @param[in] bufferIndex The buffer to write.
146 * @param[in] value The new property value.
148 void Set(BufferIndex bufferIndex, const Vector3& value)
150 mValue[bufferIndex] = value;
152 // The value has been inherited for the first time
153 mInheritedFlag = true;
155 mReinheritedFlag = true;
159 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
161 Vector3& Get(size_t bufferIndex)
163 return mValue[bufferIndex];
167 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
169 const Vector3& Get(size_t bufferIndex) const
171 return mValue[bufferIndex];
175 * Retrieve the property value.
176 * @param[in] bufferIndex The buffer to read.
177 * @return The property value.
179 const Vector3& operator[](size_t bufferIndex) const
181 return mValue[bufferIndex];
187 InheritedVector3(const InheritedVector3& property);
190 InheritedVector3& operator=(const InheritedVector3& rhs);
194 DoubleBuffered<Vector3> mValue; ///< The double-buffered property value
196 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
197 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
201 * An inherited Color property.
203 class InheritedColor : public PropertyInputImpl
208 * Create an inherited property.
209 * @param [in] initialValue The initial value of the property.
211 InheritedColor( const Vector4& initialValue )
212 : mValue( initialValue ),
213 mInheritedFlag( false ),
214 mReinheritedFlag( true )
219 * Virtual destructor.
221 virtual ~InheritedColor()
226 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
228 virtual Dali::Property::Type GetType() const
230 return Dali::PropertyTypes::Get<Vector4>();
234 * Called once per Update (only) if the property did not need to be re-inherited.
235 * @param[in] updateBufferIndex The current update buffer index.
237 void CopyPrevious( BufferIndex updateBufferIndex )
239 if ( mReinheritedFlag )
241 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
243 mReinheritedFlag = false;
248 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
250 virtual bool IsClean() const
252 return ( false == mReinheritedFlag );
256 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
258 virtual bool InputInitialized() const
260 // A constraint cannot use the property until it has been inherited (at least once).
261 return mInheritedFlag;
265 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
266 * @note A constraint can only receive the inherited property from the previous frame.
268 virtual bool InputChanged() const
274 * @copydoc Dali::PropertyInput::GetVector4()
276 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
278 return mValue[ bufferIndex ];
282 * @copydoc Dali::PropertyInput::GetConstraintInputVector4()
284 virtual const Vector4& GetConstraintInputVector4( BufferIndex bufferIndex ) const
286 // For inherited properties, constraints work with the value from the previous frame.
287 // This is because constraints are applied to position etc, before world-position is calculated.
288 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
290 return mValue[ eventBufferIndex ];
294 * Set the property value. This will only persist for the current frame; the property
295 * will be reset with the base value, at the beginning of the next frame.
296 * @param[in] bufferIndex The buffer to write.
297 * @param[in] value The new property value.
299 void Set(BufferIndex bufferIndex, const Vector4& value)
301 mValue[bufferIndex] = Clamp( value, 0.0f, 1.0f ); // color values are clamped between 0 and 1
303 // The value has been inherited for the first time
304 mInheritedFlag = true;
305 mReinheritedFlag = true;
309 * Set the property value. This will only persist for the current frame; the property
310 * will be reset with the base value, at the beginning of the next frame.
311 * @param[in] bufferIndex The buffer to write.
312 * @param[in] r The new red value.
313 * @param[in] g The new green value.
314 * @param[in] b The new blue value.
315 * @param[in] a The new alpha value.
317 void Set(BufferIndex bufferIndex, float r, float g, float b, float a )
319 mValue[bufferIndex].r = Clamp( r, 0.0f, 1.0f ); // color values are clamped between 0 and 1
320 mValue[bufferIndex].g = Clamp( g, 0.0f, 1.0f ); // color values are clamped between 0 and 1
321 mValue[bufferIndex].b = Clamp( b, 0.0f, 1.0f ); // color values are clamped between 0 and 1
322 mValue[bufferIndex].a = Clamp( a, 0.0f, 1.0f ); // color values are clamped between 0 and 1
324 // The value has been inherited for the first time
325 mInheritedFlag = true;
326 mReinheritedFlag = true;
330 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
332 Vector4& Get(size_t bufferIndex)
334 return mValue[bufferIndex];
338 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
340 const Vector4& Get(size_t bufferIndex) const
342 return mValue[bufferIndex];
346 * Retrieve the property value.
347 * @param[in] bufferIndex The buffer to read.
348 * @return The property value.
350 const Vector4& operator[](size_t bufferIndex) const
352 return mValue[bufferIndex];
358 InheritedColor(const InheritedColor& property);
360 InheritedColor& operator=(const InheritedColor& rhs);
364 DoubleBuffered<Vector4> mValue; ///< The double-buffered property value
366 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
367 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
372 * An inherited Quaternion property.
374 class InheritedQuaternion : public PropertyInputImpl
379 * Create an inherited property.
381 InheritedQuaternion()
383 mInheritedFlag( false ),
384 mReinheritedFlag( true )
389 * Virtual destructor.
391 virtual ~InheritedQuaternion()
396 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
398 virtual Dali::Property::Type GetType() const
400 return Dali::PropertyTypes::Get<Quaternion>();
404 * Called once per Update (only) if the property did not need to be re-inherited.
405 * @param[in] updateBufferIndex The current update buffer index.
407 void CopyPrevious( BufferIndex updateBufferIndex )
409 if ( mReinheritedFlag )
411 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
413 mReinheritedFlag = false;
418 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
420 virtual bool IsClean() const
422 return ( false == mReinheritedFlag );
426 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
428 virtual bool InputInitialized() const
430 // A constraint cannot use the property until it has been inherited (at least once).
431 return mInheritedFlag;
435 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
436 * @note A constraint can only receive the inherited property from the previous frame.
438 virtual bool InputChanged() const
444 * @copydoc Dali::PropertyInput::GetQuaternion()
446 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
448 return mValue[ bufferIndex ];
452 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
454 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const
456 // For inherited properties, constraints work with the value from the previous frame.
457 // This is because constraints are applied to position etc, before world-position is calculated.
458 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
460 return mValue[ eventBufferIndex ];
464 * Set the property value. This will only persist for the current frame; the property
465 * will be reset with the base value, at the beginning of the next frame.
466 * @param[in] bufferIndex The buffer to write.
467 * @param[in] value The new property value.
469 void Set(BufferIndex bufferIndex, const Quaternion& value)
471 mValue[bufferIndex] = value;
473 // The value has been inherited for the first time
474 mInheritedFlag = true;
476 mReinheritedFlag = true;
480 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
482 Quaternion& Get(size_t bufferIndex)
484 return mValue[bufferIndex];
488 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
490 const Quaternion& Get(size_t bufferIndex) const
492 return mValue[bufferIndex];
496 * Retrieve the property value.
497 * @param[in] bufferIndex The buffer to read.
498 * @return The property value.
500 const Quaternion& operator[](size_t bufferIndex) const
502 return mValue[bufferIndex];
508 InheritedQuaternion(const InheritedQuaternion& property);
511 InheritedQuaternion& operator=(const InheritedQuaternion& 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.
524 class InheritedMatrix : public PropertyInputImpl
529 * Create an inherited property.
530 * @param [in] initialValue The initial value of the property.
534 mInheritedFlag( false ),
535 mReinheritedFlag( true )
540 * Virtual destructor.
542 virtual ~InheritedMatrix()
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;
685 InheritedMatrix(const InheritedMatrix& property);
688 InheritedMatrix& operator=(const InheritedMatrix& rhs);
692 DoubleBuffered<Matrix> mValue; ///< The double-buffered property value
694 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
695 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
699 } // namespace SceneGraph
701 } // namespace Internal
705 #endif // __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__