DXGL r419 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r418‎ | r419 | r420 >
Date:18:53, 6 April 2014
Author:admin
Status:new
Tags:
Comment:
Fix aspect support.
Work on adding aspect support to dxglcfg
Modified paths:
  • /cfgmgr/cfgmgr.cpp (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.cpp
@@ -430,6 +430,7 @@
431431 cfg->TexUpload = ReadDWORD(hKey,cfg->TexUpload,cfgmask->TexUpload,_T("TexUpload"));
432432 cfg->Windows8Detected = ReadBool(hKey,cfg->Windows8Detected,cfgmask->Windows8Detected,_T("Windows8Detected"));
433433 cfg->DPIScale = ReadDWORD(hKey,cfg->DPIScale,cfgmask->DPIScale,_T("DPIScale"));
 434+ cfg->aspect = ReadFloat(hKey, cfg->aspect, cfgmask->aspect, _T("ScreenAspect"));
434435 if(!global && dll)
435436 {
436437 LPTSTR paths;
@@ -487,6 +488,11 @@
488489 if(mask[0]) RegSetValueEx(hKey,name,0,REG_SZ,(BYTE*)path,(_tcslen(path)+1)*sizeof(TCHAR));
489490 else RegDeleteValue(hKey,name);
490491 }
 492+void WriteFloat(HKEY hKey, float value, float mask, LPCTSTR name)
 493+{
 494+ if (abs(mask) > 0.5f) RegSetValueEx(hKey, name, 0, REG_DWORD, (BYTE*)&value, 4);
 495+ else RegDeleteValue(hKey, name);
 496+}
491497
492498 void WriteSettings(HKEY hKey, const DXGLCFG *cfg, const DXGLCFG *mask, bool global)
493499 {
@@ -494,6 +500,7 @@
495501 if(mask) cfgmask = mask;
496502 else cfgmask = &defaultmask;
497503 memset(&defaultmask,1,sizeof(DXGLCFG));
 504+ defaultmask.aspect = 1.0f;
498505 WriteDWORD(hKey,cfg->scaler,cfgmask->scaler,_T("ScalingMode"));
499506 WriteBool(hKey,cfg->colormode,cfgmask->colormode,_T("ChangeColorDepth"));
500507 WriteDWORD(hKey,cfg->scalingfilter,cfgmask->scalingfilter,_T("ScalingFilter"));
@@ -511,6 +518,7 @@
512519 WriteDWORD(hKey,cfg->TexUpload,cfgmask->TexUpload,_T("TexUpload"));
513520 WriteBool(hKey,cfg->Windows8Detected,cfgmask->Windows8Detected,_T("Windows8Detected"));
514521 WriteDWORD(hKey,cfg->DPIScale,cfgmask->DPIScale,_T("DPIScale"));
 522+ WriteFloat(hKey, cfg->aspect, cfgmask->aspect, _T("ScreenAspect"));
515523 }
516524
517525 tstring newregname;
Index: ddraw/glDirectDraw.cpp
@@ -1433,15 +1433,15 @@
14341434 else
14351435 {
14361436 aspect = dxglcfg.aspect;
1437 - if (screenx*aspect > screeny)
 1437+ if (screenx/aspect > screeny)
14381438 {
1439 - internalx = (DWORD)((float)screeny / (float)aspect);
 1439+ internalx = (DWORD)((float)screeny * (float)aspect);
14401440 internaly = screeny;
14411441 }
14421442 else
14431443 {
14441444 internalx = screenx;
1445 - internaly = (DWORD)((float)screenx * (float)aspect);
 1445+ internaly = (DWORD)((float)screenx / (float)aspect);
14461446 }
14471447 }
14481448 if(dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
@@ -1531,15 +1531,15 @@
15321532 else
15331533 {
15341534 aspect = dxglcfg.aspect;
1535 - if (screenx*aspect > screeny)
 1535+ if (screenx / aspect > screeny)
15361536 {
1537 - internalx = (DWORD)((float)screeny / (float)aspect);
 1537+ internalx = (DWORD)((float)screeny * (float)aspect);
15381538 internaly = screeny;
15391539 }
15401540 else
15411541 {
15421542 internalx = screenx;
1543 - internaly = (DWORD)((float)screenx * (float)aspect);
 1543+ internaly = (DWORD)((float)screenx / (float)aspect);
15441544 }
15451545 }
15461546 if (dxglcfg.colormode) internalbpp = screenbpp = dwBPP;
Index: dxglcfg/dxglcfg.cpp
@@ -217,6 +217,69 @@
218218 EnableWindow(GetDlgItem(hWnd,IDC_APPLY),FALSE);
219219 }
220220
 221+void FloatToAspect(float f, LPTSTR aspect)
 222+{
 223+ float integer;
 224+ float dummy;
 225+ TCHAR denominator[5];
 226+ if (f >= 1000.0f) // Clamp ridiculously wide aspects
 227+ {
 228+ _tcscpy(aspect, _T("1000:1"));
 229+ return;
 230+ }
 231+ if (f < 0.001f) // Exclude ridiculously tall aspects, zero, and negative
 232+ {
 233+ _tcscpy(aspect, _T("Default"));
 234+ return;
 235+ }
 236+ // Handle common aspects
 237+ if (abs(f - 1.25f) < 0.0001f)
 238+ {
 239+ _tcscpy(aspect, _T("5:4"));
 240+ return;
 241+ }
 242+ if (abs(f - 1.3333333f) < 0.0001f)
 243+ {
 244+ _tcscpy(aspect, _T("4:3"));
 245+ return;
 246+ }
 247+ if (abs(f - 1.6f) < 0.0001f)
 248+ {
 249+ _tcscpy(aspect, _T("16:10"));
 250+ return;
 251+ }
 252+ if (abs(f - 1.7777777) < 0.0001f)
 253+ {
 254+ _tcscpy(aspect, _T("16:9"));
 255+ return;
 256+ }
 257+ if (abs(f - 1.9333333) < 0.0001f)
 258+ {
 259+ _tcscpy(aspect, _T("256:135"));
 260+ return;
 261+ }
 262+ float fract = modf(f, &integer);
 263+ if (fract < 0.0001f) //Handle integer aspects
 264+ {
 265+ _itot(integer, aspect, 10);
 266+ _tcscat(aspect, _T(":1"));
 267+ }
 268+ // Finally try from 2 to 1000
 269+ for (int i = 2; i < 1000; i++)
 270+ {
 271+ if (abs(modf(fract*i, &dummy)) < 0.0001f)
 272+ {
 273+ _itot((f*i) + .5f, aspect, 10);
 274+ _itot(i, denominator, 10);
 275+ _tcscat(aspect, _T(":"));
 276+ _tcscat(aspect, denominator);
 277+ return;
 278+ }
 279+ }
 280+ // Cannot find a reasonable fractional aspect, so display as decimal.
 281+ _stprintf(aspect, _T("%.6f"), f);
 282+}
 283+
221284 void SetCheck(HWND hWnd, int DlgItem, bool value, bool mask, bool tristate)
222285 {
223286 if(tristate && !mask)
@@ -237,6 +300,22 @@
238301 SendDlgItemMessage(hWnd,DlgItem,CB_SETCURSEL,value,0);
239302 }
240303
 304+void SetAspectCombo(HWND hWnd, int DlgItem, float value, DWORD mask, bool tristate)
 305+{
 306+ TCHAR buffer[32];
 307+ if (tristate && !mask)
 308+ SendDlgItemMessage(hWnd, DlgItem, CB_SETCURSEL,
 309+ SendDlgItemMessage(hWnd, DlgItem, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
 310+ else
 311+ {
 312+ FloatToAspect(value, buffer);
 313+ SetDlgItemText(hWnd, DlgItem, buffer);
 314+ SendDlgItemMessage(hWnd,DlgItem,CB_SETCURSEL,
 315+ SendDlgItemMessage(hWnd, DlgItem, CB_FINDSTRING, -1, (LPARAM)buffer), 0);
 316+ }
 317+
 318+}
 319+
241320 void SetText(HWND hWnd, int DlgItem, TCHAR *value, TCHAR *mask, bool tristate)
242321 {
243322 if(tristate && (mask[0] == 0))
@@ -277,6 +356,37 @@
278357 }
279358 }
280359
 360+float GetAspectCombo(HWND hWnd, int DlgItem, float &mask)
 361+{
 362+ TCHAR buffer[32];
 363+ TCHAR *ptr;
 364+ float numerator, denominator;
 365+ GetDlgItemText(hWnd, DlgItem, buffer, 31);
 366+ if (!_tcscmp(buffer, strdefault))
 367+ {
 368+ mask = 0.0f;
 369+ return 0;
 370+ }
 371+ else
 372+ {
 373+ mask = 1.0f;
 374+ if (!_tcscmp(buffer, _T("Default"))) return 0.0f;
 375+ else
 376+ {
 377+ // Check for colon
 378+ ptr = _tcsstr(buffer, _T(":"));
 379+ if (ptr)
 380+ {
 381+ *ptr = 0;
 382+ numerator = _ttof(buffer);
 383+ denominator = _ttof(ptr + 1);
 384+ return numerator / denominator;
 385+ }
 386+ else return _ttof(buffer);
 387+ }
 388+ }
 389+}
 390+
281391 void GetText(HWND hWnd, int DlgItem, TCHAR *str, TCHAR *mask)
282392 {
283393 GetDlgItemText(hWnd,DlgItem,str,MAX_PATH+1);
@@ -284,10 +394,6 @@
285395 else mask[0] = 0xff;
286396 }
287397
288 -void SetAspectCombo(int item, float value)
289 -{
290 -}
291 -
292398 LRESULT CALLBACK DXGLCfgCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
293399 {
294400 PIXELFORMATDESCRIPTOR pfd =
@@ -435,6 +541,7 @@
436542 SendDlgItemMessage(hWnd,IDC_ASPECT,CB_ADDSTRING,0,(LPARAM)buffer);
437543 _tcscpy(buffer,_T("5:4"));
438544 SendDlgItemMessage(hWnd,IDC_ASPECT,CB_ADDSTRING,0,(LPARAM)buffer);
 545+ SendDlgItemMessage(hWnd, IDC_ASPECT, CB_SETCURSEL, cfg->aspect, 0);
439546
440547 // highres
441548 if(cfg->highres) SendDlgItemMessage(hWnd,IDC_HIGHRES,BM_SETCHECK,BST_CHECKED,0);
@@ -816,6 +923,7 @@
817924 SendDlgItemMessage(hWnd,IDC_TEXTUREFORMAT,CB_ADDSTRING,0,(LPARAM)strdefault);
818925 SendDlgItemMessage(hWnd,IDC_TEXUPLOAD,CB_ADDSTRING,0,(LPARAM)strdefault);
819926 SendDlgItemMessage(hWnd, IDC_DPISCALE, CB_ADDSTRING, 0, (LPARAM)strdefault);
 927+ SendDlgItemMessage(hWnd, IDC_ASPECT, CB_ADDSTRING, 0, (LPARAM)strdefault);
820928 }
821929 else if(!current_app && tristate)
822930 {
@@ -845,7 +953,9 @@
846954 SendDlgItemMessage(hWnd,IDC_TEXUPLOAD,CB_DELETESTRING,
847955 SendDlgItemMessage(hWnd,IDC_ASPECT3D,CB_FINDSTRING,-1,(LPARAM)strdefault),0);
848956 SendDlgItemMessage(hWnd, IDC_DPISCALE, CB_DELETESTRING,
849 - SendDlgItemMessage(hWnd, IDC_ASPECT3D, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
 957+ SendDlgItemMessage(hWnd, IDC_DPISCALE, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
 958+ SendDlgItemMessage(hWnd, IDC_ASPECT, CB_DELETESTRING,
 959+ SendDlgItemMessage(hWnd, IDC_ASPECT, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
850960 }
851961 // Read settings into controls
852962 SetCombo(hWnd,IDC_VIDMODE,cfg->scaler,cfgmask->scaler,tristate);
@@ -864,6 +974,7 @@
865975 SetCheck(hWnd,IDC_EXTRAMODES,cfg->ExtraModes,cfgmask->ExtraModes,tristate);
866976 SetText(hWnd,IDC_SHADER,cfg->shaderfile,cfgmask->shaderfile,tristate);
867977 SetCombo(hWnd, IDC_DPISCALE, cfg->DPIScale, cfgmask->DPIScale, tristate);
 978+ SetAspectCombo(hWnd, IDC_ASPECT, cfg->aspect, cfgmask->aspect, tristate);
868979 }
869980 case IDC_VIDMODE:
870981 cfg->scaler = GetCombo(hWnd,IDC_VIDMODE,cfgmask->scaler);
@@ -948,6 +1059,21 @@
9491060 *dirty = true;
9501061 }
9511062 break;
 1063+ case IDC_ASPECT:
 1064+ if (HIWORD(wParam) == CBN_KILLFOCUS)
 1065+ {
 1066+ cfg->aspect = GetAspectCombo(hWnd, IDC_ASPECT, cfgmask->aspect);
 1067+ SetAspectCombo(hWnd, IDC_ASPECT, cfg->aspect, cfgmask->aspect, tristate);
 1068+ EnableWindow(GetDlgItem(hWnd, IDC_APPLY), true);
 1069+ *dirty = true;
 1070+ }
 1071+ else if (HIWORD(wParam) == CBN_SELCHANGE)
 1072+ {
 1073+ cfg->aspect = GetAspectCombo(hWnd, IDC_ASPECT, cfgmask->aspect);
 1074+ EnableWindow(GetDlgItem(hWnd, IDC_APPLY), true);
 1075+ *dirty = true;
 1076+ }
 1077+ break;
9521078 case IDC_ADD:
9531079 OPENFILENAME filename;
9541080 TCHAR selectedfile[MAX_PATH+1];