Merge pull request #358 from NQNStudios/dialog-scale-2
naively scale dialogs by ui scale
This commit is contained in:
@@ -407,7 +407,6 @@ void cDialog::loadFromFile(const DialogDefn& file){
|
|||||||
dialogNotToast = true;
|
dialogNotToast = true;
|
||||||
if(bg == BG_DARK) defTextClr = sf::Color::White;
|
if(bg == BG_DARK) defTextClr = sf::Color::White;
|
||||||
// now calculate window rect
|
// now calculate window rect
|
||||||
winRect = rectangle();
|
|
||||||
recalcRect();
|
recalcRect();
|
||||||
currentFocus = "";
|
currentFocus = "";
|
||||||
for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++){
|
for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++){
|
||||||
@@ -428,6 +427,7 @@ void cDialog::loadFromFile(const DialogDefn& file){
|
|||||||
|
|
||||||
void cDialog::recalcRect(){
|
void cDialog::recalcRect(){
|
||||||
bool haveRel = false;
|
bool haveRel = false;
|
||||||
|
winRect = rectangle();
|
||||||
for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++) {
|
for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++) {
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
if(auto container = dynamic_cast<cContainer*>(iter->second))
|
if(auto container = dynamic_cast<cContainer*>(iter->second))
|
||||||
@@ -442,18 +442,22 @@ void cDialog::recalcRect(){
|
|||||||
}
|
}
|
||||||
winRect.right += 6;
|
winRect.right += 6;
|
||||||
winRect.bottom += 6;
|
winRect.bottom += 6;
|
||||||
if(!haveRel) return;
|
if(haveRel) {
|
||||||
// Resolve any remaining relative positions
|
// Resolve any remaining relative positions
|
||||||
// Controls placed relative to the dialog's edges can go off the edge of the dialog
|
// 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++) {
|
for(ctrlIter iter = controls.begin(); iter != controls.end(); iter++) {
|
||||||
location pos = iter->second->getBounds().topLeft();
|
location pos = iter->second->getBounds().topLeft();
|
||||||
if(iter->second->horz == POS_REL_NEG)
|
if(iter->second->horz == POS_REL_NEG)
|
||||||
pos.x = winRect.right - pos.x;
|
pos.x = winRect.right - pos.x;
|
||||||
if(iter->second->vert == POS_REL_NEG)
|
if(iter->second->vert == POS_REL_NEG)
|
||||||
pos.y = winRect.bottom - pos.y;
|
pos.y = winRect.bottom - pos.y;
|
||||||
iter->second->horz = iter->second->vert = POS_ABS;
|
iter->second->horz = iter->second->vert = POS_ABS;
|
||||||
iter->second->relocate(pos);
|
iter->second->relocate(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
winRect.right *= ui_scale();
|
||||||
|
winRect.bottom *= ui_scale();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cDialog::init(){
|
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.isMetaPressed()) key.mod += mod_ctrl;
|
||||||
if(kb.isAltPressed()) key.mod += mod_alt;
|
if(kb.isAltPressed()) key.mod += mod_alt;
|
||||||
if(kb.isShiftPressed()) key.mod += mod_shift;
|
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);
|
process_click(where, key.mod);
|
||||||
break;
|
break;
|
||||||
default: // To silence warning of unhandled enum values
|
default: // To silence warning of unhandled enum values
|
||||||
@@ -1043,6 +1047,11 @@ void cDialog::draw(){
|
|||||||
animTimer.restart();
|
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();
|
ctrlIter iter = controls.begin();
|
||||||
while(iter != controls.end()){
|
while(iter != controls.end()){
|
||||||
iter->second->draw();
|
iter->second->draw();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "location.hpp"
|
#include "location.hpp"
|
||||||
#include <boost/any.hpp>
|
#include <boost/any.hpp>
|
||||||
#include <boost/iterator/iterator_facade.hpp>
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
|
#include "tools/prefs.hpp"
|
||||||
|
|
||||||
class cControl;
|
class cControl;
|
||||||
class cTextField;
|
class cTextField;
|
||||||
@@ -242,6 +243,7 @@ public:
|
|||||||
cDialog& operator=(cDialog& other) = delete;
|
cDialog& operator=(cDialog& other) = delete;
|
||||||
cDialog(cDialog& other) = delete;
|
cDialog(cDialog& other) = delete;
|
||||||
private:
|
private:
|
||||||
|
inline double ui_scale() { return get_float_pref("UIScale", 1.0); };
|
||||||
void draw();
|
void draw();
|
||||||
void handle_events();
|
void handle_events();
|
||||||
void handle_one_event(const sf::Event&);
|
void handle_one_event(const sf::Event&);
|
||||||
|
|||||||
Reference in New Issue
Block a user