]> git.mxchange.org Git - flightgear.git/commitdiff
Add command to toggle fullscreen mode.
authorThorstenB <brehmt@gmail.com>
Sat, 17 Nov 2012 22:07:00 +0000 (23:07 +0100)
committerThorstenB <brehmt@gmail.com>
Sat, 17 Nov 2012 22:07:00 +0000 (23:07 +0100)
src/Main/fg_commands.cxx
src/Viewer/fg_os_osgviewer.cxx
src/Viewer/renderer.cxx
src/Viewer/viewer.cxx

index 21657fbc729e85f2af864b9ace420f940da3bcec..f32c29b5757bc1676c2e2e6f8c10f1cf46a01710 100644 (file)
@@ -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 },
index 3600a65ee5a722c9ef7f28d0a422b9c754855e22..6d18862b40b2d13710f5e375db8b37f329b2684d 100644 (file)
@@ -309,9 +309,72 @@ void fgOSInit(int* argc, char** argv)
     WindowSystemAdapter::setWSA(new WindowSystemAdapter);
 }
 
-// Noop
 void fgOSFullScreen()
 {
+    std::vector<osgViewer::GraphicsWindow*> 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)
index fdfc98a3cdabc7be50a80174f0b50c3af670c319..8745d4189de38d4dd804df2d28c5661dd10df7c9 100644 (file)
@@ -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
index 2d652182207e9fa432094a2cba12f7f97a2d6116..dc95cff12bf8c01c0a77647f3cd00118d6ea8357 100644 (file)
@@ -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())
 {