test/common.c
author Patrice Mandin <patmandin@gmail.com>
Fri, 05 Jan 2007 19:12:50 +0000
changeset 2082 e6cd882e3ac0
parent 1970 db3ba6c0d0df
child 2154 5660f48b31f5
permissions -rw-r--r--
Alpha sort the test list, add missing ones, remove removed ones
slouken@1914
     1
slouken@1914
     2
/* A simple test program framework */
slouken@1914
     3
slouken@1914
     4
#include <stdio.h>
slouken@1914
     5
slouken@1914
     6
#include "common.h"
slouken@1914
     7
slouken@1914
     8
#define VIDEO_USAGE \
slouken@1914
     9
"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
slouken@1914
    10
slouken@1914
    11
#define AUDIO_USAGE \
slouken@1914
    12
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
slouken@1914
    13
slouken@1914
    14
CommonState *
slouken@1914
    15
CommonCreateState(char **argv, Uint32 flags)
slouken@1914
    16
{
slouken@1914
    17
    CommonState *state = SDL_calloc(1, sizeof(*state));
slouken@1914
    18
    if (!state) {
slouken@1914
    19
        SDL_OutOfMemory();
slouken@1914
    20
        return NULL;
slouken@1914
    21
    }
slouken@1914
    22
slouken@1914
    23
    /* Initialize some defaults */
slouken@1914
    24
    state->argv = argv;
slouken@1914
    25
    state->flags = flags;
slouken@1914
    26
    state->window_title = argv[0];
slouken@1914
    27
    state->window_flags = SDL_WINDOW_SHOWN;
slouken@1914
    28
    state->window_x = SDL_WINDOWPOS_UNDEFINED;
slouken@1914
    29
    state->window_y = SDL_WINDOWPOS_UNDEFINED;
slouken@1914
    30
    state->window_w = 640;
slouken@1914
    31
    state->window_h = 480;
slouken@1914
    32
    state->num_windows = 1;
slouken@1914
    33
    state->audiospec.freq = 22050;
slouken@1914
    34
    state->audiospec.format = AUDIO_S16;
slouken@1914
    35
    state->audiospec.channels = 2;
slouken@1914
    36
    state->audiospec.samples = 2048;
slouken@1914
    37
    return state;
slouken@1914
    38
}
slouken@1914
    39
slouken@1914
    40
int
slouken@1914
    41
CommonArg(CommonState * state, int index)
slouken@1914
    42
{
slouken@1914
    43
    char **argv = state->argv;
slouken@1914
    44
slouken@1914
    45
    if (SDL_strcasecmp(argv[index], "--video") == 0) {
slouken@1914
    46
        ++index;
slouken@1914
    47
        if (!argv[index]) {
slouken@1914
    48
            return -1;
slouken@1914
    49
        }
slouken@1914
    50
        state->videodriver = argv[index];
slouken@1914
    51
        return 2;
slouken@1914
    52
    }
slouken@1914
    53
    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
slouken@1914
    54
        ++index;
slouken@1914
    55
        if (!argv[index]) {
slouken@1914
    56
            return -1;
slouken@1914
    57
        }
slouken@1914
    58
        state->renderdriver = argv[index];
slouken@1914
    59
        return 2;
slouken@1914
    60
    }
slouken@1914
    61
    if (SDL_strcasecmp(argv[index], "--info") == 0) {
slouken@1914
    62
        ++index;
slouken@1914
    63
        if (!argv[index]) {
slouken@1914
    64
            return -1;
slouken@1914
    65
        }
slouken@1914
    66
        if (SDL_strcasecmp(argv[index], "all") == 0) {
slouken@1914
    67
            state->verbose |=
slouken@1914
    68
                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
slouken@1914
    69
                 VERBOSE_EVENT);
slouken@1914
    70
            return 2;
slouken@1914
    71
        }
slouken@1914
    72
        if (SDL_strcasecmp(argv[index], "video") == 0) {
slouken@1914
    73
            state->verbose |= VERBOSE_VIDEO;
slouken@1914
    74
            return 2;
slouken@1914
    75
        }
slouken@1914
    76
        if (SDL_strcasecmp(argv[index], "modes") == 0) {
slouken@1914
    77
            state->verbose |= VERBOSE_MODES;
slouken@1914
    78
            return 2;
slouken@1914
    79
        }
slouken@1914
    80
        if (SDL_strcasecmp(argv[index], "render") == 0) {
slouken@1914
    81
            state->verbose |= VERBOSE_RENDER;
slouken@1914
    82
            return 2;
slouken@1914
    83
        }
slouken@1914
    84
        if (SDL_strcasecmp(argv[index], "event") == 0) {
slouken@1914
    85
            state->verbose |= VERBOSE_EVENT;
slouken@1914
    86
            return 2;
slouken@1914
    87
        }
slouken@1914
    88
        return -1;
slouken@1914
    89
    }
slouken@1914
    90
    if (SDL_strcasecmp(argv[index], "--display") == 0) {
slouken@1914
    91
        ++index;
slouken@1914
    92
        if (!argv[index]) {
slouken@1914
    93
            return -1;
slouken@1914
    94
        }
slouken@1914
    95
        state->display = SDL_atoi(argv[index]);
slouken@1914
    96
        return 2;
slouken@1914
    97
    }
slouken@1914
    98
    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
slouken@1914
    99
        state->window_flags |= SDL_WINDOW_FULLSCREEN;
slouken@1914
   100
        state->num_windows = 1;
slouken@1914
   101
        return 1;
slouken@1914
   102
    }
slouken@1914
   103
    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
slouken@1914
   104
        ++index;
slouken@1916
   105
        if (!argv[index] || !SDL_isdigit(*argv[index])) {
slouken@1914
   106
            return -1;
slouken@1914
   107
        }
slouken@1914
   108
        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
slouken@1914
   109
            state->num_windows = SDL_atoi(argv[index]);
slouken@1914
   110
        }
slouken@1914
   111
        return 2;
slouken@1914
   112
    }
slouken@1914
   113
    if (SDL_strcasecmp(argv[index], "--title") == 0) {
slouken@1914
   114
        ++index;
slouken@1914
   115
        if (!argv[index]) {
slouken@1914
   116
            return -1;
slouken@1914
   117
        }
slouken@1914
   118
        state->window_title = argv[index];
slouken@1914
   119
        return 2;
slouken@1914
   120
    }
