fix: HUD de debug alineado correcto en viewport (F3 letterbox)

Problema:
- Columna derecha del HUD (FPS, info de pelota) se alineaba usando dimensión física
- En modo letterbox (F3 INTEGER/LETTERBOX) aparecía en barras negras o fuera de pantalla
- Mismo issue que tenían Notifier y Help Overlay

Causa:
- ui_manager.cpp:renderDebugHUD() usaba `physical_window_width_` para alinear a la derecha
- En F3 letterbox: viewport visible < ventana física
- Ejemplo: ventana 1920px, viewport 1280px con offset 320px
- Cálculo: fps_x = 1920 - width - margin
- printAbsolute() aplicaba offset: 1920 - width + 320 = fuera de pantalla
- Resultado: texto del HUD invisible o en barras negras

Solución:
- Obtener viewport con SDL_GetRenderViewport() al inicio de renderDebugHUD()
- Reemplazar TODAS las referencias a `physical_window_width_` con `viewport.w`
- Coordenadas relativas al viewport, printAbsolute() aplica offset automáticamente

Código modificado:
- ui_manager.cpp:208-211 - Obtención de viewport
- ui_manager.cpp:315, 326, 333, 340, 347, 353, 360, 366, 375 - Alineación con viewport.w

Líneas afectadas (9 totales):
- FPS counter
- Posición X/Y primera pelota
- Velocidad X/Y
- Fuerza de gravedad
- Estado superficie
- Coeficiente de rebote (loss)
- Dirección de gravedad
- Convergencia (LOGO mode)

Resultado:
 HUD de debug alineado correctamente al borde derecho del viewport
 Columna derecha visible dentro del área de juego
 No aparece en barras negras en F3
 Funciona correctamente en ventana, F3 y F4

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-17 07:47:50 +02:00
parent 5b674c8ea6
commit 9b8afa1219

View File

