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 0dd87c1..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)
@@ -107,7 +110,7 @@ void Node::SetRoot(bool isRoot)
   mIsRoot = isRoot;
 }
 
-void Node::ConnectChild( Node* childNode )
+void Node::ConnectChild( Node* childNode, int index )
 {
   DALI_ASSERT_ALWAYS( this != childNode );
   DALI_ASSERT_ALWAYS( IsRoot() || NULL != mParent ); // Parent should be connected first
@@ -118,7 +121,23 @@ void Node::ConnectChild( Node* childNode )
   // Everything should be reinherited when reconnected to scene-graph
   childNode->SetAllDirtyFlags();
 
-  mChildren.PushBack( childNode );
+  if (index == -1)
+  {
+    mChildren.PushBack( childNode );
+  }
+  else
+  {
+    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 )
@@ -156,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() )
@@ -194,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 );
@@ -231,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 )
@@ -245,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 );