Merge pull request #6566 from thedax/win32-fullscr-fix

Win32: Fix a bug in fullscreen, and consolidate the fullscreen code into one function.
This commit is contained in:
Henrik Rydgård 2014-07-17 17:21:56 +02:00
commit c33833284f
4 changed files with 29 additions and 59 deletions

View File

@ -336,10 +336,7 @@ bool WindowsHost::CreateDesktopShortcut(std::string argumentPath, std::string ga
}
void WindowsHost::GoFullscreen(bool viewFullscreen) {
if (viewFullscreen)
MainWindow::SwitchToFullscreen(mainWindow_);
else
MainWindow::SwitchToWindowed(mainWindow_);
MainWindow::ToggleFullscreen(mainWindow_, viewFullscreen);
}
void WindowsHost::ToggleDebugConsoleVisibility() {

View File

@ -309,59 +309,39 @@ namespace MainWindow
}
}
void SwitchToWindowed(HWND hWnd) {
void ToggleFullscreen(HWND hWnd, bool goingFullscreen = false) {
// Make sure no rendering is happening during the switch.
Core_NotifyWindowHidden(true);
g_inModeSwitch = true; // Make sure WM_SIZE doesn't call Core_NotifyWindowHidden(false)...
// Put caption and border styles back.
DWORD dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE);
DWORD dwNewStyle = dwOldStyle | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU;
::SetWindowLong(hWnd, GWL_STYLE, dwNewStyle);
DWORD dwOldStyle;
DWORD dwNewStyle;
// Put back the menu bar.
::SetMenu(hWnd, menu);
if (!goingFullscreen) {
// Put caption and border styles back.
dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE);
dwNewStyle = dwOldStyle | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU;
// Put back the menu bar.
::SetMenu(hWnd, menu);
} else {
// Remember the normal window rectangle.
::GetWindowRect(hWnd, &g_normalRC);
// Resize to normal view.
ShowWindow(hwndMain, SW_RESTORE);
// Reset full screen indicator.
g_Config.bFullScreen = false;
CorrectCursor();
bool showOSM = (g_Config.iInternalResolution == RESOLUTION_AUTO);
ResizeDisplay(false);
if (showOSM) {
ShowScreenResolution();
// Remove caption and border styles.
dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE);
dwNewStyle = dwOldStyle & ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU);
}
ShowOwnedPopups(hwndMain, TRUE);
W32Util::MakeTopMost(hwndMain, g_Config.bTopMost);
g_inModeSwitch = false;
Core_NotifyWindowHidden(false);
}
void SwitchToFullscreen(HWND hWnd) {
// Make sure no rendering is happening during the switch.
Core_NotifyWindowHidden(true);
g_inModeSwitch = true; // Make sure WM_SIZE doesn't call Core_NotifyWindowHidden(false)...
// Remember the normal window rectangle.
::GetWindowRect(hWnd, &g_normalRC);
// Remove caption and border styles.
DWORD dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE);
DWORD dwNewStyle = dwOldStyle & ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU);
::SetWindowLong(hWnd, GWL_STYLE, dwNewStyle);
// Remove the menu bar.
::SetMenu(hWnd, NULL);
::SetMenu(hWnd, goingFullscreen ? NULL : menu);
// Resize to full screen view.
ShowWindow(hwndMain, SW_MAXIMIZE);
// Resize to the appropriate view.
ShowWindow(hwndMain, goingFullscreen ? SW_MAXIMIZE : SW_RESTORE);
// Set full screen indicator.
g_Config.bFullScreen = true;
g_Config.bFullScreen = goingFullscreen;
CorrectCursor();
bool showOSM = (g_Config.iInternalResolution == RESOLUTION_AUTO);
@ -369,8 +349,8 @@ namespace MainWindow
if (showOSM) {
ShowScreenResolution();
}
ShowOwnedPopups(hwndMain, FALSE);
ShowOwnedPopups(hwndMain, goingFullscreen ? FALSE : TRUE);
W32Util::MakeTopMost(hwndMain, g_Config.bTopMost);
g_inModeSwitch = false;
Core_NotifyWindowHidden(false);
@ -777,7 +757,7 @@ namespace MainWindow
windowTitle = title;
}
BOOL Show(HINSTANCE hInstance, int nCmdShow) {
BOOL Show(HINSTANCE hInstance) {
hInst = hInstance; // Store instance handle in our global variable.
RECT rc = DetermineWindowRectangle();
@ -819,10 +799,7 @@ namespace MainWindow
hideCursor = true;
SetTimer(hwndMain, TIMER_CURSORUPDATE, CURSORUPDATE_INTERVAL_MS, 0);
if (g_Config.bFullScreen)
SwitchToFullscreen(hwndMain);
ShowWindow(hwndMain, nCmdShow);
ToggleFullscreen(hwndMain, g_Config.bFullScreen);
W32Util::MakeTopMost(hwndMain, g_Config.bTopMost);
@ -1506,10 +1483,7 @@ namespace MainWindow
case ID_OPTIONS_FULLSCREEN:
g_Config.bFullScreen = !g_Config.bFullScreen;
if (g_Config.bFullScreen)
SwitchToFullscreen(hWnd);
else
SwitchToWindowed(hWnd);
ToggleFullscreen(hwndMain, g_Config.bFullScreen);
break;

View File

@ -49,7 +49,7 @@ namespace MainWindow
};
void Init(HINSTANCE hInstance);
BOOL Show(HINSTANCE hInstance, int nCmdShow);
BOOL Show(HINSTANCE hInstance);
void CreateDebugWindows();
void DestroyDebugWindows();
void Close();
@ -63,8 +63,7 @@ namespace MainWindow
HWND GetDisplayHWND();
void BrowseAndBoot(std::string defaultPath, bool browseDirectory = false);
void SaveStateActionFinished(bool result, void *userdata);
void SwitchToFullscreen(HWND hWnd);
void SwitchToWindowed(HWND hWnd);
void ToggleFullscreen(HWND hWnd, bool goingFullscreen);
void ToggleDebugConsoleVisibility();
void TranslateMenus();
void setTexScalingMultiplier(int level);

View File

@ -374,7 +374,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
g_hPopupMenus = LoadMenu(_hInstance, (LPCWSTR)IDR_POPUPMENUS);
MainWindow::Show(_hInstance, iCmdShow);
MainWindow::Show(_hInstance);
HWND hwndMain = MainWindow::GetHWND();
HWND hwndDisplay = MainWindow::GetDisplayHWND();