src/test/SDL_test_common.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 31 Jan 2017 10:19:56 -0800
changeset 10866 ed2b5c68379d
parent 10737 3406a0f8b041
child 10874 694f263fed30
permissions -rw-r--r--
Switch stderr output to SDL_Log() so it shows up on Windows and mobile devices
aschiffler@6727
     1
/*
aschiffler@6727
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
aschiffler@6727
     4
aschiffler@6727
     5
  This software is provided 'as-is', without any express or implied
aschiffler@6727
     6
  warranty.  In no event will the authors be held liable for any damages
aschiffler@6727
     7
  arising from the use of this software.
aschiffler@6727
     8
aschiffler@6727
     9
  Permission is granted to anyone to use this software for any purpose,
aschiffler@6727
    10
  including commercial applications, and to alter it and redistribute it
aschiffler@6727
    11
  freely, subject to the following restrictions:
aschiffler@6727
    12
aschiffler@6727
    13
  1. The origin of this software must not be misrepresented; you must not
aschiffler@6727
    14
     claim that you wrote the original software. If you use this software
aschiffler@6727
    15
     in a product, an acknowledgment in the product documentation would be
aschiffler@6727
    16
     appreciated but is not required.
aschiffler@6727
    17
  2. Altered source versions must be plainly marked as such, and must not be
aschiffler@6727
    18
     misrepresented as being the original software.
aschiffler@6727
    19
  3. This notice may not be removed or altered from any source distribution.
aschiffler@6727
    20
*/
aschiffler@6727
    21
aschiffler@6727
    22
/* Ported from original test\common.c file. */
aschiffler@6727
    23
aschiffler@6727
    24
#include "SDL_config.h"
aschiffler@6727
    25
#include "SDL_test.h"
aschiffler@6727
    26
aschiffler@6727
    27
#include <stdio.h>
aschiffler@6727
    28
aschiffler@6727
    29
#define VIDEO_USAGE \
icculus@7895
    30
"[--video driver] [--renderer driver] [--gldebug] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--min-geometry WxH] [--max-geometry WxH] [--logical WxH] [--scale N] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--allow-highdpi]"
aschiffler@6727
    31
aschiffler@6727
    32
#define AUDIO_USAGE \
aschiffler@6727
    33
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
aschiffler@6727
    34
aschiffler@6727
    35
SDLTest_CommonState *
aschiffler@6727
    36
SDLTest_CommonCreateState(char **argv, Uint32 flags)
aschiffler@6727
    37
{
aschiffler@6727
    38
    SDLTest_CommonState *state = (SDLTest_CommonState *)SDL_calloc(1, sizeof(*state));
aschiffler@6727
    39
    if (!state) {
aschiffler@6727
    40
        SDL_OutOfMemory();
aschiffler@6727
    41
        return NULL;
aschiffler@6727
    42
    }
aschiffler@6727
    43
aschiffler@6727
    44
    /* Initialize some defaults */
aschiffler@6727
    45
    state->argv = argv;
aschiffler@6727
    46
    state->flags = flags;
aschiffler@6727
    47
    state->window_title = argv[0];
aschiffler@6727
    48
    state->window_flags = 0;
aschiffler@6727
    49
    state->window_x = SDL_WINDOWPOS_UNDEFINED;
aschiffler@6727
    50
    state->window_y = SDL_WINDOWPOS_UNDEFINED;
aschiffler@6727
    51
    state->window_w = DEFAULT_WINDOW_WIDTH;
aschiffler@6727
    52
    state->window_h = DEFAULT_WINDOW_HEIGHT;
aschiffler@6727
    53
    state->num_windows = 1;
aschiffler@6727
    54
    state->audiospec.freq = 22050;
aschiffler@6727
    55
    state->audiospec.format = AUDIO_S16;
aschiffler@6727
    56
    state->audiospec.channels = 2;
aschiffler@6727
    57
    state->audiospec.samples = 2048;
aschiffler@6727
    58
aschiffler@6727
    59
    /* Set some very sane GL defaults */
aschiffler@6727
    60
    state->gl_red_size = 3;
aschiffler@6727
    61
    state->gl_green_size = 3;
aschiffler@6727
    62
    state->gl_blue_size = 2;
aschiffler@6727
    63
    state->gl_alpha_size = 0;
aschiffler@6727
    64
    state->gl_buffer_size = 0;
aschiffler@6727
    65
    state->gl_depth_size = 16;
aschiffler@6727
    66
    state->gl_stencil_size = 0;
aschiffler@6727
    67
    state->gl_double_buffer = 1;
aschiffler@6727
    68
    state->gl_accum_red_size = 0;
aschiffler@6727
    69
    state->gl_accum_green_size = 0;
aschiffler@6727
    70
    state->gl_accum_blue_size = 0;
aschiffler@6727
    71
    state->gl_accum_alpha_size = 0;
aschiffler@6727
    72
    state->gl_stereo = 0;
aschiffler@6727
    73
    state->gl_multisamplebuffers = 0;
aschiffler@6727
    74
    state->gl_multisamplesamples = 0;
aschiffler@6727
    75
    state->gl_retained_backing = 1;
aschiffler@6727
    76
    state->gl_accelerated = -1;
slouken@7194
    77
    state->gl_debug = 0;
aschiffler@6727
    78
aschiffler@6727
    79
    return state;
aschiffler@6727
    80
}
aschiffler@6727
    81
aschiffler@6727
    82
int
aschiffler@6727
    83
SDLTest_CommonArg(SDLTest_CommonState * state, int index)
aschiffler@6727
    84
{
aschiffler@6727
    85
    char **argv = state->argv;
aschiffler@6727
    86
aschiffler@6727
    87
    if (SDL_strcasecmp(argv[index], "--video") == 0) {
aschiffler@6727
    88
        ++index;
aschiffler@6727
    89
        if (!argv[index]) {
aschiffler@6727
    90
            return -1;
aschiffler@6727
    91
        }
aschiffler@6727
    92
        state->videodriver = argv[index];
aschiffler@6727
    93
        return 2;
aschiffler@6727
    94
    }
aschiffler@6727
    95
    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
aschiffler@6727
    96
        ++index;
aschiffler@6727
    97
        if (!argv[index]) {
aschiffler@6727
    98
            return -1;
aschiffler@6727
    99
        }
aschiffler@6727
   100
        state->renderdriver = argv[index];
aschiffler@6727
   101
        return 2;
aschiffler@6727
   102
    }
slouken@7194
   103
    if (SDL_strcasecmp(argv[index], "--gldebug") == 0) {
slouken@7194
   104
        state->gl_debug = 1;
slouken@7194
   105
        return 1;
slouken@7194
   106
    }
aschiffler@6727
   107
    if (SDL_strcasecmp(argv[index], "--info") == 0) {
aschiffler@6727
   108
        ++index;
aschiffler@6727
   109
        if (!argv[index]) {
aschiffler@6727
   110
            return -1;
aschiffler@6727
   111
        }
aschiffler@6727
   112
        if (SDL_strcasecmp(argv[index], "all") == 0) {
aschiffler@6727
   113
            state->verbose |=
aschiffler@6727
   114
                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
aschiffler@6727
   115
                 VERBOSE_EVENT);
aschiffler@6727
   116
            return 2;
aschiffler@6727
   117
        }
aschiffler@6727
   118
        if (SDL_strcasecmp(argv[index], "video") == 0) {
aschiffler@6727
   119
            state->verbose |= VERBOSE_VIDEO;
aschiffler@6727
   120
            return 2;
aschiffler@6727
   121
        }
aschiffler@6727
   122
        if (SDL_strcasecmp(argv[index], "modes") == 0) {
aschiffler@6727
   123
            state->verbose |= VERBOSE_MODES;
aschiffler@6727
   124
            return 2;
aschiffler@6727
   125
        }
aschiffler@6727
   126
        if (SDL_strcasecmp(argv[index], "render") == 0) {
aschiffler@6727
   127
            state->verbose |= VERBOSE_RENDER;
aschiffler@6727
   128
            return 2;
aschiffler@6727
   129
        }
aschiffler@6727
   130
        if (SDL_strcasecmp(argv[index], "event") == 0) {
aschiffler@6727
   131
            state->verbose |= VERBOSE_EVENT;
aschiffler@6727
   132
            return 2;
aschiffler@6727
   133
        }
aschiffler@6727
   134
        return -1;
aschiffler@6727
   135
    }
aschiffler@6727
   136
    if (SDL_strcasecmp(argv[index], "--log") == 0) {
aschiffler@6727
   137
        ++index;
aschiffler@6727
   138
        if (!argv[index]) {
aschiffler@6727
   139
            return -1;
aschiffler@6727
   140
        }
aschiffler@6727
   141
        if (SDL_strcasecmp(argv[index], "all") == 0) {
aschiffler@6727
   142
            SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
aschiffler@6727
   143
            return 2;
aschiffler@6727
   144
        }
aschiffler@6727
   145
        if (SDL_strcasecmp(argv[index], "error") == 0) {
aschiffler@6727
   146
            SDL_LogSetPriority(SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_VERBOSE);
aschiffler@6727
   147
            return 2;
aschiffler@6727
   148
        }
aschiffler@6727
   149
        if (SDL_strcasecmp(argv[index], "system") == 0) {
aschiffler@6727
   150
            SDL_LogSetPriority(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE);
aschiffler@6727
   151
            return 2;
aschiffler@6727
   152
        }
aschiffler@6727
   153
        if (SDL_strcasecmp(argv[index], "audio") == 0) {
aschiffler@6727
   154
            SDL_LogSetPriority(SDL_LOG_CATEGORY_AUDIO, SDL_LOG_PRIORITY_VERBOSE);
aschiffler@6727
   155
            return 2;
aschiffler@6727
   156
        }
aschiffler@6727
   157
        if (SDL_strcasecmp(argv[index], "video") == 0) {
aschiffler@6727
   158
            SDL_LogSetPriority(SDL_LOG_CATEGORY_VIDEO, SDL_LOG_PRIORITY_VERBOSE);
aschiffler@6727
   159
            return 2;
aschiffler@6727
   160
        }
aschiffler@6727
   161
        if (SDL_strcasecmp(argv[index], "render") == 0) {
aschiffler@6727
   162
            SDL_LogSetPriority(SDL_LOG_CATEGORY_RENDER, SDL_LOG_PRIORITY_VERBOSE);
aschiffler@6727
   163
            return 2;
aschiffler@6727
   164
        }
aschiffler@6727
   165
        if (SDL_strcasecmp(argv[index], "input") == 0) {
aschiffler@6727
   166
            SDL_LogSetPriority(SDL_LOG_CATEGORY_INPUT, SDL_LOG_PRIORITY_VERBOSE);
aschiffler@6727
   167
            return 2;
aschiffler@6727
   168
        }
aschiffler@6727
   169
        return -1;
aschiffler@6727
   170
    }
aschiffler@6727
   171
    if (SDL_strcasecmp(argv[index], "--display") == 0) {
aschiffler@6727
   172
        ++index;
aschiffler@6727
   173
        if (!argv[index]) {
aschiffler@6727
   174
            return -1;
aschiffler@6727
   175
        }
aschiffler@6727
   176
        state->display = SDL_atoi(argv[index]);
aschiffler@6727
   177
        if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
aschiffler@6727
   178
            state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
aschiffler@6727
   179
            state->window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
aschiffler@6727
   180
        }
aschiffler@6727
   181
        if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) {
aschiffler@6727
   182
            state->window_x = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
aschiffler@6727
   183
            state->window_y = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
aschiffler@6727
   184
        }
aschiffler@6727
   185
        return 2;
aschiffler@6727
   186
    }
aschiffler@6727
   187
    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
aschiffler@6727
   188
        state->window_flags |= SDL_WINDOW_FULLSCREEN;
aschiffler@6727
   189
        state->num_windows = 1;
