Files
vibe3_physics/source/ui/ui_manager.hpp
Sergio Valor a9d7b66e83 Refactorizar estilo del proyecto: .h → .hpp, #pragma once, includes desde raíz
Modernizar convenciones de código C++ aplicando las siguientes directivas:

## Cambios principales

**1. Renombrar headers (.h → .hpp)**
- 36 archivos renombrados a extensión .hpp (estándar C++)
- Mantenidos como .h: stb_image.h, stb_image_resize2.h (librerías C externas)

**2. Modernizar include guards (#ifndef → #pragma once)**
- resource_manager.hpp: #ifndef RESOURCE_MANAGER_H → #pragma once
- resource_pack.hpp: #ifndef RESOURCE_PACK_H → #pragma once
- spatial_grid.hpp: #ifndef SPATIAL_GRID_H → #pragma once

**3. Sistema de includes desde raíz del proyecto**
- CMakeLists.txt: añadido include_directories(${CMAKE_SOURCE_DIR}/source)
- Eliminadas rutas relativas (../) en todos los includes
- Includes ahora usan rutas absolutas desde source/

**Antes:**
```cpp
#include "../defines.h"
#include "../text/textrenderer.h"
```

**Ahora:**
```cpp
#include "defines.hpp"
#include "text/textrenderer.hpp"
```

## Archivos afectados

- 1 archivo CMakeLists.txt modificado
- 36 archivos renombrados (.h → .hpp)
- 32 archivos .cpp actualizados (includes)
- 36 archivos .hpp actualizados (includes + guards)
- 1 archivo tools/ actualizado

**Total: 70 archivos modificados**

## Verificación

 Proyecto compila sin errores
 Todas las rutas de includes correctas
 Include guards modernizados
 Librerías externas C mantienen extensión .h

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-23 13:49:58 +02:00

183 lines
6.7 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);
// === Getters ===
/**
* @brief Verifica si debug HUD está activo
*/
bool isDebugActive() const { return show_debug_; }
/**
* @brief Obtiene FPS actual
*/
int getCurrentFPS() const { return fps_current_; }
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 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_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)
// === 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)
};