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
371 * An inherited Quaternion property.
373 class InheritedQuaternion : public PropertyInputImpl
378 * Create an inherited property.
380 InheritedQuaternion()
382 mInheritedFlag( false ),
383 mReinheritedFlag( true )
388 * Virtual destructor.
390 virtual ~InheritedQuaternion()
395 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
397 virtual Dali::Property::Type GetType() const
399 return Dali::PropertyTypes::Get<Quaternion>();
403 * Called once per Update (only) if the property did not need to be re-inherited.
404 * @param[in] updateBufferIndex The current update buffer index.
406 void CopyPrevious( BufferIndex updateBufferIndex )
408 if ( mReinheritedFlag )
410 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
412 mReinheritedFlag = false;
417 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
419 virtual bool IsClean() const
421 return ( false == mReinheritedFlag );
425 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
427 virtual bool InputInitialized() const
429 // A constraint cannot use the property until it has been inherited (at least once).
430 return mInheritedFlag;
434 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
435 * @note A constraint can only receive the inherited property from the previous frame.
437 virtual bool InputChanged() const
443 * @copydoc Dali::PropertyInput::GetQuaternion()
445 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
447 return mValue[ bufferIndex ];
451 * @copydoc Dali::PropertyInput::GetConstraintInputQuaternion()
453 virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex bufferIndex ) const
455 // For inherited properties, constraints work with the value from the previous frame.
456 // This is because constraints are applied to position etc, before world-position is calculated.
457 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
459 return mValue[ eventBufferIndex ];
463 * Set the property value. This will only persist for the current frame; the property
464 * will be reset with the base value, at the beginning of the next frame.
465 * @param[in] bufferIndex The buffer to write.
466 * @param[in] value The new property value.
468 void Set(BufferIndex bufferIndex, const Quaternion& value)
470 mValue[bufferIndex] = value;
472 // The value has been inherited for the first time
473 mInheritedFlag = true;
475 mReinheritedFlag = true;
479 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
481 Quaternion& Get(size_t bufferIndex)
483 return mValue[bufferIndex];
487 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
489 const Quaternion& Get(size_t bufferIndex) const
491 return mValue[bufferIndex];
495 * Retrieve the property value.
496 * @param[in] bufferIndex The buffer to read.
497 * @return The property value.
499 const Quaternion& operator[](size_t bufferIndex) const
501 return mValue[bufferIndex];
507 InheritedQuaternion(const InheritedQuaternion& property);
510 InheritedQuaternion& operator=(const InheritedQuaternion& 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.
523 class InheritedMatrix : public PropertyInputImpl
528 * Create an inherited property.
532 mInheritedFlag( false ),
533 mReinheritedFlag( true )
538 * Virtual destructor.
540 virtual ~InheritedMatrix()
545 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
547 virtual Dali::Property::Type GetType() const
549 return Dali::PropertyTypes::Get<Matrix>();
553 * Called once per Update (only) if the property did not need to be re-inherited.
554 * @param[in] updateBufferIndex The current update buffer index.
556 void CopyPrevious( BufferIndex updateBufferIndex )
558 if ( mReinheritedFlag )
560 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
562 mReinheritedFlag = false;
567 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
569 virtual bool IsClean() const
571 return ( false == mReinheritedFlag );
575 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
577 virtual bool InputInitialized() const
579 // A constraint cannot use the property until it has been inherited (at least once).
580 return mInheritedFlag;
584 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
585 * @note A constraint can only receive the inherited property from the previous frame.
587 virtual bool InputChanged() const
593 * @copydoc Dali::Internal::PropertyInputImpl::GetMatrix()
595 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
597 return mValue[ bufferIndex ];
601 * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
603 virtual const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const
605 // For inherited properties, constraints work with the value from the previous frame.
606 // This is because constraints are applied to position etc, before world-position is calculated.
607 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
609 return mValue[ eventBufferIndex ];
613 * @copydoc Dali::PropertyInput::GetQuaternion()
615 virtual const Quaternion& GetQuaternion() const
617 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
618 return DUMMY_QUATERNION_VALUE;
622 * @copydoc Dali::PropertyInput::GetQuaternion()
624 virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
626 DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
627 return DUMMY_QUATERNION_VALUE;
631 * Set the property value. This will only persist for the current frame; the property
632 * will be reset with the base value, at the beginning of the next frame.
633 * @param[in] bufferIndex The buffer to write.
634 * @param[in] value The new property value.
636 void Set(BufferIndex bufferIndex, const Matrix& value)
638 mValue[bufferIndex] = value;
640 // The value has been inherited for the first time
641 mInheritedFlag = true;
643 mReinheritedFlag = true;
647 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
649 Matrix& Get(size_t bufferIndex)
651 return mValue[bufferIndex];
655 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
657 const Matrix& Get(size_t bufferIndex) const
659 return mValue[bufferIndex];
663 * Retrieve the property value.
664 * @param[in] bufferIndex The buffer to read.
665 * @return The property value.
667 const Matrix& operator[](size_t bufferIndex) const
669 return mValue[bufferIndex];
672 void SetDirty(size_t bufferIndex)
674 mReinheritedFlag = true;
676 // The value has been inherited for the first time
677 mInheritedFlag = true;
683 InheritedMatrix(const InheritedMatrix& property);
686 InheritedMatrix& operator=(const InheritedMatrix& rhs);
690 DoubleBuffered<Matrix> mValue; ///< The double-buffered property value
692 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
693 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
697 } // namespace SceneGraph
699 } // namespace Internal
703 #endif // __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__