Improve cursor clipping logic (fix after alt+tab and confine to game window in Editor)

#691
This commit is contained in:
Wojtek Figat
2022-07-17 00:09:59 +02:00
parent fe0e24357a
commit 7f3a32a69b
7 changed files with 65 additions and 69 deletions

View File

@@ -19,7 +19,6 @@ static CursorLockMode CursorLock = CursorLockMode::None;
class ScreenService : public EngineService
{
public:
ScreenService()
: EngineService(TEXT("Screen"), 120)
{
@@ -89,7 +88,7 @@ Float2 Screen::GameViewportToScreen(const Float2& viewportPos)
bool Screen::GetCursorVisible()
{
#if USE_EDITOR
const auto win = Editor::Managed->GetGameWindow();
const auto win = Editor::Managed->GetGameWindow(true);
#else
const auto win = Engine::MainWindow;
#endif
@@ -99,7 +98,7 @@ bool Screen::GetCursorVisible()
void Screen::SetCursorVisible(const bool value)
{
#if USE_EDITOR
const auto win = Editor::Managed->GetGameWindow();
const auto win = Editor::Managed->GetGameWindow(true);
#else
const auto win = Engine::MainWindow;
#endif
@@ -117,13 +116,18 @@ CursorLockMode Screen::GetCursorLock()
void Screen::SetCursorLock(CursorLockMode mode)
{
#if USE_EDITOR
const auto win = Editor::Managed->GetGameWindow();
const auto win = Editor::Managed->GetGameWindow(true);
#else
const auto win = Engine::MainWindow;
#endif
if (win && mode == CursorLockMode::Clipped)
{
win->StartClippingCursor(win->GetClientBounds());
#if USE_EDITOR
Rectangle bounds(Editor::Managed->GameViewportToScreen(Float2::Zero), Editor::Managed->GetGameWindowSize());
#else
Rectangle bounds = win->GetClientBounds();
#endif
win->StartClippingCursor(bounds);
}
else if (win && CursorLock == CursorLockMode::Clipped)
{