Rev 241 | Rev 333 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
194 | terminx | 1 | #ifndef RENDERTYPEWIN |
2 | #error Only for Windows |
||
3 | #endif |
||
4 | |||
5 | #include "duke3d.h" |
||
219 | terminx | 6 | #include "sounds.h" |
194 | terminx | 7 | |
8 | #include "build.h" |
||
9 | #include "winlayer.h" |
||
10 | #include "compat.h" |
||
11 | |||
241 | terminx | 12 | #include "grpscan.h" |
214 | terminx | 13 | |
194 | terminx | 14 | #define WIN32_LEAN_AND_MEAN |
15 | #include <windows.h> |
||
16 | #include <windowsx.h> |
||
17 | #define _WIN32_IE 0x0300 |
||
18 | #include <commctrl.h> |
||
19 | #include <stdio.h> |
||
20 | |||
21 | #include "startwin.game.h" |
||
22 | |||
23 | #define TAB_CONFIG 0 |
||
214 | terminx | 24 | #define TAB_GAME 1 |
25 | #define TAB_MESSAGES 2 |
||
194 | terminx | 26 | |
219 | terminx | 27 | static struct audioenumdrv *wavedevs = NULL; |
28 | |||
194 | terminx | 29 | static struct { |
222 | terminx | 30 | int fullscreen; |
31 | int xdim, ydim, bpp; |
||
32 | int forcesetup; |
||
33 | int usemouse, usejoy; |
||
34 | char selectedgrp[BMAX_PATH+1]; |
||
241 | terminx | 35 | int game; |
194 | terminx | 36 | } settings; |
37 | |||
38 | static HWND startupdlg = NULL; |
||
214 | terminx | 39 | static HWND pages[3] = { NULL, NULL, NULL }; |
197 | terminx | 40 | static int done = -1, mode = TAB_CONFIG; |
194 | terminx | 41 | |
219 | terminx | 42 | #define POPULATE_VIDEO 1 |
43 | #define POPULATE_CONFIG 2 |
||
44 | #define POPULATE_GAME 4 |
||
45 | |||
214 | terminx | 46 | static void PopulateForm(int pgs) |
194 | terminx | 47 | { |
222 | terminx | 48 | HWND hwnd; |
49 | char buf[256]; |
||
50 | int i,j; |
||
219 | terminx | 51 | |
222 | terminx | 52 | if (pgs & POPULATE_VIDEO) { |
53 | int mode; |
||
194 | terminx | 54 | |
222 | terminx | 55 | hwnd = GetDlgItem(pages[TAB_CONFIG], IDCVMODE); |
194 | terminx | 56 | |
222 | terminx | 57 | mode = checkvideomode(&settings.xdim, &settings.ydim, settings.bpp, settings.fullscreen, 1); |
58 | if (mode < 0) { |
||
59 | int cd[] = { 32, 24, 16, 15, 8, 0 }; |
||
60 | for (i=0; cd[i]; ) { if (cd[i] >= settings.bpp) i++; else break; } |
||
61 | for ( ; cd[i]; i++) { |
||
62 | mode = checkvideomode(&settings.xdim, &settings.ydim, cd[i], settings.fullscreen, 1); |
||
63 | if (mode < 0) continue; |
||
64 | settings.bpp = cd[i]; |
||
65 | break; |
||
66 | } |
||
67 | } |
||
214 | terminx | 68 | |
222 | terminx | 69 | Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), (settings.fullscreen ? BST_CHECKED : BST_UNCHECKED)); |
70 | ComboBox_ResetContent(hwnd); |
||
71 | for (i=0; i<validmodecnt; i++) { |
||
72 | if (validmode[i].fs != settings.fullscreen) continue; |
||
214 | terminx | 73 | |
222 | terminx | 74 | // all modes get added to the 3D mode list |
75 | Bsprintf(buf, "%ld x %ld %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp); |
||
76 | j = ComboBox_AddString(hwnd, buf); |
||
77 | ComboBox_SetItemData(hwnd, j, i); |
||
78 | if (i == mode) ComboBox_SetCurSel(hwnd, j); |
||
79 | } |
||
80 | } |
||
214 | terminx | 81 | |
222 | terminx | 82 | if (pgs & POPULATE_CONFIG) { |
83 | struct audioenumdev *d; |
||
84 | char *n; |
||
219 | terminx | 85 | |
222 | terminx | 86 | hwnd = GetDlgItem(pages[TAB_CONFIG], IDCSOUNDDRV); |
87 | ComboBox_ResetContent(hwnd); |
||
88 | if (wavedevs) { |
||
89 | d = wavedevs->devs; |
||
90 | for (i=0; wavedevs->drvs[i]; i++) { |
||
91 | strcpy(buf, wavedevs->drvs[i]); |
||
92 | if (d->devs) { |
||
93 | strcat(buf, ":"); |
||
94 | n = buf + strlen(buf); |
||
95 | for (j=0; d->devs[j]; j++) { |
||
96 | strcpy(n, d->devs[j]); |
||
97 | ComboBox_AddString(hwnd, buf); |
||
98 | } |
||
99 | } else { |
||
100 | ComboBox_AddString(hwnd, buf); |
||
101 | } |
||
102 | d = d->next; |
||
103 | } |
||
104 | } |
||
219 | terminx | 105 | |
222 | terminx | 106 | Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED)); |
219 | terminx | 107 | |
222 | terminx | 108 | Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), (settings.usemouse ? BST_CHECKED : BST_UNCHECKED)); |
109 | Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), (settings.usejoy ? BST_CHECKED : BST_UNCHECKED)); |
||
110 | } |
||
194 | terminx | 111 | |
222 | terminx | 112 | if (pgs & POPULATE_GAME) { |
113 | struct grpfile *fg; |
||
114 | int i, j; |
||
115 | char buf[128+BMAX_PATH]; |
||
194 | terminx | 116 | |
222 | terminx | 117 | hwnd = GetDlgItem(pages[TAB_GAME], IDGDATA); |
194 | terminx | 118 | |
222 | terminx | 119 | for (fg = foundgrps; fg; fg=fg->next) { |
241 | terminx | 120 | for (i = 0; i<numgrpfiles; i++) if (fg->crcval == grpfiles[i].crcval) break; |
222 | terminx | 121 | if (i == numgrpfiles) continue; // unrecognised grp file |
122 | Bsprintf(buf, "%s\t%s", grpfiles[i].name, fg->name); |
||
123 | j = ListBox_AddString(hwnd, buf); |
||
124 | ListBox_SetItemData(hwnd, j, (LPARAM)fg); |
||
125 | if (!Bstrcasecmp(fg->name, settings.selectedgrp)) ListBox_SetCurSel(hwnd, j); |
||
126 | } |
||
127 | } |
||
194 | terminx | 128 | } |
129 | |||
130 | static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
131 | { |
||
222 | terminx | 132 | switch (uMsg) { |
133 | case WM_COMMAND: |
||
134 | switch (LOWORD(wParam)) { |
||
135 | case IDCFULLSCREEN: |
||
136 | settings.fullscreen = !settings.fullscreen; |
||
137 | PopulateForm(POPULATE_VIDEO); |
||
138 | return TRUE; |
||
139 | case IDCVMODE: |
||
140 | if (HIWORD(wParam) == CBN_SELCHANGE) { |
||
141 | int i; |
||
142 | i = ComboBox_GetCurSel((HWND)lParam); |
||
143 | if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); |
||
144 | if (i != CB_ERR) { |
||
145 | settings.xdim = validmode[i].xdim; |
||
146 | settings.ydim = validmode[i].ydim; |
||
147 | settings.bpp = validmode[i].bpp; |
||
148 | } |
||
149 | } |
||
150 | return TRUE; |
||
151 | case IDCALWAYSSHOW: |
||
152 | settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED; |
||
153 | return TRUE; |
||
154 | case IDCINPUTMOUSE: |
||
155 | settings.usemouse = IsDlgButtonChecked(hwndDlg, IDCINPUTMOUSE) == BST_CHECKED; |
||
156 | return TRUE; |
||
157 | case IDCINPUTJOY: |
||
158 | settings.usejoy = IsDlgButtonChecked(hwndDlg, IDCINPUTJOY) == BST_CHECKED; |
||
159 | return TRUE; |
||
331 | terminx | 160 | default: |
161 | break; |
||
222 | terminx | 162 | } |
163 | break; |
||
331 | terminx | 164 | default: |
165 | break; |
||
222 | terminx | 166 | } |
167 | return FALSE; |
||
194 | terminx | 168 | } |
169 | |||
214 | terminx | 170 | static INT_PTR CALLBACK GamePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
171 | { |
||
222 | terminx | 172 | switch (uMsg) { |
173 | case WM_COMMAND: |
||
174 | switch (LOWORD(wParam)) { |
||
175 | case IDGDATA: { |
||
331 | terminx | 176 | int i; |
177 | if (HIWORD(wParam) != LBN_SELCHANGE) break; |
||
178 | i = ListBox_GetCurSel((HWND)lParam); |
||
179 | if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i); |
||
180 | if (i != CB_ERR) { |
||
181 | strcpy(settings.selectedgrp, ((struct grpfile*)i)->name); |
||
182 | settings.game = ((struct grpfile*)i)->game; |
||
222 | terminx | 183 | } |
331 | terminx | 184 | return TRUE; |
222 | terminx | 185 | } |
331 | terminx | 186 | default: |
187 | break; |
||
188 | } |
||
222 | terminx | 189 | break; |
331 | terminx | 190 | default: |
191 | break; |
||
222 | terminx | 192 | } |
193 | return FALSE; |
||
214 | terminx | 194 | } |
194 | terminx | 195 | |
196 | |||
214 | terminx | 197 | |
194 | terminx | 198 | static void SetPage(int n) |
199 | { |
||
222 | terminx | 200 | HWND tab; |
201 | int cur; |
||
202 | tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); |
||
203 | cur = (int)SendMessage(tab, TCM_GETCURSEL,0,0); |
||
204 | ShowWindow(pages[cur],SW_HIDE); |
||
205 | SendMessage(tab, TCM_SETCURSEL, n, 0); |
||
206 | ShowWindow(pages[n],SW_SHOW); |
||
207 | mode = n; |
||
196 | terminx | 208 | |
222 | terminx | 209 | SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL)); |
194 | terminx | 210 | } |
211 | |||
212 | static void EnableConfig(int n) |
||
213 | { |
||
222 | terminx | 214 | //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n); |
215 | EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n); |
||
216 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n); |
||
217 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n); |
||
218 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), n); |
||
219 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), n); |
||
214 | terminx | 220 | |
222 | terminx | 221 | EnableWindow(GetDlgItem(pages[TAB_GAME], IDGDATA), n); |
194 | terminx | 222 | } |
223 | |||
224 | static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
225 | { |
||
222 | terminx | 226 | static HBITMAP hbmp = NULL; |
227 | HDC hdc; |
||
194 | terminx | 228 | |
222 | terminx | 229 | switch (uMsg) { |
230 | case WM_INITDIALOG: { |
||
331 | terminx | 231 | HWND hwnd; |
232 | RECT r, rdlg, chrome, rtab, rcancel, rstart; |
||
233 | int xoffset = 0, yoffset = 0; |
||
194 | terminx | 234 | |
331 | terminx | 235 | // Fetch the positions (in screen coordinates) of all the windows we need to tweak |
236 | ZeroMemory(&chrome, sizeof(chrome)); |
||
237 | AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE); |
||
238 | GetWindowRect(hwndDlg, &rdlg); |
||
239 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab); |
||
240 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel); |
||
241 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart); |
||
194 | terminx | 242 | |
331 | terminx | 243 | // Knock off the non-client area of the main dialogue to give just the client area |
244 | rdlg.left -= chrome.left; rdlg.top -= chrome.top; |
||
245 | rdlg.right -= chrome.right; rdlg.bottom -= chrome.bottom; |
||
194 | terminx | 246 | |
331 | terminx | 247 | // Translate them to client-relative coordinates wrt the main dialogue window |
248 | rtab.right -= rtab.left - 1; rtab.bottom -= rtab.top - 1; |
||
249 | rtab.left -= rdlg.left; rtab.top -= rdlg.top; |
||
194 | terminx | 250 | |
331 | terminx | 251 | rcancel.right -= rcancel.left - 1; rcancel.bottom -= rcancel.top - 1; |
252 | rcancel.left -= rdlg.left; rcancel.top -= rdlg.top; |
||
194 | terminx | 253 | |
331 | terminx | 254 | rstart.right -= rstart.left - 1; rstart.bottom -= rstart.top - 1; |
255 | rstart.left -= rdlg.left; rstart.top -= rdlg.top; |
||
194 | terminx | 256 | |
331 | terminx | 257 | // And then convert the main dialogue coordinates to just width/length |
258 | rdlg.right -= rdlg.left - 1; rdlg.bottom -= rdlg.top - 1; |
||
259 | rdlg.left = 0; rdlg.top = 0; |
||
194 | terminx | 260 | |
331 | terminx | 261 | // Load the bitmap into the bitmap control and fetch its dimensions |
262 | hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP)); |
||
263 | hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP); |
||
264 | SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp); |
||
265 | GetClientRect(hwnd, &r); |
||
266 | xoffset = r.right; |
||
267 | yoffset = r.bottom - rdlg.bottom; |
||
194 | terminx | 268 | |
331 | terminx | 269 | // Shift and resize the controls that require it |
270 | rtab.left += xoffset; rtab.bottom += yoffset; |
||
271 | rcancel.left += xoffset; rcancel.top += yoffset; |
||
272 | rstart.left += xoffset; rstart.top += yoffset; |
||
273 | rdlg.right += xoffset; |
||
274 | rdlg.bottom += yoffset; |
||
194 | terminx | 275 | |
331 | terminx | 276 | // Move the controls to their new positions |
277 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE); |
||
278 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE); |
||
279 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE); |
||
194 | terminx | 280 | |
331 | terminx | 281 | // Move the main dialogue to the centre of the screen |
282 | hdc = GetDC(NULL); |
||
283 | rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2; |
||
284 | rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2; |
||
285 | ReleaseDC(NULL, hdc); |
||
286 | MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left, |
||
287 | rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE); |
||
194 | terminx | 288 | |
331 | terminx | 289 | // Add tabs to the tab control |
290 | { |
||
291 | TCITEM tab; |
||
194 | terminx | 292 | |
331 | terminx | 293 | hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL); |
194 | terminx | 294 | |
331 | terminx | 295 | ZeroMemory(&tab, sizeof(tab)); |
296 | tab.mask = TCIF_TEXT; |
||
297 | tab.pszText = TEXT("Configuration"); |
||
298 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab); |
||
299 | tab.mask = TCIF_TEXT; |
||
300 | tab.pszText = TEXT("Game"); |
||
301 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_GAME, (LPARAM)&tab); |
||
302 | tab.mask = TCIF_TEXT; |
||
303 | tab.pszText = TEXT("Messages"); |
||
304 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab); |
||
194 | terminx | 305 | |
331 | terminx | 306 | // Work out the position and size of the area inside the tab control for the pages |
307 | ZeroMemory(&r, sizeof(r)); |
||
308 | GetClientRect(hwnd, &r); |
||
309 | SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r); |
||
310 | r.right -= r.left-1; |
||
311 | r.bottom -= r.top-1; |
||
312 | r.top += rtab.top; |
||
313 | r.left += rtab.left; |
||
194 | terminx | 314 | |
331 | terminx | 315 | // Create the pages and position them in the tab control, but hide them |
316 | pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(), |
||
317 | MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc); |
||
318 | pages[TAB_GAME] = CreateDialog((HINSTANCE)win_gethinstance(), |
||
319 | MAKEINTRESOURCE(WIN_STARTWINPAGE_GAME), hwndDlg, GamePageProc); |
||
320 | pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES); |
||
321 | SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
322 | SetWindowPos(pages[TAB_GAME], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
323 | SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
194 | terminx | 324 | |
331 | terminx | 325 | // Tell the editfield acting as the console to exclude the width of the scrollbar |
326 | GetClientRect(pages[TAB_MESSAGES],&r); |
||
327 | r.right -= GetSystemMetrics(SM_CXVSCROLL)+4; |
||
328 | r.left = r.top = 0; |
||
329 | SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r); |
||
194 | terminx | 330 | |
331 | terminx | 331 | // Set a tab stop in the game data listbox |
332 | { |
||
333 | DWORD tabs[1] = { 150 }; |
||
334 | ListBox_SetTabStops(GetDlgItem(pages[TAB_GAME], IDGDATA), 1, tabs); |
||
335 | } |
||
214 | terminx | 336 | |
331 | terminx | 337 | SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START)); |
338 | SetWindowText(hwndDlg, apptitle); |
||
222 | terminx | 339 | } |
331 | terminx | 340 | return FALSE; |
341 | } |
||
194 | terminx | 342 | |
222 | terminx | 343 | case WM_NOTIFY: { |
331 | terminx | 344 | LPNMHDR nmhdr = (LPNMHDR)lParam; |
345 | int cur; |
||
346 | if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break; |
||
347 | cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); |
||
348 | switch (nmhdr->code) { |
||
349 | case TCN_SELCHANGING: { |
||
350 | if (cur < 0 || !pages[cur]) break; |
||
351 | ShowWindow(pages[cur],SW_HIDE); |
||
352 | return TRUE; |
||
222 | terminx | 353 | } |
331 | terminx | 354 | case TCN_SELCHANGE: { |
355 | if (cur < 0 || !pages[cur]) break; |
||
356 | ShowWindow(pages[cur],SW_SHOW); |
||
357 | return TRUE; |
||
358 | } |
||
359 | } |
||
360 | break; |
||
361 | } |
||
194 | terminx | 362 | |
222 | terminx | 363 | case WM_CLOSE: |
364 | if (mode == TAB_CONFIG) done = 0; |
||
365 | else quitevent++; |
||
366 | return TRUE; |
||
194 | terminx | 367 | |
222 | terminx | 368 | case WM_DESTROY: |
369 | if (hbmp) { |
||
370 | DeleteObject(hbmp); |
||
371 | hbmp = NULL; |
||
372 | } |
||
194 | terminx | 373 | |
222 | terminx | 374 | if (pages[TAB_GAME]) { |
375 | DestroyWindow(pages[TAB_GAME]); |
||
376 | pages[TAB_GAME] = NULL; |
||
377 | } |
||
214 | terminx | 378 | |
222 | terminx | 379 | if (pages[TAB_CONFIG]) { |
380 | DestroyWindow(pages[TAB_CONFIG]); |
||
381 | pages[TAB_CONFIG] = NULL; |
||
382 | } |
||
194 | terminx | 383 | |
222 | terminx | 384 | startupdlg = NULL; |
385 | return TRUE; |
||
194 | terminx | 386 | |
222 | terminx | 387 | case WM_COMMAND: |
388 | switch (LOWORD(wParam)) { |
||
389 | case WIN_STARTWIN_CANCEL: |
||
390 | if (mode == TAB_CONFIG) done = 0; |
||
391 | else quitevent++; |
||
392 | return TRUE; |
||
331 | terminx | 393 | case WIN_STARTWIN_START: |
394 | done = 1; return TRUE; |
||
222 | terminx | 395 | } |
396 | return FALSE; |
||
194 | terminx | 397 | |
222 | terminx | 398 | case WM_CTLCOLORSTATIC: |
399 | if ((HWND)lParam == pages[TAB_MESSAGES]) |
||
400 | return (BOOL)GetSysColorBrush(COLOR_WINDOW); |
||
401 | break; |
||
402 | |||
331 | terminx | 403 | default: |
404 | break; |
||
222 | terminx | 405 | } |
406 | |||
407 | return FALSE; |
||
194 | terminx | 408 | } |
409 | |||
410 | |||
411 | int startwin_open(void) |
||
412 | { |
||
222 | terminx | 413 | INITCOMMONCONTROLSEX icc; |
414 | if (startupdlg) return 1; |
||
415 | icc.dwSize = sizeof(icc); |
||
416 | icc.dwICC = ICC_TAB_CLASSES; |
||
417 | InitCommonControlsEx(&icc); |
||
418 | startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); |
||
419 | if (startupdlg) { |
||
420 | SetPage(TAB_MESSAGES); |
||
421 | EnableConfig(0); |
||
422 | return 0; |
||
423 | } |
||
424 | return -1; |
||
194 | terminx | 425 | } |
426 | |||
427 | int startwin_close(void) |
||
428 | { |
||
222 | terminx | 429 | if (!startupdlg) return 1; |
430 | DestroyWindow(startupdlg); |
||
431 | startupdlg = NULL; |
||
432 | return 0; |
||
194 | terminx | 433 | } |
434 | |||
435 | int startwin_puts(const char *buf) |
||
436 | { |
||
222 | terminx | 437 | const char *p = NULL, *q = NULL; |
438 | char workbuf[1024]; |
||
439 | static int newline = 0; |
||
440 | int curlen, linesbefore, linesafter; |
||
441 | HWND edctl; |
||
442 | int vis; |
||
194 | terminx | 443 | |
222 | terminx | 444 | if (!startupdlg) return 1; |
194 | terminx | 445 | |
222 | terminx | 446 | edctl = pages[TAB_MESSAGES]; |
447 | if (!edctl) return -1; |
||
194 | terminx | 448 | |
222 | terminx | 449 | vis = ((int)SendMessage(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL), TCM_GETCURSEL,0,0) == TAB_MESSAGES); |
450 | |||
451 | if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); |
||
452 | curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); |
||
453 | SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); |
||
454 | linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); |
||
455 | p = buf; |
||
456 | while (*p) { |
||
457 | if (newline) { |
||
458 | SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); |
||
459 | newline = 0; |
||
460 | } |
||
461 | q = p; |
||
462 | while (*q && *q != '\n') q++; |
||
463 | memcpy(workbuf, p, q-p); |
||
464 | if (*q == '\n') { |
||
465 | if (!q[1]) { |
||
466 | newline = 1; |
||
467 | workbuf[q-p] = 0; |
||
468 | } else { |
||
469 | workbuf[q-p] = '\r'; |
||
470 | workbuf[q-p+1] = '\n'; |
||
471 | workbuf[q-p+2] = 0; |
||
472 | } |
||
473 | p = q+1; |
||
474 | } else { |
||
475 | workbuf[q-p] = 0; |
||
476 | p = q; |
||
477 | } |
||
478 | SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); |
||
479 | } |
||
480 | linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); |
||
481 | SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); |
||
482 | if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); |
||
483 | return 0; |
||
194 | terminx | 484 | } |
485 | |||
486 | int startwin_settitle(const char *str) |
||
487 | { |
||
222 | terminx | 488 | if (!startupdlg) return 1; |
489 | SetWindowText(startupdlg, str); |
||
490 | return 0; |
||
194 | terminx | 491 | } |
492 | |||
493 | int startwin_idle(void *v) |
||
494 | { |
||
222 | terminx | 495 | if (!startupdlg || !IsWindow(startupdlg)) return 0; |
496 | if (IsDialogMessage(startupdlg, (MSG*)v)) return 1; |
||
497 | return 0; |
||
194 | terminx | 498 | } |
499 | |||
214 | terminx | 500 | extern char *duke3dgrp; |
501 | |||
194 | terminx | 502 | int startwin_run(void) |
503 | { |
||
222 | terminx | 504 | MSG msg; |
505 | if (!startupdlg) return 1; |
||
194 | terminx | 506 | |
222 | terminx | 507 | done = -1; |
194 | terminx | 508 | |
219 | terminx | 509 | #ifdef JFAUD |
222 | terminx | 510 | EnumAudioDevs(&wavedevs, NULL, NULL); |
219 | terminx | 511 | #endif |
222 | terminx | 512 | SetPage(TAB_CONFIG); |
513 | EnableConfig(1); |
||
194 | terminx | 514 | |
222 | terminx | 515 | settings.fullscreen = ScreenMode; |
516 | settings.xdim = ScreenWidth; |
||
517 | settings.ydim = ScreenHeight; |
||
518 | settings.bpp = ScreenBPP; |
||
519 | settings.forcesetup = ForceSetup; |
||
520 | settings.usemouse = UseMouse; |
||
521 | settings.usejoy = UseJoystick; |
||
241 | terminx | 522 | settings.game = gametype; |
222 | terminx | 523 | strncpy(settings.selectedgrp, duke3dgrp, BMAX_PATH); |
524 | PopulateForm(-1); |
||
194 | terminx | 525 | |
222 | terminx | 526 | while (done < 0) { |
527 | switch (GetMessage(&msg, NULL, 0,0)) { |
||
331 | terminx | 528 | case 0: |
529 | done = 1; break; |
||
530 | case -1: |
||
531 | return -1; |
||
222 | terminx | 532 | default: |
533 | if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; |
||
534 | TranslateMessage(&msg); |
||
535 | DispatchMessage(&msg); |
||
536 | break; |
||
537 | } |
||
538 | } |
||
194 | terminx | 539 | |
222 | terminx | 540 | SetPage(TAB_MESSAGES); |
541 | EnableConfig(0); |
||
542 | if (done) { |
||
543 | ScreenMode = settings.fullscreen; |
||
544 | ScreenWidth = settings.xdim; |
||
545 | ScreenHeight = settings.ydim; |
||
546 | ScreenBPP = settings.bpp; |
||
547 | ForceSetup = settings.forcesetup; |
||
548 | UseMouse = settings.usemouse; |
||
549 | UseJoystick = settings.usejoy; |
||
550 | duke3dgrp = settings.selectedgrp; |
||
241 | terminx | 551 | gametype = settings.game; |
222 | terminx | 552 | } |
194 | terminx | 553 | |
222 | terminx | 554 | if (wavedevs) { |
555 | struct audioenumdev *d, *e; |
||
556 | free(wavedevs->drvs); |
||
557 | for (e=wavedevs->devs; e; e=d) { |
||
558 | d = e->next; |
||
559 | if (e->devs) free(e->devs); |
||
560 | free(e); |
||
561 | } |
||
562 | free(wavedevs); |
||
563 | } |
||
219 | terminx | 564 | |
222 | terminx | 565 | return done; |
194 | terminx | 566 | } |
567 |