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