Fixes Issue 2080 for DX9 & OGL

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4910 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
ayuanx 2010-01-20 19:51:13 +00:00
parent 57d6eabace
commit af305ca95b
5 changed files with 91 additions and 151 deletions

View File

@ -200,12 +200,8 @@ HWND OpenWindow(HWND parent, HINSTANCE hInstance, int width, int height, const T
{
m_hParent = m_hMain = parent;
m_hWnd = CreateWindowEx(0, m_szClassName, title, WS_CHILD,
0, 0, width, height,
m_hParent, NULL, hInstance, NULL);
/*if( !g_Config.bFullscreen )
SetWindowPos( GetParent(m_hParent), NULL, 0, 0, width, height, SWP_NOMOVE|SWP_NOZORDER );*/
m_hWnd = CreateWindow(m_szClassName, title, WS_CHILD,
0, 0, width, height, m_hParent, NULL, hInstance, NULL);
}
else
{
@ -217,16 +213,14 @@ HWND OpenWindow(HWND parent, HINSTANCE hInstance, int width, int height, const T
RECT rc = {0, 0, width, height};
AdjustWindowRect(&rc, style, false);
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
RECT rcdesktop;
GetWindowRect(GetDesktopWindow(), &rcdesktop);
rc.left = (1280 - w)/2;
rc.right = rc.left + w;
rc.top = (1024 - h)/2;
rc.bottom = rc.top + h;
int X = (rcdesktop.right-rcdesktop.left)/2 - (rc.right-rc.left)/2;
int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2;
m_hWnd = CreateWindowEx(0, m_szClassName, title, style,
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
m_hWnd = CreateWindow(m_szClassName, title, style,
X, Y, rc.right-rc.left, rc.bottom-rc.top,
NULL, NULL, hInstance, NULL);
}
@ -253,25 +247,10 @@ HWND Create(HWND hParent, HINSTANCE hInstance, const TCHAR *title)
if (Ret)
{
RECT rc = {0, 0, width, height};
RECT rcdesktop;
GetWindowRect(GetDesktopWindow(), &rcdesktop);
int X = (rcdesktop.right-rcdesktop.left)/2 - (rc.right-rc.left)/2;
int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2;
if (g_Config.bFullscreen)
{
ToggleFullscreen(Ret, true);
}
else if (!g_Config.RenderToMainframe)
{
SetWindowPos(EmuWindow::GetWnd(), NULL, X, Y, rc.right-rc.left, rc.bottom-rc.top, SWP_NOREPOSITION | SWP_NOZORDER);
Show();
}
else
{
Show();
}
}
return Ret;
}
@ -311,7 +290,6 @@ void ToggleFullscreen(HWND hParent, bool bForceFull)
return;
}
RECT rcdesktop;
int w_fs = 640, h_fs = 480;
if (!g_Config.bFullscreen || bForceFull)
{
@ -348,25 +326,26 @@ void ToggleFullscreen(HWND hParent, bool bForceFull)
if (strlen(g_Config.cInternalRes) > 1)
sscanf(g_Config.cInternalRes, "%dx%d", &w_fs, &h_fs);
//Get out of fullscreen
g_Config.bFullscreen = false;
// FullScreen - > Desktop
ChangeDisplaySettings(NULL, 0);
// Re-Enable the cursor
ShowCursor(TRUE);
DWORD style = WS_OVERLAPPEDWINDOW;
RECT rc = {0, 0, w_fs, h_fs};
GetWindowRect(GetDesktopWindow(), &rcdesktop);
AdjustWindowRect(&rc, style, false);
RECT rcdesktop;
GetWindowRect(GetDesktopWindow(), &rcdesktop);
// SetWindowPos to the center of the screen
int X = (rcdesktop.right-rcdesktop.left)/2 - (rc.right-rc.left)/2;
int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2;
SetWindowPos(hParent, NULL, X, Y, w_fs, h_fs, SWP_NOREPOSITION | SWP_NOZORDER);
SetWindowPos(hParent, NULL, X, Y, rc.right-rc.left, rc.bottom-rc.top, SWP_NOREPOSITION | SWP_NOZORDER);
// Set new window style FS -> Windowed
SetWindowLong(hParent, GWL_STYLE, WS_OVERLAPPEDWINDOW);
SetWindowLong(hParent, GWL_STYLE, style);
// Re-Enable the cursor
ShowCursor(TRUE);
g_Config.bFullscreen = false;
// Eventually show the window!
EmuWindow::Show();

View File

@ -151,10 +151,6 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
}
}
#if defined(_WIN32)
EmuWindow::SetSize(_twidth, _theight);
#endif
// Control window size and picture scaling
s_backbuffer_width = _twidth;
s_backbuffer_height = _theight;
@ -190,37 +186,18 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
GLWin.cocoaCtx = cocoaGLInit(g_Config.iMultisampleMode);
#elif defined(_WIN32)
// Create rendering window in Windows
// Create a separate window
/*if (!g_Config.RenderToMainframe || g_VideoInitialize.pWindowHandle == NULL)
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create(NULL, g_hInstance, _T("Please wait..."));
// Create a child window
else*/
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create((HWND)g_VideoInitialize.pWindowHandle, g_hInstance, _T("Please wait..."));
// Show the window
EmuWindow::Show();
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create((HWND)g_VideoInitialize.pWindowHandle, g_hInstance, _T("Please wait..."));
if (g_VideoInitialize.pWindowHandle == NULL)
{
g_VideoInitialize.pSysMessage("failed to create window");
return false;
}
GLuint PixelFormat; // Holds The Results After Searching For A Match
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT rcdesktop;
GetWindowRect(GetDesktopWindow(), &rcdesktop);
if (g_Config.bFullscreen) {
//s_backbuffer_width = rcdesktop.right - rcdesktop.left;
//s_backbuffer_height = rcdesktop.bottom - rcdesktop.top;
if (g_Config.bFullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = s_backbuffer_width;
dmScreenSettings.dmPelsHeight = s_backbuffer_height;
dmScreenSettings.dmBitsPerPel = 32;
@ -230,10 +207,15 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
if (MessageBox(NULL, _T("The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?"), _T("NeHe GL"),MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
g_Config.bFullscreen = false;
EmuWindow::ToggleFullscreen(EmuWindow::GetWnd());
else
return false;
}
else
{
// SetWindowPos to the upper-left corner of the screen
SetWindowPos(EmuWindow::GetWnd(), HWND_TOP, 0, 0, _twidth, _theight, SWP_NOREPOSITION | SWP_NOZORDER);
}
}
else
{
@ -241,29 +223,8 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
ChangeDisplaySettings(NULL, 0);
}
if (g_Config.bFullscreen && !g_Config.RenderToMainframe)
{
// Hide the cursor
ShowCursor(FALSE);
}
else
{
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
}
RECT rc = {0, 0, s_backbuffer_width, s_backbuffer_height};
AdjustWindowRectEx(&rc, dwStyle, FALSE, dwExStyle);
int X = (rcdesktop.right-rcdesktop.left)/2 - (rc.right-rc.left)/2;
int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2;
// EmuWindow::GetWnd() is either the new child window or the new separate window
if (g_Config.bFullscreen)
// We put the window at the upper left corner of the screen, so x = y = 0
SetWindowPos(EmuWindow::GetWnd(), NULL, 0, 0, rc.right-rc.left, rc.bottom-rc.top, SWP_NOREPOSITION | SWP_NOZORDER);
else
SetWindowPos(EmuWindow::GetWnd(), NULL, X, Y, rc.right-rc.left, rc.bottom-rc.top, SWP_NOREPOSITION | SWP_NOZORDER);
// Show the window
EmuWindow::Show();
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
@ -286,22 +247,21 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
GLuint PixelFormat; // Holds The Results After Searching For A Match
if (!(hDC=GetDC(EmuWindow::GetWnd()))) {
PanicAlert("(1) Can't create an OpenGL Device context. Fail.");
return false;
}
if (!(PixelFormat = ChoosePixelFormat(hDC,&pfd))) {
PanicAlert("(2) Can't find a suitable PixelFormat.");
return false;
}
if (!SetPixelFormat(hDC, PixelFormat, &pfd)) {
PanicAlert("(3) Can't set the PixelFormat.");
return false;
}
if (!(hRC = wglCreateContext(hDC))) {
PanicAlert("(4) Can't create an OpenGL rendering context.");
return false;

View File

@ -238,8 +238,18 @@ void OnKeyDown(WPARAM wParam)
case VK_ESCAPE:
if (!g_Config.RenderToMainframe)
{
// Pressing Esc stops the emulation
SendMessage( m_hWnd, WM_CLOSE, 0, 0 );
if (g_Config.bFullscreen)
{
// Pressing Esc switches to Windowed in Fullscreen mode
ToggleFullscreen(m_hWnd);
return;
}
else
{
// Pressing Esc stops the emulation
SendMessage( m_hWnd, WM_CLOSE, 0, 0 );
return;
}
}
break;
case '3': // OSD keys
@ -404,14 +414,9 @@ HWND OpenWindow(HWND parent, HINSTANCE hInstance, int width, int height, const T
{
m_hParent = m_hMain = parent;
m_hWnd = CreateWindowEx(0, m_szClassName, title, WS_CHILD,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
parent, NULL, hInstance, NULL);
/*if( !g_Config.bFullscreen )
SetWindowPos( GetParent(m_hParent), NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER );*/
m_hWnd = CreateWindow(m_szClassName, title, WS_CHILD,
0, 0, width, height, parent, NULL, hInstance, NULL);
}
// Create new separate window
else
{
@ -422,69 +427,35 @@ HWND OpenWindow(HWND parent, HINSTANCE hInstance, int width, int height, const T
m_hMain = parent;
DWORD style = g_Config.bFullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW;
RECT rc = {0, 0, width, height};
AdjustWindowRect(&rc, style, false);
RECT rcdesktop;
GetWindowRect(GetDesktopWindow(), &rcdesktop);
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
int X = (rcdesktop.right-rcdesktop.left)/2 - (rc.right-rc.left)/2;
int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2;
rc.left = (1280 - w)/2;
rc.right = rc.left + w;
rc.top = (1024 - h)/2;
rc.bottom = rc.top + h;
m_hWnd = CreateWindowEx(0, m_szClassName, title, style,
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
m_hWnd = CreateWindow(m_szClassName, title, style,
X, Y, rc.right-rc.left, rc.bottom-rc.top,
NULL, NULL, hInstance, NULL);
}
return m_hWnd;
}
void ToggleFullscreen(HWND hParent)
void ToggleFullscreen(HWND hParent, bool bForceFull)
{
if (m_hParent == NULL)
{
int w_fs = 640, h_fs = 480;
if (g_Config.bFullscreen)
if (!g_Config.bFullscreen || bForceFull)
{
if (strlen(g_Config.cInternalRes) > 1)
sscanf(g_Config.cInternalRes, "%dx%d", &w_fs, &h_fs);
// Get out of fullscreen
g_Config.bFullscreen = false;
// FullScreen -> Desktop
ChangeDisplaySettings(NULL, 0);
// Get desktop resolution
RECT rcdesktop;
RECT rc = {0, 0, w_fs, h_fs};
GetWindowRect(GetDesktopWindow(), &rcdesktop);
ShowCursor(TRUE);
// SetWindowPos to the center of the screen
int X = (rcdesktop.right - rcdesktop.left)/2 - (rc.right - rc.left)/2;
int Y = (rcdesktop.bottom - rcdesktop.top)/2 - (rc.bottom - rc.top)/2;
SetWindowPos(hParent, NULL, X, Y, w_fs, h_fs, SWP_NOREPOSITION | SWP_NOZORDER);
// Set new window style FS -> Windowed
SetWindowLongPtr(hParent, GWL_STYLE, WS_OVERLAPPEDWINDOW);
// Eventually show the window!
EmuWindow::Show();
}
else
{
// Get into fullscreen
DEVMODE dmScreenSettings;
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
if (strlen(g_Config.cFSResolution) > 1)
sscanf(g_Config.cFSResolution, "%dx%d", &w_fs, &h_fs);
// Get into fullscreen
DEVMODE dmScreenSettings;
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
// Desktop -> FullScreen
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = w_fs;
@ -499,8 +470,37 @@ void ToggleFullscreen(HWND hParent)
// SetWindowPos to the upper-left corner of the screen
SetWindowPos(hParent, HWND_TOP, 0, 0, w_fs, h_fs, SWP_NOREPOSITION);
g_Config.bFullscreen = true;
ShowCursor(FALSE);
g_Config.bFullscreen = true;
// Eventually show the window!
EmuWindow::Show();
}
else
{
if (strlen(g_Config.cInternalRes) > 1)
sscanf(g_Config.cInternalRes, "%dx%d", &w_fs, &h_fs);
// FullScreen -> Desktop
ChangeDisplaySettings(NULL, 0);
DWORD style = WS_OVERLAPPEDWINDOW;
RECT rc = {0, 0, w_fs, h_fs};
AdjustWindowRect(&rc, style, false);
RECT rcdesktop;
GetWindowRect(GetDesktopWindow(), &rcdesktop);
// SetWindowPos to the center of the screen
int X = (rcdesktop.right-rcdesktop.left)/2 - (rc.right-rc.left)/2;
int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2;
SetWindowPos(hParent, NULL, X, Y, rc.right-rc.left, rc.bottom-rc.top, SWP_NOREPOSITION | SWP_NOZORDER);
// Set new window style FS -> Windowed
SetWindowLongPtr(hParent, GWL_STYLE, style);
// Re-Enable the cursor
ShowCursor(TRUE);
g_Config.bFullscreen = false;
// Eventually show the window!
EmuWindow::Show();

View File

@ -31,7 +31,7 @@ namespace EmuWindow
HWND Create(HWND hParent, HINSTANCE hInstance, const TCHAR *title);
void Show();
void Close();
void ToggleFullscreen(HWND hParent);
void ToggleFullscreen(HWND hParent, bool bForceFull = false);
void SetSize(int displayWidth, int displayHeight);
}

View File

@ -343,7 +343,8 @@ void Initialize(void *init)
#endif
UpdateActiveConfig();
if (!OpenGL_Create(g_VideoInitialize, 640, 480)) {
if (!OpenGL_Create(g_VideoInitialize, 640, 480))
{
g_VideoInitialize.pLog("Renderer::Create failed\n", TRUE);
return;
}