summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/screen.c77
-rw-r--r--src/screen.h33
2 files changed, 85 insertions, 25 deletions
diff --git a/src/screen.c b/src/screen.c
index 77b1a3b..626b1b1 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -83,6 +83,12 @@ static const char *menu_choices[] = {
83 "Quit" 83 "Quit"
84}; 84};
85 85
86static struct funcholder userfuncs[] = {
87 {.callback = spin, .type = FH_SPIN, .params = {.spinp = {.bannerwin = NULL, .phrasenum = 0}}},
88 {.callback = buy, .type = FH_BUY, .params = {.buyp = {}}},
89 {.callback = quit, .type = FH_QUIT, .params = {.quitp = {}}}
90};
91
86static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { 92static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) {
87 // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range 93 // x(normal) = (b - a) * ((x - x(min)) / (max x - min x)) + a, where [a, b] is the new range
88 return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin; 94 return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin;
@@ -132,7 +138,7 @@ static int docolors(void) {
132 init_rgb_color(CC_WHITE, 255, 255, 255); 138 init_rgb_color(CC_WHITE, 255, 255, 255);
133 139
134 init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); 140 init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE);
135 init_pair(CCP_TESTING, CC_RED, CC_WHITE); 141 init_pair(CCP_TESTING, CC_WHITE, CC_RED);
136 } else { 142 } else {
137 endwin(); 143 endwin();
138 error(1, ENOTSUP, "[VX-GAMBLEGROUND] Colors are not supported on your terminal"); 144 error(1, ENOTSUP, "[VX-GAMBLEGROUND] Colors are not supported on your terminal");
@@ -141,6 +147,21 @@ static int docolors(void) {
141 return 0; 147 return 0;
142} 148}
143 149
150static WINDOW* create_banner(int col, int randomnum) {
151 // Create the banner window
152 WINDOW *phrase = newwin(1, col, 0, 0);
153 if(phrase == NULL) {
154 endwin();
155 error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window");
156 }
157 wbkgd(phrase, COLOR_PAIR(1));
158 mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: ");
159 waddstr(phrase, phrases[randomnum]);
160 wrefresh(phrase);
161
162 return phrase;
163}
164
144int main() { 165int main() {
145 doinit(); 166 doinit();
146 docolors(); 167 docolors();
@@ -152,7 +173,6 @@ int main() {
152 173
153 // Variable definitions 174 // Variable definitions
154 175
155 struct funcholder funcholder[STATIC_ARRSIZE(menu_choices)]; // Stores the function pointers used for the menu
156 ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items 176 ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; // An array of ITEM pointers large enough to store all the menu items
157 int holder1 = -1, holder2 = -1; // Holders for the max yx of the menu subwindow 177 int holder1 = -1, holder2 = -1; // Holders for the max yx of the menu subwindow
158 struct funcholder *p = NULL; // Function pointer used for callbacks in the menu driver 178 struct funcholder *p = NULL; // Function pointer used for callbacks in the menu driver
@@ -176,23 +196,13 @@ int main() {
176 error(1, errno, "[VX-GAMBLEGROUND] Call to randombytes_uniform failed, can't get random phrase"); 196 error(1, errno, "[VX-GAMBLEGROUND] Call to randombytes_uniform failed, can't get random phrase");
177 } 197 }
178 198
179 // Create the banner window 199 WINDOW *banner = create_banner(col, randomnum);
180 phrase = newwin(1, col, 0, 0);
181 if(phrase == NULL) {
182 endwin();
183 error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window");
184 }
185 wbkgd(phrase, COLOR_PAIR(1));
186 mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: ");
187 waddstr(phrase, phrases[randomnum]);
188 wrefresh(phrase);
189 200
190 201
191 // Set up menu items 202 // Set up menu items
192 for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) { 203 for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) {
193 funcholder[i].callback = USERFUNCS[i];
194 items[i] = new_item(menu_choices[i], NULL); 204 items[i] = new_item(menu_choices[i], NULL);
195 set_item_userptr(items[i], (void*)(&funcholder[i])); 205 set_item_userptr(items[i], (void*)&userfuncs[i]);
196 } 206 }
197 items[STATIC_ARRSIZE(menu_choices)] = NULL; 207 items[STATIC_ARRSIZE(menu_choices)] = NULL;
198 208
@@ -236,6 +246,9 @@ int main() {
236 mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext); 246 mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext);
237 wrefresh(slots); 247 wrefresh(slots);
238 248
249 userfuncs[0].params.spinp.bannerwin = banner;
250 userfuncs[0].params.spinp.phrasenum = randomnum;
251
239 // Get user input and deal with the menu 252 // Get user input and deal with the menu
240 while((c = wgetch(menuholder)) != KEY_F(4)) { 253 while((c = wgetch(menuholder)) != KEY_F(4)) {
241 switch(c) { 254 switch(c) {
@@ -260,7 +273,23 @@ int main() {
260 //mvwaddstr(menuholder, 0, 0, "This shit brokey lmao"); 273 //mvwaddstr(menuholder, 0, 0, "This shit brokey lmao");
261 274
262 p = (struct funcholder *)item_userptr(current_item(menu)); 275 p = (struct funcholder *)item_userptr(current_item(menu));
263 p->callback(); 276 switch(p->type) {
277 case FH_SPIN:
278 p->callback((void*)&p->params.spinp);
279 break;
280
281 case FH_BUY:
282 p->callback((void*)&p->params.buyp);
283 break;
284
285 case FH_QUIT:
286 p->callback((void*)&p->params.quitp);
287 break;
288
289 default:
290 endwin();
291 error(1, ENOTSUP, "SHIT BROKE");
292 }
264 293
265 break; 294 break;
266 } 295 }
@@ -278,21 +307,29 @@ int main() {
278} 307}
279 308
280// Spin the wheel 309// Spin the wheel
281int spin(void) { 310int spin(void *spinp) {
282 endwin(); 311 struct spinp *p = (struct spinp *)spinp;
283 error(1, 0, "spin"); 312
313 // Change the color to testing for the banner
314 wbkgd(p->bannerwin, COLOR_PAIR(CCP_TESTING));
315 mvwaddstr(p->bannerwin, 0, 1, "VX-GAMBLEGROUND: ");
316 waddstr(p->bannerwin, phrases[p->phrasenum]);
317 wnoutrefresh(p->bannerwin);
318
319 doupdate();
320
284 return 0; 321 return 0;
285} 322}
286 323
287// Increase number of spins 324// Increase number of spins
288int buy(void) { 325int buy(void *buyp) {
289 endwin(); 326 endwin();
290 error(1, 0, "buy"); 327 error(1, 0, "buy");
291 return 0; 328 return 0;
292} 329}
293 330
294// Quit out 331// Quit out
295int quit(void) { 332int quit(void *quitp) {
296 endwin(); 333 endwin();
297 error(1, 0, "quit"); 334 error(1, 0, "quit");
298 return 1; 335 return 1;
diff --git a/src/screen.h b/src/screen.h
index 5d0837e..9419d5c 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -53,7 +53,31 @@ enum customcolor_pairs {
53}; 53};
54 54
55struct funcholder { 55struct funcholder {
56 int (*callback)(void); 56 int (*callback)(void*);
57 enum type {
58 FH_UNSPEC,
59
60 FH_SPIN,
61 FH_BUY,
62 FH_QUIT,
63
64 FH_TOOBIG
65 } type;
66
67 union param {
68 struct spinp {
69 WINDOW *bannerwin;
70 int phrasenum;
71 } spinp;
72
73 struct buyp {
74
75 } buyp;
76
77 struct quitp {
78
79 } quitp;
80 } params;
57 81
58}; 82};
59 83
@@ -63,9 +87,8 @@ static float normalize(float value, float oldmin, float oldmax, float newmin, fl
63// Initialize a new curses color using standard rgb values (0-255) instead of curses' 0-1000 range 87// Initialize a new curses color using standard rgb values (0-255) instead of curses' 0-1000 range
64static int init_rgb_color(int colornum, int red, int green, int blue); 88static int init_rgb_color(int colornum, int red, int green, int blue);
65 89
66int spin(void); 90int spin(void *spinp);
67int buy(void); 91int buy(void *buyp);
68int quit(void); 92int quit(void *quitp);
69#define USERFUNCS (int (* [])(void)){spin, buy, quit}
70 93
71#endif \ No newline at end of file 94#endif \ No newline at end of file