]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/radiant/WIN_DLG.CPP
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / tools / radiant / WIN_DLG.CPP
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "qe3.h"
33
34 BOOL CALLBACK EditCommandDlgProc (
35     HWND hwndDlg,       // handle to dialog box
36     UINT uMsg,  // message
37     WPARAM wParam,      // first message parameter
38     LPARAM lParam       // second message parameter
39    )
40 {
41         char    key[1024];
42         char    value[1024];
43         const char      *temp;
44         int             index;
45         HWND    hOwner;
46         
47         hOwner = GetParent (hwndDlg);
48
49         switch (uMsg)
50     {
51         case WM_INITDIALOG:
52                 index = SendDlgItemMessage (hOwner, IDC_CMD_LIST, LB_GETCURSEL, 0, 0);
53     if (index >= 0)
54     {
55                   SendDlgItemMessage(hOwner, IDC_CMD_LIST, LB_GETTEXT, index, (LPARAM) (LPCTSTR) key);
56                   temp = ValueForKey (g_qeglobals.d_project_entity, key);
57                   strcpy (value, temp);
58                   SetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key);
59                   SetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value);
60     }
61                 return FALSE;
62                 break;
63
64         case WM_COMMAND: 
65                 switch (LOWORD(wParam)) 
66                 { 
67                         case IDOK:
68                                 if (!GetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key, 64))
69                                 {
70                                         common->Printf ("Command not added\n");
71                                         return FALSE;
72                                 }
73
74                                 if (!GetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value, 64))
75                                 {
76                                         common->Printf ("Command not added\n");
77                                         return FALSE;
78                                 }
79
80                                 //if (key[0] == 'b' && key[1] == 's' && key[2] == 'p')
81                                 //{
82                                         SetKeyValue (g_qeglobals.d_project_entity, key, value);
83                                         FillBSPMenu ();
84                                 //}
85                                 //else
86                                 //      common->Printf ("BSP commands must be preceded by \"bsp\"");
87
88                                 EndDialog(hwndDlg, 1);
89                                 return TRUE;
90
91                         case IDCANCEL:
92                                 EndDialog(hwndDlg, 0);
93                                 return TRUE;
94                 }
95         }
96         return FALSE;
97 }
98
99 BOOL CALLBACK AddCommandDlgProc (
100     HWND hwndDlg,       // handle to dialog box
101     UINT uMsg,  // message
102     WPARAM wParam,      // first message parameter
103     LPARAM lParam       // second message parameter
104    )
105 {
106         char    key[64];
107         char    value[128];
108
109         switch (uMsg)
110     {
111         case WM_COMMAND: 
112                 switch (LOWORD(wParam)) 
113                 { 
114                         case IDOK:
115                                 if (!GetDlgItemText(hwndDlg, IDC_CMDMENUTEXT, key, 64))
116                                 {
117                                         common->Printf ("Command not added\n");
118                                         return FALSE;
119                                 }
120
121                                 if (!GetDlgItemText(hwndDlg, IDC_CMDCOMMAND, value, 64))
122                                 {
123                                         common->Printf ("Command not added\n");
124                                         return FALSE;
125                                 }
126
127                                 if (key[0] == 'b' && key[1] == 's' && key[2] == 'p')
128                                 {
129                                         SetKeyValue (g_qeglobals.d_project_entity, key, value);
130                                         FillBSPMenu ();
131                                 }
132                                 else
133                                         common->Printf ("BSP commands must be preceded by \"bsp\"");
134
135                                 EndDialog(hwndDlg, 1);
136                                 return TRUE;
137
138                         case IDCANCEL:
139                                 EndDialog(hwndDlg, 0);
140                                 return TRUE;
141                 }
142         }
143         return FALSE;
144 }
145
146 void UpdateBSPCommandList (HWND hwndDlg)
147 {
148         int                     i;
149
150         SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_RESETCONTENT, 0 , 0);
151
152         i = 0;
153         int count = g_qeglobals.d_project_entity->epairs.GetNumKeyVals();
154         for (int j = 0; j < count; j++) {
155                 if (g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey()[0] == 'b' && g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey()[1] == 's' && g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey()[2] == 'p') {
156                         SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_ADDSTRING, i , (LPARAM) g_qeglobals.d_project_entity->epairs.GetKeyVal(j)->GetKey().c_str());
157                         i++;
158                 }
159         }
160 }
161
162
163 // FIXME: turn this into an MFC dialog
164 BOOL CALLBACK ProjectDlgProc (
165     HWND hwndDlg,       // handle to dialog box
166     UINT uMsg,  // message
167     WPARAM wParam,      // first message parameter
168     LPARAM lParam       // second message parameter
169    )
170 {
171         char            key[1024];
172         char            value[1024];
173         int                     index;
174
175         switch (uMsg)
176     {
177         case WM_INITDIALOG:
178                 SetDlgItemText(hwndDlg, IDC_PRJBASEPATH, ValueForKey (g_qeglobals.d_project_entity, "basepath"));
179                 SetDlgItemText(hwndDlg, IDC_PRJMAPSPATH, ValueForKey (g_qeglobals.d_project_entity, "mapspath"));
180                 SetDlgItemText(hwndDlg, IDC_PRJRSHCMD, ValueForKey (g_qeglobals.d_project_entity, "rshcmd"));
181                 SetDlgItemText(hwndDlg, IDC_PRJREMOTEBASE, ValueForKey (g_qeglobals.d_project_entity, "remotebasepath"));
182                 SetDlgItemText(hwndDlg, IDC_PRJENTITYPATH, ValueForKey (g_qeglobals.d_project_entity, "entitypath"));
183                 SetDlgItemText(hwndDlg, IDC_PRJTEXPATH, ValueForKey (g_qeglobals.d_project_entity, "texturepath"));
184                 UpdateBSPCommandList (hwndDlg);
185                 // Timo
186                 // additional fields
187                 CheckDlgButton( hwndDlg, IDC_CHECK_BPRIMIT, (g_qeglobals.m_bBrushPrimitMode) ? BST_CHECKED : BST_UNCHECKED );
188 //              SendMessage( ::GetDlgItem( hwndDlg, IDC_CHECK_BPRIMIT ), BM_SETCHECK, (WPARAM) g_qeglobals.m_bBrushPrimitMode, 0 );
189                 return TRUE;
190
191         case WM_COMMAND: 
192                 switch (LOWORD(wParam)) 
193                 { 
194                         case IDC_ADDCMD:
195 //                              DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, g_qeglobals.d_hwndMain, AddCommandDlgProc);
196                                 DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, hwndDlg, AddCommandDlgProc);
197                                 UpdateBSPCommandList (hwndDlg);
198                                 break;
199
200                         case IDC_EDITCMD:
201 //                              DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, g_qeglobals.d_hwndMain, EditCommandDlgProc);
202                                 DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ADDCMD, hwndDlg, EditCommandDlgProc);
203                                 UpdateBSPCommandList (hwndDlg);
204                                 break;
205
206                         case IDC_REMCMD:
207                                 index = SendDlgItemMessage (hwndDlg, IDC_CMD_LIST, LB_GETCURSEL, 0, 0);
208                                 SendDlgItemMessage(hwndDlg, IDC_CMD_LIST, LB_GETTEXT, index, (LPARAM) (LPCTSTR) key);
209                                 DeleteKey (g_qeglobals.d_project_entity, key);
210                                 common->Printf ("Selected %d\n", index);
211                                 UpdateBSPCommandList (hwndDlg);
212                                 break;
213
214                         case IDOK:
215                                 GetDlgItemText(hwndDlg, IDC_PRJBASEPATH, value, 1024);
216                                 SetKeyValue (g_qeglobals.d_project_entity, "basepath", value);
217                                 GetDlgItemText(hwndDlg, IDC_PRJMAPSPATH, value, 1024);
218                                 SetKeyValue (g_qeglobals.d_project_entity, "mapspath", value);
219                                 GetDlgItemText(hwndDlg, IDC_PRJRSHCMD, value, 1024);
220                                 SetKeyValue (g_qeglobals.d_project_entity, "rshcmd", value);
221                                 GetDlgItemText(hwndDlg, IDC_PRJREMOTEBASE, value, 1024);
222                                 SetKeyValue (g_qeglobals.d_project_entity, "remotebasepath", value);
223                                 GetDlgItemText(hwndDlg, IDC_PRJENTITYPATH, value, 1024);
224                                 SetKeyValue (g_qeglobals.d_project_entity, "entitypath", value);
225                                 GetDlgItemText(hwndDlg, IDC_PRJTEXPATH, value, 1024);
226                                 SetKeyValue (g_qeglobals.d_project_entity, "texturepath", value);
227                                 // Timo
228                                 // read additional fields
229                                 if ( IsDlgButtonChecked( hwndDlg, IDC_CHECK_BPRIMIT ) )
230                                 {
231                                         g_qeglobals.m_bBrushPrimitMode = TRUE;
232                                 }
233                                 else
234                                 {
235                                         g_qeglobals.m_bBrushPrimitMode = FALSE;
236                                 }
237                                 SetKeyValue ( g_qeglobals.d_project_entity, "brush_primit", ( g_qeglobals.m_bBrushPrimitMode ? "1" : "0" ) );
238
239                                 EndDialog(hwndDlg, 1);
240                                 QE_SaveProject(g_strProject);
241                                 return TRUE;
242
243                         case IDCANCEL:
244                                 EndDialog(hwndDlg, 0);
245                                 return TRUE;
246                 }
247         }
248         return FALSE;
249 }
250
251 void DoProjectSettings()
252 {
253         DialogBox(g_qeglobals.d_hInstance, (char *)IDD_PROJECT, g_pParentWnd->GetSafeHwnd(), ProjectDlgProc);
254 }
255
256
257
258 BOOL CALLBACK GammaDlgProc (
259     HWND hwndDlg,       // handle to dialog box
260     UINT uMsg,  // message
261     WPARAM wParam,      // first message parameter
262     LPARAM lParam       // second message parameter
263    )
264 {
265         char sz[256];
266
267         switch (uMsg)
268     {
269         case WM_INITDIALOG:
270                 sprintf(sz, "%1.1f", g_qeglobals.d_savedinfo.fGamma);           
271                 SetWindowText(GetDlgItem(hwndDlg, IDC_G_EDIT), sz);
272                 return TRUE;
273         case WM_COMMAND: 
274                 switch (LOWORD(wParam)) 
275                 { 
276                 
277                 case IDOK:
278                         GetWindowText(GetDlgItem(hwndDlg, IDC_G_EDIT), sz, 255);
279                         g_qeglobals.d_savedinfo.fGamma = atof(sz);
280                         EndDialog(hwndDlg, 1);
281                         return TRUE;
282
283                 case IDCANCEL:
284                         EndDialog(hwndDlg, 0);
285                         return TRUE;
286                 }
287         }
288         return FALSE;
289 }
290
291
292
293 void DoGamma(void)
294 {
295         if ( DialogBox(g_qeglobals.d_hInstance, (char *)IDD_GAMMA, g_pParentWnd->GetSafeHwnd(), GammaDlgProc))
296         {
297         }
298 }               
299
300 //================================================
301
302
303 void SelectBrush (int entitynum, int brushnum)
304 {
305         entity_t        *e;
306         brush_t         *b;
307         int                     i;
308
309         if (entitynum == 0)
310                 e = world_entity;
311         else
312         {
313                 e = entities.next;
314                 while (--entitynum)
315                 {
316                         e=e->next;
317                         if (e == &entities)
318                         {
319                                 Sys_Status ("No such entity.", 0);
320                                 return;
321                         }
322                 }
323         }
324
325         b = e->brushes.onext;
326         if (b == &e->brushes)
327         {
328                 Sys_Status ("No such brush.", 0);
329                 return;
330         }
331         while (brushnum--)
332         {
333                 b=b->onext;
334                 if (b == &e->brushes)
335                 {
336                         Sys_Status ("No such brush.", 0);
337                         return;
338                 }
339         }
340
341         Brush_RemoveFromList (b);
342         Brush_AddToList (b, &selected_brushes);
343
344
345         Sys_UpdateWindows (W_ALL);
346         for (i=0 ; i<3 ; i++)
347   {
348     if (g_pParentWnd->GetXYWnd())
349       g_pParentWnd->GetXYWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
350
351     if (g_pParentWnd->GetXZWnd())
352       g_pParentWnd->GetXZWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
353     
354     if (g_pParentWnd->GetYZWnd())
355       g_pParentWnd->GetYZWnd()->GetOrigin()[i] = (b->mins[i] + b->maxs[i])/2;
356   }
357
358         Sys_Status ("Selected.", 0);
359 }
360
361 /*
362 =================
363 GetSelectionIndex
364 =================
365 */
366 void GetSelectionIndex (int *ent, int *brush)
367 {
368         brush_t         *b, *b2;
369         entity_t        *entity;
370
371         *ent = *brush = 0;
372
373         b = selected_brushes.next;
374         if (b == &selected_brushes)
375                 return;
376
377         // find entity
378         if (b->owner != world_entity)
379         {
380                 (*ent)++;
381                 for (entity = entities.next ; entity != &entities 
382                         ; entity=entity->next, (*ent)++)
383                 ;
384         }
385
386         // find brush
387         for (b2=b->owner->brushes.onext 
388                 ; b2 != b && b2 != &b->owner->brushes
389                 ; b2=b2->onext, (*brush)++)
390         ;
391 }
392
393 BOOL CALLBACK FindBrushDlgProc (
394     HWND hwndDlg,       // handle to dialog box
395     UINT uMsg,  // message
396     WPARAM wParam,      // first message parameter
397     LPARAM lParam       // second message parameter
398    )
399 {
400         char entstr[256];
401         char brushstr[256];
402         HWND    h;
403         int             ent, brush;
404
405         switch (uMsg)
406     {
407         case WM_INITDIALOG:
408                 // set entity and brush number
409                 GetSelectionIndex (&ent, &brush);
410                 sprintf (entstr, "%i", ent);
411                 sprintf (brushstr, "%i", brush);
412                 SetWindowText(GetDlgItem(hwndDlg, IDC_FIND_ENTITY), entstr);
413                 SetWindowText(GetDlgItem(hwndDlg, IDC_FIND_BRUSH), brushstr);
414
415                 h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
416                 SetFocus (h);
417                 return FALSE;
418
419         case WM_COMMAND: 
420                 switch (LOWORD(wParam)) 
421                 { 
422                         case IDOK:
423                                 GetWindowText(GetDlgItem(hwndDlg, IDC_FIND_ENTITY), entstr, 255);
424                                 GetWindowText(GetDlgItem(hwndDlg, IDC_FIND_BRUSH), brushstr, 255);
425                                 SelectBrush (atoi(entstr), atoi(brushstr));
426                                 EndDialog(hwndDlg, 1);
427                                 return TRUE;
428
429                         case IDCANCEL:
430                                 EndDialog(hwndDlg, 0);
431                                 return TRUE;
432                 }       
433         }
434         return FALSE;
435 }
436
437
438
439 void DoFind(void)
440 {
441         DialogBox(g_qeglobals.d_hInstance, (char *)IDD_FINDBRUSH, g_pParentWnd->GetSafeHwnd(), FindBrushDlgProc);
442 }       
443         
444 /*
445 ===================================================
446
447   ARBITRARY ROTATE
448
449 ===================================================
450 */
451
452
453 BOOL CALLBACK RotateDlgProc (
454     HWND hwndDlg,       // handle to dialog box
455     UINT uMsg,  // message
456     WPARAM wParam,      // first message parameter
457     LPARAM lParam       // second message parameter
458    )
459 {
460         char    str[256];
461         HWND    h;
462         float   v;
463
464         switch (uMsg)
465     {
466         case WM_INITDIALOG:
467                 h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
468                 SetFocus (h);
469                 return FALSE;
470
471         case WM_COMMAND: 
472                 switch (LOWORD(wParam)) 
473                 { 
474                 
475                 case IDOK:
476                         GetWindowText(GetDlgItem(hwndDlg, IDC_ROTX), str, 255);
477                         v = atof(str);
478                         if (v)
479                                 Select_RotateAxis (0, v);
480
481                         GetWindowText(GetDlgItem(hwndDlg, IDC_ROTY), str, 255);
482                         v = atof(str);
483                         if (v)
484                                 Select_RotateAxis (1, v);
485
486                         GetWindowText(GetDlgItem(hwndDlg, IDC_ROTZ), str, 255);
487                         v = atof(str);
488                         if (v)
489                                 Select_RotateAxis (2, v);
490
491                         EndDialog(hwndDlg, 1);
492                         return TRUE;
493
494                 case IDCANCEL:
495                         EndDialog(hwndDlg, 0);
496                         return TRUE;
497                 }       
498         }
499
500         return FALSE;
501 }
502
503
504
505 void DoRotate(void)
506 {
507         DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ROTATE, g_pParentWnd->GetSafeHwnd(), RotateDlgProc);
508 }
509                 
510 /*
511 ===================================================
512
513   ARBITRARY SIDES
514
515 ===================================================
516 */
517
518 bool g_bDoCone = false;
519 bool g_bDoSphere = false;
520 BOOL CALLBACK SidesDlgProc (
521     HWND hwndDlg,       // handle to dialog box
522     UINT uMsg,  // message
523     WPARAM wParam,      // first message parameter
524     LPARAM lParam       // second message parameter
525    )
526 {
527         char str[256];
528         HWND    h;
529
530         switch (uMsg)
531     {
532         case WM_INITDIALOG:
533                 h = GetDlgItem(hwndDlg, IDC_SIDES);
534                 SetFocus (h);
535                 return FALSE;
536
537         case WM_COMMAND: 
538                 switch (LOWORD(wParam)) { 
539                 
540                 case IDOK:
541                         GetWindowText(GetDlgItem(hwndDlg, IDC_SIDES), str, 255);
542       if (g_bDoCone)
543                           Brush_MakeSidedCone(atoi(str));
544       else if (g_bDoSphere)
545                           Brush_MakeSidedSphere(atoi(str));
546       else
547                           Brush_MakeSided (atoi(str));
548
549                         EndDialog(hwndDlg, 1);
550                 break;
551
552                 case IDCANCEL:
553                         EndDialog(hwndDlg, 0);
554                 break;
555         }       
556         default:
557                 return FALSE;
558         }
559 }
560
561
562 void DoSides(bool bCone, bool bSphere, bool bTorus)
563 {
564   g_bDoCone = bCone;
565   g_bDoSphere = bSphere;
566   //g_bDoTorus = bTorus;
567         DialogBox(g_qeglobals.d_hInstance, (char *)IDD_SIDES, g_pParentWnd->GetSafeHwnd(), SidesDlgProc);
568 }               
569
570
571 //======================================================================
572
573 /*
574 ===================
575 DoAbout
576 ===================
577 */
578 BOOL CALLBACK AboutDlgProc( HWND hwndDlg,
579                                                     UINT uMsg,
580                                                     WPARAM wParam,
581                                                     LPARAM lParam )
582 {
583         switch (uMsg)
584     {
585         case WM_INITDIALOG:
586                 {
587                         char buffer[1024];
588                         idStr::snPrintf(buffer, 1024, "DOOM Radiant Build %d\nCopyright ©1999-2004 Id Software, Inc.\n", BUILD_NUMBER);
589 //                      SetDlgItemText( hwndDlg, IDC_ABOUT_INFO, buffer);
590
591                         idStr::snPrintf( buffer, 1024, "Renderer:\t%s", qglGetString( GL_RENDERER ) );
592                         SetDlgItemText( hwndDlg, IDC_ABOUT_GLRENDERER, buffer );
593
594                         idStr::snPrintf( buffer, 1024, "Version:\t\t%s", qglGetString( GL_VERSION ) );
595                         SetDlgItemText( hwndDlg, IDC_ABOUT_GLVERSION, buffer );
596
597                         idStr::snPrintf( buffer, 1024, "Vendor:\t\t%s", qglGetString( GL_VENDOR ) );
598                         SetDlgItemText( hwndDlg, IDC_ABOUT_GLVENDOR, buffer);
599
600                         char extensions[4096];
601                         idStr::snPrintf( extensions, 4096, "%s", qglGetString( GL_EXTENSIONS ) );
602                         HWND hWndExtensions = GetDlgItem( hwndDlg, IDC_ABOUT_GLEXTENSIONS );
603
604                         char *start = extensions;
605                         char *end;
606                         do {
607                                 end = strchr(start, ' ');
608                                 if ( end ) {
609                                         *end = 0;
610                                 }
611                                 SendMessage( hWndExtensions, LB_ADDSTRING, 0, (LPARAM)start );
612                                 start = end + 1;
613                         } while ( end );
614                 }
615
616                 return TRUE;
617
618         case WM_CLOSE:
619                 EndDialog( hwndDlg, 1 );
620                 return TRUE;
621
622         case WM_COMMAND:
623                 if ( LOWORD( wParam ) == IDOK )
624                         EndDialog(hwndDlg, 1);
625                 return TRUE;
626         }
627         return FALSE;
628 }
629
630 void DoAbout(void)
631 {
632         DialogBox( g_qeglobals.d_hInstance, ( char * ) IDD_ABOUT, g_pParentWnd->GetSafeHwnd(), AboutDlgProc );
633 }
634
635