DXGL r753 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r752‎ | r753 | r754 >
Date:03:19, 9 October 2017
Author:admin
Status:new
Tags:
Comment:
DXGLCFG2: Implement checkboxes for extra modes combobox.
Fix item highlighting in application list.
Modified paths:
  • /dxglcfg2/dxglcfg2.c (modified) (history)

Diff [purge]

Index: dxglcfg2/dxglcfg2.c
@@ -66,6 +66,8 @@
6767 HRESULT(WINAPI *_DrawThemeBackground)(HTHEME hTheme, HDC hdc, int iPartID,
6868 int iStateID, const RECT *pRect, const RECT *pClipRect) = NULL;
6969 HRESULT(WINAPI *_EnableThemeDialogTexture)(HWND hwnd, DWORD dwFlags) = NULL;
 70+static BOOL ExtraModes_Dropdown = FALSE;
 71+static HWND hDialog = NULL;
7072
7173
7274 typedef struct
@@ -128,6 +130,16 @@
129131 _T("8/15/16/24/32-bit")
130132 };
131133
 134+static const TCHAR *extramodes[7] = {
 135+ _T("Common low resolutions"),
 136+ _T("Uncommon low resolutions"),
 137+ _T("Uncommon SD resolutions"),
 138+ _T("High Definition resolutions"),
 139+ _T("Ultra-HD resolutions"),
 140+ _T("Ultra-HD above 4k"),
 141+ _T("Very uncommon resolutions")
 142+};
 143+
132144 DWORD AddApp(LPCTSTR path, BOOL copyfile, BOOL admin, BOOL force, HWND hwnd)
133145 {
134146 BOOL installed = FALSE;
@@ -708,6 +720,8 @@
709721 COLORREF OldTextColor, OldBackColor;
710722 RECT r;
711723 TCHAR combotext[64];
 724+ DWORD cursel;
 725+ int i;
712726 switch (Msg)
713727 {
714728 case WM_INITDIALOG:
@@ -740,19 +754,83 @@
741755 }
742756 else ExtTextOut(drawitem->hDC, 0, 0, ETO_OPAQUE, &drawitem->rcItem, NULL, 0, NULL);
743757 memcpy(&r, &drawitem->rcItem, sizeof(RECT));
744 - r.left = r.left + 2;
745 - r.right = r.left + GetSystemMetrics(SM_CXMENUCHECK);
746 - if (hThemeDisplay) _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX,
747 - CBS_CHECKEDNORMAL, &r, NULL);
748 - else DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_HOT);
749 - drawitem->rcItem.left += GetSystemMetrics(SM_CXMENUCHECK) + 5;
 758+ if (drawitem->itemID != -1 && !(drawitem->itemState & ODS_COMBOBOXEDIT))
 759+ {
 760+ r.left = r.left + 2;
 761+ r.right = r.left + GetSystemMetrics(SM_CXMENUCHECK);
 762+ if ((cfg->AddModes >> drawitem->itemID) & 1)
 763+ {
 764+ if (hThemeDisplay)
 765+ {
 766+ if (drawitem->itemState & ODS_SELECTED)
 767+ _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_CHECKEDHOT, &r, NULL);
 768+ else _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_CHECKEDNORMAL, &r, NULL);
 769+ }
 770+ else
 771+ {
 772+ if (drawitem->itemState & ODS_SELECTED)
 773+ DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_HOT);
 774+ else DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED);
 775+ }
 776+ }
 777+ else
 778+ {
 779+ if (hThemeDisplay)
 780+ {
 781+ if (drawitem->itemState & ODS_SELECTED)
 782+ _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_UNCHECKEDHOT, &r, NULL);
 783+ else _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX, CBS_UNCHECKEDNORMAL, &r, NULL);
 784+ }
 785+ else
 786+ {
 787+ if (drawitem->itemState & ODS_SELECTED)
 788+ DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_HOT);
 789+ else DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK);
 790+ }
 791+ }
 792+ drawitem->rcItem.left += GetSystemMetrics(SM_CXMENUCHECK) + 5;
 793+ }
