test/testjoystick.c
changeset 1855 5ff2c01e475e
parent 1854 2280e314a978
child 1895 c121d94672cb
child 4071 3d9040dcc47e
     1.1 --- a/test/testjoystick.c	Sun May 21 16:47:41 2006 +0000
     1.2 +++ b/test/testjoystick.c	Sun May 21 17:26:40 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[6][2];
     1.8 +	SDL_Rect axis_area[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,38 +110,36 @@
    1.13  			SDL_UpdateRects(screen, 1, &area);
    1.14  		}
    1.15  
    1.16 -		for ( i=0; i<SDL_JoystickNumAxes(joystick)/2 && i < SDL_arraysize(axis_area); ++i ) {
    1.17 -			/* Erase previous axes */
    1.18 -			SDL_FillRect(screen, &axis_area[i][draw], 0x0000);
    1.19 +		/* Erase previous axes */
    1.20 +		SDL_FillRect(screen, &axis_area[draw], 0x0000);
    1.21  
    1.22 -			/* Draw the X/Y axis */
    1.23 -			draw = !draw;
    1.24 -			x = (((int)SDL_JoystickGetAxis(joystick, i*2+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 -			}
    1.33 -			y = (((int)SDL_JoystickGetAxis(joystick, i*2+1))+32768);
    1.34 -			y *= SCREEN_HEIGHT;
    1.35 -			y /= 65535;
    1.36 -			if ( y < 0 ) {
    1.37 -				y = 0;
    1.38 -			} else
    1.39 -			if ( y > (SCREEN_HEIGHT-16) ) {
    1.40 -				y = SCREEN_HEIGHT-16;
    1.41 -			}
    1.42 -			axis_area[i][draw].x = (Sint16)x;
    1.43 -			axis_area[i][draw].y = (Sint16)y;
    1.44 -			axis_area[i][draw].w = 16;
    1.45 -			axis_area[i][draw].h = 16;
    1.46 -			SDL_FillRect(screen, &axis_area[i][draw], 0xFFFF);
    1.47 +		/* Draw the X/Y axis */
    1.48 +		draw = !draw;
    1.49 +		x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768);
    1.50 +		x *= SCREEN_WIDTH;
    1.51 +		x /= 65535;
    1.52 +		if ( x < 0 ) {
    1.53 +			x = 0;
    1.54 +		} else
    1.55 +		if ( x > (SCREEN_WIDTH-16) ) {
    1.56 +			x = SCREEN_WIDTH-16;
    1.57 +		}
    1.58 +		y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
    1.59 +		y *= SCREEN_HEIGHT;
    1.60 +		y /= 65535;
    1.61 +		if ( y < 0 ) {
    1.62 +			y = 0;
    1.63 +		} else
    1.64 +		if ( y > (SCREEN_HEIGHT-16) ) {
    1.65 +			y = SCREEN_HEIGHT-16;
    1.66 +		}
    1.67 +		axis_area[draw].x = (Sint16)x;
    1.68 +		axis_area[draw].y = (Sint16)y;
    1.69 +		axis_area[draw].w = 16;
    1.70 +		axis_area[draw].h = 16;
    1.71 +		SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
    1.72  
    1.73 -			SDL_UpdateRects(screen, 2, axis_area[i]);
    1.74 -		}
    1.75 +		SDL_UpdateRects(screen, 2, axis_area);
    1.76  	}
    1.77  }
    1.78