Changeset 10636

Show
Ignore:
Timestamp:
10/10/09 13:06:30 (4 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.
"

Location:
OpenSceneGraph/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgWidget/Label

    r9438 r10636  
    1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield  
     1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield 
    22 * 
    3  * This library is open source and may be redistributed and/or modified under   
    4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or  
     3 * This library is open source and may be redistributed and/or modified under 
     4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
    55 * (at your option) any later version.  The full license is in LICENSE file 
    66 * included with this distribution, and on the openscenegraph.org website. 
    7  *  
     7 * 
    88 * This library is distributed in the hope that it will be useful, 
    99 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
     10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1111 * OpenSceneGraph Public License for more details. 
    1212*/ 
     
    3737 
    3838        void setLabel     (const std::string&); 
     39        void setLabel     (const osgText::String&); 
    3940        void setFont      (const std::string&); 
    4041        void setFontSize  (unsigned int); 
  • 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}