mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-17 18:28:28 +00:00
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:
parent
27ce914463
commit
0d98793693
6 changed files with 103 additions and 2 deletions
|
@ -2491,6 +2491,42 @@ SDL_RenderGetScale(SDL_Renderer * renderer, float *scaleX, float *scaleY)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_RenderWindowToLogical(SDL_Renderer * renderer, int windowX, int windowY, float *logicalX, float *logicalY)
|
||||
{
|
||||
float window_physical_x, window_physical_y;
|
||||
|
||||
CHECK_RENDERER_MAGIC(renderer, );
|
||||
|
||||
window_physical_x = ((float) windowX) / renderer->dpi_scale.x;
|
||||
window_physical_y = ((float) windowY) / renderer->dpi_scale.y;
|
||||
|
||||
if (logicalX) {
|
||||
*logicalX = (window_physical_x - renderer->viewport.x) / renderer->scale.x;
|
||||
}
|
||||
if (logicalY) {
|
||||
*logicalY = (window_physical_y - renderer->viewport.y) / renderer->scale.y;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_RenderLogicalToWindow(SDL_Renderer * renderer, float logicalX, float logicalY, int *windowX, int *windowY)
|
||||
{
|
||||
float window_physical_x, window_physical_y;
|
||||
|
||||
CHECK_RENDERER_MAGIC(renderer, );
|
||||
|
||||
window_physical_x = (logicalX * renderer->scale.x) + renderer->viewport.x;
|
||||
window_physical_y = (logicalY * renderer->scale.y) + renderer->viewport.y;
|
||||
|
||||
if (windowX) {
|
||||
*windowX = (int)(window_physical_x * renderer->dpi_scale.x);
|
||||
}
|
||||
if (windowY) {
|
||||
*windowY = (int)(window_physical_y * renderer->dpi_scale.y);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SetRenderDrawColor(SDL_Renderer * renderer,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue