DXGL r755 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r754‎ | r755 | r756 >
Date:18:03, 4 November 2017
Author:admin
Status:new
Tags:
Comment:
Implement Add color depths and Additional display modes comboboxes.
Fix owner draw combobox height.
Fix default for Add color depths (one time registry update).
Modified paths:
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /dxglcfg2/dxglcfg2.c (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.c
@@ -35,6 +35,7 @@
3636 #include "inih/ini.h"
3737
3838 TCHAR regkeyglobal[] = _T("Software\\DXGL\\Global");
 39+TCHAR regkeyprofiles[] = _T("Software\\DXGL\\Profiles\\");
3940 TCHAR regkeybase[] = _T("Software\\DXGL\\");
4041 TCHAR regkeydxgl[] = _T("Software\\DXGL");
4142
@@ -674,8 +675,8 @@
675676 WriteBool(hKey, cfg->EnableShader, cfgmask->EnableShader, _T("EnableShader"));
676677 WritePath(hKey,cfg->shaderfile,cfgmask->shaderfile,_T("ShaderFile"));
677678 WriteDWORD(hKey,cfg->SortModes,cfgmask->SortModes,_T("SortModes"));
678 - WriteBool(hKey,cfg->AddColorDepths,cfgmask->AddColorDepths,_T("AddColorDepths"));
679 - WriteBool(hKey,cfg->AddModes,cfgmask->AddModes,_T("AddModes"));
 679+ WriteDWORD(hKey,cfg->AddColorDepths,cfgmask->AddColorDepths,_T("AddColorDepths"));
 680+ WriteDWORD(hKey,cfg->AddModes,cfgmask->AddModes,_T("AddModes"));
680681 WriteDWORD(hKey,cfg->vsync,cfgmask->vsync,_T("VSync"));
681682 WriteDWORD(hKey,cfg->TextureFormat,cfgmask->TextureFormat,_T("TextureFormat"));
682683 WriteDWORD(hKey,cfg->TexUpload,cfgmask->TexUpload,_T("TexUpload"));
@@ -1131,8 +1132,9 @@
11321133 error = RegQueryValueEx(hKey, _T("Configuration Version"), NULL, &regtype, &version, &sizeout);
11331134 if (error != ERROR_SUCCESS) version = 0; // Version is 0 if not set (alpha didn't have version)
11341135 if (regtype != REG_DWORD) version = 0; // Is the key the wrong type?
1135 - if (version >= 1) return; // If version is 1 no need to upgrade.
 1136+ if (version >= 1) goto ver1to2; // If version is 1 check for version 2.
11361137 ver0to1:
 1138+ // Version 0 to 1: Convert old EXE checksum profiles to directory based profiles.
11371139 // Count profiles
11381140 keyindex = 0;
11391141 numoldconfig = 0;
@@ -1374,7 +1376,67 @@
13751377 if(oldvalue) free(oldvalue);
13761378 sizeout = 1;
13771379 RegSetValueEx(hKey, _T("Configuration Version"), 0, REG_DWORD, &sizeout, 4);
 1380+ver1to2:
13781381 RegCloseKey(hKey);
 1382+ // Version 1 to 2: Fix an incorrectly written AddColorDepths value
 1383+ if (version >= 2) return; // If version is 2 no need to upgrade.
 1384+ // Fix up the global Add color depths
 1385+ _tcscpy(regkey, regkeyglobal);
 1386+ error = RegCreateKeyEx(HKEY_CURRENT_USER, regkey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
 1387+ sizeout = 4;
 1388+ regtype = REG_DWORD;
 1389+ error = RegQueryValueEx(hKey,_T("AddColorDepths"),NULL,
 1390+ &regtype, &numvalue, &sizeout);
 1391+ if (error == ERROR_SUCCESS)
 1392+ {
 1393+ if (numvalue == 1)
 1394+ {
 1395+ numvalue = 1 | 4 | 16;
 1396+ RegSetValueEx(hKey, _T("AddColorDepths"), 0, REG_DWORD, &numvalue, 4);
 1397+ }
 1398+ }
 1399+ RegCloseKey(hKey);
 1400+ // Enumerate profiles and fix up Add color depths
 1401+ _tcscpy(regkey, regkeyprofiles);
 1402+ error = RegOpenKeyEx(HKEY_CURRENT_USER, regkey, 0, KEY_ALL_ACCESS, &hKey);
 1403+ if (error == ERROR_SUCCESS)
 1404+ {
 1405+ keyindex = 0;
 1406+ do
 1407+ {
 1408+ sizeout = MAX_PATH;
 1409+ error = RegEnumKeyEx(hKey, keyindex, &subkey, &sizeout,
 1410+ NULL, NULL, NULL, NULL);
 1411+ keyindex++;
 1412+ if (error == ERROR_SUCCESS)
 1413+ {
 1414+ error2 = RegOpenKeyEx(hKey, subkey, 0, KEY_ALL_ACCESS, &hKeyProfile);
 1415+ if (error2 == ERROR_SUCCESS)
 1416+ {
 1417+ error2 = RegQueryValueEx(hKeyProfile, _T("AddColorDepths"), NULL,
 1418+ &regtype, &numvalue, &sizeout);
 1419+ if (error2 == ERROR_SUCCESS)
 1420+ {
 1421+ if (numvalue == 1)
 1422+ {
 1423+ numvalue = 1 | 4 | 16;
 1424+ RegSetValueEx(hKeyProfile, _T("AddColorDepths"), 0, REG_DWORD, &numvalue, 4);
 1425+ }
 1426+ }
 1427+ RegCloseKey(hKeyProfile);
 1428+ }
 1429+ }
 1430+ } while (error == ERROR_SUCCESS);
 1431+ RegCloseKey(hKey);
 1432+ }
 1433+ _tcscpy(regkey, regkeybase);
 1434+ error = RegCreateKeyEx(HKEY_CURRENT_USER, regkey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
 1435+ if (error == ERROR_SUCCESS)
 1436+ {
 1437+ sizeout = 2;
 1438+ RegSetValueEx(hKey, _T("Configuration Version"), 0, REG_DWORD, &sizeout, 4);
 1439+ RegCloseKey(hKey);
 1440+ }
13791441 }
13801442
13811443 int ReadINIOptionsCallback(app_ini_options *options, const char *section, const char *name,
Index: dxglcfg2/dxglcfg2.c
@@ -103,7 +103,7 @@
104104 _T("8/15-bit"),
105105 _T("16-bit"),
106106 _T("8/16-bit"),
107 - _T("8/15-bit"),
 107+ _T("15/16-bit"),
108108 _T("8/15/16-bit"),
109109 _T("24-bit"),
110110 _T("8/24-bit"),
@@ -111,7 +111,7 @@
112112 _T("8/15/24-bit"),
113113 _T("16/24-bit"),
114114 _T("8/16/24-bit"),
115 - _T("8/15/24-bit"),
 115+ _T("15/16/24-bit"),
116116 _T("8/15/16/24-bit"),
117117 _T("32-bit"),
118118 _T("8/32-bit"),
@@ -119,7 +119,7 @@
120120 _T("8/15/32-bit"),
121121 _T("16/32-bit"),
122122 _T("8/16/32-bit"),
123 - _T("8/15/32-bit"),
 123+ _T("15/16/32-bit"),
124124 _T("8/15/16/32-bit"),
125125 _T("24/32-bit"),
126126 _T("8/24/32-bit"),
@@ -127,7 +127,7 @@
128128 _T("8/15/24/32-bit"),
129129 _T("16/24/32-bit"),
130130 _T("8/16/24/32-bit"),
131 - _T("8/15/24/32-bit"),
 131+ _T("15/16/24/32-bit"),
132132 _T("8/15/16/24/32-bit")
133133 };
134134
@@ -723,6 +723,77 @@
724724 if(str[0] == 0) mask[0] = 0;
725725 else mask[0] = 0xff;
726726 }
 727+
 728+void DrawCheck(HDC hdc, BOOL selected, BOOL checked, BOOL grayed, RECT *r)
 729+{
 730+ if (grayed)
 731+ {
 732+ if (checked)
 733+ {
 734+ if (hThemeDisplay)
 735+ {
 736+ if (selected)
 737+ _DrawThemeBackground(hThemeDisplay, hdc, BS_AUTOCHECKBOX, CBS_CHECKEDHOT, r, NULL);
 738+ else _DrawThemeBackground(hThemeDisplay, hdc, BS_AUTOCHECKBOX, CBS_CHECKEDDISABLED, r, NULL);
 739+ }
 740+ else
 741+ {
 742+ if (selected)
 743+ DrawFrameControl(hdc, r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_INACTIVE | DFCS_HOT);
 744+ else DrawFrameControl(hdc, r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_INACTIVE);
 745+ }
 746+ }
 747+ else
 748+ {
 749+ if (hThemeDisplay)
 750+ {
 751+ if (selected)
 752+ _DrawThemeBackground(hThemeDisplay, hdc, BS_AUTOCHECKBOX, CBS_UNCHECKEDHOT, r, NULL);
 753+ else _DrawThemeBackground(hThemeDisplay, hdc, BS_AUTOCHECKBOX, CBS_UNCHECKEDDISABLED, r, NULL);
 754+ }
 755+ else
 756+ {
 757+ if (selected)
 758+ DrawFrameControl(hdc, r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_INACTIVE | DFCS_HOT);
 759+ else DrawFrameControl(hdc, r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_INACTIVE);
 760+ }
 761+ }
 762+ }
 763+ else
 764+ {
 765+ if (checked)
 766+ {
 767+ if (hThemeDisplay)
 768+ {
 769+ if (selected)
 770+ _DrawThemeBackground(hThemeDisplay, hdc, BS_AUTOCHECKBOX, CBS_CHECKEDHOT, r, NULL);
 771+ else _DrawThemeBackground(hThemeDisplay, hdc, BS_AUTOCHECKBOX, CBS_CHECKEDNORMAL, r, NULL);
 772+ }
 773+ else
 774+ {
 775+ if (selected)
 776+ DrawFrameControl(hdc, r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_HOT);
 777+ else DrawFrameControl(hdc, r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED);
 778+ }
 779+ }
 780+ else
 781+ {
 782+ if (hThemeDisplay)
 783+ {
 784+ if (selected)
 785+ _DrawThemeBackground(hThemeDisplay, hdc, BS_AUTOCHECKBOX, CBS_UNCHECKEDHOT, r, NULL);
 786+ else _DrawThemeBackground(hThemeDisplay, hdc, BS_AUTOCHECKBOX, CBS_UNCHECKEDNORMAL, r, NULL);
 787+ }
 788+ else
 789+ {
 790+ if (selected)
 791+ DrawFrameControl(hdc, r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_HOT);
 792+ else DrawFrameControl(hdc, r, DFC_BUTTON, DFCS_BUTTONCHECK);
 793+ }
 794+ }
 795+ }
 796+}
 797+
727798 LRESULT CALLBACK DisplayTabCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
728799 {
729800 DRAWITEMSTRUCT* drawitem;
@@ -730,6 +801,9 @@
731802 RECT r;
732803 TCHAR combotext[64];
733804 DWORD cursel;
 805+ HDC hdc;
 806+ HFONT font1, font2;
 807+ SIZE size;
734808 int i;
735809 switch (Msg)
736810 {
@@ -743,8 +817,21 @@
744818 {
745819 case IDC_COLORDEPTH:
746820 case IDC_EXTRAMODES:
747 - ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = GetSystemMetrics(SM_CYMENUCHECK);
748 - ((LPMEASUREITEMSTRUCT)lParam)->itemWidth = GetSystemMetrics(SM_CXMENUCHECK);
 821+ if (((LPMEASUREITEMSTRUCT)lParam)->itemID == -1)
 822+ {
 823+ hdc = GetDC(hWnd);
 824+ font1 = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
 825+ font2 = SelectObject(hdc, font1);
 826+ GetTextExtentPoint(hdc, _T(" "), 1, &size);
 827+ SelectObject(hdc, font2);
 828+ ReleaseDC(hWnd, hdc);
 829+ ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = size.cy + 2;
 830+ }
 831+ else
 832+ {
 833+ ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = GetSystemMetrics(SM_CYMENUCHECK);
 834+ ((LPMEASUREITEMSTRUCT)lParam)->itemWidth = GetSystemMetrics(SM_CXMENUCHECK);
 835+ }
749836 break;
750837 default:
751838 break;
@@ -768,35 +855,17 @@
769856 {
770857 r.left = r.left + 2;
771858 r.right = r.left + GetSystemMetrics(SM_CXMENUCHECK);
772 - if ((cfg->AddColorDepths >> drawitem->itemID) & 1)
 859+ if (drawitem->itemID == 5)
773860 {
774 - if (hThemeDisplay)
775 - {
776 - if (drawitem->itemState & ODS_SELECTED)
777 - _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_CHECKEDHOT, &r, NULL);
778 - else _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_CHECKEDNORMAL, &r, NULL);
779 - }
780 - else
781 - {
782 - if (drawitem->itemState & ODS_SELECTED)
783 - DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_HOT);
784 - else DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED);
785 - }
 861+ if(!cfgmask->AddColorDepths)
 862+ DrawCheck(drawitem->hDC, drawitem->itemState & ODS_SELECTED, TRUE, FALSE, &r);
 863+ else DrawCheck(drawitem->hDC, drawitem->itemState & ODS_SELECTED, FALSE, FALSE, &r);
786864 }
787865 else
788866 {
789 - if (hThemeDisplay)
790 - {
791 - if (drawitem->itemState & ODS_SELECTED)
792 - _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_UNCHECKEDHOT, &r, NULL);
793 - else _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_UNCHECKEDNORMAL, &r, NULL);
794 - }
795 - else
796 - {
797 - if (drawitem->itemState & ODS_SELECTED)
798 - DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_HOT);
799 - else DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK);
800 - }
 867+ if ((cfg->AddColorDepths >> drawitem->itemID) & 1)
 868+ DrawCheck(drawitem->hDC, drawitem->itemState & ODS_SELECTED, TRUE, !cfgmask->AddColorDepths, &r);
 869+ else DrawCheck(drawitem->hDC, drawitem->itemState & ODS_SELECTED, FALSE, !cfgmask->AddColorDepths, &r);
