Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Make mouse relative mode save the original co-ordinates to restore them
Browse files Browse the repository at this point in the history
properly.
  • Loading branch information
Nemo157 committed Feb 3, 2012
1 parent 44341d3 commit f5a0ff7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/events/SDL_mouse.c
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions src/events/SDL_mouse_c.h
Expand Up @@ -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;
Expand Down

0 comments on commit f5a0ff7

Please sign in to comment.