Mercurial > repos > blastem
annotate nuklear_ui/blastem_nuklear.c @ 1482:2d203bf73dbd nuklear_ui
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Nov 2017 14:42:38 -0800 |
parents | 77a401044935 |
children | 001120e91fed |
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" |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 static struct nk_context *context; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 typedef void (*view_fun)(struct nk_context *); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 static view_fun current_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
|
18 static view_fun previous_view; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 void view_play(struct nk_context *context) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 void view_load(struct nk_context *context) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 static char *current_path; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 static dir_entry *entries; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 static size_t num_entries; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 static uint32_t selected_entry; |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
31 if (!current_path) { |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
32 get_initial_browse_path(¤t_path); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
33 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 if (!entries) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 entries = get_dir_list(current_path, &num_entries); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 uint32_t width = render_width(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 uint32_t height = render_height(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 nk_layout_row_static(context, 28, width-100, 1); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 for (uint32_t i = 0; i < num_entries; i++) |
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 int selected = i == selected_entry; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 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
|
47 if (selected) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 selected_entry = i; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 nk_group_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 } |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
53 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
|
54 if (nk_button_label(context, "Back")) { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
55 current_view = previous_view; |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
56 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 free(current_path); |
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
61 current_path = full_path; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 free_dir_list(entries, num_entries); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 entries = NULL; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 } else { |
1481
77a401044935
Fix directory navigation in ROM file chooser in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
65 current_system->next_rom = full_path; |
1475
afa3fbb76bff
Basic support for loading ROMs via Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1474
diff
changeset
|
66 current_system->request_exit(current_system); |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 current_view = view_play; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 nk_end(context); |
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 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 void view_about(struct nk_context *context) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 typedef struct { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 const char *title; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 view_fun next_view; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 } menu_item; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 |
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
|
83 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
|
84 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
|
85 |
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
|
86 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
|
87 { |
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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 } |
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
|
97 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
|
98 { |
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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 } |
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
|
104 } |
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
|
105 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
|
106 } |
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
|
107 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
|
108 if (nk_button_label(context, "Back")) { |
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
|
109 current_view = previous_view; |
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
|
110 } |
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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 } |
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
|
116 } 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
|
117 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
|
118 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
|
119 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
|
120 } |
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
|
121 } |
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
|
122 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
|
123 } |
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
|
124 } |
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
|
125 |
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
|
126 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
|
127 { |
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
|
128 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
|
129 } |
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
|
130 |
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
|
131 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
|
132 { |
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
|
133 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
|
134 } |
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
|
135 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 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
|
137 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 const uint32_t button_height = 52; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 const uint32_t ideal_button_width = 300; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 const uint32_t button_space = 6; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 uint32_t width = render_width(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 uint32_t height = render_height(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 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
|
145 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
|
146 uint32_t left = width/2 - button_width/2; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 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
|
149 for (uint32_t i = 0; i < num_entries; i++) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 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
|
152 if (nk_button_label(context, items[i].title)) { |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
153 previous_view = current_view; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 current_view = items[i].next_view; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 if (!current_view) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 exit(0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 } |
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
|
158 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
|
159 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
|
160 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
|
161 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 nk_layout_space_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
167 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
|
168 { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
169 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
|
170 {"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
|
171 {"Load ROM", view_load}, |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
172 {"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
|
173 {"Load State", view_load_state}, |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
174 {"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
|
175 }; |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
176 |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 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
|
181 } |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
182 } |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
183 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 void view_menu(struct nk_context *context) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 static menu_item items[] = { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 {"Load ROM", view_load}, |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 {"About", view_about}, |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 {"Exit", NULL} |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 }; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 const uint32_t num_buttons = 3; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 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
|
194 menu(context, sizeof(items)/sizeof(*items), items); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 nk_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 void blastem_nuklear_render(void) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 nk_input_end(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 current_view(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 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
|
204 nk_input_begin(context); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 void idle_loop(void) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 { |
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
|
209 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
|
210 static uint32_t last; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 while (current_view != view_play) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 { |
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
|
213 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
|
214 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
|
215 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
|
216 } |
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
|
217 last = current; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 render_update_display(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 static void handle_event(SDL_Event *event) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 nk_sdl_handle_event(event); |
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 |
1476
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
226 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
|
227 { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
228 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
|
229 } |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
230 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
|
231 { |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 } |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 } |
0646ae0987c3
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
Michael Pavone <pavone@retrodev.com>
parents:
1475
diff
changeset
|
243 |
1477
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
244 void show_pause_menu(void) |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
245 { |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
246 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
|
247 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
|
248 current_view = view_pause; |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
249 } |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
250 |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
251 static uint8_t active; |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
252 uint8_t is_nuklear_active(void) |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
253 { |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
254 return active; |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
255 } |
1cdd7f492af8
Pause menu now triggered on ui.exit event
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
256 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 void blastem_nuklear_init(uint8_t file_loaded) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 context = nk_sdl_init(render_get_window()); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 struct nk_font_atlas *atlas; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 nk_sdl_font_stash_begin(&atlas); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 char *font = default_font_path(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 if (!font) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 fatal_error("Failed to find default font path\n"); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 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
|
268 nk_sdl_font_stash_end(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 nk_style_set_font(context, &def_font->handle); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 current_view = file_loaded ? view_play : view_menu; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 render_set_ui_render_fun(blastem_nuklear_render); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 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
|
273 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
|
274 active = 1; |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 idle_loop(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 } |