Mercurial > sdl-ios-xcode
changeset 4249:429c8dd3175d SDL-1.2
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)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 27 Sep 2009 05:18:43 +0000 |
parents | a9c6e65c1416 |
children | c483b474b1cf |
files | 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 |
diffstat | 5 files changed, 24 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/events/SDL_events_c.h Sun Sep 27 04:49:30 2009 +0000 +++ b/src/events/SDL_events_c.h Sun Sep 27 05:18:43 2009 +0000 @@ -64,6 +64,9 @@ extern int SDL_PrivateQuit(void); extern int SDL_PrivateSysWMEvent(SDL_SysWMmsg *message); +/* Used to clamp the mouse coordinates separately from the video surface */ +extern void SDL_SetMouseRange(int maxX, int maxY); + /* Used by the activity event handler to remove mouse focus */ extern void SDL_ResetMouse(void);
--- a/src/events/SDL_mouse.c Sun Sep 27 04:49:30 2009 +0000 +++ b/src/events/SDL_mouse.c Sun Sep 27 05:18:43 2009 +0000 @@ -34,6 +34,8 @@ static Sint16 SDL_MouseY = 0; static Sint16 SDL_DeltaX = 0; static Sint16 SDL_DeltaY = 0; +static Sint16 SDL_MouseMaxX = 0; +static Sint16 SDL_MouseMaxY = 0; static Uint8 SDL_ButtonState = 0; @@ -45,6 +47,8 @@ SDL_MouseY = 0; SDL_DeltaX = 0; SDL_DeltaY = 0; + SDL_MouseMaxX = 0; + SDL_MouseMaxY = 0; SDL_ButtonState = 0; /* That's it! */ @@ -92,13 +96,19 @@ /* This clips absolute mouse coordinates when the apparent display surface is smaller than the real display surface. */ - if ( SDL_VideoSurface->offset ) { + if ( SDL_VideoSurface && SDL_VideoSurface->offset ) { *y -= SDL_VideoSurface->offset/SDL_VideoSurface->pitch; *x -= (SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/ SDL_VideoSurface->format->BytesPerPixel; } } +void SDL_SetMouseRange(int maxX, int maxY) +{ + SDL_MouseMaxX = (Sint16)maxX; + SDL_MouseMaxY = (Sint16)maxY; +} + /* These are global for SDL_eventloop.c */ int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y) { @@ -107,11 +117,6 @@ Sint16 Xrel; Sint16 Yrel; - /* Don't handle mouse motion if there's no cursor surface */ - if ( SDL_VideoSurface == NULL ) { - return(0); - } - /* Default buttonstate is the current one */ if ( ! buttonstate ) { buttonstate = SDL_ButtonState; @@ -132,16 +137,16 @@ if ( x < 0 ) X = 0; else - if ( x >= SDL_VideoSurface->w ) - X = SDL_VideoSurface->w-1; + if ( x >= SDL_MouseMaxX ) + X = SDL_MouseMaxX-1; else X = (Uint16)x; if ( y < 0 ) Y = 0; else - if ( y >= SDL_VideoSurface->h ) - Y = SDL_VideoSurface->h-1; + if ( y >= SDL_MouseMaxY ) + Y = SDL_MouseMaxY-1; else Y = (Uint16)y; @@ -206,14 +211,14 @@ if ( x < 0 ) x = 0; else - if ( x >= SDL_VideoSurface->w ) - x = SDL_VideoSurface->w-1; + if ( x >= SDL_MouseMaxX ) + x = SDL_MouseMaxX-1; if ( y < 0 ) y = 0; else - if ( y >= SDL_VideoSurface->h ) - y = SDL_VideoSurface->h-1; + if ( y >= SDL_MouseMaxY ) + y = SDL_MouseMaxY-1; } else { move_mouse = 0; }
--- a/src/events/SDL_resize.c Sun Sep 27 04:49:30 2009 +0000 +++ b/src/events/SDL_resize.c Sun Sep 27 05:18:43 2009 +0000 @@ -54,6 +54,7 @@ ((w == SDL_VideoSurface->w) && (h == SDL_VideoSurface->h)) ) { return(0); } + SDL_SetMouseRange(w, h); /* Pull out all old resize events */ SDL_PeepEvents(events, sizeof(events)/sizeof(events[0]),
--- a/src/video/SDL_video.c Sun Sep 27 04:49:30 2009 +0000 +++ b/src/video/SDL_video.c Sun Sep 27 05:18:43 2009 +0000 @@ -639,6 +639,7 @@ /* Reset the keyboard here so event callbacks can run */ SDL_ResetKeyboard(); SDL_ResetMouse(); + SDL_SetMouseRange(width, height); SDL_cursorstate &= ~CURSOR_USINGSW; /* Clean up any previous video mode */
--- a/src/video/wincommon/SDL_sysevents.c Sun Sep 27 04:49:30 2009 +0000 +++ b/src/video/wincommon/SDL_sysevents.c Sun Sep 27 05:18:43 2009 +0000 @@ -420,7 +420,6 @@ /* Mouse is handled by DirectInput when fullscreen */ if ( SDL_VideoSurface && ! DINPUT() ) { WORD xbuttonval = 0; - Sint16 x, y; Uint8 button, state; /* DJM: