-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButton.cpp
More file actions
164 lines (136 loc) · 2.89 KB
/
Copy pathButton.cpp
File metadata and controls
164 lines (136 loc) · 2.89 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "Button.h"
// // BUTTON // //
Button::Button() {
x = LEFT_BORDER;
y = 0;
}
Button::Button(string texture, int x, int y) {
this->x = x;
this->y = y;
setSprite(texture);
}
void Button::setSprite(string texture) {
pic.setTexture(TextureManager::GetTexture(texture));
pic.setPosition(x, y);
}
void Button::Draw(sf::RenderWindow& window) {
window.draw(pic);
}
bool Button::isPressed(int pressx, int pressy) {
if (pressx >= x && pressx <= x + BUTTON_WIDTH && pressy >= y && pressy < y + BUTTON_HEIGHT) {
return true;
}
return false;
}
// // TEXTBOX // //
TextBox::TextBox() {
SetText("");
interactive = true;
x = 0;
y = 0;
setSprite("TextBox");
pressed = false;
}
TextBox::TextBox(bool interactive, string name, int x, int y) {
SetText(name);
this->interactive = interactive;
this->x = x;
this->y = y;
text.setPosition(x + BUTTON_BORDER, y + BUTTON_BORDER);
pressed = false;
setSprite("TextBox");
}
void TextBox::SetText(string name) {
this->name = name;
text.setFont(TextureManager::GetFont(FONT));
text.setString(name);
text.setCharacterSize(100); // in pixels, not points!
text.setFillColor(sf::Color::White);
text.setStyle(sf::Text::Bold);
}
void TextBox::Draw(sf::RenderWindow& window) {
window.draw(pic);
window.draw(text);
}
void TextBox::Press(bool down) {
if (interactive && down) {
setSprite("pressedText");
pressed = true;
}
else if (interactive) {
setSprite("textBox");
pressed = false;
}
}
void TextBox::Position(int x, int y) {
this->x = x;
this->y = y;
setSprite("TextBox");
}
bool TextBox::Click(int x, int y) {
if (interactive && Button::isPressed(x, y)) {
Press(true);
return true;
}
Press(false);
return false;
}
bool TextBox::isPressed() {
return pressed;
}
void TextBox::addText(char letter) {
if (name.size() < NAME_LEN && isupper(letter + 65)) {
name = name + (char)(letter + 65);
}
else if (letter == sf::Keyboard::Backspace && name.size() > 0) {
name = name.erase(name.size() - 1);
}
SetText(name);
}
bool TextBox::isComplete() {
if (name.size() == NAME_LEN) {
return true;
}
return false;
}
string TextBox::getText() {
return name;
}
// TEXTWRAP
void TextWrap::SetText(string name) {
this->name = name;
text.setFont(TextureManager::GetFont(FONT));
text.setString(name + add);
text.setCharacterSize(TEXT_HEIGHT); // in pixels, not points!
text.setFillColor(sf::Color::White);
text.setStyle(sf::Text::Bold);
}
TextWrap::TextWrap() {
name = "";
add = "";
x = 0;
y = 0;
}
TextWrap::TextWrap(string name, int x, int y) {
this->x = x;
this->y = y;
add = "";
SetText(name);
text.setPosition(x, y);
}
void TextWrap::Draw(sf::RenderWindow& window) {
window.draw(text);
}
void TextWrap::addText(string letters) {
name = name + letters;
SetText(name);
}
void TextWrap::addon(string add) {
this->add = add;
SetText(name);
}
void TextWrap::Position(int x, int y) {
this->x = x;
this->y = y;
text.setPosition(x, y);
}