use alloc::{format, string::String};
use core::fmt::Write;
use crate::{
render::{Canvas as RenderCanvas, Pixel},
types::Color as ModuleColor,
};
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Color;
impl Pixel for Color {
type Image = String;
type Canvas = Canvas;
fn default_color(_color: ModuleColor) -> Self {
Self
}
}
#[derive(Debug)]
pub struct Canvas {
pic: String,
}
impl RenderCanvas for Canvas {
type Pixel = Color;
type Image = String;
fn new(width: u32, height: u32, _dark_pixel: Self::Pixel, _light_pixel: Self::Pixel) -> Self {
let pic = format!(
concat!(
"maxpswid={w};maxpsht={h};movewid=0;moveht=1;boxwid=1;boxht=1\n",
"define p {{ box wid $3 ht $4 fill 1 thickness 0.1 with .nw at $1,-$2 }}\n",
"box wid maxpswid ht maxpsht with .nw at 0,0\n"
),
w = width,
h = height
);
Self { pic }
}
fn draw_dark_pixel(&mut self, x: u32, y: u32) {
self.draw_dark_rect(x, y, 1, 1);
}
fn draw_dark_rect(&mut self, left: u32, top: u32, width: u32, height: u32) {
writeln!(self.pic, "p({left},{top},{width},{height})").unwrap();
}
fn into_image(mut self) -> Self::Image {
self.pic.pop();
self.pic
}
}