Rev 3219 | Rev 3617 | 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 | |||
3219 | hendricks2 | 23 | #ifndef _WIN32 |
194 | terminx | 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 | |||
3219 | hendricks2 | 228 | j = 4; |
229 | |||
230 | #ifdef RENDERTYPEWIN |
||
1729 | terminx | 231 | if (di_disabled) j = 2; |
3219 | hendricks2 | 232 | #endif |
1729 | terminx | 233 | |
234 | for (i=0; i<j; i++) |
||
1327 | terminx | 235 | { |
1457 | terminx | 236 | (void)ComboBox_InsertString(hwnd, i, controlstrings[i]); |
237 | (void)ComboBox_SetItemData(hwnd, i, i); |
||
1327 | terminx | 238 | |
1457 | terminx | 239 | switch (i) |
1327 | terminx | 240 | { |
1457 | terminx | 241 | case INPUT_MOUSE: |
242 | if (settings.usemouse && !settings.usejoy)(void)ComboBox_SetCurSel(hwnd, i); |
||
243 | break; |
||
244 | case INPUT_JOYSTICK: |
||
245 | if (!settings.usemouse && settings.usejoy)(void)ComboBox_SetCurSel(hwnd, i); |
||
246 | break; |
||
247 | case INPUT_ALL: |
||
248 | if (settings.usemouse && settings.usejoy)(void)ComboBox_SetCurSel(hwnd, i); |
||
249 | break; |
||
1327 | terminx | 250 | } |
251 | } |
||
222 | terminx | 252 | } |
194 | terminx | 253 | |
335 | terminx | 254 | if (pgs & POPULATE_GAME) |
255 | { |
||
222 | terminx | 256 | struct grpfile *fg; |
1205 | terminx | 257 | int32_t i, j; |
1454 | terminx | 258 | char buf[1024]; |
194 | terminx | 259 | |
991 | terminx | 260 | hwnd = GetDlgItem(pages[TAB_CONFIG], IDCDATA); |
194 | terminx | 261 | |
335 | terminx | 262 | for (fg = foundgrps; fg; fg=fg->next) |
263 | { |
||
2543 | helixhorne | 264 | for (i = 0; i<NUMGRPFILES; i++) if (fg->crcval == grpfiles[i].crcval) break; |
265 | if (i == NUMGRPFILES) continue; // unrecognised grp file |
||
222 | terminx | 266 | Bsprintf(buf, "%s\t%s", grpfiles[i].name, fg->name); |
267 | j = ListBox_AddString(hwnd, buf); |
||
649 | terminx | 268 | (void)ListBox_SetItemData(hwnd, j, (LPARAM)fg); |
723 | terminx | 269 | if (!Bstrcasecmp(fg->name, settings.selectedgrp))(void)ListBox_SetCurSel(hwnd, j); |
222 | terminx | 270 | } |
271 | } |
||
194 | terminx | 272 | } |
273 | |||
274 | static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
275 | { |
||
335 | terminx | 276 | switch (uMsg) |
277 | { |
||
337 | terminx | 278 | case WM_COMMAND: |
279 | switch (LOWORD(wParam)) |
||
280 | { |
||
281 | case IDCFULLSCREEN: |
||
1325 | terminx | 282 | if (settings.flags & 1) settings.flags &= ~1; |
283 | else settings.flags |= 1; |
||
337 | terminx | 284 | PopulateForm(POPULATE_VIDEO); |
285 | return TRUE; |
||
1325 | terminx | 286 | case IDCPOLYMER: |
287 | if (settings.flags & 2) settings.flags &= ~2; |
||
288 | else settings.flags |= 2; |
||
289 | if (settings.bpp == 8) settings.bpp = 32; |
||
290 | PopulateForm(POPULATE_VIDEO); |
||
291 | return TRUE; |
||
337 | terminx | 292 | case IDCVMODE: |
293 | if (HIWORD(wParam) == CBN_SELCHANGE) |
||
335 | terminx | 294 | { |
1205 | terminx | 295 | int32_t i; |
337 | terminx | 296 | i = ComboBox_GetCurSel((HWND)lParam); |
297 | if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); |
||
298 | if (i != CB_ERR) |
||
299 | { |
||
300 | settings.xdim = validmode[i].xdim; |
||
301 | settings.ydim = validmode[i].ydim; |
||
302 | settings.bpp = validmode[i].bpp; |
||
303 | } |
||
222 | terminx | 304 | } |
337 | terminx | 305 | return TRUE; |
306 | case IDCALWAYSSHOW: |
||
307 | settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED; |
||
308 | return TRUE; |
||
1325 | terminx | 309 | case IDCAUTOLOAD: |
1326 | terminx | 310 | if (IsDlgButtonChecked(hwndDlg, IDCAUTOLOAD) == BST_CHECKED) |
1325 | terminx | 311 | settings.flags &= ~4; |
312 | else settings.flags |= 4; |
||
313 | return TRUE; |
||
1327 | terminx | 314 | case IDCINPUT: |
315 | if (HIWORD(wParam) == CBN_SELCHANGE) |
||
316 | { |
||
317 | int32_t i; |
||
318 | i = ComboBox_GetCurSel((HWND)lParam); |
||
319 | if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); |
||
320 | if (i != CB_ERR) |
||
321 | { |
||
322 | switch (i) |
||
323 | { |
||
324 | case 0: |
||
325 | settings.usemouse = settings.usejoy = 0; |
||
326 | break; |
||
327 | case 1: |
||
328 | settings.usemouse = 1; |
||
329 | settings.usejoy = 0; |
||
330 | break; |
||
331 | case 2: |
||
332 | settings.usemouse = 0; |
||
333 | settings.usejoy = 1; |
||
334 | break; |
||
335 | case 3: |
||
336 | settings.usemouse = settings.usejoy = 1; |
||
337 | break; |
||
338 | } |
||
339 | } |
||
340 | } |
||
341 | return TRUE; |
||
342 | |||
991 | terminx | 343 | case IDCGAMEDIR: |
984 | terminx | 344 | if (HIWORD(wParam) == CBN_SELCHANGE) |
345 | { |
||
1205 | terminx | 346 | int32_t i,j; |
984 | terminx | 347 | CACHE1D_FIND_REC *dir = NULL; |
348 | i = ComboBox_GetCurSel((HWND)lParam); |
||
349 | if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i); |
||
350 | if (i != CB_ERR) |
||
351 | { |
||
1062 | terminx | 352 | if (i==0) |
353 | settings.gamedir = NULL; |
||
354 | else |
||
355 | { |
||
1229 | terminx | 356 | for (j=1,dir=finddirs; dir != NULL; dir=dir->next,j++) |
1062 | terminx | 357 | if (j == i) |
358 | { |
||
359 | settings.gamedir = dir->name; |
||
360 | break; |
||
361 | } |
||
362 | } |
||
984 | terminx | 363 | } |
364 | } |
||
365 | return TRUE; |
||
991 | terminx | 366 | case IDCDATA: |
367 | { |
||
3278 | hendricks2 | 368 | intptr_t i; |
991 | terminx | 369 | if (HIWORD(wParam) != LBN_SELCHANGE) break; |
370 | i = ListBox_GetCurSel((HWND)lParam); |
||
371 | if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i); |
||
372 | if (i != CB_ERR) |
||
373 | { |
||
1677 | terminx | 374 | strcpy(settings.selectedgrp, ((struct grpfile *)i)->name); |
375 | settings.game = ((struct grpfile *)i)->game; |
||
376 | settings.crcval = ((struct grpfile *)i)->crcval; |
||
991 | terminx | 377 | } |
378 | return TRUE; |
||
379 | } |
||
331 | terminx | 380 | default: |
381 | break; |
||
337 | terminx | 382 | } |
383 | break; |
||
384 | default: |
||
385 | break; |
||
222 | terminx | 386 | } |
387 | return FALSE; |
||
214 | terminx | 388 | } |
194 | terminx | 389 | |
390 | |||
1205 | terminx | 391 | static void SetPage(int32_t n) |
194 | terminx | 392 | { |
222 | terminx | 393 | HWND tab; |
1205 | terminx | 394 | int32_t cur; |
222 | terminx | 395 | tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); |
1205 | terminx | 396 | cur = (int32_t)SendMessage(tab, TCM_GETCURSEL,0,0); |
222 | terminx | 397 | ShowWindow(pages[cur],SW_HIDE); |
398 | SendMessage(tab, TCM_SETCURSEL, n, 0); |
||
399 | ShowWindow(pages[n],SW_SHOW); |
||
400 | mode = n; |
||
196 | terminx | 401 | |
222 | terminx | 402 | SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL)); |
194 | terminx | 403 | } |
404 | |||
1205 | terminx | 405 | static void EnableConfig(int32_t n) |
194 | terminx | 406 | { |
222 | terminx | 407 | //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n); |
408 | EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n); |
||
409 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n); |
||
1325 | terminx | 410 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCPOLYMER), n); |
222 | terminx | 411 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n); |
1327 | terminx | 412 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUT), n); |
214 | terminx | 413 | |
991 | terminx | 414 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCDATA), n); |
415 | EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR), n); |
||
194 | terminx | 416 | } |
417 | |||
418 | static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) |
||
419 | { |
||
222 | terminx | 420 | static HBITMAP hbmp = NULL; |
421 | HDC hdc; |
||
194 | terminx | 422 | |
335 | terminx | 423 | switch (uMsg) |
424 | { |
||
337 | terminx | 425 | case WM_INITDIALOG: |
426 | { |
||
427 | HWND hwnd; |
||
428 | RECT r, rdlg, chrome, rtab, rcancel, rstart; |
||
1205 | terminx | 429 | int32_t xoffset = 0, yoffset = 0; |
194 | terminx | 430 | |
337 | terminx | 431 | // Fetch the positions (in screen coordinates) of all the windows we need to tweak |
432 | ZeroMemory(&chrome, sizeof(chrome)); |
||
433 | AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE); |
||
434 | GetWindowRect(hwndDlg, &rdlg); |
||
435 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab); |
||
436 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel); |
||
437 | GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart); |
||
194 | terminx | 438 | |
337 | terminx | 439 | // Knock off the non-client area of the main dialogue to give just the client area |
440 | rdlg.left -= chrome.left; |
||
441 | rdlg.top -= chrome.top; |
||
442 | rdlg.right -= chrome.right; |
||
443 | rdlg.bottom -= chrome.bottom; |
||
194 | terminx | 444 | |
337 | terminx | 445 | // Translate them to client-relative coordinates wrt the main dialogue window |
446 | rtab.right -= rtab.left - 1; |
||
447 | rtab.bottom -= rtab.top - 1; |
||
448 | rtab.left -= rdlg.left; |
||
449 | rtab.top -= rdlg.top; |
||
194 | terminx | 450 | |
337 | terminx | 451 | rcancel.right -= rcancel.left - 1; |
452 | rcancel.bottom -= rcancel.top - 1; |
||
453 | rcancel.left -= rdlg.left; |
||
454 | rcancel.top -= rdlg.top; |
||
194 | terminx | 455 | |
337 | terminx | 456 | rstart.right -= rstart.left - 1; |
457 | rstart.bottom -= rstart.top - 1; |
||
458 | rstart.left -= rdlg.left; |
||
459 | rstart.top -= rdlg.top; |
||
194 | terminx | 460 | |
337 | terminx | 461 | // And then convert the main dialogue coordinates to just width/length |
462 | rdlg.right -= rdlg.left - 1; |
||
463 | rdlg.bottom -= rdlg.top - 1; |
||
464 | rdlg.left = 0; |
||
465 | rdlg.top = 0; |
||
194 | terminx | 466 | |
337 | terminx | 467 | // Load the bitmap into the bitmap control and fetch its dimensions |
468 | hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP)); |
||
469 | hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP); |
||
470 | SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp); |
||
471 | GetClientRect(hwnd, &r); |
||
472 | xoffset = r.right; |
||
473 | yoffset = r.bottom - rdlg.bottom; |
||
194 | terminx | 474 | |
337 | terminx | 475 | // Shift and resize the controls that require it |
476 | rtab.left += xoffset; |
||
477 | rtab.bottom += yoffset; |
||
478 | rcancel.left += xoffset; |
||
479 | rcancel.top += yoffset; |
||
480 | rstart.left += xoffset; |
||
481 | rstart.top += yoffset; |
||
482 | rdlg.right += xoffset; |
||
483 | rdlg.bottom += yoffset; |
||
194 | terminx | 484 | |
337 | terminx | 485 | // Move the controls to their new positions |
486 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE); |
||
487 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE); |
||
488 | MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE); |
||
194 | terminx | 489 | |
337 | terminx | 490 | // Move the main dialogue to the centre of the screen |
491 | hdc = GetDC(NULL); |
||
492 | rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2; |
||
493 | rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2; |
||
494 | ReleaseDC(NULL, hdc); |
||
495 | MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left, |
||
496 | rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE); |
||
194 | terminx | 497 | |
337 | terminx | 498 | // Add tabs to the tab control |
499 | { |
||
500 | TCITEM tab; |
||
194 | terminx | 501 | |
337 | terminx | 502 | hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL); |
194 | terminx | 503 | |
337 | terminx | 504 | ZeroMemory(&tab, sizeof(tab)); |
505 | tab.mask = TCIF_TEXT; |
||
1188 | terminx | 506 | tab.pszText = TEXT("Setup"); |
337 | terminx | 507 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab); |
508 | tab.mask = TCIF_TEXT; |
||
1188 | terminx | 509 | tab.pszText = TEXT("Message Log"); |
337 | terminx | 510 | SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab); |
194 | terminx | 511 | |
337 | terminx | 512 | // Work out the position and size of the area inside the tab control for the pages |
513 | ZeroMemory(&r, sizeof(r)); |
||
514 | GetClientRect(hwnd, &r); |
||
515 | SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r); |
||
516 | r.right -= r.left-1; |
||
517 | r.bottom -= r.top-1; |
||
518 | r.top += rtab.top; |
||
519 | r.left += rtab.left; |
||
194 | terminx | 520 | |
337 | terminx | 521 | // Create the pages and position them in the tab control, but hide them |
522 | pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(), |
||
523 | MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc); |
||
524 | pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES); |
||
525 | SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
526 | SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW); |
||
194 | terminx | 527 | |
337 | terminx | 528 | // Tell the editfield acting as the console to exclude the width of the scrollbar |
529 | GetClientRect(pages[TAB_MESSAGES],&r); |
||
530 | r.right -= GetSystemMetrics(SM_CXVSCROLL)+4; |
||
531 | r.left = r.top = 0; |
||
532 | SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r); |
||
194 | terminx | 533 | |
337 | terminx | 534 | // Set a tab stop in the game data listbox |
535 | { |
||
536 | DWORD tabs[1] = { 150 }; |
||
991 | terminx | 537 | (void)ListBox_SetTabStops(GetDlgItem(pages[TAB_CONFIG], IDCDATA), 1, tabs); |
337 | terminx | 538 | } |
335 | terminx | 539 | |
337 | terminx | 540 | SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START)); |
541 | SetWindowText(hwndDlg, apptitle); |
||
335 | terminx | 542 | } |
337 | terminx | 543 | return FALSE; |
544 | } |
||
335 | terminx | 545 | |
337 | terminx | 546 | case WM_NOTIFY: |
547 | { |
||
548 | LPNMHDR nmhdr = (LPNMHDR)lParam; |
||
1205 | terminx | 549 | int32_t cur; |
337 | terminx | 550 | if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break; |
1205 | terminx | 551 | cur = (int32_t)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); |
337 | terminx | 552 | switch (nmhdr->code) |
335 | terminx | 553 | { |
337 | terminx | 554 | case TCN_SELCHANGING: |
555 | { |
||
556 | if (cur < 0 || !pages[cur]) break; |
||
557 | ShowWindow(pages[cur],SW_HIDE); |
||
558 | return TRUE; |
||
222 | terminx | 559 | } |
337 | terminx | 560 | case TCN_SELCHANGE: |
561 | { |
||
562 | if (cur < 0 || !pages[cur]) break; |
||
563 | ShowWindow(pages[cur],SW_SHOW); |
||
331 | terminx | 564 | return TRUE; |
337 | terminx | 565 | } |
566 | } |
||
567 | break; |
||
568 | } |
||
194 | terminx | 569 | |
337 | terminx | 570 | case WM_CLOSE: |
571 | if (mode == TAB_CONFIG) done = 0; |
||
572 | else quitevent++; |
||
573 | return TRUE; |
||
194 | terminx | 574 | |
337 | terminx | 575 | case WM_DESTROY: |
576 | if (hbmp) |
||
577 | { |
||
578 | DeleteObject(hbmp); |
||
579 | hbmp = NULL; |
||
580 | } |
||
194 | terminx | 581 | |
337 | terminx | 582 | if (pages[TAB_CONFIG]) |
583 | { |
||
584 | DestroyWindow(pages[TAB_CONFIG]); |
||
585 | pages[TAB_CONFIG] = NULL; |
||
586 | } |
||
587 | |||
588 | startupdlg = NULL; |
||
589 | return TRUE; |
||
590 | |||
591 | case WM_COMMAND: |
||
592 | switch (LOWORD(wParam)) |
||
593 | { |
||
594 | case WIN_STARTWIN_CANCEL: |
||
595 | if (mode == TAB_CONFIG) done = 0; |
||
596 | else quitevent++; |
||
335 | terminx | 597 | return TRUE; |
337 | terminx | 598 | case WIN_STARTWIN_START: |
599 | done = 1; |
||
600 | return TRUE; |
||
601 | } |
||
602 | return FALSE; |
||
194 | terminx | 603 | |
337 | terminx | 604 | case WM_CTLCOLORSTATIC: |
605 | if ((HWND)lParam == pages[TAB_MESSAGES]) |
||
3278 | hendricks2 | 606 | return (BOOL)(intptr_t)GetSysColorBrush(COLOR_WINDOW); |
337 | terminx | 607 | break; |
194 | terminx | 608 | |
337 | terminx | 609 | default: |
610 | break; |
||
222 | terminx | 611 | } |
612 | |||
613 | return FALSE; |
||
194 | terminx | 614 | } |
615 | |||
616 | |||
1205 | terminx | 617 | int32_t startwin_open(void) |
194 | terminx | 618 | { |
222 | terminx | 619 | INITCOMMONCONTROLSEX icc; |
620 | if (startupdlg) return 1; |
||
621 | icc.dwSize = sizeof(icc); |
||
622 | icc.dwICC = ICC_TAB_CLASSES; |
||
623 | InitCommonControlsEx(&icc); |
||
624 | startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); |
||
335 | terminx | 625 | if (startupdlg) |
626 | { |
||
222 | terminx | 627 | SetPage(TAB_MESSAGES); |
628 | EnableConfig(0); |
||
629 | return 0; |
||
630 | } |
||
631 | return -1; |
||
194 | terminx | 632 | } |
633 | |||
1205 | terminx | 634 | int32_t startwin_close(void) |
194 | terminx | 635 | { |
222 | terminx | 636 | if (!startupdlg) return 1; |
637 | DestroyWindow(startupdlg); |
||
638 | startupdlg = NULL; |
||
639 | return 0; |
||
194 | terminx | 640 | } |
641 | |||
1205 | terminx | 642 | int32_t startwin_puts(const char *buf) |
194 | terminx | 643 | { |
222 | terminx | 644 | const char *p = NULL, *q = NULL; |
851 | terminx | 645 | static char workbuf[1024]; |
1205 | terminx | 646 | static int32_t newline = 0; |
647 | int32_t curlen, linesbefore, linesafter; |
||
222 | terminx | 648 | HWND edctl; |
1205 | terminx | 649 | int32_t vis; |
851 | terminx | 650 | static HWND dactrl = NULL; |
194 | terminx | 651 | |
222 | terminx | 652 | if (!startupdlg) return 1; |
194 | terminx | 653 | |
222 | terminx | 654 | edctl = pages[TAB_MESSAGES]; |
655 | if (!edctl) return -1; |
||
194 | terminx | 656 | |
851 | terminx | 657 | if (!dactrl) dactrl = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); |
222 | terminx | 658 | |
1205 | terminx | 659 | vis = ((int32_t)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES); |
851 | terminx | 660 | |
222 | terminx | 661 | if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); |
662 | curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); |
||
663 | SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); |
||
664 | linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); |
||
665 | p = buf; |
||
335 | terminx | 666 | while (*p) |
667 | { |
||
668 | if (newline) |
||
669 | { |
||
222 | terminx | 670 | SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); |
671 | newline = 0; |
||
672 | } |
||
673 | q = p; |
||
674 | while (*q && *q != '\n') q++; |
||
1425 | terminx | 675 | Bmemcpy(workbuf, p, q-p); |
335 | terminx | 676 | if (*q == '\n') |
677 | { |
||
678 | if (!q[1]) |
||
679 | { |
||
222 | terminx | 680 | newline = 1; |
681 | workbuf[q-p] = 0; |
||
335 | terminx | 682 | } |
683 | else |
||
684 | { |
||
222 | terminx | 685 | workbuf[q-p] = '\r'; |
686 | workbuf[q-p+1] = '\n'; |
||
687 | workbuf[q-p+2] = 0; |
||
688 | } |
||
689 | p = q+1; |
||
335 | terminx | 690 | } |
691 | else |
||
692 | { |
||
222 | terminx | 693 | workbuf[q-p] = 0; |
694 | p = q; |
||
695 | } |
||
696 | SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); |
||
697 | } |
||
698 | linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); |
||
699 | SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); |
||
700 | if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); |
||
701 | return 0; |
||
194 | terminx | 702 | } |
703 | |||
1205 | terminx | 704 | int32_t startwin_settitle(const char *str) |
194 | terminx | 705 | { |
222 | terminx | 706 | if (!startupdlg) return 1; |
707 | SetWindowText(startupdlg, str); |
||
708 | return 0; |
||
194 | terminx | 709 | } |
710 | |||
1205 | terminx | 711 | int32_t startwin_idle(void *v) |
194 | terminx | 712 | { |
222 | terminx | 713 | if (!startupdlg || !IsWindow(startupdlg)) return 0; |
1677 | terminx | 714 | if (IsDialogMessage(startupdlg, (MSG *)v)) return 1; |
222 | terminx | 715 | return 0; |
194 | terminx | 716 | } |
717 | |||
1205 | terminx | 718 | int32_t startwin_run(void) |
194 | terminx | 719 | { |
222 | terminx | 720 | MSG msg; |
721 | if (!startupdlg) return 1; |
||
194 | terminx | 722 | |
222 | terminx | 723 | done = -1; |
194 | terminx | 724 | |
219 | terminx | 725 | #ifdef JFAUD |
222 | terminx | 726 | EnumAudioDevs(&wavedevs, NULL, NULL); |
219 | terminx | 727 | #endif |
222 | terminx | 728 | SetPage(TAB_CONFIG); |
729 | EnableConfig(1); |
||
194 | terminx | 730 | |
1326 | terminx | 731 | settings.flags = 0; |
732 | if (ud.config.ScreenMode) settings.flags |= 1; |
||
1564 | plagman | 733 | #ifdef POLYMER |
1325 | terminx | 734 | if (glrendmode == 4) settings.flags |= 2; |
1564 | plagman | 735 | #endif |
1326 | terminx | 736 | if (ud.config.NoAutoLoad) settings.flags |= 4; |
563 | terminx | 737 | settings.xdim = ud.config.ScreenWidth; |
738 | settings.ydim = ud.config.ScreenHeight; |
||
739 | settings.bpp = ud.config.ScreenBPP; |
||
740 | settings.forcesetup = ud.config.ForceSetup; |
||
741 | settings.usemouse = ud.config.UseMouse; |
||
742 | settings.usejoy = ud.config.UseJoystick; |
||
1143 | terminx | 743 | settings.game = g_gameType; |
886 | terminx | 744 | // settings.crcval = 0; |
2726 | hendricks2 | 745 | Bstrncpyz(settings.selectedgrp, G_GrpFile(), BMAX_PATH); |
1587 | terminx | 746 | settings.gamedir = g_modDir; |
222 | terminx | 747 | PopulateForm(-1); |
194 | terminx | 748 | |
335 | terminx | 749 | while (done < 0) |
750 | { |
||
751 | switch (GetMessage(&msg, NULL, 0,0)) |
||
752 | { |
||
337 | terminx | 753 | case 0: |
754 | done = 1; |
||
755 | break; |
||
756 | case -1: |
||
757 | return -1; |
||
758 | default: |
||
759 | if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; |
||
760 | TranslateMessage(&msg); |
||
761 | DispatchMessage(&msg); |
||
762 | break; |
||
222 | terminx | 763 | } |
764 | } |
||
194 | terminx | 765 | |
222 | terminx | 766 | SetPage(TAB_MESSAGES); |
767 | EnableConfig(0); |
||
335 | terminx | 768 | if (done) |
769 | { |
||
1205 | terminx | 770 | int32_t i; |
886 | terminx | 771 | |
1325 | terminx | 772 | ud.config.ScreenMode = (settings.flags&1); |
1564 | plagman | 773 | #ifdef POLYMER |
1325 | terminx | 774 | if (settings.flags & 2) glrendmode = 4; |
775 | else glrendmode = 3; |
||
1564 | plagman | 776 | #endif |
1326 | terminx | 777 | if (settings.flags & 4) ud.config.NoAutoLoad = 1; |
778 | else ud.config.NoAutoLoad = 0; |
||
563 | terminx | 779 | ud.config.ScreenWidth = settings.xdim; |
780 | ud.config.ScreenHeight = settings.ydim; |
||
781 | ud.config.ScreenBPP = settings.bpp; |
||
782 | ud.config.ForceSetup = settings.forcesetup; |
||
783 | ud.config.UseMouse = settings.usemouse; |
||
784 | ud.config.UseJoystick = settings.usejoy; |
||
2563 | helixhorne | 785 | |
786 | clearGrpNamePtr(); |
||
787 | g_grpNamePtr = dup_filename(settings.selectedgrp); |
||
788 | |||
1143 | terminx | 789 | g_gameType = settings.game; |
990 | terminx | 790 | |
1143 | terminx | 791 | if (g_noSetup == 0 && settings.gamedir != NULL) |
1587 | terminx | 792 | Bstrcpy(g_modDir,settings.gamedir); |
793 | else Bsprintf(g_modDir,"/"); |
||
886 | terminx | 794 | |
2543 | helixhorne | 795 | for (i = 0; i<NUMGRPFILES; i++) if (settings.crcval == grpfiles[i].crcval) break; |
796 | if (i != NUMGRPFILES) |
||
2561 | helixhorne | 797 | g_gameNamePtr = grpfiles[i].name; |
222 | terminx | 798 | } |
194 | terminx | 799 | |
335 | terminx | 800 | if (wavedevs) |
801 | { |
||
222 | terminx | 802 | struct audioenumdev *d, *e; |
1527 | terminx | 803 | Bfree(wavedevs->drvs); |
335 | terminx | 804 | for (e=wavedevs->devs; e; e=d) |
805 | { |
||
222 | terminx | 806 | d = e->next; |
1527 | terminx | 807 | if (e->devs) Bfree(e->devs); |
808 | Bfree(e); |
||
222 | terminx | 809 | } |
1527 | terminx | 810 | Bfree(wavedevs); |
222 | terminx | 811 | } |
219 | terminx | 812 | |
222 | terminx | 813 | return done; |
194 | terminx | 814 | } |
815 |