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/double-buffered.h>
32 #include <dali/internal/update/common/property-owner.h>
33 #include <dali/internal/update/common/property-vector3.h>
34 #include <dali/internal/update/common/scene-graph-buffers.h>
35 #include <dali/internal/update/common/inherited-property.h>
36 #include <dali/integration-api/debug.h>
37 #include <dali/internal/update/nodes/node-declarations.h>
38 #include <dali/internal/update/node-attachments/node-attachment-declarations.h>
39 #include <dali/internal/render/renderers/render-data-provider.h>
47 // value types used by messages
48 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
49 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
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.
88 * Each node provides a transformation which applies to the node and its children.
89 * Node data is double-buffered. This allows an update thread to modify node data, without interferring
90 * with another thread reading the values from the previous update traversal.
92 class Node : public PropertyOwner, public RenderDataProvider
97 static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
98 static const ColorMode DEFAULT_COLOR_MODE;
103 * Construct a new Node.
113 * When a Node is marked "active" it has been disconnected, but its properties have been modified.
114 * @note An inactive Node will be skipped during the UpdateManager ResetProperties stage.
115 * @param[in] isActive True if the Node is active.
117 void SetActive( bool isActive )
119 mIsActive = isActive;
123 * Query whether the Node is active.
124 * @return True if the Node is active.
126 bool IsActive() const
132 * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
139 * Query whether the node is a layer.
140 * @return True if the node is a layer.
144 return (GetLayer() != NULL);
148 * Convert a node to a layer.
149 * @return A pointer to the layer, or NULL.
151 virtual Layer* GetLayer()
159 * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
160 * @pre The Node does not already have an attachment.
161 * @param[in] attachment The object to attach.
163 void Attach( NodeAttachment& attachment );
166 * Query the node if it has an attachment.
167 * @return True if it has an attachment.
169 bool HasAttachment() const
175 * Retreive the object attached to this node.
176 * @return The attachment.
178 NodeAttachment& GetAttachment() const
183 // Containment methods
186 * Query whether a node is the root node. Root nodes cannot have a parent node.
187 * A node becomes a root node, when it is installed by UpdateManager.
188 * @return True if the node is a root node.
196 * Set whether a node is the root node. Root nodes cannot have a parent node.
197 * This method should only be called by UpdateManager.
198 * @pre When isRoot is true, the node must not have a parent.
199 * @param[in] isRoot Whether the node is now a root node.
201 void SetRoot(bool isRoot);
204 * Retrieve the parent of a Node.
205 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
213 * Retrieve the parent of a Node.
214 * @return The parent node, or NULL if the Node has not been added to the scene-graph.
216 const Node* GetParent() const
222 * Connect a node to the scene-graph.
223 * @pre A node cannot be added to itself.
224 * @pre The parent node is connected to the scene-graph.
225 * @pre The childNode does not already have a parent.
226 * @pre The childNode is not a root node.
227 * @param[in] childNode The child to add.
228 * @param[in] index to insert at, if not supplied or -1 it will be appended
231 void ConnectChild( Node* childNode, int index = -1);
234 * Disconnect a child (& its children) from the scene-graph.
235 * @pre childNode is a child of this Node.
236 * @param[in] updateBufferIndex The current update buffer index.
237 * @param[in] childNode The node to disconnect.
238 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
239 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
241 void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
244 * Retrieve the children a Node.
245 * @return The container of children.
247 const NodeContainer& GetChildren() const
253 * Retrieve the children a Node.
254 * @return The container of children.
256 NodeContainer& GetChildren()
264 * Flag that one of the node values has changed in the current frame.
265 * @param[in] flag The flag to set.
267 void SetDirtyFlag(NodePropertyFlags flag)
273 * Flag that all of the node values are dirty.
275 void SetAllDirtyFlags()
277 mDirtyFlags = AllFlags;
281 * Query whether a node is dirty.
282 * @return The dirty flags
284 int GetDirtyFlags() const;
287 * Query whether a node is clean.
288 * @return True if the node is clean.
292 return ( NothingFlag == GetDirtyFlags() );
296 * Retrieve the parent-origin of the node.
297 * @return The parent-origin.
299 const Vector3& GetParentOrigin() const
301 return mParentOrigin.mValue;
305 * Sets both the local & base parent-origins of the node.
306 * @param[in] origin The new local & base parent-origins.
308 void SetParentOrigin(const Vector3& origin)
310 mParentOrigin.mValue = origin;
311 mParentOrigin.OnSet();
315 * Retrieve the anchor-point of the node.
316 * @return The anchor-point.
318 const Vector3& GetAnchorPoint() const
320 return mAnchorPoint.mValue;
324 * Sets both the local & base anchor-points of the node.
325 * @param[in] anchor The new local & base anchor-points.
327 void SetAnchorPoint(const Vector3& anchor)
329 mAnchorPoint.mValue = anchor;
330 mAnchorPoint.OnSet();
334 * Retrieve the local position of the node, relative to its parent.
335 * @param[in] bufferIndex The buffer to read from.
336 * @return The local position.
338 const Vector3& GetPosition(BufferIndex bufferIndex) const
340 return mPosition[bufferIndex];
344 * Sets both the local & base positions of the node.
345 * @param[in] updateBufferIndex The current update buffer index.
346 * @param[in] position The new local & base position.
348 void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
350 mPosition.Bake( updateBufferIndex, position );
354 * Sets the world of the node derived from the position of all its parents.
355 * @param[in] updateBufferIndex The current update buffer index.
356 * @param[in] position The world position.
358 void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
360 mWorldPosition.Set( updateBufferIndex, position );
364 * Sets the position of the node derived from the position of all its parents.
365 * This method should only be called when the parent's world position is up-to-date.
366 * With a non-central anchor-point, the local rotation and scale affects the world position.
367 * Therefore the world rotation & scale must be updated before the world position.
368 * @pre The node has a parent.
369 * @param[in] updateBufferIndex The current update buffer index.
371 void InheritWorldPosition(BufferIndex updateBufferIndex)
373 DALI_ASSERT_DEBUG(mParent != NULL);
375 switch( mPositionInheritanceMode )
377 case INHERIT_PARENT_POSITION : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
379 Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
381 finalPosition += mParentOrigin.mValue;
382 finalPosition *= mParent->GetSize(updateBufferIndex);
383 finalPosition += mPosition[updateBufferIndex];
384 finalPosition *= mParent->GetWorldScale(updateBufferIndex);
385 const Quaternion& parentWorldRotation = mParent->GetWorldRotation(updateBufferIndex);
386 if(!parentWorldRotation.IsIdentity())
388 finalPosition *= parentWorldRotation;
391 // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
392 // dont use operator== as that does a slower comparison (and involves function calls)
393 Vector3 localOffset(0.5f, 0.5f, 0.5f); // AnchorPoint::CENTER
394 localOffset -= mAnchorPoint.mValue;
396 if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
397 ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
398 ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
400 localOffset *= mSize[updateBufferIndex];
402 Vector3 scale = mWorldScale[updateBufferIndex];
403 if(GetTransmitGeometryScaling())
405 // Remove geometry scaling to get back to actor scale
406 scale /= mGeometryScale;
408 // Also pick up sign of local scale
409 if (mScale[updateBufferIndex].x < 0.0f)
413 if (mScale[updateBufferIndex].y < 0.0f)
417 if (mScale[updateBufferIndex].z < 0.0f)
422 // If the anchor-point is not central, then position is affected by the local rotation & scale
423 localOffset *= scale;
424 const Quaternion& localWorldRotation = mWorldRotation[updateBufferIndex];
425 if(!localWorldRotation.IsIdentity())
427 localOffset *= localWorldRotation;
429 finalPosition += localOffset;
432 finalPosition += mParent->GetWorldPosition(updateBufferIndex);
433 mWorldPosition.Set( updateBufferIndex, finalPosition );
436 case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
438 // copy parents position plus local transform
439 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
442 case USE_PARENT_POSITION :
444 // copy parents position
445 mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
448 case DONT_INHERIT_POSITION :
450 // use local position as world position
451 mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
458 * Copies the previous inherited position, if this changed in the previous frame.
459 * This method should be called instead of InheritWorldPosition i.e. if the inherited position
460 * does not need to be recalculated in the current frame.
461 * @param[in] updateBufferIndex The current update buffer index.
463 void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
465 mWorldPosition.CopyPrevious( updateBufferIndex );
469 * Retrieve the position of the node derived from the position of all its parents.
470 * @return The world position.
472 const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
474 return mWorldPosition[bufferIndex];
478 * Set the position inheritance mode.
479 * @see Dali::Actor::PositionInheritanceMode
480 * @param[in] mode The new position inheritance mode.
482 void SetPositionInheritanceMode( PositionInheritanceMode mode )
484 mPositionInheritanceMode = mode;
486 SetDirtyFlag(TransformFlag);
490 * @return The position inheritance mode.
492 PositionInheritanceMode GetPositionInheritanceMode() const
494 return mPositionInheritanceMode;
498 * Retrieve the local rotation of the node, relative to its parent.
499 * @param[in] bufferIndex The buffer to read from.
500 * @return The local rotation.
502 const Quaternion& GetRotation(BufferIndex bufferIndex) const
504 return mRotation[bufferIndex];
508 * Sets both the local & base rotations of the node.
509 * @param[in] updateBufferIndex The current update buffer index.
510 * @param[in] rotation The new local & base rotation.
512 void BakeRotation(BufferIndex updateBufferIndex, const Quaternion& rotation)
514 mRotation.Bake( updateBufferIndex, rotation );
518 * Sets the rotation of the node derived from the rotation of all its parents.
519 * @param[in] updateBufferIndex The current update buffer index.
520 * @param[in] rotation The world rotation.
522 void SetWorldRotation( BufferIndex updateBufferIndex, const Quaternion& rotation )
524 mWorldRotation.Set( updateBufferIndex, rotation );
528 * Sets the rotation of the node derived from the rotation of all its parents.
529 * This method should only be called when the parents world rotation is up-to-date.
530 * @pre The node has a parent.
531 * @param[in] updateBufferIndex The current update buffer index.
533 void InheritWorldRotation( BufferIndex updateBufferIndex )
535 DALI_ASSERT_DEBUG(mParent != NULL);
537 const Quaternion& localRotation = mRotation[updateBufferIndex];
539 if(localRotation.IsIdentity())
541 mWorldRotation.Set( updateBufferIndex, mParent->GetWorldRotation(updateBufferIndex) );
545 Quaternion finalRotation( mParent->GetWorldRotation(updateBufferIndex) );
546 finalRotation *= localRotation;
547 mWorldRotation.Set( updateBufferIndex, finalRotation );
552 * Copies the previous inherited rotation, if this changed in the previous frame.
553 * This method should be called instead of InheritWorldRotation i.e. if the inherited rotation
554 * does not need to be recalculated in the current frame.
555 * @param[in] updateBufferIndex The current update buffer index.
557 void CopyPreviousWorldRotation( BufferIndex updateBufferIndex )
559 mWorldRotation.CopyPrevious( updateBufferIndex );
563 * Retrieve the rotation of the node derived from the rotation of all its parents.
564 * @param[in] bufferIndex The buffer to read from.
565 * @return The world rotation.
567 const Quaternion& GetWorldRotation( BufferIndex bufferIndex ) const
569 return mWorldRotation[bufferIndex];
573 * Set whether the Node inherits rotation.
574 * @param[in] inherit True if the parent rotation is inherited.
576 void SetInheritRotation(bool inherit)
578 if (inherit != mInheritRotation)
580 mInheritRotation = inherit;
582 SetDirtyFlag(TransformFlag);
587 * Query whether the node inherits rotation from its parent.
588 * @return True if the parent rotation is inherited.
590 bool IsRotationInherited() const
592 return mInheritRotation;
596 * Set the initial volume of the node. Used for calculating geometry scaling
597 * as the node size is changed when transmitGeometryScaling is set to true.
599 * This property is not animatable.
601 * @param[in] volume The initial volume of this nodes meshes & children
603 void SetInitialVolume( const Vector3& volume)
605 mInitialVolume = volume;
606 SetDirtyFlag(SizeFlag);
610 * Get the initial volume. Used for calculating geometry scaling
611 * when TransmitGeometryScaling is true (i.e., the scaling is baked
612 * into the node tranform)
614 * @return The initial volume of this node and children.
616 Vector3 GetInitialVolume()
618 return mInitialVolume;
622 * Sets whether the geometry scaling should be applied to the node
623 * (In which case, set the initial scale using SetInitialVolume()).
625 * If it is applied to the node, then the attachments are not scaled,
626 * as the scaling is then already baked into the node transform.
628 * @param[in] transmitGeometryScaling true if scaling is to be applied
631 void SetTransmitGeometryScaling(bool transmitGeometryScaling)
633 mTransmitGeometryScaling = transmitGeometryScaling;
634 SetDirtyFlag(SizeFlag);
638 * Find out whether the node allows geometry scaling to be transmitted to its children.
639 * @return true if transmitted.
641 bool GetTransmitGeometryScaling() const
643 return mTransmitGeometryScaling;
647 * Retrieve the local scale of the node, relative to its parent.
648 * @param[in] bufferIndex The buffer to read from.
649 * @return The local scale.
651 const Vector3& GetScale(BufferIndex bufferIndex) const
653 return mScale[bufferIndex];
657 * Sets the scale of the node derived from the scale of all its parents and a pre-scale
658 * @param[in] updateBufferIndex The current update buffer index.
659 * @param[in] scale The world scale.
661 void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
663 mWorldScale.Set( updateBufferIndex, mGeometryScale * scale );
667 * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
668 * This method should only be called when the parents world scale is up-to-date.
669 * @pre The node has a parent.
670 * @param[in] updateBufferIndex The current update buffer index.
672 void InheritWorldScale(BufferIndex updateBufferIndex)
674 DALI_ASSERT_DEBUG(mParent != NULL);
676 mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mGeometryScale * mScale[updateBufferIndex] );
680 * Copies the previous inherited scale, if this changed in the previous frame.
681 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
682 * does not need to be recalculated in the current frame.
683 * @param[in] updateBufferIndex The current update buffer index.
685 void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
687 mWorldScale.CopyPrevious( updateBufferIndex );
691 * Retrieve the scale of the node derived from the scale of all its parents.
692 * @param[in] bufferIndex The buffer to read from.
693 * @return The world scale.
695 const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
697 return mWorldScale[bufferIndex];
701 * Set whether the Node inherits scale.
702 * @param inherit True if the Node inherits scale.
704 void SetInheritScale( bool inherit )
706 if( inherit != mInheritScale )
708 mInheritScale = inherit;
710 SetDirtyFlag( TransformFlag );
715 * Query whether the Node inherits scale.
716 * @return if scale is inherited
718 bool IsScaleInherited() const
720 return mInheritScale;
724 * Sets a geometry scale, calculated when TransmitGeometryScaling is true.
725 * Must only be used from render thread.
726 * @param[in] geometryScale The geometry scale value
728 void SetGeometryScale(Vector3 geometryScale)
730 mGeometryScale = geometryScale;
732 SetDirtyFlag( TransformFlag );
736 * Retrieve the geometry scale, calculated when TransmitGeometryScaling is true.
737 * @return The geometry scale value.
739 const Vector3& GetGeometryScale() const
741 return mGeometryScale;
745 * Retrieve the visibility of the node.
746 * @param[in] bufferIndex The buffer to read from.
747 * @return True if the node is visible.
749 bool IsVisible(BufferIndex bufferIndex) const
751 return mVisible[bufferIndex];
755 * Retrieves whether a node is fully visible.
756 * A node is fully visible if is visible and all its ancestors are visible.
757 * @param[in] updateBufferIndex The current update buffer index.
758 * @return True if the node is fully visible.
760 bool IsFullyVisible( BufferIndex updateBufferIndex ) const;
763 * Retrieve the opacity of the node.
764 * @param[in] bufferIndex The buffer to read from.
765 * @return The opacity.
767 float GetOpacity(BufferIndex bufferIndex) const
769 return mColor[bufferIndex].a;
773 * Retrieve the color of the node.
774 * @param[in] bufferIndex The buffer to read from.
777 const Vector4& GetColor(BufferIndex bufferIndex) const
779 return mColor[bufferIndex];
783 * Sets the color of the node derived from the color of all its parents.
784 * @param[in] color The world color.
785 * @param[in] updateBufferIndex The current update buffer index.
787 void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
789 mWorldColor.Set( updateBufferIndex, color );
793 * Sets the color of the node derived from the color of all its parents.
794 * This method should only be called when the parents world color is up-to-date.
795 * @pre The node has a parent.
796 * @param[in] updateBufferIndex The current update buffer index.
798 void InheritWorldColor( BufferIndex updateBufferIndex )
800 DALI_ASSERT_DEBUG(mParent != NULL);
803 if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
805 const Vector4& ownColor = mColor[updateBufferIndex];
806 mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
808 else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
810 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
812 else if( mColorMode == USE_PARENT_COLOR )
814 mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
816 else // USE_OWN_COLOR
818 mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
823 * Copies the previous inherited scale, if this changed in the previous frame.
824 * This method should be called instead of InheritWorldScale i.e. if the inherited scale
825 * does not need to be recalculated in the current frame.
826 * @param[in] updateBufferIndex The current update buffer index.
828 void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
830 mWorldColor.CopyPrevious( updateBufferIndex );
834 * Retrieve the color of the node, possibly derived from the color
835 * of all its parents, depending on the value of mColorMode.
836 * @param[in] bufferIndex The buffer to read from.
837 * @return The world color.
839 const Vector4& GetWorldColor(BufferIndex bufferIndex) const
841 return mWorldColor[bufferIndex];
845 * Set the color mode. This specifies whether the Node uses its own color,
846 * or inherits its parent color.
847 * @param[in] colorMode The new color mode.
849 void SetColorMode(ColorMode colorMode)
851 mColorMode = colorMode;
853 SetDirtyFlag(ColorFlag);
857 * Retrieve the color mode.
858 * @return The color mode.
860 ColorMode GetColorMode() const
866 * Retrieve the size of the node.
867 * @param[in] bufferIndex The buffer to read from.
870 const Vector3& GetSize(BufferIndex bufferIndex) const
872 return mSize[bufferIndex];
876 * Set the world-matrix of a node, with scale + rotation + translation.
877 * Scale and rotation are centered at the origin.
878 * Translation is applied independently of the scale or rotatation axis.
879 * @param[in] updateBufferIndex The current update buffer index.
880 * @param[in] scale The scale.
881 * @param[in] rotation The rotation.
882 * @param[in] translation The translation.
884 void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
886 mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
887 mWorldMatrix.SetDirty( updateBufferIndex );
891 * Retrieve the cached world-matrix of a node.
892 * @param[in] bufferIndex The buffer to read from.
893 * @return The world-matrix.
895 const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
897 return mWorldMatrix[ bufferIndex ];
901 * Copy previous frames world matrix
902 * @param[in] updateBufferIndex The current update buffer index.
904 void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
906 mWorldMatrix.CopyPrevious( updateBufferIndex );
910 * Mark the node as exclusive to a single RenderTask.
911 * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
913 void SetExclusiveRenderTask( RenderTask* renderTask )
915 mExclusiveRenderTask = renderTask;
919 * Query whether the node is exclusive to a single RenderTask.
920 * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
922 RenderTask* GetExclusiveRenderTask() const
924 return mExclusiveRenderTask;
928 * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
929 * @param[in] drawMode The new draw-mode to use.
931 void SetDrawMode( const DrawMode::Type& drawMode )
933 mDrawMode = drawMode;
937 * Returns whether node is an overlay or not.
938 * @return True if node is an overlay, false otherwise.
940 DrawMode::Type GetDrawMode() const
946 * Equality operator, checks for identity, not values.
949 bool operator==( const Node* rhs ) const
959 * Set the inhibit local transform flag.@n
960 * Setting this flag will stop the node's local transform (position, scale and orientation)
961 * being applied on top of its parents transformation.
962 * @param[in] flag When true, local transformation is inhibited when calculating the world matrix.
964 void SetInhibitLocalTransform( bool flag )
966 SetDirtyFlag( TransformFlag );
967 mInhibitLocalTransform = flag;
971 * Get the inhibit local transform flag.@n
972 * See @ref SetInhibitLocalTransform
973 * @result A flag, when true, local transformation is inhibited when calculating the world matrix.
975 bool GetInhibitLocalTransform() const
977 return mInhibitLocalTransform;
983 * Set the parent of a Node.
984 * @param[in] parentNode the new parent.
986 void SetParent(Node& parentNode);
989 * Protected constructor; See also Node::New()
993 private: // from RenderDataProvider
996 * @copydoc RenderDataProvider::GetModelMatrix
998 virtual const Matrix& GetModelMatrix( unsigned int bufferId )
1000 return GetWorldMatrix( bufferId );
1004 * @copydoc RenderDataProvider::GetRenderColor
1006 virtual const Vector4& GetRenderColor( unsigned int bufferId )
1008 return GetWorldColor( bufferId );
1017 Node& operator=(const Node& rhs);
1020 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
1022 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
1025 * Recursive helper to disconnect a Node and its children.
1026 * Disconnected Nodes have no parent or children.
1027 * @param[in] updateBufferIndex The current update buffer index.
1028 * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
1029 * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
1031 void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
1033 public: // Default properties
1035 PropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1036 PropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1038 AnimatableProperty<Vector3> mSize; ///< Size is provided for layouting
1039 AnimatableProperty<Vector3> mPosition; ///< Local transform; distance between parent-origin & anchor-point
1040 AnimatableProperty<Quaternion> mRotation; ///< Local transform; rotation relative to parent node
1041 AnimatableProperty<Vector3> mScale; ///< Local transform; scale relative to parent node
1042 AnimatableProperty<bool> mVisible; ///< Visibility can be inherited from the Node hierachy
1043 AnimatableProperty<Vector4> mColor; ///< Color can be inherited from the Node hierarchy
1045 // Inherited properties; read-only from public API
1047 InheritedVector3 mWorldPosition; ///< Full inherited position
1048 InheritedQuaternion mWorldRotation; ///< Full inherited rotation
1049 InheritedVector3 mWorldScale; ///< Full inherited scale
1050 InheritedMatrix mWorldMatrix; ///< Full inherited world matrix
1051 InheritedColor mWorldColor; ///< Full inherited color
1055 Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
1056 RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
1058 NodeAttachmentOwner mAttachment; ///< Optional owned attachment
1059 NodeContainer mChildren; ///< Container of children; not owned
1061 Vector3 mGeometryScale; ///< Applied before calculating world transform.
1062 Vector3 mInitialVolume; ///< Initial volume... TODO - need a better name
1064 // flags, compressed to bitfield
1065 int mDirtyFlags:10; ///< A composite set of flags for each of the Node properties
1067 bool mIsRoot:1; ///< True if the node cannot have a parent
1068 bool mInheritRotation:1; ///< Whether the parent's rotation should be inherited.
1069 bool mInheritScale:1; ///< Whether the parent's scale should be inherited.
1070 bool mTransmitGeometryScaling:1; ///< Whether geometry scaling should be applied to world transform.
1071 bool mInhibitLocalTransform:1; ///< whether local transform should be applied.
1072 bool mIsActive:1; ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1074 DrawMode::Type mDrawMode:2; ///< How the Node and its children should be drawn
1075 PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1076 ColorMode mColorMode:2; ///< Determines whether mWorldColor is inherited, 2 bits is enough
1078 // Changes scope, should be at end of class
1079 DALI_LOG_OBJECT_STRING_DECLARATION;
1082 // Messages for Node
1084 inline void SetInheritRotationMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1086 typedef MessageValue1< Node, bool > LocalType;
1088 // Reserve some memory inside the message queue
1089 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1091 // Construct message in the message queue memory; note that delete should not be called on the return value
1092 new (slot) LocalType( &node, &Node::SetInheritRotation, inherit );
1095 inline void SetInitialVolumeMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& initialVolume )
1097 typedef MessageValue1< Node, Vector3 > LocalType;
1099 // Reserve some memory inside the message queue
1100 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1102 // Construct message in the message queue memory; note that delete should not be called on the return value
1103 new (slot) LocalType( &node, &Node::SetInitialVolume, initialVolume );
1106 inline void SetTransmitGeometryScalingMessage( EventToUpdate& eventToUpdate, const Node& node, bool transmitGeometryScaling )
1108 typedef MessageValue1< Node, bool > LocalType;
1110 // Reserve some memory inside the message queue
1111 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1113 // Construct message in the message queue memory; note that delete should not be called on the return value
1114 new (slot) LocalType( &node, &Node::SetTransmitGeometryScaling, transmitGeometryScaling );
1117 inline void SetParentOriginMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& origin )
1119 typedef MessageValue1< Node, Vector3 > LocalType;
1121 // Reserve some memory inside the message queue
1122 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1124 // Construct message in the message queue memory; note that delete should not be called on the return value
1125 new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1128 inline void SetAnchorPointMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& anchor )
1130 typedef MessageValue1< Node, Vector3 > LocalType;
1132 // Reserve some memory inside the message queue
1133 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1135 // Construct message in the message queue memory; note that delete should not be called on the return value
1136 new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1139 inline void SetPositionInheritanceModeMessage( EventToUpdate& eventToUpdate, const Node& node, PositionInheritanceMode mode )
1141 typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1143 // Reserve some memory inside the message queue
1144 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1146 // Construct message in the message queue memory; note that delete should not be called on the return value
1147 new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1150 inline void SetInheritScaleMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1152 typedef MessageValue1< Node, bool > LocalType;
1154 // Reserve some memory inside the message queue
1155 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1157 // Construct message in the message queue memory; note that delete should not be called on the return value
1158 new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1161 inline void SetColorModeMessage( EventToUpdate& eventToUpdate, const Node& node, ColorMode colorMode )
1163 typedef MessageValue1< Node, ColorMode > LocalType;
1165 // Reserve some memory inside the message queue
1166 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1168 // Construct message in the message queue memory; note that delete should not be called on the return value
1169 new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1172 inline void SetDrawModeMessage( EventToUpdate& eventToUpdate, const Node& node, DrawMode::Type drawMode )
1174 typedef MessageValue1< Node, DrawMode::Type > LocalType;
1176 // Reserve some memory inside the message queue
1177 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1179 // Construct message in the message queue memory; note that delete should not be called on the return value
1180 new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1183 } // namespace SceneGraph
1185 } // namespace Internal
1189 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_