CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
CHGfx_GFX Class Reference

An Adafruit_GFX display that draws into CHGfx's 4 bpp framebuffer and presents it by DMA. More...

#include <CHGfx_AdafruitGFX.h>

Inherits Adafruit_GFX.

Public Member Functions

 CHGfx_GFX ()
 Makes a GFX_W x GFX_H display.
 
void begin (uint8_t spiDiv=GFX_DIV2, uint8_t colorMode=GFX_16BPP)
 Starts the panel, as gfx_begin().
 
void drawPixel (int16_t x, int16_t y, uint16_t color) override
 Sets one pixel in the framebuffer (gfx_pixel()).
 
void drawFastHLine (int16_t x, int16_t y, int16_t w, uint16_t color) override
 Draws a horizontal line (gfx_hline()).
 
void drawFastVLine (int16_t x, int16_t y, int16_t h, uint16_t color) override
 Draws a vertical line (gfx_vline()).
 
void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) override
 Fills a rectangle (gfx_fillRect()).
 
void fillScreen (uint16_t color) override
 Fills the screen (the clip rectangle) with one colour (gfx_clear()).
 
void writePixel (int16_t x, int16_t y, uint16_t color) override
 Sets one pixel (gfx_pixel()); the same as drawPixel().
 
void writeFillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) override
 Fills a rectangle (gfx_fillRect()); the same as fillRect().
 
void writeFastHLine (int16_t x, int16_t y, int16_t w, uint16_t color) override
 Draws a horizontal line (gfx_hline()); the same as drawFastHLine().
 
void writeFastVLine (int16_t x, int16_t y, int16_t h, uint16_t color) override
 Draws a vertical line (gfx_vline()); the same as drawFastVLine().
 
void startWrite (void) override
 Does nothing: drawing goes to RAM, so there is nothing to batch.
 
void endWrite (void) override
 Does nothing: drawing goes to RAM, so there is nothing to batch.
 
void display ()
 Sends the whole framebuffer to the panel and waits for it (gfx_flush()).
 
void displayAsync ()
 Starts sending the whole framebuffer by DMA and returns at once (gfx_flushAsync()).
 
void displayRect (int x, int y, int w, int h)
 Sends one rectangle of the framebuffer and waits for it (gfx_flushRect()).
 
void displayRectAsync (int x, int y, int w, int h)
 Starts sending one rectangle of the framebuffer and returns at once (gfx_flushRectAsync()).
 
bool busy () const
 Whether an async flush is in flight (gfx_busy()).
 
void wait ()
 Waits for the flush in flight to finish (gfx_wait()); draw after it.
 
void setPalette (const uint16_t *p, uint8_t n)
 Sets the first n palette entries (gfx_setPalette()).
 
void setPaletteEntry (uint8_t i, uint16_t c)
 Sets one palette entry (gfx_setPaletteEntry()).
 
uint8_t nearest (uint16_t rgb565) const
 Nearest palette index for an RGB565 colour (gfx_nearest()): map Adafruit colour constants once at setup.
 
void setColorMode (uint8_t m)
 Switches the colour output mode (gfx_setColorMode()).
 

Detailed Description

An Adafruit_GFX display that draws into CHGfx's 4 bpp framebuffer and presents it by DMA.

Adafruit_GFX's print(), fonts, bitmaps, triangles and the rest work as usual; the pixel and span primitives go to CHGfx's fast paths. Every color is a palette index, 0..15 (only the low 4 bits are used), unless CHGFX_GFX_AUTOMAP is defined, in which case it is an RGB565 colour matched to the nearest palette entry at every call. Nothing reaches the panel until display() or displayAsync().

Constructor & Destructor Documentation

◆ CHGfx_GFX()

CHGfx_GFX::CHGfx_GFX ( )
inline

Makes a GFX_W x GFX_H display.

Call begin() in setup().

Member Function Documentation

◆ begin()

void CHGfx_GFX::begin ( uint8_t  spiDiv = GFX_DIV2,
uint8_t  colorMode = GFX_16BPP 
)
inline

Starts the panel, as gfx_begin().

Parameters
spiDivSPI clock divider (default GFX_DIV2, 24 MHz).
colorModeGFX_16BPP (the default), GFX_12BPP or GFX_18BPP.

◆ drawPixel()

void CHGfx_GFX::drawPixel ( int16_t  x,
int16_t  y,
uint16_t  color 
)
inlineoverride

Sets one pixel in the framebuffer (gfx_pixel()).

Parameters
xColumn.
yRow.
colorPalette index.

◆ drawFastHLine()

void CHGfx_GFX::drawFastHLine ( int16_t  x,
int16_t  y,
int16_t  w,
uint16_t  color 
)
inlineoverride

Draws a horizontal line (gfx_hline()).

Parameters
xLeft end.
yRow.
wLength in pixels.
colorPalette index.

