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( Vector3::ZERO ),
48 mPosition( Vector3::ZERO ),
49 mRotation( Quaternion::IDENTITY ),
50 mScale( Vector3::ONE ),
52 mColor( Color::WHITE ),
53 mWorldPosition( Vector3::ZERO ),
54 mWorldRotation( Quaternion::IDENTITY ),
55 mWorldScale( Vector3::ONE ),
56 mWorldMatrix( Matrix::IDENTITY ),
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);
131 void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
133 DALI_ASSERT_ALWAYS( this != &childNode );
134 DALI_ASSERT_ALWAYS( childNode.GetParent() == this );
136 // Find the childNode and remove it
139 const NodeIter endIter = mChildren.End();
140 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
142 Node* current = *iter;
143 if ( current == &childNode )
146 mChildren.Erase( iter ); // order matters here
147 break; // iter is no longer valid
150 DALI_ASSERT_ALWAYS( NULL != found );
152 found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
155 int Node::GetDirtyFlags() const
157 // get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already
158 int flags = mDirtyFlags;
159 const bool sizeFlag = mSize.IsClean();
161 if ( !(flags & TransformFlag) )
163 // Check whether the transform related properties have changed
165 !mPosition.IsClean() ||
166 !mRotation.IsClean() ||
168 mParentOrigin.InputChanged() || // parent origin and anchor point rarely change
169 mAnchorPoint.InputChanged() )
171 flags |= TransformFlag;
175 // Check whether the visible property has changed
176 if ( !mVisible.IsClean() )
178 flags |= VisibleFlag;
181 // Check whether the color property has changed
182 if ( !mColor.IsClean() )
187 // Check whether the size property has changed
196 void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
198 // clear dirty flags in parent origin & anchor point
199 mParentOrigin.Clear();
200 mAnchorPoint.Clear();
201 // Reset default properties
202 mSize.ResetToBaseValue( updateBufferIndex );
203 mPosition.ResetToBaseValue( updateBufferIndex );
204 mRotation.ResetToBaseValue( updateBufferIndex );
205 mScale.ResetToBaseValue( updateBufferIndex );
206 mVisible.ResetToBaseValue( updateBufferIndex );
207 mColor.ResetToBaseValue( updateBufferIndex );
209 mDirtyFlags = NothingFlag;
212 bool Node::IsFullyVisible( BufferIndex updateBufferIndex ) const
214 if( !IsVisible( updateBufferIndex ) )
219 Node* parent = mParent;
221 while( NULL != parent )
223 if( !parent->IsVisible( updateBufferIndex ) )
228 parent = parent->GetParent();
234 void Node::SetParent(Node& parentNode)
236 DALI_ASSERT_ALWAYS(this != &parentNode);
237 DALI_ASSERT_ALWAYS(!mIsRoot);
238 DALI_ASSERT_ALWAYS(mParent == NULL);
240 mParent = &parentNode;
243 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes )
245 DALI_ASSERT_ALWAYS(!mIsRoot);
246 DALI_ASSERT_ALWAYS(mParent != NULL);
248 const NodeIter endIter = mChildren.End();
249 for ( NodeIter iter = mChildren.Begin(); iter != endIter; ++iter )
251 (*iter)->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
254 // Animators, Constraints etc. should be disconnected from the child's properties.
255 PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
257 // Remove back-pointer to parent
260 // Remove all child pointers
263 // Move into disconnectedNodes
264 std::set<Node*>::size_type removed = connectedNodes.erase( this );
265 DALI_ASSERT_ALWAYS( removed );
266 disconnectedNodes.insert( this );
269 } // namespace SceneGraph
271 } // namespace Internal