pub struct Graphics<'buffer> {
pub custom_font: HashMap<u8, CustomLetter, BuildHasherDefault<FnvHasher>>,
/* private fields */
}
Fields§
§custom_font: HashMap<u8, CustomLetter, BuildHasherDefault<FnvHasher>>
Allows you to replace any supported ASCII with a custom glyph
To replace ‘a’ with ‘█’ for 4x5 fonts (such as Standard4x5
) write
graphics.custom_font.insert(chr_to_code('a'), CustomLetter { _4x5: [true; 20], ..CustomLetter::default });
Characters are replaced on a size basis, so if _4x4
is provided then all _4x4 fonts will draw this custom character
Whitespace isn’t supported and is skipped when drawing
Note: A-Za-z0-9!@$%^&*(),./;'\\[]<>?:\"{}_+~#…¤£¥¢✓|€
are valid for text::chr_to_code
Implementations§
Source§impl Graphics<'_>
impl Graphics<'_>
Sourcepub fn get_translate(&self) -> Coord
pub fn get_translate(&self) -> Coord
Get the canvas offset in pixels
Sourcepub fn set_translate(&mut self, new_value: Coord) -> Coord
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 translation value
pub fn with_translate<F>(&mut self, set: Coord, method: F)
Sourcepub fn update_translate(&mut self, delta: Coord)
pub fn update_translate(&mut self, delta: Coord)
Adds delta
to the current canvas offset
Sourcepub fn copy_to_image(&self) -> Image
pub fn copy_to_image(&self) -> Image
Copy entire pixels array to an image
Sourcepub fn copy_to_indexed_image(
&self,
simplify_palette: bool,
) -> Result<IndexedImage, GraphicsError>
pub fn copy_to_indexed_image( &self, simplify_palette: bool, ) -> Result<IndexedImage, GraphicsError>
Copy entire pixels array to an indexed image
simplify_palette
if true and there’s more than 255 colours, this will simplify/merge the palette until there are under 255 colours
§Errors
GraphicsError::TooManyColors
Over 255 colors have been used andsimplify_palette
was falseGraphicsError::TooBig
Image is bigger than 255x255GraphicsError::ImageError
Something went wrong creating the IndexedImage
Sourcepub fn get_px_for_char(
col: usize,
row: usize,
font: &PixelFont,
) -> (usize, usize)
pub fn get_px_for_char( col: usize, row: usize, font: &PixelFont, ) -> (usize, usize)
Get top left pixel coord for letter col row
Sourcepub fn draw_image<P>(&mut self, xy: P, image: &Image)
pub fn draw_image<P>(&mut self, xy: P, image: &Image)
Draw an image at x
, y
If the image definitely will draw inside the window you can use [draw_image_unchecked] instead
Sourcepub fn draw_indexed_image<P>(&mut self, xy: P, image: &IndexedImage)
pub fn draw_indexed_image<P>(&mut self, xy: P, image: &IndexedImage)
Draw an indexed image at x
, y
pub fn draw_wrapped_image<P>(&mut self, xy: P, image: &IndexedWrapper)
Sourcepub fn draw_animated_image<P>(&mut self, xy: P, image: &AnimatedIndexedImage)
pub fn draw_animated_image<P>(&mut self, xy: P, image: &AnimatedIndexedImage)
Draw an animated image at x
, y
pub fn draw_arc( &mut self, center: Coord, angle_start: isize, angle_end: isize, radius: usize, close: bool, color: Color, )
pub fn draw_line<P1, P2>(&mut self, start: P1, end: P2, color: Color)
Sourcepub fn draw_offset<T, P>(&mut self, xy: P, renderable: &dyn Renderable<T>)
pub fn draw_offset<T, P>(&mut self, xy: P, renderable: &dyn Renderable<T>)
Draw renderable offset by [xy]
Sourcepub fn draw<T>(&mut self, renderable: &dyn Renderable<T>)
pub fn draw<T>(&mut self, renderable: &dyn Renderable<T>)
Draw renderable
Sourcepub fn get_pixel(
&self,
x: isize,
y: isize,
use_translate: bool,
) -> Option<Color>
pub fn get_pixel( &self, x: isize, y: isize, use_translate: bool, ) -> Option<Color>
Get the RGB values for a pixel Alpha will always be 255
If use_translate
is true then the x,y will be updated with self.translate
§Returns
Some(Color)
if x,y is within bounds
Sourcepub fn clear(&mut self, color: Color)
pub fn clear(&mut self, color: Color)
Set every pixel to color
, this ignores translate and clip
Sourcepub fn clear_aware(&mut self, color: Color)
pub fn clear_aware(&mut self, color: Color)
Set/blend every pixel with color
, same as [clear] but this follows translate and clip
Sourcepub fn draw_letter(
&mut self,
pos: (isize, isize),
chr: char,
font: PixelFont,
color: Color,
)
pub fn draw_letter( &mut self, pos: (isize, isize), chr: char, font: PixelFont, color: Color, )
Sourcepub fn draw_ascii_letter(
&mut self,
pos: (isize, isize),
code: u8,
font: PixelFont,
color: Color,
)
pub fn draw_ascii_letter( &mut self, pos: (isize, isize), code: u8, font: PixelFont, color: Color, )
Shouldn’t be called in normal usage
Sourcepub fn draw_ascii<P, F>(&mut self, text: &[Vec<u8>], pos: P, format: F)
pub fn draw_ascii<P, F>(&mut self, text: &[Vec<u8>], pos: P, format: F)
Should only be used by Text::render
text
param must already be corrected wrapped
Sourcepub fn draw_text<P, F>(&mut self, text: &str, pos: P, format: F)
pub fn draw_text<P, F>(&mut self, text: &str, pos: P, format: F)
Draw text
on screen at pos
using format
§Params
format
See TextFormat, can beTextFormat
Color
(Color, PixelFont)
(Color, PixelFont, Positioning)
(Color, PixelFont, WrappingStrategy, Positioning)
(Color, PixelFont, WrappingStrategy)
(Color, PixelFont, WrappingStrategy, f32)
(f32 = line height)(Color, PixelFont, WrappingStrategy, f32, f32)
(1st f32 = line height, 2nd f32 = char width)(Color, PixelFont, WrappingStrategy, f32, f32, Positioning)
(1st f32 = line height, 2nd f32 = char width)
§Usage
//simple example
graphics.draw_text("Test", TextPos::ColRow(1,1), RED);
//full example
fn draw_message(graphics: &mut Graphics, msg: String) {
let width_in_columns = PixelFont::Standard6x7.get_max_characters(graphics.width(), graphics.height()).0;
graphics.draw_text(&msg, TextPos::px(coord!(8,8)), (BLACK, PixelFont::Standard6x7, WrappingStrategy::AtCol(width_in_columns - 1)));
}
pub fn draw_rect<R>(&mut self, rect: R, draw_type: DrawType)
pub fn draw_circle<C>(&mut self, circle: C, draw_type: DrawType)
pub fn draw_polygon<P>(&mut self, polygon: P, draw_type: DrawType)
pub fn draw_triangle<T>(&mut self, triangle: T, draw_type: DrawType)
pub fn draw_ellipse<E>(&mut self, ellipse: E, draw_type: DrawType)
Source§impl<'buffer> Graphics<'_>
impl<'buffer> Graphics<'_>
Sourcepub fn new_u8_rgba(
buffer: &'buffer mut [u8],
width: usize,
height: usize,
) -> Result<Graphics<'buffer>, GraphicsError>
pub fn new_u8_rgba( buffer: &'buffer mut [u8], width: usize, height: usize, ) -> Result<Graphics<'buffer>, GraphicsError>
buffer
needs to be width * height * 4
long
You can use Graphics::create_buffer_u8 to guarantee the correct size
Sourcepub fn new_u32_rgba(
buffer: &'buffer mut [u32],
width: usize,
height: usize,
) -> Result<Graphics<'buffer>, GraphicsError>
pub fn new_u32_rgba( buffer: &'buffer mut [u32], width: usize, height: usize, ) -> Result<Graphics<'buffer>, GraphicsError>
buffer
needs to be width * height
long
You can use Graphics::create_buffer_u32 to guarantee the correct size
Sourcepub fn new_u32_argb(
buffer: &'buffer mut [u32],
width: usize,
height: usize,
) -> Result<Graphics<'buffer>, GraphicsError>
pub fn new_u32_argb( buffer: &'buffer mut [u32], width: usize, height: usize, ) -> Result<Graphics<'buffer>, GraphicsError>
buffer
needs to be width * height
long
You can use Graphics::create_buffer_u32 to guarantee the correct size
Auto Trait Implementations§
impl<'buffer> Freeze for Graphics<'buffer>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.