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 childNode->ConnectToSceneGraph();
130 void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
132 DALI_ASSERT_ALWAYS( this != &childNode );
133 DALI_ASSERT_ALWAYS( childNode.GetParent() == this );
135 // Find the childNode and remove it
138 const NodeIter endIter = mChildren.End();
139 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
141 Node* current = *iter;
142 if ( current == &childNode )
145 mChildren.Erase( iter ); // order matters here
146 break; // iter is no longer valid
149 DALI_ASSERT_ALWAYS( NULL != found );
151 found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
154 int Node::GetDirtyFlags() const
156 // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already
157 int flags = mDirtyFlags;
158 const bool sizeFlag = mSize.IsClean();
160 if ( !(flags & TransformFlag) )
162 // Check whether the transform related properties have changed
164 !mPosition.IsClean() ||
165 !mOrientation.IsClean() ||
167 mParentOrigin.InputChanged() || // parent origin and anchor point rarely change
168 mAnchorPoint.InputChanged() )
170 flags |= TransformFlag;
174 // Check whether the visible property has changed
175 if ( !mVisible.IsClean() )
177 flags |= VisibleFlag;
180 // Check whether the color property has changed
181 if ( !mColor.IsClean() )
186 // Check whether the size property has changed
195 void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
197 // clear dirty flags in parent origin & anchor point
198 mParentOrigin.Clear();
199 mAnchorPoint.Clear();
200 // Reset default properties
201 mSize.ResetToBaseValue( updateBufferIndex );
202 mPosition.ResetToBaseValue( updateBufferIndex );
203 mOrientation.ResetToBaseValue( updateBufferIndex );
204 mScale.ResetToBaseValue( updateBufferIndex );
205 mVisible.ResetToBaseValue( updateBufferIndex );
206 mColor.ResetToBaseValue( updateBufferIndex );
208 mDirtyFlags = NothingFlag;
211 bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const
213 if( !IsVisible( updateBufferIndex ) )
218 Node* parent = mParent;
220 while( NULL != parent )
222 if( !parent->IsVisible( updateBufferIndex ) )
227 parent = parent->GetParent();
233 void Node::SetParent(Node& parentNode)
235 DALI_ASSERT_ALWAYS(this != &parentNode);
236 DALI_ASSERT_ALWAYS(!mIsRoot);
237 DALI_ASSERT_ALWAYS(mParent == NULL);
239 mParent = &parentNode;
242 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
244 DALI_ASSERT_ALWAYS(!mIsRoot);
245 DALI_ASSERT_ALWAYS(mParent != NULL);
247 const NodeIter endIter = mChildren.End();
248 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
250 (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
253 // Animators, Constraints etc. should be disconnected from the child's properties.
254 PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
256 // Remove back-pointer to parent
259 // Remove all child pointers
262 // Move into disconnectedNodes
263 std::set<Node*>::size_type removed = connectedNodes.erase( this );
264 DALI_ASSERT_ALWAYS( removed );
265 disconnectedNodes.insert( this );
268 } // namespace SceneGraph
270 } // namespace Internal