Changed draw ordering to take into account the depth of the node in the hierarchy
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node.cpp
index 45004b5..db5798f 100644 (file)
@@ -44,28 +44,26 @@ Node* Node::New()
 Node::Node()
 : mParentOrigin( ParentOrigin::DEFAULT ),
   mAnchorPoint( AnchorPoint::DEFAULT ),
-  mSize( Vector3::ZERO ),
-  mPosition( Vector3::ZERO ),
-  mRotation( Quaternion::IDENTITY ),
+  mSize(),     // zero initialized by default
+  mPosition(), // zero initialized by default
+  mOrientation(), // initialized to identity by default
   mScale( Vector3::ONE ),
   mVisible( true ),
   mColor( Color::WHITE ),
-  mWorldPosition( Vector3::ZERO ),
-  mWorldRotation( Quaternion::IDENTITY ),
+  mWorldPosition(), // zero initialized by default
+  mWorldOrientation(), // initialized to identity by default
   mWorldScale( Vector3::ONE ),
-  mWorldMatrix( Matrix::IDENTITY ),
+  mWorldMatrix(),
   mWorldColor( Color::WHITE ),
   mParent( NULL ),
   mExclusiveRenderTask( NULL ),
   mAttachment( NULL ),
   mChildren(),
-  mGeometryScale( Vector3::ONE ),
-  mInitialVolume( Vector3::ONE ),
+  mDepth(0u),
   mDirtyFlags(AllFlags),
   mIsRoot( false ),
-  mInheritRotation( true ),
+  mInheritOrientation( true ),
   mInheritScale( true ),
-  mTransmitGeometryScaling( false ),
   mInhibitLocalTransform( false ),
   mIsActive( true ),
   mDrawMode( DrawMode::NORMAL ),
@@ -87,7 +85,7 @@ void Node::OnDestroy()
   }
 
   // Animators, Constraints etc. should be disconnected from the child's properties.
-  PropertyOwner::DisconnectFromSceneGraph();
+  PropertyOwner::Destroy();
 }
 
 void Node::Attach( NodeAttachment& object )
@@ -98,6 +96,11 @@ void Node::Attach( NodeAttachment& object )
 
   mAttachment = &object;
   SetAllDirtyFlags();
+
+  if( mIsActive )
+  {
+    mAttachment->ConnectedToSceneGraph();
+  }
 }
 
 void Node::SetRoot(bool isRoot)
@@ -126,6 +129,15 @@ void Node::ConnectChild( Node* childNode, int index )
   {
     mChildren.Insert(mChildren.Begin()+index, childNode);
   }
+
+  // Inform property observers of new connection
+  childNode->ConnectToSceneGraph();
+
+  // Inform child node attachment that the node has been added to the stage
+  if( childNode->mAttachment )
+  {
+    childNode->mAttachment->ConnectedToSceneGraph();
+  }
 }
 
 void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes,  std::set<Node*>& disconnectedNodes )
@@ -163,7 +175,7 @@ int Node::GetDirtyFlags() const
     // Check whether the transform related properties have changed
     if( !sizeFlag            ||
         !mPosition.IsClean() ||
-        !mRotation.IsClean() ||
+        !mOrientation.IsClean() ||
         !mScale.IsClean()    ||
         mParentOrigin.InputChanged() || // parent origin and anchor point rarely change
         mAnchorPoint.InputChanged() )
@@ -201,7 +213,7 @@ void Node::ResetDefaultProperties( BufferIndex updateBufferIndex )
   // Reset default properties
   mSize.ResetToBaseValue( updateBufferIndex );
   mPosition.ResetToBaseValue( updateBufferIndex );
-  mRotation.ResetToBaseValue( updateBufferIndex );
+  mOrientation.ResetToBaseValue( updateBufferIndex );
   mScale.ResetToBaseValue( updateBufferIndex );
   mVisible.ResetToBaseValue( updateBufferIndex );
   mColor.ResetToBaseValue( updateBufferIndex );
@@ -238,6 +250,7 @@ void Node::SetParent(Node& parentNode)
   DALI_ASSERT_ALWAYS(mParent == NULL);
 
   mParent = &parentNode;
+  mDepth = mParent->GetDepth() + 1u;
 }
 
 void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes,  std::set<Node*>& disconnectedNodes )
@@ -252,14 +265,21 @@ void Node::RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std
   }
 
   // Animators, Constraints etc. should be disconnected from the child's properties.
-  PropertyOwner::DisconnectFromSceneGraph();
+  PropertyOwner::DisconnectFromSceneGraph( updateBufferIndex );
 
   // Remove back-pointer to parent
   mParent = NULL;
+  mDepth = 0u;
 
   // Remove all child pointers
   mChildren.Clear();
 
+  // Inform child node attachment that the node has been removed from the stage
+  if( mAttachment )
+  {
+    mAttachment->DisconnectedFromSceneGraph();
+  }
+
   // Move into disconnectedNodes
   std::set<Node*>::size_type removed = connectedNodes.erase( this );
   DALI_ASSERT_ALWAYS( removed );