Skip to content

Commit 03ef34f

Browse files
authored
Dpi fixes (#449)
* Potential fix for DPI scaling. * Show window size in pixels while in Fullscreen mode.
1 parent c90d1fc commit 03ef34f

5 files changed

Lines changed: 38 additions & 18 deletions

File tree

UnleashedRecomp/gpu/rhi/plume_vulkan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ namespace plume {
23442344
dstWidth = rect.right - rect.left;
23452345
dstHeight = rect.bottom - rect.top;
23462346
# elif defined(SDL_VULKAN_ENABLED)
2347-
SDL_GetWindowSize(renderWindow, (int *)(&dstWidth), (int *)(&dstHeight));
2347+
SDL_GetWindowSizeInPixels(renderWindow, (int *)(&dstWidth), (int *)(&dstHeight));
23482348
# elif defined(__ANDROID__)
23492349
dstWidth = ANativeWindow_getWidth(renderWindow);
23502350
dstHeight = ANativeWindow_getHeight(renderWindow);

UnleashedRecomp/gpu/video.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,19 +2415,25 @@ static void DrawImGui()
24152415
// we can adjust the mouse events before ImGui processes them.
24162416
uint32_t width = g_swapChain->getWidth();
24172417
uint32_t height = g_swapChain->getHeight();
2418-
2419-
if (width != Video::s_viewportWidth || height != Video::s_viewportHeight)
2418+
float mousePosScaleX = float(width) / float(GameWindow::s_width);
2419+
float mousePosScaleY = float(height) / float(GameWindow::s_height);
2420+
float mousePosOffsetX = (width - Video::s_viewportWidth) / 2.0f;
2421+
float mousePosOffsetY = (height - Video::s_viewportHeight) / 2.0f;
2422+
for (int i = 0; i < io.Ctx->InputEventsQueue.Size; i++)
24202423
{
2421-
float mousePosOffsetX = (width - Video::s_viewportWidth) / 2.0f;
2422-
float mousePosOffsetY = (height - Video::s_viewportHeight) / 2.0f;
2423-
2424-
for (int i = 0; i < io.Ctx->InputEventsQueue.Size; i++)
2424+
auto& e = io.Ctx->InputEventsQueue[i];
2425+
if (e.Type == ImGuiInputEventType_MousePos)
24252426
{
2426-
auto& e = io.Ctx->InputEventsQueue[i];
2427-
if (e.Type == ImGuiInputEventType_MousePos)
2427+
if (e.MousePos.PosX != -FLT_MAX)
2428+
{
2429+
e.MousePos.PosX *= mousePosScaleX;
2430+
e.MousePos.PosX -= mousePosOffsetX;
2431+
}
2432+
2433+
if (e.MousePos.PosY != -FLT_MAX)
24282434
{
2429-
if (e.MousePos.PosX != -FLT_MAX) e.MousePos.PosX -= mousePosOffsetX;
2430-
if (e.MousePos.PosY != -FLT_MAX) e.MousePos.PosY -= mousePosOffsetY;
2435+
e.MousePos.PosY *= mousePosScaleY;
2436+
e.MousePos.PosY -= mousePosOffsetY;
24312437
}
24322438
}
24332439
}

UnleashedRecomp/ui/game_window.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ SDL_Rect GameWindow::GetDimensions()
378378
return rect;
379379
}
380380

381+
void GameWindow::GetSizeInPixels(int *w, int *h)
382+
{
383+
SDL_GetWindowSizeInPixels(s_pWindow, w, h);
384+
}
385+
381386
void GameWindow::SetDimensions(int w, int h, int x, int y)
382387
{
383388
s_width = w;

UnleashedRecomp/ui/game_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class GameWindow
3737
static bool IsMaximised();
3838
static EWindowState SetMaximised(bool isEnabled);
3939
static SDL_Rect GetDimensions();
40+
static void GetSizeInPixels(int *w, int *h);
4041
static void SetDimensions(int w, int h, int x = SDL_WINDOWPOS_CENTERED, int y = SDL_WINDOWPOS_CENTERED);
4142
static void ResetDimensions();
4243
static uint32_t GetWindowFlags();

UnleashedRecomp/ui/options_menu.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,17 +1121,25 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
11211121
{
11221122
if (config == &Config::WindowSize)
11231123
{
1124-
auto displayModes = GameWindow::GetDisplayModes();
1125-
1126-
if (config->Value >= 0 && config->Value < displayModes.size())
1124+
if (Config::Fullscreen)
11271125
{
1128-
auto& displayMode = displayModes[config->Value];
1129-
1130-
valueText = fmt::format("{}x{}", displayMode.w, displayMode.h);
1126+
int displayW, displayH;
1127+
GameWindow::GetSizeInPixels(&displayW, &displayH);
1128+
valueText = fmt::format("{}x{}", displayW, displayH);
11311129
}
11321130
else
11331131
{
1134-
valueText = fmt::format("{}x{}", GameWindow::s_width, GameWindow::s_height);
1132+
auto displayModes = GameWindow::GetDisplayModes();
1133+
if (config->Value >= 0 && config->Value < displayModes.size())
1134+
{
1135+
auto& displayMode = displayModes[config->Value];
1136+
1137+
valueText = fmt::format("{}x{}", displayMode.w, displayMode.h);
1138+
}
1139+
else
1140+
{
1141+
valueText = fmt::format("{}x{}", GameWindow::s_width, GameWindow::s_height);
1142+
}
11351143
}
11361144
}
11371145
else if (config == &Config::Monitor)

0 commit comments

Comments
 (0)