SDL  2.0
SDL_test_common.h File Reference
#include "SDL.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_test_common.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDLTest_CommonState
 

Macros

#define DEFAULT_WINDOW_WIDTH   640
 
#define DEFAULT_WINDOW_HEIGHT   480
 
#define VERBOSE_VIDEO   0x00000001
 
#define VERBOSE_MODES   0x00000002
 
#define VERBOSE_RENDER   0x00000004
 
#define VERBOSE_EVENT   0x00000008
 
#define VERBOSE_AUDIO   0x00000010
 

Functions

SDLTest_CommonStateSDLTest_CommonCreateState (char **argv, Uint32 flags)
 Parse command line parameters and create common state. More...
 
int SDLTest_CommonArg (SDLTest_CommonState *state, int index)
 Process one common argument. More...
 
const char * SDLTest_CommonUsage (SDLTest_CommonState *state)
 Returns common usage information. More...
 
SDL_bool SDLTest_CommonInit (SDLTest_CommonState *state)
 Open test window. More...
 
void SDLTest_CommonEvent (SDLTest_CommonState *state, SDL_Event *event, int *done)
 Common event handler for test windows. More...
 
void SDLTest_CommonQuit (SDLTest_CommonState *state)
 Close test window. More...
 

Detailed Description

Include file for SDL test framework.

This code is a part of the SDL2_test library, not the main SDL library.

Definition in file SDL_test_common.h.

Macro Definition Documentation

◆ DEFAULT_WINDOW_HEIGHT

#define DEFAULT_WINDOW_HEIGHT   480

Definition at line 42 of file SDL_test_common.h.

Referenced by main(), and SDLTest_CommonCreateState().

◆ DEFAULT_WINDOW_WIDTH

#define DEFAULT_WINDOW_WIDTH   640

Definition at line 41 of file SDL_test_common.h.

Referenced by InitInput(), main(), and SDLTest_CommonCreateState().

◆ VERBOSE_AUDIO

#define VERBOSE_AUDIO   0x00000010

Definition at line 49 of file SDL_test_common.h.

Referenced by SDLTest_CommonInit().

◆ VERBOSE_EVENT

#define VERBOSE_EVENT   0x00000008

Definition at line 48 of file SDL_test_common.h.

Referenced by SDLTest_CommonArg(), and SDLTest_CommonEvent().

◆ VERBOSE_MODES

#define VERBOSE_MODES   0x00000002

Definition at line 46 of file SDL_test_common.h.

Referenced by SDLTest_CommonArg(), and SDLTest_CommonInit().

◆ VERBOSE_RENDER

#define VERBOSE_RENDER   0x00000004

Definition at line 47 of file SDL_test_common.h.

Referenced by SDLTest_CommonArg(), and SDLTest_CommonInit().

◆ VERBOSE_VIDEO

#define VERBOSE_VIDEO   0x00000001

Definition at line 45 of file SDL_test_common.h.

Referenced by SDLTest_CommonArg(), and SDLTest_CommonInit().

Function Documentation

◆ SDLTest_CommonArg()

int SDLTest_CommonArg ( SDLTest_CommonState state,
int  index 
)

Process one common argument.

