From f1be9157ae754d0f2c7f009e8720431be855a88f Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Fri, 23 Apr 2021 18:55:34 +0200 Subject: [PATCH] Move away from color table for low level ops --- radio/src/gui/colorlcd/colors.cpp | 23 ++++++ radio/src/gui/colorlcd/colors.h | 83 +++++++++++++++++++++- radio/src/lua/api_colorlcd.cpp | 31 +++++--- radio/src/lua/api_general.cpp | 34 ++++----- radio/src/targets/horus/libopenui_config.h | 75 +++++-------------- radio/src/tests/lcd_480x272.cpp | 34 ++++----- radio/src/thirdparty/libopenui | 2 +- 7 files changed, 179 insertions(+), 103 deletions(-) create mode 100644 radio/src/gui/colorlcd/colors.cpp diff --git a/radio/src/gui/colorlcd/colors.cpp b/radio/src/gui/colorlcd/colors.cpp new file mode 100644 index 000000000..301cc9063 --- /dev/null +++ b/radio/src/gui/colorlcd/colors.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "colors.h" + + diff --git a/radio/src/gui/colorlcd/colors.h b/radio/src/gui/colorlcd/colors.h index eaf1dd473..e50a06bb2 100644 --- a/radio/src/gui/colorlcd/colors.h +++ b/radio/src/gui/colorlcd/colors.h @@ -21,8 +21,58 @@ #ifndef _COLORS_H_ #define _COLORS_H_ -#include "libopenui_config.h" +#include "libopenui_defines.h" + +// TODO common code, not in target +enum LcdColorIndex +{ + DEFAULT_COLOR_INDEX, + DEFAULT_BGCOLOR_INDEX, + FOCUS_COLOR_INDEX, + FOCUS_BGCOLOR_INDEX, + TEXT_STATUSBAR_COLOR_INDEX, + LINE_COLOR_INDEX, + MENU_LINE_COLOR_INDEX = LINE_COLOR_INDEX, + CHECKBOX_COLOR_INDEX, + SCROLLBAR_COLOR_INDEX, + MENU_BGCOLOR_INDEX, + MENU_HIGHLIGHT_BGCOLOR_INDEX = MENU_BGCOLOR_INDEX, + MENU_COLOR_INDEX, + MENU_TITLE_DISABLE_COLOR_INDEX, + HEADER_COLOR_INDEX, + ALARM_COLOR_INDEX, + HIGHLIGHT_COLOR_INDEX, + MENU_HIGHLIGHT_COLOR_INDEX = HIGHLIGHT_COLOR_INDEX, + TEXT_DISABLE_COLOR_INDEX, + DISABLE_COLOR_INDEX, + CURVE_COLOR_INDEX, + CURVE_AXIS_COLOR_INDEX, + CURVE_CURSOR_COLOR_INDEX, + HEADER_BGCOLOR_INDEX, + HEADER_ICON_BGCOLOR_INDEX, + HEADER_CURRENT_BGCOLOR_INDEX, + TITLE_BGCOLOR_INDEX, + TRIM_BGCOLOR_INDEX, + TRIM_SHADOW_COLOR_INDEX, + MAINVIEW_PANES_COLOR_INDEX, + MAINVIEW_GRAPHICS_COLOR_INDEX, + OVERLAY_COLOR_INDEX, + CUSTOM_COLOR_INDEX, + BARGRAPH1_COLOR_INDEX, + BARGRAPH2_COLOR_INDEX, + BARGRAPH_BGCOLOR_INDEX, + SCROLLBOX_COLOR_INDEX, + TABLE_HEADER_BGCOLOR_INDEX, + TABLE_BGCOLOR_INDEX, + + // this one MUST be last + LCD_COLOR_COUNT, +}; + +// +// Basic color definitions +// #define WHITE RGB(0xFF, 0xFF, 0xFF) #define LIGHTWHITE RGB(238, 234, 238) #define BLACK RGB(0, 0, 0) @@ -40,6 +90,37 @@ #define BRIGHTGREEN RGB(0, 180, 60) #define ORANGE RGB(229, 100, 30) +// +// Indexed colors +// +extern uint16_t lcdColorTable[LCD_COLOR_COUNT]; + +inline void lcdSetColor(uint16_t color) +{ + lcdColorTable[CUSTOM_COLOR_INDEX] = 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) diff --git a/radio/src/lua/api_colorlcd.cpp b/radio/src/lua/api_colorlcd.cpp index bbef3cbf3..f52eaf95f 100644 --- a/radio/src/lua/api_colorlcd.cpp +++ b/radio/src/lua/api_colorlcd.cpp @@ -75,6 +75,7 @@ static int luaLcdResetBacklightTimeout(lua_State * L) { if (!luaLcdAllowed) return 0; + resetBacklightTimeout(); return 0; } @@ -104,7 +105,9 @@ static int luaLcdDrawPoint(lua_State *L) int x = luaL_checkinteger(L, 1); int y = luaL_checkinteger(L, 2); LcdFlags att = luaL_optunsigned(L, 3, 0); - luaLcdBuffer->drawPixel(x, y, lcdColorTable[COLOR_IDX(att)]); + + // here another definition should be used + luaLcdBuffer->drawPixel(x, y, COLOR(att)); return 0; } @@ -144,16 +147,20 @@ static int luaLcdDrawLine(lua_State *L) if (pat == SOLID) { if (x1 == x2) { - luaLcdBuffer->drawSolidVerticalLine(x1, y1drawSolidVerticalLine(x1, y1drawSolidHorizontalLine(x1drawSolidHorizontalLine(x1drawLine(x1, y1, x2, y2, pat, flags); + luaLcdBuffer->drawLine(x1, y1, x2, y2, pat, COLOR2FLAGS(COLOR(flags))); return 0; } @@ -192,9 +199,9 @@ static int luaLcdDrawText(lua_State *L) unsigned int att = luaL_optunsigned(L, 4, 0); if ((att&SHADOWED) && !(att&INVERS)) { - luaLcdBuffer->drawText(x+1, y+1, s, att&0xFFFF); + luaLcdBuffer->drawText(x+1, y+1, s, att & 0xFFFF); } - luaLcdBuffer->drawText(x, y, s, att); + luaLcdBuffer->drawText(x, y, s, (att & 0xFFFF) | (COLOR2FLAGS(COLOR(att)))); return 0; } @@ -265,9 +272,9 @@ static int luaLcdDrawNumber(lua_State *L) unsigned int att = luaL_optunsigned(L, 4, 0); if ((att&SHADOWED) && !(att&INVERS)) { - luaLcdBuffer->drawNumber(x, y, val, att&0xFFFF); + luaLcdBuffer->drawNumber(x, y, val, att & 0xFFFF); } - luaLcdBuffer->drawNumber(x, y, val, att); + luaLcdBuffer->drawNumber(x, y, val, (att & 0xFFFF) | COLOR2FLAGS(COLOR(att))); return 0; } @@ -555,7 +562,9 @@ static int luaLcdDrawRectangle(lua_State *L) unsigned int flags = luaL_optunsigned(L, 5, 0); unsigned int t = luaL_optunsigned(L, 6, 1); - luaLcdBuffer->drawRect(x, y, w, h, t, 0xff, flags); + luaLcdBuffer->drawRect(x, y, w, h, t, SOLID, + COLOR2FLAGS(COLOR(flags)) | (flags & 0xFFFF), + flags >> 24); return 0; } @@ -586,7 +595,9 @@ 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, flags); + luaLcdBuffer->drawFilledRect(x, y, w, h, SOLID, + COLOR2FLAGS(COLOR(flags)) | (flags & 0xFFFF), + flags >> 24); return 0; } diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 3ee8db86a..dc682ecc3 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -1845,24 +1845,24 @@ const luaR_value_entry opentxConstants[] = { { "COLOR", ZoneOption::Color }, { "BOOL", ZoneOption::Bool }, { "STRING", ZoneOption::String }, - { "DEFAULT_COLOR", DEFAULT_COLOR }, - { "DEFAULT_BGCOLOR", DEFAULT_BGCOLOR }, - { "FOCUS_COLOR", FOCUS_COLOR }, - { "FOCUS_BGCOLOR", FOCUS_BGCOLOR }, - { "DISABLE_COLOR", DISABLE_COLOR }, - { "HIGHLIGHT_COLOR", HIGHLIGHT_COLOR }, - { "CHECKBOX_COLOR", CHECKBOX_COLOR }, - { "SCROLLBAR_COLOR", SCROLLBAR_COLOR }, - { "MENU_COLOR", MENU_COLOR }, - { "MENU_BGCOLOR", MENU_BGCOLOR }, + { "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 }, - { "MENU_HIGHLIGHT_COLOR", MENU_HIGHLIGHT_COLOR }, - { "MENU_HIGHLIGHT_BGCOLOR", MENU_HIGHLIGHT_BGCOLOR }, - { "OVERLAY_COLOR", OVERLAY_COLOR }, - { "TABLE_BGCOLOR", TABLE_BGCOLOR }, - { "TABLE_HEADER_BGCOLOR", TABLE_HEADER_BGCOLOR }, - { "CUSTOM_COLOR", CUSTOM_COLOR }, + { "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 }, { "WHITE", (double)WHITE }, { "GREY", (double)GREY }, diff --git a/radio/src/targets/horus/libopenui_config.h b/radio/src/targets/horus/libopenui_config.h index 77168ca71..87c7e8f23 100644 --- a/radio/src/targets/horus/libopenui_config.h +++ b/radio/src/targets/horus/libopenui_config.h @@ -22,10 +22,27 @@ #include "debug.h" #include "libopenui_defines.h" + #include "colors.h" #include "board.h" #include "keys.h" +enum FontIndex +{ + FONT_STD_INDEX, +#if !defined(BOLD) + FONT_BOLD_INDEX, + FONT_XXS_INDEX, + FONT_XS_INDEX, + FONT_L_INDEX, + FONT_XL_INDEX, + FONT_XXL_INDEX, +#endif + + // this one MUST be last + FONTS_COUNT +}; + typedef uint16_t pixel_t; constexpr bool WRAP_FORM_FIELDS_WITHIN_PAGE = true; @@ -86,64 +103,6 @@ constexpr uint32_t ALERT_BUTTON_TOP = 300; constexpr uint32_t PAGE_TITLE_TOP = 2; constexpr uint32_t PAGE_TITLE_LEFT = 50; -// TODO common code, not in target -enum LcdColorIndex -{ - DEFAULT_COLOR_INDEX, - DEFAULT_BGCOLOR_INDEX, - FOCUS_COLOR_INDEX, - FOCUS_BGCOLOR_INDEX, - TEXT_STATUSBAR_COLOR_INDEX, - LINE_COLOR_INDEX, - MENU_LINE_COLOR_INDEX = LINE_COLOR_INDEX, - CHECKBOX_COLOR_INDEX, - SCROLLBAR_COLOR_INDEX, - MENU_BGCOLOR_INDEX, - MENU_HIGHLIGHT_BGCOLOR_INDEX = MENU_BGCOLOR_INDEX, - MENU_COLOR_INDEX, - MENU_TITLE_DISABLE_COLOR_INDEX, - HEADER_COLOR_INDEX, - ALARM_COLOR_INDEX, - HIGHLIGHT_COLOR_INDEX, - MENU_HIGHLIGHT_COLOR_INDEX = HIGHLIGHT_COLOR_INDEX, - TEXT_DISABLE_COLOR_INDEX, - DISABLE_COLOR_INDEX, - CURVE_COLOR_INDEX, - CURVE_AXIS_COLOR_INDEX, - CURVE_CURSOR_COLOR_INDEX, - HEADER_BGCOLOR_INDEX, - HEADER_ICON_BGCOLOR_INDEX, - HEADER_CURRENT_BGCOLOR_INDEX, - TITLE_BGCOLOR_INDEX, - TRIM_BGCOLOR_INDEX, - TRIM_SHADOW_COLOR_INDEX, - MAINVIEW_PANES_COLOR_INDEX, - MAINVIEW_GRAPHICS_COLOR_INDEX, - OVERLAY_COLOR_INDEX, - CUSTOM_COLOR_INDEX, - BARGRAPH1_COLOR_INDEX, - BARGRAPH2_COLOR_INDEX, - BARGRAPH_BGCOLOR_INDEX, - SCROLLBOX_COLOR_INDEX, - LCD_COLOR_COUNT, - - TABLE_HEADER_BGCOLOR_INDEX, - TABLE_BGCOLOR_INDEX, -}; - -enum FontIndex -{ - FONT_STD_INDEX, -#if !defined(BOLD) - FONT_BOLD_INDEX, - FONT_XXS_INDEX, - FONT_XS_INDEX, - FONT_L_INDEX, - FONT_XL_INDEX, - FONT_XXL_INDEX, -#endif - FONTS_COUNT -}; constexpr uint32_t INPUT_EDIT_LABELS_WIDTH = 120; constexpr coord_t INPUT_EDIT_CURVE_WIDTH = 158; diff --git a/radio/src/tests/lcd_480x272.cpp b/radio/src/tests/lcd_480x272.cpp index 33c1c7f71..6e00481a6 100644 --- a/radio/src/tests/lcd_480x272.cpp +++ b/radio/src/tests/lcd_480x272.cpp @@ -141,25 +141,27 @@ TEST(Lcd_colorlcd, transparency) BitmapBuffer dc(BMP_RGB565, LCD_W, LCD_H); dc.clear(DEFAULT_BGCOLOR); - dc.drawText(8, 8, "The quick brown fox jumps over the lazy dog", DEFAULT_COLOR|OPACITY(4)); - dc.drawText(5, 5, "The quick brown fox jumps over the lazy dog", DEFAULT_COLOR|OPACITY(12)); + // , OPACITY(4) + dc.drawText(8, 8, "The quick brown fox jumps over the lazy dog", DEFAULT_COLOR); + // , OPACITY(12) + dc.drawText(5, 5, "The quick brown fox jumps over the lazy dog", DEFAULT_COLOR); - dc.drawFilledRect(10, 30, 30, 30, SOLID, TITLE_BGCOLOR|OPACITY(8)); - dc.drawFilledRect(50, 30, 30, 30, DOTTED, DEFAULT_COLOR|OPACITY(10)); + dc.drawFilledRect(10, 30, 30, 30, SOLID, TITLE_BGCOLOR, OPACITY(8)); + dc.drawFilledRect(50, 30, 30, 30, DOTTED, DEFAULT_COLOR, OPACITY(10)); - dc.drawRect(90, 30, 30, 30, 1, SOLID, TITLE_BGCOLOR|OPACITY(8)); - dc.drawRect(130, 30, 30, 30, 2, SOLID, TITLE_BGCOLOR|OPACITY(8)); - dc.drawRect(170, 30, 30, 30, 5, SOLID, TITLE_BGCOLOR|OPACITY(8)); + dc.drawRect(90, 30, 30, 30, 1, SOLID, TITLE_BGCOLOR, OPACITY(8)); + dc.drawRect(130, 30, 30, 30, 2, SOLID, TITLE_BGCOLOR, OPACITY(8)); + dc.drawRect(170, 30, 30, 30, 5, SOLID, TITLE_BGCOLOR, OPACITY(8)); - dc.drawVerticalLine(10, 70, 100, SOLID, TITLE_BGCOLOR|OPACITY(2)); - dc.drawVerticalLine(15, 70, 90, SOLID, TITLE_BGCOLOR|OPACITY(6)); - dc.drawVerticalLine(20, 70, 80, SOLID, TITLE_BGCOLOR|OPACITY(10)); - dc.drawVerticalLine(25, 70, 70, SOLID, TITLE_BGCOLOR|OPACITY(OPACITY_MAX)); + dc.drawVerticalLine(10, 70, 100, SOLID, TITLE_BGCOLOR, OPACITY(2)); + dc.drawVerticalLine(15, 70, 90, SOLID, TITLE_BGCOLOR, OPACITY(6)); + dc.drawVerticalLine(20, 70, 80, SOLID, TITLE_BGCOLOR, OPACITY(10)); + dc.drawVerticalLine(25, 70, 70, SOLID, TITLE_BGCOLOR, OPACITY(OPACITY_MAX)); - dc.drawHorizontalLine(30, 70, 100, SOLID, DEFAULT_COLOR|OPACITY(2)); - dc.drawHorizontalLine(30, 75, 90, SOLID, DEFAULT_COLOR|OPACITY(6)); - dc.drawHorizontalLine(30, 80, 80, SOLID, DEFAULT_COLOR|OPACITY(10)); - dc.drawHorizontalLine(30, 85, 70, SOLID, DEFAULT_COLOR|OPACITY(OPACITY_MAX)); + dc.drawHorizontalLine(30, 70, 100, SOLID, DEFAULT_COLOR, OPACITY(2)); + dc.drawHorizontalLine(30, 75, 90, SOLID, DEFAULT_COLOR, OPACITY(6)); + dc.drawHorizontalLine(30, 80, 80, SOLID, DEFAULT_COLOR, OPACITY(10)); + dc.drawHorizontalLine(30, 85, 70, SOLID, DEFAULT_COLOR, OPACITY(OPACITY_MAX)); for(int n=0; n<10; n++) { @@ -167,7 +169,7 @@ TEST(Lcd_colorlcd, transparency) int y = 80 + n * 10; int color = COLOR(n/2 + 5); int size = 100; - dc.drawFilledRect(x, y, size, size, SOLID, color|OPACITY(8)); + dc.drawFilledRect(x, y, size, size, SOLID, color, OPACITY(8)); } diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index 51d495cc8..dcea85ab5 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit 51d495cc88b9d9e0268b748dd8e46a5143b60d2e +Subproject commit dcea85ab5ec561aed63b5b6da3eb8e66e301e209