Las notificaciones se pueden configurar para que no se apilen

This commit is contained in:
2024-09-15 14:11:37 +02:00
parent c40c59275a
commit 7ef75184a5
2 changed files with 27 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF
this->options = options; this->options = options;
bgColor = options->notification.color; bgColor = options->notification.color;
waitTime = 100; waitTime = 100;
stack = false;
// Crea objetos // Crea objetos
iconTexture = new Texture(renderer, iconFile); iconTexture = new Texture(renderer, iconFile);
@@ -149,6 +150,11 @@ void Notify::clearFinishedNotifications()
// Muestra una notificación de texto por pantalla; // Muestra una notificación de texto por pantalla;
void Notify::showText(std::string text1, std::string text2, int icon) void Notify::showText(std::string text1, std::string text2, int icon)
{ {
if (!stack)
{
clearNotifications();
}
// Inicializa variables // Inicializa variables
const int iconSize = 16; const int iconSize = 16;
const int paddingOut = 1; const int paddingOut = 1;
@@ -250,7 +256,6 @@ void Notify::showText(std::string text1, std::string text2, int icon)
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
} }
// Dibuja el icono de la notificación // Dibuja el icono de la notificación
if (icon >= 0 && numTexts == 2) if (icon >= 0 && numTexts == 2)
{ {
@@ -296,3 +301,14 @@ bool Notify::active()
return false; return false;
} }
// Finaliza y elimnina todas las notificaciones activas
void Notify::clearNotifications()
{
for (int i = 0; i < (int)notifications.size(); ++i)
{
notifications[i].state = ns_finished;
}
clearFinishedNotifications();
}

View File

@@ -67,23 +67,27 @@ private:
int waitTime; // Tiempo que se ve la notificación int waitTime; // Tiempo que se ve la notificación
std::vector<notification_t> notifications; // La lista de notificaciones activas std::vector<notification_t> notifications; // La lista de notificaciones activas
JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación
bool stack; // Indica si las notificaciones se apilan
// Elimina las notificaciones finalizadas // Elimina las notificaciones finalizadas
void clearFinishedNotifications(); void clearFinishedNotifications();
// Finaliza y elimnina todas las notificaciones activas
void clearNotifications();
public: public:
// Dibuja las notificaciones por pantalla
void render();
// Actualiza el estado de las notificaiones
void update();
// Constructor // Constructor
Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options); Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
// Destructor // Destructor
~Notify(); ~Notify();
// Dibuja las notificaciones por pantalla
void render();
// Actualiza el estado de las notificaiones
void update();
// Muestra una notificación de texto por pantalla; // Muestra una notificación de texto por pantalla;
void showText(std::string text1 = "", std::string text2 = "", int icon = -1); void showText(std::string text1 = "", std::string text2 = "", int icon = -1);