feat(color): additions to LVGL for Lua scripts (#5179)
This commit is contained in:
+1
-1
@@ -142,7 +142,7 @@ class BitmapBuffer
|
||||
|
||||
void resizeToLVGL(coord_t w, coord_t h);
|
||||
|
||||
uint8_t* to8bitMask(size_t* size) const;
|
||||
MaskBitmap* to8bitMask(size_t* size) const;
|
||||
|
||||
void drawBitmapPattern(coord_t x, coord_t y, const MaskBitmap* bmp,
|
||||
LcdFlags flags, coord_t offset = 0, coord_t width = 0);
|
||||
|
||||
+13
-11
@@ -708,27 +708,29 @@ void BitmapBuffer::drawAnnulusSector(coord_t x, coord_t y,
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t *BitmapBuffer::to8bitMask(size_t *size) const
|
||||
MaskBitmap *BitmapBuffer::to8bitMask(size_t *size) const
|
||||
{
|
||||
static uint8_t grayScale[16] = {255, 238, 221, 204, 187, 170, 153, 136, 119, 102, 85, 68, 51, 34, 17, 0};
|
||||
|
||||
*size = width() * height() + 4;
|
||||
uint8_t *mask = (uint8_t *)malloc(*size);
|
||||
((uint16_t *)mask)[0] = width();
|
||||
((uint16_t *)mask)[1] = height();
|
||||
MaskBitmap *mask = (MaskBitmap*)malloc(*size);
|
||||
mask->width = width();
|
||||
mask->height = height();
|
||||
|
||||
const pixel_t *p = getPixelPtrAbs(0, 0);
|
||||
int ofs = 0;
|
||||
if (getFormat() == BMP_ARGB4444) {
|
||||
auto ofs = 4u;
|
||||
for (int i = width() * height(); i > 0; i--) {
|
||||
ARGB_SPLIT(*p, a __attribute__((unused)), r, g, b);
|
||||
auto v = ((uint32_t)r + (uint32_t)g + (uint32_t)b) / 3;
|
||||
mask[ofs++] = ((OPACITY_MAX - v) << 4);
|
||||
int v = (r + g + b) / 3;
|
||||
mask->data[ofs++] = grayScale[v];
|
||||
MOVE_TO_NEXT_RIGHT_PIXEL(p);
|
||||
}
|
||||
} else { // BMP_RGB565
|
||||
auto ofs = 4u;
|
||||
for (int i = width() * height(); i > 0; i--) {
|
||||
auto v =
|
||||
((GET_RED(*p) >> 1) + (GET_GREEN(*p) >> 2) + (GET_BLUE(*p) >> 1)) / 3;
|
||||
mask[ofs++] = ((OPACITY_MAX - v) << 4);
|
||||
RGB_SPLIT(*p, r, g, b);
|
||||
int v = ((r + (g >> 1) + b) / 3) >> 1;
|
||||
mask->data[ofs++] = grayScale[v];
|
||||
MOVE_TO_NEXT_RIGHT_PIXEL(p);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ static void btnmatrix_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
|
||||
etx_std_style(obj, LV_PART_ITEMS, PAD_LARGE);
|
||||
|
||||
etx_obj_add_style(obj, styles->border_color_focus,
|
||||
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_FOCUS_INDEX],
|
||||
LV_PART_ITEMS | LV_STATE_EDITED);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,9 +20,9 @@
|
||||
|
||||
#include "debug.h"
|
||||
#include "hal.h"
|
||||
#include "opentx_types.h"
|
||||
#include "colors.h"
|
||||
#include "keys.h"
|
||||
#include "opentx_types.h"
|
||||
|
||||
// Used by Lua API
|
||||
#define INVERS 0x01u
|
||||
|
||||
+2
-2
@@ -45,8 +45,8 @@ static void slider_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
|
||||
etx_obj_add_style(obj, styles->bg_opacity_cover, LV_PART_KNOB);
|
||||
etx_obj_add_style(obj, slider_knob, LV_PART_KNOB);
|
||||
etx_obj_add_style(obj, styles->border_color_dark, LV_PART_KNOB);
|
||||
etx_obj_add_style(obj, styles->border_color_focus,
|
||||
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_SECONDARY1_INDEX], LV_PART_MAIN);
|
||||
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_FOCUS_INDEX],
|
||||
LV_PART_KNOB | LV_STATE_FOCUSED);
|
||||
}
|
||||
|
||||
|
||||
+41
@@ -157,6 +157,37 @@ StaticIcon::StaticIcon(Window* parent, coord_t x, coord_t y, EdgeTxIcon icon,
|
||||
etx_img_color(lvobj, currentColor, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
StaticIcon::StaticIcon(Window* parent, coord_t x, coord_t y, const char* filename,
|
||||
LcdFlags color) :
|
||||
Window(parent, rect_t{x, y, 0, 0}, lv_canvas_create),
|
||||
currentColor(indexFromColor(color))
|
||||
{
|
||||
setWindowFlag(NO_FOCUS);
|
||||
|
||||
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
||||
auto bm = BitmapBuffer::loadBitmap(filename, BMP_RGB565);
|
||||
if (bm) {
|
||||
size_t size;
|
||||
mask = bm->to8bitMask(&size);
|
||||
if (mask) {
|
||||
setSize(mask->width, mask->height);
|
||||
lv_canvas_set_buffer(lvobj, (void*)mask->data, mask->width, mask->height,
|
||||
LV_IMG_CF_ALPHA_8BIT);
|
||||
}
|
||||
delete bm;
|
||||
}
|
||||
|
||||
etx_img_color(lvobj, currentColor, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
void StaticIcon::deleteLater(bool detach, bool trash)
|
||||
{
|
||||
if (_deleted) return;
|
||||
if (mask) free(mask);
|
||||
mask = nullptr;
|
||||
}
|
||||
|
||||
void StaticIcon::setColor(LcdColorIndex color)
|
||||
{
|
||||
if (currentColor != color) {
|
||||
@@ -325,3 +356,13 @@ void StaticLZ4Image::deleteLater(bool detach, bool trash)
|
||||
Window::deleteLater(detach, trash);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
QRCode::QRCode(Window *parent, coord_t x, coord_t y, coord_t sz, std::string data,
|
||||
LcdFlags color, LcdFlags bgColor) :
|
||||
Window(parent, {x, y, sz, sz})
|
||||
{
|
||||
auto qr = lv_qrcode_create(lvobj, sz, makeLvColor(color), makeLvColor(bgColor));
|
||||
lv_qrcode_update(qr, data.c_str(), data.length());
|
||||
}
|
||||
|
||||
+24
@@ -123,6 +123,10 @@ class StaticIcon : public Window
|
||||
public:
|
||||
StaticIcon(Window *parent, coord_t x, coord_t y, EdgeTxIcon icon,
|
||||
LcdFlags color);
|
||||
StaticIcon(Window *parent, coord_t x, coord_t y, const char* filename,
|
||||
LcdFlags color);
|
||||
|
||||
void deleteLater(bool detach = true, bool trash = true) override;
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "StaticIcon"; }
|
||||
@@ -134,6 +138,7 @@ class StaticIcon : public Window
|
||||
|
||||
protected:
|
||||
LcdColorIndex currentColor;
|
||||
MaskBitmap* mask = nullptr;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -159,6 +164,8 @@ class StaticImage : public Window
|
||||
lv_obj_t *image = nullptr;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class StaticBitmap : public Window
|
||||
{
|
||||
public:
|
||||
@@ -178,6 +185,8 @@ class StaticBitmap : public Window
|
||||
BitmapBuffer *img = nullptr;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class StaticLZ4Image : public Window
|
||||
{
|
||||
public:
|
||||
@@ -193,3 +202,18 @@ class StaticLZ4Image : public Window
|
||||
|
||||
void deleteLater(bool detach, bool trash) override;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class QRCode : public Window
|
||||
{
|
||||
public:
|
||||
QRCode(Window *parent, coord_t x, coord_t y, coord_t sz, std::string data,
|
||||
LcdFlags color = COLOR_THEME_SECONDARY1, LcdFlags bgColor = COLOR_THEME_SECONDARY3);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "QRCode"; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ static void table_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
|
||||
etx_solid_bg(obj, COLOR_THEME_PRIMARY2_INDEX, LV_PART_ITEMS);
|
||||
etx_txt_color(obj, COLOR_THEME_PRIMARY1_INDEX, LV_PART_ITEMS);
|
||||
etx_obj_add_style(obj, table_cell, LV_PART_ITEMS);
|
||||
etx_obj_add_style(obj, styles->border_color_normal, LV_PART_ITEMS);
|
||||
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_SECONDARY2_INDEX], LV_PART_ITEMS);
|
||||
|
||||
etx_bg_color(obj, COLOR_THEME_FOCUS_INDEX, LV_PART_ITEMS | LV_STATE_EDITED);
|
||||
etx_txt_color(obj, COLOR_THEME_PRIMARY2_INDEX, LV_PART_ITEMS | LV_STATE_EDITED);
|
||||
|
||||
Reference in New Issue
Block a user