void createControls( ControlCanvas* cs ) { // 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::Image* image = osgDB::readImageFile( "http://osgearth.org/chrome/site/osgearth.gif" ); if ( image ) { ImageControl* imageCon = new ImageControl( image ); imageCon->setHorizAlign( Control::ALIGN_CENTER ); imageCon->setFixSizeForRotation( true ); imageCon->addEventHandler( new ImageRotationHandler ); center->addControl( imageCon ); 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 ); // Add another LabelControl* label2 = new LabelControl( "(Click the osgEarth logo to rotate it)" ); label2->setHorizAlign( Control::ALIGN_CENTER ); center->addControl( label2 ); cs->addControl( center ); } // a simple vbox with absolute positioning in the upper left with two text labels. { VBox* ul = new VBox(); ul->setFrame( new Frame() ); 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->setSpacing( 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->setSpacing( 10 ); { HBox* c4 = new HBox(); c4->setSpacing( 5 ); { c4->addControl( new CheckBoxControl( true ) ); c4->addControl( new LabelControl( "Checkbox 1" ) ); } c3->addControl( c4 ); HBox* c5 = new HBox(); c5->setSpacing( 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->setSpacing( 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 ); } }
void createControls( ControlCanvas* cs ) { // 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 = osgDB::readImageFile("http://demo.pelicanmapping.com/rmweb/readymap_logo.png"); if ( image.valid() ) { 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( osgEarth::Registry::instance()->getDefaultFont() ); 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; std::string str; str = buf.str(); label->setText( 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 ); } }
void GlobePlugin::setupControls() { std::string imgDir = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/gui" ).toStdString(); //MOVE CONTROLS //Horizontal container HBox* moveHControls = new HBox(); moveHControls->setFrame( new RoundedFrame() ); moveHControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); moveHControls->setMargin( 0 ); //moveHControls->setChildSpacing( 47 ); moveHControls->setVertAlign( Control::ALIGN_CENTER ); moveHControls->setHorizAlign( Control::ALIGN_CENTER ); moveHControls->setPosition( 5, 30 ); moveHControls->setPadding( 6 ); osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( viewer.getCameraManipulator() ); //Move Left osg::Image* moveLeftImg = osgDB::readImageFile( imgDir + "/move-left.png" ); ImageControl* moveLeft = new NavigationControl( moveLeftImg ); moveLeft->addEventHandler( new PanControlHandler( manip, -MOVE_OFFSET, 0 ) ); //Move Right osg::Image* moveRightImg = osgDB::readImageFile( imgDir + "/move-right.png" ); ImageControl* moveRight = new NavigationControl( moveRightImg ); moveRight->addEventHandler( new PanControlHandler( manip, MOVE_OFFSET, 0 ) ); //Vertical container VBox* moveVControls = new VBox(); moveVControls->setFrame( new RoundedFrame() ); moveVControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); moveVControls->setMargin( 0 ); //moveVControls->setChildSpacing( 36 ); moveVControls->setVertAlign( Control::ALIGN_CENTER ); moveVControls->setHorizAlign( Control::ALIGN_CENTER ); moveVControls->setPosition( 35, 5 ); moveVControls->setPadding( 6 ); //Move Up osg::Image* moveUpImg = osgDB::readImageFile( imgDir + "/move-up.png" ); ImageControl* moveUp = new NavigationControl( moveUpImg ); moveUp->addEventHandler( new PanControlHandler( manip, 0, MOVE_OFFSET ) ); //Move Down osg::Image* moveDownImg = osgDB::readImageFile( imgDir + "/move-down.png" ); ImageControl* moveDown = new NavigationControl( moveDownImg ); moveDown->addEventHandler( new PanControlHandler( manip, 0, -MOVE_OFFSET ) ); //add controls to moveControls group moveHControls->addControl( moveLeft ); moveHControls->addControl( moveRight ); moveVControls->addControl( moveUp ); moveVControls->addControl( moveDown ); //END MOVE CONTROLS //ROTATE CONTROLS //Horizontal container HBox* rotateControls = new HBox(); rotateControls->setFrame( new RoundedFrame() ); rotateControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); rotateControls->setMargin( 0 ); //rotateControls->setChildSpacing( 10 ); rotateControls->setVertAlign( Control::ALIGN_CENTER ); rotateControls->setHorizAlign( Control::ALIGN_CENTER ); rotateControls->setPosition( 5, 113 ); rotateControls->setPadding( 6 ); //Rotate CCW osg::Image* rotateCCWImg = osgDB::readImageFile( imgDir + "/rotate-ccw.png" ); ImageControl* rotateCCW = new NavigationControl( rotateCCWImg ); rotateCCW->addEventHandler( new RotateControlHandler( manip, MOVE_OFFSET, 0 ) ); //Rotate CW osg::Image* rotateCWImg = osgDB::readImageFile( imgDir + "/rotate-cw.png" ); ImageControl* rotateCW = new NavigationControl( rotateCWImg ); rotateCW->addEventHandler( new RotateControlHandler( manip, -MOVE_OFFSET , 0 ) ); //Rotate Reset osg::Image* rotateResetImg = osgDB::readImageFile( imgDir + "/rotate-reset.png" ); ImageControl* rotateReset = new NavigationControl( rotateResetImg ); rotateReset->addEventHandler( new RotateControlHandler( manip, 0, 0 ) ); //add controls to rotateControls group rotateControls->addControl( rotateCCW ); rotateControls->addControl( rotateReset ); rotateControls->addControl( rotateCW ); //END ROTATE CONTROLS //TILT CONTROLS //Vertical container VBox* tiltControls = new VBox(); tiltControls->setFrame( new RoundedFrame() ); tiltControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); tiltControls->setMargin( 0 ); //tiltControls->setChildSpacing( 30 ); tiltControls->setVertAlign( Control::ALIGN_CENTER ); tiltControls->setHorizAlign( Control::ALIGN_CENTER ); tiltControls->setPosition( 35, 90 ); tiltControls->setPadding( 6 ); //tilt Up osg::Image* tiltUpImg = osgDB::readImageFile( imgDir + "/tilt-up.png" ); ImageControl* tiltUp = new NavigationControl( tiltUpImg ); tiltUp->addEventHandler( new RotateControlHandler( manip, 0, MOVE_OFFSET ) ); //tilt Down osg::Image* tiltDownImg = osgDB::readImageFile( imgDir + "/tilt-down.png" ); ImageControl* tiltDown = new NavigationControl( tiltDownImg ); tiltDown->addEventHandler( new RotateControlHandler( manip, 0, -MOVE_OFFSET ) ); //add controls to tiltControls group tiltControls->addControl( tiltUp ); tiltControls->addControl( tiltDown ); //END TILT CONTROLS //ZOOM CONTROLS //Vertical container VBox* zoomControls = new VBox(); zoomControls->setFrame( new RoundedFrame() ); zoomControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); zoomControls->setMargin( 0 ); //zoomControls->setChildSpacing( 5 ); zoomControls->setVertAlign( Control::ALIGN_CENTER ); zoomControls->setHorizAlign( Control::ALIGN_CENTER ); zoomControls->setPosition( 35, 170 ); zoomControls->setPadding( 6 ); //Zoom In osg::Image* zoomInImg = osgDB::readImageFile( imgDir + "/zoom-in.png" ); ImageControl* zoomIn = new NavigationControl( zoomInImg ); zoomIn->addEventHandler( new ZoomControlHandler( manip, 0, -MOVE_OFFSET ) ); //Zoom Out osg::Image* zoomOutImg = osgDB::readImageFile( imgDir + "/zoom-out.png" ); ImageControl* zoomOut = new NavigationControl( zoomOutImg ); zoomOut->addEventHandler( new ZoomControlHandler( manip, 0, MOVE_OFFSET ) ); //add controls to zoomControls group zoomControls->addControl( zoomIn ); zoomControls->addControl( zoomOut ); //END ZOOM CONTROLS //EXTRA CONTROLS //Horizontal container HBox* extraControls = new HBox(); extraControls->setFrame( new RoundedFrame() ); extraControls->getFrame()->setBackColor( 1, 1, 1, 0.5 ); extraControls->setMargin( 0 ); //extraControls->setChildSpacing( 10 ); extraControls->setVertAlign( Control::ALIGN_CENTER ); extraControls->setHorizAlign( Control::ALIGN_CENTER ); extraControls->setPosition( 5, 220 ); extraControls->setPadding( 6 ); //Sync Extent osg::Image* extraSyncImg = osgDB::readImageFile( imgDir + "/sync-extent.png" ); ImageControl* extraSync = new NavigationControl( extraSyncImg ); extraSync->addEventHandler( new SyncExtentControlHandler( this ) ); //Zoom Reset osg::Image* extraHomeImg = osgDB::readImageFile( imgDir + "/zoom-home.png" ); ImageControl* extraHome = new NavigationControl( extraHomeImg ); extraHome->addEventHandler( new HomeControlHandler( manip ) ); //refresh layers osg::Image* extraRefreshImg = osgDB::readImageFile( imgDir + "/refresh-view.png" ); ImageControl* extraRefresh = new NavigationControl( extraRefreshImg ); extraRefresh->addEventHandler( new RefreshControlHandler( this ) ); //add controls to extraControls group extraControls->addControl( extraSync ); extraControls->addControl( extraHome ); extraControls->addControl( extraRefresh ); //END EXTRA CONTROLS //add controls groups to canavas mControlCanvas->addControl( moveHControls ); mControlCanvas->addControl( moveVControls ); mControlCanvas->addControl( tiltControls ); mControlCanvas->addControl( rotateControls ); mControlCanvas->addControl( zoomControls ); mControlCanvas->addControl( extraControls ); }