DXGL r701 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r700‎ | r701 | r702 >
Date:16:23, 16 March 2017
Author:admin
Status:new
Tags:
Comment:
Add configuration for 1st pass scaling.
Fix decimal places on floating point aspect ratios.
Modified paths:
  • /cfgmgr/ReadMe.txt (modified) (history)
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /dxglcfg/dxglcfg.c (modified) (history)
  • /dxglcfg2/dxglcfg2.c (modified) (history)

Diff [purge]

Index: cfgmgr/ReadMe.txt
@@ -1,6 +1,6 @@
22 Struct DXGLCFG
33 Member scaler
4 -REG_DWORD HKCU\DXGL\<app>\ScalingMode
 4+REG_DWORD HKCU\DXGL\Profiles\<app>\ScalingMode
55 Determines the method of scaling full screen modes.
66 Valid settings:
77 0 - Change display mode to match requested mode.
@@ -13,7 +13,7 @@
1414 7 - Crop output to desktop, preserving aspect ratio
1515
1616 Member fullmode
17 -REG_DWORD HKCU\DXGL\<app>\FullscreenWindowMode
 17+REG_DWORD HKCU\DXGL\Profiles\<app>\FullscreenWindowMode
1818 Determines how to handle fullscreen modes.
1919 Valid settings:
2020 0 - Use exclusive fullscreen
@@ -23,19 +23,40 @@
2424 4 - Use a borderless, non-resizable window, called windowed borderless in industry
2525
2626 Member colormode
27 -REG_DWORD HKCU\DXGL\<app>\ChangeColorDepth
 27+REG_DWORD HKCU\DXGL\Profiles\<app>\ChangeColorDepth
2828 If nonzero, switches screen color depth if requested by the application.
2929 Recommended setting is off. DXGL handles color depth conversion internally.
3030
 31+Member firstscalefilter
 32+REG_DWORD HKCU\DXGL\Profiles\<app>\FirstScaleFilter
 33+Filter to use for the optional first pass display scaling.
 34+Valid settings:
 35+0 - Nearest-neighbor stretching
 36+1 - Bilinear interpolation
 37+
 38+Member firstscalex
 39+REG_DWORD HKCU\DXGL\Profiles\<app>\FirstScaleX
 40+Amount to stretch the display in the X direction for the first pass.
 41+If either X or Y is set to 0 or less than 0.25, automatically choose
 42+2x or 2x1 scaling for certain low resolutions.
 43+Stored as a 32-bit float encoded as a DWORD.
 44+
 45+Member firstscaley
 46+REG_DWORD HKCU\DXGL\Profiles\<app>\FirstScaley
 47+Amount to stretch the display in the Y direction for the first pass.
 48+If either X or Y is set to 0 or less than 0.25, automatically choose
 49+2x or 2x1 scaling for certain low resolutions.
 50+Stored as a 32-bit float encoded as a DWORD.
 51+
3152 Member scalingfilter
32 -REG_DWORD HKCU\DXGL\<app>\ScalingFilter
33 -Filter to use for stretched 2D blits.
 53+REG_DWORD HKCU\DXGL\Profiles\<app>\ScalingFilter
 54+Filter to use for stretched 2D blits and the final display scaling.
3455 Valid settings:
3556 0 - Nearest-neighbor stretching
3657 1 - Bilinear interpolation
3758
3859 Member primaryscale
39 -REG_DWORD HKCU\DXGL\<app>\AdjustPrimaryResolution
 60+REG_DWORD HKCU\DXGL\Profiles\<app>\AdjustPrimaryResolution
4061 Changes primary resolution to match desktop resolution.
4162 May cause glitches
4263 Valid settings:
@@ -50,19 +71,19 @@
5172 8 - Use custom scale.
5273
5374 Member primaryscalex
54 -REG_DWORD HKCU\DXGL\<app>\PrimaryScaleX
 75+REG_DWORD HKCU\DXGL\Profiles\<app>\PrimaryScaleX
5576 Custom X scale for primary scaling.
5677 Stored as a 32-bit float encoded as a DWORD.
5778 If zero, negative, or an invalid value, set to 1.
5879
5980 Member primaryscaley
60 -REG_DWORD HKCU\DXGL\<app>\PrimaryScaleY
 81+REG_DWORD HKCU\DXGL\Profiles\<app>\PrimaryScaleY
6182 Custom X scale for primary scaling.
6283 Stored as a 32-bit float encoded as a DWORD.
6384 If zero, negative, or an invalid value, set to 1.
6485
6586 Member texfilter
66 -REG_DWORD HKCU\DXGL\<app>\TextureFilter
 87+REG_DWORD HKCU\DXGL\Profiles\<app>\TextureFilter
6788 Filter for 3D textured polygons
6889 Valid settings:
6990 0 - Use application settings
@@ -74,7 +95,7 @@
7596 6 - GL_LINEAR_MIPMAP_LINEAR (Trilinear filtering)
7697
7798 Member anisotropic
78 -REG_DWORD HKCU\DXGL\<app>\AnisotropicFiltering
 99+REG_DWORD HKCU\DXGL\Profiles\<app>\AnisotropicFiltering