@@ -205,6 +205,11 @@ void UIManager::renderDebugHUD(const Engine* engine,
int line_height = text_renderer_debug_->getTextHeight();
int margin = 8; // Margen constante en píxeles físicos
// Obtener viewport actual (en modo letterbox F3 tiene dimensiones más pequeñas)
// CRÍTICO: Usar dimensiones del VIEWPORT para alineación, no de la ventana física
SDL_Rect viewport;
SDL_GetRenderViewport(renderer_, &viewport);
// ===========================
// COLUMNA LEFT (Sistema)
// ===========================
@@ -307,7 +312,7 @@ void UIManager::renderDebugHUD(const Engine* engine,
// FPS counter (esquina superior derecha)
int fps_text_width = text_renderer_debug_->getTextWidthPhysical(fps_text_.c_str());
int fps_x = physical_window_width_ - fps_text_width - margin;
int fps_x = viewport.w - fps_text_width - margin;
text_renderer_debug_->printAbsolute(fps_x, right_y, fps_text_.c_str(), {255, 255, 0, 255}); // Amarillo
right_y += line_height;
@@ -318,47 +323,47 @@ void UIManager::renderDebugHUD(const Engine* engine,
SDL_FRect pos = first_ball->getPosition();
std::string pos_text = "Pos: (" + std::to_string(static_cast<int>(pos.x)) + ", " + std::to_string(static_cast<int>(pos.y)) + ")";
int pos_width = text_renderer_debug_->getTextWidthPhysical(pos_text.c_str());
text_renderer_debug_->printAbsolute(physical_window_width_ - pos_width - margin, right_y, pos_text.c_str(), {255, 128, 128, 255}); // Rojo claro
text_renderer_debug_->printAbsolute(viewport.w - pos_width - margin, right_y, pos_text.c_str(), {255, 128, 128, 255}); // Rojo claro
right_y += line_height;
// Velocidad X
int vx_int = static_cast<int>(first_ball->getVelocityX());
std::string vx_text = "VelX: " + std::to_string(vx_int);
int vx_width = text_renderer_debug_->getTextWidthPhysical(vx_text.c_str());
text_renderer_debug_->printAbsolute(physical_window_width_ - vx_width - margin, right_y, vx_text.c_str(), {128, 255, 128, 255}); // Verde claro
text_renderer_debug_->printAbsolute(viewport.w - vx_width - margin, right_y, vx_text.c_str(), {128, 255, 128, 255}); // Verde claro
right_y += line_height;
// Velocidad Y
int vy_int = static_cast<int>(first_ball->getVelocityY());
std::string vy_text = "VelY: " + std::to_string(vy_int);
int vy_width = text_renderer_debug_->getTextWidthPhysical(vy_text.c_str());
text_renderer_debug_->printAbsolute(physical_window_width_ - vy_width - margin, right_y, vy_text.c_str(), {128, 255, 128, 255}); // Verde claro
text_renderer_debug_->printAbsolute(viewport.w - vy_width - margin, right_y, vy_text.c_str(), {128, 255, 128, 255}); // Verde claro
right_y += line_height;
// Fuerza de gravedad
int grav_int = static_cast<int>(first_ball->getGravityForce());
std::string grav_text = "Gravity: " + std::to_string(grav_int);
int grav_width = text_renderer_debug_->getTextWidthPhysical(grav_text.c_str());
text_renderer_debug_->printAbsolute(physical_window_width_ - grav_width - margin, right_y, grav_text.c_str(), {255, 255, 128, 255}); // Amarillo claro
text_renderer_debug_->printAbsolute(viewport.w - grav_width - margin, right_y, grav_text.c_str(), {255, 255, 128, 255}); // Amarillo claro
right_y += line_height;
// Estado superficie
std::string surface_text = first_ball->isOnSurface() ? "Surface: YES" : "Surface: NO";
int surface_width = text_renderer_debug_->getTextWidthPhysical(surface_text.c_str());
text_renderer_debug_->printAbsolute(physical_window_width_ - surface_width - margin, right_y, surface_text.c_str(), {255, 200, 128, 255}); // Naranja claro
text_renderer_debug_->printAbsolute(viewport.w - surface_width - margin, right_y, surface_text.c_str(), {255, 200, 128, 255}); // Naranja claro
right_y += line_height;
// Coeficiente de rebote (loss)
float loss_val = first_ball->getLossCoefficient();
std::string loss_text = "Loss: " + std::to_string(loss_val).substr(0, 4);
int loss_width = text_renderer_debug_->getTextWidthPhysical(loss_text.c_str());
text_renderer_debug_->printAbsolute(physical_window_width_ - loss_width - margin, right_y, loss_text.c_str(), {255, 128, 255, 255}); // Magenta
text_renderer_debug_->printAbsolute(viewport.w - loss_width - margin, right_y, loss_text.c_str(), {255, 128, 255, 255}); // Magenta
right_y += line_height;
// Dirección de gravedad
std::string gravity_dir_text = "Dir: " + gravityDirectionToString(static_cast<int>(scene_manager->getCurrentGravity()));
int dir_width = text_renderer_debug_->getTextWidthPhysical(gravity_dir_text.c_str());
text_renderer_debug_->printAbsolute(physical_window_width_ - dir_width - margin, right_y, gravity_dir_text.c_str(), {128, 255, 255, 255}); // Cian claro
text_renderer_debug_->printAbsolute(viewport.w - dir_width - margin, right_y, gravity_dir_text.c_str(), {128, 255, 255, 255}); // Cian claro
right_y += line_height;
}
@@ -367,7 +372,7 @@ void UIManager::renderDebugHUD(const Engine* engine,
int convergence_percent = static_cast<int>(shape_convergence * 100.0f);
std::string convergence_text = "Convergence: " + std::to_string(convergence_percent) + "%";
int conv_width = text_renderer_debug_->getTextWidthPhysical(convergence_text.c_str());
text_renderer_debug_->printAbsolute(physical_window_width_ - conv_width - margin, right_y, convergence_text.c_str(), {255, 128, 0, 255}); // Naranja
text_renderer_debug_->printAbsolute(viewport.w - conv_width - margin, right_y, convergence_text.c_str(), {255, 128, 0, 255}); // Naranja
right_y += line_height;
}
}