From 4f5e179222bd497aad541069a57f38fd5c7deb5e Mon Sep 17 00:00:00 2001 From: Noseey Date: Sun, 22 Feb 2026 00:20:27 +0100 Subject: [PATCH 01/24] window scaling limit - unfinished version. .. drawing ScaleIfs directly into the windows. Issues: - not all controls are reached (e. g. Scrollbar inside table) - requires "true value" of size to recalculate later when window is resized. --- libs/s25main/RescaleWindowProp.h | 35 +++++-- libs/s25main/Window.cpp | 96 ++++++++++++------- libs/s25main/Window.h | 20 ++-- libs/s25main/controls/ctrlComboBox.cpp | 2 +- libs/s25main/controls/ctrlScrollBar.cpp | 1 + libs/s25main/controls/ctrlTable.cpp | 1 + libs/s25main/desktops/Desktop.cpp | 1 + .../s25main/desktops/dskCampaignSelection.cpp | 5 +- 8 files changed, 111 insertions(+), 50 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 73894e2916..9b17bb98f0 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -12,7 +12,7 @@ struct ScaleWindowPropUp ScaleWindowPropUp(const Extent& size) : size(size) {} template - static T_Pt scale(const T_Pt& value, const Extent& size); + static T_Pt scale(const T_Pt& value, const Extent& size, const unsigned limfactor); template T_Pt operator()(const T_Pt& value) const; }; @@ -25,18 +25,28 @@ struct RescaleWindowProp /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template T_Pt operator()(const T_Pt& oldValue) const; + template + T_Pt operator()(const T_Pt& trueValue, const unsigned limfactor) const; }; template -inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale) +inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const unsigned limfactor) { - return T_Pt(value * sizeToScale / Extent(800, 600)); + T_Pt scaledValue(value * sizeToScale / Extent(800, 600)); + if(limfactor > 0) + { + if(scaledValue.x > value.x << limfactor) + scaledValue.x = value.x << limfactor; + if(scaledValue.y > value.y << limfactor) + scaledValue.y = value.y << limfactor; + } + return scaledValue; } template inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const { - return scale(value, size); + return scale(value, size, 0); } template @@ -44,10 +54,23 @@ inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue) const { T_Pt realValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); // Check for rounding errors - T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize); + T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize, 0); if(checkValue.x < oldValue.x) realValue.x++; if(checkValue.y < oldValue.y) realValue.y++; - return ScaleWindowPropUp::scale(realValue, newSize); + return ScaleWindowPropUp::scale(realValue, newSize, 0); +} + +template +inline T_Pt RescaleWindowProp::operator()(const T_Pt& trueValue, const unsigned limfactor) const +{ + T_Pt realValue(trueValue.x, trueValue.y); + // Check for rounding errors + T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize, limfactor); + if(checkValue.x < trueValue.x) + realValue.x++; + if(checkValue.y < trueValue.y) + realValue.y++; + return ScaleWindowPropUp::scale(realValue, newSize, limfactor); } diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 39c6b34a14..6616c93b56 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -18,8 +18,8 @@ #include Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size) - : parent_(parent), id_(id), pos_(pos), size_(size), active_(false), visible_(true), scale_(false), - isInMouseRelay(false), animations_(this) + : parent_(parent), id_(id), pos_(pos), size_(size), true_size_(size),active_(false), visible_(true), + scale_(false), limfactor_(0), isInMouseRelay(false), animations_(this) {} Window::~Window() @@ -65,6 +65,21 @@ Extent Window::GetSize() const return size_; } +Extent Window::GetTrueSize() const +{ + return true_size_; +} + +void Window::SetScale(bool scale) +{ + scale_ = scale; +} + +unsigned Window::GetLimFactor() const +{ + return limfactor_; +} + Rect Window::GetDrawRect() const { return Rect(GetDrawPos(), GetSize()); @@ -193,6 +208,14 @@ void Window::SetPos(const DrawPoint& newPos) pos_ = newPos; } +// void Window::Resize(const Extent& newSize) +// { +// if(scale_) +// size_ = ScaleWindowPropUp::scale(true_size_, VIDEODRIVER.GetRenderSize(), limfactor_); +// else +// size_ = newSize; +// } + /// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht? bool Window::IsMessageRelayAllowed() const { @@ -214,25 +237,25 @@ void Window::DeleteCtrl(unsigned id) ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, BuildingType type, const Nation nation, unsigned short size, const std::string& tooltip) { - return AddCtrl(new ctrlBuildingIcon(this, id, ScaleIf(pos), type, nation, ScaleIf(Extent(size, 0)).x, tooltip)); + return AddCtrl(new ctrlBuildingIcon(this, id, pos, type, nation, Extent(size, 0).x, tooltip)); } ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, tooltip)); + return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip)); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const unsigned fillColor, const std::string& tooltip) { - return AddCtrl(new ctrlColorButton(this, id, ScaleIf(pos), ScaleIf(size), tc, fillColor, tooltip)); + return AddCtrl(new ctrlColorButton(this, id, pos, size, tc, fillColor, tooltip)); } ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, ITexture* const image, const std::string& tooltip) { - return AddCtrl(new ctrlImageButton(this, id, ScaleIf(pos), ScaleIf(size), tc, image, tooltip)); + return AddCtrl(new ctrlImageButton(this, id, pos, size, tc, image, tooltip)); } ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -244,37 +267,37 @@ ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Exte ctrlChat* Window::AddChatCtrl(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font) { - return AddCtrl(new ctrlChat(this, id, ScaleIf(pos), ScaleIf(size), tc, font)); + return AddCtrl(new ctrlChat(this, id, pos, size, tc, font)); } ctrlCheck* Window::AddCheckBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const std::string& text, const glFont* font, bool readonly) { - return AddCtrl(new ctrlCheck(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, readonly)); + return AddCtrl(new ctrlCheck(this, id, pos, size, tc, text, font, readonly)); } ctrlComboBox* Window::AddComboBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, unsigned short max_list_height, bool readonly) { - return AddCtrl(new ctrlComboBox(this, id, ScaleIf(pos), ScaleIf(size), tc, font, max_list_height, readonly)); + return AddCtrl(new ctrlComboBox(this, id, pos, size, tc, font, max_list_height, readonly)); } ctrlDeepening* Window::AddTextDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const std::string& text, const glFont* font, unsigned color, FontStyle style) { - return AddCtrl(new ctrlTextDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, color, style)); + return AddCtrl(new ctrlTextDeepening(this, id, pos, size, tc, text, font, color, style)); } ctrlDeepening* Window::AddColorDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, unsigned fillColor) { - return AddCtrl(new ctrlColorDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, fillColor)); + return AddCtrl(new ctrlColorDeepening(this, id, pos, size, tc, fillColor)); } ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, ITexture* image) { - return AddCtrl(new ctrlImageDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, image)); + return AddCtrl(new ctrlImageDeepening(this, id, pos, size, tc, image)); } ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, @@ -287,7 +310,7 @@ ctrlEdit* Window::AddEdit(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short maxlength, bool password, bool disabled, bool notify) { return AddCtrl( - new ctrlEdit(this, id, ScaleIf(pos), ScaleIf(size), tc, font, maxlength, password, disabled, notify)); + new ctrlEdit(this, id, pos, size, tc, font, maxlength, password, disabled, notify)); } ctrlGroup* Window::AddGroup(unsigned id) @@ -297,7 +320,7 @@ ctrlGroup* Window::AddGroup(unsigned id) ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, ITexture* image, const std::string& tooltip) { - return AddCtrl(new ctrlImage(this, id, ScaleIf(pos), image, tooltip)); + return AddCtrl(new ctrlImage(this, id, pos, image, tooltip)); } ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitmap* image, const std::string& tooltip) @@ -307,13 +330,13 @@ ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitm ctrlList* Window::AddList(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font) { - return AddCtrl(new ctrlList(this, id, ScaleIf(pos), ScaleIf(size), tc, font)); + return AddCtrl(new ctrlList(this, id, pos, size, tc, font)); } ctrlMultiline* Window::AddMultiline(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, FontStyle format) { - return AddCtrl(new ctrlMultiline(this, id, ScaleIf(pos), ScaleIf(size), tc, font, format)); + return AddCtrl(new ctrlMultiline(this, id, pos, size, tc, font, format)); } /** @@ -345,7 +368,7 @@ ctrlMultiSelectGroup* Window::AddMultiSelectGroup(unsigned id, GroupSelectType s ctrlPercent* Window::AddPercent(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, unsigned text_color, const glFont* font, const unsigned short* percentage) { - return AddCtrl(new ctrlPercent(this, id, ScaleIf(pos), ScaleIf(size), tc, text_color, font, percentage)); + return AddCtrl(new ctrlPercent(this, id, pos, size, tc, text_color, font, percentage)); } ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, @@ -353,21 +376,21 @@ ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Exten const std::string& tooltip, const Extent& padding, unsigned force_color, const std::string& button_minus_tooltip, const std::string& button_plus_tooltip) { - return AddCtrl(new ctrlProgress(this, id, ScaleIf(pos), ScaleIf(size), tc, button_minus, button_plus, maximum, + return AddCtrl(new ctrlProgress(this, id, pos, size, tc, button_minus, button_plus, maximum, padding, force_color, tooltip, button_minus_tooltip, button_plus_tooltip)); } ctrlScrollBar* Window::AddScrollBar(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short button_height, TextureColor tc, unsigned short page_size) { - button_height = ScaleIf(Extent(0, button_height)).y; + button_height = Extent(0, button_height).y; - return AddCtrl(new ctrlScrollBar(this, id, ScaleIf(pos), ScaleIf(size), button_height, tc, page_size)); + return AddCtrl(new ctrlScrollBar(this, id, pos, size, button_height, tc, page_size)); } ctrlTab* Window::AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short width) { - return AddCtrl(new ctrlTab(this, id, ScaleIf(pos), ScaleIf(Extent(width, 0)).x)); + return AddCtrl(new ctrlTab(this, id, pos, Extent(width, 0).x)); } /** @@ -377,7 +400,7 @@ ctrlTab* Window::AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short wi ctrlTable* Window::AddTable(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, std::vector columns) { - return AddCtrl(new ctrlTable(this, id, ScaleIf(pos), ScaleIf(size), tc, font, std::move(columns))); + return AddCtrl(new ctrlTable(this, id, pos, size, tc, font, std::move(columns))); } ctrlTimer* Window::AddTimer(unsigned id, std::chrono::milliseconds timeout) @@ -404,13 +427,13 @@ ctrlTimer* Window::AddTimer(unsigned id, std::chrono::milliseconds timeout) ctrlText* Window::AddText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, FontStyle format, const glFont* font) { - return AddCtrl(new ctrlText(this, id, ScaleIf(pos), text, color, format, font)); + return AddCtrl(new ctrlText(this, id, pos, text, color, format, font)); } ctrlMapSelection* Window::AddMapSelection(unsigned id, const DrawPoint& pos, const Extent& size, const SelectionMapInputData& inputData) { - return AddCtrl(new ctrlMapSelection(this, id, ScaleIf(pos), ScaleIf(size), inputData)); + return AddCtrl(new ctrlMapSelection(this, id, pos, size, inputData)); } TextFormatSetter Window::AddFormattedText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, @@ -427,7 +450,7 @@ ctrlVarDeepening* Window::AddVarDeepening(unsigned id, const DrawPoint& pos, con va_start(liste, parameters); auto* ctrl = - new ctrlVarDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, formatstr, font, color, parameters, liste); + new ctrlVarDeepening(this, id, pos, size, tc, formatstr, font, color, parameters, liste); va_end(liste); @@ -458,7 +481,7 @@ ctrlVarText* Window::AddVarText(unsigned id, const DrawPoint& pos, const std::st va_list liste; va_start(liste, parameters); - auto* ctrl = new ctrlVarText(this, id, ScaleIf(pos), formatstr, color, format, font, parameters, liste); + auto* ctrl = new ctrlVarText(this, id, pos, formatstr, color, format, font, parameters, liste); va_end(liste); @@ -468,7 +491,7 @@ ctrlVarText* Window::AddVarText(unsigned id, const DrawPoint& pos, const std::st ctrlPreviewMinimap* Window::AddPreviewMinimap(const unsigned id, const DrawPoint& pos, const Extent& size, libsiedler2::ArchivItem_Map* const map) { - return AddCtrl(new ctrlPreviewMinimap(this, id, ScaleIf(pos), ScaleIf(size), map)); + return AddCtrl(new ctrlPreviewMinimap(this, id, pos, size, map)); } void Window::Draw3D(const Rect& rect, TextureColor tc, bool elevated, bool highlighted, bool illuminated, @@ -540,7 +563,7 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(!ctrl) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) - Extent newSize = rescale(ctrl->GetSize()); + Extent newSize = rescale(ctrl->GetTrueSize(), ctrl->GetLimFactor()); ctrl->SetPos(rescale(ctrl->GetPos())); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); @@ -548,21 +571,24 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) animations_.onRescale(sr); } -template -T_Pt Window::Scale(const T_Pt& pt) +void Window::Scale() { - return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize()); + if(scale_) + { + pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), 0); + size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limfactor_); + } } template -T_Pt Window::ScaleIf(const T_Pt& pt) const +T_Pt Window::ScaleIf(const T_Pt& pt, const unsigned limfactor) const { - return scale_ ? Scale(pt) : pt; + return scale_ ? ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactor) : pt; } // Inlining removes those. so add it here -template DrawPoint Window::ScaleIf(const DrawPoint&) const; -template Extent Window::ScaleIf(const Extent&) const; +template DrawPoint Window::ScaleIf(const DrawPoint&, const unsigned limfactor) const; +template Extent Window::ScaleIf(const Extent&, const unsigned limfactor) const; bool Window::IsInLockedRegion(const Position& pos, const Window* exception) const { diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 437532c762..18bc006dba 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -75,11 +75,15 @@ class Window DrawPoint GetDrawPos() const; /// Get the size of the window Extent GetSize() const; + Extent GetTrueSize() const; + /// Get limitation factor + unsigned GetLimFactor() const; /// gets the extent of the window in absolute coordinates Rect GetDrawRect() const; /// Get the actual extents of the rect (might be different to the draw rect if the window resizes according to /// content) virtual Rect GetBoundaryRect() const; + /// TODO: Check components that overlay this function /// setzt die Größe des Fensters virtual void Resize(const Extent& newSize) { size_ = newSize; } /// setzt die Breite des Fensters @@ -286,14 +290,14 @@ class Window friend constexpr auto maxEnumValue(ButtonState) { return ButtonState::Pressed; } using ControlMap = std::map; - /// scales X- und Y values to fit the screen - template - static T_Pt Scale(const T_Pt& pt); /// Scales the value when scale_ is true, else returns the value template - T_Pt ScaleIf(const T_Pt& pt) const; + T_Pt ScaleIf(const T_Pt& pt, const unsigned limfactor) const; /// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht. - void SetScale(bool scale = true) { this->scale_ = scale; } + void SetScale(bool scale); + void Scale(); + /// setzt the limiting factor for scaling + void SetLimFactor(unsigned int limfactor) { this->limfactor_ = std::clamp(limfactor,(unsigned) 0, (unsigned) 3); } /// zeichnet das Fenster. virtual void Draw_(); /// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht? @@ -304,9 +308,11 @@ class Window unsigned id_; /// ID des Fensters. DrawPoint pos_; /// Position des Fensters. Extent size_; /// Höhe des Fensters. + Extent true_size_; /// Enscaled size of the Window. bool active_; /// Fenster aktiv? bool visible_; /// Fenster sichtbar? bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? + unsigned limfactor_; /// Limiting factor 1-3 considered for scaling, disabled when 0. TODO: Factor shall be multiple of base size. std::map lockedAreas_; /// gesperrte Regionen des Fensters. std::vector tofreeAreas_; @@ -321,7 +327,9 @@ inline T* Window::AddCtrl(T* ctrl) RTTR_Assert(childIdToWnd_.find(ctrl->GetID()) == childIdToWnd_.end()); childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); - ctrl->scale_ = scale_; + ctrl->SetScale(scale_); + ctrl->SetLimFactor(limfactor_); + ctrl->Scale(); ctrl->SetActive(active_); return ctrl; diff --git a/libs/s25main/controls/ctrlComboBox.cpp b/libs/s25main/controls/ctrlComboBox.cpp index d31691f519..4933a5255c 100644 --- a/libs/s25main/controls/ctrlComboBox.cpp +++ b/libs/s25main/controls/ctrlComboBox.cpp @@ -51,7 +51,7 @@ void ctrlComboBox::Resize(const Extent& newSize) { // zu große geworden? listSize.y += font->getHeight(); - unsigned short scaledMaxHeight = ScaleIf(Extent(0, max_list_height)).y; + unsigned short scaledMaxHeight = Extent(0, max_list_height).y; if(listSize.y > scaledMaxHeight) { diff --git a/libs/s25main/controls/ctrlScrollBar.cpp b/libs/s25main/controls/ctrlScrollBar.cpp index 31103bca48..510b95c43f 100644 --- a/libs/s25main/controls/ctrlScrollBar.cpp +++ b/libs/s25main/controls/ctrlScrollBar.cpp @@ -157,6 +157,7 @@ void ctrlScrollBar::SetPageSize(unsigned short pagesize) } } +// TODO: Update resize void ctrlScrollBar::Resize(const Extent& newSize) { Window::Resize(newSize); diff --git a/libs/s25main/controls/ctrlTable.cpp b/libs/s25main/controls/ctrlTable.cpp index ba9a843e77..089b6467dc 100644 --- a/libs/s25main/controls/ctrlTable.cpp +++ b/libs/s25main/controls/ctrlTable.cpp @@ -453,6 +453,7 @@ void ctrlTable::Msg_ScrollShow(const unsigned /*ctrl_id*/, const bool /*visible* ResetButtonWidths(); } +// TODO: Update resize and Reset Buttons void ctrlTable::ResetButtonWidths() { auto addColumnWidth = [](unsigned cur, const Column& c) { return cur + c.width; }; diff --git a/libs/s25main/desktops/Desktop.cpp b/libs/s25main/desktops/Desktop.cpp index 5a4db4253b..f7bfa85388 100644 --- a/libs/s25main/desktops/Desktop.cpp +++ b/libs/s25main/desktops/Desktop.cpp @@ -25,6 +25,7 @@ Desktop::Desktop(glArchivItem_Bitmap* background) : Window(nullptr, 0, DrawPoint::all(0), VIDEODRIVER.GetRenderSize()), background(background), lastFPS_(0) { SetScale(true); + SetLimFactor(0); SetFpsDisplay(true); // By default limit the maximum frame rate to 60 FPS - used for main menu if(SETTINGS.video.framerate < 0) diff --git a/libs/s25main/desktops/dskCampaignSelection.cpp b/libs/s25main/desktops/dskCampaignSelection.cpp index 88c970485b..e57209d91f 100644 --- a/libs/s25main/desktops/dskCampaignSelection.cpp +++ b/libs/s25main/desktops/dskCampaignSelection.cpp @@ -193,11 +193,12 @@ void dskCampaignSelection::Draw_() { Desktop::Draw_(); + // TODO: Check how to call Scale from here. // replace this by AddImageButton as soon as it can handle this scenario correctly if(campaignImage_) { - campaignImage_->DrawFull(Rect(ScaleIf(DrawPoint(secondColumnOffsetX, getColumnOffsetY())), - ScaleIf(Extent(secondColumnExtentX, campaignImageExtentY)))); + campaignImage_->DrawFull(Rect(ScaleIf(DrawPoint(secondColumnOffsetX, getColumnOffsetY()),0), + ScaleIf(Extent(secondColumnExtentX, campaignImageExtentY), 0))); } } From bedbb7e33a8a481dc09ff081ae6bd8d188917f2a Mon Sep 17 00:00:00 2001 From: Noseey Date: Sun, 22 Feb 2026 00:20:42 +0100 Subject: [PATCH 02/24] Revert "window scaling limit - unfinished version." This reverts commit 4f5e179222bd497aad541069a57f38fd5c7deb5e. --- libs/s25main/RescaleWindowProp.h | 35 ++----- libs/s25main/Window.cpp | 96 +++++++------------ libs/s25main/Window.h | 20 ++-- libs/s25main/controls/ctrlComboBox.cpp | 2 +- libs/s25main/controls/ctrlScrollBar.cpp | 1 - libs/s25main/controls/ctrlTable.cpp | 1 - libs/s25main/desktops/Desktop.cpp | 1 - .../s25main/desktops/dskCampaignSelection.cpp | 5 +- 8 files changed, 50 insertions(+), 111 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 9b17bb98f0..73894e2916 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -12,7 +12,7 @@ struct ScaleWindowPropUp ScaleWindowPropUp(const Extent& size) : size(size) {} template - static T_Pt scale(const T_Pt& value, const Extent& size, const unsigned limfactor); + static T_Pt scale(const T_Pt& value, const Extent& size); template T_Pt operator()(const T_Pt& value) const; }; @@ -25,28 +25,18 @@ struct RescaleWindowProp /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template T_Pt operator()(const T_Pt& oldValue) const; - template - T_Pt operator()(const T_Pt& trueValue, const unsigned limfactor) const; }; template -inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const unsigned limfactor) +inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale) { - T_Pt scaledValue(value * sizeToScale / Extent(800, 600)); - if(limfactor > 0) - { - if(scaledValue.x > value.x << limfactor) - scaledValue.x = value.x << limfactor; - if(scaledValue.y > value.y << limfactor) - scaledValue.y = value.y << limfactor; - } - return scaledValue; + return T_Pt(value * sizeToScale / Extent(800, 600)); } template inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const { - return scale(value, size, 0); + return scale(value, size); } template @@ -54,23 +44,10 @@ inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue) const { T_Pt realValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); // Check for rounding errors - T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize, 0); + T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize); if(checkValue.x < oldValue.x) realValue.x++; if(checkValue.y < oldValue.y) realValue.y++; - return ScaleWindowPropUp::scale(realValue, newSize, 0); -} - -template -inline T_Pt RescaleWindowProp::operator()(const T_Pt& trueValue, const unsigned limfactor) const -{ - T_Pt realValue(trueValue.x, trueValue.y); - // Check for rounding errors - T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize, limfactor); - if(checkValue.x < trueValue.x) - realValue.x++; - if(checkValue.y < trueValue.y) - realValue.y++; - return ScaleWindowPropUp::scale(realValue, newSize, limfactor); + return ScaleWindowPropUp::scale(realValue, newSize); } diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 6616c93b56..39c6b34a14 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -18,8 +18,8 @@ #include Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size) - : parent_(parent), id_(id), pos_(pos), size_(size), true_size_(size),active_(false), visible_(true), - scale_(false), limfactor_(0), isInMouseRelay(false), animations_(this) + : parent_(parent), id_(id), pos_(pos), size_(size), active_(false), visible_(true), scale_(false), + isInMouseRelay(false), animations_(this) {} Window::~Window() @@ -65,21 +65,6 @@ Extent Window::GetSize() const return size_; } -Extent Window::GetTrueSize() const -{ - return true_size_; -} - -void Window::SetScale(bool scale) -{ - scale_ = scale; -} - -unsigned Window::GetLimFactor() const -{ - return limfactor_; -} - Rect Window::GetDrawRect() const { return Rect(GetDrawPos(), GetSize()); @@ -208,14 +193,6 @@ void Window::SetPos(const DrawPoint& newPos) pos_ = newPos; } -// void Window::Resize(const Extent& newSize) -// { -// if(scale_) -// size_ = ScaleWindowPropUp::scale(true_size_, VIDEODRIVER.GetRenderSize(), limfactor_); -// else -// size_ = newSize; -// } - /// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht? bool Window::IsMessageRelayAllowed() const { @@ -237,25 +214,25 @@ void Window::DeleteCtrl(unsigned id) ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, BuildingType type, const Nation nation, unsigned short size, const std::string& tooltip) { - return AddCtrl(new ctrlBuildingIcon(this, id, pos, type, nation, Extent(size, 0).x, tooltip)); + return AddCtrl(new ctrlBuildingIcon(this, id, ScaleIf(pos), type, nation, ScaleIf(Extent(size, 0)).x, tooltip)); } ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip)); + return AddCtrl(new ctrlTextButton(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, tooltip)); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const unsigned fillColor, const std::string& tooltip) { - return AddCtrl(new ctrlColorButton(this, id, pos, size, tc, fillColor, tooltip)); + return AddCtrl(new ctrlColorButton(this, id, ScaleIf(pos), ScaleIf(size), tc, fillColor, tooltip)); } ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, ITexture* const image, const std::string& tooltip) { - return AddCtrl(new ctrlImageButton(this, id, pos, size, tc, image, tooltip)); + return AddCtrl(new ctrlImageButton(this, id, ScaleIf(pos), ScaleIf(size), tc, image, tooltip)); } ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -267,37 +244,37 @@ ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Exte ctrlChat* Window::AddChatCtrl(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font) { - return AddCtrl(new ctrlChat(this, id, pos, size, tc, font)); + return AddCtrl(new ctrlChat(this, id, ScaleIf(pos), ScaleIf(size), tc, font)); } ctrlCheck* Window::AddCheckBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const std::string& text, const glFont* font, bool readonly) { - return AddCtrl(new ctrlCheck(this, id, pos, size, tc, text, font, readonly)); + return AddCtrl(new ctrlCheck(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, readonly)); } ctrlComboBox* Window::AddComboBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, unsigned short max_list_height, bool readonly) { - return AddCtrl(new ctrlComboBox(this, id, pos, size, tc, font, max_list_height, readonly)); + return AddCtrl(new ctrlComboBox(this, id, ScaleIf(pos), ScaleIf(size), tc, font, max_list_height, readonly)); } ctrlDeepening* Window::AddTextDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const std::string& text, const glFont* font, unsigned color, FontStyle style) { - return AddCtrl(new ctrlTextDeepening(this, id, pos, size, tc, text, font, color, style)); + return AddCtrl(new ctrlTextDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, color, style)); } ctrlDeepening* Window::AddColorDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, unsigned fillColor) { - return AddCtrl(new ctrlColorDeepening(this, id, pos, size, tc, fillColor)); + return AddCtrl(new ctrlColorDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, fillColor)); } ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, ITexture* image) { - return AddCtrl(new ctrlImageDeepening(this, id, pos, size, tc, image)); + return AddCtrl(new ctrlImageDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, image)); } ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, @@ -310,7 +287,7 @@ ctrlEdit* Window::AddEdit(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short maxlength, bool password, bool disabled, bool notify) { return AddCtrl( - new ctrlEdit(this, id, pos, size, tc, font, maxlength, password, disabled, notify)); + new ctrlEdit(this, id, ScaleIf(pos), ScaleIf(size), tc, font, maxlength, password, disabled, notify)); } ctrlGroup* Window::AddGroup(unsigned id) @@ -320,7 +297,7 @@ ctrlGroup* Window::AddGroup(unsigned id) ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, ITexture* image, const std::string& tooltip) { - return AddCtrl(new ctrlImage(this, id, pos, image, tooltip)); + return AddCtrl(new ctrlImage(this, id, ScaleIf(pos), image, tooltip)); } ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitmap* image, const std::string& tooltip) @@ -330,13 +307,13 @@ ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitm ctrlList* Window::AddList(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font) { - return AddCtrl(new ctrlList(this, id, pos, size, tc, font)); + return AddCtrl(new ctrlList(this, id, ScaleIf(pos), ScaleIf(size), tc, font)); } ctrlMultiline* Window::AddMultiline(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, FontStyle format) { - return AddCtrl(new ctrlMultiline(this, id, pos, size, tc, font, format)); + return AddCtrl(new ctrlMultiline(this, id, ScaleIf(pos), ScaleIf(size), tc, font, format)); } /** @@ -368,7 +345,7 @@ ctrlMultiSelectGroup* Window::AddMultiSelectGroup(unsigned id, GroupSelectType s ctrlPercent* Window::AddPercent(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, unsigned text_color, const glFont* font, const unsigned short* percentage) { - return AddCtrl(new ctrlPercent(this, id, pos, size, tc, text_color, font, percentage)); + return AddCtrl(new ctrlPercent(this, id, ScaleIf(pos), ScaleIf(size), tc, text_color, font, percentage)); } ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, @@ -376,21 +353,21 @@ ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Exten const std::string& tooltip, const Extent& padding, unsigned force_color, const std::string& button_minus_tooltip, const std::string& button_plus_tooltip) { - return AddCtrl(new ctrlProgress(this, id, pos, size, tc, button_minus, button_plus, maximum, + return AddCtrl(new ctrlProgress(this, id, ScaleIf(pos), ScaleIf(size), tc, button_minus, button_plus, maximum, padding, force_color, tooltip, button_minus_tooltip, button_plus_tooltip)); } ctrlScrollBar* Window::AddScrollBar(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short button_height, TextureColor tc, unsigned short page_size) { - button_height = Extent(0, button_height).y; + button_height = ScaleIf(Extent(0, button_height)).y; - return AddCtrl(new ctrlScrollBar(this, id, pos, size, button_height, tc, page_size)); + return AddCtrl(new ctrlScrollBar(this, id, ScaleIf(pos), ScaleIf(size), button_height, tc, page_size)); } ctrlTab* Window::AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short width) { - return AddCtrl(new ctrlTab(this, id, pos, Extent(width, 0).x)); + return AddCtrl(new ctrlTab(this, id, ScaleIf(pos), ScaleIf(Extent(width, 0)).x)); } /** @@ -400,7 +377,7 @@ ctrlTab* Window::AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short wi ctrlTable* Window::AddTable(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, std::vector columns) { - return AddCtrl(new ctrlTable(this, id, pos, size, tc, font, std::move(columns))); + return AddCtrl(new ctrlTable(this, id, ScaleIf(pos), ScaleIf(size), tc, font, std::move(columns))); } ctrlTimer* Window::AddTimer(unsigned id, std::chrono::milliseconds timeout) @@ -427,13 +404,13 @@ ctrlTimer* Window::AddTimer(unsigned id, std::chrono::milliseconds timeout) ctrlText* Window::AddText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, FontStyle format, const glFont* font) { - return AddCtrl(new ctrlText(this, id, pos, text, color, format, font)); + return AddCtrl(new ctrlText(this, id, ScaleIf(pos), text, color, format, font)); } ctrlMapSelection* Window::AddMapSelection(unsigned id, const DrawPoint& pos, const Extent& size, const SelectionMapInputData& inputData) { - return AddCtrl(new ctrlMapSelection(this, id, pos, size, inputData)); + return AddCtrl(new ctrlMapSelection(this, id, ScaleIf(pos), ScaleIf(size), inputData)); } TextFormatSetter Window::AddFormattedText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, @@ -450,7 +427,7 @@ ctrlVarDeepening* Window::AddVarDeepening(unsigned id, const DrawPoint& pos, con va_start(liste, parameters); auto* ctrl = - new ctrlVarDeepening(this, id, pos, size, tc, formatstr, font, color, parameters, liste); + new ctrlVarDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, formatstr, font, color, parameters, liste); va_end(liste); @@ -481,7 +458,7 @@ ctrlVarText* Window::AddVarText(unsigned id, const DrawPoint& pos, const std::st va_list liste; va_start(liste, parameters); - auto* ctrl = new ctrlVarText(this, id, pos, formatstr, color, format, font, parameters, liste); + auto* ctrl = new ctrlVarText(this, id, ScaleIf(pos), formatstr, color, format, font, parameters, liste); va_end(liste); @@ -491,7 +468,7 @@ ctrlVarText* Window::AddVarText(unsigned id, const DrawPoint& pos, const std::st ctrlPreviewMinimap* Window::AddPreviewMinimap(const unsigned id, const DrawPoint& pos, const Extent& size, libsiedler2::ArchivItem_Map* const map) { - return AddCtrl(new ctrlPreviewMinimap(this, id, pos, size, map)); + return AddCtrl(new ctrlPreviewMinimap(this, id, ScaleIf(pos), ScaleIf(size), map)); } void Window::Draw3D(const Rect& rect, TextureColor tc, bool elevated, bool highlighted, bool illuminated, @@ -563,7 +540,7 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(!ctrl) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) - Extent newSize = rescale(ctrl->GetTrueSize(), ctrl->GetLimFactor()); + Extent newSize = rescale(ctrl->GetSize()); ctrl->SetPos(rescale(ctrl->GetPos())); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); @@ -571,24 +548,21 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) animations_.onRescale(sr); } -void Window::Scale() +template +T_Pt Window::Scale(const T_Pt& pt) { - if(scale_) - { - pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), 0); - size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limfactor_); - } + return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize()); } template -T_Pt Window::ScaleIf(const T_Pt& pt, const unsigned limfactor) const +T_Pt Window::ScaleIf(const T_Pt& pt) const { - return scale_ ? ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactor) : pt; + return scale_ ? Scale(pt) : pt; } // Inlining removes those. so add it here -template DrawPoint Window::ScaleIf(const DrawPoint&, const unsigned limfactor) const; -template Extent Window::ScaleIf(const Extent&, const unsigned limfactor) const; +template DrawPoint Window::ScaleIf(const DrawPoint&) const; +template Extent Window::ScaleIf(const Extent&) const; bool Window::IsInLockedRegion(const Position& pos, const Window* exception) const { diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 18bc006dba..437532c762 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -75,15 +75,11 @@ class Window DrawPoint GetDrawPos() const; /// Get the size of the window Extent GetSize() const; - Extent GetTrueSize() const; - /// Get limitation factor - unsigned GetLimFactor() const; /// gets the extent of the window in absolute coordinates Rect GetDrawRect() const; /// Get the actual extents of the rect (might be different to the draw rect if the window resizes according to /// content) virtual Rect GetBoundaryRect() const; - /// TODO: Check components that overlay this function /// setzt die Größe des Fensters virtual void Resize(const Extent& newSize) { size_ = newSize; } /// setzt die Breite des Fensters @@ -290,14 +286,14 @@ class Window friend constexpr auto maxEnumValue(ButtonState) { return ButtonState::Pressed; } using ControlMap = std::map; + /// scales X- und Y values to fit the screen + template + static T_Pt Scale(const T_Pt& pt); /// Scales the value when scale_ is true, else returns the value template - T_Pt ScaleIf(const T_Pt& pt, const unsigned limfactor) const; + T_Pt ScaleIf(const T_Pt& pt) const; /// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht. - void SetScale(bool scale); - void Scale(); - /// setzt the limiting factor for scaling - void SetLimFactor(unsigned int limfactor) { this->limfactor_ = std::clamp(limfactor,(unsigned) 0, (unsigned) 3); } + void SetScale(bool scale = true) { this->scale_ = scale; } /// zeichnet das Fenster. virtual void Draw_(); /// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht? @@ -308,11 +304,9 @@ class Window unsigned id_; /// ID des Fensters. DrawPoint pos_; /// Position des Fensters. Extent size_; /// Höhe des Fensters. - Extent true_size_; /// Enscaled size of the Window. bool active_; /// Fenster aktiv? bool visible_; /// Fenster sichtbar? bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? - unsigned limfactor_; /// Limiting factor 1-3 considered for scaling, disabled when 0. TODO: Factor shall be multiple of base size. std::map lockedAreas_; /// gesperrte Regionen des Fensters. std::vector tofreeAreas_; @@ -327,9 +321,7 @@ inline T* Window::AddCtrl(T* ctrl) RTTR_Assert(childIdToWnd_.find(ctrl->GetID()) == childIdToWnd_.end()); childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); - ctrl->SetScale(scale_); - ctrl->SetLimFactor(limfactor_); - ctrl->Scale(); + ctrl->scale_ = scale_; ctrl->SetActive(active_); return ctrl; diff --git a/libs/s25main/controls/ctrlComboBox.cpp b/libs/s25main/controls/ctrlComboBox.cpp index 4933a5255c..d31691f519 100644 --- a/libs/s25main/controls/ctrlComboBox.cpp +++ b/libs/s25main/controls/ctrlComboBox.cpp @@ -51,7 +51,7 @@ void ctrlComboBox::Resize(const Extent& newSize) { // zu große geworden? listSize.y += font->getHeight(); - unsigned short scaledMaxHeight = Extent(0, max_list_height).y; + unsigned short scaledMaxHeight = ScaleIf(Extent(0, max_list_height)).y; if(listSize.y > scaledMaxHeight) { diff --git a/libs/s25main/controls/ctrlScrollBar.cpp b/libs/s25main/controls/ctrlScrollBar.cpp index 510b95c43f..31103bca48 100644 --- a/libs/s25main/controls/ctrlScrollBar.cpp +++ b/libs/s25main/controls/ctrlScrollBar.cpp @@ -157,7 +157,6 @@ void ctrlScrollBar::SetPageSize(unsigned short pagesize) } } -// TODO: Update resize void ctrlScrollBar::Resize(const Extent& newSize) { Window::Resize(newSize); diff --git a/libs/s25main/controls/ctrlTable.cpp b/libs/s25main/controls/ctrlTable.cpp index 089b6467dc..ba9a843e77 100644 --- a/libs/s25main/controls/ctrlTable.cpp +++ b/libs/s25main/controls/ctrlTable.cpp @@ -453,7 +453,6 @@ void ctrlTable::Msg_ScrollShow(const unsigned /*ctrl_id*/, const bool /*visible* ResetButtonWidths(); } -// TODO: Update resize and Reset Buttons void ctrlTable::ResetButtonWidths() { auto addColumnWidth = [](unsigned cur, const Column& c) { return cur + c.width; }; diff --git a/libs/s25main/desktops/Desktop.cpp b/libs/s25main/desktops/Desktop.cpp index f7bfa85388..5a4db4253b 100644 --- a/libs/s25main/desktops/Desktop.cpp +++ b/libs/s25main/desktops/Desktop.cpp @@ -25,7 +25,6 @@ Desktop::Desktop(glArchivItem_Bitmap* background) : Window(nullptr, 0, DrawPoint::all(0), VIDEODRIVER.GetRenderSize()), background(background), lastFPS_(0) { SetScale(true); - SetLimFactor(0); SetFpsDisplay(true); // By default limit the maximum frame rate to 60 FPS - used for main menu if(SETTINGS.video.framerate < 0) diff --git a/libs/s25main/desktops/dskCampaignSelection.cpp b/libs/s25main/desktops/dskCampaignSelection.cpp index e57209d91f..88c970485b 100644 --- a/libs/s25main/desktops/dskCampaignSelection.cpp +++ b/libs/s25main/desktops/dskCampaignSelection.cpp @@ -193,12 +193,11 @@ void dskCampaignSelection::Draw_() { Desktop::Draw_(); - // TODO: Check how to call Scale from here. // replace this by AddImageButton as soon as it can handle this scenario correctly if(campaignImage_) { - campaignImage_->DrawFull(Rect(ScaleIf(DrawPoint(secondColumnOffsetX, getColumnOffsetY()),0), - ScaleIf(Extent(secondColumnExtentX, campaignImageExtentY), 0))); + campaignImage_->DrawFull(Rect(ScaleIf(DrawPoint(secondColumnOffsetX, getColumnOffsetY())), + ScaleIf(Extent(secondColumnExtentX, campaignImageExtentY)))); } } From 50c9e0686ebb158bdbb9ae9c7aa456125b5217dc Mon Sep 17 00:00:00 2001 From: Noseey Date: Sun, 22 Feb 2026 14:55:13 +0100 Subject: [PATCH 03/24] window scaling limit - simplified solution Issue: - tables should not be considered when limiting. --- libs/s25main/RescaleWindowProp.h | 21 +++++++++++++---- libs/s25main/Window.cpp | 29 ++++++++++++++++++------ libs/s25main/Window.h | 10 +++++++- libs/s25main/animation/MoveAnimation.cpp | 4 ++-- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 73894e2916..37b6cdad1d 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -20,17 +20,25 @@ struct ScaleWindowPropUp /// Rescales a window's properties (size or positions) struct RescaleWindowProp { - Extent oldSize, newSize; + Extent oldSize, newSize, origValue; RescaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template - T_Pt operator()(const T_Pt& oldValue) const; + T_Pt operator()(const T_Pt& oldValue, const T_Pt& origValue) const; }; template inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale) { - return T_Pt(value * sizeToScale / Extent(800, 600)); + T_Pt scaledValue(value * sizeToScale / Extent(800, 600)); + if(std::is_same_v) + { + if(scaledValue.x > value.x << 1) + scaledValue.x = value.x << 1; + if(scaledValue.y > value.y << 1) + scaledValue.y = value.y << 1; + } + return scaledValue; } template @@ -40,9 +48,14 @@ inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const } template -inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue) const +inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const T_Pt& origValue) const { T_Pt realValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); + if(std::is_same_v && (origValue.x != 0 && origValue.y != 0)) + { + realValue.x = origValue.x; + realValue.y = origValue.y; + } // Check for rounding errors T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize); if(checkValue.x < oldValue.x) diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 39c6b34a14..de83238e1d 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -18,8 +18,8 @@ #include Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size) - : parent_(parent), id_(id), pos_(pos), size_(size), active_(false), visible_(true), scale_(false), - isInMouseRelay(false), animations_(this) + : parent_(parent), id_(id), pos_(pos), size_(size), orig_size_(Extent(0,0)), active_(false), visible_(true), + scale_(false), isInMouseRelay(false), animations_(this) {} Window::~Window() @@ -65,6 +65,16 @@ Extent Window::GetSize() const return size_; } +Extent Window::GetOrigSize() const +{ + return orig_size_; +} + +void Window::SetOrigSize(Extent origSize) +{ + orig_size_ = origSize; +} + Rect Window::GetDrawRect() const { return Rect(GetDrawPos(), GetSize()); @@ -540,8 +550,8 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(!ctrl) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) - Extent newSize = rescale(ctrl->GetSize()); - ctrl->SetPos(rescale(ctrl->GetPos())); + Extent newSize = rescale(ctrl->GetSize(), ctrl->GetOrigSize()); + ctrl->SetPos(rescale(ctrl->GetPos(), DrawPoint(0,0))); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); } @@ -555,14 +565,19 @@ T_Pt Window::Scale(const T_Pt& pt) } template -T_Pt Window::ScaleIf(const T_Pt& pt) const +T_Pt Window::ScaleIf(const T_Pt& pt) { + if(std::is_same_v) + { + orig_size_.x = pt.x; + orig_size_.y = pt.y; + } return scale_ ? Scale(pt) : pt; } // Inlining removes those. so add it here -template DrawPoint Window::ScaleIf(const DrawPoint&) const; -template Extent Window::ScaleIf(const Extent&) const; +template DrawPoint Window::ScaleIf(const DrawPoint&); +template Extent Window::ScaleIf(const Extent&); bool Window::IsInLockedRegion(const Position& pos, const Window* exception) const { diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 437532c762..7c659585fd 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -75,6 +75,10 @@ class Window DrawPoint GetDrawPos() const; /// Get the size of the window Extent GetSize() const; + /// Get the original size of the window + Extent GetOrigSize() const; + /// Get the original size of the window + void SetOrigSize(Extent origSize); /// gets the extent of the window in absolute coordinates Rect GetDrawRect() const; /// Get the actual extents of the rect (might be different to the draw rect if the window resizes according to @@ -291,7 +295,7 @@ class Window static T_Pt Scale(const T_Pt& pt); /// Scales the value when scale_ is true, else returns the value template - T_Pt ScaleIf(const T_Pt& pt) const; + T_Pt ScaleIf(const T_Pt& pt); /// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht. void SetScale(bool scale = true) { this->scale_ = scale; } /// zeichnet das Fenster. @@ -304,6 +308,7 @@ class Window unsigned id_; /// ID des Fensters. DrawPoint pos_; /// Position des Fensters. Extent size_; /// Höhe des Fensters. + Extent orig_size_; /// Original / unscaled size of the window. bool active_; /// Fenster aktiv? bool visible_; /// Fenster sichtbar? bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? @@ -322,6 +327,9 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; + /// Hack: Take origSize that was set by the last ScaleIf(Extent) to pass to children. + ctrl->SetOrigSize(GetOrigSize()); + orig_size_ = Extent(0,0); ctrl->SetActive(active_); return ctrl; diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 2abe143fc6..ca4ca6a78b 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -22,8 +22,8 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { RescaleWindowProp rescale(rs.oldSize, rs.newSize); - origPos_ = rescale(origPos_); - newPos_ = rescale(newPos_); + origPos_ = rescale(origPos_, DrawPoint(0,0)); + newPos_ = rescale(newPos_, DrawPoint(0,0)); } void MoveAnimation::doUpdate(Window* element, double nextFramepartTime) From 4d6c7006ec1473141170416bbad0ee5f2145e700 Mon Sep 17 00:00:00 2001 From: Noseey Date: Sun, 22 Feb 2026 17:23:23 +0100 Subject: [PATCH 04/24] window scaling limit - consider only for ctrlTextButton --- libs/s25main/RescaleWindowProp.h | 27 ++++++++++++------------ libs/s25main/Window.cpp | 26 +++++++++++++---------- libs/s25main/Window.h | 11 +++++++--- libs/s25main/animation/MoveAnimation.cpp | 4 ++-- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 37b6cdad1d..2059fd9798 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -12,7 +12,7 @@ struct ScaleWindowPropUp ScaleWindowPropUp(const Extent& size) : size(size) {} template - static T_Pt scale(const T_Pt& value, const Extent& size); + static T_Pt scale(const T_Pt& value, const Extent& size, const unsigned limfactor); template T_Pt operator()(const T_Pt& value) const; }; @@ -24,19 +24,20 @@ struct RescaleWindowProp RescaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template - T_Pt operator()(const T_Pt& oldValue, const T_Pt& origValue) const; + T_Pt operator()(const T_Pt& oldValue, const T_Pt& origValue, const unsigned limfactor) const; }; template -inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale) +inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const unsigned limfactor) { T_Pt scaledValue(value * sizeToScale / Extent(800, 600)); - if(std::is_same_v) + // Limit the scaling by a multiple (limfactor) of the base value + if(limfactor) { - if(scaledValue.x > value.x << 1) - scaledValue.x = value.x << 1; - if(scaledValue.y > value.y << 1) - scaledValue.y = value.y << 1; + if(scaledValue.x > value.x << limfactor) + scaledValue.x = value.x << limfactor; + if(scaledValue.y > value.y << limfactor) + scaledValue.y = value.y << limfactor; } return scaledValue; } @@ -44,23 +45,23 @@ inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScal template inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const { - return scale(value, size); + return scale(value, size, 0); } template -inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const T_Pt& origValue) const +inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const T_Pt& origValue, const unsigned limfactor) const { T_Pt realValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); - if(std::is_same_v && (origValue.x != 0 && origValue.y != 0)) + if(limfactor && (origValue.x != 0 && origValue.y != 0)) { realValue.x = origValue.x; realValue.y = origValue.y; } // Check for rounding errors - T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize); + T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize, limfactor); if(checkValue.x < oldValue.x) realValue.x++; if(checkValue.y < oldValue.y) realValue.y++; - return ScaleWindowPropUp::scale(realValue, newSize); + return ScaleWindowPropUp::scale(realValue, newSize, limfactor); } diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index de83238e1d..6e46b46ec8 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -230,7 +230,7 @@ ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, Bui ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, tooltip)); + return AddCtrl(new ctrlTextButton(this, id, ScaleIf(pos), ScaleLimIf(size), tc, text, font, tooltip)); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -550,8 +550,8 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(!ctrl) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) - Extent newSize = rescale(ctrl->GetSize(), ctrl->GetOrigSize()); - ctrl->SetPos(rescale(ctrl->GetPos(), DrawPoint(0,0))); + Extent newSize = rescale(ctrl->GetSize(), ctrl->GetOrigSize(), 1); + ctrl->SetPos(rescale(ctrl->GetPos(), DrawPoint(0,0), 0)); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); } @@ -559,20 +559,24 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) } template -T_Pt Window::Scale(const T_Pt& pt) +T_Pt Window::Scale(const T_Pt& pt, const unsigned limfactor) { - return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize()); + return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactor); } template T_Pt Window::ScaleIf(const T_Pt& pt) { - if(std::is_same_v) - { - orig_size_.x = pt.x; - orig_size_.y = pt.y; - } - return scale_ ? Scale(pt) : pt; + return scale_ ? Scale(pt, 0) : pt; +} + +template +T_Pt Window::ScaleLimIf(const T_Pt& pt) +{ + orig_size_.x = pt.x; + orig_size_.y = pt.y; + + return scale_ ? Scale(pt, 1) : pt; } // Inlining removes those. so add it here diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 7c659585fd..41281aab7e 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -290,12 +290,17 @@ class Window friend constexpr auto maxEnumValue(ButtonState) { return ButtonState::Pressed; } using ControlMap = std::map; - /// scales X- und Y values to fit the screen + /// scales X- und Y values to fit the screen considering a limiting factor + /// factor shall be between 0-3, 0 disables limiting. template - static T_Pt Scale(const T_Pt& pt); + static T_Pt Scale(const T_Pt& pt, const unsigned limfactor); /// Scales the value when scale_ is true, else returns the value template T_Pt ScaleIf(const T_Pt& pt); + /// Scales the value when scale_ is true with predefined scale limitation, else returns the value + /// only call once for a ctrl, so it is considered correctly in AddCtrl + template + T_Pt ScaleLimIf(const T_Pt& pt); /// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht. void SetScale(bool scale = true) { this->scale_ = scale; } /// zeichnet das Fenster. @@ -327,7 +332,7 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; - /// Hack: Take origSize that was set by the last ScaleIf(Extent) to pass to children. + // hack: take origSize that was set by the last (and presumably only) ScaleLimIf(Extent) call to pass to children. ctrl->SetOrigSize(GetOrigSize()); orig_size_ = Extent(0,0); ctrl->SetActive(active_); diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index ca4ca6a78b..86c7aa16ec 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -22,8 +22,8 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { RescaleWindowProp rescale(rs.oldSize, rs.newSize); - origPos_ = rescale(origPos_, DrawPoint(0,0)); - newPos_ = rescale(newPos_, DrawPoint(0,0)); + origPos_ = rescale(origPos_, DrawPoint(0,0), 0); + newPos_ = rescale(newPos_, DrawPoint(0,0), 0); } void MoveAnimation::doUpdate(Window* element, double nextFramepartTime) From 63c0ba8fa984179eae30d7eb2e31668fe9fabdb5 Mon Sep 17 00:00:00 2001 From: Noseey Date: Fri, 27 Feb 2026 21:33:52 +0100 Subject: [PATCH 05/24] window scaling - slow scaling instead of limiting --- libs/s25main/RescaleWindowProp.h | 42 ++++++++++++++---------- libs/s25main/Window.cpp | 36 ++++++++++---------- libs/s25main/Window.h | 26 ++++++++------- libs/s25main/animation/MoveAnimation.cpp | 4 +-- libs/s25main/controls/ctrlTextButton.cpp | 6 ++-- libs/s25main/controls/ctrlTextButton.h | 2 +- 6 files changed, 63 insertions(+), 53 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 2059fd9798..b9ddfea4f7 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -12,7 +12,7 @@ struct ScaleWindowPropUp ScaleWindowPropUp(const Extent& size) : size(size) {} template - static T_Pt scale(const T_Pt& value, const Extent& size, const unsigned limfactor); + static T_Pt scale(const T_Pt& value, const Extent& size, const Extent& limfactors); template T_Pt operator()(const T_Pt& value) const; }; @@ -24,22 +24,23 @@ struct RescaleWindowProp RescaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template - T_Pt operator()(const T_Pt& oldValue, const T_Pt& origValue, const unsigned limfactor) const; + T_Pt operator()(const T_Pt& oldValue, const Extent& limfactors) const; }; template -inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const unsigned limfactor) +inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const Extent& limfactors) { - T_Pt scaledValue(value * sizeToScale / Extent(800, 600)); - // Limit the scaling by a multiple (limfactor) of the base value - if(limfactor) + // Slow the scaling by a limfactor value for X and Y + if(limfactors.x > 0 && limfactors.y > 0 && limfactors.x < 11 && limfactors.y < 11) { - if(scaledValue.x > value.x << limfactor) - scaledValue.x = value.x << limfactor; - if(scaledValue.y > value.y << limfactor) - scaledValue.y = value.y << limfactor; + T_Pt diff(sizeToScale - Extent(800,600)); + T_Pt limScaledValue(value * (sizeToScale-diff*limfactors/10) / Extent(800, 600)); + return limScaledValue; + } else + { + T_Pt scaledValue(value * sizeToScale / Extent(800, 600)); + return scaledValue; } - return scaledValue; } template @@ -49,19 +50,24 @@ inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const } template -inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const T_Pt& origValue, const unsigned limfactor) const +inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const Extent& limfactors) const { - T_Pt realValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); - if(limfactor && (origValue.x != 0 && origValue.y != 0)) + T_Pt realValue; + if(limfactors.x > 0 && limfactors.y > 0 && limfactors.x < 11 && limfactors.y < 11) + { + T_Pt diff(oldSize - Extent(800,600)); + T_Pt limUnscaleValue(oldValue.x * 800 / (oldSize.x - (diff.x*limfactors.x/10)), oldValue.y * 600 / (oldSize.y - (diff.y*limfactors.y/10))); + realValue = limUnscaleValue; + } else { - realValue.x = origValue.x; - realValue.y = origValue.y; + T_Pt unscaleValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); + realValue = unscaleValue; } // Check for rounding errors - T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize, limfactor); + T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize, limfactors); if(checkValue.x < oldValue.x) realValue.x++; if(checkValue.y < oldValue.y) realValue.y++; - return ScaleWindowPropUp::scale(realValue, newSize, limfactor); + return ScaleWindowPropUp::scale(realValue, newSize, limfactors); } diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 6e46b46ec8..e0bc19860c 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -18,7 +18,7 @@ #include Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size) - : parent_(parent), id_(id), pos_(pos), size_(size), orig_size_(Extent(0,0)), active_(false), visible_(true), + : parent_(parent), id_(id), pos_(pos), size_(size), limit_factors_(Extent(0,0)), active_(false), visible_(true), scale_(false), isInMouseRelay(false), animations_(this) {} @@ -65,14 +65,14 @@ Extent Window::GetSize() const return size_; } -Extent Window::GetOrigSize() const +Extent Window::GetLimitFactors() const { - return orig_size_; + return limit_factors_; } -void Window::SetOrigSize(Extent origSize) +void Window::SetLimitFactors(Extent limitFactors) { - orig_size_ = origSize; + limit_factors_ = limitFactors; } Rect Window::GetDrawRect() const @@ -230,7 +230,7 @@ ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, Bui ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, ScaleIf(pos), ScaleLimIf(size), tc, text, font, tooltip)); + return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, Extent (7,5))); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -550,8 +550,8 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(!ctrl) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) - Extent newSize = rescale(ctrl->GetSize(), ctrl->GetOrigSize(), 1); - ctrl->SetPos(rescale(ctrl->GetPos(), DrawPoint(0,0), 0)); + Extent newSize = rescale(ctrl->GetSize(), ctrl->GetLimitFactors()); + ctrl->SetPos(rescale(ctrl->GetPos(), Extent(0,0))); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); } @@ -559,24 +559,24 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) } template -T_Pt Window::Scale(const T_Pt& pt, const unsigned limfactor) +T_Pt Window::Scale(const T_Pt& pt, const Extent& limfactors) { - return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactor); + return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactors); } -template -T_Pt Window::ScaleIf(const T_Pt& pt) +void Window::ScaleByFactor() { - return scale_ ? Scale(pt, 0) : pt; + if(scale_) + { + pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), Extent(0,0)); + size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limit_factors_); + } } template -T_Pt Window::ScaleLimIf(const T_Pt& pt) +T_Pt Window::ScaleIf(const T_Pt& pt) { - orig_size_.x = pt.x; - orig_size_.y = pt.y; - - return scale_ ? Scale(pt, 1) : pt; + return scale_ ? Scale(pt, Extent(0,0)) : pt; } // Inlining removes those. so add it here diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 41281aab7e..f2df2c5a84 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -76,9 +76,11 @@ class Window /// Get the size of the window Extent GetSize() const; /// Get the original size of the window - Extent GetOrigSize() const; + Extent GetLimitFactors() const; + /// get Scale-Value to check if Controls needs to be scaled or not. + bool GetScale() { return this->scale_; } /// Get the original size of the window - void SetOrigSize(Extent origSize); + void SetLimitFactors(Extent limitFactors); /// gets the extent of the window in absolute coordinates Rect GetDrawRect() const; /// Get the actual extents of the rect (might be different to the draw rect if the window resizes according to @@ -290,17 +292,15 @@ class Window friend constexpr auto maxEnumValue(ButtonState) { return ButtonState::Pressed; } using ControlMap = std::map; - /// scales X- und Y values to fit the screen considering a limiting factor + /// scales X- and Y values to fit the screen considering a limiting factor /// factor shall be between 0-3, 0 disables limiting. template - static T_Pt Scale(const T_Pt& pt, const unsigned limfactor); + static T_Pt Scale(const T_Pt& pt, const Extent& limfactors); + /// scales X- and Y values of position and size considering a limiting factor for size + void ScaleByFactor(); /// Scales the value when scale_ is true, else returns the value template T_Pt ScaleIf(const T_Pt& pt); - /// Scales the value when scale_ is true with predefined scale limitation, else returns the value - /// only call once for a ctrl, so it is considered correctly in AddCtrl - template - T_Pt ScaleLimIf(const T_Pt& pt); /// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht. void SetScale(bool scale = true) { this->scale_ = scale; } /// zeichnet das Fenster. @@ -313,7 +313,7 @@ class Window unsigned id_; /// ID des Fensters. DrawPoint pos_; /// Position des Fensters. Extent size_; /// Höhe des Fensters. - Extent orig_size_; /// Original / unscaled size of the window. + Extent limit_factors_; /// X and Y scaling limiting factors from 1 (unscaled) - 10 (fully scaled) bool active_; /// Fenster aktiv? bool visible_; /// Fenster sichtbar? bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? @@ -332,9 +332,11 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; - // hack: take origSize that was set by the last (and presumably only) ScaleLimIf(Extent) call to pass to children. - ctrl->SetOrigSize(GetOrigSize()); - orig_size_ = Extent(0,0); + Extent limfactors = ctrl->limit_factors_; + if (limfactors.x > 0 && limfactors.y > 0 && limfactors.x < 11 && limfactors.y < 11) + { + ctrl->ScaleByFactor(); + } ctrl->SetActive(active_); return ctrl; diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 86c7aa16ec..772e9a9df4 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -22,8 +22,8 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { RescaleWindowProp rescale(rs.oldSize, rs.newSize); - origPos_ = rescale(origPos_, DrawPoint(0,0), 0); - newPos_ = rescale(newPos_, DrawPoint(0,0), 0); + origPos_ = rescale(origPos_, Extent(0,0)); + newPos_ = rescale(newPos_, Extent(0,0)); } void MoveAnimation::doUpdate(Window* element, double nextFramepartTime) diff --git a/libs/s25main/controls/ctrlTextButton.cpp b/libs/s25main/controls/ctrlTextButton.cpp index 84f5957ea0..3735228710 100644 --- a/libs/s25main/controls/ctrlTextButton.cpp +++ b/libs/s25main/controls/ctrlTextButton.cpp @@ -11,9 +11,11 @@ static constexpr unsigned contentOffset = 2; ctrlTextButton::ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, - const std::string& tooltip) + const std::string& tooltip, const Extent& limitFactors) : ctrlButton(parent, id, pos, size, tc, tooltip), ctrlBaseText(text, COLOR_YELLOW, font) -{} +{ + Window::SetLimitFactors(limitFactors); +} void ctrlTextButton::ResizeForMaxChars(unsigned numChars) { diff --git a/libs/s25main/controls/ctrlTextButton.h b/libs/s25main/controls/ctrlTextButton.h index 8a6eadb000..8ea4139a5e 100644 --- a/libs/s25main/controls/ctrlTextButton.h +++ b/libs/s25main/controls/ctrlTextButton.h @@ -12,7 +12,7 @@ class ctrlTextButton : public ctrlButton, public ctrlBaseText { public: ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& text, const glFont* font, const std::string& tooltip); + const std::string& text, const glFont* font, const std::string& tooltip, const Extent& limitFactors); /// Changes width so at most this many chars can be shown void ResizeForMaxChars(unsigned numChars); From 22b56d914bf490b63e1434d165b3076f71c6930c Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 28 Feb 2026 01:01:41 +0100 Subject: [PATCH 06/24] rework checks and remove unnecessary functions --- libs/s25main/RescaleWindowProp.h | 14 +++++++------- libs/s25main/Window.cpp | 6 +++--- libs/s25main/Window.h | 18 ++++++------------ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index b9ddfea4f7..added4caab 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -20,7 +20,7 @@ struct ScaleWindowPropUp /// Rescales a window's properties (size or positions) struct RescaleWindowProp { - Extent oldSize, newSize, origValue; + Extent oldSize, newSize; RescaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template @@ -30,11 +30,10 @@ struct RescaleWindowProp template inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const Extent& limfactors) { - // Slow the scaling by a limfactor value for X and Y - if(limfactors.x > 0 && limfactors.y > 0 && limfactors.x < 11 && limfactors.y < 11) + if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) { T_Pt diff(sizeToScale - Extent(800,600)); - T_Pt limScaledValue(value * (sizeToScale-diff*limfactors/10) / Extent(800, 600)); + T_Pt limScaledValue(value * (sizeToScale-diff * limfactors / 10) / Extent(800, 600)); return limScaledValue; } else { @@ -46,17 +45,18 @@ inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScal template inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const { - return scale(value, size, 0); + return scale(value, size, Extent(0,0)); } template inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const Extent& limfactors) const { T_Pt realValue; - if(limfactors.x > 0 && limfactors.y > 0 && limfactors.x < 11 && limfactors.y < 11) + if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) { T_Pt diff(oldSize - Extent(800,600)); - T_Pt limUnscaleValue(oldValue.x * 800 / (oldSize.x - (diff.x*limfactors.x/10)), oldValue.y * 600 / (oldSize.y - (diff.y*limfactors.y/10))); + T_Pt limUnscaleValue(oldValue.x * 800 / (oldSize.x - (diff.x * limfactors.x / 10)), + oldValue.y * 600 / (oldSize.y - (diff.y * limfactors.y / 10))); realValue = limUnscaleValue; } else { diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index e0bc19860c..aab2f03c7e 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -574,14 +574,14 @@ void Window::ScaleByFactor() } template -T_Pt Window::ScaleIf(const T_Pt& pt) +T_Pt Window::ScaleIf(const T_Pt& pt) const { return scale_ ? Scale(pt, Extent(0,0)) : pt; } // Inlining removes those. so add it here -template DrawPoint Window::ScaleIf(const DrawPoint&); -template Extent Window::ScaleIf(const Extent&); +template DrawPoint Window::ScaleIf(const DrawPoint&) const; +template Extent Window::ScaleIf(const Extent&) const; bool Window::IsInLockedRegion(const Position& pos, const Window* exception) const { diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index f2df2c5a84..ccae322488 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -75,12 +75,8 @@ class Window DrawPoint GetDrawPos() const; /// Get the size of the window Extent GetSize() const; - /// Get the original size of the window + /// Get the Limit Factors for scaling Extent GetLimitFactors() const; - /// get Scale-Value to check if Controls needs to be scaled or not. - bool GetScale() { return this->scale_; } - /// Get the original size of the window - void SetLimitFactors(Extent limitFactors); /// gets the extent of the window in absolute coordinates Rect GetDrawRect() const; /// Get the actual extents of the rect (might be different to the draw rect if the window resizes according to @@ -92,6 +88,8 @@ class Window void SetWidth(unsigned width) { Resize(Extent(width, size_.y)); } /// setzt die Höhe des Fensters void SetHeight(unsigned height) { Resize(Extent(size_.x, height)); } + /// Set the Limit Factors for scaling + void SetLimitFactors(Extent limitFactors); /// Sendet eine Tastaturnachricht an die Steuerelemente. bool RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke); /// Sendet eine Mausnachricht weiter an alle Steuerelemente @@ -293,14 +291,13 @@ class Window using ControlMap = std::map; /// scales X- and Y values to fit the screen considering a limiting factor - /// factor shall be between 0-3, 0 disables limiting. template static T_Pt Scale(const T_Pt& pt, const Extent& limfactors); - /// scales X- and Y values of position and size considering a limiting factor for size + /// scales X- and Y values of position and size considering the current limiting factor for size void ScaleByFactor(); /// Scales the value when scale_ is true, else returns the value template - T_Pt ScaleIf(const T_Pt& pt); + T_Pt ScaleIf(const T_Pt& pt) const; /// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht. void SetScale(bool scale = true) { this->scale_ = scale; } /// zeichnet das Fenster. @@ -332,11 +329,8 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; - Extent limfactors = ctrl->limit_factors_; - if (limfactors.x > 0 && limfactors.y > 0 && limfactors.x < 11 && limfactors.y < 11) - { + if (ctrl->limit_factors_ != Extent(0,0)) ctrl->ScaleByFactor(); - } ctrl->SetActive(active_); return ctrl; From 96a25b46de7d80cfaaaa9035703e49660fac7b4a Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 28 Feb 2026 16:33:02 +0100 Subject: [PATCH 07/24] fixing style and updating testControls.cpp --- libs/s25main/RescaleWindowProp.h | 12 ++++++------ libs/s25main/Window.cpp | 10 +++++----- libs/s25main/Window.h | 2 +- libs/s25main/animation/MoveAnimation.cpp | 4 ++-- tests/s25Main/UI/testControls.cpp | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index added4caab..465b11aef4 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -32,8 +32,8 @@ inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScal { if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) { - T_Pt diff(sizeToScale - Extent(800,600)); - T_Pt limScaledValue(value * (sizeToScale-diff * limfactors / 10) / Extent(800, 600)); + T_Pt diff(sizeToScale - Extent(800, 600)); + T_Pt limScaledValue(value * (sizeToScale - diff * limfactors / 10) / Extent(800, 600)); return limScaledValue; } else { @@ -45,7 +45,7 @@ inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScal template inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const { - return scale(value, size, Extent(0,0)); + return scale(value, size, Extent(0, 0)); } template @@ -54,11 +54,11 @@ inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const Extent& li T_Pt realValue; if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) { - T_Pt diff(oldSize - Extent(800,600)); + T_Pt diff(oldSize - Extent(800, 600)); T_Pt limUnscaleValue(oldValue.x * 800 / (oldSize.x - (diff.x * limfactors.x / 10)), - oldValue.y * 600 / (oldSize.y - (diff.y * limfactors.y / 10))); + oldValue.y * 600 / (oldSize.y - (diff.y * limfactors.y / 10))); realValue = limUnscaleValue; - } else + } else { T_Pt unscaleValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); realValue = unscaleValue; diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index aab2f03c7e..15913b9b8a 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -18,7 +18,7 @@ #include Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size) - : parent_(parent), id_(id), pos_(pos), size_(size), limit_factors_(Extent(0,0)), active_(false), visible_(true), + : parent_(parent), id_(id), pos_(pos), size_(size), limit_factors_(Extent(0, 0)), active_(false), visible_(true), scale_(false), isInMouseRelay(false), animations_(this) {} @@ -230,7 +230,7 @@ ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, Bui ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, Extent (7,5))); + return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, Extent (7, 5))); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -551,7 +551,7 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) Extent newSize = rescale(ctrl->GetSize(), ctrl->GetLimitFactors()); - ctrl->SetPos(rescale(ctrl->GetPos(), Extent(0,0))); + ctrl->SetPos(rescale(ctrl->GetPos(), Extent(0, 0))); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); } @@ -568,7 +568,7 @@ void Window::ScaleByFactor() { if(scale_) { - pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), Extent(0,0)); + pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), Extent(0, 0)); size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limit_factors_); } } @@ -576,7 +576,7 @@ void Window::ScaleByFactor() template T_Pt Window::ScaleIf(const T_Pt& pt) const { - return scale_ ? Scale(pt, Extent(0,0)) : pt; + return scale_ ? Scale(pt, Extent(0, 0)) : pt; } // Inlining removes those. so add it here diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index ccae322488..04e1ab33ce 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -329,7 +329,7 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; - if (ctrl->limit_factors_ != Extent(0,0)) + if (ctrl->limit_factors_ != Extent(0, 0)) ctrl->ScaleByFactor(); ctrl->SetActive(active_); diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 772e9a9df4..3a5bee554a 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -22,8 +22,8 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { RescaleWindowProp rescale(rs.oldSize, rs.newSize); - origPos_ = rescale(origPos_, Extent(0,0)); - newPos_ = rescale(newPos_, Extent(0,0)); + origPos_ = rescale(origPos_, Extent(0, 0)); + newPos_ = rescale(newPos_, Extent(0, 0)); } void MoveAnimation::doUpdate(Window* element, double nextFramepartTime) diff --git a/tests/s25Main/UI/testControls.cpp b/tests/s25Main/UI/testControls.cpp index c8954d94b5..0a0e0f2d82 100644 --- a/tests/s25Main/UI/testControls.cpp +++ b/tests/s25Main/UI/testControls.cpp @@ -61,7 +61,7 @@ BOOST_FIXTURE_TEST_CASE(MouseOver, uiHelper::Fixture) const auto pos = rttr::test::randomPoint(); const auto size = rttr::test::randomPoint(10); const auto font = createMockFont({'H', 'e', 'l', 'o', '?'}); - ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), ""); + ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), "", Extent(0, 0)); BOOST_TEST(bt.IsMouseOver(pos)); BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(1, 0))); BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(0, 1))); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(AdjustWidthForMaxChars_SetsCorrectSize) } { ctrlTextButton txt(nullptr, 1, rttr::test::randomPoint(), rttr::test::randomPoint(), - TextureColor::Green1, "foo", font.get(), "tooltip"); + TextureColor::Green1, "foo", font.get(), "tooltip", Extent(0, 0)); const Extent sizeBefore = txt.GetSize(); // Don't assume size, so get size for 0 chars txt.ResizeForMaxChars(0); From eedc195effbd29d2cffa36f7a260087b56825227 Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 28 Feb 2026 16:36:21 +0100 Subject: [PATCH 08/24] fixing style --- libs/s25main/RescaleWindowProp.h | 2 +- libs/s25main/Window.cpp | 2 +- libs/s25main/Window.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 465b11aef4..999c2ed6d9 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -55,7 +55,7 @@ inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const Extent& li if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) { T_Pt diff(oldSize - Extent(800, 600)); - T_Pt limUnscaleValue(oldValue.x * 800 / (oldSize.x - (diff.x * limfactors.x / 10)), + T_Pt limUnscaleValue(oldValue.x * 800 / (oldSize.x - (diff.x * limfactors.x / 10)), oldValue.y * 600 / (oldSize.y - (diff.y * limfactors.y / 10))); realValue = limUnscaleValue; } else diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 15913b9b8a..ac60e56861 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -230,7 +230,7 @@ ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, Bui ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, Extent (7, 5))); + return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, Extent(7, 5))); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 04e1ab33ce..fa26e858e3 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -329,7 +329,7 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; - if (ctrl->limit_factors_ != Extent(0, 0)) + if(ctrl->limit_factors_ != Extent(0, 0)) ctrl->ScaleByFactor(); ctrl->SetActive(active_); From e7b3addbf78d2ad1c5e9d38d698ab91085c2bfa4 Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 28 Feb 2026 19:24:34 +0100 Subject: [PATCH 09/24] Introdouce LimitFactors Typedef, renaming and update comments --- libs/common/include/Point.h | 5 +++++ libs/s25main/RescaleWindowProp.h | 10 +++++----- libs/s25main/Window.cpp | 24 ++++++++++++------------ libs/s25main/Window.h | 14 +++++++------- libs/s25main/animation/MoveAnimation.cpp | 4 ++-- libs/s25main/controls/ctrlTextButton.cpp | 2 +- libs/s25main/controls/ctrlTextButton.h | 2 +- tests/s25Main/UI/testControls.cpp | 4 ++-- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/libs/common/include/Point.h b/libs/common/include/Point.h index 7341c31177..428ce18303 100644 --- a/libs/common/include/Point.h +++ b/libs/common/include/Point.h @@ -69,6 +69,11 @@ using Position = Point; /// Type for describing an extent/size etc. (unsigned type) using Extent = Point; using PointF = Point; +/// Type for describing limiting scaling factors for GUI elements (unsigned type) +/// Limits scaling from Base Resolution 800x600 to fit screen size in a granularity of 10 +/// Valid range is from 1 up to 10, values outside the range don't impose any limiting +/// e. g. Value 1: scales 1/10 of the difference between screensize and Base Resolution +using LimitFactors = Point; //-V:all:810 ////////////////////////////////////////////////////////////////////////// diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 999c2ed6d9..1a95a08e2f 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -12,7 +12,7 @@ struct ScaleWindowPropUp ScaleWindowPropUp(const Extent& size) : size(size) {} template - static T_Pt scale(const T_Pt& value, const Extent& size, const Extent& limfactors); + static T_Pt scale(const T_Pt& value, const Extent& size, const LimitFactors& limfactors); template T_Pt operator()(const T_Pt& value) const; }; @@ -24,11 +24,11 @@ struct RescaleWindowProp RescaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template - T_Pt operator()(const T_Pt& oldValue, const Extent& limfactors) const; + T_Pt operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const; }; template -inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const Extent& limfactors) +inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const LimitFactors& limfactors) { if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) { @@ -45,11 +45,11 @@ inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScal template inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const { - return scale(value, size, Extent(0, 0)); + return scale(value, size, LimitFactors(0, 0)); } template -inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const Extent& limfactors) const +inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const { T_Pt realValue; if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index ac60e56861..bcf1ec6114 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -17,8 +17,8 @@ #include #include -Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size) - : parent_(parent), id_(id), pos_(pos), size_(size), limit_factors_(Extent(0, 0)), active_(false), visible_(true), +Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const LimitFactors& size) + : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(LimitFactors(0, 0)), active_(false), visible_(true), scale_(false), isInMouseRelay(false), animations_(this) {} @@ -65,14 +65,14 @@ Extent Window::GetSize() const return size_; } -Extent Window::GetLimitFactors() const +LimitFactors Window::GetLimitFactors() const { - return limit_factors_; + return limitFactors_; } -void Window::SetLimitFactors(Extent limitFactors) +void Window::SetLimitFactors(LimitFactors limitFactors) { - limit_factors_ = limitFactors; + limitFactors_ = limitFactors; } Rect Window::GetDrawRect() const @@ -230,7 +230,7 @@ ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, Bui ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, Extent(7, 5))); + return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, LimitFactors(7, 5))); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -551,7 +551,7 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) Extent newSize = rescale(ctrl->GetSize(), ctrl->GetLimitFactors()); - ctrl->SetPos(rescale(ctrl->GetPos(), Extent(0, 0))); + ctrl->SetPos(rescale(ctrl->GetPos(), LimitFactors(0, 0))); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); } @@ -559,7 +559,7 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) } template -T_Pt Window::Scale(const T_Pt& pt, const Extent& limfactors) +T_Pt Window::Scale(const T_Pt& pt, const LimitFactors& limfactors) { return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactors); } @@ -568,15 +568,15 @@ void Window::ScaleByFactor() { if(scale_) { - pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), Extent(0, 0)); - size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limit_factors_); + pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); + size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); } } template T_Pt Window::ScaleIf(const T_Pt& pt) const { - return scale_ ? Scale(pt, Extent(0, 0)) : pt; + return scale_ ? Scale(pt, LimitFactors(0, 0)) : pt; } // Inlining removes those. so add it here diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index fa26e858e3..5415704720 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -76,7 +76,7 @@ class Window /// Get the size of the window Extent GetSize() const; /// Get the Limit Factors for scaling - Extent GetLimitFactors() const; + LimitFactors GetLimitFactors() const; /// gets the extent of the window in absolute coordinates Rect GetDrawRect() const; /// Get the actual extents of the rect (might be different to the draw rect if the window resizes according to @@ -89,7 +89,7 @@ class Window /// setzt die Höhe des Fensters void SetHeight(unsigned height) { Resize(Extent(size_.x, height)); } /// Set the Limit Factors for scaling - void SetLimitFactors(Extent limitFactors); + void SetLimitFactors(LimitFactors limitFactors); /// Sendet eine Tastaturnachricht an die Steuerelemente. bool RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke); /// Sendet eine Mausnachricht weiter an alle Steuerelemente @@ -290,10 +290,10 @@ class Window friend constexpr auto maxEnumValue(ButtonState) { return ButtonState::Pressed; } using ControlMap = std::map; - /// scales X- and Y values to fit the screen considering a limiting factor + /// scales X- and Y values to fit the screen, additionally considering a limiting factor for size template - static T_Pt Scale(const T_Pt& pt, const Extent& limfactors); - /// scales X- and Y values of position and size considering the current limiting factor for size + static T_Pt Scale(const T_Pt& pt, const LimitFactors& limfactors); + /// scales X- and Y values of pos_ and size_, additionally considering limitFactors_ for size_ scaling void ScaleByFactor(); /// Scales the value when scale_ is true, else returns the value template @@ -310,7 +310,7 @@ class Window unsigned id_; /// ID des Fensters. DrawPoint pos_; /// Position des Fensters. Extent size_; /// Höhe des Fensters. - Extent limit_factors_; /// X and Y scaling limiting factors from 1 (unscaled) - 10 (fully scaled) + LimitFactors limitFactors_; /// X and Y scaling limiting factors bool active_; /// Fenster aktiv? bool visible_; /// Fenster sichtbar? bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? @@ -329,7 +329,7 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; - if(ctrl->limit_factors_ != Extent(0, 0)) + if(ctrl->limitFactors_ != LimitFactors(0, 0)) ctrl->ScaleByFactor(); ctrl->SetActive(active_); diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 3a5bee554a..514d552bfa 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -22,8 +22,8 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { RescaleWindowProp rescale(rs.oldSize, rs.newSize); - origPos_ = rescale(origPos_, Extent(0, 0)); - newPos_ = rescale(newPos_, Extent(0, 0)); + origPos_ = rescale(origPos_, LimitFactors(0, 0)); + newPos_ = rescale(newPos_, LimitFactors(0, 0)); } void MoveAnimation::doUpdate(Window* element, double nextFramepartTime) diff --git a/libs/s25main/controls/ctrlTextButton.cpp b/libs/s25main/controls/ctrlTextButton.cpp index 3735228710..9029bbecf5 100644 --- a/libs/s25main/controls/ctrlTextButton.cpp +++ b/libs/s25main/controls/ctrlTextButton.cpp @@ -11,7 +11,7 @@ static constexpr unsigned contentOffset = 2; ctrlTextButton::ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, - const std::string& tooltip, const Extent& limitFactors) + const std::string& tooltip, const LimitFactors& limitFactors) : ctrlButton(parent, id, pos, size, tc, tooltip), ctrlBaseText(text, COLOR_YELLOW, font) { Window::SetLimitFactors(limitFactors); diff --git a/libs/s25main/controls/ctrlTextButton.h b/libs/s25main/controls/ctrlTextButton.h index 8ea4139a5e..6762bc0ca2 100644 --- a/libs/s25main/controls/ctrlTextButton.h +++ b/libs/s25main/controls/ctrlTextButton.h @@ -12,7 +12,7 @@ class ctrlTextButton : public ctrlButton, public ctrlBaseText { public: ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& text, const glFont* font, const std::string& tooltip, const Extent& limitFactors); + const std::string& text, const glFont* font, const std::string& tooltip, const LimitFactors& limitFactors); /// Changes width so at most this many chars can be shown void ResizeForMaxChars(unsigned numChars); diff --git a/tests/s25Main/UI/testControls.cpp b/tests/s25Main/UI/testControls.cpp index 0a0e0f2d82..14cbaff8ad 100644 --- a/tests/s25Main/UI/testControls.cpp +++ b/tests/s25Main/UI/testControls.cpp @@ -61,7 +61,7 @@ BOOST_FIXTURE_TEST_CASE(MouseOver, uiHelper::Fixture) const auto pos = rttr::test::randomPoint(); const auto size = rttr::test::randomPoint(10); const auto font = createMockFont({'H', 'e', 'l', 'o', '?'}); - ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), "", Extent(0, 0)); + ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), "", LimitFactors(0, 0)); BOOST_TEST(bt.IsMouseOver(pos)); BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(1, 0))); BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(0, 1))); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(AdjustWidthForMaxChars_SetsCorrectSize) } { ctrlTextButton txt(nullptr, 1, rttr::test::randomPoint(), rttr::test::randomPoint(), - TextureColor::Green1, "foo", font.get(), "tooltip", Extent(0, 0)); + TextureColor::Green1, "foo", font.get(), "tooltip", LimitFactors(0, 0)); const Extent sizeBefore = txt.GetSize(); // Don't assume size, so get size for 0 chars txt.ResizeForMaxChars(0); From 311036b5657bed56a3b36bdaa33052887666b6fe Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 28 Feb 2026 19:52:48 +0100 Subject: [PATCH 10/24] fixing style --- libs/s25main/Window.cpp | 4 ++-- libs/s25main/Window.h | 14 +++++++------- libs/s25main/controls/ctrlTextButton.h | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index bcf1ec6114..1460d252ed 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -18,8 +18,8 @@ #include Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const LimitFactors& size) - : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(LimitFactors(0, 0)), active_(false), visible_(true), - scale_(false), isInMouseRelay(false), animations_(this) + : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(LimitFactors(0, 0)), active_(false), + visible_(true), scale_(false), isInMouseRelay(false), animations_(this) {} Window::~Window() diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 5415704720..422b9cdf0a 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -306,14 +306,14 @@ class Window virtual bool IsMessageRelayAllowed() const; private: - Window* const parent_; /// Handle auf das Parentfenster. - unsigned id_; /// ID des Fensters. - DrawPoint pos_; /// Position des Fensters. - Extent size_; /// Höhe des Fensters. + Window* const parent_; /// Handle auf das Parentfenster. + unsigned id_; /// ID des Fensters. + DrawPoint pos_; /// Position des Fensters. + Extent size_; /// Höhe des Fensters. LimitFactors limitFactors_; /// X and Y scaling limiting factors - bool active_; /// Fenster aktiv? - bool visible_; /// Fenster sichtbar? - bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? + bool active_; /// Fenster aktiv? + bool visible_; /// Fenster sichtbar? + bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? std::map lockedAreas_; /// gesperrte Regionen des Fensters. std::vector tofreeAreas_; diff --git a/libs/s25main/controls/ctrlTextButton.h b/libs/s25main/controls/ctrlTextButton.h index 6762bc0ca2..d003fdaeec 100644 --- a/libs/s25main/controls/ctrlTextButton.h +++ b/libs/s25main/controls/ctrlTextButton.h @@ -12,7 +12,8 @@ class ctrlTextButton : public ctrlButton, public ctrlBaseText { public: ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& text, const glFont* font, const std::string& tooltip, const LimitFactors& limitFactors); + const std::string& text, const glFont* font, const std::string& tooltip, + const LimitFactors& limitFactors); /// Changes width so at most this many chars can be shown void ResizeForMaxChars(unsigned numChars); From 75225dc1900ffc06452c0930c56e3cfffa2d2a55 Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 28 Feb 2026 19:55:40 +0100 Subject: [PATCH 11/24] fixing whitespace issue --- libs/s25main/Window.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 422b9cdf0a..a596a17fba 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -293,7 +293,7 @@ class Window /// scales X- and Y values to fit the screen, additionally considering a limiting factor for size template static T_Pt Scale(const T_Pt& pt, const LimitFactors& limfactors); - /// scales X- and Y values of pos_ and size_, additionally considering limitFactors_ for size_ scaling + /// scales X- and Y values of pos_ and size_, additionally considering limitFactors_ for size_ scaling void ScaleByFactor(); /// Scales the value when scale_ is true, else returns the value template From a80169e829e29075ad04bd486bb9a76b98de6ffc Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 14 Mar 2026 17:31:15 +0100 Subject: [PATCH 12/24] Move scaling by factor into window constructor --- libs/s25main/Window.cpp | 16 ++++++++-------- libs/s25main/Window.h | 6 +++--- libs/s25main/controls/ctrlButton.cpp | 4 ++-- libs/s25main/controls/ctrlButton.h | 2 +- libs/s25main/controls/ctrlTextButton.cpp | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 1460d252ed..d2eb2723c7 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -17,10 +17,13 @@ #include #include -Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const LimitFactors& size) - : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(LimitFactors(0, 0)), active_(false), +Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const LimitFactors& factors) + : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(factors), active_(false), visible_(true), scale_(false), isInMouseRelay(false), animations_(this) -{} +{ + if(parent != nullptr && parent->GetScale() && factors != (LimitFactors(0, 0))) + ScaleByFactor(); +} Window::~Window() { @@ -566,11 +569,8 @@ T_Pt Window::Scale(const T_Pt& pt, const LimitFactors& limfactors) void Window::ScaleByFactor() { - if(scale_) - { - pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); - size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); - } + pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); + size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); } template diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index a596a17fba..8e25b0fcf8 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -65,7 +65,7 @@ class Window using KeyboardMsgHandler = bool (Window::*)(const KeyEvent&); using MouseMsgHandler = bool (Window::*)(const MouseCoords&); - Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0)); + Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0), const LimitFactors& factors = LimitFactors(0, 0)); virtual ~Window(); /// zeichnet das Fenster. void Draw(); @@ -300,6 +300,8 @@ class Window T_Pt ScaleIf(const T_Pt& pt) const; /// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht. void SetScale(bool scale = true) { this->scale_ = scale; } + /// get Scale-Value + bool GetScale() { return this->scale_; } /// zeichnet das Fenster. virtual void Draw_(); /// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht? @@ -329,8 +331,6 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; - if(ctrl->limitFactors_ != LimitFactors(0, 0)) - ctrl->ScaleByFactor(); ctrl->SetActive(active_); return ctrl; diff --git a/libs/s25main/controls/ctrlButton.cpp b/libs/s25main/controls/ctrlButton.cpp index b07c65393c..9052e3b344 100644 --- a/libs/s25main/controls/ctrlButton.cpp +++ b/libs/s25main/controls/ctrlButton.cpp @@ -8,8 +8,8 @@ #include "drivers/VideoDriverWrapper.h" ctrlButton::ctrlButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& tooltip) - : Window(parent, id, pos, size), ctrlBaseTooltip(tooltip), tc(tc), state(ButtonState::Up), hasBorder(true), + const std::string& tooltip, const LimitFactors& factors) + : Window(parent, id, pos, size, factors), ctrlBaseTooltip(tooltip), tc(tc), state(ButtonState::Up), hasBorder(true), isChecked(false), isIlluminated(false), isEnabled(true) {} diff --git a/libs/s25main/controls/ctrlButton.h b/libs/s25main/controls/ctrlButton.h index 92a9eff733..a865f5dfcc 100644 --- a/libs/s25main/controls/ctrlButton.h +++ b/libs/s25main/controls/ctrlButton.h @@ -17,7 +17,7 @@ class ctrlButton : public Window, public ctrlBaseTooltip { public: ctrlButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& tooltip); + const std::string& tooltip, const LimitFactors& factors = LimitFactors(0, 0)); ~ctrlButton() override; void SetEnabled(bool enable = true); diff --git a/libs/s25main/controls/ctrlTextButton.cpp b/libs/s25main/controls/ctrlTextButton.cpp index 9029bbecf5..d800298f7b 100644 --- a/libs/s25main/controls/ctrlTextButton.cpp +++ b/libs/s25main/controls/ctrlTextButton.cpp @@ -12,7 +12,7 @@ static constexpr unsigned contentOffset = 2; ctrlTextButton::ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip, const LimitFactors& limitFactors) - : ctrlButton(parent, id, pos, size, tc, tooltip), ctrlBaseText(text, COLOR_YELLOW, font) + : ctrlButton(parent, id, pos, size, tc, tooltip, limitFactors), ctrlBaseText(text, COLOR_YELLOW, font) { Window::SetLimitFactors(limitFactors); } From f12f9e6897d15311332a47398a1f5a2912e975c1 Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 14 Mar 2026 18:30:27 +0100 Subject: [PATCH 13/24] Largely remove ScaleIf calls from Window.cpp --- libs/s25main/Window.cpp | 51 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index d2eb2723c7..85a98b6dad 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -21,8 +21,11 @@ Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(factors), active_(false), visible_(true), scale_(false), isInMouseRelay(false), animations_(this) { - if(parent != nullptr && parent->GetScale() && factors != (LimitFactors(0, 0))) + if(parent != nullptr && parent->GetScale()) + { + scale_ = parent->GetScale(); ScaleByFactor(); + } } Window::~Window() @@ -227,7 +230,7 @@ void Window::DeleteCtrl(unsigned id) ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, BuildingType type, const Nation nation, unsigned short size, const std::string& tooltip) { - return AddCtrl(new ctrlBuildingIcon(this, id, ScaleIf(pos), type, nation, ScaleIf(Extent(size, 0)).x, tooltip)); + return AddCtrl(new ctrlBuildingIcon(this, id, pos, type, nation, Extent(size, 0).x, tooltip)); } ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -239,13 +242,13 @@ ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Exten ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const unsigned fillColor, const std::string& tooltip) { - return AddCtrl(new ctrlColorButton(this, id, ScaleIf(pos), ScaleIf(size), tc, fillColor, tooltip)); + return AddCtrl(new ctrlColorButton(this, id, pos, size, tc, fillColor, tooltip)); } ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, ITexture* const image, const std::string& tooltip) { - return AddCtrl(new ctrlImageButton(this, id, ScaleIf(pos), ScaleIf(size), tc, image, tooltip)); + return AddCtrl(new ctrlImageButton(this, id, pos, size, tc, image, tooltip)); } ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -257,37 +260,37 @@ ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Exte ctrlChat* Window::AddChatCtrl(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font) { - return AddCtrl(new ctrlChat(this, id, ScaleIf(pos), ScaleIf(size), tc, font)); + return AddCtrl(new ctrlChat(this, id, pos, size, tc, font)); } ctrlCheck* Window::AddCheckBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const std::string& text, const glFont* font, bool readonly) { - return AddCtrl(new ctrlCheck(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, readonly)); + return AddCtrl(new ctrlCheck(this, id, pos, size, tc, text, font, readonly)); } ctrlComboBox* Window::AddComboBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, unsigned short max_list_height, bool readonly) { - return AddCtrl(new ctrlComboBox(this, id, ScaleIf(pos), ScaleIf(size), tc, font, max_list_height, readonly)); + return AddCtrl(new ctrlComboBox(this, id, pos, size, tc, font, max_list_height, readonly)); } ctrlDeepening* Window::AddTextDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const std::string& text, const glFont* font, unsigned color, FontStyle style) { - return AddCtrl(new ctrlTextDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, text, font, color, style)); + return AddCtrl(new ctrlTextDeepening(this, id, pos, size, tc, text, font, color, style)); } ctrlDeepening* Window::AddColorDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, unsigned fillColor) { - return AddCtrl(new ctrlColorDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, fillColor)); + return AddCtrl(new ctrlColorDeepening(this, id, pos, size, tc, fillColor)); } ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, ITexture* image) { - return AddCtrl(new ctrlImageDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, image)); + return AddCtrl(new ctrlImageDeepening(this, id, pos, size, tc, image)); } ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, @@ -300,7 +303,7 @@ ctrlEdit* Window::AddEdit(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short maxlength, bool password, bool disabled, bool notify) { return AddCtrl( - new ctrlEdit(this, id, ScaleIf(pos), ScaleIf(size), tc, font, maxlength, password, disabled, notify)); + new ctrlEdit(this, id, pos, size, tc, font, maxlength, password, disabled, notify)); } ctrlGroup* Window::AddGroup(unsigned id) @@ -310,7 +313,7 @@ ctrlGroup* Window::AddGroup(unsigned id) ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, ITexture* image, const std::string& tooltip) { - return AddCtrl(new ctrlImage(this, id, ScaleIf(pos), image, tooltip)); + return AddCtrl(new ctrlImage(this, id, pos, image, tooltip)); } ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitmap* image, const std::string& tooltip) @@ -320,13 +323,13 @@ ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitm ctrlList* Window::AddList(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font) { - return AddCtrl(new ctrlList(this, id, ScaleIf(pos), ScaleIf(size), tc, font)); + return AddCtrl(new ctrlList(this, id, pos, size, tc, font)); } ctrlMultiline* Window::AddMultiline(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, FontStyle format) { - return AddCtrl(new ctrlMultiline(this, id, ScaleIf(pos), ScaleIf(size), tc, font, format)); + return AddCtrl(new ctrlMultiline(this, id, pos, size, tc, font, format)); } /** @@ -358,7 +361,7 @@ ctrlMultiSelectGroup* Window::AddMultiSelectGroup(unsigned id, GroupSelectType s ctrlPercent* Window::AddPercent(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, unsigned text_color, const glFont* font, const unsigned short* percentage) { - return AddCtrl(new ctrlPercent(this, id, ScaleIf(pos), ScaleIf(size), tc, text_color, font, percentage)); + return AddCtrl(new ctrlPercent(this, id, pos, size, tc, text_color, font, percentage)); } ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, @@ -366,7 +369,7 @@ ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Exten const std::string& tooltip, const Extent& padding, unsigned force_color, const std::string& button_minus_tooltip, const std::string& button_plus_tooltip) { - return AddCtrl(new ctrlProgress(this, id, ScaleIf(pos), ScaleIf(size), tc, button_minus, button_plus, maximum, + return AddCtrl(new ctrlProgress(this, id, pos, size, tc, button_minus, button_plus, maximum, padding, force_color, tooltip, button_minus_tooltip, button_plus_tooltip)); } @@ -375,12 +378,12 @@ ctrlScrollBar* Window::AddScrollBar(unsigned id, const DrawPoint& pos, const Ext { button_height = ScaleIf(Extent(0, button_height)).y; - return AddCtrl(new ctrlScrollBar(this, id, ScaleIf(pos), ScaleIf(size), button_height, tc, page_size)); + return AddCtrl(new ctrlScrollBar(this, id, pos, size, button_height, tc, page_size)); } ctrlTab* Window::AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short width) { - return AddCtrl(new ctrlTab(this, id, ScaleIf(pos), ScaleIf(Extent(width, 0)).x)); + return AddCtrl(new ctrlTab(this, id, pos, Extent(width, 0).x)); } /** @@ -390,7 +393,7 @@ ctrlTab* Window::AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short wi ctrlTable* Window::AddTable(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, std::vector columns) { - return AddCtrl(new ctrlTable(this, id, ScaleIf(pos), ScaleIf(size), tc, font, std::move(columns))); + return AddCtrl(new ctrlTable(this, id, pos, size, tc, font, std::move(columns))); } ctrlTimer* Window::AddTimer(unsigned id, std::chrono::milliseconds timeout) @@ -417,13 +420,13 @@ ctrlTimer* Window::AddTimer(unsigned id, std::chrono::milliseconds timeout) ctrlText* Window::AddText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, FontStyle format, const glFont* font) { - return AddCtrl(new ctrlText(this, id, ScaleIf(pos), text, color, format, font)); + return AddCtrl(new ctrlText(this, id, pos, text, color, format, font)); } ctrlMapSelection* Window::AddMapSelection(unsigned id, const DrawPoint& pos, const Extent& size, const SelectionMapInputData& inputData) { - return AddCtrl(new ctrlMapSelection(this, id, ScaleIf(pos), ScaleIf(size), inputData)); + return AddCtrl(new ctrlMapSelection(this, id, pos, size, inputData)); } TextFormatSetter Window::AddFormattedText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, @@ -440,7 +443,7 @@ ctrlVarDeepening* Window::AddVarDeepening(unsigned id, const DrawPoint& pos, con va_start(liste, parameters); auto* ctrl = - new ctrlVarDeepening(this, id, ScaleIf(pos), ScaleIf(size), tc, formatstr, font, color, parameters, liste); + new ctrlVarDeepening(this, id, pos, size, tc, formatstr, font, color, parameters, liste); va_end(liste); @@ -471,7 +474,7 @@ ctrlVarText* Window::AddVarText(unsigned id, const DrawPoint& pos, const std::st va_list liste; va_start(liste, parameters); - auto* ctrl = new ctrlVarText(this, id, ScaleIf(pos), formatstr, color, format, font, parameters, liste); + auto* ctrl = new ctrlVarText(this, id, pos, formatstr, color, format, font, parameters, liste); va_end(liste); @@ -481,7 +484,7 @@ ctrlVarText* Window::AddVarText(unsigned id, const DrawPoint& pos, const std::st ctrlPreviewMinimap* Window::AddPreviewMinimap(const unsigned id, const DrawPoint& pos, const Extent& size, libsiedler2::ArchivItem_Map* const map) { - return AddCtrl(new ctrlPreviewMinimap(this, id, ScaleIf(pos), ScaleIf(size), map)); + return AddCtrl(new ctrlPreviewMinimap(this, id, pos, size, map)); } void Window::Draw3D(const Rect& rect, TextureColor tc, bool elevated, bool highlighted, bool illuminated, From a6dd3e3224eeaa120a1c9a7e5827986bd68ac680 Mon Sep 17 00:00:00 2001 From: Noseey Date: Sat, 14 Mar 2026 21:34:44 +0100 Subject: [PATCH 14/24] Merge ScaleWindowPropUp and RescaleWindowProp --- libs/common/include/Point.h | 5 --- libs/s25main/RescaleWindowProp.h | 52 +++++++++++++----------- libs/s25main/Window.cpp | 8 ++-- libs/s25main/Window.h | 2 + libs/s25main/animation/MoveAnimation.cpp | 2 +- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/libs/common/include/Point.h b/libs/common/include/Point.h index 428ce18303..7341c31177 100644 --- a/libs/common/include/Point.h +++ b/libs/common/include/Point.h @@ -69,11 +69,6 @@ using Position = Point; /// Type for describing an extent/size etc. (unsigned type) using Extent = Point; using PointF = Point; -/// Type for describing limiting scaling factors for GUI elements (unsigned type) -/// Limits scaling from Base Resolution 800x600 to fit screen size in a granularity of 10 -/// Valid range is from 1 up to 10, values outside the range don't impose any limiting -/// e. g. Value 1: scales 1/10 of the difference between screensize and Base Resolution -using LimitFactors = Point; //-V:all:810 ////////////////////////////////////////////////////////////////////////// diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 1a95a08e2f..75a283865e 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -4,70 +4,74 @@ #pragma once -/// Functor or static method to scale a window propertie from the real coordinates -/// (relative to 800x600 resolution) to new coordinates given a size -struct ScaleWindowPropUp +/// Functor or static method to (Re-) scale window properties from the real coordinates +/// (relative to reference resolution) to new coordinates given a size +struct ScaleWindowProp { - Extent size; - ScaleWindowPropUp(const Extent& size) : size(size) {} + /// Type for describing limiting scaling factors for GUI elements (unsigned type) + /// Limits scaling from Base Resolution 800x600 to fit screen size in a granularity of 10 + /// Valid range is from 1 up to 10, values outside the range don't impose any limiting + /// e. g. Value 1: scales 1/10 of the difference between screensize and Reference Resolution + using LimitFactors = Point; + + /// Reference Resolution used + static constexpr Extent REFERENCE_RESOLUTION = Extent(800, 600); + + Extent size, oldSize, newSize; + ScaleWindowProp(const Extent& size) : size(size) {} + ScaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} template static T_Pt scale(const T_Pt& value, const Extent& size, const LimitFactors& limfactors); + template T_Pt operator()(const T_Pt& value) const; -}; - -/// Rescales a window's properties (size or positions) -struct RescaleWindowProp -{ - Extent oldSize, newSize; - RescaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template T_Pt operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const; }; template -inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale, const LimitFactors& limfactors) +inline T_Pt ScaleWindowProp::scale(const T_Pt& value, const Extent& sizeToScale, const LimitFactors& limfactors) { if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) { - T_Pt diff(sizeToScale - Extent(800, 600)); - T_Pt limScaledValue(value * (sizeToScale - diff * limfactors / 10) / Extent(800, 600)); + T_Pt diff(sizeToScale - REFERENCE_RESOLUTION); + T_Pt limScaledValue(value * (sizeToScale - diff * limfactors / 10) / REFERENCE_RESOLUTION); return limScaledValue; } else { - T_Pt scaledValue(value * sizeToScale / Extent(800, 600)); + T_Pt scaledValue(value * sizeToScale / REFERENCE_RESOLUTION); return scaledValue; } } template -inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const +inline T_Pt ScaleWindowProp::operator()(const T_Pt& value) const { return scale(value, size, LimitFactors(0, 0)); } template -inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const +inline T_Pt ScaleWindowProp::operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const { T_Pt realValue; if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) { - T_Pt diff(oldSize - Extent(800, 600)); - T_Pt limUnscaleValue(oldValue.x * 800 / (oldSize.x - (diff.x * limfactors.x / 10)), - oldValue.y * 600 / (oldSize.y - (diff.y * limfactors.y / 10))); + T_Pt diff(oldSize - REFERENCE_RESOLUTION); + T_Pt limUnscaleValue(oldValue.x * REFERENCE_RESOLUTION.x / (oldSize.x - (diff.x * limfactors.x / 10)), + oldValue.y * REFERENCE_RESOLUTION.y / (oldSize.y - (diff.y * limfactors.y / 10))); realValue = limUnscaleValue; } else { - T_Pt unscaleValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); + T_Pt unscaleValue(oldValue.x * REFERENCE_RESOLUTION.x / oldSize.x, oldValue.y * REFERENCE_RESOLUTION.y / oldSize.y); realValue = unscaleValue; } // Check for rounding errors - T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize, limfactors); + T_Pt checkValue = ScaleWindowProp::scale(realValue, oldSize, limfactors); if(checkValue.x < oldValue.x) realValue.x++; if(checkValue.y < oldValue.y) realValue.y++; - return ScaleWindowPropUp::scale(realValue, newSize, limfactors); + return ScaleWindowProp::scale(realValue, newSize, limfactors); } diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 85a98b6dad..e0187aebbd 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -550,7 +550,7 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) // If the window elements don't get scaled there is nothing to do if(!scale_) return; - RescaleWindowProp rescale(sr.oldSize, sr.newSize); + ScaleWindowProp rescale(sr.oldSize, sr.newSize); for(Window* ctrl : childIdToWnd_ | boost::adaptors::map_values) { if(!ctrl) @@ -567,13 +567,13 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) template T_Pt Window::Scale(const T_Pt& pt, const LimitFactors& limfactors) { - return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactors); + return ScaleWindowProp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactors); } void Window::ScaleByFactor() { - pos_ = ScaleWindowPropUp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); - size_ = ScaleWindowPropUp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); + pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); + size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); } template diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 8e25b0fcf8..b971348fac 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -58,6 +58,8 @@ namespace libsiedler2 { class ArchivItem_Map; } +using LimitFactors = Point; + /// Die Basisklasse der Fenster. class Window { diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 514d552bfa..8238a8b1ca 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -21,7 +21,7 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { - RescaleWindowProp rescale(rs.oldSize, rs.newSize); + ScaleWindowProp rescale(rs.oldSize, rs.newSize); origPos_ = rescale(origPos_, LimitFactors(0, 0)); newPos_ = rescale(newPos_, LimitFactors(0, 0)); } From 4af1ae4e950ec3b0c2ac4e9764e8ec016af35d2b Mon Sep 17 00:00:00 2001 From: Noseey Date: Sun, 22 Mar 2026 14:58:06 +0100 Subject: [PATCH 15/24] Properly consider scaling for Scrollbars, Tables and Lists --- libs/s25main/Window.cpp | 2 +- libs/s25main/controls/ctrlChat.cpp | 11 +++++++++-- libs/s25main/controls/ctrlComboBox.cpp | 2 +- libs/s25main/controls/ctrlList.cpp | 2 +- libs/s25main/controls/ctrlScrollBar.cpp | 2 +- libs/s25main/controls/ctrlTable.cpp | 6 ++++++ 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index e0187aebbd..b6100a54f1 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -376,7 +376,7 @@ ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Exten ctrlScrollBar* Window::AddScrollBar(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short button_height, TextureColor tc, unsigned short page_size) { - button_height = ScaleIf(Extent(0, button_height)).y; + button_height = Extent(0, button_height).y; return AddCtrl(new ctrlScrollBar(this, id, pos, size, button_height, tc, page_size)); } diff --git a/libs/s25main/controls/ctrlChat.cpp b/libs/s25main/controls/ctrlChat.cpp index 332d793951..58890fd796 100644 --- a/libs/s25main/controls/ctrlChat.cpp +++ b/libs/s25main/controls/ctrlChat.cpp @@ -30,12 +30,19 @@ ctrlChat::ctrlChat(Window* parent, unsigned id, const DrawPoint& pos, const Exte : Window(parent, id, pos, size), tc(tc), font(font), time_color(0xFFFFFFFF) { // Zeilen pro Seite festlegen errechnen - page_size = (size.y - 4) / (font->getHeight() + 2); + page_size = (GetSize().y - 4) / (font->getHeight() + 2); + + const bool tmpScale = GetScale(); + + // Always exclude the following from scaling + SetScale(false); // Scrollbalken hinzufügen - AddScrollBar(0, DrawPoint(size.x - SCROLLBAR_WIDTH, 0), Extent(SCROLLBAR_WIDTH, size.y), SCROLLBAR_WIDTH, tc, + AddScrollBar(0, DrawPoint(GetSize().x - SCROLLBAR_WIDTH, 0), Extent(SCROLLBAR_WIDTH, GetSize().y), SCROLLBAR_WIDTH, tc, page_size); + SetScale(tmpScale); + // Breite der Klammern <> um die Spielernamen berechnen bracket1_size = font->getWidth("<"); bracket2_size = font->getWidth("> "); diff --git a/libs/s25main/controls/ctrlComboBox.cpp b/libs/s25main/controls/ctrlComboBox.cpp index d31691f519..9cba41a22e 100644 --- a/libs/s25main/controls/ctrlComboBox.cpp +++ b/libs/s25main/controls/ctrlComboBox.cpp @@ -25,7 +25,7 @@ ctrlComboBox::ctrlComboBox(Window* parent, unsigned id, const DrawPoint& pos, co if(!readonly) AddImageButton(1, DrawPoint(size.x - size.y, 0), Extent(size.y, size.y), tc, LOADER.GetImageN("io", 34)); - Resize(size); + Resize(GetSize()); } /** diff --git a/libs/s25main/controls/ctrlList.cpp b/libs/s25main/controls/ctrlList.cpp index 680e3ee750..40d113365b 100644 --- a/libs/s25main/controls/ctrlList.cpp +++ b/libs/s25main/controls/ctrlList.cpp @@ -14,7 +14,7 @@ ctrlList::ctrlList(Window* parent, unsigned id, const DrawPoint& pos, const Exte { pagesize = (GetSize().y - 4) / font->getHeight(); - AddScrollBar(0, DrawPoint(GetSize().x - 20, 0), Extent(20, GetSize().y), 20, tc, pagesize); + AddScrollBar(0, DrawPoint(size.x - 20, 0), Extent(20, size.y), 20, tc, pagesize); } ctrlList::~ctrlList() diff --git a/libs/s25main/controls/ctrlScrollBar.cpp b/libs/s25main/controls/ctrlScrollBar.cpp index 31103bca48..28f9d39147 100644 --- a/libs/s25main/controls/ctrlScrollBar.cpp +++ b/libs/s25main/controls/ctrlScrollBar.cpp @@ -19,7 +19,7 @@ ctrlScrollBar::ctrlScrollBar(Window* parent, unsigned id, const DrawPoint& pos, AddImageButton(1, DrawPoint(0, (size.y > button_height) ? size.y - button_height : 1), Extent(size.x, button_height), tc, LOADER.GetImageN("io", 34)); - Resize(size); + Resize(GetSize()); } void ctrlScrollBar::Scroll(int distance) diff --git a/libs/s25main/controls/ctrlTable.cpp b/libs/s25main/controls/ctrlTable.cpp index ba9a843e77..d47617e009 100644 --- a/libs/s25main/controls/ctrlTable.cpp +++ b/libs/s25main/controls/ctrlTable.cpp @@ -135,6 +135,11 @@ ctrlTable::ctrlTable(Window* parent, unsigned id, const DrawPoint& pos, const Ex header_height = font->getHeight() + 10; line_count = (GetSize().y - header_height - 2) / font->getHeight(); + const bool tmpScale = GetScale(); + + // Always exclude the following from scaling + SetScale(false); + // Scrollbar hinzufügen AddScrollBar(0, DrawPoint(GetSize().x - 20, 0), Extent(20, GetSize().y), 20, tc, line_count); @@ -143,6 +148,7 @@ ctrlTable::ctrlTable(Window* parent, unsigned id, const DrawPoint& pos, const Ex AddTextButton(i + 1, DrawPoint(0, 0), Extent(0, header_height), tc, columns_[i].title, font); } + SetScale(tmpScale); ResetButtonWidths(); } From 87589d37e13f0d445b4fd41ec3b2de19579b5e12 Mon Sep 17 00:00:00 2001 From: Noseey Date: Sun, 22 Mar 2026 15:47:29 +0100 Subject: [PATCH 16/24] apply size limiting to specific desktops --- libs/s25main/Window.cpp | 13 ++++++++++--- libs/s25main/Window.h | 6 ++++++ libs/s25main/desktops/Desktop.cpp | 1 + libs/s25main/desktops/dskGameLobby.cpp | 1 + libs/s25main/desktops/dskOptions.cpp | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index b6100a54f1..15c21fc750 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -19,11 +19,12 @@ Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const LimitFactors& factors) : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(factors), active_(false), - visible_(true), scale_(false), isInMouseRelay(false), animations_(this) + visible_(true), scale_(false), limit_(false), isInMouseRelay(false), animations_(this) { if(parent != nullptr && parent->GetScale()) { scale_ = parent->GetScale(); + limit_ = parent->GetLimit(); ScaleByFactor(); } } @@ -556,7 +557,10 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(!ctrl) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) - Extent newSize = rescale(ctrl->GetSize(), ctrl->GetLimitFactors()); + LimitFactors limits(0, 0); + if(limit_) + limits = ctrl->GetLimitFactors(); + Extent newSize = rescale(ctrl->GetSize(), limits); ctrl->SetPos(rescale(ctrl->GetPos(), LimitFactors(0, 0))); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); @@ -573,7 +577,10 @@ T_Pt Window::Scale(const T_Pt& pt, const LimitFactors& limfactors) void Window::ScaleByFactor() { pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); - size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); + if(limit_) + size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); + else + size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); } template diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index b971348fac..0fc21000d8 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -302,8 +302,12 @@ class Window T_Pt ScaleIf(const T_Pt& pt) const; /// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht. void SetScale(bool scale = true) { this->scale_ = scale; } + /// Sets the limit value, deciding of control size shall be limited. + void SetLimit(bool limit = true) { this->limit_ = limit; } /// get Scale-Value bool GetScale() { return this->scale_; } + /// get Limit-Value + bool GetLimit() { return this->limit_; } /// zeichnet das Fenster. virtual void Draw_(); /// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht? @@ -318,6 +322,7 @@ class Window bool active_; /// Fenster aktiv? bool visible_; /// Fenster sichtbar? bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? + bool limit_; /// Should control size be limited? std::map lockedAreas_; /// gesperrte Regionen des Fensters. std::vector tofreeAreas_; @@ -333,6 +338,7 @@ inline T* Window::AddCtrl(T* ctrl) childIdToWnd_.insert(std::make_pair(ctrl->GetID(), ctrl)); ctrl->scale_ = scale_; + ctrl->limit_ = limit_; ctrl->SetActive(active_); return ctrl; diff --git a/libs/s25main/desktops/Desktop.cpp b/libs/s25main/desktops/Desktop.cpp index 5a4db4253b..62ee62ace1 100644 --- a/libs/s25main/desktops/Desktop.cpp +++ b/libs/s25main/desktops/Desktop.cpp @@ -25,6 +25,7 @@ Desktop::Desktop(glArchivItem_Bitmap* background) : Window(nullptr, 0, DrawPoint::all(0), VIDEODRIVER.GetRenderSize()), background(background), lastFPS_(0) { SetScale(true); + SetLimit(true); SetFpsDisplay(true); // By default limit the maximum frame rate to 60 FPS - used for main menu if(SETTINGS.video.framerate < 0) diff --git a/libs/s25main/desktops/dskGameLobby.cpp b/libs/s25main/desktops/dskGameLobby.cpp index 2e61032c23..9a512a0c76 100644 --- a/libs/s25main/desktops/dskGameLobby.cpp +++ b/libs/s25main/desktops/dskGameLobby.cpp @@ -131,6 +131,7 @@ dskGameLobby::dskGameLobby(ServerType serverType, std::shared_ptr gam localPlayerId_(playerId), lobbyClient_(std::move(lobbyClient)), hasCountdown_(false), wasActivated(false), gameChat(nullptr), lobbyChat(nullptr), lobbyChatTabAnimId(0), localChatTabAnimId(0) { + SetLimit(false); // If no lobby don't do anything else if(!gameLobby_) return; diff --git a/libs/s25main/desktops/dskOptions.cpp b/libs/s25main/desktops/dskOptions.cpp index 1048729aa5..7492bad5f5 100644 --- a/libs/s25main/desktops/dskOptions.cpp +++ b/libs/s25main/desktops/dskOptions.cpp @@ -146,6 +146,7 @@ static VideoMode getAspectRatio(const VideoMode& vm) dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0)) { + SetLimit(false); AddText(ID_txtOptions, DrawPoint(400, 10), _("Options"), COLOR_YELLOW, FontStyle::CENTER, LargeFont); ctrlOptionGroup* mainGroup = AddOptionGroup(ID_grpOptions, GroupSelectType::Check); From b920a1896859b391e6ce911a1d1e97e978e00061 Mon Sep 17 00:00:00 2001 From: Noseey Date: Tue, 7 Apr 2026 19:27:40 +0200 Subject: [PATCH 17/24] Change GUI scaling limit to percentage based value --- libs/s25main/RescaleWindowProp.h | 39 ++++++++---------------- libs/s25main/Window.cpp | 17 ++++++++--- libs/s25main/Window.h | 2 +- libs/s25main/animation/MoveAnimation.cpp | 4 +-- libs/s25main/controls/ctrlButton.h | 2 +- libs/s25main/controls/ctrlTextButton.cpp | 4 +-- tests/s25Main/UI/testControls.cpp | 4 +-- 7 files changed, 32 insertions(+), 40 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 75a283865e..b6e9047f9d 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -8,10 +8,11 @@ /// (relative to reference resolution) to new coordinates given a size struct ScaleWindowProp { - /// Type for describing limiting scaling factors for GUI elements (unsigned type) - /// Limits scaling from Base Resolution 800x600 to fit screen size in a granularity of 10 - /// Valid range is from 1 up to 10, values outside the range don't impose any limiting - /// e. g. Value 1: scales 1/10 of the difference between screensize and Reference Resolution + /// ScalingPercentage Type for proportional scaling, capped range from 0 - 100% + /// 100%: scales GUI element base size fully proportional to target size + /// 50%: considers only half of target size + /// 0% does not apply any scaling at all + /// The target size is normalized against the reference solution using LimitFactors = Point; /// Reference Resolution used @@ -34,39 +35,25 @@ struct ScaleWindowProp template inline T_Pt ScaleWindowProp::scale(const T_Pt& value, const Extent& sizeToScale, const LimitFactors& limfactors) { - if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) - { - T_Pt diff(sizeToScale - REFERENCE_RESOLUTION); - T_Pt limScaledValue(value * (sizeToScale - diff * limfactors / 10) / REFERENCE_RESOLUTION); - return limScaledValue; - } else - { - T_Pt scaledValue(value * sizeToScale / REFERENCE_RESOLUTION); - return scaledValue; - } + T_Pt diff(sizeToScale - REFERENCE_RESOLUTION); + T_Pt limScaledValue(value * (sizeToScale - diff + (diff * limfactors / 100)) / REFERENCE_RESOLUTION); + return limScaledValue; } template inline T_Pt ScaleWindowProp::operator()(const T_Pt& value) const { - return scale(value, size, LimitFactors(0, 0)); + return scale(value, size, LimitFactors(100, 100)); } template inline T_Pt ScaleWindowProp::operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const { T_Pt realValue; - if(limfactors.x > 0 && limfactors.x < 11 && limfactors.y > 0 && limfactors.y < 11) - { - T_Pt diff(oldSize - REFERENCE_RESOLUTION); - T_Pt limUnscaleValue(oldValue.x * REFERENCE_RESOLUTION.x / (oldSize.x - (diff.x * limfactors.x / 10)), - oldValue.y * REFERENCE_RESOLUTION.y / (oldSize.y - (diff.y * limfactors.y / 10))); - realValue = limUnscaleValue; - } else - { - T_Pt unscaleValue(oldValue.x * REFERENCE_RESOLUTION.x / oldSize.x, oldValue.y * REFERENCE_RESOLUTION.y / oldSize.y); - realValue = unscaleValue; - } + T_Pt diff(oldSize - REFERENCE_RESOLUTION); + T_Pt limUnscaleValue(oldValue.x * REFERENCE_RESOLUTION.x / (oldSize.x - diff.x + (diff.x * limfactors.x / 100)), + oldValue.y * REFERENCE_RESOLUTION.y / (oldSize.y - diff.y + (diff.y * limfactors.y / 100))); + realValue = limUnscaleValue; // Check for rounding errors T_Pt checkValue = ScaleWindowProp::scale(realValue, oldSize, limfactors); if(checkValue.x < oldValue.x) diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 15c21fc750..8496b19a6e 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -21,6 +21,7 @@ Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(factors), active_(false), visible_(true), scale_(false), limit_(false), isInMouseRelay(false), animations_(this) { + SetLimitFactors(factors); if(parent != nullptr && parent->GetScale()) { scale_ = parent->GetScale(); @@ -79,6 +80,12 @@ LimitFactors Window::GetLimitFactors() const void Window::SetLimitFactors(LimitFactors limitFactors) { + if(limitFactors.x > 100) + limitFactors.x = 100; + + if(limitFactors.y > 100) + limitFactors.y = 100; + limitFactors_ = limitFactors; } @@ -237,7 +244,7 @@ ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, Bui ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, LimitFactors(7, 5))); + return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, LimitFactors(30, 50))); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -561,7 +568,7 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(limit_) limits = ctrl->GetLimitFactors(); Extent newSize = rescale(ctrl->GetSize(), limits); - ctrl->SetPos(rescale(ctrl->GetPos(), LimitFactors(0, 0))); + ctrl->SetPos(rescale(ctrl->GetPos(), LimitFactors(100, 100))); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); } @@ -576,17 +583,17 @@ T_Pt Window::Scale(const T_Pt& pt, const LimitFactors& limfactors) void Window::ScaleByFactor() { - pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); + pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(100, 100)); if(limit_) size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); else - size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); + size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), LimitFactors(100, 100)); } template T_Pt Window::ScaleIf(const T_Pt& pt) const { - return scale_ ? Scale(pt, LimitFactors(0, 0)) : pt; + return scale_ ? Scale(pt, LimitFactors(100, 100)) : pt; } // Inlining removes those. so add it here diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 0fc21000d8..dba0cc2b93 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -67,7 +67,7 @@ class Window using KeyboardMsgHandler = bool (Window::*)(const KeyEvent&); using MouseMsgHandler = bool (Window::*)(const MouseCoords&); - Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0), const LimitFactors& factors = LimitFactors(0, 0)); + Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0), const LimitFactors& factors = LimitFactors(100, 100)); virtual ~Window(); /// zeichnet das Fenster. void Draw(); diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 8238a8b1ca..711d8551a5 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -22,8 +22,8 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { ScaleWindowProp rescale(rs.oldSize, rs.newSize); - origPos_ = rescale(origPos_, LimitFactors(0, 0)); - newPos_ = rescale(newPos_, LimitFactors(0, 0)); + origPos_ = rescale(origPos_, LimitFactors(100, 100)); + newPos_ = rescale(newPos_, LimitFactors(100, 100)); } void MoveAnimation::doUpdate(Window* element, double nextFramepartTime) diff --git a/libs/s25main/controls/ctrlButton.h b/libs/s25main/controls/ctrlButton.h index a865f5dfcc..8cb20ee354 100644 --- a/libs/s25main/controls/ctrlButton.h +++ b/libs/s25main/controls/ctrlButton.h @@ -17,7 +17,7 @@ class ctrlButton : public Window, public ctrlBaseTooltip { public: ctrlButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& tooltip, const LimitFactors& factors = LimitFactors(0, 0)); + const std::string& tooltip, const LimitFactors& factors = LimitFactors(100, 100)); ~ctrlButton() override; void SetEnabled(bool enable = true); diff --git a/libs/s25main/controls/ctrlTextButton.cpp b/libs/s25main/controls/ctrlTextButton.cpp index d800298f7b..8184c85735 100644 --- a/libs/s25main/controls/ctrlTextButton.cpp +++ b/libs/s25main/controls/ctrlTextButton.cpp @@ -13,9 +13,7 @@ ctrlTextButton::ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip, const LimitFactors& limitFactors) : ctrlButton(parent, id, pos, size, tc, tooltip, limitFactors), ctrlBaseText(text, COLOR_YELLOW, font) -{ - Window::SetLimitFactors(limitFactors); -} +{} void ctrlTextButton::ResizeForMaxChars(unsigned numChars) { diff --git a/tests/s25Main/UI/testControls.cpp b/tests/s25Main/UI/testControls.cpp index 14cbaff8ad..550396c704 100644 --- a/tests/s25Main/UI/testControls.cpp +++ b/tests/s25Main/UI/testControls.cpp @@ -61,7 +61,7 @@ BOOST_FIXTURE_TEST_CASE(MouseOver, uiHelper::Fixture) const auto pos = rttr::test::randomPoint(); const auto size = rttr::test::randomPoint(10); const auto font = createMockFont({'H', 'e', 'l', 'o', '?'}); - ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), "", LimitFactors(0, 0)); + ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), "", LimitFactors(100, 100)); BOOST_TEST(bt.IsMouseOver(pos)); BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(1, 0))); BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(0, 1))); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(AdjustWidthForMaxChars_SetsCorrectSize) } { ctrlTextButton txt(nullptr, 1, rttr::test::randomPoint(), rttr::test::randomPoint(), - TextureColor::Green1, "foo", font.get(), "tooltip", LimitFactors(0, 0)); + TextureColor::Green1, "foo", font.get(), "tooltip", LimitFactors(100, 100)); const Extent sizeBefore = txt.GetSize(); // Don't assume size, so get size for 0 chars txt.ResizeForMaxChars(0); From 87436cf92a59b4dc5cd6341da04b19c4b870f95c Mon Sep 17 00:00:00 2001 From: Noseey Date: Wed, 8 Apr 2026 00:10:58 +0200 Subject: [PATCH 18/24] Refactor Limit Scaling to Scale Percentage --- libs/s25main/RescaleWindowProp.h | 22 +++++------ libs/s25main/Window.cpp | 47 +++++++++++------------- libs/s25main/Window.h | 16 ++++---- libs/s25main/animation/MoveAnimation.cpp | 4 +- libs/s25main/controls/ctrlButton.cpp | 2 +- libs/s25main/controls/ctrlButton.h | 2 +- libs/s25main/controls/ctrlTextButton.cpp | 4 +- libs/s25main/controls/ctrlTextButton.h | 2 +- tests/s25Main/UI/testControls.cpp | 4 +- 9 files changed, 50 insertions(+), 53 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index b6e9047f9d..4cc5b7aafe 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -13,7 +13,7 @@ struct ScaleWindowProp /// 50%: considers only half of target size /// 0% does not apply any scaling at all /// The target size is normalized against the reference solution - using LimitFactors = Point; + using ScaleLimPercent = Point; /// Reference Resolution used static constexpr Extent REFERENCE_RESOLUTION = Extent(800, 600); @@ -23,42 +23,42 @@ struct ScaleWindowProp ScaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} template - static T_Pt scale(const T_Pt& value, const Extent& size, const LimitFactors& limfactors); + static T_Pt scale(const T_Pt& value, const Extent& size, const ScaleLimPercent& scalePercentage); template T_Pt operator()(const T_Pt& value) const; /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template - T_Pt operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const; + T_Pt operator()(const T_Pt& oldValue, const ScaleLimPercent& scalePercentage) const; }; template -inline T_Pt ScaleWindowProp::scale(const T_Pt& value, const Extent& sizeToScale, const LimitFactors& limfactors) +inline T_Pt ScaleWindowProp::scale(const T_Pt& value, const Extent& sizeToScale, const ScaleLimPercent& scalePercentage) { T_Pt diff(sizeToScale - REFERENCE_RESOLUTION); - T_Pt limScaledValue(value * (sizeToScale - diff + (diff * limfactors / 100)) / REFERENCE_RESOLUTION); + T_Pt limScaledValue(value * (sizeToScale - diff + (diff * scalePercentage / 100)) / REFERENCE_RESOLUTION); return limScaledValue; } template inline T_Pt ScaleWindowProp::operator()(const T_Pt& value) const { - return scale(value, size, LimitFactors(100, 100)); + return scale(value, size, ScaleLimPercent(100, 100)); } template -inline T_Pt ScaleWindowProp::operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const +inline T_Pt ScaleWindowProp::operator()(const T_Pt& oldValue, const ScaleLimPercent& scalePercentage) const { T_Pt realValue; T_Pt diff(oldSize - REFERENCE_RESOLUTION); - T_Pt limUnscaleValue(oldValue.x * REFERENCE_RESOLUTION.x / (oldSize.x - diff.x + (diff.x * limfactors.x / 100)), - oldValue.y * REFERENCE_RESOLUTION.y / (oldSize.y - diff.y + (diff.y * limfactors.y / 100))); + T_Pt limUnscaleValue(oldValue.x * REFERENCE_RESOLUTION.x / (oldSize.x - diff.x + (diff.x * scalePercentage.x / 100)), + oldValue.y * REFERENCE_RESOLUTION.y / (oldSize.y - diff.y + (diff.y * scalePercentage.y / 100))); realValue = limUnscaleValue; // Check for rounding errors - T_Pt checkValue = ScaleWindowProp::scale(realValue, oldSize, limfactors); + T_Pt checkValue = ScaleWindowProp::scale(realValue, oldSize, scalePercentage); if(checkValue.x < oldValue.x) realValue.x++; if(checkValue.y < oldValue.y) realValue.y++; - return ScaleWindowProp::scale(realValue, newSize, limfactors); + return ScaleWindowProp::scale(realValue, newSize, scalePercentage); } diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 8496b19a6e..20854bc64b 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -17,16 +17,16 @@ #include #include -Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const LimitFactors& factors) - : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(factors), active_(false), +Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const ScaleLimPercent& scalePercentage) + : parent_(parent), id_(id), pos_(pos), size_(size), scalePercentage_(scalePercentage), active_(false), visible_(true), scale_(false), limit_(false), isInMouseRelay(false), animations_(this) { - SetLimitFactors(factors); + SetScalePercentage(scalePercentage); if(parent != nullptr && parent->GetScale()) { scale_ = parent->GetScale(); limit_ = parent->GetLimit(); - ScaleByFactor(); + Scale(); } } @@ -73,20 +73,20 @@ Extent Window::GetSize() const return size_; } -LimitFactors Window::GetLimitFactors() const +ScaleLimPercent Window::GetScalePercentage() const { - return limitFactors_; + return scalePercentage_; } -void Window::SetLimitFactors(LimitFactors limitFactors) +void Window::SetScalePercentage(ScaleLimPercent scalePercentage) { - if(limitFactors.x > 100) - limitFactors.x = 100; + if(scalePercentage.x > 100) + scalePercentage.x = 100; - if(limitFactors.y > 100) - limitFactors.y = 100; + if(scalePercentage.y > 100) + scalePercentage.y = 100; - limitFactors_ = limitFactors; + scalePercentage_ = scalePercentage; } Rect Window::GetDrawRect() const @@ -244,7 +244,7 @@ ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, Bui ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip) { - return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, LimitFactors(30, 50))); + return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, ScaleLimPercent(30, 50))); } ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, @@ -564,11 +564,11 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(!ctrl) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) - LimitFactors limits(0, 0); + ScaleLimPercent limits(100, 100); if(limit_) - limits = ctrl->GetLimitFactors(); + limits = ctrl->GetScalePercentage(); Extent newSize = rescale(ctrl->GetSize(), limits); - ctrl->SetPos(rescale(ctrl->GetPos(), LimitFactors(100, 100))); + ctrl->SetPos(rescale(ctrl->GetPos(), ScaleLimPercent(100, 100))); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); } @@ -576,24 +576,21 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) } template -T_Pt Window::Scale(const T_Pt& pt, const LimitFactors& limfactors) +T_Pt Window::Scale(const T_Pt& pt, const ScaleLimPercent& scalePercentage) { - return ScaleWindowProp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactors); + return ScaleWindowProp::scale(pt, VIDEODRIVER.GetRenderSize(), scalePercentage); } -void Window::ScaleByFactor() +void Window::Scale() { - pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(100, 100)); - if(limit_) - size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); - else - size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), LimitFactors(100, 100)); + pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), ScaleLimPercent(100, 100)); + size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limit_ ? scalePercentage_ : ScaleLimPercent(100, 100)); } template T_Pt Window::ScaleIf(const T_Pt& pt) const { - return scale_ ? Scale(pt, LimitFactors(100, 100)) : pt; + return scale_ ? Scale(pt, ScaleLimPercent(100, 100)) : pt; } // Inlining removes those. so add it here diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index dba0cc2b93..d16235acda 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -58,7 +58,7 @@ namespace libsiedler2 { class ArchivItem_Map; } -using LimitFactors = Point; +using ScaleLimPercent = Point; /// Die Basisklasse der Fenster. class Window @@ -67,7 +67,7 @@ class Window using KeyboardMsgHandler = bool (Window::*)(const KeyEvent&); using MouseMsgHandler = bool (Window::*)(const MouseCoords&); - Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0), const LimitFactors& factors = LimitFactors(100, 100)); + Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0), const ScaleLimPercent& factors = ScaleLimPercent(100, 100)); virtual ~Window(); /// zeichnet das Fenster. void Draw(); @@ -78,7 +78,7 @@ class Window /// Get the size of the window Extent GetSize() const; /// Get the Limit Factors for scaling - LimitFactors GetLimitFactors() const; + ScaleLimPercent GetScalePercentage() const; /// gets the extent of the window in absolute coordinates Rect GetDrawRect() const; /// Get the actual extents of the rect (might be different to the draw rect if the window resizes according to @@ -91,7 +91,7 @@ class Window /// setzt die Höhe des Fensters void SetHeight(unsigned height) { Resize(Extent(size_.x, height)); } /// Set the Limit Factors for scaling - void SetLimitFactors(LimitFactors limitFactors); + void SetScalePercentage(ScaleLimPercent scalePercentage); /// Sendet eine Tastaturnachricht an die Steuerelemente. bool RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke); /// Sendet eine Mausnachricht weiter an alle Steuerelemente @@ -294,9 +294,9 @@ class Window /// scales X- and Y values to fit the screen, additionally considering a limiting factor for size template - static T_Pt Scale(const T_Pt& pt, const LimitFactors& limfactors); - /// scales X- and Y values of pos_ and size_, additionally considering limitFactors_ for size_ scaling - void ScaleByFactor(); + static T_Pt Scale(const T_Pt& pt, const ScaleLimPercent& scalePercentage); + /// scales X- and Y values of pos_ and size_, additionally considering scalePercentage_ for size_ scaling + void Scale(); /// Scales the value when scale_ is true, else returns the value template T_Pt ScaleIf(const T_Pt& pt) const; @@ -318,7 +318,7 @@ class Window unsigned id_; /// ID des Fensters. DrawPoint pos_; /// Position des Fensters. Extent size_; /// Höhe des Fensters. - LimitFactors limitFactors_; /// X and Y scaling limiting factors + ScaleLimPercent scalePercentage_; /// X and Y scaling limiting factors bool active_; /// Fenster aktiv? bool visible_; /// Fenster sichtbar? bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 711d8551a5..78ab23e91d 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -22,8 +22,8 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { ScaleWindowProp rescale(rs.oldSize, rs.newSize); - origPos_ = rescale(origPos_, LimitFactors(100, 100)); - newPos_ = rescale(newPos_, LimitFactors(100, 100)); + origPos_ = rescale(origPos_, ScaleLimPercent(100, 100)); + newPos_ = rescale(newPos_, ScaleLimPercent(100, 100)); } void MoveAnimation::doUpdate(Window* element, double nextFramepartTime) diff --git a/libs/s25main/controls/ctrlButton.cpp b/libs/s25main/controls/ctrlButton.cpp index 9052e3b344..e4344df998 100644 --- a/libs/s25main/controls/ctrlButton.cpp +++ b/libs/s25main/controls/ctrlButton.cpp @@ -8,7 +8,7 @@ #include "drivers/VideoDriverWrapper.h" ctrlButton::ctrlButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& tooltip, const LimitFactors& factors) + const std::string& tooltip, const ScaleLimPercent& factors) : Window(parent, id, pos, size, factors), ctrlBaseTooltip(tooltip), tc(tc), state(ButtonState::Up), hasBorder(true), isChecked(false), isIlluminated(false), isEnabled(true) {} diff --git a/libs/s25main/controls/ctrlButton.h b/libs/s25main/controls/ctrlButton.h index 8cb20ee354..ddcf0e6e5d 100644 --- a/libs/s25main/controls/ctrlButton.h +++ b/libs/s25main/controls/ctrlButton.h @@ -17,7 +17,7 @@ class ctrlButton : public Window, public ctrlBaseTooltip { public: ctrlButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& tooltip, const LimitFactors& factors = LimitFactors(100, 100)); + const std::string& tooltip, const ScaleLimPercent& factors = ScaleLimPercent(100, 100)); ~ctrlButton() override; void SetEnabled(bool enable = true); diff --git a/libs/s25main/controls/ctrlTextButton.cpp b/libs/s25main/controls/ctrlTextButton.cpp index 8184c85735..a1d5de178e 100644 --- a/libs/s25main/controls/ctrlTextButton.cpp +++ b/libs/s25main/controls/ctrlTextButton.cpp @@ -11,8 +11,8 @@ static constexpr unsigned contentOffset = 2; ctrlTextButton::ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc, const std::string& text, const glFont* font, - const std::string& tooltip, const LimitFactors& limitFactors) - : ctrlButton(parent, id, pos, size, tc, tooltip, limitFactors), ctrlBaseText(text, COLOR_YELLOW, font) + const std::string& tooltip, const ScaleLimPercent& scalePercentage) + : ctrlButton(parent, id, pos, size, tc, tooltip, scalePercentage), ctrlBaseText(text, COLOR_YELLOW, font) {} void ctrlTextButton::ResizeForMaxChars(unsigned numChars) diff --git a/libs/s25main/controls/ctrlTextButton.h b/libs/s25main/controls/ctrlTextButton.h index d003fdaeec..4b6df70e94 100644 --- a/libs/s25main/controls/ctrlTextButton.h +++ b/libs/s25main/controls/ctrlTextButton.h @@ -13,7 +13,7 @@ class ctrlTextButton : public ctrlButton, public ctrlBaseText public: ctrlTextButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const std::string& text, const glFont* font, const std::string& tooltip, - const LimitFactors& limitFactors); + const ScaleLimPercent& scalePercentage); /// Changes width so at most this many chars can be shown void ResizeForMaxChars(unsigned numChars); diff --git a/tests/s25Main/UI/testControls.cpp b/tests/s25Main/UI/testControls.cpp index 550396c704..41c4f478ef 100644 --- a/tests/s25Main/UI/testControls.cpp +++ b/tests/s25Main/UI/testControls.cpp @@ -61,7 +61,7 @@ BOOST_FIXTURE_TEST_CASE(MouseOver, uiHelper::Fixture) const auto pos = rttr::test::randomPoint(); const auto size = rttr::test::randomPoint(10); const auto font = createMockFont({'H', 'e', 'l', 'o', '?'}); - ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), "", LimitFactors(100, 100)); + ctrlTextButton bt(nullptr, 1, pos, size, TextureColor::Bricks, "Hello", font.get(), "", ScaleLimPercent(100, 100)); BOOST_TEST(bt.IsMouseOver(pos)); BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(1, 0))); BOOST_TEST(!bt.IsMouseOver(pos - DrawPoint(0, 1))); @@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(AdjustWidthForMaxChars_SetsCorrectSize) } { ctrlTextButton txt(nullptr, 1, rttr::test::randomPoint(), rttr::test::randomPoint(), - TextureColor::Green1, "foo", font.get(), "tooltip", LimitFactors(100, 100)); + TextureColor::Green1, "foo", font.get(), "tooltip", ScaleLimPercent(100, 100)); const Extent sizeBefore = txt.GetSize(); // Don't assume size, so get size for 0 chars txt.ResizeForMaxChars(0); From 3282130c161fcb91e5ee5c67c5688db5755f0401 Mon Sep 17 00:00:00 2001 From: Noseey Date: Wed, 8 Apr 2026 11:46:12 +0200 Subject: [PATCH 19/24] introduce default parameter for scaling / rescaling --- libs/s25main/RescaleWindowProp.h | 15 +++------------ libs/s25main/Window.cpp | 6 +++--- libs/s25main/Window.h | 2 +- libs/s25main/animation/MoveAnimation.cpp | 4 ++-- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 4cc5b7aafe..feb00fc1c2 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -18,18 +18,15 @@ struct ScaleWindowProp /// Reference Resolution used static constexpr Extent REFERENCE_RESOLUTION = Extent(800, 600); - Extent size, oldSize, newSize; - ScaleWindowProp(const Extent& size) : size(size) {} + Extent oldSize, newSize; ScaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} template - static T_Pt scale(const T_Pt& value, const Extent& size, const ScaleLimPercent& scalePercentage); + static T_Pt scale(const T_Pt& value, const Extent& size, const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)); - template - T_Pt operator()(const T_Pt& value) const; /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template - T_Pt operator()(const T_Pt& oldValue, const ScaleLimPercent& scalePercentage) const; + T_Pt operator()(const T_Pt& oldValue, const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)) const; }; template @@ -40,12 +37,6 @@ inline T_Pt ScaleWindowProp::scale(const T_Pt& value, const Extent& sizeToScale, return limScaledValue; } -template -inline T_Pt ScaleWindowProp::operator()(const T_Pt& value) const -{ - return scale(value, size, ScaleLimPercent(100, 100)); -} - template inline T_Pt ScaleWindowProp::operator()(const T_Pt& oldValue, const ScaleLimPercent& scalePercentage) const { diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 20854bc64b..771f3c097c 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -568,7 +568,7 @@ void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) if(limit_) limits = ctrl->GetScalePercentage(); Extent newSize = rescale(ctrl->GetSize(), limits); - ctrl->SetPos(rescale(ctrl->GetPos(), ScaleLimPercent(100, 100))); + ctrl->SetPos(rescale(ctrl->GetPos())); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); } @@ -583,14 +583,14 @@ T_Pt Window::Scale(const T_Pt& pt, const ScaleLimPercent& scalePercentage) void Window::Scale() { - pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), ScaleLimPercent(100, 100)); + pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize()); size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limit_ ? scalePercentage_ : ScaleLimPercent(100, 100)); } template T_Pt Window::ScaleIf(const T_Pt& pt) const { - return scale_ ? Scale(pt, ScaleLimPercent(100, 100)) : pt; + return scale_ ? Scale(pt) : pt; } // Inlining removes those. so add it here diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index d16235acda..86c80cfa05 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -294,7 +294,7 @@ class Window /// scales X- and Y values to fit the screen, additionally considering a limiting factor for size template - static T_Pt Scale(const T_Pt& pt, const ScaleLimPercent& scalePercentage); + static T_Pt Scale(const T_Pt& pt, const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)); /// scales X- and Y values of pos_ and size_, additionally considering scalePercentage_ for size_ scaling void Scale(); /// Scales the value when scale_ is true, else returns the value diff --git a/libs/s25main/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 78ab23e91d..22095f1d54 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -22,8 +22,8 @@ MoveAnimation::MoveAnimation(Window* element, DrawPoint newPos, unsigned animTim void MoveAnimation::onRescale(const ScreenResizeEvent& rs) { ScaleWindowProp rescale(rs.oldSize, rs.newSize); - origPos_ = rescale(origPos_, ScaleLimPercent(100, 100)); - newPos_ = rescale(newPos_, ScaleLimPercent(100, 100)); + origPos_ = rescale(origPos_); + newPos_ = rescale(newPos_); } void MoveAnimation::doUpdate(Window* element, double nextFramepartTime) From 1933aedc25023357648e4d7f29feddf488cac8a1 Mon Sep 17 00:00:00 2001 From: Noseey Date: Wed, 8 Apr 2026 14:53:34 +0200 Subject: [PATCH 20/24] Fixing CI issues --- libs/s25main/RescaleWindowProp.h | 8 +++++--- libs/s25main/Window.cpp | 16 ++++++++-------- libs/s25main/Window.h | 25 +++++++++++++------------ libs/s25main/controls/ctrlChat.cpp | 4 ++-- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index feb00fc1c2..cb75b69e58 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -22,7 +22,8 @@ struct ScaleWindowProp ScaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(newSize) {} template - static T_Pt scale(const T_Pt& value, const Extent& size, const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)); + static T_Pt scale(const T_Pt& value, const Extent& size, + const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)); /// Scale the point or size from beeing relative to the oldSize to relative to the newSize template @@ -42,8 +43,9 @@ inline T_Pt ScaleWindowProp::operator()(const T_Pt& oldValue, const ScaleLimPerc { T_Pt realValue; T_Pt diff(oldSize - REFERENCE_RESOLUTION); - T_Pt limUnscaleValue(oldValue.x * REFERENCE_RESOLUTION.x / (oldSize.x - diff.x + (diff.x * scalePercentage.x / 100)), - oldValue.y * REFERENCE_RESOLUTION.y / (oldSize.y - diff.y + (diff.y * scalePercentage.y / 100))); + T_Pt limUnscaleValue( + oldValue.x * REFERENCE_RESOLUTION.x / (oldSize.x - diff.x + (diff.x * scalePercentage.x / 100)), + oldValue.y * REFERENCE_RESOLUTION.y / (oldSize.y - diff.y + (diff.y * scalePercentage.y / 100))); realValue = limUnscaleValue; // Check for rounding errors T_Pt checkValue = ScaleWindowProp::scale(realValue, oldSize, scalePercentage); diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 771f3c097c..e94b79b4a4 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -17,7 +17,8 @@ #include #include -Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, const ScaleLimPercent& scalePercentage) +Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, + const ScaleLimPercent& scalePercentage) : parent_(parent), id_(id), pos_(pos), size_(size), scalePercentage_(scalePercentage), active_(false), visible_(true), scale_(false), limit_(false), isInMouseRelay(false), animations_(this) { @@ -310,8 +311,7 @@ ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, cons ctrlEdit* Window::AddEdit(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font, unsigned short maxlength, bool password, bool disabled, bool notify) { - return AddCtrl( - new ctrlEdit(this, id, pos, size, tc, font, maxlength, password, disabled, notify)); + return AddCtrl(new ctrlEdit(this, id, pos, size, tc, font, maxlength, password, disabled, notify)); } ctrlGroup* Window::AddGroup(unsigned id) @@ -377,8 +377,8 @@ ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Exten const std::string& tooltip, const Extent& padding, unsigned force_color, const std::string& button_minus_tooltip, const std::string& button_plus_tooltip) { - return AddCtrl(new ctrlProgress(this, id, pos, size, tc, button_minus, button_plus, maximum, - padding, force_color, tooltip, button_minus_tooltip, button_plus_tooltip)); + return AddCtrl(new ctrlProgress(this, id, pos, size, tc, button_minus, button_plus, maximum, padding, force_color, + tooltip, button_minus_tooltip, button_plus_tooltip)); } ctrlScrollBar* Window::AddScrollBar(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short button_height, @@ -450,8 +450,7 @@ ctrlVarDeepening* Window::AddVarDeepening(unsigned id, const DrawPoint& pos, con va_list liste; va_start(liste, parameters); - auto* ctrl = - new ctrlVarDeepening(this, id, pos, size, tc, formatstr, font, color, parameters, liste); + auto* ctrl = new ctrlVarDeepening(this, id, pos, size, tc, formatstr, font, color, parameters, liste); va_end(liste); @@ -584,7 +583,8 @@ T_Pt Window::Scale(const T_Pt& pt, const ScaleLimPercent& scalePercentage) void Window::Scale() { pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize()); - size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limit_ ? scalePercentage_ : ScaleLimPercent(100, 100)); + size_ = + ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limit_ ? scalePercentage_ : ScaleLimPercent(100, 100)); } template diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 86c80cfa05..e5cf5134c3 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -67,7 +67,8 @@ class Window using KeyboardMsgHandler = bool (Window::*)(const KeyEvent&); using MouseMsgHandler = bool (Window::*)(const MouseCoords&); - Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0), const ScaleLimPercent& factors = ScaleLimPercent(100, 100)); + Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0), + const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)); virtual ~Window(); /// zeichnet das Fenster. void Draw(); @@ -305,24 +306,24 @@ class Window /// Sets the limit value, deciding of control size shall be limited. void SetLimit(bool limit = true) { this->limit_ = limit; } /// get Scale-Value - bool GetScale() { return this->scale_; } + bool GetScale() const { return this->scale_; } /// get Limit-Value - bool GetLimit() { return this->limit_; } + bool GetLimit() const { return this->limit_; } /// zeichnet das Fenster. virtual void Draw_(); /// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht? virtual bool IsMessageRelayAllowed() const; private: - Window* const parent_; /// Handle auf das Parentfenster. - unsigned id_; /// ID des Fensters. - DrawPoint pos_; /// Position des Fensters. - Extent size_; /// Höhe des Fensters. - ScaleLimPercent scalePercentage_; /// X and Y scaling limiting factors - bool active_; /// Fenster aktiv? - bool visible_; /// Fenster sichtbar? - bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? - bool limit_; /// Should control size be limited? + Window* const parent_; /// Handle auf das Parentfenster. + unsigned id_; /// ID des Fensters. + DrawPoint pos_; /// Position des Fensters. + Extent size_; /// Höhe des Fensters. + ScaleLimPercent scalePercentage_; /// X and Y scaling limiting percentage + bool active_; /// Fenster aktiv? + bool visible_; /// Fenster sichtbar? + bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? + bool limit_; /// Should control size be limited? std::map lockedAreas_; /// gesperrte Regionen des Fensters. std::vector tofreeAreas_; diff --git a/libs/s25main/controls/ctrlChat.cpp b/libs/s25main/controls/ctrlChat.cpp index 58890fd796..185a47dc0a 100644 --- a/libs/s25main/controls/ctrlChat.cpp +++ b/libs/s25main/controls/ctrlChat.cpp @@ -38,8 +38,8 @@ ctrlChat::ctrlChat(Window* parent, unsigned id, const DrawPoint& pos, const Exte SetScale(false); // Scrollbalken hinzufügen - AddScrollBar(0, DrawPoint(GetSize().x - SCROLLBAR_WIDTH, 0), Extent(SCROLLBAR_WIDTH, GetSize().y), SCROLLBAR_WIDTH, tc, - page_size); + AddScrollBar(0, DrawPoint(GetSize().x - SCROLLBAR_WIDTH, 0), Extent(SCROLLBAR_WIDTH, GetSize().y), SCROLLBAR_WIDTH, + tc, page_size); SetScale(tmpScale); From 52de5617bda0ba041ebedb247081cc2f585b89e4 Mon Sep 17 00:00:00 2001 From: Noseey Date: Wed, 8 Apr 2026 14:56:05 +0200 Subject: [PATCH 21/24] fixing indentation in windows.h --- libs/s25main/Window.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index e5cf5134c3..b6fc258a5a 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -315,15 +315,15 @@ class Window virtual bool IsMessageRelayAllowed() const; private: - Window* const parent_; /// Handle auf das Parentfenster. - unsigned id_; /// ID des Fensters. - DrawPoint pos_; /// Position des Fensters. - Extent size_; /// Höhe des Fensters. - ScaleLimPercent scalePercentage_; /// X and Y scaling limiting percentage - bool active_; /// Fenster aktiv? - bool visible_; /// Fenster sichtbar? - bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? - bool limit_; /// Should control size be limited? + Window* const parent_; /// Handle auf das Parentfenster. + unsigned id_; /// ID des Fensters. + DrawPoint pos_; /// Position des Fensters. + Extent size_; /// Höhe des Fensters. + ScaleLimPercent scalePercentage_; /// X and Y scaling limiting percentage + bool active_; /// Fenster aktiv? + bool visible_; /// Fenster sichtbar? + bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? + bool limit_; /// Should control size be limited? std::map lockedAreas_; /// gesperrte Regionen des Fensters. std::vector tofreeAreas_; From d3468eb408fc1b0c4125b44e75503a9f769ff7e4 Mon Sep 17 00:00:00 2001 From: Noseey Date: Wed, 8 Apr 2026 15:15:26 +0200 Subject: [PATCH 22/24] Refactor Limit Scaling to Scale Percentage #2 --- libs/s25main/Window.h | 6 +++--- libs/s25main/controls/ctrlButton.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index b6fc258a5a..efa40c84a1 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -78,7 +78,7 @@ class Window DrawPoint GetDrawPos() const; /// Get the size of the window Extent GetSize() const; - /// Get the Limit Factors for scaling + /// Get the Scaling Percentage ScaleLimPercent GetScalePercentage() const; /// gets the extent of the window in absolute coordinates Rect GetDrawRect() const; @@ -91,7 +91,7 @@ class Window void SetWidth(unsigned width) { Resize(Extent(width, size_.y)); } /// setzt die Höhe des Fensters void SetHeight(unsigned height) { Resize(Extent(size_.x, height)); } - /// Set the Limit Factors for scaling + /// Set the Scaling Percentage void SetScalePercentage(ScaleLimPercent scalePercentage); /// Sendet eine Tastaturnachricht an die Steuerelemente. bool RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke); @@ -293,7 +293,7 @@ class Window friend constexpr auto maxEnumValue(ButtonState) { return ButtonState::Pressed; } using ControlMap = std::map; - /// scales X- and Y values to fit the screen, additionally considering a limiting factor for size + /// scales X- and Y values to fit the screen, additionally considering a scaling percentage for size template static T_Pt Scale(const T_Pt& pt, const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)); /// scales X- and Y values of pos_ and size_, additionally considering scalePercentage_ for size_ scaling diff --git a/libs/s25main/controls/ctrlButton.cpp b/libs/s25main/controls/ctrlButton.cpp index e4344df998..f38a88c6eb 100644 --- a/libs/s25main/controls/ctrlButton.cpp +++ b/libs/s25main/controls/ctrlButton.cpp @@ -8,8 +8,8 @@ #include "drivers/VideoDriverWrapper.h" ctrlButton::ctrlButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& tooltip, const ScaleLimPercent& factors) - : Window(parent, id, pos, size, factors), ctrlBaseTooltip(tooltip), tc(tc), state(ButtonState::Up), hasBorder(true), + const std::string& tooltip, const ScaleLimPercent& scalePercentage) + : Window(parent, id, pos, size, scalePercentage), ctrlBaseTooltip(tooltip), tc(tc), state(ButtonState::Up), hasBorder(true), isChecked(false), isIlluminated(false), isEnabled(true) {} From 3d3b4a9ad6b59175eac39770e57746f71ab3f4d5 Mon Sep 17 00:00:00 2001 From: Noseey Date: Wed, 8 Apr 2026 15:18:46 +0200 Subject: [PATCH 23/24] fixing style issue --- libs/s25main/controls/ctrlButton.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/s25main/controls/ctrlButton.cpp b/libs/s25main/controls/ctrlButton.cpp index f38a88c6eb..6fcfe5fb1f 100644 --- a/libs/s25main/controls/ctrlButton.cpp +++ b/libs/s25main/controls/ctrlButton.cpp @@ -9,8 +9,8 @@ ctrlButton::ctrlButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const std::string& tooltip, const ScaleLimPercent& scalePercentage) - : Window(parent, id, pos, size, scalePercentage), ctrlBaseTooltip(tooltip), tc(tc), state(ButtonState::Up), hasBorder(true), - isChecked(false), isIlluminated(false), isEnabled(true) + : Window(parent, id, pos, size, scalePercentage), ctrlBaseTooltip(tooltip), tc(tc), state(ButtonState::Up), + hasBorder(true), isChecked(false), isIlluminated(false), isEnabled(true) {} ctrlButton::~ctrlButton() = default; From 47ad84b42caf9440a32f1ffb9e8fb63cc60c9818 Mon Sep 17 00:00:00 2001 From: Noseey Date: Wed, 8 Apr 2026 16:40:51 +0200 Subject: [PATCH 24/24] aligning constructor parameters for ctrlButton --- libs/s25main/controls/ctrlButton.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/s25main/controls/ctrlButton.h b/libs/s25main/controls/ctrlButton.h index ddcf0e6e5d..c9971b2052 100644 --- a/libs/s25main/controls/ctrlButton.h +++ b/libs/s25main/controls/ctrlButton.h @@ -17,7 +17,7 @@ class ctrlButton : public Window, public ctrlBaseTooltip { public: ctrlButton(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, - const std::string& tooltip, const ScaleLimPercent& factors = ScaleLimPercent(100, 100)); + const std::string& tooltip, const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)); ~ctrlButton() override; void SetEnabled(bool enable = true);