750794 combotext[0] = 0;
751 - SendDlgItemMessage(hWnd, IDC_EXTRAMODES, CB_GETLBTEXT, drawitem->itemID, combotext);
752 - DrawText(drawitem->hDC, combotext, _tcslen(combotext), &drawitem->rcItem,
 795+ if (drawitem->itemID != -1 && !(drawitem->itemState & ODS_COMBOBOXEDIT))
 796+ SendDlgItemMessage(hWnd, IDC_EXTRAMODES, CB_GETLBTEXT, drawitem->itemID, combotext);
 797+ else
 798+ {
 799+ switch (cfg->AddModes)
 800+ {
 801+ case 0:
 802+ _tcscpy(combotext, _T("None"));
 803+ break;
 804+ case 1:
 805+ _tcscpy(combotext, extramodes[0]);
 806+ break;
 807+ case 2:
 808+ _tcscpy(combotext, extramodes[1]);
 809+ break;
 810+ case 4:
 811+ _tcscpy(combotext, extramodes[2]);
 812+ break;
 813+ case 8:
 814+ _tcscpy(combotext, extramodes[3]);
 815+ break;
 816+ case 16:
 817+ _tcscpy(combotext, extramodes[4]);
 818+ break;
 819+ case 32:
 820+ _tcscpy(combotext, extramodes[5]);
 821+ break;
 822+ case 64:
 823+ _tcscpy(combotext, extramodes[6]);
 824+ break;
 825+ default:
 826+ _tcscpy(combotext, _T("Multiple selections"));
 827+ }
 828+ }
 829+ DrawText(drawitem->hDC, combotext, _tcslen(combotext), &drawitem->rcItem,
753830 DT_LEFT | DT_SINGLELINE | DT_VCENTER);
754831 SetTextColor(drawitem->hDC, OldTextColor);
755832 SetBkColor(drawitem->hDC, OldBackColor);
756 - drawitem->rcItem.left -= GetSystemMetrics(SM_CXMENUCHECK) + 5;
 833+ if (drawitem->itemID != -1 && !(drawitem->itemState & ODS_COMBOBOXEDIT))
 834+ drawitem->rcItem.left -= GetSystemMetrics(SM_CXMENUCHECK) + 5;
757835 if (drawitem->itemState & ODS_FOCUS) DrawFocusRect(drawitem->hDC, &drawitem->rcItem);
758836 DefWindowProc(hWnd, Msg, wParam, lParam);
759837 break;
@@ -765,6 +843,36 @@
766844 if (hThemeDisplay) _CloseThemeData(hThemeDisplay);
767845 _OpenThemeData(hWnd, L"Button");
768846 }
 847+ case WM_COMMAND:
 848+ {
 849+ switch (LOWORD(wParam))
 850+ {
 851+ case IDC_EXTRAMODES:
 852+ if (HIWORD(wParam) == CBN_SELENDOK)
 853+ {
 854+ if (ExtraModes_Dropdown)
 855+ {
 856+ cursel = SendDlgItemMessage(hWnd, IDC_EXTRAMODES, CB_GETCURSEL, 0, 0);
 857+ i = ((cfg->AddModes >> cursel) & 1);
 858+ if (i) cfg->AddModes &= ~(1 << cursel);
 859+ else cfg->AddModes |= 1 << cursel;
 860+ EnableWindow(GetDlgItem(hDialog, IDC_APPLY), TRUE);
 861+ *dirty = TRUE;
 862+ }
 863+ }
 864+ if (HIWORD(wParam) == CBN_DROPDOWN)
 865+ {
 866+ ExtraModes_Dropdown = TRUE;
 867+ }
 868+ if (HIWORD(wParam) == CBN_CLOSEUP)
 869+ {
 870+ ExtraModes_Dropdown = FALSE;
 871+ }
 872+ /*cfg->ExtraModes = GetCheck(hWnd,IDC_EXTRAMODES,&cfgmask->ExtraModes);
 873+ */
 874+ break;
 875+ }
 876+ }
