test/testwm2.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 25 Apr 2013 00:26:17 -0700
changeset 7110 2a98852fd58d
parent 7034 3a5a53435ebd
child 7191 75360622e65f
permissions -rw-r--r--
Fixed bug 1582 - Allow disabling SDL_VIDEO_DRIVER_WINDOWS

Marcus von Appen

Trying to build SDL 2.x (HG) on Win32 platforms with either VS.NET or MinGW requires one to have the video subsystem and SDL_VIDEO_DRIVER_WINDOWS flag enabled due to the helper window creation routines.

The attached patch changes the helper window creation behaviour, so that one can build SDL2 without the video subsystem or Windows video drivers on Win32 platforms.
     1 /*
     2   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     3 
     4   This software is provided 'as-is', without any express or implied
     5   warranty.  In no event will the authors be held liable for any damages
     6   arising from the use of this software.
     7 
     8   Permission is granted to anyone to use this software for any purpose,
     9   including commercial applications, and to alter it and redistribute it
    10   freely.
    11 */
    12 
    13 #include <stdlib.h>
    14 #include <stdio.h>
    15 
    16 #include "SDL_test_common.h"
    17 
    18 static SDLTest_CommonState *state;
    19 
    20 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    21 static void
    22 quit(int rc)
    23 {
    24     SDLTest_CommonQuit(state);
    25     exit(rc);
    26 }
    27 
    28 int
    29 main(int argc, char *argv[])
    30 {
    31     static const char *cursorNames[] = {
    32         "arrow",
    33         "ibeam",
    34         "wait",
    35         "crosshair",
    36         "waitarrow",
    37         "sizeNWSE",
    38         "sizeNESW",
    39         "sizeWE",
    40         "sizeNS",
    41         "sizeALL",
    42         "NO",
    43         "hand",
    44     };
    45 
    46     int i, done;
    47     SDL_Event event;
    48     int system_cursor = -1;
    49     SDL_Cursor *cursor = NULL;
    50 
    51     SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
    52 
    53     /* Initialize test framework */
    54     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    55     if (!state) {
    56         return 1;
    57     }
    58     state->skip_renderer = SDL_TRUE;
    59     for (i = 1; i < argc;) {
    60         int consumed;
    61 
    62         consumed = SDLTest_CommonArg(state, i);
    63         if (consumed == 0) {
    64             consumed = -1;
    65         }
    66         if (consumed < 0) {
    67             fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
    68             quit(1);
    69         }
    70         i += consumed;
    71     }
    72     if (!SDLTest_CommonInit(state)) {
    73         quit(2);
    74     }
    75 
    76     /* Main render loop */
    77     done = 0;
    78     while (!done) {
    79         /* Check for events */
    80         while (SDL_PollEvent(&event)) {
    81             SDLTest_CommonEvent(state, &event, &done);
    82 
    83             if (event.type == SDL_WINDOWEVENT) {
    84                 if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
    85                     SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
    86                     if (window) {
    87                         printf("Window %d resized to %dx%d\n",
    88                             event.window.windowID,
    89                             event.window.data1,
    90                             event.window.data2);
    91                     }
    92                 }
    93                 if (event.window.event == SDL_WINDOWEVENT_MOVED) {
    94                     SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
    95                     if (window) {
    96                         printf("Window %d moved to %d,%d (display %s)\n",
    97                             event.window.windowID,
    98                             event.window.data1,
    99                             event.window.data2,
   100                             SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
   101                     }
   102                 }
   103             }
   104             if (event.type == SDL_KEYUP) {
   105                 SDL_bool updateCursor = SDL_FALSE;
   106 
   107                 if (event.key.keysym.sym == SDLK_LEFT) {
   108                     --system_cursor;
   109                     if (system_cursor < 0) {
   110                         system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
   111                     }
   112                     updateCursor = SDL_TRUE;
   113                 } else if (event.key.keysym.sym == SDLK_RIGHT) {
   114                     ++system_cursor;
   115                     if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
   116                         system_cursor = 0;
   117                     }
   118                     updateCursor = SDL_TRUE;
   119                 }
   120                 if (updateCursor) {
   121                     SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
   122                     SDL_FreeCursor(cursor);
   123                     cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
   124                     SDL_SetCursor(cursor);
   125                 }
   126             }
   127         }
   128     }
   129     SDL_FreeCursor(cursor);
   130 
   131     quit(0);
   132 	// keep the compiler happy ...
   133 	return(0);
   134 }
   135 
   136 /* vi: set ts=4 sw=4 expandtab: */