#![no_std] use port_framebuffer::Framebuffer; use types::display::{Color, Dimension, ScreenCoord}; pub struct MockFramebuffer { width: Dimension, height: Dimension, pixels: [(ScreenCoord, ScreenCoord, Color); 4096], pixel_count: usize, flushed: bool, } impl MockFramebuffer { pub fn new(width: Dimension, height: Dimension) -> Self { Self { width, height, pixels: [(ScreenCoord::new(0), ScreenCoord::new(0), Color::from_raw(0)); 4096], pixel_count: 0, flushed: false, } } pub fn pixel_count(&self) -> usize { self.pixel_count } pub fn was_flushed(&self) -> bool { self.flushed } pub fn pixel_at(&self, index: usize) -> (ScreenCoord, ScreenCoord, Color) { self.pixels[index] } } impl Framebuffer for MockFramebuffer { fn width(&self) -> Dimension { self.width } fn height(&self) -> Dimension { self.height } fn write_pixel(&mut self, x: ScreenCoord, y: ScreenCoord, color: Color) { if self.pixel_count < self.pixels.len() { self.pixels[self.pixel_count] = (x, y, color); self.pixel_count += 1; } } fn fill_rect(&mut self, x: ScreenCoord, y: ScreenCoord, w: Dimension, h: Dimension, color: Color) { for dy in 0..h.raw() { for dx in 0..w.raw() { self.write_pixel(ScreenCoord::new(x.raw() + dx), ScreenCoord::new(y.raw() + dy), color); } } } fn clear(&mut self, _color: Color) { self.pixel_count = 0; } fn flush(&mut self) { self.flushed = true; } }