Maraiah/source/rozinante/draw.rs

57 lines
1.2 KiB
Rust
Raw Normal View History

2019-03-02 21:45:04 -08:00
//! GUI drawing capabilities.
use crate::durandal::image::Color;
2019-03-02 15:26:55 -08:00
2019-03-04 18:14:09 -08:00
/// An image possibly cached into a native driver's memory.
2019-03-02 17:49:35 -08:00
pub trait CacheImage
{
2019-03-04 18:14:09 -08:00
/// The width of the image.
2019-03-02 17:49:35 -08:00
fn w(&self) -> Coord;
2019-03-04 18:14:09 -08:00
/// The width of the image.
2019-03-02 17:49:35 -08:00
fn h(&self) -> Coord;
}
2019-03-02 15:26:55 -08:00
2019-03-04 18:14:09 -08:00
/// A native vector drawing area.
2019-03-02 15:26:55 -08:00
pub trait DrawArea
{
2019-03-04 18:14:09 -08:00
/// The native `CacheImage` type for this `DrawArea`.
2019-03-02 17:49:35 -08:00
type NativeImage: CacheImage;
2019-03-04 18:14:09 -08:00
/// The width of the entire area.
2019-03-02 17:49:35 -08:00
fn w(&self) -> Coord;
2019-03-04 18:14:09 -08:00
/// The height of the entire area.
2019-03-02 17:49:35 -08:00
fn h(&self) -> Coord;
2019-03-02 15:26:55 -08:00
2019-03-04 18:14:09 -08:00
/// Fills the entire screen with `cr`.
2019-03-02 15:26:55 -08:00
fn clear(&self, cr: impl Color);
2019-03-04 18:14:09 -08:00
/// Draws a rectangle `rect` of color `cr`.
2019-03-02 15:26:55 -08:00
fn rect(&self, rect: Rect, cr: impl Color);
2019-03-04 18:14:09 -08:00
/// Draws the Unicode `text` at `pos` stroked with color `cr`.
2019-03-02 21:45:04 -08:00
fn text(&self, pos: Point, text: &str, cr: impl Color);
2019-03-04 18:14:09 -08:00
/// Draws `im` at `pos`, starting from the top left column.
2019-03-02 17:49:35 -08:00
fn image(&self, pos: Point, im: &Self::NativeImage);
2019-03-02 15:26:55 -08:00
}
2019-03-04 18:14:09 -08:00
/// A type capable of representing any coordinate on any axis.
2019-03-02 17:49:35 -08:00
pub type Coord = i32;
2019-03-04 18:14:09 -08:00
/// A 2-dimensional point.
2019-03-02 17:49:35 -08:00
pub type Point = (Coord, Coord);
2019-03-02 15:26:55 -08:00
2019-03-04 18:14:09 -08:00
/// A 2-dimensional rectangle.
2019-03-02 17:49:35 -08:00
#[derive(Copy, Clone, Debug)]
2019-03-04 02:18:57 -08:00
pub struct Rect
{
pub x: Coord,
pub y: Coord,
pub w: Coord,
pub h: Coord,
}
2019-03-02 15:26:55 -08:00
// EOF