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
impl Framebuffer
pub fn new() -> Self
Sourcepub fn display_palette(&self) -> &[u8; 16]
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.
Sourcepub fn write_rgba(&self, out: &mut [u8])
pub fn write_rgba(&self, out: &mut [u8])
Expand the indexed framebuffer into an RGBA8 buffer for GPU upload.
Sourcepub fn camera(&mut self, x: i32, y: i32)
pub fn camera(&mut self, x: i32, y: i32)
Set the camera offset applied to all subsequent draw operations.
Sourcepub fn clip(&mut self, x: i32, y: i32, w: i32, h: i32)
pub fn clip(&mut self, x: i32, y: i32, w: i32, h: i32)
Restrict drawing to a screen-space rectangle.
Sourcepub fn clip_reset(&mut self)
pub fn clip_reset(&mut self)
Remove the clip rectangle.
Sourcepub fn reset_state(&mut self)
pub fn reset_state(&mut self)
Reset camera and clip to defaults (used between host UI and cart frames).
Sourcepub fn set_transparent_color(&mut self, color: u8, transparent: bool)
pub fn set_transparent_color(&mut self, color: u8, transparent: bool)
Make a palette color transparent (or opaque) for sprite draws.
Sourcepub fn reset_transparency(&mut self)
pub fn reset_transparency(&mut self)
Reset transparency to the default (only color 0 transparent).
Sourcepub fn remap_color(&mut self, from: u8, to: u8)
pub fn remap_color(&mut self, from: u8, to: u8)
Remap a draw-palette color: later draws of from are written as to.
Sourcepub fn remap_display_color(&mut self, from: u8, to: u8)
pub fn remap_display_color(&mut self, from: u8, to: u8)
Remap a display-palette color: from is shown as to at upload time.
Sourcepub fn reset_palette(&mut self)
pub fn reset_palette(&mut self)
Reset both the draw and display palettes to identity.
Sourcepub fn set_fill_pattern(
&mut self,
pattern: u16,
secondary: u8,
transparent: bool,
)
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.
Sourcepub fn cls(&mut self, color: u8)
pub fn cls(&mut self, color: u8)
Fill the whole screen with a color. Does not touch camera/clip.
Sourcepub fn pset(&mut self, x: i32, y: i32, color: u8)
pub fn pset(&mut self, x: i32, y: i32, color: u8)
Set one pixel (camera-relative, like all draw ops).
Sourcepub fn pget(&self, x: i32, y: i32) -> u8
pub fn pget(&self, x: i32, y: i32) -> u8
Read one pixel in screen space. Out-of-bounds reads return 0.
Sourcepub fn line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
pub fn line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
Bresenham line between two points, inclusive.
Sourcepub fn rect(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
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.
Sourcepub fn rectfill(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
pub fn rectfill(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
Filled rectangle with inclusive corners.
Sourcepub fn circ(&mut self, cx: i32, cy: i32, r: i32, color: u8)
pub fn circ(&mut self, cx: i32, cy: i32, r: i32, color: u8)
Circle outline (midpoint algorithm).
Sourcepub fn oval(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
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).
Sourcepub fn ovalfill(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: u8)
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).
Sourcepub fn print(&mut self, text: &str, x: i32, y: i32, color: u8) -> i32
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.
Sourcepub fn set_pen_color(&mut self, color: u8)
pub fn set_pen_color(&mut self, color: u8)
Set the persistent pen color used by print_pen.
Sourcepub fn set_cursor(&mut self, x: i32, y: i32)
pub fn set_cursor(&mut self, x: i32, y: i32)
Set the persistent text cursor used by print_pen.
Sourcepub fn print_pen(&mut self, text: &str) -> i32
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.
Sourcepub fn spr(
&mut self,
sheet: &SpriteSheet,
n: u32,
x: i32,
y: i32,
w: i32,
h: i32,
flip_x: bool,
flip_y: bool,
)
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.
Sourcepub 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,
)
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.