diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 6 | ||||
| -rw-r--r-- | src/screen.c | 64 | ||||
| -rw-r--r-- | src/screen.h | 27 |
3 files changed, 62 insertions, 35 deletions
diff --git a/src/Makefile b/src/Makefile index 55268aa..a828be2 100644 --- a/src/Makefile +++ b/src/Makefile | |||
| @@ -2,7 +2,7 @@ CC = gcc | |||
| 2 | CFLAGS = -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -Og -g3 -ggdb | 2 | CFLAGS = -Wall -Wextra -Wpedantic -fanalyzer -Wanalyzer-too-complex -Og -g3 -ggdb |
| 3 | 3 | ||
| 4 | SHELL := /usr/bin/env -S bash | 4 | SHELL := /usr/bin/env -S bash |
| 5 | BINARY_FILES := main encryption.o search.o ll.o | 5 | BINARY_FILES := screen #main encryption.o search.o ll.o |
| 6 | 6 | ||
| 7 | .PHONY: all clean | 7 | .PHONY: all clean |
| 8 | 8 | ||
| @@ -14,9 +14,9 @@ clean: | |||
| 14 | 14 | ||
| 15 | main: main.c search.o encryption.o ll.o | 15 | main: main.c search.o encryption.o ll.o |
| 16 | 16 | ||
| 17 | encryption.o: encryption.c encryption.h | ||
| 18 | screen: screen.c screen.h | 17 | screen: screen.c screen.h |
| 19 | set -e -o pipefail && $(CC) $(CFLAGS) $$(pkg-config --cflags libsodium) screen.c -o screen -lncurses -lmenu $$(pkg-config --libs libsodium) | 18 | set -e -o pipefail && $(CC) $(CFLAGS) $$(pkg-config --cflags libsodium) screen.c -o screen $$(pkg-config --libs libsodium) -lmenu $$(pkg-config --libs ncurses) |
| 20 | 19 | ||
| 20 | encryption.o: encryption.c encryption.h | ||
| 21 | search.o: search.c search.h | 21 | search.o: search.c search.h |
| 22 | ll.o: ll.c ll.h \ No newline at end of file | 22 | ll.o: ll.c ll.h \ No newline at end of file |
diff --git a/src/screen.c b/src/screen.c index 9cdac02..5ca2dc2 100644 --- a/src/screen.c +++ b/src/screen.c | |||
| @@ -31,6 +31,7 @@ SLOTS HERE | |||
| 31 | #include <menu.h> | 31 | #include <menu.h> |
| 32 | 32 | ||
| 33 | #include <stdio.h> | 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> | ||
| 34 | 35 | ||
| 35 | static const char *phrases[] = { | 36 | static const char *phrases[] = { |
| 36 | // By @syxhe on telegram | 37 | // By @syxhe on telegram |
| @@ -78,8 +79,7 @@ static const char *phrases[] = { | |||
| 78 | static const char *menu_choices[] = { | 79 | static const char *menu_choices[] = { |
| 79 | "Spin", | 80 | "Spin", |
| 80 | "Buy spins", | 81 | "Buy spins", |
| 81 | "Quit", | 82 | "Quit" |
| 82 | NULL | ||
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| 85 | static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { | 85 | static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax) { |
| @@ -115,16 +115,17 @@ int main() { | |||
| 115 | // curses colors made this go away. Also VSCode's terminal theming is fucking with it as well, so | 115 | // curses colors made this go away. Also VSCode's terminal theming is fucking with it as well, so |
| 116 | // use a normal terminal for accurate colors */ | 116 | // use a normal terminal for accurate colors */ |
| 117 | 117 | ||
| 118 | init_rgb_color(CC_RED, 255, 0, 0); | 118 | init_rgb_color(CC_RED, 255, 0, 0); |
| 119 | init_rgb_color(CC_ORANGE, 255, 128, 0); | 119 | init_rgb_color(CC_ORANGE, 255, 128, 0); |
| 120 | init_rgb_color(CC_YELLOW, 255, 255, 0); | 120 | init_rgb_color(CC_YELLOW, 255, 255, 0); |
| 121 | init_rgb_color(CC_GREEN, 0, 255, 0); | 121 | init_rgb_color(CC_GREEN, 0, 255, 0); |
| 122 | init_rgb_color(CC_BLUE, 0, 0, 255); | 122 | init_rgb_color(CC_BLUE, 0, 0, 255); |
| 123 | init_rgb_color(CC_PURPLE, 255, 0, 255); | 123 | init_rgb_color(CC_PURPLE, 155, 0, 255); |
| 124 | init_rgb_color(CC_WHITE, 255, 255, 255); | 124 | init_rgb_color(CC_MAGENTA, 255, 0, 255); |
| 125 | 125 | init_rgb_color(CC_WHITE, 255, 255, 255); | |
| 126 | init_pair(1, CC_WHITE, CURSES_BLUE); | 126 | |
| 127 | 127 | init_pair(CCP_BANNER, CC_WHITE, CURSES_BLUE); | |
| 128 | init_pair(CCP_TESTING, CC_RED, CC_WHITE); | ||
| 128 | } | 129 | } |
| 129 | 130 | ||
| 130 | cbreak(); // Disables character buffering | 131 | cbreak(); // Disables character buffering |
| @@ -134,7 +135,8 @@ int main() { | |||
| 134 | 135 | ||
| 135 | int row = -1, col = -1; | 136 | int row = -1, col = -1; |
| 136 | getmaxyx(stdscr, row, col); | 137 | getmaxyx(stdscr, row, col); |
| 137 | 138 | if(row < 0 || col < 0) | |
| 139 | error(1, 0, "[VX-GAMBLEGROUND] Couldn't get max terminal size for some reason"); | ||
| 138 | 140 | ||
| 139 | int randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases)); | 141 | int randomnum = randombytes_uniform(STATIC_ARRSIZE(phrases)); |
| 140 | if(randomnum < 0) | 142 | if(randomnum < 0) |
| @@ -146,37 +148,43 @@ int main() { | |||
| 146 | if(phrase == NULL) | 148 | if(phrase == NULL) |
| 147 | error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); | 149 | error(1, errno, "[VX-GAMBLEGROUND] Could not create banner window"); |
| 148 | 150 | ||
| 149 | wbkgd(phrase, COLOR_PAIR(1)); | 151 | if(has_colors()) |
| 152 | wbkgd(phrase, COLOR_PAIR(1)); | ||
| 153 | |||
| 150 | mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); | 154 | mvwaddstr(phrase, 0, 1, "VX-GAMBLEGROUND: "); |
| 151 | waddstr(phrase, phrases[randomnum]); | 155 | waddstr(phrase, phrases[randomnum]); |
| 152 | wrefresh(phrase); | 156 | wrefresh(phrase); |
| 153 | 157 | ||
| 154 | //* Dummy test for fun. Shows how windows can't be overlapping or things get weird | 158 | /* Dummy test for fun. Shows how windows can't be overlapping or things get weird (and that row offsets matter) |
| 155 | WINDOW *test = newwin(row - 1, col, 1, 0); | 159 | WINDOW *test = newwin(row - 1, col, 1, 0); |
| 160 | int rand1, rand2; | ||
| 161 | |||
| 156 | for(int c = wgetch(test);; c = wgetch(test)) { | 162 | for(int c = wgetch(test);; c = wgetch(test)) { |
| 157 | mvwaddch(test, c % row, c % col, c | (A_BOLD * (randombytes_random() % 2 > 0))); | 163 | rand1 = randombytes_uniform(row - 1); |
| 164 | rand2 = randombytes_uniform(col); | ||
| 165 | |||
| 166 | mvwaddch(test, rand1, rand2, c | (A_BOLD * (randombytes_random() % 2 > 0))); | ||
| 158 | } | 167 | } |
| 159 | //*/ | 168 | //*/ |
| 160 | 169 | ||
| 161 | /* Menu example | 170 | //* Menu example (fuck menus got damn) |
| 162 | ITEM **items; | 171 | ITEM *items[STATIC_ARRSIZE(menu_choices) + 1]; |
| 163 | MENU *menu; | 172 | MENU *menu; |
| 164 | 173 | ||
| 165 | items = calloc(STATIC_ARRSIZE(menu_choices) + 1, sizeof(ITEM*)); | ||
| 166 | if(items == NULL) | ||
| 167 | error(-1, errno, "Could not allocate space for menu items"); | ||
| 168 | |||
| 169 | for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) | 174 | for(long unsigned int i = 0; i < STATIC_ARRSIZE(menu_choices); i++) |
| 170 | items[i] = new_item(menu_choices[i], menu_choices[i]); | 175 | items[i] = new_item(menu_choices[i], menu_choices[i]); |
| 171 | items[STATIC_ARRSIZE(menu_choices)] = NULL; | 176 | items[STATIC_ARRSIZE(menu_choices)] = NULL; |
| 172 | 177 | ||
| 173 | menu = new_menu(items); | 178 | menu = new_menu(items); |
| 174 | mvprintw(LINES - 2, 0, "F1 to Exit"); | 179 | if(menu == NULL) |
| 180 | error(1, errno, "Could not create menu"); | ||
| 181 | |||
| 182 | // set_menu_format(menu, 3, col); | ||
| 175 | post_menu(menu); | 183 | post_menu(menu); |
| 176 | refresh(); | 184 | refresh(); |
| 177 | 185 | ||
| 178 | int c; | 186 | int c; |
| 179 | while((c = getch()) != KEY_F(1)) { | 187 | while((c = getch()) != KEY_F(4)) { |
| 180 | switch(c) { | 188 | switch(c) { |
| 181 | case KEY_DOWN: | 189 | case KEY_DOWN: |
| 182 | menu_driver(menu, REQ_DOWN_ITEM); | 190 | menu_driver(menu, REQ_DOWN_ITEM); |
| @@ -186,6 +194,14 @@ int main() { | |||
| 186 | menu_driver(menu, REQ_UP_ITEM); | 194 | menu_driver(menu, REQ_UP_ITEM); |
| 187 | break; | 195 | break; |
| 188 | 196 | ||
| 197 | case KEY_LEFT: | ||
| 198 | menu_driver(menu, REQ_LEFT_ITEM); | ||
| 199 | break; | ||
| 200 | |||
| 201 | case KEY_RIGHT: | ||
| 202 | menu_driver(menu, REQ_RIGHT_ITEM); | ||
| 203 | break; | ||
| 204 | |||
| 189 | case KEY_ENTER: | 205 | case KEY_ENTER: |
| 190 | break; | 206 | break; |
| 191 | } | 207 | } |
diff --git a/src/screen.h b/src/screen.h index a4ecf5a..78e2077 100644 --- a/src/screen.h +++ b/src/screen.h | |||
| @@ -26,19 +26,30 @@ enum custom_colors { | |||
| 26 | CURSES_CYAN = COLOR_CYAN, // ncurses' default cyan | 26 | CURSES_CYAN = COLOR_CYAN, // ncurses' default cyan |
| 27 | CURSES_WHITE = COLOR_WHITE, // ncurses' default white | 27 | CURSES_WHITE = COLOR_WHITE, // ncurses' default white |
| 28 | 28 | ||
| 29 | CC_RED, | 29 | /* Start custom color definitions */ |
| 30 | CC_ORANGE, | 30 | |
| 31 | CC_YELLOW, | 31 | CC_RED, // RGB: 255, 0, 0 |
| 32 | CC_GREEN, | 32 | CC_ORANGE, // RGB: 255, 128, 0 |
| 33 | CC_BLUE, | 33 | CC_YELLOW, // RGB: 255, 255, 0 |
| 34 | CC_PURPLE, | 34 | CC_GREEN, // RGB: 0, 255, 0 |
| 35 | CC_MAGENTA, | 35 | CC_BLUE, // RGB: 0, 0, 255 |
| 36 | CC_WHITE, | 36 | CC_PURPLE, // RGB: 155, 0, 255 |
| 37 | CC_MAGENTA, // RGB: 255, 0, 255 | ||
| 38 | CC_WHITE, // RGB: 255, 255, 255 | ||
| 37 | 39 | ||
| 38 | // This isn't actually a color, even if you try to use it as one | 40 | // This isn't actually a color, even if you try to use it as one |
| 39 | CC_TOOBIG | 41 | CC_TOOBIG |
| 40 | }; | 42 | }; |
| 41 | 43 | ||
| 44 | enum customcolor_pairs { | ||
| 45 | CCP_UNDEFINED, | ||
| 46 | |||
| 47 | CCP_BANNER, | ||
| 48 | CCP_TESTING, | ||
| 49 | |||
| 50 | CCP_TOOBIG | ||
| 51 | }; | ||
| 52 | |||
| 42 | // Converts value from within the range of [oldmin, oldmax] to a value within the range [newmin, newmax] | 53 | // Converts value from within the range of [oldmin, oldmax] to a value within the range [newmin, newmax] |
| 43 | static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax); | 54 | static float normalize(float value, float oldmin, float oldmax, float newmin, float newmax); |
| 44 | 55 | ||
