pub struct Graphics<Api = Default>(/* private fields */);Implementations§
Source§impl<Api: Api> Graphics<Api>
impl<Api: Api> Graphics<Api>
Sourcepub fn draw_text<S: AsRef<str>>(
&self,
text: S,
x: c_int,
y: c_int,
) -> Result<c_int, NulError>
pub fn draw_text<S: AsRef<str>>( &self, text: S, x: c_int, y: c_int, ) -> Result<c_int, NulError>
Draws the given text using the provided coords x, y.
Encoding is always StringEncoding::UTF8.
If another encoding is desired, use draw_text_cstr instead.
If no font has been set with set_font,
the default system font Asheville Sans 14 Light is used.
Equivalent to sys::ffi::playdate_graphics::drawText.
Sourcepub fn draw_text_cstr(
&self,
text: &CStr,
encoding: StringEncoding,
x: c_int,
y: c_int,
) -> c_int
pub fn draw_text_cstr( &self, text: &CStr, encoding: StringEncoding, x: c_int, y: c_int, ) -> c_int
Draws the given text using the provided options.
If no font has been set with set_font,
the default system font Asheville Sans 14 Light is used.
Same as draw_text but takes a [sys::ffi::CStr],
but little bit more efficient.
Equivalent to sys::ffi::playdate_graphics::drawText.
Sourcepub fn draw_text_in_rect<S: AsRef<str>>(
&self,
text: S,
x: c_int,
y: c_int,
width: c_int,
height: c_int,
wrap: TextWrappingMode,
align: TextAlignment,
) -> Result<(), NulError>
pub fn draw_text_in_rect<S: AsRef<str>>( &self, text: S, x: c_int, y: c_int, width: c_int, height: c_int, wrap: TextWrappingMode, align: TextAlignment, ) -> Result<(), NulError>
Draws the text in the given rectangle using the provided options.
If no font has been set with set_font,
the default system font `Asheville Sans 14 Light`` is used.
Equivalent to sys::ffi::playdate_graphics::drawTextInRect.
Sourcepub fn get_text_width<S: AsRef<str>>(
&self,
text: S,
font: Option<&Font>,
tracking: c_int,
) -> Result<c_int, NulError>
pub fn get_text_width<S: AsRef<str>>( &self, text: S, font: Option<&Font>, tracking: c_int, ) -> Result<c_int, NulError>
Returns the width of the given text in the given font.
Equivalent to sys::ffi::playdate_graphics::getTextWidth.
Sourcepub fn get_text_width_cstr(
&self,
text: &CStr,
encoding: StringEncoding,
font: Option<&Font>,
tracking: c_int,
) -> c_int
pub fn get_text_width_cstr( &self, text: &CStr, encoding: StringEncoding, font: Option<&Font>, tracking: c_int, ) -> c_int
Returns the width of the given text in the given font.
Same as get_text_width but takes a [sys::ffi::CStr],
but little bit more efficient.
Equivalent to sys::ffi::playdate_graphics::getTextWidth.
Sourcepub fn get_font_height(&self, font: &Font) -> u8
pub fn get_font_height(&self, font: &Font) -> u8
Returns the height of the given font.
Equivalent to sys::ffi::playdate_graphics::getFontHeight.
Sourcepub fn set_font(&self, font: &Font)
pub fn set_font(&self, font: &Font)
Sets the font to use in subsequent draw_text calls.
Equivalent to sys::ffi::playdate_graphics::setFont.
Sourcepub fn get_glyph_kerning(
&self,
glyph: &Glyph,
glyph_code: u32,
next_code: u32,
) -> c_int
pub fn get_glyph_kerning( &self, glyph: &Glyph, glyph_code: u32, next_code: u32, ) -> c_int
Returns the kerning adjustment between characters glyph_code and next_code as specified by the font
Equivalent to sys::ffi::playdate_graphics::getGlyphKerning.
Sourcepub fn get_page_glyph(&self, page: &FontPage, c: u32) -> Result<Glyph, Error>
pub fn get_page_glyph(&self, page: &FontPage, c: u32) -> Result<Glyph, Error>
Returns an Glyph object for character c in FontPage page,
To also get the glyph’s bitmap and advance value
use get_page_glyph_with_bitmap instead.
Equivalent to sys::ffi::playdate_graphics::getPageGlyph.
Sourcepub fn get_page_glyph_with_bitmap<'p>(
&self,
page: &'p FontPage,
c: u32,
advance: &mut c_int,
) -> Result<(Glyph, BitmapRef<'p>), Error>
pub fn get_page_glyph_with_bitmap<'p>( &self, page: &'p FontPage, c: u32, advance: &mut c_int, ) -> Result<(Glyph, BitmapRef<'p>), Error>
Returns an Glyph object for character c in FontPage page,
and optionally returns the glyph’s bitmap and advance value.
If bitmap is not needed, use get_page_glyph instead.
Equivalent to sys::ffi::playdate_graphics::getPageGlyph.
Sourcepub fn get_font_page(&self, font: &Font, c: u32) -> Result<FontPage, Error>
pub fn get_font_page(&self, font: &Font, c: u32) -> Result<FontPage, Error>
Returns an FontPage object for the given character code c.
Each FontPage contains information for 256 characters;
specifically, if (c1 & ~0xff) == (c2 & ~0xff),
then c1 and c2 belong to the same page and the same FontPage
can be used to fetch the character data for both instead of searching for the page twice.
Equivalent to sys::ffi::playdate_graphics::getFontPage.
Sourcepub fn load_font<P: AsRef<Path>>(&self, path: P) -> Result<Font, ApiError>
pub fn load_font<P: AsRef<Path>>(&self, path: P) -> Result<Font, ApiError>
Returns the Font object for the font file at path.
Equivalent to sys::ffi::playdate_graphics::loadFont.
Sourcepub fn make_font_from_bytes(
&self,
data: &[u8],
wide: c_int,
) -> Result<Font, Error>
pub fn make_font_from_bytes( &self, data: &[u8], wide: c_int, ) -> Result<Font, Error>
⚠️ Caution: This function is not tested.
Returns an Font object wrapping the LCDFontData data
comprising the contents (minus 16-byte header) of an uncompressed pft file.
The wide corresponds to the flag in the header indicating
whether the font contains glyphs at codepoints above U+1FFFF.
Equivalent to sys::ffi::playdate_graphics::makeFontFromData.
Sourcepub fn set_text_leading(&self, line_height_adjustment: c_int)
pub fn set_text_leading(&self, line_height_adjustment: c_int)
Sets the leading adjustment (added to the leading specified in the font) to use when drawing text.
Equivalent to sys::ffi::playdate_graphics::setTextLeading.
Sourcepub fn set_text_tracking(&self, tracking: c_int)
pub fn set_text_tracking(&self, tracking: c_int)
Sets the tracking to use when drawing text.
Equivalent to sys::ffi::playdate_graphics::setTextTracking.
Sourcepub fn get_text_tracking(&self) -> c_int
pub fn get_text_tracking(&self) -> c_int
Sets the tracking to use when drawing text.
Equivalent to sys::ffi::playdate_graphics::getTextTracking.
Source§impl<Api: Api> Graphics<Api>
impl<Api: Api> Graphics<Api>
Sourcepub fn debug_bitmap(&self) -> Result<Bitmap<Default, false>, ApiError>
pub fn debug_bitmap(&self) -> Result<Bitmap<Default, false>, ApiError>
Only valid in the Simulator, returns the debug framebuffer as a bitmap.
Returns error on device.
Equivalent to sys::ffi::playdate_graphics::getDebugBitmap.
Sourcepub fn display_buffer_bitmap(&self) -> Result<Bitmap<Default, false>, Error>
pub fn display_buffer_bitmap(&self) -> Result<Bitmap<Default, false>, Error>
Returns a bitmap containing the contents of the display buffer.
The system owns this bitmap—do not free it.
Equivalent to sys::ffi::playdate_graphics::getDisplayBufferBitmap.
Sourcepub fn frame_buffer_bitmap(&self) -> Result<Bitmap<Default, true>, Error>
pub fn frame_buffer_bitmap(&self) -> Result<Bitmap<Default, true>, Error>
Returns a copy the contents of the working frame buffer as a bitmap.
The caller is responsible for freeing the returned bitmap, it will automatically on drop.
Equivalent to sys::ffi::playdate_graphics::copyFrameBufferBitmap.
Sourcepub fn set_stencil_tiled(&self, image: &impl AnyBitmap, tile: bool)
pub fn set_stencil_tiled(&self, image: &impl AnyBitmap, tile: bool)
Sets the stencil used for drawing.
If the tile is true the stencil image will be tiled.
Tiled stencils must have width equal to a multiple of 32 pixels.
Equivalent to sys::ffi::playdate_graphics::setStencilImage.
Sourcepub fn set_stencil(&self, image: &impl AnyBitmap)
pub fn set_stencil(&self, image: &impl AnyBitmap)
Sets the stencil used for drawing.
For a tiled stencil, use set_stencil_tiled instead.
NOTE: Officially deprecated in favor of set_stencil_tiled, which adds a tile flag
Equivalent to sys::ffi::playdate_graphics::setStencil.
Sourcepub fn set_draw_mode(&self, mode: BitmapDrawMode) -> BitmapDrawMode
pub fn set_draw_mode(&self, mode: BitmapDrawMode) -> BitmapDrawMode
Sets the mode used for drawing bitmaps.
Returns the previous draw mode.
Note that text drawing uses bitmaps, so this affects how fonts are displayed as well.
Equivalent to sys::ffi::playdate_graphics::setDrawMode.
Sourcepub fn push_context(&self, target: &impl AnyBitmap)
pub fn push_context(&self, target: &impl AnyBitmap)
Push a new drawing context for drawing into the given bitmap.
If target is BitmapRef::null(), the drawing functions will use the display framebuffer.
To push framebuffer to context use Graphics::push_framebuffer_to_context.
Equivalent to sys::ffi::playdate_graphics::pushContext.
Sourcepub fn push_framebuffer_to_context(&self)
pub fn push_framebuffer_to_context(&self)
Push a new drawing context for drawing into the display framebuffer.
Equivalent to sys::ffi::playdate_graphics::pushContext.
Sourcepub fn pop_context(&self)
pub fn pop_context(&self)
Pops a context off the stack (if any are left), restoring the drawing settings from before the context was pushed.
Equivalent to sys::ffi::playdate_graphics::popContext.
Source§impl<Api: Api> Graphics<Api>
impl<Api: Api> Graphics<Api>
Sourcepub fn draw(
&self,
bitmap: &impl AnyBitmap,
x: c_int,
y: c_int,
flip: BitmapFlip,
)
pub fn draw( &self, bitmap: &impl AnyBitmap, x: c_int, y: c_int, flip: BitmapFlip, )
Draws self with its upper-left corner at location x, y,
using the given flip orientation.
Equivalent to sys::ffi::playdate_graphics::drawBitmap.
Sourcepub fn draw_tiled(
&self,
bitmap: &impl AnyBitmap,
x: c_int,
y: c_int,
width: c_int,
height: c_int,
flip: BitmapFlip,
)
pub fn draw_tiled( &self, bitmap: &impl AnyBitmap, x: c_int, y: c_int, width: c_int, height: c_int, flip: BitmapFlip, )
Draws self with its upper-left corner at location x, y
tiled inside a width by height rectangle.
Equivalent to sys::ffi::playdate_graphics::tileBitmap.
Sourcepub fn draw_rotated(
&self,
bitmap: &impl AnyBitmap,
x: c_int,
y: c_int,
degrees: c_float,
center_x: c_float,
center_y: c_float,
x_scale: c_float,
y_scale: c_float,
)
pub fn draw_rotated( &self, bitmap: &impl AnyBitmap, x: c_int, y: c_int, degrees: c_float, center_x: c_float, center_y: c_float, x_scale: c_float, y_scale: c_float, )
Draws the bitmap scaled to x_scale and y_scale
then rotated by degrees with its center as given by proportions center_x and center_y at x, y;
that is:
- if
center_xandcenter_yare both 0.5 the center of the image is at (x,y), - if
center_xandcenter_yare both 0 the top left corner of the image (before rotation) is at (x,y), etc.
Equivalent to sys::ffi::playdate_graphics::drawRotatedBitmap.
Sourcepub fn draw_scaled(
&self,
bitmap: &impl AnyBitmap,
x: c_int,
y: c_int,
x_scale: c_float,
y_scale: c_float,
)
pub fn draw_scaled( &self, bitmap: &impl AnyBitmap, x: c_int, y: c_int, x_scale: c_float, y_scale: c_float, )
Draws this bitmap scaled to x_scale and y_scale with its upper-left corner at location x, y.
Note that flip is not available when drawing scaled bitmaps but negative scale values will achieve the same effect.
Equivalent to sys::ffi::playdate_graphics::drawScaledBitmap.
Source§impl<Api: Api> Graphics<Api>
impl<Api: Api> Graphics<Api>
Sourcepub fn video(&self) -> Video<Cache>
pub fn video(&self) -> Video<Cache>
Creates a new Video instance with cached api.
Equivalent to sys::ffi::playdate_graphics::video
Sourcepub fn video_with<VideoApi: Api>(&self, api: VideoApi) -> Video<VideoApi>
pub fn video_with<VideoApi: Api>(&self, api: VideoApi) -> Video<VideoApi>
Creates a new Video instance using given api.
Equivalent to sys::ffi::playdate_graphics::video
Source§impl Graphics<Default>
impl Graphics<Default>
Sourcepub fn Default() -> Self
pub fn Default() -> Self
Creates default Graphics without type parameter requirement.
Uses ZST api::Default.
Source§impl Graphics<Cache>
impl Graphics<Cache>
Sourcepub fn Cached() -> Self
pub fn Cached() -> Self
Creates Graphics without type parameter requirement.
Uses api::Cache.
Source§impl<Api: Api> Graphics<Api>
impl<Api: Api> Graphics<Api>
Sourcepub fn set_pixel(&self, x: c_int, y: c_int, color: Color<'_>)
pub fn set_pixel(&self, x: c_int, y: c_int, color: Color<'_>)
Sets the pixel at (x,y) in the current drawing context (by default the screen) to the given color.
Be aware that setting a pixel at a time is not very efficient:
In our testing, more than around 20,000 calls in a tight loop will drop the frame rate below 30 fps.
Equivalent to sys::ffi::playdate_graphics::setPixel
Sourcepub fn set_pixel_raw(&self, x: c_int, y: c_int, color: LCDColor)
pub fn set_pixel_raw(&self, x: c_int, y: c_int, color: LCDColor)
Same as set_pixel, but without conversion Color -> LCDColor.
Equivalent to sys::ffi::playdate_graphics::setPixel
Sourcepub fn get_frame(&self) -> Result<&'static mut [u8], ApiError>
pub fn get_frame(&self) -> Result<&'static mut [u8], ApiError>
Returns the current display frame buffer. Rows are 32-bit aligned, so the row stride is 52 bytes, with the extra 2 bytes per row ignored. Bytes are MSB-ordered; i.e., the pixel in column 0 is the 0x80 bit of the first byte of the row.
Equivalent to sys::ffi::playdate_graphics::getFrame.
Sourcepub fn get_display_frame(&self) -> Result<&'static mut [u8], ApiError>
pub fn get_display_frame(&self) -> Result<&'static mut [u8], ApiError>
Returns the raw bits in the display buffer, the last completed frame.
Equivalent to sys::ffi::playdate_graphics::getDisplayFrame.
Sourcepub fn mark_updated_rows(&self, start: c_int, end: c_int)
pub fn mark_updated_rows(&self, start: c_int, end: c_int)
After updating pixels in the buffer returned by get_frame,
you must tell the graphics system which rows were updated.
This function marks a contiguous range of rows as updated
(e.g., markUpdatedRows(0, LCD_ROWS-1) tells the system to update the entire display).
Both start and end are included in the range.
Equivalent to sys::ffi::playdate_graphics::markUpdatedRows.
Sourcepub fn display(&self)
pub fn display(&self)
Manually flushes the current frame buffer out to the display. This function is automatically called after each pass through the run loop, so there shouldn’t be any need to call it yourself.
Equivalent to sys::ffi::playdate_graphics::display.
Sourcepub fn clear(&self, color: Color<'_>)
pub fn clear(&self, color: Color<'_>)
Clears the entire display, filling it with color.
Equivalent to sys::ffi::playdate_graphics::clear.
Sourcepub fn clear_raw(&self, color: LCDColor)
pub fn clear_raw(&self, color: LCDColor)
Clears the entire display, filling it with color.
Same as clear, but without conversion Color -> LCDColor.
That conversion is really cheap,
so this function is useful if you’re working with LCDColor directly.
Equivalent to sys::ffi::playdate_graphics::clear.
Sourcepub fn set_screen_clip_rect(
&self,
x: c_int,
y: c_int,
width: c_int,
height: c_int,
)
pub fn set_screen_clip_rect( &self, x: c_int, y: c_int, width: c_int, height: c_int, )
Sets the current clip rect in screen coordinates.
Equivalent to sys::ffi::playdate_graphics::setScreenClipRect.
Sourcepub fn set_draw_offset(&self, dx: c_int, dy: c_int)
pub fn set_draw_offset(&self, dx: c_int, dy: c_int)
Offsets the origin point for all drawing calls to x, y (can be negative).
This is useful, for example, for centering a “camera” on a sprite that is moving around a world larger than the screen.
Equivalent to sys::ffi::playdate_graphics::setDrawOffset.
Sourcepub fn set_clip_rect(&self, x: c_int, y: c_int, width: c_int, height: c_int)
pub fn set_clip_rect(&self, x: c_int, y: c_int, width: c_int, height: c_int)
Sets the current clip rect, using world coordinates that is, the given rectangle will be translated by the current drawing offset.
The clip rect is cleared at the beginning of each update.
Equivalent to sys::ffi::playdate_graphics::setClipRect.
Sourcepub fn clear_clip_rect(&self)
pub fn clear_clip_rect(&self)
Clears the current clip rect.
Equivalent to sys::ffi::playdate_graphics::clearClipRect.
Sourcepub fn set_background_color(&self, color: LCDSolidColor)
pub fn set_background_color(&self, color: LCDSolidColor)
Sets the background color shown when the display is offset or for clearing dirty areas in the sprite system.
Equivalent to sys::ffi::playdate_graphics::setBackgroundColor.
Sourcepub fn fill_polygon(
&self,
num_points: c_int,
coords: &mut [c_int],
color: LCDColor,
rule: LCDPolygonFillRule,
)
pub fn fill_polygon( &self, num_points: c_int, coords: &mut [c_int], color: LCDColor, rule: LCDPolygonFillRule, )
Fills the polygon with vertices at the given coordinates
(an array of 2 * num_points ints containing alternating x and y values)
using the given color and fill, or winding, rule.
See wikipedia for an explanation of the winding rule.
Equivalent to sys::ffi::playdate_graphics::fillPolygon.
Sourcepub fn draw_line(
&self,
x1: c_int,
y1: c_int,
x2: c_int,
y2: c_int,
width: c_int,
color: LCDColor,
)
pub fn draw_line( &self, x1: c_int, y1: c_int, x2: c_int, y2: c_int, width: c_int, color: LCDColor, )
Draws a line from x1, y1 to x2, y2 with a stroke width of width.
Equivalent to sys::ffi::playdate_graphics::drawLine.
Sourcepub fn fill_triangle(
&self,
x1: c_int,
y1: c_int,
x2: c_int,
y2: c_int,
x3: c_int,
y3: c_int,
color: LCDColor,
)
pub fn fill_triangle( &self, x1: c_int, y1: c_int, x2: c_int, y2: c_int, x3: c_int, y3: c_int, color: LCDColor, )
Draws a filled triangle with points at x1, y1, x2, y2, and x3, y3.
Equivalent to sys::ffi::playdate_graphics::fillTriangle.
Sourcepub fn draw_rect(
&self,
x: c_int,
y: c_int,
width: c_int,
height: c_int,
color: LCDColor,
)
pub fn draw_rect( &self, x: c_int, y: c_int, width: c_int, height: c_int, color: LCDColor, )
Draws a width by height rect at x, y.
Equivalent to sys::ffi::playdate_graphics::drawRect.
Sourcepub fn fill_rect(
&self,
x: c_int,
y: c_int,
width: c_int,
height: c_int,
color: LCDColor,
)
pub fn fill_rect( &self, x: c_int, y: c_int, width: c_int, height: c_int, color: LCDColor, )
Draws a filled width by height rect at x, y.
Equivalent to sys::ffi::playdate_graphics::fillRect.
Sourcepub fn draw_ellipse(
&self,
x: c_int,
y: c_int,
width: c_int,
height: c_int,
line_width: c_int,
start_angle: c_float,
end_angle: c_float,
color: LCDColor,
)
pub fn draw_ellipse( &self, x: c_int, y: c_int, width: c_int, height: c_int, line_width: c_int, start_angle: c_float, end_angle: c_float, color: LCDColor, )
Draw an ellipse stroked inside the rect.
Draws an ellipse inside the rectangle x, y, width, height of width line_width
(inset from the rectangle bounds).
If start_angle != end_angle, this draws an arc between the given angles.
Angles are given in degrees, clockwise from due north.
Equivalent to sys::ffi::playdate_graphics::drawEllipse.
Sourcepub fn fill_ellipse(
&self,
x: c_int,
y: c_int,
width: c_int,
height: c_int,
start_angle: c_float,
end_angle: c_float,
color: LCDColor,
)
pub fn fill_ellipse( &self, x: c_int, y: c_int, width: c_int, height: c_int, start_angle: c_float, end_angle: c_float, color: LCDColor, )
Fills an ellipse inside the rectangle x, y, width, height.
If start_angle != end_angle, this draws a wedge/Pacman between the given angles.
Angles are given in degrees, clockwise from due north.
Equivalent to sys::ffi::playdate_graphics::fillEllipse.
Sourcepub fn set_line_cap_style(&self, end_cap_style: LineCapStyle)
pub fn set_line_cap_style(&self, end_cap_style: LineCapStyle)
Sets the end cap style used in the line drawing functions.
Equivalent to sys::ffi::playdate_graphics::setLineCapStyle.
Trait Implementations§
impl<Api: Copy> Copy for Graphics<Api>
Auto Trait Implementations§
impl<Api> Freeze for Graphics<Api>where
Api: Freeze,
impl<Api> RefUnwindSafe for Graphics<Api>where
Api: RefUnwindSafe,
impl<Api> Send for Graphics<Api>where
Api: Send,
impl<Api> Sync for Graphics<Api>where
Api: Sync,
impl<Api> Unpin for Graphics<Api>where
Api: Unpin,
impl<Api> UnwindSafe for Graphics<Api>where
Api: UnwindSafe,
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
§impl<T> ToOwned for Twhere
T: Clone,
impl<T> ToOwned for Twhere
T: Clone,
§impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.