blob: cb7dbef582a78a0ce957c2f899b223781209027e (
plain)
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
|
#include "text.h"
#include <SFML/Graphics/RenderWindow.hpp>
extern sf::RenderWindow *renderwindow;
sf::Font *font = NULL;
Text::Text(std::string str, int x, int y) {
if(!font) {
font = new sf::Font();
font->LoadFromFile("fonts/VeraMono.ttf");
}
string.SetSize(20);
string.SetFont(*font);
set_text(str);
set_position(x, y);
}
void Text::draw() {
renderwindow->Draw(string);
}
void Text::set_text(std::string str) {
string.SetText(str);
}
void Text::set_position(int x, int y) {
string.SetPosition(x, y);
}
void Text::subtract_height() {
sf::FloatRect fr = string.GetRect();
sf::Vector2f pos = string.GetPosition();
pos.y -= fr.GetHeight();
string.SetPosition(pos);
}
|