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, int index )
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();
126 mChildren.PushBack( childNode );
130 mChildren.Insert(mChildren.Begin()+index, childNode);
133 // Inform property observers of new connection
134 childNode->ConnectToSceneGraph();
136 // Inform child node attachment that the node has been added to the stage
137 if( childNode->mAttachment )
139 childNode->mAttachment->ConnectedToSceneGraph();
143 void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
145 DALI_ASSERT_ALWAYS( this != &childNode );
146 DALI_ASSERT_ALWAYS( childNode.GetParent() == this );
148 // Find the childNode and remove it
151 const NodeIter endIter = mChildren.End();
152 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
154 Node* current = *iter;
155 if ( current == &childNode )
158 mChildren.Erase( iter ); // order matters here
159 break; // iter is no longer valid
162 DALI_ASSERT_ALWAYS( NULL != found );
164 found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
167 int Node::GetDirtyFlags() const
169 // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already
170 int flags = mDirtyFlags;
171 const bool sizeFlag = mSize.IsClean();
173 if ( !(flags & TransformFlag) )
175 // Check whether the transform related properties have changed
177 !mPosition.IsClean() ||
178 !mOrientation.IsClean() ||
180 mParentOrigin.InputChanged() || // parent origin and anchor point rarely change
181 mAnchorPoint.InputChanged() )
183 flags |= TransformFlag;
187 // Check whether the visible property has changed
188 if ( !mVisible.IsClean() )
190 flags |= VisibleFlag;
193 // Check whether the color property has changed
194 if ( !mColor.IsClean() )
199 // Check whether the size property has changed
208 void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
210 // clear dirty flags in parent origin & anchor point
211 mParentOrigin.Clear();
212 mAnchorPoint.Clear();
213 // Reset default properties
214 mSize.ResetToBaseValue( updateBufferIndex );
215 mPosition.ResetToBaseValue( updateBufferIndex );
216 mOrientation.ResetToBaseValue( updateBufferIndex );
217 mScale.ResetToBaseValue( updateBufferIndex );
218 mVisible.ResetToBaseValue( updateBufferIndex );
219 mColor.ResetToBaseValue( updateBufferIndex );
221 mDirtyFlags = NothingFlag;
224 bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const
226 if( !IsVisible( updateBufferIndex ) )
231 Node* parent = mParent;
233 while( NULL != parent )
235 if( !parent->IsVisible( updateBufferIndex ) )
240 parent = parent->GetParent();
246 void Node::SetParent(Node& parentNode)
248 DALI_ASSERT_ALWAYS(this != &parentNode);
249 DALI_ASSERT_ALWAYS(!mIsRoot);
250 DALI_ASSERT_ALWAYS(mParent == NULL);
252 mParent = &parentNode;
253 mDepth = mParent->GetDepth() + 1u;
256 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
258 DALI_ASSERT_ALWAYS(!mIsRoot);
259 DALI_ASSERT_ALWAYS(mParent != NULL);
261 const NodeIter endIter = mChildren.End();
262 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
264 (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
267 // Animators, Constraints etc. should be disconnected from the child's properties.
268 PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
270 // Remove back-pointer to parent
274 // Remove all child pointers
277 // Inform child node attachment that the node has been removed from the stage
280 mAttachment->DisconnectedFromSceneGraph();
283 // Move into disconnectedNodes
284 std::set<Node*>::size_type removed = connectedNodes.erase( this );
285 DALI_ASSERT_ALWAYS( removed );
286 disconnectedNodes.insert( this );
289 } // namespace SceneGraph
291 } // namespace Internal