summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-06-28 20:09:40 +0000
committeralberth <alberth@openttd.org>2009-06-28 20:09:40 +0000
commit058bb5d6c301a8aee5a52fa26e6b6fa0c395d57e (patch)
treece9dfdb09a847c6dd3e52aab4da40ade46ec26d3 /src
parent337c707fa1f25bdae7a7fa4044d05ba03a33ee0d (diff)
downloadopenttd-058bb5d6c301a8aee5a52fa26e6b6fa0c395d57e.tar.xz
(svn r16687) -Codechange: Perform re-initialization of windows with nested widgets after a language change.
Diffstat (limited to 'src')
-rw-r--r--src/settings_gui.cpp1
-rw-r--r--src/window.cpp52
-rw-r--r--src/window_func.h2
-rw-r--r--src/window_gui.h1
4 files changed, 56 insertions, 0 deletions
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index da247b73c..126d2df10 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -323,6 +323,7 @@ struct GameOptionsWindow : Window {
CheckForMissingGlyphsInLoadedLanguagePack();
UpdateAllStationVirtCoord();
UpdateAllWaypointSigns();
+ ReInitAllWindows();
MarkWholeScreenDirty();
break;
diff --git a/src/window.cpp b/src/window.cpp
index 38b963bbd..8aaa78d69 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -560,6 +560,48 @@ void SetWindowDirty(const Window *w)
if (w != NULL) w->SetDirty();
}
+/** Re-initialize a window.
+ * @todo Extend the function to handle viewports.
+ */
+void Window::ReInit()
+{
+ if (this->nested_root == NULL) return; // Only nested widget windows can re-initialize.
+
+ this->SetDirty(); // Mark whole current window as dirty.
+
+ /* Save current size. */
+ int window_width = this->width;
+ int window_height = this->height;
+
+ /* Re-initialize the window from the ground up. No need to change the nested_array, as all widgets stay where they are. */
+ this->nested_root->SetupSmallestSize();
+ this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, false);
+ this->width = this->nested_root->smallest_x;
+ this->height = this->nested_root->smallest_y;
+ this->resize.width = this->nested_root->smallest_x;
+ this->resize.height = this->nested_root->smallest_y;
+ this->resize.step_width = this->nested_root->resize_x;
+ this->resize.step_height = this->nested_root->resize_y;
+
+ /* Resize as close to the original size as possible. */
+ window_width = max(window_width, this->width);
+ window_height = max(window_height, this->height);
+ int dx = (this->resize.step_width == 0) ? 0 : window_width - this->width;
+ int dy = (this->resize.step_height == 0) ? 0 : window_height - this->height;
+ /* dx and dy has to go by step.. calculate it.
+ * The cast to int is necessary else dx/dy are implicitly casted to unsigned int, which won't work. */
+ if (this->resize.step_width > 1) dx -= dx % (int)this->resize.step_width;
+ if (this->resize.step_height > 1) dy -= dy % (int)this->resize.step_height;
+
+ if (dx == 0 && dy == 0) return; // No resize needed.
+
+ ResizeWindow(this, dx, dy); // Sets post-resize dirty blocks.
+ Point diff;
+ diff.x = dx;
+ diff.y = dy;
+ this->OnResize(diff);
+}
+
/** Find the Window whose parent pointer points to this window
* @param w parent Window to find child of
* @return a Window pointer that is the child of w, or NULL otherwise */
@@ -2488,6 +2530,16 @@ void HideVitalWindows()
DeleteWindowById(WC_STATUS_BAR, 0);
}
+/** Re-initialize all windows. */
+void ReInitAllWindows()
+{
+ Window *w;
+
+ FOR_ALL_WINDOWS_FROM_BACK(w) {
+ w->ReInit();
+ }
+}
+
/**
* (Re)position main toolbar window at the screen
* @param w Window structure of the main toolbar window, may also be \c NULL
diff --git a/src/window_func.h b/src/window_func.h
index 4ada6b522..7e6684064 100644
--- a/src/window_func.h
+++ b/src/window_func.h
@@ -32,6 +32,8 @@ void DeleteConstructionWindows();
void HideVitalWindows();
void ShowVitalWindows();
+void ReInitAllWindows();
+
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index);
void InvalidateWindow(WindowClass cls, WindowNumber number);
void InvalidateWindowClasses(WindowClass cls);
diff --git a/src/window_gui.h b/src/window_gui.h
index 2821dfbd7..bc3237ce4 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -429,6 +429,7 @@ public:
void DeleteChildWindows() const;
void SetDirty() const;
+ void ReInit();
/*** Event handling ***/