Skip to content
Snippets Groups Projects
Commit 821a1810 authored by Monster Iestyn's avatar Monster Iestyn
Browse files

Moved lrounding of mouse motion events to the actual point an event is made

Also did some cleanup and moving around, as well as adding comments
parent 10cbe2c8
No related branches found
No related tags found
2 merge requests!252OpenGL: Public flatsprite: The Fixening,!206SDL2: Relative mouse mode
......@@ -107,6 +107,9 @@ static SDL_bool disable_mouse = SDL_FALSE;
// first entry in the modelist which is not bigger than MAXVIDWIDTHxMAXVIDHEIGHT
static INT32 firstEntry = 0;
// Total mouse motion X/Y offsets
static INT32 mousemovex = 0, mousemovey = 0;
// SDL vars
static SDL_Surface *vidSurface = NULL;
static SDL_Surface *bufSurface = NULL;
......@@ -606,8 +609,6 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
if (event.data1) D_PostEvent(&event);
}
static INT32 mousemovex, mousemovey;
static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
{
event_t event;
......@@ -623,30 +624,34 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
return;
}
// If using relative mouse mode, don't post an event_t just now,
// add on the offsets so we can make an overall event later.
if (SDL_GetRelativeMouseMode())
{
//event.data2 = evt.xrel;
//event.data3 = -evt.yrel;
if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window)
{
mousemovex += (INT32)lround( evt.xrel * ((float)wwidth / (float)realwidth));
mousemovey += (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight));
mousemovex += evt.xrel; //(INT32)lround( evt.xrel * ((float)wwidth / (float)realwidth));
mousemovey += -evt.yrel; //(INT32)lround(-evt.yrel * ((float)wheight / (float)realheight));
SDL_SetWindowGrab(window, SDL_TRUE);
}
return;
}
SDL_memset(&event, 0, sizeof(event_t));
// If the event is from warping the pointer back to middle
// of the screen then ignore it.
if ((evt.x == realwidth/2) && (evt.y == realheight/2))
{
return;
}
else
{
event.data2 = (INT32)lround((evt.xrel) * ((float)wwidth / (float)realwidth));
event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight));
}
SDL_memset(&event, 0, sizeof(event_t));
event.type = ev_mouse;
event.data2 = (INT32)lround( evt.xrel * ((float)wwidth / (float)realwidth));
event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight));
event.type = ev_mouse;
......@@ -805,13 +810,14 @@ void I_GetEvent(void)
// We only want the first motion event,
// otherwise we'll end up catching the warp back to center.
//int mouseMotionOnce = 0;
mousemovex = mousemovey = 0;
if (!graphics_started)
{
return;
}
mousemovex = mousemovey = 0;
while (SDL_PollEvent(&evt))
{
switch (evt.type)
......@@ -849,14 +855,17 @@ void I_GetEvent(void)
}
}
// Send all relative mouse movement as one single mouse event.
if (mousemovex || mousemovey)
{
event_t event;
SDL_memset(&event, 0, sizeof(event_t));
int wwidth, wheight;
SDL_GetWindowSize(window, &wwidth, &wheight);
//SDL_memset(&event, 0, sizeof(event_t));
event.type = ev_mouse;
event.data1 = 0;
event.data2 = mousemovex;
event.data3 = mousemovey;
event.data2 = (INT32)lround(mousemovex * ((float)wwidth / (float)realwidth));
event.data3 = (INT32)lround(mousemovey * ((float)wheight / (float)realheight));
D_PostEvent(&event);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment