diff --git a/libs/s25main/RescaleWindowProp.h b/libs/s25main/RescaleWindowProp.h index 73894e2916..cb75b69e58 100644 --- a/libs/s25main/RescaleWindowProp.h +++ b/libs/s25main/RescaleWindowProp.h @@ -4,50 +4,54 @@ #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) {} + /// 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 ScaleLimPercent = Point; - template - static T_Pt scale(const T_Pt& value, const Extent& size); - template - T_Pt operator()(const T_Pt& value) const; -}; + /// Reference Resolution used + static constexpr Extent REFERENCE_RESOLUTION = Extent(800, 600); -/// Rescales a window's properties (size or positions) -struct RescaleWindowProp -{ Extent oldSize, newSize; - RescaleWindowProp(Extent oldSize, Extent newSize) : oldSize(oldSize), newSize(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 = ScaleLimPercent(100, 100)); + /// 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 ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)) const; }; template -inline T_Pt ScaleWindowPropUp::scale(const T_Pt& value, const Extent& sizeToScale) -{ - return T_Pt(value * sizeToScale / Extent(800, 600)); -} - -template -inline T_Pt ScaleWindowPropUp::operator()(const T_Pt& value) const +inline T_Pt ScaleWindowProp::scale(const T_Pt& value, const Extent& sizeToScale, const ScaleLimPercent& scalePercentage) { - return scale(value, size); + T_Pt diff(sizeToScale - REFERENCE_RESOLUTION); + T_Pt limScaledValue(value * (sizeToScale - diff + (diff * scalePercentage / 100)) / REFERENCE_RESOLUTION); + return limScaledValue; } template -inline T_Pt RescaleWindowProp::operator()(const T_Pt& oldValue) const +inline T_Pt ScaleWindowProp::operator()(const T_Pt& oldValue, const ScaleLimPercent& scalePercentage) const { - T_Pt realValue(oldValue.x * 800 / oldSize.x, oldValue.y * 600 / oldSize.y); + 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))); + realValue = limUnscaleValue; // Check for rounding errors - T_Pt checkValue = ScaleWindowPropUp::scale(realValue, oldSize); + T_Pt checkValue = ScaleWindowProp::scale(realValue, oldSize, scalePercentage); if(checkValue.x < oldValue.x) realValue.x++; if(checkValue.y < oldValue.y) realValue.y++; - return ScaleWindowPropUp::scale(realValue, newSize); + return ScaleWindowProp::scale(realValue, newSize, scalePercentage); } diff --git a/libs/s25main/Window.cpp b/libs/s25main/Window.cpp index 39c6b34a14..e94b79b4a4 100644 --- a/libs/s25main/Window.cpp +++ b/libs/s25main/Window.cpp @@ -17,10 +17,19 @@ #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 ScaleLimPercent& scalePercentage) + : parent_(parent), id_(id), pos_(pos), size_(size), scalePercentage_(scalePercentage), active_(false), + visible_(true), scale_(false), limit_(false), isInMouseRelay(false), animations_(this) +{ + SetScalePercentage(scalePercentage); + if(parent != nullptr && parent->GetScale()) + { + scale_ = parent->GetScale(); + limit_ = parent->GetLimit(); + Scale(); + } +} Window::~Window() { @@ -65,6 +74,22 @@ Extent Window::GetSize() const return size_; } +ScaleLimPercent Window::GetScalePercentage() const +{ + return scalePercentage_; +} + +void Window::SetScalePercentage(ScaleLimPercent scalePercentage) +{ + if(scalePercentage.x > 100) + scalePercentage.x = 100; + + if(scalePercentage.y > 100) + scalePercentage.y = 100; + + scalePercentage_ = scalePercentage; +} + Rect Window::GetDrawRect() const { return Rect(GetDrawPos(), GetSize()); @@ -214,25 +239,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, ScaleLimPercent(30, 50))); } 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 +269,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, @@ -286,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, ScaleIf(pos), ScaleIf(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) @@ -297,7 +321,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 +331,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 +369,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 +377,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, - 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, 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 +401,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 +428,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, @@ -426,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, ScaleIf(pos), ScaleIf(size), tc, formatstr, font, color, parameters, liste); + auto* ctrl = 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, @@ -534,13 +557,16 @@ 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()); + ScaleLimPercent limits(100, 100); + if(limit_) + limits = ctrl->GetScalePercentage(); + Extent newSize = rescale(ctrl->GetSize(), limits); ctrl->SetPos(rescale(ctrl->GetPos())); ctrl->Msg_ScreenResize(sr); ctrl->Resize(newSize); @@ -549,9 +575,16 @@ 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 ScaleLimPercent& scalePercentage) +{ + return ScaleWindowProp::scale(pt, VIDEODRIVER.GetRenderSize(), scalePercentage); +} + +void Window::Scale() { - return ScaleWindowPropUp::scale(pt, VIDEODRIVER.GetRenderSize()); + pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize()); + 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 437532c762..efa40c84a1 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -58,6 +58,8 @@ namespace libsiedler2 { class ArchivItem_Map; } +using ScaleLimPercent = Point; + /// Die Basisklasse der Fenster. class Window { @@ -65,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)); + 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(); @@ -75,6 +78,8 @@ class Window DrawPoint GetDrawPos() const; /// Get the size of the window Extent GetSize() const; + /// Get the Scaling Percentage + 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 @@ -86,6 +91,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 Scaling Percentage + void SetScalePercentage(ScaleLimPercent scalePercentage); /// Sendet eine Tastaturnachricht an die Steuerelemente. bool RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke); /// Sendet eine Mausnachricht weiter an alle Steuerelemente @@ -286,27 +293,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 scaling percentage for size template - static T_Pt Scale(const T_Pt& pt); + 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 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() const { return this->scale_; } + /// get Limit-Value + 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. - 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. + 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_; @@ -322,6 +339,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..22095f1d54 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_); newPos_ = rescale(newPos_); } diff --git a/libs/s25main/controls/ctrlButton.cpp b/libs/s25main/controls/ctrlButton.cpp index b07c65393c..6fcfe5fb1f 100644 --- a/libs/s25main/controls/ctrlButton.cpp +++ b/libs/s25main/controls/ctrlButton.cpp @@ -8,9 +8,9 @@ #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), - isChecked(false), isIlluminated(false), isEnabled(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) {} ctrlButton::~ctrlButton() = default; diff --git a/libs/s25main/controls/ctrlButton.h b/libs/s25main/controls/ctrlButton.h index 92a9eff733..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 std::string& tooltip, const ScaleLimPercent& scalePercentage = ScaleLimPercent(100, 100)); ~ctrlButton() override; void SetEnabled(bool enable = true); diff --git a/libs/s25main/controls/ctrlChat.cpp b/libs/s25main/controls/ctrlChat.cpp index 332d793951..185a47dc0a 100644 --- a/libs/s25main/controls/ctrlChat.cpp +++ b/libs/s25main/controls/ctrlChat.cpp @@ -30,11 +30,18 @@ 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, - page_size); + 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("<"); 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..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) - : ctrlButton(parent, id, pos, size, tc, tooltip), 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 8a6eadb000..4b6df70e94 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 ScaleLimPercent& scalePercentage); /// 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..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(), ""); + 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"); + 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);