Exemplo n.º 1
0
 /**
  * Creates a simple label. The caller is responsible for placing it in the scene.
  */
 osg::Node* createNode(
     const std::string& text,
     const TextSymbol*  symbol )
 {
     Controls::LabelControl* label = new Controls::LabelControl( text );
     if ( symbol )
     {
         if ( symbol->fill().isSet() )
             label->setForeColor( symbol->fill()->color() );
         if ( symbol->halo().isSet() )
             label->setHaloColor( symbol->halo()->color() );
         if ( symbol->size().isSet() )
             label->setFontSize( *symbol->size() );
         if ( symbol->font().isSet() )
             label->setFont( osgText::readFontFile(*symbol->font()) );
         if ( symbol->encoding().isSet() )
         {
             osgText::String::Encoding enc;
             switch(symbol->encoding().value())
             {
             case TextSymbol::ENCODING_ASCII: enc = osgText::String::ENCODING_ASCII; break;
             case TextSymbol::ENCODING_UTF8: enc = osgText::String::ENCODING_UTF8; break;
             case TextSymbol::ENCODING_UTF16: enc = osgText::String::ENCODING_UTF16; break;
             case TextSymbol::ENCODING_UTF32: enc = osgText::String::ENCODING_UTF32; break;
             default: enc = osgText::String::ENCODING_UNDEFINED; break;
             }
             label->setEncoding( enc );
         }
     }
     Controls::ControlNode* node = new Controls::ControlNode( label );
     return node;
 }
Exemplo n.º 2
0
    /**
     * Creates a simple label. The caller is responsible for placing it in the scene.
     */
    osg::Node* createNode(
        const std::string& text,
        const Style&       style )
    {
        const TextSymbol* symbol = style.get<TextSymbol>();

        Controls::LabelControl* label = new Controls::LabelControl( text );
        if ( symbol )
        {
            if ( symbol->fill().isSet() )
                label->setForeColor( symbol->fill()->color() );
            if ( symbol->halo().isSet() )
                label->setHaloColor( symbol->halo()->color() );
            //if ( symbol->size().isSet() )
            //    label->setFontSize( *symbol->size() );
            if ( symbol->font().isSet() )
            {
                osgText::Font* font = osgText::readFontFile(*symbol->font() );
                // mitigates mipmapping issues that cause rendering artifacts for some fonts/placement
                if ( font )
                    font->setGlyphImageMargin( 2 );
                label->setFont( font );
            }
            if ( symbol->encoding().isSet() )
            {
                osgText::String::Encoding enc;
                switch(symbol->encoding().value())
                {
                case TextSymbol::ENCODING_ASCII: enc = osgText::String::ENCODING_ASCII; break;
                case TextSymbol::ENCODING_UTF8: enc = osgText::String::ENCODING_UTF8; break;
                case TextSymbol::ENCODING_UTF16: enc = osgText::String::ENCODING_UTF16; break;
                case TextSymbol::ENCODING_UTF32: enc = osgText::String::ENCODING_UTF32; break;
                default: enc = osgText::String::ENCODING_UNDEFINED; break;
                }
                label->setEncoding( enc );
            }
        }
        Controls::ControlNode* node = new Controls::ControlNode( label );
        return node;
    }