aschiffler@6727
   190
        return 1;
aschiffler@6727
   191
    }
slouken@6783
   192
    if (SDL_strcasecmp(argv[index], "--fullscreen-desktop") == 0) {
slouken@6783
   193
        state->window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
slouken@6783
   194
        state->num_windows = 1;
slouken@6783
   195
        return 1;
slouken@6783
   196
    }
urkle@7746
   197
    if (SDL_strcasecmp(argv[index], "--allow-highdpi") == 0) {
urkle@7746
   198
        state->window_flags |= SDL_WINDOW_ALLOW_HIGHDPI;
urkle@7746
   199
        return 1;
urkle@7746
   200
    }
aschiffler@6727
   201
    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
aschiffler@6727
   202
        ++index;
aschiffler@6727
   203
        if (!argv[index] || !SDL_isdigit(*argv[index])) {
aschiffler@6727
   204
            return -1;
aschiffler@6727
   205
        }
aschiffler@6727
   206
        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
aschiffler@6727
   207
            state->num_windows = SDL_atoi(argv[index]);
aschiffler@6727
   208
        }
aschiffler@6727
   209
        return 2;
aschiffler@6727
   210
    }
aschiffler@6727
   211
    if (SDL_strcasecmp(argv[index], "--title") == 0) {
aschiffler@6727
   212
        ++index;
aschiffler@6727
   213
        if (!argv[index]) {
aschiffler@6727
   214
            return -1;
aschiffler@6727
   215
        }
aschiffler@6727
   216
        state->window_title = argv[index];
aschiffler@6727
   217
        return 2;
aschiffler@6727
   218
    }
aschiffler@6727
   219
    if (SDL_strcasecmp(argv[index], "--icon") == 0) {
aschiffler@6727
   220
        ++index;
aschiffler@6727
   221
        if (!argv[index]) {
aschiffler@6727
   222
            return -1;
aschiffler@6727
   223
        }
aschiffler@6727
   224
        state->window_icon = argv[index];
aschiffler@6727
   225
        return 2;
aschiffler@6727
   226
    }
aschiffler@6727
   227
    if (SDL_strcasecmp(argv[index], "--center") == 0) {
aschiffler@6727
   228
        state->window_x = SDL_WINDOWPOS_CENTERED;
aschiffler@6727
   229
        state->window_y = SDL_WINDOWPOS_CENTERED;
aschiffler@6727
   230
        return 1;
aschiffler@6727
   231
    }
aschiffler@6727
   232
    if (SDL_strcasecmp(argv[index], "--position") == 0) {
aschiffler@6727
   233
        char *x, *y;
aschiffler@6727
   234
        ++index;
aschiffler@6727
   235
        if (!argv[index]) {
aschiffler@6727
   236
            return -1;
aschiffler@6727
   237
        }
aschiffler@6727
   238
        x = argv[index];
aschiffler@6727
   239
        y = argv[index];
aschiffler@6727
   240
        while (*y && *y != ',') {
aschiffler@6727
   241
            ++y;
aschiffler@6727
   242
        }
aschiffler@6727
   243
        if (!*y) {
aschiffler@6727
   244
            return -1;
aschiffler@6727
   245
        }
aschiffler@6727
   246
        *y++ = '\0';
aschiffler@6727
   247
        state->window_x = SDL_atoi(x);
aschiffler@6727
   248
        state->window_y = SDL_atoi(y);
aschiffler@6727
   249
        return 2;
aschiffler@6727
   250
    }
aschiffler@6727
   251
    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
aschiffler@6727
   252
        char *w, *h;
aschiffler@6727
   253
        ++index;
aschiffler@6727
   254
        if (!argv[index]) {
aschiffler@6727
   255
            return -1;
aschiffler@6727
   256
        }
aschiffler@6727
   257
        w = argv[index];
aschiffler@6727
   258
        h = argv[index];
aschiffler@6727
   259
        while (*h && *h != 'x') {
aschiffler@6727
   260
            ++h;
aschiffler@6727
   261
        }
aschiffler@6727
   262
        if (!*h) {
aschiffler@6727
   263
            return -1;
aschiffler@6727
   264
        }
aschiffler@6727
   265
        *h++ = '\0';
aschiffler@6727
   266
        state->window_w = SDL_atoi(w);
aschiffler@6727
   267
        state->window_h = SDL_atoi(h);
aschiffler@6727
   268
        return 2;
aschiffler@6727
   269
    }
slouken@6788
   270
    if (SDL_strcasecmp(argv[index], "--min-geometry") == 0) {
slouken@6788
   271
        char *w, *h;
slouken@6788
   272
        ++index;
slouken@6788
   273
        if (!argv[index]) {
slouken@6788
   274
            return -1;
slouken@6788
   275
        }
slouken@6788
   276
        w = argv[index];
slouken@6788
   277
        h = argv[index];
slouken@6788
   278
        while (*h && *h != 'x') {
slouken@6788
   279
            ++h;
slouken@6788
   280
        }
slouken@6788
   281
        if (!*h) {
slouken@6788
   282
            return -1;
slouken@6788
   283
        }
slouken@6788
   284
        *h++ = '\0';
slouken@6788
   285
        state->window_minW = SDL_atoi(w);
slouken@6788
   286
        state->window_minH = SDL_atoi(h);
slouken@6788
   287
        return 2;
slouken@6788
   288
    }
slouken@6788
   289
    if (SDL_strcasecmp(argv[index], "--max-geometry") == 0) {
slouken@6788
   290
        char *w, *h;
slouken@6788
   291
        ++index;
slouken@6788
   292
        if (!argv[index]) {
slouken@6788
   293
            return -1;
slouken@6788
   294
        }
slouken@6788
   295
        w = argv[index];
slouken@6788
   296
        h = argv[index];
slouken@6788
   297
        while (*h && *h != 'x') {
slouken@6788
   298
            ++h;
slouken@6788
   299
        }
slouken@6788
   300
        if (!*h) {
slouken@6788
   301
            return -1;
slouken@6788
   302
        }
slouken@6788
   303
        *h++ = '\0';
slouken@6788
   304
        state->window_maxW = SDL_atoi(w);
slouken@6788
   305
        state->window_maxH = SDL_atoi(h);
slouken@6788
   306
        return 2;
slouken@6788
   307
    }
slouken@7240
   308
    if (SDL_strcasecmp(argv[index], "--logical") == 0) {
slouken@7240
   309
        char *w, *h;
slouken@7240
   310
        ++index;
slouken@7240
   311
        if (!argv[index]) {
slouken@7240
   312
            return -1;
slouken@7240
   313
        }
slouken@7240
   314
        w = argv[index];
slouken@7240
   315
        h = argv[index];
slouken@7240
   316
        while (*h && *h != 'x') {
slouken@7240
   317
            ++h;
slouken@7240
   318
        }
slouken@7240
   319
        if (!*h) {
slouken@7240
   320
            return -1;
slouken@7240
   321
        }
slouken@7240
   322
        *h++ = '\0';
slouken@7240
   323
        state->logical_w = SDL_atoi(w);
slouken@7240
   324
        state->logical_h = SDL_atoi(h);
slouken@7240
   325
        return 2;
slouken@7240
   326
    }
slouken@7240
   327
    if (SDL_strcasecmp(argv[index], "--scale") == 0) {
slouken@7240
   328
        ++index;
slouken@7240
   329
        if (!argv[index]) {
slouken@7240
   330
            return -1;
slouken@7240
   331
        }
aschiffler@7249
   332
        state->scale = (float)SDL_atof(argv[index]);
slouken@7240
   333
        return 2;
slouken@7240
   334
    }
aschiffler@6727
   335
    if (SDL_strcasecmp(argv[index], "--depth") == 0) {
aschiffler@6727
   336
        ++index;
aschiffler@6727
   337
        if (!argv[index]) {
aschiffler@6727
   338
            return -1;
aschiffler@6727
   339
        }
aschiffler@6727
   340
        state->depth = SDL_atoi(argv[index]);
aschiffler@6727
   341
        return 2;
aschiffler@6727
   342
    }
aschiffler@6727
   343
    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
aschiffler@6727
   344
        ++index;
aschiffler@6727
   345
        if (!argv[index]) {
aschiffler@6727
   346
            return -1;
aschiffler@6727
   347
        }
aschiffler@6727
   348
        state->refresh_rate = SDL_atoi(argv[index]);
aschiffler@6727
   349
        return 2;
aschiffler@6727
   350
    }
aschiffler@6727
   351
    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
aschiffler@6727
   352
        state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
aschiffler@6727
   353
        return 1;
aschiffler@6727
   354
    }
aschiffler@6727
   355
    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
aschiffler@6727
   356
        state->window_flags |= SDL_WINDOW_BORDERLESS;
aschiffler@6727
   357
        return 1;
aschiffler@6727
   358
    }
aschiffler@6727
   359
    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
aschiffler@6727
   360
        state->window_flags |= SDL_WINDOW_RESIZABLE;
aschiffler@6727
   361
        return 1;
aschiffler@6727
   362
    }
aschiffler@6727
   363
    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
aschiffler@6727
   364
        state->window_flags |= SDL_WINDOW_MINIMIZED;
aschiffler@6727
   365
        return 1;
aschiffler@6727
   366
    }
aschiffler@6727
   367
    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
aschiffler@6727
   368
        state->window_flags |= SDL_WINDOW_MAXIMIZED;
aschiffler@6727
   369
        return 1;
aschiffler@6727
   370
    }
aschiffler@6727
   371
    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
aschiffler@6727
   372
        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
aschiffler@6727
   373
        return 1;
aschiffler@6727
   374
    }
aschiffler@6727
   375
    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
aschiffler@6727
   376
        ++index;
aschiffler@6727
   377
        if (!argv[index]) {
aschiffler@6727
   378
            return -1;
aschiffler@6727
   379
        }
aschiffler@6727
   380
        state->audiospec.freq = SDL_atoi(argv[index]);
aschiffler@6727
   381
        return 2;
aschiffler@6727
   382
    }
aschiffler@6727
   383
    if (SDL_strcasecmp(argv[index], "--format") == 0) {
aschiffler@6727
   384
        ++index;
aschiffler@6727
   385
        if (!argv[index]) {
aschiffler@6727
   386
            return -1;
aschiffler@6727
   387
        }
aschiffler@6727
   388
        if (SDL_strcasecmp(argv[index], "U8") == 0) {
aschiffler@6727
   389
            state->audiospec.format = AUDIO_U8;
aschiffler@6727
   390
            return 2;
aschiffler@6727
   391
        }
aschiffler@6727
   392
        if (SDL_strcasecmp(argv[index], "S8") == 0) {
aschiffler@6727
   393
            state->audiospec.format = AUDIO_S8;
aschiffler@6727
   394
            return 2;
aschiffler@6727
   395
        }
aschiffler@6727
   396
        if (SDL_strcasecmp(argv[index], "U16") == 0) {
aschiffler@6727
   397
            state->audiospec.format = AUDIO_U16;
aschiffler@6727
   398
            return 2;
aschiffler@6727
   399
        }
aschiffler@6727
   400
        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
aschiffler@6727
   401
            state->audiospec.format = AUDIO_U16LSB;
aschiffler@6727
   402
            return 2;
aschiffler@6727
   403
        }
aschiffler@6727
   404
        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
aschiffler@6727
   405
            state->audiospec.format = AUDIO_U16MSB;
aschiffler@6727
   406
            return 2;
aschiffler@6727
   407
        }
aschiffler@6727
   408
        if (SDL_strcasecmp(argv[index], "S16") == 0) {
aschiffler@6727
   409
            state->audiospec.format = AUDIO_S16;
aschiffler@6727
   410
            return 2;
aschiffler@6727
   411
        }
aschiffler@6727
   412
        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
aschiffler@6727
   413
            state->audiospec.format = AUDIO_S16LSB;
