SDL: Move code to handle cursor coordinate HiDPI scale to SdlWindow

SDL handles HiDPI scaling differently depending on the system. On
macOS for example the SDL window size and SDL drawable area have a
different size (factor 2 usually) while on Windows they are the
same. When HiDPI is disabled (for the SDL Surface mode for example)
they are always the same.

We need to appl this scaling when converting cursor position between
the drawable area and the SDL window.
This commit is contained in:
Thierry Crozat 2021-08-20 00:12:51 +01:00
parent 9d4ba30060
commit feac996b50
3 changed files with 26 additions and 9 deletions

View file

@ -272,6 +272,17 @@ float SdlWindow::getDpiScalingFactor() const {
return ratio;
}
float SdlWindow::getSdlDpiScalingFactor() const {
#if SDL_VERSION_ATLEAST(2, 0, 0)
int windowWidth, windowHeight;
SDL_GetWindowSize(getSDLWindow(), &windowWidth, &windowHeight);
int realWidth, realHeight;
SDL_GL_GetDrawableSize(getSDLWindow(), &realWidth, &realHeight);
return (float)realWidth / (float)windowWidth;
#else
return 1.f;
#endif
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Surface *copySDLSurface(SDL_Surface *src) {