浏览代码

Fix mouse confined leaving window with OS_Windows::set_window_position

Guilherme Felipe 7 年之前
父节点
当前提交
bd3d73a9fd
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      platform/windows/os_windows.cpp

+ 9 - 0
platform/windows/os_windows.cpp

@@ -1711,6 +1711,15 @@ void OS_Windows::set_window_position(const Point2 &p_position) {
 	RECT r;
 	GetWindowRect(hWnd, &r);
 	MoveWindow(hWnd, p_position.x, p_position.y, r.right - r.left, r.bottom - r.top, TRUE);
+
+	// Don't let the mouse leave the window when moved
+	if (mouse_mode == MOUSE_MODE_CONFINED) {
+		RECT rect;
+		GetClientRect(hWnd, &rect);
+		ClientToScreen(hWnd, (POINT *)&rect.left);
+		ClientToScreen(hWnd, (POINT *)&rect.right);
+		ClipCursor(&rect);
+	}
 }
 Size2 OS_Windows::get_window_size() const {