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