PlaydateGraphics

Struct PlaydateGraphics 

Source
pub struct PlaydateGraphics {
    pub video: PlaydateVideo,
    /* private fields */
}

Fields§

§video: PlaydateVideo

Implementations§

Source§

impl PlaydateGraphics

Source

pub fn clear(&self, color: impl Into<ColorOrPattern>)

Clears the entire display, filling it with color.

Examples found in repository?
examples/mandelbrot.rs (line 102)
101    fn draw_frame(&self) {
102        PLAYDATE.graphics.clear(Color::White);
103        let iter = self.get_iter();
104        for y in 0..DISPLAY_HEIGHT {
105            for x in 0..DISPLAY_WIDTH {
106                let pos = vec2![x as i32, y as i32];
107                let v = f(Complex::from_point(pos, self.center, self.scale), iter);
108                PLAYDATE
109                    .graphics
110                    .draw_pixel(pos, if v { Color::Black } else { Color::White });
111            }
112        }
113    }
More examples
Hide additional examples
examples/hello_world.rs (line 26)
24    fn update(&mut self, delta: f32) {
25        // Clear screen
26        PLAYDATE.graphics.clear(Color::White);
27        // Draw image
28        PLAYDATE.graphics.draw_rotated_bitmap(
29            &self.image,
30            vec2![130, 120],
31            self.rotation,
32            vec2![0.5, 0.5],
33            vec2![1.0, 1.0],
34        );
35        // Rotate image
36        self.rotation += delta * 90.0;
37        // Draw text
38        PLAYDATE
39            .graphics
40            .draw_text("Hello, World!", vec2![230, 112]);
41        // Draw FPS
42        PLAYDATE.system.draw_fps(vec2![0, 0]);
43    }
Source

pub fn set_background_color(&self, color: Color)

Sets the background color shown when the display is offset or for clearing dirty areas in the sprite system.

Source

pub fn set_stencil(&self, stencil: impl AsRef<Bitmap>)

Sets the stencil used for drawing. For a tiled stencil, use setStencilImage() instead.

Source

pub fn set_draw_mode(&self, mode: BitmapDrawMode)

Sets the mode used for drawing bitmaps. Note that text drawing uses bitmaps, so this affects how fonts are displayed as well.

Source

pub fn set_draw_offset(&self, delta: Vec2<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.

Source

pub fn set_clip_rect(&self, rect: Rect<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.

Source

pub fn clear_clip_rect(&self)

Clears the current clip rect.

Source

pub fn set_line_cap_style(&self, end_cap_style: LineCapStyle)

Sets the end cap style used in the line drawing functions.

Source

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

Sets the font to use in subsequent drawText calls.

Examples found in repository?
examples/mandelbrot.rs (line 170)
165    fn init(&mut self) {
166        let font = PLAYDATE
167            .graphics
168            .load_font("/System/Fonts/Roobert-10-Bold.pft")
169            .unwrap();
170        PLAYDATE.graphics.set_font(&font);
171        self.draw_frame();
172    }
Source

pub fn set_text_tracking(&self, tracking: i32)

Sets the tracking to use when drawing text.

Source

pub fn push_context(&self, target: impl AsRef<Bitmap>)

Push a new drawing context for drawing into the given bitmap. If target is nil, the drawing functions will use the display framebuffer.

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.

Source

pub fn draw_bitmap( &self, bitmap: impl AsRef<Bitmap>, pos: Vec2<i32>, flip: BitmapFlip, )

Draws the bitmap with its upper-left corner at location x, y, using the given flip orientation.

Source

pub fn tile_bitmap( &self, bitmap: impl AsRef<Bitmap>, rect: Rect<i32>, flip: BitmapFlip, )

Draws the bitmap with its upper-left corner at location x, y tiled inside a width by height rectangle.

Source

pub fn draw_line( &self, start: Vec2<i32>, end: Vec2<i32>, width: i32, color: impl Into<ColorOrPattern>, )

Draws a line from x1, y1 to x2, y2 with a stroke width of width.

Source

pub fn fill_triangle( &self, pos1: Vec2<i32>, pos2: Vec2<i32>, pos3: Vec2<i32>, color: impl Into<ColorOrPattern>, )

Draws a filled triangle with points at x1, y1, x2, y2, and x3, y3.

Source

pub fn draw_pixel(&self, pos: Vec2<i32>, color: Color)

Draws a pixel at x, y.

Examples found in repository?
examples/mandelbrot.rs (line 110)
101    fn draw_frame(&self) {
102        PLAYDATE.graphics.clear(Color::White);
103        let iter = self.get_iter();
104        for y in 0..DISPLAY_HEIGHT {
105            for x in 0..DISPLAY_WIDTH {
106                let pos = vec2![x as i32, y as i32];
107                let v = f(Complex::from_point(pos, self.center, self.scale), iter);
108                PLAYDATE
109                    .graphics
110                    .draw_pixel(pos, if v { Color::Black } else { Color::White });
111            }
112        }
113    }
Source

pub fn draw_rect(&self, rect: Rect<i32>, color: impl Into<ColorOrPattern>)

Draws a width by height rect at x, y.

Examples found in repository?
examples/mandelbrot.rs (lines 120-126)
115    fn draw_meta(&self) {
116        let text_area_width = 130;
117        let row_height = 14;
118        let text_area_height = row_height * 3;
119        let top_left_x = DISPLAY_WIDTH as i32 - text_area_width;
120        PLAYDATE.graphics.draw_rect(
121            rect! {
122                x: top_left_x - 3, y: DISPLAY_HEIGHT as i32 - text_area_height - 3,
123                w: text_area_width + 3, h: text_area_height + 3,
124            },
125            Color::White,
126        );
127        PLAYDATE.graphics.fill_rect(
128            rect! {
129                x: top_left_x - 2, y: DISPLAY_HEIGHT as i32 - text_area_height - 2,
130                w: text_area_width + 2, h: text_area_height + 2,
131            },
132            Color::Black,
133        );
134        PLAYDATE.graphics.fill_rect(
135            rect! {
136                x: top_left_x, y: DISPLAY_HEIGHT as i32 - text_area_height,
137                w: text_area_width , h: text_area_height,
138            },
139            Color::White,
140        );
141        PLAYDATE.graphics.draw_text(
142            format!("<{:.4}, {:.4}i>", self.center.re, self.center.im,),
143            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height * 3],
144        );
145        PLAYDATE.graphics.draw_text(
146            format!("SCALE: {:.8}", 1.0 / (self.scale * 100.0)),
147            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height * 2],
148        );
149        PLAYDATE.graphics.draw_text(
150            format!("ITER: {:}", self.get_iter()),
151            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height],
152        );
153    }
Source

