Afegides comprobacions de valors per al fitxer de configuració

This commit is contained in:
2025-02-28 11:34:51 +01:00
parent 366fe404ca
commit 3992fc08bf
3 changed files with 115 additions and 34 deletions

View File

@@ -40,6 +40,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
: window_(window),
renderer_(renderer)
{
// Ajusta los tamaños
adjustGameCanvasRect();
adjustWindowSize();
@@ -343,6 +344,8 @@ void Screen::adjustWindowSize()
window_width_ = options.game.width + (options.video.border.enabled ? options.video.border.width * 2 : 0);
window_height_ = options.game.height + (options.video.border.enabled ? options.video.border.height * 2 : 0);
options.window.max_zoom = getMaxZoom();
// Establece el nuevo tamaño
if (options.video.mode == 0)
{
@@ -356,11 +359,8 @@ void Screen::adjustWindowSize()
int new_pos_y = old_pos_y + (old_height - (window_height_ * options.window.zoom)) / 2;
SDL_SetWindowSize(window_, window_width_ * options.window.zoom, window_height_ * options.window.zoom);
SDL_SetWindowPosition(window_, std::max(new_pos_x, 30), std::max(new_pos_y, 10));
SDL_SetWindowPosition(window_, std::max(new_pos_x, WINDOWS_DECORATIONS_), std::max(new_pos_y, 0));
}
options.window.max_zoom = getMaxZoom();
renderBlackFrame();
}
// Ajusta game_canvas_rect_
@@ -389,7 +389,12 @@ int Screen::getMaxZoom()
SDL_GetCurrentDisplayMode(0, &DM);
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
return std::min(DM.w / window_width_, DM.h / window_height_);
const int max_zoom = std::min(DM.w / window_width_, (DM.h - WINDOWS_DECORATIONS_) / window_height_);
// Normaliza los valores de zoom
options.window.zoom = std::min(options.window.zoom, max_zoom);
return max_zoom;
}
// Renderiza un frame negro