Maraiah/source/rozinante/draw.rs

70 lines
1.7 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-24 17:04:49 -07:00
/// Fills the entire screen with `cr`. Will also default all settings.
2019-03-27 04:55:58 -07:00
fn clear(&mut self, cr: impl Color);
2019-03-04 18:14:09 -08:00
2019-03-24 17:04:49 -07:00
/// Changes the width for lines. The default is `1`.
2019-03-27 04:55:58 -07:00
fn line_width(&mut self, width: u8);
2019-03-24 17:04:49 -07:00
/// Draws a line from `p1` to `p2` with color `cr`.
2019-03-27 04:55:58 -07:00
fn line(&mut self, p1: Point, p2: Point, cr: impl Color);
2019-03-24 17:04:49 -07:00
2019-03-04 18:14:09 -08:00
/// Draws a rectangle `rect` of color `cr`.
2019-03-27 04:55:58 -07:00
fn rect(&mut 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-27 04:55:58 -07:00
fn text(&mut 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-27 04:55:58 -07:00
fn image(&mut 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
{
2019-03-09 14:03:20 -08:00
/// The horizontal coordinate to start at, from the left.
2019-03-04 02:18:57 -08:00
pub x: Coord,
2019-03-09 14:03:20 -08:00
/// The vertical coordinate to start at, from the top.
2019-03-04 02:18:57 -08:00
pub y: Coord,
2019-03-09 14:03:20 -08:00
/// The width of the rectangle.
2019-03-04 02:18:57 -08:00
pub w: Coord,
2019-03-09 14:03:20 -08:00
/// The height of the rectangle.
2019-03-04 02:18:57 -08:00
pub h: Coord,
}
2019-03-02 15:26:55 -08:00
// EOF