pub fn fill_rect(&self, rect: Rect<i32>, color: impl Into<ColorOrPattern>)

Draws a filled width by height rect at x, y.

Examples found in repository?
examples/mandelbrot.rs (lines 127-133)
115    fn draw_meta(&self) {
116        let text_area_width = 130;
117        let row_height = 14;
118        let text_area_height = row_height * 3;
119        let top_left_x = DISPLAY_WIDTH as i32 - text_area_width;
120        PLAYDATE.graphics.draw_rect(
121            rect! {
122                x: top_left_x - 3, y: DISPLAY_HEIGHT as i32 - text_area_height - 3,
123                w: text_area_width + 3, h: text_area_height + 3,
124            },
125            Color::White,
126        );
127        PLAYDATE.graphics.fill_rect(
128            rect! {
129                x: top_left_x - 2, y: DISPLAY_HEIGHT as i32 - text_area_height - 2,
130                w: text_area_width + 2, h: text_area_height + 2,
131            },
132            Color::Black,
133        );
134        PLAYDATE.graphics.fill_rect(
135            rect! {
136                x: top_left_x, y: DISPLAY_HEIGHT as i32 - text_area_height,
137                w: text_area_width , h: text_area_height,
138            },
139            Color::White,
140        );
141        PLAYDATE.graphics.draw_text(
142            format!("<{:.4}, {:.4}i>", self.center.re, self.center.im,),
143            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height * 3],
144        );
145        PLAYDATE.graphics.draw_text(
146            format!("SCALE: {:.8}", 1.0 / (self.scale * 100.0)),
147            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height * 2],
148        );
149        PLAYDATE.graphics.draw_text(
150            format!("ITER: {:}", self.get_iter()),
151            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height],
152        );
153    }
Source

pub fn draw_ellipse( &self, rect: Rect<i32>, line_width: i32, start_angle: f32, end_angle: f32, color: impl Into<ColorOrPattern>, )

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.

Source

pub fn fill_ellipse( &self, rect: Rect<i32>, start_angle: f32, end_angle: f32, color: impl Into<ColorOrPattern>, )

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.

Source

