1 // new_gui.hxx - XML-configured GUI subsystem.
4 #define __NEW_GUI_HXX 1
6 #include <simgear/props/props.hxx>
7 #include <simgear/structure/subsystem_mgr.hxx>
8 #include <simgear/misc/sg_path.hxx>
23 * XML-configured GUI subsystem.
25 * This subsystem manages the graphical user interface for FlightGear.
26 * It creates a menubar from the XML configuration file in
27 * $FG_ROOT/gui/menubar.xml, then stores the configuration properties
28 * for XML-configured dialog boxes found in $FG_ROOT/gui/dialogs/. It
29 * can show or hide the menubar, and can display any dialog by name.
31 class NewGUI : public SGSubsystem
46 * Initialize the GUI subsystem.
51 * Reinitialize the GUI subsystem. Reloads all XML dialogs.
53 virtual void reinit ();
56 * Bind properties for the GUI subsystem.
58 * Currently, this method binds the properties for showing and
64 * Unbind properties for the GUI subsystem.
66 virtual void unbind ();
69 * Update the GUI subsystem.
71 * Currently, this method is a no-op, because nothing the GUI
72 * subsystem does is time-dependent.
74 virtual void update (double delta_time_sec);
77 * Redraw the GUI picking up new GUI colors.
79 virtual void redraw ();
82 * Creates a new dialog box, using the same property format as the
83 * gui/dialogs configuration files. Does not display the
84 * resulting dialog. If a pre-existing dialog of the same name
85 * exists, it will be deleted. The node argument will be stored
86 * in the GUI subsystem using SGPropertNode_ptr reference counting.
87 * It should not be deleted by user code.
89 * @param node A property node containing the dialog definition
91 virtual void newDialog (SGPropertyNode* node);
94 * Display a dialog box.
96 * At initialization time, the subsystem reads all of the XML
97 * configuration files from the directory $FG_ROOT/gui/dialogs/.
98 * The configuration for each dialog specifies a name, and this
99 * method invokes the dialog with the name specified (if it
102 * @param name The name of the dialog box.
103 * @return true if the dialog exists, false otherwise.
105 virtual bool showDialog (const std::string &name);
109 * Close the currenty active dialog. This function is intended to
110 * be called from code (pui callbacks, for instance) that registers
111 * its dialog object as active via setActiveDialog(). Other
112 * user-level code should use the closeDialog(name) API.
114 * @return true if a dialog was active, false otherwise
116 virtual bool closeActiveDialog ();
119 * Close a named dialog, if it is open.
121 * @param name The name of the dialog box.
122 * @return true if the dialog was active, false otherwise.
124 virtual bool closeDialog (const std::string &name);
127 * Get dialog property tree's root node.
128 * @param name The name of the dialog box.
129 * @return node pointer if the dialog was found, zero otherwise.
131 virtual SGPropertyNode_ptr getDialogProperties (const std::string &name);
134 * Return a pointer to the current menubar.
136 virtual FGMenuBar * getMenuBar ();
139 * Ignore this method.
141 * This method is for internal use only, but it has to be public
142 * so that a non-class callback can see it.
144 virtual void setActiveDialog (FGDialog * dialog);
147 * Get the dialog currently active, if any.
149 * @return The active dialog, or 0 if none is active.
151 virtual FGDialog * getActiveDialog ();
155 * Get the named dialog if active.
157 * @return The named dialog, or 0 if it isn't active.
159 virtual FGDialog * getDialog (const std::string &name);
162 virtual FGColor *getColor (const char * name) const {
163 _citt_t it = _colors.find(name);
164 return (it != _colors.end()) ? it->second : NULL;
166 virtual FGColor *getColor (const std::string &name) const {
167 _citt_t it = _colors.find(name.c_str());
168 return (it != _colors.end()) ? it->second : NULL;
171 virtual puFont *getDefaultFont() { return _font; }
177 * Test if the menubar is visible.
179 * This method exists only for binding.
181 virtual bool getMenuBarVisible () const;
184 * Show or hide the menubar.
186 * This method exists only for binding.
188 virtual void setMenuBarVisible (bool visible);
190 virtual void setStyle ();
191 virtual void setupFont (SGPropertyNode *);
194 * Used by reinit() and redraw() to close all dialogs and to apply
195 * current GUI colors. If "reload" is false, reopens all dialogs.
196 * Otherwise reloads all XML dialog files from disk and reopens all
197 * but Nasal * generated dialogs, omitting dynamic widgets. (This
198 * is only useful for GUI development.)
200 virtual void reset (bool reload);
205 bool operator()(const char* s1, const char* s2) const {
206 return strcmp(s1, s2) < 0;
211 typedef std::map<const char*,FGColor*, ltstr> ColourDict;
213 typedef ColourDict::iterator _itt_t;
214 typedef ColourDict::const_iterator _citt_t;
218 // Read all the configuration files in a directory.
219 void readDir (const SGPath& path);
221 FGMenuBar * _menubar;
222 FGDialog * _active_dialog;
223 std::map<std::string,FGDialog *> _active_dialogs;
224 std::map<std::string,SGPropertyNode_ptr> _dialog_props;
229 #endif // __NEW_GUI_HXX