aschiffler@6727
   414
            return 2;
aschiffler@6727
   415
        }
aschiffler@6727
   416
        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
aschiffler@6727
   417
            state->audiospec.format = AUDIO_S16MSB;
aschiffler@6727
   418
            return 2;
aschiffler@6727
   419
        }
aschiffler@6727
   420
        return -1;
aschiffler@6727
   421
    }
aschiffler@6727
   422
    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
aschiffler@6727
   423
        ++index;
aschiffler@6727
   424
        if (!argv[index]) {
aschiffler@6727
   425
            return -1;
aschiffler@6727
   426
        }
aschiffler@6727
   427
        state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
aschiffler@6727
   428
        return 2;
aschiffler@6727
   429
    }
aschiffler@6727
   430
    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
aschiffler@6727
   431
        ++index;
aschiffler@6727
   432
        if (!argv[index]) {
aschiffler@6727
   433
            return -1;
aschiffler@6727
   434
        }
aschiffler@6727
   435
        state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
aschiffler@6727
   436
        return 2;
aschiffler@6727
   437
    }
aschiffler@6727
   438
    if ((SDL_strcasecmp(argv[index], "-h") == 0)
aschiffler@6727
   439
        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
aschiffler@6727
   440
        /* Print the usage message */
aschiffler@6727
   441
        return -1;
aschiffler@6727
   442
    }
aschiffler@6727
   443
    if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) {
slouken@7191
   444
    /* Debug flag sent by Xcode */
aschiffler@6727
   445
        return 2;
aschiffler@6727
   446
    }
aschiffler@6727
   447
    return 0;
aschiffler@6727
   448
}
aschiffler@6727
   449
aschiffler@6727
   450
const char *
aschiffler@6727
   451
SDLTest_CommonUsage(SDLTest_CommonState * state)
aschiffler@6727
   452
{
aschiffler@6727
   453
    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
aschiffler@6727
   454
    case SDL_INIT_VIDEO:
aschiffler@6727
   455
        return VIDEO_USAGE;
aschiffler@6727
   456
    case SDL_INIT_AUDIO:
aschiffler@6727
   457
        return AUDIO_USAGE;
aschiffler@6727
   458
    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
aschiffler@6727
   459
        return VIDEO_USAGE " " AUDIO_USAGE;
aschiffler@6727
   460
    default:
aschiffler@6727
   461
        return "";
aschiffler@6727
   462
    }
aschiffler@6727
   463
}
aschiffler@6727
   464
aschiffler@6727
   465
static void
aschiffler@6727
   466
SDLTest_PrintRendererFlag(Uint32 flag)
aschiffler@6727
   467
{
aschiffler@6727
   468
    switch (flag) {
aschiffler@6727
   469
    case SDL_RENDERER_PRESENTVSYNC:
slouken@10866
   470
        SDL_Log("PresentVSync");
aschiffler@6727
   471
        break;
aschiffler@6727
   472
    case SDL_RENDERER_ACCELERATED:
slouken@10866
   473
        SDL_Log("Accelerated");
aschiffler@6727
   474
        break;
aschiffler@6727
   475
    default:
slouken@10866
   476
        SDL_Log("0x%8.8x", flag);
aschiffler@6727
   477
        break;
aschiffler@6727
   478
    }
aschiffler@6727
   479
}
aschiffler@6727
   480
aschiffler@6727
   481
static void
aschiffler@6727
   482
SDLTest_PrintPixelFormat(Uint32 format)
aschiffler@6727
   483
{
aschiffler@6727
   484
    switch (format) {
aschiffler@6727
   485
    case SDL_PIXELFORMAT_UNKNOWN:
slouken@10866
   486
        SDL_Log("Unknwon");
aschiffler@6727
   487
        break;
aschiffler@6727
   488
    case SDL_PIXELFORMAT_INDEX1LSB:
slouken@10866
   489
        SDL_Log("Index1LSB");
aschiffler@6727
   490
        break;
aschiffler@6727
   491
    case SDL_PIXELFORMAT_INDEX1MSB:
slouken@10866
   492
        SDL_Log("Index1MSB");
aschiffler@6727
   493
        break;
aschiffler@6727
   494
    case SDL_PIXELFORMAT_INDEX4LSB:
slouken@10866
   495
        SDL_Log("Index4LSB");
aschiffler@6727
   496
        break;
aschiffler@6727
   497
    case SDL_PIXELFORMAT_INDEX4MSB:
slouken@10866
   498
        SDL_Log("Index4MSB");
aschiffler@6727
   499
        break;
aschiffler@6727
   500
    case SDL_PIXELFORMAT_INDEX8:
slouken@10866
   501
        SDL_Log("Index8");
aschiffler@6727
   502
        break;
aschiffler@6727
   503
    case SDL_PIXELFORMAT_RGB332:
slouken@10866
   504
        SDL_Log("RGB332");
aschiffler@6727
   505
        break;
aschiffler@6727
   506
    case SDL_PIXELFORMAT_RGB444:
slouken@10866
   507
        SDL_Log("RGB444");
aschiffler@6727
   508
        break;
aschiffler@6727
   509
    case SDL_PIXELFORMAT_RGB555:
slouken@10866
   510
        SDL_Log("RGB555");
aschiffler@6727
   511
        break;
aschiffler@6727
   512
    case SDL_PIXELFORMAT_BGR555:
slouken@10866
   513
        SDL_Log("BGR555");
aschiffler@6727
   514
        break;
aschiffler@6727
   515
    case SDL_PIXELFORMAT_ARGB4444:
slouken@10866
   516
        SDL_Log("ARGB4444");
aschiffler@6727
   517
        break;
aschiffler@6727
   518
    case SDL_PIXELFORMAT_ABGR4444:
slouken@10866
   519
        SDL_Log("ABGR4444");
aschiffler@6727
   520
        break;
aschiffler@6727
   521
    case SDL_PIXELFORMAT_ARGB1555:
slouken@10866
   522
        SDL_Log("ARGB1555");
aschiffler@6727
   523
        break;
aschiffler@6727
   524
    case SDL_PIXELFORMAT_ABGR1555:
slouken@10866
   525
        SDL_Log("ABGR1555");
aschiffler@6727
   526
        break;
aschiffler@6727
   527
    case SDL_PIXELFORMAT_RGB565:
slouken@10866
   528
        SDL_Log("RGB565");
aschiffler@6727
   529
        break;
aschiffler@6727
   530
    case SDL_PIXELFORMAT_BGR565:
slouken@10866
   531
        SDL_Log("BGR565");
aschiffler@6727
   532
        break;
aschiffler@6727
   533
    case SDL_PIXELFORMAT_RGB24:
slouken@10866
   534
        SDL_Log("RGB24");
aschiffler@6727
   535
        break;
aschiffler@6727
   536
    case SDL_PIXELFORMAT_BGR24:
slouken@10866
   537
        SDL_Log("BGR24");
aschiffler@6727
   538
        break;
aschiffler@6727
   539
    case SDL_PIXELFORMAT_RGB888:
slouken@10866
   540
        SDL_Log("RGB888");
aschiffler@6727
   541
        break;
aschiffler@6727
   542
    case SDL_PIXELFORMAT_BGR888:
slouken@10866
   543
        SDL_Log("BGR888");
aschiffler@6727
   544
        break;
aschiffler@6727
   545
    case SDL_PIXELFORMAT_ARGB8888:
slouken@10866
   546
        SDL_Log("ARGB8888");
aschiffler@6727
   547
        break;
aschiffler@6727
   548
    case SDL_PIXELFORMAT_RGBA8888:
slouken@10866
   549
        SDL_Log("RGBA8888");
aschiffler@6727
   550
        break;
aschiffler@6727
   551
    case SDL_PIXELFORMAT_ABGR8888:
slouken@10866
   552
        SDL_Log("ABGR8888");
aschiffler@6727
   553
        break;
aschiffler@6727
   554
    case SDL_PIXELFORMAT_BGRA8888:
slouken@10866
   555
        SDL_Log("BGRA8888");
aschiffler@6727
   556
        break;
aschiffler@6727
   557
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@10866
   558
        SDL_Log("ARGB2101010");
aschiffler@6727
   559
        break;
aschiffler@6727
   560
    case SDL_PIXELFORMAT_YV12:
slouken@10866
   561
        SDL_Log("YV12");
aschiffler@6727
   562
        break;
aschiffler@6727
   563
    case SDL_PIXELFORMAT_IYUV:
slouken@10866
   564
        SDL_Log("IYUV");
aschiffler@6727
   565
        break;
aschiffler@6727
   566
    case SDL_PIXELFORMAT_YUY2:
slouken@10866
   567
        SDL_Log("YUY2");
aschiffler@6727
   568
        break;
aschiffler@6727
   569
    case SDL_PIXELFORMAT_UYVY:
slouken@10866
   570
        SDL_Log("UYVY");
aschiffler@6727
   571
        break;
aschiffler@6727
   572
    case SDL_PIXELFORMAT_YVYU:
slouken@10866
   573
        SDL_Log("YVYU");
aschiffler@6727
   574
        break;
slouken@9046
   575
    case SDL_PIXELFORMAT_NV12:
slouken@10866
   576
        SDL_Log("NV12");
slouken@9046
   577
        break;
slouken@9046
   578
    case SDL_PIXELFORMAT_NV21:
slouken@10866
   579
        SDL_Log("NV21");
slouken@9046
   580
        break;
aschiffler@6727
   581
    default:
slouken@10866
   582
        SDL_Log("0x%8.8x", format);
aschiffler@6727
   583
        break;
aschiffler@6727
   584
    }
aschiffler@6727
   585
}
aschiffler@6727
   586
aschiffler@6727
   587
static void
aschiffler@6727
   588
SDLTest_PrintRenderer(SDL_RendererInfo * info)
aschiffler@6727
   589
{
aschiffler@6727
   590
    int i, count;
aschiffler@6727
   591
slouken@10866
   592
    SDL_Log("  Renderer %s:\n", info->name);
aschiffler@6727
   593
slouken@10866
   594
    SDL_Log("    Flags: 0x%8.8X", info->flags);
slouken@10866
   595
    SDL_Log(" (");
aschiffler@6727
   596
    count = 0;
aschiffler@6727
   597
    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
aschiffler@6727
   598
        Uint32 flag = (1 << i);
aschiffler@6727
   599
        if (info->flags & flag) {
aschiffler@6727
   600
            if (count > 0) {
slouken@10866
   601
                SDL_Log(" | ");
aschiffler@6727
   602
            }
aschiffler@6727
   603
            SDLTest_PrintRendererFlag(flag);
aschiffler@6727
   604
            ++count;
aschiffler@6727
   605
        }
aschiffler@6727
   606
    }
slouken@10866
   607
    SDL_Log(")\n");
aschiffler@6727
   608
slouken@10866
   609
    SDL_Log("    Texture formats (%d): ", info->num_texture_formats);
aschiffler@6727
   610
    for (i = 0; i < (int) info->num_texture_formats; ++i) {
aschiffler@6727
   611
        if (i > 0) {
slouken@10866
   612
            SDL_Log(", ");
aschiffler@6727
   613
        }
aschiffler@6727
   614
        SDLTest_PrintPixelFormat(info->texture_formats[i]);
aschiffler@6727
   615
    }
slouken@10866
   616
    SDL_Log("\n");
aschiffler@6727
   617
aschiffler@6727
   618
    if (info->max_texture_width || info->max_texture_height) {
slouken@10866
   619
        SDL_Log("    Max Texture Size: %dx%d\n",
aschiffler@6727
   620
                info->max_texture_width, info->max_texture_height);
aschiffler@6727
   621
    }
aschiffler@6727
   622
}
aschiffler@6727
   623
aschiffler@6727
   624
static SDL_Surface *
aschiffler@6727
   625
