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