Files
vibe3_physics/source/ui/ui_manager.h
Sergio Valor 8aa2a112b4 fix: Enlazar SDL3_ttf en Makefile + corregir declaración SDL_Renderer
**Problema 1: Símbolos no definidos de SDL_ttf** (CRÍTICO)
- Error: "Undefined symbols: _TTF_Init, _TTF_OpenFont, etc."
- Causa: LDFLAGS solo incluía -lSDL3 (faltaba -lSDL3_ttf)
- Solución: Añadido -lSDL3_ttf a LDFLAGS para Unix/macOS (línea 81)
- Afecta: Linux, macOS y otros sistemas Unix

**Problema 2: Mismatch class/struct SDL_Renderer** (WARNING)
- Warning: "class 'SDL_Renderer' was previously declared as a struct"
- Causa: ui_manager.h:7 declaraba "class SDL_Renderer"
- SDL3 lo declara como "struct SDL_Renderer" (SDL_render.h:119)
- Solución: Cambiado class → struct en ui_manager.h:7
- Evita warnings y potenciales errores de linker en MSVC

**Resultado:**
 make macos_release completa exitosamente
 DMG creado: vibe3_physics-2025-10-19-macos-apple-silicon.dmg (17.9 MB)
 Sin errores de enlazado, solo warnings menores de versión macOS

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-19 09:00:01 +02:00

209 lines
7.8 KiB
C++

#pragma once
#include <SDL3/SDL_stdinc.h> // for Uint64
#include <string> // for std::string
// Forward declarations
struct SDL_Renderer;
class SceneManager;
class Shape;
class ThemeManager;
class TextRenderer;
class Notifier;
class HelpOverlay;
class Engine;
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 engine Puntero a Engine (para info de sistema)
* @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 Engine* engine,
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 engine Puntero a Engine (para info de sistema)
* @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 Engine* engine,
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;
/**
* @brief Calcula tamaño de fuente apropiado según dimensiones físicas
* @param physical_width Ancho físico de ventana
* @param physical_height Alto físico de ventana
* @return Tamaño de fuente (14px/18px/24px)
*/
int calculateFontSize(int physical_width, int physical_height) 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)
// === Sistema de escalado dinámico de texto ===
int current_font_size_; // Tamaño de fuente actual (14/18/24)
};