]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake2/extra/qe4/win_dlg.c
Merge branch 'NateEag-master-patch-12920' into 'master'
[xonotic/netradiant.git] / tools / quake2 / extra / qe4 / win_dlg.c
1 /*
2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
4
5 This file is part of Quake 2 Tools source code.
6
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 ===========================================================================
21 */
22
23 #include "qe3.h"
24
25 BOOL CALLBACK GammaDlgProc (
26     HWND hwndDlg,       // handle to dialog box
27     UINT uMsg,  // message
28     WPARAM wParam,      // first message parameter
29     LPARAM lParam       // second message parameter
30    )
31 {
32         char sz[256];
33
34         switch (uMsg)
35     {
36         case WM_INITDIALOG:
37                 sprintf(sz, "%1.1f", g_qeglobals.d_savedinfo.fGamma);
38                 SetWindowText(GetDlgItem(hwndDlg, IDC_G_EDIT), sz);
39                 return TRUE;
40         case WM_COMMAND:
41                 switch (LOWORD(wParam))
42                 {
43
44                 case IDOK:
45                         GetWindowText(GetDlgItem(hwndDlg, IDC_G_EDIT), sz, 255);
46                         g_qeglobals.d_savedinfo.fGamma = atof(sz);
47                         EndDialog(hwndDlg, 1);
48                         return TRUE;
49
50                 case IDCANCEL:
51                         EndDialog(hwndDlg, 0);
52                         return TRUE;
53                 }
54         }
55         return FALSE;
56 }
57
58
59
60 void DoGamma(void)
61 {
62         char *psz, sz[256];
63         if ( DialogBox(g_qeglobals.d_hInstance, (char *)IDD_GAMMA, g_qeglobals.d_hwndMain, GammaDlgProc))
64         {
65                 psz = ValueForKey(world_entity, "_wad");
66                 if (psz)
67                 {
68                         strcpy(sz, psz);
69                         Texture_Flush();
70                         Texture_ShowInuse();
71                 }
72         }
73 }
74
75 //================================================
76
77
78 void SelectBrush (int entitynum, int brushnum)
79 {
80         entity_t        *e;
81         brush_t         *b;
82         int                     i;
83
84         if (entitynum == 0)
85                 e = world_entity;
86         else
87         {
88                 e = entities.next;
89                 while (--entitynum)
90                 {
91                         e=e->next;
92                         if (e == &entities)
93                         {
94                                 Sys_Status ("No such entity.", 0);
95                                 return;
96                         }
97                 }
98         }
99
100         b = e->brushes.onext;
101         if (b == &e->brushes)
102         {
103                 Sys_Status ("No such brush.", 0);
104                 return;
105         }
106         while (brushnum--)
107         {
108                 b=b->onext;
109                 if (b == &e->brushes)
110                 {
111                         Sys_Status ("No such brush.", 0);
112                         return;
113                 }
114         }
115
116         Brush_RemoveFromList (b);
117         Brush_AddToList (b, &selected_brushes);
118
119
120         Sys_UpdateWindows (W_ALL);
121         for (i=0 ; i<3 ; i++)
122                 g_qeglobals.d_xy.origin[i] = (b->mins[i] + b->maxs[i])/2;
123
124         Sys_Status ("Selected.", 0);
125 }
126
127 /*
128 =================
129 GetSelectionIndex
130 =================
131 */
132 void GetSelectionIndex (int *ent, int *brush)
133 {
134         brush_t         *b, *b2;
135         entity_t        *entity;
136
137         *ent = *brush = 0;
138
139         b = selected_brushes.next;
140         if (b == &selected_brushes)
141                 return;
142
143         // find entity
144         if (b->owner != world_entity)
145         {
146                 (*ent)++;
147                 for (entity = entities.next ; entity != &entities
148                         ; entity=entity->next, (*ent)++)
149                 ;
150         }
151
152         // find brush
153         for (b2=b->owner->brushes.onext
154                 ; b2 != b && b2 != &b->owner->brushes
155                 ; b2=b2->onext, (*brush)++)
156         ;
157 }
158
159 BOOL CALLBACK FindBrushDlgProc (
160     HWND hwndDlg,       // handle to dialog box
161     UINT uMsg,  // message
162     WPARAM wParam,      // first message parameter
163     LPARAM lParam       // second message parameter
164    )
165 {
166         char entstr[256];
167         char brushstr[256];
168         HWND    h;
169         int             ent, brush;
170
171         switch (uMsg)
172     {
173         case WM_INITDIALOG:
174                 // set entity and brush number
175                 GetSelectionIndex (&ent, &brush);
176                 sprintf (entstr, "%i", ent);
177                 sprintf (brushstr, "%i", brush);
178                 SetWindowText(GetDlgItem(hwndDlg, IDC_FIND_ENTITY), entstr);
179                 SetWindowText(GetDlgItem(hwndDlg, IDC_FIND_BRUSH), brushstr);
180
181                 h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
182                 SetFocus (h);
183                 return FALSE;
184
185         case WM_COMMAND:
186                 switch (LOWORD(wParam))
187                 {
188                         case IDOK:
189                                 GetWindowText(GetDlgItem(hwndDlg, IDC_FIND_ENTITY), entstr, 255);
190                                 GetWindowText(GetDlgItem(hwndDlg, IDC_FIND_BRUSH), brushstr, 255);
191                                 SelectBrush (atoi(entstr), atoi(brushstr));
192                                 EndDialog(hwndDlg, 1);
193                                 return TRUE;
194
195                         case IDCANCEL:
196                                 EndDialog(hwndDlg, 0);
197                                 return TRUE;
198                 }
199         }
200         return FALSE;
201 }
202
203
204
205 void DoFind(void)
206 {
207         DialogBox(g_qeglobals.d_hInstance, (char *)IDD_FINDBRUSH, g_qeglobals.d_hwndMain, FindBrushDlgProc);
208 }
209
210 /*
211 ===================================================
212
213   ARBITRARY ROTATE
214
215 ===================================================
216 */
217
218
219 BOOL CALLBACK RotateDlgProc (
220     HWND hwndDlg,       // handle to dialog box
221     UINT uMsg,  // message
222     WPARAM wParam,      // first message parameter
223     LPARAM lParam       // second message parameter
224    )
225 {
226         char    str[256];
227         HWND    h;
228         float   v;
229
230         switch (uMsg)
231     {
232         case WM_INITDIALOG:
233                 h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
234                 SetFocus (h);
235                 return FALSE;
236
237         case WM_COMMAND:
238                 switch (LOWORD(wParam))
239                 {
240
241                 case IDOK:
242                         GetWindowText(GetDlgItem(hwndDlg, IDC_ROTX), str, 255);
243                         v = atof(str);
244                         if (v)
245                                 Select_RotateAxis (0, v);
246
247                         GetWindowText(GetDlgItem(hwndDlg, IDC_ROTY), str, 255);
248                         v = atof(str);
249                         if (v)
250                                 Select_RotateAxis (1, v);
251
252                         GetWindowText(GetDlgItem(hwndDlg, IDC_ROTZ), str, 255);
253                         v = atof(str);
254                         if (v)
255                                 Select_RotateAxis (2, v);
256
257                         EndDialog(hwndDlg, 1);
258                         return TRUE;
259
260                 case IDCANCEL:
261                         EndDialog(hwndDlg, 0);
262                         return TRUE;
263                 }
264         }
265
266         return FALSE;
267 }
268
269
270
271 void DoRotate(void)
272 {
273         DialogBox(g_qeglobals.d_hInstance, (char *)IDD_ROTATE, g_qeglobals.d_hwndMain, RotateDlgProc);
274 }
275
276 /*
277 ===================================================
278
279   ARBITRARY SIDES
280
281 ===================================================
282 */
283
284
285 BOOL CALLBACK SidesDlgProc (
286     HWND hwndDlg,       // handle to dialog box
287     UINT uMsg,  // message
288     WPARAM wParam,      // first message parameter
289     LPARAM lParam       // second message parameter
290    )
291 {
292         char str[256];
293         HWND    h;
294
295         switch (uMsg)
296     {
297         case WM_INITDIALOG:
298                 h = GetDlgItem(hwndDlg, IDC_FIND_ENTITY);
299                 SetFocus (h);
300                 return FALSE;
301
302         case WM_COMMAND:
303                 switch (LOWORD(wParam)) {
304
305                 case IDOK:
306                         GetWindowText(GetDlgItem(hwndDlg, IDC_SIDES), str, 255);
307                         Brush_MakeSided (atoi(str));
308
309                         EndDialog(hwndDlg, 1);
310                 break;
311
312                 case IDCANCEL:
313                         EndDialog(hwndDlg, 0);
314                 break;
315         }
316         default:
317                 return FALSE;
318         }
319 }
320
321
322
323 void DoSides(void)
324 {
325         DialogBox(g_qeglobals.d_hInstance, (char *)IDD_SIDES, g_qeglobals.d_hwndMain, SidesDlgProc);
326 }
327
328 //======================================================================
329
330 /*
331 ===================
332 DoAbout
333 ===================
334 */
335 BOOL CALLBACK AboutDlgProc( HWND hwndDlg,
336                                                     UINT uMsg,
337                                                     WPARAM wParam,
338                                                     LPARAM lParam )
339 {
340         switch (uMsg)
341     {
342         case WM_INITDIALOG:
343                 {
344                         char renderer[1024];
345                         char version[1024];
346                         char vendor[1024];
347                         char extensions[4096];
348
349                         sprintf( renderer, "Renderer:\t%s", glGetString( GL_RENDERER ) );
350                         sprintf( version, "Version:\t\t%s", glGetString( GL_VERSION ) );
351                         sprintf( vendor, "Vendor:\t\t%s", glGetString( GL_VENDOR ) );
352                         sprintf( extensions, "\n%s", glGetString( GL_EXTENSIONS ) );
353
354                         SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLRENDERER ),   renderer );
355                         SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLVERSION ),    version );
356                         SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLVENDOR ),     vendor );
357                         SetWindowText( GetDlgItem( hwndDlg, IDC_ABOUT_GLEXTENSIONS ), extensions );
358                 }
359                 return TRUE;
360
361         case WM_CLOSE:
362                 EndDialog( hwndDlg, 1 );
363                 return TRUE;
364
365         case WM_COMMAND:
366                 if ( LOWORD( wParam ) == IDOK )
367                         EndDialog(hwndDlg, 1);
368                 return TRUE;
369         }
370         return FALSE;
371 }
372
373 void DoAbout(void)
374 {
375         DialogBox( g_qeglobals.d_hInstance, ( char * ) IDD_ABOUT, g_qeglobals.d_hwndMain, AboutDlgProc );
376 }
377
378
379 /*
380 ===================================================
381
382   SURFACE INSPECTOR
383
384 ===================================================
385 */
386
387 texdef_t        g_old_texdef;
388 HWND            g_surfwin;
389 qboolean        g_changed_surface;
390
391 int     g_checkboxes[64] = {
392         IDC_CHECK1, IDC_CHECK2, IDC_CHECK3, IDC_CHECK4,
393         IDC_CHECK5, IDC_CHECK6, IDC_CHECK7, IDC_CHECK8,
394         IDC_CHECK9, IDC_CHECK10, IDC_CHECK11, IDC_CHECK12,
395         IDC_CHECK13, IDC_CHECK14, IDC_CHECK15, IDC_CHECK16,
396         IDC_CHECK17, IDC_CHECK18, IDC_CHECK19, IDC_CHECK20,
397         IDC_CHECK21, IDC_CHECK22, IDC_CHECK23, IDC_CHECK24,
398         IDC_CHECK25, IDC_CHECK26, IDC_CHECK27, IDC_CHECK28,
399         IDC_CHECK29, IDC_CHECK30, IDC_CHECK31, IDC_CHECK32,
400
401         IDC_CHECK33, IDC_CHECK34, IDC_CHECK35, IDC_CHECK36,
402         IDC_CHECK37, IDC_CHECK38, IDC_CHECK39, IDC_CHECK40,
403         IDC_CHECK41, IDC_CHECK42, IDC_CHECK43, IDC_CHECK44,
404         IDC_CHECK45, IDC_CHECK46, IDC_CHECK47, IDC_CHECK48,
405         IDC_CHECK49, IDC_CHECK50, IDC_CHECK51, IDC_CHECK52,
406         IDC_CHECK53, IDC_CHECK54, IDC_CHECK55, IDC_CHECK56,
407         IDC_CHECK57, IDC_CHECK58, IDC_CHECK59, IDC_CHECK60,
408         IDC_CHECK61, IDC_CHECK62, IDC_CHECK63, IDC_CHECK64
409  };
410
411 /*
412 ==============
413 SetTexMods
414
415 Set the fields to the current texdef
416 ===============
417 */
418 void SetTexMods(void)
419 {
420         char    sz[128];
421         texdef_t *pt;
422         int             i;
423
424         pt = &g_qeglobals.d_texturewin.texdef;
425
426         SendMessage (g_surfwin, WM_SETREDRAW, 0, 0);
427
428         SetWindowText(GetDlgItem(g_surfwin, IDC_TEXTURE), pt->name);
429
430         sprintf(sz, "%d", (int)pt->shift[0]);
431         SetWindowText(GetDlgItem(g_surfwin, IDC_HSHIFT), sz);
432
433         sprintf(sz, "%d", (int)pt->shift[1]);
434         SetWindowText(GetDlgItem(g_surfwin, IDC_VSHIFT), sz);
435
436         sprintf(sz, "%4.2f", pt->scale[0]);
437         SetWindowText(GetDlgItem(g_surfwin, IDC_HSCALE), sz);
438
439         sprintf(sz, "%4.2f", pt->scale[1]);
440         SetWindowText(GetDlgItem(g_surfwin, IDC_VSCALE), sz);
441
442         sprintf(sz, "%d", (int)pt->rotate);
443         SetWindowText(GetDlgItem(g_surfwin, IDC_ROTATE), sz);
444
445         sprintf(sz, "%d", (int)pt->value);
446         SetWindowText(GetDlgItem(g_surfwin, IDC_VALUE), sz);
447
448         for (i=0 ; i<32 ; i++)
449                 SendMessage(GetDlgItem(g_surfwin, g_checkboxes[i]), BM_SETCHECK, !!(pt->flags&(1<<i)), 0 );
450         for (i=0 ; i<32 ; i++)
451                 SendMessage(GetDlgItem(g_surfwin, g_checkboxes[32+i]), BM_SETCHECK, !!(pt->contents&(1<<i)), 0 );
452
453         SendMessage (g_surfwin, WM_SETREDRAW, 1, 0);
454         InvalidateRect (g_surfwin, NULL, true);
455 }
456
457
458 /*
459 ==============
460 GetTexMods
461
462 Reads the fields to get the current texdef
463 ===============
464 */
465 void GetTexMods(void)
466 {
467         char    sz[128];
468         texdef_t *pt;
469         int             b;
470         int             i;
471
472         pt = &g_qeglobals.d_texturewin.texdef;
473
474         GetWindowText (GetDlgItem(g_surfwin, IDC_TEXTURE), sz, 127);
475         strncpy (pt->name, sz, sizeof(pt->name)-1);
476         if (pt->name[0] <= ' ')
477         {
478                 strcpy (pt->name, "none");
479                 SetWindowText(GetDlgItem(g_surfwin, IDC_TEXTURE), pt->name);
480         }
481
482         GetWindowText (GetDlgItem(g_surfwin, IDC_HSHIFT), sz, 127);
483         pt->shift[0] = atof(sz);
484
485         GetWindowText (GetDlgItem(g_surfwin, IDC_VSHIFT), sz, 127);
486         pt->shift[1] = atof(sz);
487
488         GetWindowText(GetDlgItem(g_surfwin, IDC_HSCALE), sz, 127);
489         pt->scale[0] = atof(sz);
490
491         GetWindowText(GetDlgItem(g_surfwin, IDC_VSCALE), sz, 127);
492         pt->scale[1] = atof(sz);
493
494         GetWindowText(GetDlgItem(g_surfwin, IDC_ROTATE), sz, 127);
495         pt->rotate = atof(sz);
496
497         GetWindowText(GetDlgItem(g_surfwin, IDC_VALUE), sz, 127);
498         pt->value = atof(sz);
499
500         pt->flags = 0;
501         for (i=0 ; i<32 ; i++)
502         {
503                 b = SendMessage(GetDlgItem(g_surfwin, g_checkboxes[i]), BM_GETCHECK, 0, 0);
504                 if (b != 1 && b != 0)
505                         continue;
506                 pt->flags |= b<<i;
507         }
508
509         pt->contents = 0;
510         for (i=0 ; i<32 ; i++)
511         {
512                 b = SendMessage(GetDlgItem(g_surfwin, g_checkboxes[32+i]), BM_GETCHECK, 0, 0);
513                 if (b != 1 && b != 0)
514                         continue;
515                 pt->contents |= b<<i;
516         }
517
518         g_changed_surface = true;
519         Select_SetTexture(pt);
520 }
521
522 /*
523 =================
524 UpdateSpinners
525 =================
526 */
527 void UpdateSpinners(unsigned uMsg, WPARAM wParam, LPARAM lParam)
528 {
529         int nScrollCode;
530         HWND hwnd;
531         texdef_t *pt;
532
533         pt = &g_qeglobals.d_texturewin.texdef;
534
535         nScrollCode = (int) LOWORD(wParam);  // scroll bar value
536         hwnd = (HWND) lParam;       // handle of scroll bar
537
538         if ((nScrollCode != SB_LINEUP) && (nScrollCode != SB_LINEDOWN))
539                 return;
540
541         if (hwnd == GetDlgItem(g_surfwin, IDC_ROTATEA))
542         {
543                 if (nScrollCode == SB_LINEUP)
544                         pt->rotate += 45;
545                 else
546                         pt->rotate -= 45;
547
548                 if (pt->rotate < 0)
549                         pt->rotate += 360;
550
551                 if (pt->rotate >= 360)
552                         pt->rotate -= 360;
553         }
554
555         else if (hwnd == GetDlgItem(g_surfwin, IDC_HSCALEA))
556         {
557                 if (nScrollCode == SB_LINEDOWN)
558                         pt->scale[0] -= 0.1;
559                 else
560                         pt->scale[0] += 0.1;
561         }
562
563         else if (hwnd == GetDlgItem(g_surfwin, IDC_VSCALEA))
564         {
565                 if (nScrollCode == SB_LINEUP)
566                         pt->scale[1] += 0.1;
567                 else
568                         pt->scale[1] -= 0.1;
569         }
570
571         else if (hwnd == GetDlgItem(g_surfwin, IDC_HSHIFTA))
572         {
573                 if (nScrollCode == SB_LINEDOWN)
574                         pt->shift[0] -= 8;
575                 else
576                         pt->shift[0] += 8;
577         }
578
579         else if (hwnd == GetDlgItem(g_surfwin, IDC_VSHIFTA))
580         {
581                 if (nScrollCode == SB_LINEUP)
582                         pt->shift[1] += 8;
583                 else
584                         pt->shift[1] -= 8;
585         }
586
587         SetTexMods();
588         g_changed_surface = true;
589         Select_SetTexture(pt);
590 }
591
592
593
594 BOOL CALLBACK SurfaceDlgProc (
595     HWND hwndDlg,       // handle to dialog box
596     UINT uMsg,  // message
597     WPARAM wParam,      // first message parameter
598     LPARAM lParam       // second message parameter
599    )
600 {
601         switch (uMsg)
602     {
603         case WM_INITDIALOG:
604                 g_surfwin = hwndDlg;
605                 SetTexMods ();
606                 return FALSE;
607
608         case WM_COMMAND:
609                 switch (LOWORD(wParam)) {
610
611                 case IDOK:
612                         GetTexMods ();
613                         EndDialog(hwndDlg, 1);
614                 break;
615
616                 case IDAPPLY:
617                         GetTexMods ();
618                         InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false);
619                         UpdateWindow (g_qeglobals.d_hwndCamera);
620                 break;
621
622                 case IDCANCEL:
623                         g_qeglobals.d_texturewin.texdef = g_old_texdef;
624                         if (g_changed_surface)
625                                 Select_SetTexture(&g_qeglobals.d_texturewin.texdef);
626                         EndDialog(hwndDlg, 0);
627                 break;
628                 }
629                 break;
630
631         case WM_HSCROLL:
632         case WM_VSCROLL:
633                 UpdateSpinners(uMsg, wParam, lParam);
634                 InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false);
635                 UpdateWindow (g_qeglobals.d_hwndCamera);
636                 return 0;
637
638         default:
639                 return FALSE;
640         }
641 }
642
643
644
645 void DoSurface (void)
646 {
647         // save current state for cancel
648         g_old_texdef = g_qeglobals.d_texturewin.texdef;
649         g_changed_surface = false;
650
651         DialogBox(g_qeglobals.d_hInstance, (char *)IDD_SURFACE, g_qeglobals.d_hwndMain, SurfaceDlgProc);
652 }
653