Files
orni-attack/source/core/graphics/screen_fade.cpp
T

63 lines
1.4 KiB
C++

// screen_fade.cpp - Implementació de la fosa a/desde negre
// © 2026 JailDesigner
#include "core/graphics/screen_fade.hpp"
#include <algorithm>
#include <cmath>
#include "core/defaults/game.hpp"
namespace Graphics {
ScreenFade::ScreenFade(Rendering::Renderer* renderer)
: renderer_(renderer) {}
void ScreenFade::start(float from, float to, float duration) {
from_ = from;
to_ = to;
duration_ = duration;
elapsed_ = 0.0F;
active_ = true;
}
void ScreenFade::update(float delta_time) {
if (!active_) {
return;
}
elapsed_ += delta_time;
}
auto ScreenFade::alpha() const -> float {
if (!active_) {
return 0.0F;
}
if (duration_ <= 0.0F) {
return to_;
}
const float T = std::clamp(elapsed_ / duration_, 0.0F, 1.0F);
return std::lerp(from_, to_, T);
}
auto ScreenFade::isDone() const -> bool {
return !active_ || elapsed_ >= duration_;
}
void ScreenFade::draw() const {
const float A = alpha();
if (A <= 0.0F) {
return;
}
renderer_->pushRect(
0.0F,
0.0F,
static_cast<float>(Defaults::Game::WIDTH),
static_cast<float>(Defaults::Game::HEIGHT),
0.0F,
0.0F,
0.0F,
A);
}
} // namespace Graphics