diff options
author | Bad Diode <bd@badd10de.dev> | 2023-05-28 19:17:48 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-05-28 19:17:48 +0200 |
commit | 52bdd0d79c77df0a7752fd15ebcc730f9e9796b1 (patch) | |
tree | 1efa9654ecdc5a933976bbbb37d9ec18562c1320 /src/main.c | |
parent | 70b7b9f719ab673ff776cfc0f9b7bc67dc88bac1 (diff) | |
download | stepper-52bdd0d79c77df0a7752fd15ebcc730f9e9796b1.tar.gz stepper-52bdd0d79c77df0a7752fd15ebcc730f9e9796b1.zip |
Refactor settings into own files
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 114 |
1 files changed, 4 insertions, 110 deletions
@@ -55,6 +55,8 @@ WITH REGARD TO THIS SOFTWARE. | |||
55 | #include "gba/gba.h" | 55 | #include "gba/gba.h" |
56 | 56 | ||
57 | #include "renderer_m0.c" | 57 | #include "renderer_m0.c" |
58 | #include "globals.c" | ||
59 | #include "settings.c" | ||
58 | #include "sequencer.c" | 60 | #include "sequencer.c" |
59 | 61 | ||
60 | #define PROF_ENABLE 0 | 62 | #define PROF_ENABLE 0 |
@@ -99,65 +101,6 @@ render_sequencer(void) { | |||
99 | PROF(draw_cursors(), draw_cursor_cycles); | 101 | PROF(draw_cursors(), draw_cursor_cycles); |
100 | } | 102 | } |
101 | 103 | ||
102 | bool clear_screen = false; | ||
103 | |||
104 | typedef enum Scene { | ||
105 | SCENE_SEQUENCER = 0, | ||
106 | SCENE_SETTINGS, | ||
107 | } Scene; | ||
108 | |||
109 | static scene = SCENE_SETTINGS; | ||
110 | static next_scene = SCENE_SETTINGS; | ||
111 | |||
112 | typedef enum SyncSetting { | ||
113 | SYNC_NONE = 0, | ||
114 | SYNC_OUT_LINK_16, | ||
115 | SYNC_OUT_LINK_8, | ||
116 | SYNC_OUT_LINK_4, | ||
117 | SYNC_NUM, | ||
118 | } SyncSetting; | ||
119 | |||
120 | char * sync_setting_str[] = { | ||
121 | "NONE", | ||
122 | "LINK OUT (16)", | ||
123 | "LINK OUT (8)", | ||
124 | "LINK OUT (4)", | ||
125 | }; | ||
126 | |||
127 | typedef enum ThemeSetting { | ||
128 | THEME_DEFAULT = 0, | ||
129 | } ThemeSetting; | ||
130 | |||
131 | char * theme_setting_str[] = { | ||
132 | "DEFAULT", | ||
133 | }; | ||
134 | |||
135 | typedef enum CursorSetting { | ||
136 | CURSOR_DEFAULT = 0, | ||
137 | } CursorSetting; | ||
138 | |||
139 | char * cursor_setting_str[] = { | ||
140 | "LINE", | ||
141 | }; | ||
142 | |||
143 | typedef struct Settings { | ||
144 | SyncSetting sync; | ||
145 | ThemeSetting theme; | ||
146 | CursorSetting cursor; | ||
147 | } Settings; | ||
148 | |||
149 | static Settings settings = {0}; | ||
150 | static settings_cursor_loc = 0; | ||
151 | |||
152 | void | ||
153 | draw_settings_cursor(void) { | ||
154 | int x = 6; | ||
155 | int y = 17 + settings_cursor_loc * 12; | ||
156 | draw_line(x + 1, y + 3, x + 1, y + 7, COL_CYAN); | ||
157 | draw_line(x + 2, y + 4, x + 2, y + 6, COL_CYAN); | ||
158 | draw_line(x + 3, y + 5, x + 3, y + 5, COL_CYAN); | ||
159 | } | ||
160 | |||
161 | void | 104 | void |
162 | render_settings(void) { | 105 | render_settings(void) { |
163 | PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles); | 106 | PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles); |
@@ -168,62 +111,13 @@ render_settings(void) { | |||
168 | txt_printf(" CURSOR: %s\n\n", cursor_setting_str[settings.cursor]); | 111 | txt_printf(" CURSOR: %s\n\n", cursor_setting_str[settings.cursor]); |
169 | txt_render(); | 112 | txt_render(); |
170 | txt_clear(); | 113 | txt_clear(); |
171 | draw_settings_cursor(); | 114 | PROF(draw_settings_cursor(), draw_cursor_cycles); |
172 | } | ||
173 | |||
174 | #define N_SETTINGS 3 | ||
175 | |||
176 | void | ||
177 | handle_settings_input(void) { | ||
178 | if (key_tap(KEY_DOWN)) { | ||
179 | if (settings_cursor_loc == (N_SETTINGS - 1)) { | ||
180 | settings_cursor_loc = 0; | ||
181 | } else { | ||
182 | settings_cursor_loc++; | ||
183 | } | ||
184 | clear_screen = true; | ||
185 | } | ||
186 | if (key_tap(KEY_UP)) { | ||
187 | if (settings_cursor_loc == 0) { | ||
188 | settings_cursor_loc = N_SETTINGS - 1; | ||
189 | } else { | ||
190 | settings_cursor_loc--; | ||
191 | } | ||
192 | clear_screen = true; | ||
193 | } | ||
194 | if (key_tap(KEY_R)) { | ||
195 | switch (settings_cursor_loc) { | ||
196 | case 0: { | ||
197 | if ((settings.sync + 1) >= SYNC_NUM) { | ||
198 | settings.sync = 0; | ||
199 | } else { | ||
200 | settings.sync++; | ||
201 | } | ||
202 | } break; | ||
203 | } | ||
204 | clear_screen = true; | ||
205 | } | ||
206 | if (key_tap(KEY_L)) { | ||
207 | switch (settings_cursor_loc) { | ||
208 | case 0: { | ||
209 | if (settings.sync == 0) { | ||
210 | settings.sync = SYNC_NUM - 1; | ||
211 | } else { | ||
212 | settings.sync--; | ||
213 | } | ||
214 | } break; | ||
215 | } | ||
216 | clear_screen = true; | ||
217 | } | ||
218 | if (key_tap(KEY_B)) { | ||
219 | next_scene = SCENE_SEQUENCER; | ||
220 | } | ||
221 | } | 115 | } |
222 | 116 | ||
223 | void | 117 | void |
224 | render(void) { | 118 | render(void) { |
225 | if (clear_screen) { | 119 | if (clear_screen) { |
226 | screen_fill(COL_BG); | 120 | PROF(screen_fill(COL_BG), clear_cycles); |
227 | clear_screen = false; | 121 | clear_screen = false; |
228 | } | 122 | } |
229 | switch (scene) { | 123 | switch (scene) { |