Mercurial > repos > blastem
comparison nuklear_ui/blastem_nuklear.c @ 1491:e890971f3757 nuklear_ui
Somewhat fleshed out video settings view
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 01 Dec 2017 09:22:43 -0800 |
parents | 919c0c33885e |
children | bdeb2a1d0385 |
comparison
equal
deleted
inserted
replaced
1490:919c0c33885e | 1491:e890971f3757 |
---|---|
14 | 14 |
15 static struct nk_context *context; | 15 static struct nk_context *context; |
16 | 16 |
17 typedef void (*view_fun)(struct nk_context *); | 17 typedef void (*view_fun)(struct nk_context *); |
18 static view_fun current_view; | 18 static view_fun current_view; |
19 static view_fun previous_view; | 19 static view_fun *previous_views; |
20 static uint32_t view_storage; | |
21 static uint32_t num_prev; | |
22 | |
23 static void push_view(view_fun new_view) | |
24 { | |
25 if (num_prev == view_storage) { | |
26 view_storage = view_storage ? 2*view_storage : 2; | |
27 previous_views = realloc(previous_views, view_storage*sizeof(view_fun)); | |
28 } | |
29 previous_views[num_prev++] = current_view; | |
30 current_view = new_view; | |
31 } | |
32 | |
33 static void pop_view() | |
34 { | |
35 if (num_prev) { | |
36 current_view = previous_views[--num_prev]; | |
37 } | |
38 } | |
39 | |
40 static void clear_view_stack() | |
41 { | |
42 num_prev = 0; | |
43 } | |
20 | 44 |
21 void view_play(struct nk_context *context) | 45 void view_play(struct nk_context *context) |
22 { | 46 { |
23 | 47 |
24 } | 48 } |
67 } | 91 } |
68 nk_group_end(context); | 92 nk_group_end(context); |
69 } | 93 } |
70 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2); | 94 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2); |
71 if (nk_button_label(context, "Back")) { | 95 if (nk_button_label(context, "Back")) { |
72 current_view = previous_view; | 96 pop_view(); |
73 } | 97 } |
74 if (nk_button_label(context, "Open")) { | 98 if (nk_button_label(context, "Open")) { |
75 char *full_path = path_append(current_path, entries[selected_entry].name); | 99 char *full_path = path_append(current_path, entries[selected_entry].name); |
76 if (entries[selected_entry].is_dir) { | 100 if (entries[selected_entry].is_dir) { |
77 free(current_path); | 101 free(current_path); |
89 } | 113 } |
90 } else { | 114 } else { |
91 lockon_media(full_path); | 115 lockon_media(full_path); |
92 free(full_path); | 116 free(full_path); |
93 } | 117 } |
118 clear_view_stack(); | |
94 current_view = view_play; | 119 current_view = view_play; |
95 } | 120 } |
96 } | 121 } |
97 nk_end(context); | 122 nk_end(context); |
98 } | 123 } |
141 } | 166 } |
142 nk_group_end(context); | 167 nk_group_end(context); |
143 } | 168 } |
144 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2); | 169 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2); |
145 if (nk_button_label(context, "Back")) { | 170 if (nk_button_label(context, "Back")) { |
146 current_view = previous_view; | 171 pop_view(); |
147 } | 172 } |
148 if (is_load) { | 173 if (is_load) { |
149 if (nk_button_label(context, "Load")) { | 174 if (nk_button_label(context, "Load")) { |
150 current_system->load_state(current_system, selected_slot); | 175 current_system->load_state(current_system, selected_slot); |
151 current_view = view_play; | 176 current_view = view_play; |
185 nk_layout_space_begin(context, NK_STATIC, top + button_height * num_entries, num_entries); | 210 nk_layout_space_begin(context, NK_STATIC, top + button_height * num_entries, num_entries); |
186 for (uint32_t i = 0; i < num_entries; i++) | 211 for (uint32_t i = 0; i < num_entries; i++) |
187 { | 212 { |
188 nk_layout_space_push(context, nk_rect(left, top + i * button_height, button_width, button_height-button_space)); | 213 nk_layout_space_push(context, nk_rect(left, top + i * button_height, button_width, button_height-button_space)); |
189 if (nk_button_label(context, items[i].title)) { | 214 if (nk_button_label(context, items[i].title)) { |
190 previous_view = current_view; | 215 push_view(items[i].next_view); |
191 current_view = items[i].next_view; | |
192 if (!current_view) { | 216 if (!current_view) { |
193 exit(0); | 217 exit(0); |
194 } | 218 } |
195 if (current_view == view_save_state || current_view == view_load_state) { | 219 if (current_view == view_save_state || current_view == view_load_state) { |
196 free_slot_info(slots); | 220 free_slot_info(slots); |
207 } | 231 } |
208 void view_controllers(struct nk_context *context) | 232 void view_controllers(struct nk_context *context) |
209 { | 233 { |
210 | 234 |
211 } | 235 } |
236 | |
237 void settings_toggle(struct nk_context *context, char *label, char *path, uint8_t def) | |
238 { | |
239 uint8_t curval = !strcmp("on", tern_find_path_default(config, path, (tern_val){.ptrval = def ? "on": "off"}, TVAL_PTR).ptrval); | |
240 nk_label(context, label, NK_TEXT_LEFT); | |
241 uint8_t newval = nk_check_label(context, "", curval); | |
242 if (newval != curval) { | |
243 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(newval ? "on" : "off")}, TVAL_PTR); | |
244 } | |
245 } | |
246 | |
247 void settings_int_input(struct nk_context *context, char *label, char *path, char *def) | |
248 { | |
249 char buffer[12]; | |
250 nk_label(context, label, NK_TEXT_LEFT); | |
251 uint32_t curval; | |
252 char *curstr = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval; | |
253 uint32_t len = strlen(curstr); | |
254 if (len > 11) { | |
255 len = 11; | |
256 } | |
257 memcpy(buffer, curstr, len); | |
258 nk_edit_string(context, NK_EDIT_SIMPLE, buffer, &len, sizeof(buffer)-1, nk_filter_decimal); | |
259 buffer[len] = 0; | |
260 if (strcmp(buffer, curstr)) { | |
261 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR); | |
262 } | |
263 } | |
264 | |
265 void settings_int_property(struct nk_context *context, char *label, char *name, char *path, int def, int min, int max) | |
266 { | |
267 char *curstr = tern_find_path(config, path, TVAL_PTR).ptrval; | |
268 int curval = curstr ? atoi(curstr) : def; | |
269 nk_label(context, label, NK_TEXT_LEFT); | |
270 int val = curval; | |
271 nk_property_int(context, name, min, &val, max, 1, 1.0f); | |
272 if (val != curval) { | |
273 char buffer[12]; | |
274 sprintf(buffer, "%d", val); | |
275 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR); | |
276 } | |
277 } | |
278 | |
212 void view_video_settings(struct nk_context *context) | 279 void view_video_settings(struct nk_context *context) |
213 { | 280 { |
214 | 281 uint32_t width = render_width(); |
282 uint32_t height = render_height(); | |
283 if (nk_begin(context, "Video Settings", nk_rect(0, 0, width, height), 0)) { | |
284 nk_layout_row_static(context, 30, width > 300 ? 300 : width, 2); | |
285 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0); | |
286 settings_toggle(context, "Open GL", "video\0gl\0", 1); | |
287 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0); | |
288 settings_int_input(context, "Windowed Width", "video\0width\0", "640"); | |
289 settings_int_property(context, "NTSC Overscan", "Top", "video\0ntsc\0overscan\0top\0", 2, 0, 32); | |
290 settings_int_property(context, "", "Bottom", "video\0ntsc\0overscan\0bottom\0", 17, 0, 32); | |
291 settings_int_property(context, "", "Left", "video\0ntsc\0overscan\0left\0", 13, 0, 32); | |
292 settings_int_property(context, "", "Right", "video\0ntsc\0overscan\0right\0", 14, 0, 32); | |
293 settings_int_property(context, "PAL Overscan", "Top", "video\0pal\0overscan\0top\0", 2, 0, 32); | |
294 settings_int_property(context, "", "Bottom", "video\0pal\0overscan\0bottom\0", 17, 0, 32); | |
295 settings_int_property(context, "", "Left", "video\0pal\0overscan\0left\0", 13, 0, 32); | |
296 settings_int_property(context, "", "Right", "video\0pal\0overscan\0right\0", 14, 0, 32); | |
297 if (nk_button_label(context, "Back")) { | |
298 pop_view(); | |
299 } | |
300 nk_end(context); | |
301 } | |
215 } | 302 } |
216 void view_audio_settings(struct nk_context *context) | 303 void view_audio_settings(struct nk_context *context) |
217 { | 304 { |
218 | 305 |
219 } | 306 } |
220 void view_system_settings(struct nk_context *context) | 307 void view_system_settings(struct nk_context *context) |
221 { | 308 { |
222 | 309 |
310 } | |
311 | |
312 void view_back(struct nk_context *context) | |
313 { | |
314 pop_view(); | |
315 pop_view(); | |
316 current_view(context); | |
223 } | 317 } |
224 | 318 |
225 void view_settings(struct nk_context *context) | 319 void view_settings(struct nk_context *context) |
226 { | 320 { |
227 static menu_item items[] = { | 321 static menu_item items[] = { |
228 {"Key Bindings", view_key_bindings}, | 322 {"Key Bindings", view_key_bindings}, |
229 {"Controllers", view_controllers}, | 323 {"Controllers", view_controllers}, |
230 {"Video", view_video_settings}, | 324 {"Video", view_video_settings}, |
231 {"Audio", view_audio_settings}, | 325 {"Audio", view_audio_settings}, |
232 {"System", view_system_settings}, | 326 {"System", view_system_settings}, |
233 {"Back", NULL} | 327 {"Back", view_back} |
234 }; | 328 }; |
235 | 329 |
236 const uint32_t num_buttons = 6; | 330 const uint32_t num_buttons = 6; |
237 items[num_buttons-1].next_view = previous_view; | |
238 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { | 331 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { |
239 menu(context, sizeof(items)/sizeof(*items), items); | 332 menu(context, sizeof(items)/sizeof(*items), items); |
240 nk_end(context); | 333 nk_end(context); |
241 } | 334 } |
242 } | 335 } |