DXGL r569 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r568‎ | r569 | r570 >
Date:22:53, 23 November 2014
Author:admin
Status:new
Tags:
Comment:
Read in config settings on startup of DXGLCFG2.
Modified paths:
  • /cfgmgr/ReadMe.txt (modified) (history)
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /dxglcfg2/dxglcfg2.c (modified) (history)
  • /dxglcfg2/dxglcfg2.rc (modified) (history)

Diff [purge]

Index: cfgmgr/ReadMe.txt
@@ -92,6 +92,10 @@
9393 1 - Expand viewable area. May have glitches on edge of screen.
9494 2 - Crop to viewable area. May cause graphics to get cut off.
9595
 96+Member EnableShader
 97+REG_DWORD HKCU\DXGL\<app>\EnableShader
 98+If nonzero, enables post-process shaders.
 99+
96100 Member shaderfile
97101 REG_SZ HKCU\DXGL\<app>\ShaderFile
98102 Full path to file containing a post-process shader script.
Index: cfgmgr/cfgmgr.c
@@ -440,6 +440,7 @@
441441 cfg->primaryscale = ReadDWORD(hKey,cfg->primaryscale,&cfgmask->primaryscale,_T("AdjustPrimaryResolution"));
442442 cfg->primaryscalex = ReadFloat(hKey,cfg->primaryscalex,&cfgmask->primaryscalex,_T("PrimaryScaleX"));
443443 cfg->primaryscaley = ReadFloat(hKey,cfg->primaryscaley,&cfgmask->primaryscaley,_T("PrimaryScaleY"));
 444+ cfg->EnableShader = ReadBool(hKey, cfg->EnableShader, &cfgmask->EnableShader, _T("EnableShader"));
444445 ReadPath(hKey,cfg->shaderfile,cfgmask->shaderfile,_T("ShaderFile"));
445446 cfg->SortModes = ReadDWORD(hKey,cfg->SortModes,&cfgmask->SortModes,_T("SortModes"));
446447 cfg->AddColorDepths = ReadDeprecatedBool(hKey, cfg->AddColorDepths, &cfgmask->AddColorDepths, _T("AllColorDepths"), 1 | 4 | 16, 0);
@@ -532,6 +533,7 @@
533534 WriteBool(hKey,cfg->primaryscale,cfgmask->primaryscale,_T("AdjustPrimaryResolution"));
534535 WriteFloat(hKey,cfg->primaryscalex,cfgmask->primaryscalex,_T("PrimaryScaleX"));
535536 WriteFloat(hKey,cfg->primaryscaley,cfgmask->primaryscaley,_T("PrimaryScaleY"));
 537+ WriteBool(hKey, cfg->EnableShader, cfgmask->EnableShader, _T("EnableShader"));
536538 WritePath(hKey,cfg->shaderfile,cfgmask->shaderfile,_T("ShaderFile"));
537539 WriteDWORD(hKey,cfg->SortModes,cfgmask->SortModes,_T("SortModes"));
538540 WriteBool(hKey,cfg->AddColorDepths,cfgmask->AddColorDepths,_T("AddColorDepths"));
Index: cfgmgr/cfgmgr.h
@@ -36,6 +36,7 @@
3737 float primaryscalex;
3838 float primaryscaley;
3939 DWORD vsync;
 40+ BOOL EnableShader;
4041 TCHAR shaderfile[MAX_PATH+1];
4142 DWORD SortModes;
4243 DWORD AddColorDepths;
Index: dxglcfg2/dxglcfg2.c
@@ -22,7 +22,6 @@
2323 #include <stdlib.h>
2424 #include <crtdbg.h>
2525 #include <windows.h>
26 -#include <windowsx.h>
2726 #include <HtmlHelp.h>
2827 #include <CommCtrl.h>
2928 #include <string.h>
@@ -30,6 +29,8 @@
3130 #include <stdio.h>
3231 #include <math.h>
3332 #include <io.h>
 33+#include <Uxtheme.h>
 34+#include <Vsstyle.h>
3435 #include "resource.h"
3536 #include "../cfgmgr/cfgmgr.h"
3637 #include <gl/GL.h>
@@ -56,7 +57,14 @@
5758 const char *extensions_string = NULL;
5859 OSVERSIONINFO osver;
5960 TCHAR hlppath[MAX_PATH+16];
 61+HMODULE uxtheme = NULL;
 62+HTHEME hThemeDisplay = NULL;
 63+HTHEME(WINAPI *_OpenThemeData)(HWND hwnd, LPCWSTR pszClassList) = NULL;
 64+HRESULT(WINAPI *_CloseThemeData)(HTHEME hTheme) = NULL;
 65+HRESULT(WINAPI *_DrawThemeBackground)(HTHEME hTheme, HDC hdc, int iPartID,
 66+ int iStateID, const RECT *pRect, const RECT *pClipRect) = NULL;
