Struct playdate_rs::graphics::Graphics
source · pub struct Graphics {
pub video: Video,
/* private fields */
}Fields§
§video: VideoImplementations§
source§impl Graphics
impl Graphics
sourcepub fn clear(&self, color: impl Into<LCDColor>)
pub fn clear(&self, color: impl Into<LCDColor>)
Clears the entire display, filling it with color.
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.
sourcepub fn set_stencil(&self, stencil: &Bitmap)
pub fn set_stencil(&self, stencil: &Bitmap)
Sets the stencil used for drawing. For a tiled stencil, use setStencilImage() instead.
sourcepub fn set_draw_mode(&self, mode: LCDBitmapDrawMode)
pub fn set_draw_mode(&self, mode: LCDBitmapDrawMode)
Sets the mode used for drawing bitmaps. Note that text drawing uses bitmaps, so this affects how fonts are displayed as well.
sourcepub fn set_draw_offset(&self, dx: i32, dy: i32)
pub fn set_draw_offset(&self, dx: i32, dy: i32)
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.
sourcepub fn set_clip_rect(&self, x: i32, y: i32, width: i32, height: i32)
pub fn set_clip_rect(&self, x: i32, y: i32, width: i32, height: i32)
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.
sourcepub fn clear_clip_rect(&self)
pub fn clear_clip_rect(&self)
Clears the current clip rect.
sourcepub fn set_line_cap_style(&self, end_cap_style: LCDLineCapStyle)
pub fn set_line_cap_style(&self, end_cap_style: LCDLineCapStyle)
Sets the end cap style used in the line drawing functions.
sourcepub fn set_text_tracking(&self, tracking: i32)
pub fn set_text_tracking(&self, tracking: i32)
Sets the tracking to use when drawing text.
sourcepub fn push_context(&self, target: &Bitmap)
pub fn push_context(&self, target: &Bitmap)
Push a new drawing context for drawing into the given bitmap. If target is nil, the drawing functions will use the display framebuffer.
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.
sourcepub fn draw_bitmap(&self, bitmap: &Bitmap, x: i32, y: i32, flip: LCDBitmapFlip)
pub fn draw_bitmap(&self, bitmap: &Bitmap, x: i32, y: i32, flip: LCDBitmapFlip)
Draws the bitmap with its upper-left corner at location x, y, using the given flip orientation.
sourcepub fn tile_bitmap(
&self,
bitmap: &Bitmap,
x: i32,
y: i32,
width: i32,
height: i32,
flip: LCDBitmapFlip
)
pub fn tile_bitmap( &self, bitmap: &Bitmap, x: i32, y: i32, width: i32, height: i32, flip: LCDBitmapFlip )
Draws the bitmap with its upper-left corner at location x, y tiled inside a width by height rectangle.
sourcepub fn draw_line(
&self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
width: i32,
color: impl Into<LCDColor>
)
pub fn draw_line( &self, x1: i32, y1: i32, x2: i32, y2: i32, width: i32, color: impl Into<LCDColor> )
Draws a line from x1, y1 to x2, y2 with a stroke width of width.
sourcepub fn fill_triangle(
&self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
x3: i32,
y3: i32,
color: impl Into<LCDColor>
)
pub fn fill_triangle( &self, x1: i32, y1: i32, x2: i32, y2: i32, x3: i32, y3: i32, color: impl Into<LCDColor> )
Draws a filled triangle with points at x1, y1, x2, y2, and x3, y3.
sourcepub fn draw_pixel(&self, x: i32, y: i32, color: LCDSolidColor)
pub fn draw_pixel(&self, x: i32, y: i32, color: LCDSolidColor)
Draws a pixel at x, y.
sourcepub fn draw_rect(
&self,
x: i32,
y: i32,
width: i32,
height: i32,
color: impl Into<LCDColor>
)
pub fn draw_rect( &self, x: i32, y: i32, width: i32, height: i32, color: impl Into<LCDColor> )
Draws a width by height rect at x, y.
sourcepub fn fill_rect(
&self,
x: i32,
y: i32,
width: i32,
height: i32,
color: impl Into<LCDColor>
)
pub fn fill_rect( &self, x: i32, y: i32, width: i32, height: i32, color: impl Into<LCDColor> )
Draws a filled width by height rect at x, y.
sourcepub fn draw_ellipse(
&self,
x: i32,
y: i32,
width: i32,
height: i32,
line_width: i32,
start_angle: f32,
end_angle: f32,
color: impl Into<LCDColor>
)
pub fn draw_ellipse( &self, x: i32, y: i32, width: i32, height: i32, line_width: i32, start_angle: f32, end_angle: f32, color: impl Into<LCDColor> )
Draws an ellipse inside the rectangle {x, y, width, height} of width lineWidth (inset from the rectangle bounds). If startAngle != _endAngle, this draws an arc between the given angles. Angles are given in degrees, clockwise from due north.
sourcepub fn fill_ellipse(
&self,
x: i32,
y: i32,
width: i32,
height: i32,
start_angle: f32,
end_angle: f32,
color: impl Into<LCDColor>
)
pub fn fill_ellipse( &self, x: i32, y: i32, width: i32, height: i32, start_angle: f32, end_angle: f32, color: impl Into<LCDColor> )
Fills an ellipse inside the rectangle {x, y, width, height}. If startAngle != _endAngle, this draws a wedge/Pacman between the given angles. Angles are given in degrees, clockwise from due north.
sourcepub fn draw_scaled_bitmap(
&self,
bitmap: &Bitmap,
x: i32,
y: i32,
xscale: f32,
yscale: f32
)
pub fn draw_scaled_bitmap( &self, bitmap: &Bitmap, x: i32, y: i32, xscale: f32, yscale: f32 )
Draws the bitmap scaled to xscale and yscale 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.
sourcepub fn draw_text(&self, text: impl AsRef<str>, x: i32, y: i32) -> i32
pub fn draw_text(&self, text: impl AsRef<str>, x: i32, y: i32) -> i32
Draws the given text using the provided options. If no font has been set with setFont, the default system font Asheville Sans 14 Light is used.
sourcepub fn new_bitmap(
&self,
width: i32,
height: i32,
bgcolor: impl Into<LCDColor>
) -> Bitmap
pub fn new_bitmap( &self, width: i32, height: i32, bgcolor: impl Into<LCDColor> ) -> Bitmap
Allocates and returns a new width by height LCDBitmap filled with bgcolor.
sourcepub fn load_bitmap(&self, path: impl AsRef<str>) -> Result<Bitmap, Error>
pub fn load_bitmap(&self, path: impl AsRef<str>) -> Result<Bitmap, Error>
Allocates and returns a new LCDBitmap from the file at path. If there is no file at path, the function returns null.
sourcepub fn new_bitmap_table(
&self,
count: i32,
width: i32,
height: i32
) -> BitmapTable
pub fn new_bitmap_table( &self, count: i32, width: i32, height: i32 ) -> BitmapTable
Allocates and returns a new LCDBitmapTable that can hold count width by height LCDBitmaps.
sourcepub fn load_bitmap_table(
&self,
path: impl AsRef<str>
) -> Result<BitmapTable, Error>
pub fn load_bitmap_table( &self, path: impl AsRef<str> ) -> Result<BitmapTable, Error>
Allocates and returns a new LCDBitmap from the file at path. If there is no file at path, the function returns null.
sourcepub fn load_font(&self, path: impl AsRef<str>) -> Result<Font, Error>
pub fn load_font(&self, path: impl AsRef<str>) -> Result<Font, Error>
Returns the LCDFont object for the font file at path. In case of error, outErr points to a string describing the error.
sourcepub fn get_frame(&self) -> *mut u8
pub fn get_frame(&self) -> *mut u8
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.
sourcepub fn get_display_frame(&self) -> *mut u8
pub fn get_display_frame(&self) -> *mut u8
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.
sourcepub fn get_debug_bitmap(&self) -> Option<Bitmap>
pub fn get_debug_bitmap(&self) -> Option<Bitmap>
Only valid in the Simulator, returns the debug framebuffer as a bitmap. Function is NULL on device.
sourcepub fn copy_frame_buffer_bitmap(&self) -> Bitmap
pub fn copy_frame_buffer_bitmap(&self) -> Bitmap
Returns a copy the contents of the working frame buffer as a bitmap. The caller is responsible for freeing the returned bitmap with playdate->graphics->freeBitmap().
sourcepub fn mark_updated_rows(&self, start: i32, end: i32)
pub fn mark_updated_rows(&self, start: i32, end: i32)
After updating pixels in the buffer returned by getFrame(), 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.
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.
sourcepub fn set_screen_clip_rect(&self, x: i32, y: i32, width: i32, height: i32)
pub fn set_screen_clip_rect(&self, x: i32, y: i32, width: i32, height: i32)
Sets the current clip rect in screen coordinates.
sourcepub fn fill_polygon(
&self,
n_points: i32,
coords: impl AsRef<[i32]>,
color: impl Into<LCDColor>,
fillrule: LCDPolygonFillRule
)
pub fn fill_polygon( &self, n_points: i32, coords: impl AsRef<[i32]>, color: impl Into<LCDColor>, fillrule: LCDPolygonFillRule )
Fills the polygon with vertices at the given coordinates (an array of 2*nPoints ints containing alternating x and y values) using the given color and fill, or winding, rule. See Nonzero-rule for an explanation of the winding rule.
sourcepub fn get_display_buffer_bitmap(&self) -> Bitmap
pub fn get_display_buffer_bitmap(&self) -> Bitmap
Returns a bitmap containing the contents of the display buffer. The system owns this bitmap—do not free it!
sourcepub fn draw_rotated_bitmap(
&self,
bitmap: &Bitmap,
x: i32,
y: i32,
rotation: f32,
centerx: f32,
centery: f32,
xscale: f32,
yscale: f32
)
pub fn draw_rotated_bitmap( &self, bitmap: &Bitmap, x: i32, y: i32, rotation: f32, centerx: f32, centery: f32, xscale: f32, yscale: f32 )
Draws the bitmap scaled to xscale and yscale then rotated by degrees with its center as given by proportions centerx and centery at x, y; that is: if centerx and centery are both 0.5 the center of the image is at (x,y), if centerx and centery are both 0 the top left corner of the image (before rotation) is at (x,y), etc.
sourcepub fn set_text_leading(&self, leading: i32)
pub fn set_text_leading(&self, leading: i32)
Sets the leading adjustment (added to the leading specified in the font) to use when drawing text.
sourcepub fn set_stencil_image(&self, stencil: &Bitmap, tile: i32)
pub fn set_stencil_image(&self, stencil: &Bitmap, tile: i32)
Sets the stencil used for drawing. If the tile flag is set the stencil image will be tiled. Tiled stencils must have width equal to a multiple of 32 pixels.
sourcepub unsafe fn make_font_from_data(
&self,
data: *mut LCDFontData,
wide: i32
) -> Font
pub unsafe fn make_font_from_data( &self, data: *mut LCDFontData, wide: i32 ) -> Font
Returns an LCDFont object wrapping the LCDFontData data comprising the contents (minus 16-byte header) of an uncompressed pft file. wide corresponds to the flag in the header indicating whether the font contains glyphs at codepoints above U+1FFFF.
Safety
Assumes that the LCDFontData is valid.