uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit a11cbb458f69a5d03c5a51832cab1ca86b3ba7b4
parent 064f7745d4faee1e41e9cb4ade5bc96f51fd7d14
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Fri, 11 Jun 2021 09:18:52 +0100

Added screenshot functionality, contributed by badd10de, thank you!

Diffstat:
M.gitignore | 4++--
Msrc/uxnemu.c | 16+++++++++++++++-
2 files changed, 17 insertions(+), 3 deletions(-)

diff --git 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 @@ -85,6 +85,18 @@ togglezoom(Uxn *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) { free(ppu.fg.pixels); @@ -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;