Prepare display interface for adding an extended full screen settings dialog.

Changes are backwards compatible to the old DirectDraw video mode enumeration code.
This commit is contained in:
spacy51 2008-01-14 23:13:49 +00:00
parent 45c2112d4a
commit 49b96b6be8
5 changed files with 93 additions and 44 deletions

View File

@ -63,8 +63,6 @@ extern "C" bool cpu_mmx;
extern bool detectMMX(); extern bool detectMMX();
#endif #endif
extern int winVideoModeSelect(CWnd *, GUID **);
class Direct3DDisplay : public IDisplay { class Direct3DDisplay : public IDisplay {
private: private:
bool initialized; bool initialized;
@ -119,7 +117,7 @@ public:
virtual bool changeRenderSize( int w, int h ); virtual bool changeRenderSize( int w, int h );
virtual void resize( int w, int h ); virtual void resize( int w, int h );
virtual void setOption( const char *option, int value ); virtual void setOption( const char *option, int value );
virtual int selectFullScreenMode( GUID ** ); virtual bool selectFullScreenMode( VIDEO_MODE &mode );
}; };
@ -520,9 +518,34 @@ void Direct3DDisplay::resize( int w, int h )
} }
int Direct3DDisplay::selectFullScreenMode( GUID **pGUID ) bool Direct3DDisplay::selectFullScreenMode( VIDEO_MODE &mode )
{ {
return winVideoModeSelect(theApp.m_pMainWnd, pGUID); // TODO: Add display mode enumeration dialog
if( !pD3D ) return false;
D3DDISPLAYMODE m;
pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &m );
mode.adapter = D3DADAPTER_DEFAULT;
mode.width = m.Width;
mode.height = m.Height;
mode.frequency = m.RefreshRate;
switch( m.Format )
{
case D3DFMT_X1R5G5B5:
case D3DFMT_R5G6B5:
mode.bitDepth = 16;
break;
case D3DFMT_R8G8B8:
mode.bitDepth = 24;
break;
case D3DFMT_X8R8G8B8:
mode.bitDepth = 32;
break;
default:
return false;
break;
}
return true;
// return false; when cancel is clicked
} }

View File

@ -72,7 +72,7 @@ public:
virtual DISPLAY_TYPE getType() { return DIRECT_DRAW; }; virtual DISPLAY_TYPE getType() { return DIRECT_DRAW; };
virtual void setOption(const char *, int) {} virtual void setOption(const char *, int) {}
virtual bool isSkinSupported() { return true; } virtual bool isSkinSupported() { return true; }
virtual int selectFullScreenMode(GUID **); virtual bool selectFullScreenMode( VIDEO_MODE &mode );
}; };
static HRESULT WINAPI checkModesAvailable(LPDDSURFACEDESC2 surf, LPVOID lpContext) static HRESULT WINAPI checkModesAvailable(LPDDSURFACEDESC2 surf, LPVOID lpContext)
@ -702,9 +702,18 @@ void DirectDrawDisplay::render()
} }
} }
int DirectDrawDisplay::selectFullScreenMode(GUID **pGUID) bool DirectDrawDisplay::selectFullScreenMode( VIDEO_MODE &mode )
{ {
return winVideoModeSelect(theApp.m_pMainWnd, pGUID); int ret = winVideoModeSelect( theApp.m_pMainWnd, &mode.adapter_ddraw );
if( ret == -1 ) {
return false;
} else {
mode.width = (ret >> 12) & 0xFFF;
mode.height = ret & 0xFFF;
mode.bitDepth = ret >> 24;
return true;
}
} }
IDisplay *newDirectDrawDisplay() IDisplay *newDirectDrawDisplay()

View File

@ -32,6 +32,16 @@ class IDisplay {
IDisplay() {}; IDisplay() {};
virtual ~IDisplay() {}; virtual ~IDisplay() {};
struct VIDEO_MODE
{
GUID *adapter_ddraw;
unsigned char adapter;
unsigned short width;
unsigned short height;
unsigned char bitDepth;
unsigned char frequency;
};
virtual bool initialize() = 0; virtual bool initialize() = 0;
virtual void cleanup() = 0; virtual void cleanup() = 0;
virtual void render() = 0; virtual void render() = 0;
@ -42,7 +52,7 @@ class IDisplay {
virtual void setOption(const char *option, int value) {}; virtual void setOption(const char *option, int value) {};
virtual DISPLAY_TYPE getType() = 0; virtual DISPLAY_TYPE getType() = 0;
virtual bool isSkinSupported() { return false; } virtual bool isSkinSupported() { return false; }
virtual int selectFullScreenMode(GUID **) = 0; virtual bool selectFullScreenMode( VIDEO_MODE &mode ) = 0;
}; };

View File

@ -337,35 +337,39 @@ void MainWnd::OnOptionsVideoFullscreen1280x1024()
OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN1280X1024); OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN1280X1024);
} }
void MainWnd::OnOptionsVideoFullscreen() void MainWnd::OnOptionsVideoFullscreen()
{ {
theApp.winCheckFullscreen(); theApp.winCheckFullscreen();
GUID *pGUID = NULL;
int size = theApp.display->selectFullScreenMode(&pGUID); IDisplay::VIDEO_MODE mode;
if(size != -1) { ZeroMemory( &mode, sizeof(IDisplay::VIDEO_MODE) );
int width = (size >> 12) & 4095;
int height = (size & 4095); if( theApp.display->selectFullScreenMode( mode ) ) {
int colorDepth = (size >> 24); if( ( mode.width != theApp.fsWidth ) ||
if(width != theApp.fsWidth || ( mode.height != theApp.fsHeight ) ||
height != theApp.fsHeight || ( mode.bitDepth != theApp.fsColorDepth ) ||
colorDepth != theApp.fsColorDepth || ( mode.frequency != theApp.fsFrequency ) ||
pGUID != theApp.pVideoDriverGUID || ( mode.adapter_ddraw != theApp.pVideoDriverGUID ) ||
theApp.videoOption != VIDEO_OTHER) { ( mode.adapter != theApp.fsAdapter ) ||
( theApp.videoOption != VIDEO_OTHER ) )
{
theApp.fsForceChange = true; theApp.fsForceChange = true;
theApp.fsWidth = width; theApp.fsWidth = mode.width;
theApp.fsHeight = height; theApp.fsHeight = mode.height;
theApp.fsFrequency = 60; theApp.fsFrequency = mode.frequency;
theApp.fsColorDepth = colorDepth; theApp.fsColorDepth = mode.bitDepth;
theApp.pVideoDriverGUID = pGUID; theApp.pVideoDriverGUID = mode.adapter_ddraw;
if(pGUID) { theApp.fsAdapter = mode.adapter;
theApp.videoDriverGUID = *pGUID; if( mode.adapter_ddraw ) {
regSetDwordValue("defaultVideoDriver", FALSE); theApp.videoDriverGUID = *mode.adapter_ddraw;
regSetBinaryValue("videoDriverGUID", regSetDwordValue( "defaultVideoDriver", FALSE );
(char *)pGUID, sizeof(GUID)); regSetBinaryValue( "videoDriverGUID",
(char *)mode.adapter_ddraw, sizeof(GUID) );
} else { } else {
regSetDwordValue("defaultVideoDriver", TRUE); regSetDwordValue( "defaultVideoDriver", TRUE );
} }
theApp.updateVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN); theApp.updateVideoSize( ID_OPTIONS_VIDEO_FULLSCREEN );
if( theApp.renderMethod == DIRECT_DRAW ) { if( theApp.renderMethod == DIRECT_DRAW ) {
theApp.m_pMainWnd->PostMessage(VBA_CONFIRM_MODE); theApp.m_pMainWnd->PostMessage(VBA_CONFIRM_MODE);
} }
@ -374,6 +378,7 @@ void MainWnd::OnOptionsVideoFullscreen()
theApp.winAccelMgr.UpdateMenu(theApp.menu); theApp.winAccelMgr.UpdateMenu(theApp.menu);
} }
void MainWnd::OnUpdateOptionsVideoFullscreen(CCmdUI* pCmdUI) void MainWnd::OnUpdateOptionsVideoFullscreen(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck(theApp.videoOption == VIDEO_OTHER); pCmdUI->SetCheck(theApp.videoOption == VIDEO_OTHER);

View File

@ -121,7 +121,7 @@ public:
virtual bool changeRenderSize( int w, int h ); virtual bool changeRenderSize( int w, int h );
virtual void resize( int w, int h ); virtual void resize( int w, int h );
virtual void setOption( const char *, int ); virtual void setOption( const char *, int );
virtual int selectFullScreenMode( GUID ** ); virtual bool selectFullScreenMode( VIDEO_MODE &mode );
}; };
#include "gzglfont.h" #include "gzglfont.h"
@ -652,17 +652,19 @@ void OpenGLDisplay::setOption( const char *option, int value )
} }
//set fullscreen mode //set fullscreen mode
int OpenGLDisplay::selectFullScreenMode( GUID ** ) bool OpenGLDisplay::selectFullScreenMode( VIDEO_MODE &mode )
{ {
// TODO: Add display mode enumeration dialog
HWND wnd = GetDesktopWindow(); HWND wnd = GetDesktopWindow();
RECT r; RECT r;
GetWindowRect( wnd, &r ); GetWindowRect( wnd, &r );
int w = ( r.right - r.left ) & 0xFFF; mode.width = (unsigned short)( r.right - r.left );
int h = ( r.bottom - r.top ) & 0xFFF; mode.height = (unsigned short)( r.bottom - r.top );
HDC dc = GetDC( wnd ); HDC dc = GetDC( wnd );
int c = GetDeviceCaps( dc, BITSPIXEL ); mode.bitDepth = GetDeviceCaps( dc, BITSPIXEL );
ReleaseDC( wnd, dc ); ReleaseDC( wnd, dc );
return (c << 24) | (w << 12) | h; return true;
// return false; when cancel is clicked
} }