Merge pull request #192 from yaapu/pr/colorlcd_invers_offset

colorlcd: fix for drawNumber INVERS and text per font size h/v offsets
This commit is contained in:
Raphael Coeffic
2021-06-12 21:39:24 +02:00
committed by GitHub
2 changed files with 53 additions and 2 deletions
+48
View File
@@ -28,6 +28,28 @@
BitmapBuffer* luaLcdBuffer = nullptr; BitmapBuffer* luaLcdBuffer = nullptr;
static int8_t getTextHorizontalOffset(LcdFlags flags)
{
// no need to adjust if not right aligned
if (!(flags & RIGHT)) {
return 0;
}
const uint8_t font_index = FONT_INDEX(flags);
if (font_index >= sizeof(text_horizontal_offset)) {
return 0;
}
return text_horizontal_offset[font_index];
}
static int8_t getTextVerticalOffset(LcdFlags flags)
{
const uint8_t font_index = FONT_INDEX(flags);
if (font_index >= sizeof(text_vertical_offset)) {
return 0;
}
return text_vertical_offset[font_index];
}
/*luadoc /*luadoc
@function lcd.refresh() @function lcd.refresh()
@@ -202,6 +224,10 @@ static int luaLcdDrawText(lua_State *L)
const char * s = luaL_checkstring(L, 3); const char * s = luaL_checkstring(L, 3);
unsigned int att = luaL_optunsigned(L, 4, 0); unsigned int att = luaL_optunsigned(L, 4, 0);
// apply text offsets, needed to align 2.4.x to 2.3.x font baselines
x += getTextHorizontalOffset(att);
y += getTextVerticalOffset(att);
bool shadowed = att & SHADOWED; bool shadowed = att & SHADOWED;
bool invers = (att & INVERS); bool invers = (att & INVERS);
if (att & BLINK) invers = invers && !(BLINK_ON_PHASE); if (att & BLINK) invers = invers && !(BLINK_ON_PHASE);
@@ -256,6 +282,10 @@ static int luaLcdDrawTimer(lua_State *L)
int seconds = luaL_checkinteger(L, 3); int seconds = luaL_checkinteger(L, 3);
unsigned int att = luaL_optunsigned(L, 4, 0); unsigned int att = luaL_optunsigned(L, 4, 0);
// apply text offsets, needed to align 2.4.x to 2.3.x font baselines
x += getTextHorizontalOffset(att);
y += getTextVerticalOffset(att);
bool shadowed = att & SHADOWED; bool shadowed = att & SHADOWED;
att = (att & 0xFFFF) | COLOR(COLOR_VAL(att)); att = (att & 0xFFFF) | COLOR(COLOR_VAL(att));
@@ -295,8 +325,26 @@ static int luaLcdDrawNumber(lua_State *L)
int val = luaL_checkinteger(L, 3); int val = luaL_checkinteger(L, 3);
unsigned int att = luaL_optunsigned(L, 4, 0); unsigned int att = luaL_optunsigned(L, 4, 0);
bool invers = (att & INVERS);
att = (att & 0xFFFF) | COLOR(COLOR_VAL(att)); att = (att & 0xFFFF) | COLOR(COLOR_VAL(att));
// apply text offsets, needed to align 2.4.x to 2.3.x font baselines
x += getTextHorizontalOffset(att);
y += getTextVerticalOffset(att);
char s[49];
BitmapBuffer::formatNumberAsString(s, 49, val, att & 0xFFFF);
if (invers) {
int height = getFontHeight(att & 0xFFFF);
int width = getTextWidth(s, 255, att);
luaLcdBuffer->drawSolidFilledRect(
x - INVERT_BOX_MARGIN, y - INVERT_BOX_MARGIN,
width + 2 * INVERT_BOX_MARGIN, height + 2 * INVERT_BOX_MARGIN,
FOCUS_BGCOLOR);
att = (att & 0xFFFF) | FOCUS_COLOR;
}
if ((att & SHADOWED) && !(att & INVERS)) { if ((att & SHADOWED) && !(att & INVERS)) {
luaLcdBuffer->drawNumber(x, y, val, att & 0xFFFF); luaLcdBuffer->drawNumber(x, y, val, att & 0xFFFF);
} }
+3
View File
@@ -33,5 +33,8 @@
constexpr coord_t INVERT_BOX_MARGIN = 2; constexpr coord_t INVERT_BOX_MARGIN = 2;
constexpr int8_t text_horizontal_offset[7] {-2,-2,-2,-2,-2,-2,-2};
constexpr int8_t text_vertical_offset[7] {2,0,0,2,3,3,7};
extern bool luaLcdAllowed; extern bool luaLcdAllowed;
extern BitmapBuffer * luaLcdBuffer; extern BitmapBuffer * luaLcdBuffer;