aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-08-25 08:33:16 +0200
committerBad Diode <bd@badd10de.dev>2023-08-25 08:33:16 +0200
commit88ea481015a4fc3891224cb7379bc3959aa5ad1e (patch)
treeb86e91258843467be47f276034afc6df6f6e20f1
parentcf9912cd61c9499fc60a839042fcae1ac556e044 (diff)
downloadstepper-88ea481015a4fc3891224cb7379bc3959aa5ad1e.tar.gz
stepper-88ea481015a4fc3891224cb7379bc3959aa5ad1e.zip
Update UI for settings page
-rw-r--r--src/drawing.c31
-rw-r--r--src/main.c51
-rw-r--r--src/settings.c39
-rw-r--r--src/settings.h22
4 files changed, 86 insertions, 57 deletions
diff --git a/src/drawing.c b/src/drawing.c
index f3115c5..fbc741c 100644
--- a/src/drawing.c
+++ b/src/drawing.c
@@ -363,15 +363,36 @@ draw_play() {
363} 363}
364 364
365void 365void
366draw_wrench(u8 x, u8 y, u8 clr) {
367 draw_line(x + 10, y + 3, x + 13, y + 3, clr);
368 draw_line(x + 10, y + 5, x + 13, y + 5, clr);
369 draw_line(x + 19, y + 3, x + 22, y + 3, clr);
370 draw_line(x + 19, y + 5, x + 22, y + 5, clr);
371 draw_line(x + 13, y + 4, x + 19, y + 4, clr);
372}
373
374void
366draw_settings() { 375draw_settings() {
367 size_t x = SETTINGS_START_X; 376 size_t x = SETTINGS_START_X;
368 size_t y = SETTINGS_START_Y; 377 size_t y = SETTINGS_START_Y;
369 draw_rect(x + 2, y, x + R_COL_W, y + PLAY_STOP_H, COL_OFF); 378 draw_rect(x + 2, y, x + R_COL_W, y + PLAY_STOP_H, COL_OFF);
370 draw_line(x + 10, y + 3, x + 13, y + 3, COL_OFF); 379 draw_wrench(x, y, COL_OFF);
371 draw_line(x + 10, y + 5, x + 13, y + 5, COL_OFF); 380}
372 draw_line(x + 19, y + 3, x + 22, y + 3, COL_OFF); 381
373 draw_line(x + 19, y + 5, x + 22, y + 5, COL_OFF); 382void
374 draw_line(x + 13, y + 4, x + 19, y + 4, COL_OFF); 383draw_settings_cursor(void) {
384 u8 y_pos[] = {
385 49,
386 49 + 17,
387 49 + 17 * 3,
388 49 + 17 * 4,
389 49 + 17 * 5,
390 49 + 17 * 6,
391 };
392 int x = 8;
393 int y = y_pos[settings_cursor_loc];
394 draw_line(x, y, x + 64, y, COL_ACC_0);
395 draw_line(x, y + 1, x + 64, y + 1, COL_ACC_0);
375} 396}
376 397
377void 398void
diff --git a/src/main.c b/src/main.c
index c424d9c..ae14d87 100644
--- a/src/main.c
+++ b/src/main.c
@@ -129,14 +129,49 @@ render_sequencer(void) {
129 129
130void 130void
131render_settings(void) { 131render_settings(void) {
132 txt_drawf_small("settings", 11, 5, COL_FG) 132 size_t x0 = 8;
133 txt_printf("\n\n\n"); 133 size_t x1 = x0 + 64;
134 txt_printf(" SYNC: %s\n\n", sync_setting_str[settings.sync]); 134 size_t y0 = 6;
135 txt_printf(" THEME: %s\n\n", theme_setting_str[settings.theme]); 135
136 txt_printf(" CURSOR: %s\n\n", cursor_setting_str[settings.cursor]); 136 // Header.
137 txt_printf(" HELP: %s\n\n", help_setting_str[settings.help]); 137 txt_drawf("SETTINGS", x0, y0, COL_FG)
138 txt_render(); 138 draw_wrench(SCREEN_WIDTH - 32, y0, COL_FG);
139 txt_clear(); 139 y0 = 16;
140 draw_filled_rect(x0, y0 - 1, SCREEN_WIDTH - 9, y0, COL_FG);
141 y0 = 20;
142
143 // Globals.
144 txt_drawf("GLOBAL", x0, y0, COL_FG);
145 draw_line(x0, y0 + 9, SCREEN_WIDTH - 9, y0 + 9, COL_FG);
146 y0 += 17;
147 draw_rect(x0, y0, x1, y0 + 10, COL_FG);
148 txt_drawf("MUTE", x0 + 2, y0 + 1, COL_FG);
149 txt_drawf("OFF", x1 + 8, y0 + 1, COL_FG);
150 y0 += 17;
151 draw_rect(x0, y0, x1, y0 + 10, COL_FG);
152 txt_drawf("BPM", x0 + 2, y0 + 1, COL_FG);
153 txt_drawf("OFF", x1 + 8, y0 + 1, COL_FG);
154 y0 += 17;
155
156 txt_drawf("GENERAL", x0, y0, COL_FG);
157 draw_line(x0, y0 + 9, SCREEN_WIDTH - 9, y0 + 9, COL_FG);
158 y0 += 17;
159 draw_rect(x0, y0, x1, y0 + 10, COL_FG);
160 txt_drawf("AUTO-SAVE", x0 + 2, y0 + 1, COL_FG);
161 txt_drawf("OFF", x1 + 8, y0 + 1, COL_FG);
162 y0 += 17;
163 draw_rect(x0, y0, x1, y0 + 10, COL_FG);
164 txt_drawf("SYNC", x0 + 2, y0 + 1, COL_FG);
165 txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, sync_setting_str[settings.sync]);
166 y0 += 17;
167 draw_rect(x0, y0, x1, y0 + 10, COL_FG);
168 txt_drawf("THEME", x0 + 2, y0 + 1, COL_FG);
169 txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, theme_setting_str[settings.theme]);
170 y0 += 17;
171 draw_rect(x0, y0, x1, y0 + 10, COL_FG);
172 txt_drawf("HELP", x0 + 2, y0 + 1, COL_FG);
173 txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, help_setting_str[settings.help]);
174
140 PROF(draw_settings_cursor(), draw_cursor_cycles); 175 PROF(draw_settings_cursor(), draw_cursor_cycles);
141} 176}
142 177
diff --git a/src/settings.c b/src/settings.c
index d2491b8..eb1393b 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -4,15 +4,6 @@
4static Settings settings = {0}; 4static Settings settings = {0};
5static int settings_cursor_loc = 0; 5static int settings_cursor_loc = 0;
6 6
7void
8draw_settings_cursor(void) {
9 int x = 6;
10 int y = 17 + settings_cursor_loc * 12;
11 draw_line(x + 1, y + 3, x + 1, y + 7, COL_ACC_0);
12 draw_line(x + 2, y + 4, x + 2, y + 6, COL_ACC_0);
13 draw_line(x + 3, y + 5, x + 3, y + 5, COL_ACC_0);
14}
15
16void serial_irq(void); 7void serial_irq(void);
17void stop_sound(void); 8void stop_sound(void);
18void toggle_playing(void); 9void toggle_playing(void);
@@ -62,7 +53,7 @@ set_audio_settings(void) {
62void 53void
63handle_settings_input(void) { 54handle_settings_input(void) {
64 if (key_tap(KEY_DOWN)) { 55 if (key_tap(KEY_DOWN)) {
65 if (settings_cursor_loc == (N_SETTINGS - 1)) { 56 if (settings_cursor_loc == (SETTINGS_NUM - 1)) {
66 settings_cursor_loc = 0; 57 settings_cursor_loc = 0;
67 } else { 58 } else {
68 settings_cursor_loc++; 59 settings_cursor_loc++;
@@ -71,7 +62,7 @@ handle_settings_input(void) {
71 } 62 }
72 if (key_tap(KEY_UP)) { 63 if (key_tap(KEY_UP)) {
73 if (settings_cursor_loc == 0) { 64 if (settings_cursor_loc == 0) {
74 settings_cursor_loc = N_SETTINGS - 1; 65 settings_cursor_loc = SETTINGS_NUM - 1;
75 } else { 66 } else {
76 settings_cursor_loc--; 67 settings_cursor_loc--;
77 } 68 }
@@ -79,7 +70,7 @@ handle_settings_input(void) {
79 } 70 }
80 if (key_tap(KEY_R)) { 71 if (key_tap(KEY_R)) {
81 switch (settings_cursor_loc) { 72 switch (settings_cursor_loc) {
82 case 0: { 73 case SETTINGS_SYNC: {
83 if ((settings.sync + 1) >= SYNC_NUM) { 74 if ((settings.sync + 1) >= SYNC_NUM) {
84 settings.sync = 0; 75 settings.sync = 0;
85 } else { 76 } else {
@@ -87,7 +78,7 @@ handle_settings_input(void) {
87 } 78 }
88 set_audio_settings(); 79 set_audio_settings();
89 } break; 80 } break;
90 case 1: { 81 case SETTINGS_THEME: {
91 if ((settings.theme + 1) >= THEME_NUM) { 82 if ((settings.theme + 1) >= THEME_NUM) {
92 settings.theme = 0; 83 settings.theme = 0;
93 } else { 84 } else {
@@ -95,14 +86,7 @@ handle_settings_input(void) {
95 } 86 }
96 swap_palette(settings.theme); 87 swap_palette(settings.theme);
97 } break; 88 } break;
98 case 2: { 89 case SETTINGS_HELP: {
99 if ((settings.cursor + 1) >= CURSOR_NUM) {
100 settings.cursor = 0;
101 } else {
102 settings.cursor++;
103 }
104 } break;
105 case 3: {
106 if ((settings.help + 1) >= HELP_NUM) { 90 if ((settings.help + 1) >= HELP_NUM) {
107 settings.help = 0; 91 settings.help = 0;
108 } else { 92 } else {
@@ -115,7 +99,7 @@ handle_settings_input(void) {
115 } 99 }
116 if (key_tap(KEY_L)) { 100 if (key_tap(KEY_L)) {
117 switch (settings_cursor_loc) { 101 switch (settings_cursor_loc) {
118 case 0: { 102 case SETTINGS_SYNC: {
119 if (settings.sync == 0) { 103 if (settings.sync == 0) {
120 settings.sync = SYNC_NUM - 1; 104 settings.sync = SYNC_NUM - 1;
121 } else { 105 } else {
@@ -123,7 +107,7 @@ handle_settings_input(void) {
123 } 107 }
124 set_audio_settings(); 108 set_audio_settings();
125 } break; 109 } break;
126 case 1: { 110 case SETTINGS_THEME: {
127 if (settings.theme == 0) { 111 if (settings.theme == 0) {
128 settings.theme = THEME_NUM - 1; 112 settings.theme = THEME_NUM - 1;
129 } else { 113 } else {
@@ -131,14 +115,7 @@ handle_settings_input(void) {
131 } 115 }
132 swap_palette(settings.theme); 116 swap_palette(settings.theme);
133 } break; 117 } break;
134 case 2: { 118 case SETTINGS_HELP: {
135 if (settings.cursor == 0) {
136 settings.cursor = CURSOR_NUM - 1;
137 } else {
138 settings.cursor--;
139 }
140 } break;
141 case 3: {
142 if (settings.help == 0) { 119 if (settings.help == 0) {
143 settings.help = HELP_NUM - 1; 120 settings.help = HELP_NUM - 1;
144 } else { 121 } else {
diff --git a/src/settings.h b/src/settings.h
index 332e6fd..f917534 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -1,7 +1,15 @@
1#ifndef SETTINGS_H 1#ifndef SETTINGS_H
2#define SETTINGS_H 2#define SETTINGS_H
3 3
4#define N_SETTINGS 4 4typedef enum SettingsList {
5 SETTINGS_GLOB_MUTE,
6 SETTINGS_GLOB_BPM,
7 SETTINGS_AUTO_SAVE,
8 SETTINGS_SYNC,
9 SETTINGS_THEME,
10 SETTINGS_HELP,
11 SETTINGS_NUM,
12} SettingsList;
5 13
6typedef enum SyncSetting { 14typedef enum SyncSetting {
7 SYNC_NONE = 0, 15 SYNC_NONE = 0,
@@ -51,17 +59,6 @@ char * theme_setting_str[] = {
51 "MERVEILLES", 59 "MERVEILLES",
52}; 60};
53 61
54typedef enum CursorSetting {
55 CURSOR_THICK_LINE = 0,
56 CURSOR_LINE,
57 CURSOR_NUM,
58} CursorSetting;
59
60char * cursor_setting_str[] = {
61 "THICK LINE",
62 "LINE",
63};
64
65typedef enum HelpSetting { 62typedef enum HelpSetting {
66 HELP_OFF = 0, 63 HELP_OFF = 0,
67 HELP_ON, 64 HELP_ON,
@@ -76,7 +73,6 @@ char * help_setting_str[] = {
76typedef struct Settings { 73typedef struct Settings {
77 SyncSetting sync; 74 SyncSetting sync;
78 ThemeSetting theme; 75 ThemeSetting theme;
79 CursorSetting cursor;
80 HelpSetting help; 76 HelpSetting help;
81 u8 reserved[63]; 77 u8 reserved[63];
82} Settings; 78} Settings;