test/testrelative.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 05 Jun 2013 22:33:10 -0700
changeset 7286 04087a99e3f4
parent 7191 75360622e65f
child 7517 965d57022c01
permissions -rw-r--r--
Added testautomation to the Visual Studio 2008 project.
     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: */