From: Thomas Geymayer Date: Thu, 6 Dec 2012 10:33:51 +0000 (+0100) Subject: Canvas: Propagate style changes on groups to children X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d06d94c7672b511ae989d3c85be1389682d3ed51;p=simgear.git Canvas: Propagate style changes on groups to children --- diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index 0ca940d1..b20fbd4b 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -297,6 +297,18 @@ namespace canvas childChanged(child); } + //---------------------------------------------------------------------------- + bool Element::setStyle(const SGPropertyNode* child) + { + StyleSetters::const_iterator setter = + _style_setters.find(child->getNameString()); + if( setter == _style_setters.end() ) + return false; + + setter->second(child); + return true; + } + //---------------------------------------------------------------------------- void Element::setBoundingBox(const osg::BoundingBox& bb) { @@ -364,17 +376,5 @@ namespace canvas setStyle(style.second); } - //---------------------------------------------------------------------------- - bool Element::setStyle(const SGPropertyNode* child) - { - StyleSetters::const_iterator setter = - _style_setters.find(child->getNameString()); - if( setter == _style_setters.end() ) - return false; - - setter->second(child); - return true; - } - } // namespace canvas } // namespace simgear diff --git a/simgear/canvas/elements/CanvasElement.hxx b/simgear/canvas/elements/CanvasElement.hxx index 9067c729..0d70390e 100644 --- a/simgear/canvas/elements/CanvasElement.hxx +++ b/simgear/canvas/elements/CanvasElement.hxx @@ -91,6 +91,8 @@ namespace canvas SGPropertyNode * child ); virtual void valueChanged(SGPropertyNode * child); + virtual bool setStyle(const SGPropertyNode* child); + /** * Write the given bounding box to the property tree */ @@ -182,7 +184,6 @@ namespace canvas void setDrawable(osg::Drawable* drawable); void setupStyle(); - bool setStyle(const SGPropertyNode* child); private: diff --git a/simgear/canvas/elements/CanvasGroup.cxx b/simgear/canvas/elements/CanvasGroup.cxx index e8158edf..176af793 100644 --- a/simgear/canvas/elements/CanvasGroup.cxx +++ b/simgear/canvas/elements/CanvasGroup.cxx @@ -132,6 +132,23 @@ namespace canvas return false; } + //---------------------------------------------------------------------------- + bool Group::setStyle(const SGPropertyNode* style) + { + 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 { @@ -174,6 +191,7 @@ namespace canvas } _style[ child->getNameString() ] = child; + setStyle(child); } //---------------------------------------------------------------------------- diff --git a/simgear/canvas/elements/CanvasGroup.hxx b/simgear/canvas/elements/CanvasGroup.hxx index 02ea7e8b..cd9c0bfd 100644 --- a/simgear/canvas/elements/CanvasGroup.hxx +++ b/simgear/canvas/elements/CanvasGroup.hxx @@ -58,6 +58,8 @@ namespace canvas virtual bool traverse(EventVisitor& visitor); + virtual bool setStyle(const SGPropertyNode* child); + virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const; protected: