annotate nuklear_ui/blastem_nuklear.c @ 2684:c649bcc18487

Fix crash bug in Android fallback font loading path
author Michael Pavone <pavone@retrodev.com>
date Sat, 29 Mar 2025 23:54:45 -0700
parents 143cb5762ec9
children
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
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
3 #define NK_RAWFB_IMPLEMENTATION
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
4 #define RAWFB_RGBX_8888
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include <stdlib.h>
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
7 #include <limits.h>
1827
c945a25aa75c Fix windows build
Michael Pavone <pavone@retrodev.com>
parents: 1825
diff changeset
8 #include <math.h>
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 #include "blastem_nuklear.h"
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
10 #include "nuklear_rawfb.h"
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 #include "font.h"
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
12 #include "filechooser.h"
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 #include "../render.h"
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 #include "../render_sdl.h"
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 #include "../util.h"
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 #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
17 #include "../saves.h"
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 #include "../blastem.h"
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
19 #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
20 #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
21 #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
22 #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
23 #include "../bindings.h"
2376
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
24 #include "../mediaplayer.h"
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 static struct nk_context *context;
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
27 static struct rawfb_context *fb_context;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28
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
29 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
30 {
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 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
32 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
33 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
34 } 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
35
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
36 static ui_image **ui_images, *controller_360, *controller_ps4,
2020
e42c45ff06d5 Add Genesis 6-button contoller image
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
37 *controller_ps4_6b, *controller_wiiu, *controller_gen_6b;
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
38 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
39
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 typedef void (*view_fun)(struct nk_context *);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 static view_fun current_view;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
42 static view_fun *previous_views;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
43 static uint32_t view_storage;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
44 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
45 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
46 static uint8_t config_dirty;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
47
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
48 static void push_view(view_fun new_view)
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 if (num_prev == view_storage) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
51 view_storage = view_storage ? 2*view_storage : 2;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
52 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
53 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
54 previous_views[num_prev++] = current_view;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
55 current_view = new_view;
1841
5d10b8494b02 WIP keyboard nav for Nuklear menus
Michael Pavone <pavone@retrodev.com>
parents: 1831
diff changeset
56 context->input.selected_widget = 0;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
57 }
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 static void pop_view()
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
60 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
61 if (num_prev) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
62 current_view = previous_views[--num_prev];
1841
5d10b8494b02 WIP keyboard nav for Nuklear menus
Michael Pavone <pavone@retrodev.com>
parents: 1831
diff changeset
63 context->input.selected_widget = 0;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
64 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
65 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
66
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
67 static void clear_view_stack()
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
68 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
69 num_prev = 0;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
70 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 void view_play(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 {
2376
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
74 if (current_system && current_system->type == SYSTEM_MEDIA_PLAYER) {
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
75 media_player *player = (media_player *)current_system;
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
76 if (nk_begin(context, "Media Player", nk_rect(0, 0, render_width(), render_height()), 0)) {
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
77 uint32_t desired_width = context->style.font->height * 10;
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
78 nk_layout_row_static(context, context->style.font->height * 1.25f, render_width() - 4 * context->style.font->height, 1);
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
79 nk_label(context, current_media()->name, NK_TEXT_LEFT);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
80
2376
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
81 uint32_t seconds = player->playback_time / 60;
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
82 uint32_t minutes = seconds / 60;
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
83 seconds %= 60;
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
84 uint32_t hours = minutes / 60;
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
85 minutes %= 60;
2531
f973651b48d7 Fix some warnings that show up in newer versions of gcc
Michael Pavone <pavone@retrodev.com>
parents: 2530
diff changeset
86 char buffer[22];
2376
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
87 sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
88 nk_label(context, buffer, NK_TEXT_LEFT);
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
89
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
90 nk_layout_row_static(context, context->style.font->height * 1.25f, desired_width, 1);
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
91 if (nk_button_label(context, player->state == STATE_PLAY ? "Pause" : "Play")) {
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
92 uint8_t old_state = player->button_state[BUTTON_A];
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
93 player->button_state[BUTTON_A] = 0;
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
94 current_system->gamepad_down(current_system, 1, BUTTON_A);
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
95 player->button_state[BUTTON_A] = old_state;
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
96 }
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
97 nk_end(context);
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
98 }
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
99 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
102 static char *browser_cur_path;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
103 static const char *browser_label;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
104 static const char *browser_setting_path;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
105 static const char **browser_ext_list;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
106 static uint32_t browser_num_exts;
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
107 static uint8_t use_native_filechooser;
2616
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
108 #ifdef __EMSCRIPTEN__
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
109 #include <emscripten.h>
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
110 static uint8_t chooser_open;
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
111
2616
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
112 EM_JS(void, show_html_chooser, (const char *title, const char *extensions, int normal_open, int is_settings), {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
113 let container = document.getElementById('chooser');
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
114 let canvas = document.getElementById('canvas');
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
115 let fileIn = null;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
116 let titleEl = null;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
117 if (!container) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
118 container = document.createElement('div');
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
119 container.id = 'chooser';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
120 container.style.position = 'absolute';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
121 container.style.display = 'none';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
122 container.style.borderWidth = '2px';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
123 container.style.borderColor = 'black';
2617
ad9e074c8901 Fix border style for web file chooser
Michael Pavone <pavone@retrodev.com>
parents: 2616
diff changeset
124 container.style.borderStyle = 'solid';
2616
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
125 titleEl = document.createElement('h3');
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
126 titleEl.id = 'chooser_title';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
127 container.appendChild(titleEl);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
128 fileIn = document.createElement('input');
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
129 fileIn.type = 'file';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
130 fileIn.id = 'file';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
131 container.appendChild(fileIn);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
132 canvas.parentNode.appendChild(container);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
133 } else {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
134 fileIn = document.getElementById('file');
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
135 titleEl = document.getElementById('chooser_title');
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
136 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
137 titleEl.innerText = UTF8ToString(title);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
138 fileIn.onchange = (event) => {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
139 let f = event.target;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
140 if (f.files.length) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
141 let reader = new FileReader();
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
142 let name = f.files[0].name;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
143 reader.onload = (event) => {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
144 let prefix = '/roms';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
145 let prevPath = null;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
146 if (normal_open) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
147 prevPath = 'previousRomPath';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
148 } else if (is_settings) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
149 prefix = '/firmware';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
150 } else {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
151 prevPath = 'previousSpecialPath';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
152 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
153 if (prevPath && window[prevPath]) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
154 FS.unlink(window[prevPath]);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
155 } else {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
156 FS.mkdir(prefix);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
157 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
158
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
159 let buffer = new Uint8Array(event.target.result);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
160 FS.createDataFile(prefix, name, buffer, true, false, false);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
161 let fullPath = prefix + "/" + name;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
162 if (prevPath) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
163 window[prevPath] = fullPath;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
164 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
165 console.log(fullPath, normal_open, is_settings);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
166 document.getElementById('chooser').style.display = 'none';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
167 Module.ccall('handle_chooser_result', 'void', ['number', 'string'], [normal_open, fullPath]);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
168 };
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
169 reader.readAsArrayBuffer(f.files[0]);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
170 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
171 };
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
172 fileIn.accept = UTF8ToString(extensions);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
173 let cRect = canvas.getBoundingClientRect();
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
174 let pRect = canvas.parentNode.parentNode.getBoundingClientRect();
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
175 container.style.top = '' + (cRect.top - pRect.top) + 'px';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
176 container.style.left = '' + (cRect.left - pRect.left) + 'px';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
177 container.style.width = '' + cRect.width + 'px';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
178 container.style.height = '' + cRect.height + 'px';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
179 container.style.display = 'block';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
180 container.style.backgroundColor = 'white';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
181 });
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
182 #endif
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
183
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
184 void handle_chooser_result(uint8_t normal_open, char *full_path)
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
185 {
2616
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
186 #ifdef __EMSCRIPTEN__
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
187 chooser_open = 0;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
188 full_path = strdup(full_path);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
189 #endif
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
190 if(normal_open) {
2401
34b4ff091891 Fix crash when loading a subsequent ROM after lock-on
Michael Pavone <pavone@retrodev.com>
parents: 2392
diff changeset
191 lockon_media(NULL);
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
192 if (current_system) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
193 current_system->next_rom = full_path;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
194 current_system->request_exit(current_system);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
195 } else {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
196 init_system_with_media(full_path, SYSTEM_UNKNOWN);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
197 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
198
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
199 clear_view_stack();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
200 show_play_view();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
201 } else if (browser_setting_path) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
202 config = tern_insert_path(config, browser_setting_path, (tern_val){.ptrval = full_path}, TVAL_PTR);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
203 config_dirty = 1;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
204 browser_ext_list = NULL;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
205 pop_view();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
206 } else {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
207 lockon_media(full_path);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
208
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
209 clear_view_stack();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
210 show_play_view();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
211 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
212 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
213
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
214 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
215 {
2616
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
216 static const char **ext_list;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
217 static uint32_t num_exts;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
218 static uint8_t got_ext_list;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
219 if (!browser_ext_list) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
220 if (!got_ext_list) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
221 ext_list = (const char **)get_extension_list(config, &num_exts);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
222 got_ext_list = 1;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
223 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
224 browser_ext_list = ext_list;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
225 browser_num_exts = num_exts;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
226 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
227 #ifdef __EMSCRIPTEN__
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
228 uint8_t just_opened = !chooser_open;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
229 chooser_open = 1;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
230 if (just_opened) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
231 size_t total_length = 0;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
232 for (uint32_t i = 0; i < browser_num_exts; i++)
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
233 {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
234 total_length += 1 + strlen(browser_ext_list[i]);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
235 if (i) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
236 total_length++;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
237 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
238 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
239 char *list = calloc(total_length + 1, 1);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
240 char *cur = list;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
241 for (uint32_t i = 0; i < browser_num_exts; i++)
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
242 {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
243 if (i) {
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
244 *(cur++) = ',';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
245 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
246 *(cur++) = '.';
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
247 size_t len = strlen(browser_ext_list[i]);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
248 memcpy(cur, browser_ext_list[i], len);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
249 cur += len;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
250 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
251 *(cur) = 0;
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
252 show_html_chooser(browser_label, list, normal_open, browser_setting_path != NULL);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
253 free(list);
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
254 }
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
255 #else
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 static dir_entry *entries;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 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
258 static int32_t selected_entry = -1;
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
259 if (!browser_cur_path) {
2681
c4256ce2c45a Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents: 2678
diff changeset
260 if (!get_initial_browse_path(&browser_cur_path)) {
c4256ce2c45a Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents: 2678
diff changeset
261 return;
c4256ce2c45a Updated Android port using gradle toolchain and with basic Storage Access Framework support for Android 11+ support
Michael Pavone <pavone@retrodev.com>
parents: 2678
diff changeset
262 }
1481
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
263 }
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
264 if (use_native_filechooser && native_filechooser_available()) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
265 char *path = native_filechooser_pick(browser_label, browser_cur_path);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
266 if (path) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
267 free(browser_cur_path);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
268 browser_cur_path = path_dirname(path);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
269 handle_chooser_result(normal_open, path);
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
270 } else {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
271 browser_ext_list = NULL;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
272 pop_view();
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
273 }
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
274 return;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
275 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
276 if (!entries) {
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
277 entries = get_dir_list(browser_cur_path, &num_entries);
1484
d82af64c94d2 Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
278 if (entries) {
d82af64c94d2 Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
279 sort_dir_list(entries, num_entries);
d82af64c94d2 Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
280 }
2017
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
281 if (!num_entries) {
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
282 //get_dir_list can fail if the user doesn't have permission
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
283 //for the current folder, make sure they can still navigate up
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
284 free_dir_list(entries, num_entries);
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
285 entries = calloc(1, sizeof(dir_entry));
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
286 entries[0].name = strdup("..");
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
287 entries[0].is_dir = 1;
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
288 num_entries = 1;
8e7b06ade815 Prevent user from getting stuck in directories they don't have permission to read in ROM browser
Michael Pavone <pavone@retrodev.com>
parents: 2016
diff changeset
289 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
290 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
291 uint32_t width = render_width();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
292 uint32_t height = render_height();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
293 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
294 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
295 int32_t old_selected = selected_entry;
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
296 const char *parts[] = {browser_label, ": ", browser_cur_path};
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
297 char *title = alloc_concat_m(3, parts);
2016
2d8748e0ccb2 Show current path in file browser
Michael Pavone <pavone@retrodev.com>
parents: 2015
diff changeset
298 if (nk_group_begin(context, title, 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
299 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
300 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
301 {
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
302 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
303 continue;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
304 }
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
305 if (browser_num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, browser_ext_list, browser_num_exts)) {
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
306 continue;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
307 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
308 int selected = i == selected_entry;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
309 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
310 if (selected) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
311 selected_entry = i;
1554
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
312 } else if (i == selected_entry) {
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
313 selected_entry = -1;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
314 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
315 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
316 nk_group_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
317 }
2016
2d8748e0ccb2 Show current path in file browser
Michael Pavone <pavone@retrodev.com>
parents: 2015
diff changeset
318 free(title);
1579
f66290afae65 Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents: 1578
diff changeset
319 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
320 if (nk_button_label(context, "Back")) {
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
321 browser_ext_list = NULL;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
322 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
323 }
1554
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
324 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
325 if (selected_entry < 0) {
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
326 selected_entry = old_selected;
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
327 }
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
328 char *full_path = path_append(browser_cur_path, entries[selected_entry].name);
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
329 if (entries[selected_entry].is_dir) {
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
330 free(browser_cur_path);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
331 browser_cur_path = full_path;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
332 free_dir_list(entries, num_entries);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
333 entries = NULL;
2677
2df04125ac78 Reset selected widget when changing directories in file browser
Michael Pavone <pavone@retrodev.com>
parents: 2650
diff changeset
334 context->input.selected_widget = 0;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
335 } else {
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
336 handle_chooser_result(normal_open, full_path);
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
337 }
1554
87350caf6dab Allow double click to open ROM in file browser
Michael Pavone <pavone@retrodev.com>
parents: 1553
diff changeset
338 selected_entry = -1;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
339 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
340 nk_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
341 }
2616
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
342 #endif
cbf5a01e429e Add an HTML/JS file picker to web build
Michael Pavone <pavone@retrodev.com>
parents: 2604
diff changeset
343
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
344 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
345
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
346 void view_load(struct nk_context *context)
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
347 {
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
348 browser_label = "Select ROM";
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
349 view_file_browser(context, 1);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
350 }
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
351
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
352 void view_lock_on(struct nk_context *context)
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
353 {
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
354 browser_label = "Select ROM";
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
355 view_file_browser(context, 0);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
356 }
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
357
2544
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
358 void view_load_tape(struct nk_context *context)
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
359 {
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
360 browser_label = "Select Tape Image";
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
361 view_file_browser(context, 0);
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
362 }
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
363
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
364 void view_file_settings(struct nk_context *context)
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
365 {
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
366 view_file_browser(context, 0);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
367 }
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
368
2545
c076a96f1668 Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
369 #include "../version.inc"
c076a96f1668 Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
370
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
371 void view_about(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
372 {
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
373 const char *lines[] = {
2545
c076a96f1668 Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
374 "BlastEm v" BLASTEM_VERSION,
c076a96f1668 Get CD titles sort of working in libretro target
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
375 "Copyright 2012-2025 Michael Pavone",
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
376 "",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
377 "BlastEm is a high performance open source",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
378 "(GPLv3) Genesis/Megadrive emulator",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
379 };
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
380 const uint32_t NUM_LINES = sizeof(lines)/sizeof(*lines);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
381 const char *thanks[] = {
1661
c3c3b65f17aa Updated special thanks
Mike Pavone <pavone@retrodev.com>
parents: 1660
diff changeset
382 "Nemesis: Documentation and test ROMs",
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
383 "Charles MacDonald: Documentation",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
384 "Eke-Eke: Documentation",
1812
8aeac7bd9fa7 Update version number, special thanks, CHANGELOG and README in preparation for possible 0.6.2 release
Michael Pavone <pavone@retrodev.com>
parents: 1811
diff changeset
385 "Sauraen: YM2612/YM2203 Die Analysis",
8aeac7bd9fa7 Update version number, special thanks, CHANGELOG and README in preparation for possible 0.6.2 release
Michael Pavone <pavone@retrodev.com>
parents: 1811
diff changeset
386 "Alexey Khokholov: YM3438 Die Analysis",
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
387 "Bart Trzynadlowski: Documentation",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
388 "KanedaFR: Hosting the best Sega forum",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
389 "Titan: Awesome demos and documentation",
1661
c3c3b65f17aa Updated special thanks
Mike Pavone <pavone@retrodev.com>
parents: 1660
diff changeset
390 "flamewing: BCD info and test ROM",
c3c3b65f17aa Updated special thanks
Mike Pavone <pavone@retrodev.com>
parents: 1660
diff changeset
391 "r57shell: Opcode size test ROM",
1526
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
392 "micky: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
393 "Sasha: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
394 "lol-frank: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
395 "Sik: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
396 "Tim Lawrence : Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
397 "ComradeOj: Testing",
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
398 "Vladikcomper: Testing"
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
399 };
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
400 const uint32_t NUM_THANKS = sizeof(thanks)/sizeof(*thanks);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
401 uint32_t width = render_width();
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
402 uint32_t height = render_height();
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
403 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
404 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
405 for (uint32_t i = 0; i < NUM_LINES; i++)
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
406 {
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
407 nk_label(context, lines[i], NK_TEXT_LEFT);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
408 }
1579
f66290afae65 Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents: 1578
diff changeset
409 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
410 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
411 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
412 for (uint32_t i = 0; i < NUM_THANKS; i++)
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
413 {
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
414 nk_label(context, thanks[i], NK_TEXT_LEFT);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
415 }
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
416 nk_group_end(context);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
417 }
1579
f66290afae65 Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents: 1578
diff changeset
418 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
419 if (nk_button_label(context, "Back")) {
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
420 pop_view();
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
421 }
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
422 nk_end(context);
9bea1a199f15 Filled in About view
Michael Pavone <pavone@retrodev.com>
parents: 1522
diff changeset
423 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
424 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
425
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
426 typedef struct {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
427 const char *title;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
428 view_fun next_view;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
429 } menu_item;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
430
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
431 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
432 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
433
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
434 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
435 {
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
436 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
437 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
438 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
439 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
440 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
441 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
442 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
443 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
444 }
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
445 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
446 {
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
447 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
448 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
449 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
450 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
451 }
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
452 }
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
453 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
454 }
1579
f66290afae65 Add some basic scaling to rest of UI
Michael Pavone <pavone@retrodev.com>
parents: 1578
diff changeset
455 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
456 if (nk_button_label(context, "Back")) {
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
457 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
458 }
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
459 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
460 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
461 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
462 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
463 }
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
464 } 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
465 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
466 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
467 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
468 }
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
469 }
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
470 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
471 }
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
472 }
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
473
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
474 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
475 {
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
476 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
477 }
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
478
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
479 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
480 {
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
481 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
482 }
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
483
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
484 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
485
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
486 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
487 {
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
488 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
489 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
490 const uint32_t button_space = 6;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
491
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
492 uint32_t width = render_width();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
493 uint32_t height = render_height();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
494 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
495 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
496 uint32_t left = width/2 - button_width/2;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
497
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
498 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
499 for (uint32_t i = 0; i < num_entries; i++)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
500 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
501 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
502 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
503 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
504 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
505 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
506 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
507 slots = NULL;
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
508 } else if (current_view == view_play) {
1814
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
509 clear_view_stack();
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
510 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
511 }
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
512 } 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
513 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
514 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
515 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
516 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
517 nk_layout_space_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
518 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
519
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
520 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
521 {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
522 if (valtype != TVAL_PTR) {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
523 return;
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
524 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
525 tern_node **binding_lookup = data;
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
526 *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
527 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
528
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
529 static int32_t keycode;
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
530 static const char *set_binding;
1814
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
531 static uint8_t bind_click_release, click;
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
532 char *set_label;
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
533 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
534 {
1578
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
535 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
536 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
537 nk_layout_row_static(context, context->style.font->height, render_width()/2 - 80, 2);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
538
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
539 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
540 {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
541 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
542 const char *label = label_alloc;
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
543 if (!label) {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
544 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
545 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
546 nk_label(context, label, NK_TEXT_LEFT);
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
547 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
548 set_binding = binds[i];
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
549 set_label = strdup(label);
1814
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
550 bind_click_release = 0;
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
551 keycode = 0;
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
552 }
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
553 if (label_alloc) {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
554 free(label_alloc);
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
555 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
556 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
557 nk_group_end(context);
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
558 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
559 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
560
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
561 static char *get_key_name(int32_t keycode)
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
562 {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
563 char *name = NULL;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
564 if (keycode > ' ' && keycode < 0x80) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
565 //key corresponds to a printable non-whitespace character
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
566 name = malloc(2);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
567 name[0] = keycode;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
568 name[1] = 0;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
569 } else {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
570 switch (keycode)
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
571 {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
572 case RENDERKEY_UP: name = "up"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
573 case RENDERKEY_DOWN: name = "down"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
574 case RENDERKEY_LEFT: name = "left"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
575 case RENDERKEY_RIGHT: name = "right"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
576 case '\r': name = "enter"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
577 case ' ': name = "space"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
578 case '\t': name = "tab"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
579 case '\b': name = "backspace"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
580 case RENDERKEY_ESC: name = "esc"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
581 case RENDERKEY_DEL: name = "delete"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
582 case RENDERKEY_LSHIFT: name = "lshift"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
583 case RENDERKEY_RSHIFT: name = "rshift"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
584 case RENDERKEY_LCTRL: name = "lctrl"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
585 case RENDERKEY_RCTRL: name = "rctrl"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
586 case RENDERKEY_LALT: name = "lalt"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
587 case RENDERKEY_RALT: name = "ralt"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
588 case RENDERKEY_HOME: name = "home"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
589 case RENDERKEY_END: name = "end"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
590 case RENDERKEY_PAGEUP: name = "pageup"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
591 case RENDERKEY_PAGEDOWN: name = "pagedown"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
592 case RENDERKEY_F1: name = "f1"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
593 case RENDERKEY_F2: name = "f2"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
594 case RENDERKEY_F3: name = "f3"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
595 case RENDERKEY_F4: name = "f4"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
596 case RENDERKEY_F5: name = "f5"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
597 case RENDERKEY_F6: name = "f6"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
598 case RENDERKEY_F7: name = "f7"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
599 case RENDERKEY_F8: name = "f8"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
600 case RENDERKEY_F9: name = "f9"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
601 case RENDERKEY_F10: name = "f10"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
602 case RENDERKEY_F11: name = "f11"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
603 case RENDERKEY_F12: name = "f12"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
604 case RENDERKEY_SELECT: name = "select"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
605 case RENDERKEY_PLAY: name = "play"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
606 case RENDERKEY_SEARCH: name = "search"; break;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
607 case RENDERKEY_BACK: name = "back"; break;
1549
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
608 case RENDERKEY_NP0: name = "np0"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
609 case RENDERKEY_NP1: name = "np1"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
610 case RENDERKEY_NP2: name = "np2"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
611 case RENDERKEY_NP3: name = "np3"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
612 case RENDERKEY_NP4: name = "np4"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
613 case RENDERKEY_NP5: name = "np5"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
614 case RENDERKEY_NP6: name = "np6"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
615 case RENDERKEY_NP7: name = "np7"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
616 case RENDERKEY_NP8: name = "np8"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
617 case RENDERKEY_NP9: name = "np9"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
618 case RENDERKEY_NP_DIV: name = "np/"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
619 case RENDERKEY_NP_MUL: name = "np*"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
620 case RENDERKEY_NP_MIN: name = "np-"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
621 case RENDERKEY_NP_PLUS: name = "np+"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
622 case RENDERKEY_NP_ENTER: name = "npenter"; break;
577253765192 Allow numpad keys to be mapped
Michael Pavone <pavone@retrodev.com>
parents: 1545
diff changeset
623 case RENDERKEY_NP_STOP: name = "np."; break;
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
624 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
625 if (name) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
626 name = strdup(name);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
627 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
628 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
629 return name;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
630 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
631
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
632 void view_key_bindings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
633 {
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
634 static const char *controller1_binds[] = {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
635 "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
636 "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
637 "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
638 "gamepads.1.start", "gamepads.1.mode"
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
639 };
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
640 static const char *controller2_binds[] = {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
641 "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
642 "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
643 "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
644 "gamepads.2.start", "gamepads.2.mode"
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
645 };
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
646 static const char *general_binds[] = {
2306
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2299
diff changeset
647 "ui.menu", "ui.save_state", "ui.load_state", "ui.toggle_fullscreen", "ui.soft_reset", "ui.reload",
2530
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
648 "ui.screenshot", "ui.vgm_log", "ui.record_video", "ui.sms_pause", "ui.toggle_keyboard_captured",
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
649 "ui.release_mouse", "ui.exit", "cassette.play", "cassette.stop", "cassette.rewind"
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
650 };
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
651 static const char *general_names[] = {
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
652 "Show Menu", "Quick Save", "Quick Load", "Toggle Fullscreen", "Soft Reset", "Reload Media",
2530
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
653 "Internal Screenshot", "Toggle VGM Log", "Toggle Video Recording", "SMS Pause", "Capture Keyboard",
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
654 "Release Mouse", "Exit", "Cassette Play", "Cassette Stop", "Cassette Rewind"
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
655 };
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
656 static const char *speed_binds[] = {
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
657 "ui.next_speed", "ui.prev_speed",
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
658 "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
659 "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
660 };
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
661 static const char *speed_names[] = {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
662 "Next", "Previous",
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
663 "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
664 "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
665 };
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
666 static const char *debug_binds[] = {
1660
c6cc2dae262f Updated binding UI to reflect new VDP debug options
Mike Pavone <pavone@retrodev.com>
parents: 1658
diff changeset
667 "ui.enter_debugger", "ui.plane_debug", "ui.vram_debug", "ui.cram_debug",
2530
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
668 "ui.compositing_debug", "ui.vdp_debug_mode", "ui.oscilloscope"
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
669 };
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
670 const char *debug_names[] = {
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
671 "CPU Debugger", "Plane Debugger", "VRAM Debugger", "CRAM Debugger",
2530
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
672 "Layer Debugger", "Cycle Mode/Pal", "Oscilloscope"
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
673 };
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
674 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
675 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
676 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
677 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
678 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
679 static tern_node *binding_lookup;
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
680 if (!binding_lookup) {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
681 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
682 if (bindings) {
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
683 tern_foreach(bindings, binding_loop, &binding_lookup);
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
684 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
685 }
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
686 uint32_t width = render_width();
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
687 uint32_t height = render_height();
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
688 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
689 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
690 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
691 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
692 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
693 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
694 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
695 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
696 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
697 }
1520
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
698 nk_end(context);
cb3c6395b28c Initial work on keyboard binding settings view
Michael Pavone <pavone@retrodev.com>
parents: 1501
diff changeset
699 }
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
700 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
701 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
702 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
703 nk_label(context, set_label, NK_TEXT_CENTERED);
1814
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
704 if (nk_button_label(context, "Cancel") && bind_click_release) {
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
705 free(set_label);
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
706 set_binding = set_label = NULL;
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
707 } else if (keycode) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
708 char *name = get_key_name(keycode);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
709 if (name) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
710 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
711 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
712 if (old) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
713 uint32_t suffix_len = strlen(old) + 1;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
714 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
715 memcpy(old_path, "bindings\0keys\0", prefix_len);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
716 memcpy(old_path + prefix_len, old, suffix_len);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
717 old_path[prefix_len + suffix_len] = 0;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
718 tern_val old_val;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
719 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
720 free(old_val.ptrval);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
721 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
722 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
723 uint32_t suffix_len = strlen(name) + 1;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
724 char *path = malloc(prefix_len + suffix_len + 1);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
725 memcpy(path, "bindings\0keys\0", prefix_len);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
726 memcpy(path + prefix_len, name, suffix_len);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
727 path[prefix_len + suffix_len] = 0;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
728
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
729 config_dirty = 1;
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
730 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
731 free(path);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
732 free(name);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
733 tern_free(binding_lookup);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
734 binding_lookup = NULL;
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
735 }
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
736 free(set_label);
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
737 set_binding = set_label = NULL;
1814
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
738 } else if (!click) {
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
739 bind_click_release = 1;
1521
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
740 }
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
741 nk_end(context);
a51721408c15 More fleshed out keyboard bindings view
Michael Pavone <pavone@retrodev.com>
parents: 1520
diff changeset
742 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
743 }
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
744
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
745 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
746 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
747 //#define MIN_BIND_BOX_WIDTH 140
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
748 #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
749
5e2af89c3467 Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents: 1596
diff changeset
750 #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
751 #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
752 #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
753 #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
754 enum {
2310
b0ec82a59472 Fix analog stick directions being messed up in controller binding UI
Michael Pavone <pavone@retrodev.com>
parents: 2308
diff changeset
755 DOWN, UP,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
756 };
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
757
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
758 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
759 [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
760 [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
761 [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
762 [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
763 [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
764 [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
765 [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
766 [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
767 [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
768 [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
769 };
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
770
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
771 typedef struct {
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
772 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
773 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
774 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
775 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
776 } 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
777
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
778 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
779
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
780 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
781 {
1625
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
782 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
783 if (!conf_names) {
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
784 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
785 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
786 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
787 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
788 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
789 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
790 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
791 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
792 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
793 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
794 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
795 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
796 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
797 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
798 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
799 conf_names = tern_insert_ptr(conf_names, "ui.enter_debugger", "Enter CPU Debugger");
2530
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
800 conf_names = tern_insert_ptr(conf_names, "ui.plane_debug", "Plane Debugger");
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
801 conf_names = tern_insert_ptr(conf_names, "ui.vram_debug", "VRAM Debugger");
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
802 conf_names = tern_insert_ptr(conf_names, "ui.cram_debug", "CRAM Debugger");
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
803 conf_names = tern_insert_ptr(conf_names, "ui.composite_debug", "Layer Debugger");
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
804 conf_names = tern_insert_ptr(conf_names, "ui.oscilloscope", "Oscilloscope");
1625
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
805 conf_names = tern_insert_ptr(conf_names, "ui.screenshot", "Take Screenshot");
1910
ee178f08611b Expose vgm toggle keybind in settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1900
diff changeset
806 conf_names = tern_insert_ptr(conf_names, "ui.vgm_log", "Toggle VGM Log");
2306
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2299
diff changeset
807 conf_names = tern_insert_ptr(conf_names, "ui.menu", "Show Menu");
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2299
diff changeset
808 conf_names = tern_insert_ptr(conf_names, "ui.exit", "Exit");
1625
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
809 conf_names = tern_insert_ptr(conf_names, "ui.save_state", "Quick Save");
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
810 conf_names = tern_insert_ptr(conf_names, "ui.load_state", "Quick Load");
1625
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
811 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
812 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
813 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
814 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
815 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
816 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
817 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
818 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
819 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
820 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
821 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
822 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
823 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
824 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
825 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
826 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
827 conf_names = tern_insert_ptr(conf_names, "ui.toggle_keyboard_captured", "Toggle Keyboard Capture");
2528
90a40be940f7 Implement read-only SC-3000 cassette support
Michael Pavone <pavone@retrodev.com>
parents: 2484
diff changeset
828 conf_names = tern_insert_ptr(conf_names, "cassette.play", "Cassette Play");
90a40be940f7 Implement read-only SC-3000 cassette support
Michael Pavone <pavone@retrodev.com>
parents: 2484
diff changeset
829 conf_names = tern_insert_ptr(conf_names, "cassette.stop", "Cassette Stop");
90a40be940f7 Implement read-only SC-3000 cassette support
Michael Pavone <pavone@retrodev.com>
parents: 2484
diff changeset
830 conf_names = tern_insert_ptr(conf_names, "cassette.rewind", "Cassette Rewind");
1625
6130e1e72151 Show user friendly names for binding options in controller bind config
Michael Pavone <pavone@retrodev.com>
parents: 1624
diff changeset
831 }
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
832 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
833 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
834
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
835 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
836 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
837 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
838 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
839 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
840 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
841 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
842 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
843 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
844 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
845 *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
846 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
847 pop_view();
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
848 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
849 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
850 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
851 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
852 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
853
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
854 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
855 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
856 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
857 "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
858 "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
859 "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
860 "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
861 "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
862 "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
863 "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
864 "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
865 "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
866 "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
867 "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
868 "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
869 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
870 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
871 "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
872 "ui.reload",
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
873 "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
874 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
875 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
876 "ui.save_state",
2162
1270fe86eb89 Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents: 2156
diff changeset
877 "ui.load_state",
2306
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2299
diff changeset
878 "ui.menu",
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
879 "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
880 "ui.screenshot",
2306
62f316b76e9a Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents: 2299
diff changeset
881 "ui.exit",
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
882 "ui.release_mouse",
2528
90a40be940f7 Implement read-only SC-3000 cassette support
Michael Pavone <pavone@retrodev.com>
parents: 2484
diff changeset
883 "ui.toggle_keyboard_captured",
2530
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
884 "ui.vgm_log",
2528
90a40be940f7 Implement read-only SC-3000 cassette support
Michael Pavone <pavone@retrodev.com>
parents: 2484
diff changeset
885 "cassette.play",
90a40be940f7 Implement read-only SC-3000 cassette support
Michael Pavone <pavone@retrodev.com>
parents: 2484
diff changeset
886 "cassette.stop",
90a40be940f7 Implement read-only SC-3000 cassette support
Michael Pavone <pavone@retrodev.com>
parents: 2484
diff changeset
887 "cassette.rewind",
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
888 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
889 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
890 "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
891 "ui.vdp_debug_pal",
2530
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
892 "ui.enter_debugger",
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
893 "ui.plane_debug",
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
894 "ui.vram_debug",
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
895 "ui.cram_debug",
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
896 "ui.composite_debug",
231305069cbb Add some missing binding entries in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2528
diff changeset
897 "ui.oscilloscope"
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
898 };
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
899 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
900 "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
901 "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
902 "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
903 "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
904 "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
905 "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
906 "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
907 "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
908 "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
909 "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
910 "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
911 "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
912 };
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
913
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
914 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
915 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
916 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
917 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
918 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
919 bind_option_group(context, "Speed Control", speeds, sizeof(speeds)/sizeof(*speeds));
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
920
2311
07aeea6cb068 Fix analog stick UI for real. Allow clearing a controller binding
Michael Pavone <pavone@retrodev.com>
parents: 2310
diff changeset
921 nk_layout_row_static(context, context->style.font->height, (render_width() - 80)/4, 2);
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
922 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
923 pop_view();
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
924 }
2311
07aeea6cb068 Fix analog stick UI for real. Allow clearing a controller binding
Michael Pavone <pavone@retrodev.com>
parents: 2310
diff changeset
925 if (nk_button_label(context, "Clear")) {
07aeea6cb068 Fix analog stick UI for real. Allow clearing a controller binding
Michael Pavone <pavone@retrodev.com>
parents: 2310
diff changeset
926 *current_bind_dest = NULL;
07aeea6cb068 Fix analog stick UI for real. Allow clearing a controller binding
Michael Pavone <pavone@retrodev.com>
parents: 2310
diff changeset
927 controller_binding_changed = 1;
07aeea6cb068 Fix analog stick UI for real. Allow clearing a controller binding
Michael Pavone <pavone@retrodev.com>
parents: 2310
diff changeset
928 pop_view();
07aeea6cb068 Fix analog stick UI for real. Allow clearing a controller binding
Michael Pavone <pavone@retrodev.com>
parents: 2310
diff changeset
929 }
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
930 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
931 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
932 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
933
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
934 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
935 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
936 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
937 float row_height = font->height * 2;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
938
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
939 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
940 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
941 float max_width = 0.0f;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
942
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
943 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
944 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
945 {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
946 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
947 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
948 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
949 } else if (binds[i] & STICKDIR) {
2311
07aeea6cb068 Fix analog stick UI for real. Allow clearing a controller binding
Michael Pavone <pavone@retrodev.com>
parents: 2310
diff changeset
950 static char const * dirs[] = {"Down", "Up", "Right", "Left"};
1626
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
951 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
952 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
953 } else {
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
954 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
955 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
956 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
957 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
958 skipped++;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
959 continue;
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
960 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
961 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
962 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
963 }
2c3536082c0f Add new view for selecting a new binding for a gamepad button
Michael Pavone <pavone@retrodev.com>
parents: 1625
diff changeset
964 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
965 nk_group_begin(context, name, NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
966
2650
9263d064294c Fix binding buttons getting cutoff
Michael Pavone <pavone@retrodev.com>
parents: 2644
diff changeset
967 float widths[] = {max_width + 3, width - (max_width + 22)};
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
968 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
969 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
970 {
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
971 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
972 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
973 }
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
974 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
975 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
976 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
977 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
978 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
979 }
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
980 }
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 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
982 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
983 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
984 }
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
985
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
986 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
987 {
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
988 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
989 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
990 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
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 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
993 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
994 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
995 }
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
996 }
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
997
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
998 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
999 {
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
1000 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
1001 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
1002 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
1003 }
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
1004 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
1005 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
1006 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
1007 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
1008 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
1009 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
1010 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
1011 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
1012 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
1013 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
1014 } 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
1015 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
1016 }
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
1017 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
1018 {
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
1019 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
1020 case SDL_CONTROLLER_AXIS_LEFTY:
2311
07aeea6cb068 Fix analog stick UI for real. Allow clearing a controller binding
Michael Pavone <pavone@retrodev.com>
parents: 2310
diff changeset
1021 bindings->left_stick[(SDL_CONTROLLER_AXIS_LEFTY - axis) * 2 + is_negative] = val.ptrval;
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
1022 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
1023 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
1024 case SDL_CONTROLLER_AXIS_RIGHTY:
2313
ef5dc4d02d27 Fix goof in right analog stick mapping UI
Michael Pavone <pavone@retrodev.com>
parents: 2312
diff changeset
1025 bindings->right_stick[(SDL_CONTROLLER_AXIS_RIGHTY - axis) * 2 + is_negative] = val.ptrval;
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
1026 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
1027 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
1028 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
1029 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
1030 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
1031 }
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
1032 }
5e2af89c3467 Made controller binding page more resolution independent. Added binding boxes for all buttons/axes
Michael Pavone <pavone@retrodev.com>
parents: 1596
diff changeset
1033
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
1034 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
1035 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
1036 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
1037 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
1038 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
1039 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
1040 };
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
1041
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
1042 //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
1043 //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
1044 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
1045 "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
1046 "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
1047 "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
1048 "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
1049 "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
1050 "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
1051 "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
1052 "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
1053 };
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
1054
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
1055 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
1056 {
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
1057 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
1058 {
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
1059 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
1060 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
1061 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
1062 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
1063 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
1064 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
1065 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
1066 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
1067 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
1068 full_key[axes_key_size + prefix_len + 1 + suffix_len + 1] = 0;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1069
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
1070 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
1071 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
1072 } 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
1073 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
1074 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
1075 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
1076 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
1077 }
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
1078 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1079
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
1080 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
1081 }
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
1082 }
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
1083
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
1084 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
1085 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
1086 {
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
1087 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
1088 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
1089 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
1090 {
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
1091 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
1092 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
1093 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
1094 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
1095 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
1096 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
1097 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
1098 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
1099 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
1100 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
1101 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
1102 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
1103 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
1104 }
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
1105 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
1106 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
1107 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
1108 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
1109 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
1110 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
1111 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
1112 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
1113 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
1114 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
1115 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
1116 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
1117 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
1118 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
1119 memcpy(button_key + pad_key_size, button_base, sizeof(button_base));
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1120
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
1121 char *final_key;
2307
a8080240cb92 Fix silly bug I introduced when trying to fix the problem from the SDL2 upgrade
Michael Pavone <pavone@retrodev.com>
parents: 2306
diff changeset
1122 for (int i = 0; i < SDL_CONTROLLER_BUTTON_MAX; 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
1123 {
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
1124 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
1125 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
1126 size_t base_key_len;
2299
a1c9edf44c7e Fix a place I missed a problem from the SDL2 upgrade
Michael Pavone <pavone@retrodev.com>
parents: 2294
diff changeset
1127 if ( i < SDL_CONTROLLER_BUTTON_DPAD_UP || i > SDL_CONTROLLER_BUTTON_DPAD_RIGHT) {
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
1128 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
1129 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
1130 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
1131 } 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
1132 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
1133 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
1134 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
1135 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
1136 }
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
1137 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
1138 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
1139 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
1140 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
1141 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
1142 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
1143 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
1144 } 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
1145 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
1146 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
1147 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
1148 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
1149 }
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
1150 }
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
1151 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
1152 }
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
1153 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
1154 free(dpad_key);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1155
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
1156 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
1157 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
1158 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
1159 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
1160 memcpy(axes_key + pad_key_size, axes_base, sizeof(axes_base));
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1161
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
1162 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
1163 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
1164 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
1165 {
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
1166 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
1167 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
1168 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
1169 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
1170 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
1171 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
1172 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
1173 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
1174 } 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
1175 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
1176 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
1177 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
1178 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
1179 }
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
1180 }
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
1181 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
1182 }
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
1183 free(axes_key);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1184
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
1185 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
1186 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
1187 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
1188 }
2312
3f2ecd156453 Fix use after free when re-entering controller binding UI after saving bindings
Michael Pavone <pavone@retrodev.com>
parents: 2311
diff changeset
1189 free(bindings);
3f2ecd156453 Fix use after free when re-entering controller binding UI after saving bindings
Michael Pavone <pavone@retrodev.com>
parents: 2311
diff changeset
1190 bindings = NULL;
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
1191 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
1192 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
1193 }
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
1194
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
1195 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
1196 {
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
1197 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
1198 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
1199 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
1200 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
1201 options[SIMILAR_CONTROLLERS].title = make_human_readable_type_name(&selected_controller_info);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1202
2379
9e6cb50d0639 Fix accidental search and replace in UI code
Michael Pavone <pavone@retrodev.com>
parents: 2376
diff changeset
1203 if (nk_begin(context, "Select Binding Dest", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
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
1204 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
1205 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
1206 }
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
1207 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
1208 }
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
1209
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
1210 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
1211 {
2020
e42c45ff06d5 Add Genesis 6-button contoller image
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
1212 if (info->variant != VARIANT_NORMAL || info->type == TYPE_SEGA) {
e42c45ff06d5 Add Genesis 6-button contoller image
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
1213 if (info->type == TYPE_PSX) {
e42c45ff06d5 Add Genesis 6-button contoller image
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
1214 return controller_ps4_6b;
e42c45ff06d5 Add Genesis 6-button contoller image
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
1215 } else {
e42c45ff06d5 Add Genesis 6-button contoller image
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
1216 return controller_gen_6b;
e42c45ff06d5 Add Genesis 6-button contoller image
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
1217 }
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
1218 } 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
1219 return controller_ps4;
2003
4c418ee9a9d8 Added Wii U controller image
Mike Pavone <pavone@retrodev.com>
parents: 1980
diff changeset
1220 } else if (info->type == TYPE_NINTENDO) {
4c418ee9a9d8 Added Wii U controller image
Mike Pavone <pavone@retrodev.com>
parents: 1980
diff changeset
1221 return controller_wiiu;
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
1222 } 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
1223 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
1224 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1225 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
1226
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
1227 void view_controller_bindings(struct nk_context *context)
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1228 {
2379
9e6cb50d0639 Fix accidental search and replace in UI code
Michael Pavone <pavone@retrodev.com>
parents: 2376
diff changeset
1229 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
1230 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
1231 bindings = calloc(1, sizeof(*bindings));
2317
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1232 tern_node *pad = get_binding_node_for_pad(selected_controller, &selected_controller_info);
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
1233 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
1234 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
1235 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
1236 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
1237 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
1238 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
1239 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
1240 {
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
1241 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
1242 }
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
1243 }
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
1244 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1245
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
1246 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
1247 def_font->handle.height *= 0.5f;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1248
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
1249 uint32_t avail_height = render_height() - 2 * orig_height;
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1250 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
1251 ui_image *controller_image = select_best_image(&selected_controller_info);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1252
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
1253 float controller_ratio = (float)controller_image->width / (float)controller_image->height;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1254
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
1255 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
1256 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
1257 + def_font->handle.width(font->userdata, font->height, "Internal Screenshot", strlen("Internal Screenshot"));
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1258
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1259 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
1260 desired_width = render_width() - 2.5f*MIN_BIND_BOX_WIDTH;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1261 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1262
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1263 if (desired_width / desired_height > controller_ratio) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1264 desired_width = desired_height * controller_ratio;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1265 } else {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1266 desired_height = desired_width / controller_ratio;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1267 }
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1268 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
1269 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
1270 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
1271 float img_bot = img_top + desired_height;
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1272 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
1273 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
1274 nk_image(context, controller_image->ui);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1275
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1276 float bind_box_width = (render_width() - img_right) * 0.8f;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1277 if (bind_box_width < MIN_BIND_BOX_WIDTH) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1278 bind_box_width = render_width() - img_right;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1279 if (bind_box_width > MIN_BIND_BOX_WIDTH) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1280 bind_box_width = MIN_BIND_BOX_WIDTH;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1281 }
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1282 } else if (bind_box_width > MAX_BIND_BOX_WIDTH) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1283 bind_box_width = MAX_BIND_BOX_WIDTH;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1284 }
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1285 float bind_box_left;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1286 if (bind_box_width >= (render_width() - img_right)) {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1287 bind_box_left = img_right;
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1288 } else {
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1289 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
1290 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1291
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1292 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
1293 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
1294 SDL_CONTROLLER_BUTTON_A,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1295 SDL_CONTROLLER_BUTTON_B,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1296 SDL_CONTROLLER_BUTTON_X,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1297 SDL_CONTROLLER_BUTTON_Y
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1298 });
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1299 } else {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1300 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
1301 SDL_CONTROLLER_BUTTON_A,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1302 SDL_CONTROLLER_BUTTON_B,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1303 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
1304 SDL_CONTROLLER_BUTTON_X,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1305 SDL_CONTROLLER_BUTTON_Y,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1306 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
1307 });
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1308 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1309
1816
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1310 if (selected_controller_info.variant == VARIANT_NORMAL) {
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1311 binding_box(context, bindings, "Right Shoulder", bind_box_left, font->height/2, bind_box_width, 2, (int[]){
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1312 SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1313 AXIS | SDL_CONTROLLER_AXIS_TRIGGERRIGHT
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1314 });
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1315 } else {
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1316 binding_box(context, bindings, "Right Shoulder", bind_box_left, font->height/2, bind_box_width,
2219
ff700f50541c Fix duplicated right trigger mapping button in bindings for 8-button Genesis style controllers
Michael Pavone <pavone@retrodev.com>
parents: 2202
diff changeset
1317 selected_controller_info.variant == VARIANT_6B_RIGHT ? 2 : 1,
1816
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1318 (int[]){
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1319 selected_controller_info.variant == VARIANT_6B_RIGHT ? SDL_CONTROLLER_BUTTON_LEFTSHOULDER : AXIS | SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1320 AXIS | SDL_CONTROLLER_AXIS_TRIGGERLEFT
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1321 });
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1322 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1323
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
1324 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
1325 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
1326 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
1327 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
1328 });
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1329
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1330 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
1331 {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1332 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
1333 RIGHTSTICK | UP,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1334 RIGHTSTICK | DOWN,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1335 RIGHTSTICK | LEFT,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1336 RIGHTSTICK | RIGHT,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1337 SDL_CONTROLLER_BUTTON_RIGHTSTICK
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1338 });
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1339 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1340
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1341 bind_box_left -= img_right;
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1342 float dpad_left, dpad_top;
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1343 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
1344 {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1345 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
1346 LEFTSTICK | UP,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1347 LEFTSTICK | DOWN,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1348 LEFTSTICK | LEFT,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1349 LEFTSTICK | RIGHT,
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1350 SDL_CONTROLLER_BUTTON_LEFTSTICK
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1351 });
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1352 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
1353 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
1354 } else {
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1355 dpad_left = bind_box_left;
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1356 dpad_top = img_top;
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1357 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1358
1816
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1359 if (selected_controller_info.variant == VARIANT_NORMAL) {
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1360 binding_box(context, bindings, "Left Shoulder", bind_box_left, font->height/2, bind_box_width, 2, (int[]){
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1361 SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1362 AXIS | SDL_CONTROLLER_AXIS_TRIGGERLEFT
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1363 });
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1364 } else {
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1365 binding_box(context, bindings, "Left Shoulder", bind_box_left, font->height/2, bind_box_width,
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1366 selected_controller_info.variant == VARIANT_6B_BUMPERS ? 1 : 2,
1816
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1367 (int[]){
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1368 selected_controller_info.variant == VARIANT_6B_RIGHT ? SDL_CONTROLLER_BUTTON_LEFTSTICK : AXIS | SDL_CONTROLLER_AXIS_TRIGGERLEFT,
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1369 SDL_CONTROLLER_BUTTON_RIGHTSTICK
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1370 });
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1371 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1372
1647
5a662692c215 Update binding UI for non-standard controller layouts
Michael Pavone <pavone@retrodev.com>
parents: 1646
diff changeset
1373 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
1374 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
1375 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
1376 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
1377 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
1378 });
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1379
1571
3def7b216a5b WIP controller binding view
Michael Pavone <pavone@retrodev.com>
parents: 1570
diff changeset
1380 nk_layout_space_end(context);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1381
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
1382 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
1383 nk_layout_row_static(context, orig_height + 4, (render_width() - 2*orig_height) / 4, 1);
1816
1db1510c7506 Fix bumper/trigger binding boxes for "normal" style conntrollers. Change label of "Back" button to "Save" when there are unsaved changes in controller binding
Mike Pavone <pavone@retrodev.com>
parents: 1815
diff changeset
1384 if (nk_button_label(context, controller_binding_changed ? "Save" : "Back")) {
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
1385 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
1386 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
1387 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
1388 }
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
1389 }
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
1390 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
1391 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
1392 }
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1393
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
1394 static int current_button;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1395 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
1396 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
1397 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
1398 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
1399 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
1400 static size_t mapping_pos;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1401
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1402 static void start_mapping(void)
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1403 {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1404 const char *name;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1405 mapping_string[mapping_pos++] = ',';
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1406 if (current_button != SDL_CONTROLLER_BUTTON_MAX) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1407 name = SDL_GameControllerGetStringForButton(current_button);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1408 } else {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1409 name = SDL_GameControllerGetStringForAxis(current_axis);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1410 }
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1411 size_t namesz = strlen(name);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1412 memcpy(mapping_string + mapping_pos, name, namesz);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1413 mapping_pos += namesz;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1414 mapping_string[mapping_pos++] = ':';
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1415 }
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1416
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1417 static uint8_t initial_controller_config;
1605
f7b1d983d5c0 Bump up pause between mapping inputs
Michael Pavone <pavone@retrodev.com>
parents: 1604
diff changeset
1418 #define QUIET_FRAMES 9
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1419 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
1420 {
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1421 char buffer[512];
2678
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
1422 static int button_a = -1, button_a_axis = -1;
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
1423 static uint32_t quiet_start;
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
1424 uint8_t added_mapping = 0;
2379
9e6cb50d0639 Fix accidental search and replace in UI code
Michael Pavone <pavone@retrodev.com>
parents: 2376
diff changeset
1425 if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1426
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1427 nk_layout_space_begin(context, NK_STATIC, render_height() - context->style.font->height, 3);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1428
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1429 if (current_button < SDL_CONTROLLER_BUTTON_MAX) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1430 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
1431 } else {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1432 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
1433 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1434
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1435 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
1436 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
1437 float width = render_width() - context->style.font->height;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1438
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1439 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
1440 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
1441 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
1442 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
1443 nk_label(context, "OR", NK_TEXT_CENTERED);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1444
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1445 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
1446 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
1447 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
1448 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1449
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1450 nk_layout_space_end(context);
2678
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
1451 if (quiet_start) {
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
1452 if (render_elapsed_ms() - quiet_start > 1000 * QUIET_FRAMES / 60) {
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
1453 quiet_start = 0;
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
1454 }
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1455 } else {
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1456 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
1457 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
1458 start_mapping();
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1459 mapping_string[mapping_pos++] = 'b';
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1460 if (button_pressed > 9) {
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1461 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
1462 }
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1463 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
1464 last_button = button_pressed;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1465 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
1466 button_a = button_pressed;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1467 }
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1468 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1469 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
1470 } 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
1471 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
1472 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
1473 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
1474 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
1475 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
1476 added_mapping = 1;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1477
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1478 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
1479 last_hat_value = hat_value;
2319
ab3d8759da08 Slightly more reasonable threshold value for axes during mapping. Still pretty broken though
Michael Pavone <pavone@retrodev.com>
parents: 2317
diff changeset
1480 } else if (axis_moved >= 0 && abs(axis_value) > 4000 && (
1804
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1481 axis_moved != last_axis || (
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1482 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
1483 )
34370330eaf3 Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents: 1798
diff changeset
1484 )) {
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1485 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
1486 start_mapping();
2022
380bc5d4a2cf Fix format of axis mapping strings for axes that map to a d-pad
Michael Pavone <pavone@retrodev.com>
parents: 2020
diff changeset
1487 if (current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP) {
380bc5d4a2cf Fix format of axis mapping strings for axes that map to a d-pad
Michael Pavone <pavone@retrodev.com>
parents: 2020
diff changeset
1488 mapping_string[mapping_pos++] = axis_value >= 0 ? '+' : '-';
380bc5d4a2cf Fix format of axis mapping strings for axes that map to a d-pad
Michael Pavone <pavone@retrodev.com>
parents: 2020
diff changeset
1489 }
1666
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1490 mapping_string[mapping_pos++] = 'a';
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1491 if (axis_moved > 9) {
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1492 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
1493 }
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1494 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
1495 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
1496 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
1497 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1498 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
1499 }
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1500 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1501
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
1502 while (added_mapping) {
2678
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
1503 quiet_start = render_elapsed_ms();
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1504 if (current_button < SDL_CONTROLLER_BUTTON_MAX) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1505 current_button++;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1506 if (current_button == SDL_CONTROLLER_BUTTON_MAX) {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1507 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
1508 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
1509 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
1510 }
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
1511 } 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
1512 added_mapping = 0;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1513 }
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1514 } else {
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1515 current_axis++;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1516 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
1517 button_a = -1;
a1e0ed70ad82 Allow skipping buttons/axes in controller SDL2 mapping UI
Mike Pavone <pavone@retrodev.com>
parents: 1664
diff changeset
1518 button_a_axis = -1;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1519 mapping_string[mapping_pos] = 0;
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1520 save_controller_mapping(selected_controller, mapping_string);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1521 free(mapping_string);
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1522 pop_view();
2627
df6dbf229e2f Prevent gamepad binds from firing while remapping a gamepad
Michael Pavone <pavone@retrodev.com>
parents: 2623
diff changeset
1523 bindings_set_joy_state(selected_controller, 1);
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1524 if (initial_controller_config) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1525 push_view(view_controller_bindings);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1526 controller_binding_changed = 0;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1527 }
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
1528 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
1529 } 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
1530 added_mapping = 0;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1531 }
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
1532 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1533 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1534 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
1535 hat_moved = -1;
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
1536 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
1537 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
1538 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1539 }
7f39c40b4b25 WIP UI for creating an SDL2 mapping for controllers that don't have one
Michael Pavone <pavone@retrodev.com>
parents: 1599
diff changeset
1540
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1541 static void show_mapping_view(void)
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1542 {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1543 current_button = SDL_CONTROLLER_BUTTON_A;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1544 button_pressed = -1;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1545 last_button = -1;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1546 last_hat = -1;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1547 axis_moved = -1;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1548 last_axis = -1;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1549 last_axis_value = 0;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1550 SDL_Joystick *joy = render_get_joystick(selected_controller);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1551 const char *name = SDL_JoystickName(joy);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1552 size_t namesz = strlen(name);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1553 mapping_string = malloc(512 + namesz);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1554 for (mapping_pos = 0; mapping_pos < namesz; mapping_pos++)
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1555 {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1556 char c = name[mapping_pos];
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1557 if (c == ',' || c == '\n' || c == '\r') {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1558 c = ' ';
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1559 }
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1560 mapping_string[mapping_pos] = c;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1561 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1562
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1563 push_view(view_controller_mappings);
2627
df6dbf229e2f Prevent gamepad binds from firing while remapping a gamepad
Michael Pavone <pavone@retrodev.com>
parents: 2623
diff changeset
1564 bindings_set_joy_state(selected_controller, 0);
df6dbf229e2f Prevent gamepad binds from firing while remapping a gamepad
Michael Pavone <pavone@retrodev.com>
parents: 2623
diff changeset
1565
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1566 }
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1567
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1568 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
1569 {
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1570 uint8_t selected = 0;
2379
9e6cb50d0639 Fix accidental search and replace in UI code
Michael Pavone <pavone@retrodev.com>
parents: 2376
diff changeset
1571 if (nk_begin(context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 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
1572 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
1573 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
1574 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
1575 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
1576 nk_label(context, "", NK_TEXT_CENTERED);
2015
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1577 if (selected_controller_info.subtype == SUBTYPE_GENESIS) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1578 if (nk_button_label(context, "3 button")) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1579 selected_controller_info.variant = VARIANT_3BUTTON;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1580 selected = 1;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1581 }
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1582 if (nk_button_label(context, "Standard 6 button")) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1583 selected_controller_info.variant = VARIANT_6B_BUMPERS;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1584 selected = 1;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1585 }
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1586 if (nk_button_label(context, "6 button with 2 shoulder buttons")) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1587 selected_controller_info.variant = VARIANT_8BUTTON;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1588 selected = 1;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1589 }
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1590 } else {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1591 if (nk_button_label(context, "4 face buttons")) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1592 selected_controller_info.variant = VARIANT_NORMAL;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1593 selected = 1;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1594 }
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1595 char buffer[512];
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1596 snprintf(buffer, sizeof(buffer), "6 face buttons including %s and %s",
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1597 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER),
2015
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1598 get_axis_label(&selected_controller_info, SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1599 );
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1600 if (nk_button_label(context, buffer)) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1601 selected_controller_info.variant = VARIANT_6B_RIGHT;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1602 selected = 1;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1603 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1604 snprintf(buffer, sizeof(buffer), "6 face buttons including %s and %s",
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1605 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_LEFTSHOULDER),
2015
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1606 get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1607 );
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1608 if (nk_button_label(context, buffer)) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1609 selected_controller_info.variant = VARIANT_6B_BUMPERS;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1610 selected = 1;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1611 }
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1612 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1613 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
1614 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1615 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
1616 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
1617 pop_view();
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1618 if (initial_controller_config) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1619 SDL_GameController *controller = render_get_controller(selected_controller);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1620 if (controller) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1621 push_view(view_controller_bindings);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1622 controller_binding_changed = 0;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1623 SDL_GameControllerClose(controller);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1624 } else {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1625 show_mapping_view();
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
1626 }
1602
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1627 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1628 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1629 }
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1630
b452887f85b4 Basic UI for selecting layout variants + minor fix to SDL2 mapping generation UI
Michael Pavone <pavone@retrodev.com>
parents: 1601
diff changeset
1631 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
1632 {
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
1633 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
1634 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
1635 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
1636 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
1637 {
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
1638 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
1639 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
1640 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
1641 pop_view();
2015
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1642 if (selected_controller_info.subtype == SUBTYPE_SATURN) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1643 selected_controller_info.variant = VARIANT_6B_BUMPERS;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1644 save_controller_info(selected_controller, &selected_controller_info);
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1645 if (initial_controller_config) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1646 SDL_GameController *controller = render_get_controller(selected_controller);
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1647 if (controller) {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1648 push_view(view_controller_bindings);
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1649 controller_binding_changed = 0;
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1650 SDL_GameControllerClose(controller);
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1651 } else {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1652 show_mapping_view();
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1653 }
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1654 }
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1655 } else {
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1656 push_view(view_controller_variant);
8a64d86cc362 Use different variants for Genesis controllers to better represent what types are out there
Michael Pavone <pavone@retrodev.com>
parents: 2014
diff changeset
1657 }
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
1658 }
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
1659 }
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
1660 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
1661 }
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
1662 }
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
1663
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
1664 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
1665 {
2379
9e6cb50d0639 Fix accidental search and replace in UI code
Michael Pavone <pavone@retrodev.com>
parents: 2376
diff changeset
1666 if (nk_begin(context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 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
1667 controller_type_group(context, "Xbox", TYPE_XBOX, SUBTYPE_XBOX, (const char *[]){
2220
dd9d43c67986 Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents: 2219
diff changeset
1668 "Original", "Xbox 360", "Xbox One/Series", "Xbox Elite"
dd9d43c67986 Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents: 2219
diff changeset
1669 }, 4);
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
1670 controller_type_group(context, "Playstation", TYPE_PSX, SUBTYPE_PS3, (const char *[]){
2220
dd9d43c67986 Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents: 2219
diff changeset
1671 "PS3", "PS4", "PS5"
dd9d43c67986 Add support for newer controller types. Fix crash caused by new controller button types introduced in 2.0.12 and support mapping them
Michael Pavone <pavone@retrodev.com>
parents: 2219
diff changeset
1672 }, 3);
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
1673 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
1674 "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
1675 }, 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
1676 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
1677 "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
1678 }, 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
1679 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
1680 }
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
1681 }
2317
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1682 static uint8_t stick_nav_disabled;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1683 static SDL_GameController *current_controller;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1684 static uint8_t deadzones_dirty;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1685 void stick_deadzone_widget(float left, float top, float size, SDL_GameControllerAxis x_axis)
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1686 {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1687 float crosshair_size = context->style.font->height;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1688 nk_stroke_rect(&context->current->buffer, nk_rect(left, top, size, size), context->style.window.rounding, context->style.window.border, nk_rgb(255, 255, 255));
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1689 float deadzone_size = selected_controller_info.stick_deadzone * size / 65535.0f;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1690 int16_t raw_x = SDL_GameControllerGetAxis(current_controller, x_axis);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1691 int16_t raw_y = SDL_GameControllerGetAxis(current_controller, x_axis + 1);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1692 if (raw_x > selected_controller_info.stick_deadzone) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1693 float points[] = {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1694 left + size * 0.5f + deadzone_size, top + size * 0.5f - deadzone_size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1695 left + size, top,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1696 left + size, top + size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1697 left + size * 0.5f + deadzone_size, top + size * 0.5f + deadzone_size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1698 };
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1699 nk_fill_polygon(&context->current->buffer, points, sizeof(points)/(2 * sizeof(float)), context->style.checkbox.cursor_normal.data.color);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1700 } else if (raw_x < -selected_controller_info.stick_deadzone) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1701 float points[] = {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1702 left, top,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1703 left + size * 0.5f - deadzone_size, top + size * 0.5f - deadzone_size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1704 left + size * 0.5f - deadzone_size, top + size * 0.5f + deadzone_size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1705 left, top + size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1706 };
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1707 nk_fill_polygon(&context->current->buffer, points, sizeof(points)/(2 * sizeof(float)), context->style.checkbox.cursor_normal.data.color);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1708 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1709 if (raw_y > selected_controller_info.stick_deadzone) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1710 float points[] = {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1711 left, top + size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1712 left + size, top + size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1713 left + size * 0.5f + deadzone_size, top + size * 0.5f + deadzone_size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1714 left + size * 0.5f - deadzone_size, top + size * 0.5f + deadzone_size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1715 };
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1716 nk_fill_polygon(&context->current->buffer, points, sizeof(points)/(2 * sizeof(float)), context->style.checkbox.cursor_normal.data.color);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1717 } else if (raw_y < -selected_controller_info.stick_deadzone) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1718 float points[] = {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1719 left, top,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1720 left + size, top,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1721 left + size * 0.5f + deadzone_size, top + size * 0.5f - deadzone_size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1722 left + size * 0.5f - deadzone_size, top + size * 0.5f - deadzone_size,
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1723 };
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1724 nk_fill_polygon(&context->current->buffer, points, sizeof(points)/(2 * sizeof(float)), context->style.checkbox.cursor_normal.data.color);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1725 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1726 nk_stroke_rect(&context->current->buffer, nk_rect(left + 0.5f * size - deadzone_size, top + 0.5f * size - deadzone_size, 2 * deadzone_size, 2 * deadzone_size), context->style.window.rounding, 0.5f * context->style.window.border, nk_rgb(200, 200, 200));
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1727 //nk_layout_space_push(context, nk_rect(left, top, size, size));
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1728 float x = raw_x * size / 65535.0f + size / 2.0f - crosshair_size / 2.0f;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1729 float y = raw_y * size / 65535.0f + size / 2.0f - crosshair_size / 2.0f;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1730 nk_draw_symbol(&context->current->buffer, NK_SYMBOL_X, nk_rect(left + x, top + y, crosshair_size, crosshair_size), nk_rgb(0, 0, 0), nk_rgb(255, 255, 255), 1, context->style.font);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1731 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1732
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1733 void trigger_deadzone_widget(float left, float top, float size, SDL_GameControllerAxis axis)
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1734 {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1735 float crosshair_size = context->style.font->height;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1736 nk_stroke_rect(&context->current->buffer, nk_rect(left, top, size, crosshair_size * 1.5f), context->style.window.rounding, context->style.window.border, nk_rgb(255, 255, 255));
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1737 float deadzone_size = selected_controller_info.trigger_deadzone * size / 32767.0f;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1738 int16_t raw = SDL_GameControllerGetAxis(current_controller, axis);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1739 if (raw < 0) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1740 raw = 0;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1741 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1742 if (raw > selected_controller_info.trigger_deadzone) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1743 nk_fill_rect(&context->current->buffer, nk_rect(left + deadzone_size, top, size - deadzone_size, 1.5f * crosshair_size), context->style.window.rounding, context->style.checkbox.cursor_normal.data.color);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1744 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1745 nk_stroke_line(&context->current->buffer, left + deadzone_size, top, left + deadzone_size, top + 1.5f * crosshair_size, 0.5f * context->style.window.border, nk_rgb(200, 200, 200));
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1746 float x = raw * size / 32767.0f - crosshair_size / 2.0f;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1747 nk_draw_symbol(&context->current->buffer, NK_SYMBOL_X, nk_rect(left + x, top + 0.25f * crosshair_size, crosshair_size, crosshair_size), nk_rgb(0, 0, 0), nk_rgb(255, 255, 255), 1, context->style.font);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1748 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1749
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1750 void view_deadzones(struct nk_context *context)
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1751 {
2379
9e6cb50d0639 Fix accidental search and replace in UI code
Michael Pavone <pavone@retrodev.com>
parents: 2376
diff changeset
1752 if (nk_begin(context, "Deadzones", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
2317
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1753 nk_layout_space_begin(context, NK_STATIC, render_height() - 3 * context->style.font->height, 4);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1754
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1755 float left = render_width() / 8.0f, top = render_height() / 8.0f;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1756 float size = render_height() / 3.0f;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1757 stick_deadzone_widget(left, top, size, SDL_CONTROLLER_AXIS_LEFTX);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1758 stick_deadzone_widget(left + 1.25f * size, top, size, SDL_CONTROLLER_AXIS_RIGHTX);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1759
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1760 top += size + context->style.font->height;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1761 nk_layout_space_push(context, nk_rect(left, top, size * 2, context->style.font->height));
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1762 int val = selected_controller_info.stick_deadzone;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1763 nk_property_int(context, "Stick Deadzone", 250, &val, 32000, 250, 1.0f);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1764 if (val != selected_controller_info.stick_deadzone) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1765 selected_controller_info.stick_deadzone = val;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1766 deadzones_dirty = 1;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1767 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1768
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1769 top += 2.0f * context->style.font->height;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1770 trigger_deadzone_widget(left, top, size, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1771 trigger_deadzone_widget(left + 1.25f * size, top, size, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1772
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1773 top += context->style.font->height * 2.5f;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1774 nk_layout_space_push(context, nk_rect(left, top, size * 2, context->style.font->height));
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1775 val = selected_controller_info.trigger_deadzone;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1776 nk_property_int(context, "Trigger Deadzone", 250, &val, 32000, 250, 1.0f);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1777 if (val != selected_controller_info.trigger_deadzone) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1778 selected_controller_info.trigger_deadzone = val;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1779 deadzones_dirty = 1;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1780 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1781
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1782 nk_layout_space_end(context);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1783
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1784 nk_layout_row_static(context, context->style.font->height, (render_width() - 2 * context->style.font->height) / 2, 2);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1785 if (nk_button_label(context, "Back")) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1786 stick_nav_disabled = 0;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1787 if (current_controller) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1788 SDL_GameControllerClose(current_controller);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1789 current_controller = NULL;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1790 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1791 if (deadzones_dirty) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1792 save_controller_info(selected_controller, &selected_controller_info);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1793 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1794 pop_view();
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1795 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1796 nk_end(context);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1797 }
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1798 }
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
1799
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
1800 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
1801 {
2379
9e6cb50d0639 Fix accidental search and replace in UI code
Michael Pavone <pavone@retrodev.com>
parents: 2376
diff changeset
1802 if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1803 int height = (render_height() - 2*context->style.font->height) / 5;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1804 int inner_height = height - context->style.window.spacing.y;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1805 const struct nk_user_font *font = context->style.font;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1806 int bindings_width = font->width(font->userdata, font->height, "Bindings", strlen("Bindings")) + context->style.button.padding.x * 2;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1807 int remap_width = font->width(font->userdata, font->height, "Remap", strlen("Remap")) + context->style.button.padding.x * 2;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1808 int change_type_width = font->width(font->userdata, font->height, "Change Type", strlen("Change Type")) + context->style.button.padding.x * 2;
2317
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1809 int deadzones_width = font->width(font->userdata, font->height, "Deadzones", strlen("Deadzones")) + context->style.button.padding.x * 2;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1810 int total = bindings_width + remap_width + change_type_width + deadzones_width;
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1811 float bindings_ratio = (float)bindings_width / total;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1812 float remap_ratio = (float)remap_width / total;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1813 float change_type_ratio = (float)change_type_width / total;
2317
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1814 float deadzones_ratio = (float)deadzones_width / total;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1815
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1816
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1817 uint8_t found_controller = 0;
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
1818 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
1819 {
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
1820 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
1821 if (joy) {
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1822 found_controller = 1;
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
1823 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
1824 ui_image *controller_image = select_best_image(&info);
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1825 int image_width = inner_height * controller_image->width / controller_image->height;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1826 nk_layout_space_begin(context, NK_STATIC, height, INT_MAX);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1827 nk_layout_space_push(context, nk_rect(context->style.font->height / 2, 0, image_width, inner_height));
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
1828 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
1829 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
1830 } 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
1831 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
1832 }
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1833 int button_start = image_width + context->style.font->height;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1834 int button_area_width = render_width() - image_width - 2 * context->style.font->height;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1835
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1836 nk_layout_space_push(context, nk_rect(button_start, 0, button_area_width, inner_height/2));
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1837 nk_label(context, info.name, NK_TEXT_CENTERED);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1838 const struct nk_user_font *font = context->style.font;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1839 if (info.type == TYPE_UNKNOWN || info.type == TYPE_GENERIC_MAPPING) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1840 int button_width = font->width(font->userdata, font->height, "Configure", strlen("Configure"));
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1841 nk_layout_space_push(context, nk_rect(button_start, height/2, button_width, inner_height/2));
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1842 if (nk_button_label(context, "Configure")) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1843 selected_controller = i;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1844 selected_controller_info = info;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1845 initial_controller_config = 1;
1599
1fc61c844ec5 Allow selecting controller type when controllers have an SDL 2 mapping, but heuristics fail to idenify details
Michael Pavone <pavone@retrodev.com>
parents: 1598
diff changeset
1846 push_view(view_controller_type);
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1847 }
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1848 } else {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1849 button_area_width -= 2 * context->style.window.spacing.x;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1850 bindings_width = bindings_ratio * button_area_width;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1851 nk_layout_space_push(context, nk_rect(button_start, height/2, bindings_width, inner_height/2));
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1852 if (nk_button_label(context, "Bindings")) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1853 selected_controller = i;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1854 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
1855 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
1856 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
1857 }
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1858 button_start += bindings_width + context->style.window.spacing.x;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1859 remap_width = remap_ratio * button_area_width;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1860 nk_layout_space_push(context, nk_rect(button_start, height/2, remap_width, inner_height/2));
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1861 if (nk_button_label(context, "Remap")) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1862 selected_controller = i;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1863 selected_controller_info = info;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1864 initial_controller_config = 0;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1865 show_mapping_view();
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1866 }
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1867 button_start += remap_width + context->style.window.spacing.x;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1868 change_type_width = change_type_ratio * button_area_width;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1869 nk_layout_space_push(context, nk_rect(button_start, height/2, change_type_width, inner_height/2));
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1870 if (nk_button_label(context, "Change Type")) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1871 selected_controller = i;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1872 selected_controller_info = info;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1873 initial_controller_config = 0;
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1874 push_view(view_controller_type);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1875 }
2317
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1876 button_start += change_type_width + context->style.window.spacing.x;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1877 deadzones_width = deadzones_ratio * button_area_width;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1878 nk_layout_space_push(context, nk_rect(button_start, height/2, deadzones_width, inner_height/2));
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1879 if (nk_button_label(context, "Deadzones")) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1880 selected_controller = i;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1881 selected_controller_info = info;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1882 current_controller = render_get_controller(i);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1883 stick_nav_disabled = 1;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1884 deadzones_dirty = 0;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1885 push_view(view_deadzones);
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1886 }
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
1887 }
2317
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
1888 nk_layout_space_end(context);
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
1889 }
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
1890 }
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1891 if (!found_controller) {
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1892 nk_layout_row_static(context, context->style.font->height, render_width() - 2 * context->style.font->height, 1);
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1893 nk_label(context, "No controllers detected", NK_TEXT_CENTERED);
2628
32ce6c588bc9 Add some hint test for web since controllers are hidden for anti-fingerprinting reasons
Michael Pavone <pavone@retrodev.com>
parents: 2627
diff changeset
1894 #ifdef __EMSCRIPTEN__
32ce6c588bc9 Add some hint test for web since controllers are hidden for anti-fingerprinting reasons
Michael Pavone <pavone@retrodev.com>
parents: 2627
diff changeset
1895 nk_label(context, "You must press a button on the controller", NK_TEXT_CENTERED);
32ce6c588bc9 Add some hint test for web since controllers are hidden for anti-fingerprinting reasons
Michael Pavone <pavone@retrodev.com>
parents: 2627
diff changeset
1896 nk_label(context, "before it will be shown here", NK_TEXT_CENTERED);
32ce6c588bc9 Add some hint test for web since controllers are hidden for anti-fingerprinting reasons
Michael Pavone <pavone@retrodev.com>
parents: 2627
diff changeset
1897 #endif
1859
52f136052ab0 Allow changing SDL2 mapping and controller type after initial configuration
Michael Pavone <pavone@retrodev.com>
parents: 1858
diff changeset
1898 }
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
1899 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
1900 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
1901 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
1902 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
1903 }
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
1904 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
1905 }
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
1906 }
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
1907
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1908 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
1909 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1910 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
1911 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1912 uint8_t newval = nk_check_label(context, "", curval);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1913 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
1914 config_dirty = 1;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1915 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
1916 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1917 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1918
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1919 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
1920 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1921 char buffer[12];
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1922 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1923 uint32_t curval;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1924 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
1925 uint32_t len = strlen(curstr);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1926 if (len > 11) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1927 len = 11;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1928 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1929 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
1930 memset(buffer+len, 0, sizeof(buffer)-len);
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1931 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
1932 buffer[len] = 0;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1933 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
1934 config_dirty = 1;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1935 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
1936 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1937 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1938
1853
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1939 void settings_string(struct nk_context *context, char *label, char *path, char *def)
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1940 {
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1941 nk_label(context, label, NK_TEXT_LEFT);
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1942 char *curstr = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval;
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1943 uint32_t len = strlen(curstr);
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1944 uint32_t buffer_len = len > 100 ? len + 1 : 101;
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1945 char *buffer = malloc(buffer_len);
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1946 memcpy(buffer, curstr, len);
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1947 memset(buffer+len, 0, buffer_len-len);
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1948 nk_edit_string(context, NK_EDIT_SIMPLE, buffer, &len, buffer_len-1, nk_filter_default);
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1949 buffer[len] = 0;
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1950 if (strcmp(buffer, curstr)) {
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1951 config_dirty = 1;
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1952 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR);
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1953 }
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1954 free(buffer);
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1955 }
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
1956
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1957 void settings_path(struct nk_context *context, char *label, char *path, char *def, const char **exts, uint32_t num_exts)
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1958 {
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1959 nk_label(context, label, NK_TEXT_LEFT);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1960 char *curstr = tern_find_path_default(config, path, (tern_val){.ptrval = def}, TVAL_PTR).ptrval;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1961 uint32_t len = strlen(curstr);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1962 uint32_t buffer_len = len > 100 ? len + 1 : 101;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1963 char *buffer = malloc(buffer_len);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1964 memcpy(buffer, curstr, len);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1965 memset(buffer+len, 0, buffer_len-len);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1966 nk_edit_string(context, NK_EDIT_SIMPLE, buffer, &len, buffer_len-1, nk_filter_default);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1967 buffer[len] = 0;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1968 if (strcmp(buffer, curstr)) {
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1969 config_dirty = 1;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1970 config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1971 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
1972
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1973 nk_spacing(context, 1);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1974 if (nk_button_label(context, "Browse")) {
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1975 browser_label = label;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1976 browser_setting_path = path;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1977 browser_ext_list = exts;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1978 browser_num_exts = num_exts;
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1979 if (is_absolute_path(buffer)) {
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1980 browser_cur_path = path_dirname(buffer);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1981 }
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1982 push_view(view_file_settings);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1983 }
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1984 free(buffer);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1985 }
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
1986
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1987 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
1988 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1989 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
1990 int curval = curstr ? atoi(curstr) : def;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1991 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1992 int val = curval;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1993 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
1994 if (val != curval) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1995 char buffer[12];
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1996 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
1997 config_dirty = 1;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
1998 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
1999 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2000 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2001
1796
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2002 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
2003 {
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2004 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
2005 float curval = curstr ? atof(curstr) : def;
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2006 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
2007 float val = curval;
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2008 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
2009 if (val != curval) {
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2010 char buffer[64];
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2011 sprintf(buffer, "%f", val);
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2012 config_dirty = 1;
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2013 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
2014 }
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2015 }
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1790
diff changeset
2016
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2017 typedef struct {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2018 char *fragment;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2019 char *vertex;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2020 } shader_prog;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2021
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2022 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
2023 {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2024 uint32_t num_progs = *num_existing;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2025 uint32_t prog_storage = *storage;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2026 uint32_t starting = num_progs;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2027
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2028 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
2029 if (entries[i].is_dir) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2030 continue;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2031 }
2484
ccee8dccd9cc Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
2032 if (startswith(entries[i].name, "extra_window.")) {
ccee8dccd9cc Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
2033 //skip shader used for debug windows
ccee8dccd9cc Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
2034 continue;
ccee8dccd9cc Add support for rendering debug windows with OpenGL in perparation for allowing Nuklear UI in them
Michael Pavone <pavone@retrodev.com>
parents: 2413
diff changeset
2035 }
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2036 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
2037 uint32_t len = strlen(no_ext);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2038 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
2039 uint8_t dupe = 0;;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2040 for (uint32_t j = 0; j < starting; j++) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2041 if (!strcmp(entries[i].name, progs[j].fragment)) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2042 dupe = 1;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2043 break;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2044 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2045 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2046 if (!dupe) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2047 if (num_progs == prog_storage) {
1493
24f44f26b74d Fix buffer overrun in video settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1492
diff changeset
2048 prog_storage = prog_storage ? prog_storage*2 : 4;
1857
1844cf5a4045 Fix buffer overrun in shader list UI
Michael Pavone <pavone@retrodev.com>
parents: 1855
diff changeset
2049 progs = realloc(progs, sizeof(*progs) * prog_storage);
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2050 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2051 progs[num_progs].vertex = NULL;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2052 progs[num_progs++].fragment = strdup(entries[i].name);
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2053 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2054 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2055 free(no_ext);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2056 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2057
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2058 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
2059 if (entries[i].is_dir) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2060 continue;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2061 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2062 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
2063 uint32_t len = strlen(no_ext);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2064 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
2065 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
2066 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
2067 progs[j].vertex = strdup(entries[i].name);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2068 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2069 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2070 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2071 free(no_ext);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2072 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2073 free_dir_list(entries, num_entries);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2074 *num_existing = num_progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2075 *storage = prog_storage;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2076 return progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2077 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2078
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2079 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
2080 {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2081 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
2082 size_t num_entries;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2083 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
2084 free(shader_dir);
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2085 shader_prog *progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2086 uint32_t num_progs = 0, prog_storage;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2087 if (num_entries) {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2088 progs = calloc(num_entries, sizeof(shader_prog));
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2089 prog_storage = num_entries;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2090 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
2091 } else {
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2092 progs = NULL;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2093 prog_storage = 0;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2094 }
2682
143cb5762ec9 Fix generating shader list on Android
Michael Pavone <pavone@retrodev.com>
parents: 2681
diff changeset
2095 entries = get_bundled_dir_list("shaders", &num_entries);
1492
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2096 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
2097 *num_out = num_progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2098 return progs;
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2099 }
bdeb2a1d0385 Add shader selector to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1491
diff changeset
2100
1499
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2101 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
2102 {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2103 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
2104 int32_t selected = -1;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2105 for (uint32_t i = 0; i < num_options; i++)
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2106 {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2107 if (!strcmp(setting, options[i])) {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2108 selected = i;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2109 break;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2110 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2111 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2112 if (selected == -1) {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2113 for (uint32_t i = 0; i < num_options; i++)
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2114 {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2115 if (!strcmp(def, options[i])) {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2116 selected = i;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2117 break;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2118 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2119 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2120 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2121 return selected;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2122 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2123
1500
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2124 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
2125 {
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2126 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
2127 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
2128 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
2129 config_dirty = 1;
1499
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2130 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
2131 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2132 return next;
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2133 }
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2134
1500
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2135 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
2136 {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2137 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
2138 }
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2139
1553
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2140 void view_video_settings(struct nk_context *context)
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2141 {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2142 const char *vsync_opts[] = {"on", "off", "tear"};
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2143 const char *vsync_opt_names[] = {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2144 "On",
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2145 "Off",
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2146 "On, tear if late"
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2147 };
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2148 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
2149 static shader_prog *progs;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2150 static char **prog_names;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2151 static uint32_t num_progs;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2152 static uint32_t selected_prog;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2153 static int32_t selected_vsync = -1;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2154 if (selected_vsync < 0) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2155 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
2156 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2157 if(!progs) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2158 progs = get_shader_list(&num_progs);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2159 prog_names = calloc(num_progs, sizeof(char*));
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2160 for (uint32_t i = 0; i < num_progs; i++)
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2161 {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2162 prog_names[i] = basename_no_extension(progs[i].fragment);;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2163 uint32_t len = strlen(prog_names[i]);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2164 if (len > 2) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2165 prog_names[i][len-2] = 0;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2166 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2167 if (!progs[i].vertex) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2168 progs[i].vertex = strdup("default.v.glsl");
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2169 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2170 if (!strcmp(
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2171 progs[i].fragment,
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2172 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
2173 )) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2174 selected_prog = i;
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2175 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2176 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2177 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2178 uint32_t width = render_width();
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2179 uint32_t height = render_height();
1577
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2180 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
2181 if (desired_width > width) {
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2182 desired_width = width;
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2183 }
2379
9e6cb50d0639 Fix accidental search and replace in UI code
Michael Pavone <pavone@retrodev.com>
parents: 2376
diff changeset
2184 if (nk_begin(context, "Video Settings", nk_rect(0, 0, width, height), 0)) {
2643
57345f6e18f3 Space out some of the settings pages to avoid stuff getting cut off with the smaller font
Michael Pavone <pavone@retrodev.com>
parents: 2628
diff changeset
2185 nk_layout_row_static(context, context->style.font->height * 1.25f, desired_width, 2);
1553
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2186 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2187 settings_toggle(context, "Open GL", "video\0gl\0", 1);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2188 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0);
2644
c5c9498ff279 Implement integer scaling
Michael Pavone <pavone@retrodev.com>
parents: 2643
diff changeset
2189 settings_toggle(context, "Integer Scaling", "video\0integer_scaling\0", 0);
1553
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2190 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
2191 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
2192 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
2193 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
2194 if (next_selected != selected_prog) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2195 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
2196 config_dirty = 1;
1553
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2197 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
2198 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
2199 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2200 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
2201 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
2202 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
2203 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
2204 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
2205 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
2206 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
2207 settings_int_property(context, "", "Right", "video\0pal\0overscan\0right\0", 14, 0, 32);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2208
1553
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2209 if (nk_button_label(context, "Back")) {
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2210 pop_view();
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2211 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2212 nk_end(context);
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2213 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2214 }
723c00950f41 Added vsync to video settings
Michael Pavone <pavone@retrodev.com>
parents: 1549
diff changeset
2215
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2216 void view_audio_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2217 {
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2218 const char *rates[] = {
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2219 "192000",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2220 "96000",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2221 "48000",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2222 "44100",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2223 "22050"
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2224 };
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2225 const char *sizes[] = {
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2226 "1024",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2227 "512",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2228 "256",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2229 "128",
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2230 "64"
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2231 };
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
2232 const char *dac[] = {
2556
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2546
diff changeset
2233 "auto",
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
2234 "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
2235 "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
2236 };
5278b6e44fc1 Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents: 1796
diff changeset
2237 const char *dac_desc[] = {
2556
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2546
diff changeset
2238 "Default for Model",
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
2239 "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
2240 "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
2241 };
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2242 const uint32_t num_rates = sizeof(rates)/sizeof(*rates);
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2243 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
2244 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
2245 static int32_t selected_rate = -1;
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2246 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
2247 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
2248 if (selected_rate < 0 || selected_size < 0 || selected_dac < 0) {
2383
ee0cc07dc406 Fix read of audio sample rate in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 2379
diff changeset
2249 selected_rate = find_match(rates, num_rates, "audio\0rate\0", "48000");
1499
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2250 selected_size = find_match(sizes, num_sizes, "audio\0buffer\0", "512");
2556
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2546
diff changeset
2251 selected_dac = find_match(dac, num_dacs, "audio\0fm_dac\0", "auto");
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2252 }
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2253 uint32_t width = render_width();
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2254 uint32_t height = render_height();
1578
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
2255 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
2256 if (desired_width > width) {
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
2257 desired_width = width;
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
2258 }
1494
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2259 if (nk_begin(context, "Audio Settings", nk_rect(0, 0, width, height), 0)) {
2643
57345f6e18f3 Space out some of the settings pages to avoid stuff getting cut off with the smaller font
Michael Pavone <pavone@retrodev.com>
parents: 2628
diff changeset
2260 nk_layout_row_static(context, context->style.font->height * 1.25f, desired_width, 2);
1499
756f8616d1bf Refactor basic settings dropdowns
Michael Pavone <pavone@retrodev.com>
parents: 1498
diff changeset
2261 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
2262 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
2263 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
2264 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
2265 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
2266 settings_float_property(context, "", "PSG", "audio\0psg_gain\0", 0, -30.0f, 30.0f, 0.5f);
2277
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2247
diff changeset
2267 settings_float_property(context, "", "RF5C164", "audio\0rf5c164_gain\0", -6.0f, -30.0f, 30.0f, 0.5f);
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2247
diff changeset
2268 settings_float_property(context, "", "CDDA", "audio\0cdd_gain\0", -9.5f, -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
2269 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
2270 if (nk_button_label(context, "Back")) {
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2271 pop_view();
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2272 }
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2273 nk_end(context);
8be6ea919300 Fleshed out audio settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1493
diff changeset
2274 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2275 }
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2276 typedef struct {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2277 const char **models;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2278 const char **names;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2279 uint32_t num_models;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2280 uint32_t storage;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2281 uint8_t genesis_only;
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2282 } model_foreach_state;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2283 void model_iter(char *key, tern_val val, uint8_t valtype, void *data)
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2284 {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2285 if (valtype != TVAL_NODE) {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2286 return;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2287 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2288 if (!strcmp(tern_find_ptr_default(val.ptrval, "show", "yes"), "no")) {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2289 return;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2290 }
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2291 model_foreach_state *state = data;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2292 if (state->genesis_only && strcmp(tern_find_ptr_default(val.ptrval, "vdp", "genesis"), "genesis")) {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2293 return;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2294 }
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2295 if (state->num_models == state->storage) {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2296 state->storage *= 2;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2297 state->models = realloc(state->models, state->storage * sizeof(char *));
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2298 state->names = realloc(state->names, state->storage * sizeof(char *));
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2299 }
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2300 char *def = strdup(key);
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2301 state->models[state->num_models] = def;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2302 state->names[state->num_models++] = tern_find_ptr_default(val.ptrval, "name", def);
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2303 }
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2304
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2305 typedef struct {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2306 const char **models;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2307 const char **names;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2308 } models;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2309
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2310 models get_models(uint32_t *num_out, uint8_t genesis_only)
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2311 {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2312 tern_node *systems = get_systems_config();
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2313 model_foreach_state state = {
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2314 .models = calloc(4, sizeof(char *)),
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2315 .names = calloc(4, sizeof(char *)),
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2316 .num_models = 0,
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2317 .storage = 4,
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2318 .genesis_only = genesis_only
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2319 };
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2320 tern_foreach(systems, model_iter, &state);
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2321 *num_out = state.num_models;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2322 return (models){
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2323 .models = state.models,
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2324 .names = state.names
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2325 };
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2326 }
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2327
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2328 void view_system_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2329 {
1568
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
2330 const char *sync_opts[] = {
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
2331 "video",
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
2332 "audio"
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
2333 };
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
2334 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
2335 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
2336 if (selected_sync < 0) {
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
2337 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
2338 }
1500
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2339 const char *regions[] = {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2340 "J - Japan",
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2341 "U - Americas",
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2342 "E - Europe"
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2343 };
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2344 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
2345 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
2346 static int32_t selected_region = -1;
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2347 if (selected_region < 0) {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2348 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
2349 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2350 static const char **model_opts, **sms_model_opts;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2351 static const char **model_names, **sms_model_names;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2352 static uint32_t num_models, num_sms_models;
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2353 if (!model_opts) {
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2354 models m = get_models(&num_models, 1);
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2355 model_opts = m.models;
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2356 model_names = m.names;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2357 m = get_models(&num_sms_models, 0);
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2358 sms_model_opts = m.models;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2359 sms_model_names = m.names;
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2360 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2361 static uint8_t old_show_sms;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2362 uint8_t show_sms = current_system && current_system->type == SYSTEM_SMS;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2363
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2364 static int32_t selected_model = -1;
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2365 if (selected_model < 0 || show_sms != old_show_sms) {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2366 if (show_sms) {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2367 selected_model = find_match(sms_model_opts, num_sms_models, "sms\0system\0model\0", "md1va3");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2368 } else {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2369 selected_model = find_match(model_opts, num_models, "system\0model\0", "md1va3");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2370 }
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2371 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2372
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2373 static const char *formats[] = {
1500
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2374 "native",
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2375 "gst"
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2376 };
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2377 const uint32_t num_formats = sizeof(formats)/sizeof(*formats);
1900
93960907807a Added UI for selecting configured model
Michael Pavone <pavone@retrodev.com>
parents: 1862
diff changeset
2378 static int32_t selected_format = -1;
1500
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2379 if (selected_format < 0) {
39a199dca772 Added dropdowns for default region and savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1499
diff changeset
2380 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
2381 }
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2382 static const char *ram_inits[] = {
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2383 "zero",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2384 "random"
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2385 };
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2386 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
2387 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
2388 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
2389 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
2390 }
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2391 static const char *io_opts_1[] = {
1789
b3eb74936f18 Fix off by one in IO device UI
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
2392 "none",
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2393 "gamepad2.1",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2394 "gamepad3.1",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2395 "gamepad6.1",
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2396 "sega_multitap.1",
2238
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2397 "ea_multitap_port_a",
1575
ccb3a8ae7ad0 Fix config value set when "Mega Mouse" is selected in settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1573
diff changeset
2398 "mouse.1",
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2399 "saturn keyboard",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2400 "xband keyboard"
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2401 };
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2402 static const char *io_opts_2[] = {
1789
b3eb74936f18 Fix off by one in IO device UI
Michael Pavone <pavone@retrodev.com>
parents: 1693
diff changeset
2403 "none",
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2404 "gamepad2.2",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2405 "gamepad3.2",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2406 "gamepad6.2",
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2407 "sega_multitap.1",
2238
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2408 "ea_multitap_port_b",
1575
ccb3a8ae7ad0 Fix config value set when "Mega Mouse" is selected in settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1573
diff changeset
2409 "mouse.1",
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2410 "saturn keyboard",
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2411 "xband keyboard"
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2412 };
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2413 static const char *type_names[sizeof(io_opts_1)/sizeof(*io_opts_1)];
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2414 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
2415 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
2416 const uint32_t num_io = sizeof(io_opts_1)/sizeof(*io_opts_1);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2417 if (selected_io_1 < 0 || selected_io_2 < 0 || show_sms != old_show_sms) {
2235
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2418 type_names[0] = device_type_names[IO_NONE];
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2419 type_names[1] = device_type_names[IO_GAMEPAD2];
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2420 type_names[2] = device_type_names[IO_GAMEPAD3];
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2421 type_names[3] = device_type_names[IO_GAMEPAD6];
93918a6a8ab7 Initial support for Sega multi-tap
Michael Pavone <pavone@retrodev.com>
parents: 2220
diff changeset
2422 type_names[4] = device_type_names[IO_SEGA_MULTI];
2238
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2423 type_names[5] = device_type_names[IO_EA_MULTI_A];
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2424 type_names[6] = device_type_names[IO_MOUSE];
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2425 type_names[7] = device_type_names[IO_SATURN_KEYBOARD];
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2426 type_names[8] = device_type_names[IO_XBAND_KEYBOARD];
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2427 if (show_sms) {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2428 selected_io_1 = find_match(io_opts_1, num_io, "sms\0io\0devices\0""1\0", "gamepad2.1");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2429 selected_io_2 = find_match(io_opts_2, num_io, "sms\0io\0devices\0""2\0", "gamepad2.2");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2430 } else {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2431 selected_io_1 = find_match(io_opts_1, num_io, "io\0devices\0""1\0", "gamepad6.1");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2432 selected_io_2 = find_match(io_opts_2, num_io, "io\0devices\0""2\0", "gamepad6.2");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2433 }
1501
31a2997b745e Added RAM init and IO port config to system settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1500
diff changeset
2434 }
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2435 old_show_sms = show_sms;
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2436
1498
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
2437 uint32_t width = render_width();
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
2438 uint32_t height = render_height();
1578
aaa28c9bf67d Basic interface scaling for rest of settings UI
Michael Pavone <pavone@retrodev.com>
parents: 1577
diff changeset
2439 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
2440 if (nk_begin(context, "System Settings", nk_rect(0, 0, width, height), 0)) {
2643
57345f6e18f3 Space out some of the settings pages to avoid stuff getting cut off with the smaller font
Michael Pavone <pavone@retrodev.com>
parents: 2628
diff changeset
2441 nk_layout_row_static(context, context->style.font->height * 1.25f, desired_width, 2);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2442
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2443 if (show_sms) {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2444 selected_model = settings_dropdown_ex(context, "Model", sms_model_opts, sms_model_names, num_sms_models, selected_model, "sms\0system\0model\0");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2445 } else {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2446 selected_model = settings_dropdown_ex(context, "Model", model_opts, model_names, num_models, selected_model, "system\0model\0");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2447 }
2238
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2448 int32_t old_selected = selected_io_1;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2449 char *config_path1, *config_path2;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2450 if (show_sms) {
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2451 config_path1 = "sms\0io\0devices\0""1\0";
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2452 config_path2 = "sms\0io\0devices\0""2\0";
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2453 } else {
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2454 config_path1 = "io\0devices\0""1\0";
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2455 config_path2 = "io\0devices\0""2\0";
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2456 }
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2457 selected_io_1 = settings_dropdown_ex(context, "IO Port 1 Device", io_opts_1, type_names, num_io, selected_io_1, config_path1);
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2458 if (old_selected != selected_io_1 && selected_io_1 != selected_io_2 && !strcmp(io_opts_1[selected_io_1], "ea_multitap_port_a")) {
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2459 selected_io_2 = selected_io_1;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2460 config = tern_insert_path(config, config_path2, (tern_val){.ptrval = strdup(io_opts_2[selected_io_2])}, TVAL_PTR);
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2461 }
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2462 old_selected = selected_io_2;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2463 selected_io_2 = settings_dropdown_ex(context, "IO Port 2 Device", io_opts_2, type_names, num_io, selected_io_2, config_path2);
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2464 if (old_selected != selected_io_2 && selected_io_1 != selected_io_2 && !strcmp(io_opts_2[selected_io_2], "ea_multitap_port_b")) {
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2465 selected_io_1 = selected_io_2;
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2466 config = tern_insert_path(config, config_path1, (tern_val){.ptrval = strdup(io_opts_1[selected_io_1])}, TVAL_PTR);
0a107b2d5837 Add support for EA 4-way Play
Michael Pavone <pavone@retrodev.com>
parents: 2235
diff changeset
2467 }
2014
9ca255be938d Reorder system settings so that more common options are near the top and none of the dropdowns get cut off
Michael Pavone <pavone@retrodev.com>
parents: 2003
diff changeset
2468 selected_region = settings_dropdown_ex(context, "Default Region", region_codes, regions, num_regions, selected_region, "system\0default_region\0");
2623
07faf0f5466f Add option to force use of the default region
Michael Pavone <pavone@retrodev.com>
parents: 2617
diff changeset
2469 settings_toggle(context, "Force Selected Region", "system\0force_region\0", 0);
1568
d14490dee01f Add sync_source to default.cfg and the Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1554
diff changeset
2470 selected_sync = settings_dropdown(context, "Sync Source", sync_opts, num_sync_opts, selected_sync, "system\0sync_source\0");
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2471 if (!show_sms) {
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2472 settings_int_property(context, "68000 Clock Divider", "", "clocks\0m68k_divider\0", 7, 1, 53);
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2473 selected_format = settings_dropdown(context, "Save State Format", formats, num_formats, selected_format, "ui\0state_format\0");
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2474 }
2014
9ca255be938d Reorder system settings so that more common options are near the top and none of the dropdowns get cut off
Michael Pavone <pavone@retrodev.com>
parents: 2003
diff changeset
2475 selected_init = settings_dropdown(context, "Initial RAM Value", ram_inits, num_inits, selected_init, "system\0ram_init\0");
1498
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
2476 settings_toggle(context, "Remember ROM Path", "ui\0remember_path\0", 1);
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
2477 settings_toggle(context, "Use Native File Picker", "ui\0use_native_filechooser\0", 0);
1852
a4cae960fd08 Allow config file to be saved with executable for "portable" setups
Michael Pavone <pavone@retrodev.com>
parents: 1841
diff changeset
2478 settings_toggle(context, "Save config with EXE", "ui\0config_in_exe_dir\0", 0);
1853
9b2acecf8124 Allow game save path to be edited from UI
Michael Pavone <pavone@retrodev.com>
parents: 1852
diff changeset
2479 settings_string(context, "Game Save Path", "ui\0save_path\0", "$USERDATA/blastem/$ROMNAME");
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2480
1498
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
2481 if (nk_button_label(context, "Back")) {
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
2482 if (config_dirty) {
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
2483 char *unf = tern_find_path(config, "ui\0use_native_filechooser\0", TVAL_PTR).ptrval;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
2484 use_native_filechooser = unf && !strcmp(unf, "on");
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
2485 }
1498
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
2486 pop_view();
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
2487 }
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
2488 nk_end(context);
050a5b032bc5 Initial work on system menu
Michael Pavone <pavone@retrodev.com>
parents: 1494
diff changeset
2489 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2490 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2491
2018
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2492 void view_confirm_reset(struct nk_context *context)
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2493 {
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2494 if (nk_begin(context, "Reset Confirm", nk_rect(0, 0, render_width(), render_height()), 0)) {
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2495 uint32_t desired_width = context->style.font->height * 20;
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2496 nk_layout_row_static(context, context->style.font->height, desired_width, 1);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2497 nk_label(context, "This will reset all settings and controller", NK_TEXT_LEFT);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2498 nk_label(context, "mappings back to the defaults.", NK_TEXT_LEFT);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2499 nk_label(context, "Are you sure you want to proceed?", NK_TEXT_LEFT);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2500 nk_layout_row_static(context, context->style.font->height * 1.5, desired_width / 2, 2);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2501 if (nk_button_label(context, "Maybe not")) {
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2502 pop_view();
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2503 }
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2504 if (nk_button_label(context, "Yep, delete it all")) {
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2505 delete_custom_config();
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2506 config = load_config();
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2507 delete_controller_info();
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2508 config_dirty = 1;
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2509 pop_view();
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2510 }
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2511 nk_end(context);
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2512 }
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2513 }
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2514
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2515 void view_bios_settings(struct nk_context *context)
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2516 {
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2517 if (nk_begin(context, "Firmware", nk_rect(0, 0, render_width(), render_height()), 0)) {
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2518 uint32_t desired_width = context->style.font->height * 10;
2369
3e064001594a Better spacing in firmware settings
Michael Pavone <pavone@retrodev.com>
parents: 2355
diff changeset
2519 nk_layout_row_static(context, context->style.font->height * 1.25f, desired_width, 2);
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2520 static const char* exts[] = {"md", "bin", "smd"};
2247
08a16de0e4cb Fix settings save path of TMSS ROM setting
Michael Pavone <pavone@retrodev.com>
parents: 2238
diff changeset
2521 settings_path(context, "TMSS ROM", "system\0tmss_path\0", "tmss.md", exts, 3);
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2522 settings_path(context, "US CD BIOS", "system\0scd_bios_us\0", "cdbios.md", exts, 3);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2523 settings_path(context, "JP CD BIOS", "system\0scd_bios_jp\0", "cdbios.md", exts, 3);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2524 settings_path(context, "EU CD BIOS", "system\0scd_bios_eu\0", "cdbios.md", exts, 3);
2413
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2409
diff changeset
2525 static const char* coleco_exts[] = {"col", "bin", "rom"};
64cf80e683aa Initial support for Colecovision emulation
Michael Pavone <pavone@retrodev.com>
parents: 2409
diff changeset
2526 settings_path(context, "Colecovision BIOS", "system\0coleco_bios_path\0", "colecovision_bios.col", coleco_exts, 3);
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2527 if (nk_button_label(context, "Back")) {
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2528 pop_view();
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2529 }
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2530 nk_end(context);
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2531 }
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2532 }
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2533
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2534 void view_back(struct nk_context *context)
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2535 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2536 pop_view();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2537 pop_view();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2538 current_view(context);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2539 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2540
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2541 void view_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2542 {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2543 static menu_item items[] = {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2544 {"Key Bindings", view_key_bindings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2545 {"Controllers", view_controllers},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2546 {"Video", view_video_settings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2547 {"Audio", view_audio_settings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2548 {"System", view_system_settings},
2156
237068a25523 Added UI for setting firmware paths
Michael Pavone <pavone@retrodev.com>
parents: 2022
diff changeset
2549 {"Firmware", view_bios_settings},
2018
193b804c9845 Add a UI button to reset config to defaults
Michael Pavone <pavone@retrodev.com>
parents: 2017
diff changeset
2550 {"Reset to Defaults", view_confirm_reset},
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
2551 {"Back", view_back}
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2552 };
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2553
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2554 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
2555 menu(context, sizeof(items)/sizeof(*items), items, NULL);
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2556 nk_end(context);
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2557 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2558 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2559
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
2560 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
2561 {
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
2562 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
2563 }
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
2564
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2565 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
2566 {
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2567 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
2568 {"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
2569 {"Load ROM", view_load},
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
2570 {"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
2571 {"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
2572 {"Load State", view_load_state},
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2573 {"Settings", view_settings},
2600
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2574 #ifndef __EMSCRIPTEN__
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2575 {"Exit", NULL}
2600
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2576 #endif
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2577 };
2544
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2578 static menu_item sc3k_items[] = {
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2579 {"Resume", view_play},
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2580 {"Load ROM", view_load},
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2581 {"Load Tape", view_load_tape},
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2582 {"Save State", view_save_state},
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2583 {"Load State", view_load_state},
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2584 {"Settings", view_settings},
2600
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2585 #ifndef __EMSCRIPTEN__
2544
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2586 {"Exit", NULL}
2600
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2587 #endif
2544
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2588 };
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2589
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2590 if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) {
2604
c768bbd912f1 Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents: 2600
diff changeset
2591 if (current_system->type == SYSTEM_SC3000) {
2544
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2592 menu(context, sizeof(sc3k_items)/sizeof(*sc3k_items), sc3k_items, exit_handler);
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2593 } else {
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2594 menu(context, sizeof(items)/sizeof(*items), items, exit_handler);
99e59fdddbc3 Better cassette tape UX
Michael Pavone <pavone@retrodev.com>
parents: 2531
diff changeset
2595 }
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2596 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
2597 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2598 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2599
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2600 void view_menu(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2601 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2602 static menu_item items[] = {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2603 {"Load ROM", view_load},
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
2604 {"Settings", view_settings},
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2605 {"About", view_about},
2604
c768bbd912f1 Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents: 2600
diff changeset
2606 #ifndef __EMSCRIPTEN__
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2607 {"Exit", NULL}
2604
c768bbd912f1 Give sega 8-bit consoles separate system_type enum values and allow selecting them from the command line
Michael Pavone <pavone@retrodev.com>
parents: 2600
diff changeset
2608 #endif
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2609 };
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2610
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2611 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
2612 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
2613 nk_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2614 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2615 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2616
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2617 void blastem_nuklear_render(void)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2618 {
2376
1c09f5be285b Very basic UI for media player
Michael Pavone <pavone@retrodev.com>
parents: 2369
diff changeset
2619 if (current_view != view_play || (current_system && current_system->type == SYSTEM_MEDIA_PLAYER)) {
2392
a71176b9903d Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents: 2383
diff changeset
2620 render_force_cursor(1);
1658
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2621 nk_input_end(context);
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2622 current_view(context);
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2623 if (fb_context) {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2624 fb_context->fb.pixels = render_get_framebuffer(FRAMEBUFFER_UI, &fb_context->fb.pitch);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2625 nk_rawfb_render(fb_context, nk_rgb(0,0,0), 0);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2626 render_framebuffer_updated(FRAMEBUFFER_UI, render_width());
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2627 } else {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2628 #ifndef DISABLE_OPENGL
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2629 nk_sdl_render(NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2630 #endif
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2631 }
1658
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2632 nk_input_begin(context);
2392
a71176b9903d Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents: 2383
diff changeset
2633 } else {
a71176b9903d Hide cursor in fullscreen when UI is not active
Michael Pavone <pavone@retrodev.com>
parents: 2383
diff changeset
2634 render_force_cursor(0);
1658
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2635 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2636 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2637
2600
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2638 void ui_enter(void)
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2639 {
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2640 render_enable_gamepad_events(1);
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2641 }
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2642
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2643 void ui_exit(void)
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2644 {
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2645 if (config_dirty) {
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2646 apply_updated_config();
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2647 persist_config(config);
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2648 config_dirty = 0;
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2649 }
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2650 render_enable_gamepad_events(0);
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2651 }
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2652
1486
a6881d0d76d0 Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
2653 void ui_idle_loop(void)
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2654 {
2600
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2655 #ifndef __EMSCRIPTEN__
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2656 ui_enter();
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
2657 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
2658 static uint32_t last;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2659 while (current_view != view_play)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2660 {
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
2661 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
2662 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
2663 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
2664 }
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
2665 last = current;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2666 render_update_display();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2667 }
2600
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2668 ui_exit();
251cc75574af Basic emscripten support
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2669 #endif
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2670 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2671 static void handle_event(SDL_Event *event)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2672 {
2678
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2673 SDL_Joystick *joy = render_get_joystick(selected_controller);
1522
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
2674 if (event->type == SDL_KEYDOWN) {
63659fb92db4 Key binding menu is now functional
Michael Pavone <pavone@retrodev.com>
parents: 1521
diff changeset
2675 keycode = event->key.keysym.sym;
1814
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2676 } else if (event->type == SDL_MOUSEBUTTONDOWN && event->button.button == 0) {
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2677 click = 1;
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2678 } else if (event->type == SDL_MOUSEBUTTONUP && event->button.button == 0) {
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2679 click = 0;
2678
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2680 } else if (joy) {
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2681 if (event->type == SDL_JOYBUTTONDOWN && event->jbutton.which == SDL_JoystickInstanceID(joy)) {
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2682 button_pressed = event->jbutton.button;
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2683 }
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2684 else if (event->type == SDL_JOYHATMOTION && event->jhat.which == SDL_JoystickInstanceID(joy)) {
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2685 hat_moved = event->jhat.hat;
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2686 hat_value = event->jhat.value;
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2687 }
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2688 else if (event->type == SDL_JOYAXISMOTION && event->jaxis.which == SDL_JoystickInstanceID(joy)) {
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2689 if (event->jaxis.axis == axis_moved || abs(event->jaxis.value) > abs(axis_value) || abs(event->jaxis.value) > 4000) {
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2690 axis_moved = event->jaxis.axis;
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2691 axis_value = event->jaxis.value;
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2692 }
844ca8377b45 Make the controller remap UI less twitchy on high refresh rate screens and filter out events from other controllers
Michael Pavone <pavone@retrodev.com>
parents: 2677
diff changeset
2693 }
1601
da04dd9c89ad SDL2 mapping UI now handles axes
Michael Pavone <pavone@retrodev.com>
parents: 1600
diff changeset
2694 }
2317
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
2695 if (stick_nav_disabled && event->type == SDL_CONTROLLERAXISMOTION) {
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
2696 return;
e836cf11783b Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents: 2313
diff changeset
2697 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2698 nk_sdl_handle_event(event);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2699 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2700
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2701 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
2702 {
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
2703 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
2704 {
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
2705 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
2706 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
2707 }
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2708 }
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
2709
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2710 #ifndef DISABLE_OPENGL
1609
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
2711 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
2712 {
9c8f58740450 Added PS4 controller image. Added code to use PS4 image for Playstation controllers
Michael Pavone <pavone@retrodev.com>
parents: 1606
diff changeset
2713 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
2714 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
2715 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
2716 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
2717 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
2718 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
2719 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
2720 #ifdef USE_GLES
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2721 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
2722 #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
2723 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
2724 #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
2725 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
2726 }
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2727 #endif
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2728
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2729 static struct nk_image load_image_rawfb(uint32_t *buf, uint32_t width, uint32_t height)
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2730 {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2731 struct rawfb_image *fbimg = calloc(1, sizeof(struct rawfb_image));
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2732 fbimg->pixels = buf;
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2733 fbimg->pitch = width * sizeof(uint32_t);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2734 fbimg->w = width;
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2735 fbimg->h = height;
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2736 fbimg->format = NK_FONT_ATLAS_RGBA32;
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2737 return nk_image_ptr(fbimg);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2738 }
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
2739
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
2740 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
2741 {
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2742 struct nk_font_atlas *atlas;
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2743 if (fb_context) {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2744 nk_rawfb_font_stash_begin(fb_context, &atlas);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2745 } else {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2746 #ifndef DISABLE_OPENGL
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2747 nk_sdl_font_stash_begin(&atlas);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2748 #endif
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2749 }
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
2750 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
2751 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
2752 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
2753 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
2754 }
2294
7e995fb948c3 Make UI font less comically large
Michael Pavone <pavone@retrodev.com>
parents: 2277
diff changeset
2755 def_font = nk_font_atlas_add_from_memory(atlas, font, font_size, render_height() / 24, 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
2756 free(font);
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2757 if (fb_context) {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2758 nk_rawfb_font_stash_end(fb_context);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2759 } else {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2760 #ifndef DISABLE_OPENGL
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2761 nk_sdl_font_stash_end();
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2762 #endif
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2763 }
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2764 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
2765 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
2766 {
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2767 #ifndef DISABLE_OPENGL
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2768 if (fb_context) {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2769 #endif
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2770 ui_images[i]->ui = load_image_rawfb(ui_images[i]->image_data, ui_images[i]->width, ui_images[i]->height);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2771 #ifndef DISABLE_OPENGL
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2772 } else {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2773 ui_images[i]->ui = load_image_texture(ui_images[i]->image_data, ui_images[i]->width, ui_images[i]->height);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2774 }
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2775 #endif
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
2776 }
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
2777 }
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
2778
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
2779 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
2780 {
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
2781 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
2782 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
2783 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
2784 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
2785 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
2786 .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
2787 };
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
2788 context->style.checkbox.cursor_hover = context->style.checkbox.cursor_normal;
1854
58b6f5d918f4 Minor improvements to keyboard navigation
Michael Pavone <pavone@retrodev.com>
parents: 1853
diff changeset
2789 context->style.property.inc_button.text_hover = (struct nk_color){
58b6f5d918f4 Minor improvements to keyboard navigation
Michael Pavone <pavone@retrodev.com>
parents: 1853
diff changeset
2790 .r = 255, .g = 128, .b = 0, .a = 255
58b6f5d918f4 Minor improvements to keyboard navigation
Michael Pavone <pavone@retrodev.com>
parents: 1853
diff changeset
2791 };
58b6f5d918f4 Minor improvements to keyboard navigation
Michael Pavone <pavone@retrodev.com>
parents: 1853
diff changeset
2792 context->style.property.dec_button.text_hover = context->style.property.inc_button.text_hover;
1855
92532eb6986d Make combo boxes keyboard navigable
Michael Pavone <pavone@retrodev.com>
parents: 1854
diff changeset
2793 context->style.combo.button.text_hover = context->style.property.inc_button.text_hover;
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
2794 }
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
2795
2308
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2796 static void fb_resize(void)
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2797 {
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2798 nk_rawfb_resize_fb(fb_context, NULL, render_width(), render_height(), 0);
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2799 style_init();
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2800 texture_init();
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2801 }
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2802
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
2803 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
2804 {
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
2805 context = nk_sdl_init(render_get_window());
2308
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2806 #ifndef DISABLE_OPENGL
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2807 if (render_has_gl()) {
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2808 nk_sdl_device_create();
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2809 } else {
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2810 #endif
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2811 fb_context = nk_rawfb_init(NULL, context, render_width(), render_height(), 0);
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2812 render_set_ui_fb_resize_handler(fb_resize);
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2813 #ifndef DISABLE_OPENGL
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2814 }
b7768c58f0da Initial stab at DPI scaling support
Michael Pavone <pavone@retrodev.com>
parents: 2307
diff changeset
2815 #endif
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
2816 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
2817 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
2818 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
2819
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2820 void show_pause_menu(void)
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2821 {
1814
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2822 if (current_view == view_play) {
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2823 set_content_binding_state(0);
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2824 context->style.window.background = nk_rgba(0, 0, 0, 128);
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2825 context->style.window.fixed_background = nk_style_item_color(nk_rgba(0, 0, 0, 128));
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2826 current_view = view_pause;
1841
5d10b8494b02 WIP keyboard nav for Nuklear menus
Michael Pavone <pavone@retrodev.com>
parents: 1831
diff changeset
2827 context->input.selected_widget = 0;
1980
81df9aa2de9b Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents: 1910
diff changeset
2828 system_request_exit(current_system, 1);
1814
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2829 } else if (current_system && !set_binding) {
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2830 clear_view_stack();
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2831 show_play_view();
8db3c043be00 Fix crash when pressing escape with no ROM loaded. Fix immediate cancel in keybinding view when mouse happens to be where the cancel button appears
Mike Pavone <pavone@retrodev.com>
parents: 1812
diff changeset
2832 }
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2833 }
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2834
1581
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2835 void show_play_view(void)
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2836 {
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2837 set_content_binding_state(1);
1581
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2838 current_view = view_play;
1841
5d10b8494b02 WIP keyboard nav for Nuklear menus
Michael Pavone <pavone@retrodev.com>
parents: 1831
diff changeset
2839 context->input.selected_widget = 0;
1581
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2840 }
7121daaa48c2 Fix drag and drop when using Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1579
diff changeset
2841
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2842 static uint8_t active;
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2843 uint8_t is_nuklear_active(void)
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2844 {
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2845 return active;
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2846 }
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2847
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
2848 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
2849 {
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2850 /*if (!render_has_gl()) {
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
2851 //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
2852 return 0;
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2853 }*/
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
2854 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
2855 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
2856 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
2857 }
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
2858 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
2859 }
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
2860
1577
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2861 static void persist_config_exit(void)
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2862 {
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2863 if (config_dirty) {
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2864 persist_config(config);
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2865 }
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2866 }
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2867
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
2868 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
2869 {
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2870 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
2871 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
2872 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
2873 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
2874 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
2875 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
2876 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
2877 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2878 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
2879 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
2880 #ifdef USE_GLES
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2881 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
2882 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
2883 {
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2884 uint32_t pixel = *cur;
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2885 *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
2886 }
fa9ae059e4d3 Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents: 1647
diff changeset
2887 #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
2888 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
2889 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
2890 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
2891 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
2892 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
2893 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2894 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
2895 } 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
2896 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
2897 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2898 }
60b199cbb3f7 Added PS4 6-button fighting pad image and cleaned up controller image handling code
Michael Pavone <pavone@retrodev.com>
parents: 1645
diff changeset
2899
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2900 void blastem_nuklear_init(uint8_t file_loaded)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2901 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2902 context = nk_sdl_init(render_get_window());
1825
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2903 #ifndef DISABLE_OPENGL
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2904 if (render_has_gl()) {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2905 nk_sdl_device_create();
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2906 } else {
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2907 #endif
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2908 fb_context = nk_rawfb_init(NULL, context, render_width(), render_height(), 0);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2909 render_set_ui_fb_resize_handler(fb_resize);
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2910 #ifndef DISABLE_OPENGL
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2911 }
56a1171e29b9 Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents: 1816
diff changeset
2912 #endif
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
2913 style_init();
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2914
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
2915 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
2916 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
2917 controller_ps4_6b = load_ui_image("images/ps4_6b.png");
2003
4c418ee9a9d8 Added Wii U controller image
Mike Pavone <pavone@retrodev.com>
parents: 1980
diff changeset
2918 controller_wiiu = load_ui_image("images/wiiu.png");
2020
e42c45ff06d5 Add Genesis 6-button contoller image
Michael Pavone <pavone@retrodev.com>
parents: 2018
diff changeset
2919 controller_gen_6b = load_ui_image("images/genesis_6b.png");
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2920
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
2921 texture_init();
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2922
1672
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2923 if (file_loaded) {
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2924 current_view = view_play;
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2925 } else {
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2926 current_view = view_menu;
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2927 set_content_binding_state(0);
12d0c7c4ad80 Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents: 1666
diff changeset
2928 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2929 render_set_ui_render_fun(blastem_nuklear_render);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2930 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
2931 render_set_gl_context_handlers(context_destroyed, context_created);
2355
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
2932 char *unf = tern_find_path(config, "ui\0use_native_filechooser\0", TVAL_PTR).ptrval;
94cf5cc89227 Add an option to use the system file picker on Linux and Windows
Michael Pavone <pavone@retrodev.com>
parents: 2319
diff changeset
2933 use_native_filechooser = unf && !strcmp(unf, "on");
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2934
1577
69d624271cf8 Persist config on exit if config has changed
Michael Pavone <pavone@retrodev.com>
parents: 1575
diff changeset
2935 atexit(persist_config_exit);
2202
ee6d30c56eeb Add separate model/IO selection settings for SMS/GG
Michael Pavone <pavone@retrodev.com>
parents: 2162
diff changeset
2936
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
2937 active = 1;
1486
a6881d0d76d0 Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
2938 ui_idle_loop();
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2939 }