_transform_dirty = true;
return;
}
- else if( StyleSetter const* setter =
- getStyleSetter(child->getNameString()) )
+ else if( StyleInfo const* style = getStyleInfo(child->getNameString()) )
{
- setStyle(getParentStyle(child), setter);
- return;
+ if( setStyle(getParentStyle(child), style) )
+ return;
}
}
if( parent == _node )
{
const std::string& name = child->getNameString();
- if( StyleSetter const* setter = getStyleSetter(name) )
+ if( StyleInfo const* style_info = getStyleInfo(name) )
{
SGPropertyNode const* style = child;
if( isStyleEmpty(child) )
child->clearValue();
style = getParentStyle(child);
}
- setStyle(style, setter);
+ setStyle(style, style_info);
return;
}
else if( name == "update" )
//----------------------------------------------------------------------------
bool Element::setStyle( const SGPropertyNode* child,
- const StyleSetter* setter )
+ const StyleInfo* style_info )
{
- return canApplyStyle(child) && setStyleImpl(child, setter);
+ return canApplyStyle(child) && setStyleImpl(child, style_info);
}
//----------------------------------------------------------------------------
if( !isInit<Element>() )
{
- addStyle("clip", "", &Element::setClip);
+ addStyle("clip", "", &Element::setClip, false);
}
}
//----------------------------------------------------------------------------
bool Element::setStyleImpl( const SGPropertyNode* child,
- const StyleSetter* setter )
+ const StyleInfo* style_info )
{
- const StyleSetter* style_setter = setter
- ? setter
+ const StyleSetter* style_setter = style_info
+ ? &style_info->setter
: getStyleSetter(child->getNameString());
while( style_setter )
{
}
//----------------------------------------------------------------------------
- const Element::StyleSetter*
- Element::getStyleSetter(const std::string& name) const
+ const Element::StyleInfo*
+ Element::getStyleInfo(const std::string& name) const
{
StyleSetters::const_iterator setter = _style_setters.find(name);
if( setter == _style_setters.end() )
return 0;
- return &setter->second.setter;
+ return &setter->second;
+ }
+
+ //----------------------------------------------------------------------------
+ const Element::StyleSetter*
+ Element::getStyleSetter(const std::string& name) const
+ {
+ const StyleInfo* info = getStyleInfo(name);
+ return info ? &info->setter : 0;
}
//----------------------------------------------------------------------------
{
StyleSetter setter; ///!< Function(s) for setting this style
std::string type; ///!< Interpolation type
+ bool inheritable; ///!< Whether children can inherit this style from
+ /// their parents
};
/**
virtual void valueChanged(SGPropertyNode * child);
virtual bool setStyle( const SGPropertyNode* child,
- const StyleSetter* setter = 0 );
+ const StyleInfo* style_info = 0 );
/**
* Set clipping shape
StyleSetter
addStyle( const std::string& name,
const std::string& type,
- const boost::function<void (Derived&, T2)>& setter )
+ const boost::function<void (Derived&, T2)>& setter,
+ bool inheritable = true )
{
StyleInfo& style_info = _style_setters[ name ];
if( !type.empty() )
style_info.type = type;
}
+ // TODO check if changed?
+ style_info.inheritable = inheritable;
StyleSetter* style = &style_info.setter;
while( style->next )
StyleSetter
addStyle( const std::string& name,
const std::string& type,
- const boost::function<void (Derived&, T)>& setter )
+ const boost::function<void (Derived&, T)>& setter,
+ bool inheritable = true )
{
- return addStyle<T, T>(name, type, setter);
+ return addStyle<T, T>(name, type, setter, inheritable);
}
template<
StyleSetter
addStyle( const std::string& name,
const std::string& type,
- void (Derived::*setter)(T) )
+ void (Derived::*setter)(T),
+ bool inheritable = true )
{
return addStyle<T, T>
(
name,
type,
- boost::function<void (Derived&, T)>(setter)
+ boost::function<void (Derived&, T)>(setter),
+ inheritable
);
}
StyleSetterFunc
addStyle( const std::string& name,
const std::string& type,
- void (Derived::*setter)(T2) )
+ void (Derived::*setter)(T2),
+ bool inheritable = true )
{
return addStyle<T1>
(
name,
type,
- boost::function<void (Derived&, T2)>(setter)
+ boost::function<void (Derived&, T2)>(setter),
+ inheritable
);
}
StyleSetter
addStyle( const std::string& name,
const std::string& type,
- void (Derived::*setter)(const std::string&) )
+ void (Derived::*setter)(const std::string&),
+ bool inheritable = true )
{
return addStyle<const char*, const std::string&>
(
name,
type,
- boost::function<void (Derived&, const std::string&)>(setter)
+ boost::function<void (Derived&, const std::string&)>(setter),
+ inheritable
);
}
addStyle( const std::string& name,
const std::string& type,
void (Other::*setter)(T),
- OtherRef Derived::*instance_ref )
+ OtherRef Derived::*instance_ref,
+ bool inheritable = true )
{
- return addStyle<T, T>(name, type, bindOther(setter, instance_ref));
+ return addStyle<T, T>
+ (
+ name,
+ type,
+ bindOther(setter, instance_ref),
+ inheritable
+ );
}
template<
addStyle( const std::string& name,
const std::string& type,
void (Other::*setter)(T2),
- OtherRef Derived::*instance_ref )
+ OtherRef Derived::*instance_ref,
+ bool inheritable = true )
{
- return addStyle<T1>(name, type, bindOther(setter, instance_ref));
+ return addStyle<T1>
+ (
+ name,
+ type,
+ bindOther(setter, instance_ref),
+ inheritable
+ );
}
template<
addStyle( const std::string& name,
const std::string& type,
const boost::function<void (Other&, T2)>& setter,
- OtherRef Derived::*instance_ref )
+ OtherRef Derived::*instance_ref,
+ bool inheritable = true )
{
- return addStyle<T1>(name, type, bindOther(setter, instance_ref));
+ return addStyle<T1>
+ (
+ name,
+ type,
+ bindOther(setter, instance_ref),
+ inheritable
+ );
}
template<
addStyle( const std::string& name,
const std::string& type,
void (Other::*setter)(const std::string&),
- OtherRef Derived::*instance_ref )
+ OtherRef Derived::*instance_ref,
+ bool inheritable = true )
{
return addStyle<const char*, const std::string&>
(
name,
type,
boost::function<void (Other&, const std::string&)>(setter),
- instance_ref
+ instance_ref,
+ inheritable
);
}
bool isStyleEmpty(const SGPropertyNode* child) const;
bool canApplyStyle(const SGPropertyNode* child) const;
bool setStyleImpl( const SGPropertyNode* child,
- const StyleSetter* setter = 0 );
+ const StyleInfo* style_info = 0 );
+ const StyleInfo* getStyleInfo(const std::string& name) const;
const StyleSetter* getStyleSetter(const std::string& name) const;
const SGPropertyNode* getParentStyle(const SGPropertyNode* child) const;
//----------------------------------------------------------------------------
bool Group::setStyle( const SGPropertyNode* style,
- const StyleSetter* setter )
+ const StyleInfo* style_info )
{
if( !canApplyStyle(style) )
return false;
- // Don't propagate styles directly applicable to this group
- if( setStyleImpl(style, setter) )
- return true;
-
- bool handled = false;
- for(size_t i = 0; i < _transform->getNumChildren(); ++i)
+ bool handled = setStyleImpl(style, style_info);
+ if( style_info->inheritable )
{
- if( getChildByIndex(i)->setStyle(style, setter) )
- handled = true;
+ for(size_t i = 0; i < _transform->getNumChildren(); ++i)
+ handled |= getChildByIndex(i)->setStyle(style, style_info);
}
return handled;
return;
}
- if( !Element::setStyle(child) )
- {
- // Only add style if not applicable to group itself
+ StyleInfo const* style = getStyleInfo(child->getNameString());
+ if( style && style->inheritable )
_style[ child->getNameString() ] = child;
- setStyle(child);
- }
}
//----------------------------------------------------------------------------
}
else
{
- Style::iterator style = _style.find(node->getNameString());
- if( style != _style.end() )
- _style.erase(style);
+ _style.erase( node->getNameString() );
}
}