WiP: remove legacy fonts

This commit is contained in:
Raphael Coeffic
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent 6376f8295a
commit 77382ba406
15 changed files with 51 additions and 130 deletions
@@ -0,0 +1 @@
src/thirdparty/stb/
-1
View File
@@ -11,7 +11,6 @@ if(SOFTWARE_KEYBOARD)
endif()
set(LIBOPENUI_SRC
libopenui_globals.cpp
libopenui_file.cpp
bitmapbuffer.cpp
window.cpp
+37 -61
View File
@@ -20,7 +20,6 @@
#include <math.h>
#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;
}
+8 -4
View File
@@ -52,6 +52,9 @@ enum BitmapFormats
BMP_ARGB4444
};
struct _lv_draw_ctx_t;
typedef _lv_draw_ctx_t lv_draw_ctx_t;
template<class T>
class BitmapBufferBase
{
@@ -196,6 +199,7 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
#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<pixel_t>
~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<pixel_t>
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<pixel_t>
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)) {
-1
View File
@@ -18,7 +18,6 @@
*/
#include "coloredit.h"
#include "libopenui_globals.h"
#include "numberedit.h"
#include "bitfield.h"
+2 -2
View File
@@ -19,10 +19,10 @@
#pragma once
#include <lvgl/lvgl.h>
#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);
@@ -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;
-1
View File
@@ -18,7 +18,6 @@
*/
#include "keyboard_text.h"
#include "libopenui_globals.h"
#include "textedit.h"
#include "font.h"
+1 -7
View File
@@ -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;
};
@@ -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 */
@@ -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"
-28
View File
@@ -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 <inttypes.h>
#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];
-1
View File
@@ -24,7 +24,6 @@
#include <font.h>
#include <static.h>
#include <limits.h>
#include "libopenui_globals.h"
#include "libopenui_config.h"
constexpr WindowFlags ROLLER_SEPARATION_LINES = (FORM_FLAGS_LAST << 1u);
-1
View File
@@ -19,7 +19,6 @@
#include "textedit.h"
#include "font.h"
#include "libopenui_globals.h"
#include "libopenui_config.h"
#if !defined(STR_EDIT)
+2
View File
@@ -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);