801870 }
802871 drawitem->rcItem.left += GetSystemMetrics(SM_CXMENUCHECK) + 5;
803872 }
@@ -803,7 +872,11 @@
804873 combotext[0] = 0;
805874 if (drawitem->itemID != -1 && !(drawitem->itemState & ODS_COMBOBOXEDIT))
806875 SendDlgItemMessage(hWnd, IDC_COLORDEPTH, CB_GETLBTEXT, drawitem->itemID, combotext);
807 - else _tcscpy(combotext, colormodes[cfg->AddColorDepths & 31]);
 876+ else
 877+ {
 878+ if(!cfgmask->AddColorDepths) _tcscpy(combotext, strdefault);
 879+ else _tcscpy(combotext, colormodes[cfg->AddColorDepths & 31]);
 880+ }
808881 DrawText(drawitem->hDC, combotext, _tcslen(combotext), &drawitem->rcItem,
809882 DT_LEFT | DT_SINGLELINE | DT_VCENTER);
810883 SetTextColor(drawitem->hDC, OldTextColor);
@@ -828,35 +901,17 @@
829902 {
830903 r.left = r.left + 2;
831904 r.right = r.left + GetSystemMetrics(SM_CXMENUCHECK);
832 - if ((cfg->AddModes >> drawitem->itemID) & 1)
 905+ if (drawitem->itemID == 7)
833906 {
834 - if (hThemeDisplay)
835 - {
836 - if (drawitem->itemState & ODS_SELECTED)
837 - _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_CHECKEDHOT, &r, NULL);
838 - else _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_CHECKEDNORMAL, &r, NULL);
839 - }
840 - else
841 - {
842 - if (drawitem->itemState & ODS_SELECTED)
843 - DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_HOT);
844 - else DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED);
845 - }
 907+ if (!cfgmask->AddModes)
 908+ DrawCheck(drawitem->hDC, drawitem->itemState & ODS_SELECTED, TRUE, FALSE, &r);
 909+ else DrawCheck(drawitem->hDC, drawitem->itemState & ODS_SELECTED, FALSE, FALSE, &r);
