Mercurial > repos > blastem
comparison nuklear_ui/blastem_nuklear.c @ 2156:237068a25523
Added UI for setting firmware paths
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 28 Apr 2022 18:41:16 -0700 |
parents | 380bc5d4a2cf |
children | 1270fe86eb89 |
comparison
equal
deleted
inserted
replaced
2152:c3ee42c89b27 | 2156:237068a25523 |
---|---|
70 void view_play(struct nk_context *context) | 70 void view_play(struct nk_context *context) |
71 { | 71 { |
72 | 72 |
73 } | 73 } |
74 | 74 |
75 static char *browser_cur_path; | |
76 static const char *browser_label; | |
77 static const char *browser_setting_path; | |
78 static const char **browser_ext_list; | |
79 static uint32_t browser_num_exts; | |
75 void view_file_browser(struct nk_context *context, uint8_t normal_open) | 80 void view_file_browser(struct nk_context *context, uint8_t normal_open) |
76 { | 81 { |
77 static char *current_path; | |
78 static dir_entry *entries; | 82 static dir_entry *entries; |
79 static size_t num_entries; | 83 static size_t num_entries; |
80 static int32_t selected_entry = -1; | 84 static int32_t selected_entry = -1; |
81 static char **ext_list; | 85 static const char **ext_list; |
82 static uint32_t num_exts; | 86 static uint32_t num_exts; |
83 static uint8_t got_ext_list; | 87 static uint8_t got_ext_list; |
84 if (!current_path) { | 88 if (!browser_cur_path) { |
85 get_initial_browse_path(¤t_path); | 89 get_initial_browse_path(&browser_cur_path); |
86 } | 90 } |
87 if (!entries) { | 91 if (!entries) { |
88 entries = get_dir_list(current_path, &num_entries); | 92 entries = get_dir_list(browser_cur_path, &num_entries); |
89 if (entries) { | 93 if (entries) { |
90 sort_dir_list(entries, num_entries); | 94 sort_dir_list(entries, num_entries); |
91 } | 95 } |
92 if (!num_entries) { | 96 if (!num_entries) { |
93 //get_dir_list can fail if the user doesn't have permission | 97 //get_dir_list can fail if the user doesn't have permission |
97 entries[0].name = strdup(".."); | 101 entries[0].name = strdup(".."); |
98 entries[0].is_dir = 1; | 102 entries[0].is_dir = 1; |
99 num_entries = 1; | 103 num_entries = 1; |
100 } | 104 } |
101 } | 105 } |
102 if (!got_ext_list) { | 106 if (!browser_ext_list) { |
103 ext_list = get_extension_list(config, &num_exts); | 107 if (!got_ext_list) { |
104 got_ext_list = 1; | 108 ext_list = (const char **)get_extension_list(config, &num_exts); |
109 got_ext_list = 1; | |
110 } | |
111 browser_ext_list = ext_list; | |
112 browser_num_exts = num_exts; | |
105 } | 113 } |
106 uint32_t width = render_width(); | 114 uint32_t width = render_width(); |
107 uint32_t height = render_height(); | 115 uint32_t height = render_height(); |
108 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) { | 116 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) { |
109 nk_layout_row_static(context, height - context->style.font->height * 3, width - 60, 1); | 117 nk_layout_row_static(context, height - context->style.font->height * 3, width - 60, 1); |
110 int32_t old_selected = selected_entry; | 118 int32_t old_selected = selected_entry; |
111 char *title = alloc_concat("Select ROM: ", current_path); | 119 const char *parts[] = {browser_label, ": ", browser_cur_path}; |
120 char *title = alloc_concat_m(3, parts); | |
112 if (nk_group_begin(context, title, NK_WINDOW_BORDER | NK_WINDOW_TITLE)) { | 121 if (nk_group_begin(context, title, NK_WINDOW_BORDER | NK_WINDOW_TITLE)) { |
113 nk_layout_row_static(context, context->style.font->height - 2, width-100, 1); | 122 nk_layout_row_static(context, context->style.font->height - 2, width-100, 1); |
114 for (int32_t i = 0; i < num_entries; i++) | 123 for (int32_t i = 0; i < num_entries; i++) |
115 { | 124 { |
116 if (entries[i].name[0] == '.' && entries[i].name[1] != '.') { | 125 if (entries[i].name[0] == '.' && entries[i].name[1] != '.') { |
117 continue; | 126 continue; |
118 } | 127 } |
119 if (num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, ext_list, num_exts)) { | 128 if (browser_num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, browser_ext_list, browser_num_exts)) { |
120 continue; | 129 continue; |
121 } | 130 } |
122 int selected = i == selected_entry; | 131 int selected = i == selected_entry; |
123 nk_selectable_label(context, entries[i].name, NK_TEXT_ALIGN_LEFT, &selected); | 132 nk_selectable_label(context, entries[i].name, NK_TEXT_ALIGN_LEFT, &selected); |
124 if (selected) { | 133 if (selected) { |
130 nk_group_end(context); | 139 nk_group_end(context); |
131 } | 140 } |
132 free(title); | 141 free(title); |
133 nk_layout_row_static(context, context->style.font->height * 1.75, width > 600 ? 300 : width / 2, 2); | 142 nk_layout_row_static(context, context->style.font->height * 1.75, width > 600 ? 300 : width / 2, 2); |
134 if (nk_button_label(context, "Back")) { | 143 if (nk_button_label(context, "Back")) { |
144 browser_ext_list = NULL; | |
135 pop_view(); | 145 pop_view(); |
136 } | 146 } |
137 if (nk_button_label(context, "Open") || (old_selected >= 0 && selected_entry < 0)) { | 147 if (nk_button_label(context, "Open") || (old_selected >= 0 && selected_entry < 0)) { |
138 if (selected_entry < 0) { | 148 if (selected_entry < 0) { |
139 selected_entry = old_selected; | 149 selected_entry = old_selected; |
140 } | 150 } |
141 char *full_path = path_append(current_path, entries[selected_entry].name); | 151 char *full_path = path_append(browser_cur_path, entries[selected_entry].name); |
142 if (entries[selected_entry].is_dir) { | 152 if (entries[selected_entry].is_dir) { |
143 free(current_path); | 153 free(browser_cur_path); |
144 current_path = full_path; | 154 browser_cur_path = full_path; |
145 free_dir_list(entries, num_entries); | 155 free_dir_list(entries, num_entries); |
146 entries = NULL; | 156 entries = NULL; |
147 } else { | 157 } else { |
148 if(normal_open) { | 158 if(normal_open) { |
149 if (current_system) { | 159 if (current_system) { |
151 current_system->request_exit(current_system); | 161 current_system->request_exit(current_system); |
152 } else { | 162 } else { |
153 init_system_with_media(full_path, SYSTEM_UNKNOWN); | 163 init_system_with_media(full_path, SYSTEM_UNKNOWN); |
154 free(full_path); | 164 free(full_path); |
155 } | 165 } |
166 | |
167 clear_view_stack(); | |
168 show_play_view(); | |
169 } else if (browser_setting_path) { | |
170 config = tern_insert_path(config, browser_setting_path, (tern_val){.ptrval = full_path}, TVAL_PTR); | |
171 config_dirty = 1; | |
172 browser_ext_list = NULL; | |
173 pop_view(); | |
156 } else { | 174 } else { |
157 lockon_media(full_path); | 175 lockon_media(full_path); |
158 free(full_path); | 176 free(full_path); |
177 | |
178 clear_view_stack(); | |
179 show_play_view(); | |
159 } | 180 } |
160 clear_view_stack(); | |
161 show_play_view(); | |
162 } | 181 } |
163 selected_entry = -1; | 182 selected_entry = -1; |
164 } | 183 } |
165 nk_end(context); | 184 nk_end(context); |
166 } | 185 } |
167 } | 186 } |
168 | 187 |
169 void view_load(struct nk_context *context) | 188 void view_load(struct nk_context *context) |
170 { | 189 { |
190 browser_label = "Select ROM"; | |
171 view_file_browser(context, 1); | 191 view_file_browser(context, 1); |
172 } | 192 } |
173 | 193 |
174 void view_lock_on(struct nk_context *context) | 194 void view_lock_on(struct nk_context *context) |
195 { | |
196 browser_label = "Select ROM"; | |
197 view_file_browser(context, 0); | |
198 } | |
199 | |
200 void view_file_settings(struct nk_context *context) | |
175 { | 201 { |
176 view_file_browser(context, 0); | 202 view_file_browser(context, 0); |
177 } | 203 } |
178 | 204 |
179 void view_about(struct nk_context *context) | 205 void view_about(struct nk_context *context) |
1592 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR); | 1618 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR); |
1593 } | 1619 } |
1594 free(buffer); | 1620 free(buffer); |
1595 } | 1621 } |
1596 | 1622 |
1623 void settings_path(struct nk_context *context, char *label, char *path, char *def, const char **exts, uint32_t num_exts) | |
1624 { | |
1625 nk_label(context, label, NK_TEXT_LEFT); | |
1626 char *curstr = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval; | |
1627 uint32_t len = strlen(curstr); | |
1628 uint32_t buffer_len = len > 100 ? len + 1 : 101; | |
1629 char *buffer = malloc(buffer_len); | |
1630 memcpy(buffer, curstr, len); | |
1631 memset(buffer+len, 0, buffer_len-len); | |
1632 nk_edit_string(context, NK_EDIT_SIMPLE, buffer, &len, buffer_len-1, nk_filter_default); | |
1633 buffer[len] = 0; | |
1634 if (strcmp(buffer, curstr)) { | |
1635 config_dirty = 1; | |
1636 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR); | |
1637 } | |
1638 | |
1639 nk_spacing(context, 1); | |
1640 if (nk_button_label(context, "Browse")) { | |
1641 browser_label = label; | |
1642 browser_setting_path = path; | |
1643 browser_ext_list = exts; | |
1644 browser_num_exts = num_exts; | |
1645 if (is_absolute_path(buffer)) { | |
1646 browser_cur_path = path_dirname(buffer); | |
1647 } | |
1648 push_view(view_file_settings); | |
1649 } | |
1650 free(buffer); | |
1651 } | |
1652 | |
1597 void settings_int_property(struct nk_context *context, char *label, char *name, char *path, int def, int min, int max) | 1653 void settings_int_property(struct nk_context *context, char *label, char *name, char *path, int def, int min, int max) |
1598 { | 1654 { |
1599 char *curstr = tern_find_path(config, path, TVAL_PTR).ptrval; | 1655 char *curstr = tern_find_path(config, path, TVAL_PTR).ptrval; |
1600 int curval = curstr ? atoi(curstr) : def; | 1656 int curval = curstr ? atoi(curstr) : def; |
1601 nk_label(context, label, NK_TEXT_LEFT); | 1657 nk_label(context, label, NK_TEXT_LEFT); |
2049 } | 2105 } |
2050 nk_end(context); | 2106 nk_end(context); |
2051 } | 2107 } |
2052 } | 2108 } |
2053 | 2109 |
2110 void view_bios_settings(struct nk_context *context) | |
2111 { | |
2112 if (nk_begin(context, "Firmware", nk_rect(0, 0, render_width(), render_height()), 0)) { | |
2113 uint32_t desired_width = context->style.font->height * 10; | |
2114 nk_layout_row_static(context, context->style.font->height, desired_width, 2); | |
2115 static const char* exts[] = {"md", "bin", "smd"}; | |
2116 settings_path(context, "TMSS ROM", "ui\0save_path\0", "tmss.md", exts, 3); | |
2117 settings_path(context, "US CD BIOS", "system\0scd_bios_us\0", "cdbios.md", exts, 3); | |
2118 settings_path(context, "JP CD BIOS", "system\0scd_bios_jp\0", "cdbios.md", exts, 3); | |
2119 settings_path(context, "EU CD BIOS", "system\0scd_bios_eu\0", "cdbios.md", exts, 3); | |
2120 if (nk_button_label(context, "Back")) { | |
2121 pop_view(); | |
2122 } | |
2123 nk_end(context); | |
2124 } | |
2125 } | |
2126 | |
2054 void view_back(struct nk_context *context) | 2127 void view_back(struct nk_context *context) |
2055 { | 2128 { |
2056 pop_view(); | 2129 pop_view(); |
2057 pop_view(); | 2130 pop_view(); |
2058 current_view(context); | 2131 current_view(context); |
2064 {"Key Bindings", view_key_bindings}, | 2137 {"Key Bindings", view_key_bindings}, |
2065 {"Controllers", view_controllers}, | 2138 {"Controllers", view_controllers}, |
2066 {"Video", view_video_settings}, | 2139 {"Video", view_video_settings}, |
2067 {"Audio", view_audio_settings}, | 2140 {"Audio", view_audio_settings}, |
2068 {"System", view_system_settings}, | 2141 {"System", view_system_settings}, |
2142 {"Firmware", view_bios_settings}, | |
2069 {"Reset to Defaults", view_confirm_reset}, | 2143 {"Reset to Defaults", view_confirm_reset}, |
2070 {"Back", view_back} | 2144 {"Back", view_back} |
2071 }; | 2145 }; |
2072 | 2146 |
2073 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { | 2147 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { |