1use image as im;
2
3#[allow(missing_docs)]
4pub const MAX_WIDTH_MODE0: u32 = 96 * 2;
5#[allow(missing_docs)]
6pub const MAX_WIDTH_MODE1: u32 = 96 * 4;
7#[allow(missing_docs)]
8pub const MAX_WIDTH_MODE2: u32 = 96 * 8;
9#[allow(missing_docs)]
10pub const MAX_WIDTH_MODE3: u32 = 96 * 2;
11#[allow(missing_docs)]
12pub const MAX_HEIGHT: u32 = 39 * 8;
13
14#[allow(missing_docs)]
15#[derive(Debug)]
16pub struct SimpleMonitor {
17 pub width: u32,
18 pub height: u32,
19 pub mode: u8,
20 pub pixels: Vec<Vec<u8>>,
21 pub palette: Vec<char>,
22 pub buffer: im::ImageBuffer<im::Rgba<u8>, Vec<u8>>
23}
24
25#[allow(missing_docs)]
26impl SimpleMonitor {
27 pub fn new(width: u32, height: u32, mode: u8) -> Self {
28 Self {
29 width,
30 height,
31 mode,
32 pixels: vec![vec![0_u8; width as usize]; height as usize],
33 palette: vec![0 as char; 16],
34 buffer: im::ImageBuffer::new(width, height)
35 }
36 }
37
38 pub fn width(&self) -> u32 {
39 self.width
40 }
41
42 pub fn height(&self) -> u32 {
43 self.height
44 }
45
46 pub fn set_pixel(&mut self, x: u32, y: u32, pen: u8) {
47 self.pixels[y as usize][x as usize] = pen;
48 }
49
50 pub fn set_ink(&mut self, ink: char, color: char) {
51 assert!(ink <= 17 as char);
52 assert!(color <= 27 as char);
53
54 self.palette[ink as usize] = color
55 }
56
57 pub fn update_buffer(&mut self) {
58 }
60
61 pub fn canvas(&mut self) -> &mut im::ImageBuffer<im::Rgba<u8>, Vec<u8>> {
62 &mut self.buffer
63 }
64}