Parameters
stateThe common state describing the test window to create.
indexThe index of the argument to process in argv[].
Returns
The number of arguments processed (i.e. 1 for –fullscreen, 2 for –video [videodriver], or -1 on error.

Definition at line 106 of file SDL_test_common.c.

References SDLTest_CommonState::argv, AUDIO_S16, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S8, AUDIO_U16, AUDIO_U16LSB, AUDIO_U16MSB, AUDIO_U8, SDLTest_CommonState::audiospec, SDL_AudioSpec::channels, SDLTest_CommonState::depth, SDLTest_CommonState::display, SDL_AudioSpec::format, SDL_AudioSpec::freq, SDLTest_CommonState::gl_debug, SDLTest_CommonState::logical_h, SDLTest_CommonState::logical_w, SDLTest_CommonState::num_windows, SDLTest_CommonState::refresh_rate, SDLTest_CommonState::render_flags, SDLTest_CommonState::renderdriver, SDL_AudioSpec::samples, SDLTest_CommonState::scale, SDL_atof, SDL_atoi, SDL_isdigit, SDL_LOG_CATEGORY_AUDIO, SDL_LOG_CATEGORY_ERROR, SDL_LOG_CATEGORY_INPUT, SDL_LOG_CATEGORY_RENDER, SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_CATEGORY_VIDEO, SDL_LOG_PRIORITY_VERBOSE, SDL_LogSetAllPriority, SDL_LogSetPriority, SDL_RENDERER_PRESENTVSYNC, SDL_strcasecmp, SDL_strcmp, SDL_WINDOW_ALLOW_HIGHDPI, SDL_WINDOW_BORDERLESS, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_INPUT_GRABBED, SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MINIMIZED, SDL_WINDOW_RESIZABLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED_DISPLAY, SDL_WINDOWPOS_ISCENTERED, SDL_WINDOWPOS_ISUNDEFINED, SDL_WINDOWPOS_UNDEFINED_DISPLAY, SDLTest_CommonState::verbose, VERBOSE_EVENT, VERBOSE_MODES, VERBOSE_RENDER, VERBOSE_VIDEO, SDLTest_CommonState::videodriver, SDLTest_CommonState::window_flags, SDLTest_CommonState::window_h, SDLTest_CommonState::window_icon, SDLTest_CommonState::window_maxH, SDLTest_CommonState::window_maxW, SDLTest_CommonState::window_minH, SDLTest_CommonState::window_minW, SDLTest_CommonState::window_title, SDLTest_CommonState::window_w, SDLTest_CommonState::window_x, and SDLTest_CommonState::window_y.

Referenced by main().

107 {
108  char **argv = state->argv;
109 
110  if (SDL_strcasecmp(argv[index], "--video") == 0) {
111  ++index;
112  if (!argv[index]) {
113  return -1;
114  }
115  state->videodriver = argv[index];
116  return 2;
117  }
118  if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
119  ++index;
120  if (!argv[index]) {
121  return -1;
122  }
123  state->renderdriver = argv[index];
124  return 2;
125  }
126  if (SDL_strcasecmp(argv[index], "--gldebug") == 0) {
127  state->gl_debug = 1;
128  return 1;
129  }
130  if (SDL_strcasecmp(argv[index], "--info") == 0) {
131  ++index;
132  if (!argv[index]) {
133  return -1;
134  }
135  if (SDL_strcasecmp(argv[index], "all") == 0) {
136  state->verbose |=
138  VERBOSE_EVENT);
139  return 2;
140  }
141  if (SDL_strcasecmp(argv[index], "video") == 0) {
142  state->verbose |= VERBOSE_VIDEO;
143  return 2;
144  }
145  if (SDL_strcasecmp(argv[index], "modes") == 0) {
146  state->verbose |= VERBOSE_MODES;
147  return 2;
148  }
149  if (SDL_strcasecmp(argv[index], "render") == 0) {
150  state->verbose |= VERBOSE_RENDER;
151  return 2;
152  }
153  if (SDL_strcasecmp(argv[index], "event") == 0) {
154  state->verbose |= VERBOSE_EVENT;
155  return 2;
156  }
157  return -1;
158  }
159  if (SDL_strcasecmp(argv[index], "--log") == 0) {
160  ++index;
161  if (!argv[index]) {
162  return -1;
163  }
164  if (SDL_strcasecmp(argv[index], "all") == 0) {
166  return 2;
167  }
168  if (SDL_strcasecmp(argv[index], "error") == 0) {
170  return 2;
171  }
172  if (SDL_strcasecmp(argv[index], "system") == 0) {
174  return 2;
175  }
176  if (SDL_strcasecmp(argv[index], "audio") == 0) {
178  return 2;
179  }
180  if (SDL_strcasecmp(argv[index], "video") == 0) {
182  return 2;
183  }
184  if (SDL_strcasecmp(argv[index], "render") == 0) {
186  return 2;
187  }
188  if (SDL_strcasecmp(argv[index], "input") == 0) {
190  return 2;
191  }
192  return -1;
193  }
194  if (SDL_strcasecmp(argv[index], "--display") == 0) {
195  ++index;
196  if (!argv[index]) {
197  return -1;
198  }
199  state->display = SDL_atoi(argv[index]);
200  if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
203  }
204  if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) {
207  }
208  return 2;
209  }
210  if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
212  state->num_windows = 1;
213  return 1;
214  }
215  if (SDL_strcasecmp(argv[index], "--fullscreen-desktop") == 0) {
217  state->num_windows = 1;
218  return 1;
219  }
220  if (SDL_strcasecmp(argv[index], "--allow-highdpi") == 0) {
222  return 1;
223  }
224  if (SDL_strcasecmp(argv[index], "--windows") == 0) {
225  ++index;
226  if (!argv[index] || !SDL_isdigit(*argv[index])) {
227  return -1;
228  }
229  if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
230  state->num_windows = SDL_atoi(argv[index]);
231  }
232  return 2;
233  }
234  if (SDL_strcasecmp(argv[index], "--title") == 0) {
235  ++index;
236  if (!argv[index]) {
237  return -1;
238  }
239  state->window_title = argv[index];
240  return 2;
241  }
242  if (SDL_strcasecmp(argv[index], "--icon") == 0) {
243  ++index;
244  if (!argv[index]) {
245  return -1;
246  }
247  state->window_icon = argv[index];
248  return 2;
249  }
250  if (SDL_strcasecmp(argv[index], "--center") == 0) {
253  return 1;
254  }
255  if (SDL_strcasecmp(argv[index], "--position") == 0) {
256  char *x, *y;
257  ++index;
258  if (!argv[index]) {
259  return -1;
260  }
261  x = argv[index];
262  y = argv[index];
263  while (*y && *y != ',') {
264  ++y;
265  }
266  if (!*y) {
267  return -1;
268  }
269  *y++ = '\0';
270  state->window_x = SDL_atoi(x);
271  state->window_y = SDL_atoi(y);
272  return 2;
273  }
274  if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
275  char *w, *h;
276  ++index;
277  if (!argv[index]) {
278  return -1;
279  }
280  w = argv[index];
281  h = argv[index];
282  while (*h && *h != 'x') {
283  ++h;
284  }
285  if (!*h) {
286  return -1;
287  }
288  *h++ = '\0';
289  state->window_w = SDL_atoi(w);
290  state->window_h = SDL_atoi(h);
291  return 2;
292  }
293  if (SDL_strcasecmp(argv[index], "--min-geometry") == 0) {
294  char *w, *h;
295  ++index;
296  if (!argv[index]) {
297  return -1;
298  }
299  w = argv[index];
300  h = argv[index];
301  while (*h && *h != 'x') {
302  ++h;
303  }
304  if (!*h) {
305  return -1;
306  }
307  *h++ = '\0';
308  state->window_minW = SDL_atoi(w);
309  state->window_minH = SDL_atoi(h);
310  return 2;
311  }
312  if (SDL_strcasecmp(argv[index], "--max-geometry") == 0) {
313  char *w, *h;
314  ++index;
315  if (!argv[index]) {
316  return -1;
317  }
318  w = argv[index];
319  h = argv[index];
320  while (*h && *h != 'x') {
321  ++h;
322  }
323  if (!*h) {
324  return -1;
325  }
326  *h++ = '\0';
327  state->window_maxW = SDL_atoi(w);
328  state->window_maxH = SDL_atoi(h);
329  return 2;
330  }
331  if (SDL_strcasecmp(argv[index], "--logical") == 0) {
332  char *w, *h;
333  ++index;
334  if (!argv[index]) {
335  return -1;
336  }
337  w = argv[index];
338  h = argv[index];
339  while (*h && *h != 'x') {
340  ++h;
341  }
342  if (!*h) {
343  return -1;
344  }
345  *h++ = '\0';
346  state->logical_w = SDL_atoi(w);
347  state->logical_h = SDL_atoi(h);
348  return 2;
349  }
350  if (SDL_strcasecmp(argv[index], "--scale") == 0) {
351  ++index;
352  if (!argv[index]) {
353  return -1;
354  }
355  state->scale = (float)SDL_atof(argv[index]);
356  return 2;
357  }
358  if (SDL_strcasecmp(argv[index], "--depth") == 0) {
359  ++index;
360  if (!argv[index]) {
361  return -1;
362  }
363  state->depth = SDL_atoi(argv[index]);
364  return 2;
365  }
366  if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
367  ++index;
368  if (!argv[index]) {
369  return -1;
370  }
371  state->refresh_rate = SDL_atoi(argv[index]);
372  return 2;
373  }
374  if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
376  return 1;
377  }
378  if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
380  return 1;
381  }
382  if (SDL_strcasecmp(argv[index], "--resize") == 0) {
384  return 1;
385  }
386  if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
388  return 1;
389  }
390  if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
392  return 1;
393  }
394  if (SDL_strcasecmp(argv[index], "--grab") == 0) {
396  return 1;
397  }
398  if (SDL_strcasecmp(argv[index], "--rate") == 0) {
399  ++index;
400  if (!argv[index]) {
401  return -1;
402  }
403  state->audiospec.freq = SDL_atoi(argv[index]);
404  return 2;
405  }
406  if (SDL_strcasecmp(argv[index], "--format") == 0) {
407  ++index;
408  if (!argv[index]) {
409  return -1;
410  }
411  if (SDL_strcasecmp(argv[index], "U8") == 0) {
412  state->audiospec.format = AUDIO_U8;
413  return 2;
414  }
415  if (SDL_strcasecmp(argv[index], "S8") == 0) {
416  state->audiospec.format = AUDIO_S8;
417  return 2;
418  }
419  if (SDL_strcasecmp(argv[index], "U16") == 0) {
420  state->audiospec.format = AUDIO_U16;
421  return 2;
422  }
423  if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
424  state->audiospec.format = AUDIO_U16LSB;
425  return 2;
426  }
427  if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
428  state->audiospec.format = AUDIO_U16MSB;
429  return 2;
430  }
431  if (SDL_strcasecmp(argv[index], "S16") == 0) {
432  state->audiospec.format = AUDIO_S16;
433  return 2;
434  }
435  if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
436  state->audiospec.format = AUDIO_S16LSB;
437  return 2;
438  }
439  if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
440  state->audiospec.format = AUDIO_S16MSB;
441  return 2;
442  }
443  return -1;
444  }
445  if (SDL_strcasecmp(argv[index], "--channels") == 0) {
446  ++index;
447  if (!argv[index]) {
448  return -1;
449  }
450  state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
451  return 2;
452  }
453  if (SDL_strcasecmp(argv[index], "--samples") == 0) {
454  ++index;
455  if (!argv[index]) {
456  return -1;
457  }
458  state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
459  return 2;
460  }
461  if (SDL_strcasecmp(argv[index], "--trackmem") == 0) {
462  /* Already handled in SDLTest_CommonCreateState() */
463  return 1;
464  }
465  if ((SDL_strcasecmp(argv[index], "-h") == 0)
466  || (SDL_strcasecmp(argv[index], "--help") == 0)) {
467  /* Print the usage message */
468  return -1;
469  }
470  if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) {
471  /* Debug flag sent by Xcode */
472  return 2;
473  }
474  return 0;
475 }
#define SDL_WINDOWPOS_ISUNDEFINED(X)
Definition: SDL_video.h:131
#define SDL_WINDOWPOS_CENTERED
Definition: SDL_video.h:139
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
#define AUDIO_U16LSB
Definition: SDL_audio.h:91
GLfloat GLfloat GLfloat GLfloat h
const char * window_icon
uint8_t Uint8
Definition: SDL_stdinc.h:179
#define SDL_WINDOWPOS_ISCENTERED(X)
Definition: SDL_video.h:140
Uint16 samples
Definition: SDL_audio.h:184
const char * renderdriver
#define VERBOSE_EVENT
#define SDL_strcasecmp
SDL_AudioSpec audiospec
#define AUDIO_U8
Definition: SDL_audio.h:89
#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X)
Definition: SDL_video.h:129
#define SDL_atof
#define SDL_isdigit
Uint8 channels
Definition: SDL_audio.h:182
GLubyte GLubyte GLubyte GLubyte w
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
#define SDL_atoi
GLuint index
#define SDL_WINDOWPOS_CENTERED_DISPLAY(X)
Definition: SDL_video.h:138
#define SDL_LogSetPriority
#define VERBOSE_MODES
#define VERBOSE_RENDER
#define AUDIO_S16MSB
Definition: SDL_audio.h:94
SDL_AudioFormat format
Definition: SDL_audio.h:181
#define AUDIO_S16
Definition: SDL_audio.h:96
#define AUDIO_S16LSB
Definition: SDL_audio.h:92
uint16_t Uint16
Definition: SDL_stdinc.h:191
#define SDL_LogSetAllPriority
#define SDL_strcmp
#define AUDIO_U16
Definition: SDL_audio.h:95
#define VERBOSE_VIDEO
#define AUDIO_S8
Definition: SDL_audio.h:90
const char * videodriver
#define AUDIO_U16MSB
Definition: SDL_audio.h:93
const char * window_title

