pub struct Canvas { /* private fields */ }Expand description
A framebuffer for one GPU’s screen; see the module docs.
Implementations§
Source§impl Canvas
impl Canvas
Sourcepub fn new(gpu: Gpu) -> Result<Canvas>
pub fn new(gpu: Gpu) -> Result<Canvas>
A canvas the size of the GPU’s current resolution, at its deepest colour depth.
Sourcepub fn with_size(gpu: Gpu, w: usize, h: usize) -> Canvas
pub fn with_size(gpu: Gpu, w: usize, h: usize) -> Canvas
A canvas of w x h cells, drawn from the screen’s top left corner.
Makes no GPU calls until Canvas::present.
pub fn gpu(&self) -> &Gpu
Sourcepub fn double_buffered(&mut self, on: bool) -> Result<bool>
pub fn double_buffered(&mut self, on: bool) -> Result<bool>
Composes each present in a GPU buffer and copies it to the screen in
one bitblt, so the screen never shows a half-drawn frame. Returns
false (and keeps drawing directly) if the GPU has no video memory to
spare. double_buffered(false) frees the buffer.
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Forgets what the screen shows, so the next present redraws every cell. Call it after anything else draws on the screen.
Sourcepub fn get(&self, x: i64, y: i64) -> Option<(char, Rgb, Rgb)>
pub fn get(&self, x: i64, y: i64) -> Option<(char, Rgb, Rgb)>
The character and colours of cell (x, y).
Sourcepub fn fill(
&mut self,
x: i64,
y: i64,
w: i64,
h: i64,
ch: char,
fg: Rgb,
bg: Rgb,
)
pub fn fill( &mut self, x: i64, y: i64, w: i64, h: i64, ch: char, fg: Rgb, bg: Rgb, )
Fills a rectangle of cells with ch.
Sourcepub fn text(&mut self, x: i64, y: i64, text: &str, fg: Rgb, bg: Rgb)
pub fn text(&mut self, x: i64, y: i64, text: &str, fg: Rgb, bg: Rgb)
Writes text from cell (x, y) rightwards, clipped at the edge.
Sourcepub fn text_vertical(&mut self, x: i64, y: i64, text: &str, fg: Rgb, bg: Rgb)
pub fn text_vertical(&mut self, x: i64, y: i64, text: &str, fg: Rgb, bg: Rgb)
Writes text from cell (x, y) downwards.
Sourcepub fn pixels(&mut self) -> Pixels<'_>
pub fn pixels(&mut self) -> Pixels<'_>
The canvas as half-block pixels: width() x height() * 2.
Sourcepub fn present(&mut self) -> Result<usize>
pub fn present(&mut self) -> Result<usize>
Sends what changed since the last present to the screen. Returns the number of GPU calls it made.
Sourcepub async fn present_async(&mut self) -> Result<usize>
pub async fn present_async(&mut self) -> Result<usize>
Canvas::present without blocking: every call is queued at once
(they run in order), and other tasks keep running. Requires the
async feature; see crate::task.