Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
100 lines (81 loc) · 2.58 KB

testrelative.c

File metadata and controls

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