summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/autoreplace_gui.cpp2
-rw-r--r--src/industry_gui.cpp2
-rw-r--r--src/misc_gui.cpp4
-rw-r--r--src/network/network_gui.cpp2
-rw-r--r--src/window.cpp27
-rw-r--r--src/window_gui.h4
6 files changed, 34 insertions, 7 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index 77b01e74f..af5d3d4a6 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -301,6 +301,8 @@ public:
this->caption_color = _local_player;
this->sel_group = id_g;
this->vscroll2.cap = this->vscroll.cap; // these two are always the same
+
+ this->FindWindowPlacementAndResize(desc);
}
virtual void OnPaint()
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 1f38ef499..db1a93e63 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -163,6 +163,8 @@ public:
this->selected_index = 0;
this->selected_type = this->index[0];
this->callback_timer = DAY_TICKS;
+
+ this->FindWindowPlacementAndResize(&_build_industry_desc);
}
virtual void OnPaint()
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 21f06d9e3..132863444 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -184,6 +184,8 @@ public:
DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _m[tile].m6);
DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7);
#undef LANDINFOD_LEVEL
+
+ this->FindWindowPlacementAndResize(&_land_info_desc);
}
};
@@ -1125,6 +1127,8 @@ struct QueryWindow : public Window {
this->widget[QUERY_WIDGET_CAPTION].data = caption;
this->message = message;
this->proc = callback;
+
+ this->FindWindowPlacementAndResize(desc);
}
~QueryWindow()
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 122c601f8..9ef0a88a9 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1038,6 +1038,8 @@ struct NetworkLobbyWindow : public Window {
{
strcpy(_edit_str_net_buf, "");
this->vscroll.cap = 10;
+
+ this->FindWindowPlacementAndResize(desc);
}
virtual void OnPaint()
diff --git a/src/window.cpp b/src/window.cpp
index 2dc00a318..3efdb2df3 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -887,15 +887,13 @@ static void AssignWidgetToWindow(Window *w, const Widget *widget)
* @param y offset in pixels from the top of the screen
* @param min_width minimum width in pixels of the window
* @param min_height minimum height in pixels of the window
- * @param def_width default width in pixels of the window
- * @param def_height default height in pixels of the window
* @param *proc see WindowProc function to call when any messages/updates happen to the window
* @param cls see WindowClass class of the window, used for identification and grouping
* @param *widget see Widget pointer to the window layout and various elements
* @param window_number number being assigned to the new window
* @param data the data to be given during the WE_CREATE message
* @return Window pointer of the newly created window */
-void Window::Initialize(int x, int y, int min_width, int min_height, int def_width, int def_height,
+void Window::Initialize(int x, int y, int min_width, int min_height,
WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data)
{
/* We have run out of windows, close one and use that as the place for our new one */
@@ -947,7 +945,15 @@ void Window::Initialize(int x, int y, int min_width, int min_height, int def_wid
e.event = WE_CREATE;
e.we.create.data = data;
this->HandleWindowEvent(&e);
+}
+/**
+ * Find a nice spot for this window and resize it towards the default size.
+ * @param def_width default width in pixels of the window
+ * @param def_height default height in pixels of the window
+ */
+void Window::FindWindowPlacementAndResize(int def_width, int def_height)
+{
/* Try to make windows smaller when our window is too small.
* w->(width|height) is normally the same as min_(width|height),
* but this way the GUIs can be made a little more dynamic;
@@ -987,7 +993,7 @@ void Window::Initialize(int x, int y, int min_width, int min_height, int def_wid
if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
- ny = max(ny, (wt == NULL || this == wt || y == 0) ? 0 : wt->height);
+ ny = max(ny, (wt == NULL || this == wt || this->top == 0) ? 0 : wt->height);
nx = max(nx, 0);
if (this->viewport != NULL) {
@@ -1000,6 +1006,11 @@ void Window::Initialize(int x, int y, int min_width, int min_height, int def_wid
this->SetDirty();
}
+void Window::FindWindowPlacementAndResize(const WindowDesc *desc)
+{
+ this->FindWindowPlacementAndResize(desc->default_width, desc->default_height);
+}
+
/**
* Open a new window. If there is no space for a new window, close an open
* window. Try to avoid stickied windows, but if there is no else, close one of
@@ -1016,7 +1027,9 @@ void Window::Initialize(int x, int y, int min_width, int min_height, int def_wid
*/
Window::Window(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const Widget *widget, void *data)
{
- this->Initialize(x, y, width, height, width, height, proc, cls, widget, 0, data);
+ this->Initialize(x, y, width, height, proc, cls, widget, 0, data);
+
+ if (proc != NULL) this->FindWindowPlacementAndResize(width, height);
}
@@ -1209,8 +1222,10 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int window_number)
Window::Window(const WindowDesc *desc, void *data, WindowNumber window_number)
{
Point pt = LocalGetWindowPlacement(desc, window_number);
- this->Initialize(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data);
+ this->Initialize(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->proc, desc->cls, desc->widgets, window_number, data);
this->desc_flags = desc->flags;
+
+ if (desc->proc != NULL) this->FindWindowPlacementAndResize(desc->default_width, desc->default_height);
}
/** Do a search for a window at specific coordinates. For this we start
diff --git a/src/window_gui.h b/src/window_gui.h
index 5872c6809..98431ebac 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -279,8 +279,10 @@ private:
void HandleWindowEvent(WindowEvent *e);
protected:
- void Initialize(int x, int y, int min_width, int min_height, int def_width, int def_height,
+ void Initialize(int x, int y, int min_width, int min_height,
WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data);
+ void FindWindowPlacementAndResize(int def_width, int def_height);
+ void FindWindowPlacementAndResize(const WindowDesc *desc);
public:
Window(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const Widget *widget, void *data = NULL);