-
Notifications
You must be signed in to change notification settings - Fork 9
/
gui.cpp
321 lines (276 loc) · 8.73 KB
/
gui.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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
This file is part of Retro Graphics Toolkit
Retro Graphics Toolkit 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 any later version.
Retro Graphics Toolkit 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 Retro Graphics Toolkit. If not, see <http://www.gnu.org/licenses/>.
Copyright Sega16 (or whatever you wish to call me) (2012-2017)
*/
#include <FL/Enumerations.H>
#if (FL_MAJOR_VERSION > 1) || (FL_MINOR_VERSION >= 3)
#include <FL/Fl_Native_File_Chooser.H>
#else
#include <FL/Fl_File_Chooser.H>
#endif
#include <stdint.h>
#include <cstdarg>
#include <cstdio>
#include "gui.h"
#include "project.h"
#include "class_global.h"
unsigned map_scroll_pos_x;
unsigned map_scroll_pos_y;
unsigned map_off_x, map_off_y;
unsigned tile_edit_offset_x;
unsigned tile_edit_offset_y;
unsigned tile_placer_tile_offset_y;
unsigned tile_edit_truecolor_off_x, tile_edit_truecolor_off_y;
unsigned true_color_box_x, true_color_box_y;
bool show_grid;
bool G_hflip[2];
bool G_vflip[2];
bool G_highlow_p[2];
bool show_grid_placer;
unsigned tile_zoom_edit;
uint8_t truecolor_temp[4];/*!< This stores the rgba data selected with the truecolor sliders*/
unsigned mode_editor;//this is used to determine which thing to draw
bool showTrueColor;
bool rowSolo;
bool tileEditModePlace_G;
uint32_t selTileE_G[2];
static int returnVal = 0;
static Fl_Choice*PopC;
static Fl_Window * winP;
unsigned SpriteOff[2];
void mkProgress(Fl_Window**winP, Fl_Progress**progress) {
(*winP) = new Fl_Window(400, 45, "Progress"); // access parent window
(*winP)->begin(); // add progress bar to it..
(*progress) = new Fl_Progress(25, 7, 350, 30);
(*progress)->minimum(0.0); // set progress range to be 0.0 ~ 1.0
(*progress)->maximum(1.0);
(*progress)->color(0x88888800); // background color
(*progress)->selection_color(0x4444ff00); // progress bar color
(*progress)->labelcolor(FL_WHITE); // percent text color
(*progress)->label("Please wait");
(*winP)->end(); // end adding to window
(*winP)->set_modal();
(*winP)->show();
}
static void zeroError(const char*more) {
fl_alert("Please enter a value greater than zero\n%s", more);
}
static void fixVal(Fl_Int_Input*in, int val, bool redraw) {
char tmp[16];
snprintf(tmp, 16, "%d", val);
in->value(tmp);
if (redraw && window)
window->redraw();
}
int SafeTxtInput(Fl_Int_Input*in, bool redraw) {
int val = atoi(in->value());
if (val <= 0) {
if (val == 0) {
zeroError("Defaulting to one");
val = 1;
} else {
zeroError("Defaulting to absolute value");
val = -val;
}
fixVal(in, val, redraw);
}
return val;
}
int SafeTxtInputZeroAllowed(Fl_Int_Input*in, bool redraw) {
int val = atoi(in->value());
if (val < 0) {
zeroError("Defaulting to absolute value");
val = -val;
fixVal(in, val, redraw);
}
return val;
}
static void checkMaxSlider(uint32_t newMax, Fl_Slider*s) {
if (s->value() > newMax)
s->value(newMax);
}
void updateTileSelectAmt(uint32_t newMax) {
if (!window)
return;
char tmp[128];
snprintf(tmp, 128, "Total tiles: %d", newMax);
window->totalTiles->copy_label(tmp);
if (newMax) {
if (!window->tile_select->visible()) {
window->tile_select->show();
window->tile_select_2->show();
window->tile_select_3->show();
window->spriteslat->show();
window->spritest->show();
}
--newMax;
window->tile_select->maximum(newMax);
checkMaxSlider(newMax, window->tile_select);
window->tile_select_2->maximum(newMax);
checkMaxSlider(newMax, window->tile_select_2);
if (currentProject->Chunk && currentProject->tms && currentProject->containsData(pjHaveChunks) && currentProject->Chunk->useBlocks) {
window->tile_select_3->maximum(currentProject->tms->maps[currentProject->curPlane].amt - 1);
checkMaxSlider(currentProject->tms->maps[currentProject->curPlane].amt - 1, window->tile_select_3);
} else {
window->tile_select_3->maximum(newMax);
checkMaxSlider(newMax, window->tile_select_3);
}
window->spriteslat->maximum(newMax);
checkMaxSlider(newMax, window->spriteslat);
window->spritest->maximum(newMax);
checkMaxSlider(newMax, window->spritest);
} else {
if (window->tile_select->visible()) {
window->tile_select->hide();
window->tile_select_2->hide();
window->tile_select_3->hide();
window->spriteslat->hide();
window->spritest->hide();
}
}
}
void updateTileSelectAmt(void) {
updateTileSelectAmt(currentProject->tileC->amount());
}
static void setRet(Fl_Widget*, void*r) {
bool Cancel = (uintptr_t)r ? true : false;
if (Cancel)
returnVal = -1;
else
returnVal = PopC->value();
winP->hide();
}
int menuPopupVector(const char * title, const char * text, std::vector<std::string>&slst) {
winP = new Fl_Window(480, 128, title);
winP->begin();
if (text)
new Fl_Box(FL_NO_BOX, 8, 8, 464, 88, text);
PopC = new Fl_Choice(8, 96, 192, 24);
for (std::string &s : slst) // Loop until all numbers are added
PopC->add(s.c_str(), 0, 0, 0, 0);
PopC->value(0);
Fl_Button * Ok = new Fl_Button(200, 96, 64, 24, fl_ok);
Ok->callback(setRet, 0);
Fl_Button * Cancel = new Fl_Button(264, 96, 64, 24, fl_cancel);
Cancel->callback(setRet, (void*)1);
winP->end();
winP->set_modal();
winP->show();
while (winP->shown())
Fl::wait();
delete winP;
return returnVal;
return -1;
}
int MenuPopup(const char * title, const char * text, unsigned num, unsigned def, ...) {
if (num) {
winP = new Fl_Window(480, 128, title);
winP->begin();
if (text)
new Fl_Box(FL_NO_BOX, 8, 8, 464, 88, text);
PopC = new Fl_Choice(8, 96, 192, 24);
va_list arguments;
va_start(arguments, num); // Initializing arguments to store all values after num
for (unsigned x = 0; x < num; ++x) // Loop until all numbers are added
PopC->add(va_arg(arguments, const char*), 0, 0, 0, 0);
PopC->value(def);
Fl_Button * Ok = new Fl_Button(200, 96, 64, 24, fl_ok);
Ok->callback(setRet, 0);
Fl_Button * Cancel = new Fl_Button(264, 96, 64, 24, fl_cancel);
Cancel->callback(setRet, (void*)1);
winP->end();
winP->set_modal();
winP->show();
va_end(arguments); // Cleans up the list
while (winP->shown())
Fl::wait();
delete winP;
return returnVal;
}
return -1;
}
int menuPopupArray(const char * title, const char * text, unsigned def, const Fl_Menu_Item*arr) {
winP = new Fl_Window(480, 128, title);
winP->begin();
if (text)
new Fl_Box(FL_NO_BOX, 8, 8, 464, 88, text);
PopC = new Fl_Choice(8, 96, 192, 24);
PopC->copy(arr);
PopC->value(def);
Fl_Button * Ok = new Fl_Button(200, 96, 64, 24, fl_ok);
Ok->callback(setRet, 0);
Fl_Button * Cancel = new Fl_Button(264, 96, 64, 24, fl_cancel);
Cancel->callback(setRet, (void*)1);
winP->end();
winP->set_modal();
winP->show();
while (winP->shown())
Fl::wait();
delete winP;
return returnVal;
return -1;
}
bool loadOrSaveFile(std::string&result, const char * the_tile, bool save_file) {
#if (FL_MAJOR_VERSION > 1) || (FL_MINOR_VERSION >= 3)
// Create native chooser
Fl_Native_File_Chooser native;
native.title(the_tile);
if (save_file)
native.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
else
native.type(Fl_Native_File_Chooser::BROWSE_FILE);
// Show native chooser
switch (native.show()) {
case -1:
fl_alert("Error %s", native.errmsg());
break; // ERROR
case 1:
fprintf(stderr, "*** CANCEL\n");
break; // CANCEL
default:// Picked File
if (native.filename()) {
result = native.filename();
return true;
}
break;
}
return false;
#else
const char*fnameTmp = fl_file_chooser(the_tile, nullptr, nullptr);
if (fnameTmp != nullptr && strlen(fnameTmp) > 0) {
result = fnameTmp;
return true;
} else
return false;
#endif
}
bool verify_str_number_only(const char * str) {
/*!
FLTK provides an input text box that makes it easy for the user to type text however as a side effect they may accidentally enter non-numeric characters.
This function address that issue by error checking the string and it also gives the user feedback so they are aware that the input box takes only numbers.
This function returns true when the string contains only numbers 0-9 and false when there are other characters.
It also allows the use of the minus character '-' without the quotes.
*/
while (*str++) {
if (*str != 0 && *str != '-') {
if (*str < '0') {
fl_alert("Please enter only numbers in decimal format\nCharacter entered %c", *str);
return false;
}
if (*str > '9') {
fl_alert("Please enter only numbers in decimal format\nCharacter entered %c", *str);
return false;
}
}
}
return true;
}