From: Thomas Geymayer Date: Tue, 26 Feb 2013 11:47:53 +0000 (+0100) Subject: Canvas: ensure z-index is updated on adding new child. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=50de873453382ab2356bfa9456ef3911e26cae97;p=simgear.git Canvas: ensure z-index is updated on adding new child. --- diff --git a/simgear/canvas/elements/CanvasGroup.cxx b/simgear/canvas/elements/CanvasGroup.cxx index a65cb2cb..8263b079 100644 --- a/simgear/canvas/elements/CanvasGroup.cxx +++ b/simgear/canvas/elements/CanvasGroup.cxx @@ -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; diff --git a/simgear/canvas/elements/CanvasGroup.hxx b/simgear/canvas/elements/CanvasGroup.hxx index cd9c0bfd..7eec7664 100644 --- a/simgear/canvas/elements/CanvasGroup.hxx +++ b/simgear/canvas/elements/CanvasGroup.hxx @@ -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); };