1 // new_gui.cxx: implementation of XML-configurable GUI support.
8 #include <simgear/misc/exception.hxx>
9 #include <Main/fg_props.hxx>
11 #include "menubar.hxx"
16 ////////////////////////////////////////////////////////////////////////
17 // Implementation of NewGUI.
18 ////////////////////////////////////////////////////////////////////////
22 : _menubar(new FGMenuBar),
37 ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
38 ulMakePath(path2, path1, "dialogs");
40 #if !defined(FG_OLD_MENUBAR)
50 #if !defined(FG_OLD_MENUBAR)
52 _menubar = new FGMenuBar;
54 _dialog_props.clear();
63 fgTie("/sim/menubar/visibility", this,
64 &NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
70 fgUntie("/sim/menubar/visibility");
74 NewGUI::update (double delta_time_sec)
80 NewGUI::showDialog (const string &name)
82 if (_dialog_props.find(name) == _dialog_props.end()) {
83 SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
86 new FGDialog(_dialog_props[name]); // it will be deleted by a callback
92 NewGUI::closeActiveDialog ()
94 if (_active_dialog == 0) {
97 delete _active_dialog;
104 NewGUI::setActiveDialog (FGDialog * dialog)
106 _active_dialog = dialog;
110 NewGUI::getActiveDialog ()
112 return _active_dialog;
116 NewGUI::getMenuBar ()
122 NewGUI::getMenuBarVisible () const
124 return _menubar->isVisible();
128 NewGUI::setMenuBarVisible (bool visible)
137 NewGUI::readDir (const char * path)
139 ulDir * dir = ulOpenDir(path);
142 SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
147 ulDirEnt * dirEnt = ulReadDir(dir);
148 while (dirEnt != 0) {
151 ulMakePath(subpath, path, dirEnt->d_name);
153 if (dirEnt->d_isdir && dirEnt->d_name[0] != '.') {
156 SGPropertyNode_ptr props = new SGPropertyNode;
158 readProperties(subpath, props);
159 } catch (const sg_exception &ex) {
160 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing GUI file "
163 if (!props->hasValue("name")) {
164 SG_LOG(SG_INPUT, SG_WARN, "GUI file " << subpath
165 << " has no name; skipping.");
167 string name = props->getStringValue("name");
168 SG_LOG(SG_INPUT, SG_BULK, "Saving GUI node " << name);
169 _dialog_props[name] = props;
172 dirEnt = ulReadDir(dir);
177 // end of new_gui.cxx