neteja cppcheck (105 → 0)

This commit is contained in:
2026-05-16 19:35:23 +02:00
parent c9d16959d0
commit fcd2718794
48 changed files with 293 additions and 486 deletions
+2 -5
View File
@@ -3,6 +3,7 @@
#include <algorithm> // Para max, clamp
#include <cstddef> // Para size_t
#include <functional> // Para function
#include <numeric> // Para accumulate
#include <string> // Para allocator, string, basic_string, to_string, operator==, char_traits
#include <utility> // Para move
#include <vector> // Para vector
@@ -174,11 +175,7 @@ class ListOption : public MenuOption {
setter_(value_list_[list_index_]);
}
auto getMaxValueWidth(Text* text_renderer) const -> int override {
int max_w = 0;
for (const auto& val : value_list_) {
max_w = std::max(max_w, text_renderer->length(val, -2));
}
return max_w;
return std::accumulate(value_list_.begin(), value_list_.end(), 0, [text_renderer](int max_w, const auto& val) { return std::max(max_w, text_renderer->length(val, -2)); });
}
private:
+1 -30
View File
@@ -381,9 +381,7 @@ void MenuRenderer::updatePosition() {
// Resto de métodos (sin cambios significativos)
void MenuRenderer::precalculateMenuWidths(const std::vector<std::unique_ptr<MenuOption>>& all_options, const ServiceMenu* menu_state) { // NOLINT(readability-named-parameter)
for (int& w : group_menu_widths_) {
w = ServiceMenu::MIN_WIDTH;
}
std::ranges::fill(group_menu_widths_, ServiceMenu::MIN_WIDTH);
for (int group = 0; group < 5; ++group) {
auto sg = static_cast<ServiceMenu::SettingsGroup>(group);
int max_option_width = 0;
@@ -433,33 +431,6 @@ auto MenuRenderer::getAnimatedSelectedColor() const -> Color {
static auto color_cycle_ = Colors::generateMirroredCycle(param.service_menu.selected_color, ColorCycleStyle::HUE_WAVE);
return color_cycle_.at(color_counter_ % color_cycle_.size());
}
auto MenuRenderer::setRect(SDL_FRect rect) -> SDL_FRect {
border_rect_ = {.x = rect.x - 1, .y = rect.y + 1, .w = rect.w + 2, .h = rect.h - 2};
return rect;
}
auto MenuRenderer::getTruncatedValueWidth(const std::string& value, int available_width) const -> int {
int value_width = element_text_->length(value, -2);
if (value_width <= available_width) {
return value_width;
}
// Calculamos cuántos caracteres podemos mostrar más los puntos suspensivos
// Estimamos el ancho de los puntos suspensivos como 3 caracteres promedio
int ellipsis_width = element_text_->length("...", -2);
int available_for_text = available_width - ellipsis_width;
if (available_for_text <= 0) {
return ellipsis_width; // Solo mostramos los puntos suspensivos
}
// Calculamos aproximadamente cuántos caracteres caben
float char_width = static_cast<float>(value_width) / value.length();
auto max_chars = static_cast<size_t>(available_for_text / char_width);
// Verificamos el ancho real del texto truncado
std::string truncated = truncateWithEllipsis(value, max_chars);
return element_text_->length(truncated, -2);
}
auto MenuRenderer::getTruncatedValue(const std::string& value, int available_width) const -> std::string {
int value_width = element_text_->length(value, -2);
+6 -5
View File
@@ -82,8 +82,10 @@ class MenuRenderer {
// --- Estructuras de Animación ---
struct ResizeAnimation {
bool active = false;
float start_width, start_height;
float target_width, target_height;
float start_width = 0.0F;
float start_height = 0.0F;
float target_width = 0.0F;
float target_height = 0.0F;
float elapsed = 0.0F;
float duration = 0.2F;
@@ -97,7 +99,8 @@ class MenuRenderer {
HIDING };
Type type = Type::NONE;
bool active = false;
float target_width, target_height;
float target_width = 0.0F;
float target_height = 0.0F;
float elapsed = 0.0F;
float duration = 0.25F;
@@ -140,8 +143,6 @@ class MenuRenderer {
[[nodiscard]] auto getMenuWidthForGroup(ServiceMenu::SettingsGroup group) const -> int;
[[nodiscard]] auto getAnimatedSelectedColor() const -> Color;
void updateColorCounter();
auto setRect(SDL_FRect rect) -> SDL_FRect;
[[nodiscard]] auto getTruncatedValueWidth(const std::string& value, int available_width) const -> int;
[[nodiscard]] auto getTruncatedValue(const std::string& value, int available_width) const -> std::string;
[[nodiscard]] static auto easeOut(float t) -> float;
[[nodiscard]] auto shouldShowContent() const -> bool;
+6 -7
View File
@@ -2,8 +2,9 @@
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_FRect, SDL_RenderClear
#include <algorithm> // Para remove_if, min
#include <string> // Para basic_string, string
#include <algorithm> // Para ranges::transform, min
#include <iterator> // Para back_inserter
#include <string> // Para basic_string, string, erase_if
#include <utility>
#include <vector> // Para vector
@@ -77,7 +78,7 @@ void Notifier::playNotificationSoundIfNeeded(const Notification& notification) {
}
void Notifier::updateNotificationState(int index, float delta_time) {
auto& notification = notifications_[index];
const auto& notification = notifications_[index];
switch (notification.state) {
case State::RISING:
@@ -167,7 +168,7 @@ void Notifier::show(std::vector<std::string> texts, int icon, const std::string&
}
// Elimina las cadenas vacías
texts.erase(std::ranges::remove_if(texts, [](const std::string& s) -> bool { return s.empty(); }).begin(), texts.end());
std::erase_if(texts, [](const std::string& s) -> bool { return s.empty(); });
// Encuentra la cadena más larga
std::string longest;
@@ -303,8 +304,6 @@ void Notifier::clearAllNotifications() {
auto Notifier::getCodes() -> std::vector<std::string> {
std::vector<std::string> codes;
codes.reserve(notifications_.size());
for (const auto& notification : notifications_) {
codes.emplace_back(notification.code);
}
std::ranges::transform(notifications_, std::back_inserter(codes), [](const auto& notification) { return notification.code; });
return codes;
}
+17 -24
View File
@@ -1,5 +1,8 @@
#include "game/ui/service_menu.hpp"
#include <algorithm>
#include <iterator>
#include <numeric>
#include <utility>
#include "core/audio/audio.hpp" // Para Audio
@@ -175,7 +178,7 @@ void ServiceMenu::selectOption() {
return;
}
if (auto* folder = dynamic_cast<FolderOption*>(selected_option)) {
if (const auto* folder = dynamic_cast<const FolderOption*>(selected_option)) {
previous_settings_group_ = current_settings_group_;
current_settings_group_ = folder->getTargetGroup();
selected_ = 0;
@@ -200,9 +203,8 @@ void ServiceMenu::updateDisplayOptions() {
void ServiceMenu::updateOptionPairs() {
option_pairs_.clear();
for (const auto& option : display_options_) {
option_pairs_.emplace_back(option->getCaption(), option->getValueAsString());
}
option_pairs_.reserve(display_options_.size());
std::ranges::transform(display_options_, std::back_inserter(option_pairs_), [](const auto* option) { return std::pair{option->getCaption(), option->getValueAsString()}; });
}
void ServiceMenu::updateMenu() {
@@ -250,12 +252,9 @@ void ServiceMenu::applySettingsSettings() {
}
auto ServiceMenu::getOptionByCaption(const std::string& caption) const -> MenuOption* {
for (const auto& option : options_) {
if (option->getCaption() == caption) {
return option.get();
}
}
return nullptr;
const auto it = std::ranges::find_if(options_,
[&caption](const auto& option) { return option->getCaption() == caption; });
return it != options_.end() ? it->get() : nullptr;
}
// --- Getters y otros ---
@@ -273,13 +272,8 @@ auto ServiceMenu::getCurrentGroupAlignment() const -> ServiceMenu::GroupAlignmen
}
auto ServiceMenu::countOptionsInGroup(SettingsGroup group) const -> size_t {
size_t count = 0;
for (const auto& option : options_) {
if (option->getGroup() == group && !option->isHidden()) {
count++;
}
}
return count;
return std::ranges::count_if(options_,
[group](const auto& option) { return option->getGroup() == group && !option->isHidden(); });
}
// Inicializa todas las opciones del menú
@@ -300,7 +294,7 @@ void ServiceMenu::initializeOptions() {
[this]() -> void {
// Acción: configurar botones del mando del jugador 1
auto* gamepad = &Options::gamepad_manager.getGamepad(Player::Id::PLAYER1);
if ((gamepad != nullptr) && gamepad->instance) {
if (gamepad->instance != nullptr) {
define_buttons_->enable(gamepad);
}
}));
@@ -318,7 +312,7 @@ void ServiceMenu::initializeOptions() {
[this]() -> void {
// Acción: configurar botones del mando del jugador 2
auto* gamepad = &Options::gamepad_manager.getGamepad(Player::Id::PLAYER2);
if ((gamepad != nullptr) && gamepad->instance) {
if (gamepad->instance != nullptr) {
define_buttons_->enable(gamepad);
}
}));
@@ -436,11 +430,10 @@ void ServiceMenu::initializeOptions() {
}
Screen::initShaders();
};
auto preset_max_width = [](Text* text) -> int {
int max_w = 0;
for (const auto& p : Options::postfx_presets) { max_w = std::max(max_w, text->length(p.name, -2)); }
for (const auto& p : Options::crtpi_presets) { max_w = std::max(max_w, text->length(p.name, -2)); }
return max_w;
auto preset_max_width = [](const Text* text) -> int {
const auto presets_length = [text](int max_w, const auto& p) { return std::max(max_w, text->length(p.name, -2)); };
int max_w = std::accumulate(Options::postfx_presets.begin(), Options::postfx_presets.end(), 0, presets_length);
return std::accumulate(Options::crtpi_presets.begin(), Options::crtpi_presets.end(), max_w, presets_length);
};
options_.push_back(std::make_unique<CallbackOption>(
+8 -5
View File
@@ -51,7 +51,7 @@ class WindowMessage {
text_color{200, 200, 200, 255} {}
// Constructor que convierte desde ParamServiceMenu::WindowMessage
Config(const ParamServiceMenu::WindowMessage& param_config)
explicit Config(const ParamServiceMenu::WindowMessage& param_config)
: bg_color(param_config.bg_color),
border_color(param_config.border_color),
title_color(param_config.title_color),
@@ -67,7 +67,7 @@ class WindowMessage {
animation_duration(param_config.animation_duration) {}
};
WindowMessage(
explicit WindowMessage(
std::shared_ptr<Text> text_renderer,
std::string title = "",
const Config& config = Config{});
@@ -148,8 +148,10 @@ class WindowMessage {
// Animación de redimensionado
struct ResizeAnimation {
bool active = false;
float start_width, start_height;
float target_width, target_height;
float start_width = 0.0F;
float start_height = 0.0F;
float target_width = 0.0F;
float target_height = 0.0F;
float elapsed = 0.0F;
void start(float from_w, float from_h, float to_w, float to_h) {
@@ -183,7 +185,8 @@ class WindowMessage {
Type type = Type::NONE;
bool active = false;
float target_width, target_height; // Tamaño final al mostrar
float target_width = 0.0F;
float target_height = 0.0F;
float elapsed = 0.0F;
void startShow(float to_w, float to_h) {