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>
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
#include "ui_manager.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include "ball.hpp" // for Ball
|
||||
#include "defines.hpp" // for TEXT_DURATION, NOTIFICATION_DURATION, AppMode, SimulationMode
|
||||
#include "engine.hpp" // for Engine (info de sistema)
|
||||
#include "scene/scene_manager.hpp" // for SceneManager
|
||||
#include "shapes/shape.hpp" // for Shape
|
||||
#include "text/textrenderer.hpp" // for TextRenderer
|
||||
#include "theme_manager.hpp" // for ThemeManager
|
||||
#include "notifier.hpp" // for Notifier
|
||||
#include "help_overlay.hpp" // for HelpOverlay
|
||||
#include "ball.hpp" // for Ball
|
||||
#include "defines.hpp" // for TEXT_DURATION, NOTIFICATION_DURATION, AppMode, SimulationMode
|
||||
#include "engine.hpp" // for Engine (info de sistema)
|
||||
#include "help_overlay.hpp" // for HelpOverlay
|
||||
#include "notifier.hpp" // for Notifier
|
||||
#include "scene/scene_manager.hpp" // for SceneManager
|
||||
#include "shapes/shape.hpp" // for Shape
|
||||
#include "text/textrenderer.hpp" // for TextRenderer
|
||||
#include "theme_manager.hpp" // for ThemeManager
|
||||
|
||||
// ============================================================================
|
||||
// HELPER: Obtener viewport en coordenadas físicas (no lógicas)
|
||||
@@ -20,9 +22,10 @@
|
||||
// SDL_GetRenderViewport() devuelve coordenadas LÓGICAS cuando hay presentación
|
||||
// lógica activa. Para obtener coordenadas FÍSICAS, necesitamos deshabilitar
|
||||
// temporalmente la presentación lógica.
|
||||
static SDL_Rect getPhysicalViewport(SDL_Renderer* renderer) {
|
||||
static auto getPhysicalViewport(SDL_Renderer* renderer) -> SDL_Rect {
|
||||
// Guardar estado actual de presentación lógica
|
||||
int logical_w = 0, logical_h = 0;
|
||||
int logical_w = 0;
|
||||
int logical_h = 0;
|
||||
SDL_RendererLogicalPresentation presentation_mode;
|
||||
SDL_GetRenderLogicalPresentation(renderer, &logical_w, &logical_h, &presentation_mode);
|
||||
|
||||
@@ -40,23 +43,23 @@ static SDL_Rect getPhysicalViewport(SDL_Renderer* renderer) {
|
||||
}
|
||||
|
||||
UIManager::UIManager()
|
||||
: text_renderer_debug_(nullptr)
|
||||
, text_renderer_notifier_(nullptr)
|
||||
, notifier_(nullptr)
|
||||
, help_overlay_(nullptr)
|
||||
, show_debug_(false)
|
||||
, fps_last_time_(0)
|
||||
, fps_frame_count_(0)
|
||||
, fps_current_(0)
|
||||
, fps_text_("FPS: 0")
|
||||
, vsync_text_("VSYNC ON")
|
||||
, renderer_(nullptr)
|
||||
, theme_manager_(nullptr)
|
||||
, physical_window_width_(0)
|
||||
, physical_window_height_(0)
|
||||
, logical_window_width_(0)
|
||||
, logical_window_height_(0)
|
||||
, current_font_size_(18) { // Tamaño por defecto (medium)
|
||||
: text_renderer_debug_(nullptr),
|
||||
text_renderer_notifier_(nullptr),
|
||||
notifier_(nullptr),
|
||||
help_overlay_(nullptr),
|
||||
show_debug_(false),
|
||||
fps_last_time_(0),
|
||||
fps_frame_count_(0),
|
||||
fps_current_(0),
|
||||
fps_text_("FPS: 0"),
|
||||
vsync_text_("VSYNC ON"),
|
||||
renderer_(nullptr),
|
||||
theme_manager_(nullptr),
|
||||
physical_window_width_(0),
|
||||
physical_window_height_(0),
|
||||
logical_window_width_(0),
|
||||
logical_window_height_(0),
|
||||
current_font_size_(18) { // Tamaño por defecto (medium)
|
||||
}
|
||||
|
||||
UIManager::~UIManager() {
|
||||
@@ -67,13 +70,15 @@ UIManager::~UIManager() {
|
||||
delete help_overlay_;
|
||||
}
|
||||
|
||||
void UIManager::initialize(SDL_Renderer* renderer, ThemeManager* theme_manager,
|
||||
int physical_width, int physical_height,
|
||||
int logical_width, int logical_height) {
|
||||
delete text_renderer_debug_; text_renderer_debug_ = nullptr;
|
||||
delete text_renderer_notifier_; text_renderer_notifier_ = nullptr;
|
||||
delete notifier_; notifier_ = nullptr;
|
||||
delete help_overlay_; help_overlay_ = nullptr;
|
||||
void UIManager::initialize(SDL_Renderer* renderer, ThemeManager* theme_manager, int physical_width, int physical_height, int logical_width, int logical_height) {
|
||||
delete text_renderer_debug_;
|
||||
text_renderer_debug_ = nullptr;
|
||||
delete text_renderer_notifier_;
|
||||
text_renderer_notifier_ = nullptr;
|
||||
delete notifier_;
|
||||
notifier_ = nullptr;
|
||||
delete help_overlay_;
|
||||
help_overlay_ = nullptr;
|
||||
|
||||
renderer_ = renderer;
|
||||
theme_manager_ = theme_manager;
|
||||
@@ -95,8 +100,7 @@ void UIManager::initialize(SDL_Renderer* renderer, ThemeManager* theme_manager,
|
||||
|
||||
// Crear y configurar sistema de notificaciones
|
||||
notifier_ = new Notifier();
|
||||
notifier_->init(renderer, text_renderer_notifier_, theme_manager_,
|
||||
physical_width, physical_height);
|
||||
notifier_->init(renderer, text_renderer_notifier_, theme_manager_, physical_width, physical_height);
|
||||
|
||||
// Crear y configurar sistema de ayuda (overlay)
|
||||
help_overlay_ = new HelpOverlay();
|
||||
@@ -123,30 +127,29 @@ void UIManager::update(Uint64 current_time, float delta_time) {
|
||||
}
|
||||
|
||||
void UIManager::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) {
|
||||
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) {
|
||||
// Actualizar dimensiones físicas (puede cambiar en fullscreen)
|
||||
physical_window_width_ = physical_width;
|
||||
physical_window_height_ = physical_height;
|
||||
|
||||
// Renderizar debug HUD si está activo
|
||||
if (show_debug_) {
|
||||
renderDebugHUD(engine, scene_manager, current_mode, current_app_mode,
|
||||
active_shape, shape_convergence);
|
||||
renderDebugHUD(engine, scene_manager, current_mode, current_app_mode, active_shape, shape_convergence);
|
||||
}
|
||||
|
||||
// Renderizar notificaciones (siempre al final, sobre todo lo demás)
|
||||
notifier_->render();
|
||||
|
||||
// Renderizar ayuda (siempre última, sobre todo incluso notificaciones)
|
||||
if (help_overlay_) {
|
||||
if (help_overlay_ != nullptr) {
|
||||
help_overlay_->render(renderer);
|
||||
}
|
||||
}
|
||||
@@ -156,7 +159,7 @@ void UIManager::toggleDebug() {
|
||||
}
|
||||
|
||||
void UIManager::toggleHelp() {
|
||||
if (help_overlay_) {
|
||||
if (help_overlay_ != nullptr) {
|
||||
help_overlay_->toggle();
|
||||
}
|
||||
}
|
||||
@@ -190,16 +193,16 @@ void UIManager::updatePhysicalWindowSize(int width, int height, int logical_heig
|
||||
current_font_size_ = new_font_size;
|
||||
|
||||
// Reinicializar text renderers con nuevo tamaño
|
||||
if (text_renderer_debug_) {
|
||||
if (text_renderer_debug_ != nullptr) {
|
||||
text_renderer_debug_->reinitialize(std::max(9, current_font_size_ - 2));
|
||||
}
|
||||
if (text_renderer_notifier_) {
|
||||
if (text_renderer_notifier_ != nullptr) {
|
||||
text_renderer_notifier_->reinitialize(current_font_size_);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar help overlay con font size actual Y nuevas dimensiones (atómicamente)
|
||||
if (help_overlay_) {
|
||||
if (help_overlay_ != nullptr) {
|
||||
help_overlay_->updateAll(std::max(9, current_font_size_ - 1), width, height);
|
||||
}
|
||||
|
||||
@@ -209,12 +212,12 @@ void UIManager::updatePhysicalWindowSize(int width, int height, int logical_heig
|
||||
|
||||
// === Métodos privados ===
|
||||
|
||||
void UIManager::renderDebugHUD(const Engine* engine,
|
||||
const SceneManager* scene_manager,
|
||||
SimulationMode current_mode,
|
||||
AppMode current_app_mode,
|
||||
const Shape* active_shape,
|
||||
float shape_convergence) {
|
||||
void UIManager::renderDebugHUD(const Engine* engine, // NOLINT(readability-function-cognitive-complexity)
|
||||
const SceneManager* scene_manager,
|
||||
SimulationMode current_mode,
|
||||
AppMode current_app_mode,
|
||||
const Shape* active_shape,
|
||||
float shape_convergence) {
|
||||
int line_height = text_renderer_debug_->getTextHeight();
|
||||
int margin = 8;
|
||||
SDL_Rect physical_viewport = getPhysicalViewport(renderer_);
|
||||
@@ -236,7 +239,7 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
if (current_mode == SimulationMode::PHYSICS) {
|
||||
simmode_text = "SimMode: PHYSICS";
|
||||
} else if (current_mode == SimulationMode::SHAPE) {
|
||||
if (active_shape) {
|
||||
if (active_shape != nullptr) {
|
||||
simmode_text = std::string("SimMode: SHAPE (") + active_shape->getName() + ")";
|
||||
} else {
|
||||
simmode_text = "SimMode: SHAPE";
|
||||
@@ -246,7 +249,7 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
}
|
||||
|
||||
std::string sprite_name = engine->getCurrentTextureName();
|
||||
std::transform(sprite_name.begin(), sprite_name.end(), sprite_name.begin(), ::toupper);
|
||||
std::ranges::transform(sprite_name, sprite_name.begin(), ::toupper);
|
||||
std::string sprite_text = "Sprite: " + sprite_name;
|
||||
|
||||
size_t ball_count = scene_manager->getBallCount();
|
||||
@@ -256,7 +259,9 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
std::string formatted;
|
||||
int digits = static_cast<int>(count_str.length());
|
||||
for (int i = 0; i < digits; i++) {
|
||||
if (i > 0 && (digits - i) % 3 == 0) formatted += ',';
|
||||
if (i > 0 && (digits - i) % 3 == 0) {
|
||||
formatted += ',';
|
||||
}
|
||||
formatted += count_str[i];
|
||||
}
|
||||
balls_text = "Balls: " + formatted;
|
||||
@@ -275,7 +280,9 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
std::string formatted;
|
||||
int digits = static_cast<int>(count_str.length());
|
||||
for (int i = 0; i < digits; i++) {
|
||||
if (i > 0 && (digits - i) % 3 == 0) formatted += ',';
|
||||
if (i > 0 && (digits - i) % 3 == 0) {
|
||||
formatted += ',';
|
||||
}
|
||||
formatted += count_str[i];
|
||||
}
|
||||
max_auto_text = "Auto max: " + formatted;
|
||||
@@ -303,9 +310,9 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
std::string refresh_text;
|
||||
int num_displays = 0;
|
||||
SDL_DisplayID* displays = SDL_GetDisplays(&num_displays);
|
||||
if (displays && num_displays > 0) {
|
||||
if ((displays != nullptr) && num_displays > 0) {
|
||||
const auto* dm = SDL_GetCurrentDisplayMode(displays[0]);
|
||||
if (dm) {
|
||||
if (dm != nullptr) {
|
||||
refresh_text = "Refresh: " + std::to_string(static_cast<int>(dm->refresh_rate)) + " Hz";
|
||||
} else {
|
||||
refresh_text = "Refresh: N/A";
|
||||
@@ -322,9 +329,9 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
int hh = static_cast<int>(total_secs / 3600);
|
||||
int mm = static_cast<int>((total_secs % 3600) / 60);
|
||||
int ss = static_cast<int>(total_secs % 60);
|
||||
char elapsed_buf[32];
|
||||
SDL_snprintf(elapsed_buf, sizeof(elapsed_buf), "Elapsed: %02d:%02d:%02d", hh, mm, ss);
|
||||
std::string elapsed_text(elapsed_buf);
|
||||
std::array<char, 32> elapsed_buf{};
|
||||
SDL_snprintf(elapsed_buf.data(), elapsed_buf.size(), "Elapsed: %02d:%02d:%02d", hh, mm, ss);
|
||||
std::string elapsed_text(elapsed_buf.data());
|
||||
|
||||
// --- Construir vector de líneas en orden ---
|
||||
std::vector<std::string> lines;
|
||||
@@ -344,17 +351,15 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
if (!engine->isPostFXEnabled()) {
|
||||
postfx_text = "PostFX: OFF";
|
||||
} else {
|
||||
static constexpr const char* preset_names[4] = {
|
||||
"Vinyeta", "Scanlines", "Cromatica", "Complet"
|
||||
};
|
||||
static constexpr std::array<const char*, 4> PRESET_NAMES = {
|
||||
"Vinyeta",
|
||||
"Scanlines",
|
||||
"Cromatica",
|
||||
"Complet"};
|
||||
int mode = engine->getPostFXMode();
|
||||
char buf[64];
|
||||
SDL_snprintf(buf, sizeof(buf), "PostFX: %s [V:%.2f C:%.2f S:%.2f]",
|
||||
preset_names[mode],
|
||||
engine->getPostFXVignette(),
|
||||
engine->getPostFXChroma(),
|
||||
engine->getPostFXScanline());
|
||||
postfx_text = buf;
|
||||
std::array<char, 64> buf{};
|
||||
SDL_snprintf(buf.data(), buf.size(), "PostFX: %s [V:%.2f C:%.2f S:%.2f]", PRESET_NAMES[mode], engine->getPostFXVignette(), engine->getPostFXChroma(), engine->getPostFXScanline());
|
||||
postfx_text = buf.data();
|
||||
}
|
||||
lines.push_back(postfx_text);
|
||||
lines.push_back(elapsed_text);
|
||||
@@ -366,7 +371,7 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
SDL_FRect pos = first_ball->getPosition();
|
||||
lines.push_back("Pos: (" + std::to_string(static_cast<int>(pos.x)) + ", " + std::to_string(static_cast<int>(pos.y)) + ")");
|
||||
lines.push_back("Gravity: " + std::to_string(static_cast<int>(first_ball->getGravityForce())));
|
||||
lines.push_back(first_ball->isOnSurface() ? "Surface: YES" : "Surface: NO");
|
||||
lines.emplace_back(first_ball->isOnSurface() ? "Surface: YES" : "Surface: NO");
|
||||
lines.push_back("Loss: " + std::to_string(first_ball->getLossCoefficient()).substr(0, 4));
|
||||
lines.push_back("Dir: " + gravityDirectionToString(static_cast<int>(scene_manager->getCurrentGravity())));
|
||||
}
|
||||
@@ -378,29 +383,34 @@ void UIManager::renderDebugHUD(const Engine* engine,
|
||||
|
||||
// --- Render con desbordamiento a segunda columna ---
|
||||
int max_lines = (physical_viewport.h - 2 * margin) / line_height;
|
||||
if (max_lines < 1) max_lines = 1;
|
||||
max_lines = std::max(max_lines, 1);
|
||||
int col_width = physical_viewport.w / 2;
|
||||
|
||||
for (int i = 0; i < static_cast<int>(lines.size()); i++) {
|
||||
int col = i / max_lines;
|
||||
int row = i % max_lines;
|
||||
int x = margin + col * col_width;
|
||||
int y = margin + row * line_height;
|
||||
int x = margin + (col * col_width);
|
||||
int y = margin + (row * line_height);
|
||||
text_renderer_debug_->printAbsoluteShadowed(x, y, lines[i].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::string UIManager::gravityDirectionToString(int direction) const {
|
||||
auto UIManager::gravityDirectionToString(int direction) -> std::string {
|
||||
switch (direction) {
|
||||
case 0: return "Abajo"; // DOWN
|
||||
case 1: return "Arriba"; // UP
|
||||
case 2: return "Izquierda"; // LEFT
|
||||
case 3: return "Derecha"; // RIGHT
|
||||
default: return "Desconocida";
|
||||
case 0:
|
||||
return "Abajo"; // DOWN
|
||||
case 1:
|
||||
return "Arriba"; // UP
|
||||
case 2:
|
||||
return "Izquierda"; // LEFT
|
||||
case 3:
|
||||
return "Derecha"; // RIGHT
|
||||
default:
|
||||
return "Desconocida";
|
||||
}
|
||||
}
|
||||
|
||||
int UIManager::calculateFontSize(int logical_height) const {
|
||||
auto UIManager::calculateFontSize(int logical_height) -> int {
|
||||
// Escalado híbrido basado en ALTURA LÓGICA (resolución interna, sin zoom)
|
||||
// Esto asegura que el tamaño de fuente sea consistente independientemente del zoom de ventana
|
||||
// - Proporcional en extremos (muy bajo/alto)
|
||||
@@ -435,8 +445,8 @@ int UIManager::calculateFontSize(int logical_height) const {
|
||||
}
|
||||
|
||||
// Aplicar límites: mínimo 9px, máximo 72px
|
||||
if (font_size < 9) font_size = 9;
|
||||
if (font_size > 72) font_size = 72;
|
||||
font_size = std::max(font_size, 9);
|
||||
font_size = std::min(font_size, 72);
|
||||
|
||||
return font_size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user