79100 Anisotropic filter level, may decrese performance on slower GPUs.
80101 Valid settings:
81102 0 - Application default
@@ -82,7 +103,7 @@
83104 Larger numbers enable anisotropic filtering, maximum determined by GPU driver.
84105
85106 member msaa
86 -REG_DWORD HKCU\DXGL\<app>\Antialiasing
 107+REG_DWORD HKCU\DXGL\Profiles\<app>\Antialiasing
87108 Level of Full Screen Antialiasing. May considerably decrease performance on
88109 slower GPUs.
89110 Valid settings:
@@ -94,7 +115,7 @@
95116 Example: 16 coverage, 8 color = 0x8010
96117
97118 Member aspect3d
98 -REG_DWORD HKCU\DXGL\<app>\AdjustAspectRatio
 119+REG_DWORD HKCU\DXGL\Profiles\<app>\AdjustAspectRatio
99120 If the scaler is 1 or 4, adjust 3D projection to correct aspect ratio. Does
100121 not affect 2D blits or similar operations.
101122 Valid settings:
@@ -103,15 +124,15 @@
104125 2 - Crop to viewable area. May cause graphics to get cut off.
105126
106127 Member EnableShader
107 -REG_DWORD HKCU\DXGL\<app>\EnableShader
 128+REG_DWORD HKCU\DXGL\Profiles\<app>\EnableShader
108129 If nonzero, enables post-process shaders.
109130
110131 Member shaderfile
111 -REG_SZ HKCU\DXGL\<app>\ShaderFile
 132+REG_SZ HKCU\DXGL\Profiles\<app>\ShaderFile
112133 Full path to file containing a post-process shader script.
113134
114135 Member SortModes
115 -REG_DWORD HKCU\DXGL\<app>\SortModes
 136+REG_DWORD HKCU\DXGL\Profiles\<app>\SortModes
116137 Sort display modes
117138 Valid settings:
118139 0 - As reported by system
@@ -119,7 +140,7 @@
120141 2 - Group by resolution
121142
122143 Member AllColorDepths
123 -REG_DWORD HKCU\DXGL\<app>\AllColorDepths
 144+REG_DWORD HKCU\DXGL\Profiles\<app>\AllColorDepths
124145 [DEPRECATED]Enable all color depths, even if unsupported by the system
125146 Valid settings:
126147 0 - Off
@@ -126,7 +147,7 @@
127148 1 - On
128149
129150 Member AddColorDepths
130 -REG_DWORD HKCU\DXGL\<app>\AddColorDepths
 151+REG_DWORD HKCU\DXGL\Profiles\<app>\AddColorDepths
131152 Adds color depths, even if unsupported by the system
132153 Bit-mapped variable
133154 Valid settings, OR'ed to combine settings:
@@ -138,7 +159,7 @@
139160 16 - Add 32-bit modes
140161
141162 Member ExtraModes
142 -REG_DWORD HKCU\DXGL\<app>\ExtraModes
 163+REG_DWORD HKCU\DXGL\Profiles\<app>\ExtraModes
143164 [DEPRECATED]Enable extra video modes, even if unsupported by the system
144165 Valid settings:
145166 0 - Off
@@ -145,7 +166,7 @@
146167 1 - On
147168
148169 member AddModes
149 -REG_DWORD HKCU\DXGL\<app>\AddModes
 170+REG_DWORD HKCU\DXGL\Profiles\<app>\AddModes
150171 Adds additional video modes, even if unsupported by the system
151172 Bit-mapped variable
152173 Valid settings, OR'ed to combine settings:
@@ -155,19 +176,19 @@
156177 4 - Add higher resolution modes
157178
158179 Member vsync
159 -REG_DWORD HKCU\DXGL\<app>\VSync
 180+REG_DWORD HKCU\DXGL\Profiles\<app>\VSync
160181 Vertical retrace control
161182 Valid settings:
162183 0 - Determined by application
163184
164185 Member TextureFormat
165 -REG_DWORD HKCU\DXGL\<app>\TextureFormat
 186+REG_DWORD HKCU\DXGL\Profiles\<app>\TextureFormat
166187 Texture format
167188 Valid settings:
168189 0 - Automatic
169190
170191 Member TexUpload
171 -REG_DWORD HKCU\DXGL\<app>\TexUpload
 192+REG_DWORD HKCU\DXGL\Profiles\<app>\TexUpload
172193 Method used to upload textures
173194 Valid settings:
174195 0 - Automatic
@@ -174,7 +195,7 @@
175196 1 - OpenGL Standard
176197
177198 Member DPIScale
178 -REG_DWORD HKCU\DXGL\<app>\DPIScale
 199+REG_DWORD HKCU\DXGL\Profiles\<app>\DPIScale
179200 Enable DPI scaling fix
180201 The program may be restarted if the Windows AppCompat method is enabled or
181202 disabled.
@@ -184,7 +205,7 @@
185206 2 - Use Windows AppCompat
186207
187208 Member aspect
188 -REG_DWORD HKCU\DXGL\<app>\ScreenAspect
 209+REG_DWORD HKCU\DXGL\Profiles\<app>\ScreenAspect
189210 Screen aspect ratio to simulate, if the scaler is 1 or 5.
190211 Stored as a 32-bit float encoded as a DWORD.
191212 If zero, negative, or an invalid value, use automatic ratio based on square pixels.
Index: cfgmgr/cfgmgr.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2016 William Feely
 3+// Copyright (C) 2011-2017 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
