Skip to main content

Framebuffer

Struct Framebuffer 

Source
pub struct Framebuffer { /* private fields */ }
Expand description

The virtual screen: one byte per pixel, each a palette index in 0..16.

Implementations§

Source§

impl Framebuffer

Source

pub fn new() -> Self

Source

pub fn pixels(&self) -> &[u8] ⓘ

Raw palette-index pixels, row-major, WIDTH * HEIGHT long.

Source

pub fn display_palette(&self) -> &[u8; 16]

The display palette: at present time, stored index i is shown as color display_palette()[i]. Presenters apply this when expanding the indexed framebuffer to RGB, exactly as write_rgba does for GPU upload.

Source

pub fn write_rgba(&self, out: &mut [u8])

Expand the indexed framebuffer into an RGBA8 buffer for GPU upload.

Source

pub fn camera(&mut self, x: i32, y: i32)

Set the camera offset applied to all subsequent draw operations.

Source

pub fn clip(&mut self, x: i32, y: i32, w: i32, h: i32)

Restrict drawing to a screen-space rectangle.

Source

pub fn clip_reset(&mut self)

Remove the clip rectangle.

Source

pub fn reset_state(&mut self)

Reset camera and clip to defaults (used between host UI and cart frames).

Source

pub fn set_transparent_color(&mut self, color: u8, transparent: bool)

Make a palette color transparent (or opaque) for sprite draws.

Source

pub fn reset_transparency(&mut self)

Reset transparency to the default (only color 0 transparent).

Source

pub fn remap_color(&mut self, from: u8, to: u8)

Remap a draw-palette color: later draws of from are written as to.

Source

pub fn remap_display_color(&mut self, from: u8, to: u8)

Remap a display-palette color: from is shown as to at upload time.

Source

pub fn reset_palette(&mut self)

Reset both the draw and display palettes to identity.

Source

pub fn set_fill_pattern( &mut self, pattern: u16, secondary: u8, transparent: bool, )

Configure the fill pattern for the filled shape primitives. pattern is a 4x4 bitmask (bit 15 = top-left). Pattern-0 pixels take the shape’s color; pattern-1 pixels take secondary, or are skipped when transparent. A pattern of 0 fills solid.

Source

pub fn cls(&mut self, color: u8)

Fill the whole screen with a color. Does not touch camera/clip.

Source

pub fn pset(&mut self, x: i32, y: i32, color: u8)

Set one pixel (camera-relative, like all draw ops).

Source

pub fn pget(&self, x: i32, y: i32) -> u8

Read one pixel in screen space. Out-of-bounds reads return 0.

Source

pub fn line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)

Bresenham line between two points, inclusive.

Source

pub fn rect(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)

Rectangle outline with inclusive corners, like PICO-8’s rect.

Source

pub fn rectfill(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)

Filled rectangle with inclusive corners.

Source

pub fn circ(&mut self, cx: i32, cy: i32, r: i32, color: u8)

Circle outline (midpoint algorithm).

Source

pub fn circfill(&mut self, cx: i32, cy: i32, r: i32, color: u8)

Filled circle.

Source

pub fn oval(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)

Ellipse outline within the inclusive bounding box (x0,y0)-(x1,y1).

Source

pub fn ovalfill(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)

Filled ellipse within the inclusive bounding box (x0,y0)-(x1,y1).

Source

pub fn print(&mut self, text: &str, x: i32, y: i32, color: u8) -> i32

Print text with the built-in font. Returns the x position after the last character.

Source

pub fn set_pen_color(&mut self, color: u8)

Set the persistent pen color used by print_pen.

Source

pub fn set_cursor(&mut self, x: i32, y: i32)

Set the persistent text cursor used by print_pen.

Source

pub fn print_pen(&mut self, text: &str) -> i32

Print at the cursor in the pen color, then advance the cursor one line down. Returns the x position after the last glyph.

Source

pub fn spr( &mut self, sheet: &SpriteSheet, n: u32, x: i32, y: i32, w: i32, h: i32, flip_x: bool, flip_y: bool, )

Draw sprite n (and the w x h-pixel block to its right and below) from a sheet. Color 0 is transparent, matching the classic default. w/h are pixel extents: w = 4 draws a 4-pixel-wide slice.

Source

pub fn sspr( &mut self, sheet: &SpriteSheet, sx: i32, sy: i32, sw: i32, sh: i32, dx: i32, dy: i32, dw: i32, dh: i32, flip_x: bool, flip_y: bool, )

Draw a sheet rectangle (sx,sy,sw,sh) stretched into a screen rectangle (dx,dy,dw,dh) with nearest-neighbor sampling. Honors per-color transparency and the draw palette.

Source

pub fn map( &mut self, map: &MapData, sheet: &SpriteSheet, cel_x: i32, cel_y: i32, sx: i32, sy: i32, cel_w: i32, cel_h: i32, layers: u8, )

Draw a region of the tile map. layers is a flag mask: when nonzero, only tiles whose flags intersect the mask are drawn. Tile 0 is empty.

Trait Implementations§

Source§

impl Default for Framebuffer

Source§

fn default() -> Self

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

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.