32 lines
776 B
C++
32 lines
776 B
C++
#ifndef FADING_CAPTION_HPP
|
|
#define FADING_CAPTION_HPP
|
|
|
|
#include <algorithm>
|
|
|
|
#include <basic_widgets/w/caption.hpp>
|
|
|
|
namespace game::ui
|
|
{
|
|
class FadingCaption final : public bwidgets::Caption
|
|
{
|
|
bool _shown {};
|
|
uint32_t _start_time;
|
|
void _handle_rendering() override;
|
|
|
|
public:
|
|
uint32_t duration = 2500U; // NOLINT(readability-magic-numbers)
|
|
|
|
auto show() -> FadingCaption*;
|
|
|
|
[[nodiscard]] inline auto visibility() const noexcept -> float
|
|
{
|
|
if (!_shown) return 0;
|
|
auto progress = (float)std::clamp(SDL_GetTicks() - _start_time, 0U, duration)
|
|
/ (float)duration;
|
|
return 1 - progress * progress * progress * progress;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif
|