@@ -458,6 +458,9 @@
459459 cfg->scaler = ReadDWORD(hKey, cfg->scaler, &cfgmask->scaler, _T("ScalingMode"));
460460 cfg->fullmode = ReadDWORD(hKey, cfg->fullmode, &cfgmask->fullmode, _T("FullscreenWindowMode"));
461461 cfg->colormode = ReadBool(hKey,cfg->colormode,&cfgmask->colormode,_T("ChangeColorDepth"));
 462+ cfg->firstscalefilter = ReadDWORD(hKey, cfg->firstscalefilter, &cfgmask->firstscalefilter, _T("FirstScaleFilter"));
 463+ cfg->firstscalex = ReadFloat(hKey, cfg->firstscalex, &cfgmask->firstscalex, _T("FirstScaleX"));
 464+ cfg->firstscaley = ReadFloat(hKey, cfg->firstscaley, &cfgmask->firstscaley, _T("FirstScaleY"));
462465 cfg->scalingfilter = ReadDWORD(hKey,cfg->scalingfilter,&cfgmask->scalingfilter,_T("ScalingFilter"));
463466 cfg->texfilter = ReadDWORD(hKey,cfg->texfilter,&cfgmask->texfilter,_T("TextureFilter"));
464467 cfg->anisotropic = ReadDWORD(hKey,cfg->anisotropic,&cfgmask->anisotropic,_T("AnisotropicFiltering"));
@@ -530,6 +533,9 @@
531534 WriteDWORD(hKey,cfg->scaler,cfgmask->scaler,_T("ScalingMode"));
532535 WriteDWORD(hKey, cfg->fullmode, cfgmask->fullmode, _T("FullscreenWindowMode"));
533536 WriteBool(hKey,cfg->colormode,cfgmask->colormode,_T("ChangeColorDepth"));
 537+ WriteDWORD(hKey, cfg->firstscalefilter, cfgmask->firstscalefilter, _T("FirstScaleFilter"));
 538+ WriteFloat(hKey, cfg->firstscalex, cfgmask->firstscalex, _T("FirstScaleX"));
 539+ WriteFloat(hKey, cfg->firstscalex, cfgmask->firstscalex, _T("FirstScaleY"));
534540 WriteDWORD(hKey,cfg->scalingfilter,cfgmask->scalingfilter,_T("ScalingFilter"));
535541 WriteDWORD(hKey,cfg->texfilter,cfgmask->texfilter,_T("TextureFilter"));
536542 WriteDWORD(hKey,cfg->anisotropic,cfgmask->anisotropic,_T("AnisotropicFiltering"));
Index: cfgmgr/cfgmgr.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2016 William Feely
 3+// Copyright (C) 2011-2017 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
@@ -28,6 +28,9 @@
2929 DWORD scaler;
3030 DWORD fullmode;
3131 BOOL colormode;
 32+ DWORD firstscalefilter;
 33+ float firstscalex;
 34+ float firstscaley;
3235 DWORD scalingfilter;
3336 DWORD texfilter;
3437 DWORD anisotropic;
Index: dxglcfg/dxglcfg.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2016 William Feely
 3+// Copyright (C) 2011-2017 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
@@ -227,7 +227,7 @@
228228 float fract;
229229 TCHAR denominator[5];
230230 int i;
231 - if (_isnan(f)) f = 0; //Handle NAN condition
 231+ if (_isnan(f)) f = 0.0f; //Handle NAN condition
232232 if (f >= 1000.0f) // Clamp ridiculously wide aspects
233233 {
234234 _tcscpy(aspect, _T("1000:1"));
@@ -285,11 +285,42 @@
286286 }
287287 // Cannot find a reasonable fractional aspect, so display as decimal.
288288 #ifdef _UNICODE
289 - swprintf(aspect, 31, L"%.6f", f);
 289+ swprintf(aspect, 31, L"%.6g", f);
290290 #else
291 - sprintf(aspect,"%.6f", f);
 291+ sprintf(aspect,"%.6g", f);
292292 #endif
 293+}
293294
 295+void FloatToScale(float x, float y, LPTSTR scale)
 296+{
 297+ TCHAR numberx[8];
 298+ TCHAR numbery[8];
 299+ if (_isnan(x)) x = 0.0f; //Handle NAN condition
 300+ if (_isnan(y)) y = 0.0f;
 301+ // Too low number, round to "Auto"
 302+ if (x < 0.25f) x = 0.0f;
 303+ if (y < 0.25f) y = 0.0f;
 304+ // Too high number, round to 16
 305+ if (x > 16.0f) x = 16.0f;
 306+ if (y > 16.0f) y = 16.0f;
 307+ // Test if either scale is zero
 308+ if ((x == 0) || (y == 0))
 309+ {
 310+ _tcscpy(scale, _T("Auto"));
 311+ return;
 312+ }
 313+ // Write numbers
 314+#ifdef _UNICODE
 315+ swprintf(numberx, 7, L"%.4g", x);
 316+ swprintf(numbery, 7, L"%.4g", y);
 317+#else
 318+ sprintf(numberx, ".4g", x);
 319+ sprintf(numbery, ".4g", y);
 320+#endif
 321+ // Fill out string
 322+ _tcscpy(scale, numberx);
 323+ _tcscat(scale, _T("x"));
 324+ if (x != y) _tcscat(scale, numbery);
294325 }
295326
296327 void SetCheck(HWND hWnd, int DlgItem, BOOL value, BOOL mask, BOOL tristate)
@@ -325,7 +356,21 @@
326357 SendDlgItemMessage(hWnd, DlgItem, CB_FINDSTRING, -1, (LPARAM)buffer), 0);
327358 SetDlgItemText(hWnd, DlgItem, buffer);
328359 }
 360+}
