Merge all (relative) mouse motion events into one mouse event

This fixes SDL2_RelMouse's weaker sensitivity for me on Windows (but apparently not for others??)
This commit is contained in:
Monster Iestyn 2017-08-19 21:39:04 +01:00
parent 2d661fef18
commit 758e9c4558

View file

@ -606,6 +606,8 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
if (event.data1) D_PostEvent(&event); if (event.data1) D_PostEvent(&event);
} }
static int mousemovex, mousemovey;
static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
{ {
event_t event; event_t event;
@ -623,10 +625,20 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
if (SDL_GetRelativeMouseMode()) if (SDL_GetRelativeMouseMode())
{ {
event.data2 = evt.xrel; //event.data2 = evt.xrel;
event.data3 = -evt.yrel; //event.data3 = -evt.yrel;
if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window)
{
mousemovex += evt.xrel;
mousemovey += -evt.yrel;
SDL_SetWindowGrab(window, SDL_TRUE);
}
return;
} }
else if ((evt.x == realwidth/2) && (evt.y == realheight/2))
SDL_memset(&event, 0, sizeof(event_t));
if ((evt.x == realwidth/2) && (evt.y == realheight/2))
{ {
return; return;
} }
@ -792,7 +804,8 @@ void I_GetEvent(void)
SDL_Event evt; SDL_Event evt;
// We only want the first motion event, // We only want the first motion event,
// otherwise we'll end up catching the warp back to center. // otherwise we'll end up catching the warp back to center.
int mouseMotionOnce = 0; //int mouseMotionOnce = 0;
mousemovex = mousemovey = 0;
if (!graphics_started) if (!graphics_started)
{ {
@ -811,8 +824,9 @@ void I_GetEvent(void)
Impl_HandleKeyboardEvent(evt.key, evt.type); Impl_HandleKeyboardEvent(evt.key, evt.type);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if (!mouseMotionOnce) Impl_HandleMouseMotionEvent(evt.motion); //if (!mouseMotionOnce)
mouseMotionOnce = 1; Impl_HandleMouseMotionEvent(evt.motion);
//mouseMotionOnce = 1;
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
@ -835,6 +849,17 @@ void I_GetEvent(void)
} }
} }
if (mousemovex || mousemovey)
{
event_t event;
SDL_memset(&event, 0, sizeof(event_t));
event.type = ev_mouse;
event.data1 = 0;
event.data2 = mousemovex;
event.data3 = mousemovey;
D_PostEvent(&event);
}
// In order to make wheels act like buttons, we have to set their state to Up. // In order to make wheels act like buttons, we have to set their state to Up.
// This is because wheel messages don't have an up/down state. // This is because wheel messages don't have an up/down state.
gamekeydown[KEY_MOUSEWHEELDOWN] = gamekeydown[KEY_MOUSEWHEELUP] = 0; gamekeydown[KEY_MOUSEWHEELDOWN] = gamekeydown[KEY_MOUSEWHEELUP] = 0;