src/test/SDL_test_common.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 11 Aug 2017 10:42:26 -0700
changeset 11221 4753f2320927
parent 11012 c2f18f1f7e97
child 11257 7561c9adebd4
permissions -rw-r--r--
Fixed bug 3646 - SDL_test_common.c: Add key bindings for testing SDL_SetWindowPosition

Eric Wasylishen

Alt-Up/Down/Left/Right switches between displays using SDL_WINDOWPOS_CENTERED_DISPLAY

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