]> git.mxchange.org Git - simgear.git/commitdiff
Canvas: ensure z-index is updated on adding new child.
authorThomas Geymayer <tomgey@gmail.com>
Tue, 26 Feb 2013 11:47:53 +0000 (12:47 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Tue, 26 Feb 2013 11:49:04 +0000 (12:49 +0100)
simgear/canvas/elements/CanvasGroup.cxx
simgear/canvas/elements/CanvasGroup.hxx

index a65cb2cb5c8db49f64b4b2123403be2bba3978f4..8263b079f34c8ef7a7612b28ce5afa56578d6ffd 100644 (file)
@@ -193,6 +193,9 @@ namespace canvas
       _transform->addChild( element->getMatrixTransform() );
       _children.push_back( ChildList::value_type(child, element) );
 
+      // ...and ensure correct ordering
+      handleZIndexChanged( --_children.end() );
+
       return;
     }
 
@@ -239,13 +242,13 @@ namespace canvas
   {
     if(    node->getParent()->getParent() == _node
         && node->getNameString() == "z-index" )
-      return handleZIndexChanged(node->getParent(), node->getIntValue());
+      return handleZIndexChanged( findChild(node->getParent()),
+                                  node->getIntValue() );
   }
 
   //----------------------------------------------------------------------------
-  void Group::handleZIndexChanged(SGPropertyNode* node, int z_index)
+  void Group::handleZIndexChanged(ChildList::iterator child, int z_index)
   {
-    ChildList::iterator child = findChild(node);
     if( child == _children.end() )
       return;
 
index cd9c0bfdbbc22bfecb5f0f6e27bb9976d60ac227..7eec76642fd0a12892e2ed90cbbb15e0417fd2b9 100644 (file)
@@ -73,7 +73,7 @@ namespace canvas
       virtual void childRemoved(SGPropertyNode * child);
       virtual void childChanged(SGPropertyNode * child);
 
-      void handleZIndexChanged(SGPropertyNode* node, int z_index);
+      void handleZIndexChanged(ChildList::iterator child, int z_index = 0);
 
       ChildList::iterator findChild(const SGPropertyNode* node);
   };