6067
 68+
6169 typedef struct
6270 {
6371 LPTSTR regkey;
@@ -115,10 +123,6 @@
116124 _T("8/15/16/24/32-bit")
117125 };
118126
119 -LRESULT CALLBACK CheckedComboProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
120 -{
121 -}
122 -
123127 DWORD AddApp(LPCTSTR path, BOOL copyfile, BOOL admin)
124128 {
125129 BOOL installed = FALSE;
@@ -266,6 +270,7 @@
267271 float fract;
268272 TCHAR denominator[5];
269273 int i;
 274+ if (_isnan(f)) f = 0; //Handle NAN condition
270275 if (f >= 1000.0f) // Clamp ridiculously wide aspects
271276 {
272277 _tcscpy(aspect, _T("1000:1"));
@@ -469,10 +474,65 @@
470475 }
471476 LRESULT CALLBACK DisplayTabCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
472477 {
 478+ DRAWITEMSTRUCT* drawitem;
 479+ COLORREF OldTextColor, OldBackColor;
 480+ RECT r;
 481+ TCHAR combotext[64];
473482 switch (Msg)
474483 {
475484 case WM_INITDIALOG:
 485+ if (uxtheme) hThemeDisplay = _OpenThemeData(hWnd, L"Button");
 486+ else hThemeDisplay = NULL;
476487 return TRUE;
 488+ case WM_MEASUREITEM:
 489+ switch (wParam)
 490+ {
 491+ case IDC_EXTRAMODES:
 492+ ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = GetSystemMetrics(SM_CYMENUCHECK);
 493+ ((LPMEASUREITEMSTRUCT)lParam)->itemWidth = GetSystemMetrics(SM_CXMENUCHECK);
 494+ break;
 495+ default:
 496+ break;
 497+ }
 498+ case WM_DRAWITEM:
 499+ drawitem = (DRAWITEMSTRUCT*)lParam;
 500+ switch (wParam)
 501+ {
 502+ case IDC_EXTRAMODES:
 503+ OldTextColor = GetTextColor(drawitem->hDC);
 504+ OldBackColor = GetBkColor(drawitem->hDC);
 505+ if ((drawitem->itemAction | ODA_SELECT) && (drawitem->itemState & ODS_SELECTED) &&
 506+ !(drawitem->itemState & ODS_COMBOBOXEDIT))
 507+ {
 508+ SetTextColor(drawitem->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
 509+ SetBkColor(drawitem->hDC, GetSysColor(COLOR_HIGHLIGHT));
 510+ FillRect(drawitem->hDC, &drawitem->rcItem, (HBRUSH)(COLOR_HIGHLIGHT + 1));
 511+ }
 512+ else ExtTextOut(drawitem->hDC, 0, 0, ETO_OPAQUE, &drawitem->rcItem, NULL, 0, NULL);
 513+ memcpy(&r, &drawitem->rcItem, sizeof(RECT));
 514+ r.left = r.left + 2;
 515+ r.right = r.left + GetSystemMetrics(SM_CXMENUCHECK);
 516+ if (hThemeDisplay) _DrawThemeBackground(hThemeDisplay, drawitem->hDC, BS_AUTOCHECKBOX,
 517+ CBS_CHECKEDNORMAL, &r, NULL);
 518+ else DrawFrameControl(drawitem->hDC, &r, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_HOT);
 519+ drawitem->rcItem.left += GetSystemMetrics(SM_CXMENUCHECK) + 5;
 520+ combotext[0] = 0;
 521+ SendDlgItemMessage(hWnd, IDC_EXTRAMODES, CB_GETLBTEXT, drawitem->itemID, combotext);
 522+ DrawText(drawitem->hDC, combotext, _tcslen(combotext), &drawitem->rcItem,
 523+ DT_LEFT | DT_SINGLELINE | DT_VCENTER);
 524+ SetTextColor(drawitem->hDC, OldTextColor);
 525+ SetBkColor(drawitem->hDC, OldBackColor);
 526+ DefWindowProc(hWnd, Msg, wParam, lParam);
 527+ break;
 528+ default:
 529+ break;
 530+ }
 531+ case WM_THEMECHANGED:
 532+ if (uxtheme)
 533+ {
 534+ if (hThemeDisplay) _CloseThemeData(hThemeDisplay);
 535+ _OpenThemeData(hWnd, L"Button");
 536+ }
477537 default:
478538 return FALSE;
479539 }
@@ -588,7 +648,6 @@
589649 NMHDR *nm;
590650 int newtab;
591651 TCITEM tab;
592 - drawitem = (DRAWITEMSTRUCT*)lParam;
593652 switch (Msg)
594653 {
595654 case WM_INITDIALOG:
@@ -641,6 +700,21 @@
642701 wglDeleteContext(rc);
643702 ReleaseDC(hGLWnd,dc);
644703 DestroyWindow(hGLWnd);
 704+ uxtheme = LoadLibrary(_T("uxtheme.dll"));
 705+ if (uxtheme)
 706+ {
 707+
 708+ _OpenThemeData = (HTHEME(WINAPI*)(HWND,LPCWSTR))GetProcAddress(uxtheme, "OpenThemeData");
 709+ _CloseThemeData = (HRESULT(WINAPI*)(HTHEME))GetProcAddress(uxtheme, "CloseThemeData");
 710+ _DrawThemeBackground =
 711+ (HRESULT(WINAPI*)(HTHEME, HDC, int, int, const RECT*, const RECT*))
 712+ GetProcAddress(uxtheme, "DrawThemeBackground");
 713+ if (!(_OpenThemeData && _CloseThemeData && _DrawThemeBackground))
 714+ {
 715+ FreeLibrary(uxtheme);
 716+ uxtheme = NULL;
 717+ }
 718+ }
645719 // Add tabs
646720 ZeroMemory(&tab, sizeof(TCITEM));
647721 tab.mask = TCIF_TEXT;
@@ -864,27 +938,34 @@
865939 SendDlgItemMessage(hTabs[0], IDC_COLORDEPTH, CB_ADDSTRING, i, (LPARAM)buffer);
866940 }
867941 SendDlgItemMessage(hTabs[0], IDC_COLORDEPTH, CB_SETCURSEL, cfg->AddColorDepths, 0);
868 - /*// extra modes
869 - if(cfg->ExtraModes) SendDlgItemMessage(hWnd,IDC_EXTRAMODES,BM_SETCHECK,BST_CHECKED,0);
870 - else SendDlgItemMessage(hWnd,IDC_EXTRAMODES,BM_SETCHECK,BST_UNCHECKED,0);
 942+ _tcscpy(buffer, _T("Common low resolutions"));
 943+ SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 0, (LPARAM)buffer);
 944+ _tcscpy(buffer, _T("Uncommon low resolutions"));
 945+ SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 1, (LPARAM)buffer);
 946+ _tcscpy(buffer, _T("Higher resolutions"));
 947+ SendDlgItemMessage(hTabs[0], IDC_EXTRAMODES, CB_ADDSTRING, 2, (LPARAM)buffer);
 948+ //FIXME: Populate extra resolution combobox
 949+ // Enable shader
 950+ if (cfg->colormode) SendDlgItemMessage(hTabs[2], IDC_USESHADER, BM_SETCHECK, BST_CHECKED, 0);
 951+ else SendDlgItemMessage(hTabs[2], IDC_USESHADER, BM_SETCHECK, BST_UNCHECKED, 0);
871952 // shader path
872 - SetText(hWnd,IDC_SHADER,cfg->shaderfile,cfgmask->shaderfile,FALSE);
 953+ SetText(hTabs[2],IDC_SHADER,cfg->shaderfile,cfgmask->shaderfile,FALSE);
873954 // texture format
874955 _tcscpy(buffer,_T("Automatic"));
875 - SendDlgItemMessage(hWnd,IDC_TEXTUREFORMAT,CB_ADDSTRING,0,(LPARAM)buffer);
876 - SendDlgItemMessage(hWnd,IDC_TEXTUREFORMAT,CB_SETCURSEL,cfg->TextureFormat,0);
 956+ SendDlgItemMessage(hTabs[3],IDC_TEXTUREFORMAT,CB_ADDSTRING,0,(LPARAM)buffer);
 957+ SendDlgItemMessage(hTabs[3],IDC_TEXTUREFORMAT,CB_SETCURSEL,cfg->TextureFormat,0);
877958 // Texture upload
878959 _tcscpy(buffer,_T("Automatic"));
879 - SendDlgItemMessage(hWnd,IDC_TEXUPLOAD,CB_ADDSTRING,0,(LPARAM)buffer);
880 - SendDlgItemMessage(hWnd,IDC_TEXUPLOAD,CB_SETCURSEL,cfg->TexUpload,0);
 960+ SendDlgItemMessage(hTabs[3],IDC_TEXUPLOAD,CB_ADDSTRING,0,(LPARAM)buffer);
 961+ SendDlgItemMessage(hTabs[3],IDC_TEXUPLOAD,CB_SETCURSEL,cfg->TexUpload,0);
881962 // DPI
882963 _tcscpy(buffer, _T("Disabled"));
883 - SendDlgItemMessage(hWnd,IDC_DPISCALE,CB_ADDSTRING,0,(LPARAM)buffer);
 964+ SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,0,(LPARAM)buffer);
884965 _tcscpy(buffer, _T("Enabled"));
885 - SendDlgItemMessage(hWnd,IDC_DPISCALE,CB_ADDSTRING,1,(LPARAM)buffer);
 966+ SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,1,(LPARAM)buffer);
886967 _tcscpy(buffer, _T("Windows AppCompat"));
887 - SendDlgItemMessage(hWnd,IDC_DPISCALE,CB_ADDSTRING,2,(LPARAM)buffer);
888 - SendDlgItemMessage(hWnd,IDC_DPISCALE,CB_SETCURSEL,cfg->DPIScale,0);*/
 968+ SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_ADDSTRING,2,(LPARAM)buffer);
 969+ SendDlgItemMessage(hTabs[0],IDC_DPISCALE,CB_SETCURSEL,cfg->DPIScale,0);
889970 // Add installed programs
890971 current_app = 1;
891972 appcount = 1;
@@ -1036,8 +1117,9 @@
10371118 switch(wParam)
10381119 {
10391120 case IDC_APPS:
1040 - ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = GetSystemMetrics(SM_CYSMICON)+1;
 1121+ ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = GetSystemMetrics(SM_CYSMICON) + 1;
10411122 ((LPMEASUREITEMSTRUCT)lParam)->itemWidth = GetSystemMetrics(SM_CXSMICON)+1;
 1123+ break;
10421124 default:
10431125 break;
10441126 }
@@ -1057,7 +1139,8 @@
10581140 }
10591141 break;
10601142 case WM_DRAWITEM:
1061 - switch(wParam)
 1143+ drawitem = (DRAWITEMSTRUCT*)lParam;
 1144+ switch (wParam)
10621145 {
10631146 case IDC_APPS:
10641147 OldTextColor = GetTextColor(drawitem->hDC);
@@ -1467,7 +1550,6 @@
14681551
14691552 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
14701553 {
1471 - WNDCLASSEX wc;
14721554 INITCOMMONCONTROLSEX icc;
14731555 HMODULE comctl32;
14741556 BOOL(WINAPI *iccex)(LPINITCOMMONCONTROLSEX lpInitCtrls);
@@ -1488,12 +1570,6 @@
14891571 iccex = (BOOL (WINAPI *)(LPINITCOMMONCONTROLSEX))GetProcAddress(comctl32,"InitCommonControlsEx");
14901572 if(iccex) iccex(&icc);
14911573 else InitCommonControls();
1492 - ZeroMemory(&wc, sizeof(WNDCLASSEX));
1493 - wc.cbSize = sizeof(WNDCLASSEX);
1494 - wc.lpfnWndProc = CheckedComboProc;
1495 - wc.hInstance = hInstance;
1496 - wc.lpszClassName = _T("CheckedComboBox");
1497 - RegisterClassEx(&wc);
14981574 hinstance = hInstance;
14991575 GetModuleFileName(NULL,hlppath,MAX_PATH);
15001576 GetDirFromPath(hlppath);
Index: dxglcfg2/dxglcfg2.rc
@@ -36,7 +36,7 @@
3737 {
3838 COMBOBOX IDC_VSYNC, 114, 92, 102, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_LEFT
3939 LTEXT "Vertical sync", IDC_STATIC, 114, 82, 41, 8, SS_LEFT, WS_EX_LEFT
40 - COMBOBOX IDC_EXTRAMODES, 114, 42, 102, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_LEFT
 40+ COMBOBOX IDC_EXTRAMODES, 114, 42, 102, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_OWNERDRAWFIXED, WS_EX_LEFT
4141 LTEXT "Additional display modes", 0, 114, 32, 78, 8, SS_LEFT, WS_EX_LEFT
4242 COMBOBOX IDC_COLORDEPTH, 114, 17, 102, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_LEFT
4343 LTEXT "Add color depths", IDC_STATIC, 114, 7, 54, 8, SS_LEFT, WS_EX_LEFT