diff --git a/radio/src/gui/colorlcd/colors.h b/radio/src/gui/colorlcd/colors.h index e50a06bb2..d0d7f9511 100644 --- a/radio/src/gui/colorlcd/colors.h +++ b/radio/src/gui/colorlcd/colors.h @@ -102,51 +102,46 @@ inline void lcdSetColor(uint16_t color) #define COLOR(index) (lcdColorTable[ unsigned(index) & 0xFF ] << 16u) -#define DEFAULT_COLOR COLOR(DEFAULT_COLOR_INDEX) -#define DEFAULT_BGCOLOR COLOR(DEFAULT_BGCOLOR_INDEX) -#define FOCUS_COLOR COLOR(FOCUS_COLOR_INDEX) -#define FOCUS_BGCOLOR COLOR(FOCUS_BGCOLOR_INDEX) -#define DISABLE_COLOR COLOR(DISABLE_COLOR_INDEX) -#define HIGHLIGHT_COLOR COLOR(HIGHLIGHT_COLOR_INDEX) -#define CHECKBOX_COLOR COLOR(CHECKBOX_COLOR_INDEX) -#define SCROLLBAR_COLOR COLOR(SCROLLBAR_COLOR_INDEX) -#define MENU_COLOR COLOR(MENU_COLOR_INDEX) -#define MENU_BGCOLOR COLOR(MENU_BGCOLOR_INDEX) -#define MENU_TITLE_BGCOLOR COLOR(MENU_TITLE_BGCOLOR_INDEX) -#define MENU_LINE_COLOR COLOR(MENU_LINE_COLOR_INDEX) -#define MENU_HIGHLIGHT_COLOR COLOR(MENU_HIGHLIGHT_COLOR_INDEX) -#define MENU_HIGHLIGHT_BGCOLOR COLOR(MENU_HIGHLIGHT_BGCOLOR_INDEX) -#define OVERLAY_COLOR COLOR(OVERLAY_COLOR_INDEX) -#define TABLE_BGCOLOR COLOR(TABLE_BGCOLOR_INDEX) -#define TABLE_HEADER_BGCOLOR COLOR(TABLE_HEADER_BGCOLOR_INDEX) -#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX) - -#define TEXT_STATUSBAR_COLOR COLOR(TEXT_STATUSBAR_COLOR_INDEX) -#define LINE_COLOR COLOR(LINE_COLOR_INDEX) -#define HEADER_SEPARATOR_COLOR COLOR(HEADER_SEPARATOR_COLOR_INDEX) -#define MENU_BGCOLOR COLOR(MENU_BGCOLOR_INDEX) -#define MENU_COLOR COLOR(MENU_COLOR_INDEX) -#define MENU_TITLE_DISABLE_COLOR COLOR(MENU_TITLE_DISABLE_COLOR_INDEX) -#define HEADER_COLOR COLOR(HEADER_COLOR_INDEX) #define ALARM_COLOR COLOR(ALARM_COLOR_INDEX) -#define HIGHLIGHT_COLOR COLOR(HIGHLIGHT_COLOR_INDEX) -#define TEXT_DISABLE_COLOR COLOR(TEXT_DISABLE_COLOR_INDEX) -#define CURVE_COLOR COLOR(CURVE_COLOR_INDEX) -#define CURVE_CURSOR_COLOR COLOR(CURVE_CURSOR_COLOR_INDEX) -#define CURVE_AXIS_COLOR COLOR(CURVE_AXIS_COLOR_INDEX) -#define TITLE_BGCOLOR COLOR(TITLE_BGCOLOR_INDEX) -#define TRIM_BGCOLOR COLOR(TRIM_BGCOLOR_INDEX) -#define TRIM_SHADOW_COLOR COLOR(TRIM_SHADOW_COLOR_INDEX) -#define HEADER_BGCOLOR COLOR(HEADER_BGCOLOR_INDEX) -#define HEADER_ICON_BGCOLOR COLOR(HEADER_ICON_BGCOLOR_INDEX) -#define HEADER_CURRENT_BGCOLOR COLOR(HEADER_CURRENT_BGCOLOR_INDEX) -#define MAINVIEW_PANES_COLOR COLOR(MAINVIEW_PANES_COLOR_INDEX) -#define MAINVIEW_GRAPHICS_COLOR COLOR(MAINVIEW_GRAPHICS_COLOR_INDEX) #define BARGRAPH1_COLOR COLOR(BARGRAPH1_COLOR_INDEX) #define BARGRAPH2_COLOR COLOR(BARGRAPH2_COLOR_INDEX) #define BARGRAPH_BGCOLOR COLOR(BARGRAPH_BGCOLOR_INDEX) -#define SCROLLBOX_COLOR COLOR(SCROLLBOX_COLOR_INDEX) -#define BATTERY_CHARGE_COLOR COLOR(BATTERY_CHARGE_COLOR_INDEX) +//#define BATTERY_CHARGE_COLOR COLOR(BATTERY_CHARGE_COLOR_INDEX) +#define CHECKBOX_COLOR COLOR(CHECKBOX_COLOR_INDEX) +#define CURVE_AXIS_COLOR COLOR(CURVE_AXIS_COLOR_INDEX) +#define CURVE_COLOR COLOR(CURVE_COLOR_INDEX) +#define CURVE_CURSOR_COLOR COLOR(CURVE_CURSOR_COLOR_INDEX) +#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX) +#define DEFAULT_BGCOLOR COLOR(DEFAULT_BGCOLOR_INDEX) +#define DEFAULT_COLOR COLOR(DEFAULT_COLOR_INDEX) +#define DISABLE_COLOR COLOR(DISABLE_COLOR_INDEX) +#define FOCUS_BGCOLOR COLOR(FOCUS_BGCOLOR_INDEX) +#define FOCUS_COLOR COLOR(FOCUS_COLOR_INDEX) +#define HEADER_BGCOLOR COLOR(HEADER_BGCOLOR_INDEX) +#define HEADER_COLOR COLOR(HEADER_COLOR_INDEX) +#define HEADER_CURRENT_BGCOLOR COLOR(HEADER_CURRENT_BGCOLOR_INDEX) +#define HEADER_ICON_BGCOLOR COLOR(HEADER_ICON_BGCOLOR_INDEX) +//#define HEADER_SEPARATOR_COLOR COLOR(HEADER_SEPARATOR_COLOR_INDEX) +#define HIGHLIGHT_COLOR COLOR(HIGHLIGHT_COLOR_INDEX) +#define LINE_COLOR COLOR(LINE_COLOR_INDEX) +#define MAINVIEW_GRAPHICS_COLOR COLOR(MAINVIEW_GRAPHICS_COLOR_INDEX) +#define MAINVIEW_PANES_COLOR COLOR(MAINVIEW_PANES_COLOR_INDEX) +#define MENU_BGCOLOR COLOR(MENU_BGCOLOR_INDEX) +#define MENU_COLOR COLOR(MENU_COLOR_INDEX) +#define MENU_HIGHLIGHT_BGCOLOR COLOR(MENU_HIGHLIGHT_BGCOLOR_INDEX) +#define MENU_HIGHLIGHT_COLOR COLOR(MENU_HIGHLIGHT_COLOR_INDEX) +#define MENU_LINE_COLOR COLOR(MENU_LINE_COLOR_INDEX) +//#define MENU_TITLE_BGCOLOR COLOR(MENU_TITLE_BGCOLOR_INDEX) +#define MENU_TITLE_DISABLE_COLOR COLOR(MENU_TITLE_DISABLE_COLOR_INDEX) +#define OVERLAY_COLOR COLOR(OVERLAY_COLOR_INDEX) +#define SCROLLBAR_COLOR COLOR(SCROLLBAR_COLOR_INDEX) +#define TABLE_BGCOLOR COLOR(TABLE_BGCOLOR_INDEX) +#define TABLE_HEADER_BGCOLOR COLOR(TABLE_HEADER_BGCOLOR_INDEX) +#define TEXT_DISABLE_COLOR COLOR(TEXT_DISABLE_COLOR_INDEX) +#define TEXT_STATUSBAR_COLOR COLOR(TEXT_STATUSBAR_COLOR_INDEX) +#define TITLE_BGCOLOR COLOR(TITLE_BGCOLOR_INDEX) +#define TRIM_BGCOLOR COLOR(TRIM_BGCOLOR_INDEX) +#define TRIM_SHADOW_COLOR COLOR(TRIM_SHADOW_COLOR_INDEX) #if defined(WINDOWS_INSPECT_BORDERS) #define WINDOWS_INSPECT_BORDER_COLOR LINE_COLOR diff --git a/radio/src/lua/api_colorlcd.cpp b/radio/src/lua/api_colorlcd.cpp index f52eaf95f..a8f03edf4 100644 --- a/radio/src/lua/api_colorlcd.cpp +++ b/radio/src/lua/api_colorlcd.cpp @@ -24,17 +24,20 @@ #include "lua_api.h" #include "libopenui.h" -// TODO: obsolete definition -#define INVERS 0 +#include "api_colorlcd.h" BitmapBuffer* luaLcdBuffer = nullptr; + /*luadoc @function lcd.refresh() Refresh the LCD screen -@status current Obsoleted in 2.4.0 +From 2.4.0 on color LCDs, this is done automatically when the screen +needs to be refreshed (on events and depending on refresh period). + +@status current Only used on non-color LCDs. */ static int luaLcdRefresh(lua_State *L) { @@ -107,7 +110,7 @@ static int luaLcdDrawPoint(lua_State *L) LcdFlags att = luaL_optunsigned(L, 3, 0); // here another definition should be used - luaLcdBuffer->drawPixel(x, y, COLOR(att)); + luaLcdBuffer->drawPixel(x, y, COLOR_VAL(att)); return 0; } @@ -145,22 +148,24 @@ static int luaLcdDrawLine(lua_State *L) if (x1 > LCD_W || y1 > LCD_H || x2 > LCD_W || y2 > LCD_H) return 0; + uint16_t color_idx = COLOR_VAL(flags) & 0xFF; + flags = COLOR(color_idx); + if (pat == SOLID) { if (x1 == x2) { - luaLcdBuffer->drawSolidVerticalLine(x1, y1drawSolidVerticalLine( + x1, y1 < y2 ? y1 : y2, y1 < y2 ? (y2 - y1) + 1 : (y1 - y2) + 1, + flags); return 0; - } - else if (y1 == y2) { - luaLcdBuffer->drawSolidHorizontalLine(x1drawSolidHorizontalLine( + x1 < x2 ? x1 : x2, y1, x1 < x2 ? (x2 - x1) + 1 : (x1 - x2) + 1, + flags); return 0; } } - luaLcdBuffer->drawLine(x1, y1, x2, y2, pat, COLOR2FLAGS(COLOR(flags))); + luaLcdBuffer->drawLine(x1, y1, x2, y2, pat, flags); return 0; } @@ -198,10 +203,28 @@ static int luaLcdDrawText(lua_State *L) const char * s = luaL_checkstring(L, 3); unsigned int att = luaL_optunsigned(L, 4, 0); - if ((att&SHADOWED) && !(att&INVERS)) { + bool invers = att & INVERS; + bool blink = att & INVERS; + bool shadowed = att & SHADOWED; + + // from here on, we need only the color + att = (att & 0xFFFF) | COLOR(COLOR_VAL(att)); + + if (shadowed && !invers) { + // force black luaLcdBuffer->drawText(x+1, y+1, s, att & 0xFFFF); } - luaLcdBuffer->drawText(x, y, s, (att & 0xFFFF) | (COLOR2FLAGS(COLOR(att)))); + + if (invers) { + int height = getFontHeight(att & 0xFFFF); + luaLcdBuffer->drawSolidFilledRect(x - INVERT_BOX_MARGIN, + y - INVERT_BOX_MARGIN, + end_pos - x + 2 * INVERT_BOX_MARGIN, + height + 2 * INVERT_BOX_MARGIN, + ); + } + + coord_t end_pos = luaLcdBuffer->drawText(x, y, s, att); return 0; } @@ -269,12 +292,16 @@ static int luaLcdDrawNumber(lua_State *L) int x = luaL_checkinteger(L, 1); int y = luaL_checkinteger(L, 2); int val = luaL_checkinteger(L, 3); - unsigned int att = luaL_optunsigned(L, 4, 0); - if ((att&SHADOWED) && !(att&INVERS)) { + unsigned int att = luaL_optunsigned(L, 4, 0); + att = (att & 0xFFFF) | COLOR(COLOR_VAL(att)); + + if (att & INVERS) + + if ((att & SHADOWED) && !(att & INVERS)) { luaLcdBuffer->drawNumber(x, y, val, att & 0xFFFF); } - luaLcdBuffer->drawNumber(x, y, val, (att & 0xFFFF) | COLOR2FLAGS(COLOR(att))); + luaLcdBuffer->drawNumber(x, y, val, att); return 0; } @@ -552,8 +579,7 @@ Draw a rectangle from top left corner (x,y) of specified width and height */ static int luaLcdDrawRectangle(lua_State *L) { - if (!luaLcdAllowed || !luaLcdBuffer) - return 0; + if (!luaLcdAllowed || !luaLcdBuffer) return 0; int x = luaL_checkinteger(L, 1); int y = luaL_checkinteger(L, 2); @@ -561,10 +587,12 @@ static int luaLcdDrawRectangle(lua_State *L) int h = luaL_checkinteger(L, 4); unsigned int flags = luaL_optunsigned(L, 5, 0); + + uint8_t opacity = (flags >> 24) & 0x0F; + flags = (flags & 0xFFFF) | COLOR(COLOR_VAL(flags)); + unsigned int t = luaL_optunsigned(L, 6, 1); - luaLcdBuffer->drawRect(x, y, w, h, t, SOLID, - COLOR2FLAGS(COLOR(flags)) | (flags & 0xFFFF), - flags >> 24); + luaLcdBuffer->drawRect(x, y, w, h, t, SOLID, flags, opacity); return 0; } @@ -595,9 +623,11 @@ static int luaLcdDrawFilledRectangle(lua_State *L) int h = luaL_checkinteger(L, 4); unsigned int flags = luaL_optunsigned(L, 5, 0); - luaLcdBuffer->drawFilledRect(x, y, w, h, SOLID, - COLOR2FLAGS(COLOR(flags)) | (flags & 0xFFFF), - flags >> 24); + + uint8_t opacity = (flags >> 24) & 0x0F; + flags = (flags & 0xFFFF) | COLOR(COLOR_VAL(flags)); + + luaLcdBuffer->drawFilledRect(x, y, w, h, SOLID, flags, opacity); return 0; } @@ -698,13 +728,12 @@ Set a color for specific area */ static int luaLcdSetColor(lua_State *L) { -#if 0 if (!luaLcdAllowed) return 0; unsigned int index = luaL_checkunsigned(L, 1) >> 16; unsigned int color = luaL_checkunsigned(L, 2); lcdColorTable[index] = color; -#endif + return 0; } diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index dc682ecc3..711e20fdb 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -28,6 +28,7 @@ #if defined(LIBOPENUI) #include "libopenui.h" + #include "api_colorlcd.h" #endif #if defined(PCBX12S) @@ -1794,8 +1795,8 @@ const luaR_value_entry opentxConstants[] = { { "MIDSIZE", FONT(L) }, { "SMLSIZE", FONT(XS) }, { "TINSIZE", FONT(XXS) }, - { "BLINK", 0 }, // obsolete - { "INVERS", 0 }, // obsolete + { "BLINK", BLINK }, + { "INVERS", INVERS }, #else { "XXLSIZE", XXLSIZE }, { "DBLSIZE", DBLSIZE }, @@ -1845,25 +1846,50 @@ const luaR_value_entry opentxConstants[] = { { "COLOR", ZoneOption::Color }, { "BOOL", ZoneOption::Bool }, { "STRING", ZoneOption::String }, - { "DEFAULT_COLOR", DEFAULT_COLOR_INDEX }, - { "DEFAULT_BGCOLOR", DEFAULT_BGCOLOR_INDEX }, - { "FOCUS_COLOR", FOCUS_COLOR_INDEX }, - { "FOCUS_BGCOLOR", FOCUS_BGCOLOR_INDEX }, - { "DISABLE_COLOR", DISABLE_COLOR_INDEX }, - { "HIGHLIGHT_COLOR", HIGHLIGHT_COLOR_INDEX }, - { "CHECKBOX_COLOR", CHECKBOX_COLOR_INDEX }, - { "SCROLLBAR_COLOR", SCROLLBAR_COLOR_INDEX }, - { "MENU_COLOR", MENU_COLOR_INDEX }, - { "MENU_BGCOLOR", MENU_BGCOLOR_INDEX }, - // TODO : FIX { "MENU_TITLE_BGCOLOR", MENU_TITLE_BGCOLOR }, - { "MENU_LINE_COLOR", MENU_LINE_COLOR_INDEX }, - { "MENU_HIGHLIGHT_COLOR", MENU_HIGHLIGHT_COLOR_INDEX }, - { "MENU_HIGHLIGHT_BGCOLOR", MENU_HIGHLIGHT_BGCOLOR_INDEX }, - { "OVERLAY_COLOR", OVERLAY_COLOR_INDEX }, - { "TABLE_BGCOLOR", TABLE_BGCOLOR_INDEX }, - { "TABLE_HEADER_BGCOLOR", TABLE_HEADER_BGCOLOR_INDEX }, - { "CUSTOM_COLOR", CUSTOM_COLOR_INDEX }, - { "MENU_HEADER_HEIGHT", MENU_HEADER_HEIGHT }, + + // Colors gui/colorlcd/colors.h + { "ALARM_COLOR", COLOR2FLAGS(ALARM_COLOR_INDEX) }, + { "BARGRAPH1_COLOR", COLOR2FLAGS(BARGRAPH1_COLOR_INDEX) }, + { "BARGRAPH2_COLOR", COLOR2FLAGS(BARGRAPH2_COLOR_INDEX) }, + { "BARGRAPH_BGCOLOR", COLOR2FLAGS(BARGRAPH_BGCOLOR_INDEX) }, + //{ "BATTERY_CHARGE_COLOR", COLOR2FLAGS(BATTERY_CHARGE_COLOR_INDEX) }, + { "CHECKBOX_COLOR", COLOR2FLAGS(CHECKBOX_COLOR_INDEX) }, + { "CURVE_AXIS_COLOR", COLOR2FLAGS(CURVE_AXIS_COLOR_INDEX) }, + { "CURVE_COLOR", COLOR2FLAGS(CURVE_COLOR_INDEX) }, + { "CURVE_CURSOR_COLOR", COLOR2FLAGS(CURVE_CURSOR_COLOR_INDEX) }, + { "CUSTOM_COLOR", COLOR2FLAGS(CUSTOM_COLOR_INDEX) }, + { "DEFAULT_BGCOLOR", COLOR2FLAGS(DEFAULT_BGCOLOR_INDEX) }, + { "DEFAULT_COLOR", COLOR2FLAGS(DEFAULT_COLOR_INDEX) }, + { "DISABLE_COLOR", COLOR2FLAGS(DISABLE_COLOR_INDEX) }, + { "FOCUS_BGCOLOR", COLOR2FLAGS(FOCUS_BGCOLOR_INDEX) }, + { "FOCUS_COLOR", COLOR2FLAGS(FOCUS_COLOR_INDEX) }, + { "HEADER_BGCOLOR", COLOR2FLAGS(HEADER_BGCOLOR_INDEX) }, + { "HEADER_COLOR", COLOR2FLAGS(HEADER_COLOR_INDEX) }, + { "HEADER_CURRENT_BGCOLOR", COLOR2FLAGS(HEADER_CURRENT_BGCOLOR_INDEX) }, + { "HEADER_ICON_BGCOLOR", COLOR2FLAGS(HEADER_ICON_BGCOLOR_INDEX) }, + //{ "HEADER_SEPARATOR_COLOR", COLOR2FLAGS(HEADER_SEPARATOR_COLOR_INDEX) }, + { "HIGHLIGHT_COLOR", COLOR2FLAGS(HIGHLIGHT_COLOR_INDEX) }, + { "LINE_COLOR", COLOR2FLAGS(LINE_COLOR_INDEX) }, + { "MAINVIEW_GRAPHICS_COLOR", COLOR2FLAGS(MAINVIEW_GRAPHICS_COLOR_INDEX) }, + { "MAINVIEW_PANES_COLOR", COLOR2FLAGS(MAINVIEW_PANES_COLOR_INDEX) }, + { "MENU_BGCOLOR", COLOR2FLAGS(MENU_BGCOLOR_INDEX) }, + { "MENU_COLOR", COLOR2FLAGS(MENU_COLOR_INDEX) }, + { "MENU_HEADER_HEIGHT", COLOR2FLAGS(MENU_HEADER_HEIGHT) }, + { "MENU_HIGHLIGHT_BGCOLOR", COLOR2FLAGS(MENU_HIGHLIGHT_BGCOLOR_INDEX) }, + { "MENU_HIGHLIGHT_COLOR", COLOR2FLAGS(MENU_HIGHLIGHT_COLOR_INDEX) }, + { "MENU_LINE_COLOR", COLOR2FLAGS(MENU_LINE_COLOR_INDEX) }, + //{ "MENU_TITLE_BGCOLOR", COLOR2FLAGS(MENU_TITLE_BGCOLOR) }, + { "OVERLAY_COLOR", COLOR2FLAGS(OVERLAY_COLOR_INDEX) }, + { "SCROLLBAR_COLOR", COLOR2FLAGS(SCROLLBAR_COLOR_INDEX) }, + { "TABLE_BGCOLOR", COLOR2FLAGS(TABLE_BGCOLOR_INDEX) }, + { "TABLE_HEADER_BGCOLOR", COLOR2FLAGS(TABLE_HEADER_BGCOLOR_INDEX) }, + { "TEXT_DISABLE_COLOR", COLOR2FLAGS(TEXT_DISABLE_COLOR_INDEX) }, + { "TEXT_STATUSBAR_COLOR", COLOR2FLAGS(TEXT_STATUSBAR_COLOR_INDEX) }, + { "TITLE_BGCOLOR", COLOR2FLAGS(TITLE_BGCOLOR_INDEX) }, + + // Synonyms of the above colors + { "TEXT_BGCOLOR", COLOR2FLAGS(DEFAULT_BGCOLOR_INDEX) }, + { "WHITE", (double)WHITE }, { "GREY", (double)GREY }, { "DARKGREY", (double)DARKGREY },