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

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).
 

Detailed Description

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.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : uint8_t

sprite4() flags.

Enumerator
SPR_FLIP_V 

Upside down.

SPR_FLIP_H 

Mirrored left to right (1:1 scale only).

Function Documentation

◆ fillRound()

void fillRound ( int  x,
int  y,
int  w,
int  h,
uint8_t  r,
uint8_t  c 
)

Fill a rectangle with rounded corners.

Parameters
x,yTop-left corner.
w,hSize in pixels.
rCorner radius, 0-4 (larger is 4; never more than half of h): pixel-art corners.
cColour.

◆ roundRect()

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.

Parameters
x,yTop-left corner.
w,hSize in pixels.
rCorner radius, 0-4 as for fillRound(); 0 is a plain rectangle.
cColour.

◆ panel()

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.

Parameters
x,yTop-left corner.
w,hSize in pixels.
rCorner radius, 0-4.
fillInside colour.
edgeEdge colour.

◆ panelLit()

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.

Parameters
x,yTop-left corner.
w,hSize in pixels, not counting the shadow.
rCorner radius, 0-4.
fillInside colour (a house colour, so LIGHTER/DARKER know its shades).
edgeEdge colour.

◆ bevel() [1/2]

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.

Parameters
x,yTop-left corner.
w,hSize in pixels.
cThe surface colour: the rim is LIGHTER[c] and DARKER[c].

◆ bevel() [2/2]

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.

Parameters
x,yTop-left corner.
w,hSize in pixels.
lightColour of the top and left edges.
darkColour of the bottom and right edges.

◆ dither()

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).

Parameters
x,yTop-left corner.
w,hSize in pixels.
cColour.
phase0 paints the pixels where x + y is even, 1 where it is odd.

◆ spotlight()

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).

Parameters
cx,cyCentre.
rRadius in pixels.
cColour of the dots (WHITE behind the dealer, for instance).

◆ dropShadow()

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.

Parameters
x,yTop-left corner of the box casting it.
w,hSize of the box.

◆ remapRect()

void remapRect ( int  x,
int  y,
int  w,
int  h,
const uint8_t *  remap 
)

Recolour a rectangle in place: pixel = remap[pixel] (dimming, highlighting).

Parameters
x,yTop-left corner.
w,hSize in pixels.
remapSixteen colours, the new colour for each old one.

◆ fillConvex()

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.

Parameters
xyn corners as x, y pairs, in 1/16 px.
nNumber of corners, at most 8.
cColour.
dither-1 (default): solid. 0 or 1: a 50% checker of c instead, with that phase as dither()'s.

◆ sprite4()

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).

Parameters
dataThe art.
x,yWhere its top-left corner goes.
remapA colour for each of 0..14; nullptr or RM_ID: as drawn.
scaleQ8: 256 = 1:1 (the fast path), 512 = double, 128 = half.
flip0, or SPR_FLIP_V and/or SPR_FLIP_H.

◆ spriteRot()

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.

Parameters
dataThe art (as sprite4()).
ax,ayThe pivot, a pixel of the art.
px,pyWhere the pivot lands on screen.
angleThe turn, 256 = one full turn, clockwise on screen.
scaleQ8, 256 = 1:1.
remapAs sprite4() (nullptr: as drawn).

◆ rotRaw()

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.

Parameters
w,hSize of the art in gfx_chunkScratch(): rows of (w + 1) / 2 bytes, low nibble first, 15 = clear.
ax,ayThe pivot, a pixel of the art.
px,pyWhere the pivot lands on screen.
angleThe turn, 256 = one full turn.
scaleQ8, 256 = 1:1.
remapAs sprite4() (nullptr: as drawn).

◆ glyph()

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).

Parameters
x,yTop-left corner.
colsOne byte per column.
ncolsNumber of columns.
cColour of the set bits; clear bits are left alone.

◆ glyph16()

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).

Parameters
x,yTop-left corner.
rowsOne uint16_t per row.
nrowsNumber of rows.
cColour of the set bits; clear bits are left alone.

◆ text35()

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).

Parameters
x,yTop-left corner of the first character.
strThe text.
cColour.
Returns
The advance of the last line in pixels (4 a character, 2 a '~').

◆ text35Width()

int text35Width ( const char *  str)

The width of text in the 3x5 font, without the trailing gap: for centring.

Parameters
strThe text; with '\n', the widest line.
Returns
Its width in pixels (0 for "").

◆ text35s()

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).

Parameters
x,yTop-left corner.
strThe text.
cColour of the letters.
shadeColour of the shade (default INK).
Returns
As text35().

◆ text35x2()

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.

Parameters
x,yTop-left corner.
strThe text.
cColour.

◆ text35x2s()

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.

Parameters
x,yTop-left corner.
strThe text.
cColour of the letters.
shadeColour of the shade (default INK).

◆ text35x2Width()

int text35x2Width ( const char *  str)
inline

The width of text drawn with text35x2().

Parameters
strThe text.
Returns
Its width in pixels: twice text35Width().

◆ glyph35()

const uint8_t * glyph35 ( char  ch)

A character of the 3x5 font, for drawing it yourself with glyph().

Parameters
chThe character.
Returns
Its three column bytes, or nullptr if the font has no such character.

Variable Documentation

◆ DARKER

DARKER
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.

◆ LIGHTER

LIGHTER

One step lighter for each house colour (Palette).

See also
DARKER

◆ RM_ID

const uint8_t RM_ID[16]
extern

The identity remap (every colour to itself).