34#include "Adafruit_GFX.h"
37#include <avr/pgmspace.h>
38#elif defined(ESP8266) || defined(ESP32)
47#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
50#define pgm_read_word(addr) (*(const unsigned short *)(addr))
53#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
59#if !defined(__INT_MAX__) || (__INT_MAX__ > 0xFFFF)
60#define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
62#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
65inline GFXglyph *pgm_read_glyph_ptr(
const GFXfont *gfxFont, uint8_t c) {
67 return &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
73 return gfxFont->glyph + c;
77inline uint8_t *pgm_read_bitmap_ptr(
const GFXfont *gfxFont) {
79 return (uint8_t *)pgm_read_pointer(&gfxFont->bitmap);
85 return gfxFont->bitmap;
90#define min(a, b) (((a) < (b)) ? (a) : (b))
94#define _swap_int16_t(a, b) \
135 int16_t steep = abs(y1 - y0) > abs(x1 - x0);
137 _swap_int16_t(x0, y0);
138 _swap_int16_t(x1, y1);
142 _swap_int16_t(x0, x1);
143 _swap_int16_t(y0, y1);
150 int16_t err = dx / 2;
159 for (; x0 <= x1; x0++) {
301 for (int16_t i = x; i < x + w; i++) {
333 _swap_int16_t(y0, y1);
335 }
else if (y0 == y1) {
337 _swap_int16_t(x0, x1);
362 int16_t x = 0, y = rh;
363 int32_t rw2 = rw * rw, rh2 = rh * rh;
364 int32_t twoRw2 = 2 * rw2, twoRh2 = 2 * rh2;
366 int32_t decision = rh2 - (rw2 * rh) + (rw2 / 4);
371 while ((twoRh2 * x) < (twoRw2 * y)) {
378 decision += rh2 + (twoRh2 * x);
380 decision += rh2 + (twoRh2 * x) - (twoRw2 * y);
386 decision = ((rh2 * (2 * x + 1) * (2 * x + 1)) >> 2) +
387 (rw2 * (y - 1) * (y - 1)) - (rw2 * rh2);
395 decision += rw2 - (twoRw2 * y);
397 decision += rw2 + (twoRh2 * x) - (twoRw2 * y);
421 int16_t x = 0, y = rh;
422 int32_t rw2 = rw * rw, rh2 = rh * rh;
423 int32_t twoRw2 = 2 * rw2, twoRh2 = 2 * rh2;
425 int32_t decision = rh2 - (rw2 * rh) + (rw2 / 4);
430 while ((twoRh2 * x) < (twoRw2 * y)) {
433 decision += rh2 + (twoRh2 * x);
435 decision += rh2 + (twoRh2 * x) - (twoRw2 * y);
443 decision = ((rh2 * (2 * x + 1) * (2 * x + 1)) >> 2) +
444 (rw2 * (y - 1) * (y - 1)) - (rw2 * rh2);
451 decision += rw2 - (twoRw2 * y);
453 decision += rw2 + (twoRh2 * x) - (twoRw2 * y);
477 int16_t ddF_y = -2 * r;
521 uint8_t cornername, uint16_t color) {
524 int16_t ddF_y = -2 * r;
537 if (cornername & 0x4) {
541 if (cornername & 0x2) {
545 if (cornername & 0x8) {
549 if (cornername & 0x1) {
586 uint8_t corners, int16_t delta,
591 int16_t ddF_y = -2 * r;
659 int16_t r, uint16_t color) {
660 int16_t max_radius = ((w < h) ? w : h) / 2;
689 int16_t r, uint16_t color) {
690 int16_t max_radius = ((w < h) ? w : h) / 2;
720 int16_t h, int16_t angleDeg,
729 int16_t halfW = (W / 2);
730 int16_t halfH = (H / 2);
732 int16_t x0 = W - halfW;
733 int16_t y0 = H - halfH;
735 int16_t y1 = H - halfH;
738 int16_t x3 = W - halfW;
780 int16_t h, int16_t angleDeg,
789 int16_t halfW = (W / 2);
790 int16_t halfH = (H / 2);
792 int16_t x0 = W - halfW;
793 int16_t y0 = H - halfH;
795 int16_t y1 = H - halfH;
798 int16_t x3 = W - halfW;
831 float angleRad = radians(angleDeg);
832 float s = sin(angleRad);
833 float c = cos(angleRad);
839 x0 = (int16_t)((x * c) - (y * s));
840 y0 = (int16_t)((x * s) + (y * c));
856 int16_t x2, int16_t y2, uint16_t color) {
875 int16_t x2, int16_t y2, uint16_t color) {
877 int16_t a, b, y, last;
881 _swap_int16_t(y0, y1);
882 _swap_int16_t(x0, x1);
885 _swap_int16_t(y2, y1);
886 _swap_int16_t(x2, x1);
889 _swap_int16_t(y0, y1);
890 _swap_int16_t(x0, x1);
909 int16_t dx01 = x1 - x0, dy01 = y1 - y0, dx02 = x2 - x0, dy02 = y2 - y0,
910 dx12 = x2 - x1, dy12 = y2 - y1;
911 int32_t sa = 0, sb = 0;
924 for (y = y0; y <= last; y++) {
940 sa = (int32_t)dx12 * (y - y1);
941 sb = (int32_t)dx02 * (y - y0);
942 for (; y <= y2; y++) {
973 int16_t w, int16_t h, uint16_t color) {
975 int16_t byteWidth = (w + 7) / 8;
979 for (int16_t j = 0; j < h; j++, y++) {
980 for (int16_t i = 0; i < w; i++) {
984 b = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
1007 int16_t w, int16_t h, uint16_t color,
1010 int16_t byteWidth = (w + 7) / 8;
1014 for (int16_t j = 0; j < h; j++, y++) {
1015 for (int16_t i = 0; i < w; i++) {
1019 b = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
1020 writePixel(x + i, y, (b & 0x80) ? color : bg);
1039 int16_t h, uint16_t color) {
1041 int16_t byteWidth = (w + 7) / 8;
1045 for (int16_t j = 0; j < h; j++, y++) {
1046 for (int16_t i = 0; i < w; i++) {
1050 b = bitmap[j * byteWidth + i / 8];
1073 int16_t h, uint16_t color, uint16_t bg) {
1075 int16_t byteWidth = (w + 7) / 8;
1079 for (int16_t j = 0; j < h; j++, y++) {
1080 for (int16_t i = 0; i < w; i++) {
1084 b = bitmap[j * byteWidth + i / 8];
1085 writePixel(x + i, y, (b & 0x80) ? color : bg);
1107 int16_t w, int16_t h, uint16_t color) {
1109 int16_t byteWidth = (w + 7) / 8;
1113 for (int16_t j = 0; j < h; j++, y++) {
1114 for (int16_t i = 0; i < w; i++) {
1118 b = pgm_read_byte(&bitmap[j * byteWidth + i / 8]);
1141 const uint8_t bitmap[], int16_t w,
1144 for (int16_t j = 0; j < h; j++, y++) {
1145 for (int16_t i = 0; i < w; i++) {
1146 writePixel(x + i, y, (uint8_t)pgm_read_byte(&bitmap[j * w + i]));
1165 int16_t w, int16_t h) {
1167 for (int16_t j = 0; j < h; j++, y++) {
1168 for (int16_t i = 0; i < w; i++) {
1191 const uint8_t bitmap[],
1192 const uint8_t mask[], int16_t w,
1194 int16_t bw = (w + 7) / 8;
1197 for (int16_t j = 0; j < h; j++, y++) {
1198 for (int16_t i = 0; i < w; i++) {
1202 b = pgm_read_byte(&mask[j * bw + i / 8]);
1204 writePixel(x + i, y, (uint8_t)pgm_read_byte(&bitmap[j * w + i]));
1227 uint8_t *mask, int16_t w, int16_t h) {
1228 int16_t bw = (w + 7) / 8;
1231 for (int16_t j = 0; j < h; j++, y++) {
1232 for (int16_t i = 0; i < w; i++) {
1236 b = mask[j * bw + i / 8];
1257 int16_t w, int16_t h) {
1259 for (int16_t j = 0; j < h; j++, y++) {
1260 for (int16_t i = 0; i < w; i++) {
1261 writePixel(x + i, y, pgm_read_word(&bitmap[j * w + i]));
1279 int16_t w, int16_t h) {
1281 for (int16_t j = 0; j < h; j++, y++) {
1282 for (int16_t i = 0; i < w; i++) {
1304 const uint8_t mask[], int16_t w, int16_t h) {
1305 int16_t bw = (w + 7) / 8;
1308 for (int16_t j = 0; j < h; j++, y++) {
1309 for (int16_t i = 0; i < w; i++) {
1313 b = pgm_read_byte(&mask[j * bw + i / 8]);
1315 writePixel(x + i, y, pgm_read_word(&bitmap[j * w + i]));
1337 uint8_t *mask, int16_t w, int16_t h) {
1338 int16_t bw = (w + 7) / 8;
1341 for (int16_t j = 0; j < h; j++, y++) {
1342 for (int16_t i = 0; i < w; i++) {
1346 b = mask[j * bw + i / 8];
1371 uint16_t color, uint16_t bg, uint8_t size) {
1372 drawChar(x, y, c, color, bg, size, size);
1390 uint16_t color, uint16_t bg, uint8_t size_x,
1397 ((x + 6 * size_x - 1) < 0) ||
1398 ((y + 8 * size_y - 1) < 0))
1401 if (!
_cp437 && (c >= 176))
1405 for (int8_t i = 0; i < 5; i++) {
1406 uint8_t line = pgm_read_byte(&font[c * 5 + i]);
1407 for (int8_t j = 0; j < 8; j++, line >>= 1) {
1409 if (size_x == 1 && size_y == 1)
1412 writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y,
1414 }
else if (bg != color) {
1415 if (size_x == 1 && size_y == 1)
1418 writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y, bg);
1423 if (size_x == 1 && size_y == 1)
1436 c -= (uint8_t)pgm_read_byte(&
gfxFont->first);
1437 GFXglyph *glyph = pgm_read_glyph_ptr(
gfxFont, c);
1438 uint8_t *bitmap = pgm_read_bitmap_ptr(
gfxFont);
1440 uint16_t bo = pgm_read_word(&glyph->bitmapOffset);
1441 uint8_t w = pgm_read_byte(&glyph->width), h = pgm_read_byte(&glyph->height);
1442 int8_t xo = pgm_read_byte(&glyph->xOffset),
1443 yo = pgm_read_byte(&glyph->yOffset);
1444 uint8_t xx, yy, bits = 0, bit = 0;
1445 int16_t xo16 = 0, yo16 = 0;
1447 if (size_x > 1 || size_y > 1) {
1471 for (yy = 0; yy < h; yy++) {
1472 for (xx = 0; xx < w; xx++) {
1474 bits = pgm_read_byte(&bitmap[bo++]);
1477 if (size_x == 1 && size_y == 1) {
1480 writeFillRect(x + (xo16 + xx) * size_x, y + (yo16 + yy) * size_y,
1481 size_x, size_y, color);
1503 }
else if (c !=
'\r') {
1519 }
else if (c !=
'\r') {
1520 uint8_t first = pgm_read_byte(&
gfxFont->first);
1521 if ((c >= first) && (c <= (uint8_t)pgm_read_byte(&
gfxFont->last))) {
1522 GFXglyph *glyph = pgm_read_glyph_ptr(
gfxFont, c - first);
1523 uint8_t w = pgm_read_byte(&glyph->width),
1524 h = pgm_read_byte(&glyph->height);
1525 if ((w > 0) && (h > 0)) {
1526 int16_t xo = (int8_t)pgm_read_byte(&glyph->xOffset);
1530 (uint8_t)pgm_read_byte(&
gfxFont->yAdvance);
1536 (uint8_t)pgm_read_byte(&glyph->xAdvance) * (int16_t)
textsize_x;
1627 int16_t *minx, int16_t *miny, int16_t *maxx,
1635 }
else if (c !=
'\r') {
1636 uint8_t first = pgm_read_byte(&
gfxFont->first),
1637 last = pgm_read_byte(&
gfxFont->last);
1638 if ((c >= first) && (c <= last)) {
1639 GFXglyph *glyph = pgm_read_glyph_ptr(
gfxFont, c - first);
1640 uint8_t gw = pgm_read_byte(&glyph->width),
1641 gh = pgm_read_byte(&glyph->height),
1642 xa = pgm_read_byte(&glyph->xAdvance);
1643 int8_t xo = pgm_read_byte(&glyph->xOffset),
1644 yo = pgm_read_byte(&glyph->yOffset);
1650 x1 = *x + xo * tsx, y1 = *y + yo * tsy, x2 = x1 + gw * tsx - 1,
1651 y2 = y1 + gh * tsy - 1;
1670 }
else if (c !=
'\r') {
1704 int16_t *x1, int16_t *y1, uint16_t *w,
1708 int16_t minx = 0x7FFF, miny = 0x7FFF, maxx = -1, maxy = -1;
1715 while ((c = *str++)) {
1718 charBounds(c, &x, &y, &minx, &miny, &maxx, &maxy);
1723 *w = maxx - minx + 1;
1727 *h = maxy - miny + 1;
1745 int16_t *x1, int16_t *y1, uint16_t *w,
1766 int16_t y, int16_t *x1, int16_t *y1,
1767 uint16_t *w, uint16_t *h) {
1768 uint8_t *s = (uint8_t *)str, c;
1774 int16_t minx =
_width, miny =
_height, maxx = -1, maxy = -1;
1776 while ((c = pgm_read_byte(s++)))
1777 charBounds(c, &x, &y, &minx, &miny, &maxx, &maxy);
1781 *w = maxx - minx + 1;
1785 *h = maxy - miny + 1;
1826 uint16_t w, uint16_t h, uint16_t outline,
1827 uint16_t fill, uint16_t textcolor,
1828 char *label, uint8_t textsize) {
1830 initButtonUL(gfx, x - (w / 2), y - (h / 2), w, h, outline, fill, textcolor,
1852 uint16_t w, uint16_t h, uint16_t outline,
1853 uint16_t fill, uint16_t textcolor,
1854 char *label, uint8_t textsize_x,
1855 uint8_t textsize_y) {
1857 initButtonUL(gfx, x - (w / 2), y - (h / 2), w, h, outline, fill, textcolor,
1858 label, textsize_x, textsize_y);
1878 int16_t y1, uint16_t w, uint16_t h,
1879 uint16_t outline, uint16_t fill,
1880 uint16_t textcolor,
char *label,
1882 initButtonUL(gfx, x1, y1, w, h, outline, fill, textcolor, label, textsize,
1904 int16_t y1, uint16_t w, uint16_t h,
1905 uint16_t outline, uint16_t fill,
1906 uint16_t textcolor,
char *label,
1907 uint8_t textsize_x, uint8_t textsize_y) {
1912 _outlinecolor = outline;
1914 _textcolor = textcolor;
1915 _textsize_x = textsize_x;
1916 _textsize_y = textsize_y;
1918 strncpy(_label, label, 9);
1931 uint16_t fill, outline, text;
1935 outline = _outlinecolor;
1939 outline = _outlinecolor;
1943 uint8_t r = min(_w, _h) / 4;
1947 _gfx->
setCursor(_x1 + (_w / 2) - (strlen(_label) * 3 * _textsize_x),
1948 _y1 + (_h / 2) - (4 * _textsize_y));
1951 _gfx->
print(_label);
1964 return ((x >= _x1) && (x < (int16_t)(_x1 + _w)) && (y >= _y1) &&
1965 (y < (int16_t)(_y1 + _h)));
2005const uint8_t PROGMEM GFXcanvas1::GFXsetBit[] = {0x80, 0x40, 0x20, 0x10,
2006 0x08, 0x04, 0x02, 0x01};
2007const uint8_t PROGMEM GFXcanvas1::GFXclrBit[] = {0x7F, 0xBF, 0xDF, 0xEF,
2008 0xF7, 0xFB, 0xFD, 0xFE};
2024 if (allocate_buffer) {
2025 uint32_t bytes = ((w + 7) / 8) * h;
2026 if ((
buffer = (uint8_t *)malloc(bytes))) {
2027 memset(
buffer, 0, bytes);
2075 uint8_t *ptr = &
buffer[(x / 8) + y * ((
WIDTH + 7) / 8)];
2078 *ptr |= pgm_read_byte(&GFXsetBit[x & 7]);
2080 *ptr &= pgm_read_byte(&GFXclrBit[x & 7]);
2083 *ptr |= 0x80 >> (x & 7);
2085 *ptr &= ~(0x80 >> (x & 7));
2128 if ((x < 0) || (y < 0) || (x >=
WIDTH) || (y >=
HEIGHT))
2131 uint8_t *ptr = &
buffer[(x / 8) + y * ((
WIDTH + 7) / 8)];
2134 return ((*ptr) & pgm_read_byte(&GFXsetBit[x & 7])) != 0;
2136 return ((*ptr) & (0x80 >> (x & 7))) != 0;
2151 memset(
buffer, color ? 0xFF : 0x00, bytes);
2177 if ((x < 0) || (x >=
width()) || (y >=
height()) || ((y + h - 1) < 0)) {
2232 if ((y < 0) || (y >=
height()) || (x >=
width()) || ((x + w - 1) < 0)) {
2240 if (x + w >=
width()) {
2278 int16_t row_bytes = ((
WIDTH + 7) / 8);
2279 uint8_t *ptr = &
buffer[(x / 8) + y * row_bytes];
2283 uint8_t bit_mask = pgm_read_byte(&GFXsetBit[x & 7]);
2285 uint8_t bit_mask = (0x80 >> (x & 7));
2287 for (int16_t i = 0; i < h; i++) {
2293 uint8_t bit_mask = pgm_read_byte(&GFXclrBit[x & 7]);
2295 uint8_t bit_mask = ~(0x80 >> (x & 7));
2297 for (int16_t i = 0; i < h; i++) {
2316 int16_t rowBytes = ((
WIDTH + 7) / 8);
2317 uint8_t *ptr = &
buffer[(x / 8) + y * rowBytes];
2318 size_t remainingWidthBits = w;
2323 uint8_t startByteBitMask = 0x00;
2324 for (int8_t i = (x & 7); ((i < 8) && (remainingWidthBits > 0)); i++) {
2326 startByteBitMask |= pgm_read_byte(&GFXsetBit[i]);
2328 startByteBitMask |= (0x80 >> i);
2330 remainingWidthBits--;
2333 *ptr |= startByteBitMask;
2335 *ptr &= ~startByteBitMask;
2342 if (remainingWidthBits > 0) {
2343 size_t remainingWholeBytes = remainingWidthBits / 8;
2344 size_t lastByteBits = remainingWidthBits % 8;
2345 uint8_t wholeByteColor = color > 0 ? 0xFF : 0x00;
2347 memset(ptr, wholeByteColor, remainingWholeBytes);
2349 if (lastByteBits > 0) {
2350 uint8_t lastByteBitMask = 0x00;
2351 for (
size_t i = 0; i < lastByteBits; i++) {
2353 lastByteBitMask |= pgm_read_byte(&GFXsetBit[i]);
2355 lastByteBitMask |= (0x80 >> i);
2358 ptr += remainingWholeBytes;
2361 *ptr |= lastByteBitMask;
2363 *ptr &= ~lastByteBitMask;
2382 if (allocate_buffer) {
2383 uint32_t bytes = w * h;
2384 if ((
buffer = (uint8_t *)malloc(bytes))) {
2385 memset(
buffer, 0, bytes);
2476 if ((x < 0) || (y < 0) || (x >=
WIDTH) || (y >=
HEIGHT))
2518 if ((x < 0) || (x >=
width()) || (y >=
height()) || ((y + h - 1) < 0)) {
2575 if ((y < 0) || (y >=
height()) || (x >=
width()) || ((x + w - 1) < 0)) {
2583 if (x + w >=
width()) {
2623 for (int16_t i = 0; i < h; i++) {
2624 (*buffer_ptr) = color;
2625 buffer_ptr +=
WIDTH;
2658 if (allocate_buffer) {
2659 uint32_t bytes = w * h * 2;
2660 if ((
buffer = (uint16_t *)malloc(bytes))) {
2661 memset(
buffer, 0, bytes);
2753 if ((x < 0) || (y < 0) || (x >=
WIDTH) || (y >=
HEIGHT))
2769 uint8_t hi = color >> 8, lo = color & 0xFF;
2774 for (i = 0; i < pixels; i++)
2796 for (i = 0; i < pixels; i++)
2822 if ((x < 0) || (x >=
width()) || (y >=
height()) || ((y + h - 1) < 0)) {
2877 if ((y < 0) || (y >=
height()) || (x >=
width()) || ((x + w - 1) < 0)) {
2885 if (x + w >=
width()) {
2924 for (int16_t i = 0; i < h; i++) {
2925 (*buffer_ptr) = color;
2926 buffer_ptr +=
WIDTH;
2942 uint32_t buffer_index = y *
WIDTH + x;
2943 for (uint32_t i = buffer_index; i < buffer_index + w; i++) {
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Draw a perfectly vertical line (this is often optimized in a subclass!)
void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color)
Half-circle drawer with fill, used for circles and roundrects.
uint16_t textbgcolor
16-bit text color for print()
virtual void fillScreen(uint16_t color)
Fill the screen completely with one color. Update in subclasses if desired!
int16_t HEIGHT
This is the 'raw' display height - never changes.
int16_t width(void) const
Get width of the display, accounting for current rotation.
uint8_t rotation
Display rotation (0 thru 3)
void setTextSize(uint8_t s)
Set text 'magnification' size. Each increase in s makes 1 pixel that much bigger.
void rotatePoint(int16_t &x0, int16_t &y0, int16_t angleDeg)
Rotate a point in standard position.
void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color)
Quarter-circle drawer, used to do circles and roundrects.
void fillRotatedRect(int16_t cenX, int16_t cenY, int16_t w, int16_t h, int16_t angleDeg, uint16_t color)
Draw a filled rotated rectangle.
virtual void invertDisplay(bool i)
Invert the display (ideally using built-in hardware command)
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Draw a triangle with no fill color.
int16_t height(void) const
Get height of the display, accounting for current rotation.
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Draw a triangle with color-fill.
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Draw a perfectly horizontal line (this is often optimized in a subclass!)
void setTextColor(uint16_t c)
Set text font color with transparant background.
virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Write a rectangle completely with one color, overwrite in subclasses if startWrite is defined!
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a circle with filled color.
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a circle outline.
void charBounds(unsigned char c, int16_t *x, int16_t *y, int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy)
Helper to determine size of a character with current font/size. Broke this out as it's used by both t...
virtual void setRotation(uint8_t r)
Set rotation setting for display.
Adafruit_GFX(int16_t w, int16_t h)
Instatiate a GFX context for graphics! Can only be done by a superclass.
bool _cp437
If set, use correct CP437 charset (default is off)
void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
Draw a rounded rectangle with fill color.
void fillEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh, uint16_t color)
Draw an ellipse with filled colour.
void drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
Draw a PROGMEM-resident 1-bit image at the specified (x,y) position, using the specified foreground c...
virtual void write(uint8_t)
Print one byte/character of data, used to support print()
bool wrap
If set, 'wrap' text at right edge of display.
uint16_t textcolor
16-bit background color for print()
int16_t cursor_x
x location to start print()ing text
void getTextBounds(const char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
Helper to determine size of a string with current font/size. Pass string and a cursor position,...
uint8_t textsize_x
Desired magnification in X-axis of text to print()
virtual void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a rectangle with no fill color.
virtual void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Draw a line.
virtual void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Fill a rectangle completely with one color. Update in subclasses if desired!
void drawEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh, uint16_t color)
Draw an ellipse outline.
void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
Draw PROGMEM-resident XBitMap Files (*.xbm), exported from GIMP. Usage: Export from GIMP to *....
uint8_t textsize_y
Desired magnification in Y-axis of text to print()
virtual void startWrite(void)
Start a display-writing routine, overwrite in subclasses.
void setCursor(int16_t x, int16_t y)
Set text cursor location.
void setFont(const GFXfont *f=NULL)
Set the font to display when print()ing, either custom or default.
int16_t _width
Display width as modified by current rotation.
void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
Draw a rounded rectangle with no fill color.
virtual void writePixel(int16_t x, int16_t y, uint16_t color)
Write a pixel, overwrite in subclasses if startWrite is defined!
void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
Draw a single character.
virtual void drawPixel(int16_t x, int16_t y, uint16_t color)=0
Draw to the screen/framebuffer/etc. Must be overridden in subclass.
uint8_t getRotation(void) const
Get rotation setting for display.
int16_t _height
Display height as modified by current rotation.
virtual void endWrite(void)
End a display-writing routine, overwrite in subclasses if startWrite is defined!
virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Write a perfectly horizontal line, overwrite in subclasses if startWrite is defined!
int16_t WIDTH
This is the 'raw' display width - never changes.
virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Write a perfectly vertical line, overwrite in subclasses if startWrite is defined!
virtual void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Write a line. Bresenham's algorithm - thx wikpedia.
int16_t cursor_y
y location to start print()ing text
void drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h)
Draw a PROGMEM-resident 8-bit image (grayscale) at the specified (x,y) pos. Specifically for 8-bit di...
void drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h)
Draw a PROGMEM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position. For 16-bit display ...
void drawRotatedRect(int16_t cenX, int16_t cenY, int16_t w, int16_t h, int16_t angleDeg, uint16_t color)
Draw a rotated rectangle.
GFXfont * gfxFont
Pointer to special font.
void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Speed optimized horizontal line drawing into the raw canvas buffer.
uint16_t * buffer
Raster data: no longer private, allow subclass access.
~GFXcanvas16(void)
Delete the canvas, free memory.
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Speed optimized vertical line drawing.
void byteSwap(void)
Reverses the "endian-ness" of each 16-bit pixel within the canvas; little-endian to big-endian,...
void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Speed optimized vertical line drawing into the raw canvas buffer.
uint16_t getPixel(int16_t x, int16_t y) const
Get the pixel color value at a given coordinate.
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Speed optimized horizontal line drawing.
void drawPixel(int16_t x, int16_t y, uint16_t color)
Draw a pixel to the canvas framebuffer.
void fillScreen(uint16_t color)
Fill the framebuffer completely with one color.
uint16_t getRawPixel(int16_t x, int16_t y) const
Get the pixel color value at a given, unrotated coordinate. This method is intended for hardware driv...
GFXcanvas16(uint16_t w, uint16_t h, bool allocate_buffer=true)
Instatiate a GFX 16-bit canvas context for graphics.
void drawPixel(int16_t x, int16_t y, uint16_t color)
Draw a pixel to the canvas framebuffer.
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Speed optimized vertical line drawing.
void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Speed optimized vertical line drawing into the raw canvas buffer.
GFXcanvas1(uint16_t w, uint16_t h, bool allocate_buffer=true)
Instatiate a GFX 1-bit canvas context for graphics.
bool getRawPixel(int16_t x, int16_t y) const
Get the pixel color value at a given, unrotated coordinate. This method is intended for hardware driv...
void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Speed optimized horizontal line drawing into the raw canvas buffer.
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Speed optimized horizontal line drawing.
~GFXcanvas1(void)
Delete the canvas, free memory.
bool getPixel(int16_t x, int16_t y) const
Get the pixel color value at a given coordinate.
void fillScreen(uint16_t color)
Fill the framebuffer completely with one color.
uint8_t * buffer
Raster data: no longer private, allow subclass access.
~GFXcanvas8(void)
Delete the canvas, free memory.
uint8_t getRawPixel(int16_t x, int16_t y) const
Get the pixel color value at a given, unrotated coordinate. This method is intended for hardware driv...
void drawPixel(int16_t x, int16_t y, uint16_t color)
Draw a pixel to the canvas framebuffer.
uint8_t getPixel(int16_t x, int16_t y) const
Get the pixel color value at a given coordinate.
GFXcanvas8(uint16_t w, uint16_t h, bool allocate_buffer=true)
Instatiate a GFX 8-bit canvas context for graphics.
void drawFastRawHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Speed optimized horizontal line drawing into the raw canvas buffer.
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Speed optimized vertical line drawing.
void fillScreen(uint16_t color)
Fill the framebuffer completely with one color.
uint8_t * buffer
Raster data: no longer private, allow subclass access.
void drawFastRawVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Speed optimized vertical line drawing into the raw canvas buffer.
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Speed optimized horizontal line drawing.
size_t print(const __FlashStringHelper *ifsh)
Minimal Arduino-String stand-in (see file description).
const char * c_str() const
unsigned int length() const