renderInfo amb animacio
This commit is contained in:
@@ -41,9 +41,31 @@ RenderInfo::RenderInfo() {
|
|||||||
#endif
|
#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
|
// Renderiza el overlay de información por pantalla
|
||||||
void RenderInfo::render() const {
|
void RenderInfo::render() const {
|
||||||
if (!active_) { return; }
|
if (status_ == Status::HIDDEN) { return; }
|
||||||
|
|
||||||
// FPS
|
// FPS
|
||||||
std::string line = std::to_string(Screen::get()->getLastFPS()) + " 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
|
// Fuente: preferir la de la consola si está disponible
|
||||||
auto text_obj = (Console::get() != nullptr) ? Console::get()->getText() : Screen::get()->getText();
|
auto text_obj = (Console::get() != nullptr) ? Console::get()->getText() : Screen::get()->getText();
|
||||||
|
|
||||||
// Posición Y (debajo de la consola si está visible)
|
// Posición Y: debajo de la consola + offset animado propio
|
||||||
const int Y = (Console::get() != nullptr) ? Console::get()->getVisibleHeight() : 0;
|
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
|
// Rectángulo de fondo: ancho completo, alto ajustado al texto
|
||||||
const SDL_FRect RECT = {
|
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
|
// Activa o desactiva el overlay y notifica a Notifier del cambio de offset
|
||||||
void RenderInfo::toggle() {
|
void RenderInfo::toggle() {
|
||||||
active_ = !active_;
|
switch (status_) {
|
||||||
if (active_) {
|
case Status::HIDDEN:
|
||||||
Screen::get()->updateZoomFactor();
|
status_ = Status::RISING;
|
||||||
if (Notifier::get() != nullptr) { Notifier::get()->addYOffset(HEIGHT); }
|
Screen::get()->updateZoomFactor();
|
||||||
} else {
|
if (Notifier::get() != nullptr) { Notifier::get()->addYOffset(HEIGHT); }
|
||||||
if (Notifier::get() != nullptr) { Notifier::get()->removeYOffset(HEIGHT); }
|
break;
|
||||||
|
case Status::ACTIVE:
|
||||||
|
status_ = Status::VANISHING;
|
||||||
|
if (Notifier::get() != nullptr) { Notifier::get()->removeYOffset(HEIGHT); }
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,20 @@ class RenderInfo {
|
|||||||
static auto get() -> RenderInfo*;
|
static auto get() -> RenderInfo*;
|
||||||
|
|
||||||
// Métodos principales
|
// Métodos principales
|
||||||
|
void update(float delta_time);
|
||||||
void render() const;
|
void render() const;
|
||||||
void toggle();
|
void toggle();
|
||||||
|
|
||||||
// Consultas
|
// 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)
|
// Altura fija del overlay (TEXT_SIZE(6) + PADDING_V(2) * 2)
|
||||||
static constexpr int HEIGHT = 10;
|
static constexpr int HEIGHT = 10;
|
||||||
|
static constexpr float SLIDE_SPEED = 120.0F;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum class Status { HIDDEN, RISING, ACTIVE, VANISHING };
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
static RenderInfo* render_info;
|
static RenderInfo* render_info;
|
||||||
|
|
||||||
@@ -25,5 +29,6 @@ class RenderInfo {
|
|||||||
RenderInfo();
|
RenderInfo();
|
||||||
~RenderInfo() = default;
|
~RenderInfo() = default;
|
||||||
|
|
||||||
bool active_{false}; // Estado del overlay
|
Status status_{Status::HIDDEN};
|
||||||
|
float y_{static_cast<float>(-HEIGHT)};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -221,9 +221,6 @@ void Screen::renderNotifications() const {
|
|||||||
if (notifications_enabled_) {
|
if (notifications_enabled_) {
|
||||||
Notifier::get()->render();
|
Notifier::get()->render();
|
||||||
}
|
}
|
||||||
if (Console::get() != nullptr) {
|
|
||||||
Console::get()->render();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa/desactiva todos los shaders respetando el shader actualmente seleccionado
|
// Activa/desactiva todos los shaders respetando el shader actualmente seleccionado
|
||||||
@@ -272,6 +269,7 @@ void Screen::update(float delta_time) {
|
|||||||
if (Console::get() != nullptr) {
|
if (Console::get() != nullptr) {
|
||||||
Console::get()->update(delta_time);
|
Console::get()->update(delta_time);
|
||||||
}
|
}
|
||||||
|
if (RenderInfo::get() != nullptr) { RenderInfo::get()->update(delta_time); }
|
||||||
Mouse::updateCursorVisibility();
|
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() {
|
void Screen::renderOverlays() {
|
||||||
renderNotifications();
|
renderNotifications(); // Notifier (abajo)
|
||||||
if (RenderInfo::get() != nullptr) { RenderInfo::get()->render(); }
|
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
|
// Localiza la paleta dentro del vector de paletas
|
||||||
|
|||||||
Reference in New Issue
Block a user