![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
Drop CHGfx in underneath Adafruit_GFX: existing sketches keep their drawing code and get the framebuffer and DMA transport. More...
Go to the source code of this file.
Classes | |
| class | CHGfx_GFX |
| An Adafruit_GFX display that draws into CHGfx's 4 bpp framebuffer and presents it by DMA. More... | |
Drop CHGfx in underneath Adafruit_GFX: existing sketches keep their drawing code and get the framebuffer and DMA transport.
Why you might want this. Adafruit_GFX itself is not the slow part. The slow part is Adafruit_ST7735 underneath it, pushing every pixel down a polled SPI link with a fresh address window each time. Adafruit_GFX's own feature set - print(), setTextSize(), the custom GFXfont system, drawBitmap(), triangles, rounded rectangles - is perfectly good.
So: subclass Adafruit_GFX, point drawPixel() at the 4 bpp framebuffer, override the span primitives with CHGfx's fast paths, and present with display(). Existing sketches keep working and get the full DMA transport underneath.
The one thing that changes. Adafruit_GFX passes colours as uint16_t. Here a colour is a PALETTE INDEX, 0..15 - there is no 16-colour framebuffer that can hold an arbitrary RGB565. Passing ST77XX_RED (0xF800) would be read as index 0, i.e. black, so map your colours once at setup:
Set CHGFX_GFX_AUTOMAP if you would rather have colours mapped for you at every call. It makes old code work verbatim but costs a 16-entry search per drawing call, so it is off by default.
Fonts. Adafruit_GFX's own setFont() keeps working here, and CHGfx's bundled fonts are GFXfonts, so they go straight in:
Note that tft.setFont() and Gfx.setFont() are SEPARATE state. The bridge routes drawing through Adafruit_GFX, which does its own glyph walking, so a font set on Gfx does not affect tft and vice versa. Pick one text path per sketch.
Requires the Adafruit GFX Library to be installed. This header is not included by CHGfx.h - include it yourself only if you want the bridge.
You must also write #include <Adafruit_GFX.h> in your .ino, above this include. That looks redundant, but the Arduino builder works out which library include paths to add by scanning the SKETCH file only. A library reached solely through another library's header never gets its path added, and the include below would fail to resolve.