Fix StartMouseCapture(true) with secondary monitors on the left
Yes, negative mouse coordinates are a thing
This commit is contained in:
@@ -284,6 +284,7 @@ protected:
|
||||
|
||||
Vector2 _trackingMouseOffset;
|
||||
bool _isUsingMouseOffset;
|
||||
Rectangle _mouseOffsetScreenSize;
|
||||
bool _isTrackingMouse;
|
||||
|
||||
explicit WindowBase(const CreateWindowSettings& settings);
|
||||
|
||||
@@ -479,6 +479,10 @@ void WindowsWindow::StartTrackingMouse(bool useMouseScreenOffset)
|
||||
_trackingMouseOffset = Vector2::Zero;
|
||||
_isUsingMouseOffset = useMouseScreenOffset;
|
||||
|
||||
int32 x = 0 , y = 0, width = 0, height = 0;
|
||||
GetScreenInfo(x, y, width, height);
|
||||
_mouseOffsetScreenSize = Rectangle(x, y, width, height);
|
||||
|
||||
SetCapture(_handle);
|
||||
}
|
||||
}
|
||||
@@ -712,18 +716,20 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
if (_isTrackingMouse && _isUsingMouseOffset)
|
||||
{
|
||||
// Check if move mouse to another edge of the desktop
|
||||
Vector2 destopSize = Platform::GetVirtualDesktopSize();
|
||||
Vector2 desktopLocation = _mouseOffsetScreenSize.Location;
|
||||
Vector2 destopSize = _mouseOffsetScreenSize.GetBottomRight();
|
||||
|
||||
const Vector2 mousePos(static_cast<float>(WINDOWS_GET_X_LPARAM(lParam)), static_cast<float>(WINDOWS_GET_Y_LPARAM(lParam)));
|
||||
Vector2 mousePosition = ClientToScreen(mousePos);
|
||||
Vector2 newMousePosition = mousePosition;
|
||||
if (mousePosition.X <= 1)
|
||||
if (mousePosition.X <= desktopLocation.X + 2)
|
||||
newMousePosition.X = destopSize.X - 2;
|
||||
else if (mousePosition.X >= destopSize.X - 1)
|
||||
newMousePosition.X = 2;
|
||||
if (mousePosition.Y <= 1)
|
||||
newMousePosition.X = desktopLocation.X + 2;
|
||||
if (mousePosition.Y <= desktopLocation.Y + 2)
|
||||
newMousePosition.Y = destopSize.Y - 2;
|
||||
else if (mousePosition.Y >= destopSize.Y - 1)
|
||||
newMousePosition.Y = 2;
|
||||
newMousePosition.Y = desktopLocation.Y + 2;
|
||||
if (!Vector2::NearEqual(mousePosition, newMousePosition))
|
||||
{
|
||||
_trackingMouseOffset -= newMousePosition - mousePosition;
|
||||
|
||||
Reference in New Issue
Block a user