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