Merge pull request #1332 from RadWolfie/preserve-window-position

Preserve window position after stop emulation
This commit is contained in:
Luke Usher 2018-07-06 08:02:10 +01:00 committed by GitHub
commit 56bbfe7586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 19 deletions

View File

@ -136,9 +136,16 @@ void WndMain::ResizeWindow(HWND hwnd, bool bForGUI)
if (m_h > dHeight) if (m_h > dHeight)
m_h = dHeight; m_h = dHeight;
if (bForGUI && m_prevWindowLoc.x != -1 && m_prevWindowLoc.y != -1) {
// Restore to previous Window location
m_x = m_prevWindowLoc.x;
m_y = m_prevWindowLoc.y;
}
else {
// Center to desktop // Center to desktop
m_x = desktopRect.left + ((desktopRect.right - desktopRect.left - m_w) / 2); m_x = desktopRect.left + ((dWidth - m_w) / 2);
m_y = desktopRect.top + ((desktopRect.bottom - desktopRect.top - m_h) / 2); m_y = desktopRect.top + ((dHeight - m_h) / 2);
}
// Resize the window so it's client area can contain the requested resolution // Resize the window so it's client area can contain the requested resolution
windowRect = { m_x, m_y, m_x + m_w, m_y + m_h }; windowRect = { m_x, m_y, m_x + m_w, m_y + m_h };
@ -166,7 +173,8 @@ WndMain::WndMain(HINSTANCE x_hInstance) :
m_StorageLocation(""), m_StorageLocation(""),
m_dwRecentXbe(0), m_dwRecentXbe(0),
m_hDebuggerProc(nullptr), m_hDebuggerProc(nullptr),
m_hDebuggerMonitorThread() m_hDebuggerMonitorThread(),
m_prevWindowLoc({ -1, -1 })
{ {
// initialize members // initialize members
{ {
@ -2351,6 +2359,16 @@ void WndMain::StartEmulation(HWND hwndParent, DebuggerState LocalDebuggerState /
// register storage location with emulator process // register storage location with emulator process
g_EmuShared->SetStorageLocation(m_StorageLocation); g_EmuShared->SetStorageLocation(m_StorageLocation);
// Preserve previous GUI window location.
HWND hOwner = GetParent(m_hwnd);
RECT curWindowPos;
GetWindowRect((hOwner != nullptr ? hOwner : m_hwnd), &curWindowPos);
m_prevWindowLoc.x = curWindowPos.left;
m_prevWindowLoc.y = curWindowPos.top;
ScreenToClient((hOwner != nullptr ? hOwner : m_hwnd), &m_prevWindowLoc);
m_prevWindowLoc.x = curWindowPos.left - m_prevWindowLoc.x;
m_prevWindowLoc.y = curWindowPos.top - m_prevWindowLoc.y;
if (m_ScaleViewport) { if (m_ScaleViewport) {
// Set the window size to emulation dimensions // Set the window size to emulation dimensions
// Note : Doing this here assures the emulation process will use // Note : Doing this here assures the emulation process will use
@ -2422,8 +2440,14 @@ void WndMain::StopEmulation()
UpdateCaption(); UpdateCaption();
RefreshMenus(); RefreshMenus();
int iScaleView = FALSE;
g_EmuShared->GetScaleViewport(&iScaleView);
if (iScaleView != 0) {
// Set the window size back to it's GUI dimensions // Set the window size back to it's GUI dimensions
ResizeWindow(m_hwnd, /*bForGUI=*/true); ResizeWindow(m_hwnd, /*bForGUI=*/true);
}
g_EmuShared->SetIsEmulating(false); g_EmuShared->SetIsEmulating(false);
} }

View File

@ -262,6 +262,11 @@ class WndMain : public Wnd
// ****************************************************************** // ******************************************************************
CXBX_DATA m_StorageToggle; CXBX_DATA m_StorageToggle;
char m_StorageLocation[MAX_PATH]; char m_StorageLocation[MAX_PATH];
// ******************************************************************
// * Previous GUI window location (before start emulation)
// ******************************************************************
POINT m_prevWindowLoc;
}; };
#endif #endif