Struct buffer_graphics_lib::Graphics
source · pub struct Graphics<'buffer> {
pub custom_font: FnvHashMap<u8, CustomLetter>,
/* private fields */
}
Fields§
§custom_font: FnvHashMap<u8, CustomLetter>
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 translate value
pub fn with_translate<F: Fn(&mut Graphics<'_>)>( &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_unchecked<P: Into<Coord>>(&mut self, xy: P, image: &Image)
pub fn draw_image_unchecked<P: Into<Coord>>(&mut self, xy: P, image: &Image)
Draw an image at x
, y
as fast as possible
If the image may draw outside the window you must use [draw_image] instead
Ignores clipping and translation for opaque images
sourcepub fn draw_image<P: Into<Coord>>(&mut self, xy: P, image: &Image)
pub fn draw_image<P: Into<Coord>>(&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: Into<Coord>>(
&mut self,
xy: P,
image: &IndexedImage
)
pub fn draw_indexed_image<P: Into<Coord>>( &mut self, xy: P, image: &IndexedImage )
Draw an indexed image at x
, y
pub fn draw_wrapped_image<P: Into<Coord>>( &mut self, xy: P, image: &IndexedWrapper )
sourcepub fn draw_animated_image<P: Into<Coord>>(
&mut self,
xy: P,
image: &AnimatedIndexedImage
)
pub fn draw_animated_image<P: Into<Coord>>( &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: Into<Coord>, P2: Into<Coord>>( &mut self, start: P1, end: P2, color: Color )
sourcepub fn draw_offset<T, P: Into<Coord>>(
&mut self,
xy: P,
renderable: &dyn Renderable<T>
)
pub fn draw_offset<T, P: Into<Coord>>( &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(
&mut self,
x: isize,
y: isize,
use_translate: bool
) -> Option<Color>
pub fn get_pixel( &mut 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 than the x,y will be updated with self.translate
Although the method takes &mut self
it doesn’t mutate anything
sourcepub fn clear(&mut self, color: Color)
pub fn clear(&mut self, color: Color)
Sets every pixel to the same color, this ignores translate and clip
sourcepub fn clear_aware(&mut self, color: Color)
pub fn clear_aware(&mut self, color: Color)
Sets every pixel to the same 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 )
Draw a letter at pos
pub fn draw_ascii_letter( &mut self, pos: (isize, isize), code: u8, font: PixelFont, color: Color )
sourcepub fn draw_ascii<P: Into<TextPos>, F: Into<TextFormat>>(
&mut self,
text: &[Vec<u8>],
pos: P,
format: F
)
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