Fixed bug #38
authorSam Lantinga
Tue, 14 Mar 2006 06:00:30 +0000
changeset 152523a347cfbed8
parent 1524 38a12fd1a2c1
child 1526 89f90f32f6c0
Fixed bug #38

I'm using SDL 1.2.9 with Visual C++ 7.0 on Windows 2000.

Here's the setup: my game starts in a window, with
SDL_WM_GrabInput(SDL_GRAB_ON) to constrain the cursor to the game window. The
mouse cursor is outside of the window when the game launches, and when the
window appears the cursor is grabbed and placed at the top left corner of the
inside of the game window. At this point, if I click the mouse without moving
it, the SDL_MOUSEBUTTONDOWN event's mouse coordinates are (65535,65535).
src/events/SDL_mouse.c
     1.1 --- a/src/events/SDL_mouse.c	Tue Mar 14 05:34:39 2006 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Tue Mar 14 06:00:30 2006 +0000
     1.3 @@ -30,8 +30,8 @@
     1.4  
     1.5  
     1.6  /* These are static for our mouse handling code */
     1.7 -static Sint16 SDL_MouseX = -1;
     1.8 -static Sint16 SDL_MouseY = -1;
     1.9 +static Sint16 SDL_MouseX = 0;
    1.10 +static Sint16 SDL_MouseY = 0;
    1.11  static Sint16 SDL_DeltaX = 0;
    1.12  static Sint16 SDL_DeltaY = 0;
    1.13  static Uint8  SDL_ButtonState = 0;
    1.14 @@ -41,8 +41,8 @@
    1.15  int SDL_MouseInit(void)
    1.16  {
    1.17  	/* The mouse is at (0,0) */
    1.18 -	SDL_MouseX = -1;
    1.19 -	SDL_MouseY = -1;
    1.20 +	SDL_MouseX = 0;
    1.21 +	SDL_MouseY = 0;
    1.22  	SDL_DeltaX = 0;
    1.23  	SDL_DeltaY = 0;
    1.24  	SDL_ButtonState = 0;
    1.25 @@ -68,18 +68,10 @@
    1.26  Uint8 SDL_GetMouseState (int *x, int *y)
    1.27  {
    1.28  	if ( x ) {
    1.29 -		if ( SDL_MouseX < 0 ) {
    1.30 -			*x = 0;
    1.31 -		} else {
    1.32 -			*x = SDL_MouseX;
    1.33 -		}
    1.34 +		*x = SDL_MouseX;
    1.35  	}
    1.36  	if ( y ) {
    1.37 -		if ( SDL_MouseY < 0 ) {
    1.38 -			*y = 0;
    1.39 -		} else {
    1.40 -			*y = SDL_MouseY;
    1.41 -		}
    1.42 +		*y = SDL_MouseY;
    1.43  	}
    1.44  	return(SDL_ButtonState);
    1.45  }
    1.46 @@ -157,7 +149,7 @@
    1.47  	   This prevents lots of extraneous large delta relative motion when
    1.48  	   the screen is windowed mode and the mouse is outside the window.
    1.49  	*/
    1.50 -	if ( ! relative && SDL_MouseX >= 0 && SDL_MouseY >= 0 ) {
    1.51 +	if ( ! relative ) {
    1.52  		Xrel = X-SDL_MouseX;
    1.53  		Yrel = Y-SDL_MouseY;
    1.54  	}