CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
Mask.h File Reference

1 bpp scratch masks for outlined, shadowed and gradient lettering and logos. More...

#include <stdint.h>

Go to the source code of this file.

Classes

struct  Mask
 A 1 bpp shape being built in the chunk scratch. Made by maskBegin(). More...
 

Functions

Mask maskBegin (int w, int h)
 Start an empty mask in the chunk scratch.
 
void maskText35 (Mask &m, int x, int y, const char *s, uint8_t scale=1, const int8_t *dy=nullptr)
 Add text in the 3x5 font to a mask, at an integer scale.
 
int text35WidthScaled (const char *s, uint8_t scale)
 The width of 3x5 text at a scale, for sizing a mask.
 
void maskBlit1 (Mask &m, const uint8_t *bits, uint8_t w, uint8_t h, uint8_t scale=1)
 Add a 1 bpp bitmap (a logo) to a mask.
 
void maskDraw (const Mask &m, int x, int y, uint8_t fill, int outline=-1, int shadow=-1, const uint8_t *ramp=nullptr)
 Paint a mask, with an optional outline, shadow and gradient.
 
void maskPaint (const Mask &m, int x, int y, uint8_t c)
 Paint just the shape in one colour (no outline, no shadow).
 
void maskTitle (const Mask &m, int x, int y, uint8_t base, const uint8_t *ramp, uint8_t depth, uint8_t side)
 Paint a title as the covers set it, in the house gold.
 
void titleArt (const uint8_t *bits, uint8_t w, uint8_t h, int x, int y, uint8_t base, const uint8_t *ramp, uint8_t depth, uint8_t side)
 Paint a game's title from the arrays tools/titleart.py writes from its cover recipe: maskBegin(), maskBlit1() and maskTitle() in one call.
 

Detailed Description

1 bpp scratch masks for outlined, shadowed and gradient lettering and logos.

Outlined, shadowed or gradient text drawn the naive way (the glyphs nine times over, pixel by pixel from flash) costs ~5 ms a line on this chip. Instead: render the shape once into a bit mask, grow it by one pixel with byte-wide ORs for the outline, and paint every row straight into the framebuffer, two pixels a byte. Still 5-10 ms for big lettering: draw it once onto still screens, not every frame.

CHGfx 1.3's gfx_textFx() works the same way and draws the same pixels with CHGfx_Tiny3x5, but brings CHGfx's whole GFXfont text path: about 2 KB more flash than this and Draw's 3x5 font.