window: max_zoom derivat del display via Screen::detectMaxZoom()

This commit is contained in:
2026-05-17 17:46:49 +02:00
parent 7006207b7e
commit 659e37e5a1
4 changed files with 49 additions and 6 deletions
+30 -2
View File
@@ -282,7 +282,7 @@ auto Screen::decWindowZoom() -> bool {
auto Screen::incWindowZoom() -> bool {
if (Options::video.fullscreen) { return false; }
const int PREV = Options::window.zoom;
Options::window.zoom = std::min(Options::window.zoom + 1, WINDOW_ZOOM_MAX);
Options::window.zoom = std::min(Options::window.zoom + 1, Options::window.max_zoom);
if (Options::window.zoom == PREV) { return false; }
setVideoMode(false);
return true;
@@ -291,13 +291,41 @@ auto Screen::incWindowZoom() -> bool {
// Establece el zoom de la ventana directamente
auto Screen::setWindowZoom(int zoom) -> bool {
if (Options::video.fullscreen) { return false; }
if (zoom < WINDOW_ZOOM_MIN || zoom > WINDOW_ZOOM_MAX) { return false; }
if (zoom < WINDOW_ZOOM_MIN || zoom > Options::window.max_zoom) { return false; }
if (zoom == Options::window.zoom) { return false; }
Options::window.zoom = zoom;
setVideoMode(false);
return true;
}
// Detecta el zoom màxim windowed segons la resolució del display actual.
void Screen::detectMaxZoom() {
#ifdef __EMSCRIPTEN__
// En WASM el tamany del canvas el fixa el browser; el zoom no aplica.
return;
#else
int num_displays = 0;
SDL_DisplayID *displays = SDL_GetDisplays(&num_displays);
if (displays == nullptr || num_displays == 0) {
if (displays != nullptr) { SDL_free(displays); }
return;
}
const auto *dm = SDL_GetCurrentDisplayMode(displays[0]);
if (dm != nullptr) {
const int MAX_W = dm->w / GAMECANVAS_WIDTH;
const int MAX_H = (dm->h - WINDOWS_DECORATIONS) / GAMECANVAS_HEIGHT;
const int DETECTED = std::max(WINDOW_ZOOM_MIN, std::min(MAX_W, MAX_H));
Options::window.max_zoom = DETECTED;
Options::window.zoom = std::clamp(Options::window.zoom, WINDOW_ZOOM_MIN, DETECTED);
if (Options::settings.console) {
std::cout << "Display " << dm->w << "x" << dm->h
<< " → max windowed zoom = " << DETECTED << "x\n";
}
}
SDL_free(displays);
#endif
}
// Establece el escalado entero
void Screen::setIntegerScale(bool enabled) {
if (Options::video.integer_scale == enabled) { return; }