2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/update/nodes/node.h>
22 #include <dali/internal/update/node-attachments/node-attachment.h>
23 #include <dali/internal/update/common/discard-queue.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/public-api/common/constants.h>
36 const PositionInheritanceMode Node::DEFAULT_POSITION_INHERITANCE_MODE( INHERIT_PARENT_POSITION );
37 const ColorMode Node::DEFAULT_COLOR_MODE( USE_OWN_MULTIPLY_PARENT_ALPHA );
45 : mParentOrigin( ParentOrigin::DEFAULT ),
46 mAnchorPoint( AnchorPoint::DEFAULT ),
47 mSize(), // zero initialized by default
48 mPosition(), // zero initialized by default
49 mOrientation(), // initialized to identity by default
50 mScale( Vector3::ONE ),
52 mColor( Color::WHITE ),
53 mWorldPosition(), // zero initialized by default
54 mWorldOrientation(), // initialized to identity by default
55 mWorldScale( Vector3::ONE ),
57 mWorldColor( Color::WHITE ),
59 mExclusiveRenderTask( NULL ),
63 mDirtyFlags(AllFlags),
65 mInheritOrientation( true ),
66 mInheritScale( true ),
67 mInhibitLocalTransform( false ),
69 mDrawMode( DrawMode::NORMAL ),
70 mPositionInheritanceMode( DEFAULT_POSITION_INHERITANCE_MODE ),
71 mColorMode( DEFAULT_COLOR_MODE )
79 void Node::OnDestroy()
81 // Node attachments should be notified about the disconnection.
84 mAttachment->OnDestroy();
87 // Animators, Constraints etc. should be disconnected from the child's properties.
88 PropertyOwner::Destroy();
91 void Node::Attach( NodeAttachment& object )
93 DALI_ASSERT_DEBUG(!mAttachment);
95 object.SetParent(*this);
97 mAttachment = &object;
102 mAttachment->ConnectedToSceneGraph();
106 void Node::SetRoot(bool isRoot)
108 DALI_ASSERT_DEBUG(!isRoot || mParent == NULL); // Root nodes cannot have a parent
113 void Node::ConnectChild( Node* childNode )
115 DALI_ASSERT_ALWAYS( this != childNode );
116 DALI_ASSERT_ALWAYS( IsRoot() || NULL != mParent ); // Parent should be connected first
117 DALI_ASSERT_ALWAYS( !childNode->IsRoot() && NULL == childNode->GetParent() ); // Child should be disconnected
119 childNode->SetParent( *this );
121 // Everything should be reinherited when reconnected to scene-graph
122 childNode->SetAllDirtyFlags();
124 // Add the node to the end of the child list.
125 mChildren.PushBack( childNode );
127 // Inform property observers of new connection
128 childNode->ConnectToSceneGraph();
130 // Inform child node attachment that the node has been added to the stage
131 if( childNode->mAttachment )
133 childNode->mAttachment->ConnectedToSceneGraph();
137 void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
139 DALI_ASSERT_ALWAYS( this != &childNode );
140 DALI_ASSERT_ALWAYS( childNode.GetParent() == this );
142 // Find the childNode and remove it
145 const NodeIter endIter = mChildren.End();
146 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
148 Node* current = *iter;
149 if ( current == &childNode )
152 mChildren.Erase( iter ); // order matters here
153 break; // iter is no longer valid
156 DALI_ASSERT_ALWAYS( NULL != found );
158 found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
161 int Node::GetDirtyFlags() const
163 // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already
164 int flags = mDirtyFlags;
165 const bool sizeFlag = mSize.IsClean();
167 if ( !(flags & TransformFlag) )
169 // Check whether the transform related properties have changed
171 !mPosition.IsClean() ||
172 !mOrientation.IsClean() ||
174 mParentOrigin.InputChanged() || // parent origin and anchor point rarely change
175 mAnchorPoint.InputChanged() )
177 flags |= TransformFlag;
181 // Check whether the visible property has changed
182 if ( !mVisible.IsClean() )
184 flags |= VisibleFlag;
187 // Check whether the color property has changed
188 if ( !mColor.IsClean() )
193 // Check whether the size property has changed
202 void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
204 // clear dirty flags in parent origin & anchor point
205 mParentOrigin.Clear();
206 mAnchorPoint.Clear();
207 // Reset default properties
208 mSize.ResetToBaseValue( updateBufferIndex );
209 mPosition.ResetToBaseValue( updateBufferIndex );
210 mOrientation.ResetToBaseValue( updateBufferIndex );
211 mScale.ResetToBaseValue( updateBufferIndex );
212 mVisible.ResetToBaseValue( updateBufferIndex );
213 mColor.ResetToBaseValue( updateBufferIndex );
215 mDirtyFlags = NothingFlag;
218 bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const
220 if( !IsVisible( updateBufferIndex ) )
225 Node* parent = mParent;
227 while( NULL != parent )
229 if( !parent->IsVisible( updateBufferIndex ) )
234 parent = parent->GetParent();
240 void Node::SetParent(Node& parentNode)
242 DALI_ASSERT_ALWAYS(this != &parentNode);
243 DALI_ASSERT_ALWAYS(!mIsRoot);
244 DALI_ASSERT_ALWAYS(mParent == NULL);
246 mParent = &parentNode;
247 mDepth = mParent->GetDepth() + 1u;
250 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
252 DALI_ASSERT_ALWAYS(!mIsRoot);
253 DALI_ASSERT_ALWAYS(mParent != NULL);
255 const NodeIter endIter = mChildren.End();
256 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
258 (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
261 // Animators, Constraints etc. should be disconnected from the child's properties.
262 PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
264 // Remove back-pointer to parent
268 // Remove all child pointers
271 // Inform child node attachment that the node has been removed from the stage
274 mAttachment->DisconnectedFromSceneGraph();
277 // Move into disconnectedNodes
278 std::set<Node*>::size_type removed = connectedNodes.erase( this );
279 DALI_ASSERT_ALWAYS( removed );
280 disconnectedNodes.insert( this );
283 } // namespace SceneGraph
285 } // namespace Internal