SDLTest_LoadIcon(const char *file)
aschiffler@6727
   626
{
aschiffler@6727
   627
    SDL_Surface *icon;
aschiffler@6727
   628
aschiffler@6727
   629
    /* Load the icon surface */
aschiffler@6727
   630
    icon = SDL_LoadBMP(file);
aschiffler@6727
   631
    if (icon == NULL) {
slouken@10866
   632
        SDL_Log("Couldn't load %s: %s\n", file, SDL_GetError());
aschiffler@6727
   633
        return (NULL);
aschiffler@6727
   634
    }
aschiffler@6727
   635
aschiffler@6727
   636
    if (icon->format->palette) {
aschiffler@6727
   637
        /* Set the colorkey */
aschiffler@6727
   638
        SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels));
aschiffler@6727
   639
    }
aschiffler@6727
   640
aschiffler@6727
   641
    return (icon);
aschiffler@6727
   642
}
aschiffler@6727
   643
aschiffler@6727
   644
SDL_bool
aschiffler@6727
   645
SDLTest_CommonInit(SDLTest_CommonState * state)
aschiffler@6727
   646
{
aschiffler@6727
   647
    int i, j, m, n, w, h;
aschiffler@6727
   648
    SDL_DisplayMode fullscreen_mode;
aschiffler@6727
   649
aschiffler@6727
   650
    if (state->flags & SDL_INIT_VIDEO) {
aschiffler@6727
   651
        if (state->verbose & VERBOSE_VIDEO) {
aschiffler@6727
   652
            n = SDL_GetNumVideoDrivers();
aschiffler@6727
   653
            if (n == 0) {
slouken@10866
   654
                SDL_Log("No built-in video drivers\n");
aschiffler@6727
   655
            } else {
slouken@10866
   656
                SDL_Log("Built-in video drivers:");
aschiffler@6727
   657
                for (i = 0; i < n; ++i) {
aschiffler@6727
   658
                    if (i > 0) {
slouken@10866
   659
                        SDL_Log(",");
aschiffler@6727
   660
                    }
slouken@10866
   661
                    SDL_Log(" %s", SDL_GetVideoDriver(i));
aschiffler@6727
   662
                }
slouken@10866
   663
                SDL_Log("\n");
aschiffler@6727
   664
            }
aschiffler@6727
   665
        }
aschiffler@6727
   666
        if (SDL_VideoInit(state->videodriver) < 0) {
slouken@10866
   667
            SDL_Log("Couldn't initialize video driver: %s\n",
aschiffler@6727
   668
                    SDL_GetError());
aschiffler@6727
   669
            return SDL_FALSE;
aschiffler@6727
   670
        }
aschiffler@6727
   671
        if (state->verbose & VERBOSE_VIDEO) {
slouken@10866
   672
            SDL_Log("Video driver: %s\n",
aschiffler@6727
   673
                    SDL_GetCurrentVideoDriver());
aschiffler@6727
   674
        }
aschiffler@6727
   675
aschiffler@6727
   676
        /* Upload GL settings */
aschiffler@6727
   677
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size);
aschiffler@6727
   678
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size);
aschiffler@6727
   679
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size);
aschiffler@6727
   680
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size);
aschiffler@6727
   681
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
aschiffler@6727
   682
        SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
aschiffler@6727
   683
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size);
aschiffler@6727
   684
        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
aschiffler@6727
   685
        SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
aschiffler@6727
   686
        SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
aschiffler@6727
   687
        SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
aschiffler@6727
   688
        SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
aschiffler@6727
   689
        SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
aschiffler@6727
   690
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
aschiffler@6727
   691
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
aschiffler@6727
   692
        if (state->gl_accelerated >= 0) {
aschiffler@6727
   693
            SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
aschiffler@6727
   694
                                state->gl_accelerated);
aschiffler@6727
   695
        }
aschiffler@6727
   696
        SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
aschiffler@6727
   697
        if (state->gl_major_version) {
aschiffler@6727
   698
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
aschiffler@6727
   699
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
aschiffler@6727
   700
        }
slouken@7194
   701
        if (state->gl_debug) {
slouken@7194
   702
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
slouken@7194
   703
        }
gabomdq@7796
   704
        if (state->gl_profile_mask) {
gabomdq@7796
   705
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, state->gl_profile_mask);
gabomdq@7796
   706
        }
aschiffler@6727
   707
aschiffler@6727
   708
        if (state->verbose & VERBOSE_MODES) {
aschiffler@6727
   709
            SDL_Rect bounds;
aschiffler@6727
   710
            SDL_DisplayMode mode;
aschiffler@6727
   711
            int bpp;
aschiffler@6727
   712
            Uint32 Rmask, Gmask, Bmask, Amask;
slouken@7756
   713
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@7756
   714
			int adapterIndex = 0;
slouken@8213
   715
			int outputIndex = 0;
slouken@7756
   716
#endif
aschiffler@6727
   717
            n = SDL_GetNumVideoDisplays();
slouken@10866
   718
            SDL_Log("Number of displays: %d\n", n);
aschiffler@6727
   719
            for (i = 0; i < n; ++i) {
slouken@10866
   720
                SDL_Log("Display %d: %s\n", i, SDL_GetDisplayName(i));
aschiffler@6727
   721
aschiffler@6727
   722
                SDL_zero(bounds);
aschiffler@6727
   723
                SDL_GetDisplayBounds(i, &bounds);
slouken@10866
   724
                SDL_Log("Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
aschiffler@6727
   725
aschiffler@6727
   726
                SDL_GetDesktopDisplayMode(i, &mode);
aschiffler@6727
   727
                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
aschiffler@6727
   728
                                           &Bmask, &Amask);
slouken@10866
   729
                SDL_Log("  Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
aschiffler@6727
   730
                        mode.w, mode.h, mode.refresh_rate, bpp,
aschiffler@6727
   731
                        SDL_GetPixelFormatName(mode.format));
aschiffler@6727
   732
                if (Rmask || Gmask || Bmask) {
slouken@10866
   733
                    SDL_Log("      Red Mask   = 0x%.8x\n", Rmask);
slouken@10866
   734
                    SDL_Log("      Green Mask = 0x%.8x\n", Gmask);
slouken@10866
   735
                    SDL_Log("      Blue Mask  = 0x%.8x\n", Bmask);
aschiffler@6727
   736
                    if (Amask)
slouken@10866
   737
                        SDL_Log("      Alpha Mask = 0x%.8x\n", Amask);
aschiffler@6727
   738
                }
aschiffler@6727
   739
aschiffler@6727
   740
                /* Print available fullscreen video modes */
aschiffler@6727
   741
                m = SDL_GetNumDisplayModes(i);
aschiffler@6727
   742
                if (m == 0) {
slouken@10866
   743
                    SDL_Log("No available fullscreen video modes\n");
aschiffler@6727
   744
                } else {
slouken@10866
   745
                    SDL_Log("  Fullscreen video modes:\n");
aschiffler@6727
   746
                    for (j = 0; j < m; ++j) {
aschiffler@6727
   747
                        SDL_GetDisplayMode(i, j, &mode);
aschiffler@6727
   748
                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
aschiffler@6727
   749
                                                   &Gmask, &Bmask, &Amask);
slouken@10866
   750
						SDL_Log("    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
aschiffler@6727
   751
                                j, mode.w, mode.h, mode.refresh_rate, bpp,
aschiffler@6727
   752
                                SDL_GetPixelFormatName(mode.format));
aschiffler@6727
   753
                        if (Rmask || Gmask || Bmask) {
slouken@10866
   754
                            SDL_Log("        Red Mask   = 0x%.8x\n",
aschiffler@6727
   755
                                    Rmask);
slouken@10866
   756
                            SDL_Log("        Green Mask = 0x%.8x\n",
aschiffler@6727
   757
                                    Gmask);
slouken@10866
   758
                            SDL_Log("        Blue Mask  = 0x%.8x\n",
aschiffler@6727
   759
                                    Bmask);
aschiffler@6727
   760
                            if (Amask)
slouken@10866
   761
								SDL_Log("        Alpha Mask = 0x%.8x\n",
aschiffler@6727
   762
                                        Amask);
aschiffler@6727
   763
                        }
aschiffler@6727
   764
                    }
aschiffler@6727
   765
                }
slouken@7756
   766
slouken@7756
   767
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@8213
   768
				/* Print the D3D9 adapter index */
slouken@7756
   769
				adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
slouken@10866
   770
				SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
slouken@8213
   771
slouken@8213
   772
				/* Print the DXGI adapter and output indices */
slouken@8213
   773
				SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
slouken@10866
   774
				SDL_Log("DXGI Adapter Index: %d  Output Index: %d", adapterIndex, outputIndex);
slouken@7756
   775
#endif
aschiffler@6727
   776
            }
aschiffler@6727
   777
        }
aschiffler@6727
   778
aschiffler@6727
   779
        if (state->verbose & VERBOSE_RENDER) {
aschiffler@6727
   780
            SDL_RendererInfo info;
aschiffler@6727
   781
aschiffler@6727
   782
            n = SDL_GetNumRenderDrivers();
aschiffler@6727
   783
            if (n == 0) {
slouken@10866
   784
                SDL_Log("No built-in render drivers\n");
aschiffler@6727
   785
            } else {
slouken@10866
   786
                SDL_Log("Built-in render drivers:\n");
aschiffler@6727
   787
                for (i = 0; i < n; ++i) {
aschiffler@6727
   788
                    SDL_GetRenderDriverInfo(i, &info);
aschiffler@6727
   789
                    SDLTest_PrintRenderer(&info);
aschiffler@6727
   790
                }
aschiffler@6727
   791
            }
aschiffler@6727
   792
        }
aschiffler@6727
   793
aschiffler@6727
   794
        SDL_zero(fullscreen_mode);
aschiffler@6727
   795
        switch (state->depth) {
aschiffler@6727
   796
        case 8:
aschiffler@6727
   797
            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
aschiffler@6727
   798
            break;
aschiffler@6727
   799
        case 15:
aschiffler@6727
   800
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
aschiffler@6727
   801
            break;
aschiffler@6727
   802
        case 16:
aschiffler@6727
   803
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
aschiffler@6727
   804
            break;
aschiffler@6727
   805
        case 24:
aschiffler@6727
   806
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB24;
aschiffler@6727
   807
            break;
aschiffler@6727
   808
        default:
aschiffler@6727
   809
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
aschiffler@6727
   810
            break;
aschiffler@6727
   811
        }
aschiffler@6727
   812
        fullscreen_mode.refresh_rate = state->refresh_rate;
aschiffler@6727
   813
aschiffler@6727
   814
        state->windows =
aschiffler@6727
   815
            (SDL_Window **) SDL_malloc(state->num_windows *
aschiffler@6727
   816
                                        sizeof(*state->windows));
aschiffler@6727
   817
        state->renderers =
aschiffler@6727
   818
            (SDL_Renderer **) SDL_malloc(state->num_windows *
aschiffler@6727
   819
                                        sizeof(*state->renderers));
slouken@7993
   820
        state->targets =
slouken@7993
   821
            (SDL_Texture **) SDL_malloc(state->num_windows *
slouken@7993
   822
                                        sizeof(*state->targets));
aschiffler@6727
   823
        if (!state->windows || !state->renderers) {
slouken@10866
   824
            SDL_Log("Out of memory!\n");
aschiffler@6727
   825
            return SDL_FALSE;
aschiffler@6727
   826
        }
aschiffler@6727
   827
        for (i = 0; i < state->num_windows; ++i) {
aschiffler@6727
   828
            char title[1024];
aschiffler@6727
   829
aschiffler@6727
   830
            if (state->num_windows > 1) {
aschiffler@6727
   831
                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
aschiffler@6727
   832
                             state->window_title, i + 1);
aschiffler@6727
   833
            } else {
aschiffler@6727
   834
                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
aschiffler@6727
   835
            }
aschiffler@6727
   836
            state->windows[i] =
aschiffler@6727
   837
                SDL_CreateWindow(title, state->window_x, state->window_y,
aschiffler@6727
   838
                                 state->window_w, state->window_h,
aschiffler@6727
   839
                                 state->window_flags);
aschiffler@6727
   840
            if (!state->windows[i]) {
slouken@10866
   841
                SDL_Log("Couldn't create window: %s\n",
aschiffler@6727
   842
                        SDL_GetError());
aschiffler@6727
   843
                return SDL_FALSE;
aschiffler@6727
   844
            }
slouken@6788
   845
            if (state->window_minW || state->window_minH) {
slouken@6788
   846
                SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
slouken@6788
   847
            }
slouken@6788
   848
            if (state->window_maxW || state->window_maxH) {
slouken@6788
   849
                SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
slouken@6788
   850
            }
aschiffler@6727
   851
            SDL_GetWindowSize(state->windows[i], &w, &h);
aschiffler@6727
   852
            if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
aschiffler@6727
   853
                (w != state->window_w || h != state->window_h)) {
aschiffler@6727
   854
                printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
aschiffler@6727
   855
                state->window_w = w;
aschiffler@6727
   856
                state->window_h = h;
aschiffler@6727
   857
            }
aschiffler@6727
   858
            if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
slouken@10866
   859
                SDL_Log("Can't set up fullscreen display mode: %s\n",
aschiffler@6727
   860
                        SDL_GetError());
aschiffler@6727
   861
                return SDL_FALSE;
aschiffler@6727
   862
            }
aschiffler@6727
   863
aschiffler@6727
   864
            if (state->window_icon) {
aschiffler@6727
   865
                SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
aschiffler@6727
   866
                if (icon) {
aschiffler@6727
   867
                    SDL_SetWindowIcon(state->windows[i], icon);
aschiffler@6727
   868
                    SDL_FreeSurface(icon);
aschiffler@6727
   869
                }
aschiffler@6727
   870
            }
aschiffler@6727
   871
aschiffler@6727
   872
            SDL_ShowWindow(state->windows[i]);
aschiffler@6727
   873
aschiffler@6727
   874
            state->renderers[i] = NULL;
slouken@7993
   875
            state->targets[i] = NULL;
aschiffler@6727
   876
aschiffler@6727
   877
            if (!state->skip_renderer
aschiffler@6727
   878
                && (state->renderdriver
aschiffler@6727
   879
                    || !(state->window_flags & SDL_WINDOW_OPENGL))) {
aschiffler@6727
   880
                m = -1;
aschiffler@6727
   881
                if (state->renderdriver) {
aschiffler@6727
   882
                    SDL_RendererInfo info;
aschiffler@6727
   883
                    n = SDL_GetNumRenderDrivers();
aschiffler@6727
   884
                    for (j = 0; j < n; ++j) {
aschiffler@6727
   885
                        SDL_GetRenderDriverInfo(j, &info);
aschiffler@6727
   886
                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
aschiffler@6727
   887
                            0) {
aschiffler@6727
   888
                            m = j;
aschiffler@6727
   889
                            break;
aschiffler@6727
   890
                        }
aschiffler@6727
   891
                    }
slouken@8697
   892
                    if (m == -1) {
slouken@10866
   893
						SDL_Log("Couldn't find render driver named %s",
aschiffler@6727
   894
                                state->renderdriver);
aschiffler@6727
   895
                        return SDL_FALSE;
aschiffler@6727
   896
                    }
aschiffler@6727
   897
                }
aschiffler@6727
   898
                state->renderers[i] = SDL_CreateRenderer(state->windows[i],
aschiffler@6727
   899
                                            m, state->render_flags);
aschiffler@6727
   900
                if (!state->renderers[i]) {
slouken@10866
   901
                    SDL_Log("Couldn't create renderer: %s\n",
aschiffler@6727
   902
                            SDL_GetError());
aschiffler@6727
   903
                    return SDL_FALSE;
aschiffler@6727
   904
                }
slouken@7240
   905
                if (state->logical_w && state->logical_h) {
slouken@7240
   906
                    SDL_RenderSetLogicalSize(state->renderers[i], state->logical_w, state->logical_h);
slouken@7240
   907
                } else if (state->scale) {
slouken@7240
   908
                    SDL_RenderSetScale(state->renderers[i], state->scale, state->scale);
slouken@7240
   909
                }
aschiffler@6727
   910
                if (state->verbose & VERBOSE_RENDER) {
aschiffler@6727
   911
                    SDL_RendererInfo info;
aschiffler@6727
   912
slouken@10866
   913
                    SDL_Log("Current renderer:\n");
aschiffler@6727
   914
                    SDL_GetRendererInfo(state->renderers[i], &info);
aschiffler@6727
   915
                    SDLTest_PrintRenderer(&info);
aschiffler@6727
   916
                }
aschiffler@6727
   917
            }
aschiffler@6727
   918
        }
aschiffler@6727
   919
    }
aschiffler@6727
   920
aschiffler@6727
   921
    if (state->flags & SDL_INIT_AUDIO) {
aschiffler@6727
   922
        if (state->verbose & VERBOSE_AUDIO) {
aschiffler@6727
   923
            n = SDL_GetNumAudioDrivers();
aschiffler@6727
   924
            if (n == 0) {
slouken@10866
   925
                SDL_Log("No built-in audio drivers\n");
aschiffler@6727
   926
            } else {
slouken@10866
   927
                SDL_Log("Built-in audio drivers:");
aschiffler@6727
   928
                for (i = 0; i < n; ++i) {
aschiffler@6727
   929
                    if (i > 0) {
slouken@10866
   930
                        SDL_Log(",");
aschiffler@6727
   931
                    }
slouken@10866
   932
                    SDL_Log(" %s", SDL_GetAudioDriver(i));
aschiffler@6727
   933
                }
slouken@10866
   934
                SDL_Log("\n");
aschiffler@6727
   935
            }
aschiffler@6727
   936
        }
aschiffler@6727
   937
        if (SDL_AudioInit(state->audiodriver) < 0) {
slouken@10866
   938
            SDL_Log("Couldn't initialize audio driver: %s\n",
aschiffler@6727
   939
                    SDL_GetError());
aschiffler@6727
   940
            return SDL_FALSE;
aschiffler@6727
   941
        }
aschiffler@6727
   942
        if (state->verbose & VERBOSE_VIDEO) {
slouken@10866
   943
            SDL_Log("Audio driver: %s\n",
aschiffler@6727
   944
                    SDL_GetCurrentAudioDriver());
aschiffler@6727
   945
        }
aschiffler@6727
   946
aschiffler@6727
   947
        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
slouken@10866
   948
            SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
aschiffler@6727
   949
            return SDL_FALSE;
aschiffler@6727
   950
        }
aschiffler@6727
   951
    }
aschiffler@6727
   952
aschiffler@6727
   953
    return SDL_TRUE;
aschiffler@6727
   954
}
aschiffler@6727
   955
slouken@8069
   956
static const char *
slouken@8069
   957
ControllerAxisName(const SDL_GameControllerAxis axis)
slouken@8069
   958
{
slouken@8069
   959
    switch (axis)
slouken@8069
   960
    {
slouken@8069
   961
#define AXIS_CASE(ax) case SDL_CONTROLLER_AXIS_##ax: return #ax
slouken@8069
   962
        AXIS_CASE(INVALID);
slouken@8069
   963
        AXIS_CASE(LEFTX);
slouken@8069
   964
        AXIS_CASE(LEFTY);
slouken@8069
   965
        AXIS_CASE(RIGHTX);
slouken@8069
   966
        AXIS_CASE(RIGHTY);
slouken@8069
   967
        AXIS_CASE(TRIGGERLEFT);
slouken@8069
   968
        AXIS_CASE(TRIGGERRIGHT);
slouken@8069
   969
#undef AXIS_CASE
slouken@8069
   970
default: return "???";
slouken@8069
   971
    }
slouken@8069
   972
}
slouken@8069
   973
slouken@8069
   974
static const char *
slouken@8069
   975
ControllerButtonName(const SDL_GameControllerButton button)
slouken@8069
   976
{
slouken@8069
   977
    switch (button)
slouken@8069
   978
    {
slouken@8069
   979
#define BUTTON_CASE(btn) case SDL_CONTROLLER_BUTTON_##btn: return #btn
slouken@8069
   980
        BUTTON_CASE(INVALID);
slouken@8069
   981
        BUTTON_CASE(A);
slouken@8069
   982
        BUTTON_CASE(B);
slouken@8069
   983
        BUTTON_CASE(X);
slouken@8069
   984
        BUTTON_CASE(Y);
slouken@8069
   985
        BUTTON_CASE(BACK);
slouken@8069
   986
        BUTTON_CASE(GUIDE);
slouken@8069
   987
        BUTTON_CASE(START);
slouken@8069
   988
        BUTTON_CASE(LEFTSTICK);
slouken@8069
   989
        BUTTON_CASE(RIGHTSTICK);
slouken@8069
   990
        BUTTON_CASE(LEFTSHOULDER);
slouken@8069
   991
        BUTTON_CASE(RIGHTSHOULDER);
slouken@8069
   992
        BUTTON_CASE(DPAD_UP);
slouken@8069
   993
        BUTTON_CASE(DPAD_DOWN);
slouken@8069
   994
        BUTTON_CASE(DPAD_LEFT);
slouken@8069
   995
        BUTTON_CASE(DPAD_RIGHT);
slouken@8069
   996
#undef BUTTON_CASE
slouken@8069
   997
default: return "???";
slouken@8069
   998
    }
slouken@8069
   999
}
slouken@8069
  1000
aschiffler@6727
  1001
static void
aschiffler@6727
  1002
