Loading...
Searching...
No Matches
Fadeable.h
Go to the documentation of this file.
1#pragma once
2
4#include <Malena/Engine/Events/EventsManager.h>
6#include <functional>
7#include <optional>
8#include <cstdint>
9
10namespace ml
11{
51 class Fadeable : public Trait
52 {
53 public:
55 virtual ~Fadeable();
56
57 // ── Fade API ──────────────────────────────────────────────────────────
58
67 void fadeTo(uint8_t targetAlpha,
68 float duration = 0.5f,
69 Tween tween = LINEAR,
70 std::function<void()> onComplete = nullptr);
71
81 void fadeIn(float duration = 0.5f,
82 Tween tween = LINEAR,
83 std::function<void()> onComplete = nullptr);
84
94 void fadeOut(float duration = 0.5f,
95 Tween tween = LINEAR,
96 std::function<void()> onComplete = nullptr);
97
112 void holdFor(float duration,
113 std::function<void()> onComplete = nullptr);
114
122 void setAlpha(uint8_t alpha);
123
132 uint8_t getAlpha() const;
133
139 bool isFading() const;
140
141 private:
143 void tick();
144
145 float _alpha = 255.f;
146 float _startAlpha = 255.f;
147 float _targetAlpha = 255.f;
148 float _elapsed = 0.f;
149 float _duration = 0.f;
150 bool _active = false;
151 bool _holding = false;
152 Tween _tween = LINEAR;
153
154 std::function<void()> _onComplete;
155
156 static float applyTween(float t, Tween tween);
158 };
159
160} // namespace ml
161
162#include "Fadeable.tpp"
void fadeTo(uint8_t targetAlpha, float duration=0.5f, Tween tween=LINEAR, std::function< void()> onComplete=nullptr)
Animate alpha from its current value to targetAlpha.
void setAlpha(uint8_t alpha)
Set alpha immediately with no animation.
void fadeOut(float duration=0.5f, Tween tween=LINEAR, std::function< void()> onComplete=nullptr)
Animate alpha from its current value to 0 (fully transparent).
virtual ~Fadeable()
bool isFading() const
Return true while a fade or hold animation is running.
uint8_t getAlpha() const
Return the current alpha as a uint8_t (0–255).
void fadeIn(float duration=0.5f, Tween tween=LINEAR, std::function< void()> onComplete=nullptr)
Animate alpha from 0 to 255 (fully opaque).
void holdFor(float duration, std::function< void()> onComplete=nullptr)
Hold at the current alpha for duration seconds, then fire onComplete.
Empty marker base class for all Malena traits.
Definition Trait.h:31
Tween
Easing curve selection for animated movement.
Definition Tween.h:40
@ LINEAR
Constant-speed interpolation.
Definition Tween.h:41
Definition Component.h:18