SDL_test_common.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  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. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_test_common.h
  20. *
  21. * Common functions of SDL test framework.
  22. *
  23. * This code is a part of the SDL test library, not the main SDL library.
  24. */
  25. /* Ported from original test/common.h file. */
  26. #ifndef SDL_test_common_h_
  27. #define SDL_test_common_h_
  28. #include <SDL3/SDL.h>
  29. #ifdef SDL_PLATFORM_PSP
  30. #define DEFAULT_WINDOW_WIDTH 480
  31. #define DEFAULT_WINDOW_HEIGHT 272
  32. #elif defined(SDL_PLATFORM_VITA)
  33. #define DEFAULT_WINDOW_WIDTH 960
  34. #define DEFAULT_WINDOW_HEIGHT 544
  35. #else
  36. #define DEFAULT_WINDOW_WIDTH 640
  37. #define DEFAULT_WINDOW_HEIGHT 480
  38. #endif
  39. typedef Uint32 SDLTest_VerboseFlags;
  40. #define VERBOSE_VIDEO 0x00000001
  41. #define VERBOSE_MODES 0x00000002
  42. #define VERBOSE_RENDER 0x00000004
  43. #define VERBOSE_EVENT 0x00000008
  44. #define VERBOSE_AUDIO 0x00000010
  45. #define VERBOSE_MOTION 0x00000020
  46. typedef struct
  47. {
  48. /* SDL init flags */
  49. char **argv;
  50. SDL_InitFlags flags;
  51. SDLTest_VerboseFlags verbose;
  52. /* Video info */
  53. const char *videodriver;
  54. int display_index;
  55. SDL_DisplayID displayID;
  56. const char *window_title;
  57. const char *window_icon;
  58. SDL_WindowFlags window_flags;
  59. SDL_bool flash_on_focus_loss;
  60. int window_x;
  61. int window_y;
  62. int window_w;
  63. int window_h;
  64. int window_minW;
  65. int window_minH;
  66. int window_maxW;
  67. int window_maxH;
  68. int logical_w;
  69. int logical_h;
  70. SDL_bool auto_scale_content;
  71. SDL_RendererLogicalPresentation logical_presentation;
  72. SDL_ScaleMode logical_scale_mode;
  73. float scale;
  74. int depth;
  75. float refresh_rate;
  76. SDL_bool fullscreen_exclusive;
  77. SDL_DisplayMode fullscreen_mode;
  78. int num_windows;
  79. SDL_Window **windows;
  80. /* Renderer info */
  81. const char *renderdriver;
  82. int render_vsync;
  83. SDL_bool skip_renderer;
  84. SDL_Renderer **renderers;
  85. SDL_Texture **targets;
  86. /* Audio info */
  87. const char *audiodriver;
  88. SDL_AudioFormat audio_format;
  89. int audio_channels;
  90. int audio_freq;
  91. SDL_AudioDeviceID audio_id;
  92. /* GL settings */
  93. int gl_red_size;
  94. int gl_green_size;
  95. int gl_blue_size;
  96. int gl_alpha_size;
  97. int gl_buffer_size;
  98. int gl_depth_size;
  99. int gl_stencil_size;
  100. int gl_double_buffer;
  101. int gl_accum_red_size;
  102. int gl_accum_green_size;
  103. int gl_accum_blue_size;
  104. int gl_accum_alpha_size;
  105. int gl_stereo;
  106. int gl_multisamplebuffers;
  107. int gl_multisamplesamples;
  108. int gl_retained_backing;
  109. int gl_accelerated;
  110. int gl_major_version;
  111. int gl_minor_version;
  112. int gl_debug;
  113. int gl_profile_mask;
  114. /* Mouse info */
  115. SDL_Rect confine;
  116. SDL_bool hide_cursor;
  117. } SDLTest_CommonState;
  118. #include <SDL3/SDL_begin_code.h>
  119. /* Set up for C function definitions, even when using C++ */
  120. #ifdef __cplusplus
  121. extern "C" {
  122. #endif
  123. /* Function prototypes */
  124. /**
  125. * Parse command line parameters and create common state.
  126. *
  127. * \param argv Array of command line parameters
  128. * \param flags Flags indicating which subsystem to initialize (i.e. SDL_INIT_VIDEO | SDL_INIT_AUDIO)
  129. *
  130. * \returns a newly allocated common state object.
  131. */
  132. SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, SDL_InitFlags flags);
  133. /**
  134. * Free the common state object.
  135. *
  136. * \param state The common state object to destroy
  137. */
  138. void SDLTest_CommonDestroyState(SDLTest_CommonState *state);
  139. /**
  140. * Process one common argument.
  141. *
  142. * \param state The common state describing the test window to create.
  143. * \param index The index of the argument to process in argv[].
  144. *
  145. * \returns the number of arguments processed (i.e. 1 for --fullscreen, 2 for --video [videodriver], or -1 on error.
  146. */
  147. int SDLTest_CommonArg(SDLTest_CommonState *state, int index);
  148. /**
  149. * Logs command line usage info.
  150. *
  151. * This logs the appropriate command line options for the subsystems in use
  152. * plus other common options, and then any application-specific options.
  153. * This uses the SDL_Log() function and splits up output to be friendly to
  154. * 80-character-wide terminals.
  155. *
  156. * \param state The common state describing the test window for the app.
  157. * \param argv0 argv[0], as passed to main/SDL_main.
  158. * \param options an array of strings for application specific options. The last element of the array should be NULL.
  159. */
  160. void SDLTest_CommonLogUsage(SDLTest_CommonState *state, const char *argv0, const char **options);
  161. /**
  162. * Open test window.
  163. *
  164. * \param state The common state describing the test window to create.
  165. *
  166. * \returns SDL_TRUE if initialization succeeded, false otherwise
  167. */
  168. SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state);
  169. /**
  170. * Easy argument handling when test app doesn't need any custom args.
  171. *
  172. * \param state The common state describing the test window to create.
  173. * \param argc argc, as supplied to SDL_main
  174. * \param argv argv, as supplied to SDL_main
  175. *
  176. * \returns SDL_FALSE if app should quit, true otherwise.
  177. */
  178. SDL_bool SDLTest_CommonDefaultArgs(SDLTest_CommonState *state, const int argc, char **argv);
  179. /**
  180. * Common event handler for test windows if you use a standard SDL_main.
  181. *
  182. * This will free data from the event, like the string in a drop event!
  183. *
  184. * \param state The common state used to create test window.
  185. * \param event The event to handle.
  186. * \param done Flag indicating we are done.
  187. */
  188. void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done);
  189. /**
  190. * Common event handler for test windows if you use SDL_AppEvent.
  191. *
  192. * This does _not_ free anything in `event`.
  193. *
  194. * \param state The common state used to create test window.
  195. * \param event The event to handle.
  196. * \returns Value suitable for returning from SDL_AppEvent().
  197. */
  198. int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event *event);
  199. /**
  200. * Close test window.
  201. *
  202. * \param state The common state used to create test window.
  203. *
  204. */
  205. void SDLTest_CommonQuit(SDLTest_CommonState *state);
  206. /**
  207. * Draws various window information (position, size, etc.) to the renderer.
  208. *
  209. * \param renderer The renderer to draw to.
  210. * \param window The window whose information should be displayed.
  211. * \param usedHeight Returns the height used, so the caller can draw more below.
  212. *
  213. */
  214. void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, float *usedHeight);
  215. /* Ends C function definitions when using C++ */
  216. #ifdef __cplusplus
  217. }
  218. #endif
  219. #include <SDL3/SDL_close_code.h>
  220. #endif /* SDL_test_common_h_ */