Revert "(Messiness warning) attempt to start using SDL_SetRelativeMouseMode instead of the old hacks of making the mouse do movement without leaving the window and be hidden"

This reverts commit 347b531881.

(Too experimental, may end up adding new bugs; let's just keep it to clean up for now)
This commit is contained in:
Monster Iestyn 2016-11-30 17:21:28 +00:00
parent 347b531881
commit ae3e11369e
1 changed files with 14 additions and 52 deletions

View File

@ -527,7 +527,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which)
static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{ {
//static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool firsttimeonmouse = SDL_TRUE;
static SDL_bool mousefocus = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE;
static SDL_bool kbfocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE;
@ -535,21 +535,17 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{ {
case SDL_WINDOWEVENT_ENTER: case SDL_WINDOWEVENT_ENTER:
mousefocus = SDL_TRUE; mousefocus = SDL_TRUE;
//CONS_Printf("Window gained mouse focus!\n");
break; break;
case SDL_WINDOWEVENT_LEAVE: case SDL_WINDOWEVENT_LEAVE:
mousefocus = SDL_FALSE; mousefocus = SDL_FALSE;
//CONS_Printf("Window lost mouse focus!\n");
break; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
kbfocus = SDL_TRUE; kbfocus = SDL_TRUE;
mousefocus = SDL_TRUE; mousefocus = SDL_TRUE;
//CONS_Printf("Window gained keyboard focus!\n");
break; break;
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
kbfocus = SDL_FALSE; kbfocus = SDL_FALSE;
mousefocus = SDL_FALSE; mousefocus = SDL_FALSE;
//CONS_Printf("Window lost keyboard focus!\n");
break; break;
case SDL_WINDOWEVENT_MAXIMIZED: case SDL_WINDOWEVENT_MAXIMIZED:
break; break;
@ -562,14 +558,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
if (!paused) if (!paused)
I_ResumeSong(0); //resume it I_ResumeSong(0); //resume it
/*if (!firsttimeonmouse) if (!firsttimeonmouse)
{ {
if (cv_usemouse.value) I_StartupMouse(); if (cv_usemouse.value) I_StartupMouse();
} }
//else firsttimeonmouse = SDL_FALSE; //else firsttimeonmouse = SDL_FALSE;
if (!disable_mouse && cv_usemouse.value)
SDL_SetRelativeMouseMode(SDL_TRUE);*/
} }
else if (!mousefocus && !kbfocus) else if (!mousefocus && !kbfocus)
{ {
@ -577,34 +570,15 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
window_notinfocus = true; window_notinfocus = true;
I_PauseSong(0); I_PauseSong(0);
/*if (!disable_mouse)
{
SDLforceUngrabMouse();
SDL_SetRelativeMouseMode(SDL_FALSE);
HalfWarpMouse(realwidth, realheight); // warp to center
}*/
memset(gamekeydown, 0, NUMKEYS); // TODO this is a scary memset
/*if (MOUSE_MENU)
{
SDLdoUngrabMouse();
}*/
}
if (!disable_mouse) if (!disable_mouse)
{ {
if (mousefocus) SDLforceUngrabMouse();
{
//if (cv_usemouse.value)
//SDL_SetRelativeMouseMode(SDL_TRUE);
} }
else memset(gamekeydown, 0, NUMKEYS); // TODO this is a scary memset
if (MOUSE_MENU)
{ {
if (SDL_GetRelativeMouseMode() == SDL_TRUE) SDLdoUngrabMouse();
{
SDL_SetRelativeMouseMode(SDL_FALSE);
HalfWarpMouse(realwidth, realheight); // warp to center
}
} }
} }
@ -640,15 +614,15 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window)) if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window))
{ {
//SDLdoUngrabMouse(); SDLdoUngrabMouse();
return; return;
} }
/*if ((evt.x == realwidth/2) && (evt.y == realheight/2)) if ((evt.x == realwidth/2) && (evt.y == realheight/2))
{ {
return; return;
} }
else*/ else
{ {
event.data2 = (INT32)lround((evt.xrel) * ((float)wwidth / (float)realwidth)); event.data2 = (INT32)lround((evt.xrel) * ((float)wwidth / (float)realwidth));
event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight)); event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight));
@ -658,13 +632,9 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window)
{ {
if (SDL_GetRelativeMouseMode() == SDL_FALSE)
SDL_SetRelativeMouseMode(SDL_TRUE);
else
D_PostEvent(&event); D_PostEvent(&event);
//SDL_SetRelativeMouseMode(SDL_TRUE); SDL_SetWindowGrab(window, SDL_TRUE);
//SDL_SetWindowGrab(window, SDL_TRUE); HalfWarpMouse(wwidth, wheight);
//HalfWarpMouse(wwidth, wheight);
} }
} }
} }
@ -862,18 +832,11 @@ void I_GetEvent(void)
void I_StartupMouse(void) void I_StartupMouse(void)
{ {
//static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool firsttimeonmouse = SDL_TRUE;
if (disable_mouse) if (disable_mouse)
return; return;
if (cv_usemouse.value)
SDL_SetRelativeMouseMode(SDL_TRUE);
else if (SDL_GetRelativeMouseMode() == SDL_TRUE) {
SDLdoUngrabMouse();
SDL_SetRelativeMouseMode(SDL_FALSE);
HalfWarpMouse(realwidth, realheight); // warp to center
}
/*
if (!firsttimeonmouse) if (!firsttimeonmouse)
HalfWarpMouse(realwidth, realheight); // warp to center HalfWarpMouse(realwidth, realheight); // warp to center
else else
@ -882,7 +845,6 @@ void I_StartupMouse(void)
return; return;
else else
SDLdoUngrabMouse(); SDLdoUngrabMouse();
*/
} }
// //
@ -1508,7 +1470,7 @@ void I_StartupGraphics(void)
realheight = (Uint16)vid.height; realheight = (Uint16)vid.height;
VID_Command_Info_f(); VID_Command_Info_f();
if (!disable_mouse) SDL_SetRelativeMouseMode(SDL_TRUE); if (!disable_mouse) SDL_ShowCursor(SDL_DISABLE);
SDLdoUngrabMouse(); SDLdoUngrabMouse();
graphics_started = true; graphics_started = true;