slouken@1914
   121
    if (SDL_strcasecmp(argv[index], "--center") == 0) {
slouken@1914
   122
        state->window_x = SDL_WINDOWPOS_CENTERED;
slouken@1914
   123
        state->window_y = SDL_WINDOWPOS_CENTERED;
slouken@1914
   124
        return 1;
slouken@1914
   125
    }
slouken@1914
   126
    if (SDL_strcasecmp(argv[index], "--position") == 0) {
slouken@1914
   127
        char *x, *y;
slouken@1914
   128
        ++index;
slouken@1914
   129
        if (!argv[index]) {
slouken@1914
   130
            return -1;
slouken@1914
   131
        }
slouken@1914
   132
        x = argv[index];
slouken@1914
   133
        y = argv[index];
slouken@1914
   134
        while (*y && *y != ',') {
slouken@1914
   135
            ++y;
slouken@1914
   136
        }
slouken@1914
   137
        if (!*y) {
slouken@1914
   138
            return -1;
slouken@1914
   139
        }
slouken@1914
   140
        *y++ = '\0';
slouken@1914
   141
        state->window_x = SDL_atoi(x);
slouken@1914
   142
        state->window_y = SDL_atoi(y);
slouken@1914
   143
        return 2;
slouken@1914
   144
    }
slouken@1914
   145
    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
slouken@1914
   146
        char *w, *h;
slouken@1914
   147
        ++index;
slouken@1914
   148
        if (!argv[index]) {
slouken@1914
   149
            return -1;
slouken@1914
   150
        }
slouken@1914
   151
        w = argv[index];
slouken@1914
   152
        h = argv[index];
slouken@1914
   153
        while (*h && *h != 'x') {
slouken@1914
   154
            ++h;
slouken@1914
   155
        }
slouken@1914
   156
        if (!*h) {
slouken@1914
   157
            return -1;
slouken@1914
   158
        }
slouken@1914
   159
        *h++ = '\0';
slouken@1914
   160
        state->window_w = SDL_atoi(w);
slouken@1914
   161
        state->window_h = SDL_atoi(h);
slouken@1914
   162
        return 2;
slouken@1914
   163
    }
slouken@1914
   164
    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
slouken@1914
   165
        ++index;
slouken@1914
   166
        if (!argv[index]) {
slouken@1914
   167
            return -1;
slouken@1914
   168
        }
slouken@1914
   169
        state->refresh_rate = SDL_atoi(argv[index]);
slouken@1914
   170
        return 2;
slouken@1914
   171
    }
slouken@1914
   172
    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
slouken@1965
   173
        state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@1914
   174
        return 1;
slouken@1914
   175
    }
slouken@1914
   176
    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
slouken@1914
   177
        state->window_flags |= SDL_WINDOW_BORDERLESS;
slouken@1914
   178
        return 1;
slouken@1914
   179
    }
slouken@1914
   180
    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
slouken@1914
   181
        state->window_flags |= SDL_WINDOW_RESIZABLE;
slouken@1914
   182
        return 1;
slouken@1914
   183
    }
slouken@1914
   184
    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
slouken@1914
   185
        state->window_flags |= SDL_WINDOW_MINIMIZED;
slouken@1914
   186
        return 1;
slouken@1914
   187
    }
slouken@1914
   188
    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
slouken@1914
   189
        state->window_flags |= SDL_WINDOW_MAXIMIZED;
slouken@1914
   190
        return 1;
slouken@1914
   191
    }
slouken@1914
   192
    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
slouken@1914
   193
        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
slouken@1914
   194
        return 1;
slouken@1914
   195
    }
slouken@1914
   196
    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
slouken@1914
   197
        ++index;
slouken@1914
   198
        if (!argv[index]) {
slouken@1914
   199
            return -1;
slouken@1914
   200
        }
slouken@1914
   201
        state->audiospec.freq = SDL_atoi(argv[index]);
slouken@1914
   202
        return 2;
slouken@1914
   203
    }
slouken@1914
   204
    if (SDL_strcasecmp(argv[index], "--format") == 0) {
slouken@1914
   205
        ++index;
slouken@1914
   206
        if (!argv[index]) {
slouken@1914
   207
            return -1;
slouken@1914
   208
        }
slouken@1914
   209
        if (SDL_strcasecmp(argv[index], "U8") == 0) {
slouken@1914
   210
            state->audiospec.format = AUDIO_U8;
slouken@1914
   211
            return 2;
slouken@1914
   212
        }
slouken@1914
   213
        if (SDL_strcasecmp(argv[index], "S8") == 0) {
slouken@1914
   214
            state->audiospec.format = AUDIO_S8;
slouken@1914
   215
            return 2;
slouken@1914
   216
        }
slouken@1914
   217
        if (SDL_strcasecmp(argv[index], "U16") == 0) {
slouken@1914
   218
            state->audiospec.format = AUDIO_U16;
slouken@1914
   219
            return 2;
slouken@1914
   220
        }
slouken@1914
   221
        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
slouken@1914
   222
            state->audiospec.format = AUDIO_U16LSB;
slouken@1914
   223
            return 2;
slouken@1914
   224
        }
slouken@1914
   225
        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
slouken@1914
   226
            state->audiospec.format = AUDIO_U16MSB;
slouken@1914
   227
            return 2;
slouken@1914
   228
        }
slouken@1914
   229
        if (SDL_strcasecmp(argv[index], "S16") == 0) {
slouken@1914
   230
            state->audiospec.format = AUDIO_S16;
slouken@1914
   231
            return 2;
slouken@1914
   232
        }
slouken@1914
   233
        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
slouken@1914
   234
            state->audiospec.format = AUDIO_S16LSB;
slouken@1914
   235
            return 2;
slouken@1914
   236
        }
slouken@1914
   237
        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
slouken@1914
   238
            state->audiospec.format = AUDIO_S16MSB;
slouken@1914
   239
            return 2;
slouken@1914
   240
        }
slouken@1914
   241
        return -1;
slouken@1914
   242
    }
slouken@1914
   243
    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
slouken@1914
   244
        ++index;
slouken@1914
   245
        if (!argv[index]) {
slouken@1914
   246
            return -1;
slouken@1914
   247
        }
slouken@1914
   248
        state->audiospec.channels = SDL_atoi(argv[index]);
slouken@1914
   249
        return 2;
slouken@1914
   250
    }
slouken@1914
   251
    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
slouken@1914
   252
        ++index;
slouken@1914
   253
        if (!argv[index]) {
slouken@1914
   254
            return -1;
slouken@1914
   255
        }
