_style( parent_style ),
_drawable( 0 )
{
+ staticInit();
+
SG_LOG
(
SG_GL,
"New canvas element " << node->getPath()
);
- if( !isInit<Element>() )
- {
- addStyle("clip", "", &Element::setClip, false);
- }
-
// Ensure elements are drawn in order they appear in the element tree
_transform->getOrCreateStateSet()
->setRenderBinDetails
);
}
+ //----------------------------------------------------------------------------
+ void Element::staticInit()
+ {
+ if( isInit<Element>() )
+ return;
+
+ addStyle("clip", "", &Element::setClip, false);
+ }
+
//----------------------------------------------------------------------------
bool Element::isStyleEmpty(const SGPropertyNode* child) const
{
typedef std::map<std::string, StyleInfo> StyleSetters;
static StyleSetters _style_setters;
+ static void staticInit();
+
Element( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
const Style& parent_style,
* @tparam Derived (Derived) class type
*/
template<class Derived>
- bool isInit() const
+ static bool isInit()
{
static bool is_init = false;
if( is_init )
typename T2,
class Derived
>
+ static
StyleSetter
addStyle( const std::string& name,
const std::string& type,
typename T,
class Derived
>
+ static
StyleSetter
addStyle( const std::string& name,
const std::string& type,
typename T,
class Derived
>
+ static
StyleSetter
addStyle( const std::string& name,
const std::string& type,
typename T2,
class Derived
>
+ static
StyleSetterFunc
addStyle( const std::string& name,
const std::string& type,
template<
class Derived
>
+ static
StyleSetter
addStyle( const std::string& name,
const std::string& type,
class Other,
class OtherRef
>
+ static
StyleSetter
addStyle( const std::string& name,
const std::string& type,
class Other,
class OtherRef
>
+ static
StyleSetter
addStyle( const std::string& name,
const std::string& type,
class Other,
class OtherRef
>
+ static
StyleSetter
addStyle( const std::string& name,
const std::string& type,
class Other,
class OtherRef
>
+ static
StyleSetter
addStyle( const std::string& name,
const std::string& type,
}
template<typename T, class Derived, class Other, class OtherRef>
+ static
boost::function<void (Derived&, T)>
bindOther( void (Other::*setter)(T), OtherRef Derived::*instance_ref )
{
}
template<typename T, class Derived, class Other, class OtherRef>
+ static
boost::function<void (Derived&, T)>
bindOther( const boost::function<void (Other&, T)>& setter,
OtherRef Derived::*instance_ref )
}
template<typename T1, typename T2, class Derived>
+ static
StyleSetterFuncUnchecked
bindStyleSetter( const std::string& name,
const boost::function<void (Derived&, T2)>& setter )
template<typename ElementType>
void add(ElementFactories& factories)
{
+ ElementType::staticInit();
factories[ElementType::TYPE_NAME] = &Element::create<ElementType>;
}
"canvas::Group::" << member_name << ": Group has expired." );
}
+ //----------------------------------------------------------------------------
+ void Group::staticInit()
+ {
+ if( isInit<Group>() )
+ return;
+
+ add<Group>(_child_factories);
+ add<Image>(_child_factories);
+ add<Map >(_child_factories);
+ add<Path >(_child_factories);
+ add<Text >(_child_factories);
+ }
+
//----------------------------------------------------------------------------
Group::Group( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
Element* parent ):
Element(canvas, node, parent_style, parent)
{
- if( !isInit<Group>() )
- {
- add<Group>(_child_factories);
- add<Image>(_child_factories);
- add<Map >(_child_factories);
- add<Path >(_child_factories);
- add<Text >(_child_factories);
- }
+ staticInit();
}
//----------------------------------------------------------------------------
{
public:
static const std::string TYPE_NAME;
+ static void staticInit();
typedef std::list< std::pair< const SGPropertyNode*,
ElementPtr
//----------------------------------------------------------------------------
const std::string Image::TYPE_NAME = "image";
+ //----------------------------------------------------------------------------
+ void Image::staticInit()
+ {
+ if( isInit<Image>() )
+ return;
+
+ addStyle("fill", "color", &Image::setFill);
+ addStyle("slice", "", &Image::setSlice);
+ addStyle("slice-width", "", &Image::setSliceWidth);
+ addStyle("outset", "", &Image::setOutset);
+ }
+
//----------------------------------------------------------------------------
Image::Image( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
_src_rect(0,0),
_region(0,0)
{
+ staticInit();
+
_geom = new osg::Geometry;
_geom->setUseDisplayList(false);
setDrawable(_geom);
- if( !isInit<Image>() )
- {
- addStyle("fill", "color", &Image::setFill);
- addStyle("slice", "", &Image::setSlice);
- addStyle("slice-width", "", &Image::setSliceWidth);
- addStyle("outset", "", &Image::setOutset);
- }
-
setFill("#ffffff"); // TODO how should we handle default values?
-
setupStyle();
}
{
public:
static const std::string TYPE_NAME;
+ static void staticInit();
/**
* @param node Property node containing settings for this image:
const std::string GEO = "-geo";
const std::string Map::TYPE_NAME = "map";
+ //----------------------------------------------------------------------------
+ void Map::staticInit()
+ {
+ Group::staticInit();
+
+ if( isInit<Map>() )
+ return;
+
+ // Do some initialization if needed...
+ }
+
//----------------------------------------------------------------------------
Map::Map( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
_projection(new SansonFlamsteedProjection),
_projection_dirty(true)
{
-
+ staticInit();
}
//----------------------------------------------------------------------------
{
public:
static const std::string TYPE_NAME;
+ static void staticInit();
Map( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
//----------------------------------------------------------------------------
const std::string Path::TYPE_NAME = "path";
+ //----------------------------------------------------------------------------
+ void Path::staticInit()
+ {
+ if( isInit<Path>() )
+ return;
+
+ PathDrawableRef Path::*path = &Path::_path;
+
+ addStyle("fill", "color", &PathDrawable::setFill, path);
+ addStyle("fill-rule", "", &PathDrawable::setFillRule, path);
+ addStyle("stroke", "color", &PathDrawable::setStroke, path);
+ addStyle("stroke-width", "numeric", &PathDrawable::setStrokeWidth, path);
+ addStyle("stroke-dasharray", "", &PathDrawable::setStrokeDashArray, path);
+ addStyle("stroke-linecap", "", &PathDrawable::setStrokeLinecap, path);
+ }
+
//----------------------------------------------------------------------------
Path::Path( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
Element(canvas, node, parent_style, parent),
_path( new PathDrawable(this) )
{
- setDrawable(_path);
-
- if( !isInit<Path>() )
- {
- PathDrawableRef Path::*path = &Path::_path;
-
- addStyle("fill", "color", &PathDrawable::setFill, path);
- addStyle("fill-rule", "", &PathDrawable::setFillRule, path);
- addStyle("stroke", "color", &PathDrawable::setStroke, path);
- addStyle("stroke-width", "numeric", &PathDrawable::setStrokeWidth, path);
- addStyle("stroke-dasharray", "", &PathDrawable::setStrokeDashArray, path);
- addStyle("stroke-linecap", "", &PathDrawable::setStrokeLinecap, path);
- }
+ staticInit();
+ setDrawable(_path);
setupStyle();
}
{
public:
static const std::string TYPE_NAME;
+ static void staticInit();
Path( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
//----------------------------------------------------------------------------
const std::string Text::TYPE_NAME = "text";
+ //----------------------------------------------------------------------------
+ void Text::staticInit()
+ {
+ if( isInit<Text>() )
+ return;
+
+ osg::ref_ptr<TextOSG> Text::*text = &Text::_text;
+
+ addStyle("fill", "color", &TextOSG::setFill, text);
+ addStyle("background", "color", &TextOSG::setBackgroundColor, text);
+ addStyle("character-size",
+ "numeric",
+ static_cast<
+ void (TextOSG::*)(float)
+ > (&TextOSG::setCharacterSize),
+ text);
+ addStyle("character-aspect-ratio",
+ "numeric",
+ &TextOSG::setCharacterAspect, text);
+ addStyle("line-height", "numeric", &TextOSG::setLineHeight, text);
+ addStyle("font-resolution", "numeric", &TextOSG::setFontResolution, text);
+ addStyle("padding", "numeric", &TextOSG::setBoundingBoxMargin, text);
+ // TEXT = 1 default
+ // BOUNDINGBOX = 2
+ // FILLEDBOUNDINGBOX = 4
+ // ALIGNMENT = 8
+ addStyle<int>("draw-mode", "", &TextOSG::setDrawMode, text);
+ addStyle("max-width", "numeric", &TextOSG::setMaximumWidth, text);
+ addStyle("font", "", &Text::setFont);
+ addStyle("alignment", "", &Text::setAlignment);
+ addStyle("text", "", &Text::setText, false);
+ }
+
//----------------------------------------------------------------------------
Text::Text( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,
Element(canvas, node, parent_style, parent),
_text( new Text::TextOSG(this) )
{
+ staticInit();
+
setDrawable(_text);
_text->setCharacterSizeMode(osgText::Text::OBJECT_COORDS);
_text->setAxisAlignment(osgText::Text::USER_DEFINED_ROTATION);
_text->setRotation(osg::Quat(osg::PI, osg::X_AXIS));
- if( !isInit<Text>() )
- {
- osg::ref_ptr<TextOSG> Text::*text = &Text::_text;
-
- addStyle("fill", "color", &TextOSG::setFill, text);
- addStyle("background", "color", &TextOSG::setBackgroundColor, text);
- addStyle("character-size",
- "numeric",
- static_cast<
- void (TextOSG::*)(float)
- > (&TextOSG::setCharacterSize),
- text);
- addStyle("character-aspect-ratio",
- "numeric",
- &TextOSG::setCharacterAspect, text);
- addStyle("line-height", "numeric", &TextOSG::setLineHeight, text);
- addStyle("font-resolution", "numeric", &TextOSG::setFontResolution, text);
- addStyle("padding", "numeric", &TextOSG::setBoundingBoxMargin, text);
- // TEXT = 1 default
- // BOUNDINGBOX = 2
- // FILLEDBOUNDINGBOX = 4
- // ALIGNMENT = 8
- addStyle<int>("draw-mode", "", &TextOSG::setDrawMode, text);
- addStyle("max-width", "numeric", &TextOSG::setMaximumWidth, text);
- addStyle("font", "", &Text::setFont);
- addStyle("alignment", "", &Text::setAlignment);
- addStyle("text", "", &Text::setText, false);
- }
-
setupStyle();
}
{
public:
static const std::string TYPE_NAME;
+ static void staticInit();
Text( const CanvasWeakPtr& canvas,
const SGPropertyNode_ptr& node,