diff --git a/Source/Engine/Platform/Base/WindowBase.cpp b/Source/Engine/Platform/Base/WindowBase.cpp
index 5d2cd4ef0..ddb37c21b 100644
--- a/Source/Engine/Platform/Base/WindowBase.cpp
+++ b/Source/Engine/Platform/Base/WindowBase.cpp
@@ -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
diff --git a/Source/Engine/Platform/Base/WindowBase.h b/Source/Engine/Platform/Base/WindowBase.h
index d8c014ef4..dfcad6fe6 100644
--- a/Source/Engine/Platform/Base/WindowBase.h
+++ b/Source/Engine/Platform/Base/WindowBase.h
@@ -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:
{
}
+ ///
+ /// Starts the cursor clipping.
+ ///
+ /// The bounds that the cursor will be confined to.
+ API_FUNCTION() virtual void StartClippingCursor(const Rectangle& bounds)
+ {
+ }
+
+ ///
+ /// Gets the value indicating whenever the cursor is being clipped.
+ ///
+ API_PROPERTY bool IsCursorClipping() const
+ {
+ return _isClippingCursor;
+ }
+
+ ///
+ /// Ends the cursor clipping.
+ ///
+ API_FUNCTION() virtual void EndClippingCursor()
+ {
+ }
+
///
/// Gets the mouse cursor.
///
diff --git a/Source/Engine/Platform/Windows/WindowsWindow.cpp b/Source/Engine/Platform/Windows/WindowsWindow.cpp
index 50f092407..733064016 100644
--- a/Source/Engine/Platform/Windows/WindowsWindow.cpp
+++ b/Source/Engine/Platform/Windows/WindowsWindow.cpp
@@ -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
diff --git a/Source/Engine/Platform/Windows/WindowsWindow.h b/Source/Engine/Platform/Windows/WindowsWindow.h
index e9d65a9e9..cf0c4735d 100644
--- a/Source/Engine/Platform/Windows/WindowsWindow.h
+++ b/Source/Engine/Platform/Windows/WindowsWindow.h
@@ -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