mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 04:41:39 +00:00
Dpi fixes (#449)
* Potential fix for DPI scaling. * Show window size in pixels while in Fullscreen mode.
This commit is contained in:
parent
c90d1fcb7b
commit
03ef34ffe8
5 changed files with 38 additions and 18 deletions
|
|
@ -2344,7 +2344,7 @@ namespace plume {
|
||||||
dstWidth = rect.right - rect.left;
|
dstWidth = rect.right - rect.left;
|
||||||
dstHeight = rect.bottom - rect.top;
|
dstHeight = rect.bottom - rect.top;
|
||||||
# elif defined(SDL_VULKAN_ENABLED)
|
# elif defined(SDL_VULKAN_ENABLED)
|
||||||
SDL_GetWindowSize(renderWindow, (int *)(&dstWidth), (int *)(&dstHeight));
|
SDL_GetWindowSizeInPixels(renderWindow, (int *)(&dstWidth), (int *)(&dstHeight));
|
||||||
# elif defined(__ANDROID__)
|
# elif defined(__ANDROID__)
|
||||||
dstWidth = ANativeWindow_getWidth(renderWindow);
|
dstWidth = ANativeWindow_getWidth(renderWindow);
|
||||||
dstHeight = ANativeWindow_getHeight(renderWindow);
|
dstHeight = ANativeWindow_getHeight(renderWindow);
|
||||||
|
|
|
||||||
|
|
@ -2415,19 +2415,25 @@ static void DrawImGui()
|
||||||
// we can adjust the mouse events before ImGui processes them.
|
// we can adjust the mouse events before ImGui processes them.
|
||||||
uint32_t width = g_swapChain->getWidth();
|
uint32_t width = g_swapChain->getWidth();
|
||||||
uint32_t height = g_swapChain->getHeight();
|
uint32_t height = g_swapChain->getHeight();
|
||||||
|
float mousePosScaleX = float(width) / float(GameWindow::s_width);
|
||||||
if (width != Video::s_viewportWidth || height != Video::s_viewportHeight)
|
float mousePosScaleY = float(height) / float(GameWindow::s_height);
|
||||||
{
|
|
||||||
float mousePosOffsetX = (width - Video::s_viewportWidth) / 2.0f;
|
float mousePosOffsetX = (width - Video::s_viewportWidth) / 2.0f;
|
||||||
float mousePosOffsetY = (height - Video::s_viewportHeight) / 2.0f;
|
float mousePosOffsetY = (height - Video::s_viewportHeight) / 2.0f;
|
||||||
|
|
||||||
for (int i = 0; i < io.Ctx->InputEventsQueue.Size; i++)
|
for (int i = 0; i < io.Ctx->InputEventsQueue.Size; i++)
|
||||||
{
|
{
|
||||||
auto& e = io.Ctx->InputEventsQueue[i];
|
auto& e = io.Ctx->InputEventsQueue[i];
|
||||||
if (e.Type == ImGuiInputEventType_MousePos)
|
if (e.Type == ImGuiInputEventType_MousePos)
|
||||||
{
|
{
|
||||||
if (e.MousePos.PosX != -FLT_MAX) e.MousePos.PosX -= mousePosOffsetX;
|
if (e.MousePos.PosX != -FLT_MAX)
|
||||||
if (e.MousePos.PosY != -FLT_MAX) e.MousePos.PosY -= mousePosOffsetY;
|
{
|
||||||
|
e.MousePos.PosX *= mousePosScaleX;
|
||||||
|
e.MousePos.PosX -= mousePosOffsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.MousePos.PosY != -FLT_MAX)
|
||||||
|
{
|
||||||
|
e.MousePos.PosY *= mousePosScaleY;
|
||||||
|
e.MousePos.PosY -= mousePosOffsetY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -378,6 +378,11 @@ SDL_Rect GameWindow::GetDimensions()
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameWindow::GetSizeInPixels(int *w, int *h)
|
||||||
|
{
|
||||||
|
SDL_GetWindowSizeInPixels(s_pWindow, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
void GameWindow::SetDimensions(int w, int h, int x, int y)
|
void GameWindow::SetDimensions(int w, int h, int x, int y)
|
||||||
{
|
{
|
||||||
s_width = w;
|
s_width = w;
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ public:
|
||||||
static bool IsMaximised();
|
static bool IsMaximised();
|
||||||
static EWindowState SetMaximised(bool isEnabled);
|
static EWindowState SetMaximised(bool isEnabled);
|
||||||
static SDL_Rect GetDimensions();
|
static SDL_Rect GetDimensions();
|
||||||
|
static void GetSizeInPixels(int *w, int *h);
|
||||||
static void SetDimensions(int w, int h, int x = SDL_WINDOWPOS_CENTERED, int y = SDL_WINDOWPOS_CENTERED);
|
static void SetDimensions(int w, int h, int x = SDL_WINDOWPOS_CENTERED, int y = SDL_WINDOWPOS_CENTERED);
|
||||||
static void ResetDimensions();
|
static void ResetDimensions();
|
||||||
static uint32_t GetWindowFlags();
|
static uint32_t GetWindowFlags();
|
||||||
|
|
|
||||||
|
|
@ -1120,9 +1120,16 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
|
||||||
else if constexpr (std::is_same_v<T, int32_t>)
|
else if constexpr (std::is_same_v<T, int32_t>)
|
||||||
{
|
{
|
||||||
if (config == &Config::WindowSize)
|
if (config == &Config::WindowSize)
|
||||||
|
{
|
||||||
|
if (Config::Fullscreen)
|
||||||
|
{
|
||||||
|
int displayW, displayH;
|
||||||
|
GameWindow::GetSizeInPixels(&displayW, &displayH);
|
||||||
|
valueText = fmt::format("{}x{}", displayW, displayH);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
auto displayModes = GameWindow::GetDisplayModes();
|
auto displayModes = GameWindow::GetDisplayModes();
|
||||||
|
|
||||||
if (config->Value >= 0 && config->Value < displayModes.size())
|
if (config->Value >= 0 && config->Value < displayModes.size())
|
||||||
{
|
{
|
||||||
auto& displayMode = displayModes[config->Value];
|
auto& displayMode = displayModes[config->Value];
|
||||||
|
|
@ -1134,6 +1141,7 @@ static void DrawConfigOption(int32_t rowIndex, float yOffset, ConfigDef<T>* conf
|
||||||
valueText = fmt::format("{}x{}", GameWindow::s_width, GameWindow::s_height);
|
valueText = fmt::format("{}x{}", GameWindow::s_width, GameWindow::s_height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (config == &Config::Monitor)
|
else if (config == &Config::Monitor)
|
||||||
{
|
{
|
||||||
valueText = fmt::format("{}", config->Value + 1);
|
valueText = fmt::format("{}", config->Value + 1);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue