|
osgEarth 2.1.1
|
Inheritance diagram for osgEarth::Util::Controls::LabelControl:
Collaboration diagram for osgEarth::Util::Controls::LabelControl:Public Member Functions | |
| LabelControl (const std::string &value="", float fontSize=18.0f, const osg::Vec4f &foreColor=osg::Vec4f(1, 1, 1, 1)) | |
| LabelControl (const std::string &value, const osg::Vec4f &foreColor) | |
| void | setText (const std::string &value) |
| const std::string & | text () const |
| void | setFont (osgText::Font *font) |
| osgText::Font * | font () const |
| void | setFontSize (float value) |
| float | fontSize () const |
| void | setHaloColor (const osg::Vec4f &value) |
| const optional< osg::Vec4f > & | haloColor () const |
| virtual void | calcSize (const ControlContext &context, osg::Vec2f &out_size) |
| virtual void | draw (const ControlContext &context, DrawableList &out_drawables) |
Private Attributes | |
| std::string | _text |
| osg::ref_ptr< osgText::Font > | _font |
| float | _fontSize |
| osg::ref_ptr< osgText::Text > | _drawable |
| osg::Vec3 | _bmin |
| osg::Vec3 | _bmax |
| optional< osg::Vec4f > | _haloColor |
| LabelControl::LabelControl | ( | const std::string & | value = "", |
| float | fontSize = 18.0f, |
||
| const osg::Vec4f & | foreColor = osg::Vec4f(1,1,1,1) |
||
| ) |
Definition at line 466 of file Controls.cpp.
{
setText( text );
setFont( osgText::readFontFile( "arial.ttf" ) ); // TODO: cache this?
setFontSize( fontSize );
setBackColor( osg::Vec4f(0,0,0,0) );
setForeColor( foreColor );
}
Here is the call graph for this function:| LabelControl::LabelControl | ( | const std::string & | value, |
| const osg::Vec4f & | foreColor | ||
| ) |
Definition at line 477 of file Controls.cpp.
{
setText( text );
setFont( osgText::readFontFile( "arial.ttf" ) ); // TODO: cache this?
setFontSize( 18.0f );
setBackColor( osg::Vec4f(0,0,0,0) );
setForeColor( foreColor );
}
Here is the call graph for this function:| void LabelControl::calcSize | ( | const ControlContext & | context, |
| osg::Vec2f & | out_size | ||
| ) | [virtual] |
Reimplemented from osgEarth::Util::Controls::Control.
Definition at line 524 of file Controls.cpp.
{
if ( visible() == true )
{
// we have to create the drawable during the layout pass so we can calculate its size.
LabelText* t = new LabelText();
#if 1
// needs a special shader
// todo: doesn't work. why?
osg::Program* program = new osg::Program();
program->addShader( new osg::Shader( osg::Shader::VERTEX, s_controlVertexShader ) );
program->addShader( new osg::Shader( osg::Shader::FRAGMENT, s_labelControlFragmentShader ) );
t->getOrCreateStateSet()->setAttributeAndModes( program, osg::StateAttribute::ON );
#endif
t->setText( _text );
// yes, object coords. screen coords won't work becuase the bounding box will be wrong.
t->setCharacterSizeMode( osgText::Text::OBJECT_COORDS );
t->setCharacterSize( _fontSize );
// always align to top. layout alignment gets calculated layer in Control::calcPos().
t->setAlignment( osgText::Text::LEFT_TOP );
t->setColor( foreColor().value() );
if ( _font.valid() )
t->setFont( _font.get() );
if ( haloColor().isSet() )
{
t->setBackdropType( osgText::Text::OUTLINE );
t->setBackdropOffset( 0.03 );
t->setBackdropColor( haloColor().value() );
}
osg::BoundingBox bbox = t->getTextBB();
if ( cx._viewContextID != ~0u )
{
//the Text's autoTransformCache matrix puts some mojo on the bounding box
osg::Matrix m = t->getATMatrix( cx._viewContextID );
_bmin = osg::Vec3( bbox.xMin(), bbox.yMin(), bbox.zMin() ) * m;
_bmax = osg::Vec3( bbox.xMax(), bbox.yMax(), bbox.zMax() ) * m;
}
else
{
_bmin = osg::Vec3( bbox.xMin(), bbox.yMin(), bbox.zMin() );
_bmax = osg::Vec3( bbox.xMax(), bbox.yMax(), bbox.zMax() );
}
_renderSize.set(
(_bmax.x() - _bmin.x()) + padding().x(),
(_bmax.y() - _bmin.y()) + padding().y() );
_drawable = t;
out_size.set(
margin().x() + _renderSize.x(),
margin().y() + _renderSize.y() );
}
else
{
out_size.set(0,0);
}
//_dirty = false;
}
Here is the call graph for this function:| void LabelControl::draw | ( | const ControlContext & | context, |
| DrawableList & | out_drawables | ||
| ) | [virtual] |
Reimplemented from osgEarth::Util::Controls::Control.
Definition at line 590 of file Controls.cpp.
{
if ( _drawable.valid() && visible() == true )
{
Control::draw( cx, out );
float vph = cx._vp->height(); // - padding().bottom();
LabelText* t = static_cast<LabelText*>( _drawable.get() );
osg::BoundingBox bbox = t->getTextBB();
t->setPosition( osg::Vec3( _renderPos.x(), vph - _renderPos.y(), 0 ) );
out.push_back( _drawable.get() );
}
}
Here is the call graph for this function:| osgText::Font* osgEarth::Util::Controls::LabelControl::font | ( | ) | const [inline] |
| float osgEarth::Util::Controls::LabelControl::fontSize | ( | ) | const [inline] |
| const optional<osg::Vec4f>& osgEarth::Util::Controls::LabelControl::haloColor | ( | ) | const [inline] |
Definition at line 286 of file Controls.
{ return _haloColor; }
Here is the caller graph for this function:| void LabelControl::setFont | ( | osgText::Font * | font | ) |
Definition at line 497 of file Controls.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:| void LabelControl::setFontSize | ( | float | value | ) |
Definition at line 506 of file Controls.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:| void LabelControl::setHaloColor | ( | const osg::Vec4f & | value | ) |
Definition at line 515 of file Controls.cpp.
{
if ( !_haloColor.isSet() || *_haloColor != value ) {
_haloColor = value;
dirty();
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| void LabelControl::setText | ( | const std::string & | value | ) |
Definition at line 488 of file Controls.cpp.
Here is the call graph for this function:
Here is the caller graph for this function:| const std::string& osgEarth::Util::Controls::LabelControl::text | ( | ) | const [inline] |
osg::Vec3 osgEarth::Util::Controls::LabelControl::_bmax [private] |
osg::Vec3 osgEarth::Util::Controls::LabelControl::_bmin [private] |
osg::ref_ptr<osgText::Text> osgEarth::Util::Controls::LabelControl::_drawable [private] |
osg::ref_ptr<osgText::Font> osgEarth::Util::Controls::LabelControl::_font [private] |
float osgEarth::Util::Controls::LabelControl::_fontSize [private] |
optional<osg::Vec4f> osgEarth::Util::Controls::LabelControl::_haloColor [private] |
std::string osgEarth::Util::Controls::LabelControl::_text [private] |
1.7.3