DXGL r795 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r794‎ | r795 | r796 >
Date:01:14, 26 March 2018
Author:admin
Status:new
Tags:
Comment:
Add hack for cropping 640x480 modes to 640x400.
Remove unimplemented "Write INI file..." button from DXGL Config.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /dxglcfg/dxglcfg.rc (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2017 William Feely
 3+// Copyright (C) 2011-2018 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -1729,7 +1729,9 @@
17301730 TRACE_ENTER(1, 14, This);
17311731 if (This->currmode.dmSize != 0)
17321732 {
1733 - ChangeDisplaySettingsEx(NULL, &This->currmode, NULL, CDS_FULLSCREEN, NULL);
 1733+ if((This->currmode.dmPelsWidth == 640) && (This->currmode.dmPelsHeight == 480)
 1734+ && dxglcfg.HackCrop640480to640400) Try640400Mode(NULL, &This->currmode, CDS_FULLSCREEN, NULL);
 1735+ else ChangeDisplaySettingsEx(NULL, &This->currmode, NULL, CDS_FULLSCREEN, NULL);
17341736 }
17351737 TRACE_EXIT(0, 0);
17361738 }
@@ -1741,6 +1743,8 @@
17421744 {
17431745 glDD7->internalx = glDD7->screenx = dwWidth;
17441746 glDD7->internaly = glDD7->screeny = dwHeight;
 1747+ if ((glDD7->primaryx == 640) && (glDD7->primaryy == 480) && dxglcfg.HackCrop640480to640400)
 1748+ glDD7->internaly *= 1.2f;
17451749 if (glDD7->renderer && glDD7->primary) glRenderer_DrawScreen(glDD7->renderer, glDD7->primary->texture,
17461750 glDD7->primary->texture->palette, 0, NULL);
17471751 }
@@ -1919,6 +1923,26 @@
19201924 else return 0;
19211925 }
19221926
 1927+LONG Try640400Mode(LPCWSTR devname, DEVMODE *mode, DWORD flags, BOOL *crop400)
 1928+{
 1929+ LONG error;
 1930+ DEVMODE newmode = *mode;
 1931+ newmode.dmPelsHeight = 400;
 1932+ error = ChangeDisplaySettingsEx(devname, &newmode, NULL, flags, NULL);
 1933+ if (error == DISP_CHANGE_SUCCESSFUL) return error;
 1934+ // Try setting refresh to 70
 1935+ newmode.dmDisplayFrequency = 70;
 1936+ error = ChangeDisplaySettingsEx(devname, &newmode, NULL, flags, NULL);
 1937+ if (error == DISP_CHANGE_SUCCESSFUL) return error;
 1938+ // Try without refresh
 1939+ newmode.dmFields &= (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS | DM_POSITION);
 1940+ error = ChangeDisplaySettingsEx(devname, &newmode, NULL, flags, NULL);
 1941+ if (error == DISP_CHANGE_SUCCESSFUL) return error;
 1942+ // Finally try the original mode
 1943+ if(crop400) *crop400 = FALSE;
 1944+ return ChangeDisplaySettingsEx(devname, mode, NULL, flags, NULL);
 1945+}
 1946+
