Fix restoring locked cursor state when window gains focus again
This commit is contained in:
@@ -1179,9 +1179,10 @@ namespace FlaxEditor.Windows
|
||||
_cursorVisible = Screen.CursorVisible;
|
||||
_cursorLockMode = Screen.CursorLock;
|
||||
|
||||
// Restore cursor visibility (could be hidden by the game)
|
||||
// Restore cursor state, could be hidden or locked by the game
|
||||
if (!_cursorVisible)
|
||||
Screen.CursorVisible = true;
|
||||
Screen.CursorLock = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,8 @@ public:
|
||||
/// <summary>
|
||||
/// Gets the current state of mouse relative mode.
|
||||
/// </summary>
|
||||
API_FUNCTION() FORCE_INLINE bool IsRelative() const
|
||||
/// <param name="window">The window to check against, or null to check for any window.</param>
|
||||
virtual API_FUNCTION() bool IsRelative(Window* window = nullptr) const
|
||||
{
|
||||
return _relativeMode;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ protected:
|
||||
bool _isHorizontalFlippingMouse = false;
|
||||
bool _isVerticalFlippingMouse = false;
|
||||
bool _isClippingCursor = false;
|
||||
bool _restoreRelativeMode = false;
|
||||
|
||||
explicit WindowBase(const CreateWindowSettings& settings);
|
||||
virtual ~WindowBase();
|
||||
|
||||
@@ -432,6 +432,13 @@ public:
|
||||
if (!SDL_SetWindowRelativeMouseMode(windowHandle, relativeMode))
|
||||
LOG(Error, "Failed to set mouse relative mode: {0}", String(SDL_GetError()));
|
||||
}
|
||||
|
||||
bool IsRelative(Window* window) const override
|
||||
{
|
||||
if (window == nullptr)
|
||||
return _relativeMode;
|
||||
return _relativeModeWindow == window && _relativeMode;
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -440,6 +440,9 @@ void SDLWindow::HandleEvent(SDL_Event& event)
|
||||
if (inRelativeMode)
|
||||
Input::Mouse->SetRelativeMode(true, this);
|
||||
}
|
||||
else if (_restoreRelativeMode)
|
||||
Input::Mouse->SetRelativeMode(true, this);
|
||||
_restoreRelativeMode = false;
|
||||
return;
|
||||
}
|
||||
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||
@@ -448,6 +451,13 @@ void SDLWindow::HandleEvent(SDL_Event& event)
|
||||
SDL_StopTextInput(_window);
|
||||
if (_isClippingCursor)
|
||||
SDL_SetWindowMouseRect(_window, nullptr);
|
||||
|
||||
if (Input::Mouse->IsRelative(this))
|
||||
{
|
||||
Input::Mouse->SetRelativeMode(false, this);
|
||||
_restoreRelativeMode = true;
|
||||
}
|
||||
|
||||
OnLostFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user