fix: Help Overlay centrado correcto en modo F3 letterbox

Problemas resueltos:
- En modo F3 (letterbox), el overlay se centraba en pantalla física
  en lugar de en el viewport visible, quedando desplazado
- Al salir de F3 a ventana, el overlay seguía roto
- Padding inferior no se respetaba correctamente

Cambios implementados:
1. render() ahora usa SDL_GetRenderViewport() para obtener área visible
2. Centrado calculado dentro del viewport (con offset de barras negras)
3. toggleFullscreen() restaura tamaño de ventana al salir de F3
4. Padding check movido ANTES de escribir línea (>= en lugar de >)
5. Debug logging añadido para diagnóstico de dimensiones

Resultado:
 Overlay centrado correctamente en F3 letterbox
 Overlay se regenera correctamente al salir de F3
 Padding inferior respetado en columna 0

Pendiente:
- Columna 2 (índice 1) todavía no respeta padding inferior
- Verificar que F4 (real fullscreen) siga funcionando correctamente

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-17 07:30:31 +02:00
parent 1b3d32ba84
commit bcceb94c9e
4 changed files with 190 additions and 10 deletions

View File

@@ -86,6 +86,13 @@ HelpOverlay::~HelpOverlay() {
delete text_renderer_;
}
void HelpOverlay::toggle() {
visible_ = !visible_;
SDL_Log("HelpOverlay::toggle() - visible=%s, box_pos=(%d,%d), box_size=%dx%d, physical=%dx%d",
visible_ ? "TRUE" : "FALSE", box_x_, box_y_, box_width_, box_height_,
physical_width_, physical_height_);
}
void HelpOverlay::initialize(SDL_Renderer* renderer, ThemeManager* theme_mgr, int physical_width, int physical_height, int font_size) {
renderer_ = renderer;
theme_mgr_ = theme_mgr;
@@ -96,7 +103,12 @@ void HelpOverlay::initialize(SDL_Renderer* renderer, ThemeManager* theme_mgr, in
text_renderer_ = new TextRenderer();
text_renderer_->init(renderer, "data/fonts/FunnelSans-Regular.ttf", font_size, true);
SDL_Log("HelpOverlay::initialize() - physical=%dx%d, font_size=%d", physical_width, physical_height, font_size);
calculateBoxDimensions();
SDL_Log("HelpOverlay::initialize() - AFTER calculateBoxDimensions: box_pos=(%d,%d), box_size=%dx%d",
box_x_, box_y_, box_width_, box_height_);
}
void HelpOverlay::updatePhysicalWindowSize(int physical_width, int physical_height) {
@@ -123,6 +135,11 @@ void HelpOverlay::reinitializeFontSize(int new_font_size) {
}
void HelpOverlay::updateAll(int font_size, int physical_width, int physical_height) {
SDL_Log("HelpOverlay::updateAll() - INPUT: font_size=%d, physical=%dx%d",
font_size, physical_width, physical_height);
SDL_Log("HelpOverlay::updateAll() - BEFORE: box_pos=(%d,%d), box_size=%dx%d",
box_x_, box_y_, box_width_, box_height_);
// Actualizar dimensiones físicas PRIMERO
physical_width_ = physical_width;
physical_height_ = physical_height;
@@ -137,6 +154,9 @@ void HelpOverlay::updateAll(int font_size, int physical_width, int physical_heig
// Marcar textura para regeneración completa
texture_needs_rebuild_ = true;
SDL_Log("HelpOverlay::updateAll() - AFTER: box_pos=(%d,%d), box_size=%dx%d",
box_x_, box_y_, box_width_, box_height_);
}
void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) {
@@ -226,10 +246,15 @@ void HelpOverlay::calculateTextDimensions(int& max_width, int& total_height) {
}
void HelpOverlay::calculateBoxDimensions() {
SDL_Log("HelpOverlay::calculateBoxDimensions() START - physical=%dx%d", physical_width_, physical_height_);
// Calcular dimensiones necesarias según el texto
int text_width, text_height;
calculateTextDimensions(text_width, text_height);
SDL_Log("HelpOverlay::calculateBoxDimensions() - text_width=%d, text_height=%d, col1_width=%d, col2_width=%d",
text_width, text_height, column1_width_, column2_width_);
// Usar directamente el ancho y altura calculados según el contenido
box_width_ = text_width;
@@ -240,11 +265,17 @@ void HelpOverlay::calculateBoxDimensions() {
// Centrar en pantalla
box_x_ = (physical_width_ - box_width_) / 2;
box_y_ = (physical_height_ - box_height_) / 2;
SDL_Log("HelpOverlay::calculateBoxDimensions() END - box_pos=(%d,%d), box_size=%dx%d, max_height=%d",
box_x_, box_y_, box_width_, box_height_, max_height);
}
void HelpOverlay::rebuildCachedTexture() {
if (!renderer_ || !theme_mgr_ || !text_renderer_) return;
SDL_Log("HelpOverlay::rebuildCachedTexture() - Regenerando textura: box_size=%dx%d, box_pos=(%d,%d)",
box_width_, box_height_, box_x_, box_y_);
// Destruir textura anterior si existe
if (cached_texture_) {
SDL_DestroyTexture(cached_texture_);
@@ -354,6 +385,14 @@ void HelpOverlay::rebuildCachedTexture() {
continue;
}
// CHECK PADDING INFERIOR ANTES de escribir la línea (solo para columna 0)
// Verificar si la PRÓXIMA línea cabrá dentro del box con padding inferior
if (current_y + line_height >= box_height_ - padding && current_column == 0) {
current_column = 1;
current_x = padding + column1_width_ + padding;
current_y = content_start_y;
}
if (binding.description[0] == '\0') {
text_renderer_->printAbsolute(current_x, current_y, binding.key, category_color);
current_y += line_height + 2;
@@ -365,12 +404,6 @@ void HelpOverlay::rebuildCachedTexture() {
text_renderer_->printAbsolute(current_x + key_width + 10, current_y, binding.description, content_color);
current_y += line_height;
if (current_y > box_height_ - padding && current_column == 0) {
current_column = 1;
current_x = padding + column1_width_ + padding; // Usar ancho real de columna 1
current_y = content_start_y;
}
}
// Restaurar render target original
@@ -421,10 +454,23 @@ void HelpOverlay::render(SDL_Renderer* renderer) {
// CRÍTICO: Habilitar alpha blending para que la transparencia funcione
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
// Renderizar la textura cacheada en la posición del overlay
// Obtener viewport actual (en modo letterbox F3 tiene offset para centrar imagen)
SDL_Rect viewport;
SDL_GetRenderViewport(renderer, &viewport);
// Calcular posición centrada dentro del VIEWPORT, no de la pantalla física
// viewport.w y viewport.h son las dimensiones del área visible
// viewport.x y viewport.y son el offset de las barras negras
int centered_x = viewport.x + (viewport.w - box_width_) / 2;
int centered_y = viewport.y + (viewport.h - box_height_) / 2;
SDL_Log("HelpOverlay::render() - viewport=(%d,%d,%dx%d), centered_pos=(%d,%d), box_size=%dx%d",
viewport.x, viewport.y, viewport.w, viewport.h, centered_x, centered_y, box_width_, box_height_);
// Renderizar la textura cacheada centrada en el viewport
SDL_FRect dest_rect;
dest_rect.x = static_cast<float>(box_x_);
dest_rect.y = static_cast<float>(box_y_);
dest_rect.x = static_cast<float>(centered_x);
dest_rect.y = static_cast<float>(centered_y);
dest_rect.w = static_cast<float>(box_width_);
dest_rect.h = static_cast<float>(box_height_);

View File

@@ -52,7 +52,7 @@ class HelpOverlay {
/**
* @brief Toggle visibilidad del overlay
*/
void toggle() { visible_ = !visible_; }
void toggle();
/**
* @brief Consulta si el overlay está visible