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) -> Coord

Set the canvas offset in pixels

All drawing commands will be offset by this value

Returns

The previous translate value

source

pub fn with_translate<F>(&mut self, set: Coord, method: F)where F: Fn(&mut Graphics<'_>),

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>(&mut self, xy: P, image: &Image)where P: Into<Coord>,

Draw an image at x, y

source

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

Draw an indexed image at x, y

source

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

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, P2>(&mut self, start: P1, end: P2, color: Color)where P1: Into<Coord>, P2: Into<Coord>,

source

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

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 set_pixel or blend_pixel depending on whether colors alpha is 255 or not If the alpha is 0 the call is does nothing

source

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

Sets every pixel to the same color, this ignores translate and clip

source

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

Sets every pixel to the same color, same as [clear] but this follows translate and clip

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, F>(&mut self, text: &[Vec<u8, Global>], pos: P, format: F)where P: Into<TextPos>, F: Into<TextFormat>,

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

source

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

source

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

source

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

source

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

source

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

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 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>

source§

impl Graphics<'_>

source

pub fn set_clip(&mut self, clip: Clip)

source

pub fn clip(&self) -> &Clip

source

pub fn clip_mut(&mut self) -> &mut Clip

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> AnyToAny for Twhere T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
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.
source§

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

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>