From a11cbb458f69a5d03c5a51832cab1ca86b3ba7b4 Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Fri, 11 Jun 2021 09:18:52 +0100 Subject: [PATCH] Added screenshot functionality, contributed by badd10de, thank you! --- .gitignore | 3 ++- src/uxnemu.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7f7ecce..04b83fc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ /bin *io.bit *.bak -/*-test \ No newline at end of file +/*-test +/screenshot.bmp diff --git a/src/uxnemu.c b/src/uxnemu.c index d2b8b48..7746ce8 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -84,6 +84,18 @@ togglezoom(Uxn *u) redraw(u); } +void +save_screenshot(void) +{ + const Uint32 format = SDL_PIXELFORMAT_ARGB8888; + SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(0, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom, 32, format); + SDL_LockSurface(surface); + SDL_RenderReadPixels(gRenderer, NULL, format, surface->pixels, surface->pitch); + SDL_UnlockSurface(surface); + SDL_SaveBMP(surface, "screenshot.bmp"); + SDL_FreeSurface(surface); +} + void quit(void) { @@ -178,7 +190,9 @@ doctrl(Uxn *u, SDL_Event *event, int z) toggledebug(u); if(SDL_GetModState() & KMOD_LALT) togglezoom(u); - } + } else if(z && event->key.keysym.sym == SDLK_s) + if(SDL_GetModState() & KMOD_LCTRL) + save_screenshot(); switch(event->key.keysym.sym) { case SDLK_LCTRL: flag = 0x01; break; case SDLK_LALT: flag = 0x02; break;