Add ClipCursor (Windows only)

This commit is contained in:
Scott Longley
2022-02-18 21:14:08 +10:00
parent 69a1e007a6
commit 8db4c3cfff
4 changed files with 55 additions and 0 deletions

View File

@@ -104,6 +104,7 @@ WindowBase::WindowBase(const CreateWindowSettings& settings)
, _trackingMouseOffset(Vector2::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::EndClippingMouse()
{
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