846910 }
847911 else
848912 {
849 - if (hThemeDisplay)
850 - {
851 - if (drawitem->itemState & ODS_SELECTED)
852 - _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_UNCHECKEDHOT, &r, NULL);
853 - else _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_UNCHECKEDNORMAL, &r, NULL);
854 - }
855 - else
856 - {
857 - if (drawitem->itemState & ODS_SELECTED)
858 - DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_HOT);
859 - else DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK);
860 - }
 913+ if ((cfg->AddModes >> drawitem->itemID) & 1)
 914+ DrawCheck(drawitem->hDC, drawitem->itemState & ODS_SELECTED, TRUE, !cfgmask->AddModes, &r);
 915+ else DrawCheck(drawitem->hDC, drawitem->itemState & ODS_SELECTED, FALSE, !cfgmask->AddModes, &r);
861916 }
862917 drawitem->rcItem.left += GetSystemMetrics(SM_CXMENUCHECK) + 5;
863918 }
@@ -865,34 +920,38 @@
866921 SendDlgItemMessage(hWnd, IDC_EXTRAMODES, CB_GETLBTEXT, drawitem->itemID, combotext);
867922 else
868923 {
869 - switch (cfg->AddModes)
 924+ if (!cfgmask->AddModes) _tcscpy(combotext, strdefault);
 925+ else
870926 {
871 - case 0:
872 - _tcscpy(combotext, _T("None"));
873 - break;
874 - case 1:
875 - _tcscpy(combotext, extramodes[0]);
876 - break;
877 - case 2:
878 - _tcscpy(combotext, extramodes[1]);
879 - break;
880 - case 4:
881 - _tcscpy(combotext, extramodes[2]);
882 - break;
883 - case 8:
884 - _tcscpy(combotext, extramodes[3]);
885 - break;
886 - case 16:
887 - _tcscpy(combotext, extramodes[4]);
888 - break;
889 - case 32:
890 - _tcscpy(combotext, extramodes[5]);
891 - break;
892 - case 64:
893 - _tcscpy(combotext, extramodes[6]);
894 - break;
895 - default:
896 - _tcscpy(combotext, _T("Multiple selections"));
 927+ switch (cfg->AddModes)
 928+ {
 929+ case 0:
 930+ _tcscpy(combotext, _T("None"));
 931+ break;
 932+ case 1:
 933+ _tcscpy(combotext, extramodes[0]);
 934+ break;
 935+ case 2:
 936+ _tcscpy(combotext, extramodes[1]);
 937+ break;
 938+ case 4:
 939+ _tcscpy(combotext, extramodes[2]);
 940+ break;
 941+ case 8:
 942+ _tcscpy(combotext, extramodes[3]);
 943+ break;
 944+ case 16:
 945+ _tcscpy(combotext, extramodes[4]);
 946+ break;
 947+ case 32:
 948+ _tcscpy(combotext, extramodes[5]);
 949+ break;
 950+ case 64:
 951+ _tcscpy(combotext, extramodes[6]);
 952+ break;
 953+ default:
 954+ _tcscpy(combotext, _T("Multiple selections"));
 955+ }
897956 }
898957 }
899958 DrawText(drawitem->hDC, combotext, _tcslen(combotext), &drawitem->rcItem,
@@ -923,9 +982,18 @@
924983 if (ColorDepth_Dropdown)
925984 {
926985 cursel = SendDlgItemMessage(hWnd, IDC_COLORDEPTH, CB_GETCURSEL, 0, 0);
927 - i = ((cfg->AddColorDepths >> cursel) & 1);
928 - if (i) cfg->AddColorDepths &= ~(1 << cursel);
929 - else cfg->AddColorDepths |= 1 << cursel;
 986+ if (cursel == 5)
 987+ {
 988+ if (cfgmask->AddColorDepths) cfgmask->AddColorDepths = 0;
 989+ else cfgmask->AddColorDepths = 1;
 990+ }
 991+ else
 992+ {
 993+ if (!cfgmask->AddColorDepths) cfgmask->AddColorDepths = 1;
 994+ i = ((cfg->AddColorDepths >> cursel) & 1);
 995+ if (i) cfg->AddColorDepths &= ~(1 << cursel);
 996+ else cfg->AddColorDepths |= 1 << cursel;
 997+ }
930998 EnableWindow(GetDlgItem(hDialog, IDC_APPLY), TRUE);
931999 *dirty = TRUE;
9321000 }
@@ -945,9 +1013,18 @@
9461014 if (ExtraModes_Dropdown)
9471015 {
9481016 cursel = SendDlgItemMessage(hWnd, IDC_EXTRAMODES, CB_GETCURSEL, 0, 0);
949 - i = ((cfg->AddModes >> cursel) & 1);
950 - if (i) cfg->AddModes &= ~(1 << cursel);
951 - else cfg->AddModes |= 1 << cursel;
 1017+ if (cursel == 7)
 1018+ {
 1019+ if (cfgmask->AddModes) cfgmask->AddModes = 0;
 1020+ else cfgmask->AddModes = 1;
 1021+ }
 1022+ else
 1023+ {
 1024+ if (!cfgmask->AddModes) cfgmask->AddModes = 1;
 1025+ i = ((cfg->AddModes >> cursel) & 1);
 1026+ if (i) cfg->AddModes &= ~(1 << cursel);
 1027+ else cfg->AddModes |= 1 << cursel;
 1028+ }
9521029 EnableWindow(GetDlgItem(hDialog, IDC_APPLY), TRUE);
9531030 *dirty = TRUE;
9541031 }