diff --git a/src/company_gui.cpp b/src/company_gui.cpp index d1394d0e93..8c14f3c6b7 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1882,7 +1882,7 @@ struct CompanyInfrastructureWindow : Window } } - void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override + void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize) override { if (def_height == 0) { /* Try to open the window with the exact required rows, but clamp to a reasonable limit. */ @@ -1891,7 +1891,7 @@ struct CompanyInfrastructureWindow : Window def_height = this->height + delta * GetCharacterHeight(FS_NORMAL); } - this->Window::FindWindowPlacementAndResize(def_width, def_height); + this->Window::FindWindowPlacementAndResize(def_width, def_height, allow_resize); } void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index eefdf37a29..52cf424881 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1037,7 +1037,7 @@ struct QueryWindow : public Window { this->Window::Close(); } - void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override + void FindWindowPlacementAndResize(int, int, bool) override { /* Position query window over the calling window, ensuring it's within screen bounds. */ this->left = SoftClamp(parent->left + (parent->width / 2) - (this->width / 2), 0, _screen.width - this->width); diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index cfb8b60d2f..b410c3577a 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -330,9 +330,9 @@ struct NetworkChatWindow : public Window { this->Window::Close(); } - void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override + void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override { - Window::FindWindowPlacementAndResize(_toolbar_width, def_height); + Window::FindWindowPlacementAndResize(_toolbar_width, def_height, allow_resize); } /** diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 4f1c8b59b9..fe3eba3ef7 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -2216,7 +2216,7 @@ struct NetworkAskRelayWindow : public Window { } } - void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override + void FindWindowPlacementAndResize(int, int, bool) override { /* Position query window over the calling window, ensuring it's within screen bounds. */ this->left = Clamp(parent->left + (parent->width / 2) - (this->width / 2), 0, _screen.width - this->width); @@ -2309,7 +2309,7 @@ struct NetworkAskSurveyWindow : public Window { } } - void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override + void FindWindowPlacementAndResize(int, int, bool) override { /* Position query window over the calling window, ensuring it's within screen bounds. */ this->left = Clamp(parent->left + (parent->width / 2) - (this->width / 2), 0, _screen.width - this->width); diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index 7dbde04b44..2db43dc391 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -74,9 +74,9 @@ struct StatusBarWindow : Window { return pt; } - void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override + void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override { - Window::FindWindowPlacementAndResize(_toolbar_width, def_height); + Window::FindWindowPlacementAndResize(_toolbar_width, def_height, allow_resize); } void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 1d9c378a0f..a1541b77e9 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -2001,9 +2001,9 @@ struct MainToolbarWindow : Window { DoZoomInOutWindow(ZOOM_NONE, this); } - void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override + void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override { - Window::FindWindowPlacementAndResize(_toolbar_width, def_height); + Window::FindWindowPlacementAndResize(_toolbar_width, def_height, allow_resize); } void OnPaint() override @@ -2340,9 +2340,9 @@ struct ScenarioEditorToolbarWindow : Window { DoZoomInOutWindow(ZOOM_NONE, this); } - void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override + void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override { - Window::FindWindowPlacementAndResize(_toolbar_width, def_height); + Window::FindWindowPlacementAndResize(_toolbar_width, def_height, allow_resize); } void OnPaint() override diff --git a/src/window.cpp b/src/window.cpp index da33f07c33..0465b3c0f3 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -990,7 +990,7 @@ void Window::ReInit(int rx, int ry, bool reposition) if (reposition) { Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number); this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y); - this->FindWindowPlacementAndResize(this->window_desc.GetDefaultWidth(), this->window_desc.GetDefaultHeight()); + this->FindWindowPlacementAndResize(this->window_desc.GetDefaultWidth(), this->window_desc.GetDefaultHeight(), false); } ResizeWindow(this, dx, dy, true, false); @@ -1423,39 +1423,42 @@ void Window::InitializePositionSize(int x, int y, int sm_width, int sm_height) * done here. * @param def_width default width in pixels of the window * @param def_height default height in pixels of the window + * @param allow_resize Set if resizing is permitted. * @see Window::Window(), Window::InitializeData(), Window::InitializePositionSize() */ -void Window::FindWindowPlacementAndResize(int def_width, int def_height) +void Window::FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize) { - def_width = std::max(def_width, this->width); // Don't allow default size to be smaller than smallest size - def_height = std::max(def_height, this->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; - * one can use the same spec for multiple windows and those - * can then determine the real minimum size of the window. */ - if (this->width != def_width || this->height != def_height) { - /* Think about the overlapping toolbars when determining the minimum window size */ - int free_height = _screen.height; - const Window *wt = FindWindowById(WC_STATUS_BAR, 0); - if (wt != nullptr) free_height -= wt->height; - wt = FindWindowById(WC_MAIN_TOOLBAR, 0); - if (wt != nullptr) free_height -= wt->height; + if (allow_resize) { + def_width = std::max(def_width, this->width); // Don't allow default size to be smaller than smallest size + def_height = std::max(def_height, this->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; + * one can use the same spec for multiple windows and those + * can then determine the real minimum size of the window. */ + if (this->width != def_width || this->height != def_height) { + /* Think about the overlapping toolbars when determining the minimum window size */ + int free_height = _screen.height; + const Window *wt = FindWindowById(WC_STATUS_BAR, 0); + if (wt != nullptr) free_height -= wt->height; + wt = FindWindowById(WC_MAIN_TOOLBAR, 0); + if (wt != nullptr) free_height -= wt->height; - int enlarge_x = std::max(std::min(def_width - this->width, _screen.width - this->width), 0); - int enlarge_y = std::max(std::min(def_height - this->height, free_height - this->height), 0); + int enlarge_x = std::max(std::min(def_width - this->width, _screen.width - this->width), 0); + int enlarge_y = std::max(std::min(def_height - this->height, free_height - this->height), 0); - /* X and Y has to go by step.. calculate it. - * The cast to int is necessary else x/y are implicitly casted to - * unsigned int, which won't work. */ - if (this->resize.step_width > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width; - if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height; + /* X and Y has to go by step.. calculate it. + * The cast to int is necessary else x/y are implicitly casted to + * unsigned int, which won't work. */ + if (this->resize.step_width > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width; + if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height; - ResizeWindow(this, enlarge_x, enlarge_y, true, false); - /* ResizeWindow() calls this->OnResize(). */ - } else { - /* Always call OnResize; that way the scrollbars and matrices get initialized. */ - this->OnResize(); + ResizeWindow(this, enlarge_x, enlarge_y, true, false); + /* ResizeWindow() calls this->OnResize(). */ + } else { + /* Always call OnResize; that way the scrollbars and matrices get initialized. */ + this->OnResize(); + } } int nx = this->left; @@ -1744,7 +1747,7 @@ void Window::FinishInitNested(WindowNumber window_number) this->ApplyDefaults(); Point pt = this->OnInitialPosition(this->nested_root->smallest_x, this->nested_root->smallest_y, window_number); this->InitializePositionSize(pt.x, pt.y, this->nested_root->smallest_x, this->nested_root->smallest_y); - this->FindWindowPlacementAndResize(this->window_desc.GetDefaultWidth(), this->window_desc.GetDefaultHeight()); + this->FindWindowPlacementAndResize(this->window_desc.GetDefaultWidth(), this->window_desc.GetDefaultHeight(), true); } /** diff --git a/src/window_gui.h b/src/window_gui.h index 089d1b35ab..4587844380 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -277,7 +277,7 @@ private: protected: void InitializeData(WindowNumber window_number); void InitializePositionSize(int x, int y, int min_width, int min_height); - virtual void FindWindowPlacementAndResize(int def_width, int def_height); + virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize); std::vector scheduled_invalidation_data{}; ///< Data of scheduled OnInvalidateData() calls. bool scheduled_resize = false; ///< Set if window has been resized.