use super::*; use stockbook::{stamp, Stamp}; macro_rules! bitmaps { ($($name:ident($path:literal)),* $(,)?) => { $( impl Bitmap { #[allow(unused)] pub fn $name(position: Vec2, color: Color) -> Self { #[allow(unused)] static STAMP: Stamp = stamp!($path); Self::new(&STAMP, position, color) } } )* }; } bitmaps! { ear_tilt1("assets/ear_tilt1.png"), ear_tilt2("assets/ear_tilt2.png"), ear_tilt3("assets/ear_tilt3.png"), ear_tilt4("assets/ear_tilt4.png"), strand("assets/strand.png"), whiskers("assets/whiskers.png"), torso("assets/torso.png"), tail("assets/tail.png"), eyes_hard_closed("assets/eyes_hard_closed.png"), eyes_soft_closed("assets/eyes_soft_closed.png"), mouth_1("assets/mouth_1.png"), mouth_2("assets/mouth_2.png"), mouth_3("assets/mouth_3.png"), } pub struct Bitmap { stamp: &'static Stamp, position: Vec2, color: Color, flip_h: bool, flip_v: bool, } impl Bitmap { #[must_use] fn new(stamp: &'static Stamp, position: Vec2, color: Color) -> Self { Self { stamp, position, color, flip_h: false, flip_v: false, } } } impl Bitmap { pub fn flip_h(mut self) -> Self { self.flip_h = !self.flip_h; self } } impl Draw for Bitmap { fn draw(&self, canvas: &mut impl Canvas) { let [width, height] = self.stamp.size(); for (u, v, color) in self.stamp.pixels() { let x = match self.flip_h { false => u, true => width - u - 1, }; let y = match self.flip_v { false => v, true => height - v - 1, }; if let (Color::On, stockbook::Color::Black) | (Color::Off, stockbook::Color::White) = (self.color, color) { canvas.blit_pixel( self.position.x + x as isize, self.position.y + y as isize, self.color, ); } } } }