From 7ef75184a59fccc30d08994646d6906f7376f274 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 15 Sep 2024 14:11:37 +0200 Subject: [PATCH] Las notificaciones se pueden configurar para que no se apilen --- source/common/notify.cpp | 18 +++++++++++++++++- source/common/notify.h | 16 ++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/source/common/notify.cpp b/source/common/notify.cpp index 354d47c..cd9e306 100644 --- a/source/common/notify.cpp +++ b/source/common/notify.cpp @@ -11,6 +11,7 @@ Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapF this->options = options; bgColor = options->notification.color; waitTime = 100; + stack = false; // Crea objetos iconTexture = new Texture(renderer, iconFile); @@ -149,6 +150,11 @@ void Notify::clearFinishedNotifications() // Muestra una notificación de texto por pantalla; void Notify::showText(std::string text1, std::string text2, int icon) { + if (!stack) + { + clearNotifications(); + } + // Inicializa variables const int iconSize = 16; const int paddingOut = 1; @@ -250,7 +256,6 @@ void Notify::showText(std::string text1, std::string text2, int icon) SDL_RenderClear(renderer); } - // Dibuja el icono de la notificación if (icon >= 0 && numTexts == 2) { @@ -295,4 +300,15 @@ bool Notify::active() } 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(); } \ No newline at end of file diff --git a/source/common/notify.h b/source/common/notify.h index 8f7fc71..3cc3489 100644 --- a/source/common/notify.h +++ b/source/common/notify.h @@ -67,22 +67,26 @@ private: int waitTime; // Tiempo que se ve la notificación std::vector notifications; // La lista de notificaciones activas JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación + bool stack; // Indica si las notificaciones se apilan // Elimina las notificaciones finalizadas void clearFinishedNotifications(); + // Finaliza y elimnina todas las notificaciones activas + void clearNotifications(); + public: - // Dibuja las notificaciones por pantalla - void render(); - - // Actualiza el estado de las notificaiones - void update(); - // Constructor Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options); // Destructor ~Notify(); + + // Dibuja las notificaciones por pantalla + void render(); + + // Actualiza el estado de las notificaiones + void update(); // Muestra una notificación de texto por pantalla; void showText(std::string text1 = "", std::string text2 = "", int icon = -1);