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 );
38 const SizeMode Node::DEFAULT_SIZE_MODE( USE_OWN_SIZE );
46 : mParentOrigin( ParentOrigin::DEFAULT ),
47 mAnchorPoint( AnchorPoint::DEFAULT ),
48 mSize(), // zero initialized by default
49 mPosition(), // zero initialized by default
50 mOrientation(), // initialized to identity by default
51 mScale( Vector3::ONE ),
53 mColor( Color::WHITE ),
54 mWorldPosition(), // zero initialized by default
55 mWorldOrientation(), // initialized to identity by default
56 mWorldScale( Vector3::ONE ),
58 mWorldColor( Color::WHITE ),
60 mExclusiveRenderTask( NULL ),
63 mGeometryScale( Vector3::ONE ),
64 mInitialVolume( Vector3::ONE ),
65 mSizeModeFactor( Vector3::ONE ),
66 mDirtyFlags(AllFlags),
68 mInheritOrientation( true ),
69 mInheritScale( true ),
70 mTransmitGeometryScaling( false ),
71 mInhibitLocalTransform( false ),
73 mDrawMode( DrawMode::NORMAL ),
74 mPositionInheritanceMode( DEFAULT_POSITION_INHERITANCE_MODE ),
75 mColorMode( DEFAULT_COLOR_MODE ),
76 mSizeMode( DEFAULT_SIZE_MODE )
84 void Node::OnDestroy()
86 // Node attachments should be notified about the disconnection.
89 mAttachment->OnDestroy();
92 // Animators, Constraints etc. should be disconnected from the child's properties.
93 PropertyOwner::Destroy();
96 void Node::Attach( NodeAttachment& object )
98 DALI_ASSERT_DEBUG(!mAttachment);
100 object.SetParent(*this);
102 mAttachment = &object;
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 childNode->ConnectToSceneGraph();
136 void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
138 DALI_ASSERT_ALWAYS( this != &childNode );
139 DALI_ASSERT_ALWAYS( childNode.GetParent() == this );
141 // Find the childNode and remove it
144 const NodeIter endIter = mChildren.End();
145 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
147 Node* current = *iter;
148 if ( current == &childNode )
151 mChildren.Erase( iter ); // order matters here
152 break; // iter is no longer valid
155 DALI_ASSERT_ALWAYS( NULL != found );
157 found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
160 int Node::GetDirtyFlags() const
162 // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already
163 int flags = mDirtyFlags;
164 const bool sizeFlag = mSize.IsClean();
166 if ( !(flags & TransformFlag) )
168 // Check whether the transform related properties have changed
170 !mPosition.IsClean() ||
171 !mOrientation.IsClean() ||
173 mParentOrigin.InputChanged() || // parent origin and anchor point rarely change
174 mAnchorPoint.InputChanged() )
176 flags |= TransformFlag;
180 // Check whether the visible property has changed
181 if ( !mVisible.IsClean() )
183 flags |= VisibleFlag;
186 // Check whether the color property has changed
187 if ( !mColor.IsClean() )
192 // Check whether the size property has changed
201 void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
203 // clear dirty flags in parent origin & anchor point
204 mParentOrigin.Clear();
205 mAnchorPoint.Clear();
206 // Reset default properties
207 mSize.ResetToBaseValue( updateBufferIndex );
208 mPosition.ResetToBaseValue( updateBufferIndex );
209 mOrientation.ResetToBaseValue( updateBufferIndex );
210 mScale.ResetToBaseValue( updateBufferIndex );
211 mVisible.ResetToBaseValue( updateBufferIndex );
212 mColor.ResetToBaseValue( updateBufferIndex );
214 mDirtyFlags = NothingFlag;
217 bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const
219 if( !IsVisible( updateBufferIndex ) )
224 Node* parent = mParent;
226 while( NULL != parent )
228 if( !parent->IsVisible( updateBufferIndex ) )
233 parent = parent->GetParent();
239 void Node::SetParent(Node& parentNode)
241 DALI_ASSERT_ALWAYS(this != &parentNode);
242 DALI_ASSERT_ALWAYS(!mIsRoot);
243 DALI_ASSERT_ALWAYS(mParent == NULL);
245 mParent = &parentNode;
248 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
250 DALI_ASSERT_ALWAYS(!mIsRoot);
251 DALI_ASSERT_ALWAYS(mParent != NULL);
253 const NodeIter endIter = mChildren.End();
254 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
256 (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
259 // Animators, Constraints etc. should be disconnected from the child's properties.
260 PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
262 // Remove back-pointer to parent
265 // Remove all child pointers
268 // Move into disconnectedNodes
269 std::set<Node*>::size_type removed = connectedNodes.erase( this );
270 DALI_ASSERT_ALWAYS( removed );
271 disconnectedNodes.insert( this );
274 } // namespace SceneGraph
276 } // namespace Internal