◆ SDLTest_CommonCreateState()

SDLTest_CommonState* SDLTest_CommonCreateState ( char **  argv,
Uint32  flags 
)

Parse command line parameters and create common state.

Parameters
argvArray of command line parameters
flagsFlags indicating which subsystem to initialize (i.e. SDL_INIT_VIDEO | SDL_INIT_AUDIO)
Returns
Returns a newly allocated common state object.

Definition at line 48 of file SDL_test_common.c.

References SDLTest_CommonState::argv, AUDIO_S16, SDLTest_CommonState::audiospec, SDL_AudioSpec::channels, DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH, SDLTest_CommonState::flags, SDL_AudioSpec::format, SDL_AudioSpec::freq, SDLTest_CommonState::gl_accelerated, SDLTest_CommonState::gl_accum_alpha_size, SDLTest_CommonState::gl_accum_blue_size, SDLTest_CommonState::gl_accum_green_size, SDLTest_CommonState::gl_accum_red_size, SDLTest_CommonState::gl_alpha_size, SDLTest_CommonState::gl_blue_size, SDLTest_CommonState::gl_buffer_size, SDLTest_CommonState::gl_debug, SDLTest_CommonState::gl_depth_size, SDLTest_CommonState::gl_double_buffer, SDLTest_CommonState::gl_green_size, SDLTest_CommonState::gl_multisamplebuffers, SDLTest_CommonState::gl_multisamplesamples, SDLTest_CommonState::gl_red_size, SDLTest_CommonState::gl_retained_backing, SDLTest_CommonState::gl_stencil_size, SDLTest_CommonState::gl_stereo, i, NULL, SDLTest_CommonState::num_windows, SDL_AudioSpec::samples, SDL_calloc, SDL_OutOfMemory, SDL_strcasecmp, SDL_WINDOWPOS_UNDEFINED, SDLTest_TrackAllocations(), state, SDLTest_CommonState::window_flags, SDLTest_CommonState::window_h, SDLTest_CommonState::window_title, SDLTest_CommonState::window_w, SDLTest_CommonState::window_x, and SDLTest_CommonState::window_y.

Referenced by main().

49 {
50  int i;
52 
53  /* Do this first so we catch all allocations */
54  for (i = 1; argv[i]; ++i) {
55  if (SDL_strcasecmp(argv[i], "--trackmem") == 0) {
57  break;
58  }
59  }
60 
61  state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
62  if (!state) {
64  return NULL;
65  }
66 
67  /* Initialize some defaults */
68  state->argv = argv;
69  state->flags = flags;
70  state->window_title = argv[0];
71  state->window_flags = 0;
76  state->num_windows = 1;
77  state->audiospec.freq = 22050;
78  state->audiospec.format = AUDIO_S16;
79  state->audiospec.channels = 2;
80  state->audiospec.samples = 2048;
81 
82  /* Set some very sane GL defaults */
83  state->gl_red_size = 3;
84  state->gl_green_size = 3;
85  state->gl_blue_size = 2;
86  state->gl_alpha_size = 0;
87  state->gl_buffer_size = 0;
88  state->gl_depth_size = 16;
89  state->gl_stencil_size = 0;
90  state->gl_double_buffer = 1;
91  state->gl_accum_red_size = 0;
92  state->gl_accum_green_size = 0;
93  state->gl_accum_blue_size = 0;
94  state->gl_accum_alpha_size = 0;
95  state->gl_stereo = 0;
96  state->gl_multisamplebuffers = 0;
97  state->gl_multisamplesamples = 0;
98  state->gl_retained_backing = 1;
99  state->gl_accelerated = -1;
100  state->gl_debug = 0;
101 
102  return state;
103 }
struct xkb_state * state
Uint16 samples
Definition: SDL_audio.h:184
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:130
int SDLTest_TrackAllocations()
Start tracking SDL memory allocations.
#define SDL_strcasecmp
SDL_AudioSpec audiospec
Uint8 channels
Definition: SDL_audio.h:182
#define DEFAULT_WINDOW_HEIGHT
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
GLbitfield flags
#define SDL_calloc
SDL_AudioFormat format
Definition: SDL_audio.h:181
#define AUDIO_S16
Definition: SDL_audio.h:96
#define DEFAULT_WINDOW_WIDTH
const char * window_title

◆ SDLTest_CommonEvent()

void SDLTest_CommonEvent ( SDLTest_CommonState state,
SDL_Event event,
int *  done 
)

Common event handler for test windows.

Parameters
stateThe common state used to create test window.
eventThe event to handle.
doneFlag indicating we are done.

Definition at line 1463 of file SDL_test_common.c.

