From 1db80b31a0891c2598335bd357d4658773ba656b Mon Sep 17 00:00:00 2001 From: jfrickmann Date: Sat, 4 Sep 2021 06:05:57 -0400 Subject: [PATCH 1/4] Improved drawtextLines(...) Now supports newline \n and automatic line break with hyphens, slashes and colons. --- radio/src/gui/colorlcd/draw_functions.cpp | 38 ++++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/radio/src/gui/colorlcd/draw_functions.cpp b/radio/src/gui/colorlcd/draw_functions.cpp index 148b2ae9a..81d5f9762 100644 --- a/radio/src/gui/colorlcd/draw_functions.cpp +++ b/radio/src/gui/colorlcd/draw_functions.cpp @@ -511,20 +511,42 @@ void drawTextLines(BitmapBuffer * dc, coord_t left, coord_t top, coord_t width, coord_t line = getFontHeight(flags & 0xFFFF); coord_t space = getTextWidth(" ", 1, flags); coord_t word; - const char * eos = str + strlen(str); - const char * nxt; + const char * nxt = str; - while (str < eos) { - nxt = strstr(str, " "); - if (!nxt) nxt = eos; + while (true) { + for (bool done = false; !done; nxt++) { + switch (nxt[0]) { + case '-': + case '/': + case ':': + nxt++; + case ' ': + case '\n': + case '\0': + done = true; + } + } + nxt--; word = getTextWidth(str, nxt - str, flags); if (x + word > left + width && x > left) { x = left; y += line; } - if (y + line > top + height) break; + if (y + line > top + height) return; dc->drawSizedText(x, y, str, nxt - str, flags); - str = nxt + 1; - x += word + space; + x += word; + switch (nxt[0]) { + case '\0': + return; + case '\n': + x = left; + y += line; + nxt++; + break; + case ' ': + x += space; + nxt++; + } + str = nxt; } } \ No newline at end of file From e15b9636fa38c63e1fa93e900681a33972eeada7 Mon Sep 17 00:00:00 2001 From: jfrickmann Date: Sat, 4 Sep 2021 07:15:02 -0400 Subject: [PATCH 2/4] Implemented BLINK, INVERSE and SHADOWED Also updated documentation --- radio/src/lua/api_colorlcd.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/radio/src/lua/api_colorlcd.cpp b/radio/src/lua/api_colorlcd.cpp index 5213ac6cf..81e8c4dc1 100644 --- a/radio/src/lua/api_colorlcd.cpp +++ b/radio/src/lua/api_colorlcd.cpp @@ -300,7 +300,7 @@ Draw text inside rectangle (x,y,w,h) with line breaks @param text (string) text to display -@param flags (optional) please see [Lcd functions overview](../lcd-functions-less-than-greater-than-luadoc-begin-lcd/lcd_functions-overview.html) for drawing flags and colors, and [Appendix](../../part_vii_-_appendix/fonts.md) for available characters in each font set. INVERS and BLINK are not implemented. +@param flags (optional) please see [Lcd functions overview](../lcd-functions-less-than-greater-than-luadoc-begin-lcd/lcd_functions-overview.html) for drawing flags and colors, and [Appendix](../../part_vii_-_appendix/fonts.md) for available characters in each font set. RIGHT, CENTER and VCENTER are not implemented. @status current Introduced in 2.5.0 */ @@ -320,6 +320,31 @@ static int luaLcdDrawTextLines(lua_State *L) x += getTextHorizontalOffset(flags); y += getTextVerticalOffset(flags); + bool invers = flags & INVERS; + if (flags & BLINK) + invers = invers && !BLINK_ON_PHASE; + + if (invers) { + // Find inverse color or read from optional Lua argument + LcdFlags color = flagsRGB(flags); + LcdFlags invColor = luaL_optunsigned(L, 7, ~0u); // ~0 is impossible for color flag! + if (invColor == ~0u) { + RGB_SPLIT(COLOR_VAL(color), r, g, b); + invColor = COLOR2FLAGS(RGB_JOIN(31 - r, 63 - g, 31 - b)); + } else + invColor = flagsRGB(invColor); + flags = (flags & 0xFFFF) | invColor; + + // Draw color box + luaLcdBuffer->drawSolidFilledRect(x, y, w, h, color); + } else { + if ((flags & BLINK) && !BLINK_ON_PHASE) + return 0; + if (flags & SHADOWED) + drawTextLines(luaLcdBuffer, x+1, y+1, w, h, s, flags & 0xFFFF); // force black + flags = (flags & 0xFFFF) | flagsRGB(flags); + } + drawTextLines(luaLcdBuffer, x, y, w, h, s, flags); return 0; } From 1d2983ad93a09082254805b33a2b1ae9f7f54e3a Mon Sep 17 00:00:00 2001 From: jfrickmann Date: Sat, 4 Sep 2021 15:54:44 -0400 Subject: [PATCH 3/4] Mask out VCENTER, CENTER and RIGHT flags --- radio/src/gui/colorlcd/draw_functions.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/radio/src/gui/colorlcd/draw_functions.cpp b/radio/src/gui/colorlcd/draw_functions.cpp index 81d5f9762..fb5485071 100644 --- a/radio/src/gui/colorlcd/draw_functions.cpp +++ b/radio/src/gui/colorlcd/draw_functions.cpp @@ -512,6 +512,7 @@ void drawTextLines(BitmapBuffer * dc, coord_t left, coord_t top, coord_t width, coord_t space = getTextWidth(" ", 1, flags); coord_t word; const char * nxt = str; + flags &= ~(VCENTERED | CENTERED | RIGHT); while (true) { for (bool done = false; !done; nxt++) { From 1e505d40294693f61a5130fb3ac8f45f649c4b6d Mon Sep 17 00:00:00 2001 From: jfrickmann Date: Sat, 4 Sep 2021 15:55:14 -0400 Subject: [PATCH 4/4] Do not apply (x,y) offsets! --- radio/src/lua/api_colorlcd.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/radio/src/lua/api_colorlcd.cpp b/radio/src/lua/api_colorlcd.cpp index 81e8c4dc1..c109f7338 100644 --- a/radio/src/lua/api_colorlcd.cpp +++ b/radio/src/lua/api_colorlcd.cpp @@ -316,10 +316,6 @@ static int luaLcdDrawTextLines(lua_State *L) const char * s = luaL_checkstring(L, 5); LcdFlags flags = luaL_optunsigned(L, 6, 0); - // apply text offsets, needed to align 2.4.x to 2.3.x font baselines - x += getTextHorizontalOffset(flags); - y += getTextVerticalOffset(flags); - bool invers = flags & INVERS; if (flags & BLINK) invers = invers && !BLINK_ON_PHASE;