restore relative mouse mode

This commit is contained in:
Lee Salzman 2013-03-05 01:57:05 +02:00
parent 22d4952d17
commit abcd01c584

View File

@ -8,7 +8,7 @@ void cleanup()
{
recorder::stop();
cleanupserver();
if(screen) SDL_SetWindowGrab(screen, SDL_FALSE);
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_ShowCursor(SDL_ENABLE);
cleargamma();
freeocta(worldroot);
@ -47,7 +47,7 @@ void fatal(const char *s, ...) // failure exit
{
if(SDL_WasInit(SDL_INIT_VIDEO))
{
if(screen) SDL_SetWindowGrab(screen, SDL_FALSE);
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_ShowCursor(SDL_ENABLE);
cleargamma();
}
@ -390,7 +390,7 @@ void renderprogress(float bar, const char *text, GLuint tex, bool background)
swapbuffers();
}
bool grabinput = false, minimized = false, allowrepeat = false;
bool grabinput = false, minimized = false, canrelativemouse = true, relativemouse = false, allowrepeat = false;
void keyrepeat(bool on)
{
@ -402,12 +402,20 @@ void inputgrab(bool on)
if(on)
{
SDL_ShowCursor(SDL_DISABLE);
SDL_SetWindowGrab(screen, SDL_TRUE);
if(canrelativemouse)
{
if(SDL_SetRelativeMouseMode(SDL_TRUE) >= 0) relativemouse = true;
else canrelativemouse = false;
}
}
else
{
SDL_ShowCursor(SDL_ENABLE);
SDL_SetWindowGrab(screen, SDL_FALSE);
if(relativemouse)
{
SDL_SetRelativeMouseMode(SDL_FALSE);
relativemouse = false;
}
}
}
@ -574,7 +582,7 @@ void resetgl()
cleanupgl();
setupscreen();
inputgrab(grabinput);
gl_init(scr_w, scr_h);
@ -621,7 +629,7 @@ static bool filterevent(const SDL_Event &event)
switch(event.type)
{
case SDL_MOUSEMOTION:
if(grabinput)
if(grabinput && !relativemouse)
{
if(event.motion.x == screenw / 2 && event.motion.y == screenh / 2)
return false; // ignore any motion events generated by SDL_WarpMouse
@ -674,7 +682,7 @@ static void ignoremousemotion()
static void resetmousemotion()
{
if(grabinput)
if(grabinput && !relativemouse)
{
SDL_WarpMouseInWindow(screen, screenw / 2, screenh / 2);
}