Skip to main content

Module painted

Module painted 

Source
Expand description

Pictures a skin paints at run time (ADR-0078): a Painted picture whose pixels the game makes while it runs (a decoded video frame, a software renderer’s screen, a plasma), kept between frames in the frame’s PaintedTable and placed with a PaintedSprite.

The table lives in the GlyphBuffer a screen draws into: the game’s buffer outlives every frame, so its pictures do too. A skin takes its picture from the table, writes its pixels when they change, and places it:

use shuyi_ui::frame::painted::{Painted, PaintedId, PaintedSprite};
use shuyi_ui::frame::{Cell, GlyphBuffer, Layer, PxRect, Rgb};

const PLASMA: PaintedId = PaintedId::new("plasma");
let mut buf = GlyphBuffer::new(20, 6, Cell::new(' ', Rgb::new(255, 255, 255), Rgb::new(0, 0, 0)));
let picture = buf
    .pictures_mut()
    .get_or_insert_with(PLASMA, || Painted::rgba(64, 48));
for pixel in picture.pixels_mut().chunks_exact_mut(4) {
    pixel.copy_from_slice(&[255, 128, 0, 255]);
}
let whole = PxRect::new(0, 0, 64, 48);
buf.add_painted(PaintedSprite::new(PLASMA, whole, PxRect::new(8, 8, 128, 96), Layer::Over));
assert_eq!(buf.pictures().get(PLASMA).map(Painted::revision), Some(1));

Every pixel is written with Painted::pixels_mut (or the palette with Painted::palette_mut), which moves the picture’s revision: shuyi-app uploads a picture again only in a frame whose revision moved. Borrow them only in a frame that changes them.

Structs§

Painted
A picture a skin paints at run time (ADR-0078). Its fields keep their sizes, so they are read and written through methods; the ones that write move its revision.
PaintedId
The game’s name for a painted picture, as an image’s path names an image: cheap to copy and compare.
PaintedSprite
Where a painted picture is drawn (ADR-0078): part of it, src, stretched to dest with nearest-pixel sampling, never smoothed.
PaintedTable
The painted pictures of a frame, by id (ADR-0078). A GlyphBuffer holds one (GlyphBuffer::pictures_mut).

Enums§

PaintedKind
What a Painted picture’s bytes are.

Constants§

PALETTE_LEN
How many colours an indexed picture’s palette holds.