annotate nuklear_ui/blastem_nuklear.c @ 1811:af14c21939f6

Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
author Michael Pavone <pavone@retrodev.com>
date Wed, 27 Mar 2019 23:04:42 -0700
parents a218c253fcb3
children 8aeac7bd9fa7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
18 #include "../bindings.h"
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 static struct nk_context *context;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
22 typedef struct
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
23 {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
24 uint32_t *image_data;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
25 uint32_t width, height;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
26 struct nk_image ui;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
27 } ui_image;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
28
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
29 static ui_image **ui_images, *controller_360, *controller_ps4, *controller_ps4_6b;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
30 static uint32_t num_ui_images, ui_image_storage;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
31
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 typedef void (*view_fun)(struct nk_context *);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 static view_fun current_view;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
34 static view_fun *previous_views;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
35 static uint32_t view_storage;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
36 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
37 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
38 static uint8_t config_dirty;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
39
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
40 static void push_view(view_fun new_view)
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
41 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
42 if (num_prev == view_storage) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
43 view_storage = view_storage ? 2*view_storage : 2;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
44 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
45 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
46 previous_views[num_prev++] = current_view;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
47 current_view = new_view;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
48 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
49
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
50 static void pop_view()
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
51 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
52 if (num_prev) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
53 current_view = previous_views[--num_prev];
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
54 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
55 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
56
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
57 static void clear_view_stack()
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
58 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
59 num_prev = 0;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
60 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 void view_play(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
67 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
68 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 static char *current_path;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 static dir_entry *entries;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 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
72 static int32_t selected_entry = -1;
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
73 static char **ext_list;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
74 static uint32_t num_exts;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
75 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
76 if (!current_path) {
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
77 get_initial_browse_path(&current_path);
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
78 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 if (!entries) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 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
81 if (entries) {
d82af64c94d2 Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
82 sort_dir_list(entries, num_entries);
d82af64c94d2 Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
83 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 }
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
85 if (!got_ext_list) {
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
86 ext_list = get_extension_list(config, &num_exts);
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
87 got_ext_list = 1;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
88 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 uint32_t width = render_width();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 uint32_t height = render_height();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 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
92 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
93 int32_t old_selected = selected_entry;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 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
95 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
96 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
97 {
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
98 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
99 continue;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
100 }
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
101 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
102 continue;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
103 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 int selected = i == selected_entry;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 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
106 if (selected) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 selected_entry = i;
1554
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
108 } else if (i == selected_entry) {
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
109 selected_entry = -1;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 nk_group_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 }
1579
f66290afae65 Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents: 1578
diff changeset
114 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
115 if (nk_button_label(context, "Back")) {
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
116 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
117 }
1554
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
118 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
119 if (selected_entry < 0) {
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
120 selected_entry = old_selected;
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
121 }
1481
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
122 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
123 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
124 free(current_path);
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
125 current_path = full_path;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 free_dir_list(entries, num_entries);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 entries = NULL;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 } else {
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
129 if(normal_open) {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
130 if (current_system) {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
131 current_system->next_rom = full_path;
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
132 current_system->request_exit(current_system);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
133 } else {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
134 init_system_with_media(full_path, SYSTEM_UNKNOWN);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
135 free(full_path);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
136 }
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
137 } else {
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
138 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
139 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
140 }
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
141 clear_view_stack();
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
142 show_play_view();
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 }
1554
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
144 selected_entry = -1;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 nk_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
150 void view_load(struct nk_context *context)
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
151 {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
152 view_file_browser(context, 1);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
153 }
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
154
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
155 void view_lock_on(struct nk_context *context)
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
156 {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
157 view_file_browser(context, 0);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
158 }
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
159
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 void view_about(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 {
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
162 const char *lines[] = {
1675
357b4951d9b2 Updated version number and CHANGELOG for possible 0.6.1 release
Michael Pavone <pavone@retrodev.com>
parents: 1672
diff changeset
163 "BlastEm v0.6.1",
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
164 "Copyright 2012-2017 Michael Pavone",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
165 "",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
166 "BlastEm is a high performance open source",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
167 "(GPLv3) Genesis/Megadrive emulator",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
168 };
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
169 const uint32_t NUM_LINES = sizeof(lines)/sizeof(*lines);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
170 const char *thanks[] = {
1661
c3c3b65f17aa Updated special thanks
Mike Pavone <pavone@retrodev.com>
parents: 1660
diff changeset
171 "Nemesis: Documentation and test ROMs",
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
172 "Charles MacDonald: Documentation",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
173 "Eke-Eke: Documentation",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
174 "Bart Trzynadlowski: Documentation",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
175 "KanedaFR: Hosting the best Sega forum",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
176 "Titan: Awesome demos and documentation",
1661
c3c3b65f17aa Updated special thanks
Mike Pavone <pavone@retrodev.com>
parents: 1660
diff changeset
177 "flamewing: BCD info and test ROM",
c3c3b65f17aa Updated special thanks
Mike Pavone <pavone@retrodev.com>
parents: 1660
diff changeset
178 "r57shell: Opcode size test ROM",
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
179 "micky: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
180 "Sasha: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
181 "lol-frank: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
182 "Sik: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
183 "Tim Lawrence : Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
184 "ComradeOj: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
185 "Vladikcomper: Testing"
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
186 };
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
187 const uint32_t NUM_THANKS = sizeof(thanks)/sizeof(*thanks);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
188 uint32_t width = render_width();
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
189 uint32_t height = render_height();
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
190 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
191 nk_layout_row_static(context, context->style.font->height, width-40, 1);
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
192 for (uint32_t i = 0; i < NUM_LINES; i++)
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
193 {
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
194 nk_label(context, lines[i], NK_TEXT_LEFT);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
195 }
1579
f66290afae65 Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents: 1578
diff changeset
196 nk_layout_row_static(context, height - (context->style.font->height * 2 + 20) - (context->style.font->height +4)*NUM_LINES, width-40, 1);
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
197 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
198 nk_layout_row_static(context, context->style.font->height, width - 80, 1);
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
199 for (uint32_t i = 0; i < NUM_THANKS; i++)
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
200 {
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
201 nk_label(context, thanks[i], NK_TEXT_LEFT);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
202 }
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
203 nk_group_end(context);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
204 }
1579
f66290afae65 Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents: 1578
diff changeset
205 nk_layout_row_static(context, context->style.font->height * 1.75, width/3, 1);
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
206 if (nk_button_label(context, "Back")) {
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
207 pop_view();
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
208 }
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
209 nk_end(context);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
210 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 typedef struct {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 const char *title;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 view_fun next_view;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 } menu_item;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217
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
218 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
219 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
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 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
222 {
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 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 }
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 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
233 {
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 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
235 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
236 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
237 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
238 }
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 }
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 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
241 }
1579
f66290afae65 Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents: 1578
diff changeset
242 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
243 if (nk_button_label(context, "Back")) {
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
244 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
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 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
247 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
248 current_system->load_state(current_system, selected_slot);
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
249 show_play_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
250 }
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 } 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
252 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
253 current_system->save_state = selected_slot + 1;
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
254 show_play_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
255 }
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 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
258 }
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
259 }
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
260
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
261 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
262 {
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
263 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
264 }
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
265
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
266 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
267 {
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
268 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
269 }
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
270
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
271 typedef void (*menu_handler)(uint32_t index);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
272
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
273 static void menu(struct nk_context *context, uint32_t num_entries, const menu_item *items, menu_handler handler)
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
274 {
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
275 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
276 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
277 const uint32_t button_space = 6;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
278
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
279 uint32_t width = render_width();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
280 uint32_t height = render_height();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
281 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
282 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
283 uint32_t left = width/2 - button_width/2;
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_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
286 for (uint32_t i = 0; i < num_entries; i++)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
287 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
288 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
289 if (nk_button_label(context, items[i].title)) {
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
290 if (items[i].next_view) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
291 push_view(items[i].next_view);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
292 if (current_view == view_save_state || current_view == view_load_state) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
293 free_slot_info(slots);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
294 slots = NULL;
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
295 } else if (current_view == view_play) {
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
296 set_content_binding_state(1);
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
297 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
298 } else {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
299 handler(i);
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
300 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
301 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
302 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
303 nk_layout_space_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
304 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
305
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
306 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
307 {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
308 if (valtype != TVAL_PTR) {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
309 return;
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
310 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
311 tern_node **binding_lookup = data;
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
312 *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
313 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
314
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
315 static int32_t keycode;
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
316 static const char *set_binding;
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
317 char *set_label;
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
318 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
319 {
1578
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
320 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
321 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
322 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
323
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
324 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
325 {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
326 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
327 const char *label = label_alloc;
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
328 if (!label) {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
329 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
330 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
331 nk_label(context, label, NK_TEXT_LEFT);
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
332 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
333 set_binding = binds[i];
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
334 set_label = strdup(label);
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
335 keycode = 0;
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
336 }
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
337 if (label_alloc) {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
338 free(label_alloc);
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
339 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
340 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
341 nk_group_end(context);
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
342 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
343 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
344
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
345 static char *get_key_name(int32_t keycode)
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
346 {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
347 char *name = NULL;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
348 if (keycode > ' ' && keycode < 0x80) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
349 //key corresponds to a printable non-whitespace character
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
350 name = malloc(2);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
351 name[0] = keycode;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
352 name[1] = 0;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
353 } else {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
354 switch (keycode)
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
355 {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
356 case RENDERKEY_UP: name = "up"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
357 case RENDERKEY_DOWN: name = "down"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
358 case RENDERKEY_LEFT: name = "left"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
359 case RENDERKEY_RIGHT: name = "right"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
360 case '\r': name = "enter"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
361 case ' ': name = "space"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
362 case '\t': name = "tab"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
363 case '\b': name = "backspace"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
364 case RENDERKEY_ESC: name = "esc"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
365 case RENDERKEY_DEL: name = "delete"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
366 case RENDERKEY_LSHIFT: name = "lshift"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
367 case RENDERKEY_RSHIFT: name = "rshift"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
368 case RENDERKEY_LCTRL: name = "lctrl"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
369 case RENDERKEY_RCTRL: name = "rctrl"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
370 case RENDERKEY_LALT: name = "lalt"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
371 case RENDERKEY_RALT: name = "ralt"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
372 case RENDERKEY_HOME: name = "home"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
373 case RENDERKEY_END: name = "end"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
374 case RENDERKEY_PAGEUP: name = "pageup"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
375 case RENDERKEY_PAGEDOWN: name = "pagedown"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
376 case RENDERKEY_F1: name = "f1"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
377 case RENDERKEY_F2: name = "f2"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
378 case RENDERKEY_F3: name = "f3"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
379 case RENDERKEY_F4: name = "f4"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
380 case RENDERKEY_F5: name = "f5"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
381 case RENDERKEY_F6: name = "f6"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
382 case RENDERKEY_F7: name = "f7"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
383 case RENDERKEY_F8: name = "f8"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
384 case RENDERKEY_F9: name = "f9"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
385 case RENDERKEY_F10: name = "f10"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
386 case RENDERKEY_F11: name = "f11"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
387 case RENDERKEY_F12: name = "f12"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
388 case RENDERKEY_SELECT: name = "select"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
389 case RENDERKEY_PLAY: name = "play"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
390 case RENDERKEY_SEARCH: name = "search"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
391 case RENDERKEY_BACK: name = "back"; break;
1549
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
392 case RENDERKEY_NP0: name = "np0"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
393 case RENDERKEY_NP1: name = "np1"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
394 case RENDERKEY_NP2: name = "np2"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
395 case RENDERKEY_NP3: name = "np3"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
396 case RENDERKEY_NP4: name = "np4"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
397 case RENDERKEY_NP5: name = "np5"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
398 case RENDERKEY_NP6: name = "np6"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
399 case RENDERKEY_NP7: name = "np7"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
400 case RENDERKEY_NP8: name = "np8"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
401 case RENDERKEY_NP9: name = "np9"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
402 case RENDERKEY_NP_DIV: name = "np/"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
403 case RENDERKEY_NP_MUL: name = "np*"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
404 case RENDERKEY_NP_MIN: name = "np-"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
405 case RENDERKEY_NP_PLUS: name = "np+"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
406 case RENDERKEY_NP_ENTER: name = "npenter"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
407 case RENDERKEY_NP_STOP: name = "np."; break;
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
408 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
409 if (name) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
410 name = strdup(name);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
411 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
412 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
413 return name;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
414 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
415
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
416 void view_key_bindings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
417 {
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
418 const char *controller1_binds[] = {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
419 "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
420 "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
421 "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
422 "gamepads.1.start", "gamepads.1.mode"
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
423 };
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
424 const char *controller2_binds[] = {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
425 "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
426 "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
427 "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
428 "gamepads.2.start", "gamepads.2.mode"
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
429 };
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
430 const char *general_binds[] = {
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
431 "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
432 "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
433 };
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
434 const char *general_names[] = {
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
435 "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
436 "Internal Screenshot", "SMS Pause", "Capture Keyboard", "Release Mouse"
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
437 };
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
438 const char *speed_binds[] = {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
439 "ui.next_speed", "ui.prev_speed",
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
440 "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
441 "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
442 };
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
443 const char *speed_names[] = {
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
444 "Next", "Previous",
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
445 "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
446 "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
447 };
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
448 const char *debug_binds[] = {
1660
c6cc2dae262f Updated binding UI to reflect new VDP debug options
Mike Pavone <pavone@retrodev.com>
parents: 1658
diff changeset
449 "ui.enter_debugger", "ui.plane_debug", "ui.vram_debug", "ui.cram_debug",
c6cc2dae262f Updated binding UI to reflect new VDP debug options
Mike Pavone <pavone@retrodev.com>
parents: 1658
diff changeset
450 "ui.compositing_debug", "ui.vdp_debug_mode"
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
451 };
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
452 const char *debug_names[] = {
1660
c6cc2dae262f Updated binding UI to reflect new VDP debug options
Mike Pavone <pavone@retrodev.com>
parents: 1658
diff changeset
453 "CPU Debugger", "Plane Debugger", "VRAM Debugger", "CRAM Debugger",
c6cc2dae262f Updated binding UI to reflect new VDP debug options
Mike Pavone <pavone@retrodev.com>
parents: 1658
diff changeset
454 "Layer Debugger", "Cycle Mode/Pal"
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
455 };
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
456 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
457 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
458 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
459 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
460 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
461 static tern_node *binding_lookup;
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
462 if (!binding_lookup) {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
463 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
464 if (bindings) {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
465 tern_foreach(bindings, binding_loop, &binding_lookup);
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
466 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
467 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
468 uint32_t width = render_width();
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
469 uint32_t height = render_height();
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
470 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
471 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
472 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
473 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
474 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
475 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
476 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
477 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
478 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
479 }
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
480 nk_end(context);
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
481 }
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
482 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
483 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
484 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
485 nk_label(context, set_label, NK_TEXT_CENTERED);
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
486 if (nk_button_label(context, "Cancel")) {
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
487 free(set_label);
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
488 set_binding = set_label = NULL;
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
489 } else if (keycode) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
490 char *name = get_key_name(keycode);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
491 if (name) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
492 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
493 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
494 if (old) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
495 uint32_t suffix_len = strlen(old) + 1;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
496 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
497 memcpy(old_path, "bindings\0keys\0", prefix_len);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
498 memcpy(old_path + prefix_len, old, suffix_len);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
499 old_path[prefix_len + suffix_len] = 0;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
500 tern_val old_val;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
501 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
502 free(old_val.ptrval);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
503 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
504 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
505 uint32_t suffix_len = strlen(name) + 1;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
506 char *path = malloc(prefix_len + suffix_len + 1);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
507 memcpy(path, "bindings\0keys\0", prefix_len);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
508 memcpy(path + prefix_len, name, suffix_len);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
509 path[prefix_len + suffix_len] = 0;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
510
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
511 config_dirty = 1;
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
512 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
513 free(path);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
514 free(name);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
515 tern_free(binding_lookup);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
516 binding_lookup = NULL;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
517 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
518 free(set_label);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
519 set_binding = set_label = NULL;
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
520 }
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
521 nk_end(context);
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
522 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
523 }
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
524
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
525 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
526 static controller_info selected_controller_info;
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
527 //#define MIN_BIND_BOX_WIDTH 140
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
528 #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
529
5e2af89c3467 Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents: 1596
diff changeset
530 #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
531 #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
532 #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
533 #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
534 enum {
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
535 UP,DOWN,RIGHT,LEFT,NUM_AXIS_DIRS
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
536 };
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
537
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 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
539 [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
540 [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
541 [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
542 [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
543 [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
544 [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
545 [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
546 [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
547 [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
548 [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
549 };
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
550
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
551 typedef struct {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
552 const char *button_binds[SDL_CONTROLLER_BUTTON_MAX];
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
553 const char *left_stick[NUM_AXIS_DIRS];
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
554 const char *right_stick[NUM_AXIS_DIRS];
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
555 const char *triggers[2];
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
556 } pad_bind_config;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
557
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
558 static const char **current_bind_dest;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
559
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
560 const char *translate_binding_option(const char *option)
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
561 {
1625
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
562 static tern_node *conf_names;
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
563 if (!conf_names) {
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
564 conf_names = tern_insert_ptr(conf_names, "gamepads.n.up", "Pad Up");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
565 conf_names = tern_insert_ptr(conf_names, "gamepads.n.down", "Pad Down");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
566 conf_names = tern_insert_ptr(conf_names, "gamepads.n.left", "Pad Left");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
567 conf_names = tern_insert_ptr(conf_names, "gamepads.n.right", "Pad Right");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
568 conf_names = tern_insert_ptr(conf_names, "gamepads.n.a", "Pad A");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
569 conf_names = tern_insert_ptr(conf_names, "gamepads.n.b", "Pad B");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
570 conf_names = tern_insert_ptr(conf_names, "gamepads.n.c", "Pad C");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
571 conf_names = tern_insert_ptr(conf_names, "gamepads.n.x", "Pad X");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
572 conf_names = tern_insert_ptr(conf_names, "gamepads.n.y", "Pad Y");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
573 conf_names = tern_insert_ptr(conf_names, "gamepads.n.z", "Pad Z");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
574 conf_names = tern_insert_ptr(conf_names, "gamepads.n.start", "Pad Start");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
575 conf_names = tern_insert_ptr(conf_names, "gamepads.n.mode", "Pad Mode");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
576 conf_names = tern_insert_ptr(conf_names, "ui.release_mouse", "Release Mouse");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
577 conf_names = tern_insert_ptr(conf_names, "ui.vdp_debug_mode", "VDP Debug Mode");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
578 conf_names = tern_insert_ptr(conf_names, "ui.vdp_debug_pal", "VDP Debug Palette");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
579 conf_names = tern_insert_ptr(conf_names, "ui.enter_debugger", "Enter CPU Debugger");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
580 conf_names = tern_insert_ptr(conf_names, "ui.screenshot", "Take Screenshot");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
581 conf_names = tern_insert_ptr(conf_names, "ui.exit", "Show Menu");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
582 conf_names = tern_insert_ptr(conf_names, "ui.save_state", "Quick Save");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
583 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.0", "Set Speed 0");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
584 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.1", "Set Speed 1");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
585 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.2", "Set Speed 2");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
586 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.3", "Set Speed 3");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
587 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.4", "Set Speed 4");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
588 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.5", "Set Speed 5");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
589 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.6", "Set Speed 6");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
590 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.7", "Set Speed 7");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
591 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.8", "Set Speed 8");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
592 conf_names = tern_insert_ptr(conf_names, "ui.set_speed.9", "Set Speed 9");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
593 conf_names = tern_insert_ptr(conf_names, "ui.next_speed", "Next Speed");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
594 conf_names = tern_insert_ptr(conf_names, "ui.prev_speed", "Prev. Speed");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
595 conf_names = tern_insert_ptr(conf_names, "ui.toggle_fullscreen", "Toggle Fullscreen");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
596 conf_names = tern_insert_ptr(conf_names, "ui.soft_reset", "Soft Reset");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
597 conf_names = tern_insert_ptr(conf_names, "ui.reload", "Reload ROM");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
598 conf_names = tern_insert_ptr(conf_names, "ui.sms_pause", "SMS Pause");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
599 conf_names = tern_insert_ptr(conf_names, "ui.toggle_keyboard_captured", "Toggle Keyboard Capture");
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
600 }
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
601 return tern_find_ptr_default(conf_names, option, (void *)option);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
602 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
603
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
604 static uint8_t controller_binding_changed;
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
605 static void bind_option_group(struct nk_context *context, char *name, const char **options, uint32_t num_options)
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
606 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
607 float margin = context->style.font->height * 2;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
608 nk_layout_row_static(context, (context->style.font->height + 3) * ((num_options + 2) / 3) + context->style.font->height*2.1, render_width() - margin, 1);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
609 if (nk_group_begin(context, name, NK_WINDOW_TITLE|NK_WINDOW_NO_SCROLLBAR)) {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
610 nk_layout_row_static(context, context->style.font->height, (render_width() - margin - context->style.font->height) / 3, 3);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
611 for (int i = 0; i < num_options; i++)
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
612 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
613 if (nk_button_label(context, translate_binding_option(options[i]))) {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
614 *current_bind_dest = options[i];
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
615 controller_binding_changed = 1;
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
616 pop_view();
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
617 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
618 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
619 nk_group_end(context);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
620 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
621 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
622
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
623 static void view_button_binding(struct nk_context *context)
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
624 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
625 static const char *pad_opts[] = {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
626 "gamepads.n.up",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
627 "gamepads.n.down",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
628 "gamepads.n.left",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
629 "gamepads.n.right",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
630 "gamepads.n.a",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
631 "gamepads.n.b",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
632 "gamepads.n.c",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
633 "gamepads.n.x",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
634 "gamepads.n.y",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
635 "gamepads.n.z",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
636 "gamepads.n.start",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
637 "gamepads.n.mode"
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
638 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
639 static const char *system_buttons[] = {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
640 "ui.soft_reset",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
641 "ui.reload",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
642 "ui.sms_pause"
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
643 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
644 static const char *emu_control[] = {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
645 "ui.save_state",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
646 "ui.exit",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
647 "ui.toggle_fullscreen",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
648 "ui.screenshot",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
649 "ui.release_mouse",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
650 "ui.toggle_keyboard_captured"
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
651 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
652 static const char *debugger[] = {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
653 "ui.vdp_debug_mode",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
654 "ui.vdp_debug_pal",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
655 "ui.enter_debugger"
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
656 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
657 static const char *speeds[] = {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
658 "ui.next_speed",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
659 "ui.prev_speed",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
660 "ui.set_speed.0",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
661 "ui.set_speed.1",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
662 "ui.set_speed.2",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
663 "ui.set_speed.3",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
664 "ui.set_speed.4",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
665 "ui.set_speed.5",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
666 "ui.set_speed.6",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
667 "ui.set_speed.7",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
668 "ui.set_speed.8",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
669 "ui.set_speed.9"
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
670 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
671
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
672 if (nk_begin(context, "Button Binding", nk_rect(0, 0, render_width(), render_height()), 0)) {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
673 bind_option_group(context, "Controller Buttons", pad_opts, sizeof(pad_opts)/sizeof(*pad_opts));
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
674 bind_option_group(context, "System Buttons", system_buttons, sizeof(system_buttons)/sizeof(*system_buttons));
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
675 bind_option_group(context, "Emulator Control", emu_control, sizeof(emu_control)/sizeof(*emu_control));
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
676 bind_option_group(context, "Debugging", debugger, sizeof(debugger)/sizeof(*debugger));
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
677 bind_option_group(context, "Speed Control", speeds, sizeof(speeds)/sizeof(*speeds));
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
678
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
679 nk_layout_row_static(context, context->style.font->height, (render_width() - 80)/4, 1);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
680 if (nk_button_label(context, "Back")) {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
681 pop_view();
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
682 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
683 nk_end(context);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
684 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
685 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
686
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
687 static void binding_box(struct nk_context *context, pad_bind_config *bindings, char *name, float x, float y, float width, int num_binds, int *binds)
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
688 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
689 const struct nk_user_font *font = context->style.font;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
690 float row_height = font->height * 2;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
691
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
692 char const **labels = calloc(sizeof(char *), num_binds);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
693 char const ***conf_vals = calloc(sizeof(char *), num_binds);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
694 float max_width = 0.0f;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
695
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
696 int skipped = 0;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
697 for (int i = 0; i < num_binds; i++)
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
698 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
699 if (binds[i] & AXIS) {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
700 labels[i] = get_axis_label(&selected_controller_info, binds[i] & ~AXIS);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
701 conf_vals[i] = &bindings->triggers[(binds[i] & ~AXIS) - SDL_CONTROLLER_AXIS_TRIGGERLEFT];
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
702 } else if (binds[i] & STICKDIR) {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
703 static char const * dirs[] = {"Up", "Down", "Right", "Left"};
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
704 labels[i] = dirs[binds[i] & 3];
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
705 conf_vals[i] = &(binds[i] & LEFTSTICK ? bindings->left_stick : bindings->right_stick)[binds[i] & 3];
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
706 } else {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
707 labels[i] = get_button_label(&selected_controller_info, binds[i]);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
708 conf_vals[i] = &bindings->button_binds[binds[i]];
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
709 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
710 if (!labels[i]) {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
711 skipped++;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
712 continue;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
713 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
714 float lb_width = font->width(font->userdata, font->height, labels[i], strlen(labels[i]));
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
715 max_width = max_width < lb_width ? lb_width : max_width;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
716 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
717 nk_layout_space_push(context, nk_rect(x, y, width, (num_binds - skipped) * (row_height + 4) + 4));
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
718 nk_group_begin(context, name, NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR);
1625
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
719
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
720 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
721 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
722 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
723 {
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
724 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
725 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
726 }
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
727 nk_label(context, labels[i], NK_TEXT_LEFT);
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
728 const char *name = *conf_vals[i] ? translate_binding_option(*conf_vals[i]) : "None";
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
729 if (nk_button_label(context, name)) {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
730 current_bind_dest = conf_vals[i];
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
731 push_view(view_button_binding);
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
732 }
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
733 }
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
734 free(labels);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
735 free(conf_vals);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
736 nk_group_end(context);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
737 }
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
738
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
739 static void button_iter(char *key, tern_val val, uint8_t valtype, void *data)
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
740 {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
741 pad_bind_config *bindings = data;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
742 if (valtype != TVAL_PTR) {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
743 return;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
744 }
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
745 int button = render_lookup_button(key);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
746 if (button != SDL_CONTROLLER_BUTTON_INVALID) {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
747 bindings->button_binds[button] = val.ptrval;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
748 }
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
749 }
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
750
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
751 static void axis_iter(char *key, tern_val val, uint8_t valtype, void *data)
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
752 {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
753 pad_bind_config *bindings = data;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
754 if (valtype != TVAL_PTR) {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
755 return;
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
756 }
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
757 int axis;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
758 uint8_t is_negative = 0;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
759 char *period = strchr(key, '.');
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
760 if (period) {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
761 char *tmp = malloc(period-key + 1);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
762 memcpy(tmp, key, period-key);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
763 tmp[period-key] = 0;
1624
7bbe0bfedb58 Handle looking up dpad config in binding UI. Fix left/right stick config display in binding UI
Michael Pavone <pavone@retrodev.com>
parents: 1623
diff changeset
764 axis = render_lookup_axis(tmp);
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
765 free(tmp);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
766 is_negative = strcmp(period+1, "negative") == 0;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
767 } else {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
768 axis = render_lookup_axis(key);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
769 }
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
770 switch (axis)
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
771 {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
772 case SDL_CONTROLLER_AXIS_LEFTX:
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
773 case SDL_CONTROLLER_AXIS_LEFTY:
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
774 bindings->left_stick[(axis - SDL_CONTROLLER_AXIS_LEFTX) * 2 + is_negative] = val.ptrval;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
775 break;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
776 case SDL_CONTROLLER_AXIS_RIGHTX:
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
777 case SDL_CONTROLLER_AXIS_RIGHTY:
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
778 bindings->right_stick[(axis - SDL_CONTROLLER_AXIS_RIGHTX) * 2 + is_negative] = val.ptrval;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
779 break;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
780 case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
781 case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
782 bindings->triggers[axis-SDL_CONTROLLER_AXIS_TRIGGERLEFT] = val.ptrval;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
783 break;
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
784 }
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
785 }
5e2af89c3467 Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents: 1596
diff changeset
786
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
787 enum {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
788 SIMILAR_CONTROLLERS,
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
789 IDENTICAL_CONTROLLERS,
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
790 BY_INDEX,
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
791 DEFAULT,
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
792 NUM_DEST_TYPES
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
793 };
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
794
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
795 //it would be cleaner to generate this algorithmically for 4th and up,
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
796 //but BlastEm only supports 8 controllers currently so it's not worth the effort
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
797 static const char *by_index_names[] = {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
798 "Use for 1st controller",
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
799 "Use for 2nd controller",
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
800 "Use for 3rd controller",
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
801 "Use for 4th controller",
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
802 "Use for 5th controller",
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
803 "Use for 6th controller",
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
804 "Use for 7th controller",
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
805 "Use for 8th controller",
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
806 };
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
807
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
808 static void save_stick_binds(char *axes_key, size_t axes_key_size, const char **bindings, char *prefix)
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
809 {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
810 for (int i = 0; i < NUM_AXIS_DIRS; i++)
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
811 {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
812 char axis = (i / 2) ? 'x' : 'y';
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
813 char *suffix = (i % 2) ? ".negative" : ".positive";
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
814 size_t prefix_len = strlen(prefix), suffix_len = strlen(suffix);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
815 size_t full_key_size = axes_key_size + prefix_len + 1 + suffix_len + 2;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
816 char *full_key = malloc(full_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
817 memcpy(full_key, axes_key, axes_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
818 memcpy(full_key + axes_key_size, prefix, prefix_len);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
819 full_key[axes_key_size+prefix_len] = axis;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
820 memcpy(full_key + axes_key_size + prefix_len + 1, suffix, suffix_len +1);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
821 full_key[axes_key_size + prefix_len + 1 + suffix_len + 1] = 0;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
822
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
823 if (bindings[i]) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
824 tern_insert_path(config, full_key, (tern_val){.ptrval = strdup(bindings[i])}, TVAL_PTR);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
825 } else {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
826 tern_val prev_val;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
827 uint8_t prev_type = tern_delete_path(&config, full_key, &prev_val);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
828 if (prev_type == TVAL_PTR) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
829 free(prev_val.ptrval);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
830 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
831 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
832
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
833 free(full_key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
834 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
835 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
836
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
837 static pad_bind_config *bindings;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
838 static void handle_dest_clicked(uint32_t dest)
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
839 {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
840 char key_buf[12];
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
841 char *key;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
842 switch (dest)
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
843 {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
844 case SIMILAR_CONTROLLERS:
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
845 key = make_controller_type_key(&selected_controller_info);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
846 break;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
847 case IDENTICAL_CONTROLLERS:
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
848 key = render_joystick_type_id(selected_controller);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
849 break;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
850 case BY_INDEX:
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
851 snprintf(key_buf, sizeof(key_buf), "%d", selected_controller);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
852 key = key_buf;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
853 break;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
854 default:
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
855 key = "default";
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
856 break;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
857 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
858 static const char base_path[] = "bindings\0pads";
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
859 size_t pad_key_size = sizeof(base_path) + strlen(key) + 1;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
860 char *pad_key = malloc(pad_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
861 memcpy(pad_key, base_path, sizeof(base_path));
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
862 strcpy(pad_key + sizeof(base_path), key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
863 static const char dpad_base[] = "dpads\0""0";
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
864 size_t dpad_key_size = pad_key_size + sizeof(dpad_base);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
865 char *dpad_key = malloc(dpad_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
866 memcpy(dpad_key, pad_key, pad_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
867 memcpy(dpad_key + pad_key_size, dpad_base, sizeof(dpad_base));
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
868 static const char button_base[] = "buttons";
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
869 size_t button_key_size = pad_key_size + sizeof(button_base);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
870 char *button_key = malloc(button_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
871 memcpy(button_key, pad_key, pad_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
872 memcpy(button_key + pad_key_size, button_base, sizeof(button_base));
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
873
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
874 char *final_key;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
875 for (int i = 0; i < SDL_CONTROLLER_BUTTON_MAX; i++)
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
876 {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
877 char *base;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
878 const char *suffix;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
879 size_t base_key_len;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
880 if ( i < SDL_CONTROLLER_BUTTON_DPAD_UP) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
881 suffix = SDL_GameControllerGetStringForButton(i);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
882 base_key_len = button_key_size;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
883 base = button_key;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
884
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
885
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
886 } else {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
887 static const char *dir_keys[] = {"up", "down", "left", "right"};
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
888 suffix = dir_keys[i - SDL_CONTROLLER_BUTTON_DPAD_UP];
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
889 base = dpad_key;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
890 base_key_len = dpad_key_size;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
891 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
892 size_t suffix_len = strlen(suffix);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
893 final_key = malloc(base_key_len + suffix_len + 2);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
894 memcpy(final_key, base, base_key_len);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
895 memcpy(final_key + base_key_len, suffix, suffix_len + 1);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
896 final_key[base_key_len + suffix_len + 1] = 0;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
897 if (bindings->button_binds[i]) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
898 tern_insert_path(config, final_key, (tern_val){.ptrval = strdup(bindings->button_binds[i])}, TVAL_PTR);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
899 } else {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
900 tern_val prev_val;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
901 uint8_t prev_type = tern_delete_path(&config, final_key, &prev_val);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
902 if (prev_type == TVAL_PTR) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
903 free(prev_val.ptrval);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
904 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
905 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
906 free(final_key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
907 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
908 free(button_key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
909 free(dpad_key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
910
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
911 static const char axes_base[] = "axes";
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
912 size_t axes_key_size = pad_key_size + sizeof(axes_base);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
913 char *axes_key = malloc(axes_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
914 memcpy(axes_key, pad_key, pad_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
915 memcpy(axes_key + pad_key_size, axes_base, sizeof(axes_base));
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
916
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
917 save_stick_binds(axes_key, axes_key_size,bindings->left_stick, "left");
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
918 save_stick_binds(axes_key, axes_key_size,bindings->right_stick, "right");
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
919 for (int i = SDL_CONTROLLER_AXIS_TRIGGERLEFT; i < SDL_CONTROLLER_AXIS_MAX; i++)
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
920 {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
921 const char *suffix = SDL_GameControllerGetStringForAxis(i);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
922 size_t suffix_len = strlen(suffix);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
923 final_key = malloc(axes_key_size + suffix_len + 2);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
924 memcpy(final_key, axes_key, axes_key_size);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
925 memcpy(final_key + axes_key_size, suffix, suffix_len + 1);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
926 final_key[axes_key_size + suffix_len + 1] = 0;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
927 if (bindings->triggers[i - SDL_CONTROLLER_AXIS_TRIGGERLEFT]) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
928 tern_insert_path(config, final_key, (tern_val){.ptrval = strdup(bindings->triggers[i - SDL_CONTROLLER_AXIS_TRIGGERLEFT])}, TVAL_PTR);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
929 } else {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
930 tern_val prev_val;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
931 uint8_t prev_type = tern_delete_path(&config, final_key, &prev_val);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
932 if (prev_type == TVAL_PTR) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
933 free(prev_val.ptrval);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
934 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
935 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
936 free(final_key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
937 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
938 free(axes_key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
939
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
940 free(pad_key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
941 if (dest == SIMILAR_CONTROLLERS) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
942 free(key);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
943 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
944 pop_view();
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
945 config_dirty = 1;
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
946 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
947
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
948 void view_select_binding_dest(struct nk_context *context)
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
949 {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
950 static menu_item options[NUM_DEST_TYPES];
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
951 options[IDENTICAL_CONTROLLERS].title = "Use for identical controllers";
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
952 options[DEFAULT].title = "Use as default";
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
953 options[BY_INDEX].title = by_index_names[selected_controller];
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
954 options[SIMILAR_CONTROLLERS].title = make_human_readable_type_name(&selected_controller_info);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
955
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
956 if (nk_begin(context, "Select Binding Dest", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
957 menu(context, NUM_DEST_TYPES, options, handle_dest_clicked);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
958 nk_end(context);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
959 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
960 free((char *)options[SIMILAR_CONTROLLERS].title);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
961 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
962
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
963 static ui_image *select_best_image(controller_info *info)
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
964 {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
965 if (info->variant != VARIANT_NORMAL) {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
966 return controller_ps4_6b;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
967 } else if (info->type == TYPE_PSX) {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
968 return controller_ps4;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
969 } else {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
970 return controller_360;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
971 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
972 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
973
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
974 void view_controller_bindings(struct nk_context *context)
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
975 {
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
976 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
977 if (!bindings) {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
978 bindings = calloc(1, sizeof(*bindings));
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
979 tern_node *pad = get_binding_node_for_pad(selected_controller);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
980 if (pad) {
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
981 tern_foreach(tern_find_node(pad, "buttons"), button_iter, bindings);
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
982 tern_foreach(tern_find_node(pad, "axes"), axis_iter, bindings);
1624
7bbe0bfedb58 Handle looking up dpad config in binding UI. Fix left/right stick config display in binding UI
Michael Pavone <pavone@retrodev.com>
parents: 1623
diff changeset
983 tern_node *dpad = tern_find_path(pad, "dpads\0" "0\0", TVAL_NODE).ptrval;
7bbe0bfedb58 Handle looking up dpad config in binding UI. Fix left/right stick config display in binding UI
Michael Pavone <pavone@retrodev.com>
parents: 1623
diff changeset
984 const char *dir_keys[] = {"up", "down", "right", "left"};
7bbe0bfedb58 Handle looking up dpad config in binding UI. Fix left/right stick config display in binding UI
Michael Pavone <pavone@retrodev.com>
parents: 1623
diff changeset
985 const int button_idx[] = {SDL_CONTROLLER_BUTTON_DPAD_UP, SDL_CONTROLLER_BUTTON_DPAD_DOWN, SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_LEFT};
7bbe0bfedb58 Handle looking up dpad config in binding UI. Fix left/right stick config display in binding UI
Michael Pavone <pavone@retrodev.com>
parents: 1623
diff changeset
986 for (int i = 0; i < NUM_AXIS_DIRS; i++)
7bbe0bfedb58 Handle looking up dpad config in binding UI. Fix left/right stick config display in binding UI
Michael Pavone <pavone@retrodev.com>
parents: 1623
diff changeset
987 {
7bbe0bfedb58 Handle looking up dpad config in binding UI. Fix left/right stick config display in binding UI
Michael Pavone <pavone@retrodev.com>
parents: 1623
diff changeset
988 bindings->button_binds[button_idx[i]] = tern_find_ptr(dpad, dir_keys[i]);
7bbe0bfedb58 Handle looking up dpad config in binding UI. Fix left/right stick config display in binding UI
Michael Pavone <pavone@retrodev.com>
parents: 1623
diff changeset
989 }
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
990 }
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
991 }
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
992
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
993 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
994 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
995
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
996 uint32_t avail_height = render_height() - 2 * orig_height;
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
997 float desired_width = render_width() * 0.5f, desired_height = avail_height * 0.5f;
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
998 ui_image *controller_image = select_best_image(&selected_controller_info);
1609
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
999
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1000 float controller_ratio = (float)controller_image->width / (float)controller_image->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
1001
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
1002 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
1003 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
1004 + 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
1005
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1006 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
1007 desired_width = render_width() - 2.5f*MIN_BIND_BOX_WIDTH;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1008 }
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1009
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1010 if (desired_width / desired_height > controller_ratio) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1011 desired_width = desired_height * controller_ratio;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1012 } else {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1013 desired_height = desired_width / controller_ratio;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1014 }
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1015 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
1016 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
1017 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
1018 float img_bot = img_top + desired_height;
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1019 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
1020 nk_layout_space_push(context, nk_rect(img_left, img_top, desired_width, desired_height));
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1021 nk_image(context, controller_image->ui);
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1022
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1023 float bind_box_width = (render_width() - img_right) * 0.8f;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1024 if (bind_box_width < MIN_BIND_BOX_WIDTH) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1025 bind_box_width = render_width() - img_right;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1026 if (bind_box_width > MIN_BIND_BOX_WIDTH) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1027 bind_box_width = MIN_BIND_BOX_WIDTH;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1028 }
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1029 } else if (bind_box_width > MAX_BIND_BOX_WIDTH) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1030 bind_box_width = MAX_BIND_BOX_WIDTH;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1031 }
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1032 float bind_box_left;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1033 if (bind_box_width >= (render_width() - img_right)) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1034 bind_box_left = img_right;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1035 } else {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1036 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
1037 }
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1038
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1039 if (selected_controller_info.variant == VARIANT_NORMAL) {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1040 binding_box(context, bindings, "Action Buttons", bind_box_left, img_top, bind_box_width, 4, (int[]){
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1041 SDL_CONTROLLER_BUTTON_A,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1042 SDL_CONTROLLER_BUTTON_B,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1043 SDL_CONTROLLER_BUTTON_X,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1044 SDL_CONTROLLER_BUTTON_Y
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1045 });
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1046 } else {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1047 binding_box(context, bindings, "Action Buttons", bind_box_left, img_top, bind_box_width, 6, (int[]){
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1048 SDL_CONTROLLER_BUTTON_A,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1049 SDL_CONTROLLER_BUTTON_B,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1050 selected_controller_info.variant == VARIANT_6B_RIGHT ? AXIS | SDL_CONTROLLER_AXIS_TRIGGERRIGHT : SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1051 SDL_CONTROLLER_BUTTON_X,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1052 SDL_CONTROLLER_BUTTON_Y,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1053 selected_controller_info.variant == VARIANT_6B_RIGHT ? SDL_CONTROLLER_BUTTON_RIGHTSHOULDER : SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1054 });
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1055 }
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
1056
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1057 binding_box(context, bindings, "Right Shoulder", bind_box_left, font->height/2, bind_box_width,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1058 selected_controller_info.variant == VARIANT_6B_BUMPERS ? 1 : 2,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1059 (int[]){
1807
a218c253fcb3 Fixed contents of left and right shoulder boxes for VARIANT_6B_BUMPER controllers
Michael Pavone <pavone@retrodev.com>
parents: 1806
diff changeset
1060 selected_controller_info.variant == VARIANT_6B_RIGHT ? SDL_CONTROLLER_BUTTON_LEFTSHOULDER : AXIS | SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
1664
cc5107def372 Fix binding UI for "6 button right" style controllers
Mike Pavone <pavone@retrodev.com>
parents: 1661
diff changeset
1061 AXIS | SDL_CONTROLLER_AXIS_TRIGGERLEFT
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
1062 });
5e2af89c3467 Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents: 1596
diff changeset
1063
1623
18a946ec74c8 Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents: 1609
diff changeset
1064 binding_box(context, bindings, "Misc Buttons", (render_width() - bind_box_width) / 2, font->height/2, bind_box_width, 3, (int[]){
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
1065 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
1066 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
1067 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
1068 });
5e2af89c3467 Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents: 1596
diff changeset
1069
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1070 if (selected_controller_info.variant == VARIANT_NORMAL)
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1071 {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1072 binding_box(context, bindings, "Right Stick", img_right - desired_width/3, img_bot, bind_box_width, 5, (int[]){
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1073 RIGHTSTICK | UP,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1074 RIGHTSTICK | DOWN,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1075 RIGHTSTICK | LEFT,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1076 RIGHTSTICK | RIGHT,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1077 SDL_CONTROLLER_BUTTON_RIGHTSTICK
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1078 });
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1079 }
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1080
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1081 bind_box_left -= img_right;
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1082 float dpad_left, dpad_top;
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1083 if (selected_controller_info.variant == VARIANT_NORMAL)
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1084 {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1085 binding_box(context, bindings, "Left Stick", bind_box_left, img_top, bind_box_width, 5, (int[]){
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1086 LEFTSTICK | UP,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1087 LEFTSTICK | DOWN,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1088 LEFTSTICK | LEFT,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1089 LEFTSTICK | RIGHT,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1090 SDL_CONTROLLER_BUTTON_LEFTSTICK
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1091 });
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1092 dpad_left = img_left - desired_width/6;
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1093 dpad_top = img_bot + font->height * 1.5;
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1094 } else {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1095 dpad_left = bind_box_left;
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1096 dpad_top = img_top;
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1097 }
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1098
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1099 binding_box(context, bindings, "Left Shoulder", bind_box_left, font->height/2, bind_box_width,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1100 selected_controller_info.variant == VARIANT_6B_BUMPERS ? 1 : 2,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1101 (int[]){
1807
a218c253fcb3 Fixed contents of left and right shoulder boxes for VARIANT_6B_BUMPER controllers
Michael Pavone <pavone@retrodev.com>
parents: 1806
diff changeset
1102 selected_controller_info.variant == VARIANT_6B_RIGHT ? SDL_CONTROLLER_BUTTON_LEFTSTICK : AXIS | SDL_CONTROLLER_AXIS_TRIGGERLEFT,
1664
cc5107def372 Fix binding UI for "6 button right" style controllers
Mike Pavone <pavone@retrodev.com>
parents: 1661
diff changeset
1103 SDL_CONTROLLER_BUTTON_RIGHTSTICK
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
1104 });
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1105
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1106 binding_box(context, bindings, "D-pad", dpad_left, dpad_top, bind_box_width, 4, (int[]){
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
1107 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
1108 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
1109 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
1110 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
1111 });
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1112
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1113 nk_layout_space_end(context);
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1114
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
1115 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
1116 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
1117 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
1118 pop_view();
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1119 if (controller_binding_changed) {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1120 push_view(view_select_binding_dest);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1121 }
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
1122 }
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
1123 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
1124 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1125 }
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1126
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
1127 static int current_button;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1128 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
1129 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
1130 static int hat_moved, hat_value, last_hat, last_hat_value;
1804
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1131 static int axis_moved, axis_value, last_axis, last_axis_value;
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
1132 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
1133 static size_t mapping_pos;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1134
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1135 static void start_mapping(void)
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1136 {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1137 const char *name;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1138 mapping_string[mapping_pos++] = ',';
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1139 if (current_button != SDL_CONTROLLER_BUTTON_MAX) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1140 name = SDL_GameControllerGetStringForButton(current_button);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1141 } else {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1142 name = SDL_GameControllerGetStringForAxis(current_axis);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1143 }
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1144 size_t namesz = strlen(name);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1145 memcpy(mapping_string + mapping_pos, name, namesz);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1146 mapping_pos += namesz;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1147 mapping_string[mapping_pos++] = ':';
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1148 }
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1149
1605
f7b1d983d5c0 Bump up pause between mapping inputs
Michael Pavone <pavone@retrodev.com>
parents: 1604
diff changeset
1150 #define QUIET_FRAMES 9
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1151 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
1152 {
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1153 char buffer[512];
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1154 static int quiet, button_a = -1, button_a_axis = -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
1155 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
1156 if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1157
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1158 nk_layout_space_begin(context, NK_STATIC, render_height() - context->style.font->height, 3);
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1159
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1160 if (current_button < SDL_CONTROLLER_BUTTON_MAX) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1161 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
1162 } else {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1163 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
1164 }
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1165
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1166 float height = context->style.font->height * 1.25;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1167 float top = render_height()/2 - 1.5 * height;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1168 float width = render_width() - context->style.font->height;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1169
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1170 nk_layout_space_push(context, nk_rect(0, top, width, height));
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
1171 nk_label(context, buffer, NK_TEXT_CENTERED);
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1172 if (current_button > SDL_CONTROLLER_BUTTON_B) {
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1173 nk_layout_space_push(context, nk_rect(0, top + height, width, height));
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1174 nk_label(context, "OR", NK_TEXT_CENTERED);
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1175
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1176 nk_layout_space_push(context, nk_rect(0, top + 2.0 * height, width, height));
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1177 snprintf(buffer, sizeof(buffer), "Press Button %s to skip", get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_A));
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1178 nk_label(context, buffer, NK_TEXT_CENTERED);
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1179 }
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1180
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1181 nk_layout_space_end(context);
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1182 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
1183 --quiet;
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1184 } else {
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1185 if (button_pressed >= 0 && button_pressed != last_button) {
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1186 if (current_button <= SDL_CONTROLLER_BUTTON_B || button_pressed != button_a) {
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1187 start_mapping();
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1188 mapping_string[mapping_pos++] = 'b';
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1189 if (button_pressed > 9) {
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1190 mapping_string[mapping_pos++] = '0' + button_pressed / 10;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1191 }
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1192 mapping_string[mapping_pos++] = '0' + button_pressed % 10;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1193 last_button = button_pressed;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1194 if (current_button == SDL_CONTROLLER_BUTTON_A) {
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1195 button_a = button_pressed;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1196 }
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1197 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1198 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
1199 } 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
1200 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
1201 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
1202 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
1203 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
1204 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
1205 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
1206
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1207 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
1208 last_hat_value = hat_value;
1804
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1209 } else if (axis_moved >= 0 && abs(axis_value) > 1000 && (
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1210 axis_moved != last_axis || (
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1211 axis_value/abs(axis_value) != last_axis_value/abs(axis_value) && current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1212 )
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1213 )) {
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1214 if (current_button <= SDL_CONTROLLER_BUTTON_B || axis_moved != button_a_axis) {
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1215 start_mapping();
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1216 mapping_string[mapping_pos++] = 'a';
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1217 if (axis_moved > 9) {
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1218 mapping_string[mapping_pos++] = '0' + axis_moved / 10;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1219 }
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1220 mapping_string[mapping_pos++] = '0' + axis_moved % 10;
1804
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1221 if (current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP) {
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1222 mapping_string[mapping_pos++] = axis_value >= 0 ? '+' : '-';
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1223 }
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1224 last_axis = axis_moved;
1804
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1225 last_axis_value = axis_value;
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1226 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1227 added_mapping = 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
1228 }
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1229 }
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
1230
1806
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1231 while (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
1232 quiet = QUIET_FRAMES;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1233 if (current_button < SDL_CONTROLLER_BUTTON_MAX) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1234 current_button++;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1235 if (current_button == SDL_CONTROLLER_BUTTON_MAX) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1236 current_axis = 0;
1806
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1237 if (get_axis_label(&selected_controller_info, current_axis)) {
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1238 added_mapping = 0;
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1239 }
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1240 } else if (get_button_label(&selected_controller_info, current_button)) {
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1241 added_mapping = 0;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1242 }
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1243 } else {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1244 current_axis++;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1245 if (current_axis == SDL_CONTROLLER_AXIS_MAX) {
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1246 button_a = -1;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1247 button_a_axis = -1;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1248 mapping_string[mapping_pos] = 0;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1249 save_controller_mapping(selected_controller, mapping_string);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1250 free(mapping_string);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1251 pop_view();
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1252 push_view(view_controller_bindings);
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1253 controller_binding_changed = 0;
1806
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1254 added_mapping = 0;
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1255 } else if (get_axis_label(&selected_controller_info, current_axis)) {
396369ab481a Skip buttons or axes in the mapping UI that have no label for the selected controller type
Michael Pavone <pavone@retrodev.com>
parents: 1804
diff changeset
1256 added_mapping = 0;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1257 }
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
1258 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1259 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1260 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
1261 hat_moved = -1;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1262 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
1263 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
1264 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1265 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1266
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1267 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
1268 {
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1269 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
1270 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
1271 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
1272 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
1273 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
1274 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
1275 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
1276 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
1277 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
1278 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
1279 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1280 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
1281 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
1282 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
1283 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
1284 );
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1285 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
1286 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
1287 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
1288 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1289 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
1290 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
1291 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
1292 );
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1293 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
1294 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
1295 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
1296 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1297 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
1298 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1299 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
1300 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
1301 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
1302 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
1303 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
1304 push_view(view_controller_bindings);
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1305 controller_binding_changed = 0;
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1306 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
1307 } else {
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1308 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
1309 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
1310 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
1311 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
1312 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
1313 last_axis = -1;
1804
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1314 last_axis_value = 0;
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1315 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
1316 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
1317 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
1318 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
1319 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
1320 {
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
1321 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
1322 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
1323 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
1324 }
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
1325 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
1326 }
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1327
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1328 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
1329 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1330 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1331 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1332
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1333 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
1334 {
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
1335 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
1336 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
1337 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
1338 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
1339 {
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
1340 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
1341 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
1342 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
1343 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
1344 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
1345 }
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
1346 }
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
1347 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
1348 }
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
1349 }
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
1350
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
1351 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
1352 {
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
1353 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
1354 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
1355 "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
1356 }, 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
1357 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
1358 "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
1359 }, 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
1360 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
1361 "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
1362 }, 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
1363 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
1364 "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
1365 }, 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
1366 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
1367 }
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
1368 }
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
1369
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
1370 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
1371 {
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
1372 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
1373 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
1374 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
1375 {
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
1376 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
1377 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
1378 controller_info info = get_controller_info(i);
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1379 ui_image *controller_image = select_best_image(&info);
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1380 int image_width = height * controller_image->width / controller_image->height;
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
1381 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
1382 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
1383 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
1384 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
1385 } else {
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1386 nk_image(context, controller_image->ui);
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
1387 }
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
1388 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
1389 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
1390 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
1391 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
1392 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
1393 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
1394 } 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
1395 push_view(view_controller_bindings);
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1396 controller_binding_changed = 0;
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
1397 }
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
1398
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
1399 }
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
1400 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
1401 }
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
1402 }
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
1403 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
1404 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
1405 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
1406 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
1407 }
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
1408 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
1409 }
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
1410 }
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
1411
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1412 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
1413 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1414 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
1415 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1416 uint8_t newval = nk_check_label(context, "", curval);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1417 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
1418 config_dirty = 1;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1419 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
1420 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1421 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1422
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1423 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
1424 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1425 char buffer[12];
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1426 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1427 uint32_t curval;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1428 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
1429 uint32_t len = strlen(curstr);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1430 if (len > 11) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1431 len = 11;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1432 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1433 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
1434 memset(buffer+len, 0, sizeof(buffer)-len);
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1435 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
1436 buffer[len] = 0;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1437 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
1438 config_dirty = 1;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1439 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
1440 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1441 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1442
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1443 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
1444 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1445 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
1446 int curval = curstr ? atoi(curstr) : def;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1447 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1448 int val = curval;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1449 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
1450 if (val != curval) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1451 char buffer[12];
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1452 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
1453 config_dirty = 1;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1454 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
1455 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1456 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1457
1796
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1458 void settings_float_property(struct nk_context *context, char *label, char *name, char *path, float def, float min, float max, float step)
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1459 {
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1460 char *curstr = tern_find_path(config, path, TVAL_PTR).ptrval;
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1461 float curval = curstr ? atof(curstr) : def;
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1462 nk_label(context, label, NK_TEXT_LEFT);
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1463 float val = curval;
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1464 nk_property_float(context, name, min, &val, max, step, step);
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1465 if (val != curval) {
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1466 char buffer[64];
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1467 sprintf(buffer, "%f", val);
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1468 config_dirty = 1;
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1469 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR);
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1470 }
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1471 }
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1472
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1473 typedef struct {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1474 char *fragment;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1475 char *vertex;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1476 } shader_prog;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1477
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1478 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
1479 {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1480 uint32_t num_progs = *num_existing;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1481 uint32_t prog_storage = *storage;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1482 uint32_t starting = num_progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1483
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1484 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
1485 if (entries[i].is_dir) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1486 continue;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1487 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1488 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
1489 uint32_t len = strlen(no_ext);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1490 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
1491 uint8_t dupe = 0;;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1492 for (uint32_t j = 0; j < starting; j++) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1493 if (!strcmp(entries[i].name, progs[j].fragment)) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1494 dupe = 1;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1495 break;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1496 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1497 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1498 if (!dupe) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1499 if (num_progs == prog_storage) {
1493
24f44f26b74d Fix buffer overrun in video settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1492
diff changeset
1500 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
1501 progs = realloc(progs, sizeof(progs) * prog_storage);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1502 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1503 progs[num_progs].vertex = NULL;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1504 progs[num_progs++].fragment = strdup(entries[i].name);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1505 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1506 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1507 free(no_ext);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1508 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1509
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1510 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
1511 if (entries[i].is_dir) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1512 continue;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1513 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1514 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
1515 uint32_t len = strlen(no_ext);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1516 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
1517 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
1518 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
1519 progs[j].vertex = strdup(entries[i].name);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1520 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1521 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1522 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1523 free(no_ext);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1524 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1525 free_dir_list(entries, num_entries);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1526 *num_existing = num_progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1527 *storage = prog_storage;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1528 return progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1529 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1530
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1531 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
1532 {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1533 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
1534 size_t num_entries;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1535 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
1536 free(shader_dir);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1537 shader_prog *progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1538 uint32_t num_progs = 0, prog_storage;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1539 if (num_entries) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1540 progs = calloc(num_entries, sizeof(shader_prog));
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1541 prog_storage = num_entries;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1542 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
1543 } else {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1544 progs = NULL;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1545 prog_storage = 0;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1546 }
1693
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1681
diff changeset
1547 #ifdef DATA_PATH
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1681
diff changeset
1548 shader_dir = path_append(DATA_PATH, "shaders");
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1681
diff changeset
1549 #else
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1550 shader_dir = path_append(get_exe_dir(), "shaders");
1693
ba3fb7a3be6b Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents: 1681
diff changeset
1551 #endif
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1552 entries = get_dir_list(shader_dir, &num_entries);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1553 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
1554 *num_out = num_progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1555 return progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1556 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
1557
1499
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1558 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
1559 {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1560 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
1561 int32_t selected = -1;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1562 for (uint32_t i = 0; i < num_options; i++)
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1563 {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1564 if (!strcmp(setting, options[i])) {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1565 selected = i;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1566 break;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1567 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1568 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1569 if (selected == -1) {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1570 for (uint32_t i = 0; i < num_options; i++)
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1571 {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1572 if (!strcmp(def, options[i])) {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1573 selected = i;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1574 break;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1575 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1576 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1577 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1578 return selected;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1579 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1580
1500
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1581 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
1582 {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1583 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
1584 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
1585 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
1586 config_dirty = 1;
1499
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1587 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
1588 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1589 return next;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1590 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1591
1500
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1592 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
1593 {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1594 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
1595 }
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1596
1553
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1597 void view_video_settings(struct nk_context *context)
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1598 {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1599 const char *vsync_opts[] = {"on", "off", "tear"};
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1600 const char *vsync_opt_names[] = {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1601 "On",
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1602 "Off",
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1603 "On, tear if late"
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1604 };
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1605 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
1606 static shader_prog *progs;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1607 static char **prog_names;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1608 static uint32_t num_progs;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1609 static uint32_t selected_prog;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1610 static int32_t selected_vsync = -1;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1611 if (selected_vsync < 0) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1612 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
1613 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1614 if(!progs) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1615 progs = get_shader_list(&num_progs);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1616 prog_names = calloc(num_progs, sizeof(char*));
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1617 for (uint32_t i = 0; i < num_progs; i++)
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1618 {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1619 prog_names[i] = basename_no_extension(progs[i].fragment);;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1620 uint32_t len = strlen(prog_names[i]);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1621 if (len > 2) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1622 prog_names[i][len-2] = 0;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1623 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1624 if (!progs[i].vertex) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1625 progs[i].vertex = strdup("default.v.glsl");
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1626 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1627 if (!strcmp(
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1628 progs[i].fragment,
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1629 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
1630 )) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1631 selected_prog = i;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1632 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1633 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1634 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1635 uint32_t width = render_width();
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1636 uint32_t height = render_height();
1577
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
1637 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
1638 if (desired_width > width) {
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
1639 desired_width = width;
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
1640 }
1553
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1641 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
1642 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
1643 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1644 settings_toggle(context, "Open GL", "video\0gl\0", 1);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1645 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1646 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
1647 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
1648 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
1649 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
1650 if (next_selected != selected_prog) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1651 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
1652 config_dirty = 1;
1553
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1653 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
1654 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
1655 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1656 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
1657 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
1658 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
1659 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
1660 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
1661 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
1662 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
1663 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
1664
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1665 if (nk_button_label(context, "Back")) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1666 pop_view();
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1667 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1668 nk_end(context);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1669 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1670 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
1671
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1672 void view_audio_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1673 {
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1674 const char *rates[] = {
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1675 "192000",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1676 "96000",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1677 "48000",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1678 "44100",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1679 "22050"
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1680 };
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1681 const char *sizes[] = {
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1682 "1024",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1683 "512",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1684 "256",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1685 "128",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1686 "64"
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1687 };
1798
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1688 const char *dac[] = {
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1689 "zero_offset",
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1690 "linear"
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1691 };
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1692 const char *dac_desc[] = {
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1693 "Zero Offset",
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1694 "Linear"
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1695 };
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1696 const uint32_t num_rates = sizeof(rates)/sizeof(*rates);
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1697 const uint32_t num_sizes = sizeof(sizes)/sizeof(*sizes);
1798
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1698 const uint32_t num_dacs = sizeof(dac)/sizeof(*dac);
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1699 static int32_t selected_rate = -1;
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1700 static int32_t selected_size = -1;
1798
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1701 static int32_t selected_dac = -1;
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1702 if (selected_rate < 0 || selected_size < 0 || selected_dac < 0) {
1499
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
1703 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
1704 selected_size = find_match(sizes, num_sizes, "audio\0buffer\0", "512");
1798
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1705 selected_dac = find_match(dac, num_dacs, "audio\0fm_dac\0", "zero_offset");
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1706 }
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1707 uint32_t width = render_width();
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1708 uint32_t height = render_height();
1578
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
1709 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
1710 if (desired_width > width) {
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
1711 desired_width = width;
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
1712 }
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1713 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
1714 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
1715 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
1716 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
1717 settings_int_input(context, "Lowpass Cutoff Hz", "audio\0lowpass_cutoff\0", "3390");
1811
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1718 settings_float_property(context, "Gain (dB)", "Overall", "audio\0gain\0", 0, -30.0f, 30.0f, 0.5f);
1796
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1719 settings_float_property(context, "", "FM", "audio\0fm_gain\0", 0, -30.0f, 30.0f, 0.5f);
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
1720 settings_float_property(context, "", "PSG", "audio\0psg_gain\0", 0, -30.0f, 30.0f, 0.5f);
1798
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
1721 selected_dac = settings_dropdown_ex(context, "FM DAC", dac, dac_desc, num_dacs, selected_dac, "audio\0fm_dac\0");
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1722 if (nk_button_label(context, "Back")) {
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1723 pop_view();
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1724 }
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1725 nk_end(context);
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
1726 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1727 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1728 void view_system_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1729 {
1568
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
1730 const char *sync_opts[] = {
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
1731 "video",
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
1732 "audio"
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
1733 };
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
1734 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
1735 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
1736 if (selected_sync < 0) {
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
1737 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
1738 }
1500
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1739 const char *regions[] = {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1740 "J - Japan",
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1741 "U - Americas",
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1742 "E - Europe"
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1743 };
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1744 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
1745 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
1746 static int32_t selected_region = -1;
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1747 if (selected_region < 0) {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1748 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
1749 }
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1750 const char *formats[] = {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1751 "native",
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1752 "gst"
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1753 };
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1754 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
1755 int32_t selected_format = -1;
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1756 if (selected_format < 0) {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
1757 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
1758 }
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1759 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
1760 "zero",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1761 "random"
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1762 };
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1763 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
1764 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
1765 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
1766 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
1767 }
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1768 const char *io_opts_1[] = {
1789
b3eb74936f18 Fix off by one in IO device UI
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
1769 "none",
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1770 "gamepad2.1",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1771 "gamepad3.1",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1772 "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
1773 "mouse.1",
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1774 "saturn keyboard",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1775 "xband keyboard"
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1776 };
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1777 const char *io_opts_2[] = {
1789
b3eb74936f18 Fix off by one in IO device UI
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
1778 "none",
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1779 "gamepad2.2",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1780 "gamepad3.2",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1781 "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
1782 "mouse.1",
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1783 "saturn keyboard",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1784 "xband keyboard"
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1785 };
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1786 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
1787 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
1788 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
1789 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
1790 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
1791 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
1792 }
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
1793
1498
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
1794 uint32_t width = render_width();
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
1795 uint32_t height = render_height();
1578
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
1796 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
1797 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
1798 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
1799 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
1800 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
1801 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
1802 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
1803 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
1804 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
1805 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
1806 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
1807 if (nk_button_label(context, "Back")) {
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
1808 pop_view();
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
1809 }
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
1810 nk_end(context);
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
1811 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1812 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1813
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1814 void view_back(struct nk_context *context)
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1815 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1816 pop_view();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1817 pop_view();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1818 current_view(context);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1819 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1820
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1821 void view_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1822 {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1823 static menu_item items[] = {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1824 {"Key Bindings", view_key_bindings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1825 {"Controllers", view_controllers},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1826 {"Video", view_video_settings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1827 {"Audio", view_audio_settings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1828 {"System", view_system_settings},
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1829 {"Back", view_back}
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1830 };
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1831
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1832 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) {
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1833 menu(context, sizeof(items)/sizeof(*items), items, NULL);
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1834 nk_end(context);
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1835 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1836 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1837
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1838 void exit_handler(uint32_t index)
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1839 {
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1840 exit(0);
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1841 }
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1842
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1843 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
1844 {
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1845 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
1846 {"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
1847 {"Load ROM", view_load},
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
1848 {"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
1849 {"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
1850 {"Load State", view_load_state},
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1851 {"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
1852 {"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
1853 };
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1854
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1855 if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) {
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1856 menu(context, sizeof(items)/sizeof(*items), items, exit_handler);
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1857 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
1858 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1859 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1860
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1861 void view_menu(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1862 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1863 static menu_item items[] = {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1864 {"Load ROM", view_load},
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1865 {"Settings", view_settings},
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1866 {"About", view_about},
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1867 {"Exit", NULL}
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1868 };
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1869
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1870 if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) {
1645
84ef1eb2c96a Added code for actually saving new controller bindings to an appropriate key in the config file
Michael Pavone <pavone@retrodev.com>
parents: 1626
diff changeset
1871 menu(context, sizeof(items)/sizeof(*items), items, exit_handler);
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1872 nk_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1873 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1874 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1875
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1876 void blastem_nuklear_render(void)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1877 {
1658
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1878 if (current_view != view_play) {
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1879 nk_input_end(context);
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1880 current_view(context);
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1881 nk_sdl_render(NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024);
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1882 nk_input_begin(context);
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1883 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1884 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1885
1486
a6881d0d76d0 Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
1886 void ui_idle_loop(void)
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1887 {
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
1888 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
1889 static uint32_t last;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1890 while (current_view != view_play)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1891 {
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
1892 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
1893 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
1894 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
1895 }
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
1896 last = current;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1897 render_update_display();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1898 }
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
1899 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
1900 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
1901 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
1902 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
1903 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1904 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1905 static void handle_event(SDL_Event *event)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1906 {
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
1907 if (event->type == SDL_KEYDOWN) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
1908 keycode = event->key.keysym.sym;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
1909 }
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
1910 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
1911 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
1912 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1913 else if (event->type == SDL_JOYHATMOTION) {
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1914 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
1915 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
1916 }
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1917 else if (event->type == SDL_JOYAXISMOTION) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1918 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
1919 axis_moved = event->jaxis.axis;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1920 axis_value = event->jaxis.value;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1921 }
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1922 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1923 nk_sdl_handle_event(event);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1924 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1925
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1926 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
1927 {
1681
3f1c8258e20f Hopefully fix Nuklear assert when loading ROM after changing video settings that some users are reporting
Michael Pavone <pavone@retrodev.com>
parents: 1675
diff changeset
1928 if (context)
3f1c8258e20f Hopefully fix Nuklear assert when loading ROM after changing video settings that some users are reporting
Michael Pavone <pavone@retrodev.com>
parents: 1675
diff changeset
1929 {
3f1c8258e20f Hopefully fix Nuklear assert when loading ROM after changing video settings that some users are reporting
Michael Pavone <pavone@retrodev.com>
parents: 1675
diff changeset
1930 nk_sdl_shutdown();
3f1c8258e20f Hopefully fix Nuklear assert when loading ROM after changing video settings that some users are reporting
Michael Pavone <pavone@retrodev.com>
parents: 1675
diff changeset
1931 context = NULL;
3f1c8258e20f Hopefully fix Nuklear assert when loading ROM after changing video settings that some users are reporting
Michael Pavone <pavone@retrodev.com>
parents: 1675
diff changeset
1932 }
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1933 }
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
1934
1609
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1935 static struct nk_image load_image_texture(uint32_t *buf, uint32_t width, uint32_t height)
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1936 {
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1937 GLuint tex;
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1938 glGenTextures(1, &tex);
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1939 glBindTexture(GL_TEXTURE_2D, tex);
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1940 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1941 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1942 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1943 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1658
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1944 #ifdef USE_GLES
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1945 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1946 #else
1609
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1947 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buf);
1658
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
1948 #endif
1609
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1949 return nk_image_id((int)tex);
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
1950 }
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
1951
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
1952 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
1953 {
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1954 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
1955 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
1956 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
1957 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
1958 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
1959 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
1960 }
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
1961 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
1962 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
1963 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
1964 nk_style_set_font(context, &def_font->handle);
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1965 for (uint32_t i = 0; i < num_ui_images; i++)
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1966 {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1967 ui_images[i]->ui = load_image_texture(ui_images[i]->image_data, ui_images[i]->width, ui_images[i]->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
1968 }
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
1969 }
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
1970
1811
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1971 static void style_init(void)
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1972 {
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1973 context->style.checkbox.padding.x = render_height() / 120;
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1974 context->style.checkbox.padding.y = render_height() / 120;
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1975 context->style.checkbox.border = render_height() / 240;
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1976 context->style.checkbox.cursor_normal.type = NK_STYLE_ITEM_COLOR;
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1977 context->style.checkbox.cursor_normal.data.color = (struct nk_color){
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1978 .r = 255, .g = 128, .b = 0, .a = 255
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1979 };
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1980 context->style.checkbox.cursor_hover = context->style.checkbox.cursor_normal;
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1981 }
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1982
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
1983 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
1984 {
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
1985 context = nk_sdl_init(render_get_window());
1811
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
1986 style_init();
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
1987 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
1988 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
1989
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
1990 void show_pause_menu(void)
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
1991 {
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
1992 set_content_binding_state(0);
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
1993 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
1994 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
1995 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
1996 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
1997 }
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
1998
1581
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
1999 void show_play_view(void)
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2000 {
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2001 set_content_binding_state(1);
1581
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2002 current_view = view_play;
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2003 }
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2004
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2005 static uint8_t active;
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2006 uint8_t is_nuklear_active(void)
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2007 {
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2008 return active;
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2009 }
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2010
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
2011 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
2012 {
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
2013 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
2014 //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
2015 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
2016 }
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
2017 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
2018 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
2019 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
2020 }
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
2021 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
2022 }
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
2023
1577
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2024 static void persist_config_exit(void)
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2025 {
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2026 if (config_dirty) {
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2027 persist_config(config);
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2028 }
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2029 }
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2030
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2031 ui_image *load_ui_image(char *name)
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2032 {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2033 uint32_t buf_size;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2034 uint8_t *buf = (uint8_t *)read_bundled_file(name, &buf_size);
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2035 if (buf) {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2036 num_ui_images++;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2037 if (num_ui_images > ui_image_storage) {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2038 ui_image_storage = (ui_image_storage + 1) * 2;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2039 ui_images = realloc(ui_images, ui_image_storage * sizeof(*ui_images));
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2040 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2041 ui_image *this_image = ui_images[num_ui_images-1] = calloc(1, sizeof(ui_image));
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2042 this_image->image_data = load_png(buf, buf_size, &this_image->width, &this_image->height);
1658
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2043 #ifdef USE_GLES
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2044 uint32_t *cur = this_image->image_data;
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2045 for (int i = 0; i < this_image->width*this_image->height; i++, cur++)
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2046 {
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2047 uint32_t pixel = *cur;
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2048 *cur = (pixel & 0xFF00FF00) | (pixel << 16 & 0xFF0000) | (pixel >> 16 & 0xFF);
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2049 }
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2050 #endif
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2051 free(buf);
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2052 if (!this_image->image_data) {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2053 num_ui_images--;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2054 free(this_image);
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2055 return NULL;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2056 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2057 return this_image;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2058 } else {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2059 return NULL;
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2060 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2061 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2062
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2063 void blastem_nuklear_init(uint8_t file_loaded)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2064 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2065 context = nk_sdl_init(render_get_window());
1811
af14c21939f6 Add unit to gain label and change color of checkbox selected state to hopefully make it more clear
Michael Pavone <pavone@retrodev.com>
parents: 1807
diff changeset
2066 style_init();
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2067
1646
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2068 controller_360 = load_ui_image("images/360.png");
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2069 controller_ps4 = load_ui_image("images/ps4.png");
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2070 controller_ps4_6b = load_ui_image("images/ps4_6b.png");
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2071
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
2072 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
2073
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2074 if (file_loaded) {
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2075 current_view = view_play;
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2076 } else {
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2077 current_view = view_menu;
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2078 set_content_binding_state(0);
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2079 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2080 render_set_ui_render_fun(blastem_nuklear_render);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2081 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
2082 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
2083
1577
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2084 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
2085
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2086 active = 1;
1486
a6881d0d76d0 Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
2087 ui_idle_loop();
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2088 }