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();
#endif
extern int winVideoModeSelect(CWnd *, GUID **);
class Direct3DDisplay : public IDisplay {
private:
bool initialized;
@ -119,7 +117,7 @@ public:
virtual bool changeRenderSize( int w, int h );
virtual void resize( int w, int h );
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 void setOption(const char *, int) {}
virtual bool isSkinSupported() { return true; }
virtual int selectFullScreenMode(GUID **);
virtual bool selectFullScreenMode( VIDEO_MODE &mode );
};
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()

View File

@ -32,6 +32,16 @@ class IDisplay {
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 void cleanup() = 0;
virtual void render() = 0;
@ -42,7 +52,7 @@ class IDisplay {
virtual void setOption(const char *option, int value) {};
virtual DISPLAY_TYPE getType() = 0;
virtual bool isSkinSupported() { return false; }
virtual int selectFullScreenMode(GUID **) = 0;
virtual bool selectFullScreenMode( VIDEO_MODE &mode ) = 0;
};

View File

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

View File

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