Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/engines/clocks/castle_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/engines/clocks/mario_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/engines/clocks/megaman_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions src/engines/clocks/metal_slug_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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
};
Expand All @@ -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
};
Expand Down
23 changes: 19 additions & 4 deletions src/engines/clocks/pokedex_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
48 changes: 40 additions & 8 deletions src/engines/clocks/sonic_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
45 changes: 36 additions & 9 deletions src/engines/clocks/words_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand All @@ -79,6 +97,7 @@ impl WordsClock {
h * 45 / 100,
(255, 255, 255),
w,
is_4x3,
);

let rule_w = w * 3 / 4;
Expand All @@ -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),
);
Expand Down
Loading
Loading