comparison test/testjoystick.c @ 1854:2280e314a978

Closed bug #74 Added DirectInput joystick code, contributed by Glenn Maynard. This fixes a problem with the Windows Multimedia joystick driver not showing all 6 axes on a GameCube controller converter, which was donated by Jacob Kolding.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 21 May 2006 16:47:41 +0000
parents 74212992fb08
children 782fd950bd46 5ff2c01e475e
comparison
equal deleted inserted replaced
1853:2c4923336dd0 1854:2280e314a978
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[2]; 20 SDL_Rect axis_area[6][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 /* Erase previous axes */ 113 for ( i=0; i<SDL_JoystickNumAxes(joystick)/2 && i < SDL_arraysize(axis_area); ++i ) {
114 SDL_FillRect(screen, &axis_area[draw], 0x0000); 114 /* Erase previous axes */
115 SDL_FillRect(screen, &axis_area[i][draw], 0x0000);
115 116
116 /* Draw the X/Y axis */ 117 /* Draw the X/Y axis */
117 draw = !draw; 118 draw = !draw;
118 x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768); 119 x = (((int)SDL_JoystickGetAxis(joystick, i*2+0))+32768);
119 x *= SCREEN_WIDTH; 120 x *= SCREEN_WIDTH;
120 x /= 65535; 121 x /= 65535;
121 if ( x < 0 ) { 122 if ( x < 0 ) {
122 x = 0; 123 x = 0;
123 } else 124 } else
124 if ( x > (SCREEN_WIDTH-16) ) { 125 if ( x > (SCREEN_WIDTH-16) ) {
125 x = SCREEN_WIDTH-16; 126 x = SCREEN_WIDTH-16;
127 }
128 y = (((int)SDL_JoystickGetAxis(joystick, i*2+1))+32768);
129 y *= SCREEN_HEIGHT;
130 y /= 65535;
131 if ( y < 0 ) {
132 y = 0;
133 } else
134 if ( y > (SCREEN_HEIGHT-16) ) {
135 y = SCREEN_HEIGHT-16;
136 }
137 axis_area[i][draw].x = (Sint16)x;
138 axis_area[i][draw].y = (Sint16)y;
139 axis_area[i][draw].w = 16;
140 axis_area[i][draw].h = 16;
141 SDL_FillRect(screen, &axis_area[i][draw], 0xFFFF);
142
143 SDL_UpdateRects(screen, 2, axis_area[i]);
126 } 144 }
127 y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
128 y *= SCREEN_HEIGHT;
129 y /= 65535;
130 if ( y < 0 ) {
131 y = 0;
132 } else
133 if ( y > (SCREEN_HEIGHT-16) ) {
134 y = SCREEN_HEIGHT-16;
135 }
136 axis_area[draw].x = (Sint16)x;
137 axis_area[draw].y = (Sint16)y;
138 axis_area[draw].w = 16;
139 axis_area[draw].h = 16;
140 SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
141
142 SDL_UpdateRects(screen, 2, axis_area);
143 } 145 }
144 } 146 }
145 147
146 int main(int argc, char *argv[]) 148 int main(int argc, char *argv[])
147 { 149 {