slouken@1914
   256
        state->audiospec.samples = SDL_atoi(argv[index]);
slouken@1914
   257
        return 2;
slouken@1914
   258
    }
slouken@1914
   259
    if ((SDL_strcasecmp(argv[index], "-h") == 0)
slouken@1914
   260
        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
slouken@1914
   261
        /* Print the usage message */
slouken@1914
   262
        return -1;
slouken@1914
   263
    }
slouken@1914
   264
    return 0;
slouken@1914
   265
}
slouken@1914
   266
slouken@1914
   267
const char *
slouken@1914
   268
CommonUsage(CommonState * state)
slouken@1914
   269
{
slouken@1914
   270
    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
slouken@1914
   271
    case SDL_INIT_VIDEO:
slouken@1914
   272
        return VIDEO_USAGE;
slouken@1914
   273
    case SDL_INIT_AUDIO:
slouken@1914
   274
        return AUDIO_USAGE;
slouken@1914
   275
    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
slouken@1914
   276
        return VIDEO_USAGE " " AUDIO_USAGE;
slouken@1914
   277
    default:
slouken@1914
   278
        return "";
slouken@1914
   279
    }
slouken@1914
   280
}
slouken@1914
   281
slouken@1914
   282
static void
slouken@1914
   283
PrintRendererFlag(Uint32 flag)
slouken@1914
   284
{
slouken@1914
   285
    switch (flag) {
slouken@1965
   286
    case SDL_RENDERER_SINGLEBUFFER:
slouken@1914
   287
        fprintf(stderr, "SingleBuffer");
slouken@1914
   288
        break;
slouken@1965
   289
    case SDL_RENDERER_PRESENTCOPY:
slouken@1914
   290
        fprintf(stderr, "PresentCopy");
slouken@1914
   291
        break;
slouken@1965
   292
    case SDL_RENDERER_PRESENTFLIP2:
slouken@1914
   293
        fprintf(stderr, "PresentFlip2");
slouken@1914
   294
        break;
slouken@1965
   295
    case SDL_RENDERER_PRESENTFLIP3:
slouken@1914
   296
        fprintf(stderr, "PresentFlip3");
slouken@1914
   297
        break;
slouken@1965
   298
    case SDL_RENDERER_PRESENTDISCARD:
slouken@1914
   299
        fprintf(stderr, "PresentDiscard");
slouken@1914
   300
        break;
slouken@1965
   301
    case SDL_RENDERER_PRESENTVSYNC:
slouken@1914
   302
        fprintf(stderr, "PresentVSync");
slouken@1914
   303
        break;
slouken@1965
   304
    case SDL_RENDERER_ACCELERATED:
slouken@1921
   305
        fprintf(stderr, "Accelerated");
slouken@1921
   306
        break;
slouken@1914
   307
    default:
slouken@1914
   308
        fprintf(stderr, "0x%8.8x", flag);
slouken@1914
   309
        break;
slouken@1914
   310
    }
slouken@1914
   311
}
slouken@1914
   312
slouken@1914
   313
static void
slouken@1914
   314
PrintBlendMode(Uint32 flag)
slouken@1914
   315
{
slouken@1914
   316
    switch (flag) {
slouken@1965
   317
    case SDL_TEXTUREBLENDMODE_NONE:
slouken@1914
   318
        fprintf(stderr, "None");
slouken@1914
   319
        break;
slouken@1965
   320
    case SDL_TEXTUREBLENDMODE_MASK:
slouken@1914
   321
        fprintf(stderr, "Mask");
slouken@1914
   322
        break;
slouken@1965
   323
    case SDL_TEXTUREBLENDMODE_BLEND:
slouken@1914
   324
        fprintf(stderr, "Blend");
slouken@1914
   325
        break;
slouken@1965
   326
    case SDL_TEXTUREBLENDMODE_ADD:
slouken@1914
   327
        fprintf(stderr, "Add");
slouken@1914
   328
        break;
slouken@1965
   329
    case SDL_TEXTUREBLENDMODE_MOD:
slouken@1914
   330
        fprintf(stderr, "Mod");
slouken@1914
   331
        break;
slouken@1914
   332
    default:
slouken@1914
   333
        fprintf(stderr, "0x%8.8x", flag);
slouken@1914
   334
        break;
slouken@1914
   335
    }
slouken@1914
   336
}
slouken@1914
   337
slouken@1914
   338
static void
slouken@1914
   339
PrintScaleMode(Uint32 flag)
slouken@1914
   340
{
slouken@1914
   341
    switch (flag) {
slouken@1965
   342
    case SDL_TEXTURESCALEMODE_NONE:
slouken@1914
   343
        fprintf(stderr, "None");
slouken@1914
   344
        break;
slouken@1965
   345
    case SDL_TEXTURESCALEMODE_FAST:
slouken@1914
   346
        fprintf(stderr, "Fast");
slouken@1914
   347
        break;
slouken@1965
   348
    case SDL_TEXTURESCALEMODE_SLOW:
slouken@1914
   349
        fprintf(stderr, "Slow");
slouken@1914
   350
        break;
slouken@1965
   351
    case SDL_TEXTURESCALEMODE_BEST:
slouken@1914
   352
        fprintf(stderr, "Best");
slouken@1914
   353
        break;
slouken@1914
   354
    default:
slouken@1914
   355
        fprintf(stderr, "0x%8.8x", flag);
slouken@1914
   356
        break;
slouken@1914
   357
    }
slouken@1914
   358
}
slouken@1914
   359
slouken@1914
   360
static void
slouken@1914
   361
