Mercurial > repos > blastem
diff render_sdl.c @ 1649:b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 18 Dec 2018 19:58:00 -0800 |
parents | c6b2c0f8cc61 |
children | fa9ae059e4d3 |
line wrap: on
line diff
--- a/render_sdl.c Sat Dec 15 13:06:47 2018 -0800 +++ b/render_sdl.c Tue Dec 18 19:58:00 2018 -0800 @@ -29,6 +29,7 @@ static SDL_Renderer *main_renderer; static SDL_Renderer **extra_renderers; static SDL_Texture **sdl_textures; +static window_close_handler *close_handlers; static uint8_t num_textures; static SDL_Rect main_clip; static SDL_GLContext *main_context; @@ -921,6 +922,21 @@ } #endif break; + case SDL_WINDOWEVENT_CLOSE: + if (SDL_GetWindowID(main_window) == event->window.windowID) { + exit(0); + } else { + for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) + { + if (SDL_GetWindowID(extra_windows[i]) == event->window.windowID) { + if (close_handlers[i]) { + close_handlers[i](i + FRAMEBUFFER_USER_START); + } + break; + } + } + } + break; } break; case SDL_DROPFILE: @@ -1326,7 +1342,7 @@ screenshot_path = path; } -uint8_t render_create_window(char *caption, uint32_t width, uint32_t height) +uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) { uint8_t win_idx = 0xFF; for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) @@ -1342,6 +1358,7 @@ sdl_textures = realloc(sdl_textures, num_textures * sizeof(*sdl_textures)); extra_windows = realloc(extra_windows, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_windows)); extra_renderers = realloc(extra_renderers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_renderers)); + close_handlers = realloc(close_handlers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*close_handlers)); win_idx = num_textures - FRAMEBUFFER_USER_START - 1; } extra_windows[win_idx] = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); @@ -1357,6 +1374,7 @@ if (!sdl_textures[texture_idx]) { goto fail_texture; } + close_handlers[win_idx] = close_handler; return texture_idx; fail_texture: