# HG changeset patch # User Michael Pavone # Date 1511376867 28800 # Node ID 0646ae0987c3d5f0dc1a1a752348b2ba91d0eb55 # Parent afa3fbb76bffb302c750849f73a53b52f3afd3a8 Fix UI rendering in fullscreen and wome initial work on the "pause" menu diff -r afa3fbb76bff -r 0646ae0987c3 nuklear_ui/blastem_nuklear.c --- a/nuklear_ui/blastem_nuklear.c Tue Nov 21 23:11:11 2017 -0800 +++ b/nuklear_ui/blastem_nuklear.c Wed Nov 22 10:54:27 2017 -0800 @@ -14,6 +14,7 @@ typedef void (*view_fun)(struct nk_context *); static view_fun current_view; +static view_fun previous_view; void view_play(struct nk_context *context) { @@ -46,7 +47,10 @@ } nk_group_end(context); } - nk_layout_row_static(context, 52, 300, 1); + nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2); + if (nk_button_label(context, "Back")) { + current_view = previous_view; + } if (nk_button_label(context, "Open")) { char const *pieces[] = {current_path, PATH_SEP, entries[selected_entry].name}; if (entries[selected_entry].is_dir) { @@ -91,6 +95,7 @@ { nk_layout_space_push(context, nk_rect(left, top + i * button_height, button_width, button_height-button_space)); if (nk_button_label(context, items[i].title)) { + previous_view = current_view; current_view = items[i].next_view; if (!current_view) { exit(0); @@ -100,6 +105,38 @@ nk_layout_space_end(context); } +void view_choose_state(struct nk_context *context, uint8_t is_load) +{ + +} + +void view_save_state(struct nk_context *context) +{ + view_choose_state(context, 0); +} + +void view_load_state(struct nk_context *context) +{ + view_choose_state(context, 1); +} + +void view_pause(struct nk_context *context) +{ + static menu_item items[] = { + {"Resume", view_play}, + {"Load ROM", view_load}, + {"Save State", view_save_state}, + {"Load State", view_load_state}, + {"Exit", NULL} + }; + + const uint32_t num_buttons = 3; + if (nk_begin(context, "Main Menu", nk_rect(0, 0, render_width(), render_height()), 0)) { + menu(context, sizeof(items)/sizeof(*items), items); + nk_end(context); + } +} + void view_menu(struct nk_context *context) { static menu_item items[] = { @@ -119,11 +156,7 @@ { nk_input_end(context); current_view(context); - glViewport(0, 0, render_width(), render_height()); -/* glClear(GL_COLOR_BUFFER_BIT); - glClearColor(0, 0, 0, 0);*/ nk_sdl_render(NK_ANTI_ALIASING_ON, 512 * 1024, 128 * 1024); - //SDL_GL_SwapWindow(render_get_window()); nk_input_begin(context); } @@ -139,6 +172,24 @@ nk_sdl_handle_event(event); } +static void context_destroyed(void) +{ + nk_sdl_device_destroy(); +} +static void context_created(void) +{ + nk_sdl_device_create(); + struct nk_font_atlas *atlas; + nk_sdl_font_stash_begin(&atlas); + char *font = default_font_path(); + if (!font) { + fatal_error("Failed to find default font path\n"); + } + struct nk_font *def_font = nk_font_atlas_add_from_file(atlas, font, 30, NULL); + nk_sdl_font_stash_end(); + nk_style_set_font(context, &def_font->handle); +} + void blastem_nuklear_init(uint8_t file_loaded) { context = nk_sdl_init(render_get_window()); @@ -155,5 +206,6 @@ current_view = file_loaded ? view_play : view_menu; render_set_ui_render_fun(blastem_nuklear_render); render_set_event_handler(handle_event); + render_set_gl_context_handlers(context_destroyed, context_created); idle_loop(); } diff -r afa3fbb76bff -r 0646ae0987c3 render_sdl.c --- a/render_sdl.c Tue Nov 21 23:11:11 2017 -0800 +++ b/render_sdl.c Wed Nov 22 10:54:27 2017 -0800 @@ -696,7 +696,7 @@ { #ifndef DISABLE_OPENGL if (render_gl) { - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(program); @@ -997,6 +997,13 @@ drag_drop_handler = handler; } +static ui_render_fun on_context_destroyed, on_context_created; +void render_set_gl_context_handlers(ui_render_fun destroy, ui_render_fun create) +{ + on_context_destroyed = destroy; + on_context_created = create; +} + static event_handler custom_event_handler; void render_set_event_handler(event_handler handler) { @@ -1070,9 +1077,15 @@ update_aspect(); #ifndef DISABLE_OPENGL if (render_gl) { + if (on_context_destroyed) { + on_context_destroyed(); + } SDL_GL_DeleteContext(main_context); main_context = SDL_GL_CreateContext(main_window); gl_setup(); + if (on_context_created) { + on_context_created(); + } } #endif break; diff -r afa3fbb76bff -r 0646ae0987c3 render_sdl.h --- a/render_sdl.h Tue Nov 21 23:11:11 2017 -0800 +++ b/render_sdl.h Wed Nov 22 10:54:27 2017 -0800 @@ -9,5 +9,6 @@ void render_update_display(void); void render_set_ui_render_fun(ui_render_fun); void render_set_event_handler(event_handler handler); +void render_set_gl_context_handlers(ui_render_fun destroy, ui_render_fun create); #endif //RENDER_SDL_H_