summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2024-07-28 00:35:41 -0500
committer@syxhe <https://t.me/syxhe>2024-07-28 00:35:41 -0500
commit21c242d0316a296fcd27072fb6dd46ccc6a76bd1 (patch)
tree290e45e17adc89ece7ea3fdb36a4040c5c33d435 /src
parent78d7f29b532705c5997e565539d9c250449cd061 (diff)
Scroll through colors when spinning
Diffstat (limited to 'src')
-rw-r--r--src/screen.c50
-rw-r--r--src/screen.h12
2 files changed, 47 insertions, 15 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
100static int rangemod(int x, int offset, int min, int max) {
101 return ((x - min + offset) % (max - min + 1)) + min;
102}
103
97static int init_rgb_color(int colornum, int red, int green, int blue) { 104static 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() {
312int spin(void *spinp) { 331int 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}
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 {
39 CC_PURPLE, // RGB: 155, 0, 255 39 CC_PURPLE, // RGB: 155, 0, 255
40 CC_MAGENTA, // RGB: 255, 0, 255 40 CC_MAGENTA, // RGB: 255, 0, 255
41 CC_WHITE, // RGB: 255, 255, 255 41 CC_WHITE, // RGB: 255, 255, 255
42 CC_BLACK, // RGB: 0, 0, 0
42 43
43 // This isn't actually a color, even if you try to use it as one 44 // This isn't actually a color, even if you try to use it as one
44 CC_TOOBIG 45 CC_TOOBIG
@@ -47,8 +48,17 @@ enum custom_colors {
47enum customcolor_pairs { 48enum customcolor_pairs {
48 CCP_UNDEFINED, 49 CCP_UNDEFINED,
49 50
50 CCP_BANNER,
51 CCP_TESTING, 51 CCP_TESTING,
52 CCP_BANNER,
53
54 CCP_RED,
55 CCP_ORANGE,
56 CCP_YELLOW,
57 CCP_GREEN,
58 CCP_BLUE,
59 CCP_PURPLE,
60 CCP_MAGENTA,
61 CCP_WHITE,
52 62
53 CCP_TOOBIG 63 CCP_TOOBIG
54}; 64};