![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
Arduino-style access to CHGfx: every method is a zero-cost inline forwarder to a gfx_* function.
More...
#include <CHGfx.h>
Public Member Functions | |
| void | begin (uint8_t spiDiv=GFX_DIV2, uint8_t colorMode=GFX_16BPP) |
| Starts the panel. | |
Configuration | |
| void | setSpiDiv (uint8_t d) |
| Changes the SPI clock divider. | |
| void | setColorMode (uint8_t m) |
| Switches the colour output mode. | |
| uint8_t | colorMode () const |
| The current colour output mode. | |
| uint32_t | spiHz () const |
| The current SPI clock. | |
| void | setPanelOffsets (uint8_t m, uint8_t cs, uint8_t rs) |
| Sets the panel's MADCTL and window offsets. | |
| void | setInverted (bool on) |
| Turns colour inversion on or off. | |
| void | setPanelFrameRate (uint8_t r, uint8_t f, uint8_t b) |
| Sets the panel's own refresh rate (FRMCTR1). | |
Present | |
| void | display () |
| Sends the whole framebuffer and waits for it. | |
| void | stream (gfx_streamFn fn, void *user=nullptr) |
| Draws one full-colour frame from a callback, bypassing the framebuffer. | |
| void | displayAsync () |
| Starts sending the whole framebuffer by DMA and returns at once. | |
| void | displayRect (int x, int y, int w, int h) |
| Sends one rectangle of the framebuffer and waits for it. | |
| void | displayRectAsync (int x, int y, int w, int h) |
| Starts sending one rectangle of the framebuffer and returns at once. | |
| bool | busy () const |
| Whether an async flush is in flight. | |
| void | wait () |
| Waits for the flush in flight to finish. | |
| int | flushRow () const |
| The first row the flush in flight may still read. | |
| void | waitRow (int y) |
| Waits until rows 0..y-1 are free to draw into. | |
Clip | |
| void | setClip (int x, int y, int w, int h) |
| Sets the clip rectangle. | |
| void | resetClip () |
| Puts the clip rectangle back to the whole screen. | |
| void | getClip (int *x, int *y, int *w, int *h) const |
| Reads the clip rectangle. | |
Draw | |
| void | clear (uint8_t c) |
| Fills the clip rectangle with one colour. | |
| void | drawPixel (int x, int y, uint8_t c) |
| Sets one pixel. | |
| uint8_t | getPixel (int x, int y) const |
| Reads one pixel. | |
| void | drawFastHLine (int x, int y, int w, uint8_t c) |
| Draws a horizontal line. | |
| void | drawFastVLine (int x, int y, int h, uint8_t c) |
| Draws a vertical line. | |
| void | fillRect (int x, int y, int w, int h, uint8_t c) |
| Fills a rectangle. | |
| void | drawRect (int x, int y, int w, int h, uint8_t c) |
| Draws a rectangle's outline. | |
| void | drawLine (int x0, int y0, int x1, int y1, uint8_t c) |
| Draws a line, both ends included. | |
| void | drawCircle (int cx, int cy, int r, uint8_t c) |
| Draws a circle's outline. | |
| void | fillCircle (int cx, int cy, int r, uint8_t c) |
| Draws a filled circle. | |
| void | drawSprite (const uint8_t *s, int x, int y, int w, int h, int transparent=-1) |
| Copies a 4 bpp bitmap into the framebuffer. | |
| void | drawRoundRect (int x, int y, int w, int h, int r, uint8_t c) |
| Draws a rounded rectangle's outline. | |
| void | fillRoundRect (int x, int y, int w, int h, int r, uint8_t c) |
| Fills a rounded rectangle. | |
| void | drawEllipse (int cx, int cy, int rx, int ry, uint8_t c) |
| Draws an ellipse's outline. | |
| void | fillEllipse (int cx, int cy, int rx, int ry, uint8_t c) |
| Draws a filled ellipse. | |
| void | dither (int x, int y, int w, int h, uint8_t c, uint8_t phase=0) |
| Paints a 50% checkerboard of one colour over a rectangle. | |
| void | remapRect (int x, int y, int w, int h, const uint8_t *remap) |
| Recolours a rectangle in place through a 16-entry table. | |
| void | drawSprite4 (const uint8_t *s, int x, int y, const uint8_t *remap=nullptr, int scale=256) |
| Draws a span sprite. | |
| void | drawSprite4Rot (const uint8_t *s, int ax, int ay, int px, int py, uint8_t angle, int scale=256, const uint8_t *remap=nullptr) |
| Draws a span sprite rotated and scaled about a pivot. | |
| void | scroll (int y, int h, int dx, int dy, int fill=-1) |
| Moves a band of rows by (dx, dy) inside the band. | |
| void | copyRow (int y, const uint8_t *src, int x0, int x1) |
| Copies pixels [x0, x1) of a row buffer into a framebuffer row. | |
| void | drawChar (int x, int y, char ch, uint8_t c) |
| Draws one character. | |
| void | drawChar (int x, int y, char ch, uint8_t c, uint8_t scale) |
| Draws one character, scaled. | |
| void | print (int x, int y, const char *s, uint8_t c) |
| Draws a string. | |
| void | print (int x, int y, const char *s, uint8_t c, uint8_t scale) |
| Draws a string, scaled. | |
| bool | printFx (int x, int y, const char *s, uint8_t scale, uint8_t fill, int outline=-1, int shadow=-1, const uint8_t *ramp=nullptr, const int8_t *dy=nullptr) |
| Draws outlined, shadowed or gradient-filled text. | |
Fonts | |
setFont(nullptr) returns to the built-in 5x7. Note that a custom font takes y as the baseline - see Text. | |
| void | setFont (const GFXfont *f=nullptr) |
| Selects the font. | |
| const GFXfont * | font () const |
| The current font. | |
| int | fontLineHeight () const |
| Baseline-to-baseline line spacing. | |
| int | fontBaseline () const |
| The font's ascent above the baseline. | |
| int | textWidth (const char *s) const |
| Advance width of a string. | |
| int | textWidth (const char *s, uint8_t scale) const |
| Advance width of a string at a scale. | |
| void | textBounds (const char *s, int x, int y, uint8_t scale, int *bx, int *by, int *bw, int *bh) const |
| Bounding box of a string drawn at (x, y). | |
Direct to the panel | |
| void | fillRectDirect (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t rgb565) |
| Fills a rectangle of the panel by DMA, bypassing the framebuffer (16 bpp only). | |
Palette | |
| void | setPalette (const uint16_t *p, uint8_t n) |
Sets the first n palette entries. | |
| void | setPaletteEntry (uint8_t i, uint16_t c) |
| Sets one palette entry. | |
| void | setFade (uint8_t amount, uint16_t rgb565=0) |
| Fades every colour toward one colour. | |
| uint8_t | fade () const |
| The current fade amount. | |
| uint8_t | nearest (uint16_t rgb565) const |
| Nearest palette index for an RGB565 colour (slow: setup only). | |
| static uint16_t | rgb (uint8_t r, uint8_t g, uint8_t b) |
| Packs an 8-bit-per-channel colour into RGB565. | |
The raw framebuffer | |
| uint8_t * | buffer () const |
| The framebuffer, for primitives of your own. | |
| static constexpr int | width () |
| Screen width. | |
| static constexpr int | height () |
| Screen height. | |
Arduino-style access to CHGfx: every method is a zero-cost inline forwarder to a gfx_* function.
There is exactly one panel, one SPI peripheral and one DMA channel, so the driver state is inherently global - the class exists for the familiar Gfx.clear(0) spelling, not to allow two instances. Use the one instance, Gfx. Use whichever style you prefer; they are the same code. Each method's full description is on the function it forwards to.
Starts the panel.
| spiDiv | SPI clock divider (default GFX_DIV2, 24 MHz). |
| colorMode | GFX_16BPP (the default), GFX_12BPP or GFX_18BPP. |
|
inline |
|
inline |
Switches the colour output mode.
| m | GFX_16BPP, GFX_12BPP or GFX_18BPP. |
|
inline |
|
inline |
|
inline |
Sets the panel's MADCTL and window offsets.
| m | MADCTL value. |
| cs | First visible column. |
| rs | First visible row. |
|
inline |
|
inline |
Sets the panel's own refresh rate (FRMCTR1).
| r | RTNA. |
| f | Front porch. |
| b | Back porch. |
|
inline |
Sets the first n palette entries.
| p | RGB565 colours. |
| n | How many, at most 16. |
|
inline |
Sets one palette entry.
| i | Palette index, 0..15. |
| c | RGB565 colour. |
|
inline |
Fades every colour toward one colour.
| amount | 0 = none, 255 = solid rgb565. |
| rgb565 | The colour faded toward (default black). |
|
inline |
|
inline |
Nearest palette index for an RGB565 colour (slow: setup only).
| rgb565 | The colour. |
|
inlinestatic |
Packs an 8-bit-per-channel colour into RGB565.
| r | Red, 0..255. |
| g | Green, 0..255. |
| b | Blue, 0..255. |
|
inline |
Sends the whole framebuffer and waits for it.
|
inline |
Draws one full-colour frame from a callback, bypassing the framebuffer.
| fn | Fills each chunk of rows. |
| user | Passed to fn (default nullptr). |
|
inline |
Starts sending the whole framebuffer by DMA and returns at once.
|
inline |
Sends one rectangle of the framebuffer and waits for it.
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
|
inline |
Starts sending one rectangle of the framebuffer and returns at once.
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
|
inline |
|
inline |
Waits for the flush in flight to finish.
|
inline |
The first row the flush in flight may still read.
|
inline |
Waits until rows 0..y-1 are free to draw into.
| y | One past the last row needed. |
|
inline |
|
inline |
Puts the clip rectangle back to the whole screen.
|
inline |
Reads the clip rectangle.
| [out] | x | Left edge (may be nullptr). |
| [out] | y | Top edge (may be nullptr). |
| [out] | w | Width (may be nullptr). |
| [out] | h | Height (may be nullptr). |
|
inline |
|
inline |
|
inline |
Reads one pixel.
| x | Column. |
| y | Row. |
|
inline |
|
inline |
|
inline |
Fills a rectangle.
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
| c | Palette index. |
|
inline |
Draws a rectangle's outline.
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
| c | Palette index. |
|
inline |
Draws a line, both ends included.
| x0 | Start column. |
| y0 | Start row. |
| x1 | End column. |
| y1 | End row. |
| c | Palette index. |
|
inline |
Draws a circle's outline.
| cx | Centre column. |
| cy | Centre row. |
| r | Radius. |
| c | Palette index. |
|
inline |
Draws a filled circle.
| cx | Centre column. |
| cy | Centre row. |
| r | Radius. |
| c | Palette index. |
|
inline |
Copies a 4 bpp bitmap into the framebuffer.
| s | The bitmap, packed like the framebuffer. |
| x | Left edge. |
| y | Top edge. |
| w | Width in pixels. |
| h | Height in pixels. |
| transparent | Colour index skipped, or -1 (the default) for opaque. |
|
inline |
Draws a rounded rectangle's outline.
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
| r | Corner radius. |
| c | Palette index. |
|
inline |
Fills a rounded rectangle.
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
| r | Corner radius. |
| c | Palette index. |
|
inline |
Draws an ellipse's outline.
| cx | Centre column. |
| cy | Centre row. |
| rx | Horizontal radius. |
| ry | Vertical radius. |
| c | Palette index. |
|
inline |
Draws a filled ellipse.
| cx | Centre column. |
| cy | Centre row. |
| rx | Horizontal radius. |
| ry | Vertical radius. |
| c | Palette index. |
|
inline |
Paints a 50% checkerboard of one colour over a rectangle.
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
| c | Palette index. |
| phase | 0 (the default) paints where x + y is even, 1 where odd. |
|
inline |
Recolours a rectangle in place through a 16-entry table.
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
| remap | 16 palette indices. |
|
inline |
Draws a span sprite.
| s | The sprite data. |
| x | Left edge. |
| y | Top edge. |
| remap | 16 palette indices, or nullptr (the default). |
| scale | Q8 scale, 256 = 1:1 (the default). |
|
inline |
Draws a span sprite rotated and scaled about a pivot.
| s | The sprite data (at most 1 KB decoded). |
| ax | Pivot column in the sprite. |
| ay | Pivot row in the sprite. |
| px | Screen column of the pivot. |
| py | Screen row of the pivot. |
| angle | 256 = a full turn, clockwise. |
| scale | Q8 scale, 256 = 1:1 (the default). |
| remap | 16 palette indices, or nullptr (the default). |
|
inline |
Moves a band of rows by (dx, dy) inside the band.
| y | First row. |
| h | Rows. |
| dx | Pixels right (negative: left). |
| dy | Rows down (negative: up). |
| fill | Palette index for uncovered pixels, or -1 (the default) to keep them. |
|
inline |
Copies pixels [x0, x1) of a row buffer into a framebuffer row.
| y | Framebuffer row. |
| src | GFX_FB_STRIDE bytes, packed like the framebuffer. |
| x0 | First pixel. |
| x1 | One past the last pixel. |
|
inline |
Draws one character.
| x | Left edge. |
| y | Top (built-in font) or baseline (GFXfont). |
| ch | The character. |
| c | Palette index. |
|
inline |
Draws one character, scaled.
| x | Left edge. |
| y | Top (built-in font) or baseline (GFXfont). |
| ch | The character. |
| c | Palette index. |
| scale | Integer scale. |
|
inline |
Draws a string.
| x | Left edge. |
| y | Top (built-in font) or baseline (GFXfont). |
| s | Null-terminated string. |
| c | Palette index. |
|
inline |
Draws a string, scaled.
| x | Left edge. |
| y | Top (built-in font) or baseline (GFXfont). |
| s | Null-terminated string. |
| c | Palette index. |
| scale | Integer scale. |
|
inline |
Draws outlined, shadowed or gradient-filled text.
| x | Left edge. |
| y | Top (built-in font) or baseline (GFXfont). |
| s | Null-terminated string. |
| scale | Integer scale. |
| fill | Palette index of the letters. |
| outline | Palette index of the outline, or -1 (the default). |
| shadow | Palette index of the shadow, or -1 (the default). |
| ramp | A fill colour per pixel row, or nullptr (the default). |
| dy | A vertical offset per character, or nullptr (the default). |
|
inline |
Selects the font.
| f | A GFXfont, or nullptr (the default) for the built-in 5x7. |
|
inline |
|
inline |
|
inline |
The font's ascent above the baseline.
|
inline |
Advance width of a string.
| s | Null-terminated string. |
|
inline |
Advance width of a string at a scale.
| s | Null-terminated string. |
| scale | Integer scale. |
|
inline |
Bounding box of a string drawn at (x, y).
| s | Null-terminated string. | |
| x | Where it would be drawn. | |
| y | Where it would be drawn. | |
| scale | Integer scale. | |
| [out] | bx | Left edge (may be nullptr). |
| [out] | by | Top edge (may be nullptr). |
| [out] | bw | Width (may be nullptr). |
| [out] | bh | Height (may be nullptr). |
|
inline |
Fills a rectangle of the panel by DMA, bypassing the framebuffer (16 bpp only).
| x | Left edge. |
| y | Top edge. |
| w | Width. |
| h | Height. |
| rgb565 | The colour. |
|
inline |
The framebuffer, for primitives of your own.
|
inlinestaticconstexpr |
Screen width.
|
inlinestaticconstexpr |
Screen height.