src/test/SDL_test_common.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 15 Feb 2013 08:47:44 -0800
changeset 6885 700f1b25f77f
parent 6796 424a12862805
child 7011 82bbfbbc720e
permissions -rw-r--r--
Happy New Year!
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 /* Ported from original test\common.c file. */
    23 
    24 #include "SDL_config.h"
    25 #include "SDL_test.h"
    26 
    27 #include <stdio.h>
    28 
    29 #define VIDEO_USAGE \
    30 "[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--min-geometry WxH] [--max-geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
    31 
    32 #define AUDIO_USAGE \
    33 "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
    34 
    35 SDLTest_CommonState *
    36 SDLTest_CommonCreateState(char **argv, Uint32 flags)
    37 {
    38     SDLTest_CommonState *state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
    39     if (!state) {
    40         SDL_OutOfMemory();
    41         return NULL;
    42     }
    43 
    44     /* Initialize some defaults */
    45     state->argv = argv;
    46     state->flags = flags;
    47 #ifdef __NDS__
    48     state->window_title = "";
    49 #else
    50     state->window_title = argv[0];
    51 #endif
    52     state->window_flags = 0;
    53     state->window_x = SDL_WINDOWPOS_UNDEFINED;
    54     state->window_y = SDL_WINDOWPOS_UNDEFINED;
    55     state->window_w = DEFAULT_WINDOW_WIDTH;
    56     state->window_h = DEFAULT_WINDOW_HEIGHT;
    57     state->num_windows = 1;
    58     state->audiospec.freq = 22050;
    59     state->audiospec.format = AUDIO_S16;
    60     state->audiospec.channels = 2;
    61     state->audiospec.samples = 2048;
    62 
    63     /* Set some very sane GL defaults */
    64     state->gl_red_size = 3;
    65     state->gl_green_size = 3;
    66     state->gl_blue_size = 2;
    67     state->gl_alpha_size = 0;
    68     state->gl_buffer_size = 0;
    69     state->gl_depth_size = 16;
    70     state->gl_stencil_size = 0;
    71     state->gl_double_buffer = 1;
    72     state->gl_accum_red_size = 0;
    73     state->gl_accum_green_size = 0;
    74     state->gl_accum_blue_size = 0;
    75     state->gl_accum_alpha_size = 0;
    76     state->gl_stereo = 0;
    77     state->gl_multisamplebuffers = 0;
    78     state->gl_multisamplesamples = 0;
    79     state->gl_retained_backing = 1;
    80     state->gl_accelerated = -1;
    81 
    82     return state;
    83 }
    84 
    85 int
    86 SDLTest_CommonArg(SDLTest_CommonState * state, int index)
    87 {
    88     char **argv = state->argv;
    89 
    90 #ifdef __NDS__
    91     return 0;
    92 #endif
    93 
    94     if (SDL_strcasecmp(argv[index], "--video") == 0) {
    95         ++index;
    96         if (!argv[index]) {
    97             return -1;
    98         }
    99         state->videodriver = argv[index];
   100         return 2;
   101     }
   102     if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
   103         ++index;
   104         if (!argv[index]) {
   105             return -1;
   106         }
   107         state->renderdriver = argv[index];
   108         return 2;
   109     }
   110     if (SDL_strcasecmp(argv[index], "--info") == 0) {
   111         ++index;
   112         if (!argv[index]) {
   113             return -1;
   114         }
   115         if (SDL_strcasecmp(argv[index], "all") == 0) {
   116             state->verbose |=
   117                 (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
   118                  VERBOSE_EVENT);
   119             return 2;
   120         }
   121         if (SDL_strcasecmp(argv[index], "video") == 0) {
   122             state->verbose |= VERBOSE_VIDEO;
   123             return 2;
   124         }
   125         if (SDL_strcasecmp(argv[index], "modes") == 0) {
   126             state->verbose |= VERBOSE_MODES;
   127             return 2;
   128         }
   129         if (SDL_strcasecmp(argv[index], "render") == 0) {
   130             state->verbose |= VERBOSE_RENDER;
   131             return 2;
   132         }
   133         if (SDL_strcasecmp(argv[index], "event") == 0) {
   134             state->verbose |= VERBOSE_EVENT;
   135             return 2;
   136         }
   137         return -1;
   138     }
   139     if (SDL_strcasecmp(argv[index], "--log") == 0) {
   140         ++index;
   141         if (!argv[index]) {
   142             return -1;
   143         }
   144         if (SDL_strcasecmp(argv[index], "all") == 0) {
   145             SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
   146             return 2;
   147         }
   148         if (SDL_strcasecmp(argv[index], "error") == 0) {
   149             SDL_LogSetPriority(SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_VERBOSE);
   150             return 2;
   151         }
   152         if (SDL_strcasecmp(argv[index], "system") == 0) {
   153             SDL_LogSetPriority(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE);
   154             return 2;
   155         }
   156         if (SDL_strcasecmp(argv[index], "audio") == 0) {
   157             SDL_LogSetPriority(SDL_LOG_CATEGORY_AUDIO, SDL_LOG_PRIORITY_VERBOSE);
   158             return 2;
   159         }
   160         if (SDL_strcasecmp(argv[index], "video") == 0) {
   161             SDL_LogSetPriority(SDL_LOG_CATEGORY_VIDEO, SDL_LOG_PRIORITY_VERBOSE);
   162             return 2;
   163         }
   164         if (SDL_strcasecmp(argv[index], "render") == 0) {
   165             SDL_LogSetPriority(SDL_LOG_CATEGORY_RENDER, SDL_LOG_PRIORITY_VERBOSE);
   166             return 2;
   167         }
   168         if (SDL_strcasecmp(argv[index], "input") == 0) {
   169             SDL_LogSetPriority(SDL_LOG_CATEGORY_INPUT, SDL_LOG_PRIORITY_VERBOSE);
   170             return 2;
   171         }
   172         return -1;
   173     }
   174     if (SDL_strcasecmp(argv[index], "--display") == 0) {
   175         ++index;
   176         if (!argv[index]) {
   177             return -1;
   178         }
   179         state->display = SDL_atoi(argv[index]);
   180         if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
   181             state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
   182             state->window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
   183         }
   184         if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) {
   185             state->window_x = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
   186             state->window_y = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
   187         }
   188         return 2;
   189     }
   190     if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
   191         state->window_flags |= SDL_WINDOW_FULLSCREEN;
   192         state->num_windows = 1;
   193         return 1;
   194     }
   195     if (SDL_strcasecmp(argv[index], "--fullscreen-desktop") == 0) {
   196         state->window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
   197         state->num_windows = 1;
   198         return 1;
   199     }
   200     if (SDL_strcasecmp(argv[index], "--windows") == 0) {
   201         ++index;
   202         if (!argv[index] || !SDL_isdigit(*argv[index])) {
   203             return -1;
   204         }
   205         if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
   206             state->num_windows = SDL_atoi(argv[index]);
   207         }
   208         return 2;
   209     }
   210     if (SDL_strcasecmp(argv[index], "--title") == 0) {
   211         ++index;
   212         if (!argv[index]) {
   213             return -1;
   214         }
   215         state->window_title = argv[index];
   216         return 2;
   217     }
   218     if (SDL_strcasecmp(argv[index], "--icon") == 0) {
   219         ++index;
   220         if (!argv[index]) {
   221             return -1;
   222         }
   223         state->window_icon = argv[index];
   224         return 2;
   225     }
   226     if (SDL_strcasecmp(argv[index], "--center") == 0) {
   227         state->window_x = SDL_WINDOWPOS_CENTERED;
   228         state->window_y = SDL_WINDOWPOS_CENTERED;
   229         return 1;
   230     }
   231     if (SDL_strcasecmp(argv[index], "--position") == 0) {
   232         char *x, *y;
   233         ++index;
   234         if (!argv[index]) {
   235             return -1;
   236         }
   237         x = argv[index];
   238         y = argv[index];
   239         while (*y && *y != ',') {
   240             ++y;
   241         }
   242         if (!*y) {
   243             return -1;
   244         }
   245         *y++ = '\0';
   246         state->window_x = SDL_atoi(x);
   247         state->window_y = SDL_atoi(y);
   248         return 2;
   249     }
   250     if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
   251         char *w, *h;
   252         ++index;
   253         if (!argv[index]) {
   254             return -1;
   255         }
   256         w = argv[index];
   257         h = argv[index];
   258         while (*h && *h != 'x') {
   259             ++h;
   260         }
   261         if (!*h) {
   262             return -1;
   263         }
   264         *h++ = '\0';
   265         state->window_w = SDL_atoi(w);
   266         state->window_h = SDL_atoi(h);
   267         return 2;
   268     }
   269     if (SDL_strcasecmp(argv[index], "--min-geometry") == 0) {
   270         char *w, *h;
   271         ++index;
   272         if (!argv[index]) {
   273             return -1;
   274         }
   275         w = argv[index];
   276         h = argv[index];
   277         while (*h && *h != 'x') {
   278             ++h;
   279         }
   280         if (!*h) {
   281             return -1;
   282         }
   283         *h++ = '\0';
   284         state->window_minW = SDL_atoi(w);
   285         state->window_minH = SDL_atoi(h);
   286         return 2;
   287     }
   288     if (SDL_strcasecmp(argv[index], "--max-geometry") == 0) {
   289         char *w, *h;
   290         ++index;
   291         if (!argv[index]) {
   292             return -1;
   293         }
   294         w = argv[index];
   295         h = argv[index];
   296         while (*h && *h != 'x') {
   297             ++h;
   298         }
   299         if (!*h) {
   300             return -1;
   301         }
   302         *h++ = '\0';
   303         state->window_maxW = SDL_atoi(w);
   304         state->window_maxH = SDL_atoi(h);
   305         return 2;
   306     }
   307     if (SDL_strcasecmp(argv[index], "--depth") == 0) {
   308         ++index;
   309         if (!argv[index]) {
   310             return -1;
   311         }
   312         state->depth = SDL_atoi(argv[index]);
   313         return 2;
   314     }
   315     if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
   316         ++index;
   317         if (!argv[index]) {
   318             return -1;
   319         }
   320         state->refresh_rate = SDL_atoi(argv[index]);
   321         return 2;
   322     }
   323     if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
   324         state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
   325         return 1;
   326     }
   327     if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
   328         state->window_flags |= SDL_WINDOW_BORDERLESS;
   329         return 1;
   330     }
   331     if (SDL_strcasecmp(argv[index], "--resize") == 0) {
   332         state->window_flags |= SDL_WINDOW_RESIZABLE;
   333         return 1;
   334     }
   335     if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
   336         state->window_flags |= SDL_WINDOW_MINIMIZED;
   337         return 1;
   338     }
   339     if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
   340         state->window_flags |= SDL_WINDOW_MAXIMIZED;
   341         return 1;
   342     }
   343     if (SDL_strcasecmp(argv[index], "--grab") == 0) {
   344         state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
   345         return 1;
   346     }
   347     if (SDL_strcasecmp(argv[index], "--rate") == 0) {
   348         ++index;
   349         if (!argv[index]) {
   350             return -1;
   351         }
   352         state->audiospec.freq = SDL_atoi(argv[index]);
   353         return 2;
   354     }
   355     if (SDL_strcasecmp(argv[index], "--format") == 0) {
   356         ++index;
   357         if (!argv[index]) {
   358             return -1;
   359         }
   360         if (SDL_strcasecmp(argv[index], "U8") == 0) {
   361             state->audiospec.format = AUDIO_U8;
   362             return 2;
   363         }
   364         if (SDL_strcasecmp(argv[index], "S8") == 0) {
   365             state->audiospec.format = AUDIO_S8;
   366             return 2;
   367         }
   368         if (SDL_strcasecmp(argv[index], "U16") == 0) {
   369             state->audiospec.format = AUDIO_U16;
   370             return 2;
   371         }
   372         if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
   373             state->audiospec.format = AUDIO_U16LSB;
   374             return 2;
   375         }
   376         if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
   377             state->audiospec.format = AUDIO_U16MSB;
   378             return 2;
   379         }
   380         if (SDL_strcasecmp(argv[index], "S16") == 0) {
   381             state->audiospec.format = AUDIO_S16;
   382             return 2;
   383         }
   384         if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
   385             state->audiospec.format = AUDIO_S16LSB;
   386             return 2;
   387         }
   388         if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
   389             state->audiospec.format = AUDIO_S16MSB;
   390             return 2;
   391         }
   392         return -1;
   393     }
   394     if (SDL_strcasecmp(argv[index], "--channels") == 0) {
   395         ++index;
   396         if (!argv[index]) {
   397             return -1;
   398         }
   399         state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
   400         return 2;
   401     }
   402     if (SDL_strcasecmp(argv[index], "--samples") == 0) {
   403         ++index;
   404         if (!argv[index]) {
   405             return -1;
   406         }
   407         state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
   408         return 2;
   409     }
   410     if ((SDL_strcasecmp(argv[index], "-h") == 0)
   411         || (SDL_strcasecmp(argv[index], "--help") == 0)) {
   412         /* Print the usage message */
   413         return -1;
   414     }
   415     if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) {
   416 	/* Debug flag sent by Xcode */
   417         return 2;
   418     }
   419     return 0;
   420 }
   421 
   422 const char *
   423 SDLTest_CommonUsage(SDLTest_CommonState * state)
   424 {
   425     switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
   426     case SDL_INIT_VIDEO:
   427         return VIDEO_USAGE;
   428     case SDL_INIT_AUDIO:
   429         return AUDIO_USAGE;
   430     case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
   431         return VIDEO_USAGE " " AUDIO_USAGE;
   432     default:
   433         return "";
   434     }
   435 }
   436 
   437 static void
   438 SDLTest_PrintRendererFlag(Uint32 flag)
   439 {
   440     switch (flag) {
   441     case SDL_RENDERER_PRESENTVSYNC:
   442         fprintf(stderr, "PresentVSync");
   443         break;
   444     case SDL_RENDERER_ACCELERATED:
   445         fprintf(stderr, "Accelerated");
   446         break;
   447     default:
   448         fprintf(stderr, "0x%8.8x", flag);
   449         break;
   450     }
   451 }
   452 
   453 static void
   454 SDLTest_PrintPixelFormat(Uint32 format)
   455 {
   456     switch (format) {
   457     case SDL_PIXELFORMAT_UNKNOWN:
   458         fprintf(stderr, "Unknwon");
   459         break;
   460     case SDL_PIXELFORMAT_INDEX1LSB:
   461         fprintf(stderr, "Index1LSB");
   462         break;
   463     case SDL_PIXELFORMAT_INDEX1MSB:
   464         fprintf(stderr, "Index1MSB");
   465         break;
   466     case SDL_PIXELFORMAT_INDEX4LSB:
   467         fprintf(stderr, "Index4LSB");
   468         break;
   469     case SDL_PIXELFORMAT_INDEX4MSB:
   470         fprintf(stderr, "Index4MSB");
   471         break;
   472     case SDL_PIXELFORMAT_INDEX8:
   473         fprintf(stderr, "Index8");
   474         break;
   475     case SDL_PIXELFORMAT_RGB332:
   476         fprintf(stderr, "RGB332");
   477         break;
   478     case SDL_PIXELFORMAT_RGB444:
   479         fprintf(stderr, "RGB444");
   480         break;
   481     case SDL_PIXELFORMAT_RGB555:
   482         fprintf(stderr, "RGB555");
   483         break;
   484     case SDL_PIXELFORMAT_BGR555:
   485         fprintf(stderr, "BGR555");
   486         break;
   487     case SDL_PIXELFORMAT_ARGB4444:
   488         fprintf(stderr, "ARGB4444");
   489         break;
   490     case SDL_PIXELFORMAT_ABGR4444:
   491         fprintf(stderr, "ABGR4444");
   492         break;
   493     case SDL_PIXELFORMAT_ARGB1555:
   494         fprintf(stderr, "ARGB1555");
   495         break;
   496     case SDL_PIXELFORMAT_ABGR1555:
   497         fprintf(stderr, "ABGR1555");
   498         break;
   499     case SDL_PIXELFORMAT_RGB565:
   500         fprintf(stderr, "RGB565");
   501         break;
   502     case SDL_PIXELFORMAT_BGR565:
   503         fprintf(stderr, "BGR565");
   504         break;
   505     case SDL_PIXELFORMAT_RGB24:
   506         fprintf(stderr, "RGB24");
   507         break;
   508     case SDL_PIXELFORMAT_BGR24:
   509         fprintf(stderr, "BGR24");
   510         break;
   511     case SDL_PIXELFORMAT_RGB888:
   512         fprintf(stderr, "RGB888");
   513         break;
   514     case SDL_PIXELFORMAT_BGR888:
   515         fprintf(stderr, "BGR888");
   516         break;
   517     case SDL_PIXELFORMAT_ARGB8888:
   518         fprintf(stderr, "ARGB8888");
   519         break;
   520     case SDL_PIXELFORMAT_RGBA8888:
   521         fprintf(stderr, "RGBA8888");
   522         break;
   523     case SDL_PIXELFORMAT_ABGR8888:
   524         fprintf(stderr, "ABGR8888");
   525         break;
   526     case SDL_PIXELFORMAT_BGRA8888:
   527         fprintf(stderr, "BGRA8888");
   528         break;
   529     case SDL_PIXELFORMAT_ARGB2101010:
   530         fprintf(stderr, "ARGB2101010");
   531         break;
   532     case SDL_PIXELFORMAT_YV12:
   533         fprintf(stderr, "YV12");
   534         break;
   535     case SDL_PIXELFORMAT_IYUV:
   536         fprintf(stderr, "IYUV");
   537         break;
   538     case SDL_PIXELFORMAT_YUY2:
   539         fprintf(stderr, "YUY2");
   540         break;
   541     case SDL_PIXELFORMAT_UYVY:
   542         fprintf(stderr, "UYVY");
   543         break;
   544     case SDL_PIXELFORMAT_YVYU:
   545         fprintf(stderr, "YVYU");
   546         break;
   547     default:
   548         fprintf(stderr, "0x%8.8x", format);
   549         break;
   550     }
   551 }
   552 
   553 static void
   554 SDLTest_PrintRenderer(SDL_RendererInfo * info)
   555 {
   556     int i, count;
   557 
   558     fprintf(stderr, "  Renderer %s:\n", info->name);
   559 
   560     fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
   561     fprintf(stderr, " (");
   562     count = 0;
   563     for (i = 0; i < sizeof(info->flags) * 8; ++i) {
   564         Uint32 flag = (1 << i);
   565         if (info->flags & flag) {
   566             if (count > 0) {
   567                 fprintf(stderr, " | ");
   568             }
   569             SDLTest_PrintRendererFlag(flag);
   570             ++count;
   571         }
   572     }
   573     fprintf(stderr, ")\n");
   574 
   575     fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
   576     for (i = 0; i < (int) info->num_texture_formats; ++i) {
   577         if (i > 0) {
   578             fprintf(stderr, ", ");
   579         }
   580         SDLTest_PrintPixelFormat(info->texture_formats[i]);
   581     }
   582     fprintf(stderr, "\n");
   583 
   584     if (info->max_texture_width || info->max_texture_height) {
   585         fprintf(stderr, "    Max Texture Size: %dx%d\n",
   586                 info->max_texture_width, info->max_texture_height);
   587     }
   588 }
   589 
   590 static SDL_Surface *
   591 SDLTest_LoadIcon(const char *file)
   592 {
   593     SDL_Surface *icon;
   594 
   595     /* Load the icon surface */
   596     icon = SDL_LoadBMP(file);
   597     if (icon == NULL) {
   598         fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
   599         return (NULL);
   600     }
   601 
   602     if (icon->format->palette) {
   603         /* Set the colorkey */
   604         SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels));
   605     }
   606 
   607     return (icon);
   608 }
   609 
   610 SDL_bool
   611 SDLTest_CommonInit(SDLTest_CommonState * state)
   612 {
   613     int i, j, m, n, w, h;
   614     SDL_DisplayMode fullscreen_mode;
   615 
   616     if (state->flags & SDL_INIT_VIDEO) {
   617         if (state->verbose & VERBOSE_VIDEO) {
   618             n = SDL_GetNumVideoDrivers();
   619             if (n == 0) {
   620                 fprintf(stderr, "No built-in video drivers\n");
   621             } else {
   622                 fprintf(stderr, "Built-in video drivers:");
   623                 for (i = 0; i < n; ++i) {
   624                     if (i > 0) {
   625                         fprintf(stderr, ",");
   626                     }
   627                     fprintf(stderr, " %s", SDL_GetVideoDriver(i));
   628                 }
   629                 fprintf(stderr, "\n");
   630             }
   631         }
   632         if (SDL_VideoInit(state->videodriver) < 0) {
   633             fprintf(stderr, "Couldn't initialize video driver: %s\n",
   634                     SDL_GetError());
   635             return SDL_FALSE;
   636         }
   637         if (state->verbose & VERBOSE_VIDEO) {
   638             fprintf(stderr, "Video driver: %s\n",
   639                     SDL_GetCurrentVideoDriver());
   640         }
   641 
   642         /* Upload GL settings */
   643         SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size);
   644         SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size);
   645         SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size);
   646         SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size);
   647         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
   648         SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
   649         SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size);
   650         SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
   651         SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
   652         SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
   653         SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
   654         SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
   655         SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
   656         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
   657         SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
   658         if (state->gl_accelerated >= 0) {
   659             SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
   660                                 state->gl_accelerated);
   661         }
   662         SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
   663         if (state->gl_major_version) {
   664             SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
   665             SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
   666         }
   667 
   668         if (state->verbose & VERBOSE_MODES) {
   669             SDL_Rect bounds;
   670             SDL_DisplayMode mode;
   671             int bpp;
   672             Uint32 Rmask, Gmask, Bmask, Amask;
   673 
   674             n = SDL_GetNumVideoDisplays();
   675             fprintf(stderr, "Number of displays: %d\n", n);
   676             for (i = 0; i < n; ++i) {
   677                 fprintf(stderr, "Display %d: %s\n", i, SDL_GetDisplayName(i));
   678 
   679                 SDL_zero(bounds);
   680                 SDL_GetDisplayBounds(i, &bounds);
   681                 fprintf(stderr, "Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
   682 
   683                 SDL_GetDesktopDisplayMode(i, &mode);
   684                 SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
   685                                            &Bmask, &Amask);
   686                 fprintf(stderr,
   687                         "  Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
   688                         mode.w, mode.h, mode.refresh_rate, bpp,
   689                         SDL_GetPixelFormatName(mode.format));
   690                 if (Rmask || Gmask || Bmask) {
   691                     fprintf(stderr, "      Red Mask   = 0x%.8x\n", Rmask);
   692                     fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
   693                     fprintf(stderr, "      Blue Mask  = 0x%.8x\n", Bmask);
   694                     if (Amask)
   695                         fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
   696                 }
   697 
   698                 /* Print available fullscreen video modes */
   699                 m = SDL_GetNumDisplayModes(i);
   700                 if (m == 0) {
   701                     fprintf(stderr, "No available fullscreen video modes\n");
   702                 } else {
   703                     fprintf(stderr, "  Fullscreen video modes:\n");
   704                     for (j = 0; j < m; ++j) {
   705                         SDL_GetDisplayMode(i, j, &mode);
   706                         SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
   707                                                    &Gmask, &Bmask, &Amask);
   708                         fprintf(stderr,
   709                                 "    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
   710                                 j, mode.w, mode.h, mode.refresh_rate, bpp,
   711                                 SDL_GetPixelFormatName(mode.format));
   712                         if (Rmask || Gmask || Bmask) {
   713                             fprintf(stderr, "        Red Mask   = 0x%.8x\n",
   714                                     Rmask);
   715                             fprintf(stderr, "        Green Mask = 0x%.8x\n",
   716                                     Gmask);
   717                             fprintf(stderr, "        Blue Mask  = 0x%.8x\n",
   718                                     Bmask);
   719                             if (Amask)
   720                                 fprintf(stderr,
   721                                         "        Alpha Mask = 0x%.8x\n",
   722                                         Amask);
   723                         }
   724                     }
   725                 }
   726             }
   727         }
   728 
   729         if (state->verbose & VERBOSE_RENDER) {
   730             SDL_RendererInfo info;
   731 
   732             n = SDL_GetNumRenderDrivers();
   733             if (n == 0) {
   734                 fprintf(stderr, "No built-in render drivers\n");
   735             } else {
   736                 fprintf(stderr, "Built-in render drivers:\n");
   737                 for (i = 0; i < n; ++i) {
   738                     SDL_GetRenderDriverInfo(i, &info);
   739                     SDLTest_PrintRenderer(&info);
   740                 }
   741             }
   742         }
   743 
   744         SDL_zero(fullscreen_mode);
   745         switch (state->depth) {
   746         case 8:
   747             fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
   748             break;
   749         case 15:
   750             fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
   751             break;
   752         case 16:
   753             fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
   754             break;
   755         case 24:
   756             fullscreen_mode.format = SDL_PIXELFORMAT_RGB24;
   757             break;
   758         default:
   759             fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
   760             break;
   761         }
   762         fullscreen_mode.refresh_rate = state->refresh_rate;
   763 
   764         state->windows =
   765             (SDL_Window **) SDL_malloc(state->num_windows *
   766                                         sizeof(*state->windows));
   767         state->renderers =
   768             (SDL_Renderer **) SDL_malloc(state->num_windows *
   769                                         sizeof(*state->renderers));
   770         if (!state->windows || !state->renderers) {
   771             fprintf(stderr, "Out of memory!\n");
   772             return SDL_FALSE;
   773         }
   774         for (i = 0; i < state->num_windows; ++i) {
   775             char title[1024];
   776 
   777             if (state->num_windows > 1) {
   778                 SDL_snprintf(title, SDL_arraysize(title), "%s %d",
   779                              state->window_title, i + 1);
   780             } else {
   781                 SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
   782             }
   783             state->windows[i] =
   784                 SDL_CreateWindow(title, state->window_x, state->window_y,
   785                                  state->window_w, state->window_h,
   786                                  state->window_flags);
   787             if (!state->windows[i]) {
   788                 fprintf(stderr, "Couldn't create window: %s\n",
   789                         SDL_GetError());
   790                 return SDL_FALSE;
   791             }
   792             if (state->window_minW || state->window_minH) {
   793                 SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
   794             }
   795             if (state->window_maxW || state->window_maxH) {
   796                 SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
   797             }
   798             SDL_GetWindowSize(state->windows[i], &w, &h);
   799             if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
   800                 (w != state->window_w || h != state->window_h)) {
   801                 printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
   802                 state->window_w = w;
   803                 state->window_h = h;
   804             }
   805             if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
   806                 fprintf(stderr, "Can't set up fullscreen display mode: %s\n",
   807                         SDL_GetError());
   808                 return SDL_FALSE;
   809             }
   810 
   811             if (state->window_icon) {
   812                 SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
   813                 if (icon) {
   814                     SDL_SetWindowIcon(state->windows[i], icon);
   815                     SDL_FreeSurface(icon);
   816                 }
   817             }
   818 
   819             SDL_ShowWindow(state->windows[i]);
   820 
   821             state->renderers[i] = NULL;
   822 
   823             if (!state->skip_renderer
   824                 && (state->renderdriver
   825                     || !(state->window_flags & SDL_WINDOW_OPENGL))) {
   826                 m = -1;
   827                 if (state->renderdriver) {
   828                     SDL_RendererInfo info;
   829                     n = SDL_GetNumRenderDrivers();
   830                     for (j = 0; j < n; ++j) {
   831                         SDL_GetRenderDriverInfo(j, &info);
   832                         if (SDL_strcasecmp(info.name, state->renderdriver) ==
   833                             0) {
   834                             m = j;
   835                             break;
   836                         }
   837                     }
   838                     if (m == n) {
   839                         fprintf(stderr,
   840                                 "Couldn't find render driver named %s",
   841                                 state->renderdriver);
   842                         return SDL_FALSE;
   843                     }
   844                 }
   845                 state->renderers[i] = SDL_CreateRenderer(state->windows[i],
   846                                             m, state->render_flags);
   847                 if (!state->renderers[i]) {
   848                     fprintf(stderr, "Couldn't create renderer: %s\n",
   849                             SDL_GetError());
   850                     return SDL_FALSE;
   851                 }
   852                 if (state->verbose & VERBOSE_RENDER) {
   853                     SDL_RendererInfo info;
   854 
   855                     fprintf(stderr, "Current renderer:\n");
   856                     SDL_GetRendererInfo(state->renderers[i], &info);
   857                     SDLTest_PrintRenderer(&info);
   858                 }
   859             }
   860         }
   861     }
   862 
   863     if (state->flags & SDL_INIT_AUDIO) {
   864         if (state->verbose & VERBOSE_AUDIO) {
   865             n = SDL_GetNumAudioDrivers();
   866             if (n == 0) {
   867                 fprintf(stderr, "No built-in audio drivers\n");
   868             } else {
   869                 fprintf(stderr, "Built-in audio drivers:");
   870                 for (i = 0; i < n; ++i) {
   871                     if (i > 0) {
   872                         fprintf(stderr, ",");
   873                     }
   874                     fprintf(stderr, " %s", SDL_GetAudioDriver(i));
   875                 }
   876                 fprintf(stderr, "\n");
   877             }
   878         }
   879         if (SDL_AudioInit(state->audiodriver) < 0) {
   880             fprintf(stderr, "Couldn't initialize audio driver: %s\n",
   881                     SDL_GetError());
   882             return SDL_FALSE;
   883         }
   884         if (state->verbose & VERBOSE_VIDEO) {
   885             fprintf(stderr, "Audio driver: %s\n",
   886                     SDL_GetCurrentAudioDriver());
   887         }
   888 
   889         if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
   890             fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
   891             return SDL_FALSE;
   892         }
   893     }
   894 
   895     return SDL_TRUE;
   896 }
   897 
   898 static void
   899 SDLTest_PrintEvent(SDL_Event * event)
   900 {
   901     if (event->type == SDL_MOUSEMOTION) {
   902         /* Mouse motion is really spammy */
   903         //return;
   904     }
   905 
   906     fprintf(stderr, "SDL EVENT: ");
   907     switch (event->type) {
   908     case SDL_WINDOWEVENT:
   909         switch (event->window.event) {
   910         case SDL_WINDOWEVENT_SHOWN:
   911             fprintf(stderr, "Window %d shown", event->window.windowID);
   912             break;
   913         case SDL_WINDOWEVENT_HIDDEN:
   914             fprintf(stderr, "Window %d hidden", event->window.windowID);
   915             break;
   916         case SDL_WINDOWEVENT_EXPOSED:
   917             fprintf(stderr, "Window %d exposed", event->window.windowID);
   918             break;
   919         case SDL_WINDOWEVENT_MOVED:
   920             fprintf(stderr, "Window %d moved to %d,%d",
   921                     event->window.windowID, event->window.data1,
   922                     event->window.data2);
   923             break;
   924         case SDL_WINDOWEVENT_RESIZED:
   925             fprintf(stderr, "Window %d resized to %dx%d",
   926                     event->window.windowID, event->window.data1,
   927                     event->window.data2);
   928             break;
   929         case SDL_WINDOWEVENT_SIZE_CHANGED:
   930             fprintf(stderr, "Window %d changed size to %dx%d",
   931                     event->window.windowID, event->window.data1,
   932                     event->window.data2);
   933             break;
   934         case SDL_WINDOWEVENT_MINIMIZED:
   935             fprintf(stderr, "Window %d minimized", event->window.windowID);
   936             break;
   937         case SDL_WINDOWEVENT_MAXIMIZED:
   938             fprintf(stderr, "Window %d maximized", event->window.windowID);
   939             break;
   940         case SDL_WINDOWEVENT_RESTORED:
   941             fprintf(stderr, "Window %d restored", event->window.windowID);
   942             break;
   943         case SDL_WINDOWEVENT_ENTER:
   944             fprintf(stderr, "Mouse entered window %d",
   945                     event->window.windowID);
   946             break;
   947         case SDL_WINDOWEVENT_LEAVE:
   948             fprintf(stderr, "Mouse left window %d", event->window.windowID);
   949             break;
   950         case SDL_WINDOWEVENT_FOCUS_GAINED:
   951             fprintf(stderr, "Window %d gained keyboard focus",
   952                     event->window.windowID);
   953             break;
   954         case SDL_WINDOWEVENT_FOCUS_LOST:
   955             fprintf(stderr, "Window %d lost keyboard focus",
   956                     event->window.windowID);
   957             break;
   958         case SDL_WINDOWEVENT_CLOSE:
   959             fprintf(stderr, "Window %d closed", event->window.windowID);
   960             break;
   961         default:
   962             fprintf(stderr, "Window %d got unknown event %d",
   963                     event->window.windowID, event->window.event);
   964             break;
   965         }
   966         break;
   967     case SDL_KEYDOWN:
   968         fprintf(stderr,
   969                 "Keyboard: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   970                 event->key.windowID,
   971                 event->key.keysym.scancode,
   972                 SDL_GetScancodeName(event->key.keysym.scancode),
   973                 event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   974         break;
   975     case SDL_KEYUP:
   976         fprintf(stderr,
   977                 "Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   978                 event->key.windowID,
   979                 event->key.keysym.scancode,
   980                 SDL_GetScancodeName(event->key.keysym.scancode),
   981                 event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   982         break;
   983     case SDL_TEXTINPUT:
   984         fprintf(stderr, "Keyboard: text input \"%s\" in window %d",
   985                 event->text.text, event->text.windowID);
   986         break;
   987     case SDL_MOUSEMOTION:
   988         fprintf(stderr, "Mouse: moved to %d,%d (%d,%d) in window %d",
   989                 event->motion.x, event->motion.y,
   990                 event->motion.xrel, event->motion.yrel,
   991                 event->motion.windowID);
   992         break;
   993     case SDL_MOUSEBUTTONDOWN:
   994         fprintf(stderr, "Mouse: button %d pressed at %d,%d in window %d",
   995                 event->button.button, event->button.x, event->button.y,
   996                 event->button.windowID);
   997         break;
   998     case SDL_MOUSEBUTTONUP:
   999         fprintf(stderr, "Mouse: button %d released at %d,%d in window %d",
  1000                 event->button.button, event->button.x, event->button.y,
  1001                 event->button.windowID);
  1002         break;
  1003     case SDL_MOUSEWHEEL:
  1004         fprintf(stderr,
  1005                 "Mouse: wheel scrolled %d in x and %d in y in window %d",
  1006                 event->wheel.x, event->wheel.y, event->wheel.windowID);
  1007         break;
  1008     case SDL_JOYBALLMOTION:
  1009         fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
  1010                 event->jball.which, event->jball.ball, event->jball.xrel,
  1011                 event->jball.yrel);
  1012         break;
  1013     case SDL_JOYHATMOTION:
  1014         fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
  1015                 event->jhat.hat);
  1016         switch (event->jhat.value) {
  1017         case SDL_HAT_CENTERED:
  1018             fprintf(stderr, "CENTER");
  1019             break;
  1020         case SDL_HAT_UP:
  1021             fprintf(stderr, "UP");
  1022             break;
  1023         case SDL_HAT_RIGHTUP:
  1024             fprintf(stderr, "RIGHTUP");
  1025             break;
  1026         case SDL_HAT_RIGHT:
  1027             fprintf(stderr, "RIGHT");
  1028             break;
  1029         case SDL_HAT_RIGHTDOWN:
  1030             fprintf(stderr, "RIGHTDOWN");
  1031             break;
  1032         case SDL_HAT_DOWN:
  1033             fprintf(stderr, "DOWN");
  1034             break;
  1035         case SDL_HAT_LEFTDOWN:
  1036             fprintf(stderr, "LEFTDOWN");
  1037             break;
  1038         case SDL_HAT_LEFT:
  1039             fprintf(stderr, "LEFT");
  1040             break;
  1041         case SDL_HAT_LEFTUP:
  1042             fprintf(stderr, "LEFTUP");
  1043             break;
  1044         default:
  1045             fprintf(stderr, "UNKNOWN");
  1046             break;
  1047         }
  1048         break;
  1049     case SDL_JOYBUTTONDOWN:
  1050         fprintf(stderr, "Joystick %d: button %d pressed",
  1051                 event->jbutton.which, event->jbutton.button);
  1052         break;
  1053     case SDL_JOYBUTTONUP:
  1054         fprintf(stderr, "Joystick %d: button %d released",
  1055                 event->jbutton.which, event->jbutton.button);
  1056         break;
  1057     case SDL_CLIPBOARDUPDATE:
  1058         fprintf(stderr, "Clipboard updated");
  1059         break;
  1060     case SDL_QUIT:
  1061         fprintf(stderr, "Quit requested");
  1062         break;
  1063     case SDL_USEREVENT:
  1064         fprintf(stderr, "User event %d", event->user.code);
  1065         break;
  1066     default:
  1067         fprintf(stderr, "Unknown event %d", event->type);
  1068         break;
  1069     }
  1070     fprintf(stderr, "\n");
  1071 }
  1072 
  1073 static void
  1074 SDLTest_ScreenShot(SDL_Renderer *renderer)
  1075 {
  1076     SDL_Rect viewport;
  1077     SDL_Surface *surface;
  1078 
  1079     if (!renderer) {
  1080         return;
  1081     }
  1082 
  1083     SDL_RenderGetViewport(renderer, &viewport);
  1084     surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24,
  1085 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  1086                     0x00FF0000, 0x0000FF00, 0x000000FF,
  1087 #else
  1088                     0x000000FF, 0x0000FF00, 0x00FF0000,
  1089 #endif
  1090                     0x00000000);
  1091     if (!surface) {
  1092         fprintf(stderr, "Couldn't create surface: %s\n", SDL_GetError());
  1093         return;
  1094     }
  1095 
  1096     if (SDL_RenderReadPixels(renderer, NULL, surface->format->format,
  1097                              surface->pixels, surface->pitch) < 0) {
  1098         fprintf(stderr, "Couldn't read screen: %s\n", SDL_GetError());
  1099         return;
  1100     }
  1101 
  1102     if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) {
  1103         fprintf(stderr, "Couldn't save screenshot.bmp: %s\n", SDL_GetError());
  1104         return;
  1105     }
  1106 }
  1107 
  1108 void
  1109 SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
  1110 {
  1111     int i;
  1112 
  1113     if (state->verbose & VERBOSE_EVENT) {
  1114         SDLTest_PrintEvent(event);
  1115     }
  1116 
  1117     switch (event->type) {
  1118     case SDL_WINDOWEVENT:
  1119         switch (event->window.event) {
  1120         case SDL_WINDOWEVENT_SIZE_CHANGED:
  1121             {
  1122                 SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
  1123                 if (window) {
  1124                     for (i = 0; i < state->num_windows; ++i) {
  1125                         if (window == state->windows[i] &&
  1126                             (state->window_flags & SDL_WINDOW_RESIZABLE)) {
  1127                             SDL_Rect viewport;
  1128 
  1129                             viewport.x = 0;
  1130                             viewport.y = 0;
  1131                             SDL_GetWindowSize(window, &viewport.w, &viewport.h);
  1132                             SDL_RenderSetViewport(state->renderers[i], &viewport);
  1133                         }
  1134                     }
  1135                 }
  1136             }
  1137             break;
  1138         case SDL_WINDOWEVENT_CLOSE:
  1139 			{
  1140                 SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
  1141                 if (window) {
  1142 					SDL_DestroyWindow(window);
  1143 				}
  1144 			}
  1145             break;
  1146         }
  1147         break;
  1148     case SDL_KEYDOWN:
  1149         switch (event->key.keysym.sym) {
  1150             /* Add hotkeys here */
  1151         case SDLK_PRINTSCREEN: {
  1152                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1153                 if (window) {
  1154                     for (i = 0; i < state->num_windows; ++i) {
  1155                         if (window == state->windows[i]) {
  1156                             SDLTest_ScreenShot(state->renderers[i]);
  1157                         }
  1158                     }
  1159                 }
  1160             }
  1161             break;
  1162         case SDLK_EQUALS:
  1163             if (event->key.keysym.mod & KMOD_CTRL) {
  1164                 /* Ctrt-+ double the size of the window */
  1165                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1166                 if (window) {
  1167                     int w, h;
  1168                     SDL_GetWindowSize(window, &w, &h);
  1169                     SDL_SetWindowSize(window, w*2, h*2);
  1170                 }
  1171             }
  1172             break;
  1173         case SDLK_MINUS:
  1174             if (event->key.keysym.mod & KMOD_CTRL) {
  1175                 /* Ctrt-- double the size of the window */
  1176                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1177                 if (window) {
  1178                     int w, h;
  1179                     SDL_GetWindowSize(window, &w, &h);
  1180                     SDL_SetWindowSize(window, w/2, h/2);
  1181                 }
  1182             }
  1183             break;
  1184         case SDLK_c:
  1185             if (event->key.keysym.mod & KMOD_CTRL) {
  1186                 /* Ctrl-C copy awesome text! */
  1187                 SDL_SetClipboardText("SDL rocks!\nYou know it!");
  1188                 printf("Copied text to clipboard\n");
  1189             }
  1190             break;
  1191         case SDLK_v:
  1192             if (event->key.keysym.mod & KMOD_CTRL) {
  1193                 /* Ctrl-V paste awesome text! */
  1194                 char *text = SDL_GetClipboardText();
  1195                 if (*text) {
  1196                     printf("Clipboard: %s\n", text);
  1197                 } else {
  1198                     printf("Clipboard is empty\n");
  1199                 }
  1200                 SDL_free(text);
  1201             }
  1202             break;
  1203         case SDLK_g:
  1204             if (event->key.keysym.mod & KMOD_CTRL) {
  1205                 /* Ctrl-G toggle grab */
  1206                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1207                 if (window) {
  1208                     SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window));
  1209                 }
  1210             }
  1211             break;
  1212         case SDLK_m:
  1213             if (event->key.keysym.mod & KMOD_CTRL) {
  1214                 /* Ctrl-M maximize */
  1215                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1216                 if (window) {
  1217                     Uint32 flags = SDL_GetWindowFlags(window);
  1218                     if (flags & SDL_WINDOW_MAXIMIZED) {
  1219                         SDL_RestoreWindow(window);
  1220                     } else {
  1221                         SDL_MaximizeWindow(window);
  1222                     }
  1223                 }
  1224             }
  1225             break;
  1226         case SDLK_r:
  1227             if (event->key.keysym.mod & KMOD_CTRL) {
  1228                 /* Ctrl-R toggle mouse relative mode */
  1229                 SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode());
  1230             }
  1231             break;
  1232         case SDLK_z:
  1233             if (event->key.keysym.mod & KMOD_CTRL) {
  1234                 /* Ctrl-Z minimize */
  1235                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1236                 if (window) {
  1237                     SDL_MinimizeWindow(window);
  1238                 }
  1239             }
  1240             break;
  1241         case SDLK_RETURN:
  1242             if (event->key.keysym.mod & KMOD_CTRL) {
  1243                 /* Ctrl-Enter toggle fullscreen */
  1244                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1245                 if (window) {
  1246                     Uint32 flags = SDL_GetWindowFlags(window);
  1247                     if (flags & SDL_WINDOW_FULLSCREEN) {
  1248                         SDL_SetWindowFullscreen(window, SDL_FALSE);
  1249                     } else {
  1250                         SDL_SetWindowFullscreen(window, SDL_TRUE);
  1251                     }
  1252                 }
  1253             }
  1254             break;
  1255         case SDLK_b:
  1256             if (event->key.keysym.mod & KMOD_CTRL) {
  1257                 /* Ctrl-B toggle window border */
  1258                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1259                 if (window) {
  1260                     const Uint32 flags = SDL_GetWindowFlags(window);
  1261                     const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0);
  1262                     SDL_SetWindowBordered(window, b);
  1263                 }
  1264             }
  1265             break;
  1266         case SDLK_1:
  1267             if (event->key.keysym.mod & KMOD_CTRL) {
  1268                 SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
  1269                 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
  1270             }
  1271             break;
  1272         case SDLK_ESCAPE:
  1273             *done = 1;
  1274             break;
  1275         default:
  1276             break;
  1277         }
  1278         break;
  1279     case SDL_QUIT:
  1280         *done = 1;
  1281         break;
  1282     }
  1283 }
  1284 
  1285 void
  1286 SDLTest_CommonQuit(SDLTest_CommonState * state)
  1287 {
  1288     int i;
  1289 
  1290     if (state->windows) {
  1291         SDL_free(state->windows);
  1292     }
  1293     if (state->renderers) {
  1294         for (i = 0; i < state->num_windows; ++i) {
  1295             if (state->renderers[i]) {
  1296                 SDL_DestroyRenderer(state->renderers[i]);
  1297             }
  1298         }
  1299         SDL_free(state->renderers);
  1300     }
  1301     if (state->flags & SDL_INIT_VIDEO) {
  1302         SDL_VideoQuit();
  1303     }
  1304     if (state->flags & SDL_INIT_AUDIO) {
  1305         SDL_AudioQuit();
  1306     }
  1307     SDL_free(state);
  1308 }
  1309 
  1310 /* vi: set ts=4 sw=4 expandtab: */