![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
Panels, span sprites, dithering, polygons and the 3x5 font, drawn into CHGfx's framebuffer. More...
Enumerations | |
| enum | : uint8_t { SPR_FLIP_V = 1 , SPR_FLIP_H = 2 } |
| sprite4() flags. More... | |
Functions | |
| void | fillRound (int x, int y, int w, int h, uint8_t r, uint8_t c) |
| Fill a rectangle with rounded corners. | |
| void | roundRect (int x, int y, int w, int h, uint8_t r, uint8_t c) |
| Outline a rectangle with rounded corners, 1 px wide. | |
| void | panel (int x, int y, int w, int h, uint8_t r, uint8_t fill, uint8_t edge) |
A rounded panel: fillRound() in fill, then roundRect() in edge. | |
| void | panelLit (int x, int y, int w, int h, uint8_t r, uint8_t fill, uint8_t edge) |
| A panel lit from above. | |
| void | bevel (int x, int y, int w, int h, uint8_t c) |
| A raised rectangle's rim: light along the top and left, dark along the bottom and right. | |
| void | bevel (int x, int y, int w, int h, uint8_t light, uint8_t dark) |
| A raised rectangle's rim in two given colours. | |
| void | dither (int x, int y, int w, int h, uint8_t c, uint8_t phase) |
| A 50% checkerboard of one colour over a rectangle; the pixels in between are left alone (darkened backdrops, shadows). | |
| void | spotlight (int cx, int cy, int r, uint8_t c) |
| A round spotlight: a disc of dots, on 25% of its pixels (every other pixel of every other row). | |
| void | dropShadow (int x, int y, int w, int h) |
| A soft shadow (a 50% INK checker) 2 px below and right of a box. | |
| void | remapRect (int x, int y, int w, int h, const uint8_t *remap) |
| Recolour a rectangle in place: pixel = remap[pixel] (dimming, highlighting). | |
| void | fillConvex (const int16_t *xy, uint8_t n, uint8_t c, int dither=-1) |
| Fill a convex polygon. | |
| void | sprite4 (const uint8_t *data, int x, int y, const uint8_t *remap=nullptr, int scale=256, uint8_t flip=0) |
| Draw span4 art, through a remap and at a scale. | |
| void | spriteRot (const uint8_t *data, int ax, int ay, int px, int py, uint8_t angle, int scale, const uint8_t *remap) |
| Draw span4 art turned and scaled about a pivot. | |
| void | rotRaw (int w, int h, int ax, int ay, int px, int py, uint8_t angle, int scale, const uint8_t *remap) |
| spriteRot() for raw 4 bpp art the caller has put in the chunk scratch. | |
| void | glyph (int x, int y, const uint8_t *cols, uint8_t ncols, uint8_t c) |
| Draw a column-major 1 bpp glyph (bit 0 = top row, up to 8 rows). | |
| void | glyph16 (int x, int y, const uint16_t *rows, uint8_t nrows, uint8_t c) |
| Draw a row-major 1 bpp glyph up to 16 wide (the leftmost pixel in bit 15). | |
| int | text35 (int x, int y, const char *str, uint8_t c) |
| Draw text in PPOT's 3x5 font. | |
| int | text35Width (const char *str) |
| The width of text in the 3x5 font, without the trailing gap: for centring. | |
| int | text35s (int x, int y, const char *str, uint8_t c, uint8_t shade=0) |
| text35() over its own shade a pixel down and right (embossed). | |
| void | text35x2 (int x, int y, const char *str, uint8_t c) |
| The 3x5 font doubled (8 px advance, 12 rows with the descender): menus. | |
| void | text35x2s (int x, int y, const char *str, uint8_t c, uint8_t shade=0) |
| text35x2() over its own shade a pixel down and right. | |
| int | text35x2Width (const char *str) |
| The width of text drawn with text35x2(). | |
| const uint8_t * | glyph35 (char ch) |
| A character of the 3x5 font, for drawing it yourself with glyph(). | |
Variables | |
| const uint8_t | DARKER [16] |
| One step darker for each house colour (Palette): the shading that gives panels, cards and chips their depth. | |
| const uint8_t | LIGHTER [16] |
| One step lighter for each house colour (Palette). | |
| const uint8_t | RM_ID [16] |
| The identity remap (every colour to itself). | |
Panels, span sprites, dithering, polygons and the 3x5 font, drawn into CHGfx's framebuffer.
Colours are palette indices (0-15; see Palette). Coordinates are pixels, (0, 0) top left of the 128x128 screen; anything may lie partly or wholly off screen. Draw between gfx_wait() and the next flush.
| anonymous enum : uint8_t |
sprite4() flags.
| Enumerator | |
|---|---|
| SPR_FLIP_V | Upside down. |
| SPR_FLIP_H | Mirrored left to right (1:1 scale only). |
| void fillRound | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h, | ||
| uint8_t | r, | ||
| uint8_t | c | ||
| ) |
Fill a rectangle with rounded corners.
| x,y | Top-left corner. |
| w,h | Size in pixels. |
| r | Corner radius, 0-4 (larger is 4; never more than half of h): pixel-art corners. |
| c | Colour. |
| void roundRect | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h, | ||
| uint8_t | r, | ||
| uint8_t | c | ||
| ) |
Outline a rectangle with rounded corners, 1 px wide.
| x,y | Top-left corner. |
| w,h | Size in pixels. |
| r | Corner radius, 0-4 as for fillRound(); 0 is a plain rectangle. |
| c | Colour. |
| void panel | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h, | ||
| uint8_t | r, | ||
| uint8_t | fill, | ||
| uint8_t | edge | ||
| ) |
A rounded panel: fillRound() in fill, then roundRect() in edge.
Cards, plates, panels.
| x,y | Top-left corner. |
| w,h | Size in pixels. |
| r | Corner radius, 0-4. |
| fill | Inside colour. |
| edge | Edge colour. |
| void panelLit | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h, | ||
| uint8_t | r, | ||
| uint8_t | fill, | ||
| uint8_t | edge | ||
| ) |
A panel lit from above.
A 1 px INK drop shadow outside (down and right), the edge, then inside a lighter top line and a darker bottom one (from LIGHTER and DARKER). The shadow makes it one pixel wider and taller than w x h.
| x,y | Top-left corner. |
| w,h | Size in pixels, not counting the shadow. |
| r | Corner radius, 0-4. |
| fill | Inside colour (a house colour, so LIGHTER/DARKER know its shades). |
| edge | Edge colour. |
| void bevel | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h, | ||
| uint8_t | c | ||
| ) |
A raised rectangle's rim: light along the top and left, dark along the bottom and right.
| x,y | Top-left corner. |
| w,h | Size in pixels. |
| c | The surface colour: the rim is LIGHTER[c] and DARKER[c]. |
| void bevel | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h, | ||
| uint8_t | light, | ||
| uint8_t | dark | ||
| ) |
A raised rectangle's rim in two given colours.
| x,y | Top-left corner. |
| w,h | Size in pixels. |
| light | Colour of the top and left edges. |
| dark | Colour of the bottom and right edges. |
| void dither | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h, | ||
| uint8_t | c, | ||
| uint8_t | phase | ||
| ) |
A 50% checkerboard of one colour over a rectangle; the pixels in between are left alone (darkened backdrops, shadows).
| x,y | Top-left corner. |
| w,h | Size in pixels. |
| c | Colour. |
| phase | 0 paints the pixels where x + y is even, 1 where it is odd. |
| void spotlight | ( | int | cx, |
| int | cy, | ||
| int | r, | ||
| uint8_t | c | ||
| ) |
A round spotlight: a disc of dots, on 25% of its pixels (every other pixel of every other row).
| cx,cy | Centre. |
| r | Radius in pixels. |
| c | Colour of the dots (WHITE behind the dealer, for instance). |
| void dropShadow | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h | ||
| ) |
A soft shadow (a 50% INK checker) 2 px below and right of a box.
| x,y | Top-left corner of the box casting it. |
| w,h | Size of the box. |
| void remapRect | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h, | ||
| const uint8_t * | remap | ||
| ) |
Recolour a rectangle in place: pixel = remap[pixel] (dimming, highlighting).
| x,y | Top-left corner. |
| w,h | Size in pixels. |
| remap | Sixteen colours, the new colour for each old one. |
| void fillConvex | ( | const int16_t * | xy, |
| uint8_t | n, | ||
| uint8_t | c, | ||
| int | dither = -1 |
||
| ) |
Fill a convex polygon.
Filled by pixel centres, so polygons sharing an edge neither overlap nor leave a gap. The corners may go in either winding order.
| xy | n corners as x, y pairs, in 1/16 px. |
| n | Number of corners, at most 8. |
| c | Colour. |
| dither | -1 (default): solid. 0 or 1: a 50% checker of c instead, with that phase as dither()'s. |
| void sprite4 | ( | const uint8_t * | data, |
| int | x, | ||
| int | y, | ||
| const uint8_t * | remap = nullptr, |
||
| int | scale = 256, |
||
| uint8_t | flip = 0 |
||
| ) |
Draw span4 art, through a remap and at a scale.
span4 art (tools/assets.py pack_span4): w, h, then per row a count and (len-1)<<4|colour bytes, colour 15 = skip. Every pixel goes through the remap, so one image serves many looks (a team colour, a hit flash).
| data | The art. |
| x,y | Where its top-left corner goes. |
| remap | A colour for each of 0..14; nullptr or RM_ID: as drawn. |
| scale | Q8: 256 = 1:1 (the fast path), 512 = double, 128 = half. |
| flip | 0, or SPR_FLIP_V and/or SPR_FLIP_H. |
| void spriteRot | ( | const uint8_t * | data, |
| int | ax, | ||
| int | ay, | ||
| int | px, | ||
| int | py, | ||
| uint8_t | angle, | ||
| int | scale, | ||
| const uint8_t * | remap | ||
| ) |
Draw span4 art turned and scaled about a pivot.
Decodes into the CHGfx chunk scratch, so it is for drawing time only (between gfx_wait() and the flush), and the art must unpack to 1 KB at most (e.g. 32x60). Larger art draws nothing.
| void rotRaw | ( | int | w, |
| int | h, | ||
| int | ax, | ||
| int | ay, | ||
| int | px, | ||
| int | py, | ||
| uint8_t | angle, | ||
| int | scale, | ||
| const uint8_t * | remap | ||
| ) |
spriteRot() for raw 4 bpp art the caller has put in the chunk scratch.
| w,h | Size of the art in gfx_chunkScratch(): rows of (w + 1) / 2 bytes, low nibble first, 15 = clear. |
| ax,ay | The pivot, a pixel of the art. |
| px,py | Where the pivot lands on screen. |
| angle | The turn, 256 = one full turn. |
| scale | Q8, 256 = 1:1. |
| remap | As sprite4() (nullptr: as drawn). |
| void glyph | ( | int | x, |
| int | y, | ||
| const uint8_t * | cols, | ||
| uint8_t | ncols, | ||
| uint8_t | c | ||
| ) |
Draw a column-major 1 bpp glyph (bit 0 = top row, up to 8 rows).
| x,y | Top-left corner. |
| cols | One byte per column. |
| ncols | Number of columns. |
| c | Colour of the set bits; clear bits are left alone. |
| void glyph16 | ( | int | x, |
| int | y, | ||
| const uint16_t * | rows, | ||
| uint8_t | nrows, | ||
| uint8_t | c | ||
| ) |
Draw a row-major 1 bpp glyph up to 16 wide (the leftmost pixel in bit 15).
| x,y | Top-left corner. |
| rows | One uint16_t per row. |
| nrows | Number of rows. |
| c | Colour of the set bits; clear bits are left alone. |
| int text35 | ( | int | x, |
| int | y, | ||
| const char * | str, | ||
| uint8_t | c | ||
| ) |
Draw text in PPOT's 3x5 font.
Capitals, lower case (with descenders), figures and punctuation. 4 px advance, '~' = a 2 px space, '\n' = 7 px down (back to x). Characters the font lacks are skipped (a 4 px gap).
| x,y | Top-left corner of the first character. |
| str | The text. |
| c | Colour. |
| int text35Width | ( | const char * | str | ) |
The width of text in the 3x5 font, without the trailing gap: for centring.
| str | The text; with '\n', the widest line. |
| int text35s | ( | int | x, |
| int | y, | ||
| const char * | str, | ||
| uint8_t | c, | ||
| uint8_t | shade = 0 |
||
| ) |
| void text35x2 | ( | int | x, |
| int | y, | ||
| const char * | str, | ||
| uint8_t | c | ||
| ) |
The 3x5 font doubled (8 px advance, 12 rows with the descender): menus.
Each font pixel is a 2x2 block; '\n' goes 14 px down. Drawn from flash: for menus and titles, not for text redrawn every frame.
| x,y | Top-left corner. |
| str | The text. |
| c | Colour. |
| void text35x2s | ( | int | x, |
| int | y, | ||
| const char * | str, | ||
| uint8_t | c, | ||
| uint8_t | shade = 0 |
||
| ) |
text35x2() over its own shade a pixel down and right.
| x,y | Top-left corner. |
| str | The text. |
| c | Colour of the letters. |
| shade | Colour of the shade (default INK). |
|
inline |
The width of text drawn with text35x2().
| str | The text. |
| const uint8_t * glyph35 | ( | char | ch | ) |
A character of the 3x5 font, for drawing it yourself with glyph().
| ch | The character. |
|
extern |
One step darker for each house colour (Palette): the shading that gives panels, cards and chips their depth.
DARKER[FELT] is FELT_DK, for instance.
|
extern |
The identity remap (every colour to itself).