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

The clip rectangle, pixels, lines, rectangles, circles and sprite blits, drawn into the 4 bpp framebuffer. More...

Functions

void gfx_setClip (int x, int y, int w, int h)
 Sets the clip rectangle every drawing call stays inside.
 
void gfx_resetClip (void)
 Puts the clip rectangle back to the whole screen.
 
void gfx_getClip (int *x, int *y, int *w, int *h)
 Reads the clip rectangle, as intersected with the screen.
 
void gfx_clear (uint8_t c)
 Fills the clip rectangle (normally the whole screen) with one colour.
 
void gfx_pixel (int x, int y, uint8_t c)
 Sets one pixel.
 
uint8_t gfx_getPixel (int x, int y)
 Reads one pixel of the framebuffer (the clip is ignored).
 
void gfx_hline (int x, int y, int w, uint8_t c)
 Draws a horizontal line from (x, y), w pixels to the right.
 
void gfx_vline (int x, int y, int h, uint8_t c)
 Draws a vertical line from (x, y), h pixels down.
 
void gfx_fillRect (int x, int y, int w, int h, uint8_t c)
 Fills a rectangle.
 
void gfx_rect (int x, int y, int w, int h, uint8_t c)
 Draws a rectangle's 1-pixel outline.
 
void gfx_line (int x0, int y0, int x1, int y1, uint8_t c)
 Draws a line between two points, both ends included.
 
void gfx_circle (int cx, int cy, int r, uint8_t c)
 Draws a circle's 1-pixel outline, 2*r+1 pixels across.
 
void gfx_fillCircle (int cx, int cy, int r, uint8_t c)
 Draws a filled circle, 2*r+1 pixels across.
 
void gfx_blit (const uint8_t *spr, int x, int y, int w, int h, int transparent)
 Copies a 4 bpp bitmap into the framebuffer, optionally with one colour transparent.
 

Variables

uint8_t gfx_fb [GFX_FB_BYTES]
 The framebuffer: GFX_FB_BYTES of 4 bpp pixels, two per byte.
 

Detailed Description

The clip rectangle, pixels, lines, rectangles, circles and sprite blits, drawn into the 4 bpp framebuffer.

Every colour is a palette index, 0..15 (only the low 4 bits are used). Every call is clipped to the clip rectangle, and nothing reaches the panel until a flush. Draw only after gfx_wait() (or gfx_waitRow() for the rows you touch).

The clip rectangle. Every call that paints pixels - fills, lines, shapes, text, sprites, gfx_clear() - stays inside it. It is intersected with the screen; an empty one (w or h <= 0) stops all drawing. Defaults to the whole screen. gfx_getPixel(), gfx_scroll() and the flush ignore it. Changing it costs nothing, so set it around a panel or a HUD and put it back:

gfx_setClip(0, 10, 128, 118); drawBoard(); gfx_resetClip();
void gfx_setClip(int x, int y, int w, int h)
Sets the clip rectangle every drawing call stays inside.
void gfx_resetClip(void)
Puts the clip rectangle back to the whole screen.

Function Documentation

◆ gfx_setClip()

void gfx_setClip ( int  x,
int  y,
int  w,
int  h 
)

Sets the clip rectangle every drawing call stays inside.

Parameters
xLeft edge, in pixels.
yTop edge, in pixels.
wWidth; 0 or less stops all drawing.
hHeight; 0 or less stops all drawing.

◆ gfx_resetClip()

void gfx_resetClip ( void  )

Puts the clip rectangle back to the whole screen.

◆ gfx_getClip()

void gfx_getClip ( int *  x,
int *  y,
int *  w,
int *  h 
)

Reads the clip rectangle, as intersected with the screen.

Parameters
[out]xLeft edge (may be nullptr).
[out]yTop edge (may be nullptr).
[out]wWidth (may be nullptr).
[out]hHeight (may be nullptr).

◆ gfx_clear()

