From 77382ba406077712a78d8d110c71e8fa82888474 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 12 Feb 2022 22:39:42 +0100 Subject: [PATCH] WiP: remove legacy fonts --- radio/src/thirdparty/libopenui/.gitignore | 1 + .../thirdparty/libopenui/src/CMakeLists.txt | 1 - .../thirdparty/libopenui/src/bitmapbuffer.cpp | 98 +++++++------------ .../thirdparty/libopenui/src/bitmapbuffer.h | 12 ++- .../thirdparty/libopenui/src/coloredit.cpp | 1 - radio/src/thirdparty/libopenui/src/font.h | 4 +- .../libopenui/src/keyboard_number.cpp | 1 - .../libopenui/src/keyboard_text.cpp | 1 - .../thirdparty/libopenui/src/keyboard_text.h | 8 +- .../libopenui/src/libopenui_defines.h | 1 - .../libopenui/src/libopenui_globals.cpp | 21 ---- .../libopenui/src/libopenui_globals.h | 28 ------ radio/src/thirdparty/libopenui/src/roller.h | 1 - .../src/thirdparty/libopenui/src/textedit.cpp | 1 - radio/src/thirdparty/libopenui/src/window.cpp | 2 + 15 files changed, 51 insertions(+), 130 deletions(-) create mode 100644 radio/src/thirdparty/libopenui/.gitignore delete mode 100644 radio/src/thirdparty/libopenui/src/libopenui_globals.cpp delete mode 100644 radio/src/thirdparty/libopenui/src/libopenui_globals.h diff --git a/radio/src/thirdparty/libopenui/.gitignore b/radio/src/thirdparty/libopenui/.gitignore new file mode 100644 index 000000000..e5d594669 --- /dev/null +++ b/radio/src/thirdparty/libopenui/.gitignore @@ -0,0 +1 @@ +src/thirdparty/stb/ diff --git a/radio/src/thirdparty/libopenui/src/CMakeLists.txt b/radio/src/thirdparty/libopenui/src/CMakeLists.txt index 0c812042b..9e9b31f6a 100644 --- a/radio/src/thirdparty/libopenui/src/CMakeLists.txt +++ b/radio/src/thirdparty/libopenui/src/CMakeLists.txt @@ -11,7 +11,6 @@ if(SOFTWARE_KEYBOARD) endif() set(LIBOPENUI_SRC - libopenui_globals.cpp libopenui_file.cpp bitmapbuffer.cpp window.cpp diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index bda7e7f54..a5b0e8810 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -20,7 +20,6 @@ #include #include "bitmapbuffer.h" #include "libopenui_depends.h" -#include "libopenui_globals.h" #include "libopenui_helpers.h" #include "libopenui_file.h" #include "font.h" @@ -1008,21 +1007,13 @@ void BitmapBuffer::drawBitmapPattern(coord_t x, coord_t y, const uint8_t * bmp, srcx, srcy, srcw, srch, COLOR_VAL(flags)); } -uint8_t BitmapBuffer::drawChar(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, unsigned int index, LcdFlags flags) -{ - coord_t offset = spec[index + 1]; - coord_t width = spec[index + 2] - offset; - if (width > 0) { - drawBitmapPattern(x, y, font, flags, offset, width); - } - return width; -} +// TODO: find a better place to define this +extern lv_color_t makeLvColor(uint32_t colorFlags); -#define INCREMENT_POS(delta) do { if (flags & VERTICAL) y -= delta; else x += delta; } while(0) - -coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlags flags) +coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char *s, + uint8_t len, LcdFlags flags) { - if (!s) return (flags & VERTICAL) ? y : x; + if (!s) return x; MOVE_OFFSET(); int height = getFontHeight(flags); @@ -1032,61 +1023,46 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_ return x; } - uint32_t fontindex = FONT_INDEX(flags); - const unsigned char * font = fontsTable[fontindex]; - const uint16_t * fontspecs = fontspecsTable[fontindex]; - - if (flags & (RIGHT | CENTERED)) { - int width = getTextWidth(s, len, flags); - if (flags & RIGHT) { - INCREMENT_POS(-width); - } - else if (flags & CENTERED) { - INCREMENT_POS(-width / 2); - } - } - - coord_t & pos = (flags & VERTICAL) ? y : x; + coord_t pos = x; const coord_t orig_pos = pos; - while (len--) { - unsigned c = uint8_t(*s); - // TRACE("c = %d %o 0x%X '%c'", c, c, c, c); + lv_draw_label_dsc_t label_draw_dsc; + lv_draw_label_dsc_init(&label_draw_dsc); - if (!c) { - break; - } - else if (c >= 0xFE) { - // CJK char - s++; - c = uint8_t(*s) + ((c & 0x01u) << 8u) - 1; - // TRACE("CJK = %d", c); - if (c >= 0x100) - c -= 1; - c += CJK_FIRST_LETTER_INDEX; - uint8_t width = drawChar(x, y, font, fontspecs, c, flags); - INCREMENT_POS(width + CHAR_SPACING); - } - else if ((c >= 0x20u) && (c < fontCharactersTable[FONT_INDEX(flags)] + 0x20u)) { - uint8_t width = drawChar(x, y, font, fontspecs, getMappedChar(c), flags); - if ((flags & SPACING_NUMBERS_CONST) && c >= '0' && c <= '9') - INCREMENT_POS(getCharWidth('9', fontspecs) + CHAR_SPACING); - else - INCREMENT_POS(width + CHAR_SPACING); - } - else if (c == '\n') { - pos = orig_pos; - if (flags & VERTICAL) - x += height; - else - y += height; - } + const lv_font_t* font = getFont(flags); + label_draw_dsc.font = font; + label_draw_dsc.color = makeLvColor(flags); - s++; + x += draw_ctx->buf_area->x1; + y += draw_ctx->buf_area->y1; + + lv_point_t p; + lv_txt_get_size(&p, s, font, label_draw_dsc.letter_space, + label_draw_dsc.line_space, LV_COORD_MAX, 0); + + lv_coord_t lv_x = (lv_coord_t)x; + lv_coord_t lv_y = (lv_coord_t)y; + + lv_area_t coords = { + lv_x, lv_y, lv_x, lv_y, + }; + + coords.x2 += p.x - 1; + coords.y2 += p.y - 1; + + if (flags & RIGHT) { + label_draw_dsc.align = LV_TEXT_ALIGN_RIGHT; + } else if (flags & CENTERED) { + label_draw_dsc.align = LV_TEXT_ALIGN_CENTER; + coords.x1 -= p.x / 2; + coords.x2 -= p.x / 2; } + lv_draw_label(draw_ctx, &label_draw_dsc, &coords, s, nullptr); + RESTORE_OFFSET(); + pos += p.x; return ((flags & RIGHT) ? orig_pos : pos) - offsetX; } diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h index f5ce24548..ee10d5b8a 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h @@ -52,6 +52,9 @@ enum BitmapFormats BMP_ARGB4444 }; +struct _lv_draw_ctx_t; +typedef _lv_draw_ctx_t lv_draw_ctx_t; + template class BitmapBufferBase { @@ -196,6 +199,7 @@ class BitmapBuffer: public BitmapBufferBase #if defined(DEBUG) bool leakReported; #endif + lv_draw_ctx_t* draw_ctx = nullptr; public: BitmapBuffer(uint8_t format, uint16_t width, uint16_t height); @@ -203,6 +207,8 @@ class BitmapBuffer: public BitmapBufferBase ~BitmapBuffer(); + void setDrawCtx(lv_draw_ctx_t* ctx) { draw_ctx = ctx; } + inline void setFormat(uint8_t format) { this->format = format; @@ -313,8 +319,8 @@ class BitmapBuffer: public BitmapBufferBase coord_t drawText(coord_t x, coord_t y, const char * s, LcdFlags flags = 0) { - if (!s) return (flags & VERTICAL) ? y : x; - return drawSizedText(x, y, s, 255, flags); + if (!s) return x; + return drawSizedText(x, y, s, strlen(s), flags); } coord_t drawTextAtIndex(coord_t x, coord_t y, const char * s, uint8_t idx, LcdFlags flags = 0) @@ -384,8 +390,6 @@ class BitmapBuffer: public BitmapBufferBase coord_t srcy = 0, coord_t srcw = 0, coord_t srch = 0, float scale = 0); - uint8_t drawChar(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, unsigned int index, LcdFlags flags); - inline void drawPixel(pixel_t * p, pixel_t value) { if (data && (data <= p || p < data_end)) { diff --git a/radio/src/thirdparty/libopenui/src/coloredit.cpp b/radio/src/thirdparty/libopenui/src/coloredit.cpp index 35b7d6c0e..3c97cfb10 100644 --- a/radio/src/thirdparty/libopenui/src/coloredit.cpp +++ b/radio/src/thirdparty/libopenui/src/coloredit.cpp @@ -18,7 +18,6 @@ */ #include "coloredit.h" -#include "libopenui_globals.h" #include "numberedit.h" #include "bitfield.h" diff --git a/radio/src/thirdparty/libopenui/src/font.h b/radio/src/thirdparty/libopenui/src/font.h index b45bf8150..97e99346e 100644 --- a/radio/src/thirdparty/libopenui/src/font.h +++ b/radio/src/thirdparty/libopenui/src/font.h @@ -19,10 +19,10 @@ #pragma once +#include #include "libopenui_types.h" -uint8_t getMappedChar(uint8_t c); +const lv_font_t* getFont(LcdFlags flags); uint8_t getFontHeight(LcdFlags flags); -int getCharWidth(uint8_t c, const uint16_t * spec); int getTextWidth(const char * s, int len = 0, LcdFlags flags = 0); diff --git a/radio/src/thirdparty/libopenui/src/keyboard_number.cpp b/radio/src/thirdparty/libopenui/src/keyboard_number.cpp index 93b1b0d2e..2a4b5fad9 100644 --- a/radio/src/thirdparty/libopenui/src/keyboard_number.cpp +++ b/radio/src/thirdparty/libopenui/src/keyboard_number.cpp @@ -19,7 +19,6 @@ #include "keyboard_number.h" #include "button.h" -#include "libopenui_globals.h" constexpr coord_t KEYBOARD_HEIGHT = 90; NumberKeyboard * NumberKeyboard::_instance = nullptr; diff --git a/radio/src/thirdparty/libopenui/src/keyboard_text.cpp b/radio/src/thirdparty/libopenui/src/keyboard_text.cpp index 109d0c4a1..a449a6cad 100644 --- a/radio/src/thirdparty/libopenui/src/keyboard_text.cpp +++ b/radio/src/thirdparty/libopenui/src/keyboard_text.cpp @@ -18,7 +18,6 @@ */ #include "keyboard_text.h" -#include "libopenui_globals.h" #include "textedit.h" #include "font.h" diff --git a/radio/src/thirdparty/libopenui/src/keyboard_text.h b/radio/src/thirdparty/libopenui/src/keyboard_text.h index 0e873de86..c4e4e8e50 100644 --- a/radio/src/thirdparty/libopenui/src/keyboard_text.h +++ b/radio/src/thirdparty/libopenui/src/keyboard_text.h @@ -66,12 +66,6 @@ class TextKeyboard : public Keyboard { #endif static TextKeyboard * _instance; - const char * const * layout; - private: - int calculateMaxWidth(); - int getCharWidth(const char c); - - char touch_key = -128; - bool touched = false; + // const char * const * layout; }; diff --git a/radio/src/thirdparty/libopenui/src/libopenui_defines.h b/radio/src/thirdparty/libopenui/src/libopenui_defines.h index b766f035e..94ddacdd5 100644 --- a/radio/src/thirdparty/libopenui/src/libopenui_defines.h +++ b/radio/src/thirdparty/libopenui/src/libopenui_defines.h @@ -35,7 +35,6 @@ #define SHADOWED 0x80u /* black copy at +1 +1 */ // 0x1000u used by Lua in api_colorlcd.h #define SPACING_NUMBERS_CONST 0x2000u -#define VERTICAL 0x4000u // 0x8000u used by Lua in api_colorlcd.h /* drawNumber flags */ diff --git a/radio/src/thirdparty/libopenui/src/libopenui_globals.cpp b/radio/src/thirdparty/libopenui/src/libopenui_globals.cpp deleted file mode 100644 index 3bee77f51..000000000 --- a/radio/src/thirdparty/libopenui/src/libopenui_globals.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) OpenTX - * - * Source: - * https://github.com/opentx/libopenui - * - * This file is a part of libopenui library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - */ - -#include "libopenui_globals.h" - diff --git a/radio/src/thirdparty/libopenui/src/libopenui_globals.h b/radio/src/thirdparty/libopenui/src/libopenui_globals.h deleted file mode 100644 index c1352e747..000000000 --- a/radio/src/thirdparty/libopenui/src/libopenui_globals.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) OpenTX - * - * Source: - * https://github.com/opentx/libopenui - * - * This file is a part of libopenui library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - */ - -#pragma once - -#include -#include "libopenui_config.h" - -extern const uint16_t fontCharactersTable[FONTS_COUNT]; -extern const uint16_t * const fontspecsTable[FONTS_COUNT]; -extern const uint8_t * fontsTable[FONTS_COUNT]; - diff --git a/radio/src/thirdparty/libopenui/src/roller.h b/radio/src/thirdparty/libopenui/src/roller.h index 7135e509a..c9ea66850 100644 --- a/radio/src/thirdparty/libopenui/src/roller.h +++ b/radio/src/thirdparty/libopenui/src/roller.h @@ -24,7 +24,6 @@ #include #include #include -#include "libopenui_globals.h" #include "libopenui_config.h" constexpr WindowFlags ROLLER_SEPARATION_LINES = (FORM_FLAGS_LAST << 1u); diff --git a/radio/src/thirdparty/libopenui/src/textedit.cpp b/radio/src/thirdparty/libopenui/src/textedit.cpp index 9b4f67aaf..50d37ced3 100644 --- a/radio/src/thirdparty/libopenui/src/textedit.cpp +++ b/radio/src/thirdparty/libopenui/src/textedit.cpp @@ -19,7 +19,6 @@ #include "textedit.h" #include "font.h" -#include "libopenui_globals.h" #include "libopenui_config.h" #if !defined(STR_EDIT) diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 19c154972..5d9dd5a62 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -64,6 +64,8 @@ static void window_event_cb(lv_event_t * e) BitmapBuffer buf = {BMP_RGB565, (uint16_t)w, (uint16_t)h, (uint16_t *)draw_ctx->buf}; + buf.setDrawCtx(draw_ctx); + buf.setOffset(obj_coords.x1 - a.x1, obj_coords.y1 - a.y1); buf.setClippingRect(clipping.x1 - a.x1, clipping.x2 + 1 - a.x1, clipping.y1 - a.y1, clipping.y2 + 1 - a.y1);