From eab51cb2b9d12f4550a0cbcf7e6bcb2c7ff4e541 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Sun, 19 Dec 2021 01:38:36 +0200 Subject: [PATCH] Emscripten: adjust resolution to the device DPI --- os/emscripten/shell.html | 2 +- src/video/sdl2_v.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/os/emscripten/shell.html b/os/emscripten/shell.html index 0782044353..c52c4c9c78 100644 --- a/os/emscripten/shell.html +++ b/os/emscripten/shell.html @@ -3,7 +3,7 @@ - + OpenTTD diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 5679ee6525..7c9815e784 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -86,6 +86,9 @@ static void FindResolutions() _resolutions.clear(); SDL_DisplayMode mode; SDL_GetDesktopDisplayMode(0, &mode); + // Stupid mobile web browser reports 2x smaller window size + mode.w *= emscripten_get_device_pixel_ratio(); + mode.h *= emscripten_get_device_pixel_ratio(); _resolutions.emplace_back(mode.w, mode.h); // 1920x1080 _resolutions.emplace_back(mode.w * 8 / 9, mode.h * 8 / 9); // 8 / 9 : 1920x1080 -> 1706x960 _resolutions.emplace_back(mode.w * 7 / 8, mode.h * 7 / 8); // 7 / 8 : 1920x1080 -> 1680x945 @@ -99,6 +102,7 @@ static void FindResolutions() _resolutions.emplace_back(mode.w * 4 / 9, mode.h * 4 / 9); // 4 / 9 : 1920x1080 -> 853x480 _resolutions.emplace_back(mode.w * 3 / 8, mode.h * 3 / 8); // 3 / 8 : 1920x1080 -> 720x405 _resolutions.emplace_back(mode.w * 2 / 6, mode.h * 2 / 6); // 2 / 6 : 1920x1080 -> 640x360 + _resolutions.emplace_back(mode.w * 5 / 18, mode.h * 5 / 18); // 5 / 18: 1920x1080 -> 533x300 _resolutions.emplace_back(mode.w * 2 / 8, mode.h * 2 / 8); // 2 / 8 : 1920x1080 -> 480x270 _resolutions.emplace_back(mode.w * 2 / 9, mode.h * 2 / 9); // 2 / 9 : 1920x1080 -> 426x240 #endif