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 ); }
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 GlobePlugin::setupControls() { std::string imgDir = QDir::cleanPath( QgsApplication::pkgDataPath() + "/globe/gui" ).toStdString(); osgEarth::Util::EarthManipulator* manip = dynamic_cast<osgEarth::Util::EarthManipulator*>( mOsgViewer->getCameraManipulator() ); osg::Image* yawPitchWheelImg = osgDB::readImageFile( imgDir + "/YawPitchWheel.png" ); ImageControl* yawPitchWheel = new ImageControl( yawPitchWheelImg ); int imgLeft = 16; int imgTop = 20; yawPitchWheel->setPosition( imgLeft, imgTop ); mControlCanvas->addControl( yawPitchWheel ); //ROTATE CONTROLS Control* rotateCCW = new NavigationControl(); rotateCCW->setHeight( 22 ); rotateCCW->setWidth( 20 ); rotateCCW->setPosition( imgLeft + 0, imgTop + 18 ); rotateCCW->addEventHandler( new RotateControlHandler( manip, MOVE_OFFSET, 0 ) ); mControlCanvas->addControl( rotateCCW ); Control* rotateCW = new NavigationControl(); rotateCW->setHeight( 22 ); rotateCW->setWidth( 20 ); rotateCW->setPosition( imgLeft + 36, imgTop + 18 ); rotateCW->addEventHandler( new RotateControlHandler( manip, -MOVE_OFFSET , 0 ) ); mControlCanvas->addControl( rotateCW ); //Rotate Reset Control* rotateReset = new NavigationControl(); rotateReset->setHeight( 22 ); rotateReset->setWidth( 16 ); rotateReset->setPosition( imgLeft + 20, imgTop + 18 ); rotateReset->addEventHandler( new RotateControlHandler( manip, 0, 0 ) ); mControlCanvas->addControl( rotateReset ); //TILT CONTROLS Control* tiltUp = new NavigationControl(); tiltUp->setHeight( 19 ); tiltUp->setWidth( 24 ); tiltUp->setPosition( imgLeft + 20, imgTop + 0 ); tiltUp->addEventHandler( new RotateControlHandler( manip, 0, MOVE_OFFSET ) ); mControlCanvas->addControl( tiltUp ); Control* tiltDown = new NavigationControl(); tiltDown->setHeight( 19 ); tiltDown->setWidth( 24 ); tiltDown->setPosition( imgLeft + 16, imgTop + 36 ); tiltDown->addEventHandler( new RotateControlHandler( manip, 0, -MOVE_OFFSET ) ); mControlCanvas->addControl( tiltDown ); // ------- osg::Image* moveWheelImg = osgDB::readImageFile( imgDir + "/MoveWheel.png" ); ImageControl* moveWheel = new ImageControl( moveWheelImg ); imgTop = 80; moveWheel->setPosition( imgLeft, imgTop ); mControlCanvas->addControl( moveWheel ); //MOVE CONTROLS Control* moveLeft = new NavigationControl(); moveLeft->setHeight( 22 ); moveLeft->setWidth( 20 ); moveLeft->setPosition( imgLeft + 0, imgTop + 18 ); moveLeft->addEventHandler( new PanControlHandler( manip, -MOVE_OFFSET, 0 ) ); mControlCanvas->addControl( moveLeft ); Control* moveRight = new NavigationControl(); moveRight->setHeight( 22 ); moveRight->setWidth( 20 ); moveRight->setPosition( imgLeft + 36, imgTop + 18 ); moveRight->addEventHandler( new PanControlHandler( manip, MOVE_OFFSET, 0 ) ); mControlCanvas->addControl( moveRight ); Control* moveUp = new NavigationControl(); moveUp->setHeight( 19 ); moveUp->setWidth( 24 ); moveUp->setPosition( imgLeft + 20, imgTop + 0 ); moveUp->addEventHandler( new PanControlHandler( manip, 0, MOVE_OFFSET ) ); mControlCanvas->addControl( moveUp ); Control* moveDown = new NavigationControl(); moveDown->setHeight( 19 ); moveDown->setWidth( 24 ); moveDown->setPosition( imgLeft + 16, imgTop + 36 ); moveDown->addEventHandler( new PanControlHandler( manip, 0, -MOVE_OFFSET ) ); mControlCanvas->addControl( moveDown ); //Zoom Reset Control* zoomHome = new NavigationControl(); zoomHome->setHeight( 22 ); zoomHome->setWidth( 16 ); zoomHome->setPosition( imgLeft + 20, imgTop + 18 ); zoomHome->addEventHandler( new HomeControlHandler( manip ) ); mControlCanvas->addControl( zoomHome ); // ------- osg::Image* backgroundImg = osgDB::readImageFile( imgDir + "/button-background.png" ); ImageControl* backgroundGrp1 = new ImageControl( backgroundImg ); imgTop = imgTop + 62; backgroundGrp1->setPosition( imgLeft + 12, imgTop ); mControlCanvas->addControl( backgroundGrp1 ); osg::Image* plusImg = osgDB::readImageFile( imgDir + "/zoom-in.png" ); ImageControl* zoomIn = new NavigationControl( plusImg ); zoomIn->setPosition( imgLeft + 12 + 3, imgTop + 3 ); zoomIn->addEventHandler( new ZoomControlHandler( manip, 0, -MOVE_OFFSET ) ); mControlCanvas->addControl( zoomIn ); osg::Image* minusImg = osgDB::readImageFile( imgDir + "/zoom-out.png" ); ImageControl* zoomOut = new NavigationControl( minusImg ); zoomOut->setPosition( imgLeft + 12 + 3, imgTop + 3 + 23 + 2 ); zoomOut->addEventHandler( new ZoomControlHandler( manip, 0, MOVE_OFFSET ) ); mControlCanvas->addControl( zoomOut ); // ------- ImageControl* backgroundGrp2 = new ImageControl( backgroundImg ); imgTop = imgTop + 60; backgroundGrp2->setPosition( imgLeft + 12, imgTop ); mControlCanvas->addControl( backgroundGrp2 ); //Zoom Reset osg::Image* homeImg = osgDB::readImageFile( imgDir + "/zoom-home.png" ); ImageControl* home = new NavigationControl( homeImg ); home->setPosition( imgLeft + 12 + 3, imgTop + 2 ); home->addEventHandler( new HomeControlHandler( manip ) ); mControlCanvas->addControl( home ); //refresh layers osg::Image* refreshImg = osgDB::readImageFile( imgDir + "/refresh-view.png" ); ImageControl* refresh = new NavigationControl( refreshImg ); refresh->setPosition( imgLeft + 12 + 3, imgTop + 2 + 23 + 2 ); refresh->addEventHandler( new RefreshControlHandler( this ) ); mControlCanvas->addControl( refresh ); //Sync Extent #if ENABLE_SYNC_BUTTON osg::Image* syncImg = osgDB::readImageFile( imgDir + "/sync-extent.png" ); ImageControl* sync = new NavigationControl( syncImg ); sync->addEventHandler( new SyncExtentControlHandler( this ) ); mControlCanvas->addControl( sync ); #endif }