testwm2: Fix video modes menu hit detection when highdpi or logical size used (#4936)

* SDLTest_CommonDrawWindowInfo: log SDL_RenderGetScale, SDL_RenderGetLogicalSize

* testwm2: fix video modes menu hit detection in High DPI cases

- also when logical size is specified, e.g.
  `--logical 640x480 --resizable --allow-highdpi`

* add function to determine logical coordinates of renderer point when given window point

* change since to the targeted milestone

* fix typo

* rename for consistency

* Change logical coordinate type to float, since we can render with floating point precision.

* add function to convert logical to window coordinates

* testwm2: use new SDL_RenderWindowToLogical

* SDL_render.c: alternate SDL_RenderWindowToLogical/SDL_RenderLogicalToWindow

Co-authored-by: John Blat <johnblat64@protonmail.com>
Co-authored-by: John Blat <47202511+johnblat64@users.noreply.github.com>
This commit is contained in:
Eric Wasylishen
2021-11-09 22:03:42 -07:00
committed by GitHub
parent 27ce914463
commit 0d98793693
6 changed files with 103 additions and 2 deletions

View File

@@ -52,7 +52,7 @@ quit(int rc)
/* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */
static void
draw_modes_menu(SDL_Window* window, SDL_Renderer* renderer, SDL_Rect viewport)
draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
{
SDL_DisplayMode mode;
char text[1024];
@@ -68,7 +68,14 @@ draw_modes_menu(SDL_Window* window, SDL_Renderer* renderer, SDL_Rect viewport)
/* Get mouse position */
if (SDL_GetMouseFocus() == window) {
SDL_GetMouseState(&mouse_pos.x, &mouse_pos.y);
int window_x, window_y;
float logical_x, logical_y;
SDL_GetMouseState(&window_x, &window_y);
SDL_RenderWindowToLogical(renderer, window_x, window_y, &logical_x, &logical_y);
mouse_pos.x = (int)logical_x;
mouse_pos.y = (int)logical_y;
}
x = 0;