mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-31 17:26:12 +00:00
fix: scale Lemon font glyphs with setTextSize on lock screen clock
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
319428c7c6
commit
fa842b202a
@@ -43,11 +43,13 @@ void SH1106Display::startFrame(Color bkg)
|
|||||||
_color = SH110X_WHITE;
|
_color = SH110X_WHITE;
|
||||||
display.setTextColor(_color);
|
display.setTextColor(_color);
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
|
_text_sz = 1;
|
||||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||||
}
|
}
|
||||||
|
|
||||||
void SH1106Display::setTextSize(int sz)
|
void SH1106Display::setTextSize(int sz)
|
||||||
{
|
{
|
||||||
|
_text_sz = sz;
|
||||||
display.setTextSize(sz);
|
display.setTextSize(sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +90,7 @@ uint32_t SH1106Display::decodeUtf8(const uint8_t*& p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
|
int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
|
||||||
|
int sz = _text_sz;
|
||||||
for (uint8_t i = 0; i < lemonIconCount; i++) {
|
for (uint8_t i = 0; i < lemonIconCount; i++) {
|
||||||
if (pgm_read_dword(&lemonIconCPs[i]) == cp) {
|
if (pgm_read_dword(&lemonIconCPs[i]) == cp) {
|
||||||
const GFXglyph* g = &lemonIconGlyphs[i];
|
const GFXglyph* g = &lemonIconGlyphs[i];
|
||||||
@@ -99,16 +102,19 @@ int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
|
|||||||
for (uint8_t row = 0; row < h; row++)
|
for (uint8_t row = 0; row < h; row++)
|
||||||
for (uint8_t col = 0; col < w; col++) {
|
for (uint8_t col = 0; col < w; col++) {
|
||||||
if (!bit) { bits = pgm_read_byte(&lemonIconBitmaps[bo++]); bit = 0x80; }
|
if (!bit) { bits = pgm_read_byte(&lemonIconBitmaps[bo++]); bit = 0x80; }
|
||||||
if (bits & bit) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
|
if (bits & bit) {
|
||||||
|
if (sz == 1) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
|
||||||
|
else display.fillRect(x + xo*sz + col*sz, y + 6*sz + yo*sz + row*sz, sz, sz, _color);
|
||||||
|
}
|
||||||
bit >>= 1;
|
bit >>= 1;
|
||||||
}
|
}
|
||||||
return x + xa;
|
return x + xa * sz;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cp < Lemon.first || cp > Lemon.last) {
|
if (cp < Lemon.first || cp > Lemon.last) {
|
||||||
if (cp >= 0x20) display.fillRect(x + 1, y - 1, 4, 6, _color);
|
if (cp >= 0x20) display.fillRect(x + sz, y - sz, 4*sz, 6*sz, _color);
|
||||||
return x + 6;
|
return x + 6 * sz;
|
||||||
}
|
}
|
||||||
const GFXglyph* g = &lemonGlyphs[cp - Lemon.first];
|
const GFXglyph* g = &lemonGlyphs[cp - Lemon.first];
|
||||||
uint8_t w = pgm_read_byte(&g->width), h = pgm_read_byte(&g->height);
|
uint8_t w = pgm_read_byte(&g->width), h = pgm_read_byte(&g->height);
|
||||||
@@ -119,15 +125,20 @@ int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
|
|||||||
for (uint8_t row = 0; row < h; row++)
|
for (uint8_t row = 0; row < h; row++)
|
||||||
for (uint8_t col = 0; col < w; col++) {
|
for (uint8_t col = 0; col < w; col++) {
|
||||||
if (!bit) { bits = pgm_read_byte(&lemonBitmaps[bo++]); bit = 0x80; }
|
if (!bit) { bits = pgm_read_byte(&lemonBitmaps[bo++]); bit = 0x80; }
|
||||||
if (bits & bit) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
|
if (bits & bit) {
|
||||||
|
if (sz == 1) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
|
||||||
|
else display.fillRect(x + xo*sz + col*sz, y + 6*sz + yo*sz + row*sz, sz, sz, _color);
|
||||||
|
}
|
||||||
bit >>= 1;
|
bit >>= 1;
|
||||||
}
|
}
|
||||||
return x + xa;
|
return x + xa * sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t SH1106Display::lemonXAdvance(uint32_t cp) {
|
uint8_t SH1106Display::lemonXAdvance(uint32_t cp) {
|
||||||
if (cp < Lemon.first || cp > Lemon.last) return 6;
|
uint8_t xa;
|
||||||
return pgm_read_byte(&lemonGlyphs[cp - Lemon.first].xAdvance);
|
if (cp < Lemon.first || cp > Lemon.last) xa = 6;
|
||||||
|
else xa = pgm_read_byte(&lemonGlyphs[cp - Lemon.first].xAdvance);
|
||||||
|
return xa * _text_sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SH1106Display::translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) {
|
void SH1106Display::translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class SH1106Display : public DisplayDriver
|
|||||||
uint8_t _contrast;
|
uint8_t _contrast;
|
||||||
uint8_t _precharge;
|
uint8_t _precharge;
|
||||||
bool _use_lemon;
|
bool _use_lemon;
|
||||||
|
int _text_sz;
|
||||||
|
|
||||||
bool i2c_probe(TwoWire &wire, uint8_t addr);
|
bool i2c_probe(TwoWire &wire, uint8_t addr);
|
||||||
static uint32_t decodeUtf8(const uint8_t*& p);
|
static uint32_t decodeUtf8(const uint8_t*& p);
|
||||||
@@ -30,7 +31,7 @@ class SH1106Display : public DisplayDriver
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SH1106Display() : DisplayDriver(128, 64), display(128, 64, &Wire, PIN_OLED_RESET) {
|
SH1106Display() : DisplayDriver(128, 64), display(128, 64, &Wire, PIN_OLED_RESET) {
|
||||||
_isOn = false; _contrast = 255; _precharge = 0x1F; _use_lemon = false;
|
_isOn = false; _contrast = 255; _precharge = 0x1F; _use_lemon = false; _text_sz = 1;
|
||||||
}
|
}
|
||||||
bool begin();
|
bool begin();
|
||||||
|
|
||||||
@@ -47,8 +48,8 @@ public:
|
|||||||
void drawRect(int x, int y, int w, int h) override;
|
void drawRect(int x, int y, int w, int h) override;
|
||||||
void drawXbm(int x, int y, const uint8_t *bits, int w, int h) override;
|
void drawXbm(int x, int y, const uint8_t *bits, int w, int h) override;
|
||||||
uint16_t getTextWidth(const char *str) override;
|
uint16_t getTextWidth(const char *str) override;
|
||||||
int getCharWidth() const override { return _use_lemon ? 5 : 6; }
|
int getCharWidth() const override { return (_use_lemon ? 5 : 6) * _text_sz; }
|
||||||
int getLineHeight() const override { return _use_lemon ? 9 : 8; }
|
int getLineHeight() const override { return (_use_lemon ? 9 : 8) * _text_sz; }
|
||||||
void setLemonFont(bool enabled) override { _use_lemon = enabled; }
|
void setLemonFont(bool enabled) override { _use_lemon = enabled; }
|
||||||
void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) override;
|
void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) override;
|
||||||
void setBrightness(uint8_t level) override;
|
void setBrightness(uint8_t level) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user