annotate nuklear_ui/blastem_nuklear.c @ 1491:e890971f3757 nuklear_ui

Somewhat fleshed out video settings view
author Michael Pavone <pavone@retrodev.com>
date Fri, 01 Dec 2017 09:22:43 -0800
parents 919c0c33885e
children bdeb2a1d0385
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #define NK_IMPLEMENTATION
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #define NK_SDL_GLES2_IMPLEMENTATION
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include <stdlib.h>
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "blastem_nuklear.h"
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "font.h"
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include "../render.h"
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "../render_sdl.h"
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 #include "../util.h"
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 #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
11 #include "../saves.h"
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 #include "../blastem.h"
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
13 #include "../config.h"
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 static struct nk_context *context;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 typedef void (*view_fun)(struct nk_context *);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 static view_fun current_view;
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
19 static view_fun *previous_views;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
20 static uint32_t view_storage;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
21 static uint32_t num_prev;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
22
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
23 static void push_view(view_fun new_view)
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
24 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
25 if (num_prev == view_storage) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
26 view_storage = view_storage ? 2*view_storage : 2;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
27 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
28 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
29 previous_views[num_prev++] = current_view;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
30 current_view = new_view;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
31 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
32
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
33 static void pop_view()
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
34 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
35 if (num_prev) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
36 current_view = previous_views[--num_prev];
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
37 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
38 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
39
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
40 static void clear_view_stack()
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
41 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
42 num_prev = 0;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
43 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 void view_play(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
50 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
51 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 static char *current_path;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 static dir_entry *entries;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 static size_t num_entries;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 static uint32_t selected_entry;
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
56 static char **ext_list;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
57 static uint32_t num_exts;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
58 static uint8_t got_ext_list;
1481
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
59 if (!current_path) {
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
60 get_initial_browse_path(&current_path);
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
61 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 if (!entries) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 entries = get_dir_list(current_path, &num_entries);
1484
d82af64c94d2 Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
64 if (entries) {
d82af64c94d2 Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
65 sort_dir_list(entries, num_entries);
d82af64c94d2 Sort directory listing in Nuklear UI file browser
Michael Pavone <pavone@retrodev.com>
parents: 1483
diff changeset
66 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 }
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
68 if (!got_ext_list) {
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
69 ext_list = get_extension_list(config, &num_exts);
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
70 got_ext_list = 1;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
71 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 uint32_t width = render_width();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 uint32_t height = render_height();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 nk_layout_row_static(context, height - 100, width - 60, 1);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 if (nk_group_begin(context, "Select ROM", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 nk_layout_row_static(context, 28, width-100, 1);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 for (uint32_t i = 0; i < num_entries; i++)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 {
1485
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
80 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
81 continue;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
82 }
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
83 if (num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, ext_list, num_exts)) {
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
84 continue;
369da70ee2c2 Filter file list in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1484
diff changeset
85 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 int selected = i == selected_entry;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 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
88 if (selected) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 selected_entry = i;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 nk_group_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 }
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
94 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2);
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
95 if (nk_button_label(context, "Back")) {
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
96 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
97 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 if (nk_button_label(context, "Open")) {
1481
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
99 char *full_path = path_append(current_path, entries[selected_entry].name);
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 if (entries[selected_entry].is_dir) {
1481
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
101 free(current_path);
77a401044935 Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
102 current_path = full_path;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 free_dir_list(entries, num_entries);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 entries = NULL;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105 } else {
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
106 if(normal_open) {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
107 if (current_system) {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
108 current_system->next_rom = full_path;
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
109 current_system->request_exit(current_system);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
110 } else {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
111 init_system_with_media(full_path, SYSTEM_UNKNOWN);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
112 free(full_path);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
113 }
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
114 } else {
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
115 lockon_media(full_path);
1483
001120e91fed Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents: 1482
diff changeset
116 free(full_path);
001120e91fed Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents: 1482
diff changeset
117 }
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
118 clear_view_stack();
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 current_view = view_play;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 nk_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
126 void view_load(struct nk_context *context)
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
127 {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
128 view_file_browser(context, 1);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
129 }
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
130
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
131 void view_lock_on(struct nk_context *context)
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
132 {
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
133 view_file_browser(context, 0);
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
134 }
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
135
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 void view_about(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 typedef struct {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 const char *title;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 view_fun next_view;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 } menu_item;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144
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
145 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
146 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
147
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
148 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
149 {
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
150 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
151 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
152 if (nk_begin(context, "Slot Picker", nk_rect(0, 0, width, height), 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
153 nk_layout_row_static(context, height - 100, width - 60, 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
154 if (nk_group_begin(context, "Select Save Slot", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) {
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
155 nk_layout_row_static(context, 28, width-100, 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
156 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
157 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
158 }
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
159 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
160 {
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
161 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
162 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
163 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
164 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
165 }
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
166 }
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
167 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
168 }
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
169 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2);
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
170 if (nk_button_label(context, "Back")) {
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
171 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
172 }
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
173 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
174 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
175 current_system->load_state(current_system, selected_slot);
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1477
diff changeset
176 current_view = view_play;
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1477
diff changeset
177 }
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
178 } 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
179 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
180 current_system->save_state = selected_slot + 1;
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1477
diff changeset
181 current_view = view_play;
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1477
diff changeset
182 }
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
183 }
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
184 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
185 }
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
186 }
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
187
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
188 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
189 {
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
190 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
191 }
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
192
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
193 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
194 {
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
195 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
196 }
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
197
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 static void menu(struct nk_context *context, uint32_t num_entries, const menu_item *items)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 const uint32_t button_height = 52;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 const uint32_t ideal_button_width = 300;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 const uint32_t button_space = 6;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 uint32_t width = render_width();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 uint32_t height = render_height();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 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
207 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
208 uint32_t left = width/2 - button_width/2;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 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
211 for (uint32_t i = 0; i < num_entries; i++)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 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
214 if (nk_button_label(context, items[i].title)) {
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
215 push_view(items[i].next_view);
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 if (!current_view) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 exit(0);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 }
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
219 if (current_view == view_save_state || current_view == view_load_state) {
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1477
diff changeset
220 free_slot_info(slots);
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1477
diff changeset
221 slots = NULL;
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1477
diff changeset
222 }
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
223 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
224 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 nk_layout_space_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
228 void view_key_bindings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
229 {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
230
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
231 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
232 void view_controllers(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
233 {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
234
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
235 }
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
236
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
237 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
238 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
239 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
240 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
241 uint8_t newval = nk_check_label(context, "", curval);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
242 if (newval != curval) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
243 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
244 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
245 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
246
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
247 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
248 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
249 char buffer[12];
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
250 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
251 uint32_t curval;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
252 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
253 uint32_t len = strlen(curstr);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
254 if (len > 11) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
255 len = 11;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
256 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
257 memcpy(buffer, curstr, len);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
258 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
259 buffer[len] = 0;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
260 if (strcmp(buffer, curstr)) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
261 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
262 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
263 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
264
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
265 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
266 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
267 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
268 int curval = curstr ? atoi(curstr) : def;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
269 nk_label(context, label, NK_TEXT_LEFT);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
270 int val = curval;
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
271 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
272 if (val != curval) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
273 char buffer[12];
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
274 sprintf(buffer, "%d", val);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
275 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
276 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
277 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
278
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
279 void view_video_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
280 {
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
281 uint32_t width = render_width();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
282 uint32_t height = render_height();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
283 if (nk_begin(context, "Video Settings", nk_rect(0, 0, width, height), 0)) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
284 nk_layout_row_static(context, 30, width > 300 ? 300 : width, 2);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
285 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
286 settings_toggle(context, "Open GL", "video\0gl\0", 1);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
287 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
288 settings_int_input(context, "Windowed Width", "video\0width\0", "640");
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
289 settings_int_property(context, "NTSC Overscan", "Top", "video\0ntsc\0overscan\0top\0", 2, 0, 32);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
290 settings_int_property(context, "", "Bottom", "video\0ntsc\0overscan\0bottom\0", 17, 0, 32);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
291 settings_int_property(context, "", "Left", "video\0ntsc\0overscan\0left\0", 13, 0, 32);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
292 settings_int_property(context, "", "Right", "video\0ntsc\0overscan\0right\0", 14, 0, 32);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
293 settings_int_property(context, "PAL Overscan", "Top", "video\0pal\0overscan\0top\0", 2, 0, 32);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
294 settings_int_property(context, "", "Bottom", "video\0pal\0overscan\0bottom\0", 17, 0, 32);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
295 settings_int_property(context, "", "Left", "video\0pal\0overscan\0left\0", 13, 0, 32);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
296 settings_int_property(context, "", "Right", "video\0pal\0overscan\0right\0", 14, 0, 32);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
297 if (nk_button_label(context, "Back")) {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
298 pop_view();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
299 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
300 nk_end(context);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
301 }
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
302 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
303 void view_audio_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
304 {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
305
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
306 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
307 void view_system_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
308 {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
309
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
310 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
311
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
312 void view_back(struct nk_context *context)
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
313 {
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
314 pop_view();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
315 pop_view();
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
316 current_view(context);
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
317 }
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
318
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
319 void view_settings(struct nk_context *context)
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
320 {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
321 static menu_item items[] = {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
322 {"Key Bindings", view_key_bindings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
323 {"Controllers", view_controllers},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
324 {"Video", view_video_settings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
325 {"Audio", view_audio_settings},
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
326 {"System", view_system_settings},
1491
e890971f3757 Somewhat fleshed out video settings view
Michael Pavone <pavone@retrodev.com>
parents: 1490
diff changeset
327 {"Back", view_back}
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
328 };
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
329
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
330 const uint32_t num_buttons = 6;
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
331 if (nk_begin(context, "Settings Menu", nk_rect(0, 0, render_width(), render_height()), 0)) {
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
332 menu(context, sizeof(items)/sizeof(*items), items);
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
333 nk_end(context);
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
334 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
335 }
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
336
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
337 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
338 {
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
339 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
340 {"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
341 {"Load ROM", view_load},
1487
6a35815cc409 Enable lock-on in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents: 1486
diff changeset
342 {"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
343 {"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
344 {"Load State", view_load_state},
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
345 {"Settings", view_settings},
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
346 {"Exit", NULL}
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
347 };
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
348
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
349 const uint32_t num_buttons = 3;
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
350 if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) {
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
351 menu(context, sizeof(items)/sizeof(*items), items);
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
352 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
353 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
354 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
355
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
356 void view_menu(struct nk_context *context)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
357 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
358 static menu_item items[] = {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
359 {"Load ROM", view_load},
1490
919c0c33885e Initial work on settings menu
Michael Pavone <pavone@retrodev.com>
parents: 1487
diff changeset
360 {"Settings", view_settings},
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
361 {"About", view_about},
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
362 {"Exit", NULL}
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
363 };
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
364
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
365 const uint32_t num_buttons = 3;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
366 if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
367 menu(context, sizeof(items)/sizeof(*items), items);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
368 nk_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
369 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
370 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
371
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
372 void blastem_nuklear_render(void)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
373 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
374 nk_input_end(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
375 current_view(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
376 nk_sdl_render(NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
377 nk_input_begin(context);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
378 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
379
1486
a6881d0d76d0 Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
380 void ui_idle_loop(void)
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
381 {
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
382 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
383 static uint32_t last;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
384 while (current_view != view_play)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
385 {
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
386 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
387 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
388 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
389 }
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
390 last = current;
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
391 render_update_display();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
392 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
393 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
394 static void handle_event(SDL_Event *event)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
395 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
396 nk_sdl_handle_event(event);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
397 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
398
1476
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
399 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
400 {
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
401 nk_sdl_device_destroy();
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
402 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
403 static void context_created(void)
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
404 {
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
405 nk_sdl_device_create();
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
406 struct nk_font_atlas *atlas;
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
407 nk_sdl_font_stash_begin(&atlas);
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
408 char *font = default_font_path();
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
409 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
410 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
411 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
412 struct nk_font *def_font = nk_font_atlas_add_from_file(atlas, font, 30, NULL);
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
413 nk_sdl_font_stash_end();
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
414 nk_style_set_font(context, &def_font->handle);
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
415 }
0646ae0987c3 Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents: 1475
diff changeset
416
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
417 void show_pause_menu(void)
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
418 {
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
419 context->style.window.background = nk_rgba(0, 0, 0, 128);
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
420 context->style.window.fixed_background = nk_style_item_color(nk_rgba(0, 0, 0, 128));
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
421 current_view = view_pause;
1486
a6881d0d76d0 Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
422 current_system->request_exit(current_system);
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
423 }
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
424
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
425 static uint8_t active;
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
426 uint8_t is_nuklear_active(void)
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
427 {
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
428 return active;
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
429 }
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
430
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
431 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
432 {
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
433 if (!render_has_gl()) {
001120e91fed Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents: 1482
diff changeset
434 //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
435 return 0;
001120e91fed Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents: 1482
diff changeset
436 }
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
437 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
438 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
439 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
440 }
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
441 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
442 }
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
443
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
444 void blastem_nuklear_init(uint8_t file_loaded)
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
445 {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
446 context = nk_sdl_init(render_get_window());
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
447
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
448 struct nk_font_atlas *atlas;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
449 nk_sdl_font_stash_begin(&atlas);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
450 char *font = default_font_path();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
451 if (!font) {
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
452 fatal_error("Failed to find default font path\n");
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
453 }
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
454 struct nk_font *def_font = nk_font_atlas_add_from_file(atlas, font, 30, NULL);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
455 nk_sdl_font_stash_end();
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
456 nk_style_set_font(context, &def_font->handle);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
457 current_view = file_loaded ? view_play : view_menu;
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
458 render_set_ui_render_fun(blastem_nuklear_render);
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
459 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
460 render_set_gl_context_handlers(context_destroyed, context_created);
1477
1cdd7f492af8 Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents: 1476
diff changeset
461 active = 1;
1486
a6881d0d76d0 Pause game execution when in the new UI pause menu
Michael Pavone <pavone@retrodev.com>
parents: 1485
diff changeset
462 ui_idle_loop();
1474
c5c022c7aa54 Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
463 }