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;
100 void Node::SetRoot(bool isRoot)
102 DALI_ASSERT_DEBUG(!isRoot || mParent == NULL); // Root nodes cannot have a parent
107 void Node::ConnectChild( Node* childNode, int index )
109 DALI_ASSERT_ALWAYS( this != childNode );
110 DALI_ASSERT_ALWAYS( IsRoot() || NULL != mParent ); // Parent should be connected first
111 DALI_ASSERT_ALWAYS( !childNode->IsRoot() && NULL == childNode->GetParent() ); // Child should be disconnected
113 childNode->SetParent( *this );
115 // Everything should be reinherited when reconnected to scene-graph
116 childNode->SetAllDirtyFlags();
120 mChildren.PushBack( childNode );
124 mChildren.Insert(mChildren.Begin()+index, 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;
249 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
251 DALI_ASSERT_ALWAYS(!mIsRoot);
252 DALI_ASSERT_ALWAYS(mParent != NULL);
254 const NodeIter endIter = mChildren.End();
255 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
257 (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
260 // Animators, Constraints etc. should be disconnected from the child's properties.
261 PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
263 // Remove back-pointer to parent
266 // Remove all child pointers
269 // Inform child node attachment that the node has been removed from the stage
272 mAttachment->DisconnectedFromSceneGraph();
275 // Move into disconnectedNodes
276 std::set<Node*>::size_type removed = connectedNodes.erase( this );
277 DALI_ASSERT_ALWAYS( removed );
278 disconnectedNodes.insert( this );
281 } // namespace SceneGraph
283 } // namespace Internal