test/testwm2.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 17 Aug 2016 21:04:50 +0200
changeset 10275 ba7dc3ebb81e
parent 10193 75cd0fc3fec2
permissions -rw-r--r--
Emscripten: Fixed opening previously closed joystick.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     1
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9922
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     3
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     4
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     6
  arising from the use of this software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     7
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
    10
  freely.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5246
diff changeset
    11
*/
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
1933
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    13
#include <stdlib.h>
7ee5297340f7 Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    14
#include <stdio.h>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    16
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    17
#include <emscripten/emscripten.h>
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    18
#endif
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    19
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6677
diff changeset
    20
#include "SDL_test_common.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6677
diff changeset
    22
static SDLTest_CommonState *state;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    23
int done;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    25
static const char *cursorNames[] = {
6677
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    26
        "arrow",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    27
        "ibeam",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    28
        "wait",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    29
        "crosshair",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    30
        "waitarrow",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    31
        "sizeNWSE",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    32
        "sizeNESW",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    33
        "sizeWE",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    34
        "sizeNS",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    35
        "sizeALL",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    36
        "NO",
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    37
        "hand",
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    38
};
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    39
int system_cursor = -1;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    40
SDL_Cursor *cursor = NULL;
7034
3a5a53435ebd Patched test apps to compile with C89 compilers (thanks, Axel!).
Ryan C. Gordon <icculus@icculus.org>
parents: 6788
diff changeset
    41
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    42
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    43
static void
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    44
quit(int rc)
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    45
{
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    46
    SDLTest_CommonQuit(state);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    47
    exit(rc);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    48
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    50
void
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    51
loop()
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    52
{
10193
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
    53
    int i;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
    54
    SDL_Event event;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
        /* Check for events */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
        while (SDL_PollEvent(&event)) {
6785
c094c438c0a6 Switched the test code over to use the common functions in the test library.
Sam Lantinga <slouken@libsdl.org>
parents: 6677
diff changeset
    57
            SDLTest_CommonEvent(state, &event, &done);
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    58
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    59
            if (event.type == SDL_WINDOWEVENT) {
6788
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6787
diff changeset
    60
                if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6787
diff changeset
    61
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6787
diff changeset
    62
                    if (window) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    63
                        SDL_Log("Window %d resized to %dx%d\n",
6788
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6787
diff changeset
    64
                            event.window.windowID,
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6787
diff changeset
    65
                            event.window.data1,
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6787
diff changeset
    66
                            event.window.data2);
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6787
diff changeset
    67
                    }
036f53f2f5aa Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Sam Lantinga <slouken@libsdl.org>
parents: 6787
diff changeset
    68
                }
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    69
                if (event.window.event == SDL_WINDOWEVENT_MOVED) {
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    70
                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    71
                    if (window) {
7639
9406b7dd2f2d Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 7517
diff changeset
    72
                        SDL_Log("Window %d moved to %d,%d (display %s)\n",
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    73
                            event.window.windowID,
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    74
                            event.window.data1,
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    75
                            event.window.data2,
6787
95a4c5a5464c Added SDL_GetDisplayName(), with implementation for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 6786
diff changeset
    76
                            SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
5246
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    77
                    }
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    78
                }
58265e606e4e Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents: 3338
diff changeset
    79
            }
6677
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    80
            if (event.type == SDL_KEYUP) {
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    81
                SDL_bool updateCursor = SDL_FALSE;
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    82
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    83
                if (event.key.keysym.sym == SDLK_LEFT) {
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    84
                    --system_cursor;
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    85
                    if (system_cursor < 0) {
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    86
                        system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    87
                    }
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    88
                    updateCursor = SDL_TRUE;
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    89
                } else if (event.key.keysym.sym == SDLK_RIGHT) {
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    90
                    ++system_cursor;
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    91
                    if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    92
                        system_cursor = 0;
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    93
                    }
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    94
                    updateCursor = SDL_TRUE;
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    95
                }
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    96
                if (updateCursor) {
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    97
                    SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    98
                    SDL_FreeCursor(cursor);
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
    99
                    cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   100
                    SDL_SetCursor(cursor);
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   101
                }
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   102
            }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
        }
10193
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   104
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   105
        for (i = 0; i < state->num_windows; ++i) {
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   106
            SDL_Renderer *renderer = state->renderers[i];
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   107
            SDL_RenderClear(renderer);
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   108
            SDL_RenderPresent(renderer);
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   109
        }
9607
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   110
#ifdef __EMSCRIPTEN__
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   111
    if (done) {
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   112
        emscripten_cancel_main_loop();
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   113
    }
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
   114
#endif
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   115
}
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   116
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   117
int
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   118
main(int argc, char *argv[])
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   119
{
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   120
    int i;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   121
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   122
    /* Enable standard application logging */
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   123
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   124
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   125
    SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   126
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   127
    /* Initialize test framework */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   128
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   129
    if (!state) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   130
        return 1;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   132
    for (i = 1; i < argc;) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   133
        int consumed;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   134
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   135
        consumed = SDLTest_CommonArg(state, i);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   136
        if (consumed == 0) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   137
            consumed = -1;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   138
        }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   139
        if (consumed < 0) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   140
            SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   141
            quit(1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   142
        }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   143
        i += consumed;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   144
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   145
    if (!SDLTest_CommonInit(state)) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   146
        quit(2);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   147
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   148
10193
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   149
    for (i = 0; i < state->num_windows; ++i) {
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   150
        SDL_Renderer *renderer = state->renderers[i];
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   151
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   152
        SDL_RenderClear(renderer);
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   153
    }
75cd0fc3fec2 Tests: Mir needs the window to swap at lease 1 frame for the cursor to show. So render in testwm2
Brandon Schaefer <brandon.schaefer@canonical.com>
parents: 9998
diff changeset
   154
 
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   155
    /* Main render loop */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   156
    done = 0;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   157
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   158
    emscripten_set_main_loop(loop, 0, 1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   159
#else
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   160
    while (!done) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   161
        loop();
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   162
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8149
diff changeset
   163
#endif
6677
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   164
    SDL_FreeCursor(cursor);
c3202c29e352 Added code to testwm2 to test the system cursor support
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
   165
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
    quit(0);
7663
53fe1b64eb2d More non C89 compliant comments
Gabriel Jacobo <gabomdq@gmail.com>
parents: 7639
diff changeset
   167
    /* keep the compiler happy ... */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7034
diff changeset
   168
    return(0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
/* vi: set ts=4 sw=4 expandtab: */