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