From 1bf3e7ea20f5cf6953ef4446d824adcb0f49b917 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 1 Dec 2022 19:49:00 +0100 Subject: [PATCH] Removed a lot of useless shit --- TFT_eSPI.cpp | 980 ++++----------------------------------------------- TFT_eSPI.h | 157 +++------ 2 files changed, 135 insertions(+), 1002 deletions(-) diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 03e6964..67f916f 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -467,12 +467,7 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h) resetViewport(); rotation = 0; - cursor_y = cursor_x = last_cursor_x = bg_cursor_x = 0; - textfont = 1; textsize = 1; - textcolor = bitmap_fg = 0xFFFF; // White - textbgcolor = bitmap_bg = 0x0000; // Black - padX = 0; // No padding _fillbg = false; // Smooth font only at the moment, force text background fill @@ -1375,7 +1370,7 @@ void TFT_eSPI::pushRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da ** Function name: pushImage ** Description: plot 16 bit colour sprite or image onto TFT ***************************************************************************************/ -void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data) +void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data) { PI_CLIP; @@ -1405,7 +1400,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d ** Function name: pushImage ** Description: plot 16 bit sprite or image with 1 colour being transparent ***************************************************************************************/ -void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transp) +void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transp) { PI_CLIP; @@ -1423,7 +1418,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d while (dh--) { int32_t len = dw; - uint16_t* ptr = data; + const uint16_t* ptr = data; int32_t px = x, sx = x; bool move = true; uint16_t np = 0; @@ -1442,7 +1437,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d if (np) { setWindow(sx, y, sx + np - 1, y); - pushPixels((uint16_t*)lineBuf, np); + pushPixels((const uint16_t*)lineBuf, np); np = 0; } } @@ -1460,564 +1455,6 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d } -/*************************************************************************************** -** Function name: pushImage - for FLASH (PROGMEM) stored images -** Description: plot 16 bit image -***************************************************************************************/ -void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data) -{ - // Requires 32 bit aligned access, so use PROGMEM 16 bit word functions - PI_CLIP; - - begin_tft_write(); - inTransaction = true; - - data += dx + dy * w; - - uint16_t buffer[dw]; - - setWindow(x, y, x + dw - 1, y + dh - 1); - - // Fill and send line buffers to TFT - for (int32_t i = 0; i < dh; i++) { - for (int32_t j = 0; j < dw; j++) { - buffer[j] = pgm_read_word(&data[i * w + j]); - } - pushPixels(buffer, dw); - } - - inTransaction = lockTransaction; - end_tft_write(); -} - -/*************************************************************************************** -** Function name: pushImage - for FLASH (PROGMEM) stored images -** Description: plot 16 bit image with 1 colour being transparent -***************************************************************************************/ -void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transp) -{ - // Requires 32 bit aligned access, so use PROGMEM 16 bit word functions - PI_CLIP; - - begin_tft_write(); - inTransaction = true; - - data += dx + dy * w; - - - uint16_t lineBuf[dw]; - - // The little endian transp color must be byte swapped if the image is big endian - if (!_swapBytes) transp = transp >> 8 | transp << 8; - - while (dh--) { - int32_t len = dw; - uint16_t* ptr = (uint16_t*)data; - int32_t px = x, sx = x; - bool move = true; - - uint16_t np = 0; - - while (len--) { - uint16_t color = pgm_read_word(ptr); - if (transp != color) { - if (move) { move = false; sx = px; } - lineBuf[np] = color; - np++; - } - else { - move = true; - if (np) { - setWindow(sx, y, sx + np - 1, y); - pushPixels(lineBuf, np); - np = 0; - } - } - px++; - ptr++; - } - if (np) { setWindow(sx, y, sx + np - 1, y); pushPixels(lineBuf, np); } - - y++; - data += w; - } - - inTransaction = lockTransaction; - end_tft_write(); -} - -/*************************************************************************************** -** Function name: pushImage -** Description: plot 8 bit or 4 bit or 1 bit image or sprite using a line buffer -***************************************************************************************/ -void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data, bool bpp8, uint16_t *cmap) -{ - PI_CLIP; - - begin_tft_write(); - inTransaction = true; - bool swap = _swapBytes; - - setWindow(x, y, x + dw - 1, y + dh - 1); // Sets CS low and sent RAMWR - - // Line buffer makes plotting faster - uint16_t lineBuf[dw]; - - if (bpp8) - { - _swapBytes = false; - - uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table - - _lastColor = -1; // Set to illegal value - - // Used to store last shifted colour - uint8_t msbColor = 0; - uint8_t lsbColor = 0; - - data += dx + dy * w; - while (dh--) { - uint32_t len = dw; - uint8_t* ptr = (uint8_t*)data; - uint8_t* linePtr = (uint8_t*)lineBuf; - - while(len--) { - uint32_t color = pgm_read_byte(ptr++); - - // Shifts are slow so check if colour has changed first - if (color != _lastColor) { - // =====Green===== ===============Red============== - msbColor = (color & 0x1C)>>2 | (color & 0xC0)>>3 | (color & 0xE0); - // =====Green===== =======Blue====== - lsbColor = (color & 0x1C)<<3 | blue[color & 0x03]; - _lastColor = color; - } - - *linePtr++ = msbColor; - *linePtr++ = lsbColor; - } - - pushPixels(lineBuf, dw); - - data += w; - } - _swapBytes = swap; // Restore old value - } - else if (cmap != nullptr) // Must be 4bpp - { - _swapBytes = true; - - w = (w+1) & 0xFFFE; // if this is a sprite, w will already be even; this does no harm. - bool splitFirst = (dx & 0x01) != 0; // split first means we have to push a single px from the left of the sprite / image - - if (splitFirst) { - data += ((dx - 1 + dy * w) >> 1); - } - else { - data += ((dx + dy * w) >> 1); - } - - while (dh--) { - uint32_t len = dw; - uint8_t * ptr = (uint8_t*)data; - uint16_t *linePtr = lineBuf; - uint8_t colors; // two colors in one byte - uint16_t index; - - if (splitFirst) { - colors = pgm_read_byte(ptr); - index = (colors & 0x0F); - *linePtr++ = cmap[index]; - len--; - ptr++; - } - - while (len--) - { - colors = pgm_read_byte(ptr); - index = ((colors & 0xF0) >> 4) & 0x0F; - *linePtr++ = cmap[index]; - - if (len--) - { - index = colors & 0x0F; - *linePtr++ = cmap[index]; - } else { - break; // nothing to do here - } - - ptr++; - } - - pushPixels(lineBuf, dw); - data += (w >> 1); - } - _swapBytes = swap; // Restore old value - } - else // Must be 1bpp - { - _swapBytes = false; - uint8_t * ptr = (uint8_t*)data; - uint32_t ww = (w+7)>>3; // Width of source image line in bytes - for (int32_t yp = dy; yp < dy + dh; yp++) - { - uint8_t* linePtr = (uint8_t*)lineBuf; - for (int32_t xp = dx; xp < dx + dw; xp++) - { - uint16_t col = (pgm_read_byte(ptr + (xp>>3)) & (0x80 >> (xp & 0x7)) ); - if (col) {*linePtr++ = bitmap_fg>>8; *linePtr++ = (uint8_t) bitmap_fg;} - else {*linePtr++ = bitmap_bg>>8; *linePtr++ = (uint8_t) bitmap_bg;} - } - ptr += ww; - pushPixels(lineBuf, dw); - } - } - - _swapBytes = swap; // Restore old value - inTransaction = lockTransaction; - end_tft_write(); -} - - -/*************************************************************************************** -** Function name: pushImage -** Description: plot 8 bit or 4 bit or 1 bit image or sprite using a line buffer -***************************************************************************************/ -void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, bool bpp8, uint16_t *cmap) -{ - PI_CLIP; - - begin_tft_write(); - inTransaction = true; - bool swap = _swapBytes; - - setWindow(x, y, x + dw - 1, y + dh - 1); // Sets CS low and sent RAMWR - - // Line buffer makes plotting faster - uint16_t lineBuf[dw]; - - if (bpp8) - { - _swapBytes = false; - - uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table - - _lastColor = -1; // Set to illegal value - - // Used to store last shifted colour - uint8_t msbColor = 0; - uint8_t lsbColor = 0; - - data += dx + dy * w; - while (dh--) { - uint32_t len = dw; - uint8_t* ptr = data; - uint8_t* linePtr = (uint8_t*)lineBuf; - - while(len--) { - uint32_t color = *ptr++; - - // Shifts are slow so check if colour has changed first - if (color != _lastColor) { - // =====Green===== ===============Red============== - msbColor = (color & 0x1C)>>2 | (color & 0xC0)>>3 | (color & 0xE0); - // =====Green===== =======Blue====== - lsbColor = (color & 0x1C)<<3 | blue[color & 0x03]; - _lastColor = color; - } - - *linePtr++ = msbColor; - *linePtr++ = lsbColor; - } - - pushPixels(lineBuf, dw); - - data += w; - } - _swapBytes = swap; // Restore old value - } - else if (cmap != nullptr) // Must be 4bpp - { - _swapBytes = true; - - w = (w+1) & 0xFFFE; // if this is a sprite, w will already be even; this does no harm. - bool splitFirst = (dx & 0x01) != 0; // split first means we have to push a single px from the left of the sprite / image - - if (splitFirst) { - data += ((dx - 1 + dy * w) >> 1); - } - else { - data += ((dx + dy * w) >> 1); - } - - while (dh--) { - uint32_t len = dw; - uint8_t * ptr = data; - uint16_t *linePtr = lineBuf; - uint8_t colors; // two colors in one byte - uint16_t index; - - if (splitFirst) { - colors = *ptr; - index = (colors & 0x0F); - *linePtr++ = cmap[index]; - len--; - ptr++; - } - - while (len--) - { - colors = *ptr; - index = ((colors & 0xF0) >> 4) & 0x0F; - *linePtr++ = cmap[index]; - - if (len--) - { - index = colors & 0x0F; - *linePtr++ = cmap[index]; - } else { - break; // nothing to do here - } - - ptr++; - } - - pushPixels(lineBuf, dw); - data += (w >> 1); - } - _swapBytes = swap; // Restore old value - } - else // Must be 1bpp - { - _swapBytes = false; - - uint32_t ww = (w+7)>>3; // Width of source image line in bytes - for (int32_t yp = dy; yp < dy + dh; yp++) - { - uint8_t* linePtr = (uint8_t*)lineBuf; - for (int32_t xp = dx; xp < dx + dw; xp++) - { - uint16_t col = (data[(xp>>3)] & (0x80 >> (xp & 0x7)) ); - if (col) {*linePtr++ = bitmap_fg>>8; *linePtr++ = (uint8_t) bitmap_fg;} - else {*linePtr++ = bitmap_bg>>8; *linePtr++ = (uint8_t) bitmap_bg;} - } - data += ww; - pushPixels(lineBuf, dw); - } - } - - _swapBytes = swap; // Restore old value - inTransaction = lockTransaction; - end_tft_write(); -} - - -/*************************************************************************************** -** Function name: pushImage -** Description: plot 8 or 4 or 1 bit image or sprite with a transparent colour -***************************************************************************************/ -void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, uint8_t transp, bool bpp8, uint16_t *cmap) -{ - PI_CLIP; - - begin_tft_write(); - inTransaction = true; - bool swap = _swapBytes; - - - // Line buffer makes plotting faster - uint16_t lineBuf[dw]; - - if (bpp8) { // 8 bits per pixel - _swapBytes = false; - - data += dx + dy * w; - - uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table - - _lastColor = -1; // Set to illegal value - - // Used to store last shifted colour - uint8_t msbColor = 0; - uint8_t lsbColor = 0; - - while (dh--) { - int32_t len = dw; - uint8_t* ptr = data; - uint8_t* linePtr = (uint8_t*)lineBuf; - - int32_t px = x, sx = x; - bool move = true; - uint16_t np = 0; - - while (len--) { - if (transp != *ptr) { - if (move) { move = false; sx = px; } - uint8_t color = *ptr; - - // Shifts are slow so check if colour has changed first - if (color != _lastColor) { - // =====Green===== ===============Red============== - msbColor = (color & 0x1C)>>2 | (color & 0xC0)>>3 | (color & 0xE0); - // =====Green===== =======Blue====== - lsbColor = (color & 0x1C)<<3 | blue[color & 0x03]; - _lastColor = color; - } - *linePtr++ = msbColor; - *linePtr++ = lsbColor; - np++; - } - else { - move = true; - if (np) { - setWindow(sx, y, sx + np - 1, y); - pushPixels(lineBuf, np); - linePtr = (uint8_t*)lineBuf; - np = 0; - } - } - px++; - ptr++; - } - - if (np) { setWindow(sx, y, sx + np - 1, y); pushPixels(lineBuf, np); } - y++; - data += w; - } - } - else if (cmap != nullptr) // 4bpp with color map - { - _swapBytes = true; - - w = (w+1) & 0xFFFE; // here we try to recreate iwidth from dwidth. - bool splitFirst = ((dx & 0x01) != 0); - if (splitFirst) { - data += ((dx - 1 + dy * w) >> 1); - } - else { - data += ((dx + dy * w) >> 1); - } - - while (dh--) { - uint32_t len = dw; - uint8_t * ptr = data; - - int32_t px = x, sx = x; - bool move = true; - uint16_t np = 0; - - uint8_t index; // index into cmap. - - if (splitFirst) { - index = (*ptr & 0x0F); // odd = bits 3 .. 0 - if (index != transp) { - move = false; sx = px; - lineBuf[np] = cmap[index]; - np++; - } - px++; ptr++; - len--; - } - - while (len--) - { - uint8_t color = *ptr; - - // find the actual color you care about. There will be two pixels here! - // but we may only want one at the end of the row - uint16_t index = ((color & 0xF0) >> 4) & 0x0F; // high bits are the even numbers - if (index != transp) { - if (move) { - move = false; sx = px; - } - lineBuf[np] = cmap[index]; - np++; // added a pixel - } - else { - move = true; - if (np) { - setWindow(sx, y, sx + np - 1, y); - pushPixels(lineBuf, np); - np = 0; - } - } - px++; - - if (len--) - { - index = color & 0x0F; // the odd number is 3 .. 0 - if (index != transp) { - if (move) { - move = false; sx = px; - } - lineBuf[np] = cmap[index]; - np++; - } - else { - move = true; - if (np) { - setWindow(sx, y, sx + np - 1, y); - pushPixels(lineBuf, np); - np = 0; - } - } - px++; - } - else { - break; // we are done with this row. - } - ptr++; // we only increment ptr once in the loop (deliberate) - } - - if (np) { - setWindow(sx, y, sx + np - 1, y); - pushPixels(lineBuf, np); - np = 0; - } - data += (w>>1); - y++; - } - } - else { // 1 bit per pixel - _swapBytes = false; - - uint32_t ww = (w+7)>>3; // Width of source image line in bytes - uint16_t np = 0; - - for (int32_t yp = dy; yp < dy + dh; yp++) - { - int32_t px = x, sx = x; - bool move = true; - for (int32_t xp = dx; xp < dx + dw; xp++) - { - if (data[(xp>>3)] & (0x80 >> (xp & 0x7))) { - if (move) { - move = false; - sx = px; - } - np++; - } - else { - move = true; - if (np) { - setWindow(sx, y, sx + np - 1, y); - pushBlock(bitmap_fg, np); - np = 0; - } - } - px++; - } - if (np) { setWindow(sx, y, sx + np - 1, y); pushBlock(bitmap_fg, np); np = 0; } - y++; - data += ww; - } - } - _swapBytes = swap; // Restore old value - inTransaction = lockTransaction; - end_tft_write(); -} - - /*************************************************************************************** ** Function name: setSwapBytes ** Description: Used by 16 bit pushImage() to swap byte order in colours @@ -2713,48 +2150,6 @@ void TFT_eSPI::drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t } -/*************************************************************************************** -** Function name: setCursor -** Description: Set the text cursor x,y position -***************************************************************************************/ -void TFT_eSPI::setCursor(int16_t x, int16_t y) -{ - cursor_x = x; - cursor_y = y; -} - - -/*************************************************************************************** -** Function name: setCursor -** Description: Set the text cursor x,y position and font -***************************************************************************************/ -void TFT_eSPI::setCursor(int16_t x, int16_t y, uint8_t font) -{ - textfont = font; - cursor_x = x; - cursor_y = y; -} - - -/*************************************************************************************** -** Function name: getCursorX -** Description: Get the text cursor x position -***************************************************************************************/ -int16_t TFT_eSPI::getCursorX(void) -{ - return cursor_x; -} - -/*************************************************************************************** -** Function name: getCursorY -** Description: Get the text cursor y position -***************************************************************************************/ -int16_t TFT_eSPI::getCursorY(void) -{ - return cursor_y; -} - - /*************************************************************************************** ** Function name: setTextSize ** Description: Set the text size multiplier @@ -2766,33 +2161,6 @@ void TFT_eSPI::setTextSize(uint8_t s) } -/*************************************************************************************** -** Function name: setTextColor -** Description: Set the font foreground colour (background is transparent) -***************************************************************************************/ -void TFT_eSPI::setTextColor(uint16_t c) -{ - // For 'transparent' background, we'll set the bg - // to the same as fg instead of using a flag - textcolor = textbgcolor = c; -} - - -/*************************************************************************************** -** Function name: setTextColor -** Description: Set the font foreground and background colour -***************************************************************************************/ -// Smooth fonts use the background colour for anti-aliasing and by default the -// background is not filled. If bgfill = true, then a smooth font background fill will -// be used. -void TFT_eSPI::setTextColor(uint16_t c, uint16_t b, bool bgfill) -{ - textcolor = c; - textbgcolor = b; - _fillbg = bgfill; -} - - /*************************************************************************************** ** Function name: setPivot ** Description: Set the pivot point on the TFT @@ -2824,18 +2192,6 @@ int16_t TFT_eSPI::getPivotY(void) } -/*************************************************************************************** -** Function name: setBitmapColor -** Description: Set the foreground foreground and background colour -***************************************************************************************/ -void TFT_eSPI::setBitmapColor(uint16_t c, uint16_t b) -{ - if (c == b) b = ~c; - bitmap_fg = c; - bitmap_bg = b; -} - - /*************************************************************************************** ** Function name: setTextWrap ** Description: Define if text should wrap at end of line @@ -2856,30 +2212,11 @@ void TFT_eSPI::setTextDatum(uint8_t d) textdatum = d; } - -/*************************************************************************************** -** Function name: setTextPadding -** Description: Define padding width (aids erasing old text and numbers) -***************************************************************************************/ -void TFT_eSPI::setTextPadding(uint16_t x_width) -{ - padX = x_width; -} - -/*************************************************************************************** -** Function name: setTextPadding -** Description: Define padding width (aids erasing old text and numbers) -***************************************************************************************/ -uint16_t TFT_eSPI::getTextPadding(void) -{ - return padX; -} - /*************************************************************************************** ** Function name: getRotation ** Description: Return the rotation value (as used by setRotation()) ***************************************************************************************/ -uint8_t TFT_eSPI::getRotation(void) +uint8_t TFT_eSPI::getRotation(void) const { return rotation; } @@ -2899,7 +2236,7 @@ uint8_t TFT_eSPI::getTextDatum(void) ** Description: Return the pixel width of display (per current rotation) ***************************************************************************************/ // Return the size of the display (per current rotation) -int16_t TFT_eSPI::width(void) +int16_t TFT_eSPI::width() const { if (_vpDatum) return _xWidth; return _width; @@ -2910,7 +2247,7 @@ int16_t TFT_eSPI::width(void) ** Function name: height ** Description: Return the pixel height of display (per current rotation) ***************************************************************************************/ -int16_t TFT_eSPI::height(void) +int16_t TFT_eSPI::height() const { if (_vpDatum) return _yHeight; return _height; @@ -2922,11 +2259,6 @@ int16_t TFT_eSPI::height(void) ** Description: Return the width in pixels of a string in a given font ***************************************************************************************/ -int16_t TFT_eSPI::textWidth(std::string_view string) -{ - return textWidth(string, textfont); -} - int16_t TFT_eSPI::textWidth(std::string_view string, uint8_t font) { int32_t str_width = 0; @@ -3022,7 +2354,11 @@ int16_t TFT_eSPI::fontHeight(int16_t font) { #ifdef CONFIG_TFT_IS_AUTOBAHN if (font == 4) + { + if (gfxFont != &din1451alt10pt8b) + setFreeFont(&din1451alt10pt8b); font = 1; + } #endif #ifdef SMOOTH_FONT @@ -3038,11 +2374,6 @@ int16_t TFT_eSPI::fontHeight(int16_t font) return pgm_read_byte( &fontdata[font].height ) * textsize; } -int16_t TFT_eSPI::fontHeight(void) -{ - return fontHeight(textfont); -} - /*************************************************************************************** ** Function name: drawChar ** Description: draw a single character in the GLCD or GFXFF font @@ -4460,168 +3791,25 @@ uint32_t TFT_eSPI::alphaBlend24(uint8_t alpha, uint32_t fgc, uint32_t bgc, uint8 return (r << 16) | (g << 8) | (b << 0); } -/*************************************************************************************** -** Function name: write -** Description: draw characters piped through serial stream -***************************************************************************************/ -/* // Not all processors support buffered write -#ifndef ESP8266 // Avoid ESP8266 board package bug -size_t TFT_eSPI::write(const uint8_t *buf, size_t len) -{ - inTransaction = true; - - uint8_t *lbuf = (uint8_t *)buf; - while(*lbuf !=0 && len--) write(*lbuf++); - - inTransaction = lockTransaction; - end_tft_write(); - return 1; -} -#endif -*/ -/*************************************************************************************** -** Function name: write -** Description: draw characters piped through serial stream -***************************************************************************************/ -size_t TFT_eSPI::write(uint8_t utf8) -{ - if (_vpOoB) return 1; - - uint16_t uniCode = decodeUTF8(utf8); - - if (!uniCode) return 1; - - if (utf8 == '\r') return 1; - -#ifdef SMOOTH_FONT - if(fontLoaded) { - if (uniCode < 32 && utf8 != '\n') return 1; - - drawGlyph(uniCode); - - return 1; - } -#endif - - if (uniCode == '\n') uniCode+=22; // Make it a valid space character to stop errors - else if (uniCode < 32) return 1; - - uint16_t cwidth = 0; - uint16_t cheight = 0; - -//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv DEBUG vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv - //Serial.print((uint8_t) uniCode); // Debug line sends all printed TFT text to serial port - //Serial.println(uniCode, HEX); // Debug line sends all printed TFT text to serial port - //delay(5); // Debug optional wait for serial port to flush through -//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DEBUG ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -#ifdef LOAD_GFXFF - if(!gfxFont) { -#endif -//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - -#ifdef LOAD_FONT2 - if (textfont == 2) { - if (uniCode > 127) return 1; - - cwidth = pgm_read_byte(widtbl_f16 + uniCode-32); - cheight = chr_hgt_f16; - // Font 2 is rendered in whole byte widths so we must allow for this - cwidth = (cwidth + 6) / 8; // Width in whole bytes for font 2, should be + 7 but must allow for font width change - cwidth = cwidth * 8; // Width converted back to pixels - } - #ifdef LOAD_RLE - else - #endif -#endif - -#ifdef LOAD_RLE - { - if ((textfont>2) && (textfont<9)) { - if (uniCode > 127) return 1; - // Uses the fontinfo struct array to avoid lots of 'if' or 'switch' statements - cwidth = pgm_read_byte( (uint8_t *)pgm_read_dword( &(fontdata[textfont].widthtbl ) ) + uniCode-32 ); - cheight= pgm_read_byte( &fontdata[textfont].height ); - } - } -#endif - -#ifdef LOAD_GLCD - if (textfont==1) { - cwidth = 6; - cheight = 8; - } -#else - if (textfont==1) return 1; -#endif - - cheight = cheight * textsize; - - if (utf8 == '\n') { - cursor_y += cheight; - cursor_x = 0; - } - else { - if (textwrapX && (cursor_x + cwidth * textsize > width())) { - cursor_y += cheight; - cursor_x = 0; - } - if (textwrapY && (cursor_y >= (int32_t) height())) cursor_y = 0; - cursor_x += drawChar(uniCode, cursor_x, cursor_y, textfont); - } - -//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -#ifdef LOAD_GFXFF - } // Custom GFX font - else { - if(utf8 == '\n') { - cursor_x = 0; - cursor_y += (int16_t)textsize * (uint8_t)pgm_read_byte(&gfxFont->yAdvance); - } else { - if (uniCode > pgm_read_word(&gfxFont->last )) return 1; - if (uniCode < pgm_read_word(&gfxFont->first)) return 1; - - uint16_t c2 = uniCode - pgm_read_word(&gfxFont->first); - GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c2]); - uint8_t w = pgm_read_byte(&glyph->width), - h = pgm_read_byte(&glyph->height); - if((w > 0) && (h > 0)) { // Is there an associated bitmap? - int16_t xo = (int8_t)pgm_read_byte(&glyph->xOffset); - if(textwrapX && ((cursor_x + textsize * (xo + w)) > width())) { - // Drawing character would go off right edge; wrap to new line - cursor_x = 0; - cursor_y += (int16_t)textsize * (uint8_t)pgm_read_byte(&gfxFont->yAdvance); - } - if (textwrapY && (cursor_y >= (int32_t) height())) cursor_y = 0; - drawChar(cursor_x, cursor_y, uniCode, textcolor, textbgcolor, textsize); - } - cursor_x += pgm_read_byte(&glyph->xAdvance) * (int16_t)textsize; - } - } -#endif // LOAD_GFXFF -//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - return 1; -} - - /*************************************************************************************** ** Function name: drawChar ** Description: draw a Unicode glyph onto the screen ***************************************************************************************/ - // TODO: Rationalise with TFT_eSprite - // Any UTF-8 decoding must be done before calling drawChar() -int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y) -{ - return drawChar(uniCode, x, y, textfont); -} // Any UTF-8 decoding must be done before calling drawChar() -int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) +int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font) { if (_vpOoB || !uniCode) return 0; +#ifdef CONFIG_TFT_IS_AUTOBAHN + if (font == 4) + { + if (gfxFont != &din1451alt10pt8b) + setFreeFont(&din1451alt10pt8b); + font = 1; + } +#endif + if (font==1) { #ifdef LOAD_GLCD #ifndef LOAD_GFXFF @@ -4635,7 +3823,7 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) #endif #ifdef LOAD_GFXFF - drawChar(x, y, uniCode, textcolor, textbgcolor, textsize); + drawChar(x, y, uniCode, color, bgcolor, textsize); if(!gfxFont) { // 'Classic' built-in font #ifdef LOAD_GLCD return 6 * textsize; @@ -4700,37 +3888,38 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) w = w + 6; // Should be + 7 but we need to compensate for width increment w = w / 8; - if (textcolor == textbgcolor || textsize != 1 || clip) { + if (color == bgcolor || textsize != 1 || clip) { //begin_tft_write(); // Sprite class can use this function, avoiding begin_tft_write() inTransaction = true; for (int32_t i = 0; i < height; i++) { - if (textcolor != textbgcolor) fillRect(x, pY, width * textsize, textsize, textbgcolor); + if (color != bgcolor) + fillRect(x, pY, width * textsize, textsize, bgcolor); for (int32_t k = 0; k < w; k++) { line = pgm_read_byte((uint8_t *)flash_address + w * i + k); if (line) { if (textsize == 1) { pX = x + k * 8; - if (line & 0x80) drawPixel(pX, pY, textcolor); - if (line & 0x40) drawPixel(pX + 1, pY, textcolor); - if (line & 0x20) drawPixel(pX + 2, pY, textcolor); - if (line & 0x10) drawPixel(pX + 3, pY, textcolor); - if (line & 0x08) drawPixel(pX + 4, pY, textcolor); - if (line & 0x04) drawPixel(pX + 5, pY, textcolor); - if (line & 0x02) drawPixel(pX + 6, pY, textcolor); - if (line & 0x01) drawPixel(pX + 7, pY, textcolor); + if (line & 0x80) drawPixel(pX, pY, color); + if (line & 0x40) drawPixel(pX + 1, pY, color); + if (line & 0x20) drawPixel(pX + 2, pY, color); + if (line & 0x10) drawPixel(pX + 3, pY, color); + if (line & 0x08) drawPixel(pX + 4, pY, color); + if (line & 0x04) drawPixel(pX + 5, pY, color); + if (line & 0x02) drawPixel(pX + 6, pY, color); + if (line & 0x01) drawPixel(pX + 7, pY, color); } else { pX = x + k * 8 * textsize; - if (line & 0x80) fillRect(pX, pY, textsize, textsize, textcolor); - if (line & 0x40) fillRect(pX + textsize, pY, textsize, textsize, textcolor); - if (line & 0x20) fillRect(pX + 2 * textsize, pY, textsize, textsize, textcolor); - if (line & 0x10) fillRect(pX + 3 * textsize, pY, textsize, textsize, textcolor); - if (line & 0x08) fillRect(pX + 4 * textsize, pY, textsize, textsize, textcolor); - if (line & 0x04) fillRect(pX + 5 * textsize, pY, textsize, textsize, textcolor); - if (line & 0x02) fillRect(pX + 6 * textsize, pY, textsize, textsize, textcolor); - if (line & 0x01) fillRect(pX + 7 * textsize, pY, textsize, textsize, textcolor); + if (line & 0x80) fillRect(pX, pY, textsize, textsize, color); + if (line & 0x40) fillRect(pX + textsize, pY, textsize, textsize, color); + if (line & 0x20) fillRect(pX + 2 * textsize, pY, textsize, textsize, color); + if (line & 0x10) fillRect(pX + 3 * textsize, pY, textsize, textsize, color); + if (line & 0x08) fillRect(pX + 4 * textsize, pY, textsize, textsize, color); + if (line & 0x04) fillRect(pX + 5 * textsize, pY, textsize, textsize, color); + if (line & 0x02) fillRect(pX + 6 * textsize, pY, textsize, textsize, color); + if (line & 0x01) fillRect(pX + 7 * textsize, pY, textsize, textsize, color); } } } @@ -4753,13 +3942,13 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) line = pgm_read_byte((uint8_t *) (flash_address + w * i + k) ); mask = 0x80; while (mask && pX) { - if (line & mask) {tft_Write_16(textcolor);} - else {tft_Write_16(textbgcolor);} + if (line & mask) {tft_Write_16(color);} + else {tft_Write_16(bgcolor);} pX--; mask = mask >> 1; } } - if (pX) {tft_Write_16(textbgcolor);} + if (pX) {tft_Write_16(bgcolor);} } end_tft_write(); @@ -4778,7 +3967,7 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) inTransaction = true; w *= height; // Now w is total number of pixels in the character - if (textcolor == textbgcolor && !clip) { + if (color == bgcolor && !clip) { int32_t px = 0, py = pY; // To hold character block start and end column and row values int32_t pc = 0; // Pixel count @@ -4808,9 +3997,9 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) if (ts) { tnp = np; - while (tnp--) {tft_Write_16(textcolor);} + while (tnp--) {tft_Write_16(color);} } - else {tft_Write_16(textcolor);} + else {tft_Write_16(color);} px += textsize; if (px >= (xd + width * textsize)) { @@ -4828,7 +4017,7 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) else { // Text colour != background and textsize = 1 and character is within viewport area // so use faster drawing of characters and background using block write - if (textcolor != textbgcolor && textsize == 1 && !clip) + if (color != bgcolor && textsize == 1 && !clip) { setWindow(xd, yd, xd + width - 1, yd + height - 1); @@ -4838,11 +4027,11 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) if (line & 0x80) { line &= 0x7F; line++; w -= line; - pushBlock(textcolor,line); + pushBlock(color,line); } else { line++; w -= line; - pushBlock(textbgcolor,line); + pushBlock(bgcolor,line); } } } @@ -4857,8 +4046,8 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) while (pc < w) { line = pgm_read_byte((uint8_t *)flash_address); flash_address++; - if (line & 0x80) { pcol = textcolor; line &= 0x7F; pf = true;} - else { pcol = textbgcolor; if (textcolor == textbgcolor) pf = false;} + if (line & 0x80) { pcol = color; line &= 0x7F; pf = true;} + else { pcol = bgcolor; if (color == bgcolor) pf = false;} line++; px = pc % width; tx = x + textsize * px; @@ -4906,19 +4095,19 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) ** Function name: drawString (with or without user defined font) ** Description : draw string with padding if it is defined ***************************************************************************************/ -// Without font number, uses font set by setTextFont() -int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY) -{ - return drawString(string, poX, poY, textfont); -} // With font number. Note: font number is over-ridden if a smooth font is loaded -int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY, uint8_t font) +int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font) { #ifdef CONFIG_TFT_IS_AUTOBAHN if (font == 4) + { + if (gfxFont != &din1451alt10pt8b) + setFreeFont(&din1451alt10pt8b); font = 1; + } #endif + int16_t sumX = 0; uint8_t padding = 1, baseline = 0; uint16_t cwidth = textWidth(string, font); // Find the pixel width of the string in the font @@ -4958,7 +4147,7 @@ int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY, cheight = fontHeight(font); } - if (textdatum || padX) { + if (textdatum) { switch(textdatum) { case TC_DATUM: @@ -5017,7 +4206,7 @@ int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY, int8_t xo = 0; #ifdef LOAD_GFXFF - if (freeFont && (textcolor!=textbgcolor)) { + if (freeFont && (color!=bgcolor)) { cheight = (glyph_ab + glyph_bb) * textsize; // Get the offset for the first character only to allow for negative offsets uint16_t c2 = 0; @@ -5036,7 +4225,7 @@ int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY, // Add 1 pixel of padding all round //cheight +=2; //fillRect(poX+xo-1, poY - 1 - glyph_ab * textsize, cwidth+2, cheight, textbgcolor); - fillRect(poX+xo, poY - glyph_ab * textsize, cwidth, cheight, textbgcolor); + fillRect(poX+xo, poY - glyph_ab * textsize, cwidth, cheight, bgcolor); } padding -=100; } @@ -5066,10 +4255,12 @@ int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY, { while (n < len) { uint16_t uniCode = decodeUTF8((const uint8_t*)std::begin(string), &n, len - n); - sumX += drawChar(uniCode, poX+sumX, poY, font); + sumX += drawChar(uniCode, poX+sumX, poY, color, bgcolor, font); } } + auto padX = 0; + //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv DEBUG vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv // Switch on debugging for the padding areas //#define PADDING_DEBUG @@ -5077,7 +4268,7 @@ int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY, #ifndef PADDING_DEBUG //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DEBUG ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - if((padX>cwidth) && (textcolor!=textbgcolor)) { + if((0>cwidth) && (color!=bgcolor)) { int16_t padXc = poX+cwidth+xo; #ifdef LOAD_GFXFF if (freeFont) { @@ -5088,16 +4279,16 @@ int16_t TFT_eSPI::drawString(std::string_view string, int32_t poX, int32_t poY, #endif switch(padding) { case 1: - fillRect(padXc,poY,padX-cwidth,cheight, textbgcolor); + fillRect(padXc,poY,padX-cwidth,cheight, bgcolor); break; case 2: - fillRect(padXc,poY,(padX-cwidth)>>1,cheight, textbgcolor); + fillRect(padXc,poY,(padX-cwidth)>>1,cheight, bgcolor); padXc = poX - ((padX-cwidth)>>1); - fillRect(padXc,poY,(padX-cwidth)>>1,cheight, textbgcolor); + fillRect(padXc,poY,(padX-cwidth)>>1,cheight, bgcolor); break; case 3: if (padXc>padX) padXc = padX; - fillRect(poX + cwidth - padXc,poY,padXc-cwidth,cheight, textbgcolor); + fillRect(poX + cwidth - padXc,poY,padXc-cwidth,cheight, bgcolor); break; } } @@ -5141,12 +4332,12 @@ return sumX; ** Function name: drawCentreString (deprecated, use setTextDatum()) ** Descriptions: draw string centred on dX ***************************************************************************************/ -int16_t TFT_eSPI::drawCentreString(std::string_view string, int32_t dX, int32_t poY, uint8_t font) +int16_t TFT_eSPI::drawCentreString(std::string_view string, int32_t dX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font) { uint8_t tempdatum = textdatum; int32_t sumX = 0; textdatum = TC_DATUM; - sumX = drawString(string, dX, poY, font); + sumX = drawString(string, dX, poY, color, bgcolor, font); textdatum = tempdatum; return sumX; } @@ -5156,12 +4347,12 @@ int16_t TFT_eSPI::drawCentreString(std::string_view string, int32_t dX, int32_t ** Function name: drawRightString (deprecated, use setTextDatum()) ** Descriptions: draw string right justified to dX ***************************************************************************************/ -int16_t TFT_eSPI::drawRightString(std::string_view string, int32_t dX, int32_t poY, uint8_t font) +int16_t TFT_eSPI::drawRightString(std::string_view string, int32_t dX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font) { uint8_t tempdatum = textdatum; int16_t sumX = 0; textdatum = TR_DATUM; - sumX = drawString(string, dX, poY, font); + sumX = drawString(string, dX, poY, color, bgcolor, font); textdatum = tempdatum; return sumX; } @@ -5177,11 +4368,12 @@ int16_t TFT_eSPI::drawRightString(std::string_view string, int32_t dX, int32_t p void TFT_eSPI::setFreeFont(const GFXfont *f) { if (f == nullptr) { // Fix issue #400 (ESP32 crash) - setTextFont(1); // Use GLCD font + // TODO FIX THIS AGAIN + //setTextFont(1); // Use GLCD font return; } - textfont = 1; +// textfont = 1; gfxFont = (GFXfont *)f; glyph_ab = 0; @@ -5198,22 +4390,6 @@ void TFT_eSPI::setFreeFont(const GFXfont *f) } } -/*************************************************************************************** -** Function name: setTextFont -** Description: Set the font for the print stream -***************************************************************************************/ -void TFT_eSPI::setTextFont(uint8_t f) -{ -#ifdef CONFIG_TFT_IS_AUTOBAHN - if (f == 4) { - setFreeFont(&din1451alt10pt8b); - return; - } -#endif - textfont = (f > 0) ? f : 1; // Don't allow font 0 - gfxFont = NULL; -} - #else @@ -5440,9 +4616,9 @@ void TFT_eSPI::getSetup(setup_t &tft_settings) #include "Extensions/Touch.cpp" #endif -#include "Extensions/Button.cpp" +//#include "Extensions/Button.cpp" -#include "Extensions/Sprite.cpp" +//#include "Extensions/Sprite.cpp" #ifdef SMOOTH_FONT #include "Extensions/Smooth_font.cpp" diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 98f9ace..b55e912 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -269,31 +269,31 @@ constexpr uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) noexcept ** Section 6: Colour enumeration ***************************************************************************************/ // Default color definitions -constexpr uint16_t TFT_BLACK = 0x0000; /* 0, 0, 0 */ -constexpr uint16_t TFT_NAVY = 0x000F; /* 0, 0, 128 */ -constexpr uint16_t TFT_DARKGREEN = 0x03E0; /* 0, 128, 0 */ -constexpr uint16_t TFT_DARKCYAN = 0x03EF; /* 0, 128, 128 */ -constexpr uint16_t TFT_MAROON = 0x7800; /* 128, 0, 0 */ -constexpr uint16_t TFT_PURPLE = 0x780F; /* 128, 0, 128 */ -constexpr uint16_t TFT_OLIVE = 0x7BE0; /* 128, 128, 0 */ -constexpr uint16_t TFT_LIGHTGREY = 0xD69A; /* 211, 211, 211 */ -constexpr uint16_t TFT_DARKGREY = 0x7BEF; /* 128, 128, 128 */ -constexpr uint16_t TFT_BLUE = 0x001F; /* 0, 0, 255 */ -constexpr uint16_t TFT_GREEN = 0x07E0; /* 0, 255, 0 */ -constexpr uint16_t TFT_CYAN = 0x07FF; /* 0, 255, 255 */ -constexpr uint16_t TFT_RED = 0xF800; /* 255, 0, 0 */ -constexpr uint16_t TFT_MAGENTA = 0xF81F; /* 255, 0, 255 */ -constexpr uint16_t TFT_YELLOW = 0xFFE0; /* 255, 255, 0 */ -constexpr uint16_t TFT_WHITE = 0xFFFF; /* 255, 255, 255 */ +constexpr uint16_t TFT_BLACK = color565( 0, 0, 0); +constexpr uint16_t TFT_NAVY = color565( 0, 0, 128); +constexpr uint16_t TFT_DARKGREEN = color565( 0, 128, 0); +constexpr uint16_t TFT_DARKCYAN = color565( 0, 128, 128); +constexpr uint16_t TFT_MAROON = color565(128, 0, 0); +constexpr uint16_t TFT_PURPLE = color565(128, 0, 128); +constexpr uint16_t TFT_OLIVE = color565(128, 128, 0); +constexpr uint16_t TFT_LIGHTGREY = color565(211, 211, 211); +constexpr uint16_t TFT_DARKGREY = color565(128, 128, 128); +constexpr uint16_t TFT_BLUE = color565( 0, 0, 255); +constexpr uint16_t TFT_GREEN = color565( 0, 255, 0); +constexpr uint16_t TFT_CYAN = color565( 0, 255, 255); +constexpr uint16_t TFT_RED = color565(255, 0, 0); +constexpr uint16_t TFT_MAGENTA = color565(255, 0, 255); +constexpr uint16_t TFT_YELLOW = color565(255, 255, 0); +constexpr uint16_t TFT_WHITE = color565(255, 255, 255); constexpr uint16_t TFT_GREY = 0x5AEB; -constexpr uint16_t TFT_ORANGE = 0xFDA0; /* 255, 180, 0 */ -constexpr uint16_t TFT_GREENYELLOW = 0xB7E0; /* 180, 255, 0 */ -constexpr uint16_t TFT_PINK = 0xFE19; /* 255, 192, 203 */ //Lighter pink, was 0xFC9F -constexpr uint16_t TFT_BROWN = 0x9A60; /* 150, 75, 0 */ -constexpr uint16_t TFT_GOLD = 0xFEA0; /* 255, 215, 0 */ -constexpr uint16_t TFT_SILVER = 0xC618; /* 192, 192, 192 */ -constexpr uint16_t TFT_SKYBLUE = 0x867D; /* 135, 206, 235 */ -constexpr uint16_t TFT_VIOLET = 0x915C; /* 180, 46, 226 */ +constexpr uint16_t TFT_ORANGE = color565(255, 180, 0); +constexpr uint16_t TFT_GREENYELLOW = color565(180, 255, 0); +constexpr uint16_t TFT_PINK = color565(255, 192, 203); //Lighter pink, was 0xFC9F +constexpr uint16_t TFT_BROWN = color565(150, 75, 0); +constexpr uint16_t TFT_GOLD = color565(255, 215, 0); +constexpr uint16_t TFT_SILVER = color565(192, 192, 192); +constexpr uint16_t TFT_SKYBLUE = color565(135, 206, 235); +constexpr uint16_t TFT_VIOLET = color565(180, 46, 226); constexpr uint16_t TFT_NICEBLUE = color565(59, 163, 255); // Next is a special 16 bit colour value that encodes to 8 bits @@ -394,7 +394,7 @@ swap_coord(T& a, T& b) { T t = a; a = b; b = t; } typedef uint16_t (*getColorCallback)(uint16_t x, uint16_t y); // Class functions and variables -class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protected members +class TFT_eSPI { //--------------------------------------- public ------------------------------------// public: @@ -405,18 +405,16 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect // Sketch defined tab colour option is for ST7735 displays only void init(uint8_t tc = TAB_COLOUR), begin(uint8_t tc = TAB_COLOUR); - // These are virtual so the TFT_eSprite class can override them with sprite specific functions - virtual void drawPixel(int32_t x, int32_t y, uint16_t color), - drawChar(int32_t x, int32_t y, uint16_t c, uint16_t color, uint16_t bg, uint8_t size), - drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint16_t color), - drawFastVLine(int32_t x, int32_t y, int32_t h, uint16_t color), - drawFastHLine(int32_t x, int32_t y, int32_t w, uint16_t color), - fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color); + void drawPixel(int32_t x, int32_t y, uint16_t color); + void drawChar(int32_t x, int32_t y, uint16_t c, uint16_t color, uint16_t bg, uint8_t size); + void drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint16_t color); + void drawFastVLine(int32_t x, int32_t y, int32_t h, uint16_t color); + void drawFastHLine(int32_t x, int32_t y, int32_t w, uint16_t color); + void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color); - virtual int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font), - drawChar(uint16_t uniCode, int32_t x, int32_t y), - height(void), - width(void); + int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font); + int16_t height() const; + int16_t width() const; // Read the colour of a pixel at x,y and return value in 565 format virtual uint16_t readPixel(int32_t x, int32_t y); @@ -431,7 +429,7 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect virtual void end_nin_write(); void setRotation(uint8_t r); // Set the display image orientation to 0, 1, 2 or 3 - uint8_t getRotation(void); // Read the current rotation + uint8_t getRotation(void) const; // Read the current rotation void invertDisplay(bool i); // Tell TFT to invert all displayed colours @@ -476,10 +474,10 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect #endif // Graphics drawing - void fillScreen(uint32_t color), - drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color), - drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color), - fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color); + void fillScreen(uint32_t color); + void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color); + void drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color); + void fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color); void fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2); void fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2); @@ -509,17 +507,17 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect void drawSunkenRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color0, uint32_t color1, uint32_t color2); - void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color), - drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color), - fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color), - fillCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, int32_t delta, uint32_t color), + void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color); + void drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color); + void fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color); + void fillCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, int32_t delta, uint32_t color); - drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color), - fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color), + void drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color); + void fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color); // Corner 1 Corner 2 Corner 3 - drawTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color), - fillTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color); + void drawTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color); + void fillTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color); // Image rendering // Swap the byte order for pushImage() and pushPixels() - corrects endianness @@ -530,8 +528,7 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect void drawBitmap( int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor), drawBitmap( int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor), drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor), - drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor), - setBitmapColor(uint16_t fgcolor, uint16_t bgcolor); // Define the 2 colours for 1bpp sprites + drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t fgcolor, uint16_t bgcolor); // Set TFT pivot point (use when rendering rotated sprites) void setPivot(int16_t x, int16_t y); @@ -545,20 +542,9 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect void pushRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data); // These are used to render images or sprites stored in RAM arrays (used by Sprite class for 16bpp Sprites) - void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data); - void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transparent); - - // These are used to render images stored in FLASH (PROGMEM) - void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent); void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data); + void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent); - // These are used by Sprite class pushSprite() member function for 1, 4 and 8 bits per pixel (bpp) colours - // They are not intended to be used with user sketches (but could be) - // Set bpp8 true for 8bpp sprites, false otherwise. The cmap pointer must be specified for 4bpp - void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, bool bpp8 = true, uint16_t *cmap = nullptr); - void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, uint8_t transparent, bool bpp8 = true, uint16_t *cmap = nullptr); - // FLASH version - void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data, bool bpp8, uint16_t *cmap = nullptr); // This next function has been used successfully to dump the TFT screen to a PC for documentation purposes // It reads a screen area and returns the 3 RGB 8 bit colour values of each pixel in the buffer // Set w and h to 1 to read 1 pixel's colour. The data buffer must be at least w * h * 3 bytes @@ -566,52 +552,32 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect // Handle char arrays // Use with setTextDatum() to position string on TFT, and setTextPadding() to blank old displayed strings - int16_t drawString(std::string_view string, int32_t x, int32_t y, uint8_t font), // Draw string using specifed font number - drawString(std::string_view string, int32_t x, int32_t y), // Draw string using current font - - drawCentreString(std::string_view string, int32_t x, int32_t y, uint8_t font), // Deprecated, use setTextDatum() and drawString() - drawRightString(std::string_view string, int32_t x, int32_t y, uint8_t font); // Deprecated, use setTextDatum() and drawString() + int16_t drawString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font); // Draw string using specifed font number + int16_t drawCentreString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font); // Deprecated, use setTextDatum() and drawString() + int16_t drawRightString(std::string_view string, int32_t x, int32_t y, uint16_t color, uint16_t bgcolor, uint8_t font); // Deprecated, use setTextDatum() and drawString() // Text rendering and font handling support funtions - void setCursor(int16_t x, int16_t y), // Set cursor for tft.print() - setCursor(int16_t x, int16_t y, uint8_t font); // Set cursor and font number for tft.print() - - int16_t getCursorX(void), // Read current cursor x position (moves with tft.print()) - getCursorY(void); // Read current cursor y position - - void setTextColor(uint16_t color), // Set character (glyph) color only (background not over-written) - setTextColor(uint16_t fgcolor, uint16_t bgcolor, bool bgfill = false), // Set character (glyph) foreground and background colour, optional background fill for smooth fonts - setTextSize(uint8_t size); // Set character size multiplier (this increases pixel size) + void setTextSize(uint8_t size); // Set character size multiplier (this increases pixel size) void setTextWrap(bool wrapX, bool wrapY = false); // Turn on/off wrapping of text in TFT width and/or height void setTextDatum(uint8_t datum); // Set text datum position (default is top left), see Section 6 above uint8_t getTextDatum(void); - void setTextPadding(uint16_t x_width); // Set text padding (background blanking/over-write) width in pixels - uint16_t getTextPadding(void); // Get text padding - #ifdef LOAD_GFXFF - void setFreeFont(const GFXfont *f = NULL), // Select the GFX Free Font - setTextFont(uint8_t font); // Set the font number to use in future + void setFreeFont(const GFXfont *f = NULL); // Select the GFX Free Font #else void setFreeFont(uint8_t font), // Not used, historical fix to prevent an error setTextFont(uint8_t font); // Set the font number to use in future #endif - int16_t textWidth(std::string_view string, uint8_t font), // Returns pixel width of string in specified font - textWidth(std::string_view string), // Returns pixel width of string in current font - fontHeight(int16_t font), // Returns pixel height of string in specified font - fontHeight(void); // Returns pixel width of string in current font + int16_t textWidth(std::string_view string, uint8_t font); // Returns pixel width of string in specified font + int16_t fontHeight(int16_t font); // Returns pixel height of string in specified font // Used by library and Smooth font class to extract Unicode point codes from a UTF8 encoded string uint16_t decodeUTF8(const uint8_t *buf, uint16_t *index, uint16_t remaining), decodeUTF8(uint8_t c); - // Support function to UTF8 decode and draw characters piped through print stream - size_t write(uint8_t); - // size_t write(const uint8_t *buf, size_t len); - // Used by Smooth font class to fetch a pixel colour for the anti-aliasing void setCallback(getColorCallback getCol); @@ -728,12 +694,7 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect // Global variables static SPIClass& getSPIinstance(void); // Get SPI class handle - uint16_t textcolor, textbgcolor; // Text foreground and background colours - - uint32_t bitmap_fg, bitmap_bg; // Bitmap foreground (bit=1) and background (bit=0) colours - - uint8_t textfont, // Current selected font number - textsize, // Current font size multiplier + uint8_t textsize, // Current font size multiplier textdatum, // Text reference datum rotation; // Display rotation (0-3) @@ -825,10 +786,6 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect bool _vpDatum; bool _vpOoB; - int32_t cursor_x, cursor_y, padX; // Text cursor x,y and padding setting - int32_t bg_cursor_x; // Background fill cursor - int32_t last_cursor_x; // Previous text cursor position when fill used - uint32_t fontsloaded; // Bit field of fonts loaded uint8_t glyph_ab, // Smooth font glyph delta Y (height) above baseline