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