summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/screen.c103
-rw-r--r--src/screen.h10
2 files changed, 62 insertions, 51 deletions
diff --git a/src/screen.c b/src/screen.c
index 00381d2..44269ae 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -5,19 +5,6 @@
5 * files back. To do this, I am using curses and probably the menu library to create the TUI. Once I figure 5 * files back. To do this, I am using curses and probably the menu library to create the TUI. Once I figure
6 * out how to actually do this, everything should work hopefully maybe 6 * out how to actually do this, everything should work hopefully maybe
7 * 7 *
8Example window layout
9
10======================================================== (Window 1) (One line long, top of screen)
11VX-GAMBLEGROUND: <Random phrase from list of phrases>
12======================================================== (End Window 1) (Takes up space between top & bottom windows)
13======================================================== (Window 2)
14
15SLOTS HERE
16
17======================================================== (End Window 2)
18======================================================== (Window 3) (One line long, bottom of screen)
19> Spin > Buy Spins > Quit
20======================================================== (End Window 3)
21 */ 8 */
22 9
23#define _GNU_SOURCE 10#define _GNU_SOURCE
@@ -135,6 +122,11 @@ static int doinit(void) {
135 if(sigaction(SIGINT, &handler, NULL) < 0 || sigaction(SIGWINCH, &handler, NULL) < 0) 122 if(sigaction(SIGINT, &handler, NULL) < 0 || sigaction(SIGWINCH, &handler, NULL) < 0)
136 error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal catcher"); 123 error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal catcher");
137 124
125
126 cbreak(); // Disables character buffering
127 noecho(); // Disable echoing characters
128 curs_set(0); // Stop the cursor from blinking
129
138 return 0; 130 return 0;
139} 131}
140 132
@@ -205,6 +197,48 @@ static int init_items(ITEM *items[], const char *menuopts[], size_t menuopts_siz
205 return 0; 197 return 0;
206} 198}
207 199
200static int mvwcreate_box(WINDOW *win, int y, int x, int height, int width, const chtype chars[6]) {
201 const chtype * realchars = chars;
202 if(chars == NULL)
203 realchars = (const chtype []){ACS_VLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER};
204
205 // Vertical lines
206 mvwvline(win, y, x, realchars[0], height);
207 mvwvline(win, y, x + width - 1, realchars[0], height);
208
209 // Horizontal lines
210 mvwhline(win, y, x, realchars[1], width - 1);
211 mvwhline(win, y + height - 1, x, realchars[1], width) - 1;
212
213 // Corners
214 mvwaddch(win, y, x, realchars[2]);
215 mvwaddch(win, y, x + width - 1, realchars[3]);
216 mvwaddch(win, y + height - 1, x, realchars[4]);
217 mvwaddch(win, y + height - 1, x + width - 1, realchars[5]);
218
219 // Yeah I'm not happy about the magic numbers either, but this combo of shit makes the box draw correctly
220
221 return 0;
222}
223
224static int init_slotholder(struct slotholder *slots) {
225 getmaxyx(slots->slotwin, slots->sloty, slots->slotx);
226 for(size_t i = 0; i < STATIC_ARRSIZE(slots->subslot); i++) {
227 slots->subslot[i] = derwin(slots->slotwin, slots->sloty, slots->slotx/3, 0, slots->slotx/3 * i);
228
229 // This works but I need to figure out how to use box() because it should be nicer
230 int mx = 0, my = 0;
231 getmaxyx(slots->subslot[i], my, mx);
232
233 mvwcreate_box(slots->subslot[i], 1, 1, my - 2, mx - 2, NULL);
234
235 wnoutrefresh(slots->subslot[i]);
236 }
237
238 return 0;
239}
240
241
208static int init_custom_menu_format(WINDOW *menuholder, MENU *menu, const int fmtdim[2], Menu_Options toggleon, Menu_Options toggleoff) { 242static int init_custom_menu_format(WINDOW *menuholder, MENU *menu, const int fmtdim[2], Menu_Options toggleon, Menu_Options toggleoff) {
209 // Set menu options & format 243 // Set menu options & format
210 set_menu_format(menu, fmtdim[0], fmtdim[1]); 244 set_menu_format(menu, fmtdim[0], fmtdim[1]);
@@ -233,13 +267,7 @@ int main() {
233 doinit(); 267 doinit();
234 docolors(); 268 docolors();
235 269
236 cbreak(); // Disables character buffering
237 noecho(); // Disable echoing characters
238 curs_set(0); // Stop the cursor from blinking
239
240
241 // Variable definitions 270 // Variable definitions
242
243 ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items 271 ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items
244 struct funcholder *p = NULL; // Function pointer used for callbacks in the menu driver 272 struct funcholder *p = NULL; // Function pointer used for callbacks in the menu driver
245 WINDOW *menuholder = NULL; // The window for displaying the menu 273 WINDOW *menuholder = NULL; // The window for displaying the menu
@@ -284,28 +312,7 @@ int main() {
284 error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window"); 312 error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window");
285 } 313 }
286 314
287 /* 315 init_slotholder(&slots);
288 const char *sampletext = "Lmao longer sample";
289 mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext);
290 wnoutrefresh(slots);
291 */
292
293 /*
294 int sy, sx;
295 getmaxyx(slots, sy, sx);
296 WINDOW *TEST = derwin(slots, sy, sx/3, 0, 0);
297 wbkgd(TEST, COLOR_PAIR(CCP_TESTING));
298 waddstr(TEST, "lol");
299 wnoutrefresh(TEST);
300 //*/
301
302 getmaxyx(slots.slotwin, slots.sloty, slots.slotx);
303 for(size_t i = 0; i < STATIC_ARRSIZE(slots.subslots); i++) {
304 slots.subslots[i].subslot = derwin(slots.slotwin, slots.sloty, slots.slotx/3, 0, slots.slotx/3 * i);
305 wbkgd(slots.subslots[i].subslot, COLOR_PAIR((slots.subslots[i].color = CCP_RED + i)));
306 mvwaddstr(slots.subslots[i].subslot, slots.sloty/2, slots.slotx/3/2 - 2, "lol");
307 wnoutrefresh(slots.subslots[i].subslot);
308 }
309 316
310 doupdate(); 317 doupdate();
311 318
@@ -390,10 +397,11 @@ int spin(void *spinp) {
390 set_menu_back(p->menu, COLOR_PAIR(color)); 397 set_menu_back(p->menu, COLOR_PAIR(color));
391 wnoutrefresh(p->menuholder); 398 wnoutrefresh(p->menuholder);
392 399
393 for(size_t subs = 0; subs < STATIC_ARRSIZE(p->slots->subslots); subs++) { 400 for(size_t subs = 0; subs < STATIC_ARRSIZE(p->slots->subslot); subs++) {
394 p->slots->subslots[subs].color = rangemod(p->slots->subslots[subs].color, 1, CCP_RED, CCP_WHITE); 401 /* Previous solution fucked it by changing the actual color when it's supposed to be the default color to revert back to
395 wbkgd(p->slots->subslots[subs].subslot, COLOR_PAIR(p->slots->subslots[subs].color)); 402 // This works better, but is also more ugly. So be it */
396 wnoutrefresh(p->slots->subslots[subs].subslot); 403 wbkgd(p->slots->subslot[subs], COLOR_PAIR(rangemod(CCP_CURSES_DEFAULT, i + CCP_RED, CCP_RED, CCP_WHITE)));
404 wnoutrefresh(p->slots->subslot[subs]);
397 } 405 }
398 406
399 doupdate(); 407 doupdate();
@@ -408,6 +416,11 @@ int spin(void *spinp) {
408 set_menu_back(p->menu, COLOR_PAIR(CCP_BANNER)); 416 set_menu_back(p->menu, COLOR_PAIR(CCP_BANNER));
409 wnoutrefresh(p->menuholder); 417 wnoutrefresh(p->menuholder);
410 418
419 for(size_t i = 0; i < STATIC_ARRSIZE(p->slots->subslot); i++) {
420 wbkgd(p->slots->subslot[i], COLOR_PAIR(CCP_CURSES_DEFAULT));
421 wnoutrefresh(p->slots->subslot[i]);
422 }
423
411 doupdate(); 424 doupdate();
412 425
413 return 0; 426 return 0;
diff --git a/src/screen.h b/src/screen.h
index 93297ee..9ffff20 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -46,7 +46,9 @@ enum custom_colors {
46}; 46};
47 47
48enum customcolor_pairs { 48enum customcolor_pairs {
49 CCP_UNDEFINED, 49 CCP_UNDEFINED = -1,
50
51 CCP_CURSES_DEFAULT = 0,
50 52
51 CCP_TESTING, 53 CCP_TESTING,
52 CCP_BANNER, 54 CCP_BANNER,
@@ -71,11 +73,7 @@ struct slotholder {
71 int slotx; 73 int slotx;
72 int sloty; 74 int sloty;
73 75
74 struct subslot { 76 WINDOW *subslot[3];
75 WINDOW *subslot;
76 enum customcolor_pairs color;
77
78 } subslots[3];
79}; 77};
80 78
81struct funcholder { 79struct funcholder {