References SDL_Event::drop, SDL_WindowEvent::event, SDL_DropEvent::file, FullscreenTo(), SDL_Rect::h, i, SDL_Event::key, SDL_KeyboardEvent::keysym, KMOD_ALT, KMOD_CTRL, KMOD_SHIFT, NULL, SDLTest_CommonState::num_windows, SDLTest_CommonState::renderers, SDL_BUTTON_LMASK, SDL_BUTTON_MMASK, SDL_BUTTON_RMASK, SDL_BUTTON_X1MASK, SDL_BUTTON_X2MASK, SDL_CaptureMouse, SDL_DestroyRenderer, SDL_DestroyTexture, SDL_DestroyWindow, SDL_DROPFILE, SDL_DROPTEXT, SDL_FALSE, SDL_free, SDL_GetClipboardText, SDL_GetGlobalMouseState, SDL_GetKeyboardFocus, SDL_GetNumVideoDisplays, SDL_GetRelativeMouseMode, SDL_GetWindowDisplayIndex, SDL_GetWindowFlags, SDL_GetWindowFromID, SDL_GetWindowGrab, SDL_GetWindowOpacity, SDL_GetWindowPosition, SDL_GetWindowSize, SDL_KEYDOWN, SDL_Log, SDL_MaximizeWindow, SDL_MESSAGEBOX_INFORMATION, SDL_MinimizeWindow, SDL_MOUSEMOTION, SDL_QUIT, SDL_RectEmpty(), SDL_RenderGetClipRect, SDL_RenderSetClipRect, SDL_RestoreWindow, SDL_SetClipboardText, SDL_SetRelativeMouseMode, SDL_SetWindowBordered, SDL_SetWindowFullscreen, SDL_SetWindowGrab, SDL_SetWindowOpacity, SDL_SetWindowPosition, SDL_SetWindowSize, SDL_ShowSimpleMessageBox, SDL_snprintf, SDL_TRUE, SDL_WINDOW_BORDERLESS, SDL_WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MOUSE_CAPTURE, SDL_WINDOWEVENT, SDL_WINDOWEVENT_CLOSE, SDL_WINDOWPOS_CENTERED_DISPLAY, SDLK_0, SDLK_1, SDLK_2, SDLK_a, SDLK_b, SDLK_c, SDLK_DOWN, SDLK_EQUALS, SDLK_ESCAPE, SDLK_g, SDLK_LEFT, SDLK_m, SDLK_MINUS, SDLK_o, SDLK_PRINTSCREEN, SDLK_r, SDLK_RETURN, SDLK_RIGHT, SDLK_SPACE, SDLK_UP, SDLK_v, SDLK_z, SDLTest_PrintEvent(), SDLTest_ScreenShot(), SDL_Keysym::sym, SDLTest_CommonState::targets, text, SDL_Event::type, SDLTest_CommonState::verbose, VERBOSE_EVENT, SDL_Rect::w, SDL_Event::window, SDL_WindowEvent::windowID, SDL_KeyboardEvent::windowID, SDLTest_CommonState::windows, SDL_Rect::x, SDL_MouseMotionEvent::x, SDL_MouseMotionEvent::xrel, SDL_Rect::y, SDL_MouseMotionEvent::y, and SDL_MouseMotionEvent::yrel.

Referenced by loop(), and main().

