forked from turanszkij/WickedEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiFadeManager.h
59 lines (56 loc) · 1.13 KB
/
wiFadeManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include "CommonInclude.h"
#include "wiColor.h"
#include "wiTimer.h"
#include "wiMath.h"
#include <functional>
namespace wi
{
class FadeManager
{
public:
float opacity = 0;
float timer = 0;
float targetFadeTimeInSeconds = 1.0f;
enum FADE_STATE
{
FADE_IN, // no fade -> faded
FADE_MID, // completely faded
FADE_OUT, // faded -> no fade
FADE_FINISHED,
} state = FADE_FINISHED;
wi::Color color = wi::Color(0, 0, 0, 255);
std::function<void()> onFade = [] {};
bool fadeEventTriggeredThisFrame = false;
FadeManager()
{
Clear();
}
void Clear();
void Start(float seconds, wi::Color color, std::function<void()> onFadeFunction)
{
targetFadeTimeInSeconds = seconds;
this->color = color;
timer = 0;
if (IsFaded())
{
// If starting a new fade on mid-fadeout, it will start from faded and just transition out of mid
state = FADE_MID;
}
else
{
state = FADE_IN;
}
onFade = onFadeFunction;
}
void Update(float dt);
bool IsFaded() const
{
return fadeEventTriggeredThisFrame;
}
bool IsActive() const
{
return state != FADE_FINISHED;
}
};
}