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 mRotation(), // initialized to identity by default
50 mScale( Vector3::ONE ),
52 mColor( Color::WHITE ),
53 mWorldPosition(), // zero initialized by default
54 mWorldRotation(), // initialized to identity by default
55 mWorldScale( Vector3::ONE ),
57 mWorldColor( Color::WHITE ),
59 mExclusiveRenderTask( NULL ),
62 mGeometryScale( Vector3::ONE ),
63 mInitialVolume( Vector3::ONE ),
64 mDirtyFlags(AllFlags),
66 mInheritRotation( true ),
67 mInheritScale( true ),
68 mTransmitGeometryScaling( false ),
69 mInhibitLocalTransform( false ),
71 mDrawMode( DrawMode::NORMAL ),
72 mPositionInheritanceMode( DEFAULT_POSITION_INHERITANCE_MODE ),
73 mColorMode( DEFAULT_COLOR_MODE )
81 void Node::OnDestroy()
83 // Node attachments should be notified about the disconnection.
86 mAttachment->OnDestroy();
89 // Animators, Constraints etc. should be disconnected from the child's properties.
90 PropertyOwner::Destroy();
93 void Node::Attach( NodeAttachment& object )
95 DALI_ASSERT_DEBUG(!mAttachment);
97 object.SetParent(*this);
99 mAttachment = &object;
103 void Node::SetRoot(bool isRoot)
105 DALI_ASSERT_DEBUG(!isRoot || mParent == NULL); // Root nodes cannot have a parent
110 void Node::ConnectChild( Node* childNode, int index )
112 DALI_ASSERT_ALWAYS( this != childNode );
113 DALI_ASSERT_ALWAYS( IsRoot() || NULL != mParent ); // Parent should be connected first
114 DALI_ASSERT_ALWAYS( !childNode->IsRoot() && NULL == childNode->GetParent() ); // Child should be disconnected
116 childNode->SetParent( *this );
118 // Everything should be reinherited when reconnected to scene-graph
119 childNode->SetAllDirtyFlags();
123 mChildren.PushBack( childNode );
127 mChildren.Insert(mChildren.Begin()+index, childNode);
130 childNode->ConnectToSceneGraph();
133 void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
135 DALI_ASSERT_ALWAYS( this != &childNode );
136 DALI_ASSERT_ALWAYS( childNode.GetParent() == this );
138 // Find the childNode and remove it
141 const NodeIter endIter = mChildren.End();
142 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
144 Node* current = *iter;
145 if ( current == &childNode )
148 mChildren.Erase( iter ); // order matters here
149 break; // iter is no longer valid
152 DALI_ASSERT_ALWAYS( NULL != found );
154 found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
157 int Node::GetDirtyFlags() const
159 // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already
160 int flags = mDirtyFlags;
161 const bool sizeFlag = mSize.IsClean();
163 if ( !(flags & TransformFlag) )
165 // Check whether the transform related properties have changed
167 !mPosition.IsClean() ||
168 !mRotation.IsClean() ||
170 mParentOrigin.InputChanged() || // parent origin and anchor point rarely change
171 mAnchorPoint.InputChanged() )
173 flags |= TransformFlag;
177 // Check whether the visible property has changed
178 if ( !mVisible.IsClean() )
180 flags |= VisibleFlag;
183 // Check whether the color property has changed
184 if ( !mColor.IsClean() )
189 // Check whether the size property has changed
198 void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
200 // clear dirty flags in parent origin & anchor point
201 mParentOrigin.Clear();
202 mAnchorPoint.Clear();
203 // Reset default properties
204 mSize.ResetToBaseValue( updateBufferIndex );
205 mPosition.ResetToBaseValue( updateBufferIndex );
206 mRotation.ResetToBaseValue( updateBufferIndex );
207 mScale.ResetToBaseValue( updateBufferIndex );
208 mVisible.ResetToBaseValue( updateBufferIndex );
209 mColor.ResetToBaseValue( updateBufferIndex );
211 mDirtyFlags = NothingFlag;
214 bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const
216 if( !IsVisible( updateBufferIndex ) )
221 Node* parent = mParent;
223 while( NULL != parent )
225 if( !parent->IsVisible( updateBufferIndex ) )
230 parent = parent->GetParent();
236 void Node::SetParent(Node& parentNode)
238 DALI_ASSERT_ALWAYS(this != &parentNode);
239 DALI_ASSERT_ALWAYS(!mIsRoot);
240 DALI_ASSERT_ALWAYS(mParent == NULL);
242 mParent = &parentNode;
245 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
247 DALI_ASSERT_ALWAYS(!mIsRoot);
248 DALI_ASSERT_ALWAYS(mParent != NULL);
250 const NodeIter endIter = mChildren.End();
251 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
253 (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
256 // Animators, Constraints etc. should be disconnected from the child's properties.
257 PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
259 // Remove back-pointer to parent
262 // Remove all child pointers
265 // Move into disconnectedNodes
266 std::set<Node*>::size_type removed = connectedNodes.erase( this );
267 DALI_ASSERT_ALWAYS( removed );
268 disconnectedNodes.insert( this );
271 } // namespace SceneGraph
273 } // namespace Internal