Maraiah/source/rozinante/draw.rs

57 lines
1.2 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
{
pub x: Coord,
pub y: Coord,
pub w: Coord,
pub h: Coord,
}
// EOF