diff options
Diffstat (limited to 'src/screen.c')
| -rw-r--r-- | src/screen.c | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/screen.c b/src/screen.c index 749054b..4287da8 100644 --- a/src/screen.c +++ b/src/screen.c | |||
| @@ -25,7 +25,9 @@ SLOTS HERE | |||
| 25 | #include "screen.h" | 25 | #include "screen.h" |
| 26 | #include <curses.h> | 26 | #include <curses.h> |
| 27 | #include <locale.h> | 27 | #include <locale.h> |
| 28 | #include <signal.h> | ||
| 28 | #include <sodium.h> | 29 | #include <sodium.h> |
| 30 | #include <unistd.h> | ||
| 29 | #include <errno.h> | 31 | #include <errno.h> |
| 30 | #include <error.h> | 32 | #include <error.h> |
| 31 | #include <menu.h> | 33 | #include <menu.h> |
| @@ -94,6 +96,11 @@ static float normalize(float value, float oldmin, float oldmax, float newmin, fl | |||
| 94 | return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin; | 96 | return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin; |
| 95 | } | 97 | } |
| 96 | 98 | ||
| 99 | // Find the result of x + offset and constrict it to the range [min, max]. x must be >= min | ||
| 100 | static int rangemod(int x, int offset, int min, int max) { | ||
| 101 | return ((x - min + offset) % (max - min + 1)) + min; | ||
| 102 | } | ||
| 103 | |||
| 97 | static int init_rgb_color(int colornum, int red, int green, int blue) { | 104 | static int init_rgb_color(int colornum, int red, int green, int blue) { |
| 98 | int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); | 105 | int nred = normalize(red, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); |
| 99 | int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); | 106 | int ngreen = normalize(green, RGB_MIN, RGB_MAX, CURSESCOLOR_MIN, CURSESCOLOR_MAX); |
| @@ -133,12 +140,22 @@ static int docolors(void) { | |||
| 133 | init_rgb_color(CC_YELLOW, 255, 255, 0); | 140 | init_rgb_color(CC_YELLOW, 255, 255, 0); |
| 134 | init_rgb_color(CC_GREEN, 0, 255, 0); | 141 | init_rgb_color(CC_GREEN, 0, 255, 0); |
| 135 | init_rgb_color(CC_BLUE, 0, 0, 255); | 142 | init_rgb_color(CC_BLUE, 0, 0, 255); |
| 136 | init_rgb_color(CC_PURPLE, 155, 0, 255); | 143 | init_rgb_color(CC_PURPLE, 128, 0, 255); |
| 137 | init_rgb_color(CC_MAGENTA, 255, 0, 255); | 144 | init_rgb_color(CC_MAGENTA, 255, 0, 255); |
| 138 | init_rgb_color(CC_WHITE, 255, 255, 255); | 145 | init_rgb_color(CC_WHITE, 255, 255, 255); |
| 146 | init_rgb_color(CC_BLACK, 0, 0, 0); | ||
| 139 | 147 | ||
| 140 | init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); | ||
| 141 | init_pair(CCP_TESTING, CC_RED, CC_WHITE); | 148 | init_pair(CCP_TESTING, CC_RED, CC_WHITE); |
| 149 | init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); | ||
| 150 | |||
| 151 | init_pair(CCP_RED, CC_WHITE, CC_RED); | ||
| 152 | init_pair(CCP_ORANGE, CC_BLACK, CC_ORANGE); | ||
| 153 | init_pair(CCP_YELLOW, CC_BLACK, CC_YELLOW); | ||
| 154 | init_pair(CCP_GREEN, CC_BLACK, CC_GREEN); | ||
| 155 | init_pair(CCP_BLUE, CC_WHITE, CC_BLUE); | ||
| 156 | init_pair(CCP_PURPLE, CC_WHITE, CC_PURPLE); | ||
| 157 | init_pair(CCP_MAGENTA, CC_WHITE, CC_MAGENTA); | ||
| 158 | init_pair(CCP_WHITE, CC_BLACK, CC_WHITE); | ||
| 142 | } else { | 159 | } else { |
| 143 | endwin(); | 160 | endwin(); |
| 144 | error(1, ENOTSUP, "[VX-GAMBLEGROUND] Colors are not supported on your terminal"); | 161 | error(1, ENOTSUP, "[VX-GAMBLEGROUND] Colors are not supported on your terminal"); |
| @@ -154,10 +171,10 @@ static WINDOW* create_banner(int col, int randomnum) { | |||
| 154 | endwin(); | 171 | endwin(); |
| 155 | error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); | 172 | error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); |
| 156 | } | 173 | } |
| 157 | wbkgd(phrase, COLOR_PAIR(1)); | 174 | wbkgd(phrase, COLOR_PAIR(CCP_BANNER)); |
| 158 | mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); | 175 | mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); |
| 159 | waddstr(phrase, phrases[randomnum]); | 176 | waddstr(phrase, phrases[randomnum]); |
| 160 | wrefresh(phrase); | 177 | wnoutrefresh(phrase); |
| 161 | 178 | ||
| 162 | return phrase; | 179 | return phrase; |
| 163 | } | 180 | } |
| @@ -233,7 +250,7 @@ int main() { | |||
| 233 | post_menu(menu); | 250 | post_menu(menu); |
| 234 | wbkgd(menuholder, COLOR_PAIR(CCP_BANNER)); | 251 | wbkgd(menuholder, COLOR_PAIR(CCP_BANNER)); |
| 235 | set_menu_back(menu, COLOR_PAIR(CCP_BANNER)); | 252 | set_menu_back(menu, COLOR_PAIR(CCP_BANNER)); |
| 236 | wrefresh(menuholder); | 253 | wnoutrefresh(menuholder); |
| 237 | 254 | ||
| 238 | 255 | ||
| 239 | WINDOW *slots = newwin(row - 2, col, 1, 0); | 256 | WINDOW *slots = newwin(row - 2, col, 1, 0); |
| @@ -244,7 +261,9 @@ int main() { | |||
| 244 | 261 | ||
| 245 | const char *sampletext = "Lmao longer sample"; | 262 | const char *sampletext = "Lmao longer sample"; |
| 246 | mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext); | 263 | mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext); |
| 247 | wrefresh(slots); | 264 | wnoutrefresh(slots); |
| 265 | |||
| 266 | doupdate(); | ||
| 248 | 267 | ||
| 249 | userfuncs[0].params.spinp.bannerwin = banner; | 268 | userfuncs[0].params.spinp.bannerwin = banner; |
| 250 | userfuncs[0].params.spinp.phrasenum = randomnum; | 269 | userfuncs[0].params.spinp.phrasenum = randomnum; |
| @@ -312,16 +331,19 @@ int main() { | |||
| 312 | int spin(void *spinp) { | 331 | int spin(void *spinp) { |
| 313 | struct spinp *p = (struct spinp *)spinp; | 332 | struct spinp *p = (struct spinp *)spinp; |
| 314 | 333 | ||
| 315 | // Change the color to testing for the banner | 334 | for(int i = CCP_RED;; i = rangemod(i, 1, CCP_RED, CCP_WHITE)) { |
| 316 | wbkgd(p->bannerwin, COLOR_PAIR(CCP_TESTING)); | 335 | // Change the color to testing for the banner |
| 317 | wnoutrefresh(p->bannerwin); | 336 | wbkgd(p->bannerwin, COLOR_PAIR(i)); |
| 337 | wnoutrefresh(p->bannerwin); | ||
| 318 | 338 | ||
| 319 | // Change the color to testing for the menu | 339 | // Change the color to testing for the menu |
| 320 | wbkgd(p->menuholder, COLOR_PAIR(CCP_TESTING)); | 340 | wbkgd(p->menuholder, COLOR_PAIR(i)); |
| 321 | set_menu_back(p->menu, COLOR_PAIR(CCP_TESTING)); | 341 | set_menu_back(p->menu, COLOR_PAIR(i)); |
| 322 | wnoutrefresh(p->menuholder); | 342 | wnoutrefresh(p->menuholder); |
| 323 | 343 | ||
| 324 | doupdate(); | 344 | doupdate(); |
| 345 | sleep(1); | ||
| 346 | } | ||
| 325 | 347 | ||
| 326 | return 0; | 348 | return 0; |
| 327 | } | 349 | } |
