test/common.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 20 Dec 2008 12:00:00 +0000
changeset 2884 9dde605c7540
parent 2306 1a8bab15a45d
child 3184 68d3b48a6002
permissions -rw-r--r--
Date: Fri, 19 Dec 2008 20:17:35 +0100
From: Couriersud
Subject: Re: Aw: Experience using SDL1.3 in sdlmame/Proposal for api additions

> For consistency you'd probably want:
> SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
> SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode);
> SDL_RenderLine(int x1, int y1, int x2, int y2);
> SDL_RenderFill(SDL_Rect *rect);
>
> You probably also want to add API functions query the current state.
>

I have implemented the above api for the opengl, x11, directfb and
software renderers. I have also renamed *TEXTUREBLENDMODE* constants to
BLENDMODE*. The unix build compiles. The windows renderer still needs to
be updated, but I have no windows development machine at hand. Have a
look at the x11 renderer for a sample.

Vector games now run at 90% both on opengl and directfb in comparison to
sdlmame's own opengl renderer. The same applies to raster games.

The diff also includes

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