test/testrelative.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 25 Apr 2013 00:26:17 -0700
changeset 7110 2a98852fd58d
parent 6785 c094c438c0a6
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 /* Simple program:  Test relative mouse motion */
    14 
    15 #include <stdlib.h>
    16 #include <stdio.h>
    17 #include <time.h>
    18 
    19 #include "SDL_test_common.h"
    20 
    21 
    22 static SDLTest_CommonState *state;
    23 static SDL_Rect rect;
    24 
    25 static void
    26 DrawRects(SDL_Renderer * renderer)
    27 {
    28     SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
    29     SDL_RenderFillRect(renderer,&rect);
    30 }
    31 
    32 int
    33 main(int argc, char *argv[])
    34 {
    35     int i, done;
    36     SDL_Event event;
    37 
    38  
    39     /* Initialize test framework */
    40     state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    41     if (!state) {
    42         return 1;
    43     }
    44     for (i = 1; i < argc;i++) {
    45         SDLTest_CommonArg(state, i);
    46     }
    47     if (!SDLTest_CommonInit(state)) {
    48         return 2;
    49     }
    50 
    51     /* Create the windows and initialize the renderers */
    52     for (i = 0; i < state->num_windows; ++i) {
    53         SDL_Renderer *renderer = state->renderers[i];
    54         SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
    55         SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    56         SDL_RenderClear(renderer);
    57     }
    58 
    59     srand((unsigned int)time(NULL));
    60     if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
    61         return 3;
    62     };
    63 
    64     rect.x = DEFAULT_WINDOW_WIDTH / 2;
    65     rect.y = DEFAULT_WINDOW_HEIGHT / 2;
    66     rect.w = 10;
    67     rect.h = 10;
    68     /* Main render loop */
    69     done = 0;
    70     while (!done) {
    71         /* Check for events */
    72         while (SDL_PollEvent(&event)) {
    73             SDLTest_CommonEvent(state, &event, &done);
    74             switch(event.type) {
    75                 case SDL_MOUSEMOTION:
    76                 {
    77                     /*printf("mouse motion ABS x %d y %d REL x %d y %d\n",event.motion.x,event.motion.y,event.motion.xrel,event.motion.yrel);*/
    78                     rect.x += event.motion.xrel;
    79                     rect.y += event.motion.yrel;
    80 
    81                 }
    82                 break;
    83             }
    84         }
    85         for (i = 0; i < state->num_windows; ++i) {
    86             SDL_Renderer *renderer = state->renderers[i];
    87             SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    88             SDL_RenderClear(renderer);
    89 
    90             DrawRects(renderer);
    91 
    92             SDL_RenderPresent(renderer);
    93         }
    94     }
    95 
    96     SDLTest_CommonQuit(state);
    97     return 0;
    98 }
    99 
   100 /* vi: set ts=4 sw=4 expandtab: */