From 2eb14f09e12826d3e33ee1ab44949f22b6d85ae1 Mon Sep 17 00:00:00 2001 From: lif <> Date: Tue, 24 Dec 2024 13:47:31 -0800 Subject: [PATCH] first pass, broken on xdg-portal because of course it is. thanks dbus --- main.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 2fbf92b..2260859 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,8 @@ #define SDL_MAIN_USE_CALLBACKS 1 +#include "SDL3/SDL_atomic.h" #include "SDL3/SDL_blendmode.h" #include "SDL3/SDL_camera.h" +#include "SDL3/SDL_dialog.h" #include "SDL3/SDL_error.h" #include "SDL3/SDL_events.h" #include "SDL3/SDL_init.h" @@ -79,6 +81,17 @@ enum mColorFormat pixfmt_sdl_to_mgba(uint32_t sdl_fmt) { } } +const SDL_DialogFileFilter DIALOG_FILENAME_FILTER[1] = {{ "Gameboy Camera ROM", "gb" }}; + +static void SDLCALL dialog_callback(void* userdata, const char* const* files, int filter) { + if (files && *files) { + SDL_Log("\nSelected: %s", *files); + SDL_SetAtomicPointer((void**)userdata, strdup(*files)); + } else { + exit(1); + } +} + void myStartRequestImageRed(struct mImageSource* self, unsigned w, unsigned h, int colorFormats) { SDL_DestroySurface(scaled); SDL_DestroySurface(filtered[0]); @@ -256,7 +269,7 @@ bool SelectCamera(struct AppState* st) { return true; } -SDL_AppResult SDL_AppInit(void** appstate, int argc, char *argv[]) { +SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) { int i; unsigned w, h; @@ -275,6 +288,16 @@ SDL_AppResult SDL_AppInit(void** appstate, int argc, char *argv[]) { return SDL_APP_FAILURE; } + if (!args.fname) { + SDL_ShowOpenFileDialog(dialog_callback, &args.fname, NULL, DIALOG_FILENAME_FILTER, 1, NULL, false); + printf("Must provide a Gameboy Camera ROM"); + do { + putchar('.'); + fflush(stdout); + SDL_Delay(1000); + } while (!SDL_GetAtomicPointer((void**)&args.fname)); + } + gb_img_src[0].requestImage = myRequestImageRed; gb_img_src[0].startRequestImage = myStartRequestImageRed; gb_img_src[0].stopRequestImage = myStopRequestImageRed;