changeset 1477:1cdd7f492af8 nuklear_ui

Pause menu now triggered on ui.exit event
author Michael Pavone <pavone@retrodev.com>
date Wed, 22 Nov 2017 11:18:36 -0800
parents 0646ae0987c3
children da1dce39e846
files io.c nuklear_ui/blastem_nuklear.c nuklear_ui/blastem_nuklear.h
diffstat 3 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/io.c	Wed Nov 22 10:54:27 2017 -0800
+++ b/io.c	Wed Nov 22 11:18:36 2017 -0800
@@ -23,6 +23,9 @@
 #include "render.h"
 #include "util.h"
 #include "menu.h"
+#ifndef DISABLE_NUKLEAR
+#include "nuklear_ui/blastem_nuklear.h"
+#endif
 
 #define CYCLE_NEVER 0xFFFFFFFF
 #define MIN_POLL_INTERVAL 6840
@@ -532,6 +535,11 @@
 			break;
 		}
 		case UI_EXIT:
+#ifndef DISABLE_NUKLEAR
+			if (is_nuklear_active) {
+				show_pause_menu();
+			} else {
+#endif
 			current_system->request_exit(current_system);
 			if (current_system->type == SYSTEM_GENESIS) {
 				genesis_context *gen = (genesis_context *)current_system;
@@ -541,6 +549,9 @@
 					menu->external_game_load = 1;
 				}
 			}
+#ifndef DISABLE_NUKLEAR
+			}
+#endif
 			break;
 		}
 		break;
--- a/nuklear_ui/blastem_nuklear.c	Wed Nov 22 10:54:27 2017 -0800
+++ b/nuklear_ui/blastem_nuklear.c	Wed Nov 22 11:18:36 2017 -0800
@@ -190,6 +190,19 @@
 	nk_style_set_font(context, &def_font->handle);
 }
 
+void show_pause_menu(void)
+{
+	context->style.window.background = nk_rgba(0, 0, 0, 128);
+	context->style.window.fixed_background = nk_style_item_color(nk_rgba(0, 0, 0, 128));
+	current_view = view_pause;
+}
+
+static uint8_t active;
+uint8_t is_nuklear_active(void)
+{
+	return active;
+}
+
 void blastem_nuklear_init(uint8_t file_loaded)
 {
 	context = nk_sdl_init(render_get_window());
@@ -207,5 +220,6 @@
 	render_set_ui_render_fun(blastem_nuklear_render);
 	render_set_event_handler(handle_event);
 	render_set_gl_context_handlers(context_destroyed, context_created);
+	active = 1;
 	idle_loop();
 }
--- a/nuklear_ui/blastem_nuklear.h	Wed Nov 22 10:54:27 2017 -0800
+++ b/nuklear_ui/blastem_nuklear.h	Wed Nov 22 11:18:36 2017 -0800
@@ -12,5 +12,7 @@
 #include "nuklear_sdl_gles2.h"
 
 void blastem_nuklear_init(uint8_t file_loaded);
+void show_pause_menu(void);
+uint8_t is_nuklear_active(void);
 
 #endif //BLASTEM_NUKLEAR_H_