SDLTest_PrintEvent(SDL_Event * event)
aschiffler@6727
  1003
{
icculus@7470
  1004
    if ((event->type == SDL_MOUSEMOTION) || (event->type == SDL_FINGERMOTION)) {
icculus@7470
  1005
        /* Mouse and finger motion are really spammy */
slouken@8012
  1006
        return;
aschiffler@6727
  1007
    }
aschiffler@6727
  1008
aschiffler@6727
  1009
    switch (event->type) {
aschiffler@6727
  1010
    case SDL_WINDOWEVENT:
aschiffler@6727
  1011
        switch (event->window.event) {
aschiffler@6727
  1012
        case SDL_WINDOWEVENT_SHOWN:
slouken@8069
  1013
            SDL_Log("SDL EVENT: Window %d shown", event->window.windowID);
aschiffler@6727
  1014
            break;
aschiffler@6727
  1015
        case SDL_WINDOWEVENT_HIDDEN:
slouken@8069
  1016
            SDL_Log("SDL EVENT: Window %d hidden", event->window.windowID);
aschiffler@6727
  1017
            break;
aschiffler@6727
  1018
        case SDL_WINDOWEVENT_EXPOSED:
slouken@8069
  1019
            SDL_Log("SDL EVENT: Window %d exposed", event->window.windowID);
aschiffler@6727
  1020
            break;
aschiffler@6727
  1021
        case SDL_WINDOWEVENT_MOVED:
slouken@8069
  1022
            SDL_Log("SDL EVENT: Window %d moved to %d,%d",
aschiffler@6727
  1023
                    event->window.windowID, event->window.data1,
aschiffler@6727
  1024
                    event->window.data2);
aschiffler@6727
  1025
            break;
aschiffler@6727
  1026
        case SDL_WINDOWEVENT_RESIZED:
slouken@8069
  1027
            SDL_Log("SDL EVENT: Window %d resized to %dx%d",
aschiffler@6727
  1028
                    event->window.windowID, event->window.data1,
aschiffler@6727
  1029
                    event->window.data2);
aschiffler@6727
  1030
            break;
aschiffler@6727
  1031
        case SDL_WINDOWEVENT_SIZE_CHANGED:
slouken@8069
  1032
            SDL_Log("SDL EVENT: Window %d changed size to %dx%d",
aschiffler@6727
  1033
                    event->window.windowID, event->window.data1,
aschiffler@6727
  1034
                    event->window.data2);
aschiffler@6727
  1035
            break;
aschiffler@6727
  1036
        case SDL_WINDOWEVENT_MINIMIZED:
slouken@8069
  1037
            SDL_Log("SDL EVENT: Window %d minimized", event->window.windowID);
aschiffler@6727
  1038
            break;
aschiffler@6727
  1039
        case SDL_WINDOWEVENT_MAXIMIZED:
slouken@8069
  1040
            SDL_Log("SDL EVENT: Window %d maximized", event->window.windowID);
aschiffler@6727
  1041
            break;
aschiffler@6727
  1042
        case SDL_WINDOWEVENT_RESTORED:
slouken@8069
  1043
            SDL_Log("SDL EVENT: Window %d restored", event->window.windowID);
aschiffler@6727
  1044
            break;
aschiffler@6727
  1045
        case SDL_WINDOWEVENT_ENTER:
slouken@8069
  1046
            SDL_Log("SDL EVENT: Mouse entered window %d",
aschiffler@6727
  1047
                    event->window.windowID);
aschiffler@6727
  1048
            break;
aschiffler@6727
  1049
        case SDL_WINDOWEVENT_LEAVE:
slouken@8069
  1050
            SDL_Log("SDL EVENT: Mouse left window %d", event->window.windowID);
aschiffler@6727
  1051
            break;
aschiffler@6727
  1052
        case SDL_WINDOWEVENT_FOCUS_GAINED:
slouken@8069
  1053
            SDL_Log("SDL EVENT: Window %d gained keyboard focus",
aschiffler@6727
  1054
                    event->window.windowID);
aschiffler@6727
  1055
            break;
aschiffler@6727
  1056
        case SDL_WINDOWEVENT_FOCUS_LOST:
slouken@8069
  1057
            SDL_Log("SDL EVENT: Window %d lost keyboard focus",
aschiffler@6727
  1058
                    event->window.windowID);
aschiffler@6727
  1059
            break;
aschiffler@6727
  1060
        case SDL_WINDOWEVENT_CLOSE:
slouken@8069
  1061
            SDL_Log("SDL EVENT: Window %d closed", event->window.windowID);
aschiffler@6727
  1062
            break;
slouken@10381
  1063
        case SDL_WINDOWEVENT_TAKE_FOCUS:
slouken@10381
  1064
            SDL_Log("SDL EVENT: Window %d take focus", event->window.windowID);
slouken@10381
  1065
            break;
slouken@10381
  1066
        case SDL_WINDOWEVENT_HIT_TEST:
slouken@10381
  1067
            SDL_Log("SDL EVENT: Window %d hit test", event->window.windowID);
slouken@10381
  1068
            break;
aschiffler@6727
  1069
        default:
slouken@8069
  1070
            SDL_Log("SDL EVENT: Window %d got unknown event %d",
aschiffler@6727
  1071
                    event->window.windowID, event->window.event);
aschiffler@6727
  1072
            break;
aschiffler@6727
  1073
        }
aschiffler@6727
  1074
        break;
aschiffler@6727
  1075
    case SDL_KEYDOWN:
slouken@8069
  1076
        SDL_Log("SDL EVENT: Keyboard: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
aschiffler@6727
  1077
                event->key.windowID,
aschiffler@6727
  1078
                event->key.keysym.scancode,
aschiffler@6727
  1079
                SDL_GetScancodeName(event->key.keysym.scancode),
aschiffler@6727
  1080
                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
aschiffler@6727
  1081
        break;
aschiffler@6727
  1082
    case SDL_KEYUP:
slouken@8069
  1083
        SDL_Log("SDL EVENT: Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
aschiffler@6727
  1084
                event->key.windowID,
aschiffler@6727
  1085
                event->key.keysym.scancode,
aschiffler@6727
  1086
                SDL_GetScancodeName(event->key.keysym.scancode),
aschiffler@6727
  1087
                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
aschiffler@6727
  1088
        break;
aschiffler@6727
  1089
    case SDL_TEXTINPUT:
slouken@8069
  1090
        SDL_Log("SDL EVENT: Keyboard: text input \"%s\" in window %d",
aschiffler@6727
  1091
                event->text.text, event->text.windowID);
aschiffler@6727
  1092
        break;
aschiffler@6727
  1093
    case SDL_MOUSEMOTION:
slouken@8069
  1094
        SDL_Log("SDL EVENT: Mouse: moved to %d,%d (%d,%d) in window %d",
aschiffler@6727
  1095
                event->motion.x, event->motion.y,
aschiffler@6727
  1096
                event->motion.xrel, event->motion.yrel,
aschiffler@6727
  1097
                event->motion.windowID);
aschiffler@6727
  1098
        break;
aschiffler@6727
  1099
    case SDL_MOUSEBUTTONDOWN:
slouken@8069
  1100
        SDL_Log("SDL EVENT: Mouse: button %d pressed at %d,%d with click count %d in window %d",
slouken@8066
  1101
                event->button.button, event->button.x, event->button.y, event->button.clicks,
aschiffler@6727
  1102
                event->button.windowID);
aschiffler@6727
  1103
        break;
aschiffler@6727
  1104
    case SDL_MOUSEBUTTONUP:
slouken@8069
  1105
        SDL_Log("SDL EVENT: Mouse: button %d released at %d,%d with click count %d in window %d",
slouken@8066
  1106
                event->button.button, event->button.x, event->button.y, event->button.clicks,
aschiffler@6727
  1107
                event->button.windowID);
aschiffler@6727
  1108
        break;
aschiffler@6727
  1109
    case SDL_MOUSEWHEEL:
urkle@9258
  1110
        SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y (reversed: %d) in window %d",
urkle@9259
  1111
                event->wheel.x, event->wheel.y, event->wheel.direction, event->wheel.windowID);
aschiffler@6727
  1112
        break;
slouken@8069
  1113
    case SDL_JOYDEVICEADDED:
slouken@8069
  1114
        SDL_Log("SDL EVENT: Joystick index %d attached",
slouken@8069
  1115
            event->jdevice.which);
slouken@8069
  1116
        break;
slouken@8069
  1117
    case SDL_JOYDEVICEREMOVED:
slouken@8069
  1118
        SDL_Log("SDL EVENT: Joystick %d removed",
slouken@8069
  1119
            event->jdevice.which);
slouken@8069
  1120
        break;
aschiffler@6727
  1121
    case SDL_JOYBALLMOTION:
slouken@8069
  1122
        SDL_Log("SDL EVENT: Joystick %d: ball %d moved by %d,%d",
aschiffler@6727
  1123
                event->jball.which, event->jball.ball, event->jball.xrel,
aschiffler@6727
  1124
                event->jball.yrel);
aschiffler@6727
  1125
        break;
aschiffler@6727
  1126
    case SDL_JOYHATMOTION:
slouken@8069
  1127
        {
slouken@8069
  1128
            const char *position = "UNKNOWN";
slouken@8069
  1129
            switch (event->jhat.value) {
slouken@8069
  1130
            case SDL_HAT_CENTERED:
slouken@8069
  1131
                position = "CENTER";
slouken@8069
  1132
                break;
slouken@8069
  1133
            case SDL_HAT_UP:
slouken@8069
  1134
                position = "UP";
slouken@8069
  1135
                break;
slouken@8069
  1136
            case SDL_HAT_RIGHTUP:
slouken@8069
  1137
                position = "RIGHTUP";
slouken@8069
  1138
                break;
slouken@8069
  1139
            case SDL_HAT_RIGHT:
slouken@8069
  1140
                position = "RIGHT";
slouken@8069
  1141
                break;
slouken@8069
  1142
            case SDL_HAT_RIGHTDOWN:
slouken@8069
  1143
                position = "RIGHTDOWN";
slouken@8069
  1144
                break;
slouken@8069
  1145
            case SDL_HAT_DOWN:
slouken@8069
  1146
                position = "DOWN";
slouken@8069
  1147
                break;
slouken@8069
  1148
            case SDL_HAT_LEFTDOWN:
slouken@8069
  1149
                position = "LEFTDOWN";
slouken@8069
  1150
                break;
slouken@8069
  1151
            case SDL_HAT_LEFT:
slouken@8069
  1152
                position = "LEFT";
slouken@8069
  1153
                break;
slouken@8069
  1154
            case SDL_HAT_LEFTUP:
slouken@8069
  1155
                position = "LEFTUP";
slouken@8069
  1156
                break;
slouken@8069
  1157
            }
slouken@8069
  1158
            SDL_Log("SDL EVENT: Joystick %d: hat %d moved to %s", event->jhat.which,
slouken@8069
  1159
                event->jhat.hat, position);
aschiffler@6727
  1160
        }
aschiffler@6727
  1161
        break;
aschiffler@6727
  1162
    case SDL_JOYBUTTONDOWN:
slouken@8069
  1163
        SDL_Log("SDL EVENT: Joystick %d: button %d pressed",
aschiffler@6727
  1164
                event->jbutton.which, event->jbutton.button);
aschiffler@6727
  1165
        break;
aschiffler@6727
  1166
    case SDL_JOYBUTTONUP:
slouken@8069
  1167
        SDL_Log("SDL EVENT: Joystick %d: button %d released",
aschiffler@6727
  1168
                event->jbutton.which, event->jbutton.button);
aschiffler@6727
  1169
        break;
slouken@8069
  1170
    case SDL_CONTROLLERDEVICEADDED:
slouken@8069
  1171
        SDL_Log("SDL EVENT: Controller index %d attached",
slouken@8069
  1172
            event->cdevice.which);
slouken@8069
  1173
        break;
slouken@8069
  1174
    case SDL_CONTROLLERDEVICEREMOVED:
slouken@8069
  1175
        SDL_Log("SDL EVENT: Controller %d removed",
slouken@8069
  1176
            event->cdevice.which);
slouken@8069
  1177
        break;
slouken@8069
  1178
    case SDL_CONTROLLERAXISMOTION:
slouken@8069
  1179
        SDL_Log("SDL EVENT: Controller %d axis %d ('%s') value: %d",
slouken@8069
  1180
            event->caxis.which,
slouken@8069
  1181
            event->caxis.axis,
slouken@8069
  1182
            ControllerAxisName((SDL_GameControllerAxis)event->caxis.axis),
slouken@8069
  1183
            event->caxis.value);
slouken@8069
  1184
        break;
slouken@8069
  1185
    case SDL_CONTROLLERBUTTONDOWN:
slouken@8069
  1186
        SDL_Log("SDL EVENT: Controller %d button %d ('%s') down",
slouken@8069
  1187
            event->cbutton.which, event->cbutton.button,
slouken@8069
  1188
            ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
slouken@8069
  1189
        break;
slouken@8069
  1190
    case SDL_CONTROLLERBUTTONUP:
slouken@8069
  1191
        SDL_Log("SDL EVENT: Controller %d button %d ('%s') up",
slouken@8069
  1192
            event->cbutton.which, event->cbutton.button,
slouken@8069
  1193
            ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
slouken@8069
  1194
        break;
aschiffler@6727
  1195
    case SDL_CLIPBOARDUPDATE:
slouken@8069
  1196
        SDL_Log("SDL EVENT: Clipboard updated");
aschiffler@6727
  1197
        break;
icculus@7470
  1198
icculus@7470
  1199
    case SDL_FINGERDOWN:
icculus@7470
  1200
    case SDL_FINGERUP:
slouken@8069
  1201
        SDL_Log("SDL EVENT: Finger: %s touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f",
icculus@7470
  1202
                (event->type == SDL_FINGERDOWN) ? "down" : "up",
slouken@7828
  1203
                (long) event->tfinger.touchId,
slouken@7828
  1204
                (long) event->tfinger.fingerId,
icculus@7470
  1205
                event->tfinger.x, event->tfinger.y,
icculus@7470
  1206
                event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure);
icculus@7470
  1207
        break;
urkle@9258
  1208
    case SDL_DOLLARGESTURE:
icculus@10644
  1209
        SDL_Log("SDL_EVENT: Dollar gesture detect: %ld", (long) event->dgesture.gestureId);
urkle@9258
  1210
        break;
urkle@9258
  1211
    case SDL_DOLLARRECORD:
icculus@10644
  1212
        SDL_Log("SDL_EVENT: Dollar gesture record: %ld", (long) event->dgesture.gestureId);
urkle@9258
  1213
        break;
urkle@9258
  1214
    case SDL_MULTIGESTURE:
urkle@9258
  1215
        SDL_Log("SDL_EVENT: Multi gesture fingers: %d", event->mgesture.numFingers);
urkle@9258
  1216
        break;
icculus@7470
  1217
slouken@8674
  1218
    case SDL_RENDER_DEVICE_RESET:
slouken@8674
  1219
        SDL_Log("SDL EVENT: render device reset");
slouken@8674
  1220
        break;
slouken@8674
  1221
    case SDL_RENDER_TARGETS_RESET:
slouken@8674
  1222
        SDL_Log("SDL EVENT: render targets reset");
slouken@8674
  1223
        break;
slouken@8674
  1224
aschiffler@6727
  1225
    case SDL_QUIT:
slouken@8069
  1226
        SDL_Log("SDL EVENT: Quit requested");
aschiffler@6727
  1227
        break;
aschiffler@6727
  1228
    case SDL_USEREVENT:
slouken@8069
  1229
        SDL_Log("SDL EVENT: User event %d", event->user.code);
aschiffler@6727
  1230
        break;
aschiffler@6727
  1231
    default:
urkle@9258
  1232
        SDL_Log("Unknown event %04x", event->type);
aschiffler@6727
  1233
        break;
aschiffler@6727
  1234
    }
aschiffler@6727
  1235
}
aschiffler@6727
  1236
aschiffler@6727
  1237
static void
aschiffler@6727
  1238
SDLTest_ScreenShot(SDL_Renderer *renderer)
aschiffler@6727
  1239
{
aschiffler@6727
  1240
    SDL_Rect viewport;
aschiffler@6727
  1241
    SDL_Surface *surface;
aschiffler@6727
  1242
aschiffler@6727
  1243
    if (!renderer) {
aschiffler@6727
  1244
        return;
aschiffler@6727
  1245
    }
aschiffler@6727
  1246
aschiffler@6727
  1247
    SDL_RenderGetViewport(renderer, &viewport);
aschiffler@6727
  1248
    surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24,
aschiffler@6727
  1249
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
aschiffler@6727
  1250
                    0x00FF0000, 0x0000FF00, 0x000000FF,
aschiffler@6727
  1251
#else
aschiffler@6727
  1252
                    0x000000FF, 0x0000FF00, 0x00FF0000,
aschiffler@6727
  1253
#endif
aschiffler@6727
  1254
                    0x00000000);
aschiffler@6727
  1255
    if (!surface) {
slouken@10866
  1256
        SDL_Log("Couldn't create surface: %s\n", SDL_GetError());
aschiffler@6727
  1257
        return;
aschiffler@6727
  1258
    }
aschiffler@6727
  1259
aschiffler@6727
  1260
    if (SDL_RenderReadPixels(renderer, NULL, surface->format->format,
aschiffler@6727
  1261
                             surface->pixels, surface->pitch) < 0) {
slouken@10866
  1262
        SDL_Log("Couldn't read screen: %s\n", SDL_GetError());
slouken@7869
  1263
        SDL_free(surface);
aschiffler@6727
  1264
        return;
aschiffler@6727
  1265
    }
aschiffler@6727
  1266
aschiffler@6727
  1267
    if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) {
slouken@10866
  1268
        SDL_Log("Couldn't save screenshot.bmp: %s\n", SDL_GetError());
slouken@7869
  1269
        SDL_free(surface);
aschiffler@6727
  1270
        return;
aschiffler@6727
  1271
    }
aschiffler@6727
  1272
}
aschiffler@6727
  1273
slouken@7191
  1274
static void
jorgen@7092
  1275
FullscreenTo(int index, int windowId)
jorgen@7092
  1276
{
jorgen@7092
  1277
    Uint32 flags;
jorgen@7092
  1278
    struct SDL_Rect rect = { 0, 0, 0, 0 };
jorgen@7092
  1279
    SDL_Window *window = SDL_GetWindowFromID(windowId);
jorgen@7092
  1280
    if (!window) {
jorgen@7092
  1281
        return;
jorgen@7092
  1282
    }
jorgen@7092
  1283
jorgen@7092
  1284
    SDL_GetDisplayBounds( index, &rect );
jorgen@7092
  1285
jorgen@7092
  1286
    flags = SDL_GetWindowFlags(window);
jorgen@7092
  1287
    if (flags & SDL_WINDOW_FULLSCREEN) {
jorgen@7092
  1288
        SDL_SetWindowFullscreen( window, SDL_FALSE );
jorgen@7092
  1289
        SDL_Delay( 15 );
jorgen@7092
  1290
    }
jorgen@7092
  1291
jorgen@7092
  1292
    SDL_SetWindowPosition( window, rect.x, rect.y );
jorgen@7092
  1293
    SDL_SetWindowFullscreen( window, SDL_TRUE );
jorgen@7092
  1294
}
jorgen@7092
  1295
aschiffler@6727
  1296
void
aschiffler@6727
  1297
SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
aschiffler@6727
  1298
{
aschiffler@6727
  1299
    int i;
jorgen@7092
  1300
    static SDL_MouseMotionEvent lastEvent;
aschiffler@6727
  1301
aschiffler@6727
  1302
    if (state->verbose & VERBOSE_EVENT) {
aschiffler@6727
  1303
        SDLTest_PrintEvent(event);
aschiffler@6727
  1304
    }
aschiffler@6727
  1305
aschiffler@6727
  1306
    switch (event->type) {
aschiffler@6727
  1307
    case SDL_WINDOWEVENT:
aschiffler@6727
  1308
        switch (event->window.event) {
aschiffler@6727
  1309
        case SDL_WINDOWEVENT_CLOSE:
slouken@7191
  1310
            {
aschiffler@6727
  1311
                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
aschiffler@6727
  1312
                if (window) {
slouken@7787
  1313
                    for (i = 0; i < state->num_windows; ++i) {
slouken@7787
  1314
                        if (window == state->windows[i]) {
slouken@8115
  1315
                            if (state->targets[i]) {
slouken@8115
  1316
                                SDL_DestroyTexture(state->targets[i]);
slouken@8115
  1317
                                state->targets[i] = NULL;
slouken@8115
  1318
                            }
slouken@8115
  1319
                            if (state->renderers[i]) {
slouken@8115
  1320
                                SDL_DestroyRenderer(state->renderers[i]);
slouken@8115
  1321
                                state->renderers[i] = NULL;
slouken@8115
  1322
                            }
slouken@8115
  1323
                            SDL_DestroyWindow(state->windows[i]);
slouken@7787
  1324
                            state->windows[i] = NULL;
slouken@7787
  1325
                            break;
slouken@7787
  1326
                        }
slouken@7787
  1327
                    }
slouken@7191
  1328
                }
slouken@7191
  1329
            }
aschiffler@6727
  1330
            break;
aschiffler@6727
  1331
        }
aschiffler@6727
  1332
        break;
jorgen@8108
  1333
    case SDL_KEYDOWN: {
jorgen@8108
  1334
        SDL_bool withControl = !!(event->key.keysym.mod & KMOD_CTRL);
jorgen@8108
  1335
        SDL_bool withShift = !!(event->key.keysym.mod & KMOD_SHIFT);
jorgen@8108
  1336
        SDL_bool withAlt = !!(event->key.keysym.mod & KMOD_ALT);
jorgen@8108
  1337
aschiffler@6727
  1338
        switch (event->key.keysym.sym) {
aschiffler@6727
  1339
            /* Add hotkeys here */
aschiffler@6727
  1340
        case SDLK_PRINTSCREEN: {
aschiffler@6727
  1341
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1342
                if (window) {
aschiffler@6727
  1343
                    for (i = 0; i < state->num_windows; ++i) {
aschiffler@6727
  1344
                        if (window == state->windows[i]) {
aschiffler@6727
  1345
                            SDLTest_ScreenShot(state->renderers[i]);
aschiffler@6727
  1346
                        }
aschiffler@6727
  1347
                    }
aschiffler@6727
  1348
                }
aschiffler@6727
  1349
            }
aschiffler@6727
  1350
            break;
aschiffler@6727
  1351
        case SDLK_EQUALS:
jorgen@8108
  1352
            if (withControl) {
philipp@7474
  1353
                /* Ctrl-+ double the size of the window */
aschiffler@6727
  1354
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1355
                if (window) {
aschiffler@6727
  1356
                    int w, h;
aschiffler@6727
  1357
                    SDL_GetWindowSize(window, &w, &h);
aschiffler@6727
  1358
                    SDL_SetWindowSize(window, w*2, h*2);
aschiffler@6727
  1359
                }
aschiffler@6727
  1360
            }
aschiffler@6727
  1361
            break;
aschiffler@6727
  1362
        case SDLK_MINUS:
jorgen@8108
  1363
            if (withControl) {
philipp@7474
  1364
                /* Ctrl-- half the size of the window */
aschiffler@6727
  1365
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1366
                if (window) {
aschiffler@6727
  1367
                    int w, h;
aschiffler@6727
  1368
                    SDL_GetWindowSize(window, &w, &h);
aschiffler@6727
  1369
                    SDL_SetWindowSize(window, w/2, h/2);
aschiffler@6727
  1370
                }
aschiffler@6727
  1371
            }
aschiffler@6727
  1372
            break;
icculus@10025
  1373
        case SDLK_o:
icculus@10025
  1374
            if (withControl) {
icculus@10025
  1375
                /* Ctrl-O (or Ctrl-Shift-O) changes window opacity. */
icculus@10025
  1376
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
icculus@10025
  1377
                if (window) {
icculus@10025
  1378
                    float opacity;
icculus@10025
  1379
                    if (SDL_GetWindowOpacity(window, &opacity) == 0) {
icculus@10025
  1380
                        if (withShift) {
icculus@10025
  1381
                            opacity += 0.20f;
icculus@10025
  1382
                        } else {
icculus@10025
  1383
                            opacity -= 0.20f;
icculus@10025
  1384
                        }
icculus@10025
  1385
                        SDL_SetWindowOpacity(window, opacity);
icculus@10025
  1386
                    }
icculus@10025
  1387
                }
icculus@10025
  1388
            }
icculus@10025
  1389
            break;
icculus@10025
  1390
aschiffler@6727
  1391
        case SDLK_c:
jorgen@8108
  1392
            if (withControl) {
aschiffler@6727
  1393
                /* Ctrl-C copy awesome text! */
aschiffler@6727
  1394
                SDL_SetClipboardText("SDL rocks!\nYou know it!");
aschiffler@6727
  1395
                printf("Copied text to clipboard\n");
aschiffler@6727
  1396
            }
jorgen@8108
  1397
            if (withAlt) {
slouken@7141
  1398
                /* Alt-C toggle a render clip rectangle */
slouken@7141
  1399
                for (i = 0; i < state->num_windows; ++i) {
slouken@7141
  1400
                    int w, h;
slouken@7141
  1401
                    if (state->renderers[i]) {
slouken@7141
  1402
                        SDL_Rect clip;
slouken@7141
  1403
                        SDL_GetWindowSize(state->windows[i], &w, &h);
slouken@7141
  1404
                        SDL_RenderGetClipRect(state->renderers[i], &clip);
slouken@7141
  1405
                        if (SDL_RectEmpty(&clip)) {
slouken@7141
  1406
                            clip.x = w/4;
slouken@7141
  1407
                            clip.y = h/4;
slouken@7141
  1408
                            clip.w = w/2;
slouken@7141
  1409
                            clip.h = h/2;
slouken@7141
  1410
                            SDL_RenderSetClipRect(state->renderers[i], &clip);
slouken@7141
  1411
                        } else {
slouken@7141
  1412
                            SDL_RenderSetClipRect(state->renderers[i], NULL);
slouken@7141
  1413
                        }
slouken@7141
  1414
                    }
slouken@7141
  1415
                }
slouken@7141
  1416
            }
icculus@8927
  1417
            if (withShift) {
icculus@8927
  1418
                SDL_Window *current_win = SDL_GetKeyboardFocus();
icculus@8927
  1419
                if (current_win) {
icculus@8927
  1420
                    const SDL_bool shouldCapture = (SDL_GetWindowFlags(current_win) & SDL_WINDOW_MOUSE_CAPTURE) == 0;
icculus@8927
  1421
                    const int rc = SDL_CaptureMouse(shouldCapture);
icculus@8939
  1422
                    SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", (rc == 0) ? "succeeded" : "failed");
icculus@8927
  1423
                }
icculus@8927
  1424
            }
aschiffler@6727
  1425
            break;
aschiffler@6727
  1426
        case SDLK_v:
jorgen@8108
  1427
            if (withControl) {
aschiffler@6727
  1428
                /* Ctrl-V paste awesome text! */
aschiffler@6727
  1429
                char *text = SDL_GetClipboardText();
aschiffler@6727
  1430
                if (*text) {
aschiffler@6727
  1431
                    printf("Clipboard: %s\n", text);
aschiffler@6727
  1432
                } else {
aschiffler@6727
  1433
                    printf("Clipboard is empty\n");
aschiffler@6727
  1434
                }
aschiffler@6727
  1435
                SDL_free(text);
aschiffler@6727
  1436
            }
aschiffler@6727
  1437
            break;
aschiffler@6727
  1438
        case SDLK_g:
jorgen@8108
  1439
            if (withControl) {
aschiffler@6727
  1440
                /* Ctrl-G toggle grab */
aschiffler@6727
  1441
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1442
                if (window) {
aschiffler@7249
  1443
                    SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window) ? SDL_TRUE : SDL_FALSE);
aschiffler@6727
  1444
                }
aschiffler@6727
  1445
            }
aschiffler@6727
  1446
            break;
aschiffler@6727
  1447
        case SDLK_m:
jorgen@8108
  1448
            if (withControl) {
aschiffler@6727
  1449
                /* Ctrl-M maximize */
aschiffler@6727
  1450
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1451
                if (window) {
aschiffler@6727
  1452
                    Uint32 flags = SDL_GetWindowFlags(window);
aschiffler@6727
  1453
                    if (flags & SDL_WINDOW_MAXIMIZED) {
aschiffler@6727
  1454
                        SDL_RestoreWindow(window);
aschiffler@6727
  1455
                    } else {
aschiffler@6727
  1456
                        SDL_MaximizeWindow(window);
aschiffler@6727
  1457
                    }
aschiffler@6727
  1458
                }
aschiffler@6727
  1459
            }
aschiffler@6727
  1460
            break;
aschiffler@6727
  1461
        case SDLK_r:
jorgen@8108
  1462
            if (withControl) {
aschiffler@6727
  1463
                /* Ctrl-R toggle mouse relative mode */
aschiffler@7249
  1464
                SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode() ? SDL_TRUE : SDL_FALSE);
aschiffler@6727
  1465
            }
aschiffler@6727
  1466
            break;
aschiffler@6727
  1467
        case SDLK_z:
jorgen@8108
  1468
            if (withControl) {
aschiffler@6727
  1469
                /* Ctrl-Z minimize */
aschiffler@6727
  1470
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1471
                if (window) {
aschiffler@6727
  1472
                    SDL_MinimizeWindow(window);
aschiffler@6727
  1473
                }
aschiffler@6727
  1474
            }
aschiffler@6727
  1475
            break;
aschiffler@6727
  1476
        case SDLK_RETURN:
jorgen@8108
  1477
            if (withControl) {
aschiffler@6727
  1478
                /* Ctrl-Enter toggle fullscreen */
aschiffler@6727
  1479
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1480
                if (window) {
aschiffler@6727
  1481
                    Uint32 flags = SDL_GetWindowFlags(window);
aschiffler@6727
  1482
                    if (flags & SDL_WINDOW_FULLSCREEN) {
aschiffler@6727
  1483
                        SDL_SetWindowFullscreen(window, SDL_FALSE);
aschiffler@6727
  1484
                    } else {
slouken@7949
  1485
                        SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
aschiffler@6727
  1486
                    }
aschiffler@6727
  1487
                }
jorgen@8108
  1488
            } else if (withAlt) {
philipp@7474
  1489
                /* Alt-Enter toggle fullscreen desktop */
urkle@7340
  1490
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
urkle@7340
  1491
                if (window) {
urkle@7340
  1492
                    Uint32 flags = SDL_GetWindowFlags(window);
urkle@7340
  1493
                    if (flags & SDL_WINDOW_FULLSCREEN) {
urkle@7340
  1494
                        SDL_SetWindowFullscreen(window, SDL_FALSE);
urkle@7340
  1495
                    } else {
urkle@7340
  1496
                        SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
urkle@7340
  1497
                    }
urkle@7340
  1498
                }
jorgen@8109
  1499
            } else if (withShift) {
jorgen@8109
  1500
                /* Shift-Enter toggle fullscreen desktop / fullscreen */
jorgen@8109
  1501
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
jorgen@8109
  1502
                if (window) {
jorgen@8109
  1503
                    Uint32 flags = SDL_GetWindowFlags(window);
jorgen@8109
  1504
                    if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
jorgen@8109
  1505
                        SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
jorgen@8109
  1506
                    } else {
jorgen@8109
  1507
                        SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
jorgen@8109
  1508
                    }
jorgen@8109
  1509
                }
aschiffler@6727
  1510
            }
jorgen@8109
  1511
aschiffler@6727
  1512
            break;
aschiffler@6727
  1513
        case SDLK_b:
jorgen@8108
  1514
            if (withControl) {
aschiffler@6727
  1515
                /* Ctrl-B toggle window border */
aschiffler@6727
  1516
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1517
                if (window) {
aschiffler@6727
  1518
                    const Uint32 flags = SDL_GetWindowFlags(window);
aschiffler@7249
  1519
                    const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0) ? SDL_TRUE : SDL_FALSE;
aschiffler@6727
  1520
                    SDL_SetWindowBordered(window, b);
aschiffler@6727
  1521
                }
aschiffler@6727
  1522
            }
aschiffler@6727
  1523
            break;
icculus@8945
  1524
        case SDLK_a:
icculus@8945
  1525
            if (withControl) {
icculus@8945
  1526
                /* Ctrl-A reports absolute mouse position. */
icculus@8945
  1527
                int x, y;
icculus@8952
  1528
                const Uint32 mask = SDL_GetGlobalMouseState(&x, &y);
icculus@8945
  1529
                SDL_Log("ABSOLUTE MOUSE: (%d, %d)%s%s%s%s%s\n", x, y,
icculus@8945
  1530
                        (mask & SDL_BUTTON_LMASK) ? " [LBUTTON]" : "",
icculus@8945
  1531
                        (mask & SDL_BUTTON_MMASK) ? " [MBUTTON]" : "",
icculus@8945
  1532
                        (mask & SDL_BUTTON_RMASK) ? " [RBUTTON]" : "",
icculus@8945
  1533
                        (mask & SDL_BUTTON_X1MASK) ? " [X2BUTTON]" : "",
icculus@8945
  1534
                        (mask & SDL_BUTTON_X2MASK) ? " [X2BUTTON]" : "");
icculus@8945
  1535
            }
icculus@8945
  1536
            break;
slouken@7191
  1537
        case SDLK_0:
jorgen@8108
  1538
            if (withControl) {
aschiffler@6727
  1539
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
aschiffler@6727
  1540
                SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
aschiffler@6727
  1541
            }
aschiffler@6727
  1542
            break;
jorgen@7092
  1543
        case SDLK_1:
jorgen@8108
  1544
            if (withControl) {
jorgen@7092
  1545
                FullscreenTo(0, event->key.windowID);
jorgen@7092
  1546
            }
jorgen@7092
  1547
            break;
jorgen@7092
  1548
        case SDLK_2:
jorgen@8108
  1549
            if (withControl) {
jorgen@7092
  1550
                FullscreenTo(1, event->key.windowID);
jorgen@7092
  1551
            }
jorgen@7092
  1552
            break;
aschiffler@6727
  1553
        case SDLK_ESCAPE:
aschiffler@6727
  1554
            *done = 1;
aschiffler@6727
  1555
            break;
jorgen@7092
  1556
        case SDLK_SPACE:
jorgen@7092
  1557
        {
jorgen@7092
  1558
            char message[256];
jorgen@7092
  1559
            SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
jorgen@7092
  1560
jorgen@7092
  1561
            SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
jorgen@7092
  1562
            SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window);
jorgen@7092
  1563
            break;
jorgen@7092
  1564
        }
aschiffler@6727
  1565
        default:
aschiffler@6727
  1566
            break;
aschiffler@6727
  1567
        }
aschiffler@6727
  1568
        break;
jorgen@8108
  1569
    }
aschiffler@6727
  1570
    case SDL_QUIT:
aschiffler@6727
  1571
        *done = 1;
aschiffler@6727
  1572
        break;
jorgen@7092
  1573
    case SDL_MOUSEMOTION:
jorgen@7092
  1574
        lastEvent = event->motion;
slouken@7191
  1575
        break;
aschiffler@6727
  1576
    }
aschiffler@6727
  1577
}
aschiffler@6727
  1578
aschiffler@6727
  1579
void
aschiffler@6727
  1580
SDLTest_CommonQuit(SDLTest_CommonState * state)
aschiffler@6727
  1581
{
aschiffler@6727
  1582
    int i;
aschiffler@6727
  1583
slouken@7719
  1584
    SDL_free(state->windows);
slouken@8011
  1585
    if (state->targets) {
slouken@8011
  1586
        for (i = 0; i < state->num_windows; ++i) {
slouken@8011
  1587
            if (state->targets[i]) {
slouken@8011
  1588
                SDL_DestroyTexture(state->targets[i]);
slouken@8011
  1589
            }
slouken@8011
  1590
        }
slouken@8011
  1591
        SDL_free(state->targets);
slouken@8011
  1592
    }
aschiffler@6727
  1593
    if (state->renderers) {
aschiffler@6727
  1594
        for (i = 0; i < state->num_windows; ++i) {
aschiffler@6727
  1595
            if (state->renderers[i]) {
aschiffler@6727
  1596
                SDL_DestroyRenderer(state->renderers[i]);
aschiffler@6727
  1597
            }
aschiffler@6727
  1598
        }
aschiffler@6727
  1599
        SDL_free(state->renderers);
aschiffler@6727
  1600
    }
aschiffler@6727
  1601
    if (state->flags & SDL_INIT_VIDEO) {
aschiffler@6727
  1602
        SDL_VideoQuit();
aschiffler@6727
  1603
    }
aschiffler@6727
  1604
    if (state->flags & SDL_INIT_AUDIO) {
aschiffler@6727
  1605
        SDL_AudioQuit();
aschiffler@6727
  1606
    }
aschiffler@6727
  1607
    SDL_free(state);
slouken@8268
  1608
    SDL_Quit();
aschiffler@6727
  1609
}
aschiffler@6727
  1610
aschiffler@6727
  1611
/* vi: set ts=4 sw=4 expandtab: */