Mercurial > repos > blastem
comparison nuklear_ui/blastem_nuklear.c @ 1476:0646ae0987c3 nuklear_ui
Fix UI rendering in fullscreen and wome initial work on the "pause" menu
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 22 Nov 2017 10:54:27 -0800 |
parents | afa3fbb76bff |
children | 1cdd7f492af8 |
comparison
equal
deleted
inserted
replaced
1475:afa3fbb76bff | 1476:0646ae0987c3 |
---|---|
12 | 12 |
13 static struct nk_context *context; | 13 static struct nk_context *context; |
14 | 14 |
15 typedef void (*view_fun)(struct nk_context *); | 15 typedef void (*view_fun)(struct nk_context *); |
16 static view_fun current_view; | 16 static view_fun current_view; |
17 static view_fun previous_view; | |
17 | 18 |
18 void view_play(struct nk_context *context) | 19 void view_play(struct nk_context *context) |
19 { | 20 { |
20 | 21 |
21 } | 22 } |
44 selected_entry = i; | 45 selected_entry = i; |
45 } | 46 } |
46 } | 47 } |
47 nk_group_end(context); | 48 nk_group_end(context); |
48 } | 49 } |
49 nk_layout_row_static(context, 52, 300, 1); | 50 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2); |
51 if (nk_button_label(context, "Back")) { | |
52 current_view = previous_view; | |
53 } | |
50 if (nk_button_label(context, "Open")) { | 54 if (nk_button_label(context, "Open")) { |
51 char const *pieces[] = {current_path, PATH_SEP, entries[selected_entry].name}; | 55 char const *pieces[] = {current_path, PATH_SEP, entries[selected_entry].name}; |
52 if (entries[selected_entry].is_dir) { | 56 if (entries[selected_entry].is_dir) { |
53 char *old = current_path; | 57 char *old = current_path; |
54 current_path = alloc_concat_m(3, pieces); | 58 current_path = alloc_concat_m(3, pieces); |
89 nk_layout_space_begin(context, NK_STATIC, top + button_height * num_entries, num_entries); | 93 nk_layout_space_begin(context, NK_STATIC, top + button_height * num_entries, num_entries); |
90 for (uint32_t i = 0; i < num_entries; i++) | 94 for (uint32_t i = 0; i < num_entries; i++) |
91 { | 95 { |
92 nk_layout_space_push(context, nk_rect(left, top + i * button_height, button_width, button_height-button_space)); | 96 nk_layout_space_push(context, nk_rect(left, top + i * button_height, button_width, button_height-button_space)); |
93 if (nk_button_label(context, items[i].title)) { | 97 if (nk_button_label(context, items[i].title)) { |
98 previous_view = current_view; | |
94 current_view = items[i].next_view; | 99 current_view = items[i].next_view; |
95 if (!current_view) { | 100 if (!current_view) { |
96 exit(0); | 101 exit(0); |
97 } | 102 } |
98 } | 103 } |
99 } | 104 } |
100 nk_layout_space_end(context); | 105 nk_layout_space_end(context); |
106 } | |
107 | |
108 void view_choose_state(struct nk_context *context, uint8_t is_load) | |
109 { | |
110 | |
111 } | |
112 | |
113 void view_save_state(struct nk_context *context) | |
114 { | |
115 view_choose_state(context, 0); | |
116 } | |
117 | |
118 void view_load_state(struct nk_context *context) | |
119 { | |
120 view_choose_state(context, 1); | |
121 } | |
122 | |
123 void view_pause(struct nk_context *context) | |
124 { | |
125 static menu_item items[] = { | |
126 {"Resume", view_play}, | |
127 {"Load ROM", view_load}, | |
128 {"Save State", view_save_state}, | |
129 {"Load State", view_load_state}, | |
130 {"Exit", NULL} | |
131 }; | |
132 | |
133 const uint32_t num_buttons = 3; | |
134 if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { | |
135 menu(context, sizeof(items)/sizeof(*items), items); | |
136 nk_end(context); | |
137 } | |
101 } | 138 } |
102 | 139 |
103 void view_menu(struct nk_context *context) | 140 void view_menu(struct nk_context *context) |
104 { | 141 { |
105 static menu_item items[] = { | 142 static menu_item items[] = { |
117 | 154 |
118 void blastem_nuklear_render(void) | 155 void blastem_nuklear_render(void) |
119 { | 156 { |
120 nk_input_end(context); | 157 nk_input_end(context); |
121 current_view(context); | 158 current_view(context); |
122 glViewport(0, 0, render_width(), render_height()); | |
123 /* glClear(GL_COLOR_BUFFER_BIT); | |
124 glClearColor(0, 0, 0, 0);*/ | |
125 nk_sdl_render(NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024); | 159 nk_sdl_render(NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024); |
126 //SDL_GL_SwapWindow(render_get_window()); | |
127 nk_input_begin(context); | 160 nk_input_begin(context); |
128 } | 161 } |
129 | 162 |
130 void idle_loop(void) | 163 void idle_loop(void) |
131 { | 164 { |
135 } | 168 } |
136 } | 169 } |
137 static void handle_event(SDL_Event *event) | 170 static void handle_event(SDL_Event *event) |
138 { | 171 { |
139 nk_sdl_handle_event(event); | 172 nk_sdl_handle_event(event); |
173 } | |
174 | |
175 static void context_destroyed(void) | |
176 { | |
177 nk_sdl_device_destroy(); | |
178 } | |
179 static void context_created(void) | |
180 { | |
181 nk_sdl_device_create(); | |
182 struct nk_font_atlas *atlas; | |
183 nk_sdl_font_stash_begin(&atlas); | |
184 char *font = default_font_path(); | |
185 if (!font) { | |
186 fatal_error("Failed to find default font path\n"); | |
187 } | |
188 struct nk_font *def_font = nk_font_atlas_add_from_file(atlas, font, 30, NULL); | |
189 nk_sdl_font_stash_end(); | |
190 nk_style_set_font(context, &def_font->handle); | |
140 } | 191 } |
141 | 192 |
142 void blastem_nuklear_init(uint8_t file_loaded) | 193 void blastem_nuklear_init(uint8_t file_loaded) |
143 { | 194 { |
144 context = nk_sdl_init(render_get_window()); | 195 context = nk_sdl_init(render_get_window()); |
153 nk_sdl_font_stash_end(); | 204 nk_sdl_font_stash_end(); |
154 nk_style_set_font(context, &def_font->handle); | 205 nk_style_set_font(context, &def_font->handle); |
155 current_view = file_loaded ? view_play : view_menu; | 206 current_view = file_loaded ? view_play : view_menu; |
156 render_set_ui_render_fun(blastem_nuklear_render); | 207 render_set_ui_render_fun(blastem_nuklear_render); |
157 render_set_event_handler(handle_event); | 208 render_set_event_handler(handle_event); |
209 render_set_gl_context_handlers(context_destroyed, context_created); | |
158 idle_loop(); | 210 idle_loop(); |
159 } | 211 } |