123 return (int16_t)m_d.width();
129 return (int16_t)m_d.height();
137 if ( D::BITS_PER_PIXEL == 1 && color == 0 )
142 m_d.setColor(mapColor(color));
151 m_d.setColor(mapColor(color));
160 m_d.setColor(mapColor(color));
165 void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
167 m_d.setColor(mapColor(color));
172 void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
174 if ( w <= 0 || h <= 0 )
176 m_d.setColor(mapColor(color));
181 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
183 if ( w <= 0 || h <= 0 )
185 m_d.setColor(mapColor(color));
192 m_d.setColor(mapColor(color));
193 m_d.fillRect(0, 0, (
lcdint_t)(m_d.width() - 1), (
lcdint_t)(m_d.height() - 1));
197 void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
201 m_d.setColor(mapColor(color));
206 void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
211 fillCircleHelper(x0, y0, r, 3, 0, color);
215 void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
230 void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
232 int16_t minX = x0, maxX = x0;
241 for ( int16_t x = minX; x <= maxX; x++ )
243 int16_t lo = 0, hi = 0;
245 edgeSpan(x, x0, y0, x1, y1, lo, hi, hit);
246 edgeSpan(x, x1, y1, x2, y2, lo, hi, hit);
247 edgeSpan(x, x2, y2, x0, y0, lo, hi, hit);
254 void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
256 if ( w <= 0 || h <= 0 )
258 int16_t maxR = ((w < h) ? w : h) / 2;
265 drawCircleHelper(x + r, y + r, r, 1, color);
266 drawCircleHelper(x + w - r - 1, y + r, r, 2, color);
267 drawCircleHelper(x + w - r - 1, y + h - r - 1, r, 4, color);
268 drawCircleHelper(x + r, y + h - r - 1, r, 8, color);
272 void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
274 if ( w <= 0 || h <= 0 )
276 int16_t maxR = ((w < h) ? w : h) / 2;
279 fillRect(x + r, y, w - 2 * r, h, color);
280 fillCircleHelper(x + w - r - 1, y + r, r, 1, h - 2 * r - 1, color);
281 fillCircleHelper(x + r, y + r, r, 2, h - 2 * r - 1, color);
288 void drawBitmap(int16_t x, int16_t y,
const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
290 if ( w <= 0 || h <= 0 )
292 m_d.setColor(mapColor(color));
308 m_d.setColor(mapColor(color));
315 m_d.setColor(mapColor(color));
316 m_d.setBackground(mapColor(background));
344 m_rotation = rotation & 0x03;
362 char s[2] = {(char)ch,
'\0'};
375 writeGfxChar((uint8_t)*str++);
400 numToStr(number, buf);
401 print((
const char *)buf);
408 write((uint8_t)
'\n');
415 write((uint8_t)
'\n');
421 write((uint8_t)
'\n');
452 static uint16_t mapColor(uint16_t color)
454 if ( D::BITS_PER_PIXEL == 1 )
455 return color ? 0xFFFF : 0x0000;
461 static void edgeSpan(int16_t x, int16_t xa, int16_t ya, int16_t xb, int16_t yb, int16_t &lo, int16_t &hi,
bool &hit)
463 int16_t xmin = xa < xb ? xa : xb;
464 int16_t xmax = xa > xb ? xa : xb;
465 if ( x < xmin || x > xmax )
475 ey0 = ey1 = (int16_t)((
long)ya + (long)(yb - ya) * (x - xa) / (xb - xa));
499 static void numToStr(
long value,
char *buf)
503 bool neg = value < 0;
504 unsigned long v = neg ? (
unsigned long)(-value) : (
unsigned long)value;
507 tmp[i++] = (char)(
'0' + (v % 10));
519 void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t corner, uint16_t color)
521 int16_t f = 1 - r, ddF_x = 1, ddF_y = -2 * r, x = 0, y = r;
557 void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t corner, int16_t delta, uint16_t color)
559 int16_t f = 1 - r, ddF_x = 1, ddF_y = -2 * r, x = 0, y = r, px = x, py = y;
593 static void readStruct(
const void *src,
void *dst,
size_t n)
595 const uint8_t *s = (
const uint8_t *)src;
596 uint8_t *d = (uint8_t *)dst;
597 for (
size_t i = 0; i < n; i++ )
599 d[i] = pgm_read_byte(s + i);
605 static const uint16_t kGlyphBufSize = 128;
612 void writeGfxChar(uint8_t c)
615 readStruct(m_gfxFont, &font,
sizeof(
GFXfont));
620 m_cursorY += (int16_t)font.
yAdvance;
623 if ( c ==
'\r' || c < font.first || c > font.
last )
633 if ( w == 0 || h == 0 )
635 m_cursorX += (int16_t)xa;
643 int16_t top = m_cursorY + glyph.
yOffset;
644 uint8_t shift = (uint8_t)(((top % 8) + 8) % 8);
645 int16_t alignedTop = top - shift;
646 uint8_t packedH = (uint8_t)(h + shift);
647 uint8_t pages = (uint8_t)((packedH + 7) >> 3);
648 if ( (uint16_t)w * pages > kGlyphBufSize )
650 m_cursorX += (int16_t)xa;
654 uint8_t buf[kGlyphBufSize];
655 for ( uint16_t k = 0; k < (uint16_t)w * pages; k++ )
658 const uint8_t *bitmap = font.
bitmap;
660 uint8_t bits = 0, bit = 0;
661 for ( uint8_t row = 0; row < h; row++ )
663 uint8_t dst = (uint8_t)(row + shift);
664 uint8_t page = (uint8_t)(dst >> 3);
665 uint8_t pbit = (uint8_t)(dst & 7);
666 for ( uint8_t col = 0; col < w; col++ )
668 if ( (bit++ & 7) == 0 )
670 bits = pgm_read_byte(bitmap + bo++);
674 buf[(uint16_t)page * w + col] |= (uint8_t)(1 << pbit);
680 m_d.setColor(mapColor(m_textColor));
683 m_cursorX += (int16_t)xa;
687 const GFXfont *m_gfxFont =
nullptr;
688 uint16_t m_textColor = 0xFFFF;
689 int16_t m_cursorX = 0;
690 int16_t m_cursorY = 0;
691 uint8_t m_textSize = 1;
692 uint8_t m_rotation = 0;
uint16_t bitmapOffset
Pointer into GFXfont->bitmap.
void startWrite()
Adafruit_GFX transaction start hook.
GFXglyph * glyph
Glyph array.
uint8_t lcduint_t
internal int type, used by the library.
Adafruit_GFX font descriptor.
void endWrite()
Adafruit_GFX transaction end hook.
void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
Draws a filled rounded rectangle (Adafruit_GFX::fillRoundRect()).
uint8_t width
Bitmap dimensions in pixels.
uint16_t first
ASCII extents (first char)
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Draws a vertical run of h pixels (Adafruit_GFX::drawFastVLine()).
void setTextSize(uint8_t size)
Accepts an Adafruit_GFX text size.
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Fills a rectangle of size w*h (Adafruit_GFX::fillRect()).
GfxCompat(D &display)
Creates an Adafruit_GFX-compatible facade bound to an existing display.
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Draws a horizontal run of w pixels (Adafruit_GFX::drawFastHLine()).
GfxCompat< D > makeGfxCompat(D &display)
Convenience factory that deduces the display type, so callers can write auto gfx = makeGfxCompat(disp...
int8_t lcdint_t
internal int type, used by the library.
int16_t height()
Returns display height in pixels (Adafruit_GFX::height()).
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draws a circle outline (Adafruit_GFX::drawCircle()).
SSD1306 HAL IO communication functions.
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Draws an arbitrary line (Adafruit_GFX::drawLine()).
size_t write(uint8_t ch)
Writes a single character at the text cursor (Adafruit_GFX::write()).
void setCursor(int16_t x, int16_t y)
Positions the text cursor (Adafruit_GFX::setCursor()).
uint8_t yAdvance
Newline distance (y axis)
void setFont(const GFXfont *font)
Selects an Adafruit_GFX custom font (GFXfont) for text output.
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Draws a triangle outline (Adafruit_GFX::drawTriangle()).
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draws a rectangle outline of size w*h (Adafruit_GFX::drawRect()).
void writePixel(int16_t x, int16_t y, uint16_t color)
Adafruit_GFX transaction pixel write; identical to drawPixel().
void println()
Emits a newline (Adafruit_GFX/Print::println()).
void print(char c)
Prints a single character (Adafruit_GFX/Print::print()).
void println(int number)
Prints an integer followed by a newline (Adafruit_GFX/Print::println()).
uint8_t xAdvance
Distance to advance cursor (x axis)
void fillScreen(uint16_t color)
Fills the whole screen with a single color (Adafruit_GFX::fillScreen()).
uint16_t last
ASCII extents (last char)
void println(const char *str)
Prints a string followed by a newline (Adafruit_GFX/Print::println()).
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Draws a filled triangle (Adafruit_GFX::fillTriangle()).
void setTextColor(uint16_t color, uint16_t background)
Sets text foreground and background color (Adafruit_GFX::setTextColor()).
uint8_t height
Bitmap dimensions in pixels.
void setTextColor(uint16_t color)
Sets text foreground color (Adafruit_GFX::setTextColor()).
int8_t yOffset
Y dist from cursor pos to UL corner.
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
Draws a 1-bit bitmap using the foreground color (Adafruit_GFX::drawBitmap()).
D & display()
Returns the wrapped lcdgfx display/canvas for native calls.
uint8_t * bitmap
Glyph bitmaps, concatenated.
void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
Draws a rounded-rectangle outline (Adafruit_GFX::drawRoundRect()).
Adafruit_GFX glyph descriptor.
void print(int number)
Prints a signed integer in base 10 (Adafruit_GFX/Print::print()).
int8_t xOffset
X dist from cursor pos to UL corner.
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draws a filled circle (Adafruit_GFX::fillCircle()).
void drawPixel(int16_t x, int16_t y, uint16_t color)
Draws a single pixel of the given color (Adafruit_GFX::drawPixel()).
void print(long number)
Prints a signed long in base 10 (Adafruit_GFX/Print::print()).
void setRotation(uint8_t rotation)
Accepts an Adafruit_GFX rotation value for source compatibility.
void print(const char *str)
Prints a null-terminated string (Adafruit_GFX/Print::print()).
Adafruit_GFX-compatible adapter around any lcdgfx display or canvas type D.
uint8_t getRotation()
Returns the stored rotation value (Adafruit_GFX::getRotation()).
int16_t width()
Returns display width in pixels (Adafruit_GFX::width()).