Canvas: Propagate style changes on groups to children

This commit is contained in:
Thomas Geymayer 2012-12-06 11:33:51 +01:00
parent 66786651b0
commit d06d94c767
4 changed files with 34 additions and 13 deletions

View File

@ -297,6 +297,18 @@ namespace canvas
childChanged(child); 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) void Element::setBoundingBox(const osg::BoundingBox& bb)
{ {
@ -364,17 +376,5 @@ namespace canvas
setStyle(style.second); 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 canvas
} // namespace simgear } // namespace simgear

View File

@ -91,6 +91,8 @@ namespace canvas
SGPropertyNode * child ); SGPropertyNode * child );
virtual void valueChanged(SGPropertyNode * child); virtual void valueChanged(SGPropertyNode * child);
virtual bool setStyle(const SGPropertyNode* child);
/** /**
* Write the given bounding box to the property tree * Write the given bounding box to the property tree
*/ */
@ -182,7 +184,6 @@ namespace canvas
void setDrawable(osg::Drawable* drawable); void setDrawable(osg::Drawable* drawable);
void setupStyle(); void setupStyle();
bool setStyle(const SGPropertyNode* child);
private: private:

View File

@ -132,6 +132,23 @@ namespace canvas
return false; 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 osg::BoundingBox Group::getTransformedBounds(const osg::Matrix& m) const
{ {
@ -174,6 +191,7 @@ namespace canvas
} }
_style[ child->getNameString() ] = child; _style[ child->getNameString() ] = child;
setStyle(child);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -58,6 +58,8 @@ namespace canvas
virtual bool traverse(EventVisitor& visitor); virtual bool traverse(EventVisitor& visitor);
virtual bool setStyle(const SGPropertyNode* child);
virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const; virtual osg::BoundingBox getTransformedBounds(const osg::Matrix& m) const;
protected: protected: