-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaption.cpp
More file actions
128 lines (102 loc) · 2.4 KB
/
Caption.cpp
File metadata and controls
128 lines (102 loc) · 2.4 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "stdafx.h"
#include "Caption.h"
// private: Functions:
void gui::Caption::initVariables()
{
this->shown = false;
this->back.setFillColor(sf::Color::Transparent);
}
// Constructors and Destructor:
gui::Caption::Caption(sf::Font& font, sf::Color text_color, const std::string str)
{
this->initVariables();
this->text.setFont(font);
this->text.setFillColor(text_color);
this->text.setString(str);
}
gui::Caption::~Caption()
{
}
// Modifiers:
void gui::Caption::setSize(sf::Vector2f size)
{
this->back.setSize(size);
this->text.setCharacterSize(static_cast<uint32_t>(size.y / 2.f));
}
void gui::Caption::setSize(const float x, const float y)
{
this->back.setSize(sf::Vector2f(x, y));
this->text.setCharacterSize(static_cast<uint32_t>(y / 2.f));
}
void gui::Caption::setPosition(sf::Vector2f position)
{
this->back.setPosition(position);
this->text.setPosition
(
(this->back.getPosition().x + (this->back.getSize().x / 2.f)) - (this->text.getGlobalBounds().width / 2.f ),
position.y
);
}
void gui::Caption::setPosition(const float x, const float y)
{
this->back.setPosition(x, y);
this->text.setPosition
(
(this->back.getPosition().x + (this->back.getSize().x / 2.f)) - (this->text.getGlobalBounds().width / 2.f),
y
);
}
void gui::Caption::setBackColor(sf::Color color)
{
this->back.setFillColor(color);
}
void gui::Caption::setTextColor(sf::Color color)
{
this->text.setFillColor(color);
}
void gui::Caption::setString(const std::string str)
{
this->text.setString(str);
}
void gui::Caption::setTexture(sf::Texture& texture)
{
this->back.setTexture(&texture);
}
// Functions:
void gui::Caption::show()
{
this->shown = true;
}
void gui::Caption::hide()
{
this->shown = false;
}
void gui::Caption::updatePosition(sf::Vector2f position)
{
this->back.setPosition(position);
this->text.setPosition
(
(this->back.getPosition().x + (this->back.getSize().x / 2.f)) - (this->text.getGlobalBounds().width / 2.f),
position.y
);
}
void gui::Caption::updatePosition(sf::Vector2i position)
{
this->back.setPosition(sf::Vector2f(position));
this->text.setPosition
(
(this->back.getPosition().x + (this->back.getSize().x / 2.f)) - (this->text.getGlobalBounds().width / 2.f),
static_cast<float>(position.y)
);
}
void gui::Caption::update(const float& dt)
{
}
void gui::Caption::render(sf::RenderTarget* target)
{
if (this->shown)
{
target->draw(this->back);
target->draw(this->text);
}
}