329361
 362+void Set1stScaleCombo(HWND hWnd, int DlgItem, float x, float y, DWORD maskx, DWORD masky, BOOL tristate)
 363+{
 364+ TCHAR buffer[32];
 365+ if (tristate && !maskx && !masky)
 366+ SendDlgItemMessage(hWnd, DlgItem, CB_SETCURSEL,
 367+ SendDlgItemMessage(hWnd, DlgItem, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
 368+ else
 369+ {
 370+ FloatToScale(x, y, buffer);
 371+ SendDlgItemMessage(hWnd, DlgItem, CB_SETCURSEL,
 372+ SendDlgItemMessage(hWnd, DlgItem, CB_FINDSTRING, -1, (LPARAM)buffer), 0);
 373+ SetDlgItemText(hWnd, DlgItem, buffer);
 374+ }
330375 }
331376
332377 void SetText(HWND hWnd, int DlgItem, TCHAR *value, TCHAR *mask, BOOL tristate)
@@ -386,6 +431,56 @@
387432 }
388433 }
389434
 435+void Get1stScaleCombo(HWND hWnd, int DlgItem, float *x, float *y, float *maskx, float *masky)
 436+{
 437+ TCHAR buffer[32];
 438+ TCHAR *ptr;
 439+ GetDlgItemText(hWnd, DlgItem, buffer, 31);
 440+ buffer[31] = 0;
 441+ if (!_tcscmp(buffer, strdefault))
 442+ {
 443+ *maskx = 0.0f;
 444+ *masky = 0.0f;
 445+ *x = 0.0f;
 446+ *y = 0.0f;
 447+ return;
 448+ }
 449+ else
 450+ {
 451+ *maskx = 1.0f;
 452+ *masky = 1.0f;
 453+ // Check for Auto
 454+ if (!_tcsicmp(buffer, _T("Auto)")))
 455+ {
 456+ *x = 0.0f;
 457+ *y = 0.0f;
 458+ return;
 459+ }
 460+ else
 461+ {
 462+ // Check for certain characters
 463+ ptr = _tcsstr(buffer, _T("x"));
 464+ if (!ptr) ptr = _tcsstr(buffer, _T("X"));
 465+ if (!ptr) ptr = _tcsstr(buffer, _T(","));
 466+ if (!ptr) ptr = _tcsstr(buffer, _T("-"));
 467+ if (!ptr) ptr = _tcsstr(buffer, _T(":"));
 468+ if (ptr)
 469+ {
 470+ *ptr = 0;
 471+ *x = _ttof(buffer);
 472+ *y = _ttof(ptr + 1);
 473+ return;
 474+ }
 475+ else
 476+ {
 477+ *x = _ttof(buffer);
 478+ *y = _ttof(buffer);
 479+ return;
 480+ }
 481+ }
 482+ }
 483+}
 484+
390485 float GetAspectCombo(HWND hWnd, int DlgItem, float *mask)
391486 {
392487 TCHAR buffer[32];
@@ -392,15 +487,16 @@
393488 TCHAR *ptr;
394489 float numerator, denominator;
395490 GetDlgItemText(hWnd, DlgItem, buffer, 31);
 491+ buffer[31] = 0;
396492 if (!_tcscmp(buffer, strdefault))
397493 {
398494 *mask = 0.0f;
399 - return 0;
 495+ return 0.0f;
400496 }
401497 else
402498 {
403499 *mask = 1.0f;
404 - if (!_tcscmp(buffer, _T("Default"))) return 0.0f;
 500+ if (!_tcsicmp(buffer, _T("Default"))) return 0.0f;
405501 else
406502 {
407503 // Check for colon
@@ -582,7 +678,7 @@
583679 SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_ADDSTRING, 0, (LPARAM)buffer);
584680 _tcscpy(buffer, _T("Bilinear"));
585681 SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_ADDSTRING, 1, (LPARAM)buffer);
586 - SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_SETCURSEL, cfg->scalingfilter, 0);
 682+ SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_SETCURSEL, cfg->firstscalefilter, 0);
587683 // first scaling sizes
588684 _tcscpy(buffer, _T("Auto"));
589685 SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_ADDSTRING, 0, (LPARAM)buffer);
@@ -596,6 +692,8 @@
597693 SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_ADDSTRING, 0, (LPARAM)buffer);
598694 _tcscpy(buffer, _T("4x"));
599695 SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_ADDSTRING, 0, (LPARAM)buffer);
 696+ Set1stScaleCombo(hWnd, IDC_PRESCALESIZE, cfg->firstscalex, cfg->firstscaley,
 697+ cfgmask->firstscalex, cfgmask->firstscaley, tristate);
