Implement UI scaling option
There are still a few minor visual glitches, but it works pretty well
This commit is contained in:
@@ -1139,6 +1139,11 @@ static bool prefs_event_filter (cDialog& me, std::string id, eKeyMod) {
|
||||
if(dynamic_cast<cLed&>(me["resethelp"]).getState() == led_red) {
|
||||
reset_help = true;
|
||||
}
|
||||
cLed& ui_scale = dynamic_cast<cLed&>(me["scaleui"]);
|
||||
if(ui_scale.getState() == led_off)
|
||||
set_pref("UIScale", 1.0);
|
||||
else if(ui_scale.getState() == led_red)
|
||||
set_pref("UIScale", 2.0);
|
||||
}
|
||||
save_prefs(reset_help);
|
||||
return true;
|
||||
@@ -1202,12 +1207,15 @@ void pick_preferences() {
|
||||
break;
|
||||
}
|
||||
|
||||
float ui_scale = get_float_pref("UIScale", 1.0);
|
||||
dynamic_cast<cLed&>(prefsDlog["scaleui"]).setState(ui_scale == 1.0 ? led_off : (ui_scale == 2.0 ? led_red : led_green));
|
||||
|
||||
void (*give_help)(short,short,cDialog&) = ::give_help;
|
||||
|
||||
int store_display_mode = get_int_pref("DisplayMode");
|
||||
prefsDlog.run(std::bind(give_help, 55, 0, std::ref(prefsDlog)));
|
||||
|
||||
if(get_int_pref("DisplayMode") != store_display_mode)
|
||||
if(get_int_pref("DisplayMode") != store_display_mode || get_float_pref("UIScale") != ui_scale)
|
||||
changed_display_mode = true;
|
||||
}
|
||||
|
||||
|
@@ -131,7 +131,9 @@ void adjust_window_mode() {
|
||||
hideMenuBar();
|
||||
int menubarHeight = getMenubarHeight();
|
||||
bool firstTime = !mainPtr.isOpen();
|
||||
float width = 605, height = 430;
|
||||
float ui_scale = get_float_pref("UIScale", 1.0);
|
||||
if(ui_scale < 0.1) ui_scale = 1.0;
|
||||
float width = 605 * ui_scale, height = 430 * ui_scale;
|
||||
location ul;
|
||||
|
||||
// TODO: Make display_mode an enum
|
||||
@@ -165,8 +167,8 @@ void adjust_window_mode() {
|
||||
sf::FloatRect mainPort;
|
||||
mainPort.left = float(ul.x) / windRect.width();
|
||||
mainPort.top = float(ul.y) / windRect.height();
|
||||
mainPort.width = width / windRect.width();
|
||||
mainPort.height = height / windRect.height();
|
||||
mainPort.width = ui_scale * width / windRect.width();
|
||||
mainPort.height = ui_scale * height / windRect.height();
|
||||
mainView.setViewport(mainPort);
|
||||
|
||||
#ifndef __APPLE__ // This overrides Dock icon on OSX, which isn't what we want at all
|
||||
|
Reference in New Issue
Block a user