Trait lux::graphics::Canvas
[−]
[src]
pub trait Canvas: PrimitiveCanvas + Colored + Transform + DrawParamMod + Sized {
fn size(&self) -> (Float, Float);
fn width(&self) -> Float { ... }
fn height(&self) -> Float { ... }
fn clear<C: Color>(&mut self, color: C) { ... }
fn with_scissor<F, R>(&mut self, x: u32, y: u32, w: u32, h: u32, f: F) -> R where F: FnOnce(&mut Self) -> R { ... }
fn draw_to_stencil<R, S>(&mut self, typ: StencilType, stencil_fn: S) -> R where S: FnOnce(&mut Self) -> R { ... }
fn clear_stencil(&mut self, typ: StencilType) { ... }
fn rect<'a>(&'a mut self, x: Float, y: Float, w: Float, h: Float) -> Rectangle<'a, Self> { ... }
fn square<'a>(&'a mut self, x: Float, y: Float, size: Float) -> Rectangle<'a, Self> { ... }
fn ellipse<'a>(&'a mut self, x: Float, y: Float, w: Float, h: Float) -> Ellipse<'a, Self> { ... }
fn circle<'a>(&'a mut self, x: Float, y: Float, size: Float) -> Ellipse<'a, Self> { ... }
fn draw_point<C: Color>(&mut self, x: Float, y: Float, color: C) { ... }
fn draw_points(&mut self, pixels: &[ColorVertex]) { ... }
fn draw_line(&mut self, _x1: Float, _y1: Float, _x2: Float, _y2: Float, _line_size: Float) { ... }
fn draw_lines<I: Iterator<Item=(Float, Float)>>(&mut self, _positions: I, _line_size: Float) { ... }
fn draw_arc(&mut self, _pos: (Float, Float), _radius: Float, _angle1: Float, _angle2: Float, _line_size: Float) { ... }
fn sprite(&mut self, sprite: &Sprite, x: Float, y: Float) -> ContainedSprite<Self> { ... }
}Canvas is the main trait for drawing in Lux. It supports all operations that paint to the screen or to a buffer.
Required Methods
Provided Methods
fn width(&self) -> Float
Returns the width of the canvas.
fn height(&self) -> Float
Returns the height of the canvas.
fn clear<C: Color>(&mut self, color: C)
Clears the canvas with a solid color.
use lux::prelude::*; let mut window = Window::new().unwrap(); let mut frame = window.frame(); // Clear the screen with purple. frame.clear(rgb(1.0, 0.0, 1.0));
fn with_scissor<F, R>(&mut self, x: u32, y: u32, w: u32, h: u32, f: F) -> R where F: FnOnce(&mut Self) -> R
Evaluates the function with a canvas that will only draw into the provided rectangle.
fn draw_to_stencil<R, S>(&mut self, typ: StencilType, stencil_fn: S) -> R where S: FnOnce(&mut Self) -> R
Executes a drawing function where all drawing is done on the stencil buffer.
fn clear_stencil(&mut self, typ: StencilType)
Clears the stencil buffer allowing all draws to go though.
When called with StencilType::Allow, the stencil buffer will
be cleared allowing all future draws to pass through until
draw_to_stencil is called with StencilType::Deny.
Whene called with StencilType::Deny, the stencil buffer will be
filled, preventing all future draws to fail until draw_to_stencil
is called with StencilType::Allow.
fn rect<'a>(&'a mut self, x: Float, y: Float, w: Float, h: Float) -> Rectangle<'a, Self>
Returns a rectangle with the given dimensions and position.
use lux::prelude::*; let mut window = Window::new().unwrap(); let mut frame = window.frame(); let (x, y, w, h) = (0.0, 5.0, 50.0, 70.0); frame.rect(x, y, w, h) .color(rgb(100, 200, 255)) .fill();
fn square<'a>(&'a mut self, x: Float, y: Float, size: Float) -> Rectangle<'a, Self>
Returns a square with the given dimensions and position.
use lux::prelude::*; let mut window = Window::new().unwrap(); let mut frame = window.frame(); let (x, y, size) = (0.0, 5.0, 50.0); frame.square(x, y, size) .color(rgb(100, 200, 255)) .fill();
fn ellipse<'a>(&'a mut self, x: Float, y: Float, w: Float, h: Float) -> Ellipse<'a, Self>
Returns an ellipse with the given dimensions and position.
use lux::prelude::*; let mut window = Window::new().unwrap(); let mut frame = window.frame(); let (x, y, w, h) = (0.0, 5.0, 50.0, 70.0); frame.ellipse(x, y, w, h) .color(rgb(100, 200, 255)) .fill();
fn circle<'a>(&'a mut self, x: Float, y: Float, size: Float) -> Ellipse<'a, Self>
Returns an circle with the given dimensions and position.
use lux::prelude::*; let mut window = Window::new().unwrap(); let mut frame = window.frame(); let (x, y, size) = (0.0, 5.0, 50.0); frame.circle(x, y, size) .color(rgb(100, 200, 255)) .fill();
fn draw_point<C: Color>(&mut self, x: Float, y: Float, color: C)
Draws a 1-pixel colored point to the screen at a position.
This is not the same as setting a "pixel" because the point can be moved by transformations on the Frame.
use lux::prelude::*; let mut window = Window::new().unwrap(); let mut frame = window.frame(); let (x, y) = (10.0, 20.0); frame.draw_point(x, y, lux::color::RED);
fn draw_points(&mut self, pixels: &[ColorVertex])
Draws a sequence of colored points with the size of 1 pixel.
use lux::prelude::*; use lux::graphics::ColorVertex; let mut window = Window::new().unwrap(); let mut frame = window.frame(); let points = [ ColorVertex { pos: [10.0, 15.0], color: rgb(255, 0, 0) }, ColorVertex { pos: [15.0, 10.0], color: rgb(0, 255, 0) }, ]; frame.draw_points(&points[..]);
fn draw_line(&mut self, _x1: Float, _y1: Float, _x2: Float, _y2: Float, _line_size: Float)
Draws a single line from start to end with a
thickness of line_size.
fn draw_lines<I: Iterator<Item=(Float, Float)>>(&mut self, _positions: I, _line_size: Float)
Draws a series of lines from each point to the next with a thickness
of line_size.
fn draw_arc(&mut self, _pos: (Float, Float), _radius: Float, _angle1: Float, _angle2: Float, _line_size: Float)
Draws an arc centered at pos from angle1 to angle_2 with a
thickness of line_size.
fn sprite(&mut self, sprite: &Sprite, x: Float, y: Float) -> ContainedSprite<Self>
Draws a sprite to the screen.
use std::path::Path; use lux::prelude::*; use lux::graphics::ColorVertex; let mut window = Window::new().unwrap(); let mut frame = window.frame(); let logo = window.load_texture_file(&Path::new("./logo.png")) .unwrap() .to_sprite(); let (x, y) = (20.0, 50.0); frame.sprite(&logo, x, y).draw();
Implementors
impl Canvas for Frameimpl<'a, D> Canvas for DrawableTexture<'a, D> where D: HasDisplay + HasPrograms