Skip to content

Commit

Permalink
chore!(color): remove font offsets for Lua 'lcd' text drawing (#5671)
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored Nov 24, 2024
1 parent 4b86285 commit 4bea3af
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions radio/src/lua/api_colorlcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,9 @@

#define BITMAP_METATABLE "BITMAP*"

constexpr coord_t INVERT_BOX_MARGIN = 2;
constexpr int8_t text_horizontal_offset[7] = {-2,-1,-2,-2,-2,-2,-2};
constexpr int8_t text_vertical_offset[7] = {0,0,0,0,0,-1,7};

BitmapBuffer* luaLcdBuffer = nullptr;
LuaWidget *runningFS = 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 0;//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;
}
int vcenter = 0;
if (flags & VCENTERED)
vcenter = 0.5 * getFontHeight(flags & 0xFFFF);
return text_vertical_offset[font_index] - vcenter;
}

/*luadoc
@function lcd.refresh()
Expand Down Expand Up @@ -210,10 +181,6 @@ static void drawString(lua_State *L, const char * s, LcdFlags flags)
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);

// apply text offsets, needed to align 2.4.x to 2.3.x font baselines
x += getTextHorizontalOffset(flags);
y += getTextVerticalOffset(flags);

bool invers = flags & INVERS;
if (flags & BLINK)
invers = invers && !BLINK_ON_PHASE;
Expand All @@ -230,6 +197,7 @@ static void drawString(lua_State *L, const char * s, LcdFlags flags)
flags = (flags & 0xFFFF) | invColor;

// Draw color box
constexpr coord_t INVERT_BOX_MARGIN = 2;
int height = getFontHeight(flags & 0xFFFF) + 2 * INVERT_BOX_MARGIN;
int width = getTextWidth(s, 0, flags);
int ix = x - INVERT_BOX_MARGIN;
Expand Down Expand Up @@ -291,7 +259,7 @@ static int luaLcdSizeText(lua_State *L)
const char * s = luaL_checkstring(L, 1);
LcdFlags flags = luaL_optunsigned(L, 2, 0);
lua_pushinteger(L, getTextWidth(s, 0, flags));
lua_pushinteger(L, getFontHeight(flags & 0xFFFF) + getTextVerticalOffset(flags & ~VCENTERED));
lua_pushinteger(L, getFontHeight(flags & 0xFFFF));
return 2;
}

Expand Down

0 comments on commit 4bea3af

Please sign in to comment.