Skip to content

Commit 154ded4

Browse files
author
LocalIdentity
committed
Allow window scaling override from within PoB
Extends the scaling feature with the ability to set the scaling value from within PoB and also have it update in real-time when a user changes the option so they don't need to restart the app
1 parent 03fb38e commit 154ded4

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

engine/render.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class r_IRenderer {
102102
virtual int VirtualScreenWidth() = 0;
103103
virtual int VirtualScreenHeight() = 0;
104104
virtual float VirtualScreenScaleFactor() = 0;
105+
virtual void SetDpiScaleOverridePercent(int percent) = 0;
106+
virtual int DpiScaleOverridePercent() const = 0;
105107
virtual int VirtualMap(int properValue) = 0;
106108
virtual int VirtualUnmap(int mappedValue) = 0;
107109

engine/render/r_main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,11 +1863,25 @@ int r_renderer_c::VirtualScreenHeight() {
18631863

18641864
float r_renderer_c::VirtualScreenScaleFactor() {
18651865
if (apiDpiAware) {
1866+
if (dpiScaleOverridePercent > 0) {
1867+
return (float)dpiScaleOverridePercent / 100.0f;
1868+
}
18661869
return sys->video->vid.dpiScale;
18671870
}
18681871
return 1.0f;
18691872
}
18701873

1874+
void r_renderer_c::SetDpiScaleOverridePercent(int percent) {
1875+
if (percent < 0) {
1876+
percent = 0;
1877+
}
1878+
dpiScaleOverridePercent = percent;
1879+
}
1880+
1881+
int r_renderer_c::DpiScaleOverridePercent() const {
1882+
return dpiScaleOverridePercent;
1883+
}
1884+
18711885
int r_renderer_c::VirtualMap(int properValue) {
18721886
if (apiDpiAware) {
18731887
return properValue;

engine/render/r_main.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
9999
int VirtualScreenWidth();
100100
int VirtualScreenHeight();
101101
float VirtualScreenScaleFactor();
102+
void SetDpiScaleOverridePercent(int percent);
103+
int DpiScaleOverridePercent() const;
102104
int VirtualMap(int properValue);
103105
int VirtualUnmap(int mappedValue);
104106

@@ -126,7 +128,7 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
126128
PFNGLINSERTEVENTMARKEREXTPROC glInsertEventMarkerEXT = nullptr;
127129
PFNGLPUSHGROUPMARKEREXTPROC glPushGroupMarkerEXT = nullptr;
128130
PFNGLPOPGROUPMARKEREXTPROC glPopGroupMarkerEXT = nullptr;
129-
131+
130132
conVar_c* r_compress = nullptr;
131133
conVar_c* r_screenshotFormat = nullptr;
132134
conVar_c* r_layerDebug = nullptr;
@@ -173,6 +175,7 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
173175
};
174176

175177
bool apiDpiAware{};
178+
int dpiScaleOverridePercent = 0;
176179
RenderTarget rttMain[2];
177180
int presentRtt = 0;
178181

ui_api.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,26 @@ static int l_DrawStringCursorIndex(lua_State* L)
11321132
return 1;
11331133
}
11341134

1135+
static int l_SetDPIScaleOverridePercent(lua_State* L)
1136+
{
1137+
ui_main_c* ui = GetUIPtr(L);
1138+
ui->LAssert(L, ui->renderer != NULL, "Renderer is not initialised");
1139+
int n = lua_gettop(L);
1140+
ui->LAssert(L, n >= 1, "Usage: SetDPIScaleOverridePercent(percent)");
1141+
ui->LAssert(L, lua_isnumber(L, 1), "SetDPIScaleOverridePercent() argument 1: expected number, got %s", luaL_typename(L, 1));
1142+
int percent = (int)lua_tointeger(L, 1);
1143+
ui->renderer->SetDpiScaleOverridePercent(percent);
1144+
return 0;
1145+
}
1146+
1147+
static int l_GetDPIScaleOverridePercent(lua_State* L)
1148+
{
1149+
ui_main_c* ui = GetUIPtr(L);
1150+
ui->LAssert(L, ui->renderer != NULL, "Renderer is not initialised");
1151+
lua_pushinteger(L, ui->renderer->DpiScaleOverridePercent());
1152+
return 1;
1153+
}
1154+
11351155
static int l_StripEscapes(lua_State* L)
11361156
{
11371157
ui_main_c* ui = GetUIPtr(L);
@@ -2146,6 +2166,8 @@ int ui_main_c::InitAPI(lua_State* L)
21462166
ADDFUNC(SetViewport);
21472167
ADDFUNC(SetBlendMode);
21482168
ADDFUNC(SetDrawColor);
2169+
ADDFUNC(SetDPIScaleOverridePercent);
2170+
ADDFUNC(GetDPIScaleOverridePercent);
21492171
ADDFUNC(DrawImage);
21502172
ADDFUNC(DrawImageQuad);
21512173
ADDFUNC(DrawString);

0 commit comments

Comments
 (0)