X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fcanvas%2Felements%2FCanvasGroup.cxx;h=9bfb8c2f26d3df44be309cc8815c591423dde953;hb=1f431323635de0dd86d60a0fc58efa9557983ef8;hp=0740026828c721d9146eeba92e56ea6a3e793514;hpb=8816d0a9ac5c33c7c911714978c91f732dc0bb42;p=simgear.git diff --git a/simgear/canvas/elements/CanvasGroup.cxx b/simgear/canvas/elements/CanvasGroup.cxx index 07400268..9bfb8c2f 100644 --- a/simgear/canvas/elements/CanvasGroup.cxx +++ b/simgear/canvas/elements/CanvasGroup.cxx @@ -41,9 +41,14 @@ namespace canvas const Style& style, Element* parent ) { - return ElementPtr( new T(canvas, node, style, parent) ); + ElementPtr el( new T(canvas, node, style, parent) ); + el->setSelf(el); + return el; } + //---------------------------------------------------------------------------- + ElementFactories Group::_child_factories; + //---------------------------------------------------------------------------- Group::Group( const CanvasWeakPtr& canvas, const SGPropertyNode_ptr& node, @@ -51,11 +56,14 @@ namespace canvas Element* parent ): Element(canvas, node, parent_style, parent) { - _child_factories["group"] = &createElement; - _child_factories["image"] = &createElement; - _child_factories["map" ] = &createElement; - _child_factories["path" ] = &createElement; - _child_factories["text" ] = &createElement; + if( !isInit() ) + { + _child_factories["group"] = &createElement; + _child_factories["image"] = &createElement; + _child_factories["map" ] = &createElement; + _child_factories["path" ] = &createElement; + _child_factories["text" ] = &createElement; + } } //---------------------------------------------------------------------------- @@ -132,13 +140,56 @@ namespace canvas return false; } + //---------------------------------------------------------------------------- + bool Group::setStyle(const SGPropertyNode* style) + { + // Don't propagate styles directly applicable to this group + if( Element::setStyle(style) ) + return true; + + if( style->getParent() != _node + && _style.find(style->getNameString()) != _style.end() ) + return false; + + bool handled = false; + BOOST_FOREACH( ChildList::value_type child, _children ) + { + if( child.second->setStyle(style) ) + handled = true; + } + + return handled; + } + + //---------------------------------------------------------------------------- + osg::BoundingBox Group::getTransformedBounds(const osg::Matrix& m) const + { + osg::BoundingBox bb; + + BOOST_FOREACH( ChildList::value_type child, _children ) + { + if( !child.second->getMatrixTransform()->getNodeMask() ) + continue; + + bb.expandBy + ( + child.second->getTransformedBounds + ( + child.second->getMatrixTransform()->getMatrix() * m + ) + ); + } + + return bb; + } + //---------------------------------------------------------------------------- void Group::childAdded(SGPropertyNode* child) { if( child->getParent() != _node ) return; - ChildFactories::iterator child_factory = + ElementFactories::iterator child_factory = _child_factories.find( child->getNameString() ); if( child_factory != _child_factories.end() ) { @@ -148,10 +199,18 @@ namespace canvas _transform->addChild( element->getMatrixTransform() ); _children.push_back( ChildList::value_type(child, element) ); + // ...and ensure correct ordering + handleZIndexChanged( --_children.end() ); + return; } - _style[ child->getNameString() ] = child; + if( !Element::setStyle(child) ) + { + // Only add style if not applicable to group itself + _style[ child->getNameString() ] = child; + setStyle(child); + } } //---------------------------------------------------------------------------- @@ -189,13 +248,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;