コード例 #1
0
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 );

}
コード例 #2
0
int
main(int argc, char** argv)
{
    // allocate pager threads based on CPU configuration.
    int cores = Registry::capabilities().getNumProcessors();
    osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint( osg::clampAbove(cores, 2) );
    osg::DisplaySettings::instance()->setNumOfHttpDatabaseThreadsHint( osg::clampAbove(cores/2, 1) );

    // parse the command line.
    osg::ArgumentParser arguments(&argc,argv);
    osgViewer::Viewer viewer(arguments);

    // set up the motion model.
    viewer.setCameraManipulator( new EarthManipulator() );

    // simple UI.
    VBox* vbox = new VBox();
    vbox->setMargin( 3 );
    vbox->setChildSpacing( 5 );
    vbox->setAbsorbEvents( true );
    vbox->setHorizAlign( Control::ALIGN_RIGHT );
    vbox->setVertAlign ( Control::ALIGN_BOTTOM );

    // Control instructions:
    Grid* grid = vbox->addControl( new Grid() );
    grid->setControl( 0, 0, new LabelControl("Pan:"));
    grid->setControl( 1, 0, new LabelControl("Left mouse"));
    grid->setControl( 0, 1, new LabelControl("Zoom:"));
    grid->setControl( 1, 1, new LabelControl("Right mouse / scroll"));
    grid->setControl( 0, 2, new LabelControl("Rotate:") );
    grid->setControl( 1, 2, new LabelControl("Middle mouse"));
    grid->setControl( 0, 3, new LabelControl("Go to:"));
    grid->setControl( 1, 3, new LabelControl("Double-click"));

    ControlCanvas::getOrCreate(&viewer)->addControl(vbox);

    // Load an earth file
    osg::Node* node = MapNodeHelper().load(arguments, &viewer);
    if ( !node )
        return usage( "Failed to load earth file." );
    viewer.setSceneData( node );


#ifdef Q_WS_X11
    // required for multi-threaded viewer on linux:
    XInitThreads();
#endif


    QApplication app(argc, argv);

    QWidget* viewerWidget = new ViewerWidget( &viewer );
    
    QMainWindow win;
    win.setWindowTitle( "osgEarth -- The #1 Open Source Terrain SDK for Mission-Critical Applications" );
    win.setCentralWidget( viewerWidget );
    win.setGeometry(100, 100, 1024, 800);

    win.statusBar()->showMessage(QString("osgEarth.  Copyright 2014 Pelican Mapping.   Please visit http://osgearth.org"));

    win.show();
    app.exec();
}