-
Notifications
You must be signed in to change notification settings - Fork 0
/
Textbox.cpp
51 lines (41 loc) · 1.34 KB
/
Textbox.cpp
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
#include "Textbox.hpp"
Textbox::Textbox() {
Setup(5,9,200,sf::Vector2f(0,0));
}
Textbox::Textbox(int l_visible, int l_charSize,
int l_width, sf::Vector2f l_screenPos) {
Setup(l_visible, l_charSize, l_width, l_screenPos);
}
Textbox::~Textbox(){ Clear(); }
void Textbox::Setup(int l_visible, int l_charSize,
int l_width, sf::Vector2f l_screenPos) {
m_numVisible = l_visible;
sf::Vector2f l_offset(2.0f, 2.0f);
m_font.loadFromFile("arial.ttf");
m_content.setFont(m_font);
m_content.setString("");
m_content.setCharacterSize(l_charSize);
m_content.setFillColor(sf::Color::White);
m_content.setPosition(l_screenPos + l_offset);
m_backdrop.setSize(sf::Vector2f(
l_width, (l_visible * (l_charSize * 1.2f))));
m_backdrop.setFillColor(sf::Color(90,90,90,90));
m_backdrop.setPosition(l_screenPos);
}
void Textbox::Add(std::string l_message) {
m_messages.push_back(l_message);
if (m_messages.size() < 6) { return; }
m_messages.erase(m_messages.begin());
}
void Textbox::Clear() { m_messages.clear(); }
void Textbox::Render(sf::RenderWindow& l_wind) {
std::string l_content;
for (auto &itr : m_messages) {
l_content.append(itr+"\n");
}
if(l_content != "") {
m_content.setString(l_content);
l_wind.draw(m_backdrop);
l_wind.draw(m_content);
}
}