From 21c242d0316a296fcd27072fb6dd46ccc6a76bd1 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sun, 28 Jul 2024 00:35:41 -0500 Subject: Scroll through colors when spinning --- src/screen.c | 50 ++++++++++++++++++++++++++++++++++++-------------- src/screen.h | 12 +++++++++++- 2 files changed, 47 insertions(+), 15 deletions(-) (limited to 'src') 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 #include "screen.h" #include #include +#include #include +#include #include #include #include @@ -94,6 +96,11 @@ static float normalize(float value, float oldmin, float oldmax, float newmin, fl return (newmax - newmin) * ((value - oldmin) / (oldmax - oldmin)) + newmin; } +// Find the result of x + offset and constrict it to the range [min, max]. x must be >= min +static int rangemod(int x, int offset, int min, int max) { + return ((x - min + offset) % (max - min + 1)) + min; +} + 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); @@ -133,12 +140,22 @@ static int docolors(void) { init_rgb_color(CC_YELLOW, 255, 255, 0); init_rgb_color(CC_GREEN, 0, 255, 0); init_rgb_color(CC_BLUE, 0, 0, 255); - init_rgb_color(CC_PURPLE, 155, 0, 255); + init_rgb_color(CC_PURPLE, 128, 0, 255); init_rgb_color(CC_MAGENTA, 255, 0, 255); init_rgb_color(CC_WHITE, 255, 255, 255); + init_rgb_color(CC_BLACK, 0, 0, 0); - init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); init_pair(CCP_TESTING, CC_RED, CC_WHITE); + init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); + + init_pair(CCP_RED, CC_WHITE, CC_RED); + init_pair(CCP_ORANGE, CC_BLACK, CC_ORANGE); + init_pair(CCP_YELLOW, CC_BLACK, CC_YELLOW); + init_pair(CCP_GREEN, CC_BLACK, CC_GREEN); + init_pair(CCP_BLUE, CC_WHITE, CC_BLUE); + init_pair(CCP_PURPLE, CC_WHITE, CC_PURPLE); + init_pair(CCP_MAGENTA, CC_WHITE, CC_MAGENTA); + init_pair(CCP_WHITE, CC_BLACK, CC_WHITE); } else { endwin(); error(1, ENOTSUP, "[VX-GAMBLEGROUND] Colors are not supported on your terminal"); @@ -154,10 +171,10 @@ static WINDOW* create_banner(int col, int randomnum) { endwin(); error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); } - wbkgd(phrase, COLOR_PAIR(1)); + wbkgd(phrase, COLOR_PAIR(CCP_BANNER)); mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); waddstr(phrase, phrases[randomnum]); - wrefresh(phrase); + wnoutrefresh(phrase); return phrase; } @@ -233,7 +250,7 @@ int main() { post_menu(menu); wbkgd(menuholder, COLOR_PAIR(CCP_BANNER)); set_menu_back(menu, COLOR_PAIR(CCP_BANNER)); - wrefresh(menuholder); + wnoutrefresh(menuholder); WINDOW *slots = newwin(row - 2, col, 1, 0); @@ -244,7 +261,9 @@ int main() { const char *sampletext = "Lmao longer sample"; mvwaddstr(slots, (row - 2) / 2, (col / 2) - (strlen(sampletext) / 2), sampletext); - wrefresh(slots); + wnoutrefresh(slots); + + doupdate(); userfuncs[0].params.spinp.bannerwin = banner; userfuncs[0].params.spinp.phrasenum = randomnum; @@ -312,16 +331,19 @@ int main() { int spin(void *spinp) { struct spinp *p = (struct spinp *)spinp; - // Change the color to testing for the banner - wbkgd(p->bannerwin, COLOR_PAIR(CCP_TESTING)); - wnoutrefresh(p->bannerwin); + for(int i = CCP_RED;; i = rangemod(i, 1, CCP_RED, CCP_WHITE)) { + // Change the color to testing for the banner + wbkgd(p->bannerwin, COLOR_PAIR(i)); + wnoutrefresh(p->bannerwin); - // Change the color to testing for the menu - wbkgd(p->menuholder, COLOR_PAIR(CCP_TESTING)); - set_menu_back(p->menu, COLOR_PAIR(CCP_TESTING)); - wnoutrefresh(p->menuholder); + // Change the color to testing for the menu + wbkgd(p->menuholder, COLOR_PAIR(i)); + set_menu_back(p->menu, COLOR_PAIR(i)); + wnoutrefresh(p->menuholder); - doupdate(); + doupdate(); + sleep(1); + } return 0; } diff --git a/src/screen.h b/src/screen.h index 8b8c8f8..a5f51fd 100644 --- a/src/screen.h +++ b/src/screen.h @@ -39,6 +39,7 @@ enum custom_colors { CC_PURPLE, // RGB: 155, 0, 255 CC_MAGENTA, // RGB: 255, 0, 255 CC_WHITE, // RGB: 255, 255, 255 + CC_BLACK, // RGB: 0, 0, 0 // This isn't actually a color, even if you try to use it as one CC_TOOBIG @@ -47,8 +48,17 @@ enum custom_colors { enum customcolor_pairs { CCP_UNDEFINED, - CCP_BANNER, CCP_TESTING, + CCP_BANNER, + + CCP_RED, + CCP_ORANGE, + CCP_YELLOW, + CCP_GREEN, + CCP_BLUE, + CCP_PURPLE, + CCP_MAGENTA, + CCP_WHITE, CCP_TOOBIG }; -- cgit v1.2.3