1
0
Fork 0

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.
This commit is contained in:
mfranz 2005-11-09 17:16:59 +00:00
parent b06049219e
commit cff9e51840
3 changed files with 54 additions and 21 deletions

View file

@ -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<string,FGDialog *>::iterator iter;
vector<string> 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();

View file

@ -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<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);

View file

@ -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 },