From e53a059c188c72bf7eea7a966606fe086e4c2d04 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 26 Aug 2024 21:19:46 -0500 Subject: Box --- src/screen.c | 103 +++++++++++++++++++++++++++++++++-------------------------- src/screen.h | 10 +++--- 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 @@ * files back. To do this, I am using curses and probably the menu library to create the TUI. Once I figure * out how to actually do this, everything should work hopefully maybe * -Example window layout - -======================================================== (Window 1) (One line long, top of screen) -VX-GAMBLEGROUND: -======================================================== (End Window 1) (Takes up space between top & bottom windows) -======================================================== (Window 2) - -SLOTS HERE - -======================================================== (End Window 2) -======================================================== (Window 3) (One line long, bottom of screen) -> Spin > Buy Spins > Quit -======================================================== (End Window 3) */ #define _GNU_SOURCE @@ -135,6 +122,11 @@ static int doinit(void) { if(sigaction(SIGINT, &handler, NULL) < 0 || sigaction(SIGWINCH, &handler, NULL) < 0) error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal catcher"); + + cbreak(); // Disables character buffering + noecho(); // Disable echoing characters + curs_set(0); // Stop the cursor from blinking + return 0; } @@ -205,6 +197,48 @@ static int init_items(ITEM *items[], const char *menuopts[], size_t menuopts_siz return 0; } +static int mvwcreate_box(WINDOW *win, int y, int x, int height, int width, const chtype chars[6]) { + const chtype * realchars = chars; + if(chars == NULL) + realchars = (const chtype []){ACS_VLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER}; + + // Vertical lines + mvwvline(win, y, x, realchars[0], height); + mvwvline(win, y, x + width - 1, realchars[0], height); + + // Horizontal lines + mvwhline(win, y, x, realchars[1], width - 1); + mvwhline(win, y + height - 1, x, realchars[1], width) - 1; + + // Corners + mvwaddch(win, y, x, realchars[2]); + mvwaddch(win, y, x + width - 1, realchars[3]); + mvwaddch(win, y + height - 1, x, realchars[4]); + mvwaddch(win, y + height - 1, x + width - 1, realchars[5]); + + // Yeah I'm not happy about the magic numbers either, but this combo of shit makes the box draw correctly + + return 0; +} + +static int init_slotholder(struct slotholder *slots) { + getmaxyx(slots->slotwin, slots->sloty, slots->slotx); + for(size_t i = 0; i < STATIC_ARRSIZE(slots->subslot); i++) { + slots->subslot[i] = derwin(slots->slotwin, slots->sloty, slots->slotx/3, 0, slots->slotx/3 * i); + + // This works but I need to figure out how to use box() because it should be nicer + int mx = 0, my = 0; + getmaxyx(slots->subslot[i], my, mx); + + mvwcreate_box(slots->subslot[i], 1, 1, my - 2, mx - 2, NULL); + + wnoutrefresh(slots->subslot[i]); + } + + return 0; +} + + static int init_custom_menu_format(WINDOW *menuholder, MENU *menu, const int fmtdim[2], Menu_Options toggleon, Menu_Options toggleoff) { // Set menu options & format set_menu_format(menu, fmtdim[0], fmtdim[1]); @@ -233,13 +267,7 @@ int main() { doinit(); docolors(); - cbreak(); // Disables character buffering - noecho(); // Disable echoing characters - curs_set(0); // Stop the cursor from blinking - - // Variable definitions - ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items struct funcholder *p = NULL; // Function pointer used for callbacks in the menu driver WINDOW *menuholder = NULL; // The window for displaying the menu @@ -284,28 +312,7 @@ int main() { error(1, errno, "[VX-GAMBLEGROUND] Could not create slots window"); } - /* - const char *sampletext = "Lmao longer sample"; - mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext); - wnoutrefresh(slots); - */ - - /* - int sy, sx; - getmaxyx(slots, sy, sx); - WINDOW *TEST = derwin(slots, sy, sx/3, 0, 0); - wbkgd(TEST, COLOR_PAIR(CCP_TESTING)); - waddstr(TEST, "lol"); - wnoutrefresh(TEST); - //*/ - - getmaxyx(slots.slotwin, slots.sloty, slots.slotx); - for(size_t i = 0; i < STATIC_ARRSIZE(slots.subslots); i++) { - slots.subslots[i].subslot = derwin(slots.slotwin, slots.sloty, slots.slotx/3, 0, slots.slotx/3 * i); - wbkgd(slots.subslots[i].subslot, COLOR_PAIR((slots.subslots[i].color = CCP_RED + i))); - mvwaddstr(slots.subslots[i].subslot, slots.sloty/2, slots.slotx/3/2 - 2, "lol"); - wnoutrefresh(slots.subslots[i].subslot); - } + init_slotholder(&slots); doupdate(); @@ -390,10 +397,11 @@ int spin(void *spinp) { set_menu_back(p->menu, COLOR_PAIR(color)); wnoutrefresh(p->menuholder); - for(size_t subs = 0; subs < STATIC_ARRSIZE(p->slots->subslots); subs++) { - p->slots->subslots[subs].color = rangemod(p->slots->subslots[subs].color, 1, CCP_RED, CCP_WHITE); - wbkgd(p->slots->subslots[subs].subslot, COLOR_PAIR(p->slots->subslots[subs].color)); - wnoutrefresh(p->slots->subslots[subs].subslot); + for(size_t subs = 0; subs < STATIC_ARRSIZE(p->slots->subslot); subs++) { + /* Previous solution fucked it by changing the actual color when it's supposed to be the default color to revert back to + // This works better, but is also more ugly. So be it */ + wbkgd(p->slots->subslot[subs], COLOR_PAIR(rangemod(CCP_CURSES_DEFAULT, i + CCP_RED, CCP_RED, CCP_WHITE))); + wnoutrefresh(p->slots->subslot[subs]); } doupdate(); @@ -408,6 +416,11 @@ int spin(void *spinp) { set_menu_back(p->menu, COLOR_PAIR(CCP_BANNER)); wnoutrefresh(p->menuholder); + for(size_t i = 0; i < STATIC_ARRSIZE(p->slots->subslot); i++) { + wbkgd(p->slots->subslot[i], COLOR_PAIR(CCP_CURSES_DEFAULT)); + wnoutrefresh(p->slots->subslot[i]); + } + doupdate(); 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 { }; enum customcolor_pairs { - CCP_UNDEFINED, + CCP_UNDEFINED = -1, + + CCP_CURSES_DEFAULT = 0, CCP_TESTING, CCP_BANNER, @@ -71,11 +73,7 @@ struct slotholder { int slotx; int sloty; - struct subslot { - WINDOW *subslot; - enum customcolor_pairs color; - - } subslots[3]; + WINDOW *subslot[3]; }; struct funcholder { -- cgit v1.2.3