From cff9e518403376c4b11d8fc9002a352b58d1a93b Mon Sep 17 00:00:00 2001 From: mfranz Date: Wed, 9 Nov 2005 17:16:59 +0000 Subject: [PATCH] reinit(): destroy, reload and re-open dialogs (menu: Debug -> GUI Reload) 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. --- src/GUI/new_gui.cxx | 43 ++++++++++++++++++++++++---------------- src/GUI/new_gui.hxx | 20 +++++++++++++++---- src/Main/fg_commands.cxx | 12 +++++++++++ 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index 339cc92a9..2eedc1674 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -34,7 +34,8 @@ NewGUI::NewGUI () NewGUI::~NewGUI () { - clear(); + delete _menubar; + _dialog_props.clear(); } void @@ -51,6 +52,18 @@ NewGUI::init () void NewGUI::reinit () +{ + reset(true); +} + +void +NewGUI::redraw () +{ + reset(false); +} + +void +NewGUI::reset (bool reload) { map::iterator iter; vector dlg; @@ -62,15 +75,22 @@ NewGUI::reinit () 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]); } @@ -188,18 +208,6 @@ NewGUI::setMenuBarVisible (bool visible) _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) { @@ -293,6 +301,7 @@ NewGUI::setStyle (void) _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(); diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx index 980b7871f..76aca62fb 100644 --- a/src/GUI/new_gui.hxx +++ b/src/GUI/new_gui.hxx @@ -63,7 +63,7 @@ public: virtual void init (); /** - * Reinitialize the GUI subsystem. + * Reinitialize the GUI subsystem. Reloads all XML dialogs. */ virtual void reinit (); @@ -88,6 +88,11 @@ public: */ 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 @@ -145,7 +150,6 @@ public: */ virtual FGMenuBar * getMenuBar (); - /** * Ignore this method. * @@ -199,6 +203,15 @@ protected: 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 { @@ -213,8 +226,7 @@ private: typedef map::iterator _itt_t; typedef map::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); diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 8db3908dd..bd72af4c0 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -1106,6 +1106,17 @@ do_dialog_apply (const SGPropertyNode * arg) } +/** + * 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/) */ @@ -1345,6 +1356,7 @@ static struct { { "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 }, -- 2.39.5