Hook up Android_ScreenDensity to convert pixels to screen coordinates on Android

Fixes https://github.com/libsdl-org/SDL/issues/7149
This commit is contained in:
Sam Lantinga
2023-01-25 10:22:43 -08:00
parent 9bbc402b81
commit a37f2aed7e
4 changed files with 17 additions and 8 deletions

View File

@@ -54,8 +54,8 @@ int Android_CreateWindow(_THIS, SDL_Window *window)
/* Adjust the window data to match the screen */
window->x = 0;
window->y = 0;
window->w = Android_SurfaceWidth;
window->h = Android_SurfaceHeight;
window->w = (int)SDL_ceilf(Android_SurfaceWidth / Android_ScreenDensity);
window->h = (int)SDL_ceilf(Android_SurfaceHeight / Android_ScreenDensity);
/* One window, it always has focus */
SDL_SetMouseFocus(window);
@@ -139,8 +139,8 @@ void Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *di
old_w = window->w;
old_h = window->h;
new_w = ANativeWindow_getWidth(data->native_window);
new_h = ANativeWindow_getHeight(data->native_window);
new_w = (int)SDL_ceilf(ANativeWindow_getWidth(data->native_window) / Android_ScreenDensity);
new_h = (int)SDL_ceilf(ANativeWindow_getHeight(data->native_window) / Android_ScreenDensity);
if (new_w < 0 || new_h < 0) {
SDL_SetError("ANativeWindow_getWidth/Height() fails");