Skip to content

Commit 9d1a53f

Browse files
authored
Merge pull request #80 from LeonSparta/master
2 parents cc7d253 + 890c595 commit 9d1a53f

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

ui_api.cpp

Lines changed: 33 additions & 11 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();
@@ -893,10 +897,11 @@ static int l_DrawImage(lua_State* L)
893897
}
894898

895899
if (af & AF_XY) {
900+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
896901
for (int i = k; i < k + 4; i++) {
897902
ui->LAssert(L, lua_isnumber(L, i), "DrawImage() argument %d: expected number, got %s", i, luaL_typename(L, i));
898903
const int idx = i - k;
899-
xys[idx/2][idx%2] = (float)lua_tonumber(L, i);
904+
xys[idx/2][idx%2] = (float)lua_tonumber(L, i) * dpiScale;
900905
}
901906
k += 4;
902907
}
@@ -991,10 +996,11 @@ static int l_DrawImageQuad(lua_State* L)
991996
}
992997

993998
if (af & AF_XY) {
999+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
9941000
for (int i = k; i < k + 8; i++) {
9951001
ui->LAssert(L, lua_isnumber(L, i), "DrawImageQuad() argument %d: expected number, got %s", i, luaL_typename(L, i));
9961002
const int idx = i - k;
997-
xys[idx / 2][idx % 2] = (float)lua_tonumber(L, i);
1003+
xys[idx / 2][idx % 2] = (float)lua_tonumber(L, i) * dpiScale;
9981004
}
9991005
k += 8;
10001006
}
@@ -1061,9 +1067,15 @@ static int l_DrawString(lua_State* L)
10611067
ui->LAssert(L, lua_isstring(L, 6), "DrawString() argument 6: expected string, got %s", luaL_typename(L, 6));
10621068
static const char* alignMap[6] = { "LEFT", "CENTER", "RIGHT", "CENTER_X", "RIGHT_X", NULL };
10631069
static const char* fontMap[4] = { "FIXED", "VAR", "VAR BOLD", NULL };
1070+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
10641071
ui->renderer->DrawString(
1065-
(float)lua_tonumber(L, 1), (float)lua_tonumber(L, 2), luaL_checkoption(L, 3, "LEFT", alignMap),
1066-
(int)lua_tointeger(L, 4), NULL, luaL_checkoption(L, 5, "FIXED", fontMap), lua_tostring(L, 6)
1072+
(float)lua_tonumber(L, 1) * dpiScale,
1073+
(float)lua_tonumber(L, 2) * dpiScale,
1074+
luaL_checkoption(L, 3, "LEFT", alignMap),
1075+
(int)lua_tointeger(L, 4) * dpiScale,
1076+
NULL,
1077+
luaL_checkoption(L, 5, "FIXED", fontMap),
1078+
lua_tostring(L, 6)
10671079
);
10681080
return 0;
10691081
}
@@ -1078,7 +1090,10 @@ static int l_DrawStringWidth(lua_State* L)
10781090
ui->LAssert(L, lua_isstring(L, 2), "DrawStringWidth() argument 2: expected string, got %s", luaL_typename(L, 2));
10791091
ui->LAssert(L, lua_isstring(L, 3), "DrawStringWidth() argument 3: expected string, got %s", luaL_typename(L, 3));
10801092
static const char* fontMap[4] = { "FIXED", "VAR", "VAR BOLD", NULL };
1081-
lua_pushinteger(L, ui->renderer->DrawStringWidth((int)lua_tointeger(L, 1), luaL_checkoption(L, 2, "FIXED", fontMap), lua_tostring(L, 3)));
1093+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
1094+
lua_pushinteger(L, ui->renderer->DrawStringWidth((int)lua_tointeger(L, 1) * dpiScale,
1095+
luaL_checkoption(L, 2, "FIXED", fontMap),
1096+
lua_tostring(L, 3)));
10821097
return 1;
10831098
}
10841099

@@ -1087,14 +1102,18 @@ static int l_DrawStringCursorIndex(lua_State* L)
10871102
ui_main_c* ui = GetUIPtr(L);
10881103
ui->LAssert(L, ui->renderer != NULL, "Renderer is not initialised");
10891104
int n = lua_gettop(L);
1105+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
10901106
ui->LAssert(L, n >= 5, "Usage: DrawStringCursorIndex(height, font, text, cursorX, cursorY)");
10911107
ui->LAssert(L, lua_isnumber(L, 1), "DrawStringCursorIndex() argument 1: expected number, got %s", luaL_typename(L, 1));
10921108
ui->LAssert(L, lua_isstring(L, 2), "DrawStringCursorIndex() argument 2: expected string, got %s", luaL_typename(L, 2));
10931109
ui->LAssert(L, lua_isstring(L, 3), "DrawStringCursorIndex() argument 3: expected string, got %s", luaL_typename(L, 3));
10941110
ui->LAssert(L, lua_isnumber(L, 4), "DrawStringCursorIndex() argument 4: expected number, got %s", luaL_typename(L, 4));
10951111
ui->LAssert(L, lua_isnumber(L, 5), "DrawStringCursorIndex() argument 5: expected number, got %s", luaL_typename(L, 5));
10961112
static const char* fontMap[4] = { "FIXED", "VAR", "VAR BOLD", NULL };
1097-
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);
10981117
return 1;
10991118
}
11001119

@@ -1376,20 +1395,22 @@ static int l_SetWindowTitle(lua_State* L)
13761395
static int l_GetCursorPos(lua_State* L)
13771396
{
13781397
ui_main_c* ui = GetUIPtr(L);
1379-
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorX));
1380-
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorY));
1398+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
1399+
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorX) / dpiScale);
1400+
lua_pushinteger(L, ui->renderer->VirtualMap(ui->cursorY) / dpiScale);
13811401
return 2;
13821402
}
13831403

13841404
static int l_SetCursorPos(lua_State* L)
13851405
{
13861406
ui_main_c* ui = GetUIPtr(L);
13871407
int n = lua_gettop(L);
1408+
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
13881409
ui->LAssert(L, n >= 2, "Usage: SetCursorPos(x, y)");
13891410
ui->LAssert(L, lua_isnumber(L, 1), "SetCursorPos() argument 1: expected number, got %s", luaL_typename(L, 1));
13901411
ui->LAssert(L, lua_isnumber(L, 2), "SetCursorPos() argument 2: expected number, got %s", luaL_typename(L, 2));
1391-
int x = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 1));
1392-
int y = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 2));
1412+
int x = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 1) * dpiScale);
1413+
int y = ui->renderer->VirtualUnmap((int)lua_tointeger(L, 2) * dpiScale);
13931414
ui->sys->video->SetRelativeCursor(x, y);
13941415
return 0;
13951416
}
@@ -2183,3 +2204,4 @@ int ui_main_c::InitAPI(lua_State* L)
21832204
return 0;
21842205
}
21852206

2207+

0 commit comments

Comments
 (0)