#pragma once #include // for SDL_Rect #include // for shared_ptr #include // for string, basic_string #include // for vector #include "utils.h" // for Color class Sprite; // lines 9-9 class Text; // lines 10-10 class Texture; // lines 11-11 enum class NotificationText { LEFT, CENTER, }; class Notifier { private: // Constantes static constexpr int ICON_SIZE_ = 16; static constexpr int PADDING_OUT_ = 0; // [SINGLETON] Objeto notifier static Notifier *notifier_; enum class NotificationStatus { RISING, STAY, VANISHING, FINISHED, }; enum class NotificationShape { ROUNDED, SQUARED, }; struct Notification { std::shared_ptr texture; std::shared_ptr sprite; std::vector texts; int counter; NotificationStatus state; NotificationShape shape; SDL_Rect rect; int y; int travel_dist; std::string code; // Permite asignar un código a la notificación bool can_be_removed; int height; // Constructor explicit Notification() : texture(nullptr), sprite(nullptr), texts(), counter(0), state(NotificationStatus::RISING), shape(NotificationShape::SQUARED), rect{0, 0, 0, 0}, y(0), travel_dist(0), code(""), can_be_removed(true), height(0) {} }; std::shared_ptr icon_texture_; // Textura para los iconos de las notificaciones std::shared_ptr text_; // Objeto para dibujar texto // Variables Color bg_color_; // Color de fondo de las notificaciones int wait_time_; // Tiempo que se ve la notificación std::vector notifications_; // La lista de notificaciones activas bool stack_; // Indica si las notificaciones se apilan bool has_icons_; // Indica si el notificador tiene textura para iconos // Elimina las notificaciones finalizadas void clearFinishedNotifications(); // Finaliza y elimnina todas las notificaciones activas void clearNotifications(); // [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos notifier desde fuera // Constructor Notifier(const std::string &icon_file, const std::string &text); // Destructor ~Notifier() = default; public: // [SINGLETON] Crearemos el objeto con esta función estática static void init(const std::string &icon_file, const std::string &text); // [SINGLETON] Destruiremos el objeto con esta función estática static void destroy(); // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él static Notifier *get(); // Dibuja las notificaciones por pantalla void render(); // Actualiza el estado de las notificaiones void update(); // Muestra una notificación de texto por pantalla void show(std::vector texts, NotificationText text_is = NotificationText::LEFT, int icon = -1, bool can_be_removed = true, const std::string &code = std::string()); // Indica si hay notificaciones activas bool isActive(); // Obtiene los códigos de las notificaciones std::vector getCodes(); };