pub fn draw_scaled_bitmap( &self, bitmap: impl AsRef<Bitmap>, pos: Vec2<i32>, scale: Vec2<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.

Source

pub fn draw_text(&self, text: impl AsRef<str>, pos: Vec2<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.

Examples found in repository?
examples/hello_world.rs (line 40)
24    fn update(&mut self, delta: f32) {
25        // Clear screen
26        PLAYDATE.graphics.clear(Color::White);
27        // Draw image
28        PLAYDATE.graphics.draw_rotated_bitmap(
29            &self.image,
30            vec2![130, 120],
31            self.rotation,
32            vec2![0.5, 0.5],
33            vec2![1.0, 1.0],
34        );
35        // Rotate image
36        self.rotation += delta * 90.0;
37        // Draw text
38        PLAYDATE
39            .graphics
40            .draw_text("Hello, World!", vec2![230, 112]);
41        // Draw FPS
42        PLAYDATE.system.draw_fps(vec2![0, 0]);
43    }
More examples
Hide additional examples
examples/mandelbrot.rs (lines 141-144)
115    fn draw_meta(&self) {
116        let text_area_width = 130;
117        let row_height = 14;
118        let text_area_height = row_height * 3;
119        let top_left_x = DISPLAY_WIDTH as i32 - text_area_width;
120        PLAYDATE.graphics.draw_rect(
121            rect! {
122                x: top_left_x - 3, y: DISPLAY_HEIGHT as i32 - text_area_height - 3,
123                w: text_area_width + 3, h: text_area_height + 3,
124            },
125            Color::White,
126        );
127        PLAYDATE.graphics.fill_rect(
128            rect! {
129                x: top_left_x - 2, y: DISPLAY_HEIGHT as i32 - text_area_height - 2,
130                w: text_area_width + 2, h: text_area_height + 2,
131            },
132            Color::Black,
133        );
134        PLAYDATE.graphics.fill_rect(
135            rect! {
136                x: top_left_x, y: DISPLAY_HEIGHT as i32 - text_area_height,
137                w: text_area_width , h: text_area_height,
138            },
139            Color::White,
140        );
141        PLAYDATE.graphics.draw_text(
142            format!("<{:.4}, {:.4}i>", self.center.re, self.center.im,),
143            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height * 3],
144        );
145        PLAYDATE.graphics.draw_text(
146            format!("SCALE: {:.8}", 1.0 / (self.scale * 100.0)),
147            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height * 2],
148        );
149        PLAYDATE.graphics.draw_text(
150            format!("ITER: {:}", self.get_iter()),
151            vec2![top_left_x + 2, DISPLAY_HEIGHT as i32 - row_height],
152        );
153    }
Source

pub fn new_bitmap( &self, width: i32, height: i32, bgcolor: impl Into<ColorOrPattern>, ) -> Bitmap

Allocates and returns a new width by height LCDBitmap filled with bgcolor.

Source

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.

Examples found in repository?
examples/hello_world.rs (line 19)
16    fn new() -> Self {
17        println!("Hello, World!");
18        Self {
19            image: PLAYDATE.graphics.load_bitmap("rust").unwrap(),
20            rotation: 0f32,
21        }
22    }
Source

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.

Source

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.

Source

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.

Examples found in repository?
examples/mandelbrot.rs (line 168)
165    fn init(&mut self) {
166        let font = PLAYDATE
167            .graphics
168            .load_font("/System/Fonts/Roobert-10-Bold.pft")
169            .unwrap();
170        PLAYDATE.graphics.set_font(&font);
171        self.draw_frame();
172    }
Source

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.

Source

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.

Source

pub fn get_debug_bitmap(&self) -> Option<Ref<'_, Bitmap>>

Only valid in the Simulator, returns the debug framebuffer as a bitmap. Function is NULL on device.

Source

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().

Source

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.

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.

Source

pub fn set_screen_clip_rect(&self, rect: Rect<i32>)

Sets the current clip rect in screen coordinates.

Source

pub fn fill_polygon( &self, n_points: i32, coords: impl AsRef<[i32]>, color: impl Into<ColorOrPattern>, fillrule: PolygonFillRule, )

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.

Source

pub fn get_display_buffer_bitmap(&self) -> Ref<'_, Bitmap>

Returns a bitmap containing the contents of the display buffer. The system owns this bitmap—​do not free it!

Source

pub fn draw_rotated_bitmap( &self, bitmap: impl AsRef<Bitmap>, pos: Vec2<i32>, rotation: f32, center_pos: Vec2<f32>, scale: Vec2<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.

Examples found in repository?
examples/hello_world.rs (lines 28-34)
24    fn update(&mut self, delta: f32) {
25        // Clear screen
26        PLAYDATE.graphics.clear(Color::White);
27        // Draw image
28        PLAYDATE.graphics.draw_rotated_bitmap(
29            &self.image,
30            vec2![130, 120],
31            self.rotation,
32            vec2![0.5, 0.5],
33            vec2![1.0, 1.0],
34        );
35        // Rotate image
36        self.rotation += delta * 90.0;
37        // Draw text
38        PLAYDATE
39            .graphics
40            .draw_text("Hello, World!", vec2![230, 112]);
41        // Draw FPS
42        PLAYDATE.system.draw_fps(vec2![0, 0]);
43    }
Source

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.

Source

pub fn set_stencil_image(&self, stencil: impl AsRef<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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.