WIN_DLG.CPP 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include "stdafx.h"
  19. #include "qe3.h"
  20. #include "PrefsDlg.h"
  21. BOOL CALLBACK EditCommandDlgProc (
  22. HWND hwndDlg, // handle to dialog box
  23. UINT uMsg, // message
  24. WPARAM wParam, // first message parameter
  25. LPARAM lParam // second message parameter
  26. )
  27. {
  28. char key[1024];
  29. char value[1024];
  30. char *temp;
  31. int index;
  32. HWND hOwner;
  33. hOwner = GetParent (hwndDlg);
  34. switch (uMsg)
  35. {
  36. case WM_INITDIALOG:
  37. index = SendDlgItemMessage (hOwner, IDC_CMD_LIST, LB_GETCURSEL, 0, 0);
  38. if (index >= 0)
  39. {
  40. SendDlgItemMessage(hOwner, IDC_CMD_LIST, LB_GETTEXT, index, (LPARAM) (LPCTSTR) key);
  41. temp = ValueForKey (g_qeglobals.d_project_entity, key);
  42. strcpy (value, temp);
  43. SetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key);
  44. SetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value);
  45. }
  46. return FALSE;
  47. break;
  48. case WM_COMMAND:
  49. switch (LOWORD(wParam))
  50. {
  51. case IDOK:
  52. if (!GetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key, 64))
  53. {
  54. Sys_Printf ("Command not added\n");
  55. return FALSE;
  56. }
  57. if (!GetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value, 64))
  58. {
  59. Sys_Printf ("Command not added\n");
  60. return FALSE;
  61. }
  62. //if (key[0] == 'b' && key[1] == 's' && key[2] == 'p')
  63. //{
  64. SetKeyValue (g_qeglobals.d_project_entity, key, value);
  65. FillBSPMenu ();
  66. //}
  67. //else
  68. // Sys_Printf ("BSP commands must be preceded by \"bsp\"");
  69. EndDialog(hwndDlg, 1);
  70. return TRUE;
  71. case IDCANCEL:
  72. EndDialog(hwndDlg, 0);
  73. return TRUE;
  74. }
  75. }
  76. return FALSE;
  77. }
  78. BOOL CALLBACK AddCommandDlgProc (
  79. HWND hwndDlg, // handle to dialog box
  80. UINT uMsg, // message
  81. WPARAM wParam, // first message parameter
  82. LPARAM lParam // second message parameter
  83. )
  84. {
  85. char key[64];
  86. char value[128];
  87. switch (uMsg)
  88. {
  89. case WM_COMMAND:
  90. switch (LOWORD(wParam))
  91. {
  92. case IDOK:
  93. if (!GetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key, 64))
  94. {
  95. Sys_Printf ("Command not added\n");
  96. return FALSE;
  97. }
  98. if (!GetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value, 64))
  99. {
  100. Sys_Printf ("Command not added\n");
  101. return FALSE;
  102. }
  103. if (key[0] == 'b' && key[1] == 's' && key[2] == 'p')
  104. {
  105. SetKeyValue (g_qeglobals.d_project_entity, key, value);
  106. FillBSPMenu ();
  107. }
  108. else
  109. Sys_Printf ("BSP commands must be preceded by \"bsp\"");
  110. EndDialog(hwndDlg, 1);
  111. return TRUE;
  112. case IDCANCEL:
  113. EndDialog(hwndDlg, 0);
  114. return TRUE;
  115. }
  116. }
  117. return FALSE;
  118. }
  119. void UpdateBSPCommandList (HWND hwndDlg)
  120. {
  121. int i;
  122. epair_t *ep;
  123. SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_RESETCONTENT, 0 , 0);
  124. i = 0;
  125. for (ep = g_qeglobals.d_project_entity->epairs ; ep ; ep=ep->next)
  126. {
  127. if (ep->key[0] == 'b' && ep->key[1] == 's' && ep->key[2] == 'p')
  128. {
  129. SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_ADDSTRING, i , (LPARAM) ep->key);
  130. i++;
  131. }
  132. }
  133. }
  134. // FIXME: turn this into an MFC dialog
  135. BOOL CALLBACK ProjectDlgProc (
  136. HWND hwndDlg, // handle to dialog box
  137. UINT uMsg, // message
  138. WPARAM wParam, // first message parameter
  139. LPARAM lParam // second message parameter
  140. )
  141. {
  142. char key[1024];
  143. char value[1024];
  144. int index;
  145. switch (uMsg)
  146. {
  147. case WM_INITDIALOG:
  148. SetDlgItemText(hwndDlg, IDC_PRJBASEPATH, ValueForKey (g_qeglobals.d_project_entity, "basepath"));
  149. SetDlgItemText(hwndDlg, IDC_PRJMAPSPATH, ValueForKey (g_qeglobals.d_project_entity, "mapspath"));
  150. SetDlgItemText(hwndDlg, IDC_PRJRSHCMD, ValueForKey (g_qeglobals.d_project_entity, "rshcmd"));
  151. SetDlgItemText(hwndDlg, IDC_PRJREMOTEBASE, ValueForKey (g_qeglobals.d_project_entity, "remotebasepath"));
  152. SetDlgItemText(hwndDlg, IDC_PRJENTITYPATH, ValueForKey (g_qeglobals.d_project_entity, "entitypath"));
  153. SetDlgItemText(hwndDlg, IDC_PRJTEXPATH, ValueForKey (g_qeglobals.d_project_entity, "texturepath"));
  154. UpdateBSPCommandList (hwndDlg);
  155. // Timo
  156. // additional fields
  157. CheckDlgButton( hwndDlg, IDC_CHECK_BPRIMIT, (g_qeglobals.m_bBrushPrimitMode) ? BST_CHECKED : BST_UNCHECKED );
  158. // SendMessage( ::GetDlgItem( hwndDlg, IDC_CHECK_BPRIMIT ), BM_SETCHECK, (WPARAM) g_qeglobals.m_bBrushPrimitMode, 0 );
  159. return TRUE;
  160. case WM_COMMAND:
  161. switch (LOWORD(wParam))
  162. {
  163. case IDC_ADDCMD:
  164. // DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, g_qeglobals.d_hwndMain, AddCommandDlgProc);
  165. DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, hwndDlg, AddCommandDlgProc);
  166. UpdateBSPCommandList (hwndDlg);
  167. break;
  168. case IDC_EDITCMD:
  169. // DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, g_qeglobals.d_hwndMain, EditCommandDlgProc);
  170. DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, hwndDlg, EditCommandDlgProc);
  171. UpdateBSPCommandList (hwndDlg);
  172. break;
  173. case IDC_REMCMD:
  174. index = SendDlgItemMessage (hwndDlg, IDC_CMD_LIST, LB_GETCURSEL, 0, 0);
  175. SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_GETTEXT, index, (LPARAM) (LPCTSTR) key);
  176. DeleteKey (g_qeglobals.d_project_entity, key);
  177. Sys_Printf ("Selected %d\n", index);
  178. UpdateBSPCommandList (hwndDlg);
  179. break;
  180. case IDOK:
  181. GetDlgItemText(hwndDlg, IDC_PRJBASEPATH, value, 1024);
  182. SetKeyValue (g_qeglobals.d_project_entity, "basepath", value);
  183. GetDlgItemText(hwndDlg, IDC_PRJMAPSPATH, value, 1024);
  184. SetKeyValue (g_qeglobals.d_project_entity, "mapspath", value);
  185. GetDlgItemText(hwndDlg, IDC_PRJRSHCMD, value, 1024);
  186. SetKeyValue (g_qeglobals.d_project_entity, "rshcmd", value);
  187. GetDlgItemText(hwndDlg, IDC_PRJREMOTEBASE, value, 1024);
  188. SetKeyValue (g_qeglobals.d_project_entity, "remotebasepath", value);
  189. GetDlgItemText(hwndDlg, IDC_PRJENTITYPATH, value, 1024);
  190. SetKeyValue (g_qeglobals.d_project_entity, "entitypath", value);
  191. GetDlgItemText(hwndDlg, IDC_PRJTEXPATH, value, 1024);
  192. SetKeyValue (g_qeglobals.d_project_entity, "texturepath", value);
  193. // Timo
  194. // read additional fields
  195. if ( IsDlgButtonChecked( hwndDlg, IDC_CHECK_BPRIMIT ) )
  196. {
  197. g_qeglobals.m_bBrushPrimitMode = TRUE;
  198. }
  199. else
  200. {
  201. g_qeglobals.m_bBrushPrimitMode = FALSE;
  202. }
  203. SetKeyValue ( g_qeglobals.d_project_entity, "brush_primit", ( g_qeglobals.m_bBrushPrimitMode ? "1" : "0" ) );
  204. EndDialog(hwndDlg, 1);
  205. QE_SaveProject(g_strProject);
  206. return TRUE;
  207. case IDCANCEL:
  208. EndDialog(hwndDlg, 0);
  209. return TRUE;
  210. }
  211. }
  212. return FALSE;
  213. }
  214. void DoProjectSettings()
  215. {
  216. DialogBox(g_qeglobals.d_hInstance, (char *)IDD_PROJECT, g_qeglobals.d_hwndMain, ProjectDlgProc);
  217. }
  218. BOOL CALLBACK GammaDlgProc (
  219. HWND hwndDlg, // handle to dialog box
  220. UINT uMsg, // message
  221. WPARAM wParam, // first message parameter
  222. LPARAM lParam // second message parameter
  223. )
  224. {
  225. char sz[256];
  226. switch (uMsg)
  227. {
  228. case WM_INITDIALOG:
  229. sprintf(sz, "%1.1f", g_qeglobals.d_savedinfo.fGamma);
  230. SetWindowText(GetDlgItem(hwndDlg, IDC_G_EDIT), sz);
  231. return TRUE;
  232. case WM_COMMAND:
  233. switch (LOWORD(wParam))
  234. {
  235. case IDOK:
  236. GetWindowText(GetDlgItem(hwndDlg, IDC_G_EDIT), sz, 255);
  237. g_qeglobals.d_savedinfo.fGamma = atof(sz);
  238. EndDialog(hwndDlg, 1);
  239. return TRUE;
  240. case IDCANCEL:
  241. EndDialog(hwndDlg, 0);
  242. return TRUE;
  243. }
  244. }
  245. return FALSE;
  246. }
  247. void DoGamma(void)
  248. {
  249. if ( DialogBox(g_qeglobals.d_hInstance, (char *)IDD_GAMMA, g_qeglobals.d_hwndMain, GammaDlgProc))
  250. {
  251. }
  252. }
  253. //================================================
  254. void SelectBrush (int entitynum, int brushnum)
  255. {
  256. entity_t *e;
  257. brush_t *b;
  258. int i;
  259. if (entitynum == 0)
  260. e = world_entity;
  261. else
  262. {
  263. e = entities.next;
  264. while (--entitynum)
  265. {
  266. e=e->next;
  267. if (e == &entities)
  268. {
  269. Sys_Status ("No such entity.", 0);
  270. return;
  271. }
  272. }
  273. }
  274. b = e->brushes.onext;
  275. if (b == &e->brushes)
  276. {
  277. Sys_Status ("No such brush.", 0);
  278. return;
  279. }
  280. while (brushnum--)
  281. {
  282. b=b->onext;
  283. if (b == &e->brushes)
  284. {
  285. Sys_Status ("No such brush.", 0);
  286. return;
  287. }
  288. }
  289. Brush_RemoveFromList (b);
  290. Brush_AddToList (b, &selected_brushes);
  291. Sys_UpdateWindows (W_ALL);
  292. for (i=0 ; i<3 ; i++)
  293. {
  294. if (g_pParentWnd->GetXYWnd())
  295. g_pParentWnd->GetXYWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
  296. if (g_pParentWnd->GetXZWnd())
  297. g_pParentWnd->GetXZWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
  298. if (g_pParentWnd->GetYZWnd())
  299. g_pParentWnd->GetYZWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
  300. }
  301. Sys_Status ("Selected.", 0);
  302. }
  303. /*
  304. =================
  305. GetSelectionIndex
  306. =================
  307. */
  308. void GetSelectionIndex (int *ent, int *brush)
  309. {
  310. brush_t *b, *b2;
  311. entity_t *entity;
  312. *ent = *brush = 0;
  313. b = selected_brushes.next;
  314. if (b == &selected_brushes)
  315. return;
  316. // find entity
  317. if (b->owner != world_entity)
  318. {
  319. (*ent)++;
  320. for (entity = entities.next ; entity != &entities
  321. ; entity=entity->next, (*ent)++)
  322. ;
  323. }
  324. // find brush
  325. for (b2=b->owner->brushes.onext
  326. ; b2 != b && b2 != &b->owner->brushes
  327. ; b2=b2->onext, (*brush)++)
  328. ;
  329. }
  330. BOOL CALLBACK FindBrushDlgProc (
  331. HWND hwndDlg, // handle to dialog box
  332. UINT uMsg, // message
  333. WPARAM wParam, // first message parameter
  334. LPARAM lParam // second message parameter
  335. )
  336. {
  337. char entstr[256];
  338. char brushstr[256];
  339. HWND h;
  340. int ent, brush;
  341. switch (uMsg)
  342. {
  343. case WM_INITDIALOG:
  344. // set entity and brush number
  345. GetSelectionIndex (&ent, &brush);
  346. sprintf (entstr, "%i", ent);
  347. sprintf (brushstr, "%i", brush);
  348. SetWindowText(GetDlgItem(hwndDlg, IDC_FIND_ENTITY), entstr);
  349. SetWindowText(GetDlgItem(hwndDlg, IDC_FIND_BRUSH), brushstr);
  350. h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
  351. SetFocus (h);
  352. return FALSE;
  353. case WM_COMMAND:
  354. switch (LOWORD(wParam))
  355. {
  356. case IDOK:
  357. GetWindowText(GetDlgItem(hwndDlg, IDC_FIND_ENTITY), entstr, 255);
  358. GetWindowText(GetDlgItem(hwndDlg, IDC_FIND_BRUSH), brushstr, 255);
  359. SelectBrush (atoi(entstr), atoi(brushstr));
  360. EndDialog(hwndDlg, 1);
  361. return TRUE;
  362. case IDCANCEL:
  363. EndDialog(hwndDlg, 0);
  364. return TRUE;
  365. }
  366. }
  367. return FALSE;
  368. }
  369. void DoFind(void)
  370. {
  371. DialogBox(g_qeglobals.d_hInstance, (char *)IDD_FINDBRUSH, g_qeglobals.d_hwndMain, FindBrushDlgProc);
  372. }
  373. /*
  374. ===================================================
  375. ARBITRARY ROTATE
  376. ===================================================
  377. */
  378. BOOL CALLBACK RotateDlgProc (
  379. HWND hwndDlg, // handle to dialog box
  380. UINT uMsg, // message
  381. WPARAM wParam, // first message parameter
  382. LPARAM lParam // second message parameter
  383. )
  384. {
  385. char str[256];
  386. HWND h;
  387. float v;
  388. switch (uMsg)
  389. {
  390. case WM_INITDIALOG:
  391. h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
  392. SetFocus (h);
  393. return FALSE;
  394. case WM_COMMAND:
  395. switch (LOWORD(wParam))
  396. {
  397. case IDOK:
  398. GetWindowText(GetDlgItem(hwndDlg, IDC_ROTX), str, 255);
  399. v = atof(str);
  400. if (v)
  401. Select_RotateAxis (0, v);
  402. GetWindowText(GetDlgItem(hwndDlg, IDC_ROTY), str, 255);
  403. v = atof(str);
  404. if (v)
  405. Select_RotateAxis (1, v);
  406. GetWindowText(GetDlgItem(hwndDlg, IDC_ROTZ), str, 255);
  407. v = atof(str);
  408. if (v)
  409. Select_RotateAxis (2, v);
  410. EndDialog(hwndDlg, 1);
  411. return TRUE;
  412. case IDCANCEL:
  413. EndDialog(hwndDlg, 0);
  414. return TRUE;
  415. }
  416. }
  417. return FALSE;
  418. }
  419. void DoRotate(void)
  420. {
  421. DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ROTATE, g_qeglobals.d_hwndMain, RotateDlgProc);
  422. }
  423. /*
  424. ===================================================
  425. ARBITRARY SIDES
  426. ===================================================
  427. */
  428. bool g_bDoCone = false;
  429. bool g_bDoSphere = false;
  430. BOOL CALLBACK SidesDlgProc (
  431. HWND hwndDlg, // handle to dialog box
  432. UINT uMsg, // message
  433. WPARAM wParam, // first message parameter
  434. LPARAM lParam // second message parameter
  435. )
  436. {
  437. char str[256];
  438. HWND h;
  439. switch (uMsg)
  440. {
  441. case WM_INITDIALOG:
  442. h = GetDlgItem(hwndDlg, IDC_SIDES);
  443. SetFocus (h);
  444. return FALSE;
  445. case WM_COMMAND:
  446. switch (LOWORD(wParam)) {
  447. case IDOK:
  448. GetWindowText(GetDlgItem(hwndDlg, IDC_SIDES), str, 255);
  449. if (g_bDoCone)
  450. Brush_MakeSidedCone(atoi(str));
  451. else if (g_bDoSphere)
  452. Brush_MakeSidedSphere(atoi(str));
  453. else
  454. Brush_MakeSided (atoi(str));
  455. EndDialog(hwndDlg, 1);
  456. break;
  457. case IDCANCEL:
  458. EndDialog(hwndDlg, 0);
  459. break;
  460. }
  461. default:
  462. return FALSE;
  463. }
  464. }
  465. void DoSides(bool bCone, bool bSphere, bool bTorus)
  466. {
  467. g_bDoCone = bCone;
  468. g_bDoSphere = bSphere;
  469. //g_bDoTorus = bTorus;
  470. DialogBox(g_qeglobals.d_hInstance, (char *)IDD_SIDES, g_qeglobals.d_hwndMain, SidesDlgProc);
  471. }
  472. //======================================================================
  473. /*
  474. ===================
  475. DoAbout
  476. ===================
  477. */
  478. BOOL CALLBACK AboutDlgProc( HWND hwndDlg,
  479. UINT uMsg,
  480. WPARAM wParam,
  481. LPARAM lParam )
  482. {
  483. switch (uMsg)
  484. {
  485. case WM_INITDIALOG:
  486. {
  487. char renderer[1024];
  488. char version[1024];
  489. char vendor[1024];
  490. char extensions[4096];
  491. sprintf( renderer, "Renderer:\t%s", qglGetString( GL_RENDERER ) );
  492. sprintf( version, "Version:\t\t%s", qglGetString( GL_VERSION ) );
  493. sprintf( vendor, "Vendor:\t\t%s", qglGetString( GL_VENDOR ) );
  494. sprintf( extensions, "%s", qglGetString( GL_EXTENSIONS ) );
  495. SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLRENDERER ), renderer );
  496. SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLVERSION ), version );
  497. SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLVENDOR ), vendor );
  498. SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLEXTENSIONS ), extensions );
  499. }
  500. return TRUE;
  501. case WM_CLOSE:
  502. EndDialog( hwndDlg, 1 );
  503. return TRUE;
  504. case WM_COMMAND:
  505. if ( LOWORD( wParam ) == IDOK )
  506. EndDialog(hwndDlg, 1);
  507. return TRUE;
  508. }
  509. return FALSE;
  510. }
  511. void DoAbout(void)
  512. {
  513. DialogBox( g_qeglobals.d_hInstance, ( char * ) IDD_ABOUT, g_qeglobals.d_hwndMain, AboutDlgProc );
  514. }