Implement UI scaling option
There are still a few minor visual glitches, but it works pretty well
This commit is contained in:
@@ -39,6 +39,8 @@
|
||||
<led name='easier' top='389' left='53' width='352'>Make game easier (monsters much weaker)</led>
|
||||
<led name='lesswm' top='409' left='53' width='340'>Fewer wandering monsters</led>
|
||||
<led name='skipsplash' top='429' left='53' width='340'>Skip splash screen on startup</led>
|
||||
<button name='okay' type='regular' top='446' left='354'>OK</button>
|
||||
<button name='cancel' type='regular' def-key='esc' top='446' left='281'>Cancel</button>
|
||||
<led name='scaleui' top='449' left='53' width='340'>Apply UI scaling</led>
|
||||
|
||||
<button name='okay' type='regular' top='466' left='354'>OK</button>
|
||||
<button name='cancel' type='regular' def-key='esc' top='466' left='281'>Cancel</button>
|
||||
</dialog>
|
||||
|
@@ -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
|
||||
|
@@ -19,6 +19,9 @@ bool get_bool_pref(std::string keypath, bool fallback = false);
|
||||
void set_pref(std::string keypath, int value);
|
||||
int get_int_pref(std::string keypath, int fallback = 0);
|
||||
|
||||
void set_pref(std::string keypath, double value);
|
||||
double get_float_pref(std::string keypath, double fallback = 0);
|
||||
|
||||
void append_iarray_pref(std::string keypath, int value);
|
||||
std::vector<int> get_iarray_pref(std::string keypath);
|
||||
|
||||
|
@@ -37,6 +37,16 @@ int get_int_pref(std::string keypath, int fallback) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
void set_pref(std::string keypath, double value) {
|
||||
[[NSUserDefaults standardUserDefaults] setDouble: value forKey: convertKey(keypath)];
|
||||
}
|
||||
|
||||
double get_float_pref(std::string keypath, double fallback) {
|
||||
id val = [[NSUserDefaults standardUserDefaults] objectForKey: convertKey(keypath)];
|
||||
if([val isKindOfClass: [NSNumber class]]) return [val doubleValue];
|
||||
return fallback;
|
||||
}
|
||||
|
||||
void append_iarray_pref(std::string keypath, int value) {
|
||||
NSString* key = convertKey(keypath);
|
||||
NSArray* list = [[NSUserDefaults standardUserDefaults] arrayForKey: key];
|
||||
|
@@ -35,6 +35,17 @@ int get_int_pref(std::string keypath, int fallback) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
void set_pref(std::string keypath, double value) {
|
||||
prefsDirty = true;
|
||||
prefs[keypath] = value;
|
||||
}
|
||||
|
||||
double get_float_pref(std::string keypath, double fallback) {
|
||||
if(prefs.find(keypath) == prefs.end()) return fallback;
|
||||
if(prefs[keypath].type() == typeid(double)) return boost::any_cast<double>(prefs[keypath]);
|
||||
return fallback;
|
||||
}
|
||||
|
||||
void append_iarray_pref(std::string keypath, int value) {
|
||||
prefsDirty = true;
|
||||
if(prefs.find(keypath) == prefs.end() || prefs[keypath].type() != typeid(iarray))
|
||||
|
Reference in New Issue
Block a user