diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp index 6b590a25c..3e94ab113 100644 --- a/src/dialogxml/dialogs/dialog.cpp +++ b/src/dialogxml/dialogs/dialog.cpp @@ -407,7 +407,6 @@ void cDialog::loadFromFile(const DialogDefn& file){ dialogNotToast = true; if(bg == BG_DARK) defTextClr = sf::Color::White; // now calculate window rect - winRect = rectangle(); recalcRect(); currentFocus = ""; for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++){ @@ -428,6 +427,7 @@ void cDialog::loadFromFile(const DialogDefn& file){ void cDialog::recalcRect(){ bool haveRel = false; + winRect = rectangle(); for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++) { using namespace std::placeholders; if(auto container = dynamic_cast(iter->second)) @@ -442,18 +442,22 @@ void cDialog::recalcRect(){ } winRect.right += 6; winRect.bottom += 6; - if(!haveRel) return; - // Resolve any remaining relative positions - // Controls placed relative to the dialog's edges can go off the edge of the dialog - for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++) { - location pos = iter->second->getBounds().topLeft(); - if(iter->second->horz == POS_REL_NEG) - pos.x = winRect.right - pos.x; - if(iter->second->vert == POS_REL_NEG) - pos.y = winRect.bottom - pos.y; - iter->second->horz = iter->second->vert = POS_ABS; - iter->second->relocate(pos); + if(haveRel) { + // Resolve any remaining relative positions + // Controls placed relative to the dialog's edges can go off the edge of the dialog + for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++) { + location pos = iter->second->getBounds().topLeft(); + if(iter->second->horz == POS_REL_NEG) + pos.x = winRect.right - pos.x; + if(iter->second->vert == POS_REL_NEG) + pos.y = winRect.bottom - pos.y; + iter->second->horz = iter->second->vert = POS_ABS; + iter->second->relocate(pos); + } } + + winRect.right *= ui_scale(); + winRect.bottom *= ui_scale(); } void cDialog::init(){ @@ -682,7 +686,7 @@ void cDialog::handle_one_event(const sf::Event& currentEvent) { if(kb.isMetaPressed()) key.mod += mod_ctrl; if(kb.isAltPressed()) key.mod += mod_alt; if(kb.isShiftPressed()) key.mod += mod_shift; - where = {currentEvent.mouseButton.x, currentEvent.mouseButton.y}; + where = {(int)(currentEvent.mouseButton.x / ui_scale()), (int)(currentEvent.mouseButton.y / ui_scale())}; process_click(where, key.mod); break; default: // To silence warning of unhandled enum values @@ -1043,6 +1047,11 @@ void cDialog::draw(){ animTimer.restart(); } + // Scale dialogs: + sf::View view = win.getDefaultView(); + view.setViewport(sf::FloatRect(0, 0, ui_scale(), ui_scale())); + win.setView(view); + ctrlIter iter = controls.begin(); while(iter != controls.end()){ iter->second->draw(); diff --git a/src/dialogxml/dialogs/dialog.hpp b/src/dialogxml/dialogs/dialog.hpp index 7404dce44..9b219f271 100644 --- a/src/dialogxml/dialogs/dialog.hpp +++ b/src/dialogxml/dialogs/dialog.hpp @@ -27,6 +27,7 @@ #include "location.hpp" #include #include +#include "tools/prefs.hpp" class cControl; class cTextField; @@ -242,6 +243,7 @@ class cDialog { cDialog& operator=(cDialog& other) = delete; cDialog(cDialog& other) = delete; private: + inline double ui_scale() { return get_float_pref("UIScale", 1.0); }; void draw(); void handle_events(); void handle_one_event(const sf::Event&);