2020-10-05 11:30:33 -04:00
|
|
|
/*
|
2026-01-01 09:48:19 -08:00
|
|
|
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
2020-10-05 11:30:33 -04:00
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
|
freely.
|
|
|
|
|
*/
|
2022-11-26 20:43:38 -08:00
|
|
|
#include <SDL3/SDL.h>
|
2022-12-15 05:58:20 +01:00
|
|
|
#include <SDL3/SDL_main.h>
|
2025-11-17 13:24:16 +01:00
|
|
|
#include <SDL3/SDL_test.h>
|
2020-10-05 11:30:33 -04:00
|
|
|
|
2022-07-01 19:59:06 +01:00
|
|
|
static void tryOpenURL(const char *url)
|
|
|
|
|
{
|
|
|
|
|
SDL_Log("Opening '%s' ...", url);
|
2024-08-22 17:33:49 -07:00
|
|
|
if (SDL_OpenURL(url)) {
|
2022-07-01 19:59:06 +01:00
|
|
|
SDL_Log(" success!");
|
|
|
|
|
} else {
|
|
|
|
|
SDL_Log(" failed! %s", SDL_GetError());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 11:30:33 -04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2026-04-04 22:28:06 -04:00
|
|
|
const char *url = NULL;
|
|
|
|
|
SDLTest_CommonState *state = SDLTest_CommonCreateState(argv, 0);
|
|
|
|
|
bool use_gui = false;
|
2020-10-05 11:30:33 -04:00
|
|
|
|
2025-11-17 13:24:16 +01:00
|
|
|
/* Parse commandline */
|
2026-04-04 22:28:06 -04:00
|
|
|
for (int i = 1; i < argc;) {
|
2025-11-17 13:24:16 +01:00
|
|
|
int consumed;
|
|
|
|
|
|
|
|
|
|
consumed = SDLTest_CommonArg(state, i);
|
|
|
|
|
if (consumed == 0) {
|
|
|
|
|
if (argv[i][0] != '-') {
|
2026-04-04 22:28:06 -04:00
|
|
|
url = argv[i];
|
|
|
|
|
consumed = 1;
|
|
|
|
|
} else if (SDL_strcasecmp(argv[i], "--gui") == 0) {
|
|
|
|
|
use_gui = true;
|
2025-11-17 13:24:16 +01:00
|
|
|
consumed = 1;
|
|
|
|
|
}
|
2020-10-05 11:30:33 -04:00
|
|
|
}
|
2025-11-17 13:24:16 +01:00
|
|
|
if (consumed <= 0) {
|
|
|
|
|
static const char *options[] = {
|
2026-04-04 22:28:06 -04:00
|
|
|
"[--gui]"
|
2025-11-17 13:24:16 +01:00
|
|
|
"[URL [...]]",
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
SDLTest_CommonLogUsage(state, argv[0], options);
|
|
|
|
|
return SDL_APP_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
i += consumed;
|
2020-10-05 11:30:33 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-04 22:28:06 -04:00
|
|
|
state->flags = SDL_INIT_VIDEO;
|
|
|
|
|
if (!SDLTest_CommonInit(state)) {
|
|
|
|
|
return SDL_APP_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!use_gui) {
|
|
|
|
|
tryOpenURL(url);
|
|
|
|
|
} else {
|
|
|
|
|
SDL_Event event;
|
|
|
|
|
bool quit = false;
|
|
|
|
|
|
|
|
|
|
while (!quit) {
|
|
|
|
|
while (SDL_PollEvent(&event)) {
|
|
|
|
|
if (event.type == SDL_EVENT_KEY_DOWN) {
|
|
|
|
|
if (event.key.key == SDLK_SPACE) {
|
|
|
|
|
tryOpenURL(url);
|
|
|
|
|
} else if (event.key.key == SDLK_ESCAPE) {
|
|
|
|
|
quit = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (event.type == SDL_EVENT_QUIT) {
|
|
|
|
|
quit = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_SetRenderDrawColor(state->renderers[0], 0, 0, 0, 255);
|
|
|
|
|
SDL_RenderClear(state->renderers[0]);
|
|
|
|
|
SDL_SetRenderDrawColor(state->renderers[0], 255, 255, 255, 255);
|
|
|
|
|
SDL_RenderDebugTextFormat(state->renderers[0], 8.f, 16.f, "Press space to open %s", url);
|
|
|
|
|
SDL_RenderPresent(state->renderers[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 11:30:33 -04:00
|
|
|
SDL_Quit();
|
2025-11-17 13:24:16 +01:00
|
|
|
SDLTest_CommonDestroyState(state);
|
2020-10-05 11:30:33 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|