Atlas - testurl.c
Home / ext / SDL / test Lines: 1 | Size: 2694 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 3 4 This software is provided 'as-is', without any express or implied 5 warranty. In no event will the authors be held liable for any damages 6 arising from the use of this software. 7 8 Permission is granted to anyone to use this software for any purpose, 9 including commercial applications, and to alter it and redistribute it 10 freely. 11*/ 12#include <SDL3/SDL.h> 13#include <SDL3/SDL_main.h> 14#include <SDL3/SDL_test.h> 15 16static void tryOpenURL(const char *url) 17{ 18 SDL_Log("Opening '%s' ...", url); 19 if (SDL_OpenURL(url)) { 20 SDL_Log(" success!"); 21 } else { 22 SDL_Log(" failed! %s", SDL_GetError()); 23 } 24} 25 26int main(int argc, char **argv) 27{ 28 const char *url = NULL; 29 SDLTest_CommonState *state = SDLTest_CommonCreateState(argv, 0); 30 bool use_gui = false; 31 32 /* Parse commandline */ 33 for (int i = 1; i < argc;) { 34 int consumed; 35 36 consumed = SDLTest_CommonArg(state, i); 37 if (consumed == 0) { 38 if (argv[i][0] != '-') { 39 url = argv[i]; 40 consumed = 1; 41 } else if (SDL_strcasecmp(argv[i], "--gui") == 0) { 42 use_gui = true; 43 consumed = 1; 44 } 45 } 46 if (consumed <= 0) { 47 static const char *options[] = { 48 "[--gui]" 49 "[URL [...]]", 50 NULL, 51 }; 52 SDLTest_CommonLogUsage(state, argv[0], options); 53 return SDL_APP_FAILURE; 54 } 55 i += consumed; 56 } 57 58 state->flags = SDL_INIT_VIDEO; 59 if (!SDLTest_CommonInit(state)) { 60 return SDL_APP_FAILURE; 61 } 62 63 if (!use_gui) { 64 tryOpenURL(url); 65 } else { 66 SDL_Event event; 67 bool quit = false; 68 69 while (!quit) { 70 while (SDL_PollEvent(&event)) { 71 if (event.type == SDL_EVENT_KEY_DOWN) { 72 if (event.key.key == SDLK_SPACE) { 73 tryOpenURL(url); 74 } else if (event.key.key == SDLK_ESCAPE) { 75 quit = true; 76 } 77 } else if (event.type == SDL_EVENT_QUIT) { 78 quit = true; 79 } 80 } 81 82 SDL_SetRenderDrawColor(state->renderers[0], 0, 0, 0, 255); 83 SDL_RenderClear(state->renderers[0]); 84 SDL_SetRenderDrawColor(state->renderers[0], 255, 255, 255, 255); 85 SDL_RenderDebugTextFormat(state->renderers[0], 8.f, 16.f, "Press space to open %s", url); 86 SDL_RenderPresent(state->renderers[0]); 87 } 88 } 89 90 SDL_Quit(); 91 SDLTest_CommonDestroyState(state); 92 return 0; 93} 94[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.