test/testrelative.c
changeset 6311 4e5e46f43438
child 6316 a89c79a3f0cd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testrelative.c	Wed May 30 11:25:35 2012 -0400
     1.3 @@ -0,0 +1,95 @@
     1.4 +/*
     1.5 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     1.6 +
     1.7 +  This software is provided 'as-is', without any express or implied
     1.8 +  warranty.  In no event will the authors be held liable for any damages
     1.9 +  arising from the use of this software.
    1.10 +
    1.11 +  Permission is granted to anyone to use this software for any purpose,
    1.12 +  including commercial applications, and to alter it and redistribute it
    1.13 +  freely.
    1.14 +*/
    1.15 +
    1.16 +/* Simple program:  Test relative mouse motion */
    1.17 +
    1.18 +#include <stdlib.h>
    1.19 +#include <stdio.h>
    1.20 +#include <time.h>
    1.21 +
    1.22 +#include "common.h"
    1.23 +
    1.24 +
    1.25 +static CommonState *state;
    1.26 +static SDL_Rect rect;
    1.27 +
    1.28 +static void
    1.29 +DrawRects(SDL_Renderer * renderer)
    1.30 +{
    1.31 +    SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
    1.32 +    SDL_RenderFillRect(renderer,&rect);
    1.33 +}
    1.34 +
    1.35 +int
    1.36 +main(int argc, char *argv[])
    1.37 +{
    1.38 +    int i, done;
    1.39 +    SDL_Event event;
    1.40 +
    1.41 + 
    1.42 +    /* Initialize test framework */
    1.43 +    state = CommonCreateState(argv, SDL_INIT_VIDEO);
    1.44 +    if (!state) {
    1.45 +        return 1;
    1.46 +    }
    1.47 +    if (!CommonInit(state)) {
    1.48 +        return 2;
    1.49 +    }
    1.50 +
    1.51 +    /* Create the windows and initialize the renderers */
    1.52 +    for (i = 0; i < state->num_windows; ++i) {
    1.53 +        SDL_Renderer *renderer = state->renderers[i];
    1.54 +        SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
    1.55 +        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.56 +        SDL_RenderClear(renderer);
    1.57 +    }
    1.58 +
    1.59 +    srand((unsigned int)time(NULL));
    1.60 +    SDL_SetRelativeMouseMode(SDL_TRUE);
    1.61 +
    1.62 +    rect.x = DEFAULT_WINDOW_WIDTH / 2;
    1.63 +    rect.y = DEFAULT_WINDOW_HEIGHT / 2;
    1.64 +    rect.w = 10;
    1.65 +    rect.h = 10;
    1.66 +    /* Main render loop */
    1.67 +    done = 0;
    1.68 +    while (!done) {
    1.69 +        /* Check for events */
    1.70 +        while (SDL_PollEvent(&event)) {
    1.71 +            CommonEvent(state, &event, &done);
    1.72 +            switch(event.type) {
    1.73 +                case SDL_MOUSEMOTION:
    1.74 +                {
    1.75 +                    /*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);*/
    1.76 +                    rect.x += event.motion.xrel;
    1.77 +                    rect.y += event.motion.yrel;
    1.78 +
    1.79 +                }
    1.80 +                break;
    1.81 +            }
    1.82 +        }
    1.83 +        for (i = 0; i < state->num_windows; ++i) {
    1.84 +            SDL_Renderer *renderer = state->renderers[i];
    1.85 +            SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.86 +            SDL_RenderClear(renderer);
    1.87 +
    1.88 +            DrawRects(renderer);
    1.89 +
    1.90 +            SDL_RenderPresent(renderer);
    1.91 +        }
    1.92 +    }
    1.93 +
    1.94 +    CommonQuit(state);
    1.95 +    return 0;
    1.96 +}
    1.97 +
    1.98 +/* vi: set ts=4 sw=4 expandtab: */