Let the mouse move freely when a menu is open or game is paused

That means you can now easily move your mouse out of SRB2's window
and switch between several windows easily by just pressing escape!

Any phase of the game that isn't actual gameplay counts as a menu,
which means you can also move the mouse in cutscenes,
at the title screen, server connection screen,
and even when the chat or console are open.
This commit is contained in:
Louis-Antoine 2020-01-01 13:29:07 +01:00
parent 2728536589
commit caadf6aa61
1 changed files with 7 additions and 10 deletions

View File

@ -67,6 +67,7 @@
#include "../s_sound.h"
#include "../i_joy.h"
#include "../st_stuff.h"
#include "../hu_stuff.h"
#include "../g_game.h"
#include "../i_video.h"
#include "../console.h"
@ -108,6 +109,7 @@ static SDL_bool disable_fullscreen = SDL_FALSE;
#define USE_FULLSCREEN (disable_fullscreen||!allow_fullscreen)?0:cv_fullscreen.value
static SDL_bool disable_mouse = SDL_FALSE;
#define USE_MOUSEINPUT (!disable_mouse && cv_usemouse.value && havefocus)
#define IGNORE_MOUSE (menuactive || paused || con_destlines || chat_on || gamestate != GS_LEVEL)
#define MOUSE_MENU false //(!disable_mouse && cv_usemouse.value && menuactive && !USE_FULLSCREEN)
#define MOUSEBUTTONS_MAX MOUSEBUTTONS
@ -590,7 +592,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
}
//else firsttimeonmouse = SDL_FALSE;
if (USE_MOUSEINPUT)
if (USE_MOUSEINPUT && !IGNORE_MOUSE)
SDLdoGrabMouse();
}
else if (!mousefocus && !kbfocus)
@ -639,7 +641,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
{
if (USE_MOUSEINPUT)
{
if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window))
if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window) || IGNORE_MOUSE)
{
SDLdoUngrabMouse();
return;
@ -687,7 +689,7 @@ static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type)
// this apparently makes a mouse button down event but not a mouse button up event,
// resulting in whatever key was pressed down getting "stuck" if we don't ignore it.
// -- Monster Iestyn (28/05/18)
if (SDL_GetMouseFocus() != window)
if (SDL_GetMouseFocus() != window || IGNORE_MOUSE)
return;
/// \todo inputEvent.button.which
@ -1069,7 +1071,7 @@ void I_StartupMouse(void)
}
else
firsttimeonmouse = SDL_FALSE;
if (cv_usemouse.value)
if (cv_usemouse.value && !IGNORE_MOUSE)
SDLdoGrabMouse();
else
SDLdoUngrabMouse();
@ -1702,12 +1704,7 @@ void I_StartupGraphics(void)
SDL_RaiseWindow(window);
if (mousegrabok && !disable_mouse)
{
SDL_ShowCursor(SDL_DISABLE);
SDL_SetRelativeMouseMode(SDL_TRUE);
wrapmouseok = SDL_TRUE;
SDL_SetWindowGrab(window, SDL_TRUE);
}
SDLdoGrabMouse();
graphics_started = true;
}