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