]> git.mxchange.org Git - flightgear.git/blob - src/GUI/new_gui.hxx
Remove unnecessary includes/using
[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 #include <simgear/props/props.hxx>
7 #include <simgear/structure/subsystem_mgr.hxx>
8 #include <simgear/misc/sg_path.hxx>
9
10 #include <vector>
11 #include <map>
12 #include <memory> // for auto_ptr on some systems
13 #include <cstring> // for strcmp in lstr() (in this header, alas)
14
15 class FGMenuBar;
16 class FGDialog;
17 class FGColor;
18 class FGFontCache;
19 class puFont;
20
21 /**
22  * XML-configured GUI subsystem.
23  *
24  * This subsystem manages the graphical user interface for FlightGear.
25  * It creates a menubar from the XML configuration file in
26  * $FG_ROOT/gui/menubar.xml, then stores the configuration properties
27  * for XML-configured dialog boxes found in $FG_ROOT/gui/dialogs/.  It
28  * can show or hide the menubar, and can display any dialog by name.
29  */
30 class NewGUI : public SGSubsystem
31 {
32 public:
33
34     /**
35      * Constructor.
36      */
37     NewGUI ();
38
39     /**
40      * Destructor.
41      */
42     virtual ~NewGUI ();
43
44     /**
45      * Initialize the GUI subsystem.
46      */
47     virtual void init ();
48
49     /**
50      * Reinitialize the GUI subsystem. Reloads all XML dialogs.
51      */
52     virtual void reinit ();
53
54     /**
55      * Bind properties for the GUI subsystem.
56      *
57      * Currently, this method binds the properties for showing and
58      * hiding the menu.
59      */
60     virtual void bind ();
61
62     /**
63      * Unbind properties for the GUI subsystem.
64      */
65     virtual void unbind ();
66
67     /**
68      * Update the GUI subsystem.
69      *
70      * Currently, this method is a no-op, because nothing the GUI
71      * subsystem does is time-dependent.
72      */
73     virtual void update (double delta_time_sec);
74
75     /**
76      * Redraw the GUI picking up new GUI colors.
77      */
78     virtual void redraw ();
79
80     /**
81      * Creates a new dialog box, using the same property format as the
82      * gui/dialogs configuration files.  Does not display the
83      * resulting dialog.  If a pre-existing dialog of the same name
84      * exists, it will be deleted.  The node argument will be stored
85      * in the GUI subsystem using SGPropertNode_ptr reference counting.
86      * It should not be deleted by user code.
87      *
88      * @param node A property node containing the dialog definition
89      */
90     virtual void newDialog (SGPropertyNode* node);
91
92     /**
93      * Display a dialog box.
94      *
95      * At initialization time, the subsystem reads all of the XML
96      * configuration files from the directory $FG_ROOT/gui/dialogs/.
97      * The configuration for each dialog specifies a name, and this
98      * method invokes the dialog with the name specified (if it
99      * exists).
100      *
101      * @param name The name of the dialog box.
102      * @return true if the dialog exists, false otherwise.
103      */
104     virtual bool showDialog (const std::string &name);
105
106
107     /**
108      * Close the currenty active dialog.  This function is intended to
109      * be called from code (pui callbacks, for instance) that registers
110      * its dialog object as active via setActiveDialog().  Other
111      * user-level code should use the closeDialog(name) API.
112      *
113      * @return true if a dialog was active, false otherwise
114      */
115     virtual bool closeActiveDialog ();
116
117     /**
118      * Close a named dialog, if it is open.
119      *
120      * @param name The name of the dialog box.
121      * @return true if the dialog was active, false otherwise.
122      */
123     virtual bool closeDialog (const std::string &name);
124
125     /**
126      * Get dialog property tree's root node.
127      * @param name The name of the dialog box.
128      * @return node pointer if the dialog was found, zero otherwise.
129      */
130     virtual SGPropertyNode_ptr getDialogProperties (const std::string &name);
131
132     /**
133      * Return a pointer to the current menubar.
134      */
135     virtual FGMenuBar * getMenuBar ();
136
137     /**
138      * Ignore this method.
139      *
140      * This method is for internal use only, but it has to be public
141      * so that a non-class callback can see it.
142      */
143     virtual void setActiveDialog (FGDialog * dialog);
144
145     /**
146      * Get the dialog currently active, if any.
147      *
148      * @return The active dialog, or 0 if none is active.
149      */
150     virtual FGDialog * getActiveDialog ();
151
152
153     /**
154      * Get the named dialog if active.
155      *
156      * @return The named dialog, or 0 if it isn't active.
157      */
158     virtual FGDialog * getDialog (const std::string &name);
159
160
161     virtual FGColor *getColor (const char * name) const {
162         _citt_t it = _colors.find(name);
163         return (it != _colors.end()) ? it->second : NULL;
164     }
165     virtual FGColor *getColor (const std::string &name) const {
166         _citt_t it = _colors.find(name.c_str());
167         return (it != _colors.end()) ? it->second : NULL;
168     }
169
170     virtual puFont *getDefaultFont() { return _font; }
171
172
173 protected:
174
175     /**
176      * Test if the menubar is visible.
177      *
178      * This method exists only for binding.
179      */
180     virtual bool getMenuBarVisible () const;
181
182     /**
183      * Show or hide the menubar.
184      *
185      * This method exists only for binding.
186      */
187     virtual void setMenuBarVisible (bool visible);
188
189     virtual void setStyle ();
190     virtual void setupFont (SGPropertyNode *);
191
192     /**
193      * Used by reinit() and redraw() to close all dialogs and to apply
194      * current GUI colors. If "reload" is false, reopens all dialogs.
195      * Otherwise reloads all XML dialog files from disk and reopens all
196      * but Nasal * generated dialogs, omitting dynamic widgets. (This
197      * is only useful for GUI development.)
198      */
199     virtual void reset (bool reload);
200
201 private:
202     struct ltstr
203     {
204         bool operator()(const char* s1, const char* s2) const {
205             return strcmp(s1, s2) < 0;
206         }
207     };
208
209     puFont *_font;
210     typedef std::map<const char*,FGColor*, ltstr> ColourDict;
211     ColourDict _colors;
212     typedef ColourDict::iterator _itt_t;
213     typedef ColourDict::const_iterator _citt_t;
214
215     void clear_colors();
216
217     // Read all the configuration files in a directory.
218     void readDir (const SGPath& path);
219
220     std::auto_ptr<FGMenuBar> _menubar;
221     FGDialog * _active_dialog;
222     std::map<std::string,FGDialog *> _active_dialogs;
223   
224     typedef std::map<std::string, SGPath> NamePathDict;
225     // mapping from dialog names to the corresponding XML property list
226     // which defines them
227     NamePathDict _dialog_names;
228   
229     // cache of loaded dialog proeprties
230     typedef std::map<std::string,SGPropertyNode_ptr> NameDialogDict;
231     NameDialogDict _dialog_props;
232
233 };
234
235
236 #endif // __NEW_GUI_HXX
237