Skip to content

Commit d617255

Browse files
author
ethanblazkowicz
committed
Added DPI scaling to the ui_api.cpp, now the SetViewPort, DrawImage, DrawImageQuad, DrawString, DrawStringWidth, GetCursorPos and SetCursorPos function can scale with windows scale settings. Some usage of these functions in lua files from POB and POB 2 are coded in the lua scripts, so they still need to be adjusted accordingly.
1 parent 2067baf commit d617255

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

ui_api.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,16 @@ static int l_SetViewport(lua_State* L)
792792
ui->LAssert(L, ui->renderer != NULL, "Renderer is not initialised");
793793
ui->LAssert(L, ui->renderEnable, "SetViewport() called outside of OnFrame");
794794
int n = lua_gettop(L);
795+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
795796
if (n) {
796797
ui->LAssert(L, n >= 4, "Usage: SetViewport([x, y, width, height])");
797798
for (int i = 1; i <= 4; i++) {
798799
ui->LAssert(L, lua_isnumber(L, i), "SetViewport() argument %d: expected number, got %s", i, luaL_typename(L, i));
799800
}
800-
ui->renderer->SetViewport((int)lua_tointeger(L, 1), (int)lua_tointeger(L, 2), (int)lua_tointeger(L, 3), (int)lua_tointeger(L, 4));
801+
ui->renderer->SetViewport((int)(lua_tointeger(L, 1) * dpiScale),
802+
(int)(lua_tointeger(L, 2) * dpiScale),
803+
(int)(lua_tointeger(L, 3) * dpiScale),
804+
(int)(lua_tointeger(L, 4) * dpiScale));
801805
}
802806
else {
803807
ui->renderer->SetViewport();
@@ -992,10 +996,11 @@ static int l_DrawImageQuad(lua_State* L)
992996
}
993997

994998
if (af & AF_XY) {
999+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
9951000
for (int i = k; i < k + 8; i++) {
9961001
ui->LAssert(L, lua_isnumber(L, i), "DrawImageQuad() argument %d: expected number, got %s", i, luaL_typename(L, i));
9971002
const int idx = i - k;
998-
xys[idx / 2][idx % 2] = (float)lua_tonumber(L, i);
1003+
xys[idx / 2][idx % 2] = (float)lua_tonumber(L, i) * dpiScale;
9991004
}
10001005
k += 8;
10011006
}
@@ -1386,18 +1391,22 @@ static int l_SetWindowTitle(lua_State* L)
13861391
static int l_GetCursorPos(lua_State* L)
13871392
{
13881393
ui_main_c* ui = GetUIPtr(L);
1389-
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorX));
1390-
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorY));
1394+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
1395+
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorX) / dpiScale);
1396+
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorY) / dpiScale);
13911397
return 2;
13921398
}
13931399

13941400
static int l_SetCursorPos(lua_State* L)
13951401
{
13961402
ui_main_c* ui = GetUIPtr(L);
13971403
int n = lua_gettop(L);
1404+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
13981405
ui->LAssert(L, n >= 2, "Usage: SetCursorPos(x, y)");
13991406
ui->LAssert(L, lua_isnumber(L, 1), "SetCursorPos() argument 1: expected number, got %s", luaL_typename(L, 1));
14001407
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);
14011410
int x = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 1));
14021411
int y = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 2));
14031412
ui->sys->video->SetRelativeCursor(x, y);

0 commit comments

Comments
 (0)