-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.cpp
More file actions
64 lines (61 loc) · 1.64 KB
/
Copy pathItem.cpp
File metadata and controls
64 lines (61 loc) · 1.64 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
//
// Created by jonng on 5/2/2021.
//
#include "Item.h"
Item::Item() {
text.setFont(Fonts::getFont(Fonts::MILKY_NICE));
setIsColored(false);
}
void Item::setPosition(Vector2f position) {
text_box.setPosition(position);
centerTextInBox();
}
void Item::setString(String label) {
text.setString(label);
centerTextInBox();
}
void Item::draw (RenderTarget& target, RenderStates states) const {
target.draw(text_box);
target.draw(text);
}
FloatRect Item::getGlobalBounds() {
return text_box.getGlobalBounds();
}
void Item::setSize(Vector2f size) {
text_box.setSize(size);
centerTextInBox();
}
float Item::getOutlineThickness() {
return text_box.getOutlineThickness();
}
void Item::addEventHandler(sf::RenderWindow& window, sf::Event event) {
if (MouseEvents<TextBox>::hovered(text_box,window)) {
setIsColored(true);
}
else {
setIsColored(false);
}
}
bool Item::contains (Vector2i aVector) {
return text_box.contains(aVector);
}
String Item::getString() {
return text.getString();
}
void Item::setCharacterSize(unsigned int size) {
text.setCharacterSize(size);
}
void Item::centerTextInBox() {
text.setPosition(text_box.getGlobalBounds().left+text_box.getGlobalBounds().width/2-text.getGlobalBounds().width/2, text_box.getGlobalBounds().top+text_box.getGlobalBounds().height/2-text.getGlobalBounds().height/1.3f);
}
void Item::setIsColored(bool aBoolean) {
if(aBoolean) {
text_box.setFillColor({66,66,200});
}
else {
text_box.setFillColor({66,66,66});
}
}
void Item::setOutlineThickness(float thickness) {
text_box.setOutlineThickness(thickness);
}