PrintPixelFormat(Uint32 format)
slouken@1914
   362
{
slouken@1914
   363
    switch (format) {
slouken@1965
   364
    case SDL_PIXELFORMAT_UNKNOWN:
slouken@1914
   365
        fprintf(stderr, "Unknwon");
slouken@1914
   366
        break;
slouken@1965
   367
    case SDL_PIXELFORMAT_INDEX1LSB:
slouken@1914
   368
        fprintf(stderr, "Index1LSB");
slouken@1914
   369
        break;
slouken@1965
   370
    case SDL_PIXELFORMAT_INDEX1MSB:
slouken@1914
   371
        fprintf(stderr, "Index1MSB");
slouken@1914
   372
        break;
slouken@1965
   373
    case SDL_PIXELFORMAT_INDEX4LSB:
slouken@1914
   374
        fprintf(stderr, "Index4LSB");
slouken@1914
   375
        break;
slouken@1965
   376
    case SDL_PIXELFORMAT_INDEX4MSB:
slouken@1914
   377
        fprintf(stderr, "Index4MSB");
slouken@1914
   378
        break;
slouken@1965
   379
    case SDL_PIXELFORMAT_INDEX8:
slouken@1914
   380
        fprintf(stderr, "Index8");
slouken@1914
   381
        break;
slouken@1965
   382
    case SDL_PIXELFORMAT_RGB332:
slouken@1914
   383
        fprintf(stderr, "RGB332");
slouken@1914
   384
        break;
slouken@1965
   385
    case SDL_PIXELFORMAT_RGB444:
slouken@1914
   386
        fprintf(stderr, "RGB444");
slouken@1914
   387
        break;
slouken@1965
   388
    case SDL_PIXELFORMAT_RGB555:
slouken@1914
   389
        fprintf(stderr, "RGB555");
slouken@1914
   390
        break;
slouken@1965
   391
    case SDL_PIXELFORMAT_ARGB4444:
slouken@1914
   392
        fprintf(stderr, "ARGB4444");
slouken@1914
   393
        break;
slouken@1965
   394
    case SDL_PIXELFORMAT_ARGB1555:
slouken@1914
   395
        fprintf(stderr, "ARGB1555");
slouken@1914
   396
        break;
slouken@1965
   397
    case SDL_PIXELFORMAT_RGB565:
slouken@1914
   398
        fprintf(stderr, "RGB565");
slouken@1914
   399
        break;
slouken@1965
   400
    case SDL_PIXELFORMAT_RGB24:
slouken@1914
   401
        fprintf(stderr, "RGB24");
slouken@1914
   402
        break;
slouken@1965
   403
    case SDL_PIXELFORMAT_BGR24:
slouken@1914
   404
        fprintf(stderr, "BGR24");
slouken@1914
   405
        break;
slouken@1965
   406
    case SDL_PIXELFORMAT_RGB888:
slouken@1914
   407
        fprintf(stderr, "RGB888");
slouken@1914
   408
        break;
slouken@1965
   409
    case SDL_PIXELFORMAT_BGR888:
slouken@1914
   410
        fprintf(stderr, "BGR888");
slouken@1914
   411
        break;
slouken@1965
   412
    case SDL_PIXELFORMAT_ARGB8888:
slouken@1914
   413
        fprintf(stderr, "ARGB8888");
slouken@1914
   414
        break;
slouken@1965
   415
    case SDL_PIXELFORMAT_RGBA8888:
slouken@1914
   416
        fprintf(stderr, "RGBA8888");
slouken@1914
   417
        break;
slouken@1965
   418
    case SDL_PIXELFORMAT_ABGR8888:
slouken@1914
   419
        fprintf(stderr, "ABGR8888");
slouken@1914
   420
        break;
slouken@1965
   421
    case SDL_PIXELFORMAT_BGRA8888:
slouken@1914
   422
        fprintf(stderr, "BGRA8888");
slouken@1914
   423
        break;
slouken@1965
   424
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@1914
   425
        fprintf(stderr, "ARGB2101010");
slouken@1914
   426
        break;
slouken@1965
   427
    case SDL_PIXELFORMAT_YV12:
slouken@1914
   428
        fprintf(stderr, "YV12");
slouken@1914
   429
        break;
slouken@1965
   430
    case SDL_PIXELFORMAT_IYUV:
slouken@1914
   431
        fprintf(stderr, "IYUV");
slouken@1914
   432
        break;
slouken@1965
   433
    case SDL_PIXELFORMAT_YUY2:
slouken@1914
   434
        fprintf(stderr, "YUY2");
slouken@1914
   435
        break;
slouken@1965
   436
    case SDL_PIXELFORMAT_UYVY:
slouken@1914
   437
        fprintf(stderr, "UYVY");
slouken@1914
   438
        break;
slouken@1965
   439
    case SDL_PIXELFORMAT_YVYU:
slouken@1914
   440
        fprintf(stderr, "YVYU");
slouken@1914
   441
        break;
slouken@1914
   442
    default:
slouken@1914
   443
        fprintf(stderr, "0x%8.8x", format);
slouken@1914
   444
        break;
slouken@1914
   445
    }
slouken@1914
   446
}
slouken@1914
   447
slouken@1914
   448
static void
slouken@1914
   449
PrintRenderer(SDL_RendererInfo * info)
slouken@1914
   450
{
slouken@1914
   451
    int i, count;
slouken@1914
   452
slouken@1914
   453
    fprintf(stderr, "  Renderer %s:\n", info->name);
slouken@1914
   454
slouken@1914
   455
    fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
slouken@1914
   456
    fprintf(stderr, " (");
slouken@1914
   457
    count = 0;
slouken@1914
   458
    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
slouken@1914
   459
        Uint32 flag = (1 << i);
slouken@1914
   460
        if (info->flags & flag) {
slouken@1914
   461
            if (count > 0) {
slouken@1914
   462
                fprintf(stderr, " | ");
slouken@1914
   463
            }
slouken@1914
   464
            PrintRendererFlag(flag);
slouken@1914
   465
            ++count;
slouken@1914
   466
        }
slouken@1914
   467
    }
slouken@1914
   468
    fprintf(stderr, ")\n");
slouken@1914
   469
slouken@1914
   470
    fprintf(stderr, "    Blend: 0x%8.8X", info->blend_modes);
slouken@1914
   471
    fprintf(stderr, " (");
slouken@1914
   472
    count = 0;
slouken@1914
   473
    for (i = 0; i < sizeof(info->blend_modes) * 8; ++i) {
slouken@1914
   474
        Uint32 flag = (1 << i);
slouken@1914
   475
        if (info->blend_modes & flag) {
slouken@1914
   476
            if (count > 0) {
slouken@1914
   477
                fprintf(stderr, " | ");
slouken@1914
   478
            }
slouken@1914
   479
            PrintBlendMode(flag);
slouken@1914
   480
            ++count;
slouken@1914
   481
        }
slouken@1914
   482
    }
slouken@1914
   483
    fprintf(stderr, ")\n");
slouken@1914
   484
slouken@1914
   485
    fprintf(stderr, "    Scale: 0x%8.8X", info->scale_modes);
slouken@1914
   486
    fprintf(stderr, " (");
slouken@1914
   487
    count = 0;
