Skip to content

Commit 890c595

Browse files
author
ethanblazkowicz
committed
1. Fixed l_DrawStringCursorIndex to behave correctly with DPI scaling.
2. Fixed bugs with l_DrawStringWidth and l_SetCursorPos
1 parent c44e58e commit 890c595

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ui_api.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ static int l_DrawStringWidth(lua_State* L)
10931093
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
10941094
lua_pushinteger(L, ui->renderer->DrawStringWidth((int)lua_tointeger(L, 1) * dpiScale,
10951095
luaL_checkoption(L, 2, "FIXED", fontMap),
1096-
lua_tostring(L, 3)) / dpiScale);
1096+
lua_tostring(L, 3)));
10971097
return 1;
10981098
}
10991099

@@ -1102,14 +1102,18 @@ static int l_DrawStringCursorIndex(lua_State* L)
11021102
ui_main_c* ui = GetUIPtr(L);
11031103
ui->LAssert(L, ui->renderer != NULL, "Renderer is not initialised");
11041104
int n = lua_gettop(L);
1105+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
11051106
ui->LAssert(L, n >= 5, "Usage: DrawStringCursorIndex(height, font, text, cursorX, cursorY)");
11061107
ui->LAssert(L, lua_isnumber(L, 1), "DrawStringCursorIndex() argument 1: expected number, got %s", luaL_typename(L, 1));
11071108
ui->LAssert(L, lua_isstring(L, 2), "DrawStringCursorIndex() argument 2: expected string, got %s", luaL_typename(L, 2));
11081109
ui->LAssert(L, lua_isstring(L, 3), "DrawStringCursorIndex() argument 3: expected string, got %s", luaL_typename(L, 3));
11091110
ui->LAssert(L, lua_isnumber(L, 4), "DrawStringCursorIndex() argument 4: expected number, got %s", luaL_typename(L, 4));
11101111
ui->LAssert(L, lua_isnumber(L, 5), "DrawStringCursorIndex() argument 5: expected number, got %s", luaL_typename(L, 5));
11111112
static const char* fontMap[4] = { "FIXED", "VAR", "VAR BOLD", NULL };
1112-
lua_pushinteger(L, ui->renderer->DrawStringCursorIndex((int)lua_tointeger(L, 1), luaL_checkoption(L, 2, "FIXED", fontMap), lua_tostring(L, 3), (int)lua_tointeger(L, 4), (int)lua_tointeger(L, 5)) + 1);
1113+
lua_pushinteger(L, ui->renderer->DrawStringCursorIndex((int)lua_tointeger(L, 1) * dpiScale,
1114+
luaL_checkoption(L, 2, "FIXED", fontMap),
1115+
lua_tostring(L, 3),
1116+
(int)lua_tointeger(L, 4) * dpiScale, (int)lua_tointeger(L, 5) * dpiScale) + 1);
11131117
return 1;
11141118
}
11151119

@@ -1405,8 +1409,8 @@ static int l_SetCursorPos(lua_State* L)
14051409
ui->LAssert(L, n >= 2, "Usage: SetCursorPos(x, y)");
14061410
ui->LAssert(L, lua_isnumber(L, 1), "SetCursorPos() argument 1: expected number, got %s", luaL_typename(L, 1));
14071411
ui->LAssert(L, lua_isnumber(L, 2), "SetCursorPos() argument 2: expected number, got %s", luaL_typename(L, 2));
1408-
int x = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 1) / dpiScale);
1409-
int y = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 2) / dpiScale);
1412+
int x = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 1) * dpiScale);
1413+
int y = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 2) * dpiScale);
14101414
ui->sys->video->SetRelativeCursor(x, y);
14111415
return 0;
14121416
}

0 commit comments

Comments
 (0)