Commitet pa gastar el Cppcheck

This commit is contained in:
2024-10-08 20:32:24 +02:00
parent c00f4326ae
commit 3e3d764b25
12 changed files with 241 additions and 405 deletions

View File

@@ -54,7 +54,7 @@ void Notify::update()
// Si la notificación anterior está "saliendo", no hagas nada
if (i > 0)
{
if (notifications[i - 1].state == ns_rising)
if (notifications[i - 1].status == NotificationStatus::RISING)
{
break;
}
@@ -67,7 +67,7 @@ void Notify::update()
{
if (options.notification.sound)
{
if (notifications[i].state == ns_rising)
if (notifications[i].status == NotificationStatus::RISING)
{ // Reproduce el sonido de la notificación
JA_PlaySound(sound);
}
@@ -75,7 +75,7 @@ void Notify::update()
}
// Comprueba los estados
if (notifications[i].state == ns_rising)
if (notifications[i].status == NotificationStatus::RISING)
{
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
const int alpha = 255 * step;
@@ -92,21 +92,21 @@ void Notify::update()
if (notifications[i].rect.y == notifications[i].y)
{
notifications[i].state = ns_stay;
notifications[i].status = NotificationStatus::STAY;
notifications[i].texture->setAlpha(255);
notifications[i].counter = 0;
}
}
else if (notifications[i].state == ns_stay)
else if (notifications[i].status == NotificationStatus::STAY)
{
if (notifications[i].counter == waitTime)
{
notifications[i].state = ns_vanishing;
notifications[i].status = NotificationStatus::VANISHING;
notifications[i].counter = 0;
}
}
else if (notifications[i].state == ns_vanishing)
else if (notifications[i].status == NotificationStatus::VANISHING)
{
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
@@ -124,7 +124,7 @@ void Notify::update()
if (notifications[i].rect.y == notifications[i].y - notifications[i].travelDist)
{
notifications[i].state = ns_finished;
notifications[i].status = NotificationStatus::FINISHED;
}
}
@@ -139,7 +139,7 @@ void Notify::clearFinishedNotifications()
{
for (int i = (int)notifications.size() - 1; i >= 0; --i)
{
if (notifications[i].state == ns_finished)
if (notifications[i].status == NotificationStatus::FINISHED)
{
notifications.erase(notifications.begin() + i);
}
@@ -150,15 +150,7 @@ void Notify::clearFinishedNotifications()
void Notify::showText(std::string text1, std::string text2, int icon)
{
// Cuenta el número de textos a mostrar
int numTexts = 0;
if (text1 != "")
{
numTexts++;
}
if (text2 != "")
{
numTexts++;
}
const int numTexts = (text1 != "") + (text2 != "");
// Si no hay texto, acaba
if (numTexts == 0)
@@ -179,17 +171,17 @@ void Notify::showText(std::string text1, std::string text2, int icon)
}
// Inicializa variables
constexpr int iconSize = 16;
constexpr int paddingOut = 1;
const int paddingIn = text->getCharacterSize() / 2;
const int iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
constexpr auto iconSize = 16;
constexpr auto paddingOut = 1;
const auto paddingIn = text->getCharacterSize() / 2;
const auto iconSpace = icon >= 0 ? iconSize + paddingIn : 0;
const std::string txt = text1.length() > text2.length() ? text1 : text2;
const int width = text->lenght(txt) + (paddingIn * 2) + iconSpace;
const int height = (text->getCharacterSize() * numTexts) + (paddingIn * 2);
const notification_shape_t shape = notification_shape_squared;
const auto width = text->lenght(txt) + (paddingIn * 2) + iconSpace;
const auto height = (text->getCharacterSize() * numTexts) + (paddingIn * 2);
const auto shape = NotificationShape::SQUARED;
// Posición horizontal
int despH = 0;
auto despH = 0;
if (options.notification.posH == pos_left)
{
despH = paddingOut;
@@ -204,20 +196,11 @@ void Notify::showText(std::string text1, std::string text2, int icon)
}
// Posición vertical
int despV = 0;
if (options.notification.posV == pos_top)
{
despV = paddingOut;
}
else
{
despV = param.game.height - height - paddingOut;
}
const int travelDist = height + paddingOut;
const int despV = (options.notification.posV == pos_top) ? paddingOut : (param.game.height - height - paddingOut);
// Offset
int offset = 0;
const auto travelDist = height + paddingOut;
auto offset = 0;
if (options.notification.posV == pos_top)
{
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
@@ -227,18 +210,32 @@ void Notify::showText(std::string text1, std::string text2, int icon)
offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
}
// Crea la textura de fondo de la notificación
auto texture = std::make_unique<Texture>(renderer);
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
texture->setBlendMode(SDL_BLENDMODE_BLEND);
// Crea la notificacion
Notification n;
// Inicializa variables
n.y = offset;
n.travelDist = travelDist;
n.counter = 0;
n.status = NotificationStatus::RISING;
n.text1 = text1;
n.text2 = text2;
n.shape = shape;
auto yPos = offset + (options.notification.posV == pos_top ? -travelDist : travelDist);
n.rect = {despH, yPos, width, height};
// Crea la textura
n.texture = new Texture(renderer);
n.texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
// Prepara para dibujar en la textura
texture->setAsRenderTarget(renderer);
n.texture->setAsRenderTarget(renderer);
// Dibuja fondo de la notificación sobre la textura
// Dibuja el fondo de la notificación
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
SDL_Rect rect;
if (shape == notification_shape_rounded)
if (shape == NotificationShape::ROUNDED)
{
rect = {4, 0, width - (4 * 2), height};
SDL_RenderFillRect(renderer, &rect);
@@ -253,7 +250,7 @@ void Notify::showText(std::string text1, std::string text2, int icon)
SDL_RenderFillRect(renderer, &rect);
}
else if (shape == notification_shape_squared)
else if (shape == NotificationShape::SQUARED)
{
SDL_RenderClear(renderer);
}
@@ -283,28 +280,13 @@ void Notify::showText(std::string text1, std::string text2, int icon)
SDL_SetRenderTarget(renderer, nullptr);
// Crea el sprite de la notificación
auto sprite = std::make_unique<Sprite>((SDL_Rect){despH, 50, width, height}, texture.get());
// Crea la notificacion
notification_t n(std::move(texture), std::move(sprite));
// Inicializa variables
n.y = offset;
n.travelDist = travelDist;
n.counter = 0;
n.state = ns_rising;
n.text1 = text1;
n.text2 = text2;
n.shape = shape;
const int yPos = offset + (options.notification.posV == pos_top ? -travelDist : travelDist);
n.rect = {despH, yPos, width, height};
n.sprite->setPos(n.rect);
n.sprite = new Sprite(n.rect, n.texture);
// Deja la notificación invisible
n.texture->setAlpha(0);
// Añade la notificación a la lista
notifications.push_back(std::move(n));
notifications.push_back(n);
}
// Indica si hay notificaciones activas
@@ -323,7 +305,7 @@ void Notify::clearNotifications()
{
for (int i = 0; i < (int)notifications.size(); ++i)
{
notifications[i].state = ns_finished;
notifications[i].status = NotificationStatus::FINISHED;
}
clearFinishedNotifications();