osgEarth 2.1.1
|
#include <typeinfo>
#include <osg/Notify>
#include <osgGA/GUIEventHandler>
#include <osgViewer/Viewer>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/Controls>
#include <osgEarthSymbology/Color>
Go to the source code of this file.
Classes | |
struct | MyClickHandler |
struct | MySliderHandler |
struct | RotateImage |
Functions | |
void | createControls (ControlCanvas *) |
int | main (int argc, char **argv) |
Variables | |
ImageControl * | s_imageControl |
static LabelControl * | s_sliderLabel |
void createControls | ( | ControlCanvas * | cs | ) |
Definition at line 91 of file osgearth_controls.cpp.
{ // a container centered on the screen, containing an image and a text label. { VBox* center = new VBox(); center->setFrame( new RoundedFrame() ); center->getFrame()->setBackColor( 1,1,1,0.5 ); center->setPadding( 10 ); center->setHorizAlign( Control::ALIGN_CENTER ); center->setVertAlign( Control::ALIGN_CENTER ); // Add an image: osg::ref_ptr<osg::Image> image; if ( HTTPClient::readImageFile("http://demo.pelicanmapping.com/rmweb/readymap_logo.png", image) == HTTPClient::RESULT_OK ) { s_imageControl = new ImageControl( image.get() ); s_imageControl->setHorizAlign( Control::ALIGN_CENTER ); s_imageControl->setFixSizeForRotation( true ); //imageCon->addEventHandler( new ImageRotationHandler ); center->addControl( s_imageControl ); center->setHorizAlign( Control::ALIGN_CENTER ); } // Add a text label: LabelControl* label = new LabelControl( "osgEarth Controls Toolkit" ); label->setFont( osgText::readFontFile( "arialbd.ttf" ) ); label->setFontSize( 24.0f ); label->setHorizAlign( Control::ALIGN_CENTER ); label->setMargin( 5 ); center->addControl( label ); // Rotation slider HBox* rotateBox = new HBox(); rotateBox->setChildVertAlign( Control::ALIGN_CENTER ); rotateBox->setHorizFill( true ); rotateBox->setBackColor( Color::Blue ); { rotateBox->addControl( new LabelControl("Rotate: ") ); HSliderControl* rotateSlider = new HSliderControl( -180.0, 180.0, 0.0 ); rotateSlider->addEventHandler( new RotateImage() ); rotateSlider->setHeight( 8.0f ); rotateSlider->setHorizFill( true ); rotateBox->addControl( rotateSlider ); } center->addControl( rotateBox ); cs->addControl( center ); } // a simple vbox with absolute positioning in the upper left with two text labels. { VBox* ul = new VBox(); ul->setPosition( 20, 20 ); ul->setPadding( 10 ); { LabelControl* title = new LabelControl( "Upper left control", 22, osg::Vec4f(1,1,0,1) ); ul->addControl( title ); LabelControl* content = new LabelControl( "Here is some text in the upper left control" ); ul->addControl( content ); HBox* c2 = new HBox(); c2->setChildSpacing( 10 ); { HSliderControl* slider = new HSliderControl( 0, 100 ); slider->setBackColor( .6,0,0,1 ); slider->setHeight( 25 ); slider->setWidth( 300 ); slider->addEventHandler( new MySliderHandler() ); c2->addControl( slider ); s_sliderLabel = new LabelControl(); s_sliderLabel->setVertAlign( Control::ALIGN_CENTER ); c2->addControl( s_sliderLabel ); } ul->addControl( c2 ); HBox* c3 = new HBox(); c3->setHorizAlign( Control::ALIGN_CENTER ); c3->setChildSpacing( 10 ); { HBox* c4 = new HBox(); c4->setChildSpacing( 5 ); { c4->addControl( new CheckBoxControl( true ) ); c4->addControl( new LabelControl( "Checkbox 1" ) ); } c3->addControl( c4 ); HBox* c5 = new HBox(); c5->setChildSpacing( 5 ); { c5->addControl( new CheckBoxControl( false ) ); c5->addControl( new LabelControl( "Checkbox 2" ) ); } c3->addControl( c5 ); } ul->addControl( c3 ); } cs->addControl( ul ); ul->addEventHandler( new MyClickHandler ); } // a centered hbox container along the bottom on the screen. { HBox* bottom = new HBox(); bottom->setFrame( new RoundedFrame() ); bottom->getFrame()->setBackColor(0,0,0,0.5); bottom->setMargin( 10 ); bottom->setChildSpacing( 145 ); bottom->setVertAlign( Control::ALIGN_BOTTOM ); bottom->setHorizAlign( Control::ALIGN_CENTER ); for( int i=0; i<4; ++i ) { LabelControl* label = new LabelControl(); std::stringstream buf; buf << "Label_" << i; label->setText( buf.str() ); label->setMargin( 10 ); label->setBackColor( 1,1,1,0.4 ); bottom->addControl( label ); label->setActiveColor(1,.3,.3,1); label->addEventHandler( new MyClickHandler ); } cs->addControl( bottom ); } }
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 37 of file osgearth_controls.cpp.
{ osg::ArgumentParser arguments(&argc,argv); osgViewer::Viewer viewer(arguments); osg::Group* root = new osg::Group(); osg::Node* node = osgDB::readNodeFiles( arguments ); if ( node ) root->addChild( node ); // create a surface to house the controls ControlCanvas* cs = ControlCanvas::get( &viewer ); root->addChild( cs ); viewer.setSceneData( root ); viewer.setCameraManipulator( new osgEarth::Util::EarthManipulator ); // create some controls. createControls( cs ); return viewer.run(); }
Definition at line 34 of file osgearth_controls.cpp.
LabelControl* s_sliderLabel [static] |
Definition at line 69 of file osgearth_controls.cpp.