-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtext_handler.cpp
More file actions
68 lines (48 loc) · 1.32 KB
/
text_handler.cpp
File metadata and controls
68 lines (48 loc) · 1.32 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
#include "text_handler.hpp"
std::vector<text_list> text_handler::text;
sf::Font text_handler::font;
sf::RenderWindow* text_handler::window;
void text_list::set_pos(int px, int py)
{
x = px;
y = py;
}
void text_handler::load_font()
{
font.loadFromFile("VeraMono.ttf");
}
void text_handler::set_render_window(sf::RenderWindow* rw)
{
window = rw;
}
void text_handler::queue_text_block(text_list tl)
{
text.push_back(tl);
}
void text_handler::render()
{
int font_size = 10;
for(int i=0; i<text.size(); i++)
{
const text_list& tl = text[i];
int running_y = tl.y;
for(int j=0; j<tl.elements.size(); j++)
{
const std::string& txt = tl.elements[j];
sf::Color col(255, 255, 255, 255);
if(j < tl.colours.size())
col = tl.colours[j];
sf::String str;
str = txt;
sf::Text to_draw;
to_draw.setString(str);
to_draw.setFont(font);
to_draw.setPosition(tl.x, running_y);
to_draw.setCharacterSize(font_size);
to_draw.setColor(col);
window->draw(to_draw);
running_y += to_draw.getGlobalBounds().height + 2;
}
}
text.clear();
}