600698 // final scaling filter
601699 _tcscpy(buffer,_T("Nearest"));
602700 SendDlgItemMessage(hWnd,IDC_SCALE,CB_ADDSTRING,0,(LPARAM)buffer);
@@ -613,8 +711,7 @@
614712 SendDlgItemMessage(hWnd,IDC_ASPECT,CB_ADDSTRING,0,(LPARAM)buffer);
615713 _tcscpy(buffer,_T("5:4"));
616714 SendDlgItemMessage(hWnd,IDC_ASPECT,CB_ADDSTRING,0,(LPARAM)buffer);
617 - SetAspectCombo(hWnd, IDC_ASPECT, cfg->aspect, cfgmask->aspect, tristate);
618 -
 715+ SetAspectCombo(hWnd, IDC_ASPECT, cfg->aspect, cfgmask->aspect, tristate);
619716 // highres
620717 if(cfg->primaryscale) SendDlgItemMessage(hWnd,IDC_HIGHRES,BM_SETCHECK,BST_CHECKED,0);
621718 else SendDlgItemMessage(hWnd,IDC_HIGHRES,BM_SETCHECK,BST_UNCHECKED,0);
@@ -1026,6 +1123,8 @@
10271124 tristate = TRUE;
10281125 SendDlgItemMessage(hWnd,IDC_VIDMODE,CB_ADDSTRING,0,(LPARAM)strdefault);
10291126 SendDlgItemMessage(hWnd,IDC_SORTMODES,CB_ADDSTRING,0,(LPARAM)strdefault);
 1127+ SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_ADDSTRING, 0, (LPARAM)strdefault);
 1128+ SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_ADDSTRING, 0, (LPARAM)strdefault);
10301129 SendDlgItemMessage(hWnd,IDC_SCALE,CB_ADDSTRING,0,(LPARAM)strdefault);
10311130 //SendDlgItemMessage(hWnd,IDC_VSYNC,CB_ADDSTRING,0,(LPARAM)strdefault);
10321131 SendDlgItemMessage(hWnd, IDC_FULLMODE, CB_ADDSTRING, 0, (LPARAM)strdefault);
@@ -1049,6 +1148,10 @@
10501149 SendDlgItemMessage(hWnd,IDC_VIDMODE,CB_FINDSTRING,-1,(LPARAM)strdefault),0);
10511150 SendDlgItemMessage(hWnd,IDC_SORTMODES,CB_DELETESTRING,
10521151 SendDlgItemMessage(hWnd,IDC_SORTMODES,CB_FINDSTRING,-1,(LPARAM)strdefault),0);
 1152+ SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_DELETESTRING,
 1153+ SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
 1154+ SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_DELETESTRING,
 1155+ SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
