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