Update the Renderer dpi_scale on SIZE_CHANGED event (fix #4580)

The Renderer logical scaling code scales mouse coordinates, and needs to
take the window DPI into account on HIGHDPI windows. However, the
variable which tracks this, renderer->dpi_scale, is set once when the
renderer is created, and then not updated. In the event that the window
is moved to another screen, or the screen DPI otherwise changes, this
will be outdates, and potentially the coordinates will be all wrong.

So let's update the dpi_scale on the SIZE_CHANGED event: it's at least a
possibility that this will be issued on some OSes when DPI changes, and
it's otherwise already handled by SDL_Renderer's event filter.
This commit is contained in:
David Gow 2021-08-03 20:55:45 +08:00 committed by Sam Lantinga
parent 9b4884d58a
commit 4077f7a2d9
1 changed files with 11 additions and 0 deletions

View File

@ -619,6 +619,17 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
SDL_SetRenderTarget(renderer, NULL);
}
/* Update the DPI scale if the window has been resized. */
if (window && renderer->GetOutputSize) {
int window_w, window_h;
int output_w, output_h;
if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) {
SDL_GetWindowSize(renderer->window, &window_w, &window_h);
renderer->dpi_scale.x = (float)window_w / output_w;
renderer->dpi_scale.y = (float)window_h / output_h;
}
}
if (renderer->logical_w) {
UpdateLogicalSize(renderer);
} else {