From 87d2982bf6778b7289cbf830a10a062f9f662fac Mon Sep 17 00:00:00 2001 From: spacy51 Date: Sun, 2 Dec 2007 01:46:05 +0000 Subject: [PATCH] MainWnd creation is now the same for all render devices --- src/win32/Direct3D.cpp | 124 ++------------------------------------ src/win32/DirectDraw.cpp | 104 +------------------------------- src/win32/OpenGL.cpp | 119 +----------------------------------- src/win32/VBA.cpp | 126 +++++++++++++++++++++++++++++++++++++++ src/win32/VBA.h | 1 + 5 files changed, 136 insertions(+), 338 deletions(-) diff --git a/src/win32/Direct3D.cpp b/src/win32/Direct3D.cpp index 88017a63..d6b7b0b7 100644 --- a/src/win32/Direct3D.cpp +++ b/src/win32/Direct3D.cpp @@ -192,132 +192,16 @@ bool Direct3DDisplay::initialize() TRACE( _T("Initializing Direct3D renderer {\n") ); #endif + if( !theApp.preInitialize() ) return false; + initializing = true; - switch( theApp.cartridgeType ) - { - case IMAGE_GBA: - theApp.sizeX = 240; - theApp.sizeY = 160; - break; - case IMAGE_GB: - if(gbBorderOn) { - theApp.sizeX = 256; - theApp.sizeY = 224; - } else { - theApp.sizeX = 160; - theApp.sizeY = 144; - } - break; - } - - - switch(theApp.videoOption) - { - case VIDEO_1X: - theApp.surfaceSizeX = theApp.sizeX; - theApp.surfaceSizeY = theApp.sizeY; - break; - case VIDEO_2X: - theApp.surfaceSizeX = theApp.sizeX * 2; - theApp.surfaceSizeY = theApp.sizeY * 2; - break; - case VIDEO_3X: - theApp.surfaceSizeX = theApp.sizeX * 3; - theApp.surfaceSizeY = theApp.sizeY * 3; - break; - case VIDEO_4X: - theApp.surfaceSizeX = theApp.sizeX * 4; - theApp.surfaceSizeY = theApp.sizeY * 4; - break; - case VIDEO_320x240: - case VIDEO_640x480: - case VIDEO_800x600: - case VIDEO_1024x768: - case VIDEO_1280x1024: - case VIDEO_OTHER: - float scaleX = ((float)theApp.fsWidth / theApp.sizeX); - float scaleY = ((float)theApp.fsHeight / theApp.sizeY); - float min = (scaleX < scaleY) ? scaleX : scaleY; - if(theApp.fullScreenStretch) { - theApp.surfaceSizeX = theApp.fsWidth; - theApp.surfaceSizeY = theApp.fsHeight; - } else { - theApp.surfaceSizeX = (int)(theApp.sizeX * min); - theApp.surfaceSizeY = (int)(theApp.sizeY * min); - } - break; - } - - theApp.rect.left = 0; - theApp.rect.top = 0; - theApp.rect.right = theApp.sizeX; - theApp.rect.bottom = theApp.sizeY; - - theApp.dest.left = 0; - theApp.dest.top = 0; - theApp.dest.right = theApp.surfaceSizeX; - theApp.dest.bottom = theApp.surfaceSizeY; - - - DWORD style = WS_POPUP | WS_VISIBLE; - DWORD styleEx = 0; - - if(theApp.videoOption <= VIDEO_4X) { - style |= WS_OVERLAPPEDWINDOW; - } else { - styleEx = 0; - } - - if(theApp.videoOption <= VIDEO_4X) { - AdjustWindowRectEx(&theApp.dest, style, TRUE, styleEx); - } else { - AdjustWindowRectEx(&theApp.dest, style, FALSE, styleEx); - } - - int winSizeX = theApp.dest.right-theApp.dest.left; - int winSizeY = theApp.dest.bottom-theApp.dest.top; - - if(theApp.videoOption > VIDEO_4X) { - winSizeX = theApp.fsWidth; - winSizeY = theApp.fsHeight; - } - - int x = 0, y = 0; - - if(theApp.videoOption <= VIDEO_4X) { - x = theApp.windowPositionX; - y = theApp.windowPositionY; - } - - - // Create a window - MainWnd *pWnd = new MainWnd; - theApp.m_pMainWnd = pWnd; - - pWnd->CreateEx(styleEx, - theApp.wndClass, - _T("VisualBoyAdvance"), - style, - x,y,winSizeX,winSizeY, - NULL, - 0); - - if( !((HWND)*pWnd) ) { - DXTRACE_ERR_MSGBOX( _T("Error creating window"), 0 ); - return FALSE; - } - pWnd->DragAcceptFiles(TRUE); - theApp.updateMenuBar(); - theApp.adjustDestRect(); - - // load Direct3D v9 pD3D = Direct3DCreate9( D3D_SDK_VERSION ); if(pD3D == NULL) { DXTRACE_ERR_MSGBOX( _T("Error creating Direct3D object"), 0 ); - return FALSE; + return false; } pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode); @@ -406,7 +290,7 @@ bool Direct3DDisplay::initialize() HRESULT hret = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, - pWnd->GetSafeHwnd(), + theApp.m_pMainWnd->GetSafeHwnd(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &dpp, &pDevice); diff --git a/src/win32/DirectDraw.cpp b/src/win32/DirectDraw.cpp index 667926c6..3e45157f 100644 --- a/src/win32/DirectDraw.cpp +++ b/src/win32/DirectDraw.cpp @@ -180,103 +180,7 @@ void DirectDrawDisplay::cleanup() bool DirectDrawDisplay::initialize() { - theApp.sizeX = 240; - theApp.sizeY = 160; - - switch(theApp.videoOption) { - case VIDEO_1X: - theApp.surfaceSizeX = theApp.sizeX; - theApp.surfaceSizeY = theApp.sizeY; - break; - case VIDEO_2X: - theApp.surfaceSizeX = theApp.sizeX * 2; - theApp.surfaceSizeY = theApp.sizeY * 2; - break; - case VIDEO_3X: - theApp.surfaceSizeX = theApp.sizeX * 3; - theApp.surfaceSizeY = theApp.sizeY * 3; - break; - case VIDEO_4X: - theApp.surfaceSizeX = theApp.sizeX * 4; - theApp.surfaceSizeY = theApp.sizeY * 4; - break; - case VIDEO_320x240: - case VIDEO_640x480: - case VIDEO_800x600: - case VIDEO_1024x768: - case VIDEO_1280x1024: - case VIDEO_OTHER: - { - int scaleX = (theApp.fsWidth / theApp.sizeX); - int scaleY = (theApp.fsHeight / theApp.sizeY); - int min = scaleX < scaleY ? scaleX : scaleY; - if(theApp.fsMaxScale) - min = min > theApp.fsMaxScale ? theApp.fsMaxScale : min; - theApp.surfaceSizeX = theApp.sizeX * min; - theApp.surfaceSizeY = theApp.sizeY * min; - if(theApp.fullScreenStretch) { - theApp.surfaceSizeX = theApp.fsWidth; - theApp.surfaceSizeY = theApp.fsHeight; - } - } - break; - } - - theApp.rect.left = 0; - theApp.rect.top = 0; - theApp.rect.right = theApp.sizeX; - theApp.rect.bottom = theApp.sizeY; - - theApp.dest.left = 0; - theApp.dest.top = 0; - theApp.dest.right = theApp.surfaceSizeX; - theApp.dest.bottom = theApp.surfaceSizeY; - - DWORD style = WS_POPUP | WS_VISIBLE; - DWORD styleEx = 0; - - if(theApp.videoOption <= VIDEO_4X) - style |= WS_OVERLAPPEDWINDOW; - else - styleEx = WS_EX_TOPMOST; - - if(theApp.videoOption <= VIDEO_4X) - AdjustWindowRectEx(&theApp.dest, style, TRUE, styleEx); - else - AdjustWindowRectEx(&theApp.dest, style, FALSE, styleEx); - - int winSizeX = theApp.dest.right-theApp.dest.left; - int winSizeY = theApp.dest.bottom-theApp.dest.top; - - int x = 0; - int y = 0; - - if(theApp.videoOption <= VIDEO_4X) { - x = theApp.windowPositionX; - y = theApp.windowPositionY; - } - - // Create a window - MainWnd *pWnd = new MainWnd; - theApp.m_pMainWnd = pWnd; - - pWnd->CreateEx(styleEx, - theApp.wndClass, - "VisualBoyAdvance", - style, - x,y,winSizeX,winSizeY, - NULL, - 0); - - if (!(HWND)*pWnd) { - winlog("Error creating Window %08x\n", GetLastError()); - return FALSE; - } - - - theApp.updateMenuBar(); - - theApp.adjustDestRect(); + if( !theApp.preInitialize() ) return false; GUID *guid = NULL; if(theApp.ddrawEmulationOnly) @@ -356,7 +260,7 @@ bool DirectDrawDisplay::initialize() DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN; - hret = pDirectDraw->SetCooperativeLevel(pWnd->m_hWnd, + hret = pDirectDraw->SetCooperativeLevel(theApp.m_pMainWnd->GetSafeHwnd(), flags); if(hret != DD_OK) { @@ -432,7 +336,7 @@ bool DirectDrawDisplay::initialize() // if(videoOption <= VIDEO_4X) { hret = pDirectDraw->CreateClipper(0, &ddsClipper, NULL); if(hret == DD_OK) { - ddsClipper->SetHWnd(0, pWnd->m_hWnd); + ddsClipper->SetHWnd(0, theApp.m_pMainWnd->GetSafeHwnd()); if(theApp.videoOption > VIDEO_4X) { if(theApp.tripleBuffering) ddsFlip->SetClipper(ddsClipper); @@ -471,8 +375,6 @@ bool DirectDrawDisplay::initialize() if(failed) return false; - pWnd->DragAcceptFiles(TRUE); - return true; } diff --git a/src/win32/OpenGL.cpp b/src/win32/OpenGL.cpp index 4f2590f4..f28038b2 100644 --- a/src/win32/OpenGL.cpp +++ b/src/win32/OpenGL.cpp @@ -199,121 +199,8 @@ void OpenGLDisplay::cleanup() bool OpenGLDisplay::initialize() { - switch( theApp.cartridgeType ) - { - case IMAGE_GBA: - theApp.sizeX = 240; - theApp.sizeY = 160; - break; - case IMAGE_GB: - if ( gbBorderOn ) - { - theApp.sizeX = 256; - theApp.sizeY = 224; - } - else - { - theApp.sizeX = 160; - theApp.sizeY = 144; - } - break; - } - - - switch(theApp.videoOption) - { - case VIDEO_1X: - theApp.surfaceSizeX = theApp.sizeX; - theApp.surfaceSizeY = theApp.sizeY; - break; - case VIDEO_2X: - theApp.surfaceSizeX = theApp.sizeX * 2; - theApp.surfaceSizeY = theApp.sizeY * 2; - break; - case VIDEO_3X: - theApp.surfaceSizeX = theApp.sizeX * 3; - theApp.surfaceSizeY = theApp.sizeY * 3; - break; - case VIDEO_4X: - theApp.surfaceSizeX = theApp.sizeX * 4; - theApp.surfaceSizeY = theApp.sizeY * 4; - break; - case VIDEO_320x240: - case VIDEO_640x480: - case VIDEO_800x600: - case VIDEO_OTHER: - { - if( theApp.fullScreenStretch ) { - theApp.surfaceSizeX = theApp.fsWidth; - theApp.surfaceSizeY = theApp.fsHeight; - } else { - float scaleX = (float)theApp.fsWidth / (float)theApp.sizeX; - float scaleY = (float)theApp.fsHeight / (float)theApp.sizeY; - float min = ( scaleX < scaleY ) ? scaleX : scaleY; - if( theApp.fsMaxScale ) - min = ( min > (float)theApp.fsMaxScale ) ? (float)theApp.fsMaxScale : min; - theApp.surfaceSizeX = (int)((float)theApp.sizeX * min); - theApp.surfaceSizeY = (int)((float)theApp.sizeY * min); - } - } - break; - } - - theApp.rect.left = 0; - theApp.rect.top = 0; - theApp.rect.right = theApp.sizeX; - theApp.rect.bottom = theApp.sizeY; - - theApp.dest.left = 0; - theApp.dest.top = 0; - theApp.dest.right = theApp.surfaceSizeX; - theApp.dest.bottom = theApp.surfaceSizeY; - - DWORD style = WS_POPUPWINDOW | WS_VISIBLE; - DWORD styleEx = 0; - - if( theApp.videoOption <= VIDEO_4X ) - style |= WS_OVERLAPPEDWINDOW; - else - styleEx = 0; - - if( theApp.videoOption <= VIDEO_4X ) - AdjustWindowRectEx( &theApp.dest, style, TRUE, styleEx ); - else - AdjustWindowRectEx( &theApp.dest, style, FALSE, styleEx ); - - int winSizeX = theApp.dest.right - theApp.dest.left; - int winSizeY = theApp.dest.bottom - theApp.dest.top; - int x = 0, y = 0; - - if( theApp.videoOption <= VIDEO_4X ) { - x = theApp.windowPositionX; - y = theApp.windowPositionY; - } else { - winSizeX = theApp.fsWidth; - winSizeY = theApp.fsHeight; - } - - // Create a window - MainWnd *pWnd = new MainWnd; - theApp.m_pMainWnd = pWnd; - - pWnd->CreateEx( - styleEx, - theApp.wndClass, - "VisualBoyAdvance", - style, - x,y,winSizeX,winSizeY, - NULL, - 0 ); - - if (!(HWND)*pWnd) { - winlog("Error creating Window %08x\n", GetLastError()); - return FALSE; - } - - theApp.updateMenuBar(); - theApp.adjustDestRect(); + if( !theApp.preInitialize() ) return false; + theApp.mode320Available = FALSE; theApp.mode640Available = FALSE; theApp.mode800Available = FALSE; @@ -356,8 +243,6 @@ bool OpenGLDisplay::initialize() if(failed) return false; - pWnd->DragAcceptFiles(TRUE); - return TRUE; } diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index bcc905a9..74f185f2 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -1907,6 +1907,132 @@ bool VBA::initDisplay() return updateRenderMethod(false); } + +bool VBA::preInitialize() +{ + switch( cartridgeType ) + { + case IMAGE_GBA: + sizeX = 240; + sizeY = 160; + break; + case IMAGE_GB: + if( gbBorderOn ) { + sizeX = 256; + sizeY = 224; + } else { + sizeX = 160; + sizeY = 144; + } + break; + } + + switch( videoOption ) + { + case VIDEO_1X: + surfaceSizeX = sizeX; + surfaceSizeY = sizeY; + break; + case VIDEO_2X: + surfaceSizeX = sizeX * 2; + surfaceSizeY = sizeY * 2; + break; + case VIDEO_3X: + surfaceSizeX = sizeX * 3; + surfaceSizeY = sizeY * 3; + break; + case VIDEO_4X: + surfaceSizeX = sizeX * 4; + surfaceSizeY = sizeY * 4; + break; + case VIDEO_320x240: + case VIDEO_640x480: + case VIDEO_800x600: + case VIDEO_1024x768: + case VIDEO_1280x1024: + case VIDEO_OTHER: + float scaleX = (float)fsWidth / sizeX; + float scaleY = (float)fsHeight / sizeY; + float min = ( scaleX < scaleY ) ? scaleX : scaleY; + if( fullScreenStretch ) { + surfaceSizeX = fsWidth; + surfaceSizeY = fsHeight; + } else { + surfaceSizeX = (int)( sizeX * min ); + surfaceSizeY = (int)( sizeY * min ); + } + break; + } + + rect.left = 0; + rect.top = 0; + rect.right = sizeX; + rect.bottom = sizeY; + + dest.left = 0; + dest.top = 0; + dest.right = surfaceSizeX; + dest.bottom = surfaceSizeY; + + + DWORD style = WS_POPUP | WS_VISIBLE; + DWORD styleEx = 0; + + if( videoOption <= VIDEO_4X ) { + style |= WS_OVERLAPPEDWINDOW; + } else { + styleEx = 0; + } + + if( videoOption <= VIDEO_4X ) { + AdjustWindowRectEx( &dest, style, TRUE, styleEx ); + } else { + AdjustWindowRectEx( &dest, style, FALSE, styleEx ); + } + + int winSizeX = dest.right-dest.left; + int winSizeY = dest.bottom-dest.top; + + if( videoOption > VIDEO_4X ) { + winSizeX = fsWidth; + winSizeY = fsHeight; + } + + int x = 0, y = 0; + + if( videoOption <= VIDEO_4X ) { + x = windowPositionX; + y = windowPositionY; + } + + + // Create a window + MainWnd *pWnd = new MainWnd; + m_pMainWnd = pWnd; + + pWnd->CreateEx( + styleEx, + wndClass, + _T("VisualBoyAdvance"), + style, + x, y, + winSizeX, winSizeY, + NULL, + 0 + ); + + if( !((HWND)*pWnd) ) { + winlog( "Error creating Window %08x\n", GetLastError() ); + return false; + } + pWnd->DragAcceptFiles( TRUE ); + updateMenuBar(); + adjustDestRect(); + + return true; +} + + bool VBA::updateRenderMethod(bool force) { Sm60FPS_Init(); diff --git a/src/win32/VBA.h b/src/win32/VBA.h index 2ba7f3d5..6850ed4f 100644 --- a/src/win32/VBA.h +++ b/src/win32/VBA.h @@ -259,6 +259,7 @@ class VBA : public CWinApp void directXMessage(const char *msg); void shutdownDisplay(); void winCheckFullscreen(); + bool preInitialize(); bool updateRenderMethod0(bool force); bool updateRenderMethod(bool force); bool initDisplay();