#include <simgear/canvas/Canvas.hxx>
#include <simgear/canvas/CanvasSystemAdapter.hxx>
#include <simgear/scene/util/parse_color.hxx>
-#include <simgear/structure/OSGVersion.hxx>
+#include <osg/Version>
#include <osgText/Text>
namespace simgear
TextOSG(canvas::Text* text);
- void setCharacterSize(float height);
+ void setFontResolution(int res);
void setCharacterAspect(float aspect);
+ void setLineHeight(float factor);
void setFill(const std::string& fill);
void setBackgroundColor(const std::string& fill);
Text::TextOSG::TextOSG(canvas::Text* text):
_text_element(text)
{
-
+ setBackdropImplementation(NO_DEPTH_BUFFER);
}
//----------------------------------------------------------------------------
- void Text::TextOSG::setCharacterSize(float height)
+ void Text::TextOSG::setFontResolution(int res)
{
- TextBase::setCharacterSize(height);
-
- unsigned int res = 32;
- CanvasPtr canvas = _text_element->_canvas.lock();
- if( canvas )
- {
- float factor = canvas->getSizeY() / canvas->getViewHeight();
- res = height * factor;
- }
-
- // TODO different vertical/horizontal resolution?
- // TODO configurable?
- setFontResolution(res, res);
+ TextBase::setFontResolution(res, res);
}
//----------------------------------------------------------------------------
void Text::TextOSG::setCharacterAspect(float aspect)
{
- TextBase::setCharacterSize(getCharacterHeight(), aspect);
+ setCharacterSize(getCharacterHeight(), aspect);
+ }
+
+ //----------------------------------------------------------------------------
+ void Text::TextOSG::setLineHeight(float factor)
+ {
+ setLineSpacing(factor - 1);
}
//----------------------------------------------------------------------------
if( !bb.valid() )
return bb;
-#if SG_OSG_VERSION_LESS_THAN(3,1,0)
+#if OSG_VERSION_LESS_THAN(3,1,0)
// TODO bounding box still doesn't seem always right (eg. with center
// horizontal alignment not completely accurate)
bb._min.y() += _offset.y();
//----------------------------------------------------------------------------
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("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);
- }
-
setupStyle();
}
//----------------------------------------------------------------------------
void Text::setFont(const char* name)
{
- _text->setFont( _canvas.lock()->getSystemAdapter()->getFont(name) );
+ _text->setFont( Canvas::getSystemAdapter()->getFont(name) );
}
//----------------------------------------------------------------------------