//! GUI drawing capabilities. use crate::durandal::image::Color; /// An image possibly cached into a native driver's memory. pub trait CacheImage { /// The width of the image. fn w(&self) -> Coord; /// The width of the image. fn h(&self) -> Coord; } /// A native vector drawing area. pub trait DrawArea { /// The native `CacheImage` type for this `DrawArea`. type NativeImage: CacheImage; /// The width of the entire area. fn w(&self) -> Coord; /// The height of the entire area. fn h(&self) -> Coord; /// Fills the entire screen with `cr`. Will also default all settings. fn clear(&mut self, cr: impl Color); /// Changes the width for lines. The default is `1`. fn line_width(&mut self, width: u8); /// Draws a line from `p1` to `p2` with color `cr`. fn line(&mut self, p1: Point, p2: Point, cr: impl Color); /// Draws a rectangle `rect` of color `cr`. fn rect(&mut self, rect: Rect, cr: impl Color); /// Draws the Unicode `text` at `pos` stroked with color `cr`. fn text(&mut self, pos: Point, text: &str, cr: impl Color); /// Draws `im` at `pos`, starting from the top left column. fn image(&mut self, pos: Point, im: &Self::NativeImage); } /// A type capable of representing any coordinate on any axis. pub type Coord = i32; /// A 2-dimensional point. pub type Point = (Coord, Coord); /// A 2-dimensional rectangle. #[derive(Copy, Clone, Debug)] pub struct Rect { /// The horizontal coordinate to start at, from the left. pub x: Coord, /// The vertical coordinate to start at, from the top. pub y: Coord, /// The width of the rectangle. pub w: Coord, /// The height of the rectangle. pub h: Coord, } // EOF