afegit un mini-notificador

This commit is contained in:
2026-04-13 16:27:57 +02:00
parent 58cacf7bda
commit 86323a0e56
2 changed files with 59 additions and 8 deletions

View File

@@ -6,8 +6,9 @@
#include <iostream> // for basic_ostream, operator<<, cout, endl
#include <string> // for basic_string, char_traits, string
#include "asset.h" // for Asset
#include "mouse.hpp" // for Mouse::cursorVisible, Mouse::lastMouseMoveTime
class Asset;
#include "text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_STROKE
// Constructor
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options) {
@@ -21,8 +22,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
gameCanvasHeight = options->gameHeight;
borderWidth = options->borderWidth * 2;
borderHeight = options->borderHeight * 2;
notificationLogicalWidth = gameCanvasWidth;
notificationLogicalHeight = gameCanvasHeight;
iniFade();
iniSpectrumFade();
@@ -44,12 +43,18 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
// Establece el modo de video
setVideoMode(options->videoMode);
// Inicializa variables
notifyActive = false;
// Inicializa el sistema de notificaciones
notificationText = new Text(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
notificationMessage = "";
notificationTextColor = {0xFF, 0xFF, 0xFF};
notificationOutlineColor = {0x00, 0x00, 0x00};
notificationEndTime = 0;
notificationY = 2;
}
// Destructor
Screen::~Screen() {
delete notificationText;
SDL_DestroyTexture(gameCanvas);
}
@@ -66,6 +71,10 @@ void Screen::start() {
// Vuelca el contenido del renderizador en pantalla
void Screen::blit() {
// Dibuja la notificación activa sobre el gameCanvas antes de presentar
SDL_SetRenderTarget(renderer, gameCanvas);
renderNotification();
// Vuelve a dejar el renderizador en modo normal
SDL_SetRenderTarget(renderer, nullptr);
@@ -346,4 +355,29 @@ void Screen::updateFX() {
void Screen::renderFX() {
renderFade();
renderSpectrumFade();
}
// Muestra una notificación en la línea superior durante durationMs
void Screen::notify(const std::string &text, color_t textColor, color_t outlineColor, Uint32 durationMs) {
notificationMessage = text;
notificationTextColor = textColor;
notificationOutlineColor = outlineColor;
notificationEndTime = SDL_GetTicks() + durationMs;
}
// Limpia la notificación actual
void Screen::clearNotification() {
notificationEndTime = 0;
notificationMessage.clear();
}
// Dibuja la notificación activa (si la hay) sobre el gameCanvas
void Screen::renderNotification() {
if (SDL_GetTicks() >= notificationEndTime) {
return;
}
notificationText->writeDX(TXT_CENTER | TXT_COLOR | TXT_STROKE,
gameCanvasWidth / 2, notificationY,
notificationMessage, 1,
notificationTextColor, 1, notificationOutlineColor);
}