113 lines
3.0 KiB
C++
113 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_rect.h> // for SDL_Rect
|
|
#include <memory> // for shared_ptr
|
|
#include <string> // for string, basic_string
|
|
#include <vector> // 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> texture;
|
|
std::shared_ptr<Sprite> sprite;
|
|
std::vector<std::string> 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<Texture> icon_texture_; // Textura para los iconos de las notificaciones
|
|
std::shared_ptr<Text> 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<Notification> 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<std::string> 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<std::string> getCodes();
|
|
};
|