test/testjoystick.c
changeset 1854 2280e314a978
parent 0 74212992fb08
child 1662 782fd950bd46
child 1855 5ff2c01e475e
     1.1 --- a/test/testjoystick.c	Sun May 21 02:50:05 2006 +0000
     1.2 +++ b/test/testjoystick.c	Sun May 21 16:47:41 2006 +0000
     1.3 @@ -17,7 +17,7 @@
     1.4  	int i, done;
     1.5  	SDL_Event event;
     1.6  	int x, y, draw;
     1.7 -	SDL_Rect axis_area[2];
     1.8 +	SDL_Rect axis_area[6][2];
     1.9  
    1.10  	/* Set a video mode to display joystick axis position */
    1.11  	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0);
    1.12 @@ -110,36 +110,38 @@
    1.13  			SDL_UpdateRects(screen, 1, &area);
    1.14  		}
    1.15  
    1.16 -		/* Erase previous axes */
    1.17 -		SDL_FillRect(screen, &axis_area[draw], 0x0000);
    1.18 +		for ( i=0; i<SDL_JoystickNumAxes(joystick)/2 && i < SDL_arraysize(axis_area); ++i ) {
    1.19 +			/* Erase previous axes */
    1.20 +			SDL_FillRect(screen, &axis_area[i][draw], 0x0000);
    1.21  
    1.22 -		/* Draw the X/Y axis */
    1.23 -		draw = !draw;
    1.24 -		x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768);
    1.25 -		x *= SCREEN_WIDTH;
    1.26 -		x /= 65535;
    1.27 -		if ( x < 0 ) {
    1.28 -			x = 0;
    1.29 -		} else
    1.30 -		if ( x > (SCREEN_WIDTH-16) ) {
    1.31 -			x = SCREEN_WIDTH-16;
    1.32 +			/* Draw the X/Y axis */
    1.33 +			draw = !draw;
    1.34 +			x = (((int)SDL_JoystickGetAxis(joystick, i*2+0))+32768);
    1.35 +			x *= SCREEN_WIDTH;
    1.36 +			x /= 65535;
    1.37 +			if ( x < 0 ) {
    1.38 +				x = 0;
    1.39 +			} else
    1.40 +			if ( x > (SCREEN_WIDTH-16) ) {
    1.41 +				x = SCREEN_WIDTH-16;
    1.42 +			}
    1.43 +			y = (((int)SDL_JoystickGetAxis(joystick, i*2+1))+32768);
    1.44 +			y *= SCREEN_HEIGHT;
    1.45 +			y /= 65535;
    1.46 +			if ( y < 0 ) {
    1.47 +				y = 0;
    1.48 +			} else
    1.49 +			if ( y > (SCREEN_HEIGHT-16) ) {
    1.50 +				y = SCREEN_HEIGHT-16;
    1.51 +			}
    1.52 +			axis_area[i][draw].x = (Sint16)x;
    1.53 +			axis_area[i][draw].y = (Sint16)y;
    1.54 +			axis_area[i][draw].w = 16;
    1.55 +			axis_area[i][draw].h = 16;
    1.56 +			SDL_FillRect(screen, &axis_area[i][draw], 0xFFFF);
    1.57 +
    1.58 +			SDL_UpdateRects(screen, 2, axis_area[i]);
    1.59  		}
    1.60 -		y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
    1.61 -		y *= SCREEN_HEIGHT;
    1.62 -		y /= 65535;
    1.63 -		if ( y < 0 ) {
    1.64 -			y = 0;
    1.65 -		} else
    1.66 -		if ( y > (SCREEN_HEIGHT-16) ) {
    1.67 -			y = SCREEN_HEIGHT-16;
    1.68 -		}
    1.69 -		axis_area[draw].x = (Sint16)x;
    1.70 -		axis_area[draw].y = (Sint16)y;
    1.71 -		axis_area[draw].w = 16;
    1.72 -		axis_area[draw].h = 16;
    1.73 -		SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
    1.74 -
    1.75 -		SDL_UpdateRects(screen, 2, axis_area);
    1.76  	}
    1.77  }
    1.78