-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFadeScreen.cpp
More file actions
112 lines (89 loc) · 1.79 KB
/
FadeScreen.cpp
File metadata and controls
112 lines (89 loc) · 1.79 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "stdafx.h"
#include "FadeScreen.h"
// Constructors and Destructor:
void gui::FadeScreen::initVariables()
{
this->shape.setSize(sf::Vector2f(100.f, 100.f));
this->shape.setPosition(0.f, 0.f);
this->shape.setFillColor(sf::Color::Black);
this->color = color;
this->alphaMultiplier = 1.f;
this->speed = 1.f;
this->fade = false;
this->covered = false;
}
gui::FadeScreen::FadeScreen()
{
this->initVariables();
}
gui::FadeScreen::~FadeScreen()
{
}
const bool gui::FadeScreen::isVisible() const
{
if (this->shape.getFillColor().a != 0)
{
return true;
}
return false;
}
const bool gui::FadeScreen::isOpaque() const
{
if (this->shape.getFillColor().a == 255)
{
return true;
}
return false;
}
void gui::FadeScreen::setSize(const float x, const float y)
{
this->shape.setSize(sf::Vector2f(x, y));
}
void gui::FadeScreen::setSize(sf::Vector2f size)
{
this->shape.setSize(size);
}
void gui::FadeScreen::setColor(sf::Color color)
{
this->shape.setFillColor(color);
}
void gui::FadeScreen::setFadeSpeed(const float speed)
{
this->speed = speed;
}
// Fucntions:
void gui::FadeScreen::fadeIn()
{
this->fade = false;
}
void gui::FadeScreen::fadeOut()
{
this->fade = true;
}
void gui::FadeScreen::update(const float& dt)
{
if (this->fade)
{
this->alphaMultiplier += this->speed * dt;
if (this->alphaMultiplier > 1)
{
this->alphaMultiplier = 1;
}
}
else
{
this->alphaMultiplier -= this->speed * dt;
if (this->alphaMultiplier < 0)
{
this->alphaMultiplier = 0;
}
}
this->shape.setFillColor(sf::Color(this->color.r, this->color.g, this->color.b, static_cast<uint8_t>(static_cast<float>(this->color.a) * this->alphaMultiplier)));
}
void gui::FadeScreen::render(sf::RenderTarget* target)
{
if (this->shape.getFillColor().a != 0)
{
target->draw(this->shape);
}
}