xref: /reactos/dll/cpl/wined3dcfg/general.c (revision 1734f297)
1 #include "wined3dcfg.h"
2 
3 #include <winreg.h>
4 
5 WINED3D_SETTINGS gwd3dsShaderLvl[] =
6 {
7     {VALUE_DEFAULT, REG_NONE, 0},
8     {L"1.4", REG_DWORD, 1},
9     {L"2", REG_DWORD, 2},
10     {L"3", REG_DWORD, 3},
11 };
12 
13 WINED3D_SETTINGS gwd3dsDisable[] =
14 {
15     {VALUE_DEFAULT, REG_NONE, 0},
16     {VALUE_DISABLED, REG_SZ, 0}
17 };
18 
19 WINED3D_SETTINGS gwd3dsEnable[] =
20 {
21     {VALUE_DEFAULT, REG_NONE, 0},
22     {VALUE_ENABLED, REG_SZ, 0}
23 };
24 
25 WINED3D_SETTINGS gwd3dsOffscreen[] =
26 {
27     {VALUE_DEFAULT, REG_NONE, 0},
28     {VALUE_BACKBUFFER, REG_SZ, 0},
29     {VALUE_FBO, REG_SZ, 0}
30 };
31 
32 WINED3D_SETTINGS gwd3dsVidMem[] =
33 {
34     {VALUE_DEFAULT, REG_NONE, 0},
35     {L"8 MB", REG_SZ, 8},
36     {L"16 MB", REG_SZ, 16},
37     {L"32 MB", REG_SZ, 32},
38     {L"64 MB", REG_SZ, 64},
39     {L"128 MB", REG_SZ, 128},
40     {L"256 MB", REG_SZ, 256},
41     {L"512 MB", REG_SZ, 512},
42 };
43 
44 WINED3D_SETTINGS gwd3dsDdRender[] =
45 {
46     {VALUE_DEFAULT, REG_NONE, 0},
47     {VALUE_GDI, REG_SZ, 0}
48 };
49 
50 
51 void InitControl(HWND hWndDlg, HKEY hKey, PWCHAR szKey, PWINED3D_SETTINGS pSettings, INT iControlId, INT iCount)
52 {
53     WCHAR szBuffer[MAX_KEY_LENGTH];
54     DWORD dwSize = sizeof(szBuffer);
55     DWORD dwType = 0;
56     INT iCurrent;
57     INT iActive = 0;
58 
59     RegQueryValueExW(hKey, szKey, NULL, &dwType, (LPBYTE)szBuffer, &dwSize);
60 
61     for(iCurrent = 0; iCurrent < iCount; iCurrent++)
62     {
63         SendDlgItemMessageW(hWndDlg, iControlId, CB_ADDSTRING, 0, (LPARAM)pSettings[iCurrent].szValue);
64 
65         if(dwSize && ((dwType == REG_DWORD && *szBuffer == pSettings[iCurrent].iValue) ||
66            (dwType == REG_SZ && !wcscmp(szBuffer, pSettings[iCurrent].szValue))))
67         {
68             iActive = iCurrent;
69         }
70     }
71 
72     SendDlgItemMessageW(hWndDlg, iControlId, CB_SETCURSEL, iActive, 0);
73 
74 }
75 
76 static VOID InitSettings(HWND hWndDlg)
77 {
78     HKEY hKey;
79 
80     if (RegCreateKeyExW(HKEY_CURRENT_USER, KEY_WINE, 0, NULL, 0, MAXIMUM_ALLOWED, NULL, &hKey, NULL) != ERROR_SUCCESS)
81         return;
82 
83     INIT_CONTROL(GLSL, gwd3dsDisable);
84     INIT_CONTROL(OFFSCREEN, gwd3dsOffscreen);
85     INIT_CONTROL(VIDMEMSIZE, gwd3dsVidMem);
86     INIT_CONTROL(MULTISAMPLING, gwd3dsDisable);
87     INIT_CONTROL(STRICTDRAWORDERING, gwd3dsEnable);
88     INIT_CONTROL(ALWAYSOFFSCREEN, gwd3dsEnable);
89     INIT_CONTROL(DDRENDERER, gwd3dsDdRender);
90     INIT_CONTROL(PSLEVEL, gwd3dsShaderLvl);
91     INIT_CONTROL(VSLEVEL, gwd3dsShaderLvl);
92     INIT_CONTROL(GSLEVEL, gwd3dsShaderLvl);
93 
94     RegCloseKey(hKey);
95 }
96 
97 
98 static VOID SaveSetting(HWND hWnd, HKEY hKey, PWCHAR szKey, PWINED3D_SETTINGS pCfg, INT iControlId, INT iCount)
99 {
100     INT iSel = 0;
101 
102     iSel = (INT)SendDlgItemMessageW(hWnd, iControlId, CB_GETCURSEL, 0, 0);
103 
104     if(iSel < 0 || iSel > iCount)
105         return;
106 
107     if(pCfg[iSel].iType == REG_NONE)
108     {
109         RegDeleteValueW(hKey, szKey);
110         return;
111     }
112 
113     if(pCfg[iSel].iType == REG_DWORD)
114     {
115         RegSetValueExW(hKey, szKey, 0, REG_DWORD, (LPBYTE)&pCfg[iSel].iValue, sizeof(pCfg[iSel].iValue));
116         return;
117     } else if (pCfg[iSel].iType == REG_SZ)
118     {
119         RegSetValueExW(hKey, szKey, 0, pCfg[iSel].iType, (LPBYTE)pCfg[iSel].szValue, (wcslen(pCfg[iSel].szValue) + 1) * sizeof(WCHAR));
120     }
121 }
122 
123 
124 static VOID WriteSettings(HWND hWndDlg)
125 {
126     HKEY hKey;
127 
128     if (RegOpenKeyExW(HKEY_CURRENT_USER, KEY_WINE, 0, KEY_WRITE, &hKey) != ERROR_SUCCESS)
129         return;
130 
131     SAVE_CONTROL(GLSL, gwd3dsDisable);
132     SAVE_CONTROL(OFFSCREEN, gwd3dsOffscreen);
133     SAVE_CONTROL(VIDMEMSIZE, gwd3dsVidMem);
134     SAVE_CONTROL(MULTISAMPLING, gwd3dsDisable);
135     SAVE_CONTROL(STRICTDRAWORDERING, gwd3dsEnable);
136     SAVE_CONTROL(ALWAYSOFFSCREEN, gwd3dsEnable);
137     SAVE_CONTROL(DDRENDERER, gwd3dsDdRender);
138     SAVE_CONTROL(PSLEVEL, gwd3dsShaderLvl);
139     SAVE_CONTROL(VSLEVEL, gwd3dsShaderLvl);
140     SAVE_CONTROL(GSLEVEL, gwd3dsShaderLvl);
141 
142     RegCloseKey(hKey);
143 }
144 
145 
146 INT_PTR CALLBACK GeneralPageProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
147 {
148     LPPSHNOTIFY lppsn;
149 
150     switch (uMsg)
151     {
152         case WM_INITDIALOG:
153             InitSettings(hWndDlg);
154             return TRUE;
155 
156         case WM_COMMAND:
157             if (LOWORD(wParam) > IDC_MIN && LOWORD(wParam) < IDC_MAX && HIWORD(wParam) == CBN_SELCHANGE)
158                 PropSheet_Changed(GetParent(hWndDlg), hWndDlg);
159             break;
160 
161         case WM_NOTIFY:
162             lppsn = (LPPSHNOTIFY)lParam;
163             if (lppsn->hdr.code == PSN_APPLY)
164             {
165                 WriteSettings(hWndDlg);
166                 return TRUE;
167             }
168             break;
169     }
170 
171     return FALSE;
172 }
173