Skip to content

Commit 427228a

Browse files
author
dave
committed
Prepare for 3.0 docs and small fix
1 parent 5e19bd1 commit 427228a

File tree

6 files changed

+48
-11
lines changed

6 files changed

+48
-11
lines changed

examples/esp/esp32Amplifier/esp32Amplifier.emf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@
540540
"latestValue": "TITLE_ALWAYS",
541541
"subsystem": "THEME"
542542
},
543+
{
544+
"name": "USE_TC_UNICODE",
545+
"latestValue": "false",
546+
"subsystem": "THEME"
547+
},
543548
{
544549
"name": "USE_SLIDER_ANALOG",
545550
"latestValue": "true",

examples/esp/esp32Amplifier/tcMenuTfteSpi.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* This library requires the AdaGfx library along with a suitable driver.
1313
*/
1414

15-
1615
#include "tcMenuTfteSpi.h"
16+
#include "tcUnicodeHelper.h"
1717
#include <TFT_eSPI.h>
1818

1919
TfteSpiDrawable::TfteSpiDrawable(TFT_eSPI *tft, int spriteHeight) : tft(tft), spriteWithConfig(nullptr), spriteHeight(spriteHeight) {}
@@ -30,7 +30,7 @@ DeviceDrawable *TfteSpiDrawable::getSubDeviceFor(const Coord &where, const Coord
3030
else return nullptr;
3131
}
3232

33-
void TfteSpiDrawable::drawText(const Coord &where, const void *font, int mag, const char *text) {
33+
void TfteSpiDrawable::internalDrawText(const Coord &where, const void *font, int mag, const char *text) {
3434
fontPtrToNum(font, mag);
3535
tft->setTextColor(drawColor, drawColor); // transparent background
3636
tft->drawString(text, where.x, where.y);
@@ -88,12 +88,16 @@ void TfteSpiDrawable::transaction(bool isStarting, bool redrawNeeded) {
8888
if(isStarting) tft->setTextDatum(TL_DATUM);
8989
}
9090

91-
Coord TfteSpiDrawable::textExtents(const void *font, int mag, const char *text, int *baseline) {
91+
Coord TfteSpiDrawable::internalTextExtents(const void *font, int mag, const char *text, int *baseline) {
9292
if(baseline) *baseline = 0;
9393
fontPtrToNum(font, mag);
9494
return Coord(tft->textWidth(text), tft->fontHeight());
9595
}
9696

97+
void TfteSpiDrawable::drawPixel(uint16_t x, uint16_t y) {
98+
tft->drawPixel(x, y, drawColor);
99+
}
100+
97101
void TfteSpiDrawable::fontPtrToNum(const void* font, int mag) {
98102
if(font == nullptr) {
99103
tft->setTextFont((uint8_t) mag);
@@ -103,6 +107,10 @@ void TfteSpiDrawable::fontPtrToNum(const void* font, int mag) {
103107
}
104108
}
105109

110+
UnicodeFontHandler *TfteSpiDrawable::createFontHandler() {
111+
return fontHandler = new UnicodeFontHandler(tft, tccore::ENCMODE_UTF8);
112+
}
113+
106114
//
107115
// Sprite object
108116
//
@@ -115,6 +123,10 @@ bool TftSpriteAndConfig::initSprite(const Coord &spriteWhere, const Coord &sprit
115123
// if the area is too big, or the sprite is in use, don't proceed.
116124
if(spriteSize.x > size.x || spriteSize.y > size.y) return false;
117125

126+
if(root->isTcUnicodeEnabled() && fontHandler == nullptr) {
127+
fontHandler = new UnicodeFontHandler(&sprite, tccore::ENCMODE_UTF8);
128+
}
129+
118130
// create the sprite if needed
119131
if(!sprite.created()) {
120132
sprite.createSprite(size.x, size.y);

examples/esp/esp32Amplifier/tcMenuTfteSpi.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TfteSpiDrawable : public DeviceDrawable {
3434

3535
DeviceDrawable *getSubDeviceFor(const Coord &where, const Coord& size, const color_t *palette, int paletteSize) override;
3636

37-
void drawText(const Coord &where, const void *font, int mag, const char *text) override;
37+
void internalDrawText(const Coord &where, const void *font, int mag, const char *text) override;
3838

3939
void drawBitmap(const Coord &where, const DrawableIcon *icon, bool selected) override;
4040

@@ -46,11 +46,15 @@ class TfteSpiDrawable : public DeviceDrawable {
4646

4747
void drawPolygon(const Coord *points, int numPoints, bool filled) override;
4848

49+
void drawPixel(uint16_t x, uint16_t y) override;
50+
4951
void transaction(bool isStarting, bool redrawNeeded) override;
5052

51-
Coord textExtents(const void *font, int mag, const char *text, int *baseline) override;
53+
Coord internalTextExtents(const void *font, int mag, const char *text, int *baseline) override;
5254
Coord getDisplayDimensions() override { return Coord(tft->width(), tft->height());}
5355
TFT_eSPI* getTFT() { return tft; }
56+
protected:
57+
UnicodeFontHandler* createFontHandler() override;
5458
private:
5559
void fontPtrToNum(const void* font, int mag);
5660
};

examples/esp/esp32s2Saola/esp32s2Saola.emf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@
483483
"name": "TITLE_SHOW_MODE",
484484
"latestValue": "TITLE_ALWAYS",
485485
"subsystem": "THEME"
486+
},
487+
{
488+
"name": "USE_TC_UNICODE",
489+
"latestValue": "false",
490+
"subsystem": "THEME"
486491
}
487492
],
488493
"namingRecursive": true,

examples/esp/esp32s2Saola/tcMenuU8g2.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <U8g2lib.h>
1818
#include <Wire.h>
1919
#include "tcMenuU8g2.h"
20+
#include <tcUnicodeHelper.h>
2021

2122
const uint8_t* safeGetFont(const void* fnt) {
2223
if(fnt) return static_cast<const uint8_t *>(fnt);
@@ -65,7 +66,7 @@ U8g2Drawable::U8g2Drawable(U8G2 *u8g2, TwoWire* wireImpl) : u8g2(u8g2) {
6566
#endif
6667
}
6768

68-
void U8g2Drawable::drawText(const Coord &where, const void *font, int mag, const char *text) {
69+
void U8g2Drawable::internalDrawText(const Coord &where, const void *font, int mag, const char *text) {
6970
u8g2->setFont(safeGetFont(font));
7071
u8g2->setFontMode(drawColor == 2);
7172
auto extraHeight = u8g2->getMaxCharHeight();
@@ -137,7 +138,7 @@ void U8g2Drawable::transaction(bool isStarting, bool redrawNeeded) {
137138
}
138139
}
139140

140-
Coord U8g2Drawable::textExtents(const void *font, int mag, const char *text, int *baseline) {
141+
Coord U8g2Drawable::internalTextExtents(const void *font, int mag, const char *text, int *baseline) {
141142
u8g2->setFont(safeGetFont(font));
142143
if(baseline) *baseline = (int)u8g2->getFontDescent();
143144
#ifdef TC_USE_UTF_8_ENCODING
@@ -146,3 +147,11 @@ Coord U8g2Drawable::textExtents(const void *font, int mag, const char *text, int
146147
return Coord(u8g2->getStrWidth(text), u8g2->getMaxCharHeight());
147148
#endif
148149
}
150+
151+
void U8g2Drawable::drawPixel(uint16_t x, uint16_t y) {
152+
u8g2->drawPixel(x, y);
153+
}
154+
155+
UnicodeFontHandler* U8g2Drawable::createFontHandler() {
156+
return new UnicodeFontHandler(u8g2, ENCMODE_UTF8);
157+
}

examples/esp/esp32s2Saola/tcMenuU8g2.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class U8g2Drawable : public DeviceDrawable {
8080

8181
DeviceDrawable* getSubDeviceFor(const Coord &where, const Coord &size, const color_t *palette, int paletteSize) override {return nullptr; }
8282

83-
void drawText(const Coord &where, const void *font, int mag, const char *text) override;
83+
void internalDrawText(const Coord &where, const void *font, int mag, const char *text) override;
8484
void drawBitmap(const Coord &where, const DrawableIcon *icon, bool selected) override;
8585
void drawXBitmap(const Coord &where, const Coord &size, const uint8_t *data) override;
8686
void drawBox(const Coord &where, const Coord &size, bool filled) override;
@@ -89,9 +89,11 @@ class U8g2Drawable : public DeviceDrawable {
8989

9090
Coord getDisplayDimensions() override { return Coord(u8g2->getWidth(), u8g2->getHeight()); }
9191
void transaction(bool isStarting, bool redrawNeeded) override;
92-
Coord textExtents(const void *font, int mag, const char *text, int *baseline) override;
93-
color_t getUnderlyingColor(color_t col) { return (col<4) ? col : 1; }
94-
92+
Coord internalTextExtents(const void *font, int mag, const char *text, int *baseline) override;
93+
color_t getUnderlyingColor(color_t col) override { return (col<4) ? col : 1; }
94+
protected:
95+
void drawPixel(uint16_t x, uint16_t y) override;
96+
UnicodeFontHandler *createFontHandler() override;
9597
};
9698

9799
#endif // _TCMENU_U8G2_H_

0 commit comments

Comments
 (0)