add a flag to override DPI, so we can tune on mac

This commit is contained in:
Dustin Carlino 2019-12-16 19:09:02 -08:00
parent b1da0f0284
commit e893e6b98c
3 changed files with 19 additions and 2 deletions

View File

@ -15,7 +15,11 @@ Grab a pre-built binary release -- updated every Sunday, announced at
https://github.com/dabreegster/abstreet/releases/download/v0.1.19/abstreet_windows_v0_1_19.zip https://github.com/dabreegster/abstreet/releases/download/v0.1.19/abstreet_windows_v0_1_19.zip
- Mac: - Mac:
https://github.com/dabreegster/abstreet/releases/download/v0.1.19/abstreet_mac_v0_1_19.zip https://github.com/dabreegster/abstreet/releases/download/v0.1.19/abstreet_mac_v0_1_19.zip
- The minimap may be missing, depending on your monitor's DPI. - The minimap may be missing, depending on your monitor's DPI. If so, modify
the `play_abstreet.sh` script to pass `--hidpi_factor=2.0` and experiment
with different values. If you have to do this, please
[file an issue](https://github.com/dabreegster/abstreet/issues) and let me
know, so I can figure out why `glutin` misreports this.
- Linux: - Linux:
https://github.com/dabreegster/abstreet/releases/download/v0.1.19/abstreet_linux_v0_1_19.zip https://github.com/dabreegster/abstreet/releases/download/v0.1.19/abstreet_linux_v0_1_19.zip
- The binary might not work on your flavor of Linux; let me know - The binary might not work on your flavor of Linux; let me know

View File

@ -181,6 +181,7 @@ pub struct Settings {
initial_dims: (f64, f64), initial_dims: (f64, f64),
profiling_enabled: bool, profiling_enabled: bool,
default_font_size: usize, default_font_size: usize,
override_hidpi_factor: Option<f64>,
} }
impl Settings { impl Settings {
@ -190,6 +191,7 @@ impl Settings {
initial_dims, initial_dims,
profiling_enabled: false, profiling_enabled: false,
default_font_size: 30, default_font_size: 30,
override_hidpi_factor: None,
} }
} }
@ -201,6 +203,10 @@ impl Settings {
pub fn default_font_size(&mut self, size: usize) { pub fn default_font_size(&mut self, size: usize) {
self.default_font_size = size; self.default_font_size = size;
} }
pub fn override_hidpi_factor(&mut self, override_hidpi_factor: f64) {
self.override_hidpi_factor = Some(override_hidpi_factor);
}
} }
pub fn run<G: GUI, F: FnOnce(&mut EventCtx) -> G>(settings: Settings, make_gui: F) { pub fn run<G: GUI, F: FnOnce(&mut EventCtx) -> G>(settings: Settings, make_gui: F) {
@ -271,8 +277,12 @@ pub fn run<G: GUI, F: FnOnce(&mut EventCtx) -> G>(settings: Settings, make_gui:
) )
.unwrap(); .unwrap();
let hidpi_factor = events_loop.get_primary_monitor().get_hidpi_factor(); let mut hidpi_factor = events_loop.get_primary_monitor().get_hidpi_factor();
println!("HiDPI factor is purportedly {}", hidpi_factor); println!("HiDPI factor is purportedly {}", hidpi_factor);
if let Some(x) = settings.override_hidpi_factor {
println!("... but overriding it to {} by flag", x);
hidpi_factor = x;
}
let mut canvas = Canvas::new( let mut canvas = Canvas::new(
settings.initial_dims.0, settings.initial_dims.0,
settings.initial_dims.1, settings.initial_dims.1,

View File

@ -46,6 +46,9 @@ fn main() {
if let Some(n) = args.optional_parse("--font_size", |s| s.parse::<usize>()) { if let Some(n) = args.optional_parse("--font_size", |s| s.parse::<usize>()) {
settings.default_font_size(n); settings.default_font_size(n);
} }
if let Some(x) = args.optional_parse("--hidpi_factor", |x| x.parse::<f64>()) {
settings.override_hidpi_factor(x);
}
args.done(); args.done();
ezgui::run(settings, |ctx| game::Game::new(flags, opts, ctx)); ezgui::run(settings, |ctx| game::Game::new(flags, opts, ctx));