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