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;
// Center to desktop if (bForGUI && m_prevWindowLoc.x != -1 && m_prevWindowLoc.y != -1) {
m_x = desktopRect.left + ((desktopRect.right - desktopRect.left - m_w) / 2); // Restore to previous Window location
m_y = desktopRect.top + ((desktopRect.bottom - desktopRect.top - m_h) / 2); m_x = m_prevWindowLoc.x;
m_y = m_prevWindowLoc.y;
}
else {
// Center to desktop
m_x = desktopRect.left + ((dWidth - m_w) / 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
@ -2411,19 +2429,25 @@ void WndMain::StartEmulation(HWND hwndParent, DebuggerState LocalDebuggerState /
// stop emulation // stop emulation
void WndMain::StopEmulation() void WndMain::StopEmulation()
{ {
m_bIsStarted = false; m_bIsStarted = false;
if (m_hwndChild != NULL) { if (m_hwndChild != NULL) {
if (IsWindow(m_hwndChild)) { if (IsWindow(m_hwndChild)) {
SendMessage(m_hwndChild, WM_CLOSE, 0, 0); SendMessage(m_hwndChild, WM_CLOSE, 0, 0);
} }
m_hwndChild = NULL; m_hwndChild = NULL;
} }
UpdateCaption(); UpdateCaption();
RefreshMenus(); RefreshMenus();
// Set the window size back to it's GUI dimensions
ResizeWindow(m_hwnd, /*bForGUI=*/true); int iScaleView = FALSE;
g_EmuShared->GetScaleViewport(&iScaleView);
if (iScaleView != 0) {
// Set the window size back to it's GUI dimensions
ResizeWindow(m_hwnd, /*bForGUI=*/true);
}
g_EmuShared->SetIsEmulating(false); g_EmuShared->SetIsEmulating(false);
} }

View File

@ -184,7 +184,7 @@ class WndMain : public Wnd
HBITMAP m_OriLed; HBITMAP m_OriLed;
HBITMAP m_SplashBmp; HBITMAP m_SplashBmp;
HBITMAP m_LogoBmp; HBITMAP m_LogoBmp;
HBITMAP m_GameLogoBMP; HBITMAP m_GameLogoBMP;
HBITMAP m_LedBmp; HBITMAP m_LedBmp;
HBRUSH m_Brushes[4]; HBRUSH m_Brushes[4];
HPEN m_Pens[4]; HPEN m_Pens[4];
@ -239,17 +239,17 @@ class WndMain : public Wnd
// ****************************************************************** // ******************************************************************
// * XInput Enabled Flag // * XInput Enabled Flag
// ****************************************************************** // ******************************************************************
int m_XInputEnabled; int m_XInputEnabled;
// ****************************************************************** // ******************************************************************
// * Hack Flags // * Hack Flags
// ****************************************************************** // ******************************************************************
int m_DisablePixelShaders; int m_DisablePixelShaders;
int m_UncapFramerate; int m_UncapFramerate;
int m_UseAllCores; int m_UseAllCores;
int m_SkipRdtscPatching; int m_SkipRdtscPatching;
int m_ScaleViewport; int m_ScaleViewport;
int m_DirectHostBackBufferAccess; int m_DirectHostBackBufferAccess;
// ****************************************************************** // ******************************************************************
// * debug output filenames // * debug output filenames
@ -261,7 +261,12 @@ class WndMain : public Wnd
// * Storage location // * Storage location
// ****************************************************************** // ******************************************************************
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