test/testrelative.c
author Dimitris Zenios <dimitris.zenios@gmail.com>
Thu, 31 May 2012 13:37:02 +0300
changeset 6316 a89c79a3f0cd
parent 6311 4e5e46f43438
child 6318 49b2cb56db6e
permissions -rw-r--r--
1.Moved all xinput2 functionality to its own file
2.Implement touch events using Xinput2.Leave evtouch as a fallback when xinput2 is not supported
     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 "common.h"
    20 
    21 
    22 static 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 = CommonCreateState(argv, SDL_INIT_VIDEO);
    41     if (!state) {
    42         return 1;
    43     }
    44     if (!CommonInit(state)) {
    45         return 2;
    46     }
    47 
    48     /* Create the windows and initialize the renderers */
    49     for (i = 0; i < state->num_windows; ++i) {
    50         SDL_Renderer *renderer = state->renderers[i];
    51         SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
    52         SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    53         SDL_RenderClear(renderer);
    54     }
    55 
    56     srand((unsigned int)time(NULL));
    57     if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
    58         return 3;
    59     };
    60 
    61     rect.x = DEFAULT_WINDOW_WIDTH / 2;
    62     rect.y = DEFAULT_WINDOW_HEIGHT / 2;
    63     rect.w = 10;
    64     rect.h = 10;
    65     /* Main render loop */
    66     done = 0;
    67     while (!done) {
    68         /* Check for events */
    69         while (SDL_PollEvent(&event)) {
    70             CommonEvent(state, &event, &done);
    71             switch(event.type) {
    72                 case SDL_MOUSEMOTION:
    73                 {
    74                     /*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);*/
    75                     rect.x += event.motion.xrel;
    76                     rect.y += event.motion.yrel;
    77 
    78                 }
    79                 break;
    80             }
    81         }
    82         for (i = 0; i < state->num_windows; ++i) {
    83             SDL_Renderer *renderer = state->renderers[i];
    84             SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    85             SDL_RenderClear(renderer);
    86 
    87             DrawRects(renderer);
    88 
    89             SDL_RenderPresent(renderer);
    90         }
    91     }
    92 
    93     CommonQuit(state);
    94     return 0;
    95 }
    96 
    97 /* vi: set ts=4 sw=4 expandtab: */