renderInfo amb animacio

This commit is contained in:
2026-03-29 17:47:48 +02:00
parent b986778bb4
commit 7551115912
3 changed files with 50 additions and 17 deletions

View File

@@ -41,9 +41,31 @@ RenderInfo::RenderInfo() {
#endif
}
// Actualiza la animación de entrada/salida del overlay
void RenderInfo::update(float delta_time) {
switch (status_) {
case Status::RISING:
y_ += SLIDE_SPEED * delta_time;
if (y_ >= 0.0F) {
y_ = 0.0F;
status_ = Status::ACTIVE;
}
break;
case Status::VANISHING:
y_ -= SLIDE_SPEED * delta_time;
if (y_ <= static_cast<float>(-HEIGHT)) {
y_ = static_cast<float>(-HEIGHT);
status_ = Status::HIDDEN;
}
break;
default:
break;
}
}
// Renderiza el overlay de información por pantalla
void RenderInfo::render() const {
if (!active_) { return; }
if (status_ == Status::HIDDEN) { return; }
// FPS
std::string line = std::to_string(Screen::get()->getLastFPS()) + " fps";
@@ -96,8 +118,9 @@ void RenderInfo::render() const {
// Fuente: preferir la de la consola si está disponible
auto text_obj = (Console::get() != nullptr) ? Console::get()->getText() : Screen::get()->getText();
// Posición Y (debajo de la consola si está visible)
const int Y = (Console::get() != nullptr) ? Console::get()->getVisibleHeight() : 0;
// Posición Y: debajo de la consola + offset animado propio
const int CONSOLE_Y = (Console::get() != nullptr) ? Console::get()->getVisibleHeight() : 0;
const int Y = CONSOLE_Y + static_cast<int>(y_);
// Rectángulo de fondo: ancho completo, alto ajustado al texto
const SDL_FRect RECT = {
@@ -119,11 +142,17 @@ void RenderInfo::render() const {
// Activa o desactiva el overlay y notifica a Notifier del cambio de offset
void RenderInfo::toggle() {
active_ = !active_;
if (active_) {
Screen::get()->updateZoomFactor();
if (Notifier::get() != nullptr) { Notifier::get()->addYOffset(HEIGHT); }
} else {
if (Notifier::get() != nullptr) { Notifier::get()->removeYOffset(HEIGHT); }
switch (status_) {
case Status::HIDDEN:
status_ = Status::RISING;
Screen::get()->updateZoomFactor();
if (Notifier::get() != nullptr) { Notifier::get()->addYOffset(HEIGHT); }
break;
case Status::ACTIVE:
status_ = Status::VANISHING;
if (Notifier::get() != nullptr) { Notifier::get()->removeYOffset(HEIGHT); }
break;
default:
break;
}
}

View File

@@ -8,16 +8,20 @@ class RenderInfo {
static auto get() -> RenderInfo*;
// Métodos principales
void update(float delta_time);
void render() const;
void toggle();
// Consultas
[[nodiscard]] auto isActive() const -> bool { return active_; }
[[nodiscard]] auto isActive() const -> bool { return status_ != Status::HIDDEN; }
// Altura fija del overlay (TEXT_SIZE(6) + PADDING_V(2) * 2)
static constexpr int HEIGHT = 10;
static constexpr float SLIDE_SPEED = 120.0F;
private:
enum class Status { HIDDEN, RISING, ACTIVE, VANISHING };
// Singleton
static RenderInfo* render_info;
@@ -25,5 +29,6 @@ class RenderInfo {
RenderInfo();
~RenderInfo() = default;
bool active_{false}; // Estado del overlay
Status status_{Status::HIDDEN};
float y_{static_cast<float>(-HEIGHT)};
};

View File

@@ -221,9 +221,6 @@ void Screen::renderNotifications() const {
if (notifications_enabled_) {
Notifier::get()->render();
}
if (Console::get() != nullptr) {
Console::get()->render();
}
}
// Activa/desactiva todos los shaders respetando el shader actualmente seleccionado
@@ -272,6 +269,7 @@ void Screen::update(float delta_time) {
if (Console::get() != nullptr) {
Console::get()->update(delta_time);
}
if (RenderInfo::get() != nullptr) { RenderInfo::get()->update(delta_time); }
Mouse::updateCursorVisibility();
}
@@ -469,10 +467,11 @@ void Screen::textureToRenderer() {
}
}
// Renderiza todos los overlays
// Renderiza todos los overlays (orden: último dibujado queda encima)
void Screen::renderOverlays() {
renderNotifications();
if (RenderInfo::get() != nullptr) { RenderInfo::get()->render(); }
renderNotifications(); // Notifier (abajo)
if (RenderInfo::get() != nullptr) { RenderInfo::get()->render(); } // RenderInfo (medio)
if (Console::get() != nullptr) { Console::get()->render(); } // Console (encima)
}
// Localiza la paleta dentro del vector de paletas