瀏覽代碼

Fix invalid window border when toggled from fullscreen to windowed mode

Yuri Roubinsky 5 年之前
父節點
當前提交
034625ed93
共有 2 個文件被更改,包括 13 次插入5 次删除
  1. 11 4
      platform/windows/os_windows.cpp
  2. 2 1
      platform/windows/os_windows.h

+ 11 - 4
platform/windows/os_windows.cpp

@@ -1876,6 +1876,8 @@ void OS_Windows::set_window_fullscreen(bool p_enabled) {
 
 	if (p_enabled) {
 
+		was_maximized = maximized;
+
 		if (pre_fs_valid) {
 			GetWindowRect(hWnd, &pre_fs_rect);
 		}
@@ -1905,7 +1907,7 @@ void OS_Windows::set_window_fullscreen(bool p_enabled) {
 			rect.bottom = video_mode.height;
 		}
 
-		_update_window_style(false);
+		_update_window_style(false, was_maximized);
 
 		MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
 
@@ -2087,12 +2089,16 @@ bool OS_Windows::get_borderless_window() {
 	return video_mode.borderless_window;
 }
 
-void OS_Windows::_update_window_style(bool repaint) {
+void OS_Windows::_update_window_style(bool p_repaint, bool p_maximized) {
 	if (video_mode.fullscreen || video_mode.borderless_window) {
 		SetWindowLongPtr(hWnd, GWL_STYLE, WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE);
 	} else {
 		if (video_mode.resizable) {
-			SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE);
+			if (p_maximized) {
+				SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_MAXIMIZE);
+			} else {
+				SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE);
+			}
 		} else {
 			SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_MINIMIZEBOX | WS_POPUPWINDOW | WS_VISIBLE);
 		}
@@ -2100,7 +2106,7 @@ void OS_Windows::_update_window_style(bool repaint) {
 
 	SetWindowPos(hWnd, video_mode.always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
 
-	if (repaint) {
+	if (p_repaint) {
 		RECT rect;
 		GetWindowRect(hWnd, &rect);
 		MoveWindow(hWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE);
@@ -3247,6 +3253,7 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) {
 	control_mem = false;
 	meta_mem = false;
 	minimized = false;
+	was_maximized = false;
 	console_visible = IsWindowVisible(GetConsoleWindow());
 
 	hInstance = _hInstance;

+ 2 - 1
platform/windows/os_windows.h

@@ -176,7 +176,7 @@ class OS_Windows : public OS {
 	void _drag_event(float p_x, float p_y, int idx);
 	void _touch_event(bool p_pressed, float p_x, float p_y, int idx);
 
-	void _update_window_style(bool repaint = true);
+	void _update_window_style(bool p_repaint = true, bool p_maximized = false);
 
 	void _set_mouse_mode_impl(MouseMode p_mode);
 
@@ -209,6 +209,7 @@ protected:
 	bool minimized;
 	bool borderless;
 	bool console_visible;
+	bool was_maximized;
 
 public:
 	LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);