Show
Ignore:
Timestamp:
10/10/09 13:06:30 (5 years ago)
Author:
robert
Message:

From Cesar L.B. Silveira, "I have written these few lines of code which allow setting the label
of an osgWidget::Label with an osgText::String. I had to do this on a
project I'm working on, because I needed UTF-8 strings on my labels,
and using setLabel with std::string was not working.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgWidget/Label.cpp

    r9287 r10636  
    99Label::Label(const std::string& name, const std::string& label): 
    1010Widget     (name, 0, 0), 
    11 _text      (new osgText::Text()),  
     11_text      (new osgText::Text()), 
    1212_textIndex (0) { 
    1313    _text->setAlignment(osgText::Text::LEFT_BOTTOM); 
     
    4444 
    4545    if(getWidth() < size.x()) setWidth(size.x()); 
    46      
     46 
    4747    if(getHeight() < size.y()) setHeight(size.y()); 
    4848} 
     
    5757    // currently cloned object. In this case, we'll need to check to be SURE. 
    5858    osgText::Text* text = dynamic_cast<osgText::Text*>(geode->getDrawable(_textIndex)); 
    59      
     59 
    6060    if(text) parent->getGeode()->setDrawable(_textIndex, _text.get()); 
    6161 
     
    109109} 
    110110 
     111void Label::setLabel(const osgText::String& label) 
     112{ 
     113   _text->setText(label); 
     114 
     115   _calculateSize(getTextSize()); 
     116} 
     117 
    111118void Label::setFont(const std::string& font) { 
    112119    _text->setFont(font); 
    113      
     120 
    114121    _calculateSize(getTextSize()); 
    115122} 
     
    118125    _text->setCharacterSize(size); 
    119126    _text->setFontResolution(size, size); 
    120      
     127 
    121128    _calculateSize(getTextSize()); 
    122129}