Mercurial > repos > blastem
annotate nuklear_ui/blastem_nuklear.c @ 1606:aa7533000161
Show current config value for controller butotn and axis mappings
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 02 Aug 2018 19:05:48 -0700 |
parents | f7b1d983d5c0 |
children | 9c8f58740450 |
rev | line source |
---|---|
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #define NK_IMPLEMENTATION |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #define NK_SDL_GLES2_IMPLEMENTATION |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <stdlib.h> |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
5 #include <limits.h> |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "blastem_nuklear.h" |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "font.h" |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "../render.h" |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include "../render_sdl.h" |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include "../util.h" |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include "../paths.h" |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
12 #include "../saves.h" |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #include "../blastem.h" |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
14 #include "../config.h" |
1501
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
15 #include "../io.h" |
1569
0ec89dadb36d
Add code for loading PNG images. Added 360 controller image. WIP work on gamepad mapping UI
Michael Pavone <pavone@retrodev.com>
parents:
1568
diff
changeset
|
16 #include "../png.h" |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
17 #include "../controller_info.h" |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 static struct nk_context *context; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 typedef void (*view_fun)(struct nk_context *); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 static view_fun current_view; |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
23 static view_fun *previous_views; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
24 static uint32_t view_storage; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
25 static uint32_t num_prev; |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
26 static struct nk_font *def_font; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
27 static uint8_t config_dirty; |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
28 |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
29 static void push_view(view_fun new_view) |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
30 { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
31 if (num_prev == view_storage) { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
32 view_storage = view_storage ? 2*view_storage : 2; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
33 previous_views = realloc(previous_views, view_storage*sizeof(view_fun)); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
34 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
35 previous_views[num_prev++] = current_view; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
36 current_view = new_view; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
37 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
38 |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
39 static void pop_view() |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
40 { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
41 if (num_prev) { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
42 current_view = previous_views[--num_prev]; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
43 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
44 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
45 |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
46 static void clear_view_stack() |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
47 { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
48 num_prev = 0; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
49 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 void view_play(struct nk_context *context) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 |
1487
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
56 void view_file_browser(struct nk_context *context, uint8_t normal_open) |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 static char *current_path; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 static dir_entry *entries; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 static size_t num_entries; |
1554
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
61 static int32_t selected_entry = -1; |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
62 static char **ext_list; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
63 static uint32_t num_exts; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
64 static uint8_t got_ext_list; |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
65 if (!current_path) { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
66 get_initial_browse_path(¤t_path); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
67 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 if (!entries) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 entries = get_dir_list(current_path, &num_entries); |
1484
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1483
diff
changeset
|
70 if (entries) { |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1483
diff
changeset
|
71 sort_dir_list(entries, num_entries); |
d82af64c94d2
Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents:
1483
diff
changeset
|
72 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 } |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
74 if (!got_ext_list) { |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
75 ext_list = get_extension_list(config, &num_exts); |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
76 got_ext_list = 1; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
77 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 uint32_t width = render_width(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 uint32_t height = render_height(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) { |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
81 nk_layout_row_static(context, height - context->style.font->height * 3, width - 60, 1); |
1554
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
82 int32_t old_selected = selected_entry; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 if (nk_group_begin(context, "Select ROM", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) { |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
84 nk_layout_row_static(context, context->style.font->height - 2, width-100, 1); |
1554
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
85 for (int32_t i = 0; i < num_entries; i++) |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 { |
1485
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
87 if (entries[i].name[0] == '.' && entries[i].name[1] != '.') { |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
88 continue; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
89 } |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
90 if (num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, ext_list, num_exts)) { |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
91 continue; |
369da70ee2c2
Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1484
diff
changeset
|
92 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 int selected = i == selected_entry; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 nk_selectable_label(context, entries[i].name, NK_TEXT_ALIGN_LEFT, &selected); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 if (selected) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 selected_entry = i; |
1554
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
97 } else if (i == selected_entry) { |
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
98 selected_entry = -1; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 nk_group_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 } |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
103 nk_layout_row_static(context, context->style.font->height * 1.75, width > 600 ? 300 : width / 2, 2); |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
104 if (nk_button_label(context, "Back")) { |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
105 pop_view(); |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
106 } |
1554
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
107 if (nk_button_label(context, "Open") || (old_selected >= 0 && selected_entry < 0)) { |
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
108 if (selected_entry < 0) { |
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
109 selected_entry = old_selected; |
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
110 } |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
111 char *full_path = path_append(current_path, entries[selected_entry].name); |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 if (entries[selected_entry].is_dir) { |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
113 free(current_path); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
114 current_path = full_path; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 free_dir_list(entries, num_entries); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 entries = NULL; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 } else { |
1487
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
118 if(normal_open) { |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
119 if (current_system) { |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
120 current_system->next_rom = full_path; |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
121 current_system->request_exit(current_system); |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
122 } else { |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
123 init_system_with_media(full_path, SYSTEM_UNKNOWN); |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
124 free(full_path); |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
125 } |
1483
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
126 } else { |
1487
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
127 lockon_media(full_path); |
1483
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
128 free(full_path); |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
129 } |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
130 clear_view_stack(); |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 current_view = view_play; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 } |
1554
87350caf6dab
Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents:
1553
diff
changeset
|
133 selected_entry = -1; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 nk_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 |
1487
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
139 void view_load(struct nk_context *context) |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
140 { |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
141 view_file_browser(context, 1); |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
142 } |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
143 |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
144 void view_lock_on(struct nk_context *context) |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
145 { |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
146 view_file_browser(context, 0); |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
147 } |
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
148 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 void view_about(struct nk_context *context) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 { |
1526 | 151 const char *lines[] = { |
152 "BlastEm v0.6.0", | |
153 "Copyright 2012-2017 Michael Pavone", | |
154 "", | |
155 "BlastEm is a high performance open source", | |
156 "(GPLv3) Genesis/Megadrive emulator", | |
157 }; | |
158 const uint32_t NUM_LINES = sizeof(lines)/sizeof(*lines); | |
159 const char *thanks[] = { | |
160 "Nemesis: Documentatino and test ROMs", | |
161 "Charles MacDonald: Documentation", | |
162 "Eke-Eke: Documentation", | |
163 "Bart Trzynadlowski: Documentation", | |
164 "KanedaFR: Hosting the best Sega forum", | |
165 "Titan: Awesome demos and documentation", | |
166 "micky: Testing", | |
167 "Sasha: Testing", | |
168 "lol-frank: Testing", | |
169 "Sik: Testing", | |
170 "Tim Lawrence : Testing", | |
171 "ComradeOj: Testing", | |
172 "Vladikcomper: Testing" | |
173 }; | |
174 const uint32_t NUM_THANKS = sizeof(thanks)/sizeof(*thanks); | |
175 uint32_t width = render_width(); | |
176 uint32_t height = render_height(); | |
177 if (nk_begin(context, "About", nk_rect(0, 0, width, height), 0)) { | |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
178 nk_layout_row_static(context, context->style.font->height, width-40, 1); |
1526 | 179 for (uint32_t i = 0; i < NUM_LINES; i++) |
180 { | |
181 nk_label(context, lines[i], NK_TEXT_LEFT); | |
182 } | |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
183 nk_layout_row_static(context, height - (context->style.font->height * 2 + 20) - (context->style.font->height +4)*NUM_LINES, width-40, 1); |
1526 | 184 if (nk_group_begin(context, "Special Thanks", NK_WINDOW_TITLE)) { |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
185 nk_layout_row_static(context, context->style.font->height, width - 80, 1); |
1526 | 186 for (uint32_t i = 0; i < NUM_THANKS; i++) |
187 { | |
188 nk_label(context, thanks[i], NK_TEXT_LEFT); | |
189 } | |
190 nk_group_end(context); | |
191 } | |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
192 nk_layout_row_static(context, context->style.font->height * 1.75, width/3, 1); |
1526 | 193 if (nk_button_label(context, "Back")) { |
194 pop_view(); | |
195 } | |
196 nk_end(context); | |
197 } | |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 typedef struct { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 const char *title; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 view_fun next_view; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 } menu_item; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
205 static save_slot_info *slots; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
206 static uint32_t num_slots, selected_slot; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
207 |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
208 void view_choose_state(struct nk_context *context, uint8_t is_load) |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
209 { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
210 uint32_t width = render_width(); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
211 uint32_t height = render_height(); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
212 if (nk_begin(context, "Slot Picker", nk_rect(0, 0, width, height), 0)) { |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
213 nk_layout_row_static(context, height - context->style.font->height * 3, width - 60, 1); |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
214 if (nk_group_begin(context, "Select Save Slot", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) { |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
215 nk_layout_row_static(context, context->style.font->height - 2, width-100, 1); |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
216 if (!slots) { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
217 slots = get_slot_info(current_system, &num_slots); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
218 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
219 for (uint32_t i = 0; i < num_slots; i++) |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
220 { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
221 int selected = i == selected_slot; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
222 nk_selectable_label(context, slots[i].desc, NK_TEXT_ALIGN_LEFT, &selected); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
223 if (selected && (slots[i].modification_time || !is_load)) { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
224 selected_slot = i; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
225 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
226 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
227 nk_group_end(context); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
228 } |
1579
f66290afae65
Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents:
1578
diff
changeset
|
229 nk_layout_row_static(context, context->style.font->height * 1.75, width > 600 ? 300 : width / 2, 2); |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
230 if (nk_button_label(context, "Back")) { |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
231 pop_view(); |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
232 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
233 if (is_load) { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
234 if (nk_button_label(context, "Load")) { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
235 current_system->load_state(current_system, selected_slot); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
236 current_view = view_play; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
237 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
238 } else { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
239 if (nk_button_label(context, "Save")) { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
240 current_system->save_state = selected_slot + 1; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
241 current_view = view_play; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
242 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
243 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
244 nk_end(context); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
245 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
246 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
247 |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
248 void view_save_state(struct nk_context *context) |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
249 { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
250 view_choose_state(context, 0); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
251 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
252 |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
253 void view_load_state(struct nk_context *context) |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
254 { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
255 view_choose_state(context, 1); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
256 } |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
257 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 static void menu(struct nk_context *context, uint32_t num_entries, const menu_item *items) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 { |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
260 const uint32_t button_height = context->style.font->height * 1.75; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
261 const uint32_t ideal_button_width = context->style.font->height * 10; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 const uint32_t button_space = 6; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 uint32_t width = render_width(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 uint32_t height = render_height(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 uint32_t top = height/2 - (button_height * num_entries)/2; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 uint32_t button_width = width > ideal_button_width ? ideal_button_width : width; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 uint32_t left = width/2 - button_width/2; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 nk_layout_space_begin(context, NK_STATIC, top + button_height * num_entries, num_entries); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 for (uint32_t i = 0; i < num_entries; i++) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 nk_layout_space_push(context, nk_rect(left, top + i * button_height, button_width, button_height-button_space)); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 if (nk_button_label(context, items[i].title)) { |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
275 push_view(items[i].next_view); |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 if (!current_view) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 exit(0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 } |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
279 if (current_view == view_save_state || current_view == view_load_state) { |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
280 free_slot_info(slots); |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
281 slots = NULL; |
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1477
diff
changeset
|
282 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 nk_layout_space_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
288 void binding_loop(char *key, tern_val val, uint8_t valtype, void *data) |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
289 { |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
290 if (valtype != TVAL_PTR) { |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
291 return; |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
292 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
293 tern_node **binding_lookup = data; |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
294 *binding_lookup = tern_insert_ptr(*binding_lookup, val.ptrval, strdup(key)); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
295 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
296 |
1522
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
297 static int32_t keycode; |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
298 static const char *set_binding; |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
299 char *set_label; |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
300 void binding_group(struct nk_context *context, char *name, const char **binds, const char **bind_names, uint32_t num_binds, tern_node *binding_lookup) |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
301 { |
1578
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
302 nk_layout_row_static(context, (context->style.font->height + 4)*num_binds+context->style.font->height+30, render_width() - 80, 1); |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
303 if (nk_group_begin(context, name, NK_WINDOW_TITLE)) { |
1578
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
304 nk_layout_row_static(context, context->style.font->height, render_width()/2 - 80, 2); |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
305 |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
306 for (int i = 0; i < num_binds; i++) |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
307 { |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
308 char *label_alloc = bind_names ? NULL : path_extension(binds[i]); |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
309 const char *label = label_alloc; |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
310 if (!label) { |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
311 label = bind_names ? bind_names[i] : binds[i]; |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
312 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
313 nk_label(context, label, NK_TEXT_LEFT); |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
314 if (nk_button_label(context, tern_find_ptr_default(binding_lookup, binds[i], "Not Set"))) { |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
315 set_binding = binds[i]; |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
316 set_label = strdup(label); |
1522
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
317 keycode = 0; |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
318 } |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
319 if (label_alloc) { |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
320 free(label_alloc); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
321 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
322 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
323 nk_group_end(context); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
324 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
325 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
326 |
1522
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
327 static char *get_key_name(int32_t keycode) |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
328 { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
329 char *name = NULL; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
330 if (keycode > ' ' && keycode < 0x80) { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
331 //key corresponds to a printable non-whitespace character |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
332 name = malloc(2); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
333 name[0] = keycode; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
334 name[1] = 0; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
335 } else { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
336 switch (keycode) |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
337 { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
338 case RENDERKEY_UP: name = "up"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
339 case RENDERKEY_DOWN: name = "down"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
340 case RENDERKEY_LEFT: name = "left"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
341 case RENDERKEY_RIGHT: name = "right"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
342 case '\r': name = "enter"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
343 case ' ': name = "space"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
344 case '\t': name = "tab"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
345 case '\b': name = "backspace"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
346 case RENDERKEY_ESC: name = "esc"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
347 case RENDERKEY_DEL: name = "delete"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
348 case RENDERKEY_LSHIFT: name = "lshift"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
349 case RENDERKEY_RSHIFT: name = "rshift"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
350 case RENDERKEY_LCTRL: name = "lctrl"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
351 case RENDERKEY_RCTRL: name = "rctrl"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
352 case RENDERKEY_LALT: name = "lalt"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
353 case RENDERKEY_RALT: name = "ralt"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
354 case RENDERKEY_HOME: name = "home"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
355 case RENDERKEY_END: name = "end"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
356 case RENDERKEY_PAGEUP: name = "pageup"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
357 case RENDERKEY_PAGEDOWN: name = "pagedown"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
358 case RENDERKEY_F1: name = "f1"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
359 case RENDERKEY_F2: name = "f2"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
360 case RENDERKEY_F3: name = "f3"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
361 case RENDERKEY_F4: name = "f4"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
362 case RENDERKEY_F5: name = "f5"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
363 case RENDERKEY_F6: name = "f6"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
364 case RENDERKEY_F7: name = "f7"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
365 case RENDERKEY_F8: name = "f8"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
366 case RENDERKEY_F9: name = "f9"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
367 case RENDERKEY_F10: name = "f10"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
368 case RENDERKEY_F11: name = "f11"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
369 case RENDERKEY_F12: name = "f12"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
370 case RENDERKEY_SELECT: name = "select"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
371 case RENDERKEY_PLAY: name = "play"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
372 case RENDERKEY_SEARCH: name = "search"; break; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
373 case RENDERKEY_BACK: name = "back"; break; |
1549
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
374 case RENDERKEY_NP0: name = "np0"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
375 case RENDERKEY_NP1: name = "np1"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
376 case RENDERKEY_NP2: name = "np2"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
377 case RENDERKEY_NP3: name = "np3"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
378 case RENDERKEY_NP4: name = "np4"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
379 case RENDERKEY_NP5: name = "np5"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
380 case RENDERKEY_NP6: name = "np6"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
381 case RENDERKEY_NP7: name = "np7"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
382 case RENDERKEY_NP8: name = "np8"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
383 case RENDERKEY_NP9: name = "np9"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
384 case RENDERKEY_NP_DIV: name = "np/"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
385 case RENDERKEY_NP_MUL: name = "np*"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
386 case RENDERKEY_NP_MIN: name = "np-"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
387 case RENDERKEY_NP_PLUS: name = "np+"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
388 case RENDERKEY_NP_ENTER: name = "npenter"; break; |
577253765192
Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents:
1545
diff
changeset
|
389 case RENDERKEY_NP_STOP: name = "np."; break; |
1522
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
390 } |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
391 if (name) { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
392 name = strdup(name); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
393 } |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
394 } |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
395 return name; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
396 } |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
397 |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
398 void view_key_bindings(struct nk_context *context) |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
399 { |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
400 const char *controller1_binds[] = { |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
401 "gamepads.1.up", "gamepads.1.down", "gamepads.1.left", "gamepads.1.right", |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
402 "gamepads.1.a", "gamepads.1.b", "gamepads.1.c", |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
403 "gamepads.1.x", "gamepads.1.y", "gamepads.1.z", |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
404 "gamepads.1.start", "gamepads.1.mode" |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
405 }; |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
406 const char *controller2_binds[] = { |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
407 "gamepads.2.up", "gamepads.2.down", "gamepads.2.left", "gamepads.2.right", |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
408 "gamepads.2.a", "gamepads.2.b", "gamepads.2.c", |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
409 "gamepads.2.x", "gamepads.2.y", "gamepads.2.z", |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
410 "gamepads.2.start", "gamepads.2.mode" |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
411 }; |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
412 const char *general_binds[] = { |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
413 "ui.exit", "ui.save_state", "ui.toggle_fullscreen", "ui.soft_reset", "ui.reload", |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
414 "ui.screenshot", "ui.sms_pause", "ui.toggle_keyboard_cpatured", "ui.release_mouse" |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
415 }; |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
416 const char *general_names[] = { |
1522
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
417 "Show Menu", "Quick Save", "Toggle Fullscreen", "Soft Reset", "Reload Media", |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
418 "Internal Screenshot", "SMS Pause", "Capture Keyboard", "Release Mouse" |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
419 }; |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
420 const char *speed_binds[] = { |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
421 "ui.next_speed", "ui.prev_speed", |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
422 "ui.set_speed.0", "ui.set_speed.1", "ui.set_speed.2" ,"ui.set_speed.3", "ui.set_speed.4", |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
423 "ui.set_speed.5", "ui.set_speed.6", "ui.set_speed.7" ,"ui.set_speed.8", "ui.set_speed.9", |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
424 }; |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
425 const char *speed_names[] = { |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
426 "Next", "Previous", |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
427 "Default Speed", "Set Speed 1", "Set Speed 2", "Set Speed 3", "Set Speed 4", |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
428 "Set Speed 5", "Set Speed 6", "Set Speed 7", "Set Speed 8", "Set Speed 9" |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
429 }; |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
430 const char *debug_binds[] = { |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
431 "ui.enter_debugger", "ui.vdp_debug_mode", "ui.vdp_debug_pal" |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
432 }; |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
433 const char *debug_names[] = { |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
434 "Enter Debugger", "VDP Debug Mode", "Debug Palette" |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
435 }; |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
436 const uint32_t NUM_C1_BINDS = sizeof(controller1_binds)/sizeof(*controller1_binds); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
437 const uint32_t NUM_C2_BINDS = sizeof(controller2_binds)/sizeof(*controller2_binds); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
438 const uint32_t NUM_SPEED_BINDS = sizeof(speed_binds)/sizeof(*speed_binds); |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
439 const uint32_t NUM_GEN_BINDS = sizeof(general_binds)/sizeof(*general_binds); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
440 const uint32_t NUM_DBG_BINDS = sizeof(debug_binds)/sizeof(*debug_binds); |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
441 static tern_node *binding_lookup; |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
442 if (!binding_lookup) { |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
443 tern_node *bindings = tern_find_path(config, "bindings\0keys\0", TVAL_NODE).ptrval; |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
444 if (bindings) { |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
445 tern_foreach(bindings, binding_loop, &binding_lookup); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
446 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
447 } |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
448 uint32_t width = render_width(); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
449 uint32_t height = render_height(); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
450 if (nk_begin(context, "Keyboard Bindings", nk_rect(0, 0, width, height), 0)) { |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
451 binding_group(context, "Controller 1", controller1_binds, NULL, NUM_C1_BINDS, binding_lookup); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
452 binding_group(context, "Controller 2", controller2_binds, NULL, NUM_C2_BINDS, binding_lookup); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
453 binding_group(context, "General", general_binds, general_names, NUM_GEN_BINDS, binding_lookup); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
454 binding_group(context, "Speed Control", speed_binds, speed_names, NUM_SPEED_BINDS, binding_lookup); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
455 binding_group(context, "Debug", debug_binds, debug_names, NUM_DBG_BINDS, binding_lookup); |
1578
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
456 nk_layout_row_static(context, context->style.font->height * 1.1333, (render_width() - 80) / 2, 1); |
1545
3faf917bab56
Add back button to Key binding view and add a window and back button to empty controller view so you can always get back to the main menu
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
457 if (nk_button_label(context, "Back")) { |
3faf917bab56
Add back button to Key binding view and add a window and back button to empty controller view so you can always get back to the main menu
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
458 pop_view(); |
3faf917bab56
Add back button to Key binding view and add a window and back button to empty controller view so you can always get back to the main menu
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
459 } |
1520
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
460 nk_end(context); |
cb3c6395b28c
Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents:
1501
diff
changeset
|
461 } |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
462 if (set_binding && nk_begin(context, "Set Binding", nk_rect(width/4, height/4, width/2/*width*3/4*/, height/2), NK_WINDOW_TITLE | NK_WINDOW_BORDER)) { |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
463 nk_layout_row_static(context, 30, width/2-30, 1); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
464 nk_label(context, "Press new key for", NK_TEXT_CENTERED); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
465 nk_label(context, set_label, NK_TEXT_CENTERED); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
466 if (nk_button_label(context, "Cancel")) { |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
467 free(set_label); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
468 set_binding = set_label = NULL; |
1522
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
469 } else if (keycode) { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
470 char *name = get_key_name(keycode); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
471 if (name) { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
472 uint32_t prefix_len = strlen("bindings") + strlen("keys") + 2; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
473 char * old = tern_find_ptr(binding_lookup, set_binding); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
474 if (old) { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
475 uint32_t suffix_len = strlen(old) + 1; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
476 char *old_path = malloc(prefix_len + suffix_len + 1); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
477 memcpy(old_path, "bindings\0keys\0", prefix_len); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
478 memcpy(old_path + prefix_len, old, suffix_len); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
479 old_path[prefix_len + suffix_len] = 0; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
480 tern_val old_val; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
481 if (tern_delete_path(&config, old_path, &old_val) == TVAL_PTR) { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
482 free(old_val.ptrval); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
483 } |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
484 } |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
485 uint32_t suffix_len = strlen(name) + 1; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
486 char *path = malloc(prefix_len + suffix_len + 1); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
487 memcpy(path, "bindings\0keys\0", prefix_len); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
488 memcpy(path + prefix_len, name, suffix_len); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
489 path[prefix_len + suffix_len] = 0; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
490 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
491 config_dirty = 1; |
1522
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
492 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(set_binding)}, TVAL_PTR); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
493 free(path); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
494 free(name); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
495 tern_free(binding_lookup); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
496 binding_lookup = NULL; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
497 } |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
498 free(set_label); |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
499 set_binding = set_label = NULL; |
1521
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
500 } |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
501 nk_end(context); |
a51721408c15
More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents:
1520
diff
changeset
|
502 } |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
503 } |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
504 |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
505 static int selected_controller; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
506 static controller_info selected_controller_info; |
1570
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
507 static struct nk_image controller_360_image; |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
508 static uint32_t controller_360_width, controller_360_height; |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
509 //#define MIN_BIND_BOX_WIDTH 140 |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
510 #define MAX_BIND_BOX_WIDTH 350 |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
511 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
512 #define AXIS 0x40000000 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
513 #define STICKDIR 0x30000000 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
514 #define LEFTSTICK 0x10000000 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
515 #define RIGHTSTICK 0x20000000 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
516 enum { |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
517 UP,DOWN,LEFT,RIGHT |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
518 }; |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
519 |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
520 static char * config_ps_names[] = { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
521 [SDL_CONTROLLER_BUTTON_A] = "cross", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
522 [SDL_CONTROLLER_BUTTON_B] = "circle", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
523 [SDL_CONTROLLER_BUTTON_X] = "square", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
524 [SDL_CONTROLLER_BUTTON_Y] = "triangle", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
525 [SDL_CONTROLLER_BUTTON_BACK] = "share", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
526 [SDL_CONTROLLER_BUTTON_START] = "options", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
527 [SDL_CONTROLLER_BUTTON_LEFTSHOULDER] = "l1", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
528 [SDL_CONTROLLER_BUTTON_RIGHTSHOULDER] = "r1", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
529 [SDL_CONTROLLER_BUTTON_LEFTSTICK] = "l3", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
530 [SDL_CONTROLLER_BUTTON_RIGHTSTICK] = "r3", |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
531 }; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
532 |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
533 static void binding_box(struct nk_context *context, char *name, float x, float y, float width, int num_binds, int *binds) |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
534 { |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
535 const struct nk_user_font *font = context->style.font; |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
536 float row_height = font->height * 2; |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
537 |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
538 char const **labels = calloc(sizeof(char *), num_binds); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
539 char **conf_keys = calloc(sizeof(char *), num_binds); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
540 float max_width = 0.0f; |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
541 |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
542 static const char base_path[] = "bindings\0pads"; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
543 static const char buttons[] = "buttons"; |
1606
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
544 static const char dpads[] = "dpads\00"; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
545 static const char axes[] = "axes"; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
546 static const char positive[] = ".positive"; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
547 static const char negative[] = ".negative"; |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
548 char padkey[] = {'0' + selected_controller, 0}; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
549 int skipped = 0; |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
550 for (int i = 0; i < num_binds; i++) |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
551 { |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
552 if (binds[i] & AXIS) { |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
553 labels[i] = get_axis_label(&selected_controller_info, binds[i] & ~AXIS); |
1606
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
554 const char *axname = SDL_GameControllerGetStringForAxis(binds[i] & ~AXIS); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
555 size_t namelen = strlen(axname); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
556 conf_keys[i] = malloc(sizeof(base_path) + sizeof(padkey) + sizeof(axes) + namelen + 2); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
557 memcpy(conf_keys[i], base_path, sizeof(base_path)); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
558 memcpy(conf_keys[i] + sizeof(base_path), padkey, sizeof(padkey)); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
559 memcpy(conf_keys[i] + sizeof(base_path) + sizeof(padkey), axes, sizeof(axes)); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
560 memcpy(conf_keys[i] + sizeof(base_path) + sizeof(padkey) + sizeof(axes), axname, namelen+1); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
561 conf_keys[i][sizeof(base_path) + sizeof(padkey) + sizeof(axes) + namelen + 1] = 0; |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
562 } else if (binds[i] & STICKDIR) { |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
563 static char const * dirs[] = {"Up", "Down", "Left", "Right"}; |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
564 labels[i] = dirs[binds[i] & 3]; |
1606
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
565 uint8_t is_pos = (binds[i] & 3) == 3 || !(binds[i] & 3); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
566 int sdl_axis = (binds[i] & LEFTSTICK ? SDL_CONTROLLER_AXIS_LEFTX : SDL_CONTROLLER_AXIS_RIGHTX) + !(binds[i] & 2); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
567 const char *axname = SDL_GameControllerGetStringForAxis(sdl_axis); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
568 size_t namelen = strlen(axname); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
569 conf_keys[i] = malloc(sizeof(base_path) + sizeof(padkey) + sizeof(axes) + namelen + sizeof(positive) + 1); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
570 memcpy(conf_keys[i], base_path, sizeof(base_path)); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
571 memcpy(conf_keys[i] + sizeof(base_path), padkey, sizeof(padkey)); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
572 memcpy(conf_keys[i] + sizeof(base_path) + sizeof(padkey), axes, sizeof(axes)); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
573 memcpy(conf_keys[i] + sizeof(base_path) + sizeof(padkey) + sizeof(axes), axname, namelen); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
574 memcpy(conf_keys[i] + sizeof(base_path) + sizeof(padkey) + sizeof(axes) + namelen, is_pos ? positive : negative, sizeof(positive)); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
575 conf_keys[i][sizeof(base_path) + sizeof(padkey) + sizeof(axes) + namelen + sizeof(positive)] = 0; |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
576 } else { |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
577 labels[i] = get_button_label(&selected_controller_info, binds[i]); |
1606
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
578 static const char* dpdirs[] = {"up", "down", "left", "right"}; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
579 const char *but_name, *mid; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
580 size_t midsz; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
581 if (binds[i] < SDL_CONTROLLER_BUTTON_DPAD_UP) { |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
582 but_name = SDL_GameControllerGetStringForButton(binds[i]); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
583 mid = buttons; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
584 midsz = sizeof(buttons); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
585 } else { |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
586 but_name = dpdirs[binds[i] - SDL_CONTROLLER_BUTTON_DPAD_UP]; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
587 mid = dpads; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
588 midsz = sizeof(dpads); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
589 } |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
590 size_t namelen = strlen(but_name); |
1606
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
591 conf_keys[i] = malloc(sizeof(base_path) + sizeof(padkey) + midsz + namelen + 2); |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
592 memcpy(conf_keys[i], base_path, sizeof(base_path)); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
593 memcpy(conf_keys[i] + sizeof(base_path), padkey, sizeof(padkey)); |
1606
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
594 memcpy(conf_keys[i] + sizeof(base_path) + sizeof(padkey), mid, midsz); |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
595 |
1606
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
596 memcpy(conf_keys[i] + sizeof(base_path) + sizeof(padkey) + midsz, but_name, namelen+1); |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
597 conf_keys[i][sizeof(base_path) + sizeof(padkey) + sizeof(buttons) + namelen + 1] = 0; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
598 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
599 if (!labels[i]) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
600 skipped++; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
601 continue; |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
602 } |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
603 float lb_width = font->width(font->userdata, font->height, labels[i], strlen(labels[i])); |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
604 max_width = max_width < lb_width ? lb_width : max_width; |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
605 } |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
606 nk_layout_space_push(context, nk_rect(x, y, width, (num_binds - skipped) * (row_height + 4) + 4)); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
607 nk_group_begin(context, name, NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
608 |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
609 float widths[] = {max_width + 3, width - (max_width + 6)}; |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
610 nk_layout_row(context, NK_STATIC, row_height, 2, widths); |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
611 for (int i = 0; i < num_binds; i++) |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
612 { |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
613 if (!labels[i]) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
614 continue; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
615 } |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
616 nk_label(context, labels[i], NK_TEXT_LEFT); |
1606
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
617 if (conf_keys[i]) { |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
618 char *assigned = tern_find_path(config, conf_keys[i], TVAL_PTR).ptrval; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
619 if (!assigned) { |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
620 assigned = "None"; |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
621 } else if (!memcmp("gamepads.", assigned, strlen("gamepads."))) { |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
622 assigned += strlen("gamepads.0."); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
623 } |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
624 nk_button_label(context, assigned); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
625 } else { |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
626 nk_button_label(context, i & 1 ? "Internal Screenshot" : "A"); |
aa7533000161
Show current config value for controller butotn and axis mappings
Michael Pavone <pavone@retrodev.com>
parents:
1605
diff
changeset
|
627 } |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
628 free(conf_keys[i]); |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
629 } |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
630 nk_group_end(context); |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
631 } |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
632 |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
633 void view_controller_bindings(struct nk_context *context) |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
634 { |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
635 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
636 float orig_height = def_font->handle.height; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
637 def_font->handle.height *= 0.5f; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
638 |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
639 uint32_t avail_height = render_height() - 2 * orig_height; |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
640 float desired_width = render_width() * 0.5f, desired_height = avail_height * 0.5f; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
641 float controller_ratio = (float)controller_360_width / (float)controller_360_height; |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
642 |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
643 const struct nk_user_font *font = context->style.font; |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
644 int MIN_BIND_BOX_WIDTH = font->width(font->userdata, font->height, "Right", strlen("Right")) |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
645 + def_font->handle.width(font->userdata, font->height, "Internal Screenshot", strlen("Internal Screenshot")); |
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
646 |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
647 if (render_width() - desired_width < 2.5f*MIN_BIND_BOX_WIDTH) { |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
648 desired_width = render_width() - 2.5f*MIN_BIND_BOX_WIDTH; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
649 } |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
650 |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
651 if (desired_width / desired_height > controller_ratio) { |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
652 desired_width = desired_height * controller_ratio; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
653 } else { |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
654 desired_height = desired_width / controller_ratio; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
655 } |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
656 float img_left = render_width() / 2.0f - desired_width / 2.0f; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
657 float img_top = avail_height / 2.0f - desired_height / 2.0f; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
658 float img_right = img_left + desired_width; |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
659 float img_bot = img_top + desired_height; |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
660 nk_layout_space_begin(context, NK_STATIC, avail_height, INT_MAX); |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
661 nk_layout_space_push(context, nk_rect(img_left, img_top, desired_width, desired_height)); |
1570
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
662 nk_image(context, controller_360_image); |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
663 |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
664 float bind_box_width = (render_width() - img_right) * 0.8f; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
665 if (bind_box_width < MIN_BIND_BOX_WIDTH) { |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
666 bind_box_width = render_width() - img_right; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
667 if (bind_box_width > MIN_BIND_BOX_WIDTH) { |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
668 bind_box_width = MIN_BIND_BOX_WIDTH; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
669 } |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
670 } else if (bind_box_width > MAX_BIND_BOX_WIDTH) { |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
671 bind_box_width = MAX_BIND_BOX_WIDTH; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
672 } |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
673 float bind_box_left; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
674 if (bind_box_width >= (render_width() - img_right)) { |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
675 bind_box_left = img_right; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
676 } else { |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
677 bind_box_left = img_right + (render_width() - img_right) / 2.0f - bind_box_width / 2.0f; |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
678 } |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
679 |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
680 binding_box(context, "Action Buttons", bind_box_left, img_top, bind_box_width, 4, (int[]){ |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
681 SDL_CONTROLLER_BUTTON_A, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
682 SDL_CONTROLLER_BUTTON_B, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
683 SDL_CONTROLLER_BUTTON_X, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
684 SDL_CONTROLLER_BUTTON_Y |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
685 }); |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
686 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
687 binding_box(context, "Right Shoulder", bind_box_left, font->height/2, bind_box_width, 2, (int[]){ |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
688 SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
689 AXIS | SDL_CONTROLLER_AXIS_TRIGGERRIGHT |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
690 }); |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
691 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
692 binding_box(context, "Misc Buttons", (render_width() - bind_box_width) / 2, font->height/2, bind_box_width, 3, (int[]){ |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
693 SDL_CONTROLLER_BUTTON_BACK, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
694 SDL_CONTROLLER_BUTTON_GUIDE, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
695 SDL_CONTROLLER_BUTTON_START |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
696 }); |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
697 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
698 binding_box(context, "Right Stick", img_right - desired_width/3, img_bot, bind_box_width, 5, (int[]){ |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
699 RIGHTSTICK | UP, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
700 RIGHTSTICK | DOWN, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
701 RIGHTSTICK | LEFT, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
702 RIGHTSTICK | RIGHT, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
703 SDL_CONTROLLER_BUTTON_RIGHTSTICK |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
704 }); |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
705 |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
706 |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
707 bind_box_left -= img_right; |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
708 binding_box(context, "Left Stick", bind_box_left, img_top, bind_box_width, 5, (int[]){ |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
709 LEFTSTICK | UP, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
710 LEFTSTICK | DOWN, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
711 LEFTSTICK | LEFT, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
712 LEFTSTICK | RIGHT, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
713 SDL_CONTROLLER_BUTTON_LEFTSTICK |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
714 }); |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
715 |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
716 binding_box(context, "Left Shoulder", bind_box_left, font->height/2, bind_box_width, 2, (int[]){ |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
717 SDL_CONTROLLER_BUTTON_LEFTSHOULDER, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
718 AXIS | SDL_CONTROLLER_AXIS_TRIGGERLEFT |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
719 }); |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
720 |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
721 binding_box(context, "D-pad", img_left - desired_width/6, img_bot + font->height * 1.5, bind_box_width, 4, (int[]){ |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
722 SDL_CONTROLLER_BUTTON_DPAD_UP, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
723 SDL_CONTROLLER_BUTTON_DPAD_DOWN, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
724 SDL_CONTROLLER_BUTTON_DPAD_LEFT, |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
725 SDL_CONTROLLER_BUTTON_DPAD_RIGHT |
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
726 }); |
1571
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
727 |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
728 nk_layout_space_end(context); |
3def7b216a5b
WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents:
1570
diff
changeset
|
729 |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
730 def_font->handle.height = orig_height; |
1598
5e2af89c3467
Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents:
1596
diff
changeset
|
731 nk_layout_row_static(context, orig_height + 4, (render_width() - 2*orig_height) / 4, 1); |
1545
3faf917bab56
Add back button to Key binding view and add a window and back button to empty controller view so you can always get back to the main menu
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
732 if (nk_button_label(context, "Back")) { |
3faf917bab56
Add back button to Key binding view and add a window and back button to empty controller view so you can always get back to the main menu
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
733 pop_view(); |
3faf917bab56
Add back button to Key binding view and add a window and back button to empty controller view so you can always get back to the main menu
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
734 } |
3faf917bab56
Add back button to Key binding view and add a window and back button to empty controller view so you can always get back to the main menu
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
735 nk_end(context); |
3faf917bab56
Add back button to Key binding view and add a window and back button to empty controller view so you can always get back to the main menu
Michael Pavone <pavone@retrodev.com>
parents:
1527
diff
changeset
|
736 } |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
737 } |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
738 |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
739 static int current_button; |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
740 static int current_axis; |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
741 static int button_pressed, last_button; |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
742 static int hat_moved, hat_value, last_hat, last_hat_value; |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
743 static int axis_moved, axis_value, last_axis; |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
744 static char *mapping_string; |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
745 static size_t mapping_pos; |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
746 |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
747 static void start_mapping(void) |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
748 { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
749 const char *name; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
750 mapping_string[mapping_pos++] = ','; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
751 if (current_button != SDL_CONTROLLER_BUTTON_MAX) { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
752 name = SDL_GameControllerGetStringForButton(current_button); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
753 } else { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
754 name = SDL_GameControllerGetStringForAxis(current_axis); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
755 } |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
756 size_t namesz = strlen(name); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
757 memcpy(mapping_string + mapping_pos, name, namesz); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
758 mapping_pos += namesz; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
759 mapping_string[mapping_pos++] = ':'; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
760 } |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
761 |
1605
f7b1d983d5c0
Bump up pause between mapping inputs
Michael Pavone <pavone@retrodev.com>
parents:
1604
diff
changeset
|
762 #define QUIET_FRAMES 9 |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
763 static void view_controller_mappings(struct nk_context *context) |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
764 { |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
765 char buffer[512]; |
1602
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
766 static int quiet; |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
767 uint8_t added_mapping = 0; |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
768 if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
769 nk_layout_row_static(context, render_height() - context->style.font->height, render_width() - context->style.font->height, 1); |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
770 if (current_button < SDL_CONTROLLER_BUTTON_MAX) { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
771 snprintf(buffer, sizeof(buffer), "Press Button %s", get_button_label(&selected_controller_info, current_button)); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
772 } else { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
773 snprintf(buffer, sizeof(buffer), "Move Axis %s", get_axis_label(&selected_controller_info, current_axis)); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
774 } |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
775 nk_label(context, buffer, NK_TEXT_CENTERED); |
1602
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
776 if (quiet) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
777 --quiet; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
778 } else { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
779 if (button_pressed >= 0 && button_pressed != last_button) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
780 start_mapping(); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
781 mapping_string[mapping_pos++] = 'b'; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
782 if (button_pressed > 9) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
783 mapping_string[mapping_pos++] = '0' + button_pressed / 10; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
784 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
785 mapping_string[mapping_pos++] = '0' + button_pressed % 10; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
786 added_mapping = 1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
787 last_button = button_pressed; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
788 } else if (hat_moved >= 0 && hat_value && (hat_moved != last_hat || hat_value != last_hat_value)) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
789 start_mapping(); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
790 mapping_string[mapping_pos++] = 'h'; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
791 mapping_string[mapping_pos++] = '0' + hat_moved; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
792 mapping_string[mapping_pos++] = '.'; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
793 mapping_string[mapping_pos++] = '0' + hat_value; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
794 added_mapping = 1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
795 |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
796 last_hat = hat_moved; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
797 last_hat_value = hat_value; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
798 } else if (axis_moved >= 0 && abs(axis_value) > 1000 && axis_moved != last_axis) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
799 start_mapping(); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
800 mapping_string[mapping_pos++] = 'a'; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
801 if (axis_moved > 9) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
802 mapping_string[mapping_pos++] = '0' + axis_moved / 10; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
803 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
804 mapping_string[mapping_pos++] = '0' + axis_moved % 10; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
805 added_mapping = 1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
806 last_axis = axis_moved; |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
807 } |
1602
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
808 } |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
809 |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
810 if (added_mapping) { |
1602
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
811 quiet = QUIET_FRAMES; |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
812 if (current_button < SDL_CONTROLLER_BUTTON_MAX) { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
813 current_button++; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
814 if (current_button == SDL_CONTROLLER_BUTTON_MAX) { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
815 current_axis = 0; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
816 } |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
817 } else { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
818 current_axis++; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
819 if (current_axis == SDL_CONTROLLER_AXIS_MAX) { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
820 mapping_string[mapping_pos] = 0; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
821 save_controller_mapping(selected_controller, mapping_string); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
822 free(mapping_string); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
823 pop_view(); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
824 push_view(view_controller_bindings); |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
825 } |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
826 } |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
827 } |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
828 button_pressed = -1; |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
829 hat_moved = -1; |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
830 axis_moved = -1; |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
831 nk_end(context); |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
832 } |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
833 } |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
834 |
1602
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
835 static void view_controller_variant(struct nk_context *context) |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
836 { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
837 uint8_t selected = 0; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
838 if (nk_begin(context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 0)) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
839 nk_layout_row_static(context, context->style.font->height*1.25, render_width() - context->style.font->height * 2, 1); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
840 nk_label(context, "", NK_TEXT_CENTERED); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
841 nk_label(context, "Select the layout that", NK_TEXT_CENTERED); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
842 nk_label(context, "best matches your controller", NK_TEXT_CENTERED); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
843 nk_label(context, "", NK_TEXT_CENTERED); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
844 if (nk_button_label(context, "4 face buttons")) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
845 selected_controller_info.variant = VARIANT_NORMAL; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
846 selected = 1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
847 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
848 char buffer[512]; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
849 snprintf(buffer, sizeof(buffer), "6 face buttons including %s and %s", |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
850 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
851 get_axis_label(&selected_controller_info, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
852 ); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
853 if (nk_button_label(context, buffer)) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
854 selected_controller_info.variant = VARIANT_6B_RIGHT; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
855 selected = 1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
856 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
857 snprintf(buffer, sizeof(buffer), "6 face buttons including %s and %s", |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
858 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_LEFTSHOULDER), |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
859 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
860 ); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
861 if (nk_button_label(context, buffer)) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
862 selected_controller_info.variant = VARIANT_6B_BUMPERS; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
863 selected = 1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
864 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
865 nk_end(context); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
866 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
867 if (selected) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
868 save_controller_info(selected_controller, &selected_controller_info); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
869 pop_view(); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
870 SDL_GameController *controller = render_get_controller(selected_controller); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
871 if (controller) { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
872 push_view(view_controller_bindings); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
873 SDL_GameControllerClose(controller); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
874 } else { |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
875 current_button = SDL_CONTROLLER_BUTTON_A; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
876 button_pressed = -1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
877 last_button = -1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
878 last_hat = -1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
879 axis_moved = -1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
880 last_axis = -1; |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
881 SDL_Joystick *joy = render_get_joystick(selected_controller); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
882 const char *name = SDL_JoystickName(joy); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
883 size_t namesz = strlen(name); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
884 mapping_string = malloc(512 + namesz); |
1604
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1602
diff
changeset
|
885 for (mapping_pos = 0; mapping_pos < namesz; mapping_pos++) |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1602
diff
changeset
|
886 { |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1602
diff
changeset
|
887 char c = name[mapping_pos]; |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1602
diff
changeset
|
888 if (c == ',' || c == '\n' || c == '\r') { |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1602
diff
changeset
|
889 c = ' '; |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1602
diff
changeset
|
890 } |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1602
diff
changeset
|
891 mapping_string[mapping_pos] = c; |
68b05322d971
Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
Michael Pavone <pavone@retrodev.com>
parents:
1602
diff
changeset
|
892 } |
1602
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
893 |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
894 push_view(view_controller_mappings); |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
895 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
896 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
897 } |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
898 |
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
899 static void controller_type_group(struct nk_context *context, char *name, int type_id, int first_subtype_id, const char **types, uint32_t num_types) |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
900 { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
901 nk_layout_row_static(context, (context->style.font->height + 3) * num_types + context->style.font->height, render_width() - 80, 1); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
902 if (nk_group_begin(context, name, NK_WINDOW_TITLE)) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
903 nk_layout_row_static(context, context->style.font->height, render_width()/2 - 80, 2); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
904 for (int i = 0; i < num_types; i++) |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
905 { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
906 if (nk_button_label(context, types[i])) { |
1602
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
907 selected_controller_info.type = type_id; |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
908 selected_controller_info.subtype = first_subtype_id + i; |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
909 pop_view(); |
1602
b452887f85b4
Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents:
1601
diff
changeset
|
910 push_view(view_controller_variant); |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
911 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
912 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
913 nk_group_end(context); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
914 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
915 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
916 |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
917 void view_controller_type(struct nk_context *context) |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
918 { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
919 if (nk_begin(context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 0)) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
920 controller_type_group(context, "Xbox", TYPE_XBOX, SUBTYPE_XBOX, (const char *[]){ |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
921 "Original", "Xbox 360", "Xbox One" |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
922 }, 3); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
923 controller_type_group(context, "Playstation", TYPE_PSX, SUBTYPE_PS3, (const char *[]){ |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
924 "PS3", "PS4" |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
925 }, 2); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
926 controller_type_group(context, "Sega", TYPE_SEGA, SUBTYPE_GENESIS, (const char *[]){ |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
927 "Genesis", "Saturn" |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
928 }, 2); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
929 controller_type_group(context, "Nintendo", TYPE_NINTENDO, SUBTYPE_WIIU, (const char *[]){ |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
930 "WiiU", "Switch" |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
931 }, 2); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
932 nk_end(context); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
933 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
934 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
935 |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
936 void view_controllers(struct nk_context *context) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
937 { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
938 if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
939 int height = (render_width() - 2*context->style.font->height) / MAX_JOYSTICKS; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
940 int image_width = height * controller_360_width / controller_360_height; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
941 for (int i = 0; i < MAX_JOYSTICKS; i++) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
942 { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
943 SDL_Joystick *joy = render_get_joystick(i); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
944 if (joy) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
945 controller_info info = get_controller_info(i); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
946 nk_layout_row_begin(context, NK_STATIC, height, 2); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
947 nk_layout_row_push(context, image_width); |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
948 if (info.type == TYPE_UNKNOWN || info.type == TYPE_GENERIC_MAPPING) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
949 nk_label(context, "?", NK_TEXT_CENTERED); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
950 } else { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
951 nk_image(context, controller_360_image); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
952 } |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
953 nk_layout_row_push(context, render_width() - image_width - 2 * context->style.font->height); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
954 if (nk_button_label(context, info.name)) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
955 selected_controller = i; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
956 selected_controller_info = info; |
1599
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
957 if (info.type == TYPE_UNKNOWN || info.type == TYPE_GENERIC_MAPPING) { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
958 push_view(view_controller_type); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
959 } else { |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
960 push_view(view_controller_bindings); |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
961 } |
1fc61c844ec5
Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents:
1598
diff
changeset
|
962 |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
963 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
964 nk_layout_row_end(context); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
965 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
966 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
967 nk_layout_row_static(context, context->style.font->height, (render_width() - 2 * context->style.font->height) / 2, 2); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
968 nk_label(context, "", NK_TEXT_LEFT); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
969 if (nk_button_label(context, "Back")) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
970 pop_view(); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
971 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
972 nk_end(context); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
973 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
974 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
975 |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
976 void settings_toggle(struct nk_context *context, char *label, char *path, uint8_t def) |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
977 { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
978 uint8_t curval = !strcmp("on", tern_find_path_default(config, path, (tern_val){.ptrval = def ? "on": "off"}, TVAL_PTR).ptrval); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
979 nk_label(context, label, NK_TEXT_LEFT); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
980 uint8_t newval = nk_check_label(context, "", curval); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
981 if (newval != curval) { |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
982 config_dirty = 1; |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
983 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(newval ? "on" : "off")}, TVAL_PTR); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
984 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
985 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
986 |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
987 void settings_int_input(struct nk_context *context, char *label, char *path, char *def) |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
988 { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
989 char buffer[12]; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
990 nk_label(context, label, NK_TEXT_LEFT); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
991 uint32_t curval; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
992 char *curstr = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
993 uint32_t len = strlen(curstr); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
994 if (len > 11) { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
995 len = 11; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
996 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
997 memcpy(buffer, curstr, len); |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1581
diff
changeset
|
998 memset(buffer+len, 0, sizeof(buffer)-len); |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
999 nk_edit_string(context, NK_EDIT_SIMPLE, buffer, &len, sizeof(buffer)-1, nk_filter_decimal); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1000 buffer[len] = 0; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1001 if (strcmp(buffer, curstr)) { |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1002 config_dirty = 1; |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1003 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1004 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1005 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1006 |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1007 void settings_int_property(struct nk_context *context, char *label, char *name, char *path, int def, int min, int max) |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1008 { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1009 char *curstr = tern_find_path(config, path, TVAL_PTR).ptrval; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1010 int curval = curstr ? atoi(curstr) : def; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1011 nk_label(context, label, NK_TEXT_LEFT); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1012 int val = curval; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1013 nk_property_int(context, name, min, &val, max, 1, 1.0f); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1014 if (val != curval) { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1015 char buffer[12]; |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1016 sprintf(buffer, "%d", val); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1017 config_dirty = 1; |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1018 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1019 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1020 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1021 |
1492
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1022 typedef struct { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1023 char *fragment; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1024 char *vertex; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1025 } shader_prog; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1026 |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1027 shader_prog *get_shader_progs(dir_entry *entries, size_t num_entries, shader_prog *progs, uint32_t *num_existing, uint32_t *storage) |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1028 { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1029 uint32_t num_progs = *num_existing; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1030 uint32_t prog_storage = *storage; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1031 uint32_t starting = num_progs; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1032 |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1033 for (uint32_t i = 0; i < num_entries; i++) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1034 if (entries[i].is_dir) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1035 continue; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1036 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1037 char *no_ext = basename_no_extension(entries[i].name); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1038 uint32_t len = strlen(no_ext); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1039 if (no_ext[len-1] == 'f' && no_ext[len-2] == '.') { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1040 uint8_t dupe = 0;; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1041 for (uint32_t j = 0; j < starting; j++) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1042 if (!strcmp(entries[i].name, progs[j].fragment)) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1043 dupe = 1; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1044 break; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1045 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1046 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1047 if (!dupe) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1048 if (num_progs == prog_storage) { |
1493
24f44f26b74d
Fix buffer overrun in video settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1492
diff
changeset
|
1049 prog_storage = prog_storage ? prog_storage*2 : 4; |
1492
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1050 progs = realloc(progs, sizeof(progs) * prog_storage); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1051 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1052 progs[num_progs].vertex = NULL; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1053 progs[num_progs++].fragment = strdup(entries[i].name); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1054 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1055 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1056 free(no_ext); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1057 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1058 |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1059 for (uint32_t i = 0; i < num_entries; i++) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1060 if (entries[i].is_dir) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1061 continue; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1062 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1063 char *no_ext = basename_no_extension(entries[i].name); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1064 uint32_t len = strlen(no_ext); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1065 if (no_ext[len-1] == 'v' && no_ext[len-2] == '.') { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1066 for (uint32_t j = 0; j < num_progs; j++) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1067 if (!strncmp(no_ext, progs[j].fragment, len-1) && progs[j].fragment[len-1] == 'f' && progs[j].fragment[len] == '.') { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1068 progs[j].vertex = strdup(entries[i].name); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1069 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1070 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1071 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1072 free(no_ext); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1073 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1074 free_dir_list(entries, num_entries); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1075 *num_existing = num_progs; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1076 *storage = prog_storage; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1077 return progs; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1078 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1079 |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1080 shader_prog *get_shader_list(uint32_t *num_out) |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1081 { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1082 char *shader_dir = path_append(get_config_dir(), "shaders"); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1083 size_t num_entries; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1084 dir_entry *entries = get_dir_list(shader_dir, &num_entries); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1085 free(shader_dir); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1086 shader_prog *progs; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1087 uint32_t num_progs = 0, prog_storage; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1088 if (num_entries) { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1089 progs = calloc(num_entries, sizeof(shader_prog)); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1090 prog_storage = num_entries; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1091 progs = get_shader_progs(entries, num_entries, progs, &num_progs, &prog_storage); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1092 } else { |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1093 progs = NULL; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1094 prog_storage = 0; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1095 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1096 shader_dir = path_append(get_exe_dir(), "shaders"); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1097 entries = get_dir_list(shader_dir, &num_entries); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1098 progs = get_shader_progs(entries, num_entries, progs, &num_progs, &prog_storage); |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1099 *num_out = num_progs; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1100 return progs; |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1101 } |
bdeb2a1d0385
Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1491
diff
changeset
|
1102 |
1499
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1103 int32_t find_match(const char **options, uint32_t num_options, char *path, char *def) |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1104 { |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1105 char *setting = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval; |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1106 int32_t selected = -1; |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1107 for (uint32_t i = 0; i < num_options; i++) |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1108 { |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1109 if (!strcmp(setting, options[i])) { |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1110 selected = i; |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1111 break; |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1112 } |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1113 } |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1114 if (selected == -1) { |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1115 for (uint32_t i = 0; i < num_options; i++) |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1116 { |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1117 if (!strcmp(def, options[i])) { |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1118 selected = i; |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1119 break; |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1120 } |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1121 } |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1122 } |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1123 return selected; |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1124 } |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1125 |
1500
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1126 int32_t settings_dropdown_ex(struct nk_context *context, char *label, const char **options, const char **opt_display, uint32_t num_options, int32_t current, char *path) |
1499
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1127 { |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1128 nk_label(context, label, NK_TEXT_LEFT); |
1500
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1129 int32_t next = nk_combo(context, opt_display, num_options, current, 30, nk_vec2(300, 300)); |
1499
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1130 if (next != current) { |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1131 config_dirty = 1; |
1499
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1132 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(options[next])}, TVAL_PTR); |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1133 } |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1134 return next; |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1135 } |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1136 |
1500
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1137 int32_t settings_dropdown(struct nk_context *context, char *label, const char **options, uint32_t num_options, int32_t current, char *path) |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1138 { |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1139 return settings_dropdown_ex(context, label, options, options, num_options, current, path); |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1140 } |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1141 |
1553
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1142 void view_video_settings(struct nk_context *context) |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1143 { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1144 const char *vsync_opts[] = {"on", "off", "tear"}; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1145 const char *vsync_opt_names[] = { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1146 "On", |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1147 "Off", |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1148 "On, tear if late" |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1149 }; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1150 const uint32_t num_vsync_opts = sizeof(vsync_opts)/sizeof(*vsync_opts); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1151 static shader_prog *progs; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1152 static char **prog_names; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1153 static uint32_t num_progs; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1154 static uint32_t selected_prog; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1155 static int32_t selected_vsync = -1; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1156 if (selected_vsync < 0) { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1157 selected_vsync = find_match(vsync_opts, num_vsync_opts, "video\0vsync\0", "off"); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1158 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1159 if(!progs) { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1160 progs = get_shader_list(&num_progs); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1161 prog_names = calloc(num_progs, sizeof(char*)); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1162 for (uint32_t i = 0; i < num_progs; i++) |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1163 { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1164 prog_names[i] = basename_no_extension(progs[i].fragment);; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1165 uint32_t len = strlen(prog_names[i]); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1166 if (len > 2) { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1167 prog_names[i][len-2] = 0; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1168 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1169 if (!progs[i].vertex) { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1170 progs[i].vertex = strdup("default.v.glsl"); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1171 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1172 if (!strcmp( |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1173 progs[i].fragment, |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1174 tern_find_path_default(config, "video\0fragment_shader\0", (tern_val){.ptrval = "default.f.glsl"}, TVAL_PTR).ptrval |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1175 )) { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1176 selected_prog = i; |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1177 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1178 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1179 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1180 uint32_t width = render_width(); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1181 uint32_t height = render_height(); |
1577
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1182 uint32_t desired_width = context->style.font->height * 10; |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1183 if (desired_width > width) { |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1184 desired_width = width; |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1185 } |
1553
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1186 if (nk_begin(context, "Video Settings", nk_rect(0, 0, width, height), 0)) { |
1577
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1187 nk_layout_row_static(context, context->style.font->height, desired_width, 2); |
1553
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1188 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1189 settings_toggle(context, "Open GL", "video\0gl\0", 1); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1190 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1191 selected_vsync = settings_dropdown_ex(context, "VSync", vsync_opts, vsync_opt_names, num_vsync_opts, selected_vsync, "video\0vsync\0"); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1192 settings_int_input(context, "Windowed Width", "video\0width\0", "640"); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1193 nk_label(context, "Shader", NK_TEXT_LEFT); |
1577
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1194 uint32_t next_selected = nk_combo(context, (const char **)prog_names, num_progs, selected_prog, context->style.font->height, nk_vec2(desired_width, desired_width)); |
1553
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1195 if (next_selected != selected_prog) { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1196 selected_prog = next_selected; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1197 config_dirty = 1; |
1553
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1198 config = tern_insert_path(config, "video\0fragment_shader\0", (tern_val){.ptrval = strdup(progs[next_selected].fragment)}, TVAL_PTR); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1199 config = tern_insert_path(config, "video\0vertex_shader\0", (tern_val){.ptrval = strdup(progs[next_selected].vertex)}, TVAL_PTR); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1200 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1201 settings_int_property(context, "NTSC Overscan", "Top", "video\0ntsc\0overscan\0top\0", 2, 0, 32); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1202 settings_int_property(context, "", "Bottom", "video\0ntsc\0overscan\0bottom\0", 17, 0, 32); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1203 settings_int_property(context, "", "Left", "video\0ntsc\0overscan\0left\0", 13, 0, 32); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1204 settings_int_property(context, "", "Right", "video\0ntsc\0overscan\0right\0", 14, 0, 32); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1205 settings_int_property(context, "PAL Overscan", "Top", "video\0pal\0overscan\0top\0", 2, 0, 32); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1206 settings_int_property(context, "", "Bottom", "video\0pal\0overscan\0bottom\0", 17, 0, 32); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1207 settings_int_property(context, "", "Left", "video\0pal\0overscan\0left\0", 13, 0, 32); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1208 settings_int_property(context, "", "Right", "video\0pal\0overscan\0right\0", 14, 0, 32); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1209 |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1210 if (nk_button_label(context, "Back")) { |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1211 pop_view(); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1212 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1213 nk_end(context); |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1214 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1215 } |
723c00950f41
Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents:
1549
diff
changeset
|
1216 |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1217 void view_audio_settings(struct nk_context *context) |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1218 { |
1494
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1219 const char *rates[] = { |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1220 "192000", |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1221 "96000", |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1222 "48000", |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1223 "44100", |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1224 "22050" |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1225 }; |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1226 const char *sizes[] = { |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1227 "1024", |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1228 "512", |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1229 "256", |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1230 "128", |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1231 "64" |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1232 }; |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1233 const uint32_t num_rates = sizeof(rates)/sizeof(*rates); |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1234 const uint32_t num_sizes = sizeof(sizes)/sizeof(*sizes); |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1235 static int32_t selected_rate = -1; |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1236 static int32_t selected_size = -1; |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1237 if (selected_rate < 0 || selected_size < 0) { |
1499
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1238 selected_rate = find_match(rates, num_rates, "autio\0rate\0", "48000"); |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1239 selected_size = find_match(sizes, num_sizes, "audio\0buffer\0", "512"); |
1494
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1240 } |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1241 uint32_t width = render_width(); |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1242 uint32_t height = render_height(); |
1578
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
1243 uint32_t desired_width = context->style.font->height * 10; |
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
1244 if (desired_width > width) { |
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
1245 desired_width = width; |
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
1246 } |
1494
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1247 if (nk_begin(context, "Audio Settings", nk_rect(0, 0, width, height), 0)) { |
1578
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
1248 nk_layout_row_static(context, context->style.font->height , desired_width, 2); |
1499
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1249 selected_rate = settings_dropdown(context, "Rate in Hz", rates, num_rates, selected_rate, "audio\0rate\0"); |
756f8616d1bf
Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents:
1498
diff
changeset
|
1250 selected_size = settings_dropdown(context, "Buffer Samples", sizes, num_sizes, selected_size, "audio\0buffer\0"); |
1494
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1251 settings_int_input(context, "Lowpass Cutoff Hz", "audio\0lowpass_cutoff\0", "3390"); |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1252 if (nk_button_label(context, "Back")) { |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1253 pop_view(); |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1254 } |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1255 nk_end(context); |
8be6ea919300
Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1493
diff
changeset
|
1256 } |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1257 } |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1258 void view_system_settings(struct nk_context *context) |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1259 { |
1568
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1260 const char *sync_opts[] = { |
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1261 "video", |
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1262 "audio" |
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1263 }; |
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1264 const uint32_t num_sync_opts = sizeof(sync_opts)/sizeof(*sync_opts); |
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1265 static int32_t selected_sync = -1; |
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1266 if (selected_sync < 0) { |
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1267 selected_sync = find_match(sync_opts, num_sync_opts, "system\0sync_source\0", "video"); |
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1268 } |
1500
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1269 const char *regions[] = { |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1270 "J - Japan", |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1271 "U - Americas", |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1272 "E - Europe" |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1273 }; |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1274 const char *region_codes[] = {"J", "U", "E"}; |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1275 const uint32_t num_regions = sizeof(regions)/sizeof(*regions); |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1276 static int32_t selected_region = -1; |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1277 if (selected_region < 0) { |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1278 selected_region = find_match(region_codes, num_regions, "system\0default_region\0", "U"); |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1279 } |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1280 const char *formats[] = { |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1281 "native", |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1282 "gst" |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1283 }; |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1284 const uint32_t num_formats = sizeof(formats)/sizeof(*formats); |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1285 int32_t selected_format = -1; |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1286 if (selected_format < 0) { |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1287 selected_format = find_match(formats, num_formats, "ui\0state_format\0", "native"); |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1288 } |
1501
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1289 const char *ram_inits[] = { |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1290 "zero", |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1291 "random" |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1292 }; |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1293 const uint32_t num_inits = sizeof(ram_inits)/sizeof(*ram_inits); |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1294 static int32_t selected_init = -1; |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1295 if (selected_init < 0) { |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1296 selected_init = find_match(ram_inits, num_inits, "system\0ram_init\0", "zero"); |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1297 } |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1298 const char *io_opts_1[] = { |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1299 "gamepad2.1", |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1300 "gamepad3.1", |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1301 "gamepad6.1", |
1575
ccb3a8ae7ad0
Fix config value set when "Mega Mouse" is selected in settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
1302 "mouse.1", |
1501
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1303 "saturn keyboard", |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1304 "xband keyboard" |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1305 }; |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1306 const char *io_opts_2[] = { |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1307 "gamepad2.2", |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1308 "gamepad3.2", |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1309 "gamepad6.2", |
1575
ccb3a8ae7ad0
Fix config value set when "Mega Mouse" is selected in settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
1310 "mouse.1", |
1501
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1311 "saturn keyboard", |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1312 "xband keyboard" |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1313 }; |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1314 static int32_t selected_io_1 = -1; |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1315 static int32_t selected_io_2 = -1; |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1316 const uint32_t num_io = sizeof(io_opts_1)/sizeof(*io_opts_1); |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1317 if (selected_io_1 < 0 || selected_io_2 < 0) { |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1318 selected_io_1 = find_match(io_opts_1, num_io, "io\0devices\0""1\0", "gamepad6.1"); |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1319 selected_io_2 = find_match(io_opts_2, num_io, "io\0devices\0""2\0", "gamepad6.2"); |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1320 } |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1321 |
1498
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1322 uint32_t width = render_width(); |
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1323 uint32_t height = render_height(); |
1578
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
1324 uint32_t desired_width = context->style.font->height * 10; |
1498
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1325 if (nk_begin(context, "System Settings", nk_rect(0, 0, width, height), 0)) { |
1578
aaa28c9bf67d
Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents:
1577
diff
changeset
|
1326 nk_layout_row_static(context, context->style.font->height, desired_width, 2); |
1568
d14490dee01f
Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1554
diff
changeset
|
1327 selected_sync = settings_dropdown(context, "Sync Source", sync_opts, num_sync_opts, selected_sync, "system\0sync_source\0"); |
1498
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1328 settings_int_property(context, "68000 Clock Divider", "", "clocks\0m68k_divider\0", 7, 1, 53); |
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1329 settings_toggle(context, "Remember ROM Path", "ui\0remember_path\0", 1); |
1500
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1330 selected_region = settings_dropdown_ex(context, "Default Region", region_codes, regions, num_regions, selected_region, "system\0default_region\0"); |
39a199dca772
Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1499
diff
changeset
|
1331 selected_format = settings_dropdown(context, "Save State Format", formats, num_formats, selected_format, "ui\0state_format\0"); |
1501
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1332 selected_init = settings_dropdown(context, "Initial RAM Value", ram_inits, num_inits, selected_init, "system\0ram_init\0"); |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1333 selected_io_1 = settings_dropdown_ex(context, "IO Port 1 Device", io_opts_1, device_type_names, num_io, selected_io_1, "io\0devices\0""1\0"); |
31a2997b745e
Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1500
diff
changeset
|
1334 selected_io_2 = settings_dropdown_ex(context, "IO Port 2 Device", io_opts_2, device_type_names, num_io, selected_io_2, "io\0devices\0""2\0"); |
1498
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1335 if (nk_button_label(context, "Back")) { |
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1336 pop_view(); |
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1337 } |
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1338 nk_end(context); |
050a5b032bc5
Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents:
1494
diff
changeset
|
1339 } |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1340 } |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1341 |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1342 void view_back(struct nk_context *context) |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1343 { |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1344 pop_view(); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1345 pop_view(); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1346 current_view(context); |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1347 } |
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1348 |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1349 void view_settings(struct nk_context *context) |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1350 { |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1351 static menu_item items[] = { |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1352 {"Key Bindings", view_key_bindings}, |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1353 {"Controllers", view_controllers}, |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1354 {"Video", view_video_settings}, |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1355 {"Audio", view_audio_settings}, |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1356 {"System", view_system_settings}, |
1491
e890971f3757
Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents:
1490
diff
changeset
|
1357 {"Back", view_back} |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1358 }; |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1359 |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1360 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1361 menu(context, sizeof(items)/sizeof(*items), items); |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1362 nk_end(context); |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1363 } |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1364 } |
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1365 |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1366 void view_pause(struct nk_context *context) |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1367 { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1368 static menu_item items[] = { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1369 {"Resume", view_play}, |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1370 {"Load ROM", view_load}, |
1487
6a35815cc409
Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1486
diff
changeset
|
1371 {"Lock On", view_lock_on}, |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1372 {"Save State", view_save_state}, |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1373 {"Load State", view_load_state}, |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1374 {"Settings", view_settings}, |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1375 {"Exit", NULL} |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1376 }; |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1377 |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1378 if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1379 menu(context, sizeof(items)/sizeof(*items), items); |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1380 nk_end(context); |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1381 } |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1382 } |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1383 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1384 void view_menu(struct nk_context *context) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1385 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1386 static menu_item items[] = { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1387 {"Load ROM", view_load}, |
1490
919c0c33885e
Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents:
1487
diff
changeset
|
1388 {"Settings", view_settings}, |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1389 {"About", view_about}, |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1390 {"Exit", NULL} |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1391 }; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1392 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1393 if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1394 menu(context, sizeof(items)/sizeof(*items), items); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1395 nk_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1396 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1397 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1398 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1399 void blastem_nuklear_render(void) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1400 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1401 nk_input_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1402 current_view(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1403 nk_sdl_render(NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1404 nk_input_begin(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1405 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1406 |
1486
a6881d0d76d0
Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents:
1485
diff
changeset
|
1407 void ui_idle_loop(void) |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1408 { |
1482
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
1409 const uint32_t MIN_UI_DELAY = 15; |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
1410 static uint32_t last; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1411 while (current_view != view_play) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1412 { |
1482
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
1413 uint32_t current = render_elapsed_ms(); |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
1414 if ((current - last) < MIN_UI_DELAY) { |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
1415 render_sleep_ms(MIN_UI_DELAY - (current - last) - 1); |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
1416 } |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1481
diff
changeset
|
1417 last = current; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1418 render_update_display(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1419 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1420 if (config_dirty) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1421 apply_updated_config(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1422 persist_config(config); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1423 config_dirty = 0; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1424 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1425 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1426 static void handle_event(SDL_Event *event) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1427 { |
1522
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
1428 if (event->type == SDL_KEYDOWN) { |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
1429 keycode = event->key.keysym.sym; |
63659fb92db4
Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents:
1521
diff
changeset
|
1430 } |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
1431 else if (event->type == SDL_JOYBUTTONDOWN) { |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
1432 button_pressed = event->jbutton.button; |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
1433 } |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
1434 else if (event->type == SDL_JOYHATMOTION) { |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1435 hat_moved = event->jhat.hat; |
1600
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
1436 hat_value = event->jhat.value; |
7f39c40b4b25
WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents:
1599
diff
changeset
|
1437 } |
1601
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1438 else if (event->type == SDL_JOYAXISMOTION) { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1439 if (event->jaxis.axis == axis_moved || abs(event->jaxis.value) > abs(axis_value) || abs(event->jaxis.value) > 1000) { |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1440 axis_moved = event->jaxis.axis; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1441 axis_value = event->jaxis.value; |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1442 } |
da04dd9c89ad
SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1443 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1444 nk_sdl_handle_event(event); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1445 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1446 |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1447 static void context_destroyed(void) |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1448 { |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1449 nk_sdl_shutdown(); |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1450 } |
1570
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1451 |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1452 static uint32_t *controller_360_buf; |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1453 |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1454 static void texture_init(void) |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1455 { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1456 struct nk_font_atlas *atlas; |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1457 nk_sdl_font_stash_begin(&atlas); |
1527
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1526
diff
changeset
|
1458 uint32_t font_size; |
4f6e8acd7b6a
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
Michael Pavone <pavone@retrodev.com>
parents:
1526
diff
changeset
|
1459 uint8_t *font = default_font(&font_size); |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1460 if (!font) { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1461 fatal_error("Failed to find default font path\n"); |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1462 } |
1572
5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
Michael Pavone <pavone@retrodev.com>
parents:
1571
diff
changeset
|
1463 def_font = nk_font_atlas_add_from_memory(atlas, font, font_size, render_height() / 16, NULL); |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1581
diff
changeset
|
1464 free(font); |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1465 nk_sdl_font_stash_end(); |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1466 nk_style_set_font(context, &def_font->handle); |
1570
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1467 if (controller_360_buf) { |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1468 GLuint tex; |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1469 glGenTextures(1, &tex); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1470 glBindTexture(GL_TEXTURE_2D, tex); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1471 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1472 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1473 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1474 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1475 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, controller_360_width, controller_360_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, controller_360_buf); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1476 controller_360_image = nk_image_id((int)tex); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1477 } |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1478 } |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1479 |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1480 static void context_created(void) |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1481 { |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1572
diff
changeset
|
1482 context = nk_sdl_init(render_get_window()); |
1570
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1483 texture_init(); |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1484 } |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1485 |
1477
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1486 void show_pause_menu(void) |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1487 { |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1488 context->style.window.background = nk_rgba(0, 0, 0, 128); |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1489 context->style.window.fixed_background = nk_style_item_color(nk_rgba(0, 0, 0, 128)); |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1490 current_view = view_pause; |
1486
a6881d0d76d0
Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents:
1485
diff
changeset
|
1491 current_system->request_exit(current_system); |
1477
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1492 } |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1493 |
1581
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1579
diff
changeset
|
1494 void show_play_view(void) |
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1579
diff
changeset
|
1495 { |
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1579
diff
changeset
|
1496 current_view = view_play; |
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1579
diff
changeset
|
1497 } |
7121daaa48c2
Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1579
diff
changeset
|
1498 |
1477
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1499 static uint8_t active; |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1500 uint8_t is_nuklear_active(void) |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1501 { |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1502 return active; |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1503 } |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1504 |
1483
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1505 uint8_t is_nuklear_available(void) |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1506 { |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1507 if (!render_has_gl()) { |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1508 //currently no fallback if GL2 unavailable |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1509 return 0; |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1510 } |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1511 char *style = tern_find_path(config, "ui\0style\0", TVAL_PTR).ptrval; |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1512 if (!style) { |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1513 return 1; |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1514 } |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1515 return strcmp(style, "rom") != 0; |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1516 } |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1517 |
1577
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1518 static void persist_config_exit(void) |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1519 { |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1520 if (config_dirty) { |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1521 persist_config(config); |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1522 } |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1523 } |
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1524 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1525 void blastem_nuklear_init(uint8_t file_loaded) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1526 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1527 context = nk_sdl_init(render_get_window()); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1528 |
1570
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1529 uint32_t buf_size; |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1530 uint8_t *buf = (uint8_t *)read_bundled_file("images/360.png", &buf_size); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1531 if (buf) { |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1532 controller_360_buf = load_png(buf, buf_size, &controller_360_width, &controller_360_height); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1533 free(buf); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1534 } |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1535 texture_init(); |
bc96bb3a0998
Use read_bundle_file for controller PNG. Re-upload texture when GL context is recreated
Michael Pavone <pavone@retrodev.com>
parents:
1569
diff
changeset
|
1536 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1537 current_view = file_loaded ? view_play : view_menu; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1538 render_set_ui_render_fun(blastem_nuklear_render); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1539 render_set_event_handler(handle_event); |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
1540 render_set_gl_context_handlers(context_destroyed, context_created); |
1569
0ec89dadb36d
Add code for loading PNG images. Added 360 controller image. WIP work on gamepad mapping UI
Michael Pavone <pavone@retrodev.com>
parents:
1568
diff
changeset
|
1541 |
1577
69d624271cf8
Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1575
diff
changeset
|
1542 atexit(persist_config_exit); |
1569
0ec89dadb36d
Add code for loading PNG images. Added 360 controller image. WIP work on gamepad mapping UI
Michael Pavone <pavone@retrodev.com>
parents:
1568
diff
changeset
|
1543 |
1477
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1544 active = 1; |
1486
a6881d0d76d0
Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents:
1485
diff
changeset
|
1545 ui_idle_loop(); |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1546 } |