10531156 SendDlgItemMessage(hWnd,IDC_SCALE,CB_DELETESTRING,
10541157 SendDlgItemMessage(hWnd,IDC_SCALE,CB_FINDSTRING,-1,(LPARAM)strdefault),0);
10551158 /* SendDlgItemMessage(hWnd,IDC_VSYNC,CB_DELETESTRING,
@@ -1079,6 +1182,7 @@
10801183 // Read settings into controls
10811184 SetCombo(hWnd,IDC_VIDMODE,cfg->scaler,cfgmask->scaler,tristate);
10821185 SetCombo(hWnd,IDC_SORTMODES,cfg->SortModes,cfgmask->SortModes,tristate);
 1186+ SetCombo(hWnd,IDC_PRESCALE,cfg->firstscalefilter,cfgmask->firstscalefilter,tristate);
10831187 SetCombo(hWnd,IDC_SCALE,cfg->scalingfilter,cfgmask->scalingfilter,tristate);
10841188 //SetCombo(hWnd,IDC_VSYNC,cfg->vsync,cfgmask->vsync,tristate);
10851189 SetCombo(hWnd,IDC_FULLMODE,cfg->fullmode,cfgmask->fullmode,tristate);
@@ -1093,6 +1197,8 @@
10941198 SetCombo(hWnd,IDC_TEXUPLOAD,cfg->TexUpload,cfgmask->TexUpload,tristate);
10951199 SetCheck(hWnd,IDC_EXTRAMODES,cfg->AddModes,cfgmask->AddModes,tristate);
10961200 SetCombo(hWnd, IDC_DPISCALE, cfg->DPIScale, cfgmask->DPIScale, tristate);
 1201+ Set1stScaleCombo(hWnd, IDC_PRESCALESIZE, cfg->firstscalex, cfg->firstscaley,
 1202+ cfgmask->firstscalex, cfgmask->firstscaley, tristate);
10971203 SetAspectCombo(hWnd, IDC_ASPECT, cfg->aspect, cfgmask->aspect, tristate);
10981204 }
10991205 break;
@@ -1106,6 +1212,11 @@
11071213 EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);
11081214 *dirty = TRUE;
11091215 break;
 1216+ case IDC_PRESCALE:
 1217+ cfg->firstscalefilter = GetCombo(hWnd,IDC_PRESCALE,&cfgmask->firstscalefilter);
 1218+ EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);
 1219+ *dirty = TRUE;
 1220+ break;
11101221 case IDC_SCALE:
11111222 cfg->scalingfilter = GetCombo(hWnd,IDC_SCALE,&cfgmask->scalingfilter);
11121223 EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);
@@ -1176,6 +1287,24 @@
11771288 EnableWindow(GetDlgItem(hWnd, IDC_APPLY), TRUE);
11781289 *dirty = TRUE;
11791290 break;
 1291+ case IDC_PRESCALESIZE:
 1292+ if (HIWORD(wParam) == CBN_KILLFOCUS)
 1293+ {
 1294+ Get1stScaleCombo(hWnd, IDC_PRESCALESIZE, &cfg->firstscalex, &cfg->firstscaley,
 1295+ &cfgmask->firstscalex, &cfgmask->firstscaley);
 1296+ Set1stScaleCombo(hWnd, IDC_PRESCALESIZE, cfg->firstscalex, cfg->firstscaley,
 1297+ cfgmask->firstscalex, cfgmask->firstscaley, tristate);
 1298+ EnableWindow(GetDlgItem(hWnd, IDC_APPLY), TRUE);
 1299+ *dirty = TRUE;
 1300+ }
 1301+ else if (HIWORD(wParam) == CBN_SELCHANGE)
 1302+ {
 1303+ Get1stScaleCombo(hWnd, IDC_PRESCALESIZE, &cfg->firstscalex, &cfg->firstscaley,
 1304+ &cfgmask->firstscalex, &cfgmask->firstscaley);
 1305+ EnableWindow(GetDlgItem(hWnd, IDC_APPLY), TRUE);
 1306+ *dirty = TRUE;
 1307+ }
 1308+ break;
11801309 case IDC_ASPECT:
11811310 if (HIWORD(wParam) == CBN_KILLFOCUS)
11821311 {
Index: dxglcfg2/dxglcfg2.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2016 William Feely
 3+// Copyright (C) 2011-2017 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
@@ -275,7 +275,7 @@
276276 float fract;
277277 TCHAR denominator[5];
278278 int i;
279 - if (_isnan(f)) f = 0; //Handle NAN condition
 279+ if (_isnan(f)) f = 0.0f; //Handle NAN condition
280280 if (f >= 1000.0f) // Clamp ridiculously wide aspects
281281 {
282282 _tcscpy(aspect, _T("1000:1"));
@@ -333,11 +333,42 @@
334334 }
335335 // Cannot find a reasonable fractional aspect, so display as decimal.
336336 #ifdef _UNICODE
337 - swprintf(aspect, 31, L"%.6f", f);
 337+ swprintf(aspect, 31, L"%.6g", f);
338338 #else
339 - sprintf(aspect,"%.6f", f);
 339+ sprintf(aspect,"%.6g", f);
340340 #endif
 341+}
341342
 343+void FloatToScale(float x, float y, LPTSTR scale)
 344+{
 345+ TCHAR numberx[8];
 346+ TCHAR numbery[8];
 347+ if (_isnan(x)) x = 0.0f; //Handle NAN condition
 348+ if (_isnan(y)) y = 0.0f;
 349+ // Too low number, round to "Auto"
 350+ if (x < 0.25f) x = 0.0f;
 351+ if (y < 0.25f) y = 0.0f;
 352+ // Too high number, round to 16
 353+ if (x > 16.0f) x = 16.0f;
 354+ if (y > 16.0f) y = 16.0f;
 355+ // Test if either scale is zero
 356+ if ((x == 0) || (y == 0))
 357+ {
 358+ _tcscpy(scale, _T("Auto"));
 359+ return;
 360+ }
 361+ // Write numbers
 362+#ifdef _UNICODE
 363+ swprintf(numberx, 7, L"%.4g", x);
 364+ swprintf(numbery, 7, L"%.4g", y);
 365+#else
 366+ sprintf(numberx, ".4g", x);
 367+ sprintf(numbery, ".4g", y);
 368+#endif
 369+ // Fill out string
 370+ _tcscpy(scale, numberx);
 371+ _tcscat(scale, _T("x"));
 372+ if (x != y) _tcscat(scale, numbery);
342373 }
343374
344375 void SetCheck(HWND hWnd, int DlgItem, BOOL value, BOOL mask, BOOL tristate)
@@ -397,7 +428,21 @@
398429 SendDlgItemMessage(hWnd, DlgItem, CB_FINDSTRING, -1, (LPARAM)buffer), 0);
399430 SetDlgItemText(hWnd, DlgItem, buffer);
400431 }
 432+}
401433
 434+void Set1stScaleCombo(HWND hWnd, int DlgItem, float x, float y, DWORD maskx, DWORD masky, BOOL tristate)
 435+{
 436+ TCHAR buffer[32];
 437+ if (tristate && !maskx && !masky)
 438+ SendDlgItemMessage(hWnd, DlgItem, CB_SETCURSEL,
 439+ SendDlgItemMessage(hWnd, DlgItem, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
 440+ else
 441+ {
 442+ FloatToScale(x, y, buffer);
 443+ SendDlgItemMessage(hWnd, DlgItem, CB_SETCURSEL,
 444+ SendDlgItemMessage(hWnd, DlgItem, CB_FINDSTRING, -1, (LPARAM)buffer), 0);
 445+ SetDlgItemText(hWnd, DlgItem, buffer);
 446+ }
402447 }
403448
404449 void SetText(HWND hWnd, int DlgItem, TCHAR *value, TCHAR *mask, BOOL tristate)
@@ -440,6 +485,56 @@
441486 }
442487 }
443488
 489+void Get1stScaleCombo(HWND hWnd, int DlgItem, float *x, float *y, float *maskx, float *masky)
 490+{
 491+ TCHAR buffer[32];
 492+ TCHAR *ptr;
 493+ GetDlgItemText(hWnd, DlgItem, buffer, 31);
 494+ buffer[31] = 0;
 495+ if (!_tcscmp(buffer, strdefault))
 496+ {
 497+ *maskx = 0.0f;
 498+ *masky = 0.0f;
 499+ *x = 0.0f;
 500+ *y = 0.0f;
 501+ return;
 502+ }
 503+ else
 504+ {
 505+ *maskx = 1.0f;
 506+ *masky = 1.0f;
 507+ // Check for Auto
 508+ if (!_tcsicmp(buffer, _T("Auto)")))
 509+ {
 510+ *x = 0.0f;
 511+ *y = 0.0f;
 512+ return;
 513+ }
 514+ else
 515+ {
 516+ // Check for certain characters
 517+ ptr = _tcsstr(buffer, _T("x"));
 518+ if (!ptr) ptr = _tcsstr(buffer, _T("X"));
 519+ if (!ptr) ptr = _tcsstr(buffer, _T(","));
 520+ if (!ptr) ptr = _tcsstr(buffer, _T("-"));
 521+ if (!ptr) ptr = _tcsstr(buffer, _T(":"));
 522+ if (ptr)
 523+ {
 524+ *ptr = 0;
 525+ *x = _ttof(buffer);
 526+ *y = _ttof(ptr + 1);
 527+ return;
 528+ }
 529+ else
 530+ {
 531+ *x = _ttof(buffer);
 532+ *y = _ttof(buffer);
 533+ return;
 534+ }
 535+ }
 536+ }
 537+}
 538+
444539 float GetAspectCombo(HWND hWnd, int DlgItem, float *mask)
445540 {
446541 TCHAR buffer[32];
@@ -446,15 +541,16 @@
447542 TCHAR *ptr;
448543 float numerator, denominator;
449544 GetDlgItemText(hWnd, DlgItem, buffer, 31);
 545+ buffer[31] = 0;
450546 if (!_tcscmp(buffer, strdefault))
451547 {
452548 *mask = 0.0f;
453 - return 0;
 549+ return 0.0f;
454550 }
455551 else
456552 {
457553 *mask = 1.0f;
458 - if (!_tcscmp(buffer, _T("Default"))) return 0.0f;
 554+ if (!_tcsicmp(buffer, _T("Default"))) return 0.0f;
459555 else
460556 {
461557 // Check for colon
@@ -814,7 +910,7 @@
815911 SendDlgItemMessage(hTabs[0], IDC_PRESCALE, CB_ADDSTRING, 0, (LPARAM)buffer);
816912 _tcscpy(buffer, _T("Bilinear"));
817913 SendDlgItemMessage(hTabs[0], IDC_PRESCALE, CB_ADDSTRING, 1, (LPARAM)buffer);
818 - SendDlgItemMessage(hTabs[0], IDC_PRESCALE, CB_SETCURSEL, cfg->scalingfilter, 0);
 914+ SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_SETCURSEL, cfg->firstscalefilter, 0);
819915 // first scaling sizes
820916 _tcscpy(buffer, _T("Auto"));
821917 SendDlgItemMessage(hTabs[0], IDC_PRESCALESIZE, CB_ADDSTRING, 0, (LPARAM)buffer);
@@ -828,6 +924,8 @@
829925 SendDlgItemMessage(hTabs[0], IDC_PRESCALESIZE, CB_ADDSTRING, 0, (LPARAM)buffer);
830926 _tcscpy(buffer, _T("4x"));
831927 SendDlgItemMessage(hTabs[0], IDC_PRESCALESIZE, CB_ADDSTRING, 0, (LPARAM)buffer);
 928+ Set1stScaleCombo(hWnd, IDC_PRESCALESIZE, cfg->firstscalex, cfg->firstscaley,
 929+ cfgmask->firstscalex, cfgmask->firstscaley, tristate);
832930 // final scaling filter
833931 _tcscpy(buffer,_T("Nearest"));
834932 SendDlgItemMessage(hTabs[0], IDC_SCALE, CB_ADDSTRING, 0, (LPARAM)buffer);
@@ -1305,6 +1403,8 @@
13061404 tristate = TRUE;
13071405 SendDlgItemMessage(hWnd,IDC_VIDMODE,CB_ADDSTRING,0,(LPARAM)strdefault);
13081406 SendDlgItemMessage(hWnd,IDC_SORTMODES,CB_ADDSTRING,0,(LPARAM)strdefault);
 1407+ SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_ADDSTRING, 0, (LPARAM)strdefault);
 1408+ SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_ADDSTRING, 0, (LPARAM)strdefault);
13091409 SendDlgItemMessage(hWnd,IDC_SCALE,CB_ADDSTRING,0,(LPARAM)strdefault);
13101410 SendDlgItemMessage(hWnd,IDC_VSYNC,CB_ADDSTRING,0,(LPARAM)strdefault);
13111411 SendDlgItemMessage(hWnd,IDC_MSAA,CB_ADDSTRING,0,(LPARAM)strdefault);
@@ -1327,6 +1427,10 @@
13281428 SendDlgItemMessage(hWnd,IDC_VIDMODE,CB_FINDSTRING,-1,(LPARAM)strdefault),0);
13291429 SendDlgItemMessage(hWnd,IDC_SORTMODES,CB_DELETESTRING,
13301430 SendDlgItemMessage(hWnd,IDC_SORTMODES,CB_FINDSTRING,-1,(LPARAM)strdefault),0);
 1431+ SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_DELETESTRING,
 1432+ SendDlgItemMessage(hWnd, IDC_PRESCALE, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
 1433+ SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_DELETESTRING,
 1434+ SendDlgItemMessage(hWnd, IDC_PRESCALESIZE, CB_FINDSTRING, -1, (LPARAM)strdefault), 0);
13311435 SendDlgItemMessage(hWnd,IDC_SCALE,CB_DELETESTRING,
13321436 SendDlgItemMessage(hWnd,IDC_SCALE,CB_FINDSTRING,-1,(LPARAM)strdefault),0);
13331437 SendDlgItemMessage(hWnd,IDC_VSYNC,CB_DELETESTRING,
@@ -1355,6 +1459,7 @@
13561460 // Read settings into controls
13571461 SetCombo(hWnd,IDC_VIDMODE,cfg->scaler,cfgmask->scaler,tristate);
13581462 SetCombo(hWnd,IDC_SORTMODES,cfg->SortModes,cfgmask->SortModes,tristate);
 1463+ SetCombo(hWnd,IDC_PRESCALE,cfg->firstscalefilter,cfgmask->firstscalefilter,tristate);
13591464 SetCombo(hWnd,IDC_SCALE,cfg->scalingfilter,cfgmask->scalingfilter,tristate);
13601465 SetCombo(hWnd,IDC_VSYNC,cfg->vsync,cfgmask->vsync,tristate);
13611466 SetCombo(hWnd,IDC_MSAA,cfg->msaa,cfgmask->msaa,tristate);
@@ -1369,6 +1474,8 @@
13701475 SetCheck(hWnd,IDC_EXTRAMODES,cfg->ExtraModes,cfgmask->ExtraModes,tristate);
13711476 SetText(hWnd,IDC_SHADER,cfg->shaderfile,cfgmask->shaderfile,tristate);
13721477 SetCombo(hWnd, IDC_DPISCALE, cfg->DPIScale, cfgmask->DPIScale, tristate);
 1478+ Set1stScaleCombo(hWnd, IDC_PRESCALESIZE, cfg->firstscalex, cfg->firstscaley,
 1479+ cfgmask->firstscalex, cfgmask->firstscaley, tristate);
13731480 SetAspectCombo(hWnd, IDC_ASPECT, cfg->aspect, cfgmask->aspect, tristate);*/
13741481 }
13751482 break;
@@ -1382,6 +1489,11 @@
13831490 EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);
13841491 *dirty = TRUE;
13851492 break;
 1493+ case IDC_PRESCALE:
 1494+ cfg->firstscalefilter = GetCombo(hWnd,IDC_PRESCALE,&cfgmask->firstscalefilter);
 1495+ EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);
 1496+ *dirty = TRUE;
 1497+ break;