slouken@1914
   488
    for (i = 0; i < sizeof(info->scale_modes) * 8; ++i) {
slouken@1914
   489
        Uint32 flag = (1 << i);
slouken@1914
   490
        if (info->scale_modes & flag) {
slouken@1914
   491
            if (count > 0) {
slouken@1914
   492
                fprintf(stderr, " | ");
slouken@1914
   493
            }
slouken@1914
   494
            PrintScaleMode(flag);
slouken@1914
   495
            ++count;
slouken@1914
   496
        }
slouken@1914
   497
    }
slouken@1914
   498
    fprintf(stderr, ")\n");
slouken@1914
   499
slouken@1914
   500
    fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
slouken@1914
   501
    for (i = 0; i < info->num_texture_formats; ++i) {
slouken@1914
   502
        if (i > 0) {
slouken@1914
   503
            fprintf(stderr, ", ");
slouken@1914
   504
        }
slouken@1914
   505
        PrintPixelFormat(info->texture_formats[i]);
slouken@1914
   506
    }
slouken@1914
   507
    fprintf(stderr, "\n");
slouken@1914
   508
slouken@1914
   509
    if (info->max_texture_width || info->max_texture_height) {
slouken@1914
   510
        fprintf(stderr, "    Max Texture Size: %dx%d\n",
slouken@1914
   511
                info->max_texture_width, info->max_texture_height);
slouken@1914
   512
    }
slouken@1914
   513
}
slouken@1914
   514
slouken@1914
   515
SDL_bool
slouken@1914
   516
CommonInit(CommonState * state)
slouken@1914
   517
{
slouken@1914
   518
    int i, j, m, n;
slouken@1914
   519
    SDL_DisplayMode fullscreen_mode;
slouken@1914
   520
slouken@1914
   521
    if (state->flags & SDL_INIT_VIDEO) {
slouken@1914
   522
        if (state->verbose & VERBOSE_VIDEO) {
slouken@1914
   523
            n = SDL_GetNumVideoDrivers();
slouken@1914
   524
            if (n == 0) {
slouken@1914
   525
                fprintf(stderr, "No built-in video drivers\n");
slouken@1914
   526
            } else {
slouken@1914
   527
                fprintf(stderr, "Built-in video drivers:");
slouken@1914
   528
                for (i = 0; i < n; ++i) {
slouken@1914
   529
                    if (i > 0) {
slouken@1914
   530
                        fprintf(stderr, ",");
slouken@1914
   531
                    }
slouken@1914
   532
                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
slouken@1914
   533
                }
slouken@1914
   534
                fprintf(stderr, "\n");
slouken@1914
   535
            }
slouken@1914
   536
        }
slouken@1914
   537
        if (SDL_VideoInit(state->videodriver, 0) < 0) {
slouken@1914
   538
            fprintf(stderr, "Couldn't initialize video driver: %s\n",
slouken@1914
   539
                    SDL_GetError());
slouken@1914
   540
            return SDL_FALSE;
slouken@1914
   541
        }
slouken@1914
   542
        if (state->verbose & VERBOSE_VIDEO) {
slouken@1914
   543
            fprintf(stderr, "Video driver: %s\n",
slouken@1914
   544
                    SDL_GetCurrentVideoDriver());
slouken@1914
   545
        }
slouken@1914
   546
slouken@1914
   547
        if (state->verbose & VERBOSE_MODES) {
slouken@1967
   548
            SDL_DisplayMode mode;
slouken@1914
   549
            int bpp;
slouken@1914
   550
            Uint32 Rmask, Gmask, Bmask, Amask;
slouken@1914
   551
slouken@1914
   552
            n = SDL_GetNumVideoDisplays();
slouken@1914
   553
            fprintf(stderr, "Number of displays: %d\n", n);
slouken@1914
   554
            for (i = 0; i < n; ++i) {
slouken@1914
   555
                fprintf(stderr, "Display %d:\n", i);
slouken@1914
   556
                SDL_SelectVideoDisplay(i);
slouken@1914
   557
slouken@1967
   558
                SDL_GetDesktopDisplayMode(&mode);
slouken@1967
   559
                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
slouken@1914
   560
                                           &Bmask, &Amask);
slouken@1914
   561
                fprintf(stderr,
slouken@1914
   562
                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel\n",
slouken@1967
   563
                        mode.w, mode.h, mode.refresh_rate, bpp);
slouken@1914
   564
                if (Rmask || Gmask || Bmask) {
slouken@1914
   565
                    fprintf(stderr, "      Red Mask = 0x%.8x\n", Rmask);
slouken@1914
   566
                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
slouken@1914
   567
                    fprintf(stderr, "      Blue Mask = 0x%.8x\n", Bmask);
slouken@1914
   568
                    if (Amask)
slouken@1914
   569
                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
slouken@1914
   570
                }
slouken@1914
   571
slouken@1914
   572
                /* Print available fullscreen video modes */
slouken@1914
   573
                m = SDL_GetNumDisplayModes();
slouken@1914
   574
                if (m == 0) {
slouken@1914
   575
                    fprintf(stderr, "No available fullscreen video modes\n");
slouken@1914
   576
                } else {
slouken@1914
   577
                    fprintf(stderr, "  Fullscreen video modes:\n");
slouken@1914
   578
                    for (j = 0; j < m; ++j) {
slouken@1967
   579
                        SDL_GetDisplayMode(j, &mode);
slouken@1967
   580
                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
slouken@1914
   581
                                                   &Gmask, &Bmask, &Amask);
slouken@1914
   582
                        fprintf(stderr,
slouken@1914
   583
                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n",
slouken@1967
   584
                                j, mode.w, mode.h, mode.refresh_rate, bpp);
slouken@1914
   585
                        if (Rmask || Gmask || Bmask) {
slouken@1914
   586
                            fprintf(stderr, "        Red Mask = 0x%.8x\n",
slouken@1914
   587
                                    Rmask);
slouken@1914
   588
                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
slouken@1914
   589
                                    Gmask);
slouken@1914
   590
                            fprintf(stderr, "        Blue Mask = 0x%.8x\n",
slouken@1914
   591
                                    Bmask);
slouken@1914
   592
                            if (Amask)
slouken@1914
   593
                                fprintf(stderr,
slouken@1914
   594
                                        "        Alpha Mask = 0x%.8x\n",
slouken@1914
   595
                                        Amask);
slouken@1914
   596
                        }
slouken@1914
   597
                    }
slouken@1914
   598
                }
slouken@1914
   599
            }
slouken@1914
   600
        }
slouken@1914
   601
