]> 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 9713b45c6fd84a570fecb9c34b0db7fdfecf1be0..a839ae6f2052a4d6a4cba7ba2449fd5e9da8b257 100644 (file)
 #  include <config.h>
 #endif
 
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
 #include <simgear/compiler.h>
 
 #include <fstream>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/fg_os.hxx>
-#include <Main/renderer.hxx>
-#include <Main/viewmgr.hxx>
-#include <Main/WindowSystemAdapter.hxx>
-#include <Main/CameraGroup.hxx>
+#include <Viewer/renderer.hxx>
+#include <Viewer/viewmgr.hxx>
+#include <Viewer/WindowSystemAdapter.hxx>
+#include <Viewer/CameraGroup.hxx>
 #include <GUI/new_gui.hxx>
 
 
 #  include <shellapi.h>
 #endif
 
+#if defined(SG_MAC)
+# include <GUI/CocoaHelpers.h> // for cocoaOpenUrl
+#endif
+
 #include "gui.h"
 
 using std::string;
@@ -141,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 += ')';
@@ -156,46 +164,65 @@ void guiErrorMessage (const char *txt, const sg_throwable &throwable)
 the Gui callback functions 
 ____________________________________________________________________*/
 
-
-// Hier Neu :-) This is my newly added code
-// Added by David Findlay <nedz@bigpond.com>
-// on Sunday 3rd of December
-
-
-void helpCb ()
+void helpCb()
 {
-    string command;
-       
-    SGPath path( globals->get_fg_root() );
-    path.append( "Docs/index.html" );
-       
-#ifndef _WIN32
-
-    command = globals->get_browser();
-    string::size_type pos;
-    if ((pos = command.find("%u", 0)) != string::npos)
-        command.replace(pos, 2, path.str());
-    else
-        command += " " + path.str();
+    openBrowser( "Docs/index.html" );
+}
 
-    command += " &";
-    system( command.c_str() );
+bool openBrowser(const std::string& aAddress)
+{
+    bool ok = true;
+    string address(aAddress);
+    
+    // do not resolve addresses with given protocol, i.e. "http://...", "ftp://..."
+    if (address.find("://")==string::npos)
+    {
+        // resolve local file path
+        SGPath path(address);
+        path = globals->resolve_maybe_aircraft_path(address);
+        if (!path.isNull())
+            address = path.str();
+        else
+        {
+            mkDialog ("Sorry, file not found!");
+            SG_LOG(SG_GENERAL, SG_ALERT, "openBrowser: Cannot find requested file '"  
+                    << address << "'.");
+            return false;
+        }
+    }
 
-#else // _WIN32
+#ifdef SG_MAC
+  if (address.find("://")==string::npos) {
+    address = "file://" + address;
+  }
+  
+  cocoaOpenUrl(address);
+#elif defined _WIN32
 
     // Look for favorite browser
     char win32_name[1024];
 # ifdef __CYGWIN__
-    cygwin32_conv_to_full_win32_path(path.c_str(),win32_name);
+    cygwin32_conv_to_full_win32_path(address.c_str(),win32_name);
 # else
-    strncpy(win32_name,path.c_str(), 1024);
+    strncpy(win32_name,address.c_str(), 1024);
 # endif
     ShellExecute ( NULL, "open", win32_name, NULL, NULL,
                    SW_SHOWNORMAL ) ;
+#else
+    // Linux, BSD, SGI etc
+    string command = globals->get_browser();
+    string::size_type pos;
+    if ((pos = command.find("%u", 0)) != string::npos)
+        command.replace(pos, 2, address);
+    else
+        command += " \"" + address +"\"";
 
+    command += " &";
+    ok = (system( command.c_str() ) == 0);
 #endif
-       
-    mkDialog ("Help started in your web browser window.");
+
+    mkDialog("The file is shown in your web browser window.");
+    return ok;
 }
 
 #if defined( TR_HIRES_SNAP)
@@ -207,12 +234,11 @@ void fgHiResDump()
     char *filename = new char [24];
     static int count = 1;
 
-    static const SGPropertyNode *master_freeze
-        = fgGetNode("/sim/freeze/master");
+    SGPropertyNode *master_freeze = fgGetNode("/sim/freeze/master");
 
     bool freeze = master_freeze->getBoolValue();
     if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", true);
+        master_freeze->setBoolValue(true);
     }
 
     fgSetBool("/sim/menubar/visibility", false);
@@ -322,7 +348,7 @@ void fgHiResDump()
         int curColumn = trGet(tr, TR_CURRENT_COLUMN);
         // int curRow =  trGet(tr, TR_CURRENT_ROW);
 
-        renderer->update( false );
+        renderer->update();
         // OSGFIXME
 //         if ( do_hud )
 //             fgUpdateHUD( curColumn*hud_col_step,      curRow*hud_row_step,
@@ -393,7 +419,7 @@ void fgHiResDump()
     fgSetBool("/sim/menubar/visibility", menu_status);
 
     if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", false);
+        master_freeze->setBoolValue(false);
     }
 }
 #endif // #if defined( TR_HIRES_SNAP)
@@ -411,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:
@@ -454,28 +497,16 @@ namespace
 
             string dir = fgGetString("/sim/paths/screenshot-dir");
             if (dir.empty())
-                dir = fgGetString("/sim/fg-current");
+                dir = SGPath::desktop().str();
 
             _path.set(dir + '/');
             if (_path.create_dir( 0755 )) {
                 SG_LOG(SG_GENERAL, SG_ALERT, "Cannot create screenshot directory '"
                         << dir << "'. Trying home directory.");
-                dir = fgGetString("/sim/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;
-                }
+                dir = globals->get_fg_home();
             }
 
+            _path = nextScreenshotPath(dir);
             _xsize = fgGetInt("/sim/startup/xsize");
             _ysize = fgGetInt("/sim/startup/ysize");
 
@@ -522,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
-    static SGConstPropertyNode_ptr master_freeze = fgGetNode("/sim/freeze/master");
-
-    bool freeze = master_freeze->getBoolValue();
-    if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", 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 = fgGetString("/sim/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 ) {
-        fgSetBool("/sim/freeze/master", false);
-    }
-    return result;
-#endif
 }
 
 // do an entire scenegraph dump
@@ -604,12 +572,11 @@ void fgDumpSceneGraph()
     string message;
     static int count = 1;
 
-    static const SGPropertyNode *master_freeze
-       = fgGetNode("/sim/freeze/master");
+    SGPropertyNode *master_freeze = fgGetNode("/sim/freeze/master");
 
     bool freeze = master_freeze->getBoolValue();
     if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", true);
+        master_freeze->setBoolValue(true);
     }
 
     while (count < 1000) {
@@ -635,7 +602,7 @@ void fgDumpSceneGraph()
     delete [] filename;
 
     if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", false);
+        master_freeze->setBoolValue(false);
     }
 }
 
@@ -647,12 +614,11 @@ void fgDumpTerrainBranch()
     string message;
     static int count = 1;
 
-    static const SGPropertyNode *master_freeze
-       = fgGetNode("/sim/freeze/master");
+    SGPropertyNode *master_freeze = fgGetNode("/sim/freeze/master");
 
     bool freeze = master_freeze->getBoolValue();
     if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", true);
+        master_freeze->setBoolValue(true);
     }
 
     while (count < 1000) {
@@ -678,26 +644,22 @@ void fgDumpTerrainBranch()
     delete [] filename;
 
     if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", false);
+        master_freeze->setBoolValue(false);
     }
 }
 
 void fgPrintVisibleSceneInfoCommand()
 {
-    static const SGPropertyNode *master_freeze
-        = fgGetNode("/sim/freeze/master");
+    SGPropertyNode *master_freeze = fgGetNode("/sim/freeze/master");
 
     bool freeze = master_freeze->getBoolValue();
     if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", true);
+        master_freeze->setBoolValue(true);
     }
 
     flightgear::printVisibleSceneInfo(globals->get_renderer());
 
     if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", false);
+        master_freeze->setBoolValue(false);
     }
 }
-
-    
-