13861498 case IDC_SCALE:
13871499 cfg->scalingfilter = GetCombo(hWnd,IDC_SCALE,&cfgmask->scalingfilter);
13881500 EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);
@@ -1447,6 +1559,24 @@
14481560 EnableWindow(GetDlgItem(hWnd, IDC_APPLY), TRUE);
14491561 *dirty = TRUE;
14501562 break;
 1563+ case IDC_PRESCALESIZE:
 1564+ if (HIWORD(wParam) == CBN_KILLFOCUS)
 1565+ {
 1566+ Get1stScaleCombo(hWnd, IDC_PRESCALESIZE, &cfg->firstscalex, &cfg->firstscaley,
 1567+ &cfgmask->firstscalex, &cfgmask->firstscaley);
 1568+ Set1stScaleCombo(hWnd, IDC_PRESCALESIZE, cfg->firstscalex, cfg->firstscaley,
 1569+ cfgmask->firstscalex, cfgmask->firstscaley, tristate);
 1570+ EnableWindow(GetDlgItem(hWnd, IDC_APPLY), TRUE);
 1571+ *dirty = TRUE;
 1572+ }
 1573+ else if (HIWORD(wParam) == CBN_SELCHANGE)
 1574+ {
 1575+ Get1stScaleCombo(hWnd, IDC_PRESCALESIZE, &cfg->firstscalex, &cfg->firstscaley,
 1576+ &cfgmask->firstscalex, &cfgmask->firstscaley);
 1577+ EnableWindow(GetDlgItem(hWnd, IDC_APPLY), TRUE);
 1578+ *dirty = TRUE;
 1579+ }
 1580+ break;
14511581 case IDC_SHADER:
14521582 if(HIWORD(wParam) == EN_CHANGE)
14531583 {