Maraiah/source/rozinante/draw.rs

64 lines
1.4 KiB
Rust

//! 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`.
fn clear(&self, cr: impl Color);
/// Draws a rectangle `rect` of color `cr`.
fn rect(&self, rect: Rect, cr: impl Color);
/// Draws the Unicode `text` at `pos` stroked with color `cr`.
fn text(&self, pos: Point, text: &str, cr: impl Color);
/// Draws `im` at `pos`, starting from the top left column.
fn image(&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