This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel.cpp
54 lines (47 loc) · 1.94 KB
/
label.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
52
53
#include "label.hpp"
#include <iostream>
#include "simple_functions.hpp"
label::label(sf::RenderWindow &window,
sf::Vector2f position,
std::string text_string,
int size_char,
sf::Color background_text_color,
bool rectangle_display,
sf::Color text_color):
drawable(window, position, {0,0}),
text_string(text_string),
size_char(size_char),
rectangle_display(rectangle_display),
text_color(text_color),
background_text_color(background_text_color)
{
if(!font_text.loadFromFile("res/fonts/arcade_font.ttf")){
std::cout << "geen arcade_font" << std::endl;
}
text_SFML.setFont(font_text);
text_SFML.setPosition(position);
text_SFML.setFillColor(text_color);
text_SFML.setString(text_string);
text_SFML.setFillColor(text_color);
text_SFML.setCharacterSize(size_char);
rect_SFML.setPosition(position - sf::Vector2f(float_from_double(text_SFML.getGlobalBounds().width*0.1), 0));
size ={ float_from_double(text_SFML.getGlobalBounds().width*1.2), float_from_double(text_SFML.getGlobalBounds().height*1.5)};
rect_SFML.setSize(size);
rect_SFML.setFillColor(background_text_color);
}
void label::draw() {
if(rectangle_display){
window.draw(rect_SFML);
}
rect_SFML.setPosition(position - sf::Vector2f(float_from_double(text_SFML.getGlobalBounds().width*0.1), 0));
size ={ float_from_double(text_SFML.getGlobalBounds().width*1.2), float_from_double(text_SFML.getGlobalBounds().height*1.5)};
rect_SFML.setSize(size);
text_SFML.setString(text_string);
window.draw(text_SFML);
}
void label::update_text(std::string new_value) {
text_SFML.setString(new_value);
rect_SFML.setPosition(position - sf::Vector2f(float_from_double(text_SFML.getGlobalBounds().width*0.2), 0));
size ={ float_from_double(text_SFML.getGlobalBounds().width*1.2), float_from_double(text_SFML.getGlobalBounds().height*1.5)};
rect_SFML.setSize(size);
}