1464 {
1465  int i;
1466  static SDL_MouseMotionEvent lastEvent;
1467 
1468  if (state->verbose & VERBOSE_EVENT) {
1469  SDLTest_PrintEvent(event);
1470  }
1471 
1472  switch (event->type) {
1473  case SDL_WINDOWEVENT:
1474  switch (event->window.event) {
1475  case SDL_WINDOWEVENT_CLOSE:
1476  {
1478  if (window) {
1479  for (i = 0; i < state->num_windows; ++i) {
1480  if (window == state->windows[i]) {
1481  if (state->targets[i]) {
1482  SDL_DestroyTexture(state->targets[i]);
1483  state->targets[i] = NULL;
1484  }
1485  if (state->renderers[i]) {
1486  SDL_DestroyRenderer(state->renderers[i]);
1487  state->renderers[i] = NULL;
1488  }
1489  SDL_DestroyWindow(state->windows[i]);
1490  state->windows[i] = NULL;
1491  break;
1492  }
1493  }
1494  }
1495  }
1496  break;
1497  }
1498  break;
1499  case SDL_KEYDOWN: {
1500  SDL_bool withControl = !!(event->key.keysym.mod & KMOD_CTRL);
1501  SDL_bool withShift = !!(event->key.keysym.mod & KMOD_SHIFT);
1502  SDL_bool withAlt = !!(event->key.keysym.mod & KMOD_ALT);
1503 
1504  switch (event->key.keysym.sym) {
1505  /* Add hotkeys here */
1506  case SDLK_PRINTSCREEN: {
1507  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1508  if (window) {
1509  for (i = 0; i < state->num_windows; ++i) {
1510  if (window == state->windows[i]) {
1511  SDLTest_ScreenShot(state->renderers[i]);
1512  }
1513  }
1514  }
1515  }
1516  break;
1517  case SDLK_EQUALS:
1518  if (withControl) {
1519  /* Ctrl-+ double the size of the window */
1520  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1521  if (window) {
1522  int w, h;
1523  SDL_GetWindowSize(window, &w, &h);
1524  SDL_SetWindowSize(window, w*2, h*2);
1525  }
1526  }
1527  break;
1528  case SDLK_MINUS:
1529  if (withControl) {
1530  /* Ctrl-- half the size of the window */
1531  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1532  if (window) {
1533  int w, h;
1534  SDL_GetWindowSize(window, &w, &h);
1535  SDL_SetWindowSize(window, w/2, h/2);
1536  }
1537  }
1538  break;
1539  case SDLK_UP:
1540  case SDLK_DOWN:
1541  case SDLK_LEFT:
1542  case SDLK_RIGHT:
1543  if (withAlt) {
1544  /* Alt-Up/Down/Left/Right switches between displays */
1545  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1546  if (window) {
1547  int currentIndex = SDL_GetWindowDisplayIndex(window);
1548  int numDisplays = SDL_GetNumVideoDisplays();
1549 
1550  if (currentIndex >= 0 && numDisplays >= 1) {
1551  int dest;
1552  if (event->key.keysym.sym == SDLK_UP || event->key.keysym.sym == SDLK_LEFT) {
1553  dest = (currentIndex + numDisplays - 1) % numDisplays;
1554  } else {
1555  dest = (currentIndex + numDisplays + 1) % numDisplays;
1556  }
1557  SDL_Log("Centering on display %d\n", dest);
1558  SDL_SetWindowPosition(window,
1561  }
1562  }
1563  }
1564  if (withShift) {
1565  /* Shift-Up/Down/Left/Right shift the window by 100px */
1566  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1567  if (window) {
1568  const int delta = 100;
1569  int x, y;
1570  SDL_GetWindowPosition(window, &x, &y);
1571 
1572  if (event->key.keysym.sym == SDLK_UP) y -= delta;
1573  if (event->key.keysym.sym == SDLK_DOWN) y += delta;
1574  if (event->key.keysym.sym == SDLK_LEFT) x -= delta;
1575  if (event->key.keysym.sym == SDLK_RIGHT) x += delta;
1576 
1577  SDL_Log("Setting position to (%d, %d)\n", x, y);
1578  SDL_SetWindowPosition(window, x, y);
1579  }
1580  }
1581  break;
1582  case SDLK_o:
1583  if (withControl) {
1584  /* Ctrl-O (or Ctrl-Shift-O) changes window opacity. */
1585  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1586  if (window) {
1587  float opacity;
1588  if (SDL_GetWindowOpacity(window, &opacity) == 0) {
1589  if (withShift) {
1590  opacity += 0.20f;
1591  } else {
1592  opacity -= 0.20f;
1593  }
1594  SDL_SetWindowOpacity(window, opacity);
1595  }
1596  }
1597  }
1598  break;
1599 
1600  case SDLK_c:
1601  if (withControl) {
1602  /* Ctrl-C copy awesome text! */
1603  SDL_SetClipboardText("SDL rocks!\nYou know it!");
1604  printf("Copied text to clipboard\n");
1605  }
1606  if (withAlt) {
1607  /* Alt-C toggle a render clip rectangle */
1608  for (i = 0; i < state->num_windows; ++i) {
1609  int w, h;
1610  if (state->renderers[i]) {
1611  SDL_Rect clip;
1612  SDL_GetWindowSize(state->windows[i], &w, &h);
1613  SDL_RenderGetClipRect(state->renderers[i], &clip);
1614  if (SDL_RectEmpty(&clip)) {
1615  clip.x = w/4;
1616  clip.y = h/4;
1617  clip.w = w/2;
1618  clip.h = h/2;
1619  SDL_RenderSetClipRect(state->renderers[i], &clip);
1620  } else {
1621  SDL_RenderSetClipRect(state->renderers[i], NULL);
1622  }
1623  }
1624  }
1625  }
1626  if (withShift) {
1627  SDL_Window *current_win = SDL_GetKeyboardFocus();
1628  if (current_win) {
1629  const SDL_bool shouldCapture = (SDL_GetWindowFlags(current_win) & SDL_WINDOW_MOUSE_CAPTURE) == 0;
1630  const int rc = SDL_CaptureMouse(shouldCapture);
1631  SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", (rc == 0) ? "succeeded" : "failed");
1632  }
1633  }
1634  break;
1635  case SDLK_v:
1636  if (withControl) {
1637  /* Ctrl-V paste awesome text! */
1638  char *text = SDL_GetClipboardText();
1639  if (*text) {
1640  printf("Clipboard: %s\n", text);
1641  } else {
1642  printf("Clipboard is empty\n");
1643  }
1644  SDL_free(text);
1645  }
1646  break;
1647  case SDLK_g:
1648  if (withControl) {
1649  /* Ctrl-G toggle grab */
1650  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1651  if (window) {
1652  SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window) ? SDL_TRUE : SDL_FALSE);
1653  }
1654  }
1655  break;
1656  case SDLK_m:
1657  if (withControl) {
1658  /* Ctrl-M maximize */
1659  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1660  if (window) {
1661  Uint32 flags = SDL_GetWindowFlags(window);
1662  if (flags & SDL_WINDOW_MAXIMIZED) {
1663  SDL_RestoreWindow(window);
1664  } else {
1665  SDL_MaximizeWindow(window);
1666  }
1667  }
1668  }
1669  break;
1670  case SDLK_r:
1671  if (withControl) {
1672  /* Ctrl-R toggle mouse relative mode */
1674  }
1675  break;
1676  case SDLK_z:
1677  if (withControl) {
1678  /* Ctrl-Z minimize */
1679  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1680  if (window) {
1681  SDL_MinimizeWindow(window);
1682  }
1683  }
1684  break;
1685  case SDLK_RETURN:
1686  if (withControl) {
1687  /* Ctrl-Enter toggle fullscreen */
1688  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1689  if (window) {
1690  Uint32 flags = SDL_GetWindowFlags(window);
1691  if (flags & SDL_WINDOW_FULLSCREEN) {
1693  } else {
1694  SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
1695  }
1696  }
1697  } else if (withAlt) {
1698  /* Alt-Enter toggle fullscreen desktop */
1699  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1700  if (window) {
1701  Uint32 flags = SDL_GetWindowFlags(window);
1702  if (flags & SDL_WINDOW_FULLSCREEN) {
1704  } else {
1706  }
1707  }
1708  } else if (withShift) {
1709  /* Shift-Enter toggle fullscreen desktop / fullscreen */
1710  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1711  if (window) {
1712  Uint32 flags = SDL_GetWindowFlags(window);
1713  if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
1715  } else {
1716  SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
1717  }
1718  }
1719  }
1720 
1721  break;
1722  case SDLK_b:
1723  if (withControl) {
1724  /* Ctrl-B toggle window border */
1725  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1726  if (window) {
1727  const Uint32 flags = SDL_GetWindowFlags(window);
1728  const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0) ? SDL_TRUE : SDL_FALSE;
1729  SDL_SetWindowBordered(window, b);
1730  }
1731  }
1732  break;
1733  case SDLK_a:
1734  if (withControl) {
1735  /* Ctrl-A reports absolute mouse position. */
1736  int x, y;
1737  const Uint32 mask = SDL_GetGlobalMouseState(&x, &y);
1738  SDL_Log("ABSOLUTE MOUSE: (%d, %d)%s%s%s%s%s\n", x, y,
1739  (mask & SDL_BUTTON_LMASK) ? " [LBUTTON]" : "",
1740  (mask & SDL_BUTTON_MMASK) ? " [MBUTTON]" : "",
1741  (mask & SDL_BUTTON_RMASK) ? " [RBUTTON]" : "",
1742  (mask & SDL_BUTTON_X1MASK) ? " [X2BUTTON]" : "",
1743  (mask & SDL_BUTTON_X2MASK) ? " [X2BUTTON]" : "");
1744  }
1745  break;
1746  case SDLK_0:
1747  if (withControl) {
1748  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1749  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
1750  }
1751  break;
1752  case SDLK_1:
1753  if (withControl) {
1754  FullscreenTo(0, event->key.windowID);
1755  }
1756  break;
1757  case SDLK_2:
1758  if (withControl) {
1759  FullscreenTo(1, event->key.windowID);
1760  }
1761  break;
1762  case SDLK_ESCAPE:
1763  *done = 1;
1764  break;
1765  case SDLK_SPACE:
1766  {
1767  char message[256];
1768  SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
1769 
1770  SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
1771  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window);
1772  break;
1773  }
1774  default:
1775  break;
1776  }
1777  break;
1778  }
1779  case SDL_QUIT:
1780  *done = 1;
1781  break;
1782  case SDL_MOUSEMOTION:
1783  lastEvent = event->motion;
1784  break;
1785 
1786  case SDL_DROPFILE:
1787  case SDL_DROPTEXT:
1788  SDL_free(event->drop.file);
1789  break;
1790  }
1791 }
SDL_Texture ** targets
#define SDL_GetWindowDisplayIndex
#define SDL_RenderGetClipRect
#define SDL_SetWindowFullscreen
#define SDL_BUTTON_RMASK
Definition: SDL_mouse.h:289
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLuint GLsizei const GLchar * message
#define KMOD_CTRL
Definition: SDL_keycode.h:342
#define SDL_BUTTON_X2MASK
Definition: SDL_mouse.h:291
GLfloat GLfloat GLfloat GLfloat h
#define SDL_SetWindowSize
#define SDL_GetWindowFlags
#define KMOD_ALT
Definition: SDL_keycode.h:344
#define VERBOSE_EVENT
#define SDL_SetRelativeMouseMode
#define SDL_GetKeyboardFocus
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define SDL_MinimizeWindow
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
Definition: SDL_rect.h:82
SDL_Window ** windows
#define SDL_GetNumVideoDisplays
SDL_WindowEvent window
Definition: SDL_events.h:562
#define SDL_GetWindowSize
#define SDL_Log
#define SDL_GetRelativeMouseMode
#define SDL_ShowSimpleMessageBox
#define SDL_GetClipboardText
#define SDL_SetWindowGrab
#define KMOD_SHIFT
Definition: SDL_keycode.h:343
#define SDL_free
int done
Definition: checkkeys.c:28
GLenum GLint GLuint mask
#define SDL_SetWindowOpacity
#define SDL_BUTTON_X1MASK
Definition: SDL_mouse.h:290
GLubyte GLubyte GLubyte GLubyte w
#define SDL_BUTTON_LMASK
Definition: SDL_mouse.h:287
#define SDL_GetWindowPosition
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
int x
Definition: SDL_rect.h:66
SDL_Keysym keysym
Definition: SDL_events.h:220
#define SDL_GetWindowFromID
int w
Definition: SDL_rect.h:67
#define SDL_RestoreWindow
SDL_Renderer ** renderers
static void SDLTest_PrintEvent(SDL_Event *event)
#define SDL_WINDOWPOS_CENTERED_DISPLAY(X)
Definition: SDL_video.h:138
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_GetWindowOpacity
#define NULL
Definition: begin_code.h:164
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetWindowBordered
GLbitfield flags
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
Mouse motion event structure (event.motion.*)
Definition: SDL_events.h:253
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_KeyboardEvent key
Definition: SDL_events.h:563
#define SDL_DestroyTexture
int h
Definition: SDL_rect.h:67
The type used to identify a window.
Definition: SDL_sysvideo.h:73
#define SDL_GetWindowGrab
#define SDL_CaptureMouse
SDL_Keycode sym
Definition: SDL_keyboard.h:50
#define SDL_GetGlobalMouseState
static void SDLTest_ScreenShot(SDL_Renderer *renderer)
#define SDL_snprintf
#define SDL_RenderSetClipRect
#define SDL_DestroyRenderer
#define SDL_MaximizeWindow
static void FullscreenTo(int index, int windowId)
#define SDL_BUTTON_MMASK
Definition: SDL_mouse.h:288
#define SDL_DestroyWindow
GLboolean GLboolean GLboolean b
int y
Definition: SDL_rect.h:66
#define SDL_SetWindowPosition
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
SDL_DropEvent drop
Definition: SDL_events.h:585
#define SDL_SetClipboardText
Uint32 type
Definition: SDL_events.h:559

