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 ),
62 mDirtyFlags(AllFlags),
64 mInheritOrientation( true ),
65 mInheritScale( true ),
66 mInhibitLocalTransform( false ),
68 mDrawMode( DrawMode::NORMAL ),
69 mPositionInheritanceMode( DEFAULT_POSITION_INHERITANCE_MODE ),
70 mColorMode( DEFAULT_COLOR_MODE )
78 void Node::OnDestroy()
80 // Node attachments should be notified about the disconnection.
83 mAttachment->OnDestroy();
86 // Animators, Constraints etc. should be disconnected from the child's properties.
87 PropertyOwner::Destroy();
90 void Node::Attach( NodeAttachment& object )
92 DALI_ASSERT_DEBUG(!mAttachment);
94 object.SetParent(*this);
96 mAttachment = &object;
101 mAttachment->ConnectedToSceneGraph();
105 void Node::SetRoot(bool isRoot)
107 DALI_ASSERT_DEBUG(!isRoot || mParent == NULL); // Root nodes cannot have a parent
112 void Node::ConnectChild( Node* childNode, int index )
114 DALI_ASSERT_ALWAYS( this != childNode );
115 DALI_ASSERT_ALWAYS( IsRoot() || NULL != mParent ); // Parent should be connected first
116 DALI_ASSERT_ALWAYS( !childNode->IsRoot() && NULL == childNode->GetParent() ); // Child should be disconnected
118 childNode->SetParent( *this );
120 // Everything should be reinherited when reconnected to scene-graph
121 childNode->SetAllDirtyFlags();
125 mChildren.PushBack( childNode );
129 mChildren.Insert(mChildren.Begin()+index, childNode);
132 // Inform property observers of new connection
133 childNode->ConnectToSceneGraph();
135 // Inform child node attachment that the node has been added to the stage
136 if( childNode->mAttachment )
138 childNode->mAttachment->ConnectedToSceneGraph();
142 void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
144 DALI_ASSERT_ALWAYS( this != &childNode );
145 DALI_ASSERT_ALWAYS( childNode.GetParent() == this );
147 // Find the childNode and remove it
150 const NodeIter endIter = mChildren.End();
151 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
153 Node* current = *iter;
154 if ( current == &childNode )
157 mChildren.Erase( iter ); // order matters here
158 break; // iter is no longer valid
161 DALI_ASSERT_ALWAYS( NULL != found );
163 found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
166 int Node::GetDirtyFlags() const
168 // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already
169 int flags = mDirtyFlags;
170 const bool sizeFlag = mSize.IsClean();
172 if ( !(flags & TransformFlag) )
174 // Check whether the transform related properties have changed
176 !mPosition.IsClean() ||
177 !mOrientation.IsClean() ||
179 mParentOrigin.InputChanged() || // parent origin and anchor point rarely change
180 mAnchorPoint.InputChanged() )
182 flags |= TransformFlag;
186 // Check whether the visible property has changed
187 if ( !mVisible.IsClean() )
189 flags |= VisibleFlag;
192 // Check whether the color property has changed
193 if ( !mColor.IsClean() )
198 // Check whether the size property has changed
207 void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
209 // clear dirty flags in parent origin & anchor point
210 mParentOrigin.Clear();
211 mAnchorPoint.Clear();
212 // Reset default properties
213 mSize.ResetToBaseValue( updateBufferIndex );
214 mPosition.ResetToBaseValue( updateBufferIndex );
215 mOrientation.ResetToBaseValue( updateBufferIndex );
216 mScale.ResetToBaseValue( updateBufferIndex );
217 mVisible.ResetToBaseValue( updateBufferIndex );
218 mColor.ResetToBaseValue( updateBufferIndex );
220 mDirtyFlags = NothingFlag;
223 bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const
225 if( !IsVisible( updateBufferIndex ) )
230 Node* parent = mParent;
232 while( NULL != parent )
234 if( !parent->IsVisible( updateBufferIndex ) )
239 parent = parent->GetParent();
245 void Node::SetParent(Node& parentNode)
247 DALI_ASSERT_ALWAYS(this != &parentNode);
248 DALI_ASSERT_ALWAYS(!mIsRoot);
249 DALI_ASSERT_ALWAYS(mParent == NULL);
251 mParent = &parentNode;
254 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
256 DALI_ASSERT_ALWAYS(!mIsRoot);
257 DALI_ASSERT_ALWAYS(mParent != NULL);
259 const NodeIter endIter = mChildren.End();
260 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
262 (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
265 // Animators, Constraints etc. should be disconnected from the child's properties.
266 PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
268 // Remove back-pointer to parent
271 // Remove all child pointers
274 // Inform child node attachment that the node has been removed from the stage
277 mAttachment->DisconnectedFromSceneGraph();
280 // Move into disconnectedNodes
281 std::set<Node*>::size_type removed = connectedNodes.erase( this );
282 DALI_ASSERT_ALWAYS( removed );
283 disconnectedNodes.insert( this );
286 } // namespace SceneGraph
288 } // namespace Internal