Make mouse relative mode save the original co-ordinates to restore them
authorWim Looman <ghostunderscore@gmail.com>
Sat, 04 Feb 2012 00:13:21 +1300
changeset 6302 b0ae93a5b8d6
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
--- a/src/events/SDL_mouse.c	Fri Feb 03 23:53:51 2012 +1300
+++ b/src/events/SDL_mouse.c	Sat Feb 04 00:13:21 2012 +1300
@@ -323,9 +323,13 @@
     /* Set the relative mode */
     mouse->relative_mode = enabled;
 
-    if (!enabled && mouse->focus) {
+    if (enabled) {
+        /* Save the expected mouse position */
+        mouse->original_x = mouse->x;
+        mouse->original_y = mouse->y;
+    } else if (mouse->focus) {
         /* Restore the expected mouse position */
-        SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
+        SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y);
     }
 
     /* Flush pending mouse motion */
--- a/src/events/SDL_mouse_c.h	Fri Feb 03 23:53:51 2012 +1300
+++ b/src/events/SDL_mouse_c.h	Sat Feb 04 00:13:21 2012 +1300
@@ -60,6 +60,8 @@
     int last_x, last_y;         /* the last reported x and y coordinates */
     Uint8 buttonstate;
     SDL_bool relative_mode;
+    /* the x and y coordinates when relative mode was activated */
+    int original_x, original_y;
 
     SDL_Cursor *cursors;
     SDL_Cursor *def_cursor;