Fix: Sistema de zoom y fullscreen con parámetros CLI
Corrige bugs críticos en el manejo de ventanas cuando se inician con parámetros de línea de comandos (-w, -h, -z). ## Problemas Resueltos **1. Zoom incorrecto con parámetros CLI** - El zoom calculado no se guardaba en current_window_zoom_ - F1/F2 usaban valor default (3) en lugar del zoom actual - Resultado: Posicionamiento erróneo de ventana al hacer zoom **2. Ventana no centrada al iniciar** - Faltaba SDL_SetWindowPosition() después de crear ventana - Ventana aparecía en posición aleatoria **3. F4 restauraba tamaño incorrecto** - toggleRealFullscreen() usaba DEFAULT_WINDOW_ZOOM hardcoded - Al salir de fullscreen real, ventana cambiaba de tamaño - No re-centraba ventana después de restaurar ## Cambios Implementados **engine.cpp:initialize() línea 86-87:** - Guardar zoom calculado en current_window_zoom_ antes de crear ventana - Asegura consistencia entre zoom real y zoom guardado **engine.cpp:initialize() línea 114-117:** - Centrar ventana con SDL_WINDOWPOS_CENTERED al iniciar - Solo si no está en modo fullscreen **engine.cpp:toggleRealFullscreen() línea 1174-1175:** - Usar current_window_zoom_ en lugar de DEFAULT_WINDOW_ZOOM - Re-centrar ventana con SDL_WINDOWPOS_CENTERED al salir de F4 ## Casos de Prueba Verificados ✅ Sin parámetros: vibe3_physics.exe ✅ Con resolución: vibe3_physics.exe -w 640 -h 480 ✅ Con zoom: vibe3_physics.exe -z 2 ✅ Combinado: vibe3_physics.exe -w 1920 -h 1080 -z 1 ## Teclas Afectadas - F1 (Zoom Out): ✅ Funciona correctamente - F2 (Zoom In): ✅ Funciona correctamente - F3 (Fullscreen Toggle): ✅ Funciona correctamente - F4 (Real Fullscreen): ✅ Ahora restaura tamaño correcto 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -83,6 +83,9 @@ bool Engine::initialize(int width, int height, int zoom, bool fullscreen) {
|
||||
window_zoom = 1;
|
||||
}
|
||||
|
||||
// Guardar zoom calculado ANTES de crear la ventana (para F1/F2/F3/F4)
|
||||
current_window_zoom_ = window_zoom;
|
||||
|
||||
// Calcular tamaño de ventana
|
||||
int window_width = logical_width * window_zoom;
|
||||
int window_height = logical_height * window_zoom;
|
||||
@@ -108,6 +111,11 @@ bool Engine::initialize(int width, int height, int zoom, bool fullscreen) {
|
||||
std::cout << "¡No se pudo crear la ventana! Error de SDL: " << SDL_GetError() << std::endl;
|
||||
success = false;
|
||||
} else {
|
||||
// Centrar ventana en pantalla si no está en fullscreen
|
||||
if (!fullscreen) {
|
||||
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
|
||||
// Crear renderizador
|
||||
renderer_ = SDL_CreateRenderer(window_, nullptr);
|
||||
if (renderer_ == nullptr) {
|
||||
@@ -1161,9 +1169,10 @@ void Engine::toggleRealFullscreen() {
|
||||
current_screen_width_ = base_screen_width_;
|
||||
current_screen_height_ = base_screen_height_;
|
||||
|
||||
// Restaurar ventana normal
|
||||
// Restaurar ventana normal con el zoom actual (no hardcoded)
|
||||
SDL_SetWindowFullscreen(window_, false);
|
||||
SDL_SetWindowSize(window_, base_screen_width_ * DEFAULT_WINDOW_ZOOM, base_screen_height_ * DEFAULT_WINDOW_ZOOM);
|
||||
SDL_SetWindowSize(window_, base_screen_width_ * current_window_zoom_, base_screen_height_ * current_window_zoom_);
|
||||
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
// Restaurar presentación lógica base
|
||||
SDL_SetRenderLogicalPresentation(renderer_, base_screen_width_, base_screen_height_, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
|
||||
|
||||
Reference in New Issue
Block a user