summaryrefslogtreecommitdiff
path: root/src/screen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/screen.c')
-rw-r--r--src/screen.c61
1 files changed, 50 insertions, 11 deletions
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
31#include <errno.h> 31#include <errno.h>
32#include <error.h> 32#include <error.h>
33#include <menu.h> 33#include <menu.h>
34#include <time.h>
34 35
35#include <stdio.h> 36#include <stdio.h>
36#include <stdlib.h> 37#include <stdlib.h>
@@ -91,6 +92,22 @@ static struct funcholder userfuncs[] = {
91 {.callback = quit, .type = FH_QUIT, .params = {.quitp = {}}} 92 {.callback = quit, .type = FH_QUIT, .params = {.quitp = {}}}
92}; 93};
93 94
95void intercleanup(int signum, siginfo_t *info, void *ucontext) {
96 endwin();
97 error(0, 0, "[VX-GAMBLEGROUND] Caught interrupt");
98 exit(0);
99
100 return;
101}
102
103static const struct sigaction handlers[] = {
104 { // intercleanup
105 .sa_flags = SA_SIGINFO,
106 .sa_mask = SIGINT,
107 .sa_sigaction = intercleanup
108 }
109};
110
94static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { 111static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) {
95 // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range 112 // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range
96 return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin; 113 return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin;
@@ -102,9 +119,9 @@ static int rangemod(int x, int offset, int min, int max) {
102} 119}
103 120
104static int init_rgb_color(int colornum, int red, int green, int blue) { 121static int init_rgb_color(int colornum, int red, int green, int blue) {
105 int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); 122 int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
106 int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); 123 int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
107 int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); 124 int nblue = normalize(blue, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX);
108 125
109 return init_color(colornum, nred, ngreen, nblue); 126 return init_color(colornum, nred, ngreen, nblue);
110} 127}
@@ -120,6 +137,9 @@ static int doinit(void) {
120 if(initscr() == NULL) // Initialize curses 137 if(initscr() == NULL) // Initialize curses
121 error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen"); 138 error(1, errno, "[VX-GAMBLEGROUND] Could not init standard screen");
122 139
140 if(sigaction(SIGINT, &handlers[0], NULL) < 0)
141 error(1, errno, "[VX-GAMBLEGROUND] Could not set up signal handler");
142
123 return 0; 143 return 0;
124} 144}
125 145
@@ -331,33 +351,52 @@ int main() {
331int spin(void *spinp) { 351int spin(void *spinp) {
332 struct spinp *p = (struct spinp *)spinp; 352 struct spinp *p = (struct spinp *)spinp;
333 353
334 for(int i = CCP_RED;; i = rangemod(i, 1, CCP_RED, CCP_WHITE)) { 354 struct timespec sleeper = {
355 .tv_sec = 0,
356 .tv_nsec = 1000000000 /* Nanoseconds in 1 second */ / NUMCOLORPAIRS
357 };
358
359 for(int color = CCP_RED, i = 0; i < (NUMCOLORPAIRS * NUMCOLORCYCLE); color = rangemod(color, 1, CCP_RED, CCP_WHITE), i++) {
335 // Change the color to testing for the banner 360 // Change the color to testing for the banner
336 wbkgd(p->bannerwin, COLOR_PAIR(i)); 361 wbkgd(p->bannerwin, COLOR_PAIR(color));
337 wnoutrefresh(p->bannerwin); 362 wnoutrefresh(p->bannerwin);
338 363
339 // Change the color to testing for the menu 364 // Change the color to testing for the menu
340 wbkgd(p->menuholder, COLOR_PAIR(i)); 365 wbkgd(p->menuholder, COLOR_PAIR(color));
341 set_menu_back(p->menu, COLOR_PAIR(i)); 366 set_menu_back(p->menu, COLOR_PAIR(color));
342 wnoutrefresh(p->menuholder); 367 wnoutrefresh(p->menuholder);
343 368
344 doupdate(); 369 doupdate();
345 sleep(1); 370 nanosleep(&sleeper, NULL);
346 } 371 }
347 372
373 // Revert colors back to normal
374 wbkgd(p->bannerwin, COLOR_PAIR(CCP_BANNER));
375 wnoutrefresh(p->bannerwin);
376
377 wbkgd(p->menuholder, COLOR_PAIR(CCP_BANNER));
378 set_menu_back(p->menu, COLOR_PAIR(CCP_BANNER));
379 wnoutrefresh(p->menuholder);
380
381 doupdate();
382
348 return 0; 383 return 0;
349} 384}
350 385
351// Increase number of spins 386// Increase number of spins
352int buy(void *buyp) { 387int buy(void *buyp) {
353 endwin(); 388 endwin();
354 error(1, 0, "buy"); 389 error(0, 0, "buy");
390 exit(0);
391
355 return 0; 392 return 0;
356} 393}
357 394
358// Quit out 395// Quit out
359int quit(void *quitp) { 396int quit(void *quitp) {
360 endwin(); 397 endwin();
361 error(1, 0, "quit"); 398 error(0, 0, "quit");
362 return 1; 399 exit(0);
400
401 return 0;
363} \ No newline at end of file 402} \ No newline at end of file