From d2f170d313db70ae2f4a88e38a439ffdf989aceb Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 10 Oct 2025 09:39:17 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20HUD=20debug=20usa=20coordenadas=20f?= =?UTF-8?q?=C3=ADsicas=20absolutas=20(como=20notificaciones)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migra el sistema de renderizado de HUD debug desde printPhysical() (coordenadas lógicas escaladas) a printAbsolute() (píxeles físicos absolutos). ## Cambios **engine.cpp (líneas 830-951):** - Eliminadas líneas de cálculo de factores de escala (text_scale_x/y) - Todas las coordenadas ahora en píxeles físicos absolutos - FPS: `physical_window_width_ - text_width - margin` (esquina derecha física) - 10 llamadas printPhysical() → printAbsolute() con SDL_Color - 4 llamadas getTextWidth() → getTextWidthPhysical() ## Resultado ✅ HUD de tamaño fijo independiente de resolución lógica ✅ FPS siempre pegado a esquina derecha física ✅ Espaciado constante entre líneas ✅ Funciona en modo ventana y F4 (stretch fullscreen) ⚠️ PENDIENTE: Ajustar offset para modo F3 con letterbox 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- source/engine.cpp | 50 ++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/source/engine.cpp b/source/engine.cpp index d62a778..4c37678 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -827,10 +827,6 @@ void Engine::render() { SDL_RenderGeometry(renderer_, texture_->getSDLTexture(), batch_vertices_.data(), static_cast(batch_vertices_.size()), batch_indices_.data(), static_cast(batch_indices_.size())); } - // Calcular factores de escala lógica → física para texto absoluto - float text_scale_x = static_cast(physical_window_width_) / static_cast(current_screen_width_); - float text_scale_y = static_cast(physical_window_height_) / static_cast(current_screen_height_); - // SISTEMA DE TEXTO ANTIGUO DESHABILITADO // Reemplazado completamente por el sistema de notificaciones (Notifier) // El doble renderizado causaba que aparecieran textos duplicados detrás de las notificaciones @@ -865,16 +861,16 @@ void Engine::render() { if (show_debug_) { // Obtener altura de línea para espaciado dinámico (usando fuente debug) int line_height = text_renderer_debug_.getTextHeight(); - int margin = 8; // Margen constante - int current_y = margin; // Y inicial + int margin = 8; // Margen constante en píxeles físicos + int current_y = margin; // Y inicial en píxeles físicos // Mostrar contador de FPS en esquina superior derecha - int fps_text_width = text_renderer_debug_.getTextWidth(fps_text_.c_str()); - int fps_x = current_screen_width_ - fps_text_width - margin; - text_renderer_debug_.printPhysical(fps_x, current_y, fps_text_.c_str(), 255, 255, 0, text_scale_x, text_scale_y); // Amarillo + int fps_text_width = text_renderer_debug_.getTextWidthPhysical(fps_text_.c_str()); + int fps_x = physical_window_width_ - fps_text_width - margin; + text_renderer_debug_.printAbsolute(fps_x, current_y, fps_text_.c_str(), {255, 255, 0, 255}); // Amarillo // Mostrar estado V-Sync en esquina superior izquierda - text_renderer_debug_.printPhysical(margin, current_y, vsync_text_.c_str(), 0, 255, 255, text_scale_x, text_scale_y); // Cian + text_renderer_debug_.printAbsolute(margin, current_y, vsync_text_.c_str(), {0, 255, 255, 255}); // Cian current_y += line_height; // Debug: Mostrar valores de la primera pelota (si existe) @@ -882,35 +878,35 @@ void Engine::render() { // Línea 1: Gravedad int grav_int = static_cast(balls_[0]->getGravityForce()); std::string grav_text = "Gravedad: " + std::to_string(grav_int); - text_renderer_debug_.printPhysical(margin, current_y, grav_text.c_str(), 255, 0, 255, text_scale_x, text_scale_y); // Magenta + text_renderer_debug_.printAbsolute(margin, current_y, grav_text.c_str(), {255, 0, 255, 255}); // Magenta current_y += line_height; // Línea 2: Velocidad Y int vy_int = static_cast(balls_[0]->getVelocityY()); std::string vy_text = "Velocidad Y: " + std::to_string(vy_int); - text_renderer_debug_.printPhysical(margin, current_y, vy_text.c_str(), 255, 0, 255, text_scale_x, text_scale_y); // Magenta + text_renderer_debug_.printAbsolute(margin, current_y, vy_text.c_str(), {255, 0, 255, 255}); // Magenta current_y += line_height; // Línea 3: Estado superficie std::string surface_text = balls_[0]->isOnSurface() ? "Superficie: Sí" : "Superficie: No"; - text_renderer_debug_.printPhysical(margin, current_y, surface_text.c_str(), 255, 0, 255, text_scale_x, text_scale_y); // Magenta + text_renderer_debug_.printAbsolute(margin, current_y, surface_text.c_str(), {255, 0, 255, 255}); // Magenta current_y += line_height; // Línea 4: Coeficiente de rebote (loss) float loss_val = balls_[0]->getLossCoefficient(); std::string loss_text = "Rebote: " + std::to_string(loss_val).substr(0, 4); - text_renderer_debug_.printPhysical(margin, current_y, loss_text.c_str(), 255, 0, 255, text_scale_x, text_scale_y); // Magenta + text_renderer_debug_.printAbsolute(margin, current_y, loss_text.c_str(), {255, 0, 255, 255}); // Magenta current_y += line_height; // Línea 5: Dirección de gravedad std::string gravity_dir_text = "Dirección: " + gravityDirectionToString(current_gravity_); - text_renderer_debug_.printPhysical(margin, current_y, gravity_dir_text.c_str(), 255, 255, 0, text_scale_x, text_scale_y); // Amarillo + text_renderer_debug_.printAbsolute(margin, current_y, gravity_dir_text.c_str(), {255, 255, 0, 255}); // Amarillo current_y += line_height; } // Debug: Mostrar tema actual (delegado a ThemeManager) std::string theme_text = std::string("Tema: ") + theme_manager_->getCurrentThemeNameEN(); - text_renderer_debug_.printPhysical(margin, current_y, theme_text.c_str(), 255, 255, 128, text_scale_x, text_scale_y); // Amarillo claro + text_renderer_debug_.printAbsolute(margin, current_y, theme_text.c_str(), {255, 255, 128, 255}); // Amarillo claro current_y += line_height; // Debug: Mostrar modo de simulación actual @@ -922,14 +918,14 @@ void Engine::render() { } else { mode_text = "Modo: Forma"; } - text_renderer_debug_.printPhysical(margin, current_y, mode_text.c_str(), 0, 255, 128, text_scale_x, text_scale_y); // Verde claro + text_renderer_debug_.printAbsolute(margin, current_y, mode_text.c_str(), {0, 255, 128, 255}); // Verde claro current_y += line_height; // Debug: Mostrar convergencia en modo LOGO (solo cuando está activo) if (current_app_mode_ == AppMode::LOGO && current_mode_ == SimulationMode::SHAPE) { int convergence_percent = static_cast(shape_convergence_ * 100.0f); std::string convergence_text = "Convergencia: " + std::to_string(convergence_percent) + "%"; - text_renderer_debug_.printPhysical(margin, current_y, convergence_text.c_str(), 255, 128, 0, text_scale_x, text_scale_y); // Naranja + text_renderer_debug_.printAbsolute(margin, current_y, convergence_text.c_str(), {255, 128, 0, 255}); // Naranja current_y += line_height; } @@ -938,19 +934,19 @@ void Engine::render() { int fixed_y = margin + (line_height * 2); // Tercera fila fija if (current_app_mode_ == AppMode::LOGO) { const char* logo_text = "Modo Logo"; - int logo_text_width = text_renderer_debug_.getTextWidth(logo_text); - int logo_x = (current_screen_width_ - logo_text_width) / 2; - text_renderer_debug_.printPhysical(logo_x, fixed_y, logo_text, 255, 128, 0, text_scale_x, text_scale_y); // Naranja + int logo_text_width = text_renderer_debug_.getTextWidthPhysical(logo_text); + int logo_x = (physical_window_width_ - logo_text_width) / 2; + text_renderer_debug_.printAbsolute(logo_x, fixed_y, logo_text, {255, 128, 0, 255}); // Naranja } else if (current_app_mode_ == AppMode::DEMO) { const char* demo_text = "Modo Demo"; - int demo_text_width = text_renderer_debug_.getTextWidth(demo_text); - int demo_x = (current_screen_width_ - demo_text_width) / 2; - text_renderer_debug_.printPhysical(demo_x, fixed_y, demo_text, 255, 165, 0, text_scale_x, text_scale_y); // Naranja + int demo_text_width = text_renderer_debug_.getTextWidthPhysical(demo_text); + int demo_x = (physical_window_width_ - demo_text_width) / 2; + text_renderer_debug_.printAbsolute(demo_x, fixed_y, demo_text, {255, 165, 0, 255}); // Naranja } else if (current_app_mode_ == AppMode::DEMO_LITE) { const char* lite_text = "Modo Demo Lite"; - int lite_text_width = text_renderer_debug_.getTextWidth(lite_text); - int lite_x = (current_screen_width_ - lite_text_width) / 2; - text_renderer_debug_.printPhysical(lite_x, fixed_y, lite_text, 255, 200, 0, text_scale_x, text_scale_y); // Amarillo-naranja + int lite_text_width = text_renderer_debug_.getTextWidthPhysical(lite_text); + int lite_x = (physical_window_width_ - lite_text_width) / 2; + text_renderer_debug_.printAbsolute(lite_x, fixed_y, lite_text, {255, 200, 0, 255}); // Amarillo-naranja } }