redraw(): redraw gui without distroying dialogs (fgcommand "gui-redaw"/Shift-F10)
This change makes sure that Nasal-generated and dynamic dialogs can be
re-opened correctly when cycling through themes.
NewGUI::~NewGUI ()
{
- clear();
+ delete _menubar;
+ _dialog_props.clear();
}
void
void
NewGUI::reinit ()
+{
+ reset(true);
+}
+
+void
+NewGUI::redraw ()
+{
+ reset(false);
+}
+
+void
+NewGUI::reset (bool reload)
{
map<string,FGDialog *>::iterator iter;
vector<string> dlg;
for (i = 0; i < dlg.size(); i++)
closeDialog(dlg[i]);
- unbind();
- clear();
setStyle();
+
+ unbind();
delete _menubar;
_menubar = new FGMenuBar;
- init();
+
+ if (reload) {
+ _dialog_props.clear();
+ init();
+ } else {
+ _menubar->init();
+ }
+
bind();
- // open remembered dialogs again (no nasal generated ones, unfortunately)
+ // open dialogs again
for (i = 0; i < dlg.size(); i++)
showDialog(dlg[i]);
}
_menubar->hide();
}
-void
-NewGUI::clear ()
-{
- delete _menubar;
- _menubar = 0;
- _dialog_props.clear();
- _itt_t it;
- for (it = _colors.begin(); it != _colors.end(); ++it)
- delete it->second;
- _colors.clear();
-}
-
static bool
test_extension (const char * path, const char * ext)
{
_colors["label"] = new FGColor(0.0f, 0.0f, 0.0f, 1.0f);
_colors["legend"] = new FGColor(0.0f, 0.0f, 0.0f, 1.0f);
_colors["misc"] = new FGColor(0.0f, 0.0f, 0.0f, 1.0f);
+ _colors["inputfield"] = new FGColor(0.8f, 0.7f, 0.7f, 1.0f);
//puSetDefaultStyle();
virtual void init ();
/**
- * Reinitialize the GUI subsystem.
+ * Reinitialize the GUI subsystem. Reloads all XML dialogs.
*/
virtual void reinit ();
*/
virtual void update (double delta_time_sec);
+ /**
+ * Redraw the GUI picking up new GUI colors.
+ */
+ virtual void redraw ();
+
/**
* Creates a new dialog box, using the same property format as the
* gui/dialogs configuration files. Does not display the
*/
virtual FGMenuBar * getMenuBar ();
-
/**
* Ignore this method.
*
virtual void setStyle ();
virtual void setupFont (SGPropertyNode *);
+ /**
+ * Used by reinit() and redraw() to close all dialogs and to apply
+ * current GUI colors. If "reload" is false, reopens all dialogs.
+ * Otherwise reloads all XML dialog files from disk and reopens all
+ * but Nasal * generated dialogs, omitting dynamic widgets. (This
+ * is only useful for GUI development.)
+ */
+ virtual void reset (bool reload);
+
private:
struct ltstr
{
typedef map<const char*,FGColor*, ltstr>::iterator _itt_t;
typedef map<const char*,FGColor*, ltstr>::const_iterator _citt_t;
- // Free all allocated memory.
- void clear ();
+ void clear_colors();
// Read all the configuration files in a directory.
void readDir (const char * path);
}
+/**
+ * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
+ * unlike reinit().
+ */
+static bool
+do_gui_redraw (const SGPropertyNode * arg)
+{
+ NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
+ gui->redraw();
+}
+
/**
* Built-in command: commit presets (read from in /sim/presets/)
*/
{ "dialog-close", do_dialog_close },
{ "dialog-update", do_dialog_update },
{ "dialog-apply", do_dialog_apply },
+ { "gui-redraw", do_gui_redraw },
{ "presets-commit", do_presets_commit },
{ "log-level", do_log_level },
{ "replay", do_replay },