Fixed bug #713 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sun, 27 Sep 2009 05:18:43 +0000
branchSDL-1.2
changeset 4249429c8dd3175d
parent 4248 a9c6e65c1416
child 4250 c483b474b1cf
Fixed bug #713

Don't clamp the mouse coordinates to the video surface size, instead clamp them to the last known window size.

This allows users to get the correct mouse coordinates even if they don't call SDL_SetVideoMode() in response to an SDL_VIDEORESIZE event (used as a hack to retain the OpenGL context on Windows and Linux after a window resize)
src/events/SDL_events_c.h
src/events/SDL_mouse.c
src/events/SDL_resize.c
src/video/SDL_video.c
src/video/wincommon/SDL_sysevents.c
     1.1 --- a/src/events/SDL_events_c.h	Sun Sep 27 04:49:30 2009 +0000
     1.2 +++ b/src/events/SDL_events_c.h	Sun Sep 27 05:18:43 2009 +0000
     1.3 @@ -64,6 +64,9 @@
     1.4  extern int SDL_PrivateQuit(void);
     1.5  extern int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message);
     1.6  
     1.7 +/* Used to clamp the mouse coordinates separately from the video surface */
     1.8 +extern void SDL_SetMouseRange(int maxX, int maxY);
     1.9 +
    1.10  /* Used by the activity event handler to remove mouse focus */
    1.11  extern void SDL_ResetMouse(void);
    1.12  
     2.1 --- a/src/events/SDL_mouse.c	Sun Sep 27 04:49:30 2009 +0000
     2.2 +++ b/src/events/SDL_mouse.c	Sun Sep 27 05:18:43 2009 +0000
     2.3 @@ -34,6 +34,8 @@
     2.4  static Sint16 SDL_MouseY = 0;
     2.5  static Sint16 SDL_DeltaX = 0;
     2.6  static Sint16 SDL_DeltaY = 0;
     2.7 +static Sint16 SDL_MouseMaxX = 0;
     2.8 +static Sint16 SDL_MouseMaxY = 0;
     2.9  static Uint8  SDL_ButtonState = 0;
    2.10  
    2.11  
    2.12 @@ -45,6 +47,8 @@
    2.13  	SDL_MouseY = 0;
    2.14  	SDL_DeltaX = 0;
    2.15  	SDL_DeltaY = 0;
    2.16 +	SDL_MouseMaxX = 0;
    2.17 +	SDL_MouseMaxY = 0;
    2.18  	SDL_ButtonState = 0;
    2.19  
    2.20  	/* That's it! */
    2.21 @@ -92,13 +96,19 @@
    2.22  	/* This clips absolute mouse coordinates when the apparent
    2.23  	   display surface is smaller than the real display surface.
    2.24  	 */
    2.25 -	if ( SDL_VideoSurface->offset ) {
    2.26 +	if ( SDL_VideoSurface && SDL_VideoSurface->offset ) {
    2.27  		*y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch;
    2.28  		*x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
    2.29  				SDL_VideoSurface->format->BytesPerPixel;
    2.30  	}
    2.31  }
    2.32  
    2.33 +void SDL_SetMouseRange(int maxX, int maxY)
    2.34 +{
    2.35 +	SDL_MouseMaxX = (Sint16)maxX;
    2.36 +	SDL_MouseMaxY = (Sint16)maxY;
    2.37 +}
    2.38 +
    2.39  /* These are global for SDL_eventloop.c */
    2.40  int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
    2.41  {
    2.42 @@ -107,11 +117,6 @@
    2.43  	Sint16 Xrel;
    2.44  	Sint16 Yrel;
    2.45  
    2.46 -	/* Don't handle mouse motion if there's no cursor surface */
    2.47 -	if ( SDL_VideoSurface == NULL ) {
    2.48 -		return(0);
    2.49 -	}
    2.50 -
    2.51  	/* Default buttonstate is the current one */
    2.52  	if ( ! buttonstate ) {
    2.53  		buttonstate = SDL_ButtonState;
    2.54 @@ -132,16 +137,16 @@
    2.55  	if ( x < 0 )
    2.56  		X = 0;
    2.57  	else
    2.58 -	if ( x >= SDL_VideoSurface->w )
    2.59 -		X = SDL_VideoSurface->w-1;
    2.60 +	if ( x >= SDL_MouseMaxX )
    2.61 +		X = SDL_MouseMaxX-1;
    2.62  	else
    2.63  		X = (Uint16)x;
    2.64  
    2.65  	if ( y < 0 )
    2.66  		Y = 0;
    2.67  	else
    2.68 -	if ( y >= SDL_VideoSurface->h )
    2.69 -		Y = SDL_VideoSurface->h-1;
    2.70 +	if ( y >= SDL_MouseMaxY )
    2.71 +		Y = SDL_MouseMaxY-1;
    2.72  	else
    2.73  		Y = (Uint16)y;
    2.74  
    2.75 @@ -206,14 +211,14 @@
    2.76  		if ( x < 0 )
    2.77  			x = 0;
    2.78  		else
    2.79 -		if ( x >= SDL_VideoSurface->w )
    2.80 -			x = SDL_VideoSurface->w-1;
    2.81 +		if ( x >= SDL_MouseMaxX )
    2.82 +			x = SDL_MouseMaxX-1;
    2.83  
    2.84  		if ( y < 0 )
    2.85  			y = 0;
    2.86  		else
    2.87 -		if ( y >= SDL_VideoSurface->h )
    2.88 -			y = SDL_VideoSurface->h-1;
    2.89 +		if ( y >= SDL_MouseMaxY )
    2.90 +			y = SDL_MouseMaxY-1;
    2.91  	} else {
    2.92  		move_mouse = 0;
    2.93  	}
     3.1 --- a/src/events/SDL_resize.c	Sun Sep 27 04:49:30 2009 +0000
     3.2 +++ b/src/events/SDL_resize.c	Sun Sep 27 05:18:43 2009 +0000
     3.3 @@ -54,6 +54,7 @@
     3.4  	     ((w == SDL_VideoSurface->w) && (h == SDL_VideoSurface->h)) ) {
     3.5  		return(0);
     3.6  	}
     3.7 +	SDL_SetMouseRange(w, h);
     3.8  
     3.9  	/* Pull out all old resize events */
    3.10  	SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]),
     4.1 --- a/src/video/SDL_video.c	Sun Sep 27 04:49:30 2009 +0000
     4.2 +++ b/src/video/SDL_video.c	Sun Sep 27 05:18:43 2009 +0000
     4.3 @@ -639,6 +639,7 @@
     4.4  	/* Reset the keyboard here so event callbacks can run */
     4.5  	SDL_ResetKeyboard();
     4.6  	SDL_ResetMouse();
     4.7 +	SDL_SetMouseRange(width, height);
     4.8  	SDL_cursorstate &= ~CURSOR_USINGSW;
     4.9  
    4.10  	/* Clean up any previous video mode */
     5.1 --- a/src/video/wincommon/SDL_sysevents.c	Sun Sep 27 04:49:30 2009 +0000
     5.2 +++ b/src/video/wincommon/SDL_sysevents.c	Sun Sep 27 05:18:43 2009 +0000
     5.3 @@ -420,7 +420,6 @@
     5.4  			/* Mouse is handled by DirectInput when fullscreen */
     5.5  			if ( SDL_VideoSurface && ! DINPUT() ) {
     5.6  				WORD xbuttonval = 0;
     5.7 -				Sint16 x, y;
     5.8  				Uint8 button, state;
     5.9  
    5.10  				/* DJM: