Skip to content

Commit

Permalink
Store real mouse warp x/y instead of relying on SDL_GetMouseState
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceLR committed Aug 4, 2019
1 parent ef226c3 commit 599ad88
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
10 changes: 10 additions & 0 deletions docs/changelog.txt
@@ -1,3 +1,13 @@
GIT

USERS

+ Fixed a bug where mouse warping both mouse coordinates would
not actually warp both coordinates.

DEVELOPERS


July 22nd, 2019 - MZX 2.92

Here's another inexcusably big minor version release. First off,
Expand Down
21 changes: 17 additions & 4 deletions src/event.c
Expand Up @@ -540,6 +540,8 @@ static void start_frame_event_status(void)
status->mouse_last_y = status->mouse_y;
status->real_mouse_last_x = status->real_mouse_x;
status->real_mouse_last_y = status->real_mouse_y;
status->warped_mouse_x = -1;
status->warped_mouse_y = -1;
}

boolean update_event_status(void)
Expand Down Expand Up @@ -903,6 +905,9 @@ void warp_mouse(Uint32 x, Uint32 y)
status->real_mouse_y = my;

set_screen_coords(mx, my, &mx_real, &my_real);
status->warped_mouse_x = mx_real;
status->warped_mouse_y = my_real;

real_warp_mouse(mx_real, my_real);
}

Expand All @@ -915,7 +920,9 @@ void warp_mouse_x(Uint32 x)
status->real_mouse_x = mx;

set_screen_coords(mx, status->real_mouse_y, &mx_real, &my_real);
real_warp_mouse(mx_real, -1);
status->warped_mouse_x = mx_real;

real_warp_mouse(mx_real, status->warped_mouse_y);
}

void warp_mouse_y(Uint32 y)
Expand All @@ -927,7 +934,9 @@ void warp_mouse_y(Uint32 y)
status->real_mouse_y = my;

set_screen_coords(status->real_mouse_x, my, &mx_real, &my_real);
real_warp_mouse(-1, my_real);
status->warped_mouse_y = my_real;

real_warp_mouse(status->warped_mouse_x, my_real);
}

void warp_real_mouse_x(Uint32 mx)
Expand All @@ -939,7 +948,9 @@ void warp_real_mouse_x(Uint32 mx)
status->real_mouse_x = mx;

set_screen_coords(mx, status->real_mouse_y, &mx_real, &my_real);
real_warp_mouse(mx_real, -1);
status->warped_mouse_x = mx_real;

real_warp_mouse(mx_real, status->warped_mouse_y);
}

void warp_real_mouse_y(Uint32 my)
Expand All @@ -951,7 +962,9 @@ void warp_real_mouse_y(Uint32 my)
status->real_mouse_y = my;

set_screen_coords(status->real_mouse_x, my, &mx_real, &my_real);
real_warp_mouse(-1, my_real);
status->warped_mouse_y = my_real;

real_warp_mouse(status->warped_mouse_x, my_real);
}

void force_last_key(enum keycode_type type, int val)
Expand Down
2 changes: 2 additions & 0 deletions src/event.h
Expand Up @@ -113,6 +113,8 @@ struct buffered_status
Uint32 real_mouse_y;
Uint32 real_mouse_last_x;
Uint32 real_mouse_last_y;
Sint32 warped_mouse_x;
Sint32 warped_mouse_y;
Uint32 mouse_button;
Uint32 mouse_repeat;
Uint32 mouse_repeat_state;
Expand Down
15 changes: 9 additions & 6 deletions src/event_sdl.c
Expand Up @@ -1417,16 +1417,19 @@ void __wait_event(void)

void real_warp_mouse(int x, int y)
{
int current_x, current_y;
SDL_Window *window = SDL_GetWindowFromID(sdl_window_id);

SDL_GetMouseState(&current_x, &current_y);
if((x < 0) || (y < 0))
{
int current_x, current_y;
SDL_GetMouseState(&current_x, &current_y);

if(x < 0)
x = current_x;
if(x < 0)
x = current_x;

if(y < 0)
y = current_y;
if(y < 0)
y = current_y;
}

SDL_WarpMouseInWindow(window, x, y);
}
Expand Down

0 comments on commit 599ad88

Please sign in to comment.