]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/new_gui.cxx
Don't scale elevator by 0.5.
[flightgear.git] / src / GUI / new_gui.cxx
index a0e17a65ed72ee70d435c123d13f2ab93435eb03..f6e087ca91a1ad602d9ee7c8ac60cc103561a9db 100644 (file)
@@ -5,12 +5,15 @@
 #include <plib/pu.h>
 #include <plib/ul.h>
 
-#include <simgear/misc/exception.hxx>
+#include <simgear/compiler.h>
+#include <simgear/structure/exception.hxx>
+
 #include <Main/fg_props.hxx>
 
 #include "menubar.hxx"
 #include "dialog.hxx"
 
+SG_USING_STD(map);
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -26,7 +29,7 @@ NewGUI::NewGUI ()
 
 NewGUI::~NewGUI ()
 {
-    delete _menubar;
+    clear();
 }
 
 void
@@ -37,22 +40,15 @@ NewGUI::init ()
     ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
     ulMakePath(path2, path1, "dialogs");
     readDir(path2);
-#if !defined(FG_OLD_MENUBAR)
     _menubar->init();
-#endif
 }
 
 void
 NewGUI::reinit ()
 {
     unbind();
-
-#if !defined(FG_OLD_MENUBAR)
-    delete _menubar;
+    clear();
     _menubar = new FGMenuBar;
-#endif
-    _dialog_props.clear();
-
     init();
     bind();
 }
@@ -133,6 +129,31 @@ NewGUI::setMenuBarVisible (bool visible)
         _menubar->hide();
 }
 
+void
+NewGUI::clear ()
+{
+    delete _menubar;
+    _menubar = 0;
+
+    map<string,SGPropertyNode *>::iterator it;
+    for (it = _dialog_props.begin(); it != _dialog_props.end(); it++)
+        delete it->second;
+    _dialog_props.clear();
+}
+
+static bool
+test_extension (const char * path, const char * ext)
+{
+    int pathlen = strlen(path);
+    int extlen = strlen(ext);
+    
+    for (int i = 1; i <= pathlen && i <= extlen; i++) {
+        if (path[pathlen-i] != ext[extlen-i])
+            return false;
+    }
+    return true;
+}
+
 void
 NewGUI::readDir (const char * path)
 {
@@ -144,32 +165,36 @@ NewGUI::readDir (const char * path)
         return;
     }
 
-    ulDirEnt * dirEnt = ulReadDir(dir);
-    while (dirEnt != 0) {
+    for (ulDirEnt * dirEnt = ulReadDir(dir);
+         dirEnt != 0;
+         dirEnt = ulReadDir(dir)) {
+
         char subpath[1024];
 
         ulMakePath(subpath, path, dirEnt->d_name);
 
-        if (dirEnt->d_isdir && dirEnt->d_name[0] != '.') {
-            readDir(subpath);
-        } else {
-            SGPropertyNode_ptr props = new SGPropertyNode;
+        if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
+            SGPropertyNode * props = new SGPropertyNode;
             try {
                 readProperties(subpath, props);
             } catch (const sg_exception &ex) {
-                SG_LOG(SG_INPUT, SG_ALERT, "Error parsing GUI file "
+                SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
                        << subpath);
+                delete props;
+                continue;
             }
             if (!props->hasValue("name")) {
-                SG_LOG(SG_INPUT, SG_WARN, "GUI file " << subpath
+                SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
                    << " has no name; skipping.");
-            } else {
-                string name = props->getStringValue("name");
-                SG_LOG(SG_INPUT, SG_BULK, "Saving GUI node " << name);
-                _dialog_props[name] = props;
+                delete props;
+                continue;
             }
+            string name = props->getStringValue("name");
+            SG_LOG(SG_INPUT, SG_BULK, "Saving dialog " << name);
+            if (_dialog_props[name] != 0)
+                delete _dialog_props[name];
+            _dialog_props[name] = props;
         }
-        dirEnt = ulReadDir(dir);
     }
     ulCloseDir(dir);
 }