◆ SDLTest_CommonInit()

SDL_bool SDLTest_CommonInit ( SDLTest_CommonState state)

Open test window.

Parameters
stateThe common state describing the test window to create.
Returns
True if initialization succeeded, false otherwise

Definition at line 726 of file SDL_test_common.c.

References SDLTest_CommonState::audiodriver, SDLTest_CommonState::audiospec, SDLTest_CommonState::depth, SDLTest_CommonState::flags, SDL_DisplayMode::format, SDLTest_CommonState::gl_accelerated, SDLTest_CommonState::gl_accum_alpha_size, SDLTest_CommonState::gl_accum_blue_size, SDLTest_CommonState::gl_accum_green_size, SDLTest_CommonState::gl_accum_red_size, SDLTest_CommonState::gl_alpha_size, SDLTest_CommonState::gl_blue_size, SDLTest_CommonState::gl_buffer_size, SDLTest_CommonState::gl_debug, SDLTest_CommonState::gl_depth_size, SDLTest_CommonState::gl_double_buffer, SDLTest_CommonState::gl_green_size, SDLTest_CommonState::gl_major_version, SDLTest_CommonState::gl_minor_version, SDLTest_CommonState::gl_multisamplebuffers, SDLTest_CommonState::gl_multisamplesamples, SDLTest_CommonState::gl_profile_mask, SDLTest_CommonState::gl_red_size, SDLTest_CommonState::gl_retained_backing, SDLTest_CommonState::gl_stencil_size, SDLTest_CommonState::gl_stereo, SDL_DisplayMode::h, SDL_Rect::h, i, j, SDLTest_CommonState::logical_h, SDLTest_CommonState::logical_w, SDL_RendererInfo::name, NULL, SDLTest_CommonState::num_windows, SDL_DisplayMode::refresh_rate, SDLTest_CommonState::refresh_rate, SDLTest_CommonState::render_flags, SDLTest_CommonState::renderdriver, SDLTest_CommonState::renderers, SDLTest_CommonState::scale, SDL_arraysize, SDL_AudioInit, SDL_calloc, SDL_CreateRenderer, SDL_CreateWindow, SDL_Direct3D9GetAdapterIndex(), SDL_DXGIGetOutputInfo(), SDL_FALSE, SDL_FreeSurface, SDL_GetAudioDriver, SDL_GetCurrentAudioDriver, SDL_GetCurrentVideoDriver, SDL_GetDesktopDisplayMode, SDL_GetDisplayBounds, SDL_GetDisplayDPI, SDL_GetDisplayMode, SDL_GetDisplayName, SDL_GetDisplayUsableBounds, SDL_GetError, SDL_GetNumAudioDrivers, SDL_GetNumDisplayModes, SDL_GetNumRenderDrivers, SDL_GetNumVideoDisplays, SDL_GetNumVideoDrivers, SDL_GetPixelFormatName, SDL_GetRenderDriverInfo, SDL_GetRendererInfo, SDL_GetVideoDriver, SDL_GetWindowSize, SDL_GL_ACCELERATED_VISUAL, SDL_GL_ACCUM_ALPHA_SIZE, SDL_GL_ACCUM_BLUE_SIZE, SDL_GL_ACCUM_GREEN_SIZE, SDL_GL_ACCUM_RED_SIZE, SDL_GL_ALPHA_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_BUFFER_SIZE, SDL_GL_CONTEXT_DEBUG_FLAG, SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_MAJOR_VERSION, SDL_GL_CONTEXT_MINOR_VERSION, SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_DEPTH_SIZE, SDL_GL_DOUBLEBUFFER, SDL_GL_GREEN_SIZE, SDL_GL_MULTISAMPLEBUFFERS, SDL_GL_MULTISAMPLESAMPLES, SDL_GL_RED_SIZE, SDL_GL_RETAINED_BACKING, SDL_GL_SetAttribute, SDL_GL_STENCIL_SIZE, SDL_GL_STEREO, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_Log, SDL_OpenAudio, SDL_PIXELFORMAT_INDEX8, SDL_PIXELFORMAT_RGB24, SDL_PIXELFORMAT_RGB555, SDL_PIXELFORMAT_RGB565, SDL_PIXELFORMAT_RGB888, SDL_PixelFormatEnumToMasks, SDL_RenderSetLogicalSize, SDL_RenderSetScale, SDL_SetWindowDisplayMode, SDL_SetWindowHitTest, SDL_SetWindowIcon, SDL_SetWindowMaximumSize, SDL_SetWindowMinimumSize, SDL_ShowWindow, SDL_snprintf, SDL_snprintfcat(), SDL_strcasecmp, SDL_strlcpy, SDL_TRUE, SDL_VideoInit, SDL_WINDOW_BORDERLESS, SDL_WINDOW_OPENGL, SDL_WINDOW_RESIZABLE, SDL_WINDOW_VULKAN, SDL_zero, SDLTest_ExampleHitTestCallback(), SDLTest_LoadIcon(), SDLTest_PrintRenderer(), SDLTest_CommonState::skip_renderer, SDLTest_CommonState::targets, text, SDLTest_CommonState::verbose, VERBOSE_AUDIO, VERBOSE_MODES, VERBOSE_RENDER, VERBOSE_VIDEO, SDLTest_CommonState::videodriver, SDL_DisplayMode::w, SDL_Rect::w, SDLTest_CommonState::window_flags, SDLTest_CommonState::window_h, SDLTest_CommonState::window_icon, SDLTest_CommonState::window_maxH, SDLTest_CommonState::window_maxW, SDLTest_CommonState::window_minH, SDLTest_CommonState::window_minW, SDLTest_CommonState::window_title, SDLTest_CommonState::window_w, SDLTest_CommonState::window_x, SDLTest_CommonState::window_y, SDLTest_CommonState::windows, SDL_Rect::x, and SDL_Rect::y.

Referenced by main().

