From f975d2119584f3859b3ca514f9368364cb428bfa Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Fri, 16 Jan 2026 20:09:51 +0100 Subject: [PATCH] Make scrolling look way better --- include/scrolling_text.h | 13 +++----- lib/TFT_eSPI/TFT_eSPI.cpp | 68 +++++++++++++++++---------------------- src/globals.cpp | 4 +-- 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/include/scrolling_text.h b/include/scrolling_text.h index a30fa72..7e236cb 100644 --- a/include/scrolling_text.h +++ b/include/scrolling_text.h @@ -14,7 +14,6 @@ private: unsigned long holdTick; bool isScrolling; std::function postDrawCallback; - int usedW; int usedH; static const unsigned long SCROLL_INTERVAL = 5; @@ -22,8 +21,8 @@ private: static const int SCROLL_GAP = 10; public: - ScrollingTextDisplay(TFT_eSprite* spr, int y, int maxW, int inuseW = -1, int inuseH = -1 ) : - sprite(spr), yPos(y), maxWidth(maxW), xPos(0), textWidth(0), lastTick(0), holdTick(0), isScrolling(false), postDrawCallback(nullptr), usedW(inuseW), usedH(inuseH) {} + ScrollingTextDisplay(TFT_eSprite* spr, int y, int maxW, int inuseH = -1 ) : + sprite(spr), yPos(y), maxWidth(maxW), xPos(0), textWidth(0), lastTick(0), holdTick(0), isScrolling(false), postDrawCallback(nullptr), usedH(inuseH) {} void setPostDrawCallback(std::function callback) { postDrawCallback = callback; @@ -74,11 +73,11 @@ public: private: void drawText(const String& text, bool status, uint16_t activeColor, uint16_t activeSmooth, uint16_t dropoutColor, uint16_t dropoutSmooth, uint16_t backgroundColor) { - if(usedW > 0 && usedH > 0) { + if(usedH > 0) { sprite->fillSprite(TFT_TRANSPARENT); - sprite->fillRect(0, 0, usedW, usedH, backgroundColor); + sprite->fillRect(0, 0, maxWidth, usedH, backgroundColor); - sprite->setViewport(0, 0, usedW, usedH); + sprite->setViewport(0, 0, maxWidth, usedH); if(status) sprite->setTextColor(activeColor, activeSmooth, false); else sprite->setTextColor(dropoutColor, dropoutSmooth, false); @@ -97,8 +96,6 @@ private: if(isScrolling) sprite->drawString(text, xPos + textWidth + SCROLL_GAP, 0); } - sprite->fillRect(0, sprite->fontHeight(), sprite->width(), sprite->height() - sprite->fontHeight(), TFT_TRANSPARENT); - if(postDrawCallback) postDrawCallback(sprite, false); sprite->pushSprite(35, yPos, TFT_TRANSPARENT); } diff --git a/lib/TFT_eSPI/TFT_eSPI.cpp b/lib/TFT_eSPI/TFT_eSPI.cpp index 906b78d..66be0ac 100644 --- a/lib/TFT_eSPI/TFT_eSPI.cpp +++ b/lib/TFT_eSPI/TFT_eSPI.cpp @@ -388,7 +388,7 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h) textbgcolor = bitmap_bg = 0x0000; _fillbg = isDigits = textwrapY = false; - textwrapX = true; + textwrapX = false; textdatum = TL_DATUM; _swapBytes = false; @@ -2256,7 +2256,6 @@ void TFT_eSPI::drawWedgeLine(float ax, float ay, float bx, float by, float ar, f float alpha = 1.0f; ar += 0.5; - uint16_t bg = bg_color; float xpax, ypay, bax = bx - ax, bay = by - ay; begin_nin_write(); @@ -2282,10 +2281,10 @@ void TFT_eSPI::drawWedgeLine(float ax, float ay, float bx, float by, float ar, f } //Blend color with background and plot if (bg_color == 0x00FFFFFF) { - bg = readPixel(xp, yp); swin = true; + bg_color = readPixel(xp, yp); swin = true; } if (swin) { setWindow(xp, yp, x1, yp); swin = false; } - pushColor(fastBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg)); + pushColor(fastBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg_color)); } } @@ -2309,10 +2308,10 @@ void TFT_eSPI::drawWedgeLine(float ax, float ay, float bx, float by, float ar, f continue; } if (bg_color == 0x00FFFFFF) { - bg = readPixel(xp, yp); swin = true; + bg_color = readPixel(xp, yp); swin = true; } if (swin) { setWindow(xp, yp, x1, yp); swin = false; } - pushColor(fastBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg)); + pushColor(fastBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg_color)); } } @@ -2549,7 +2548,7 @@ int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY, uint8 uint16_t cheight = 8 * textsize; baseline = gFonts[font].maxAscent; - cheight = fontHeight(font); + cheight = fontHeight(font); if (textdatum || padX) { switch(textdatum) { @@ -2862,14 +2861,9 @@ bool TFT_eSPI::getUnicodeIndex(uint16_t unicode, uint16_t *index, uint16_t font) return false; } -void TFT_eSPI::drawGlyph(uint16_t code, uint16_t font) -{ - uint16_t fg = textcolor; - uint16_t bg = textbgcolor; - +void TFT_eSPI::drawGlyph(uint16_t code, uint16_t font) { // Check if cursor has moved - if (last_cursor_x != cursor_x) - { + if (last_cursor_x != cursor_x) { bg_cursor_x = cursor_x; last_cursor_x = cursor_x; } @@ -2877,7 +2871,7 @@ void TFT_eSPI::drawGlyph(uint16_t code, uint16_t font) if (code < 0x21) { if (code == 0x20) { - if (_fillbg) fillRect(bg_cursor_x, cursor_y, (cursor_x + gFonts[font].spaceWidth) - bg_cursor_x, gFonts[font].yAdvance, bg); + if (_fillbg) fillRect(bg_cursor_x, cursor_y, (cursor_x + gFonts[font].spaceWidth) - bg_cursor_x, gFonts[font].yAdvance, textbgcolor); cursor_x += gFonts[font].spaceWidth; bg_cursor_x = cursor_x; last_cursor_x = cursor_x; @@ -2958,16 +2952,16 @@ void TFT_eSPI::drawGlyph(uint16_t code, uint16_t font) if (pixel) { - if (bl) { drawFastHLine( bxs, y + cy, bl, bg); bl = 0; } + if (bl) { drawFastHLine( bxs, y + cy, bl, textbgcolor); bl = 0; } if (pixel != 0xFF) { if (fl) { - if (fl==1) drawPixel(fxs, y + cy, fg); - else drawFastHLine( fxs, y + cy, fl, fg); + if (fl==1) drawPixel(fxs, y + cy, textcolor); + else drawFastHLine( fxs, y + cy, fl, textcolor); fl = 0; } - if (getColor) bg = getColor(x + cx, y + cy); - drawPixel(x + cx, y + cy, alphaBlend(pixel, fg, bg)); + if (getColor) textbgcolor = getColor(x + cx, y + cy); + drawPixel(x + cx, y + cy, alphaBlend(pixel, textcolor, textbgcolor)); } else { @@ -2977,7 +2971,7 @@ void TFT_eSPI::drawGlyph(uint16_t code, uint16_t font) } else { - if (fl) { drawFastHLine( fxs, y + cy, fl, fg); fl = 0; } + if (fl) { drawFastHLine( fxs, y + cy, fl, textcolor); fl = 0; } if (_fillbg) { if (x >= bx) { if (bl==0) bxs = x + cx; @@ -2986,8 +2980,8 @@ void TFT_eSPI::drawGlyph(uint16_t code, uint16_t font) } } } - if (fl) { drawFastHLine( fxs, y + cy, fl, fg); fl = 0; } - if (bl) { drawFastHLine( bxs, y + cy, bl, bg); bl = 0; } + if (fl) { drawFastHLine( fxs, y + cy, fl, textcolor); fl = 0; } + if (bl) { drawFastHLine( bxs, y + cy, bl, textcolor); bl = 0; } } // Fill area below glyph @@ -3005,7 +2999,7 @@ void TFT_eSPI::drawGlyph(uint16_t code, uint16_t font) else { // Point code not in font so draw a rectangle and move on cursor - drawRect(cursor_x, cursor_y + gFonts[font].maxAscent - gFonts[font].ascent, gFonts[font].spaceWidth, gFonts[font].ascent, fg); + drawRect(cursor_x, cursor_y + gFonts[font].maxAscent - gFonts[font].ascent, gFonts[font].spaceWidth, gFonts[font].ascent, textcolor); cursor_x += gFonts[font].spaceWidth + 1; } bg_cursor_x = cursor_x; @@ -4474,10 +4468,8 @@ int16_t TFT_eSprite::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t fo void TFT_eSprite::drawGlyph(uint16_t code, uint16_t font) { - uint16_t fg = textcolor; - uint16_t bg = textbgcolor; bool getBG = false; - if (fg == bg) getBG = true; + if (textcolor == textbgcolor) getBG = true; // Check if cursor has moved if (last_cursor_x != cursor_x) { @@ -4487,7 +4479,7 @@ void TFT_eSprite::drawGlyph(uint16_t code, uint16_t font) if (code < 0x21) { if (code == 0x20) { - if (_fillbg) fillRect(bg_cursor_x, cursor_y, (cursor_x + gFonts[font].spaceWidth) - bg_cursor_x, gFonts[font].yAdvance, bg); + if (_fillbg) fillRect(bg_cursor_x, cursor_y, (cursor_x + gFonts[font].spaceWidth) - bg_cursor_x, gFonts[font].yAdvance, textbgcolor); cursor_x += gFonts[font].spaceWidth; bg_cursor_x = cursor_x; last_cursor_x = cursor_x; @@ -4511,7 +4503,7 @@ void TFT_eSprite::drawGlyph(uint16_t code, uint16_t font) bool newSprite = !_created; if (newSprite) { createSprite(gWidth[font][gNum], gFonts[font].yAdvance); - if(fg != bg) fillSprite(bg); + if(textcolor != textbgcolor) fillSprite(textbgcolor); cursor_x = -gdX[font][gNum]; bg_cursor_x = cursor_x; last_cursor_x = cursor_x; @@ -4566,22 +4558,22 @@ void TFT_eSprite::drawGlyph(uint16_t code, uint16_t font) pixel = pgm_read_byte(gPtr + gBitmap[font][gNum] + x + gWidth[font][gNum] * y); if (pixel) { - if (bl) { drawFastHLine( bxs, y + cy, bl, bg); bl = 0; } + if (bl) { drawFastHLine( bxs, y + cy, bl, textbgcolor); bl = 0; } if (pixel != 0xFF) { if (fl) { - if (fl==1) drawPixel(fxs, y + cy, fg); - else drawFastHLine( fxs, y + cy, fl, fg); + if (fl==1) drawPixel(fxs, y + cy, textcolor); + else drawFastHLine( fxs, y + cy, fl, textcolor); fl = 0; } - if (getBG) bg = readPixel(x + cx, y + cy); - drawPixel(x + cx, y + cy, alphaBlend(pixel, fg, bg)); + if (getBG) textbgcolor = readPixel(x + cx, y + cy); + drawPixel(x + cx, y + cy, alphaBlend(pixel, textcolor, textbgcolor)); } else { if (fl==0) fxs = x + cx; fl++; } } else { - if (fl) { drawFastHLine( fxs, y + cy, fl, fg); fl = 0; } + if (fl) { drawFastHLine( fxs, y + cy, fl, textcolor); fl = 0; } if (_fillbg) { if (x >= bx) { if (bl==0) bxs = x + cx; @@ -4590,8 +4582,8 @@ void TFT_eSprite::drawGlyph(uint16_t code, uint16_t font) } } } - if (fl) { drawFastHLine( fxs, y + cy, fl, fg); fl = 0; } - if (bl) { drawFastHLine( bxs, y + cy, bl, bg); bl = 0; } + if (fl) { drawFastHLine( fxs, y + cy, fl, textcolor); fl = 0; } + if (bl) { drawFastHLine( bxs, y + cy, bl, textbgcolor); bl = 0; } } // Fill area below glyph @@ -4609,7 +4601,7 @@ void TFT_eSprite::drawGlyph(uint16_t code, uint16_t font) } } else { - drawRect(cursor_x, cursor_y + gFonts[font].maxAscent - gFonts[font].ascent, gFonts[font].spaceWidth, gFonts[font].ascent, fg); + drawRect(cursor_x, cursor_y + gFonts[font].maxAscent - gFonts[font].ascent, gFonts[font].spaceWidth, gFonts[font].ascent, textcolor); cursor_x += gFonts[font].spaceWidth + 1; } bg_cursor_x = cursor_x; diff --git a/src/globals.cpp b/src/globals.cpp index e54769d..76181c9 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -351,7 +351,7 @@ WiFiClient RemoteClient; WiFiUDP Udp; WebServer webserver(80); -ScrollingTextDisplay rtplusDisplay(&GeneralTextSprite, 147, 180, 165, 19); -ScrollingTextDisplay eonDisplay(&GeneralTextSprite, 174, 180, 165, 19); +ScrollingTextDisplay rtplusDisplay(&GeneralTextSprite, 147, 173, 19); +ScrollingTextDisplay eonDisplay(&GeneralTextSprite, 174, 173, 19); ScrollingTextDisplay eccDisplay(&FullLineSprite, 198, 270); ScrollingTextDisplay rtDisplay(&FullLineSprite, 220, 270); \ No newline at end of file