]> git.mxchange.org Git - flightgear.git/commitdiff
reinit(): destroy, reload and re-open dialogs (menu: Debug -> GUI Reload)
authormfranz <mfranz>
Wed, 9 Nov 2005 17:16:59 +0000 (17:16 +0000)
committermfranz <mfranz>
Wed, 9 Nov 2005 17:16:59 +0000 (17:16 +0000)
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
src/GUI/new_gui.hxx
src/Main/fg_commands.cxx

index 339cc92a9016ae1bfa7307c833514206d1d76800..2eedc1674457274b80ac3e57aa4f4a6efdbd409e 100644 (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();
 
index 980b7871f86d2420e812f5bcc4a442c82831bdb0..76aca62fbda2637afbd24a445253435d61a8559f 100644 (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);
index 8db3908dd6e66f5eb8276bafb5f71b6f6fce1ad6..bd72af4c07aaf96442188d239cc8a4e5bf776d5a 100644 (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 },