comparison nuklear_ui/blastem_nuklear.c @ 2355:94cf5cc89227

Add an option to use the system file picker on Linux and Windows
author Michael Pavone <pavone@retrodev.com>
date Sat, 21 Oct 2023 19:22:01 -0700
parents ab3d8759da08
children 3e064001594a
comparison
equal deleted inserted replaced
2354:a773b8f09292 2355:94cf5cc89227
7 #include <limits.h> 7 #include <limits.h>
8 #include <math.h> 8 #include <math.h>
9 #include "blastem_nuklear.h" 9 #include "blastem_nuklear.h"
10 #include "nuklear_rawfb.h" 10 #include "nuklear_rawfb.h"
11 #include "font.h" 11 #include "font.h"
12 #include "filechooser.h"
12 #include "../render.h" 13 #include "../render.h"
13 #include "../render_sdl.h" 14 #include "../render_sdl.h"
14 #include "../util.h" 15 #include "../util.h"
15 #include "../paths.h" 16 #include "../paths.h"
16 #include "../saves.h" 17 #include "../saves.h"
75 static char *browser_cur_path; 76 static char *browser_cur_path;
76 static const char *browser_label; 77 static const char *browser_label;
77 static const char *browser_setting_path; 78 static const char *browser_setting_path;
78 static const char **browser_ext_list; 79 static const char **browser_ext_list;
79 static uint32_t browser_num_exts; 80 static uint32_t browser_num_exts;
81 static uint8_t use_native_filechooser;
82
83 static void handle_chooser_result(uint8_t normal_open, char *full_path)
84 {
85 if(normal_open) {
86 if (current_system) {
87 current_system->next_rom = full_path;
88 current_system->request_exit(current_system);
89 } else {
90 init_system_with_media(full_path, SYSTEM_UNKNOWN);
91 free(full_path);
92 }
93
94 clear_view_stack();
95 show_play_view();
96 } else if (browser_setting_path) {
97 config = tern_insert_path(config, browser_setting_path, (tern_val){.ptrval = full_path}, TVAL_PTR);
98 config_dirty = 1;
99 browser_ext_list = NULL;
100 pop_view();
101 } else {
102 lockon_media(full_path);
103 free(full_path);
104
105 clear_view_stack();
106 show_play_view();
107 }
108 }
109
80 void view_file_browser(struct nk_context *context, uint8_t normal_open) 110 void view_file_browser(struct nk_context *context, uint8_t normal_open)
81 { 111 {
82 static dir_entry *entries; 112 static dir_entry *entries;
83 static size_t num_entries; 113 static size_t num_entries;
84 static int32_t selected_entry = -1; 114 static int32_t selected_entry = -1;
85 static const char **ext_list; 115 static const char **ext_list;
86 static uint32_t num_exts; 116 static uint32_t num_exts;
87 static uint8_t got_ext_list; 117 static uint8_t got_ext_list;
88 if (!browser_cur_path) { 118 if (!browser_cur_path) {
89 get_initial_browse_path(&browser_cur_path); 119 get_initial_browse_path(&browser_cur_path);
120 }
121 if (use_native_filechooser && native_filechooser_available()) {
122 char *path = native_filechooser_pick(browser_label, browser_cur_path);
123 if (path) {
124 free(browser_cur_path);
125 browser_cur_path = path_dirname(path);
126 handle_chooser_result(normal_open, path);
127 } else {
128 browser_ext_list = NULL;
129 pop_view();
130 }
131 return;
90 } 132 }
91 if (!entries) { 133 if (!entries) {
92 entries = get_dir_list(browser_cur_path, &num_entries); 134 entries = get_dir_list(browser_cur_path, &num_entries);
93 if (entries) { 135 if (entries) {
94 sort_dir_list(entries, num_entries); 136 sort_dir_list(entries, num_entries);
153 free(browser_cur_path); 195 free(browser_cur_path);
154 browser_cur_path = full_path; 196 browser_cur_path = full_path;
155 free_dir_list(entries, num_entries); 197 free_dir_list(entries, num_entries);
156 entries = NULL; 198 entries = NULL;
157 } else { 199 } else {
158 if(normal_open) { 200 handle_chooser_result(normal_open, full_path);
159 if (current_system) {
160 current_system->next_rom = full_path;
161 current_system->request_exit(current_system);
162 } else {
163 init_system_with_media(full_path, SYSTEM_UNKNOWN);
164 free(full_path);
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();
174 } else {
175 lockon_media(full_path);
176 free(full_path);
177
178 clear_view_stack();
179 show_play_view();
180 }
181 } 201 }
182 selected_entry = -1; 202 selected_entry = -1;
183 } 203 }
184 nk_end(context); 204 nk_end(context);
185 } 205 }
2275 settings_int_property(context, "68000 Clock Divider", "", "clocks\0m68k_divider\0", 7, 1, 53); 2295 settings_int_property(context, "68000 Clock Divider", "", "clocks\0m68k_divider\0", 7, 1, 53);
2276 selected_format = settings_dropdown(context, "Save State Format", formats, num_formats, selected_format, "ui\0state_format\0"); 2296 selected_format = settings_dropdown(context, "Save State Format", formats, num_formats, selected_format, "ui\0state_format\0");
2277 } 2297 }
2278 selected_init = settings_dropdown(context, "Initial RAM Value", ram_inits, num_inits, selected_init, "system\0ram_init\0"); 2298 selected_init = settings_dropdown(context, "Initial RAM Value", ram_inits, num_inits, selected_init, "system\0ram_init\0");
2279 settings_toggle(context, "Remember ROM Path", "ui\0remember_path\0", 1); 2299 settings_toggle(context, "Remember ROM Path", "ui\0remember_path\0", 1);
2300 settings_toggle(context, "Use Native File Picker", "ui\0use_native_filechooser\0", 0);
2280 settings_toggle(context, "Save config with EXE", "ui\0config_in_exe_dir\0", 0); 2301 settings_toggle(context, "Save config with EXE", "ui\0config_in_exe_dir\0", 0);
2281 settings_string(context, "Game Save Path", "ui\0save_path\0", "$USERDATA/blastem/$ROMNAME"); 2302 settings_string(context, "Game Save Path", "ui\0save_path\0", "$USERDATA/blastem/$ROMNAME");
2282 2303
2283 if (nk_button_label(context, "Back")) { 2304 if (nk_button_label(context, "Back")) {
2305 if (config_dirty) {
2306 char *unf = tern_find_path(config, "ui\0use_native_filechooser\0", TVAL_PTR).ptrval;
2307 use_native_filechooser = unf && !strcmp(unf, "on");
2308 }
2284 pop_view(); 2309 pop_view();
2285 } 2310 }
2286 nk_end(context); 2311 nk_end(context);
2287 } 2312 }
2288 } 2313 }
2687 set_content_binding_state(0); 2712 set_content_binding_state(0);
2688 } 2713 }
2689 render_set_ui_render_fun(blastem_nuklear_render); 2714 render_set_ui_render_fun(blastem_nuklear_render);
2690 render_set_event_handler(handle_event); 2715 render_set_event_handler(handle_event);
2691 render_set_gl_context_handlers(context_destroyed, context_created); 2716 render_set_gl_context_handlers(context_destroyed, context_created);
2717 char *unf = tern_find_path(config, "ui\0use_native_filechooser\0", TVAL_PTR).ptrval;
2718 use_native_filechooser = unf && !strcmp(unf, "on");
2692 2719
2693 atexit(persist_config_exit); 2720 atexit(persist_config_exit);
2694 2721
2695 active = 1; 2722 active = 1;
2696 ui_idle_loop(); 2723 ui_idle_loop();