Files
vibe3_physics/source/ui/ui_manager.hpp
Sergio c9bcce6f9b style: aplicar fixes de clang-tidy (todo excepto uppercase-literal-suffix)
Corregidos ~2570 issues automáticamente con clang-tidy --fix-errors
más ajustes manuales posteriores:

- modernize: designated-initializers, trailing-return-type, use-auto,
  avoid-c-arrays (→ std::array<>), use-ranges, use-emplace,
  deprecated-headers, use-equals-default, pass-by-value,
  return-braced-init-list, use-default-member-init
- readability: math-missing-parentheses, implicit-bool-conversion,
  braces-around-statements, isolate-declaration, use-std-min-max,
  identifier-naming, else-after-return, redundant-casting,
  convert-member-functions-to-static, make-member-function-const,
  static-accessed-through-instance
- performance: avoid-endl, unnecessary-value-param, type-promotion,
  inefficient-vector-operation
- dead code: XOR_KEY (orphan tras eliminar encryptData/decryptData),
  dead stores en engine.cpp y png_shape.cpp
- NOLINT justificado en 10 funciones con alta complejidad cognitiva
  (initialize, render, main, processEvents, update×3, performDemoAction,
  randomizeOnDemoStart, renderDebugHUD, AppLogo::update)

Compilación: gcc -Wall sin warnings. clang-tidy: 0 issues.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 10:52:07 +01:00

187 lines
6.9 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)
* @param logical_width Ancho lógico (resolución interna)
* @param logical_height Alto lógico (resolución interna)
*/
void initialize(SDL_Renderer* renderer, ThemeManager* theme_manager, int physical_width, int physical_height, int logical_width, int logical_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
* @param logical_height Nuevo alto lógico (0 = sin cambio)
*/
void updatePhysicalWindowSize(int width, int height, int logical_height = 0);
// === 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.)
*/
static std::string gravityDirectionToString(int direction);
/**
* @brief Calcula tamaño de fuente apropiado según dimensiones lógicas
* @param logical_height Alto lógico (resolución interna, sin zoom)
* @return Tamaño de fuente (9-72px)
*/
static int calculateFontSize(int logical_height);
// === 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)
int logical_window_width_; // Ancho lógico (resolución interna)
int logical_window_height_; // Alto lógico (resolución interna)
// === Sistema de escalado dinámico de texto ===
int current_font_size_; // Tamaño de fuente actual (9-72px)
};