From e3c986f45eeeb1bb3ba5e931ecf042907676b3df Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Tue, 30 Jul 2024 22:12:22 -0500 Subject: COLORS!!! --- src/screen.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 11 deletions(-) (limited to 'src/screen.c') diff --git a/src/screen.c b/src/screen.c index 4287da8..6df9cac 100644 --- a/src/screen.c +++ b/src/screen.c @@ -31,6 +31,7 @@ SLOTS HERE #include #include #include +#include #include #include @@ -91,6 +92,22 @@ static struct funcholder userfuncs[] = { {.callback = quit, .type = FH_QUIT, .params = {.quitp = {}}} }; +void intercleanup(int signum, siginfo_t *info, void *ucontext) { + endwin(); + error(0, 0, "[VX-GAMBLEGROUND] Caught interrupt"); + exit(0); + + return; +} + +static const struct sigaction handlers[] = { + { // intercleanup + .sa_flags = SA_SIGINFO, + .sa_mask = SIGINT, + .sa_sigaction = intercleanup + } +}; + static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin; @@ -102,9 +119,9 @@ static int rangemod(int x, int offset, int min, int max) { } static int init_rgb_color(int colornum, int red, int green, int blue) { - int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); - int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); - int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); + int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); + int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); + int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); return init_color(colornum, nred, ngreen, nblue); } @@ -120,6 +137,9 @@ static int doinit(void) { if(initscr() == NULL) // Initialize curses error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen"); + if(sigaction(SIGINT, &handlers[0], NULL) < 0) + error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal handler"); + return 0; } @@ -331,33 +351,52 @@ int main() { int spin(void *spinp) { struct spinp *p = (struct spinp *)spinp; - for(int i = CCP_RED;; i = rangemod(i, 1, CCP_RED, CCP_WHITE)) { + struct timespec sleeper = { + .tv_sec = 0, + .tv_nsec = 1000000000 /* Nanoseconds in 1 second */ / NUMCOLORPAIRS + }; + + for(int color = CCP_RED, i = 0; i < (NUMCOLORPAIRS * NUMCOLORCYCLE); color = rangemod(color, 1, CCP_RED, CCP_WHITE), i++) { // Change the color to testing for the banner - wbkgd(p->bannerwin, COLOR_PAIR(i)); + wbkgd(p->bannerwin, COLOR_PAIR(color)); wnoutrefresh(p->bannerwin); // Change the color to testing for the menu - wbkgd(p->menuholder, COLOR_PAIR(i)); - set_menu_back(p->menu, COLOR_PAIR(i)); + wbkgd(p->menuholder, COLOR_PAIR(color)); + set_menu_back(p->menu, COLOR_PAIR(color)); wnoutrefresh(p->menuholder); doupdate(); - sleep(1); + nanosleep(&sleeper, NULL); } + // Revert colors back to normal + wbkgd(p->bannerwin, COLOR_PAIR(CCP_BANNER)); + wnoutrefresh(p->bannerwin); + + wbkgd(p->menuholder, COLOR_PAIR(CCP_BANNER)); + set_menu_back(p->menu, COLOR_PAIR(CCP_BANNER)); + wnoutrefresh(p->menuholder); + + doupdate(); + return 0; } // Increase number of spins int buy(void *buyp) { endwin(); - error(1, 0, "buy"); + error(0, 0, "buy"); + exit(0); + return 0; } // Quit out int quit(void *quitp) { endwin(); - error(1, 0, "quit"); - return 1; + error(0, 0, "quit"); + exit(0); + + return 0; } \ No newline at end of file -- cgit v1.2.3