]> git.mxchange.org Git - flightgear.git/blob - src/GUI/new_gui.cxx
Unbundle dialog-box support from the top-level GUI manager, to
[flightgear.git] / src / GUI / new_gui.cxx
1 // new_gui.cxx: implementation of XML-configurable GUI support.
2
3 #include "new_gui.hxx"
4
5 #include <plib/pu.h>
6 #include <plib/ul.h>
7
8 #include <simgear/misc/exception.hxx>
9 #include <Main/fg_props.hxx>
10
11 #include "menubar.hxx"
12 #include "dialog.hxx"
13
14
15 \f
16 ////////////////////////////////////////////////////////////////////////
17 // Implementation of NewGUI.
18 ////////////////////////////////////////////////////////////////////////
19
20
21 NewGUI::NewGUI ()
22     : _menubar(new FGMenuBar),
23       _current_widget(0)
24 {
25 }
26
27 NewGUI::~NewGUI ()
28 {
29     delete _menubar;
30 }
31
32 void
33 NewGUI::init ()
34 {
35     char path1[1024];
36     char path2[1024];
37     ulMakePath(path1, getenv("FG_ROOT"), "gui");
38     ulMakePath(path2, path1, "dialogs");
39     readDir(path2);
40 #if !defined(FG_OLD_MENUBAR)
41     _menubar->init();
42 #endif
43 }
44
45 void
46 NewGUI::update (double delta_time_sec)
47 {
48     // NO OP
49 }
50
51 void
52 NewGUI::display (const string &name)
53 {
54     if (_widgets.find(name) == _widgets.end())
55         SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
56     else
57         new FGDialog(_widgets[name]);
58 }
59
60 void
61 NewGUI::setCurrentWidget (FGDialog * widget)
62 {
63     _current_widget = widget;
64 }
65
66 FGDialog *
67 NewGUI::getCurrentWidget ()
68 {
69     return _current_widget;
70 }
71
72 FGMenuBar *
73 NewGUI::getMenuBar ()
74 {
75     return _menubar;
76 }
77
78 void
79 NewGUI::readDir (const char * path)
80 {
81     ulDir * dir = ulOpenDir(path);
82
83     if (dir == 0) {
84         SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
85                << path);
86         return;
87     }
88
89     ulDirEnt * dirEnt = ulReadDir(dir);
90     while (dirEnt != 0) {
91         char subpath[1024];
92
93         ulMakePath(subpath, path, dirEnt->d_name);
94
95         if (dirEnt->d_isdir && dirEnt->d_name[0] != '.') {
96             readDir(subpath);
97         } else {
98             SGPropertyNode_ptr props = new SGPropertyNode;
99             try {
100                 readProperties(subpath, props);
101             } catch (const sg_exception &ex) {
102                 SG_LOG(SG_INPUT, SG_ALERT, "Error parsing GUI file "
103                        << subpath);
104             }
105             if (!props->hasValue("name")) {
106                 SG_LOG(SG_INPUT, SG_WARN, "GUI file " << subpath
107                    << " has no name; skipping.");
108             } else {
109                 string name = props->getStringValue("name");
110                 SG_LOG(SG_INPUT, SG_BULK, "Saving GUI node " << name);
111                 _widgets[name] = props;
112             }
113         }
114         dirEnt = ulReadDir(dir);
115     }
116     ulCloseDir(dir);
117 }
118
119 // end of new_gui.cxx