use avrox_display::gfx::{Area, patterns, Renderable, RenderPlane};
use avrox_display::gfx::pixels::Monochromatic;
use avrox_display::gfx::Point;
use avrox_display::GfxResult;
use avr_oxide::OxideResult::Ok;
pub struct SolidFill<PIX: Clone>(PIX);
pub type GraphicsPatternFunction<PIX> = fn(Point) -> GfxResult<PIX>;
pub struct FunctionFill<PIX> {
function: GraphicsPatternFunction<PIX>
}
pub fn crosshatch_fill() -> FunctionFill<Monochromatic> {
FunctionFill {
function: patterns::crosshatch
}
}
pub fn horizontal_pinstripe_fill() -> FunctionFill<Monochromatic> {
FunctionFill {
function: patterns::horizontal_pinstripe
}
}
pub fn vertical_pinstripe_fill() -> FunctionFill<Monochromatic> {
FunctionFill {
function: patterns::vertical_pinstripe
}
}
impl<PIX: Clone> SolidFill<PIX> {
pub fn new(pix: PIX) -> Self {
SolidFill(pix)
}
}
impl<PIX> FunctionFill<PIX>{
pub fn new(function: GraphicsPatternFunction<PIX>) -> Self {
FunctionFill {
function
}
}
}
impl<PIX> Renderable for FunctionFill<PIX> {
type PIXEL = PIX;
fn get_pixel_at<P: RenderPlane>(&self, coord: Point) -> GfxResult<Self::PIXEL> {
(self.function)(coord)
}
fn has_changes<P: RenderPlane>(&self) -> bool {
false
}
}
impl<PIX> Renderable for SolidFill<PIX>
where
PIX: Clone
{
type PIXEL = PIX;
fn get_pixel_at<P: RenderPlane>(&self, _coord: Point) -> GfxResult<Self::PIXEL> {
Ok(self.0.clone())
}
fn has_changes<P: RenderPlane>(&self) -> bool {
false
}
fn get_change_area<P: RenderPlane>(&self) -> GfxResult<Option<Area>> {
Ok(None)
}
}
#[cfg(test)]
mod tests {
}