]> git.mxchange.org Git - flightgear.git/blob - src/GUI/new_gui.hxx
6e96a5aa060778a16902cbf9b205aef63219254c
[flightgear.git] / src / GUI / new_gui.hxx
1 // new_gui.hxx - XML-configured GUI subsystem.
2
3 #ifndef __NEW_GUI_HXX
4 #define __NEW_GUI_HXX 1
5
6 #ifndef __cplusplus
7 # error This library requires C++
8 #endif
9
10 #ifdef HAVE_CONFIG_H
11 #  include <config.h>
12 #endif
13
14 #include <plib/pu.h>
15
16 #include <simgear/compiler.h>   // for SG_USING_STD
17 #include <simgear/props/props.hxx>
18 #include <simgear/structure/subsystem_mgr.hxx>
19
20 #include <vector>
21 SG_USING_STD(vector);
22
23 #include <map>
24 SG_USING_STD(map);
25
26 #include <Main/fg_props.hxx>
27
28 class FGMenuBar;
29 class FGDialog;
30 class FGBinding;
31
32
33 /**
34  * XML-configured GUI subsystem.
35  *
36  * This subsystem manages the graphical user interface for FlightGear.
37  * It creates a menubar from the XML configuration file in
38  * $FG_ROOT/gui/menubar.xml, then stores the configuration properties
39  * for XML-configured dialog boxes found in $FG_ROOT/gui/dialogs/.  It
40  * can show or hide the menubar, and can display any dialog by name.
41  */
42 class NewGUI : public SGSubsystem
43 {
44 public:
45
46     /**
47      * Constructor.
48      */
49     NewGUI ();
50
51     /**
52      * Destructor.
53      */
54     virtual ~NewGUI ();
55
56     /**
57      * Initialize the GUI subsystem.
58      */
59     virtual void init ();
60
61     /**
62      * Reinitialize the GUI subsystem.
63      */
64     virtual void reinit ();
65
66     /**
67      * Bind properties for the GUI subsystem.
68      *
69      * Currently, this method binds the properties for showing and
70      * hiding the menu.
71      */
72     virtual void bind ();
73
74     /**
75      * Unbind properties for the GUI subsystem.
76      */
77     virtual void unbind ();
78
79     /**
80      * Update the GUI subsystem.
81      *
82      * Currently, this method is a no-op, because nothing the GUI
83      * subsystem does is time-dependent.
84      */
85     virtual void update (double delta_time_sec);
86
87     /**
88      * Creates a new dialog box, using the same property format as the
89      * gui/dialogs configuration files.  Does not display the
90      * resulting dialog.  If a pre-existing dialog of the same name
91      * exists, it will be deleted.  The node argument will be stored
92      * in the GUI subsystem using SGPropertNode_ptr reference counting.
93      * It should not be deleted by user code.
94      *
95      * @param node A property node containing the dialog definition
96      */
97     virtual void newDialog (SGPropertyNode* node);
98
99     /**
100      * Display a dialog box.
101      *
102      * At initialization time, the subsystem reads all of the XML
103      * configuration files from the directory $FG_ROOT/gui/dialogs/.
104      * The configuration for each dialog specifies a name, and this
105      * method invokes the dialog with the name specified (if it
106      * exists).
107      *
108      * @param name The name of the dialog box.
109      * @return true if the dialog exists, false otherwise.
110      */
111     virtual bool showDialog (const string &name);
112
113
114     /**
115      * Close the currenty active dialog.  This function is intended to
116      * be called from code (pui callbacks, for instance) that registers
117      * its dialog object as active via setActiveDialog().  Other
118      * user-level code should use the closeDialog(name) API.
119      *
120      * @return true if a dialog was active, false otherwise
121      */
122     virtual bool closeActiveDialog ();
123
124     /**
125      * Close a named dialog, if it is open.
126      *
127      * @param name The name of the dialog box.
128      * @return true if the dialog was active, false otherwise.
129      */
130     virtual bool closeDialog (const string &name);
131
132     /**
133      * Return a pointer to the current menubar.
134      */
135     virtual FGMenuBar * getMenuBar ();
136
137
138     /**
139      * Ignore this method.
140      *
141      * This method is for internal use only, but it has to be public
142      * so that a non-class callback can see it.
143      */
144     virtual void setActiveDialog (FGDialog * dialog);
145
146     /**
147      * Get the dialog currently active, if any.
148      *
149      * @return The active dialog, or 0 if none is active.
150      */
151     virtual FGDialog * getActiveDialog ();
152
153 protected:
154
155     /**
156      * Test if the menubar is visible.
157      *
158      * This method exists only for binding.
159      */
160     virtual bool getMenuBarVisible () const;
161
162     /**
163      * Show or hide the menubar.
164      *
165      * This method exists only for binding.
166      */
167     virtual void setMenuBarVisible (bool visible);
168
169
170 private:
171
172     // Free all allocated memory.
173     void clear ();
174
175     // Read all the configuration files in a directory.
176     void readDir (const char * path);
177
178     FGMenuBar * _menubar;
179     FGDialog * _active_dialog;
180     map<string,FGDialog *> _active_dialogs;
181     map<string,SGPropertyNode_ptr> _dialog_props;
182
183 };
184
185
186 #endif // __NEW_GUI_HXX
187