Graphics

Struct Graphics 

Source
pub struct Graphics<Api = Default>(/* private fields */);

Implementations§

Source§

impl<Api: Api> Graphics<Api>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_font_height(&self, font: &Font) -> u8

Returns the height of the given font.

Equivalent to sys::ffi::playdate_graphics::getFontHeight.

Source

pub fn set_font(&self, font: &Font)

Sets the font to use in subsequent draw_text calls.

Equivalent to sys::ffi::playdate_graphics::setFont.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn set_text_tracking(&self, tracking: c_int)

Sets the tracking to use when drawing text.

Equivalent to sys::ffi::playdate_graphics::setTextTracking.

Source

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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source

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.

Source

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.

Source

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_x and center_y are both 0.5 the center of the image is at (x,y),
  • if center_x and center_y are both 0 the top left corner of the image (before rotation) is at (x,y), etc.

Equivalent to sys::ffi::playdate_graphics::drawRotatedBitmap.

Source

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>

Source

pub fn video(&self) -> Video<Cache>

Creates a new Video instance with cached api.

Equivalent to sys::ffi::playdate_graphics::video

Source

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>

Source

pub fn Default() -> Self

Creates default Graphics without type parameter requirement.

Uses ZST api::Default.

Source§

impl Graphics<Cache>

Source

pub fn Cached() -> Self

Creates Graphics without type parameter requirement.

Uses api::Cache.

Source§

impl<Api: Default + Api> Graphics<Api>

Source

pub fn new() -> Self

Source§

impl<Api: Api> Graphics<Api>

Source

pub fn new_with(api: Api) -> Self

Source§

impl<Api: Api> Graphics<Api>

Source

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

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&self, color: Color<'_>)

Clears the entire display, filling it with color.

Equivalent to sys::ffi::playdate_graphics::clear.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear_clip_rect(&self)

Clears the current clip rect.

Equivalent to sys::ffi::playdate_graphics::clearClipRect.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl<Api: Clone> Clone for Graphics<Api>

Source§

fn clone(&self) -> Graphics<Api>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Api: Debug> Debug for Graphics<Api>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Api: Default + Api> Default for Graphics<Api>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
§

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

Performs the conversion.
§

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

§

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

The type returned in the event of a conversion error.
§

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

Performs the conversion.

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.