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.
slouken@6311
     1
/*
slouken@6311
     2
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@6311
     3
slouken@6311
     4
  This software is provided 'as-is', without any express or implied
slouken@6311
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@6311
     6
  arising from the use of this software.
slouken@6311
     7
slouken@6311
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@6311
     9
  including commercial applications, and to alter it and redistribute it
slouken@6311
    10
  freely.
slouken@6311
    11
*/
slouken@6311
    12
slouken@6311
    13
/* Simple program:  Test relative mouse motion */
slouken@6311
    14
slouken@6311
    15
#include <stdlib.h>
slouken@6311
    16
#include <stdio.h>
slouken@6311
    17
#include <time.h>
slouken@6311
    18
slouken@6785
    19
#include "SDL_test_common.h"
slouken@6311
    20
slouken@6311
    21
slouken@6785
    22
static SDLTest_CommonState *state;
slouken@6311
    23
static SDL_Rect rect;
slouken@6311
    24
slouken@6311
    25
static void
slouken@6311
    26
DrawRects(SDL_Renderer * renderer)
slouken@6311
    27
{
slouken@6311
    28
    SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
slouken@6311
    29
    SDL_RenderFillRect(renderer,&rect);
slouken@6311
    30
}
slouken@6311
    31
slouken@6311
    32
int
slouken@6311
    33
main(int argc, char *argv[])
slouken@6311
    34
{
slouken@6311
    35
    int i, done;
slouken@6311
    36
    SDL_Event event;
slouken@6311
    37
slouken@6311
    38
 
slouken@6311
    39
    /* Initialize test framework */
slouken@6785
    40
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
slouken@6311
    41
    if (!state) {
slouken@6311
    42
        return 1;
slouken@6311
    43
    }
dimitris@6318
    44
    for (i = 1; i < argc;i++) {
slouken@6785
    45
        SDLTest_CommonArg(state, i);
dimitris@6318
    46
    }
slouken@6785
    47
    if (!SDLTest_CommonInit(state)) {
slouken@6311
    48
        return 2;
slouken@6311
    49
    }
slouken@6311
    50
slouken@6311
    51
    /* Create the windows and initialize the renderers */
slouken@6311
    52
    for (i = 0; i < state->num_windows; ++i) {
slouken@6311
    53
        SDL_Renderer *renderer = state->renderers[i];
slouken@6311
    54
        SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
slouken@6311
    55
        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
slouken@6311
    56
        SDL_RenderClear(renderer);
slouken@6311
    57
    }
slouken@6311
    58
slouken@6311
    59
    srand((unsigned int)time(NULL));
dimitris@6316
    60
    if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
dimitris@6316
    61
        return 3;
dimitris@6316
    62
    };
slouken@6311
    63
slouken@6311
    64
    rect.x = DEFAULT_WINDOW_WIDTH / 2;
slouken@6311
    65
    rect.y = DEFAULT_WINDOW_HEIGHT / 2;
slouken@6311
    66
    rect.w = 10;
slouken@6311
    67
    rect.h = 10;
slouken@6311
    68
    /* Main render loop */
slouken@6311
    69
    done = 0;
slouken@6311
    70
    while (!done) {
slouken@6311
    71
        /* Check for events */
slouken@6311
    72
        while (SDL_PollEvent(&event)) {
slouken@6785
    73
            SDLTest_CommonEvent(state, &event, &done);
slouken@6311
    74
            switch(event.type) {
slouken@6311
    75
                case SDL_MOUSEMOTION:
slouken@6311
    76
                {
slouken@6311
    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);*/
slouken@6311
    78
                    rect.x += event.motion.xrel;
slouken@6311
    79
                    rect.y += event.motion.yrel;
slouken@6311
    80
slouken@6311
    81
                }
slouken@6311
    82
                break;
slouken@6311
    83
            }
slouken@6311
    84
        }
slouken@6311
    85
        for (i = 0; i < state->num_windows; ++i) {
slouken@6311
    86
            SDL_Renderer *renderer = state->renderers[i];
slouken@6311
    87
            SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
slouken@6311
    88
            SDL_RenderClear(renderer);
slouken@6311
    89
slouken@6311
    90
            DrawRects(renderer);
slouken@6311
    91
slouken@6311
    92
            SDL_RenderPresent(renderer);
slouken@6311
    93
        }
slouken@6311
    94
    }
slouken@6311
    95
slouken@6785
    96
    SDLTest_CommonQuit(state);
slouken@6311
    97
    return 0;
slouken@6311
    98
}
slouken@6311
    99
slouken@6311
   100
/* vi: set ts=4 sw=4 expandtab: */