CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
Lettering masks

Outlined, shadowed and gradient lettering, logos and the cover titles. More...

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

Outlined, shadowed and gradient lettering, logos and the cover titles.

The mask lives in CHGfx's chunk buffers (gfx_chunkScratch, 1 KB), which are idle between gfx_wait() and the next flush - i.e. while drawing. Never keep a Mask across frames or use one outside drawing. Masks paint anywhere on screen: they ignore CHGfx's clip rectangle.

Mask m = maskBegin(text35WidthScaled("WIN", 3), 6 * 3);
maskText35(m, 0, 0, "WIN", 3);
maskDraw(m, 40, 50, GOLD, INK, WINE); // fill, outline, shadow
int text35WidthScaled(const char *s, uint8_t scale)
The width of 3x5 text at a scale, for sizing a mask.
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.
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.
Mask maskBegin(int w, int h)
Start an empty mask in the chunk scratch.
@ GOLD
8: gold (0xFC2).
Definition Palette.h:50
@ WINE
7: dark red (0x702).
Definition Palette.h:49
@ INK
0: black (0x000), outlines and text.
Definition Palette.h:42
A 1 bpp shape being built in the chunk scratch. Made by maskBegin().
Definition Mask.h:34

Function Documentation

◆ maskBegin()

Mask maskBegin ( int  w,
int  h 
)

Start an empty mask in the chunk scratch.

Parameters
w,hUsable size in pixels; with the 1 px margin, (w + 2) x (h + 2) must fit in 1 KB of bits (about 8000 px).
Returns
The mask, cleared. Valid until the next flush or the next maskBegin() (or anything else that uses gfx_chunkScratch()).

◆ maskText35()

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.

Parameters
mThe mask.
x,yTop-left of the text inside the mask.
sThe text ('~' is a half space).
scaleSize: each font pixel becomes scale x scale (4*scale px advance, 6*scale rows with the descender).
dyOptional: a vertical offset for each character (wavy banners).

◆ text35WidthScaled()

int text35WidthScaled ( const char *  s,
uint8_t  scale 
)

The width of 3x5 text at a scale, for sizing a mask.

Parameters
sThe text.
scaleThe scale given to maskText35().
Returns
text35Width(s) * scale.

◆ maskBlit1()

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.

Parameters
mA mask begun at w*scale x h*scale.
bitsThe bitmap: MSB-first rows of (w + 7) / 8 bytes, zero padding bits.
w,hIts size in pixels.
scaleEach bitmap pixel becomes scale x scale.

◆ maskDraw()

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.

Parameters
mThe mask.
x,yWhere its top-left (inside the margin) goes on screen.
fillColour of the shape.
outlineColour of a 1 px ring around it (all 8 directions), or -1 for none.
shadowColour of a shadow, or -1 for none: the outline moved a pixel down and right, or without an outline the shape moved so.
rampOptional: a fill colour for each mask row, replacing fill (gradient lettering).

◆ maskPaint()

void maskPaint ( const Mask &  m,
int  x,
int  y,
uint8_t  c 
)

Paint just the shape in one colour (no outline, no shadow).

Parameters
mThe mask.
x,yWhere its top-left goes on screen.
cColour.

◆ maskTitle()

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.

(docs/cover-art.md, "the stack".) The shape extruded depth px down and right in side, an INK outline round letters and extrusion together, thickened a pixel down and right (the drop shadow), and the face a smooth gradient. A one-pixel gap between letters stays INK. About twice a maskDraw(): draw it onto still screens where the game can.

Parameters
mThe mask holding the lettering.
x,yWhere its top-left goes on screen.
baseThe face's base colour.
rampA byte for each mask row: a colour (high nibble) laid over base where the row's dither pattern (low nibble, MSB the first of every 4 pixels from the lettering's left; 0 none, 15 all) has bits. tools/titleart.py works the patterns out of a 4x4 ordered dither.
depthThe extrusion in pixels, at most 4.
sideThe extrusion's colour.

◆ titleArt()

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.

Parameters
bitsThe 1 bpp lettering (as maskBlit1()).
w,hIts size in pixels.
x,yWhere its top-left goes on screen.
baseThe face's base colour.
rampThe gradient, a byte a row (as maskTitle()).
depthThe extrusion in pixels, at most 4.
sideThe extrusion's colour.