osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 #include <osgEarthSymbology/TextSymbol> 00020 00021 using namespace osgEarth; 00022 using namespace osgEarth::Symbology; 00023 00024 TextSymbol::TextSymbol( const Config& conf ) : 00025 Symbol( conf ), 00026 _fill( Fill( 1, 1, 1, 1 ) ), 00027 _halo( Stroke( 0.3, 0.3, 0.3, 1) ), 00028 _size( 16.0f ), 00029 _sizeMode( SIZEMODE_SCREEN ), 00030 _rotateToScreen( false ), 00031 _removeDuplicateLabels( false ), 00032 _provider( "overlay" ) 00033 { 00034 mergeConfig(conf); 00035 } 00036 00037 Config 00038 TextSymbol::getConfig() const 00039 { 00040 Config conf = Symbol::getConfig(); 00041 conf.key() = "text"; 00042 conf.addObjIfSet( "fill", _fill ); 00043 conf.addObjIfSet( "halo", _halo ); 00044 conf.addIfSet( "font", _font ); 00045 conf.addIfSet( "size", _size ); 00046 conf.addObjIfSet( "content", _content ); 00047 conf.addObjIfSet( "priority", _priority ); 00048 conf.addIfSet( "rotate_to_screen", _rotateToScreen ); 00049 conf.addIfSet( "remove_duplicate_labels", _removeDuplicateLabels ); 00050 conf.addIfSet( "size_mode", "screen", _sizeMode, SIZEMODE_SCREEN ); 00051 conf.addIfSet( "size_mode", "object", _sizeMode, SIZEMODE_OBJECT ); 00052 conf.addIfSet( "line_orientation", "parallel", _lineOrientation, LINEORIENTATION_PARALLEL ); 00053 conf.addIfSet( "line_orientation", "perpendicular", _lineOrientation, LINEORIENTATION_PERPENDICULAR ); 00054 conf.addIfSet( "line_orientation", "horizontal", _lineOrientation, LINEORIENTATION_HORIZONTAL ); 00055 conf.addIfSet( "line_placement", "along_line", _linePlacement, LINEPLACEMENT_ALONG_LINE ); 00056 conf.addIfSet( "line_placement", "centroid", _linePlacement, LINEPLACEMENT_CENTROID ); 00057 conf.addIfSet( "provider", _provider ); 00058 conf.addIfSet( "theme", _theme ); 00059 if ( _pixelOffset.isSet() ) { 00060 conf.add( "pixel_offset_x", toString(_pixelOffset->x()) ); 00061 conf.add( "pixel_offset_y", toString(_pixelOffset->y()) ); 00062 } 00063 return conf; 00064 } 00065 00066 void 00067 TextSymbol::mergeConfig( const Config& conf ) 00068 { 00069 conf.getObjIfSet( "fill", _fill ); 00070 conf.getObjIfSet( "halo", _halo ); 00071 conf.getIfSet( "font", _font ); 00072 conf.getIfSet( "size", _size ); 00073 conf.getObjIfSet( "content", _content ); 00074 conf.getObjIfSet( "priority", _priority ); 00075 conf.getIfSet( "rotate_to_screen", _rotateToScreen ); 00076 conf.getIfSet( "remove_duplicate_labels", _removeDuplicateLabels ); 00077 conf.getIfSet( "size_mode", "screen", _sizeMode, SIZEMODE_SCREEN ); 00078 conf.getIfSet( "size_mode", "object", _sizeMode, SIZEMODE_OBJECT ); 00079 conf.getIfSet( "line_orientation", "parallel", _lineOrientation, LINEORIENTATION_PARALLEL ); 00080 conf.getIfSet( "line_orientation", "perpendicular", _lineOrientation, LINEORIENTATION_PERPENDICULAR ); 00081 conf.getIfSet( "line_orientation", "horizontal", _lineOrientation, LINEORIENTATION_HORIZONTAL ); 00082 conf.getIfSet( "line_placement", "along_line", _linePlacement, LINEPLACEMENT_ALONG_LINE ); 00083 conf.getIfSet( "line_placement", "centroid", _linePlacement, LINEPLACEMENT_CENTROID ); 00084 conf.getIfSet( "provider", _provider ); 00085 conf.getIfSet( "theme", _theme ); 00086 if ( conf.hasValue( "pixel_offset_x" ) ) 00087 _pixelOffset = osg::Vec2s( conf.value<short>("pixel_offset_x",0), 0 ); 00088 if ( conf.hasValue( "pixel_offset_y" ) ) 00089 _pixelOffset = osg::Vec2s( _pixelOffset->x(), conf.value<short>("pixel_offset_y",0) ); 00090 }