Mercurial > repos > blastem
comparison 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 |
comparison
equal
deleted
inserted
replaced
1647:5a662692c215 | 1649:b500e971da75 |
---|---|
27 static SDL_Window *main_window; | 27 static SDL_Window *main_window; |
28 static SDL_Window **extra_windows; | 28 static SDL_Window **extra_windows; |
29 static SDL_Renderer *main_renderer; | 29 static SDL_Renderer *main_renderer; |
30 static SDL_Renderer **extra_renderers; | 30 static SDL_Renderer **extra_renderers; |
31 static SDL_Texture **sdl_textures; | 31 static SDL_Texture **sdl_textures; |
32 static window_close_handler *close_handlers; | |
32 static uint8_t num_textures; | 33 static uint8_t num_textures; |
33 static SDL_Rect main_clip; | 34 static SDL_Rect main_clip; |
34 static SDL_GLContext *main_context; | 35 static SDL_GLContext *main_context; |
35 | 36 |
36 static int main_width, main_height, windowed_width, windowed_height, is_fullscreen; | 37 static int main_width, main_height, windowed_width, windowed_height, is_fullscreen; |
919 on_context_created(); | 920 on_context_created(); |
920 } | 921 } |
921 } | 922 } |
922 #endif | 923 #endif |
923 break; | 924 break; |
925 case SDL_WINDOWEVENT_CLOSE: | |
926 if (SDL_GetWindowID(main_window) == event->window.windowID) { | |
927 exit(0); | |
928 } else { | |
929 for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) | |
930 { | |
931 if (SDL_GetWindowID(extra_windows[i]) == event->window.windowID) { | |
932 if (close_handlers[i]) { | |
933 close_handlers[i](i + FRAMEBUFFER_USER_START); | |
934 } | |
935 break; | |
936 } | |
937 } | |
938 } | |
939 break; | |
924 } | 940 } |
925 break; | 941 break; |
926 case SDL_DROPFILE: | 942 case SDL_DROPFILE: |
927 if (drag_drop_handler) { | 943 if (drag_drop_handler) { |
928 drag_drop_handler(event->drop.file); | 944 drag_drop_handler(event->drop.file); |
1324 free(screenshot_path); | 1340 free(screenshot_path); |
1325 } | 1341 } |
1326 screenshot_path = path; | 1342 screenshot_path = path; |
1327 } | 1343 } |
1328 | 1344 |
1329 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height) | 1345 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) |
1330 { | 1346 { |
1331 uint8_t win_idx = 0xFF; | 1347 uint8_t win_idx = 0xFF; |
1332 for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) | 1348 for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) |
1333 { | 1349 { |
1334 if (!extra_windows[i]) { | 1350 if (!extra_windows[i]) { |
1340 if (win_idx == 0xFF) { | 1356 if (win_idx == 0xFF) { |
1341 num_textures++; | 1357 num_textures++; |
1342 sdl_textures = realloc(sdl_textures, num_textures * sizeof(*sdl_textures)); | 1358 sdl_textures = realloc(sdl_textures, num_textures * sizeof(*sdl_textures)); |
1343 extra_windows = realloc(extra_windows, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_windows)); | 1359 extra_windows = realloc(extra_windows, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_windows)); |
1344 extra_renderers = realloc(extra_renderers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_renderers)); | 1360 extra_renderers = realloc(extra_renderers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_renderers)); |
1361 close_handlers = realloc(close_handlers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*close_handlers)); | |
1345 win_idx = num_textures - FRAMEBUFFER_USER_START - 1; | 1362 win_idx = num_textures - FRAMEBUFFER_USER_START - 1; |
1346 } | 1363 } |
1347 extra_windows[win_idx] = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); | 1364 extra_windows[win_idx] = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); |
1348 if (!extra_windows[win_idx]) { | 1365 if (!extra_windows[win_idx]) { |
1349 goto fail_window; | 1366 goto fail_window; |
1355 uint8_t texture_idx = win_idx + FRAMEBUFFER_USER_START; | 1372 uint8_t texture_idx = win_idx + FRAMEBUFFER_USER_START; |
1356 sdl_textures[texture_idx] = SDL_CreateTexture(extra_renderers[win_idx], SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); | 1373 sdl_textures[texture_idx] = SDL_CreateTexture(extra_renderers[win_idx], SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); |
1357 if (!sdl_textures[texture_idx]) { | 1374 if (!sdl_textures[texture_idx]) { |
1358 goto fail_texture; | 1375 goto fail_texture; |
1359 } | 1376 } |
1377 close_handlers[win_idx] = close_handler; | |
1360 return texture_idx; | 1378 return texture_idx; |
1361 | 1379 |
1362 fail_texture: | 1380 fail_texture: |
1363 SDL_DestroyRenderer(extra_renderers[win_idx]); | 1381 SDL_DestroyRenderer(extra_renderers[win_idx]); |
1364 fail_renderer: | 1382 fail_renderer: |