slouken@1914
   602
        SDL_SelectVideoDisplay(state->display);
slouken@1914
   603
        if (state->verbose & VERBOSE_RENDER) {
slouken@1914
   604
            SDL_RendererInfo info;
slouken@1914
   605
slouken@1969
   606
            n = SDL_GetNumRenderDrivers();
slouken@1914
   607
            if (n == 0) {
slouken@1914
   608
                fprintf(stderr, "No built-in render drivers\n");
slouken@1914
   609
            } else {
slouken@1923
   610
                fprintf(stderr, "Built-in render drivers:\n");
slouken@1914
   611
                for (i = 0; i < n; ++i) {
slouken@1969
   612
                    SDL_GetRenderDriverInfo(i, &info);
slouken@1914
   613
                    PrintRenderer(&info);
slouken@1914
   614
                }
slouken@1914
   615
            }
slouken@1914
   616
        }
slouken@1914
   617
slouken@1914
   618
        switch (state->depth) {
slouken@1914
   619
        case 8:
slouken@1965
   620
            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
slouken@1914
   621
            break;
slouken@1914
   622
        case 15:
slouken@1965
   623
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
slouken@1914
   624
            break;
slouken@1914
   625
        case 16:
slouken@1965
   626
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
slouken@1914
   627
            break;
slouken@1914
   628
        default:
slouken@1965
   629
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
slouken@1914
   630
            break;
slouken@1914
   631
        }
slouken@1914
   632
        fullscreen_mode.w = state->window_w;
slouken@1914
   633
        fullscreen_mode.h = state->window_h;
slouken@1914
   634
        fullscreen_mode.refresh_rate = state->refresh_rate;
slouken@1914
   635
        SDL_SetFullscreenDisplayMode(&fullscreen_mode);
slouken@1914
   636
slouken@1914
   637
        state->windows =
slouken@1914
   638
            (SDL_WindowID *) SDL_malloc(state->num_windows *
slouken@1914
   639
                                        sizeof(*state->windows));
slouken@1914
   640
        if (!state->windows) {
slouken@1914
   641
            fprintf(stderr, "Out of memory!\n");
slouken@1914
   642
            return SDL_FALSE;
slouken@1914
   643
        }
slouken@1914
   644
        for (i = 0; i < state->num_windows; ++i) {
slouken@1914
   645
            char title[1024];
slouken@1914
   646
slouken@1914
   647
            if (state->num_windows > 1) {
slouken@1914
   648
                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
slouken@1914
   649
                             state->window_title, i + 1);
slouken@1914
   650
            } else {
slouken@1914
   651
                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
slouken@1914
   652
            }
slouken@1914
   653
            state->windows[i] =
slouken@1914
   654
                SDL_CreateWindow(title, state->window_x, state->window_y,
slouken@1914
   655
                                 state->window_w, state->window_h,
slouken@1914
   656
                                 state->window_flags);
slouken@1914
   657
            if (!state->windows[i]) {
slouken@1914
   658
                fprintf(stderr, "Couldn't create window: %s\n",
slouken@1914
   659
                        SDL_GetError());
slouken@1914
   660
                return SDL_FALSE;
slouken@1914
   661
            }
slouken@1914
   662
slouken@1933
   663
            if (!state->skip_renderer
slouken@1933
   664
                && (state->renderdriver
slouken@1933
   665
                    || !(state->window_flags & SDL_WINDOW_OPENGL))) {
slouken@1914
   666
                m = -1;
slouken@1914
   667
                if (state->renderdriver) {
slouken@1914
   668
                    SDL_RendererInfo info;
slouken@1969
   669
                    n = SDL_GetNumRenderDrivers();
slouken@1914
   670
                    for (j = 0; j < n; ++j) {
slouken@1969
   671
                        SDL_GetRenderDriverInfo(j, &info);
slouken@1914
   672
                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
slouken@1914
   673
                            0) {
slouken@1914
   674
                            m = j;
slouken@1914
   675
                            break;
slouken@1914
   676
                        }
slouken@1914
   677
                    }
slouken@1914
   678
                    if (m == n) {
slouken@1914
   679
                        fprintf(stderr,
slouken@1914
   680
                                "Couldn't find render driver named %s",
slouken@1914
   681
                                state->renderdriver);
slouken@1914
   682
                        return SDL_FALSE;
slouken@1914
   683
                    }
slouken@1914
   684
                }
slouken@1914
   685
                if (SDL_CreateRenderer
slouken@1914
   686
                    (state->windows[i], m, state->render_flags) < 0) {
slouken@1914
   687
                    fprintf(stderr, "Couldn't create renderer: %s\n",
slouken@1914
   688
                            SDL_GetError());
slouken@1914
   689
                    return SDL_FALSE;
slouken@1914
   690
                }
slouken@1923
   691
                if (state->verbose & VERBOSE_RENDER) {
slouken@1923
   692
                    SDL_RendererInfo info;
slouken@1923
   693
slouken@1923
   694
                    fprintf(stderr, "Current renderer:\n");
slouken@1969
   695
                    SDL_GetRendererInfo(&info);
slouken@1923
   696
                    PrintRenderer(&info);
slouken@1923
   697
                }
slouken@1914
   698
            }
slouken@1914
   699
        }
slouken@1914
   700
        SDL_SelectRenderer(state->windows[0]);
slouken@1914
   701
    }
slouken@1914
   702
slouken@1914
   703
    if (state->flags & SDL_INIT_AUDIO) {
slouken@1914
   704
        if (state->verbose & VERBOSE_AUDIO) {
slouken@1914
   705
            n = SDL_GetNumAudioDrivers();
slouken@1914
   706
            if (n == 0) {
slouken@1914
   707
                fprintf(stderr, "No built-in audio drivers\n");
slouken@1914
   708
            } else {
slouken@1914
   709
                fprintf(stderr, "Built-in audio drivers:");
slouken@1914
   710
                for (i = 0; i < n; ++i) {
slouken@1914
   711
                    if (i > 0) {
slouken@1914
   712
                        fprintf(stderr, ",");
slouken@1914
   713
                    }
slouken@1914
   714
                    fprintf(stderr, " %s", SDL_GetAudioDriver(i));
slouken@1914
   715
                }
slouken@1914
   716
                fprintf(stderr, "\n");
slouken@1914
   717
            }
slouken@1914
   718
        }
slouken@1914
   719
        if (SDL_AudioInit(state->audiodriver) < 0) {
slouken@1914
   720
            fprintf(stderr, "Couldn't initialize audio driver: %s\n",
slouken@1914
   721
                    SDL_GetError());
slouken@1914
   722
            return SDL_FALSE;
slouken@1914
   723
        }
slouken@1914
   724
        if (state->verbose & VERBOSE_VIDEO) {
slouken@1914
   725
            fprintf(stderr, "Audio driver: %s\n",
slouken@1914
   726
                    SDL_GetCurrentAudioDriver());
slouken@1914
   727
        }
slouken@1914
   728
slouken@1914
   729
        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
slouken@1914
   730
            fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
slouken@1914
   731
            return SDL_FALSE;
slouken@1914
   732
        }
slouken@1914
   733
    }
slouken@1914
   734
slouken@1914
   735
    return SDL_TRUE;
slouken@1914
   736
}
slouken@1914
   737
slouken@1914
   738
static void
slouken@1914
   739
PrintEvent(SDL_Event * event)
slouken@1914
   740
{
slouken@1914
   741
    fprintf(stderr, "SDL EVENT: ");
slouken@1914
   742
    switch (event->type) {
slouken@1914
   743
    case SDL_WINDOWEVENT:
slouken@1914
   744
        switch (event->window.event) {
slouken@1914
   745
        case SDL_WINDOWEVENT_SHOWN:
slouken@1914
   746
            fprintf(stderr, "Window %d shown", event->window.windowID);
slouken@1914
   747
            break;
slouken@1914
   748
        case SDL_WINDOWEVENT_HIDDEN:
slouken@1914
   749
            fprintf(stderr, "Window %d hidden", event->window.windowID);
slouken@1914
   750
            break;
slouken@1914
   751
        case SDL_WINDOWEVENT_EXPOSED:
slouken@1970
   752
            fprintf(stderr, "Window %d exposed", event->window.windowID);
slouken@1914
   753
            break;
slouken@1914
   754
        case SDL_WINDOWEVENT_MOVED:
slouken@1970
   755
            fprintf(stderr, "Window %d moved to %d,%d",
slouken@1914
   756
                    event->window.windowID, event->window.data1,
slouken@1914
   757
                    event->window.data2);
slouken@1914
   758
            break;
slouken@1914
   759
        case SDL_WINDOWEVENT_RESIZED:
slouken@1970
   760
            fprintf(stderr, "Window %d resized to %dx%d",
slouken@1914
   761
                    event->window.windowID, event->window.data1,
slouken@1914
   762
                    event->window.data2);
slouken@1914
   763
            break;
slouken@1914
   764
        case SDL_WINDOWEVENT_MINIMIZED:
slouken@1914
   765
            fprintf(stderr, "Window %d minimized", event->window.windowID);
slouken@1914
   766
            break;
slouken@1914
   767
        case SDL_WINDOWEVENT_MAXIMIZED:
slouken@1914
   768
            fprintf(stderr, "Window %d maximized", event->window.windowID);
slouken@1914
   769
            break;
slouken@1914
   770
        case SDL_WINDOWEVENT_RESTORED:
slouken@1914
   771
            fprintf(stderr, "Window %d restored", event->window.windowID);
slouken@1914
   772
            break;
slouken@1914
   773
        case SDL_WINDOWEVENT_ENTER:
slouken@1914
   774
            fprintf(stderr, "Mouse entered window %d",
slouken@1914
   775
                    event->window.windowID);
slouken@1914
   776
            break;
slouken@1914
   777
        case SDL_WINDOWEVENT_LEAVE:
slouken@1914
   778
            fprintf(stderr, "Mouse left window %d", event->window.windowID);
slouken@1914
   779
            break;
slouken@1914
   780
        case SDL_WINDOWEVENT_FOCUS_GAINED:
slouken@1914
   781
            fprintf(stderr, "Window %d gained keyboard focus",
slouken@1914
   782
                    event->window.windowID);
slouken@1914
   783
            break;
slouken@1914
   784
        case SDL_WINDOWEVENT_FOCUS_LOST:
slouken@1914
   785
            fprintf(stderr, "Window %d lost keyboard focus",
slouken@1914
   786
                    event->window.windowID);
slouken@1914
   787
            break;
slouken@1933
   788
        case SDL_WINDOWEVENT_CLOSE:
slouken@1933
   789
            fprintf(stderr, "Window %d closed", event->window.windowID);
slouken@1933
   790
            break;
slouken@1914
   791
        default:
slouken@1914
   792
            fprintf(stderr, "Window %d got unknown event %d",
slouken@1914
   793
                    event->window.windowID, event->window.event);
slouken@1914
   794
            break;
slouken@1914
   795
        }
slouken@1914
   796
        break;
slouken@1914
   797
    case SDL_KEYDOWN:
slouken@1914
   798
        fprintf(stderr, "Keyboard %d: key %s pressed in window %d",
slouken@1914
   799
                event->key.which, SDL_GetKeyName(event->key.keysym.sym),
slouken@1914
   800
                event->key.windowID);
slouken@1914
   801
        break;
slouken@1914
   802
    case SDL_KEYUP:
slouken@1914
   803
        fprintf(stderr, "Keyboard %d: key %s released in window %d",
slouken@1914
   804
                event->key.which, SDL_GetKeyName(event->key.keysym.sym),
slouken@1914
   805
                event->key.windowID);
slouken@1914
   806
        break;
slouken@1914
   807
    case SDL_TEXTINPUT:
slouken@1914
   808
        fprintf(stderr, "Keyboard %d: text input \"%s\" in window %d",
slouken@1914
   809
                event->text.which, event->text.text, event->text.windowID);
slouken@1914
   810
        break;
slouken@1914
   811
    case SDL_MOUSEMOTION:
slouken@1914
   812
        fprintf(stderr, "Mouse %d: moved to %d,%d (%d,%d) in window %d",
slouken@1914
   813
                event->motion.which, event->motion.x, event->motion.y,
slouken@1914
   814
                event->motion.xrel, event->motion.yrel,
slouken@1914
   815
                event->motion.windowID);
slouken@1914
   816
        break;
slouken@1914
   817
    case SDL_MOUSEBUTTONDOWN:
slouken@1914
   818
        fprintf(stderr, "Mouse %d: button %d pressed at %d,%d in window %d",
slouken@1914
   819
                event->button.which, event->button.button, event->button.x,
slouken@1914
   820
                event->button.y, event->button.windowID);
slouken@1914
   821
        break;
slouken@1914
   822
    case SDL_MOUSEBUTTONUP:
slouken@1914
   823
        fprintf(stderr, "Mouse %d: button %d released at %d,%d in window %d",
slouken@1914
   824
                event->button.which, event->button.button, event->button.x,
slouken@1914
   825
                event->button.y, event->button.windowID);
slouken@1914
   826
        break;
slouken@1914
   827
    case SDL_MOUSEWHEEL:
slouken@1914
   828
        fprintf(stderr, "Mouse %d: wheel scrolled %d in window %d",
slouken@1914
   829
                event->wheel.which, event->wheel.motion,
slouken@1957
   830
                event->wheel.windowID);
slouken@1914
   831
        break;
slouken@1914
   832
    case SDL_JOYBALLMOTION:
slouken@1914
   833
        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
slouken@1914
   834
                event->jball.which, event->jball.ball, event->jball.xrel,
slouken@1914
   835
                event->jball.yrel);
slouken@1914
   836
        break;
slouken@1914
   837
    case SDL_JOYHATMOTION:
slouken@1914
   838
        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
slouken@1914
   839
                event->jhat.hat);
