Make mouse relative mode save the original co-ordinates to restore them
authorWim Looman
Sat, 04 Feb 2012 00:13:21 +1300
changeset 6302b0ae93a5b8d6
parent 6301 e8a69c5378e7
child 6303 6bb657898f55
Make mouse relative mode save the original co-ordinates to restore them
properly.
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
     1.1 --- a/src/events/SDL_mouse.c	Fri Feb 03 23:53:51 2012 +1300
     1.2 +++ b/src/events/SDL_mouse.c	Sat Feb 04 00:13:21 2012 +1300
     1.3 @@ -323,9 +323,13 @@
     1.4      /* Set the relative mode */
     1.5      mouse->relative_mode = enabled;
     1.6  
     1.7 -    if (!enabled && mouse->focus) {
     1.8 +    if (enabled) {
     1.9 +        /* Save the expected mouse position */
    1.10 +        mouse->original_x = mouse->x;
    1.11 +        mouse->original_y = mouse->y;
    1.12 +    } else if (mouse->focus) {
    1.13          /* Restore the expected mouse position */
    1.14 -        SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
    1.15 +        SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y);
    1.16      }
    1.17  
    1.18      /* Flush pending mouse motion */
     2.1 --- a/src/events/SDL_mouse_c.h	Fri Feb 03 23:53:51 2012 +1300
     2.2 +++ b/src/events/SDL_mouse_c.h	Sat Feb 04 00:13:21 2012 +1300
     2.3 @@ -60,6 +60,8 @@
     2.4      int last_x, last_y;         /* the last reported x and y coordinates */
     2.5      Uint8 buttonstate;
     2.6      SDL_bool relative_mode;
     2.7 +    /* the x and y coordinates when relative mode was activated */
     2.8 +    int original_x, original_y;
     2.9  
    2.10      SDL_Cursor *cursors;
    2.11      SDL_Cursor *def_cursor;