Merge branch 'feature-clip-cursor' of https://github.com/ScottLongley/FlaxEngine into ScottLongley-feature-clip-cursor

This commit is contained in:
Wojtek Figat
2022-07-16 09:03:47 +02:00
6 changed files with 73 additions and 0 deletions

View File

@@ -116,6 +116,19 @@ CursorLockMode Screen::GetCursorLock()
void Screen::SetCursorLock(CursorLockMode mode)
{
#if USE_EDITOR
const auto win = Editor::Managed->GetGameWindow();
#else
const auto win = Engine::MainWindow;
#endif
if (win && mode == CursorLockMode::Clipped)
{
win->StartClippingCursor(win->GetClientBounds());
}
else if (win && CursorLock == CursorLockMode::Clipped)
{
win->EndClippingCursor();
}
CursorLock = mode;
}

View File

@@ -21,6 +21,11 @@ API_ENUM() enum class CursorLockMode
/// Cursor position is locked to the center of the game window.
/// </summary>
Locked = 1,
/// <summary>
/// Cursor position is confined to the bounds of the game window.
/// </summary>
Clipped = 2,
};
/// <summary>

View File

@@ -104,6 +104,7 @@ WindowBase::WindowBase(const CreateWindowSettings& settings)
, _trackingMouseOffset(Float2::Zero)
, _isUsingMouseOffset(false)
, _isTrackingMouse(false)
, _isClippingCursor(false)
, RenderTask(nullptr)
{
// Update window location based on start location

View File

@@ -288,6 +288,7 @@ protected:
bool _isUsingMouseOffset;
Rectangle _mouseOffsetScreenSize;
bool _isTrackingMouse;
bool _isClippingCursor;
explicit WindowBase(const CreateWindowSettings& settings);
virtual ~WindowBase();
@@ -694,6 +695,29 @@ public:
{
}
/// <summary>
/// Starts the cursor clipping.
/// </summary>
/// <param name="bounds">The bounds that the cursor will be confined to.</param>
API_FUNCTION() virtual void StartClippingCursor(const Rectangle& bounds)
{
}
/// <summary>
/// Gets the value indicating whenever the cursor is being clipped.
/// </summary>
API_PROPERTY() bool IsCursorClipping() const
{
return _isClippingCursor;
}
/// <summary>
/// Ends the cursor clipping.
/// </summary>
API_FUNCTION() virtual void EndClippingCursor()
{
}
/// <summary>
/// Gets the mouse cursor.
/// </summary>

View File

@@ -564,6 +564,34 @@ void WindowsWindow::EndTrackingMouse()
}
}
void WindowsWindow::StartClippingCursor(const Rectangle& bounds)
{
ASSERT(HasHWND());
if (!_isClippingCursor)
{
_isClippingCursor = true;
}
const RECT lpRect = {
bounds.GetUpperLeft().X,
bounds.GetUpperLeft().Y,
bounds.GetBottomRight().X,
bounds.GetBottomRight().Y
};
ClipCursor(&lpRect);
}
void WindowsWindow::EndClippingCursor()
{
if (_isClippingCursor)
{
_isClippingCursor = false;
ClipCursor(NULL);
}
}
void WindowsWindow::SetCursor(CursorType type)
{
// Base

View File

@@ -120,6 +120,8 @@ public:
DragDropEffect DoDragDrop(const StringView& data) override;
void StartTrackingMouse(bool useMouseScreenOffset) override;
void EndTrackingMouse() override;
void StartClippingCursor(const Rectangle& bounds) override;
void EndClippingCursor() override;
void SetCursor(CursorType type) override;
#if USE_EDITOR