slouken@1914
   840
        switch (event->jhat.value) {
slouken@1914
   841
        case SDL_HAT_CENTERED:
slouken@1914
   842
            fprintf(stderr, "CENTER");
slouken@1914
   843
            break;
slouken@1914
   844
        case SDL_HAT_UP:
slouken@1914
   845
            fprintf(stderr, "UP");
slouken@1914
   846
            break;
slouken@1914
   847
        case SDL_HAT_RIGHTUP:
slouken@1914
   848
            fprintf(stderr, "RIGHTUP");
slouken@1914
   849
            break;
slouken@1914
   850
        case SDL_HAT_RIGHT:
slouken@1914
   851
            fprintf(stderr, "RIGHT");
slouken@1914
   852
            break;
slouken@1914
   853
        case SDL_HAT_RIGHTDOWN:
slouken@1914
   854
            fprintf(stderr, "RIGHTDOWN");
slouken@1914
   855
            break;
slouken@1914
   856
        case SDL_HAT_DOWN:
slouken@1914
   857
            fprintf(stderr, "DOWN");
slouken@1914
   858
            break;
slouken@1914
   859
        case SDL_HAT_LEFTDOWN:
slouken@1914
   860
            fprintf(stderr, "LEFTDOWN");
slouken@1914
   861
            break;
slouken@1914
   862
        case SDL_HAT_LEFT:
slouken@1914
   863
            fprintf(stderr, "LEFT");
slouken@1914
   864
            break;
slouken@1914
   865
        case SDL_HAT_LEFTUP:
slouken@1914
   866
            fprintf(stderr, "LEFTUP");
slouken@1914
   867
            break;
slouken@1914
   868
        default:
slouken@1914
   869
            fprintf(stderr, "UNKNOWN");
slouken@1914
   870
            break;
slouken@1914
   871
        }
slouken@1914
   872
        break;
slouken@1914
   873
    case SDL_JOYBUTTONDOWN:
slouken@1914
   874
        fprintf(stderr, "Joystick %d: button %d pressed",
slouken@1914
   875
                event->jbutton.which, event->jbutton.button);
slouken@1914
   876
        break;
slouken@1914
   877
    case SDL_JOYBUTTONUP:
slouken@1914
   878
        fprintf(stderr, "Joystick %d: button %d released",
slouken@1914
   879
                event->jbutton.which, event->jbutton.button);
slouken@1914
   880
        break;
slouken@1914
   881
    case SDL_QUIT:
slouken@1914
   882
        fprintf(stderr, "Quit requested");
slouken@1914
   883
        break;
slouken@1914
   884
    case SDL_USEREVENT:
slouken@1914
   885
        fprintf(stderr, "User event %d", event->user.code);
slouken@1914
   886
        break;
slouken@1914
   887
    default:
slouken@1914
   888
        fprintf(stderr, "Unknown event %d", event->type);
slouken@1914
   889
        break;
slouken@1914
   890
    }
slouken@1914
   891
    fprintf(stderr, "\n");
slouken@1914
   892
}
slouken@1914
   893
slouken@1914
   894
void
slouken@1914
   895
CommonEvent(CommonState * state, SDL_Event * event, int *done)
slouken@1914
   896
{
slouken@1914
   897
    if (state->verbose & VERBOSE_EVENT) {
slouken@1914
   898
        PrintEvent(event);
slouken@1914
   899
    }
slouken@1914
   900
slouken@1914
   901
    switch (event->type) {
slouken@1914
   902
    case SDL_WINDOWEVENT:
slouken@1914
   903
        switch (event->window.event) {
slouken@1914
   904
        case SDL_WINDOWEVENT_CLOSE:
slouken@1914
   905
            *done = 1;
slouken@1914
   906
            break;
slouken@1914
   907
        }
slouken@1914
   908
        break;
slouken@1914
   909
    case SDL_KEYDOWN:
slouken@1914
   910
        switch (event->key.keysym.sym) {
slouken@1914
   911
            /* Add hotkeys here */
slouken@1965
   912
        case SDLK_g:
slouken@1965
   913
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@1965
   914
                /* Ctrl-G toggle grab */
slouken@1965
   915
            }
slouken@1965
   916
            break;
slouken@1914
   917
        case SDLK_ESCAPE:
slouken@1914
   918
            *done = 1;
slouken@1914
   919
            break;
slouken@1914
   920
        default:
slouken@1914
   921
            break;
slouken@1914
   922
        }
slouken@1914
   923
        break;
slouken@1914
   924
    case SDL_QUIT:
slouken@1914
   925
        *done = 1;
slouken@1914
   926
        break;
slouken@1914
   927
    }
slouken@1914
   928
}
slouken@1914
   929
slouken@1914
   930
void
slouken@1914
   931
CommonQuit(CommonState * state)
slouken@1914
   932
{
slouken@1914
   933
    if (state->flags & SDL_INIT_VIDEO) {
slouken@1914
   934
        SDL_VideoQuit();
slouken@1914
   935
    }
slouken@1914
   936
    if (state->flags & SDL_INIT_AUDIO) {
slouken@1914
   937
        SDL_AudioQuit();
slouken@1914
   938
    }
slouken@1914
   939
    if (state->windows) {
slouken@1914
   940
        SDL_free(state->windows);
slouken@1914
   941
    }
slouken@1914
   942
    SDL_free(state);
slouken@1914
   943
}