Date: Sun, 18 Jul 2004 00:22:07 -0400
authorSam Lantinga <slouken@libsdl.org>
Sat, 21 Aug 2004 12:38:50 +0000
changeset 943715c32d8f26c
parent 942 41a59de7f2ed
child 944 cdea7cbc3e23
Date: Sun, 18 Jul 2004 00:22:07 -0400
From: "Philippe Anctil"
Subject: [SDL] odd mouse event generated on init

The mouse relative and absolute coordinates appear to be always equal for
the first mouse event.
src/events/SDL_mouse.c
     1.1 --- a/src/events/SDL_mouse.c	Sat Aug 21 12:27:02 2004 +0000
     1.2 +++ b/src/events/SDL_mouse.c	Sat Aug 21 12:38:50 2004 +0000
     1.3 @@ -38,8 +38,8 @@
     1.4  
     1.5  
     1.6  /* These are static for our mouse handling code */
     1.7 -static Sint16 SDL_MouseX = 0;
     1.8 -static Sint16 SDL_MouseY = 0;
     1.9 +static Sint16 SDL_MouseX = -1;
    1.10 +static Sint16 SDL_MouseY = -1;
    1.11  static Sint16 SDL_DeltaX = 0;
    1.12  static Sint16 SDL_DeltaY = 0;
    1.13  static Uint8  SDL_ButtonState = 0;
    1.14 @@ -49,8 +49,8 @@
    1.15  int SDL_MouseInit(void)
    1.16  {
    1.17  	/* The mouse is at (0,0) */
    1.18 -	SDL_MouseX = 0;
    1.19 -	SDL_MouseY = 0;
    1.20 +	SDL_MouseX = -1;
    1.21 +	SDL_MouseY = -1;
    1.22  	SDL_DeltaX = 0;
    1.23  	SDL_DeltaY = 0;
    1.24  	SDL_ButtonState = 0;
    1.25 @@ -72,10 +72,20 @@
    1.26  
    1.27  Uint8 SDL_GetMouseState (int *x, int *y)
    1.28  {
    1.29 -	if ( x )
    1.30 -		*x = SDL_MouseX;
    1.31 -	if ( y )
    1.32 -		*y = SDL_MouseY;
    1.33 +	if ( x ) {
    1.34 +		if ( SDL_MouseX < 0 ) {
    1.35 +			*x = 0;
    1.36 +		} else {
    1.37 +			*x = SDL_MouseX;
    1.38 +		}
    1.39 +	}
    1.40 +	if ( y ) {
    1.41 +		if ( SDL_MouseY < 0 ) {
    1.42 +			*y = 0;
    1.43 +		} else {
    1.44 +			*y = SDL_MouseY;
    1.45 +		}
    1.46 +	}
    1.47  	return(SDL_ButtonState);
    1.48  }
    1.49  
    1.50 @@ -152,7 +162,7 @@
    1.51  	   This prevents lots of extraneous large delta relative motion when
    1.52  	   the screen is windowed mode and the mouse is outside the window.
    1.53  	*/
    1.54 -	if ( ! relative ) {
    1.55 +	if ( ! relative && SDL_MouseX >= 0 && SDL_MouseY >= 0 ) {
    1.56  		Xrel = X-SDL_MouseX;
    1.57  		Yrel = Y-SDL_MouseY;
    1.58  	}