769877 default:
770878 return FALSE;
771879 }
@@ -900,6 +1008,7 @@
9011009 switch (Msg)
9021010 {
9031011 case WM_INITDIALOG:
 1012+ hDialog = hWnd;
9041013 tristate = FALSE;
9051014 maxapps = 128;
9061015 apps = (app_setting *)malloc(maxapps*sizeof(app_setting));
@@ -1226,21 +1335,11 @@
12271336 SendDlgItemMessage(hTabs[0], IDC_COLORDEPTH, CB_ADDSTRING, i, (LPARAM)buffer);
12281337 }
12291338 SendDlgItemMessage(hTabs[0], IDC_COLORDEPTH, CB_SETCURSEL, cfg->AddColorDepths, 0);
1230 - _tcscpy(buffer, _T("Common low resolutions"));
1231 - SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 0, (LPARAM)buffer);
1232 - _tcscpy(buffer, _T("Uncommon low resolutions"));
1233 - SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 1, (LPARAM)buffer);
1234 - _tcscpy(buffer, _T("Uncommon SD resolutions"));
1235 - SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 2, (LPARAM)buffer);
1236 - _tcscpy(buffer, _T("High Definition resolutions"));
1237 - SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 3, (LPARAM)buffer);
1238 - _tcscpy(buffer, _T("Ultra-HD resolutions"));
1239 - SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 4, (LPARAM)buffer);
1240 - _tcscpy(buffer, _T("Ultra-HD above 4k"));
1241 - SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 5, (LPARAM)buffer);
1242 - _tcscpy(buffer, _T("Very uncommon resolutions"));
1243 - SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 6, (LPARAM)buffer);
1244 - //FIXME: Populate extra resolution combobox
 1339+ for (i = 0; i < 7; i++)
 1340+ {
 1341+ _tcscpy(buffer, extramodes[i]);
 1342+ SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, i, (LPARAM)buffer);
 1343+ }
12451344 // Enable shader
12461345 if (cfg->colormode) SendDlgItemMessage(hTabs[1], IDC_USESHADER, BM_SETCHECK, BST_CHECKED, 0);
12471346 else SendDlgItemMessage(hTabs[1], IDC_USESHADER, BM_SETCHECK, BST_UNCHECKED, 0);
@@ -1462,14 +1561,18 @@
14631562 case IDC_APPS:
14641563 OldTextColor = GetTextColor(drawitem->hDC);
14651564 OldBackColor = GetBkColor(drawitem->hDC);
1466 - if((drawitem->itemAction & ODA_SELECT) && (drawitem->itemState & ODS_SELECTED) &&
1467 - !(drawitem->itemState & ODS_COMBOBOXEDIT))
 1565+ if((drawitem->itemState & ODS_SELECTED))
14681566 {
14691567 SetTextColor(drawitem->hDC,GetSysColor(COLOR_HIGHLIGHTTEXT));
14701568 SetBkColor(drawitem->hDC,GetSysColor(COLOR_HIGHLIGHT));
14711569 FillRect(drawitem->hDC,&drawitem->rcItem,(HBRUSH)(COLOR_HIGHLIGHT+1));
14721570 }
1473 - else ExtTextOut(drawitem->hDC,0,0,ETO_OPAQUE,&drawitem->rcItem,NULL,0,NULL);
 1571+ else
 1572+ {
 1573+ SetTextColor(drawitem->hDC, GetSysColor(COLOR_WINDOWTEXT));
 1574+ SetBkColor(drawitem->hDC, GetSysColor(COLOR_WINDOW));
 1575+ FillRect(drawitem->hDC, &drawitem->rcItem, (HBRUSH)(COLOR_WINDOW + 1));
 1576+ }
14741577 DrawIconEx(drawitem->hDC,drawitem->rcItem.left+2,drawitem->rcItem.top,
14751578 apps[drawitem->itemID].icon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0,NULL,DI_NORMAL);
14761579 drawitem->rcItem.left += GetSystemMetrics(SM_CXSMICON)+5;
@@ -1476,6 +1579,8 @@
14771580 DrawText(drawitem->hDC,apps[drawitem->itemID].name,
14781581 _tcslen(apps[drawitem->itemID].name),&drawitem->rcItem,
14791582 DT_LEFT|DT_SINGLELINE|DT_VCENTER);
 1583+ drawitem->rcItem.left -= GetSystemMetrics(SM_CXSMICON)+5;
 1584+ if (drawitem->itemState & ODS_FOCUS) DrawFocusRect(drawitem->hDC, &drawitem->rcItem);
14801585 SetTextColor(drawitem->hDC,OldTextColor);
14811586 SetBkColor(drawitem->hDC,OldBackColor);
14821587 DefWindowProc(hWnd,Msg,wParam,lParam);
@@ -1673,11 +1778,6 @@
16741779 EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);
16751780 *dirty = TRUE;
16761781 break;
1677 - case IDC_EXTRAMODES:
1678 - cfg->ExtraModes = GetCheck(hWnd,IDC_EXTRAMODES,&cfgmask->ExtraModes);
1679 - EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);
1680 - *dirty = TRUE;
1681 - break;
16821782 case IDC_TEXTUREFORMAT:
16831783 cfg->TextureFormat = GetCombo(hWnd,IDC_TEXTUREFORMAT,&cfgmask->TextureFormat);
16841784 EnableWindow(GetDlgItem(hWnd,IDC_APPLY),TRUE);