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; }
+9 -1
View File
@@ -21,7 +21,9 @@ class Screen {
public:
// Constantes
static constexpr int WINDOW_ZOOM_MIN = 1;
static constexpr int WINDOW_ZOOM_MAX = 4;
// Pixels reservats per a la barra de títol/decoracions a l'hora de
// calcular el zoom màxim windowed (mateix valor que CCAE/jaildoctors).
static constexpr int WINDOWS_DECORATIONS = 35;
#ifdef __EMSCRIPTEN__
// En WASM el tamaño de ventana está fijado a 1x, así que escalamos el
// renderizado por 3 aprovechando el modo NEAREST de la textura del juego
@@ -34,6 +36,12 @@ class Screen {
static void destroy(); // Libera la instancia
static auto get() -> Screen *; // Obtiene el puntero a la instancia
// Detecta el zoom màxim windowed segons la resolució del display actual.
// Cal cridar-la després de SDL_Init(VIDEO) i abans de crear la finestra.
// Escriu a `Options::window.max_zoom` i clampa `Options::window.zoom`.
// En Emscripten és no-op (el tamany del canvas el controla el browser).
static void detectMaxZoom();
// Destructor (público por requisitos de `delete` desde destroy())
~Screen();
+4
View File
@@ -269,6 +269,10 @@ auto Director::initSDL() -> bool {
// Inicia el generador de numeros aleatorios
std::srand(static_cast<unsigned int>(SDL_GetTicks()));
// Calcula el zoom màxim windowed segons el display actual i clampa
// `Options::window.zoom` abans de crear la finestra.
Screen::detectMaxZoom();
// Crea la ventana
window_ = SDL_CreateWindow(
Options::window.caption.c_str(),