From 3fce07e5e514c156e91b530a8768269d1a0811f9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 10 Oct 2009 11:06:30 +0000 Subject: [PATCH] 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. " --- include/osgWidget/Label | 11 ++++++----- src/osgWidget/Label.cpp | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/osgWidget/Label b/include/osgWidget/Label index edda4b5cc..fd8d88cbf 100644 --- a/include/osgWidget/Label +++ b/include/osgWidget/Label @@ -1,13 +1,13 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ @@ -36,6 +36,7 @@ class OSGWIDGET_EXPORT Label: public Widget virtual void positioned (); void setLabel (const std::string&); + void setLabel (const osgText::String&); void setFont (const std::string&); void setFontSize (unsigned int); void setFontColor (const Color&); diff --git a/src/osgWidget/Label.cpp b/src/osgWidget/Label.cpp index ce5f7c69f..37b462571 100644 --- a/src/osgWidget/Label.cpp +++ b/src/osgWidget/Label.cpp @@ -8,7 +8,7 @@ namespace osgWidget { Label::Label(const std::string& name, const std::string& label): Widget (name, 0, 0), -_text (new osgText::Text()), +_text (new osgText::Text()), _textIndex (0) { _text->setAlignment(osgText::Text::LEFT_BOTTOM); _text->setDataVariance(osg::Object::DYNAMIC); @@ -43,7 +43,7 @@ void Label::_calculateSize(const XYCoord& size) { // if(size.x() && size.y()) setMinimumSize(size.x(), size.y()); if(getWidth() < size.x()) setWidth(size.x()); - + if(getHeight() < size.y()) setHeight(size.y()); } @@ -56,7 +56,7 @@ void Label::parented(Window* parent) { // a Window; it'll have a _textIndex, but that _textIndex won't apply to the // currently cloned object. In this case, we'll need to check to be SURE. osgText::Text* text = dynamic_cast(geode->getDrawable(_textIndex)); - + if(text) parent->getGeode()->setDrawable(_textIndex, _text.get()); // Otherwise, add it as new. @@ -108,16 +108,23 @@ void Label::setLabel(const std::string& label) { _calculateSize(getTextSize()); } +void Label::setLabel(const osgText::String& label) +{ + _text->setText(label); + + _calculateSize(getTextSize()); +} + void Label::setFont(const std::string& font) { _text->setFont(font); - + _calculateSize(getTextSize()); } void Label::setFontSize(unsigned int size) { _text->setCharacterSize(size); _text->setFontResolution(size, size); - + _calculateSize(getTextSize()); }