From 60c16598754b8679585b25e15b5635e07885b84d Mon Sep 17 00:00:00 2001 From: Nacho Date: Thu, 28 May 2026 21:33:56 +0200 Subject: [PATCH] Enhance tft_drawText function to support background color --- src/display/display.cpp | 12 ++++++++++-- src/display/display.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/display/display.cpp b/src/display/display.cpp index 25d35a4..1f5439c 100644 --- a/src/display/display.cpp +++ b/src/display/display.cpp @@ -2,6 +2,8 @@ #include "defs/screen_defs.h" #include "defs/defs.h" +#include + int xPos = 0; int yPos = 0; @@ -59,9 +61,15 @@ void tft_drawCenteredText(const char* text, int size, int yGlobal) { composite.drawString(text, x, yGlobal); } -void tft_drawText(const char* text, int size, int x, int y, uint16_t color) { +void tft_drawText(const char* text, int size, int x, int y, uint16_t color, uint16_t bgColor = TFT_TRANSPARENT) { composite.setTextSize(size); - composite.setTextColor(color); + + if (bgColor != TFT_TRANSPARENT) { + composite.setTextColor(color, bgColor); + } else { + composite.setTextColor(color); + } + composite.drawString(text, x, y); } diff --git a/src/display/display.h b/src/display/display.h index b2b4723..28151cf 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -12,7 +12,7 @@ void tft_drawBuffer(); void tft_clearBuffer(TFT_eSprite &buffer, uint16_t color = TFT_WHITE); void tft_clearBuffer(uint16_t color = TFT_WHITE); void tft_drawCenteredText(const char* text, int factor, int y); -void tft_drawText(const char* text, int size, int x, int y, uint16_t color = TFT_BLACK); +void tft_drawText(const char* text, int size, int x, int y, uint16_t color = TFT_BLACK, uint16_t bgColor = TFT_TRANSPARENT); void tft_drawRectangle(int x, int y, int w, int h, uint16_t color = TFT_BLACK); #endif \ No newline at end of file