◆ drawFastVLine()

void CHGfx_GFX::drawFastVLine ( int16_t  x,
int16_t  y,
int16_t  h,
uint16_t  color 
)
inlineoverride

Draws a vertical line (gfx_vline()).

Parameters
xColumn.
yTop end.
hLength in pixels.
colorPalette index.

◆ fillRect()

void CHGfx_GFX::fillRect ( int16_t  x,
int16_t  y,
int16_t  w,
int16_t  h,
uint16_t  color 
)
inlineoverride

Fills a rectangle (gfx_fillRect()).

Parameters
xLeft edge.
yTop edge.
wWidth.
hHeight.
colorPalette index.

◆ fillScreen()

void CHGfx_GFX::fillScreen ( uint16_t  color)
inlineoverride

Fills the screen (the clip rectangle) with one colour (gfx_clear()).

Parameters
colorPalette index.

◆ writePixel()

void CHGfx_GFX::writePixel ( int16_t  x,
int16_t  y,
uint16_t  color 
)
inlineoverride

Sets one pixel (gfx_pixel()); the same as drawPixel().

Parameters
xColumn.
yRow.
colorPalette index.

◆ writeFillRect()

void CHGfx_GFX::writeFillRect ( int16_t  x,
int16_t  y,
int16_t  w,
int16_t  h,
uint16_t  color 
)
inlineoverride

Fills a rectangle (gfx_fillRect()); the same as fillRect().

Parameters
xLeft edge.
yTop edge.
wWidth.
hHeight.
colorPalette index.

◆ writeFastHLine()

void CHGfx_GFX::writeFastHLine ( int16_t  x,
int16_t  y,
int16_t  w,
uint16_t  color 
)
inlineoverride

Draws a horizontal line (gfx_hline()); the same as drawFastHLine().

Parameters
xLeft end.
yRow.
wLength in pixels.
colorPalette index.

◆ writeFastVLine()

void CHGfx_GFX::writeFastVLine ( int16_t  x,
int16_t  y,
int16_t  h,
uint16_t  color 
)
inlineoverride

Draws a vertical line (gfx_vline()); the same as drawFastVLine().

Parameters
xColumn.
yTop end.
hLength in pixels.
colorPalette index.

◆ startWrite()

void CHGfx_GFX::startWrite ( void  )
inlineoverride

Does nothing: drawing goes to RAM, so there is nothing to batch.

◆ endWrite()

void CHGfx_GFX::endWrite ( void  )
inlineoverride

Does nothing: drawing goes to RAM, so there is nothing to batch.

◆ display()

void CHGfx_GFX::display ( )
inline

Sends the whole framebuffer to the panel and waits for it (gfx_flush()).

◆ displayAsync()

void CHGfx_GFX::displayAsync ( )
inline

Starts sending the whole framebuffer by DMA and returns at once (gfx_flushAsync()).

◆ displayRect()

void CHGfx_GFX::displayRect ( int  x,
int  y,
int  w,
int  h 
)
inline

Sends one rectangle of the framebuffer and waits for it (gfx_flushRect()).

Parameters
xLeft edge.
yTop edge.
wWidth.
hHeight.

◆ displayRectAsync()

void CHGfx_GFX::displayRectAsync ( int  x,
int  y,
int  w,
int  h 
)
inline

Starts sending one rectangle of the framebuffer and returns at once (gfx_flushRectAsync()).

Parameters
xLeft edge.
yTop edge.
wWidth.
hHeight.

◆ busy()

bool CHGfx_GFX::busy ( ) const
inline

Whether an async flush is in flight (gfx_busy()).

Returns
true while sending.

◆ wait()

void CHGfx_GFX::wait ( )
inline

Waits for the flush in flight to finish (gfx_wait()); draw after it.

◆ setPalette()

void CHGfx_GFX::setPalette ( const uint16_t *  p,
uint8_t  n 
)
inline

Sets the first n palette entries (gfx_setPalette()).

Parameters
pRGB565 colours.
nHow many, at most 16.

◆ setPaletteEntry()

void CHGfx_GFX::setPaletteEntry ( uint8_t  i,
uint16_t  c 
)
inline

Sets one palette entry (gfx_setPaletteEntry()).

Parameters
iPalette index, 0..15.
cRGB565 colour.

◆ nearest()

uint8_t CHGfx_GFX::nearest ( uint16_t  rgb565) const
inline

Nearest palette index for an RGB565 colour (gfx_nearest()): map Adafruit colour constants once at setup.

Parameters
rgb565The colour.
Returns
Palette index, 0..15.

◆ setColorMode()

void CHGfx_GFX::setColorMode ( uint8_t  m)
inline

Switches the colour output mode (gfx_setColorMode()).

Parameters
mGFX_16BPP, GFX_12BPP or GFX_18BPP.

The documentation for this class was generated from the following file: