pub struct Graphics<'buffer> { /* private fields */ }

Implementations§

source§

impl Graphics<'_>

source

pub fn index(&self, x: usize, y: usize) -> usize

Convert an x,y coord to idx for use with self.pixels

source

pub fn width(&self) -> usize

source

pub fn height(&self) -> usize

source

pub fn is_on_screen(&self, point: Coord) -> bool

source§

impl Graphics<'_>

source

pub fn get_translate(&self) -> Coord

Get the canvas offset in pixels

source

pub fn set_translate(&mut self, new_value: Coord)

Set the canvas offset in pixels

All drawing commands will be offset by this value

source

pub fn update_translate(&mut self, delta: Coord)

Adds delta to the current canvas offset

source

pub fn copy_to_image(&self) -> Image

Copy entire pixels array to an image

source

pub fn get_px_for_char(x: usize, y: usize, size: TextSize) -> (usize, usize)

Get top left pixel coord for letter px coord

source

pub fn get_text_size(text: &str, width: usize, size: TextSize) -> (usize, usize)

Get width and height for string

Arguments
  • text - The string to be measured
  • width - The line width in characters
  • size - The text size to use when measuring
Returns

The width and height of the string in pixels

source

pub fn draw_image<P: Into<Coord>>(&mut self, xy: P, image: &Image)

Draw an image at x, y

source

pub fn draw_indexed_image<P: Into<Coord>>(&mut self, xy: P, image: &IndexedImage)

Draw an indexed image at x, y

source

pub fn draw_animated_image<P: Into<Coord>>( &mut self, xy: P, image: &AnimatedIndexedImage )

Draw an animated image at x, y

source

pub fn draw_arc( &mut self, center: Coord, angle_start: isize, angle_end: isize, radius: usize, close: bool, color: Color )

source

pub fn draw_line<P1: Into<Coord>, P2: Into<Coord>>( &mut self, start: P1, end: P2, color: Color )

source

pub fn draw_offset<T, P: Into<Coord>>( &mut self, xy: P, renderable: &dyn Renderable<T> )

Draw renderable offset by [xy]

source

pub fn draw<T>(&mut self, renderable: &dyn Renderable<T>)

Draw renderable

source

pub fn update_pixel(&mut self, x: isize, y: isize, color: Color)

Update a pixel color, using Graphics::set_pixel or Graphics::blend_pixel depending on whether colors alpha is 255 or not

source

pub fn clear(&mut self, color: Color)

Sets every pixel to the same color, this ignores translate

source

pub fn draw_letter( &mut self, pos: (isize, isize), chr: char, size: TextSize, color: Color )

Draw a letter at pos

source

pub fn draw_ascii_letter( &mut self, pos: (isize, isize), code: u8, size: TextSize, color: Color )

source

pub fn draw_ascii<P: Into<TextPos>, F: Into<TextFormat>>( &mut self, text: &[Vec<u8>], pos: P, format: F )

Should only be used by Text::render text param must already be corrected wrapped

source

pub fn draw_text<P: Into<TextPos>, F: Into<TextFormat>>( &mut self, text: &str, pos: P, format: F )

source

pub fn draw_rect<R: Into<Rect>>(&mut self, rect: R, draw_type: DrawType)

source

pub fn draw_circle<C: Into<Circle>>(&mut self, circle: C, draw_type: DrawType)

source

pub fn draw_polygon<P: Into<Polygon>>(&mut self, polygon: P, draw_type: DrawType)

source

pub fn draw_triangle<T: Into<Triangle>>( &mut self, triangle: T, draw_type: DrawType )

source

pub fn draw_ellipse<E: Into<Ellipse>>(&mut self, ellipse: E, draw_type: DrawType)

source

pub fn blend_pixel(&mut self, x: isize, y: isize, color: Color)

Set the RGB values for a pixel by blending it with the provided color This method uses alpha blending, note that the canvas pixels always have 255 alpha

source

pub fn set_pixel(&mut self, x: isize, y: isize, color: Color)

Set the RGB values for a pixel

Generally you should use Graphics::update_pixel instead

This ignores alpha, so 255,0,0,0 will draw a red pixel

source§

impl<'buffer> Graphics<'_>

source

pub fn new( buffer: &'buffer mut [u8], width: usize, height: usize ) -> Result<Graphics<'buffer>, GraphicsError>

source

pub fn new_unchecked( buffer: &'buffer mut [u8], width: usize, height: usize ) -> Graphics<'buffer>

Auto Trait Implementations§

§

impl<'buffer> RefUnwindSafe for Graphics<'buffer>

§

impl<'buffer> Send for Graphics<'buffer>

§

impl<'buffer> Sync for Graphics<'buffer>

§

impl<'buffer> Unpin for Graphics<'buffer>

§

impl<'buffer> !UnwindSafe for Graphics<'buffer>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.