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>
30 #include <dali/public-api/math/math-utils.h> // Clamp
42 * An inherited Vector3 property.
44 class InheritedVector3 : public PropertyInputImpl
49 * Create an inherited Vector3.
53 mInheritedFlag( false ),
54 mReinheritedFlag( true )
59 * Create an inherited Vector3.
60 * @param [in] initialValue The initial value of the property.
62 InheritedVector3( const Vector3& initialValue )
63 : mValue( initialValue ),
64 mInheritedFlag( false ),
65 mReinheritedFlag( true )
71 virtual ~InheritedVector3()
76 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
78 virtual Dali::Property::Type GetType() const
80 return Dali::PropertyTypes::Get<Vector3>();
84 * Called once per Update (only) if the property did not need to be re-inherited.
85 * @param[in] updateBufferIndex The current update buffer index.
87 void CopyPrevious( BufferIndex updateBufferIndex )
89 if ( mReinheritedFlag )
91 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
93 mReinheritedFlag = false;
98 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
100 virtual bool IsClean() const
102 return ( false == mReinheritedFlag );
106 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
108 virtual bool InputInitialized() const
110 // A constraint cannot use the property until it has been inherited (at least once).
111 return mInheritedFlag;
115 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
116 * @note A constraint can only receive the inherited property from the previous frame.
118 virtual bool InputChanged() const
124 * @copydoc Dali::PropertyInput::GetVector3()
126 virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
128 return mValue[ bufferIndex ];
132 * @copydoc Dali::PropertyInput::GetConstraintInputVector3()
134 virtual const Vector3& GetConstraintInputVector3( BufferIndex bufferIndex ) const
136 // For inherited properties, constraints work with the value from the previous frame.
137 // This is because constraints are applied to position etc, before world-position is calculated.
138 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
140 return mValue[ eventBufferIndex ];
144 * Set the property value. This will only persist for the current frame; the property
145 * will be reset with the base value, at the beginning of the next frame.
146 * @param[in] bufferIndex The buffer to write.
147 * @param[in] value The new property value.
149 void Set(BufferIndex bufferIndex, const Vector3& value)
151 mValue[bufferIndex] = value;
153 // The value has been inherited for the first time
154 mInheritedFlag = true;
156 mReinheritedFlag = true;
160 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
162 Vector3& Get(size_t bufferIndex)
164 return mValue[bufferIndex];
168 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
170 const Vector3& Get(size_t bufferIndex) const
172 return mValue[bufferIndex];
176 * Retrieve the property value.
177 * @param[in] bufferIndex The buffer to read.
178 * @return The property value.
180 const Vector3& operator[](size_t bufferIndex) const
182 return mValue[bufferIndex];
188 InheritedVector3(const InheritedVector3& property);
191 InheritedVector3& operator=(const InheritedVector3& rhs);
195 DoubleBuffered<Vector3> mValue; ///< The double-buffered property value
197 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
198 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
202 * An inherited Color property.
204 class InheritedColor : public PropertyInputImpl
209 * Create an inherited property.
210 * @param [in] initialValue The initial value of the property.
212 InheritedColor( const Vector4& initialValue )
213 : mValue( initialValue ),
214 mInheritedFlag( false ),
215 mReinheritedFlag( true )
220 * Virtual destructor.
222 virtual ~InheritedColor()
227 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
229 virtual Dali::Property::Type GetType() const
231 return Dali::PropertyTypes::Get<Vector4>();
235 * Called once per Update (only) if the property did not need to be re-inherited.
236 * @param[in] updateBufferIndex The current update buffer index.
238 void CopyPrevious( BufferIndex updateBufferIndex )
240 if ( mReinheritedFlag )
242 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
244 mReinheritedFlag = false;
249 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
251 virtual bool IsClean() const
253 return ( false == mReinheritedFlag );
257 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
259 virtual bool InputInitialized() const
261 // A constraint cannot use the property until it has been inherited (at least once).
262 return mInheritedFlag;
266 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
267 * @note A constraint can only receive the inherited property from the previous frame.
269 virtual bool InputChanged() const
275 * @copydoc Dali::PropertyInput::GetVector4()
277 virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
279 return mValue[ bufferIndex ];
283 * @copydoc Dali::PropertyInput::GetConstraintInputVector4()
285 virtual const Vector4& GetConstraintInputVector4( BufferIndex bufferIndex ) const
287 // For inherited properties, constraints work with the value from the previous frame.
288 // This is because constraints are applied to position etc, before world-position is calculated.
289 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
291 return mValue[ eventBufferIndex ];
295 * Set the property value. This will only persist for the current frame; the property
296 * will be reset with the base value, at the beginning of the next frame.
297 * @param[in] bufferIndex The buffer to write.
298 * @param[in] value The new property value.
300 void Set(BufferIndex bufferIndex, const Vector4& value)
302 mValue[bufferIndex] = Clamp( value, 0.0f, 1.0f ); // color values are clamped between 0 and 1
304 // The value has been inherited for the first time
305 mInheritedFlag = true;
306 mReinheritedFlag = true;
310 * Set the property value. This will only persist for the current frame; the property
311 * will be reset with the base value, at the beginning of the next frame.
312 * @param[in] bufferIndex The buffer to write.
313 * @param[in] r The new red value.
314 * @param[in] g The new green value.
315 * @param[in] b The new blue value.
316 * @param[in] a The new alpha value.
318 void Set(BufferIndex bufferIndex, float r, float g, float b, float a )
320 mValue[bufferIndex].r = Clamp( r, 0.0f, 1.0f ); // color values are clamped between 0 and 1
321 mValue[bufferIndex].g = Clamp( g, 0.0f, 1.0f ); // color values are clamped between 0 and 1
322 mValue[bufferIndex].b = Clamp( b, 0.0f, 1.0f ); // color values are clamped between 0 and 1
323 mValue[bufferIndex].a = Clamp( a, 0.0f, 1.0f ); // color values are clamped between 0 and 1
325 // The value has been inherited for the first time
326 mInheritedFlag = true;
327 mReinheritedFlag = true;
331 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
333 Vector4& Get(size_t bufferIndex)
335 return mValue[bufferIndex];
339 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
341 const Vector4& Get(size_t bufferIndex) const
343 return mValue[bufferIndex];
347 * Retrieve the property value.
348 * @param[in] bufferIndex The buffer to read.
349 * @return The property value.
351 const Vector4& operator[](size_t bufferIndex) const
353 return mValue[bufferIndex];
359 InheritedColor(const InheritedColor& property);
361 InheritedColor& operator=(const InheritedColor& rhs);
365 DoubleBuffered<Vector4> mValue; ///< The double-buffered property value
367 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
368 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.
533 mInheritedFlag( false ),
534 mReinheritedFlag( true )
539 * Virtual destructor.
541 virtual ~InheritedMatrix()
546 * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
548 virtual Dali::Property::Type GetType() const
550 return Dali::PropertyTypes::Get<Matrix>();
554 * Called once per Update (only) if the property did not need to be re-inherited.
555 * @param[in] updateBufferIndex The current update buffer index.
557 void CopyPrevious( BufferIndex updateBufferIndex )
559 if ( mReinheritedFlag )
561 mValue[updateBufferIndex] = mValue[updateBufferIndex ? 0 : 1];
563 mReinheritedFlag = false;
568 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
570 virtual bool IsClean() const
572 return ( false == mReinheritedFlag );
576 * @copydoc Dali::Internal::PropertyInputImpl::InputInitialized()
578 virtual bool InputInitialized() const
580 // A constraint cannot use the property until it has been inherited (at least once).
581 return mInheritedFlag;
585 * @copydoc Dali::Internal::PropertyInputImpl::InputChanged()
586 * @note A constraint can only receive the inherited property from the previous frame.
588 virtual bool InputChanged() const
594 * @copydoc Dali::Internal::PropertyInputImpl::GetMatrix()
596 virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
598 return mValue[ bufferIndex ];
602 * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
604 virtual const Matrix& GetConstraintInputMatrix( BufferIndex bufferIndex ) const
606 // For inherited properties, constraints work with the value from the previous frame.
607 // This is because constraints are applied to position etc, before world-position is calculated.
608 BufferIndex eventBufferIndex = bufferIndex ? 0u : 1u;
610 return mValue[ eventBufferIndex ];
614 * Set the property value. This will only persist for the current frame; the property
615 * will be reset with the base value, at the beginning of the next frame.
616 * @param[in] bufferIndex The buffer to write.
617 * @param[in] value The new property value.
619 void Set(BufferIndex bufferIndex, const Matrix& value)
621 mValue[bufferIndex] = value;
623 // The value has been inherited for the first time
624 mInheritedFlag = true;
626 mReinheritedFlag = true;
630 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
632 Matrix& Get(size_t bufferIndex)
634 return mValue[bufferIndex];
638 * @copydoc Dali::SceneGraph::PropertyInterface::Get()
640 const Matrix& Get(size_t bufferIndex) const
642 return mValue[bufferIndex];
646 * Retrieve the property value.
647 * @param[in] bufferIndex The buffer to read.
648 * @return The property value.
650 const Matrix& operator[](size_t bufferIndex) const
652 return mValue[bufferIndex];
655 void SetDirty(size_t bufferIndex)
657 mReinheritedFlag = true;
659 // The value has been inherited for the first time
660 mInheritedFlag = true;
666 InheritedMatrix(const InheritedMatrix& property);
669 InheritedMatrix& operator=(const InheritedMatrix& rhs);
673 DoubleBuffered<Matrix> mValue; ///< The double-buffered property value
675 bool mInheritedFlag :1; ///< Flag whether the value has ever been inherited
676 bool mReinheritedFlag :1; ///< Flag whether value was re-inherited in previous frame
680 } // namespace SceneGraph
682 } // namespace Internal
686 #endif // __DALI_INTERNAL_SCENE_GRAPH_INHERITED_PROPERTY_H__