1use super::Card;
2use stakker_tui::Region;
3use std::io::Write;
4
5pub const CARD_SX: i32 = 6;
6pub const CARD_SY: i32 = 5;
7
8pub fn card(r: &mut Region, y: i32, x: i32, card: Card) {
10 let mut r = r.region(y, x, CARD_SY, CARD_SX);
11 r.hfb(card.hfb).clear_all();
12 r.at(0, 2);
13 write!(r, "{}{}", card.num_ch, card.suit_ch).unwrap();
14 r.at(CARD_SY - 1, 2);
15 write!(r, "{}{}", card.num_ch, card.suit_ch).unwrap();
16}
17
18pub fn card_back(r: &mut Region, y: i32, x: i32) {
20 let mut r = r.region(y, x, CARD_SY, CARD_SX);
21 r.hfb(27);
22 for y in 0..CARD_SY {
23 r.at(y, 0).text("||||||");
24 }
25}
26
27pub fn card_space(r: &mut Region, y: i32, x: i32) {
29 let mut r = r.region(y, x, CARD_SY, CARD_SX);
30 r.hfb(71).clear_all();
31}
32
33pub fn card_dots(r: &mut Region, y: i32, x: i32) {
35 let mut r = r.region(y, x, CARD_SY, CARD_SX);
36 r.hfb(70);
37 for y in 0..CARD_SY {
38 r.at(y, 0).text("::::::");
39 }
40}
41
42#[cfg(false)]
43mod unused {
44 use crate::Region;
45 const FONT: [&[u8]; 5] = [
46 b" 0000 00 00000 00000 00 00 00000 0000 000000 0000 0000 ",
47 b"00 00 000 00 00 00 00 00 00 00 00 00 00 00 00 ",
48 b"00 00 00 0000 000 000000 00000 00000 00 0000 00000 ",
49 b"00 00 00 00 00 00 00 00 00 00 00 00 00 00 ",
50 b" 0000 0000 000000 00000 00 00000 0000 00 0000 0000 ",
51 ];
52 const FONT_CX: usize = 7;
53 const FONT_SY: usize = 5;
54
55 pub fn bignum_str(region: &mut Region, y: i32, mut x: i32, hfb: u16, glyph: &str, text: &str) {
58 for ch in text.as_bytes() {
59 let (off, wid) = match ch {
60 b'0'..=b'9' => ((ch - 48) as usize * FONT_CX, FONT_CX),
61 b':' => (10 * FONT_CX, FONT_CX - 2),
62 _ => (0, 0),
63 };
64 let mut r = region.region(y, x, wid as i32, FONT_SY as i32);
65 r.hfb(hfb);
66 for i in 0..FONT_SY {
67 let slice = &FONT[i][off..off + wid];
68 for j in 0..wid {
69 if slice[j] != b' ' {
70 r.at(i as i32, j as i32).text(glyph);
71 }
72 }
73 }
74 x += wid as i32;
75 }
76 }
77
78 pub fn bignum_str_left(r: &mut Region, y: i32, mut x: i32, hfb: u16, glyph: &str, text: &str) {
80 for ch in text.as_bytes() {
81 x -= (match ch {
82 b'0'..=b'9' => FONT_CX,
83 b':' => FONT_CX - 2,
84 _ => 0,
85 }) as i32;
86 }
87
88 bignum_str(r, y, x, hfb, glyph, text);
89 }
90}