19231947 HRESULT WINAPI glDirectDraw7::SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwRefreshRate, DWORD dwFlags)
19241948 {
19251949 TRACE_ENTER(6,14,this,8,dwWidth,8,dwHeight,8,dwBPP,8,dwRefreshRate,9,dwFlags);
@@ -1940,7 +1964,9 @@
19411965 float aspect,xmul,ymul,xscale,yscale;
19421966 LONG error;
19431967 DWORD flags;
 1968+ BOOL crop400 = FALSE;
19441969 int stretchmode;
 1970+ if ((dwWidth == 640) && (dwHeight == 480) && dxglcfg.HackCrop640480to640400) crop400 = TRUE;
19451971 if ((dxglcfg.AddColorDepths & 2) && !(dxglcfg.AddColorDepths & 4) && (dwBPP == 16))
19461972 dwBPP = 15;
19471973 if(!oldmode.dmSize)
@@ -1995,7 +2021,8 @@
19962022 else newmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
19972023 flags = 0;
19982024 if (fullscreen) flags |= CDS_FULLSCREEN;
1999 - error = ChangeDisplaySettingsEx(NULL, &newmode, NULL, flags, NULL);
 2025+ if (crop400) error = Try640400Mode(NULL, &newmode, flags, &crop400);
 2026+ else error = ChangeDisplaySettingsEx(NULL, &newmode, NULL, flags, NULL);
20002027 switch (error)
20012028 {
20022029 case DISP_CHANGE_SUCCESSFUL:
@@ -2011,7 +2038,8 @@
20122039 primaryy = newmode.dmPelsHeight / yscale;
20132040 }
20142041 screenx = newmode.dmPelsWidth;
2015 - screeny = newmode.dmPelsHeight;
 2042+ if (crop400) screeny = 400;
 2043+ else screeny = newmode.dmPelsHeight;
20162044 internalx = newmode.dmPelsWidth;
20172045 internaly = newmode.dmPelsHeight;
20182046 internalbpp = screenbpp = newmode.dmBitsPerPel;
@@ -2047,6 +2075,7 @@
20482076 internalx = screenx = currmode.dmPelsWidth;
20492077 primaryy = dwHeight;
20502078 internaly = screeny = currmode.dmPelsHeight;
 2079+ if (crop400) internaly *= 1.2f;
20512080 if (dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
20522081 else internalbpp = screenbpp = currmode.dmBitsPerPel;
20532082 if (dwRefreshRate) internalrefresh = primaryrefresh = screenrefresh = dwRefreshRate;
@@ -2093,15 +2122,18 @@
20942123 else
20952124 {
20962125 xmul = (float)screenx / (float)dwWidth;
2097 - ymul = (float)screeny / (float)dwHeight;
 2126+ if (crop400) ymul = (float)screeny / 400.0f;
 2127+ else ymul = (float)screeny / (float)dwHeight;
20982128 if ((float)dwWidth*(float)ymul > (float)screenx)
20992129 {
21002130 internalx = (DWORD)((float)dwWidth * (float)xmul);
2101 - internaly = (DWORD)((float)dwHeight * (float)xmul);
 2131+ if(crop400) internaly = (DWORD)(400.0f * (float)xmul);
 2132+ else internaly = (DWORD)((float)dwHeight * (float)xmul);
21022133 }
21032134 else
21042135 {
21052136 internalx = (DWORD)((float)dwWidth * (float)ymul);
 2137+ if(crop400) internaly = (DWORD)(400.0f * (float)ymul);
21062138 internaly = (DWORD)((float)dwHeight * (float)ymul);
21072139 }
21082140 }
@@ -2163,13 +2195,16 @@
21642196 else newmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
21652197 flags = 0;
21662198 if (fullscreen) flags |= CDS_FULLSCREEN;
2167 - error = ChangeDisplaySettingsEx(NULL, &newmode, NULL, flags, NULL);
 2199+ if (crop400) error = Try640400Mode(NULL, &newmode, flags, &crop400);
 2200+ else error = ChangeDisplaySettingsEx(NULL, &newmode, NULL, flags, NULL);
21682201 if (error != DISP_CHANGE_SUCCESSFUL)
21692202 {
21702203 newmode2 = FindClosestMode(newmode);
2171 - error = ChangeDisplaySettingsEx(NULL, &newmode2, NULL, flags, NULL);
 2204+ if (crop400) error = Try640400Mode(NULL, &newmode2, flags, &crop400);
 2205+ else error = ChangeDisplaySettingsEx(NULL, &newmode2, NULL, flags, NULL);
21722206 }
21732207 else newmode2 = newmode;
 2208+ if (crop400) newmode2.dmPelsHeight = 400;
21742209 if (error == DISP_CHANGE_SUCCESSFUL) this->currmode = newmode2;
21752210 switch (dxglcfg.scaler)
21762211 {
@@ -2178,6 +2213,7 @@
21792214 internalx = screenx = newmode2.dmPelsWidth;
21802215 primaryy = dwHeight;
21812216 internaly = screeny = newmode2.dmPelsHeight;
 2217+ if (crop400) internaly *= 1.2f;
21822218 if (dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
21832219 else internalbpp = screenbpp = newmode2.dmBitsPerPel;
21842220 if (dwRefreshRate) internalrefresh = primaryrefresh = screenrefresh = dwRefreshRate;
@@ -2224,15 +2260,18 @@
22252261 else
22262262 {
22272263 xmul = (float)screenx / (float)dwWidth;
2228 - ymul = (float)screeny / (float)dwHeight;
 2264+ if (crop400) ymul = (float)screeny / 400.0f;
 2265+ else ymul = (float)screeny / (float)dwHeight;
22292266 if ((float)dwWidth*(float)ymul > (float)screenx)
22302267 {
22312268 internalx = (DWORD)((float)dwWidth * (float)xmul);
2232 - internaly = (DWORD)((float)dwHeight * (float)xmul);
 2269+ if (crop400) internaly = (DWORD)(400.0f * (float)xmul);
 2270+ else internaly = (DWORD)((float)dwHeight * (float)xmul);
22332271 }
22342272 else
22352273 {
22362274 internalx = (DWORD)((float)dwWidth * (float)ymul);
 2275+ if (crop400) internaly = (DWORD)(400.0f * (float)ymul);
22372276 internaly = (DWORD)((float)dwHeight * (float)ymul);
22382277 }
22392278 }
@@ -2362,7 +2401,12 @@
23632402 primaryx = dwWidth;
23642403 internalx = screenx = dwWidth * xscale;
23652404 primaryy = dwHeight;
2366 - internaly = screeny = dwHeight * yscale;
 2405+ if (crop400)
 2406+ {
 2407+ screeny = 400 * yscale;
 2408+ internaly = dwHeight * yscale;
 2409+ }
 2410+ else internaly = screeny = dwHeight * yscale;
23672411 internalbpp = screenbpp = dwBPP;
23682412 if (dwRefreshRate) internalrefresh = primaryrefresh = screenrefresh = dwRefreshRate;
23692413 else internalrefresh = primaryrefresh = screenrefresh = currmode.dmDisplayFrequency;
Index: ddraw/glDirectDraw.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2016 William Feely
 3+// Copyright (C) 2011-2018 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -144,6 +144,7 @@
145145 extern "C" void glDirectDraw7_UnrestoreDisplayMode(glDirectDraw7 *This);
146146 extern "C" void glDirectDraw7_GetSizes(glDirectDraw7 *glDD7, LONG *sizes);
147147 extern "C" void glDirectDraw7_SetWindowSize(glDirectDraw7 *glDD7, DWORD dwWidth, DWORD dwHeight);
 148+LONG Try640400Mode(LPCWSTR devname, DEVMODE *mode, DWORD flags, BOOL *crop400);
148149
149150 class glDirectDraw1 : public IDirectDraw
150151 {
Index: dxglcfg/dxglcfg.rc
@@ -132,7 +132,8 @@
133133 AUTOCHECKBOX "Don't auto-size window in resizable window mode", IDC_NOAUTOSIZE, 7, 101, 171, 8, 0, WS_EX_LEFT
134134 LTEXT "Installation path", IDC_PATHLABEL, 7, 124, 51, 9, SS_LEFT, WS_EX_LEFT
135135 EDITTEXT IDC_PROFILEPATH, 7, 135, 331, 14, NOT WS_BORDER | NOT WS_TABSTOP | ES_AUTOHSCROLL | ES_READONLY, WS_EX_LEFT
136 - PUSHBUTTON "Write INI file...", IDC_WRITEINI, 262, 150, 73, 14, 0, WS_EX_LEFT
 136+ // Removed for DXGL 0.5.13 release
 137+ // PUSHBUTTON "Write INI file...", IDC_WRITEINI, 262, 150, 73, 14, 0, WS_EX_LEFT
137138 }
138139
139140