From b9f94bac317d375ae35398090348148a0be91bb8 Mon Sep 17 00:00:00 2001 From: red77290 <23342613+red77290@users.noreply.github.com> Date: Sat, 5 Dec 2026 10:39:58 +0000 Subject: [PATCH 1/3] feat(layouts): add proportional 4:3 aspect-ratio layouts across engines and clocks --- src/core/theme.rs | 6 +- src/core/types.rs | 9 + src/engines/clocks/castle_clock.rs | 15 +- src/engines/clocks/mario_clock.rs | 5 +- src/engines/clocks/megaman_clock.rs | 5 +- src/engines/clocks/metal_slug_clock.rs | 38 +++ src/engines/clocks/pokedex_clock.rs | 23 +- src/engines/clocks/sonic_clock.rs | 48 ++- src/engines/clocks/words_clock.rs | 45 ++- src/engines/clocks/worldmap_clock.rs | 81 ++++- src/engines/crypto.rs | 165 ++++++++++ src/engines/dashboard/mod.rs | 159 ++++++++++ src/engines/fighter.rs | 34 +- src/engines/gnews.rs | 6 +- src/engines/google_cast.rs | 111 ++++--- src/engines/renderers/agenda.rs | 9 +- src/engines/renderers/media_showcase.rs | 65 +++- src/engines/renderers/weather_page.rs | 93 +++++- src/engines/spotify.rs | 111 ++++--- src/engines/stock.rs | 164 ++++++++++ src/engines/sysinfo.rs | 292 +++++++++++++++++- .../test_base_resolutions_zero_regression.rs | 140 +++++++++ tests/test_weather_page.rs | 22 ++ 23 files changed, 1528 insertions(+), 118 deletions(-) diff --git a/src/core/theme.rs b/src/core/theme.rs index e698aa6a..e9ffd8a8 100644 --- a/src/core/theme.rs +++ b/src/core/theme.rs @@ -29,8 +29,12 @@ impl ThemeInfo { Some((min_w, min_h)) => w >= min_w && h >= min_h, None => false, } + } else if w >= self.min_landscape.0 && h >= self.min_landscape.1 { + true + } else if crate::core::types::DisplayGeometry::is_landscape_4x3_family(w, h) { + w >= 96 && h >= 72 } else { - w >= self.min_landscape.0 && h >= self.min_landscape.1 + false } } } diff --git a/src/core/types.rs b/src/core/types.rs index c83f20b7..19efe1aa 100644 --- a/src/core/types.rs +++ b/src/core/types.rs @@ -660,6 +660,15 @@ impl DisplayGeometry { LayoutClass::Landscape } } + + /// True for CRT `4:3`-family landscape aspect ratios (`1.0 < width / height < 2.0`, + /// e.g. `64x48`, `96x72`, `128x96`, `192x144`, `256x192`, `384x288`, `512x384`). + /// Strictly `false` for all `1:1` squares, TATE portrait panels, and `>= 2:1` widescreens + /// (`64x32`, `128x64`, `128x32`, `192x64`, `256x64`, `192x32`, `256x32`, `384x64`). + #[inline] + pub const fn is_landscape_4x3_family(width: u32, height: u32) -> bool { + width > height && height.saturating_mul(2) > width + } } /// Edge-triggering state tracker for producers diff --git a/src/engines/clocks/castle_clock.rs b/src/engines/clocks/castle_clock.rs index 8ece0eca..e560bafb 100644 --- a/src/engines/clocks/castle_clock.rs +++ b/src/engines/clocks/castle_clock.rs @@ -562,7 +562,7 @@ impl CastleClock { self.jump_t = 0.0; } else { self.simon_x = -20.0; - self.simon_y = if h >= 48 { 48.0 - 30.0 } else { 0.0 }; + self.simon_y = if h >= 48 { (h - 16 - 30) as f32 } else { 0.0 }; } } @@ -892,8 +892,17 @@ impl CastleClock { } } } else if h >= 48 { - // --- Tall Layout: Blood Red Gothic Digits Centered (`84` on 256x64) --- - let (scale, tw) = if w < 96 { (2, 44) } else { (4, 88) }; + // --- Tall Layout: Blood Red Gothic Digits Centered (`84` on 256x64, proportional on 4:3) --- + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); + let (scale, tw) = if is_4x3 { + let s = (4 * (h / 96).max(1)).min((w / 25).max(2)); + (s, 22 * s) + } else if w < 96 { + (2, 44) + } else { + (4, 88) + }; let time_x = (w - tw) / 2; let time_y = (h - 16 - 5 * scale) / 2 + 2; Self::draw_gothic_time(matrix, time_x, time_y, &time_buf, crimson, scale); diff --git a/src/engines/clocks/mario_clock.rs b/src/engines/clocks/mario_clock.rs index d26a1da6..d8ecac71 100644 --- a/src/engines/clocks/mario_clock.rs +++ b/src/engines/clocks/mario_clock.rs @@ -508,6 +508,8 @@ impl MarioClock { let is_base_4x1 = (w == 128 && h == 32) || (w == 256 && h == 64); let ground_top = if is_portrait { 70 } else { h - GROUND_H }; + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); let (hour_x, minute_x, block_y) = if is_portrait { if w >= 64 { (10, 35, 24) @@ -516,7 +518,8 @@ impl MarioClock { } } else if is_wide_tall { let scene_left = (w - SCENE) / 2; - (scene_left + 13, scene_left + 32, 8) + let by = if is_4x3 { ((h * 38) / 100).max(8) } else { 8 }; + (scene_left + 13, scene_left + 32, by) } else if !is_base_4x1 && w >= 160 { let hx = (w * 52) / 100; (hx, hx + 22, 3) diff --git a/src/engines/clocks/megaman_clock.rs b/src/engines/clocks/megaman_clock.rs index 5f70bc24..c7d262dd 100644 --- a/src/engines/clocks/megaman_clock.rs +++ b/src/engines/clocks/megaman_clock.rs @@ -503,6 +503,8 @@ impl MegamanClock { let is_base_128x32 = w == 128 && h == 32; let ground_top = h - if is_wide_tall { GROUND_TILE_H } else { 6 }; + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); let (hour_x, min_x, pod_y) = if is_portrait { if w >= 64 { (12, 38, 10) @@ -511,7 +513,8 @@ impl MegamanClock { } } else if is_wide_tall { let mid_x = w / 2; - (mid_x - 28, mid_x + 4, 10) + let py = if is_4x3 { ((h * 26) / 100).max(10) } else { 10 }; + (mid_x - 28, mid_x + 4, py) } else if !is_base_128x32 && w >= 160 { let mid_x = (w * 52) / 100; (mid_x - 27, mid_x, 6) diff --git a/src/engines/clocks/metal_slug_clock.rs b/src/engines/clocks/metal_slug_clock.rs index d7953fd1..cefa8bc8 100644 --- a/src/engines/clocks/metal_slug_clock.rs +++ b/src/engines/clocks/metal_slug_clock.rs @@ -693,6 +693,38 @@ impl MetalSlugClock { surface.fill_circle(w - 18, 4, 2, 240, 80, 20); Self::draw_arcade_digit(surface, w - 12, 2, b'1', hud_white, 1); Self::draw_arcade_digit(surface, w - 7, 2, b'0', hud_white, 1); + } else if crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32) { + // 4:3 CRT Neo-Geo HUD (e.g. 96x72, 128x96, 192x144, 256x192, 384x288) + let s = (h / 96).max(1); + let bar_h = 11 * s; + surface.fill_rect(0, 0, w, bar_h, 8, 8, 16); + surface.fill_rect(0, bar_h, w, 1, 40, 40, 70); + + Self::draw_arcade_digit(surface, 4 * s, 2 * s, b'1', hud_red, s); + let score_str = format!("00{}{}", self.shown_hh, self.shown_mm); + let mut sx = 12 * s; + for b in score_str.bytes() { + if sx >= w / 2 - 4 { + break; + } + Self::draw_arcade_digit(surface, sx, 2 * s, b, hud_white, s); + sx += 4 * s; + } + + // Right HUD ammo box + bombs without colliding with centered time + let r_box = w - 34 * s; + surface.fill_rect(r_box, 2 * s, 7 * s, 7 * s, 220, 160, 20); + surface.draw_rect(r_box, 2 * s, 7 * s, 7 * s, 255, 240, 80); + surface.fill_circle(w - 18 * s, 5 * s, 2 * s, 240, 80, 20); + Self::draw_arcade_digit(surface, w - 12 * s, 2 * s, b'1', hud_white, s); + Self::draw_arcade_digit(surface, w - 7 * s, 2 * s, b'0', hud_white, s); + + // Prominent centered Neo-Geo clock right below the HUD bar + let t_scale = (2 * s).max(2); + let time_w = 22 * t_scale; + let time_x = (w - time_w) / 2; + let time_y = bar_h + (5 * s).max(4); + Self::draw_arcade_time(surface, time_x, time_y, &time_str, hud_yellow, t_scale); } else { surface.fill_rect(0, 0, w, 12, 8, 8, 16); surface.fill_rect(0, 12, w, 1, 40, 40, 70); @@ -764,6 +796,8 @@ impl MetalSlugClock { let w = surface.width() as i32; let h = surface.height() as i32; let is_portrait = h > w; + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); let div = if !is_portrait && h < 48 { 2 } else { 1 }; let ground_top = if is_portrait { if h < 192 { @@ -782,6 +816,8 @@ impl MetalSlugClock { } } else if h < 48 { (w - 42).max(90) as f32 + } else if is_4x3 { + (w - 50).max(56) as f32 } else { (w - 71).max(96) as f32 }; @@ -793,6 +829,8 @@ impl MetalSlugClock { } } else if h < 48 { 28.0 + } else if is_4x3 { + (w / 8).max(8) as f32 } else { 42.0 }; diff --git a/src/engines/clocks/pokedex_clock.rs b/src/engines/clocks/pokedex_clock.rs index b15f85a0..78e49f1a 100644 --- a/src/engines/clocks/pokedex_clock.rs +++ b/src/engines/clocks/pokedex_clock.rs @@ -45,7 +45,9 @@ impl PokedexClock { ) { let w = matrix.width() as i32; let h = matrix.height() as i32; - let valid_tall = w >= 64 && h >= 64 && (h > w || w >= 192); + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); + let valid_tall = w >= 64 && h >= 64 && (h > w || w >= 192 || is_4x3); let valid_ribbon = w >= 192 && h >= 32 && h < 64; if !valid_tall && !valid_ribbon { super::wide_only_notice(matrix, font, scale); @@ -156,22 +158,35 @@ impl PokedexClock { let d = cwscene::divisor(h); cwscene::draw_background(matrix, &POKEDEX_BG, w, h); - if w > 64 && !(w == 256 && h == 64) { + if (w > 64 || h > 64) && !(w == 256 && h == 64) { let ox = cwscene::origin_x(w, h); + let oy = cwscene::origin_y(h); let scene_w = cwscene::scaled_size(h); + if oy > 1 && is_4x3 { + matrix.fill_rect(0, 0, w, oy, 180, 24, 36); + matrix.fill_rect(0, 0, w, 2, 225, 60, 72); + matrix.fill_rect(0, oy - 1, w, 1, 110, 10, 18); + let by = oy + scene_w; + let bh = h - by; + if bh > 0 { + matrix.fill_rect(0, by, w, bh, 180, 24, 36); + matrix.fill_rect(0, by, w, 1, 225, 60, 72); + matrix.fill_rect(0, h - 2, w, 2, 110, 10, 18); + } + } for &(wx, ww) in &[(0, ox), (ox + scene_w, w - (ox + scene_w))] { if ww <= 2 { continue; } matrix.fill_rect(wx, 0, ww, h, 180, 24, 36); matrix.fill_rect(wx, 0, ww, 2, 225, 60, 72); - matrix.fill_rect(wx, h - 2, ww, 2, 110, 10, 18); + matrix.fill_rect(wx, h - 2, w.min(ww), 2, 110, 10, 18); matrix.fill_rect(wx, 2, 1, h - 4, 120, 14, 22); matrix.fill_rect(wx + ww - 1, 2, 1, h - 4, 120, 14, 22); if ww >= 20 && h >= 24 { let cx = wx + ww / 2; let cy = h / 2; - let r = 7i32; + let r = (7 * (h / 96).max(1)).min(ww / 2 - 2); for dy in -r..=r { for dx in -r..=r { let d2 = dx * dx + dy * dy; diff --git a/src/engines/clocks/sonic_clock.rs b/src/engines/clocks/sonic_clock.rs index 9e459514..b2ded5d6 100644 --- a/src/engines/clocks/sonic_clock.rs +++ b/src/engines/clocks/sonic_clock.rs @@ -450,7 +450,7 @@ impl SonicClock { self.jump_t = 0.0; } else { self.sonic_x = -30.0; - self.sonic_y = if h >= 48 { 64.0 - 16.0 - 39.0 } else { 0.0 }; + self.sonic_y = if h >= 48 { (h - 16 - 39) as f32 } else { 0.0 }; } } @@ -767,13 +767,30 @@ impl SonicClock { } } } else if h >= 48 { - let (scale, tw) = if w < 96 { (2, 44) } else { (4, 88) }; + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); + let (scale, tw) = if is_4x3 { + let s = if w < 160 { + (3 * (h / 96).max(1)).min((w / 25).max(2)) + } else { + (4 * (h / 96).max(1)).min((w / 28).max(3)) + }; + (s, 22 * s) + } else if w < 96 { + (2, 44) + } else { + (4, 88) + }; let time_x = (w - tw) / 2; let sky_h = h - 16; - let time_y = (sky_h - 5 * scale) / 2 + 1; - let box_x = (time_x - 32).max(2); + let time_y = if is_4x3 { + ((sky_h * 28) / 100).max(4) + } else { + (sky_h - 5 * scale) / 2 + 1 + }; + let box_x = if is_4x3 { 6 } else { (time_x - 32).max(2) }; let box_y = sky_h - 32; - if w >= 128 { + if w >= 128 || (is_4x3 && w >= 96) { Self::blit_sprite( matrix, &SONIC_ITEM_BOX_PAL, @@ -786,7 +803,21 @@ impl SonicClock { ); } Self::draw_arcade_time(matrix, time_x, time_y, &time_buf, yellow_time, scale); - if time_x + tw + 22 <= w { + if is_4x3 { + Self::blit_sprite( + matrix, + ring_pal, + ring_pix, + 16, + 16, + (w - 24).max(box_x + 36), + sky_h - 26, + false, + ); + if h >= 90 && w >= 112 { + Self::blit_sprite(matrix, ring_pal, ring_pix, 16, 16, (w - 16) / 2, 4, false); + } + } else if time_x + tw + 22 <= w { Self::blit_sprite( matrix, ring_pal, @@ -798,8 +829,9 @@ impl SonicClock { false, ); } - if w >= 176 { - let moto_x = (w - 48) + moto_offset as i32; + if w >= 176 || (is_4x3 && w >= 120) { + let moto_base = if is_4x3 { w - 44 } else { w - 48 }; + let moto_x = moto_base + (moto_offset * if is_4x3 { 0.6 } else { 1.0 }) as i32; Self::blit_sprite( matrix, &SONIC_MOTOBUG_PAL, diff --git a/src/engines/clocks/words_clock.rs b/src/engines/clocks/words_clock.rs index a60a5aae..cfe35fba 100644 --- a/src/engines/clocks/words_clock.rs +++ b/src/engines/clocks/words_clock.rs @@ -29,7 +29,11 @@ impl WordsClock { ) { let w = matrix.width() as i32; let h = matrix.height() as i32; - if w < 192 || h < 32 { + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32) + && w >= 96 + && h >= 72; + if (w < 192 || h < 32) && !is_4x3 { super::wide_only_notice(matrix, font, scale); return; } @@ -58,19 +62,33 @@ impl WordsClock { h * 26 / 100, (255, 255, 255), w, + false, ); let rule_w = w * 3 / 4; let rule_y = h / 2; for x in ((w - rule_w) / 2)..((w - rule_w) / 2 + rule_w) { matrix.set_pixel(x, rule_y, ACCENT.0, ACCENT.1, ACCENT.2); } - centre(matrix, &date, font, 1.0, h * 77 / 100, ACCENT, w); + centre(matrix, &date, font, 1.0, h * 77 / 100, ACCENT, w, false); return; } - let s = scale.max(1) as f32; + let s = if is_4x3 { + (scale.max(1) * (h as u32 / 96).max(1)) as f32 + } else { + scale.max(1) as f32 + }; - centre(matrix, &hour_words, font, s, h * 22 / 100, ACCENT, w); + centre( + matrix, + &hour_words, + font, + s, + h * 22 / 100, + ACCENT, + w, + is_4x3, + ); centre( matrix, &minute_words, @@ -79,6 +97,7 @@ impl WordsClock { h * 45 / 100, (255, 255, 255), w, + is_4x3, ); let rule_w = w * 3 / 4; @@ -87,30 +106,38 @@ impl WordsClock { matrix.set_pixel(x, rule_y, 255, 255, 255); } - centre(matrix, &date, font, s, h * 80 / 100, ACCENT, w); + centre(matrix, &date, font, s, h * 80 / 100, ACCENT, w, is_4x3); } } +#[allow(clippy::too_many_arguments)] fn centre( matrix: &mut dyn IDrawingSurface, text: &str, font: &ArcadeFont<'_>, - scale: f32, + mut scale: f32, centre_y: i32, color: (u8, u8, u8), panel_w: i32, + autofit: bool, ) { if text.is_empty() { return; } - let (_, tw, th) = font.get_pixel_map(text, scale); + let (_, mut tw, mut th) = font.get_pixel_map(text, scale); + while autofit && scale > 1.0 && tw > panel_w - 4 { + scale -= 1.0; + let (_, nw, nh) = font.get_pixel_map(text, scale); + tw = nw; + th = nh; + } BaseRenderer::draw_text_at( matrix, text, font, scale, - (panel_w - tw as i32) / 2, - centre_y - th as i32 / 2, + (panel_w - tw) / 2, + centre_y - th / 2, color, (0, 0, 0), ); diff --git a/src/engines/clocks/worldmap_clock.rs b/src/engines/clocks/worldmap_clock.rs index 95065b5e..2e0850f2 100644 --- a/src/engines/clocks/worldmap_clock.rs +++ b/src/engines/clocks/worldmap_clock.rs @@ -41,9 +41,8 @@ impl WorldMapClock { ) { let w = matrix.width() as i32; let h = matrix.height() as i32; - let d = cwscene::divisor(h); - let ox = cwscene::origin_x(w, h); - let oy = cwscene::origin_y(h); + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); // Offset of the configured timezone, taken from the running clock. let local = Local::now(); @@ -55,6 +54,82 @@ impl WorldMapClock { let utc_hours = utc.hour() as f32 + utc.minute() as f32 / 60.0; let sun_col = Self::column_for_offset(12.0 - utc_hours); + if is_4x3 && h >= 72 { + let up = (h / 88).max(1); + let map_draw_h = MAP_H * up; + let hdr_h = ((h - map_draw_h) * 32 / 100).max(6); + let map_top = hdr_h; + let ox = (w - 64 * up) / 2; + + // Subtle deep-ocean header & footer telemetry bands + matrix.fill_rect(0, 0, w, h, 4, 12, 28); + matrix.fill_rect(0, hdr_h - 1, w, 1, 28, 70, 110); + if map_top + map_draw_h < h { + matrix.fill_rect(0, map_top + map_draw_h, w, 1, 28, 70, 110); + } + + for py in 0..map_draw_h { + let draw_y = map_top + py; + if draw_y >= h { + break; + } + let sy = (py / up).clamp(0, MAP_H - 1); + for px in 0..w { + let scene_x = (px - ox).div_euclid(up); + let col = (offset + scene_x).rem_euclid(MAP_W); + let mut c = WORLD_MAP[(sy * MAP_W + col) as usize]; + if c == MAP_MASK { + continue; + } + let mut away = (col - sun_col).abs(); + if away > MAP_W / 2 { + away = MAP_W - away; + } + if away > 6 * TZ_SIZE { + let r = (c >> 11) & 0x1F; + let g = (c >> 5) & 0x3F; + let b = c & 0x1F; + c = ((r / 3) << 11) | ((g / 3) << 5) | (b / 3); + } + cwscene::put(matrix, px, draw_y, c); + } + } + + let marker_x = ox + HOME_COLUMN * up; + for mw_dx in 0..up { + for y in map_top..(map_top + map_draw_h).min(h) { + cwscene::put(matrix, marker_x + mw_dx, y, MARKER); + } + } + + let text = format!("{:02}:{:02}", hours, minutes); + let ftr_top = (map_top + map_draw_h + 1).min(h - 8); + let ftr_h = (h - ftr_top).max(8); + let mut t_scale = (scale.max(1) * up as u32) as f32; + let (_, mut tw, mut th) = font.get_pixel_map(&text, t_scale); + while t_scale > 1.0 && (tw > w - 6 || th > ftr_h - 2) { + t_scale -= 1.0; + let (_, nw, nh) = font.get_pixel_map(&text, t_scale); + tw = nw; + th = nh; + } + BaseRenderer::draw_text_at( + matrix, + &text, + font, + t_scale, + ((w - tw) / 2).max(1), + ftr_top + ((ftr_h - th) / 2).max(0), + (255, 255, 255), + (0, 0, 0), + ); + return; + } + + let d = cwscene::divisor(h); + let ox = cwscene::origin_x(w, h); + let oy = cwscene::origin_y(h); + for py in 0..(MAP_H / d) { let sy = py * d; for px in 0..w { diff --git a/src/engines/crypto.rs b/src/engines/crypto.rs index 388797aa..85f1386b 100644 --- a/src/engines/crypto.rs +++ b/src/engines/crypto.rs @@ -984,6 +984,124 @@ impl CryptoEngine { let m_h = matrix.height() as i32; let tf_label = self.chart_timeframe.label(); + if crate::core::types::DisplayGeometry::is_landscape_4x3_family(m_w as u32, m_h as u32) { + let s = (m_h / 96).max(1); + let pad = (4 * s).max(3); + let div_y = (m_h * 45) / 100; + let icon_sz = if m_h >= 72 { 16 * s } else { 12 }; + draw_crypto_icon(matrix, symbol, pad, pad, icon_sz, cached_img); + + let badge_text = if success && price > 0.0 { + format!("{} {}", if change >= 0.0 { "^" } else { "v" }, pct_str) + } else { + pct_str.to_string() + }; + let badge_w = (badge_text.len() as i32 * 6 + 6) * s; + let badge_h = 10 * s; + let badge_x = (m_w - pad - badge_w).max(pad + icon_sz + 8); + let (pill_bg, pill_border) = if !success || price <= 0.0 { + ((28, 28, 28), (70, 70, 70)) + } else if change >= 0.0 { + ((0, 38, 14), (0, 130, 50)) + } else { + ((42, 10, 10), (150, 40, 40)) + }; + fill_round_rect(matrix, badge_x, pad, badge_w, badge_h, 2 * s, pill_bg); + draw_round_rect(matrix, badge_x, pad, badge_w, badge_h, 2 * s, pill_border); + draw_glcd_text_scaled( + matrix, + &badge_text, + badge_x + 3 * s, + pad + 2 * s, + s, + badge_color, + ); + + let x_sym = pad + icon_sz + 4 * s; + draw_scrolling_text( + matrix, + symbol, + x_sym, + (badge_x - 3 * s).max(x_sym + 12), + pad + s, + s, + (255, 255, 255), + elapsed_ms, + false, + ); + + let tf_w = tf_label.len() as i32 * 6 * s; + let price_max_x = (m_w - pad - tf_w - 4 * s).max(pad + 24); + let price_y = if m_h >= 72 { + pad + icon_sz + 4 * s + } else { + div_y - 9 + }; + let big_scale = 2 * s; + if m_h >= 84 && price_str.len() as i32 * 6 * big_scale <= (price_max_x - pad) { + draw_glcd_text_scaled( + matrix, + price_str, + pad, + (div_y - 15 * s).max(pad + icon_sz + 2 * s), + big_scale, + (255, 215, 0), + ); + } else { + draw_scrolling_text( + matrix, + price_str, + pad, + price_max_x, + price_y, + s, + (255, 215, 0), + elapsed_ms, + false, + ); + } + draw_glcd_text_scaled( + matrix, + tf_label, + m_w - pad - tf_w, + (div_y - 9 * s).max(price_y), + s, + (140, 140, 140), + ); + + draw_fast_hline(matrix, pad, div_y, (m_w - 2 * pad).max(4), (50, 50, 60)); + + let spark_x = pad; + let spark_y = div_y + 3 * s; + let spark_w = (m_w - 2 * pad).max(8) as u32; + let spark_h = (m_h - spark_y - pad).max(8) as u32; + if let Some(hist) = history_opt { + if hist.points.len() > 1 { + let is_up = + hist.points.last().unwrap_or(&0.0) >= hist.points.first().unwrap_or(&0.0); + let line_color = if is_up { (0, 255, 120) } else { (255, 60, 60) }; + let fill_color = if is_up { + Some((0, 35, 12)) + } else { + Some((40, 12, 12)) + }; + draw_sparkline( + matrix, hist, spark_x, spark_y, spark_w, spark_h, line_color, fill_color, + ); + return; + } + } + draw_glcd_text_scaled( + matrix, + crate::core::i18n::t(lang, "loading_chart"), + spark_x + 2 * s, + spark_y + (spark_h as i32 / 2) - 4 * s, + s, + (120, 120, 120), + ); + return; + } + draw_crypto_icon(matrix, symbol, 4, 4, 16, cached_img); let div_x = if m_w >= 320 { @@ -1964,5 +2082,52 @@ mod tests { badge_lit > 40, "expected right pill badge lit on 192x32 quote" ); + + // Verify 4:3 aspect ratio & multiples (128x96 and 256x192) populate full-width top quote + bottom sparkline + for &(w43, h43) in &[(128u32, 96u32), (256, 192)] { + let mut s43 = MockSurface::new(w43, h43); + engine.render_unified_wide( + &mut s43, + "BTC", + "$98450", + "+3.42%", + (0, 255, 120), + true, + 98450.0, + 3.42, + None, + Some(&hist), + 0, + "en", + ); + let mut top_lit = 0usize; + let mut bot_left_lit = 0usize; + let mut bot_right_lit = 0usize; + let split_y = (h43 * 45) / 100; + for y in 0..split_y { + for x in 0..w43 { + let p = s43.canvas.get_pixel(x, y); + if p[0] > 0 || p[1] > 0 || p[2] > 0 { + top_lit += 1; + } + } + } + for y in (split_y + 4)..h43 { + for x in 0..(w43 / 2) { + let p = s43.canvas.get_pixel(x, y); + if p[0] > 0 || p[1] > 0 || p[2] > 0 { + bot_left_lit += 1; + } + } + for x in (w43 / 2)..w43 { + let p = s43.canvas.get_pixel(x, y); + if p[0] > 0 || p[1] > 0 || p[2] > 0 { + bot_right_lit += 1; + } + } + } + assert!(top_lit > 80); + assert!(bot_left_lit > 50 && bot_right_lit > 50); + } } } diff --git a/src/engines/dashboard/mod.rs b/src/engines/dashboard/mod.rs index 1a36d7fe..7166d1a8 100644 --- a/src/engines/dashboard/mod.rs +++ b/src/engines/dashboard/mod.rs @@ -762,6 +762,165 @@ impl Engine for DashboardEngine { ); } } + } else if crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32) { + // ================================================================ + // 4:3 CRT COCKPIT GRID (96x72, 128x96, 192x144, 256x192, 384x288) + // ================================================================ + let gap = if h >= 96 { 2 } else { 1 }; + let has_markets = self.show_markets && !data.markets.is_empty(); + let has_world = self.show_world_clock && !data.world_times.is_empty(); + let has_mid = (has_world && self.show_weather) || self.show_sysinfo; + + let bot_h = if has_markets { + ((h * 22) / 100).max(16) + } else { + 0 + }; + let rem_after_bot = h - if bot_h > 0 { bot_h + gap } else { 0 }; + let (top_h, mid_h) = if has_mid { + let mh_band = ((rem_after_bot * 36) / 100).max(18); + (rem_after_bot - mh_band - gap, mh_band) + } else { + (rem_after_bot, 0) + }; + + // 1. Top Band: Square Watch Dial / Clock on left + Weather (or World Clocks) on right + let mut top_x = self.offset_x; + if self.show_clock { + let clock_w = if self.show_weather || (!has_mid && has_world) { + top_h.min(w / 2) + } else { + w + }; + let clock_rect = Rect::new(top_x, self.offset_y, clock_w, top_h); + match self.clock_mode { + ClockMode::WatchDial => render_analog_watch_dial( + matrix, + &clock_rect, + hours, + minutes, + seconds, + sub_second, + day, + &theme_palette, + self.show_seconds, + self.show_date, + ), + ClockMode::Digital => render_digital_clock( + matrix, + &clock_rect, + hours, + minutes, + seconds, + day, + month, + &theme_palette, + self.show_seconds, + self.show_date, + is_24h, + active_lang, + ), + ClockMode::Minimal => render_digital_clock( + matrix, + &clock_rect, + hours, + minutes, + seconds, + day, + month, + &theme_palette, + false, + false, + is_24h, + active_lang, + ), + } + top_x += clock_w + gap; + } + + let top_right_w = (self.offset_x + w) - top_x; + if top_right_w >= 16 { + let right_rect = Rect::new(top_x, self.offset_y, top_right_w, top_h); + if self.show_weather { + render_climate_slot( + matrix, + &right_rect, + data.temp_c, + is_fahrenheit, + data.weather_code, + &theme_palette, + ); + } else if has_world { + render_world_clock_slot( + matrix, + &right_rect, + &data.world_times, + seconds, + &utc, + &theme_palette, + is_24h, + ); + } + } + + // 2. Middle Band: World Clocks + SysInfo side-by-side across full width + if mid_h > 0 { + let mid_y = self.offset_y + top_h + gap; + let world_in_mid = has_world && self.show_weather; + if world_in_mid && self.show_sysinfo { + let left_w = (w - gap) / 2; + let right_w = w - gap - left_w; + let w_rect = Rect::new(self.offset_x, mid_y, left_w, mid_h); + render_world_clock_slot( + matrix, + &w_rect, + &data.world_times, + seconds, + &utc, + &theme_palette, + is_24h, + ); + let s_rect = Rect::new(self.offset_x + left_w + gap, mid_y, right_w, mid_h); + render_sysinfo_slot( + matrix, + &s_rect, + data.cpu_usage, + data.ram_usage, + data.wifi_rssi, + seconds, + &theme_palette, + ); + } else if world_in_mid { + let w_rect = Rect::new(self.offset_x, mid_y, w, mid_h); + render_world_clock_slot( + matrix, + &w_rect, + &data.world_times, + seconds, + &utc, + &theme_palette, + is_24h, + ); + } else if self.show_sysinfo { + let s_rect = Rect::new(self.offset_x, mid_y, w, mid_h); + render_sysinfo_slot( + matrix, + &s_rect, + data.cpu_usage, + data.ram_usage, + data.wifi_rssi, + seconds, + &theme_palette, + ); + } + } + + // 3. Bottom Band: Full-Width Infinite Market Ticker + if bot_h > 0 { + let bot_y = self.offset_y + h - bot_h; + let bot_rect = Rect::new(self.offset_x, bot_y, w, bot_h); + render_market_ticker(matrix, &bot_rect, &data.markets, now_ms(), &theme_palette); + } } else if is_wide { // ================================================================ // WIDESCREEN Responsive Geometry (128x32, 128x64, 256x64) diff --git a/src/engines/fighter.rs b/src/engines/fighter.rs index 0657c6b7..20e0e7c7 100644 --- a/src/engines/fighter.rs +++ b/src/engines/fighter.rs @@ -399,6 +399,10 @@ impl FighterEngine { if self.active { let is_tate = self.matrix_width < 48 || self.matrix_height > (self.matrix_width * 3) / 2; + let is_4x3 = crate::core::types::DisplayGeometry::is_landscape_4x3_family( + self.matrix_width, + self.matrix_height, + ); let (mut p1_scale, mut p1_ground_y, mut p1_head_y) = (1, 32, 0); if let Some(ref mut p1) = self.p1 { let is_32px = p1.character.meta.width <= 32; @@ -408,6 +412,12 @@ impl FighterEngine { } else { 1 } + } else if is_4x3 { + if is_32px { + (self.matrix_height / 32).min(self.matrix_width / 64) as i32 + } else { + (self.matrix_height / 64).min(self.matrix_width / 128) as i32 + } } else if self.matrix_height >= 64 && is_32px { (self.matrix_height / 32) as i32 } else { @@ -418,7 +428,7 @@ impl FighterEngine { p1_scale = scale; p1_ground_y = p1.character.meta.ground_y as i32; p1_head_y = p1.character.meta.head_y as i32; - p1.y = if is_tate { + p1.y = if is_tate || is_4x3 { (self.matrix_height as i32 - 1) - (p1_ground_y * scale) } else { (1 - p1_head_y) * scale @@ -432,6 +442,12 @@ impl FighterEngine { } else { 1 } + } else if is_4x3 { + if is_32px { + (self.matrix_height / 32).min(self.matrix_width / 64) as i32 + } else { + (self.matrix_height / 64).min(self.matrix_width / 128) as i32 + } } else if self.matrix_height >= 64 && is_32px { (self.matrix_height / 32) as i32 } else { @@ -439,7 +455,7 @@ impl FighterEngine { } .max(1); p2.scale = scale; - p2.y = if is_tate { + p2.y = if is_tate || is_4x3 { (self.matrix_height as i32 - 1) - (p2.character.meta.ground_y as i32 * scale) } else { let ground_y = (1 - p1_head_y) + (p1_ground_y * p1_scale); @@ -627,12 +643,22 @@ impl FighterEngine { let c2 = FighterChar::load_char(&char2_dir, meta2.clone()); if let (Some(c1), Some(c2)) = (c1, c2) { let is_32px = dir_path.to_string_lossy().contains("32"); + let is_4x3 = crate::core::types::DisplayGeometry::is_landscape_4x3_family( + matrix_width, + matrix_height, + ); let scale = if is_tate { if matrix_width >= 96 && is_32px { (matrix_width / 64) as i32 } else { 1 } + } else if is_4x3 { + if is_32px { + (matrix_height / 32).min(matrix_width / 64) as i32 + } else { + (matrix_height / 64).min(matrix_width / 128) as i32 + } } else if matrix_height >= 64 && is_32px { (matrix_height / 32) as i32 } else { @@ -640,8 +666,8 @@ impl FighterEngine { } .max(1); - let (y1, y2) = if is_tate { - // In TATE mode, fighters stand on the very bottom pixel of the screen: groundY = screenH - 1 + let (y1, y2) = if is_tate || is_4x3 { + // In TATE and 4:3 CRT modes, fighters stand on the bottom pixel of the screen: groundY = screenH - 1 let ground_y_screen = matrix_height as i32 - 1; ( ground_y_screen - (c1.meta.ground_y as i32 * scale), diff --git a/src/engines/gnews.rs b/src/engines/gnews.rs index 3b8886ef..51199a8e 100644 --- a/src/engines/gnews.rs +++ b/src/engines/gnews.rs @@ -1741,7 +1741,11 @@ impl Engine for GNewsEngine { } } } else if self.display_mode == "static_paged" { - let lines_per_page = if mh >= 64 { 4usize } else { 2usize }; + let lines_per_page = if mh >= 64 { + (((mh as i32) - body_y) / 9).max(4) as usize + } else { + 2usize + }; let start_idx = self.current_page_index * lines_per_page; for (row, line) in self .cached_display_lines diff --git a/src/engines/google_cast.rs b/src/engines/google_cast.rs index d960baa0..c0a51f68 100644 --- a/src/engines/google_cast.rs +++ b/src/engines/google_cast.rs @@ -246,7 +246,16 @@ impl Engine for GoogleCastEngine { }; if self.show_album_art { - let target_size = if ctx.surface.height() >= 64 { 52 } else { 24 }; + let sw = ctx.surface.width(); + let sh = ctx.surface.height(); + let target_size = + if crate::core::types::DisplayGeometry::is_landscape_4x3_family(sw, sh) { + ((sh * 58) / 100).clamp(28, (sw * 44) / 100) + } else if sh >= 64 { + 52 + } else { + 24 + }; self.target_art_size.store(target_size, Ordering::Relaxed); if let Ok(guard) = self.shared_cover.try_lock() { self.cached_cover = guard.clone(); @@ -611,6 +620,11 @@ impl Engine for GoogleCastEngine { let clip_max_x = w - right_reserved; let avail_w = (clip_max_x - clip_min_x).max(16); + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); + let s_4x3 = if is_4x3 { (h / 96).max(1) } else { 1 }; + let text_scale = s_4x3 as f32; + // 3. Continuous Circular (Seamless Looping) Marquee let render_marquee = |matrix: &mut dyn IDrawingSurface, text: &str, @@ -618,13 +632,13 @@ impl Engine for GoogleCastEngine { y: i32, color: (u8, u8, u8), offset: i32| { - let (_, text_w, _) = font.get_pixel_map(text, 1.0); + let (_, text_w, _) = font.get_pixel_map(text, text_scale); if text_w <= avail_w { BaseRenderer::draw_text_clipped( matrix, text, font, - 1.0, + text_scale, clip_min_x, y, clip_min_x, @@ -633,17 +647,16 @@ impl Engine for GoogleCastEngine { (0, 0, 0), ); } else { - let gap = 20; // 20px seamless spacing between loop repetitions + let gap = 20 * s_4x3; let total_w = text_w + gap; let dx = offset.rem_euclid(total_w); - // Draw primary text instance let draw_x1 = clip_min_x - dx; BaseRenderer::draw_text_clipped( matrix, text, font, - 1.0, + text_scale, draw_x1, y, clip_min_x, @@ -652,14 +665,13 @@ impl Engine for GoogleCastEngine { (0, 0, 0), ); - // Draw trailing secondary instance for circular looping let draw_x2 = draw_x1 + total_w; if draw_x2 < clip_max_x { BaseRenderer::draw_text_clipped( matrix, text, font, - 1.0, + text_scale, draw_x2, y, clip_min_x, @@ -671,8 +683,20 @@ impl Engine for GoogleCastEngine { } }; - let y_title = if h >= 64 { 8 } else { 3 }; - let y_artist = if h >= 64 { 22 } else { 13 }; + let y_title = if is_4x3 { + (h * 18) / 100 + } else if h >= 64 { + 8 + } else { + 3 + }; + let y_artist = if is_4x3 { + (h * 38) / 100 + } else if h >= 64 { + 22 + } else { + 13 + }; // Draw Title render_marquee( @@ -702,9 +726,26 @@ impl Engine for GoogleCastEngine { self.marquee_offset / 2, ); + if is_4x3 && !status.app_name.is_empty() && !status.artist.is_empty() { + render_marquee( + ctx.surface, + &status.app_name, + &font, + (h * 56) / 100, + (150, 165, 185), + self.marquee_offset / 3, + ); + } + // 4. Draw Beat Visualizer on the right with dynamic colors if self.show_visualizer && status.is_playing { - let eq_base_y = if h >= 64 { 44 } else { 21 }; + let eq_base_y = if is_4x3 { + (h * 84) / 100 + } else if h >= 64 { + 44 + } else { + 21 + }; if is_compact_screen && has_art { // 3 ultra-crisp compact bars (2px wide each, 1px gap) @@ -732,29 +773,29 @@ impl Engine for GoogleCastEngine { } } } else { - // 4 wide bars (2px wide + 1px spacing) - let eq_x = w - 13; + // 4 wide bars (scaled by s_4x3 on 4:3 multiples) + let eq_x = w - 13 * s_4x3; let bar_heights = [ - ((self.anim_frame.wrapping_mul(3)) % 8 + 2) as i32, - ((self.anim_frame.wrapping_mul(5)) % 11 + 3) as i32, - ((self.anim_frame.wrapping_mul(2)) % 9 + 2) as i32, - ((self.anim_frame.wrapping_mul(7)) % 7 + 2) as i32, + ((self.anim_frame.wrapping_mul(3)) % 8 + 2) as i32 * s_4x3, + ((self.anim_frame.wrapping_mul(5)) % 11 + 3) as i32 * s_4x3, + ((self.anim_frame.wrapping_mul(2)) % 9 + 2) as i32 * s_4x3, + ((self.anim_frame.wrapping_mul(7)) % 7 + 2) as i32 * s_4x3, ]; for (i, &bh) in bar_heights.iter().enumerate() { - let bx = eq_x + (i as i32 * 3); + let bx = eq_x + (i as i32 * 3 * s_4x3); for by in 0..bh { let py = eq_base_y - by; if py >= 0 { - let color = if by > 7 { + let color = if by > 7 * s_4x3 { (255, 50, 50) - } else if by > 4 { + } else if by > 4 * s_4x3 { (255, 190, 0) } else { (0, 240, 110) }; - ctx.surface.set_pixel(bx, py, color.0, color.1, color.2); - ctx.surface.set_pixel(bx + 1, py, color.0, color.1, color.2); + ctx.surface + .fill_rect(bx, py, 2 * s_4x3, 1, color.0, color.1, color.2); } } } @@ -762,12 +803,12 @@ impl Engine for GoogleCastEngine { } else if self.show_volume { let vol_pct = (status.volume_level * 100.0) as u32; let vol_str = format!("{}%", vol_pct); - let v_x = w - (vol_str.len() as i32 * 6) - 1; + let v_x = w - (vol_str.len() as i32 * 6 * s_4x3) - 1; BaseRenderer::draw_text_at( ctx.surface, &vol_str, &font, - 1.0, + text_scale, v_x, y_title, (180, 180, 180), @@ -775,20 +816,20 @@ impl Engine for GoogleCastEngine { ); } - // 5. Draw Progress Bar (Bottom 2 pixels) + // 5. Draw Progress Bar (Bottom 2 * s_4x3 pixels) if self.show_progress && status.duration_sec > 0.0 { let progress = (status.current_time_sec / status.duration_sec).clamp(0.0, 1.0); let bar_w = ((w - 2) as f32 * progress) as i32; - - // Background line - for x in 1..w - 1 { - ctx.surface.set_pixel(x, h - 2, 35, 35, 40); - ctx.surface.set_pixel(x, h - 1, 20, 20, 25); - } - // Active progress fill (Google Blue gradient) - for x in 1..=bar_w { - ctx.surface.set_pixel(x, h - 2, 66, 133, 244); - ctx.surface.set_pixel(x, h - 1, 33, 90, 180); + let p_h = 2 * s_4x3; + ctx.surface + .fill_rect(1, h - p_h, w - 2, p_h / 2, 35, 35, 40); + ctx.surface + .fill_rect(1, h - p_h / 2, w - 2, p_h / 2, 20, 20, 25); + if bar_w > 0 { + ctx.surface + .fill_rect(1, h - p_h, bar_w, p_h / 2, 66, 133, 244); + ctx.surface + .fill_rect(1, h - p_h / 2, bar_w, p_h / 2, 33, 90, 180); } } } diff --git a/src/engines/renderers/agenda.rs b/src/engines/renderers/agenda.rs index e9b35189..4b1db8ff 100644 --- a/src/engines/renderers/agenda.rs +++ b/src/engines/renderers/agenda.rs @@ -285,7 +285,14 @@ impl AgendaRenderer { } } - let page_rows = shown.min(4); + let max_rows = if crate::core::types::DisplayGeometry::is_landscape_4x3_family( + w as u32, h as u32, + ) { + ((h - 13) / 16).clamp(4, 8) as usize + } else { + 4usize + }; + let page_rows = shown.min(max_rows); let row_h = ((h - 13) / (page_rows.max(1) as i32)).clamp(12, 18); let mut cy = 13; for row in 0..page_rows { diff --git a/src/engines/renderers/media_showcase.rs b/src/engines/renderers/media_showcase.rs index 031ac07b..b961743a 100644 --- a/src/engines/renderers/media_showcase.rs +++ b/src/engines/renderers/media_showcase.rs @@ -172,6 +172,12 @@ pub fn compute_card_poster_dims(width: u32, height: u32) -> (u32, u32) { } else if width == height { let side = 32.min(width / 2).max(16); (side, side) + } else if crate::core::types::DisplayGeometry::is_landscape_4x3_family(width, height) + && height >= 64 + { + let pw = ((width * 40) / 100).max(36); + let ph = ((height * 86) / 100).max(48); + (pw, ph) } else if width >= 128 && height >= 64 { (48, 64) } else { @@ -3600,7 +3606,16 @@ impl MediaShowcaseRunner { &item.badge }; let badge_w = (badge_txt.chars().count() as i32) * 4 + 3; - let top_y = if h >= 64 { 3 } else { 1 }; + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); + let s_4x3 = if is_4x3 { (h / 96).max(1) } else { 1 }; + let top_y = if is_4x3 { + (h * 10) / 100 + } else if h >= 64 { + 3 + } else { + 1 + }; fill_round_rect(matrix, text_min_x, top_y, badge_w, 7, 1, item.badge_rgb); draw_tiny_text( matrix, @@ -3624,7 +3639,53 @@ impl MediaShowcaseRunner { (255, 215, 0), ); - if h >= 64 { + if is_4x3 && h >= 64 { + let title_y = (h * 28) / 100; + let sub_y = (h * 46) / 100; + let div_y = (h * 60) / 100; + let syn_y = (h * 72) / 100; + draw_scrolling_text( + matrix, + &item.title, + text_min_x, + w - 2, + title_y, + s_4x3, + (255, 255, 255), + phase_ms, + false, + ); + draw_tiny_text( + matrix, + &item.subtitle, + text_min_x, + sub_y, + text_min_x, + w - 2, + (180, 200, 220), + ); + draw_fast_hline( + matrix, + text_min_x, + div_y, + w - text_min_x - 2, + ( + item.badge_rgb.0 / 3, + item.badge_rgb.1 / 3, + item.badge_rgb.2 / 3, + ), + ); + draw_single_pass_synopsis( + matrix, + bottom_text, + text_min_x, + w - 2, + syn_y, + (190, 225, 255), + phase_ms, + speed_px, + ); + } else if h >= 64 { draw_scrolling_text( matrix, &item.title, diff --git a/src/engines/renderers/weather_page.rs b/src/engines/renderers/weather_page.rs index 6c245708..0e4ad09e 100644 --- a/src/engines/renderers/weather_page.rs +++ b/src/engines/renderers/weather_page.rs @@ -54,7 +54,98 @@ pub fn draw_weather_page( color_high }; - if mw >= 256 && mh >= 64 { + if crate::core::types::DisplayGeometry::is_landscape_4x3_family(mw, mh) { + // --- 4:3 CRT Aspect Ratio (e.g. 64x48, 96x72, 128x96, 192x144, 256x192, 384x288) --- + let s = (mh as i32 / 96).max(1); + let margin = (6 * s).min((mw as i32 / 14).max(3)); + let left_edge = base_x as i32 + margin + offset_x; + let right_edge = base_x as i32 + mw as i32 - margin + offset_x; + let full_w = (right_edge - left_edge).max(16); + + // 1. Top Centered Day / NOW Header + let hdr_scale = if mh >= 80 { 2 * s } else { s }; + let hdr_raw = if slide.label_long.is_empty() { + slide.label.as_str() + } else { + slide.label_long.as_str() + }; + let (hdr_text, hdr_sz) = if glcd_w(hdr_raw, hdr_scale) <= full_w { + (hdr_raw, hdr_scale) + } else if hdr_scale > s && glcd_w(hdr_raw, s) <= full_w { + (hdr_raw, s) + } else if glcd_w(&slide.label, hdr_scale) <= full_w { + (slide.label.as_str(), hdr_scale) + } else { + (slide.label.as_str(), s) + }; + let hdr_y = ((mh as i32 * 8) / 100).max(2) + offset_y; + + // 2. Middle Hero Band: Weather Icon on left + Stacked Temperatures on right + let icon_scale = if mw >= 112 && mh >= 80 { 2 * s } else { s }; + let icon_px = 24 * icon_scale; + let mid_cy = (mh as i32 * 50) / 100 + offset_y; + let icon_x = left_edge; + let icon_y = mid_cy - icon_px / 2; + draw_icon_scaled(img, &slide.icon, icon_x, icon_y, icon_scale); + + let temp_min_x = icon_x + icon_px + (4 * s).max(3); + let avail_temp_w = (right_edge - temp_min_x).max(12); + let row1 = slide.temp_min.as_str(); + let pref_t_scale = if mh >= 80 { 2 * s } else { s }; + let row2_big = now_row2(slide, right_edge, temp_min_x, pref_t_scale); + let t_scale = if glcd_w(row1, pref_t_scale) <= avail_temp_w + && (slide.is_now || glcd_w(&row2_big, pref_t_scale) <= avail_temp_w) + { + pref_t_scale + } else { + s + }; + let row2 = now_row2(slide, right_edge, temp_min_x, t_scale); + let glyph_h = 7 * t_scale; + let row_gap = (6 * s).max(4); + let t_top_y = mid_cy - glyph_h - row_gap / 2; + let t_bot_y = mid_cy + row_gap / 2; + + let mut canvas = SlideCanvas::new(img, base_x as i32, mw as i32); + let hdr_x = base_x as i32 + ((mw as i32 - glcd_w(hdr_text, hdr_sz)) / 2).max(1) + offset_x; + canvas.text(hdr_text, hdr_x, hdr_y, hdr_sz, color_label); + + canvas.text( + row1, + (right_edge - glcd_w(row1, t_scale)).max(temp_min_x), + t_top_y, + t_scale, + color_morning, + ); + canvas.text( + &row2, + (right_edge - glcd_w(&row2, t_scale)).max(temp_min_x), + t_bot_y, + t_scale, + color_afternoon, + ); + + // 3. Bottom Centered Condition Footer + let cond_raw = if slide.condition_long.is_empty() { + slide.condition.as_str() + } else { + slide.condition_long.as_str() + }; + if !cond_raw.is_empty() { + let cond_pref = if mh >= 160 { 2 * s / 2 + 1 } else { s }; + let (cond_txt, cond_sz) = if glcd_w(cond_raw, cond_pref) <= full_w { + (cond_raw, cond_pref) + } else if glcd_w(cond_raw, s) <= full_w { + (cond_raw, s) + } else { + (slide.condition.as_str(), s) + }; + let cond_y = ((mh as i32 * 83) / 100).min(mh as i32 - 8 * cond_sz - 1) + offset_y; + let cond_x = + base_x as i32 + ((mw as i32 - glcd_w(cond_txt, cond_sz)) / 2).max(1) + offset_x; + canvas.text(cond_txt, cond_x, cond_y, cond_sz, color_desc); + } + } else if mw >= 256 && mh >= 64 { // --- 256x64: three columns, as the ESP32 `drawForecast` --- let margin = 8; let icon_x = base_x as i32 + margin + offset_x; diff --git a/src/engines/spotify.rs b/src/engines/spotify.rs index 30d666bd..b00c77fb 100644 --- a/src/engines/spotify.rs +++ b/src/engines/spotify.rs @@ -215,7 +215,16 @@ impl Engine for SpotifyEngine { }; if self.show_album_art { - let target_size = if ctx.surface.height() >= 64 { 52 } else { 24 }; + let sw = ctx.surface.width(); + let sh = ctx.surface.height(); + let target_size = + if crate::core::types::DisplayGeometry::is_landscape_4x3_family(sw, sh) { + ((sh * 58) / 100).clamp(28, (sw * 44) / 100) + } else if sh >= 64 { + 52 + } else { + 24 + }; self.target_art_size.store(target_size, Ordering::Relaxed); if let Ok(guard) = self.shared_cover.try_lock() { self.cached_cover = guard.clone(); @@ -484,6 +493,11 @@ impl Engine for SpotifyEngine { let clip_max_x = w - right_reserved; let avail_w = (clip_max_x - clip_min_x).max(16); + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); + let s_4x3 = if is_4x3 { (h / 96).max(1) } else { 1 }; + let text_scale = s_4x3 as f32; + // 3. Continuous Circular (Seamless Looping) Marquee let render_marquee = |matrix: &mut dyn IDrawingSurface, text: &str, @@ -491,13 +505,13 @@ impl Engine for SpotifyEngine { y: i32, color: (u8, u8, u8), offset: i32| { - let (_, text_w, _) = font.get_pixel_map(text, 1.0); + let (_, text_w, _) = font.get_pixel_map(text, text_scale); if text_w <= avail_w { BaseRenderer::draw_text_clipped( matrix, text, font, - 1.0, + text_scale, clip_min_x, y, clip_min_x, @@ -506,17 +520,16 @@ impl Engine for SpotifyEngine { (0, 0, 0), ); } else { - let gap = 20; // 20px seamless spacing between loop repetitions + let gap = 20 * s_4x3; let total_w = text_w + gap; let dx = offset.rem_euclid(total_w); - // Draw primary text instance let draw_x1 = clip_min_x - dx; BaseRenderer::draw_text_clipped( matrix, text, font, - 1.0, + text_scale, draw_x1, y, clip_min_x, @@ -525,14 +538,13 @@ impl Engine for SpotifyEngine { (0, 0, 0), ); - // Draw trailing secondary instance for circular looping let draw_x2 = draw_x1 + total_w; if draw_x2 < clip_max_x { BaseRenderer::draw_text_clipped( matrix, text, font, - 1.0, + text_scale, draw_x2, y, clip_min_x, @@ -544,8 +556,20 @@ impl Engine for SpotifyEngine { } }; - let y_title = if h >= 64 { 8 } else { 3 }; - let y_artist = if h >= 64 { 22 } else { 13 }; + let y_title = if is_4x3 { + (h * 18) / 100 + } else if h >= 64 { + 8 + } else { + 3 + }; + let y_artist = if is_4x3 { + (h * 38) / 100 + } else if h >= 64 { + 22 + } else { + 13 + }; // Draw Title render_marquee( @@ -575,9 +599,26 @@ impl Engine for SpotifyEngine { self.marquee_offset / 2, ); + if is_4x3 && !status.album.is_empty() && !status.artist.is_empty() { + render_marquee( + ctx.surface, + &status.album, + &font, + (h * 56) / 100, + (150, 165, 180), + self.marquee_offset / 3, + ); + } + // 4. Draw Beat Visualizer on the right with dynamic colors if self.show_visualizer && status.is_playing { - let eq_base_y = if h >= 64 { 44 } else { 21 }; + let eq_base_y = if is_4x3 { + (h * 84) / 100 + } else if h >= 64 { + 44 + } else { + 21 + }; if is_compact_screen && has_art { // 3 compact bars (2px wide each, 1px gap) @@ -605,29 +646,29 @@ impl Engine for SpotifyEngine { } } } else { - // 4 wide bars (2px wide + 1px spacing) - let eq_x = w - 13; + // 4 wide bars (scaled by s_4x3 on 4:3 multiples) + let eq_x = w - 13 * s_4x3; let bar_heights = [ - ((self.anim_frame.wrapping_mul(4)) % 8 + 2) as i32, - ((self.anim_frame.wrapping_mul(6)) % 11 + 3) as i32, - ((self.anim_frame.wrapping_mul(3)) % 9 + 2) as i32, - ((self.anim_frame.wrapping_mul(5)) % 7 + 2) as i32, + ((self.anim_frame.wrapping_mul(4)) % 8 + 2) as i32 * s_4x3, + ((self.anim_frame.wrapping_mul(6)) % 11 + 3) as i32 * s_4x3, + ((self.anim_frame.wrapping_mul(3)) % 9 + 2) as i32 * s_4x3, + ((self.anim_frame.wrapping_mul(5)) % 7 + 2) as i32 * s_4x3, ]; for (i, &bh) in bar_heights.iter().enumerate() { - let bx = eq_x + (i as i32 * 3); + let bx = eq_x + (i as i32 * 3 * s_4x3); for by in 0..bh { let py = eq_base_y - by; if py >= 0 { - let color = if by > 7 { + let color = if by > 7 * s_4x3 { (255, 60, 60) - } else if by > 4 { + } else if by > 4 * s_4x3 { (255, 220, 0) } else { (30, 215, 96) }; - ctx.surface.set_pixel(bx, py, color.0, color.1, color.2); - ctx.surface.set_pixel(bx + 1, py, color.0, color.1, color.2); + ctx.surface + .fill_rect(bx, py, 2 * s_4x3, 1, color.0, color.1, color.2); } } } @@ -635,12 +676,12 @@ impl Engine for SpotifyEngine { } else if self.show_volume && status.volume_percent > 0 { // 5. Draw Volume (Top-Right, right-aligned) let vol_str = format!("{}%", status.volume_percent); - let v_x = w - (vol_str.len() as i32 * 6) - 1; + let v_x = w - (vol_str.len() as i32 * 6 * s_4x3) - 1; BaseRenderer::draw_text_at( ctx.surface, &vol_str, &font, - 1.0, + text_scale, v_x, y_title, (180, 180, 180), @@ -648,20 +689,20 @@ impl Engine for SpotifyEngine { ); } - // 6. Draw Progress Bar (Bottom 2 pixels) + // 6. Draw Progress Bar (Bottom 2 * s_4x3 pixels) if self.show_progress && status.duration_ms > 0 { let progress = (status.progress_ms as f32 / status.duration_ms as f32).clamp(0.0, 1.0); let bar_w = ((w - 2) as f32 * progress) as i32; - - // Background line - for x in 1..w - 1 { - ctx.surface.set_pixel(x, h - 2, 30, 35, 30); - ctx.surface.set_pixel(x, h - 1, 18, 22, 18); - } - // Active progress fill (Spotify Green) - for x in 1..1 + bar_w { - ctx.surface.set_pixel(x, h - 2, 30, 215, 96); - ctx.surface.set_pixel(x, h - 1, 20, 160, 70); + let p_h = 2 * s_4x3; + ctx.surface + .fill_rect(1, h - p_h, w - 2, p_h / 2, 30, 35, 30); + ctx.surface + .fill_rect(1, h - p_h / 2, w - 2, p_h / 2, 18, 22, 18); + if bar_w > 0 { + ctx.surface + .fill_rect(1, h - p_h, bar_w, p_h / 2, 30, 215, 96); + ctx.surface + .fill_rect(1, h - p_h / 2, bar_w, p_h / 2, 20, 160, 70); } } } diff --git a/src/engines/stock.rs b/src/engines/stock.rs index 2f758f90..85ba1157 100644 --- a/src/engines/stock.rs +++ b/src/engines/stock.rs @@ -986,6 +986,124 @@ impl StockEngine { let m_h = matrix.height() as i32; let tf_label = self.chart_timeframe.label(); + if crate::core::types::DisplayGeometry::is_landscape_4x3_family(m_w as u32, m_h as u32) { + let s = (m_h / 96).max(1); + let pad = (4 * s).max(3); + let div_y = (m_h * 45) / 100; + let icon_sz = if m_h >= 72 { 16 * s } else { 12 }; + draw_stock_icon(matrix, symbol, pad, pad, icon_sz, cached_img); + + let badge_text = if success && price > 0.0 { + format!("{} {}", if change >= 0.0 { "^" } else { "v" }, pct_str) + } else { + pct_str.to_string() + }; + let badge_w = (badge_text.len() as i32 * 6 + 6) * s; + let badge_h = 10 * s; + let badge_x = (m_w - pad - badge_w).max(pad + icon_sz + 8); + let (pill_bg, pill_border) = if !success || price <= 0.0 { + ((28, 28, 28), (70, 70, 70)) + } else if change >= 0.0 { + ((0, 38, 14), (0, 130, 50)) + } else { + ((42, 10, 10), (150, 40, 40)) + }; + fill_round_rect(matrix, badge_x, pad, badge_w, badge_h, 2 * s, pill_bg); + draw_round_rect(matrix, badge_x, pad, badge_w, badge_h, 2 * s, pill_border); + draw_glcd_text_scaled( + matrix, + &badge_text, + badge_x + 3 * s, + pad + 2 * s, + s, + badge_color, + ); + + let x_sym = pad + icon_sz + 4 * s; + draw_scrolling_text( + matrix, + symbol, + x_sym, + (badge_x - 3 * s).max(x_sym + 12), + pad + s, + s, + (255, 255, 255), + elapsed_ms, + false, + ); + + let tf_w = tf_label.len() as i32 * 6 * s; + let price_max_x = (m_w - pad - tf_w - 4 * s).max(pad + 24); + let price_y = if m_h >= 72 { + pad + icon_sz + 4 * s + } else { + div_y - 9 + }; + let big_scale = 2 * s; + if m_h >= 84 && price_str.len() as i32 * 6 * big_scale <= (price_max_x - pad) { + draw_glcd_text_scaled( + matrix, + price_str, + pad, + (div_y - 15 * s).max(pad + icon_sz + 2 * s), + big_scale, + (0, 220, 255), + ); + } else { + draw_scrolling_text( + matrix, + price_str, + pad, + price_max_x, + price_y, + s, + (0, 220, 255), + elapsed_ms, + false, + ); + } + draw_glcd_text_scaled( + matrix, + tf_label, + m_w - pad - tf_w, + (div_y - 9 * s).max(price_y), + s, + (140, 140, 140), + ); + + draw_fast_hline(matrix, pad, div_y, (m_w - 2 * pad).max(4), (50, 50, 60)); + + let spark_x = pad; + let spark_y = div_y + 3 * s; + let spark_w = (m_w - 2 * pad).max(8) as u32; + let spark_h = (m_h - spark_y - pad).max(8) as u32; + if let Some(hist) = history_opt { + if hist.points.len() > 1 { + let is_up = + hist.points.last().unwrap_or(&0.0) >= hist.points.first().unwrap_or(&0.0); + let line_color = if is_up { (0, 255, 120) } else { (255, 60, 60) }; + let fill_color = if is_up { + Some((0, 35, 12)) + } else { + Some((40, 12, 12)) + }; + draw_sparkline( + matrix, hist, spark_x, spark_y, spark_w, spark_h, line_color, fill_color, + ); + return; + } + } + draw_glcd_text_scaled( + matrix, + crate::core::i18n::t(lang, "loading_chart"), + spark_x + 2 * s, + spark_y + (spark_h as i32 / 2) - 4 * s, + s, + (120, 120, 120), + ); + return; + } + draw_stock_icon(matrix, symbol, 4, 4, 16, cached_img); let div_x = if m_w >= 320 { @@ -1955,5 +2073,51 @@ mod tests { badge_lit > 40, "expected right pill badge lit on 192x32 quote" ); + + for &(w43, h43) in &[(128u32, 96u32), (256, 192)] { + let mut s43 = MockSurface::new(w43, h43); + engine.render_unified_wide( + &mut s43, + "AAPL", + "$229.40", + "+1.85%", + (0, 255, 120), + true, + 229.40, + 1.85, + None, + Some(&hist), + 0, + "en", + ); + let mut top_lit = 0usize; + let mut bot_left_lit = 0usize; + let mut bot_right_lit = 0usize; + let split_y = (h43 * 45) / 100; + for y in 0..split_y { + for x in 0..w43 { + let p = s43.canvas.get_pixel(x, y); + if p[0] > 0 || p[1] > 0 || p[2] > 0 { + top_lit += 1; + } + } + } + for y in (split_y + 4)..h43 { + for x in 0..(w43 / 2) { + let p = s43.canvas.get_pixel(x, y); + if p[0] > 0 || p[1] > 0 || p[2] > 0 { + bot_left_lit += 1; + } + } + for x in (w43 / 2)..w43 { + let p = s43.canvas.get_pixel(x, y); + if p[0] > 0 || p[1] > 0 || p[2] > 0 { + bot_right_lit += 1; + } + } + } + assert!(top_lit > 80); + assert!(bot_left_lit > 50 && bot_right_lit > 50); + } } } diff --git a/src/engines/sysinfo.rs b/src/engines/sysinfo.rs index bb9d3b18..36677a85 100644 --- a/src/engines/sysinfo.rs +++ b/src/engines/sysinfo.rs @@ -144,13 +144,7 @@ impl SysInfoEngine { } } - fn draw_bitmap_char( - matrix: &mut dyn IDrawingSurface, - c: char, - x: i32, - y: i32, - color: (u8, u8, u8), - ) -> i32 { + fn bitmap_char_cols(c: char) -> [u8; 5] { let font_data: [(char, [u8; 5]); 36] = [ ('0', [0x7C, 0x82, 0x82, 0x82, 0x7C]), ('1', [0x00, 0x42, 0xFE, 0x02, 0x00]), @@ -190,12 +184,21 @@ impl SysInfoEngine { ('O', [0x7C, 0x82, 0x82, 0x82, 0x7C]), ]; - let cols = font_data + font_data .iter() .find(|(ch, _)| *ch == c) .map(|(_, arr)| *arr) - .unwrap_or([0x00, 0x00, 0x00, 0x00, 0x00]); + .unwrap_or([0x00, 0x00, 0x00, 0x00, 0x00]) + } + fn draw_bitmap_char( + matrix: &mut dyn IDrawingSurface, + c: char, + x: i32, + y: i32, + color: (u8, u8, u8), + ) -> i32 { + let cols = Self::bitmap_char_cols(c); for (col_idx, col_byte) in cols.iter().enumerate() { for row_idx in 0..8 { if (col_byte & (1 << (7 - row_idx))) != 0 { @@ -223,6 +226,40 @@ impl SysInfoEngine { x += Self::draw_bitmap_char(matrix, c, x, y, color); } } + + fn draw_bitmap_string_scaled( + matrix: &mut dyn IDrawingSurface, + text: &str, + mut x: i32, + y: i32, + scale: i32, + color: (u8, u8, u8), + ) { + let s = scale.max(1); + if s == 1 { + Self::draw_bitmap_string(matrix, text, x, y, color); + return; + } + for c in text.chars() { + let cols = Self::bitmap_char_cols(c); + for (col_idx, col_byte) in cols.iter().enumerate() { + for row_idx in 0..8 { + if (col_byte & (1 << (7 - row_idx))) != 0 { + matrix.fill_rect( + x + col_idx as i32 * s, + y + row_idx as i32 * s, + s, + s, + color.0, + color.1, + color.2, + ); + } + } + } + x += 6 * s; + } + } } impl Engine for SysInfoEngine { @@ -380,6 +417,243 @@ impl Engine for SysInfoEngine { return; } + let is_4x3 = + crate::core::types::DisplayGeometry::is_landscape_4x3_family(w as u32, h as u32); + if is_4x3 { + let s = (h / 96).max(1); + let pad_x = (4 * s).max(3); + match self.theme { + 1 => { + // Cyberpunk Neon 4:3 HUD: full-frame corner brackets, horizontal split & twin meters + let cyan = (0, 240, 255); + let purple = (200, 50, 255); + let brk_x = 8 * s; + let brk_y = 6 * s; + for t in 0..s { + matrix.fill_rect(0, t, brk_x, 1, cyan.0, cyan.1, cyan.2); + matrix.fill_rect(w - brk_x, t, brk_x, 1, cyan.0, cyan.1, cyan.2); + matrix.fill_rect(0, h - 1 - t, brk_x, 1, purple.0, purple.1, purple.2); + matrix.fill_rect( + w - brk_x, + h - 1 - t, + brk_x, + 1, + purple.0, + purple.1, + purple.2, + ); + matrix.fill_rect(t, 0, 1, brk_y, cyan.0, cyan.1, cyan.2); + matrix.fill_rect(w - 1 - t, 0, 1, brk_y, cyan.0, cyan.1, cyan.2); + matrix.fill_rect(t, h - brk_y, 1, brk_y, purple.0, purple.1, purple.2); + matrix.fill_rect( + w - 1 - t, + h - brk_y, + 1, + brk_y, + purple.0, + purple.1, + purple.2, + ); + } + let meter_zone = 10 * s; + let content_w = (w - meter_zone - pad_x).max(32); + let mid_y = h / 2 + self.offset_y; + matrix.fill_rect(pad_x, mid_y, content_w - pad_x, s, 35, 45, 70); + + let x1 = pad_x + self.offset_x; + let x2 = pad_x + content_w / 2 + self.offset_x; + let y_top = h / 4 - 9 * s + self.offset_y; + let y_bot = (3 * h) / 4 - 9 * s + self.offset_y; + let bar_w = (content_w / 2 - 8 * s).max(12); + let bar_h = (4 * s).max(3); + + let cpu_txt = format!("CPU {:2.0}%", cpu); + Self::draw_bitmap_string_scaled(matrix, &cpu_txt, x1, y_top, s, cyan); + Self::draw_gauge_bar(matrix, x1, y_top + 10 * s, bar_w, bar_h, cpu, cpu_col); + + let ram_txt = format!("RAM {:2.0}%", ram); + Self::draw_bitmap_string_scaled(matrix, &ram_txt, x1, y_bot, s, purple); + Self::draw_gauge_bar(matrix, x1, y_bot + 10 * s, bar_w, bar_h, ram, ram_col); + + let tmp_txt = format!("TMP {}", t_str); + Self::draw_bitmap_string_scaled(matrix, &tmp_txt, x2, y_top, s, (255, 140, 0)); + let temp_pct = ((temp - 20.0) * (100.0 / 60.0)).clamp(0.0, 100.0); + Self::draw_gauge_bar( + matrix, + x2, + y_top + 10 * s, + bar_w, + bar_h, + temp_pct, + temp_col, + ); + + Self::draw_bitmap_string_scaled(matrix, "UPT", x2, y_bot, s, cyan); + Self::draw_bitmap_string_scaled( + matrix, + &format!("{:02}:{:02}", hrs, mins), + x2, + y_bot + 10 * s, + s, + (0, 220, 200), + ); + + // Twin vertical CPU & RAM level meters on right + let vbar_h = (h - 10 * s).max(8); + let cpu_fh = ((cpu / 100.0) * vbar_h as f32) as i32; + let ram_fh = ((ram / 100.0) * vbar_h as f32) as i32; + if cpu_fh > 0 { + matrix.fill_rect( + w - 8 * s, + h - 5 * s - cpu_fh, + 2 * s, + cpu_fh, + cpu_col.0, + cpu_col.1, + cpu_col.2, + ); + } + if ram_fh > 0 { + matrix.fill_rect( + w - 4 * s, + h - 5 * s - ram_fh, + 2 * s, + ram_fh, + ram_col.0, + ram_col.1, + ram_col.2, + ); + } + } + 2 => { + // Compact Grid 4:3: 2x2 centered quadrants with scaled labels & values + let mid_x = w / 2; + let mid_y = h / 2; + matrix.fill_rect(mid_x, 2 * s, s, h - 4 * s, 40, 45, 60); + matrix.fill_rect(2 * s, mid_y, w - 4 * s, s, 40, 45, 60); + + let q_top_lbl = h / 4 - 10 * s + self.offset_y; + let q_top_val = h / 4 + 2 * s + self.offset_y; + let q_bot_lbl = (3 * h) / 4 - 10 * s + self.offset_y; + let q_bot_val = (3 * h) / 4 + 2 * s + self.offset_y; + let lx = pad_x + self.offset_x; + let rx = mid_x + pad_x + self.offset_x; + + Self::draw_bitmap_string_scaled(matrix, "CPU", lx, q_top_lbl, s, label_col); + Self::draw_bitmap_string_scaled( + matrix, + &format!("{:.0}%", cpu), + lx, + q_top_val, + s, + cpu_col, + ); + + Self::draw_bitmap_string_scaled(matrix, "RAM", rx, q_top_lbl, s, label_col); + Self::draw_bitmap_string_scaled( + matrix, + &format!("{:.0}%", ram), + rx, + q_top_val, + s, + ram_col, + ); + + Self::draw_bitmap_string_scaled(matrix, "TMP", lx, q_bot_lbl, s, label_col); + Self::draw_bitmap_string_scaled(matrix, &t_str, lx, q_bot_val, s, temp_col); + + Self::draw_bitmap_string_scaled(matrix, "UPT", rx, q_bot_lbl, s, label_col); + Self::draw_bitmap_string_scaled( + matrix, + &up_str, + rx, + q_bot_val, + s, + (0, 190, 255), + ); + } + _ => { + // Theme 0 (Default HUD Gauges) 4:3: 4 full-width stacked telemetry bands + let step_y = h / 4; + let bar_h = (step_y / 4).clamp(4, 12); + let text_h = 8 * s; + let block_h = text_h + 2 * s + bar_h; + let top_pad = ((step_y - block_h) / 2).max(1); + let bar_w = (w - 2 * pad_x).max(16); + let lx = pad_x + self.offset_x; + + if self.show_cpu { + let ry = top_pad + self.offset_y; + let val_s = format!("{:2.0}%", cpu); + let vx = w - pad_x - val_s.len() as i32 * 6 * s + self.offset_x; + Self::draw_bitmap_string_scaled(matrix, "CPU", lx, ry, s, label_col); + Self::draw_bitmap_string_scaled(matrix, &val_s, vx, ry, s, cpu_col); + Self::draw_gauge_bar( + matrix, + lx, + ry + text_h + 2 * s, + bar_w, + bar_h, + cpu, + cpu_col, + ); + } + + if self.show_ram { + let ry = step_y + top_pad + self.offset_y; + let val_s = format!("{:2.0}%", ram); + let vx = w - pad_x - val_s.len() as i32 * 6 * s + self.offset_x; + Self::draw_bitmap_string_scaled(matrix, "RAM", lx, ry, s, label_col); + Self::draw_bitmap_string_scaled(matrix, &val_s, vx, ry, s, ram_col); + Self::draw_gauge_bar( + matrix, + lx, + ry + text_h + 2 * s, + bar_w, + bar_h, + ram, + ram_col, + ); + } + + if self.show_temp { + let ry = step_y * 2 + top_pad + self.offset_y; + let vx = w - pad_x - t_str.len() as i32 * 6 * s + self.offset_x; + let temp_pct = ((temp - 20.0) * (100.0 / 60.0)).clamp(0.0, 100.0); + Self::draw_bitmap_string_scaled(matrix, "TMP", lx, ry, s, label_col); + Self::draw_bitmap_string_scaled(matrix, &t_str, vx, ry, s, temp_col); + Self::draw_gauge_bar( + matrix, + lx, + ry + text_h + 2 * s, + bar_w, + bar_h, + temp_pct, + temp_col, + ); + } + + if self.show_uptime { + let ry = step_y * 3 + top_pad + self.offset_y; + let vx = w - pad_x - up_str.len() as i32 * 6 * s + self.offset_x; + let up_pct = (((uptime % 3600) as f32 / 3600.0) * 100.0).clamp(8.0, 100.0); + Self::draw_bitmap_string_scaled(matrix, "UPT", lx, ry, s, label_col); + Self::draw_bitmap_string_scaled(matrix, &up_str, vx, ry, s, (0, 190, 255)); + Self::draw_gauge_bar( + matrix, + lx, + ry + text_h + 2 * s, + bar_w, + bar_h, + up_pct, + (0, 165, 230), + ); + } + } + } + return; + } + match self.theme { 1 => { // Cyberpunk Neon theme diff --git a/tests/test_base_resolutions_zero_regression.rs b/tests/test_base_resolutions_zero_regression.rs index b3f70edf..21ba060b 100644 --- a/tests/test_base_resolutions_zero_regression.rs +++ b/tests/test_base_resolutions_zero_regression.rs @@ -254,3 +254,143 @@ fn test_custom_192x32_and_ultrawide_clocks_balanced_coverage() { TetrisClock::new(false).render(&mut s_tet, "14:37", &font, 2); } } + +fn count_lit_in_y_range(surface: &MockSurface, y0: u32, y1: u32) -> usize { + let mut lit = 0usize; + for y in y0..y1.min(surface.canvas.height()) { + for x in 0..surface.canvas.width() { + let p = surface.canvas.get_pixel(x, y); + if p[0] > 0 || p[1] > 0 || p[2] > 0 { + lit += 1; + } + } + } + lit +} + +#[test] +fn test_4x3_aspect_ratio_and_multiples_coverage() { + use arcadematrix::core::types::DisplayGeometry; + + // 1. Exact isolation of 4:3 landscape family vs all standard widescreens, squares, and TATE + for &(w, h) in &[ + (64u32, 48u32), + (96, 72), + (128, 96), + (192, 144), + (256, 192), + (384, 288), + (512, 384), + ] { + assert!( + DisplayGeometry::is_landscape_4x3_family(w, h), + "{}x{} must be classified as 4:3 family", + w, + h + ); + } + for &(w, h) in &[ + (64u32, 32u32), + (128, 32), + (192, 32), + (256, 32), + (128, 64), + (192, 64), + (256, 64), + (384, 64), + (64, 64), + (128, 128), + (32, 64), + (64, 128), + (64, 256), + (96, 128), + ] { + assert!( + !DisplayGeometry::is_landscape_4x3_family(w, h), + "{}x{} must NOT be classified as 4:3 family", + w, + h + ); + } + + // 2. All 4 wide clock themes (32, 33, 37, 41) unlocked on 96x72, 128x96, 192x144, 256x192, 384x288 + let renderer = BaseRenderer::new(); + let font = renderer.font(); + for &(w, h) in &[ + (96u32, 72u32), + (128, 96), + (192, 144), + (256, 192), + (384, 288), + ] { + for id in [32, 33, 37, 41] { + assert!( + is_theme_compatible(id, w, h), + "theme {} must be compatible on {}x{}", + id, + w, + h + ); + } + + // Binary, Mario, Castle, MegaMan, Sonic, MetalSlug, Pokedex, WorldMap, Words populate top, middle, and bottom thirds + let mut s_bin = MockSurface::new(w, h); + BinaryClock::new().render(&mut s_bin, 23, 59, 58, &font, 1); + assert!(count_lit_in_y_range(&s_bin, h / 6, (5 * h) / 6) > 30); + + let mut s_mario = MockSurface::new(w, h); + let mut mario = MarioClock::new(); + mario.draw(&mut s_mario, 14, 37, 0.016); + assert!(count_lit_in_y_range(&s_mario, 0, h / 3) > 40); + assert!(count_lit_in_y_range(&s_mario, h / 3, (2 * h) / 3) > 40); + assert!(count_lit_in_y_range(&s_mario, (2 * h) / 3, h) > 40); + + let mut s_castle = MockSurface::new(w, h); + let mut castle = CastleClock::new(); + castle.draw(&mut s_castle, 14, 37, 45, 0.016); + for _ in 0..25 { + s_castle.canvas.fill(0); + castle.draw(&mut s_castle, 14, 38, 0, 0.03); + } + assert!(count_lit_in_y_range(&s_castle, h / 4, (3 * h) / 4) > 40); + assert!(count_lit_in_y_range(&s_castle, (2 * h) / 3, h) > 40); + + let mut s_sonic = MockSurface::new(w, h); + let mut sonic = SonicClock::new(); + sonic.draw(&mut s_sonic, 14, 37, 45, 0.016); + for _ in 0..20 { + s_sonic.canvas.fill(0); + sonic.draw(&mut s_sonic, 14, 38, 0, 0.03); + } + assert!(count_lit_in_y_range(&s_sonic, 0, h / 2) > 40); + assert!(count_lit_in_y_range(&s_sonic, h / 2, h) > 40); + + let mut s_mm = MockSurface::new(w, h); + MegamanClock::new().draw(&mut s_mm, 14, 37, 45, 0.016); + assert!(count_lit_in_y_range(&s_mm, h / 5, (3 * h) / 5) > 40); + assert!(count_lit_in_y_range(&s_mm, (3 * h) / 5, h) > 40); + + let mut s_ms = MockSurface::new(w, h); + let mut ms = MetalSlugClock::new(); + ms.draw(&mut s_ms, 14, 37, 45, 0.033); + assert!(count_lit_in_y_range(&s_ms, 0, h / 3) > 40); + assert!(count_lit_in_y_range(&s_ms, (2 * h) / 3, h) > 40); + + let mut s_pdx = MockSurface::new(w, h); + PokedexClock::new().render(&mut s_pdx, 14, 37, 45, &font, 1); + assert!(count_lit_in_x_range(&s_pdx, 0, w / 4) > 40); + assert!(count_lit_in_x_range(&s_pdx, (3 * w) / 4, w) > 40); + assert!(count_lit_in_y_range(&s_pdx, 0, h / 4) > 40); + assert!(count_lit_in_y_range(&s_pdx, (3 * h) / 4, h) > 40); + + let mut s_wm = MockSurface::new(w, h); + WorldMapClock::new().render(&mut s_wm, 14, 37, &font, 1); + assert!(count_lit_in_y_range(&s_wm, 0, h / 3) > 30); + assert!(count_lit_in_y_range(&s_wm, (2 * h) / 3, h) > 30); + + let mut s_words = MockSurface::new(w, h); + WordsClock::new().render(&mut s_words, 14, 35, &font, 1, "fr"); + assert!(count_lit_in_y_range(&s_words, 0, h / 2) > 20); + assert!(count_lit_in_y_range(&s_words, h / 2, h) > 20); + } +} diff --git a/tests/test_weather_page.rs b/tests/test_weather_page.rs index cc84f93c..c259988c 100644 --- a/tests/test_weather_page.rs +++ b/tests/test_weather_page.rs @@ -94,3 +94,25 @@ fn now_page_drops_wind_direction_when_too_wide() { let (lx0, _, lx1, _) = bbox(&img, LABEL).unwrap(); assert!(lx0 == 32 && lx1 < wx0); } + +#[test] +fn weather_4x3_crt_multiples_vertical_distribution() { + for &(w, h) in &[ + (96u32, 72u32), + (128, 96), + (192, 144), + (256, 192), + (384, 288), + ] { + let img = render(&day("14°C", "24°C", "Pt cloudy", "Partly cloudy"), w, h); + // Header label in top third, temperatures in middle third, condition description in bottom third + let (_, lab_y0, _, lab_y1) = bbox(&img, LABEL).unwrap(); + assert!(lab_y0 < h / 4 && lab_y1 < h / 3); + let (_, low_y0, _, _) = bbox(&img, LOW).unwrap(); + let (_, high_y0, _, high_y1) = bbox(&img, HIGH).unwrap(); + assert!(low_y0 >= h / 4 && high_y1 <= (3 * h) / 4); + assert!(low_y0 < high_y0); + let (_, desc_y0, _, desc_y1) = bbox(&img, DESC).unwrap(); + assert!(desc_y0 >= (2 * h) / 3 && desc_y1 < h); + } +} From 8f32995b091ecf02930cee1c59c213a9f591b73f Mon Sep 17 00:00:00 2001 From: red77290 <23342613+red77290@users.noreply.github.com> Date: Sat, 5 Dec 2026 13:35:17 +0000 Subject: [PATCH 2/3] fix(fighter): guard 4:3 ground line so tall sprites crop at legs instead of head --- src/engines/fighter.rs | 278 ++++++++++++++++++++++++++--------------- 1 file changed, 178 insertions(+), 100 deletions(-) diff --git a/src/engines/fighter.rs b/src/engines/fighter.rs index 20e0e7c7..2aca3039 100644 --- a/src/engines/fighter.rs +++ b/src/engines/fighter.rs @@ -173,12 +173,17 @@ pub struct FighterChar { pub name: String, pub meta: FighterIndexMeta, pub anims: HashMap, + pub is_32px: bool, } impl FighterChar { pub fn load_char>(dir: P, meta: FighterIndexMeta) -> Option { let dir = dir.as_ref(); let name = dir.file_name()?.to_str()?.to_string(); + let is_32px = dir + .parent() + .map(|p| p.to_string_lossy().contains("32")) + .unwrap_or(false); let max_frames = 40; let mut anims = HashMap::new(); @@ -271,7 +276,12 @@ impl FighterChar { try_load(action, &[&format!("{}.fgt", action)]); } - Some(Self { name, meta, anims }) + Some(Self { + name, + meta, + anims, + is_32px, + }) } pub fn compute_stand_bounds(&self) -> (i32, i32) { @@ -393,74 +403,92 @@ impl FighterEngine { } } + /// Computes `(scale, y1, y2)` for a fighter pair on `(matrix_width, matrix_height)`. + /// + /// - On `4:3` CRT panels (`is_landscape_4x3_family`), both fighters share a single ground + /// line `ground_y_screen = (matrix_height as i32 - 1).max(1 + tallest * scale)`: + /// - When the tallest standing sprite (`ground_y - head_y`) fits vertically inside the + /// panel, `ground_y_screen = matrix_height - 1` so both fighters stand firmly on the + /// bottom edge instead of floating in mid-air. + /// - When a tall sprite exceeds the panel's vertical resolution (e.g. Gouki `108px` on + /// `128x96`, or `fighters_64` on `96x72`), `ground_y_screen` drops below the bottom + /// edge (`1 + tallest * scale > matrix_height - 1`) so the tallest head stays pinned + /// at `y = 1` (never decapitated) and the overflow is cropped cleanly at the legs/feet. + /// - All non-`4:3` layouts (`128x32`, `256x64`, `192x32`, TATE, etc.) retain their exact + /// existing placement untouched. + pub(crate) fn compute_pair_placement( + matrix_width: u32, + matrix_height: u32, + is_32px: bool, + c1_meta: &FighterIndexMeta, + c2_meta: &FighterIndexMeta, + ) -> (i32, i32, i32) { + let is_tate = matrix_width < 48 || matrix_height > (matrix_width * 3) / 2; + let is_4x3 = crate::core::types::DisplayGeometry::is_landscape_4x3_family( + matrix_width, + matrix_height, + ); + let scale = if is_tate { + if matrix_width >= 96 && is_32px { + (matrix_width / 64) as i32 + } else { + 1 + } + } else if is_4x3 { + if is_32px { + (matrix_height / 32).min(matrix_width / 64) as i32 + } else { + (matrix_height / 64).min(matrix_width / 128) as i32 + } + } else if matrix_height >= 64 && is_32px { + (matrix_height / 32) as i32 + } else { + 1 + } + .max(1); + + let (y1, y2) = if is_tate { + let ground_y_screen = matrix_height as i32 - 1; + ( + ground_y_screen - (c1_meta.ground_y * scale), + ground_y_screen - (c2_meta.ground_y * scale), + ) + } else if is_4x3 { + let h1 = (c1_meta.ground_y - c1_meta.head_y).max(0); + let h2 = (c2_meta.ground_y - c2_meta.head_y).max(0); + let tallest = h1.max(h2); + let head_safe_ground_y = 1 + tallest * scale; + let ground_y_screen = (matrix_height as i32 - 1).max(head_safe_ground_y); + ( + ground_y_screen - (c1_meta.ground_y * scale), + ground_y_screen - (c2_meta.ground_y * scale), + ) + } else { + let y1 = (1 - c1_meta.head_y) * scale; + let ground_y_screen = (1 - c1_meta.head_y) + (c1_meta.ground_y * scale); + let y2 = ground_y_screen - (c2_meta.ground_y * scale); + (y1, y2) + }; + + (scale, y1, y2) + } + pub fn on_display_geometry_changed(&mut self, geometry: &crate::core::types::DisplayGeometry) { self.matrix_width = geometry.logical_width; self.matrix_height = geometry.logical_height; if self.active { - let is_tate = - self.matrix_width < 48 || self.matrix_height > (self.matrix_width * 3) / 2; - let is_4x3 = crate::core::types::DisplayGeometry::is_landscape_4x3_family( - self.matrix_width, - self.matrix_height, - ); - let (mut p1_scale, mut p1_ground_y, mut p1_head_y) = (1, 32, 0); - if let Some(ref mut p1) = self.p1 { - let is_32px = p1.character.meta.width <= 32; - let scale = if is_tate { - if self.matrix_width >= 96 && is_32px { - (self.matrix_width / 64) as i32 - } else { - 1 - } - } else if is_4x3 { - if is_32px { - (self.matrix_height / 32).min(self.matrix_width / 64) as i32 - } else { - (self.matrix_height / 64).min(self.matrix_width / 128) as i32 - } - } else if self.matrix_height >= 64 && is_32px { - (self.matrix_height / 32) as i32 - } else { - 1 - } - .max(1); + if let (Some(ref mut p1), Some(ref mut p2)) = (&mut self.p1, &mut self.p2) { + let (scale, y1, y2) = Self::compute_pair_placement( + self.matrix_width, + self.matrix_height, + p1.character.is_32px, + &p1.character.meta, + &p2.character.meta, + ); p1.scale = scale; - p1_scale = scale; - p1_ground_y = p1.character.meta.ground_y as i32; - p1_head_y = p1.character.meta.head_y as i32; - p1.y = if is_tate || is_4x3 { - (self.matrix_height as i32 - 1) - (p1_ground_y * scale) - } else { - (1 - p1_head_y) * scale - }; - } - if let Some(ref mut p2) = self.p2 { - let is_32px = p2.character.meta.width <= 32; - let scale = if is_tate { - if self.matrix_width >= 96 && is_32px { - (self.matrix_width / 64) as i32 - } else { - 1 - } - } else if is_4x3 { - if is_32px { - (self.matrix_height / 32).min(self.matrix_width / 64) as i32 - } else { - (self.matrix_height / 64).min(self.matrix_width / 128) as i32 - } - } else if self.matrix_height >= 64 && is_32px { - (self.matrix_height / 32) as i32 - } else { - 1 - } - .max(1); + p1.y = y1; p2.scale = scale; - p2.y = if is_tate || is_4x3 { - (self.matrix_height as i32 - 1) - (p2.character.meta.ground_y as i32 * scale) - } else { - let ground_y = (1 - p1_head_y) + (p1_ground_y * p1_scale); - ground_y - (p2.character.meta.ground_y as i32 * scale) - }; + p2.y = y2; } } } @@ -643,46 +671,13 @@ impl FighterEngine { let c2 = FighterChar::load_char(&char2_dir, meta2.clone()); if let (Some(c1), Some(c2)) = (c1, c2) { let is_32px = dir_path.to_string_lossy().contains("32"); - let is_4x3 = crate::core::types::DisplayGeometry::is_landscape_4x3_family( + let (scale, y1, y2) = Self::compute_pair_placement( matrix_width, matrix_height, + is_32px, + &c1.meta, + &c2.meta, ); - let scale = if is_tate { - if matrix_width >= 96 && is_32px { - (matrix_width / 64) as i32 - } else { - 1 - } - } else if is_4x3 { - if is_32px { - (matrix_height / 32).min(matrix_width / 64) as i32 - } else { - (matrix_height / 64).min(matrix_width / 128) as i32 - } - } else if matrix_height >= 64 && is_32px { - (matrix_height / 32) as i32 - } else { - 1 - } - .max(1); - - let (y1, y2) = if is_tate || is_4x3 { - // In TATE and 4:3 CRT modes, fighters stand on the bottom pixel of the screen: groundY = screenH - 1 - let ground_y_screen = matrix_height as i32 - 1; - ( - ground_y_screen - (c1.meta.ground_y as i32 * scale), - ground_y_screen - (c2.meta.ground_y as i32 * scale), - ) - } else { - // Place P1 at 1 pixel from the top of the screen - let y1 = (1 - c1.meta.head_y as i32) * scale; - // Align ground line to P1's physical feet - let ground_y_screen = - (1 - c1.meta.head_y as i32) + (c1.meta.ground_y as i32 * scale); - // Place P2 on the exact same ground line - let y2 = ground_y_screen - (c2.meta.ground_y as i32 * scale); - (y1, y2) - }; let mut mirrored_c2 = c2.clone(); for anim in mirrored_c2.anims.values_mut() { @@ -1213,4 +1208,87 @@ mod tests { assert_eq!(meta.has_special, true); assert_eq!(meta.has_super, false); } + + #[test] + fn test_fighter_4x3_head_safe_overflow_vs_floor_anchor() { + // Real fighters_64 metrics from ArcadeMatrix-Assets: + // Chun-Li: stand_h = 117 - 60 = 57px (shorter than 96px) + let chunli = FighterIndexMeta { + height: 58, + ground_y: 117, + head_y: 60, + origin_x: 47, + width: 106, + has_special: true, + has_super: true, + }; + // Haohmaru: stand_h = 111 - 48 = 63px (shorter than 96px) + let haohmaru = FighterIndexMeta { + height: 64, + ground_y: 111, + head_y: 48, + origin_x: 45, + width: 105, + has_special: true, + has_super: true, + }; + // Gouki: stand_h = 121 - 13 = 108px (EXCEEDS 128x96 vertical resolution!) + let gouki = FighterIndexMeta { + height: 111, + ground_y: 121, + head_y: 13, + origin_x: 53, + width: 125, + has_special: true, + has_super: true, + }; + // Bison: stand_h = 121 - 17 = 104px (also exceeds 128x96) + let bison = FighterIndexMeta { + height: 108, + ground_y: 121, + head_y: 17, + origin_x: 60, + width: 181, + has_special: true, + has_super: true, + }; + + // 1. Shorter sprites on 128x96: stand cleanly on floor y = 95, heads well inside [1..95] + let (scale, y1, y2) = + FighterEngine::compute_pair_placement(128, 96, false, &haohmaru, &chunli); + assert_eq!(scale, 1); + assert_eq!(y1 + haohmaru.ground_y, 95); + assert_eq!(y2 + chunli.ground_y, 95); + assert!(y1 + haohmaru.head_y >= 1); + assert!(y2 + chunli.head_y >= 1); + + // 2. Taller sprites on 128x96 (Gouki 108px > 96px): + // Ground drops to 109 (> 95) so Gouki's head stays at y = 1 (never cropped at top!), + // both fighters share the exact same ground line, and ankles overflow below y = 95. + let (scale, y1, y2) = FighterEngine::compute_pair_placement(128, 96, false, &gouki, &bison); + assert_eq!(scale, 1); + assert_eq!(y1 + gouki.head_y, 1, "Tallest head must never clip < 1"); + assert_eq!(y2 + bison.head_y, 5); + assert_eq!( + y1 + gouki.ground_y, + y2 + bison.ground_y, + "Both fighters must share the exact same ground line" + ); + assert_eq!(y1 + gouki.ground_y, 109); + + // 3. Multiples (96x72 and 256x192 at 1x): never decapitates when sprite exceeds height + let (scale_72, y1_72, _) = + FighterEngine::compute_pair_placement(96, 72, false, &gouki, &chunli); + assert_eq!(scale_72, 1); + assert_eq!(y1_72 + gouki.head_y, 1); + + let (scale_192, y1_192, y2_192) = + FighterEngine::compute_pair_placement(256, 192, false, &gouki, &bison); + assert_eq!(scale_192, 2); + assert_eq!(y1_192 + gouki.head_y * scale_192, 1); + assert_eq!( + y1_192 + gouki.ground_y * scale_192, + y2_192 + bison.ground_y * scale_192 + ); + } } From b95806861def67cab4ba45ff563253a290d5ce02 Mon Sep 17 00:00:00 2001 From: red77290 <23342613+red77290@users.noreply.github.com> Date: Sat, 5 Dec 2026 15:27:56 +0000 Subject: [PATCH 3/3] fix(fighter,tests): use 2*scale top margin on 4:3 overflow and serialize MQTT test IDs --- src/engines/fighter.rs | 44 ++++++++++++++++++++++++------------ src/engines/frontend_sync.rs | 11 +++++++++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/engines/fighter.rs b/src/engines/fighter.rs index 2aca3039..2e266093 100644 --- a/src/engines/fighter.rs +++ b/src/engines/fighter.rs @@ -406,14 +406,15 @@ impl FighterEngine { /// Computes `(scale, y1, y2)` for a fighter pair on `(matrix_width, matrix_height)`. /// /// - On `4:3` CRT panels (`is_landscape_4x3_family`), both fighters share a single ground - /// line `ground_y_screen = (matrix_height as i32 - 1).max(1 + tallest * scale)`: + /// line `ground_y_screen = (matrix_height as i32 - 1).max((2 + tallest) * scale)`: /// - When the tallest standing sprite (`ground_y - head_y`) fits vertically inside the /// panel, `ground_y_screen = matrix_height - 1` so both fighters stand firmly on the /// bottom edge instead of floating in mid-air. /// - When a tall sprite exceeds the panel's vertical resolution (e.g. Gouki `108px` on /// `128x96`, or `fighters_64` on `96x72`), `ground_y_screen` drops below the bottom - /// edge (`1 + tallest * scale > matrix_height - 1`) so the tallest head stays pinned - /// at `y = 1` (never decapitated) and the overflow is cropped cleanly at the legs/feet. + /// edge (`(2 + tallest) * scale > matrix_height - 1`) so the tallest head stays pinned + /// at `y = 2 * scale` (`2px` below top at `1x`, preserving walk-bob headroom) and both + /// fighters share that imaginary off-screen ground line with overflow cropped at the legs. /// - All non-`4:3` layouts (`128x32`, `256x64`, `192x32`, TATE, etc.) retain their exact /// existing placement untouched. pub(crate) fn compute_pair_placement( @@ -457,7 +458,7 @@ impl FighterEngine { let h1 = (c1_meta.ground_y - c1_meta.head_y).max(0); let h2 = (c2_meta.ground_y - c2_meta.head_y).max(0); let tallest = h1.max(h2); - let head_safe_ground_y = 1 + tallest * scale; + let head_safe_ground_y = (2 + tallest) * scale; let ground_y_screen = (matrix_height as i32 - 1).max(head_safe_ground_y); ( ground_y_screen - (c1_meta.ground_y * scale), @@ -1253,42 +1254,55 @@ mod tests { has_super: true, }; - // 1. Shorter sprites on 128x96: stand cleanly on floor y = 95, heads well inside [1..95] + // 1. Shorter sprites on 128x96: stand cleanly on floor y = 95, heads well inside [2..95] let (scale, y1, y2) = FighterEngine::compute_pair_placement(128, 96, false, &haohmaru, &chunli); assert_eq!(scale, 1); assert_eq!(y1 + haohmaru.ground_y, 95); assert_eq!(y2 + chunli.ground_y, 95); - assert!(y1 + haohmaru.head_y >= 1); - assert!(y2 + chunli.head_y >= 1); + assert!(y1 + haohmaru.head_y >= 2); + assert!(y2 + chunli.head_y >= 2); // 2. Taller sprites on 128x96 (Gouki 108px > 96px): - // Ground drops to 109 (> 95) so Gouki's head stays at y = 1 (never cropped at top!), - // both fighters share the exact same ground line, and ankles overflow below y = 95. + // Ground drops to 110 (> 95) so Gouki's head stays at y = 2 (walk-bob safe!), + // both fighters share the exact same imaginary off-screen ground line, and ankles crop below y = 95. let (scale, y1, y2) = FighterEngine::compute_pair_placement(128, 96, false, &gouki, &bison); assert_eq!(scale, 1); - assert_eq!(y1 + gouki.head_y, 1, "Tallest head must never clip < 1"); - assert_eq!(y2 + bison.head_y, 5); + assert_eq!(y1 + gouki.head_y, 2, "Tallest head must sit 2px below top"); + assert_eq!(y2 + bison.head_y, 6); assert_eq!( y1 + gouki.ground_y, y2 + bison.ground_y, - "Both fighters must share the exact same ground line" + "Both fighters must share the exact same imaginary off-screen ground line" ); - assert_eq!(y1 + gouki.ground_y, 109); + assert_eq!(y1 + gouki.ground_y, 110); // 3. Multiples (96x72 and 256x192 at 1x): never decapitates when sprite exceeds height let (scale_72, y1_72, _) = FighterEngine::compute_pair_placement(96, 72, false, &gouki, &chunli); assert_eq!(scale_72, 1); - assert_eq!(y1_72 + gouki.head_y, 1); + assert_eq!(y1_72 + gouki.head_y, 2); let (scale_192, y1_192, y2_192) = FighterEngine::compute_pair_placement(256, 192, false, &gouki, &bison); assert_eq!(scale_192, 2); - assert_eq!(y1_192 + gouki.head_y * scale_192, 1); + assert_eq!(y1_192 + gouki.head_y * scale_192, 4); assert_eq!( y1_192 + gouki.ground_y * scale_192, y2_192 + bison.ground_y * scale_192 ); + + // 4. Strict zero-regression on 128x32 and 256x64 (exact legacy formulas preserved) + let (s_32, y1_32, y2_32) = + FighterEngine::compute_pair_placement(128, 32, true, &gouki, &bison); + assert_eq!(s_32, 1); + assert_eq!(y1_32, 1 - gouki.head_y); + assert_eq!(y2_32, (1 - gouki.head_y) + gouki.ground_y - bison.ground_y); + + let (s_64, y1_64, y2_64) = + FighterEngine::compute_pair_placement(256, 64, false, &gouki, &bison); + assert_eq!(s_64, 1); + assert_eq!(y1_64, 1 - gouki.head_y); + assert_eq!(y2_64, (1 - gouki.head_y) + gouki.ground_y - bison.ground_y); } } diff --git a/src/engines/frontend_sync.rs b/src/engines/frontend_sync.rs index 5f117380..4f54c5be 100644 --- a/src/engines/frontend_sync.rs +++ b/src/engines/frontend_sync.rs @@ -2190,6 +2190,8 @@ mod tests { parse_dmd_stream_compact(&raw).expect("valid DMDZ v2 test stream") } + static TEST_MQTT_GLOBAL_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + #[test] fn test_format_game_name() { assert_eq!(format_game_name("super-mario_bros"), "Super Mario Bros"); @@ -2208,6 +2210,9 @@ mod tests { #[test] fn test_missing_game_marquee_displays_cyan_game_name_not_system_marquee() { + let _mqtt_guard = TEST_MQTT_GLOBAL_LOCK + .lock() + .unwrap_or_else(|e| e.into_inner()); let tmp_dir = std::env::temp_dir().join(format!( "arcadematrix_missing_game_marquee_test_{}", std::process::id() @@ -2508,6 +2513,9 @@ mod tests { use image::codecs::gif::GifEncoder; use image::{Delay, Frame, Rgba, RgbaImage}; + let _mqtt_guard = TEST_MQTT_GLOBAL_LOCK + .lock() + .unwrap_or_else(|e| e.into_inner()); let tmp_dir = std::env::temp_dir().join(format!( "arcadematrix_offline_rgb888_gif_test_{}", std::process::id() @@ -2744,6 +2752,9 @@ mod tests { #[test] fn test_handle_frontend_sync_payload_e2e_offline_tate_preemption_and_stopped() { + let _mqtt_guard = TEST_MQTT_GLOBAL_LOCK + .lock() + .unwrap_or_else(|e| e.into_inner()); let tmp_dir = std::env::temp_dir().join(format!( "arcadematrix_e2e_mqtt_offline_tate_{}", std::process::id()