727 {
728  int i, j, m, n, w, h;
729  SDL_DisplayMode fullscreen_mode;
730  char text[1024];
731 
732  if (state->flags & SDL_INIT_VIDEO) {
733  if (state->verbose & VERBOSE_VIDEO) {
735  if (n == 0) {
736  SDL_Log("No built-in video drivers\n");
737  } else {
738  SDL_snprintf(text, sizeof(text), "Built-in video drivers:");
739  for (i = 0; i < n; ++i) {
740  if (i > 0) {
741  SDL_snprintfcat(text, sizeof(text), ",");
742  }
743  SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i));
744  }
745  SDL_Log("%s\n", text);
746  }
747  }
748  if (SDL_VideoInit(state->videodriver) < 0) {
749  SDL_Log("Couldn't initialize video driver: %s\n",
750  SDL_GetError());
751  return SDL_FALSE;
752  }
753  if (state->verbose & VERBOSE_VIDEO) {
754  SDL_Log("Video driver: %s\n",
756  }
757 
758  /* Upload GL settings */
774  if (state->gl_accelerated >= 0) {
776  state->gl_accelerated);
777  }
779  if (state->gl_major_version) {
782  }
783  if (state->gl_debug) {
785  }
786  if (state->gl_profile_mask) {
788  }
789 
790  if (state->verbose & VERBOSE_MODES) {
791  SDL_Rect bounds, usablebounds;
792  float hdpi = 0;
793  float vdpi = 0;
795  int bpp;
796  Uint32 Rmask, Gmask, Bmask, Amask;
797 #if SDL_VIDEO_DRIVER_WINDOWS
798  int adapterIndex = 0;
799  int outputIndex = 0;
800 #endif
802  SDL_Log("Number of displays: %d\n", n);
803  for (i = 0; i < n; ++i) {
804  SDL_Log("Display %d: %s\n", i, SDL_GetDisplayName(i));
805 
806  SDL_zero(bounds);
807  SDL_GetDisplayBounds(i, &bounds);
808 
809  SDL_zero(usablebounds);
810  SDL_GetDisplayUsableBounds(i, &usablebounds);
811 
812  SDL_GetDisplayDPI(i, NULL, &hdpi, &vdpi);
813 
814  SDL_Log("Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
815  SDL_Log("Usable bounds: %dx%d at %d,%d\n", usablebounds.w, usablebounds.h, usablebounds.x, usablebounds.y);
816  SDL_Log("DPI: %fx%f\n", hdpi, vdpi);
817 
818  SDL_GetDesktopDisplayMode(i, &mode);
819  SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
820  &Bmask, &Amask);
821  SDL_Log(" Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
822  mode.w, mode.h, mode.refresh_rate, bpp,
824  if (Rmask || Gmask || Bmask) {
825  SDL_Log(" Red Mask = 0x%.8x\n", Rmask);
826  SDL_Log(" Green Mask = 0x%.8x\n", Gmask);
827  SDL_Log(" Blue Mask = 0x%.8x\n", Bmask);
828  if (Amask)
829  SDL_Log(" Alpha Mask = 0x%.8x\n", Amask);
830  }
831 
832  /* Print available fullscreen video modes */
833  m = SDL_GetNumDisplayModes(i);
834  if (m == 0) {
835  SDL_Log("No available fullscreen video modes\n");
836  } else {
837  SDL_Log(" Fullscreen video modes:\n");
838  for (j = 0; j < m; ++j) {
839  SDL_GetDisplayMode(i, j, &mode);
840  SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
841  &Gmask, &Bmask, &Amask);
842  SDL_Log(" Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
843  j, mode.w, mode.h, mode.refresh_rate, bpp,
845  if (Rmask || Gmask || Bmask) {
846  SDL_Log(" Red Mask = 0x%.8x\n",
847  Rmask);
848  SDL_Log(" Green Mask = 0x%.8x\n",
849  Gmask);
850  SDL_Log(" Blue Mask = 0x%.8x\n",
851  Bmask);
852  if (Amask)
853  SDL_Log(" Alpha Mask = 0x%.8x\n",
854  Amask);
855  }
856  }
857  }
858 
859 #if SDL_VIDEO_DRIVER_WINDOWS
860  /* Print the D3D9 adapter index */
861  adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
862  SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
863 
864  /* Print the DXGI adapter and output indices */
865  SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
866  SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex);
867 #endif
868  }
869  }
870 
871  if (state->verbose & VERBOSE_RENDER) {
872  SDL_RendererInfo info;
873 
875  if (n == 0) {
876  SDL_Log("No built-in render drivers\n");
877  } else {
878  SDL_Log("Built-in render drivers:\n");
879  for (i = 0; i < n; ++i) {
880  SDL_GetRenderDriverInfo(i, &info);
881  SDLTest_PrintRenderer(&info);
882  }
883  }
884  }
885 
886  SDL_zero(fullscreen_mode);
887  switch (state->depth) {
888  case 8:
889  fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
890  break;
891  case 15:
892  fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
893  break;
894  case 16:
895  fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
896  break;
897  case 24:
898  fullscreen_mode.format = SDL_PIXELFORMAT_RGB24;
899  break;
900  default:
901  fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
902  break;
903  }
904  fullscreen_mode.refresh_rate = state->refresh_rate;
905 
906  state->windows =
907  (SDL_Window **) SDL_calloc(state->num_windows,
908  sizeof(*state->windows));
909  state->renderers =
910  (SDL_Renderer **) SDL_calloc(state->num_windows,
911  sizeof(*state->renderers));
912  state->targets =
913  (SDL_Texture **) SDL_calloc(state->num_windows,
914  sizeof(*state->targets));
915  if (!state->windows || !state->renderers) {
916  SDL_Log("Out of memory!\n");
917  return SDL_FALSE;
918  }
919  for (i = 0; i < state->num_windows; ++i) {
920  char title[1024];
921 
922  if (state->num_windows > 1) {
923  SDL_snprintf(title, SDL_arraysize(title), "%s %d",
924  state->window_title, i + 1);
925  } else {
926  SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
927  }
928  state->windows[i] =
929  SDL_CreateWindow(title, state->window_x, state->window_y,
930  state->window_w, state->window_h,
931  state->window_flags);
932  if (!state->windows[i]) {
933  SDL_Log("Couldn't create window: %s\n",
934  SDL_GetError());
935  return SDL_FALSE;
936  }
937  if (state->window_minW || state->window_minH) {
938  SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
939  }
940  if (state->window_maxW || state->window_maxH) {
941  SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
942  }
943  SDL_GetWindowSize(state->windows[i], &w, &h);
944  if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
945  (w != state->window_w || h != state->window_h)) {
946  printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
947  state->window_w = w;
948  state->window_h = h;
949  }
950  if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
951  SDL_Log("Can't set up fullscreen display mode: %s\n",
952  SDL_GetError());
953  return SDL_FALSE;
954  }
955 
956  /* Add resize/drag areas for windows that are borderless and resizable */
960  }
961 
962  if (state->window_icon) {
963  SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
964  if (icon) {
965  SDL_SetWindowIcon(state->windows[i], icon);
966  SDL_FreeSurface(icon);
967  }
968  }
969 
970  SDL_ShowWindow(state->windows[i]);
971 
972  if (!state->skip_renderer
973  && (state->renderdriver
974  || !(state->window_flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_VULKAN)))) {
975  m = -1;
976  if (state->renderdriver) {
977  SDL_RendererInfo info;
979  for (j = 0; j < n; ++j) {
980  SDL_GetRenderDriverInfo(j, &info);
981  if (SDL_strcasecmp(info.name, state->renderdriver) ==
982  0) {
983  m = j;
984  break;
985  }
986  }
987  if (m == -1) {
988  SDL_Log("Couldn't find render driver named %s",
989  state->renderdriver);
990  return SDL_FALSE;
991  }
992  }
993  state->renderers[i] = SDL_CreateRenderer(state->windows[i],
994  m, state->render_flags);
995  if (!state->renderers[i]) {
996  SDL_Log("Couldn't create renderer: %s\n",
997  SDL_GetError());
998  return SDL_FALSE;
999  }
1000  if (state->logical_w && state->logical_h) {
1001  SDL_RenderSetLogicalSize(state->renderers[i], state->logical_w, state->logical_h);
1002  } else if (state->scale) {
1003  SDL_RenderSetScale(state->renderers[i], state->scale, state->scale);
1004  }
1005  if (state->verbose & VERBOSE_RENDER) {
1006  SDL_RendererInfo info;
1007 
1008  SDL_Log("Current renderer:\n");
1009  SDL_GetRendererInfo(state->renderers[i], &info);
1010  SDLTest_PrintRenderer(&info);
1011  }
1012  }
1013  }
1014  }
1015 
1016  if (state->flags & SDL_INIT_AUDIO) {
1017  if (state->verbose & VERBOSE_AUDIO) {
1018  n = SDL_GetNumAudioDrivers();
1019  if (n == 0) {
1020  SDL_Log("No built-in audio drivers\n");
1021  } else {
1022  SDL_snprintf(text, sizeof(text), "Built-in audio drivers:");
1023  for (i = 0; i < n; ++i) {
1024  if (i > 0) {
1025  SDL_snprintfcat(text, sizeof(text), ",");
1026  }
1027  SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i));
1028  }
1029  SDL_Log("%s\n", text);
1030  }
1031  }
1032  if (SDL_AudioInit(state->audiodriver) < 0) {
1033  SDL_Log("Couldn't initialize audio driver: %s\n",
1034  SDL_GetError());
1035  return SDL_FALSE;
1036  }
1037  if (state->verbose & VERBOSE_VIDEO) {
1038  SDL_Log("Audio driver: %s\n",
1040  }
1041 
1042  if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
1043  SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
1044  return SDL_FALSE;
1045  }
1046  }
1047 
1048  return SDL_TRUE;
1049 }
#define SDL_GetNumAudioDrivers
#define SDL_strlcpy
#define SDL_SetWindowMaximumSize
#define SDL_ShowWindow
SDL_Texture ** targets
#define SDL_GetError
#define SDL_GetNumVideoDrivers
#define SDL_SetWindowDisplayMode
#define SDL_OpenAudio
static SDL_Surface * SDLTest_LoadIcon(const char *file)
#define SDL_GetDisplayMode
SDL_bool SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
Returns the DXGI Adapter and Output indices for the specified display index.
#define SDL_SetWindowMinimumSize
#define SDL_AudioInit
#define SDL_GetNumRenderDrivers
GLfloat GLfloat GLfloat GLfloat h
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
const GLfloat * m
#define SDL_GetDesktopDisplayMode
#define SDL_GetDisplayName
const char * window_icon
The structure that defines a display mode.
Definition: SDL_video.h:53
#define SDL_CreateWindow
const char * renderdriver
#define SDL_strcasecmp
const char * name
Definition: SDL_render.h:80
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define SDL_GetRenderDriverInfo
SDL_AudioSpec audiospec
#define SDL_GetDisplayUsableBounds
SDL_Window ** windows
#define SDL_SetWindowIcon
#define SDL_GetNumVideoDisplays
int SDL_Direct3D9GetAdapterIndex(int displayIndex)
Returns the D3D9 adapter index that matches the specified display index.
#define VERBOSE_AUDIO
#define SDL_GL_SetAttribute
#define SDL_GetWindowSize
#define SDL_Log
static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
#define SDL_VideoInit
static void SDLTest_PrintRenderer(SDL_RendererInfo *info)
#define SDL_FreeSurface
#define SDL_RenderSetLogicalSize
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
GLenum mode
GLubyte GLubyte GLubyte GLubyte w
#define SDL_GetDisplayBounds
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
#define SDL_GetAudioDriver
#define SDL_PixelFormatEnumToMasks
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
#define SDL_RenderSetScale
SDL_Renderer ** renderers
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_GetCurrentAudioDriver
#define NULL
Definition: begin_code.h:164
#define SDL_GetCurrentVideoDriver
#define VERBOSE_MODES
Information on the capabilities of a render driver or context.
Definition: SDL_render.h:78
#define SDL_GetVideoDriver
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
#define VERBOSE_RENDER
#define SDL_calloc
const char * audiodriver
#define SDL_INIT_AUDIO
Definition: SDL.h:78
#define SDL_SetWindowHitTest
int h
Definition: SDL_rect.h:67
The type used to identify a window.
Definition: SDL_sysvideo.h:73
GLdouble n
#define SDL_GetDisplayDPI
#define SDL_snprintf
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
#define SDL_GetNumDisplayModes
Uint32 format
Definition: SDL_video.h:55
#define VERBOSE_VIDEO
int y
Definition: SDL_rect.h:66
const char * videodriver
#define SDL_INIT_VIDEO
Definition: SDL.h:79
#define SDL_CreateRenderer
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
#define SDL_GetRendererInfo
static SDL_HitTestResult SDLTest_ExampleHitTestCallback(SDL_Window *win, const SDL_Point *area, void *data)
const char * window_title
#define SDL_GetPixelFormatName

