1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_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/public-api/actors/actor-enumerations.h>
23 #include <dali/public-api/actors/draw-mode.h>
24 #include <dali/public-api/common/set-wrapper.h>
25 #include <dali/public-api/math/quaternion.h>
26 #include <dali/public-api/math/math-utils.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/common/event-to-update.h>
30 #include <dali/internal/update/common/animatable-property.h>
31 #include <dali/internal/update/common/property-owner.h>
32 #include <dali/internal/update/common/property-vector3.h>
33 #include <dali/internal/update/common/scene-graph-buffers.h>
34 #include <dali/internal/update/common/inherited-property.h>
35 #include <dali/integration-api/debug.h>
36 #include <dali/internal/update/nodes/node-declarations.h>
37 #include <dali/internal/update/node-attachments/node-attachment-declarations.h>
38 #include <dali/internal/render/data-providers/node-data-provider.h>
46 // value types used by messages
47 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
48 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
49 template <> struct ParameterType< SizeMode > : public BasicType< SizeMode > {};
61 * Flag whether property has changed, during the Update phase.
63 enum NodePropertyFlags
66 TransformFlag = 0x001,
71 SortModifierFlag = 0x020,
72 ChildDeletedFlag = 0x040
75 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
78 * Size is not inherited.
79 * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible
81 static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | OverlayFlag;
83 // Flags which require the scene renderable lists to be updated
84 static const int RenderableUpdateFlags = TransformFlag | SortModifierFlag | ChildDeletedFlag;
87 * Node is the base class for all nodes in the Scene Graph.
89 * Each node provides a transformation which applies to the node and
90 * its children. Node data is double-buffered. This allows an update
91 * thread to modify node data, without interferring with another
92 * thread reading the values from the previous update traversal.
94 class Node : public PropertyOwner, public NodeDataProvider
99 static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
100 static const ColorMode DEFAULT_COLOR_MODE;
101 static const SizeMode DEFAULT_SIZE_MODE;
106 * Construct a new Node.
116 * When a Node is marked "active" it has been disconnected, but its properties have been modified.
117 * @note An inactive Node will be skipped during the UpdateManager ResetProperties stage.
118 * @param[in] isActive True if the Node is active.
120 void SetActive( bool isActive )
122 mIsActive = isActive;
126 * Query whether the Node is active.
127 * @return True if the Node is active.
129 bool IsActive() const
135 * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
142 * Query whether the node is a layer.
143 * @return True if the node is a layer.
147 return (GetLayer() != NULL);
151 * Convert a node to a layer.
152 * @return A pointer to the layer, or NULL.
154 virtual Layer* GetLayer()
162 * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
163 * @pre The Node does not already have an attachment.
164 * @param[in] attachment The object to attach.
166 void Attach( NodeAttachment& attachment );
169 * Query the node if it has an attachment.
170 * @return True if it has an attachment.
172 bool HasAttachment() const
178 * Retreive the object attached to this node.
179 * @return The attachment.
181 NodeAttachment& GetAttachment() const
186 // Containment methods
189 * Query whether a node is the root node. Root nodes cannot have a parent node.
190 * A node becomes a root node, when it is installed by UpdateManager.
191 * @return True if the node is a root node.
199 * Set whether a node is the root node. Root nodes cannot have a parent node.
200 * This method should only be called by UpdateManager.
201 * @pre When isRoot is true, the node must not have a parent.
202 * @param[in] isRoot Whether the node is now a root node.
204 void SetRoot(bool isRoot);
207 * Retrieve the parent of a Node.
208 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
216 * Retrieve the parent of a Node.
217 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
219 const Node* GetParent() const
225 * Connect a node to the scene-graph.
226 * @pre A node cannot be added to itself.
227 * @pre The parent node is connected to the scene-graph.
228 * @pre The childNode does not already have a parent.
229 * @pre The childNode is not a root node.
230 * @param[in] childNode The child to add.
231 * @param[in] index to insert at, if not supplied or -1 it will be appended
234 void ConnectChild( Node* childNode, int index = -1);
237 * Disconnect a child (& its children) from the scene-graph.
238 * @pre childNode is a child of this Node.
239 * @param[in] updateBufferIndex The current update buffer index.
240 * @param[in] childNode The node to disconnect.
241 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
242 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
244 void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
247 * Retrieve the children a Node.
248 * @return The container of children.
250 const NodeContainer& GetChildren() const
256 * Retrieve the children a Node.
257 * @return The container of children.
259 NodeContainer& GetChildren()
267 * Flag that one of the node values has changed in the current frame.
268 * @param[in] flag The flag to set.
270 void SetDirtyFlag(NodePropertyFlags flag)
276 * Flag that all of the node values are dirty.
278 void SetAllDirtyFlags()
280 mDirtyFlags = AllFlags;
284 * Query whether a node is dirty.
285 * @return The dirty flags
287 int GetDirtyFlags() const;
290 * Query whether a node is clean.
291 * @return True if the node is clean.
295 return ( NothingFlag == GetDirtyFlags() );
299 * Retrieve the parent-origin of the node.
300 * @return The parent-origin.
302 const Vector3& GetParentOrigin() const
304 return mParentOrigin.mValue;
308 * Sets both the local & base parent-origins of the node.
309 * @param[in] origin The new local & base parent-origins.
311 void SetParentOrigin(const Vector3& origin)
313 mParentOrigin.mValue = origin;
314 mParentOrigin.OnSet();
318 * Retrieve the anchor-point of the node.
319 * @return The anchor-point.
321 const Vector3& GetAnchorPoint() const
323 return mAnchorPoint.mValue;
327 * Sets both the local & base anchor-points of the node.
328 * @param[in] anchor The new local & base anchor-points.
330 void SetAnchorPoint(const Vector3& anchor)
332 mAnchorPoint.mValue = anchor;
333 mAnchorPoint.OnSet();
337 * Retrieve the local position of the node, relative to its parent.
338 * @param[in] bufferIndex The buffer to read from.
339 * @return The local position.
341 const Vector3& GetPosition(BufferIndex bufferIndex) const
343 return mPosition[bufferIndex];
347 * Sets both the local & base positions of the node.
348 * @param[in] updateBufferIndex The current update buffer index.
349 * @param[in] position The new local & base position.
351 void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
353 mPosition.Bake( updateBufferIndex, position );
357 * Sets the world of the node derived from the position of all its parents.
358 * @param[in] updateBufferIndex The current update buffer index.
359 * @param[in] position The world position.
361 void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
363 mWorldPosition.Set( updateBufferIndex, position );
367 * Sets the position of the node derived from the position of all its parents.
368 * This method should only be called when the parent's world position is up-to-date.
369 * With a non-central anchor-point, the local rotation and scale affects the world position.
370 * Therefore the world rotation & scale must be updated before the world position.
371 * @pre The node has a parent.
372 * @param[in] updateBufferIndex The current update buffer index.
374 void InheritWorldPosition(BufferIndex updateBufferIndex)
376 DALI_ASSERT_DEBUG(mParent != NULL);
378 switch( mPositionInheritanceMode )
380 case INHERIT_PARENT_POSITION : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
382 Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
384 finalPosition += mParentOrigin.mValue;
385 finalPosition *= mParent->GetSize(updateBufferIndex);
386 finalPosition += mPosition[updateBufferIndex];
387 finalPosition *= mParent->GetWorldScale(updateBufferIndex);
388 const Quaternion& parentWorldRotation = mParent->GetWorldRotation(updateBufferIndex);
389 if(!parentWorldRotation.IsIdentity())
391 finalPosition *= parentWorldRotation;
394 // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
395 // dont use operator== as that does a slower comparison (and involves function calls)
396 Vector3 localOffset(0.5f, 0.5f, 0.5f); // AnchorPoint::CENTER
397 localOffset -= mAnchorPoint.mValue;
399 if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
400 ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
401 ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
403 localOffset *= mSize[updateBufferIndex];
405 Vector3 scale = mWorldScale[updateBufferIndex];
407 // Pick up sign of local scale
408 if (mScale[updateBufferIndex].x < 0.0f)
412 if (mScale[updateBufferIndex].y < 0.0f)
416 if (mScale[updateBufferIndex].z < 0.0f)
421 // If the anchor-point is not central, then position is affected by the local rotation & scale
422 localOffset *= scale;
423 const Quaternion& localWorldRotation = mWorldRotation[updateBufferIndex];
424 if(!localWorldRotation.IsIdentity())
426 localOffset *= localWorldRotation;
428 finalPosition += localOffset;
431 finalPosition += mParent->GetWorldPosition(updateBufferIndex);
432 mWorldPosition.Set( updateBufferIndex, finalPosition );
435 case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
437 // copy parents position plus local transform
438 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
441 case USE_PARENT_POSITION :
443 // copy parents position
444 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
447 case DONT_INHERIT_POSITION :
449 // use local position as world position
450 mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
457 * Copies the previous inherited position, if this changed in the previous frame.
458 * This method should be called instead of InheritWorldPosition i.e. if the inherited position
459 * does not need to be recalculated in the current frame.
460 * @param[in] updateBufferIndex The current update buffer index.
462 void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
464 mWorldPosition.CopyPrevious( updateBufferIndex );
468 * Retrieve the position of the node derived from the position of all its parents.
469 * @return The world position.
471 const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
473 return mWorldPosition[bufferIndex];
477 * Set the position inheritance mode.
478 * @see Dali::Actor::PositionInheritanceMode
479 * @param[in] mode The new position inheritance mode.
481 void SetPositionInheritanceMode( PositionInheritanceMode mode )
483 mPositionInheritanceMode = mode;
485 SetDirtyFlag(TransformFlag);
489 * @return The position inheritance mode.
491 PositionInheritanceMode GetPositionInheritanceMode() const
493 return mPositionInheritanceMode;
497 * Retrieve the local rotation of the node, relative to its parent.
498 * @param[in] bufferIndex The buffer to read from.
499 * @return The local rotation.
501 const Quaternion& GetRotation(BufferIndex bufferIndex) const
503 return mRotation[bufferIndex];
507 * Sets both the local & base rotations of the node.
508 * @param[in] updateBufferIndex The current update buffer index.
509 * @param[in] rotation The new local & base rotation.
511 void BakeRotation(BufferIndex updateBufferIndex, const Quaternion& rotation)
513 mRotation.Bake( updateBufferIndex, rotation );
517 * Sets the rotation of the node derived from the rotation of all its parents.
518 * @param[in] updateBufferIndex The current update buffer index.
519 * @param[in] rotation The world rotation.
521 void SetWorldRotation( BufferIndex updateBufferIndex, const Quaternion& rotation )
523 mWorldRotation.Set( updateBufferIndex, rotation );
527 * Sets the rotation of the node derived from the rotation of all its parents.
528 * This method should only be called when the parents world rotation is up-to-date.
529 * @pre The node has a parent.
530 * @param[in] updateBufferIndex The current update buffer index.
532 void InheritWorldRotation( BufferIndex updateBufferIndex )
534 DALI_ASSERT_DEBUG(mParent != NULL);
536 const Quaternion& localRotation = mRotation[updateBufferIndex];
538 if(localRotation.IsIdentity())
540 mWorldRotation.Set( updateBufferIndex, mParent->GetWorldRotation(updateBufferIndex) );
544 Quaternion finalRotation( mParent->GetWorldRotation(updateBufferIndex) );
545 finalRotation *= localRotation;
546 mWorldRotation.Set( updateBufferIndex, finalRotation );
551 * Copies the previous inherited rotation, if this changed in the previous frame.
552 * This method should be called instead of InheritWorldRotation i.e. if the inherited rotation
553 * does not need to be recalculated in the current frame.
554 * @param[in] updateBufferIndex The current update buffer index.
556 void CopyPreviousWorldRotation( BufferIndex updateBufferIndex )
558 mWorldRotation.CopyPrevious( updateBufferIndex );
562 * Retrieve the rotation of the node derived from the rotation of all its parents.
563 * @param[in] bufferIndex The buffer to read from.
564 * @return The world rotation.
566 const Quaternion& GetWorldRotation( BufferIndex bufferIndex ) const
568 return mWorldRotation[bufferIndex];
572 * Set whether the Node inherits rotation.
573 * @param[in] inherit True if the parent rotation is inherited.
575 void SetInheritRotation(bool inherit)
577 if (inherit != mInheritRotation)
579 mInheritRotation = inherit;
581 SetDirtyFlag(TransformFlag);
586 * Query whether the node inherits rotation from its parent.
587 * @return True if the parent rotation is inherited.
589 bool IsRotationInherited() const
591 return mInheritRotation;
595 * @brief Defines how a child actor's size is affected by its parent's size.
596 * @param[in] mode The size relative to parent mode to use.
598 void SetSizeMode( SizeMode mode )
600 if ( mode != mSizeMode )
604 SetDirtyFlag( TransformFlag );
609 * Query how the child actor's size is affected by its parent's size.
610 * @return The size relative to parent mode in use.
612 SizeMode GetSizeMode() const
618 * Sets the factor of the parents size used for the child actor.
619 * Note: Only used for certain SizeModes.
620 * @param[in] factor The vector to multiply the parents size by to get the childs size.
622 void SetSizeModeFactor( const Vector3& factor )
624 mSizeModeFactor = factor;
626 SetDirtyFlag( TransformFlag );
630 * Gets the factor of the parents size used for the child actor.
631 * Note: Only used for certain SizeModes.
632 * @return The vector being used to multiply the parents size by to get the childs size.
634 const Vector3& GetSizeModeFactor() const
636 return mSizeModeFactor;
640 * Retrieve the local scale of the node, relative to its parent.
641 * @param[in] bufferIndex The buffer to read from.
642 * @return The local scale.
644 const Vector3& GetScale(BufferIndex bufferIndex) const
646 return mScale[bufferIndex];
650 * Sets the scale of the node derived from the scale of all its parents and a pre-scale
651 * @param[in] updateBufferIndex The current update buffer index.
652 * @param[in] scale The world scale.
654 void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
656 mWorldScale.Set( updateBufferIndex, scale );
660 * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
661 * This method should only be called when the parents world scale is up-to-date.
662 * @pre The node has a parent.
663 * @param[in] updateBufferIndex The current update buffer index.
665 void InheritWorldScale(BufferIndex updateBufferIndex)
667 DALI_ASSERT_DEBUG(mParent != NULL);
669 mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mScale[updateBufferIndex] );
673 * Copies the previous inherited scale, if this changed in the previous frame.
674 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
675 * does not need to be recalculated in the current frame.
676 * @param[in] updateBufferIndex The current update buffer index.
678 void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
680 mWorldScale.CopyPrevious( updateBufferIndex );
684 * Retrieve the scale of the node derived from the scale of all its parents.
685 * @param[in] bufferIndex The buffer to read from.
686 * @return The world scale.
688 const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
690 return mWorldScale[bufferIndex];
694 * Set whether the Node inherits scale.
695 * @param inherit True if the Node inherits scale.
697 void SetInheritScale( bool inherit )
699 if( inherit != mInheritScale )
701 mInheritScale = inherit;
703 SetDirtyFlag( TransformFlag );
708 * Query whether the Node inherits scale.
709 * @return if scale is inherited
711 bool IsScaleInherited() const
713 return mInheritScale;
717 * Copies the previously used size, if this changed in the previous frame.
718 * @param[in] updateBufferIndex The current update buffer index.
720 void CopyPreviousSize( BufferIndex updateBufferIndex )
722 SetSize( updateBufferIndex, GetSize( 1u - updateBufferIndex ) );
726 * Retrieve the visibility of the node.
727 * @param[in] bufferIndex The buffer to read from.
728 * @return True if the node is visible.
730 bool IsVisible(BufferIndex bufferIndex) const
732 return mVisible[bufferIndex];
736 * Retrieves whether a node is fully visible.
737 * A node is fully visible if is visible and all its ancestors are visible.
738 * @param[in] updateBufferIndex The current update buffer index.
739 * @return True if the node is fully visible.
741 bool IsFullyVisible( BufferIndex updateBufferIndex ) const;
744 * Retrieve the opacity of the node.
745 * @param[in] bufferIndex The buffer to read from.
746 * @return The opacity.
748 float GetOpacity(BufferIndex bufferIndex) const
750 return mColor[bufferIndex].a;
754 * Retrieve the color of the node.
755 * @param[in] bufferIndex The buffer to read from.
758 const Vector4& GetColor(BufferIndex bufferIndex) const
760 return mColor[bufferIndex];
764 * Sets the color of the node derived from the color of all its parents.
765 * @param[in] color The world color.
766 * @param[in] updateBufferIndex The current update buffer index.
768 void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
770 mWorldColor.Set( updateBufferIndex, color );
774 * Sets the color of the node derived from the color of all its parents.
775 * This method should only be called when the parents world color is up-to-date.
776 * @pre The node has a parent.
777 * @param[in] updateBufferIndex The current update buffer index.
779 void InheritWorldColor( BufferIndex updateBufferIndex )
781 DALI_ASSERT_DEBUG(mParent != NULL);
784 if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
786 const Vector4& ownColor = mColor[updateBufferIndex];
787 mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
789 else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
791 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
793 else if( mColorMode == USE_PARENT_COLOR )
795 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
797 else // USE_OWN_COLOR
799 mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
804 * Copies the previous inherited scale, if this changed in the previous frame.
805 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
806 * does not need to be recalculated in the current frame.
807 * @param[in] updateBufferIndex The current update buffer index.
809 void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
811 mWorldColor.CopyPrevious( updateBufferIndex );
815 * Retrieve the color of the node, possibly derived from the color
816 * of all its parents, depending on the value of mColorMode.
817 * @param[in] bufferIndex The buffer to read from.
818 * @return The world color.
820 const Vector4& GetWorldColor(BufferIndex bufferIndex) const
822 return mWorldColor[bufferIndex];
826 * Set the color mode. This specifies whether the Node uses its own color,
827 * or inherits its parent color.
828 * @param[in] colorMode The new color mode.
830 void SetColorMode(ColorMode colorMode)
832 mColorMode = colorMode;
834 SetDirtyFlag(ColorFlag);
838 * Retrieve the color mode.
839 * @return The color mode.
841 ColorMode GetColorMode() const
847 * Sets the size of the node.
848 * @param[in] bufferIndex The buffer to write to.
849 * @param[in] size The size to write.
851 void SetSize( BufferIndex bufferIndex, const Vector3& size )
853 mSize[bufferIndex] = size;
857 * Retrieve the size of the node.
858 * @param[in] bufferIndex The buffer to read from.
861 const Vector3& GetSize(BufferIndex bufferIndex) const
863 return mSize[bufferIndex];
867 * Set the world-matrix of a node, with scale + rotation + translation.
868 * Scale and rotation are centered at the origin.
869 * Translation is applied independently of the scale or rotatation axis.
870 * @param[in] updateBufferIndex The current update buffer index.
871 * @param[in] scale The scale.
872 * @param[in] rotation The rotation.
873 * @param[in] translation The translation.
875 void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
877 mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
878 mWorldMatrix.SetDirty( updateBufferIndex );
882 * Retrieve the cached world-matrix of a node.
883 * @param[in] bufferIndex The buffer to read from.
884 * @return The world-matrix.
886 const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
888 return mWorldMatrix[ bufferIndex ];
892 * Copy previous frames world matrix
893 * @param[in] updateBufferIndex The current update buffer index.
895 void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
897 mWorldMatrix.CopyPrevious( updateBufferIndex );
901 * Mark the node as exclusive to a single RenderTask.
902 * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
904 void SetExclusiveRenderTask( RenderTask* renderTask )
906 mExclusiveRenderTask = renderTask;
910 * Query whether the node is exclusive to a single RenderTask.
911 * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
913 RenderTask* GetExclusiveRenderTask() const
915 return mExclusiveRenderTask;
919 * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
920 * @param[in] drawMode The new draw-mode to use.
922 void SetDrawMode( const DrawMode::Type& drawMode )
924 mDrawMode = drawMode;
928 * Returns whether node is an overlay or not.
929 * @return True if node is an overlay, false otherwise.
931 DrawMode::Type GetDrawMode() const
937 * Equality operator, checks for identity, not values.
940 bool operator==( const Node* rhs ) const
950 * Set the inhibit local transform flag.@n
951 * Setting this flag will stop the node's local transform (position, scale and orientation)
952 * being applied on top of its parents transformation.
953 * @param[in] flag When true, local transformation is inhibited when calculating the world matrix.
955 void SetInhibitLocalTransform( bool flag )
957 SetDirtyFlag( TransformFlag );
958 mInhibitLocalTransform = flag;
962 * Get the inhibit local transform flag.@n
963 * See @ref SetInhibitLocalTransform
964 * @result A flag, when true, local transformation is inhibited when calculating the world matrix.
966 bool GetInhibitLocalTransform() const
968 return mInhibitLocalTransform;
974 * Set the parent of a Node.
975 * @param[in] parentNode the new parent.
977 void SetParent(Node& parentNode);
980 * Protected constructor; See also Node::New()
984 private: // from NodeDataProvider
987 * @copydoc NodeDataProvider::GetModelMatrix
989 virtual const Matrix& GetModelMatrix( unsigned int bufferId )
991 return GetWorldMatrix( bufferId );
995 * @copydoc NodeDataProvider::GetRenderColor
997 virtual const Vector4& GetRenderColor( unsigned int bufferId )
999 return GetWorldColor( bufferId );
1008 Node& operator=(const Node& rhs);
1011 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
1013 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
1016 * Recursive helper to disconnect a Node and its children.
1017 * Disconnected Nodes have no parent or children.
1018 * @param[in] updateBufferIndex The current update buffer index.
1019 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
1020 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
1022 void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
1024 public: // Default properties
1026 PropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1027 PropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1029 AnimatableProperty<Vector3> mSize; ///< Size is provided for layouting
1030 AnimatableProperty<Vector3> mPosition; ///< Local transform; distance between parent-origin & anchor-point
1031 AnimatableProperty<Quaternion> mRotation; ///< Local transform; rotation relative to parent node
1032 AnimatableProperty<Vector3> mScale; ///< Local transform; scale relative to parent node
1033 AnimatableProperty<bool> mVisible; ///< Visibility can be inherited from the Node hierachy
1034 AnimatableProperty<Vector4> mColor; ///< Color can be inherited from the Node hierarchy
1036 // Inherited properties; read-only from public API
1038 InheritedVector3 mWorldPosition; ///< Full inherited position
1039 InheritedQuaternion mWorldRotation; ///< Full inherited rotation
1040 InheritedVector3 mWorldScale; ///< Full inherited scale
1041 InheritedMatrix mWorldMatrix; ///< Full inherited world matrix
1042 InheritedColor mWorldColor; ///< Full inherited color
1046 Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
1047 RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
1049 NodeAttachmentOwner mAttachment; ///< Optional owned attachment
1050 NodeContainer mChildren; ///< Container of children; not owned
1052 Vector3 mSizeModeFactor; ///< Factor of parent size. Used for certain SizeModes.
1054 // flags, compressed to bitfield
1055 int mDirtyFlags:10; ///< A composite set of flags for each of the Node properties
1057 bool mIsRoot:1; ///< True if the node cannot have a parent
1058 bool mInheritRotation:1; ///< Whether the parent's rotation should be inherited.
1059 bool mInheritScale:1; ///< Whether the parent's scale should be inherited.
1060 bool mInhibitLocalTransform:1; ///< whether local transform should be applied.
1061 bool mIsActive:1; ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1063 DrawMode::Type mDrawMode:2; ///< How the Node and its children should be drawn
1064 PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1065 ColorMode mColorMode:2; ///< Determines whether mWorldColor is inherited, 2 bits is enough
1066 SizeMode mSizeMode:2; ///< Determines how the actors parent affects the actors size.
1068 // Changes scope, should be at end of class
1069 DALI_LOG_OBJECT_STRING_DECLARATION;
1072 // Messages for Node
1074 inline void SetInheritRotationMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1076 typedef MessageValue1< Node, bool > LocalType;
1078 // Reserve some memory inside the message queue
1079 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1081 // Construct message in the message queue memory; note that delete should not be called on the return value
1082 new (slot) LocalType( &node, &Node::SetInheritRotation, inherit );
1085 inline void SetSizeModeMessage( EventToUpdate& eventToUpdate, const Node& node, SizeMode mode )
1087 typedef MessageValue1< Node, SizeMode > LocalType;
1089 // Reserve some memory inside the message queue
1090 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1092 // Construct message in the message queue memory; note that delete should not be called on the return value
1093 new (slot) LocalType( &node, &Node::SetSizeMode, mode );
1096 inline void SetSizeModeFactorMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& factor )
1098 typedef MessageValue1< Node, Vector3 > LocalType;
1100 // Reserve some memory inside the message queue
1101 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1103 // Construct message in the message queue memory; note that delete should not be called on the return value
1104 new (slot) LocalType( &node, &Node::SetSizeModeFactor, factor );
1107 inline void SetParentOriginMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& origin )
1109 typedef MessageValue1< Node, Vector3 > LocalType;
1111 // Reserve some memory inside the message queue
1112 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1114 // Construct message in the message queue memory; note that delete should not be called on the return value
1115 new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1118 inline void SetAnchorPointMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& anchor )
1120 typedef MessageValue1< Node, Vector3 > LocalType;
1122 // Reserve some memory inside the message queue
1123 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1125 // Construct message in the message queue memory; note that delete should not be called on the return value
1126 new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1129 inline void SetPositionInheritanceModeMessage( EventToUpdate& eventToUpdate, const Node& node, PositionInheritanceMode mode )
1131 typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1133 // Reserve some memory inside the message queue
1134 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1136 // Construct message in the message queue memory; note that delete should not be called on the return value
1137 new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1140 inline void SetInheritScaleMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1142 typedef MessageValue1< Node, bool > LocalType;
1144 // Reserve some memory inside the message queue
1145 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1147 // Construct message in the message queue memory; note that delete should not be called on the return value
1148 new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1151 inline void SetColorModeMessage( EventToUpdate& eventToUpdate, const Node& node, ColorMode colorMode )
1153 typedef MessageValue1< Node, ColorMode > LocalType;
1155 // Reserve some memory inside the message queue
1156 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1158 // Construct message in the message queue memory; note that delete should not be called on the return value
1159 new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1162 inline void SetDrawModeMessage( EventToUpdate& eventToUpdate, const Node& node, DrawMode::Type drawMode )
1164 typedef MessageValue1< Node, DrawMode::Type > LocalType;
1166 // Reserve some memory inside the message queue
1167 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1169 // Construct message in the message queue memory; note that delete should not be called on the return value
1170 new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1173 } // namespace SceneGraph
1175 } // namespace Internal
1179 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_