]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/gui_funcs.cxx
GUI support for VIA/Discontinuity
[flightgear.git] / src / GUI / gui_funcs.cxx
index 1f78d45046767d62a56c0e25ecced56f8ed3f9e0..a839ae6f2052a4d6a4cba7ba2449fd5e9da8b257 100644 (file)
@@ -52,7 +52,6 @@
 #include <Cockpit/panel.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
-#include <Main/fg_init.hxx> // for platformDesktopPath
 #include <Main/fg_os.hxx>
 #include <Viewer/renderer.hxx>
 #include <Viewer/viewmgr.hxx>
@@ -65,8 +64,8 @@
 #  include <shellapi.h>
 #endif
 
-#ifdef SG_MAC
-# include "FGCocoaMenuBar.hxx" // for cocoaOpenUrl
+#if defined(SG_MAC)
+# include <GUI/CocoaHelpers.h> // for cocoaOpenUrl
 #endif
 
 #include "gui.h"
@@ -150,7 +149,7 @@ void guiErrorMessage (const char *txt, const sg_throwable &throwable)
     string msg = txt;
     msg += '\n';
     msg += throwable.getFormattedMessage();
-    if (!std::strlen(throwable.getOrigin()) != 0) {
+    if (std::strlen(throwable.getOrigin()) != 0) {
         msg += "\n (reported by ";
         msg += throwable.getOrigin();
         msg += ')';
@@ -438,7 +437,24 @@ namespace
 {
     using namespace flightgear;
 
-    class GUISnapShotOperation : 
+    SGPath nextScreenshotPath(const std::string& screenshotDir)
+    {
+        char filename[32];
+        static int count = 1;
+        while (count < 1000) {
+            snprintf(filename, 32, "fgfs-screen-%03d.png", count++);
+            
+            SGPath p(screenshotDir);
+            p.append(filename);
+            if (!p.exists()) {
+                return p;
+            }
+        }
+        
+        return SGPath();
+    }
+    
+    class GUISnapShotOperation :
         public GraphicsContextOperation
     {
     public:
@@ -481,7 +497,7 @@ namespace
 
             string dir = fgGetString("/sim/paths/screenshot-dir");
             if (dir.empty())
-              dir = platformDesktopPath().str();
+                dir = SGPath::desktop().str();
 
             _path.set(dir + '/');
             if (_path.create_dir( 0755 )) {
@@ -490,19 +506,7 @@ namespace
                 dir = globals->get_fg_home();
             }
 
-            char filename[24];
-            static int count = 1;
-            while (count < 1000) {
-                snprintf(filename, 24, "fgfs-screen-%03d.png", count++);
-
-                SGPath p(dir);
-                p.append(filename);
-                if (!p.exists()) {
-                    _path.set(p.str());
-                    break;
-                }
-            }
-
+            _path = nextScreenshotPath(dir);
             _xsize = fgGetInt("/sim/startup/xsize");
             _ysize = fgGetInt("/sim/startup/ysize");
 
@@ -549,79 +553,16 @@ namespace
         SGPath _path;
     };
 
-}
+} // of anonymous namespace
 
 osg::ref_ptr<GUISnapShotOperation> GUISnapShotOperation::_snapShotOp;
 
 // do a screen snap shot
 bool fgDumpSnapShot ()
 {
-#if 1
     // start snap shot operation, while needs to be executed in
     // graphics context
     return GUISnapShotOperation::start();
-#else
-    // obsolete code => remove when new code is stable
-    SGPropertyNode_ptr master_freeze = fgGetNode("/sim/freeze/master");
-
-    bool freeze = master_freeze->getBoolValue();
-    if ( !freeze ) {
-        master_freeze->setBoolValue(true);
-    }
-
-    int mouse = fgGetMouseCursor();
-    fgSetMouseCursor(MOUSE_CURSOR_NONE);
-
-    fgSetBool("/sim/signals/screenshot", true);
-
-    FGRenderer *renderer = globals->get_renderer();
-    renderer->resize( fgGetInt("/sim/startup/xsize"),
-                      fgGetInt("/sim/startup/ysize") );
-
-    // we need two render frames here to clear the menu and cursor
-    // ... not sure why but doing an extra fgRenderFrame() shouldn't
-    // hurt anything
-    renderer->update( true );
-    renderer->update( true );
-
-    string dir = fgGetString("/sim/paths/screenshot-dir");
-    if (dir.empty())
-        dir = fgGetString("/sim/fg-current");
-
-    SGPath path(dir + '/');
-    if (path.create_dir( 0755 )) {
-        SG_LOG(SG_GENERAL, SG_ALERT, "Cannot create screenshot directory '"
-                << dir << "'. Trying home directory.");
-        dir = globals->get_fg_home();
-    }
-
-    char filename[24];
-    static int count = 1;
-    while (count < 1000) {
-        snprintf(filename, 24, "fgfs-screen-%03d.png", count++);
-
-        SGPath p(dir);
-        p.append(filename);
-        if (!p.exists()) {
-            path.set(p.str());
-            break;
-        }
-    }
-
-    bool result = sg_glDumpWindow(path.c_str(),
-                                 fgGetInt("/sim/startup/xsize"),
-                                 fgGetInt("/sim/startup/ysize"));
-
-    fgSetString("/sim/paths/screenshot-last", path.c_str());
-    fgSetBool("/sim/signals/screenshot", false);
-
-    fgSetMouseCursor(mouse);
-
-    if ( !freeze ) {
-        master_freeze->setBoolValue(false);
-    }
-    return result;
-#endif
 }
 
 // do an entire scenegraph dump