From 47db86ba5980c95a53b3be200ffe93f82204ad75 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 13 Sep 2024 16:45:42 +0900 Subject: [PATCH] Add option to change info text font size --- src/display.rs | 31 +++++++++++++++++++++++++------ src/main.rs | 14 ++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/display.rs b/src/display.rs index 98ce09f..a8360c0 100644 --- a/src/display.rs +++ b/src/display.rs @@ -19,14 +19,16 @@ use std::thread; use std::time::{Duration, Instant}; const POLL_TIME: Duration = Duration::from_millis(333); +const INIT_FONT_SIZE_RATIO: f32 = 1.4167; const INIT_FONT_SIZE_X: f32 = 36.0; -const INIT_FONT_SIZE_Y: f32 = 51.0; +const INIT_FONT_SIZE_Y: f32 = INIT_FONT_SIZE_X * INIT_FONT_SIZE_RATIO; const TEXT_X_OFFSET: f32 = 0.3; const TEXT_OFFSET_Y_SPACING: f32 = 0.4; const TEXT_HEIGHT_SCALE: f32 = 0.12; const ARTIST_HEIGHT_SCALE: f32 = 0.12; const ALBUM_HEIGHT_SCALE: f32 = 0.12; -const TIMER_HEIGHT_SCALE: f32 = 0.105; +const TIMER_HEIGHT_SCALE_RATIO: f32 = 0.875; +const TIMER_HEIGHT_SCALE: f32 = TEXT_HEIGHT_SCALE * TIMER_HEIGHT_SCALE_RATIO; const MIN_WIDTH_RATIO: f32 = 4.0 / 5.0; const INCREASE_AMT: f32 = 6.0 / 5.0; const DECREASE_AMT: f32 = 5.0 / 6.0; @@ -470,10 +472,27 @@ impl MPDDisplay { fn refresh_text_transforms(&mut self, ctx: &mut Context) -> GameResult<()> { let drawable_size = ctx.gfx.drawable_size(); - let text_height_limit = TEXT_HEIGHT_SCALE * drawable_size.1.abs(); - let album_height_limit = ALBUM_HEIGHT_SCALE * drawable_size.1.abs(); - let artist_height_limit = ARTIST_HEIGHT_SCALE * drawable_size.1.abs(); - let timer_height = TIMER_HEIGHT_SCALE * drawable_size.1.abs(); + let text_height_scale: f32; + let album_height_scale: f32; + let artist_height_scale: f32; + let timer_height_scale: f32; + + if let Some(forced_scale) = &self.opts.force_text_height_scale { + text_height_scale = *forced_scale; + album_height_scale = *forced_scale; + artist_height_scale = *forced_scale; + timer_height_scale = *forced_scale * TIMER_HEIGHT_SCALE_RATIO; + } else { + text_height_scale = TEXT_HEIGHT_SCALE; + album_height_scale = ALBUM_HEIGHT_SCALE; + artist_height_scale = ARTIST_HEIGHT_SCALE; + timer_height_scale = TIMER_HEIGHT_SCALE; + } + + let text_height_limit = text_height_scale * drawable_size.1.abs(); + let album_height_limit = album_height_scale * drawable_size.1.abs(); + let artist_height_limit = artist_height_scale * drawable_size.1.abs(); + let timer_height = timer_height_scale * drawable_size.1.abs(); let mut offset_y: f32 = drawable_size.1; diff --git a/src/main.rs b/src/main.rs index 10ea49a..aab0b7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,6 +37,11 @@ pub struct Opt { disable_show_filename: bool, #[arg(long = "disable-show-percentage", help = "disable percentage display")] disable_show_percentage: bool, + #[arg( + long = "force-text-height-scale", + help = "force-set text height relative to window height as a ratio (default 0.12)" + )] + force_text_height_scale: Option, #[arg(long = "pprompt", help = "input password via prompt")] enable_prompt_password: bool, #[arg(long = "pfile", help = "read password from file")] @@ -59,6 +64,15 @@ pub struct Opt { fn main() -> Result<(), String> { let mut opt = Opt::parse(); + if let Some(forced_scale) = &mut opt.force_text_height_scale { + if *forced_scale < 0.01 { + *forced_scale = 0.01; + println!("WARNING: Clamped \"force-text-height-scale\" to minimum of 0.01!"); + } else if *forced_scale > 0.5 { + *forced_scale = 0.5; + println!("WARNING: Clamped \"force-text-height-scale\" to maximum of 0.5!"); + } + } println!("Got host addr == {}, port == {}", opt.host, opt.port); // Read password from file if exists, error otherwise.