◆ SDLTest_CommonQuit()

void SDLTest_CommonQuit ( SDLTest_CommonState state)

Close test window.

Parameters
stateThe common state used to create test window.

Definition at line 1794 of file SDL_test_common.c.

References SDLTest_CommonState::flags, i, SDLTest_CommonState::num_windows, SDLTest_CommonState::renderers, SDL_AudioQuit, SDL_DestroyRenderer, SDL_DestroyTexture, SDL_free, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_Quit, SDL_VideoQuit, SDLTest_LogAllocations(), SDLTest_CommonState::targets, and SDLTest_CommonState::windows.

Referenced by main(), and quit().

1795 {
1796  int i;
1797 
1798  SDL_free(state->windows);
1799  if (state->targets) {
1800  for (i = 0; i < state->num_windows; ++i) {
1801  if (state->targets[i]) {
1802  SDL_DestroyTexture(state->targets[i]);
1803  }
1804  }
1805  SDL_free(state->targets);
1806  }
1807  if (state->renderers) {
1808  for (i = 0; i < state->num_windows; ++i) {
1809  if (state->renderers[i]) {
1810  SDL_DestroyRenderer(state->renderers[i]);
1811  }
1812  }
1813  SDL_free(state->renderers);
1814  }
1815  if (state->flags & SDL_INIT_VIDEO) {
1816  SDL_VideoQuit();
1817  }
1818  if (state->flags & SDL_INIT_AUDIO) {
1819  SDL_AudioQuit();
1820  }
1821  SDL_free(state);
1822  SDL_Quit();
1824 }
SDL_Texture ** targets
#define SDL_AudioQuit
SDL_Window ** windows
#define SDL_free
#define SDL_Quit
SDL_Renderer ** renderers
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define SDL_INIT_AUDIO
Definition: SDL.h:78
#define SDL_DestroyTexture
#define SDL_VideoQuit
#define SDL_DestroyRenderer
#define SDL_INIT_VIDEO
Definition: SDL.h:79
void SDLTest_LogAllocations()
Print a log of any outstanding allocations.

◆ SDLTest_CommonUsage()

const char* SDLTest_CommonUsage ( SDLTest_CommonState state)

Returns common usage information.

Parameters
stateThe common state describing the test window to create.
Returns
String with usage information

Definition at line 478 of file SDL_test_common.c.

References AUDIO_USAGE, SDLTest_CommonState::flags, SDL_INIT_AUDIO, SDL_INIT_VIDEO, and VIDEO_USAGE.

Referenced by main().

479 {
480  switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
481  case SDL_INIT_VIDEO:
482  return "[--trackmem] " VIDEO_USAGE;
483  case SDL_INIT_AUDIO:
484  return "[--trackmem] " AUDIO_USAGE;
486  return "[--trackmem] " VIDEO_USAGE " " AUDIO_USAGE;
487  default:
488  return "[--trackmem]";
489  }
490 }
#define AUDIO_USAGE
#define VIDEO_USAGE
#define SDL_INIT_AUDIO
Definition: SDL.h:78
#define SDL_INIT_VIDEO
Definition: SDL.h:79