From 79760f5c8953ca392333dac7dbeea9adee0642e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Thu, 5 Oct 2023 20:08:17 +0200 Subject: [PATCH] Fix input method candidates being aligned wrong in some cases Namely when the main window is resizeable and its size isn't the same as it would be with the active scale mode with resizing disabled. Also fix window position not being restored when the main window is resizeable. --- src/PowderToySDL.cpp | 17 ++++++++++------- src/gui/interface/Engine.cpp | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index c5323e52f..37b8dc8b5 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -42,11 +42,15 @@ void StopTextInput() void SetTextInputRect(int x, int y, int w, int h) { + // Why does SDL_SetTextInputRect not take logical coordinates??? + int wx, wy, wwx, why; + SDL_RenderLogicalToWindow(sdl_renderer, x, y, &wx, &wy); + SDL_RenderLogicalToWindow(sdl_renderer, x + w, y + h, &wwx, &why); SDL_Rect rect; - rect.x = x; - rect.y = y; - rect.w = w; - rect.h = h; + rect.x = wx; + rect.y = wy; + rect.w = wwx - wx; + rect.h = why - wy; SDL_SetTextInputRect(&rect); } @@ -241,13 +245,12 @@ void SDLSetScreen() //Uncomment this to enable resizing //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); //SDL_SetWindowResizable(sdl_window, SDL_TRUE); - - LoadWindowPosition(); - UpdateFpsLimit(); } SDL_SetWindowSize(sdl_window, size.X, size.Y); SDL_RenderSetIntegerScale(sdl_renderer, newFrameOpsNorm.forceIntegerScaling ? SDL_TRUE : SDL_FALSE); + LoadWindowPosition(); + UpdateFpsLimit(); if (newFrameOpsNorm.fullscreen) { SDL_RaiseWindow(sdl_window); diff --git a/src/gui/interface/Engine.cpp b/src/gui/interface/Engine.cpp index 08887d23d..0091d3484 100644 --- a/src/gui/interface/Engine.cpp +++ b/src/gui/interface/Engine.cpp @@ -331,6 +331,5 @@ void Engine::StopTextInput() void Engine::TextInputRect(Point position, Point size) { - auto scale = windowFrameOps.scale; - ::SetTextInputRect(position.X * scale, position.Y * scale, size.X * scale, size.Y * scale); + ::SetTextInputRect(position.X, position.Y, size.X, size.Y); }