-
Notifications
You must be signed in to change notification settings - Fork 0
/
Label.hpp
52 lines (46 loc) · 1.36 KB
/
Label.hpp
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
#pragma once
#include "Widget.hpp"
namespace gGUI {
class Label : public Widget {
private:
const char *str;
sf::Font font;
sf::Text text;
public:
Label(size_t in_x, size_t in_y, size_t in_w, size_t in_h, Widget *p, const char *s)
: Widget(in_x, in_y, in_w, in_h, p, "badtexture"), str(s)
{
assert(font.loadFromFile("../fonts/arial.ttf"));
text.setFont(font);
text.setString(str);
resize(-1, -1);
#if 0
text.setScale(w / text.getLocalBounds().width,
h / text.getLocalBounds().height);
#endif
}
void draw(sf::RenderWindow &window, size_t p_x, size_t p_y) override
{
text.setPosition(x + p_x, y + p_y);
window.draw(text);
}
Widget *belongs(size_t, size_t, size_t x = 0, size_t y = 0) const override
{
return nullptr;
}
virtual void move(size_t new_x, size_t new_y) override
{
Widget::move(new_x, new_y);
resize(-1, -1);
}
virtual void resize(size_t new_w, size_t new_h) override
{
Widget::resize(new_w, new_h);
x = 0.1 * w;
y = 0.1 * h;
h = 0.3 * h;
w = 0.3 * w;
text.setCharacterSize(h);
}
};
}