diff --git a/src/cli.rs b/src/cli.rs index f72f8f7..71a9e7e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -34,7 +34,7 @@ pub struct Cli { long, short, default_value_t = false, - help = "Use linear filtering (instead of pixel-perfect)" + help = "Use linear filtering (instead of pixel-perfect) this enables fractional scaling" )] pub linear_filtering: bool, } diff --git a/src/main.rs b/src/main.rs index f949eb7..a07b670 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,7 @@ async fn main() -> Result<()> { cli.cursor = !cli.cursor; } + let layout = Layout::generate(cli.linear_filtering); if !paused { ipf = 0; while !engine.wants_to_sync() && ipf <= MAX_IPF { @@ -85,10 +86,10 @@ async fn main() -> Result<()> { gilrs.update(&event); } #[cfg(not(feature = "gamepad"))] - let (mpos, keycode) = get_input_code_no_gamepad(); + let (mpos, keycode) = get_input_code_no_gamepad(&layout); #[cfg(feature = "gamepad")] - let (mpos, keycode) = get_input_code_gamepad(&gilrs); + let (mpos, keycode) = get_input_code_gamepad(&layout, &gilrs); engine.perform_sync(mpos, keycode, &mut raw_buffer); update_image_buffer(&mut buffer, &raw_buffer); @@ -96,7 +97,6 @@ async fn main() -> Result<()> { texture.update(&image); } clear_background(BLACK); - let layout = Layout::generate(); if layout.cursor_in_window() { show_mouse(cli.cursor); diff --git a/src/ui.rs b/src/ui.rs index 874bf9a..f87208c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -10,10 +10,13 @@ pub struct Layout { pub font_size: f32, } impl Layout { - pub fn generate() -> Self { + pub fn generate(linear: bool) -> Self { let (width, height) = (screen_width(), screen_height()); let minsize = width.min(height); - let image_size = ((minsize / 256.).floor() * 256.).max(256.); + let image_size = match linear { + false => ((minsize / 256.).floor() * 256.).max(256.), + true => minsize.max(256.), + }; let x = (0. as f32).max((width - image_size) / 2.); let y = (0. as f32).max((height - image_size) / 2.); let font_y = y + image_size / 15.; diff --git a/src/utils.rs b/src/utils.rs index b2ef3e2..8965d37 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -52,14 +52,14 @@ pub fn update_image_buffer(imbuff: &mut [Color; RES * RES], screen: &[u16; RES * } #[cfg(feature = "gamepad")] -pub fn get_input_code_gamepad(gilrs: &Gilrs) -> (u16, u16) { +pub fn get_input_code_gamepad(layout: &Layout, gilrs: &Gilrs) -> (u16, u16) { #[cfg(not(feature = "gamepad"))] return get_input_code_no_gamepad(); let mut key_code = 0_u16; - let mp = Layout::generate().clamp_mouse(); + let mp = layout.clamp_mouse(); let pos_code = (mp.1 as u16 * 256) + mp.0 as u16; let Some(gamepad) = gilrs.gamepads().next().map(|t| t.1) else { - return get_input_code_no_gamepad(); + return get_input_code_no_gamepad(layout); }; let tol = 0.5; let axis_horizontal = gamepad @@ -120,10 +120,8 @@ pub fn get_input_code_gamepad(gilrs: &Gilrs) -> (u16, u16) { (pos_code, key_code) } -pub fn get_input_code_no_gamepad() -> (u16, u16) { - use crate::ui::Layout; - - let mp = Layout::generate().clamp_mouse(); +pub fn get_input_code_no_gamepad(layout: &Layout) -> (u16, u16) { + let mp = layout.clamp_mouse(); let pos_code = (mp.1 as u16 * 256) + mp.0 as u16; let mut key_code = 0_u16;