mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-25 20:01:04 +00:00
(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
Seems to work so far though
This commit is contained in:
parent
8bbbeff2a9
commit
347b531881
1 changed files with 52 additions and 14 deletions
|
@ -527,7 +527,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which)
|
|||
|
||||
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 kbfocus = SDL_TRUE;
|
||||
|
||||
|
@ -535,17 +535,21 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
|
|||
{
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
mousefocus = SDL_TRUE;
|
||||
//CONS_Printf("Window gained mouse focus!\n");
|
||||
break;
|
||||
case SDL_WINDOWEVENT_LEAVE:
|
||||
mousefocus = SDL_FALSE;
|
||||
//CONS_Printf("Window lost mouse focus!\n");
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
kbfocus = SDL_TRUE;
|
||||
mousefocus = SDL_TRUE;
|
||||
//CONS_Printf("Window gained keyboard focus!\n");
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
kbfocus = SDL_FALSE;
|
||||
mousefocus = SDL_FALSE;
|
||||
//CONS_Printf("Window lost keyboard focus!\n");
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||
break;
|
||||
|
@ -558,11 +562,14 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
|
|||
if (!paused)
|
||||
I_ResumeSong(0); //resume it
|
||||
|
||||
if (!firsttimeonmouse)
|
||||
/*if (!firsttimeonmouse)
|
||||
{
|
||||
if (cv_usemouse.value) I_StartupMouse();
|
||||
}
|
||||
//else firsttimeonmouse = SDL_FALSE;
|
||||
|
||||
if (!disable_mouse && cv_usemouse.value)
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);*/
|
||||
}
|
||||
else if (!mousefocus && !kbfocus)
|
||||
{
|
||||
|
@ -570,15 +577,34 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
|
|||
window_notinfocus = true;
|
||||
I_PauseSong(0);
|
||||
|
||||
if (!disable_mouse)
|
||||
/*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)
|
||||
/*if (MOUSE_MENU)
|
||||
{
|
||||
SDLdoUngrabMouse();
|
||||
}*/
|
||||
}
|
||||
|
||||
if (!disable_mouse)
|
||||
{
|
||||
if (mousefocus)
|
||||
{
|
||||
//if (cv_usemouse.value)
|
||||
//SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GetRelativeMouseMode() == SDL_TRUE)
|
||||
{
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
HalfWarpMouse(realwidth, realheight); // warp to center
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -614,15 +640,15 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
|
|||
|
||||
if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window))
|
||||
{
|
||||
SDLdoUngrabMouse();
|
||||
//SDLdoUngrabMouse();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((evt.x == realwidth/2) && (evt.y == realheight/2))
|
||||
/*if ((evt.x == realwidth/2) && (evt.y == realheight/2))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
else*/
|
||||
{
|
||||
event.data2 = (INT32)lround((evt.xrel) * ((float)wwidth / (float)realwidth));
|
||||
event.data3 = (INT32)lround(-evt.yrel * ((float)wheight / (float)realheight));
|
||||
|
@ -632,9 +658,13 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
|
|||
|
||||
if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window)
|
||||
{
|
||||
D_PostEvent(&event);
|
||||
SDL_SetWindowGrab(window, SDL_TRUE);
|
||||
HalfWarpMouse(wwidth, wheight);
|
||||
if (SDL_GetRelativeMouseMode() == SDL_FALSE)
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
else
|
||||
D_PostEvent(&event);
|
||||
//SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
//SDL_SetWindowGrab(window, SDL_TRUE);
|
||||
//HalfWarpMouse(wwidth, wheight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -832,11 +862,18 @@ void I_GetEvent(void)
|
|||
|
||||
void I_StartupMouse(void)
|
||||
{
|
||||
static SDL_bool firsttimeonmouse = SDL_TRUE;
|
||||
//static SDL_bool firsttimeonmouse = SDL_TRUE;
|
||||
|
||||
if (disable_mouse)
|
||||
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)
|
||||
HalfWarpMouse(realwidth, realheight); // warp to center
|
||||
else
|
||||
|
@ -845,6 +882,7 @@ void I_StartupMouse(void)
|
|||
return;
|
||||
else
|
||||
SDLdoUngrabMouse();
|
||||
*/
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1470,7 +1508,7 @@ void I_StartupGraphics(void)
|
|||
realheight = (Uint16)vid.height;
|
||||
|
||||
VID_Command_Info_f();
|
||||
if (!disable_mouse) SDL_ShowCursor(SDL_DISABLE);
|
||||
if (!disable_mouse) SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
SDLdoUngrabMouse();
|
||||
|
||||
graphics_started = true;
|
||||
|
|
Loading…
Reference in a new issue