diff options
author | Wim Looman <ghostunderscore@gmail.com> | 2012-02-04 00:13:21 +1300 |
---|---|---|
committer | Wim Looman <ghostunderscore@gmail.com> | 2012-02-04 00:13:21 +1300 |
commit | f18dd535801bcb50a63d932cfe3826a3aa15fdf0 (patch) | |
tree | 17296d3730dce0dc07ccdb0cee44f3c554b78745 | |
parent | 02a32c512135d3ef52bd01cd9b169df38b6aa549 (diff) |
Make mouse relative mode save the original co-ordinates to restore them
properly.
-rwxr-xr-x | src/events/SDL_mouse.c | 8 | ||||
-rwxr-xr-x | src/events/SDL_mouse_c.h | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index b847a879..ff20a79e 100755 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -323,9 +323,13 @@ SDL_SetRelativeMouseMode(SDL_bool enabled) /* 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 */ diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 9562e075..d571ddab 100755 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -60,6 +60,8 @@ typedef struct 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; |