From 0362fd38b0689c7eaf6effaa033a8f7f4934b97a Mon Sep 17 00:00:00 2001 From: Sjef Verhoeven PE5PVB Date: Fri, 4 Aug 2023 14:18:14 +0200 Subject: [PATCH] Mods on Chinese display with external .cpp --- TEF6686_ESP32.ino | 15 +++++---------- src/gui.cpp | 24 ++++++++++++++++++++++++ src/gui.h | 4 +++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/TEF6686_ESP32.ino b/TEF6686_ESP32.ino index fff0987..48706d8 100644 --- a/TEF6686_ESP32.ino +++ b/TEF6686_ESP32.ino @@ -4768,11 +4768,8 @@ void DefaultSettings(byte userhardwaremodel) { void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, const uint8_t* font) { if (language == LANGUAGE_CHS) { - if (memcmp(font, FONT16, sizeof(FONT16)) == 0) { - font = FONT16_CHS; - } else if (memcmp(font, FONT28, sizeof(FONT28)) == 0) { - font = FONT28_CHS; - } + if (font == FONT16) font = FONT16_CHS; + else if (font == FONT28) font = FONT28_CHS; } if (currentFont != font || resetFontOnNextCall) { @@ -4795,15 +4792,13 @@ void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int colo void tftReplace(int8_t offset, const String & textold, const String & text, int16_t x, int16_t y, int color, int smoothcolor, const uint8_t* font) { if (language == LANGUAGE_CHS) { - if (memcmp(font, FONT16, sizeof(FONT16)) == 0) { - font = FONT16_CHS; - } else if (memcmp(font, FONT28, sizeof(FONT28)) == 0) { - font = FONT28_CHS; - } + if (font == FONT16) font = FONT16_CHS; + if (font == FONT28) font = FONT28_CHS; } if (currentFont != font || resetFontOnNextCall) { if (currentFont != nullptr) tft.unloadFont(); + tft.loadFont(font); currentFont = font; resetFontOnNextCall = false; diff --git a/src/gui.cpp b/src/gui.cpp index 9b67825..bdbc4e7 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -9,6 +9,30 @@ #include #include +static void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, const uint8_t* font) { + if (language == LANGUAGE_CHS) { + if (font == FONT16) font = FONT16_CHS; + else if (font == FONT28) font = FONT28_CHS; + } + + if (currentFont != font || resetFontOnNextCall) { + if (currentFont != nullptr) tft.unloadFont(); + tft.loadFont(font); + currentFont = font; + resetFontOnNextCall = false; + } + + tft.setTextColor(color, smoothcolor, false); + + switch (offset) { + case -1: tft.setTextDatum(TL_DATUM); break; + case 0: tft.setTextDatum(TC_DATUM); break; + case 1: tft.setTextDatum(TR_DATUM); break; + } + + tft.drawString(text, x, y, 1); +} + void BuildAFScreen() { if (!afscreen && RDSstatus) { tft.drawRoundRect(20, 30, 274, 170, 5, ActiveColor); diff --git a/src/gui.h b/src/gui.h index 29816c1..ea336b8 100644 --- a/src/gui.h +++ b/src/gui.h @@ -120,6 +120,8 @@ extern unsigned int ConverterSet; extern unsigned int HighEdgeSet; extern unsigned int LowEdgeSet; extern unsigned int mappedfreqold[20]; +extern bool resetFontOnNextCall; +extern const uint8_t* currentFont; extern TFT_eSPI tft; extern TEF6686 radio; @@ -134,7 +136,7 @@ void MenuDown(); void DoMenu(); // Extern: -void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, const uint8_t* font); +//void tftPrint(int8_t offset, const String & text, int16_t x, int16_t y, int color, int smoothcolor, const uint8_t* font); void ShowFreq(int mode); void ShowBandSelectionFM(bool notglanceview, bool normaldisplay); void ShowBandSelectionAM(bool notglanceview, bool normaldisplay);