comparison test/testjoystick.c @ 1855:5ff2c01e475e

Moved DirectInput joystick code to 1.3 branch
author Sam Lantinga <slouken@libsdl.org>
date Sun, 21 May 2006 17:26:40 +0000
parents 2280e314a978
children c121d94672cb 3d9040dcc47e
comparison
equal deleted inserted replaced
1854:2280e314a978 1855:5ff2c01e475e
15 SDL_Surface *screen; 15 SDL_Surface *screen;
16 const char *name; 16 const char *name;
17 int i, done; 17 int i, done;
18 SDL_Event event; 18 SDL_Event event;
19 int x, y, draw; 19 int x, y, draw;
20 SDL_Rect axis_area[6][2]; 20 SDL_Rect axis_area[2];
21 21
22 /* Set a video mode to display joystick axis position */ 22 /* Set a video mode to display joystick axis position */
23 screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0); 23 screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0);
24 if ( screen == NULL ) { 24 if ( screen == NULL ) {
25 fprintf(stderr, "Couldn't set video mode: %s\n",SDL_GetError()); 25 fprintf(stderr, "Couldn't set video mode: %s\n",SDL_GetError());
108 SDL_FillRect(screen, &area, 0x0000); 108 SDL_FillRect(screen, &area, 0x0000);
109 } 109 }
110 SDL_UpdateRects(screen, 1, &area); 110 SDL_UpdateRects(screen, 1, &area);
111 } 111 }
112 112
113 for ( i=0; i<SDL_JoystickNumAxes(joystick)/2 && i < SDL_arraysize(axis_area); ++i ) { 113 /* Erase previous axes */
114 /* Erase previous axes */ 114 SDL_FillRect(screen, &axis_area[draw], 0x0000);
115 SDL_FillRect(screen, &axis_area[i][draw], 0x0000);
116 115
117 /* Draw the X/Y axis */ 116 /* Draw the X/Y axis */
118 draw = !draw; 117 draw = !draw;
119 x = (((int)SDL_JoystickGetAxis(joystick, i*2+0))+32768); 118 x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768);
120 x *= SCREEN_WIDTH; 119 x *= SCREEN_WIDTH;
121 x /= 65535; 120 x /= 65535;
122 if ( x < 0 ) { 121 if ( x < 0 ) {
123 x = 0; 122 x = 0;
124 } else 123 } else
125 if ( x > (SCREEN_WIDTH-16) ) { 124 if ( x > (SCREEN_WIDTH-16) ) {
126 x = SCREEN_WIDTH-16; 125 x = SCREEN_WIDTH-16;
127 } 126 }
128 y = (((int)SDL_JoystickGetAxis(joystick, i*2+1))+32768); 127 y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
129 y *= SCREEN_HEIGHT; 128 y *= SCREEN_HEIGHT;
130 y /= 65535; 129 y /= 65535;
131 if ( y < 0 ) { 130 if ( y < 0 ) {
132 y = 0; 131 y = 0;
133 } else 132 } else
134 if ( y > (SCREEN_HEIGHT-16) ) { 133 if ( y > (SCREEN_HEIGHT-16) ) {
135 y = SCREEN_HEIGHT-16; 134 y = SCREEN_HEIGHT-16;
136 } 135 }
137 axis_area[i][draw].x = (Sint16)x; 136 axis_area[draw].x = (Sint16)x;
138 axis_area[i][draw].y = (Sint16)y; 137 axis_area[draw].y = (Sint16)y;
139 axis_area[i][draw].w = 16; 138 axis_area[draw].w = 16;
140 axis_area[i][draw].h = 16; 139 axis_area[draw].h = 16;
141 SDL_FillRect(screen, &axis_area[i][draw], 0xFFFF); 140 SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
142 141
143 SDL_UpdateRects(screen, 2, axis_area[i]); 142 SDL_UpdateRects(screen, 2, axis_area);
144 }
145 } 143 }
146 } 144 }
147 145
148 int main(int argc, char *argv[]) 146 int main(int argc, char *argv[])
149 { 147 {