-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlgl.cpp
More file actions
243 lines (209 loc) · 7.19 KB
/
Copy pathlgl.cpp
File metadata and controls
243 lines (209 loc) · 7.19 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
Copyright 2015 Carter Turnbaugh
This file is part of Lgl.
Lgl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Lgl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Lgl. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lgl.h"
#include <fstream>
#include <cstdlib>
using namespace std;
lgl::lgl(int era) : era(era){
buttons.clear();
cmdbuttons.clear();
endbuttons.clear();
multibuttons.clear();
endmultibuttons.clear();
elbows.clear();
elbowbuttons.clear();
bars.clear();
fullscreens.clear();
}
int lgl::button(int corner_x, int corner_y, int size, int color, std::string text){
lgl_button button(corner_x, corner_y, size, era, color, text);
buttons.push_back(button);
return 0;
}
int lgl::cmdbutton(int corner_x, int corner_y, int color, std::string text){
lgl_cmdbutton cmdbutton(corner_x, corner_y, era, color, text);
cmdbuttons.push_back(cmdbutton);
return 0;
}
int lgl::endbutton(int corner_x, int corner_y, int orientation, int color, std::string text){
lgl_endbutton endbutton(corner_x, corner_y, orientation, era, color, text);
endbuttons.push_back(endbutton);
return 0;
}
int lgl::multibutton(int corner_x, int corner_y, int extend, int color){
lgl_multibutton multibutton(corner_x, corner_y, extend, era, color);
multibuttons.push_back(multibutton);
return 0;
}
int lgl::endmultibutton(int corner_x, int corner_y, int color){
lgl_endmultibutton endmultibutton(corner_x, corner_y, era, color);
endmultibuttons.push_back(endmultibutton);
return 0;
}
int lgl::elbow(int corner_x, int corner_y, int length, int size, int orientation_x, int orientation_y, int color, std::string text){
lgl_elbow elbow(corner_x, corner_y, length, size, orientation_x, orientation_y, era, color, text);
elbows.push_back(elbow);
return 0;
}
int lgl::elbowbutton(int corner_x, int corner_y, int length, int size, int orientation_x, int orientation_y, int color, std::string text){
lgl_elbowbutton elbowbutton(corner_x, corner_y, length, size, orientation_x, orientation_y, era, color, text);
elbowbuttons.push_back(elbowbutton);
return 0;
}
int lgl::bar(int corner_x, int corner_y, int length, int color){
lgl_bar bar(corner_x, corner_y, length, era, color);
bars.push_back(bar);
return 0;
}
int lgl::fullscreen(int corner_x, int corner_y, int size_x, int size_y, int color, std::string main_text, std::string sub_text){
lgl_fullscreen fullscreen(corner_x, corner_y, size_x, size_y, era, color, main_text, sub_text);
fullscreens.push_back(fullscreen);
return 0;
}
int lgl::setmultibutton(int id, int value, bool end){
if(!end){
if(id >= multibuttons.size()){
return -1;
}
multibuttons[id].setvalue(value);
}
else{
if(id >= endmultibuttons.size()){
return -1;
}
endmultibuttons[id].setvalue(value);
}
return 0;
}
int lgl::draw(){
for(int i = 0; i < buttons.size(); i++) buttons[i].draw();
for(int i = 0; i < cmdbuttons.size(); i++) cmdbuttons[i].draw();
for(int i = 0; i < endbuttons.size(); i++) endbuttons[i].draw();
for(int i = 0; i < multibuttons.size(); i++) multibuttons[i].draw();
for(int i = 0; i < endmultibuttons.size(); i++) endmultibuttons[i].draw();
for(int i = 0; i < elbows.size(); i++) elbows[i].draw();
for(int i = 0; i < elbowbuttons.size(); i++) elbowbuttons[i].draw();
for(int i = 0; i < bars.size(); i++) bars[i].draw();
for(int i = 0; i < fullscreens.size(); i++) fullscreens[i].draw();
return 0;
}
string lgl::getclicked(int mouse_x, int mouse_y){
string clicked_title = "";
for(int i = 0; i < buttons.size(); i++){
if(buttons[i].clicked(mouse_x, mouse_y)) clicked_title = buttons[i].text;
}
for(int i = 0; i < cmdbuttons.size(); i++){
if(cmdbuttons[i].clicked(mouse_x, mouse_y)) clicked_title = cmdbuttons[i].text;
}
for(int i = 0; i < endbuttons.size(); i++){
if(endbuttons[i].clicked(mouse_x, mouse_y)) clicked_title = endbuttons[i].text;
}
for(int i = 0; i < elbowbuttons.size(); i++){
if(elbowbuttons[i].clicked(mouse_x, mouse_y)) clicked_title = elbowbuttons[i].gettext();
}
return clicked_title;
}
vector<string> split_string(string data, char splitter){
vector<string> tokens = vector<string>();
string tmp = "";
for(int i = 0; i < data.length(); i++){
if(data[i] == splitter){
tokens.push_back(tmp);
tmp = "";
}
else{
tmp += data[i];
}
}
tokens.push_back(tmp);
return tokens;
}
int lgl::load_config(string path){
fstream configfile;
configfile.open(path.c_str());
while(!configfile.eof()){
string line;
getline(configfile, line);
vector<string> data = split_string(line, ' ');
if(data[0] == "button"){
button(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str()), // size
atoi(data[4].c_str()), // color
data[5]); // text
}
else if(data[0] == "cmdbutton"){
cmdbutton(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str()), // color
data[4]); // text
}
else if(data[0] == "endbutton"){
endbutton(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str()), // orientation
atoi(data[4].c_str()), // color
data[5]); // text
}
else if(data[0] == "multibutton"){
multibutton(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str()), // extend
atoi(data[4].c_str())); //color
}
else if(data[0] == "endmultibutton"){
endmultibutton(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str())); //color
}
else if(data[0] == "elbow"){
elbow(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str()), // length
atoi(data[4].c_str()), // size
atoi(data[5].c_str()), // orientation_x
atoi(data[6].c_str()), // orientation_y
atoi(data[7].c_str()), // color
data[8]); // text
}
else if(data[0] == "elbowbutton"){
elbowbutton(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str()), // length
atoi(data[4].c_str()), // size
atoi(data[5].c_str()), // orientation_x
atoi(data[6].c_str()), // orientation_y
atoi(data[7].c_str()), // color
data[8]); // text
}
else if(data[0] == "bar"){
bar(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str()), // length
atoi(data[4].c_str())); // color
}
else if(data[0] == "fullscreen"){
fullscreen(atoi(data[1].c_str()), // corner_x
atoi(data[2].c_str()), // corner_y
atoi(data[3].c_str()), // size_x
atoi(data[4].c_str()), // size_y
atoi(data[5].c_str()), // color
data[6], // main_text
data[7]); // sub_text
}
}
configfile.close();
return 0;
}