From adfa315a43d78970f3db94ca7986acbc181b8034 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 12 Oct 2025 15:04:24 +0200 Subject: [PATCH] fix: ui_manager.h estava sent ignorat per .gitignore --- .gitignore | 1 - source/ui/ui_manager.h | 192 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 source/ui/ui_manager.h diff --git a/.gitignore b/.gitignore index f03f796..07b503a 100644 --- a/.gitignore +++ b/.gitignore @@ -57,7 +57,6 @@ Makefile moc_*.cpp moc_*.h qrc_*.cpp -ui_*.h *.qm .qmake.stash diff --git a/source/ui/ui_manager.h b/source/ui/ui_manager.h new file mode 100644 index 0000000..ec677b8 --- /dev/null +++ b/source/ui/ui_manager.h @@ -0,0 +1,192 @@ +#pragma once + +#include // for Uint64 +#include // for std::string + +// Forward declarations +class SDL_Renderer; +class SceneManager; +class Shape; +class ThemeManager; +class TextRenderer; +class Notifier; +class HelpOverlay; +enum class SimulationMode; +enum class AppMode; + +/** + * @class UIManager + * @brief Gestiona toda la interfaz de usuario (HUD, FPS, debug, notificaciones) + * + * Responsabilidad única: Renderizado y actualización de elementos UI + * + * Características: + * - HUD de debug (gravedad, velocidad, FPS, V-Sync) + * - Contador de FPS en tiempo real + * - Sistema de notificaciones (Notifier) + * - Texto obsoleto (sistema legacy) + * - Gestión de TextRenderers + */ +class UIManager { + public: + /** + * @brief Constructor + */ + UIManager(); + + /** + * @brief Destructor - Libera TextRenderers y Notifier + */ + ~UIManager(); + + /** + * @brief Inicializa el UIManager con recursos SDL + * @param renderer Renderizador SDL3 + * @param theme_manager Gestor de temas (para colores) + * @param physical_width Ancho físico de ventana (píxeles reales) + * @param physical_height Alto físico de ventana (píxeles reales) + */ + void initialize(SDL_Renderer* renderer, ThemeManager* theme_manager, + int physical_width, int physical_height); + + /** + * @brief Actualiza UI (FPS counter, notificaciones, texto obsoleto) + * @param current_time Tiempo actual en milisegundos (SDL_GetTicks) + * @param delta_time Delta time en segundos + */ + void update(Uint64 current_time, float delta_time); + + /** + * @brief Renderiza todos los elementos UI + * @param renderer Renderizador SDL3 + * @param scene_manager SceneManager (para info de debug) + * @param current_mode Modo de simulación actual (PHYSICS/SHAPE) + * @param current_app_mode Modo de aplicación (SANDBOX/DEMO/LOGO) + * @param active_shape Figura 3D activa (para nombre en debug) + * @param shape_convergence % de convergencia en LOGO mode (0.0-1.0) + * @param physical_width Ancho físico de ventana (para texto absoluto) + * @param physical_height Alto físico de ventana (para texto absoluto) + * @param current_screen_width Ancho lógico de pantalla (para texto centrado) + */ + void render(SDL_Renderer* renderer, + const SceneManager* scene_manager, + SimulationMode current_mode, + AppMode current_app_mode, + const Shape* active_shape, + float shape_convergence, + int physical_width, + int physical_height, + int current_screen_width); + + /** + * @brief Toggle del debug HUD (tecla F12) + */ + void toggleDebug(); + + /** + * @brief Toggle del overlay de ayuda (tecla H) + */ + void toggleHelp(); + + /** + * @brief Muestra una notificación en pantalla + * @param text Texto a mostrar + * @param duration Duración en milisegundos (0 = usar default) + */ + void showNotification(const std::string& text, Uint64 duration = 0); + + /** + * @brief Actualiza texto de V-Sync en HUD + * @param enabled true si V-Sync está activado + */ + void updateVSyncText(bool enabled); + + /** + * @brief Actualiza tamaño físico de ventana (cambios de fullscreen) + * @param width Nuevo ancho físico + * @param height Nuevo alto físico + */ + void updatePhysicalWindowSize(int width, int height); + + /** + * @brief Establece texto obsoleto (DEPRECATED - usar Notifier en su lugar) + * @param text Texto a mostrar + * @param pos Posición X del texto + * @param current_screen_width Ancho de pantalla (para cálculos) + */ + void setTextObsolete(const std::string& text, int pos, int current_screen_width); + + // === Getters === + + /** + * @brief Verifica si debug HUD está activo + */ + bool isDebugActive() const { return show_debug_; } + + /** + * @brief Obtiene FPS actual + */ + int getCurrentFPS() const { return fps_current_; } + + /** + * @brief Verifica si texto obsoleto está visible + */ + bool isTextObsoleteVisible() const { return show_text_; } + + private: + /** + * @brief Renderiza HUD de debug (solo si show_debug_ == true) + * @param scene_manager SceneManager (para info de pelotas) + * @param current_mode Modo de simulación (PHYSICS/SHAPE) + * @param current_app_mode Modo de aplicación (SANDBOX/DEMO/LOGO) + * @param active_shape Figura 3D activa (puede ser nullptr) + * @param shape_convergence % de convergencia en LOGO mode + */ + void renderDebugHUD(const SceneManager* scene_manager, + SimulationMode current_mode, + AppMode current_app_mode, + const Shape* active_shape, + float shape_convergence); + + /** + * @brief Renderiza texto obsoleto centrado (DEPRECATED) + * @param current_screen_width Ancho lógico de pantalla + */ + void renderObsoleteText(int current_screen_width); + + /** + * @brief Convierte dirección de gravedad a string + * @param direction Dirección como int (cast de GravityDirection) + * @return String en español ("Abajo", "Arriba", etc.) + */ + std::string gravityDirectionToString(int direction) const; + + // === Recursos de renderizado === + TextRenderer* text_renderer_; // Texto obsoleto (DEPRECATED) + TextRenderer* text_renderer_debug_; // HUD de debug + TextRenderer* text_renderer_notifier_; // Notificaciones + Notifier* notifier_; // Sistema de notificaciones + HelpOverlay* help_overlay_; // Overlay de ayuda (tecla H) + + // === Estado de UI === + bool show_debug_; // HUD de debug activo (tecla F12) + bool show_text_; // Texto obsoleto visible (DEPRECATED) + + // === Sistema de texto obsoleto (DEPRECATED) === + std::string text_; // Texto a mostrar + int text_pos_; // Posición X del texto + Uint64 text_init_time_; // Tiempo de inicio de texto + + // === Sistema de FPS === + Uint64 fps_last_time_; // Último tiempo de actualización de FPS + int fps_frame_count_; // Contador de frames + int fps_current_; // FPS actual + std::string fps_text_; // Texto "fps: XX" + std::string vsync_text_; // Texto "V-Sync: On/Off" + + // === Referencias externas === + SDL_Renderer* renderer_; // Renderizador SDL3 (referencia) + ThemeManager* theme_manager_; // Gestor de temas (para colores) + int physical_window_width_; // Ancho físico de ventana (píxeles reales) + int physical_window_height_; // Alto físico de ventana (píxeles reales) +};