void gfx_clear ( uint8_t  c)

Fills the clip rectangle (normally the whole screen) with one colour.

The whole screen is one word store per 8 pixels, from SRAM.

Parameters
cPalette index.

◆ gfx_pixel()

void gfx_pixel ( int  x,
int  y,
uint8_t  c 
)

Sets one pixel.

Parameters
xColumn.
yRow.
cPalette index.

◆ gfx_getPixel()

uint8_t gfx_getPixel ( int  x,
int  y 
)

Reads one pixel of the framebuffer (the clip is ignored).

Parameters
xColumn.
yRow.
Returns
The palette index there, or 0 off the screen.

◆ gfx_hline()

void gfx_hline ( int  x,
int  y,
int  w,
uint8_t  c 
)

Draws a horizontal line from (x, y), w pixels to the right.

Parameters
xLeft end.
yRow.
wLength in pixels; 0 or less draws nothing.
cPalette index.

◆ gfx_vline()

void gfx_vline ( int  x,
int  y,
int  h,
uint8_t  c 
)

Draws a vertical line from (x, y), h pixels down.

Parameters
xColumn.
yTop end.
hLength in pixels; 0 or less draws nothing.
cPalette index.

◆ gfx_fillRect()

void gfx_fillRect ( int  x,
int  y,
int  w,
int  h,
uint8_t  c 
)

Fills a rectangle.

Parameters
xLeft edge.
yTop edge.
wWidth; 0 or less draws nothing.
hHeight; 0 or less draws nothing.
cPalette index.

◆ gfx_rect()

void gfx_rect ( int  x,
int  y,
int  w,
int  h,
uint8_t  c 
)

Draws a rectangle's 1-pixel outline.

Parameters
xLeft edge.
yTop edge.
wWidth; 0 or less draws nothing.
hHeight; 0 or less draws nothing.
cPalette index.

◆ gfx_line()

void gfx_line ( int  x0,
int  y0,
int  x1,
int  y1,
uint8_t  c 
)

Draws a line between two points, both ends included.

Parameters
x0Start column.
y0Start row.
x1End column.
y1End row.
cPalette index.

◆ gfx_circle()

void gfx_circle ( int  cx,
int  cy,
int  r,
uint8_t  c 
)

Draws a circle's 1-pixel outline, 2*r+1 pixels across.

Parameters
cxCentre column.
cyCentre row.
rRadius in pixels.
cPalette index.

◆ gfx_fillCircle()

void gfx_fillCircle ( int  cx,
int  cy,
int  r,
uint8_t  c 
)

Draws a filled circle, 2*r+1 pixels across.

Parameters
cxCentre column.
cyCentre row.
rRadius in pixels.
cPalette index.

◆ gfx_blit()

void gfx_blit ( const uint8_t *  spr,
int  x,
int  y,
int  w,
int  h,
int  transparent 
)

Copies a 4 bpp bitmap into the framebuffer, optionally with one colour transparent.

Source rows are packed the same way as the framebuffer (2 px/byte, even x low nibble), each row padded to a whole byte. The opaque even-x case runs at memcpy speed. For art with many runs of one colour, the compact span sprites are smaller.

Parameters
sprThe bitmap, (w + 1) / 2 bytes a row.
xLeft edge on screen.
yTop edge on screen.
wWidth in pixels.
hHeight in pixels.
transparentColour index skipped, or -1 for an opaque copy.

Variable Documentation

◆ gfx_fb

uint8_t gfx_fb[GFX_FB_BYTES]
extern

The framebuffer: GFX_FB_BYTES of 4 bpp pixels, two per byte.

Row y starts at gfx_fb + y * GFX_FB_STRIDE. Even x is in the LOW nibble, odd x in the HIGH nibble - that ordering makes the expansion LUT a single uint32 store with no shuffling on a little-endian core. Each nibble is a palette index. Write it directly only for primitives of your own, and only when no flush is reading it (after gfx_wait()).