diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 73894e2916..75a283865e 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -4,50 +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); + 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; + T_Pt operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const; }; template -inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale) +inline T_Pt ScaleWindowProp::scale(const T_Pt& value, const Extent& sizeToScale, const LimitFactors& limfactors) { - return T_Pt(value * sizeToScale / Extent(800, 600)); + 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; + } } 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); + return scale(value, size, LimitFactors(0, 0)); } template -inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue) const +inline T_Pt ScaleWindowProp::operator()(const T_Pt& oldValue, const LimitFactors& limfactors) const { - T_Pt realValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); + 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; + } // Check for rounding errors - T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize); + 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); + return ScaleWindowProp::scale(realValue, newSize, limfactors); } diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 39c6b34a14..15c21fc750 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -17,10 +17,17 @@ #include #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) -{} +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), limit_(false), isInMouseRelay(false), animations_(this) +{ + if(parent != nullptr && parent->GetScale()) + { + scale_ = parent->GetScale(); + limit_ = parent->GetLimit(); + ScaleByFactor(); + } +} Window::~Window() { @@ -65,6 +72,16 @@ Extent Window::GetSize() const return size_; } +LimitFactors Window::GetLimitFactors() const +{ + return limitFactors_; +} + +void Window::SetLimitFactors(LimitFactors limitFactors) +{ + limitFactors_ = limitFactors; +} + Rect Window::GetDrawRect() const { return Rect(GetDrawPos(), GetSize()); @@ -214,25 +231,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, LimitFactors(7, 5))); } 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 +261,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 +304,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 +314,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 +324,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 +362,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 +370,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 +394,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 +421,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 +444,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 +475,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 +485,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, @@ -534,14 +551,17 @@ 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) continue; // Save new size (could otherwise be changed(?) in Msg_ScreenResize) - Extent newSize = rescale(ctrl->GetSize()); - ctrl->SetPos(rescale(ctrl->GetPos())); + 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); } @@ -549,15 +569,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 LimitFactors& limfactors) { - return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize()); + return ScaleWindowProp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactors); +} + +void Window::ScaleByFactor() +{ + pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); + if(limit_) + size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_); + else + size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0)); } template T_Pt Window::ScaleIf(const T_Pt& pt) const { - return scale_ ? Scale(pt) : 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 437532c762..0fc21000d8 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 { @@ -65,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)); + 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(); @@ -75,6 +77,8 @@ class Window DrawPoint GetDrawPos() const; /// Get the size of the window Extent GetSize() const; + /// Get the Limit Factors for scaling + 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 @@ -86,6 +90,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(LimitFactors limitFactors); /// Sendet eine Tastaturnachricht an die Steuerelemente. bool RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke); /// Sendet eine Mausnachricht weiter an alle Steuerelemente @@ -286,27 +292,37 @@ 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- and Y values to fit the screen, additionally considering a limiting factor for size template - static T_Pt Scale(const T_Pt& pt); + 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 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? 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. - bool active_; /// Fenster aktiv? - bool visible_; /// Fenster sichtbar? - bool scale_; /// Sollen Controls an Fenstergröße angepasst werden? + 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 limit_; /// Should control size be limited? std::map lockedAreas_; /// gesperrte Regionen des Fensters. std::vector tofreeAreas_; @@ -322,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/animation/MoveAnimation.cpp b/libs/s25main/animation/MoveAnimation.cpp index 2abe143fc6..8238a8b1ca 100644 --- a/libs/s25main/animation/MoveAnimation.cpp +++ b/libs/s25main/animation/MoveAnimation.cpp @@ -21,9 +21,9 @@ 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_); + ScaleWindowProp rescale(rs.oldSize, rs.newSize); + 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/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/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(); } diff --git a/libs/s25main/controls/ctrlTextButton.cpp b/libs/s25main/controls/ctrlTextButton.cpp index 84f5957ea0..d800298f7b 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) - : ctrlButton(parent, id, pos, size, tc, tooltip), ctrlBaseText(text, COLOR_YELLOW, 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/libs/s25main/controls/ctrlTextButton.h b/libs/s25main/controls/ctrlTextButton.h index 8a6eadb000..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 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/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); diff --git a/tests/s25Main/UI/testControls.cpp b/tests/s25Main/UI/testControls.cpp index c8954d94b5..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(), ""); + 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"); + 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);