From b577ec70fcd7bb6a8835475582caee93975d3477 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sat, 17 Nov 2012 23:07:00 +0100 Subject: [PATCH] Add command to toggle fullscreen mode. --- src/Main/fg_commands.cxx | 13 +++++++ src/Viewer/fg_os_osgviewer.cxx | 65 +++++++++++++++++++++++++++++++++- src/Viewer/renderer.cxx | 4 --- src/Viewer/viewer.cxx | 3 ++ 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 21657fbc7..f32c29b57 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -379,6 +379,17 @@ do_view_prev( bool ) globals->get_viewmgr()->prev_view(); } +/** + * An fgcommand to toggle fullscreen mode. + * No parameters. + */ +static bool +do_toggle_fullscreen(const SGPropertyNode *arg) +{ + fgOSFullScreen(); + return true; +} + /** * Built-in command: cycle view. */ @@ -1533,6 +1544,7 @@ do_profiler_stop(const SGPropertyNode *arg) #endif } + //////////////////////////////////////////////////////////////////////// // Command setup. //////////////////////////////////////////////////////////////////////// @@ -1559,6 +1571,7 @@ static struct { { "load-tape", do_load_tape }, { "panel-load", do_panel_load }, { "preferences-load", do_preferences_load }, + { "toggle-fullscreen", do_toggle_fullscreen }, { "view-cycle", do_view_cycle }, { "screen-capture", do_screen_capture }, { "hires-screen-capture", do_hires_screen_capture }, diff --git a/src/Viewer/fg_os_osgviewer.cxx b/src/Viewer/fg_os_osgviewer.cxx index 3600a65ee..6d18862b4 100644 --- a/src/Viewer/fg_os_osgviewer.cxx +++ b/src/Viewer/fg_os_osgviewer.cxx @@ -309,9 +309,72 @@ void fgOSInit(int* argc, char** argv) WindowSystemAdapter::setWSA(new WindowSystemAdapter); } -// Noop void fgOSFullScreen() { + std::vector windows; + viewer->getWindows(windows); + + if (windows.size() == 0) + return; // Huh?!? + + /* Toggling window fullscreen is only supported for the main GUI window. + * The other windows should use fixed setup from the camera.xml file anyway. */ + osgViewer::GraphicsWindow* window = windows[0]; + + { + osg::GraphicsContext::WindowingSystemInterface *wsi = osg::GraphicsContext::getWindowingSystemInterface(); + + if (wsi == NULL) + { + SG_LOG(SG_VIEW, SG_ALERT, "ERROR: No WindowSystemInterface available. Cannot toggle window fullscreen."); + return; + } + + static int previous_x = 0; + static int previous_y = 0; + static int previous_width = 800; + static int previous_height = 600; + + unsigned int screenWidth; + unsigned int screenHeight; + wsi->getScreenResolution(*(window->getTraits()), screenWidth, screenHeight); + + int x; + int y; + int width; + int height; + window->getWindowRectangle(x, y, width, height); + + bool isFullScreen = x == 0 && y == 0 && width == (int)screenWidth && height == (int)screenHeight; + + SG_LOG(SG_VIEW, SG_DEBUG, "Toggling fullscreen. Previous window rectangle (" + << x << ", " << y << ") x (" << width << ", " << height << "), fullscreen: " << isFullScreen); + if (isFullScreen) + { + // disable fullscreen mode, restore previous window size/coordinates + window->setWindowDecoration(true); + // limit x,y coordinates and window size to screen area + if (previous_x + previous_width > (int)screenWidth) + previous_x = 0; + if (previous_y + previous_height > (int)screenHeight) + previous_y = 0; + window->setWindowRectangle(previous_x, previous_y, previous_width, previous_height); + } + else + { + // remember previous setting + previous_x = x; + previous_y = y; + previous_width = width; + previous_height = height; + + // enable fullscreen + window->setWindowDecoration(false); + window->setWindowRectangle(0, 0, screenWidth, screenHeight); + } + + window->grabFocusIfPointerInWindow(); + } } static void setMouseCursor(osgViewer::GraphicsWindow* gw, int cursor) diff --git a/src/Viewer/renderer.cxx b/src/Viewer/renderer.cxx index fdfc98a3c..8745d4189 100644 --- a/src/Viewer/renderer.cxx +++ b/src/Viewer/renderer.cxx @@ -1380,10 +1380,6 @@ FGRenderer::setupView( void ) osg::PolygonOffset::setUnitsMultiplier(1); osg::PolygonOffset::setFactorMultiplier(1); - // Go full screen if requested ... - if ( fgGetBool("/sim/startup/fullscreen") ) - fgOSFullScreen(); - // build the sky // The sun and moon diameters are scaled down numbers of the // actual diameters. This was needed to fit both the sun and the diff --git a/src/Viewer/viewer.cxx b/src/Viewer/viewer.cxx index 2d6521822..dc95cff12 100644 --- a/src/Viewer/viewer.cxx +++ b/src/Viewer/viewer.cxx @@ -61,6 +61,9 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index, _roll_deg(0), _pitch_deg(0), _heading_deg(0), + _target_roll_deg(0), + _target_pitch_deg(0), + _target_heading_deg(0), _scaling_type(FG_SCALING_MAX), _cameraGroup(CameraGroup::getDefault()) { -- 2.39.5