]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/preferences.cpp
Adding "Preferences" -> "Other" -> "Brush" tab. This now has
[xonotic/netradiant.git] / radiant / preferences.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 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 GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 //
23 // User preferences
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include "stdafx.h"
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <assert.h>
32 #if defined (__linux__) || defined (__APPLE__)
33 #include <sys/stat.h>
34 #include <sys/types.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <dirent.h>
38 #endif
39 #include "missing.h"
40 #include "gtkmisc.h"
41
42 #ifdef _WIN32
43         // sanity check - some gtk2 win32 runtimes replace sprintf
44         #if defined( sprintf )
45                 #error sprintf is a macro. are you sure?
46         #endif
47 #endif
48
49 #ifdef _WIN32
50 #include <io.h>
51 #define X_OK 0
52 #include <sys/stat.h>
53 #endif
54
55 #define PREF_SECTION            "Prefs"
56 #define INTERNAL_SECTION        "Internals"
57 #define MOUSE_KEY               "MouseButtons"
58 #define WINDOW_KEY              "QE4StyleWindows"
59 #define LAYOUT_KEY              "WindowLayout"
60 #define RUNQ2_KEY               "RunQuake2Run"
61 #define TLOCK_KEY               "TextureLock"
62 #define RLOCK_KEY               "RotateLock"
63 #define LOADLAST_KEY            "LoadLast"
64 #define LOADLASTMAP_KEY         "LoadLastMap"
65 #define LASTPROJ_KEY            "LastProject"
66 #define LASTPROJVER_KEY         "LastProjectKey"
67 #define LASTMAP_KEY             "LastMap"
68 #define FACE_KEY                "NewFaceGrab"
69 #define BSP_KEY                 "InternalBSP"
70 #define RCLICK_KEY              "NewRightClick"
71 #define VERTEX_KEY              "NewVertex"
72 #define AUTOSAVE_KEY            "Autosave"
73 #define AUTOSAVETIME_KEY        "AutosaveMinutes"
74 #define PAK_KEY                 "UsePAK"
75 #define NEWAPPLY_KEY            "ApplyDismissesSurface"
76 #define HACK_KEY                "Gatewayescapehack"
77 #define TEXTURE_KEY             "NewTextureWindowStuff"
78 #define TINYBRUSH_KEY           "CleanTinyBrushes"
79 #define TINYSIZE_KEY            "CleanTinyBrusheSize"
80 #define SNAPSHOT_KEY            "Snapshots"
81 #define MOVESPEED_KEY           "MoveSpeed"
82 #define ANGLESPEED_KEY          "AngleSpeed"
83 #define SETGAME_KEY             "UseSetGame"
84 #define CAMXYUPDATE_KEY         "CamXYUpdate"
85 #define CAMDRAGMULTISELECT_KEY  "CamDragMultiSelect"
86 #define CAMFREELOOK_KEY         "CamFreeLook"
87 #define CAMINVERSEMOUSE_KEY         "CamInverseMouse"
88 #define CAMDISCRETE_KEY         "CamDiscrete"
89 #define LIGHTDRAW_KEY           "NewLightStyle"
90 #define WHATGAME_KEY            "WhichGame"
91 #define CUBICCLIP_KEY           "CubicClipping"
92 #define CUBICSCALE_KEY          "CubicScale"
93 #define ALTEDGE_KEY             "ALTEdgeDrag"
94 #define FACECOLORS_KEY          "FaceColors"
95 #define SNAPT_KEY               "SnapT"
96 #define XZVIS_KEY               "XZVIS"
97 #define YZVIS_KEY               "YZVIS"
98 #define ZVIS_KEY                "ZVIS"
99 #define SIZEPAINT_KEY           "SizePainting"
100 #define DLLENTITIES_KEY         "DLLEntities"
101 #define DETACHABLEMENUS_KEY     "DetachableMenus"
102 #define PATCHTOOLBAR_KEY        "PatchToolBar"
103 #define WIDETOOLBAR_KEY         "WideToolBar"
104 #define PLUGINTOOLBAR_KEY "PluginToolBar"
105 #define NOCLAMP_KEY             "NoClamp"
106 #define SNAP_KEY                "Snap"
107 #define PREFAB_KEY              "PrefabPath"
108 #define USERINI_KEY             "UserINIPath"
109 #define ROTATION_KEY            "Rotation"
110 #define BUGGYICD_KEY            "BuggyICD"
111 #define CHASEMOUSE_KEY          "ChaseMouse"
112 #define ENTITYSHOW_KEY          "EntityShow"
113 #define TEXTURESCALE_KEY        "TextureScale"
114 #define TEXTURESCROLLBAR_KEY    "TextureScrollbar"
115 #define DISPLAYLISTS_KEY        "UseDisplayLists"
116 #define ANTIALIASEDLINES_KEY    "UseAntialiasedPointsAndLines" // Fishman - Add antialiazed points and lines support. 09/03/00
117 #define NORMALIZECOLORS_KEY     "NormalizeColors"
118 #define SHADERS_KEY             "UseShaders"
119 #define SWITCHCLIP_KEY          "SwitchClipKey"
120 #define SELWHOLEENTS_KEY                    "SelectWholeEntitiesKey"
121 #define TEXTURESUBSET_KEY                 "UseTextureSubsetLoading"
122 #define TEXTUREQUALITY_KEY          "TextureQuality"
123 #define SHOWSHADERS_KEY               "ShowShaders"
124 #define SHADERTEST_KEY          "ShaderTest"
125 #define GLLIGHTING_KEY          "UseGLLighting"
126 #define LOADSHADERS_KEY         "LoadShaders"
127 #define NOSTIPPLE_KEY           "NoStipple"
128 #define UNDOLEVELS_KEY          "UndoLevels"
129 #define VERTEXMODE_KEY          "VertexSplit"
130 #define ENGINEPATH_KEY          "EnginePath"
131 #define ENGINE_KEY              "Engine"
132 #define LOGCONSOLE_KEY          "LogConsole"
133 #define SELECTCURVES_KEY        "SelectCurves"
134 #define SELECTMODELS_KEY        "SelectModels"
135 #define SHADERLISTONLY_KEY      "ShowShaderlistOnly"
136 #define WATCHBSP_KEY            "WatchBSP"
137 #define LEAKSTOP_KEY            "LeakStop"
138 #define DOSLEEP_KEY             "SleepMode"
139 #define SUBDIVISIONS_KEY        "Subdivisions"
140 #define DEFAULTTEXURESCALE_KEY  "DefaultTextureScale"
141 #define CLIPCAULK_KEY           "ClipCaulk"
142 #define PATCHSHOWBOUNDS_KEY     "PatchShowBounds"
143 #define NATIVEGUI_KEY           "NativeGUI"
144 #define STARTONPRIMMON_KEY      "StartOnPrimMon"
145 #define NOSYSMENUPOPUPS_KEY     "NoSysMenuPopups"
146 #define SNAPTTOGRID_KEY         "SnapTToGrid"
147 #define FLOATINGZ_KEY           "FloatingZ"
148 #define TARGETFIX_KEY           "TargetFix"
149 #define GLPOINTWORKAROUND_KEY   "GlPointWorkaround"             // Gef: Workaround for broken Kyro * gl driver 25-aug-2001
150 #define WHEELINC_KEY            "WheelMouseInc"
151 #define PATCHBBOXSEL_KEY        "PatchBBoxSel"
152 #define LASTLIGHTINTENSITY_KEY  "LastLightIntensity"
153 #define CUSTOMSHADEREDITOR_KEY        "UseCustomShaderEditor"
154 #define CUSTOMSHADEREDITORCOMMAND_KEY "CustomShaderEditorCommand"
155 #define TEXTURECOMPRESSIONFORMAT_KEY "TextureCompressionFormat"
156 #define LIGHTRADIUS_KEY "LightRadiuses"
157 #define Q3MAP2TEX_KEY "Q3Map2Tex"
158 #define ATIHACK_KEY "ATIHack"
159
160 // window stuff
161 #define ENTITYSPLIT1_KEY  "EntitySplit1"
162 #define ENTITYSPLIT2_KEY  "EntitySplit2"
163 #define POSITIONX_KEY     "PositionX"
164 #define POSITIONY_KEY     "PositionY"
165 #define ENTITYWND_KEY     "EntityWnd"
166 #define MAPINFOWND_KEY    "MapInfoDlg"
167 #define CAMWND_KEY        "CamWnd"
168 #define ZWND_KEY          "ZWnd"
169 #define XYWND_KEY         "XYWnd"
170 #define XZWND_KEY         "XZWnd"
171 #define YZWND_KEY         "YZWnd"
172 #define PATCHWND_KEY      "PatchWnd"
173 #define SURFACEWND_KEY    "SurfaceWnd"
174 #define ENTITYINFOWND_KEY "EntityInfoDlg"
175 #define WIDTH_KEY         "Width"
176 #define HEIGHT_KEY        "Height"
177 #define ZWIDTH_KEY        "ZWidth"
178 #define XYHEIGHT_KEY      "XYHeight"
179 #define XYWIDTH_KEY       "XYWidth"
180 #define CAMWIDTH_KEY      "CamWidth"
181 #define CAMHEIGHT_KEY     "CamHeight"
182 #define ZFLOATWIDTH_KEY   "ZWidthFloating"
183 #define STATE_KEY         "State"
184
185 // menu stuff
186 #define COUNT_KEY         "Count"
187 #define FILE_KEY          "File"
188
189 //saved info
190 #define SI_TEXMENU_KEY          "SI_TexMenu"
191 #define SI_GAMMA_KEY            "SI_Gamma"
192 #define SI_COLORS_KEY           "SI_Colors"
193 #define SI_EXCLUDE_KEY          "SI_Exclude"
194 #define SI_INCLUDE_KEY          "SI_Include"
195 #define SI_SURFACE_TEXDEF_KEY   "SI_SurfaceTexdef"
196 #define SI_PATCH_TEXDEF_KEY     "SI_PatchTexdef"
197 #define SI_AXISCOLORS_KEY       "SI_AxisColors"
198 #define SI_SHOWNAMES_KEY        "SI_ShowNames"
199 #define SI_SHOWCOORDS_KEY       "SI_ShowCoords"
200 #define SI_SHOWANGLES_KEY       "SI_ShowAngles"
201 #define SI_SHOWOUTLINES_KEY     "SI_ShowOutlines"
202 #define SI_SHOWAXIS_KEY         "SI_ShowAxis"
203 #define SI_NOSELOUTLINES_KEY    "SI_NoSelectedOutlines"
204 #define SI_OUTLINESTYLE_KEY "SI_OutLineStyle"
205
206 //for texdefs
207 #define TD_SCALE1_KEY           "_Scale1"
208 #define TD_SCALE2_KEY           "_Scale2"
209 #define TD_SHIFT1_KEY           "_Shift1"
210 #define TD_SHIFT2_KEY           "_Shift2"
211 #define TD_ROTATE_KEY           "_Rotate"
212
213 #define MOUSE_DEF 1
214 #define WINDOW_DEF 0
215 #define RUNQ2_DEF 0
216 #define WATCHBSP_DEF 1
217 #define TLOCK_DEF 1
218 #define LOADLAST_DEF 1
219 #define RUN_DEF 0
220 #define SUBDIVISIONS_DEF 4
221
222 void WindowPosition_Parse(window_position_t& m_value, const CString& value)
223 {
224   if(sscanf(value.GetBuffer(), "%d %d %d %d", &m_value.x, &m_value.y, &m_value.w, &m_value.h) != 4)
225     m_value.x = m_value.y = m_value.w = m_value.h = -1;
226 }
227
228 void WindowPosition_Write(const window_position_t& m_value, CString& value)
229 {
230   char buffer[64];
231   sprintf(buffer, "%d %d %d %d", m_value.x, m_value.y, m_value.w, m_value.h);
232   value = buffer;
233 }
234
235
236 CXMLPropertyBag::CXMLPropertyBag() {
237   mStrFilename = "";
238   mpDoc = NULL;
239   mbEmpty = false;
240 }
241
242 // generic preference functions
243
244 void CXMLPropertyBag::PushAssignment(const char *name, PrefTypes_t type, void *pV)
245 {
246   list<CPrefAssignment>::iterator iAssign;
247   for(iAssign=mPrefAssignments.begin(); iAssign!=mPrefAssignments.end(); iAssign++)
248   {
249     if ((*iAssign).mName == name)
250     {
251       // we have it already, check anyway
252       if (pV != (*iAssign).mVal)
253       {
254         Sys_FPrintf(SYS_ERR, "PushAssignment, '%s' has different mVal\n", name);
255         return;
256       }
257     }
258   }
259   // ok, it's not in our list yet
260   mPrefAssignments.push_front(CPrefAssignment(name, type, pV));
261 }
262
263 xmlNodePtr CXMLPropertyBag::EpairForName(const char *name)
264 {
265   xmlNodePtr ret = NULL;
266
267   xmlNodePtr pNode = mpDocNode->children;
268   while (pNode != NULL)
269   {
270     if(pNode->type == XML_ELEMENT_NODE)
271     {
272       xmlAttrPtr tmp_attr_ptr = xmlHasProp(pNode, (xmlChar *)"name");
273       if (tmp_attr_ptr != NULL && !strcmp(name, (char *)tmp_attr_ptr->children->content))
274       {
275         if ( ret ) {
276           Sys_FPrintf( SYS_WRN, "WARNING: dupe property in CXMLPropertyBag::EpairForName '%s'\n", name );
277         } else {
278           ret = pNode;
279         }
280       }
281     }
282     pNode = pNode->next;
283   }
284   return ret;
285 }
286
287 void CXMLPropertyBag::GetPref(const char *name, Str *pV, const char *V)
288 {
289   xmlNodePtr pNode = EpairForName( name );
290   if ( pNode )
291   {
292     if ( pNode->children && pNode->children->content ) {
293       *pV = pNode->children->content;
294     } else {
295       // means the pref exists, and that the value is ""
296       *pV = "";
297     }
298   }
299   else
300   {
301     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)V);
302     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
303   }
304   // push the pref assignment if needed
305   PushAssignment(name, PREF_STR, pV);
306 }
307
308 void CXMLPropertyBag::GetPref(const char *name, int *pV, int V)
309 {
310   xmlNodePtr pNode;
311   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
312   {
313     *pV = atoi((char *)pNode->children->content);
314   }
315   else
316   {
317     char s[10];
318     sprintf(s, "%d", V);
319     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s);
320     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
321     *pV=V;
322   }
323   // push the pref assignment if needed
324   PushAssignment(name, PREF_INT, pV);
325 }
326
327 void CXMLPropertyBag::GetPref(const char *name, bool *pV, bool V)
328 {
329   xmlNodePtr pNode;
330   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
331   {
332     if (!strcmp((char *)pNode->children->content, "true"))
333     {
334       *pV = true;
335     }
336     else
337     {
338       *pV = false;
339     }
340   }
341   else
342   {
343     char s[10];
344     V ? strcpy(s, "true") : strcpy(s, "false");
345     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s);
346     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
347     *pV=V;
348   }
349   // push the pref assignment
350   PushAssignment(name, PREF_BOOL, pV);
351 }
352
353 void CXMLPropertyBag::GetPref(const char *name, float *pV, float V)
354 {
355   xmlNodePtr pNode;
356   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
357   {
358     *pV = atof((char *)pNode->children->content);
359   }
360   else
361   {
362     char s[10];
363     sprintf(s, "%f", V);
364     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s);
365     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
366     *pV=V;
367   }
368   // push the pref assignment if needed
369   PushAssignment(name, PREF_FLOAT, pV);
370 }
371
372 void CXMLPropertyBag::GetPref(const char *name, float* pV, float* V)
373 {
374   xmlNodePtr pNode;
375   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
376   {
377     sscanf((char *)pNode->children->content, "%f %f %f", &pV[0], &pV[1], &pV[2]);
378   }
379   else
380   {
381     char s[128];
382     sprintf(s, "%f %f %f", V[0], V[1], V[2]);
383     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)s);
384     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
385     pV[0] = V[0];
386     pV[1] = V[1];
387     pV[2] = V[2];
388   }
389   // push the pref assignment if needed
390   PushAssignment(name, PREF_VEC3, pV);
391 }
392
393 void CXMLPropertyBag::GetPref(const char *name, window_position_t* pV, window_position_t V)
394 {
395   xmlNodePtr pNode;
396   if ((pNode = EpairForName(name)) && pNode->children && pNode->children->content)
397   {
398     WindowPosition_Parse(*pV, CString((xmlChar *)pNode->children->content));
399   }
400   else
401   {
402     CString str;
403     WindowPosition_Write(V, str);
404     pNode = xmlNewChild(mpDocNode, NULL, (xmlChar *)"epair", (xmlChar *)str.GetBuffer());
405     xmlSetProp(pNode, (xmlChar *)"name", (xmlChar *)name);
406     *pV = V;
407   }
408   // push the pref assignment if needed
409   PushAssignment(name, PREF_WNDPOS, pV);
410 }
411
412 void CXMLPropertyBag::UpdatePrefTree()
413 {
414   // read the assignments and update the tree
415   list<CPrefAssignment>::iterator iPref;
416   for(iPref = mPrefAssignments.begin(); iPref != mPrefAssignments.end(); iPref++)
417   {
418     CPrefAssignment *pPref = &(*iPref);
419     // look for the node
420     xmlNodePtr pNode;
421     char s[64];
422
423     pNode = EpairForName(pPref->mName.GetBuffer());
424     // we never expect that the node could not be found, because this is supposed to happen
425     // after the tree was built with GetPref calls, never on a blank tree
426     if (!pNode)
427     {
428       Sys_FPrintf(SYS_ERR, "Unexpected EpairForName '%s' not found in UpdatePrefTree\n", pPref->mName.GetBuffer());
429       return;
430     }
431     switch ((*iPref).mType)
432     {
433     case PREF_STR:
434       xmlNodeSetContent(pNode, (const xmlChar *)((Str *)pPref->mVal)->GetBuffer());
435       break;
436     case PREF_INT:
437       sprintf(s, "%d", *(int *)pPref->mVal);
438       xmlNodeSetContent(pNode, (xmlChar *)s);
439       break;
440     case PREF_FLOAT:
441       sprintf(s, "%f", *(float *)pPref->mVal);
442       xmlNodeSetContent(pNode, (xmlChar *)s);
443       break;
444     case PREF_BOOL:
445       *(bool *)pPref->mVal ? strcpy(s, "true") : strcpy(s, "false");
446       xmlNodeSetContent(pNode, (xmlChar *)s);
447       break;
448     case PREF_VEC3:
449       {
450         float* v = (float*)pPref->mVal;
451         sprintf(s, "%f %f %f", v[0], v[1], v[2]);
452         xmlNodeSetContent(pNode, (xmlChar *)s);
453       }
454       break;
455     case PREF_WNDPOS:
456       {
457         CString str;
458         WindowPosition_Write(*(window_position_t*)pPref->mVal, str);
459         xmlNodeSetContent(pNode, (xmlChar*)str.GetBuffer());
460       }
461       break;
462     }
463   }
464 }
465
466 void CXMLPropertyBag::Clear()
467 {
468   if(!InUse())
469     return;
470
471   xmlFreeDoc(mpDoc);
472   mpDoc = NULL;
473   mpDocNode = NULL;
474   mbEmpty = false;
475 }
476
477 void CXMLPropertyBag::ReadXMLFile(const char* pFilename)
478 {
479   mpDoc = xmlParseFile(pFilename);
480
481   // basic checks
482   if (mpDoc)
483   {
484     mpDocNode = mpDoc->children;
485     xmlAttrPtr tmp_attr_ptr = xmlHasProp(mpDocNode, (xmlChar *)"version");
486     if (strcmp((char *)mpDocNode->name, "qpref"))
487     {
488       Sys_FPrintf(SYS_ERR, "Unrecognized node '%s' in '%s'\n", mpDocNode->name, mpDoc->URL);
489       xmlFreeDoc(mpDoc);
490       mpDoc = NULL;
491     }
492     else if (tmp_attr_ptr != NULL && strcmp((char*)tmp_attr_ptr->children->content, "1"))
493     {
494       Sys_FPrintf(SYS_ERR, "Wrong version '%s' in <qpref> node for '%s'\n", (char*)tmp_attr_ptr->children->content, mpDoc->URL);
495       xmlFreeDoc(mpDoc);
496       mpDoc = NULL;
497     }
498     Sys_Printf("Opened XML property file: '%s'\n", pFilename);
499   }
500
501   if (!mpDoc)
502   {
503     mbEmpty = true;
504     // no document, create one
505     mpDoc = xmlNewDoc((xmlChar *)"1.0");
506     mpDocNode = xmlNewDocNode(mpDoc, NULL, (xmlChar *)"qpref", NULL);
507     xmlDocSetRootElement(mpDoc, mpDocNode);
508     xmlSetProp(mpDocNode, (xmlChar *)"version", (xmlChar *)"1");
509     Sys_Printf("XML property file '%s' invalid/not found, creating blank properties tree\n", pFilename);
510   }
511 }
512
513 qboolean CXMLPropertyBag::WriteXMLFile(const char* pFilename)
514 {
515   int res = xmlSaveFormatFile(pFilename, mpDoc, 1);
516
517   if(res == -1)
518     return false;
519
520   Sys_Printf("Wrote XML property file '%s'\n", pFilename);
521   return true;
522 }
523
524 // =============================================================================
525 // Widget callbacks for PrefsDlg
526
527 #if !defined(WIN32)
528 // browse for custom editor executable
529 static void OnBtnBrowseEditor (GtkWidget *widget, gpointer data)
530 {
531   PrefsDlg *dlg = (PrefsDlg*)data;
532
533   const char *filename = file_dialog(g_PrefsDlg.GetWidget(), TRUE, _("Executable for Custom Editor"));
534
535   if(filename != NULL)
536   {
537     dlg->m_strEditorCommand = filename;
538     dlg->UpdateData(FALSE);
539   }
540 }
541 #endif
542
543 static void OnBtnBrowseprefab (GtkWidget *widget, gpointer data)
544 {
545   PrefsDlg *dlg = (PrefsDlg*)data;
546   char *path = dlg->m_strPrefabPath;
547   if (strlen (path) == 0)
548     path = g_strGameToolsPath;
549   char *dir = dir_dialog (g_PrefsDlg.GetWidget (), _("Set prefab path"), path);
550   dlg->UpdateData(TRUE);
551
552   if (dir != NULL)
553   {
554     CString strPath;
555     strPath = dir;
556     AddSlash(strPath);
557     dlg->m_strPrefabPath = strPath;
558     dlg->UpdateData(FALSE);
559     free (dir);
560   }
561 }
562
563 static void OnBtnBrowseuserini (GtkWidget *widget, gpointer data)
564 {
565   PrefsDlg *dlg = (PrefsDlg*)data;
566   char *path = dlg->m_strUserPath;
567   if (strlen (path) == 0)
568     path = g_strGameToolsPath;
569   // TODO: INI filter?
570   const char *filename = file_dialog (g_PrefsDlg.GetWidget(), TRUE, _("Find INI file"), path);
571
572   if (filename != NULL)
573   {
574     dlg->UpdateData(TRUE);
575     dlg->m_strUserPath = filename;
576     dlg->UpdateData(FALSE);
577   }
578 }
579
580 static void OnButtonClean (GtkWidget *widget, gpointer data)
581 {
582   // make sure this is what the user wants
583   if (gtk_MessageBox (g_PrefsDlg.GetWidget (), _("This will close Radiant and clean the corresponding registry entries.\n"
584                   "Next time you start Radiant it will be good as new. Do you wish to continue?"),
585                   _("Reset Registry"), MB_YESNO) == IDYES)
586   {
587     PrefsDlg *dlg = (PrefsDlg*)data;
588     dlg->EndModal (IDCANCEL);
589
590     g_qeglobals.disable_ini = true;
591     remove (dlg->m_inipath->str);
592     char buf[PATH_MAX];
593     sprintf(buf, "%sSavedInfo.bin", dlg->m_rc_path->str);
594     remove(buf);
595     HandleCommand (NULL, GINT_TO_POINTER (ID_FILE_EXIT));
596     _exit (0);
597   }
598 }
599
600 // =============================================================================
601 // PrefsDlg class
602
603 // IMPORTANT NOTE: the values here don't matter very much
604 // the actual intialization if you start with an empty .ini is done when loading the prefs for the first time
605 // profile_load_int takes an argument to use if the value is not found
606 PrefsDlg::PrefsDlg ()
607 {
608   m_bWarn = TRUE;
609   m_nMouse = 1;
610   m_nView = MainFrame::eRegular;
611   m_bLoadLast = FALSE;
612   m_bInternalBSP = FALSE;
613   m_bRightClick = FALSE;
614   m_bSetGame = FALSE;
615   m_bAutoSave = TRUE;
616   m_nAutoSave = 5;
617   m_bLoadLastMap = FALSE;
618   m_bTextureWindow = FALSE;
619   m_bSnapShots = FALSE;
620   m_fTinySize = 0.5;
621   m_bCleanTiny = FALSE;
622   m_bCamXYUpdate = TRUE;
623   m_bCamDragMultiSelect = FALSE;
624   m_bCamFreeLook = TRUE;
625   m_bCamFreeLookStrafe = FALSE;
626   m_bCamInverseMouse = FALSE;
627   m_bCamDiscrete = TRUE;
628   m_bNewLightDraw = FALSE;
629   m_strPrefabPath = "";
630   m_nWhatGame = 0;
631   m_bALTEdge = FALSE;
632   m_bFaceColors = FALSE;
633   m_bXZVis = FALSE;
634   m_bYZVis = FALSE;
635   m_bZVis = FALSE;
636   m_bSizePaint = FALSE;
637   m_bDLLEntities = FALSE;
638 #ifdef _WIN32
639   m_bDetachableMenus = FALSE;   // Most win32 users will find detachable menus annoying
640 #else
641   m_bDetachableMenus = TRUE;    // Linux/Apple users are used to them...
642 #endif
643   m_bPatchToolbar = TRUE;
644   m_bWideToolbar = TRUE;
645   m_bPluginToolbar = TRUE;
646   m_bNoClamp = FALSE;
647   m_bSnap = TRUE;
648   m_strUserPath = "";
649   m_nRotation = 0;
650   m_bChaseMouse = FALSE;
651   m_bTextureScrollbar = TRUE;
652   m_bDisplayLists = TRUE;
653   m_bAntialiasedPointsAndLines = FALSE; // Fishman - Add antialiazed points and lines support. 09/03/00
654   m_bShowShaders = FALSE;
655   m_nShader = -1;
656   m_bNoStipple = FALSE;
657   m_bVertexSplit = FALSE;
658   m_bSelectCurves = TRUE;
659   m_bSelectModels = TRUE;
660   m_nEntityShowState = ENTITY_SKINNED_BOXED;
661   m_nTextureScale = 2;
662   m_bSwitchClip = FALSE;
663   m_bSelectWholeEntities = TRUE;
664   m_nTextureQuality = 3;
665   m_bShowShaders = TRUE;
666   m_bGLLighting = FALSE;
667   m_nShader = 0;
668   m_nUndoLevels = 30;
669   m_bTexturesShaderlistOnly = FALSE;
670   // paths to ini files
671   m_rc_path = NULL;
672   m_inipath = NULL;
673   m_bWatchBSP = TRUE;
674   m_bLeakStop = TRUE;
675   m_iTimeout = 15;
676   m_bRunQuake = TRUE;
677   m_bDoSleep = FALSE;
678   m_nSubdivisions = 4;
679   // not prefs
680   m_bFloatingZ = FALSE;
681   m_bGlPtWorkaround = FALSE;    // Gef: Kyro/GL_POINTS workaround 25-aug-2001
682 #ifdef _WIN32
683   m_bNativeGUI = FALSE;
684   m_bStartOnPrimMon = FALSE;
685 #endif
686   m_global_rc_path = NULL;
687 #ifdef _WIN32
688   m_bUseWin32Editor = TRUE;
689 #else
690   // custom shader editor options
691   m_bUseCustomEditor = FALSE;
692   m_strEditorCommand = "";
693 #endif
694   m_nLightRadiuses = 1;
695   m_bQ3Map2Texturing = TRUE;
696 #ifdef ATIHACK_812
697         m_bGlATIHack = FALSE;
698 #endif
699 }
700
701 /*!
702 =========================================================
703 Games selection dialog
704 =========================================================
705 */
706
707 #if defined(WIN32)
708 #define TOOLS_ATTRIBUTE "gametools_win32"
709 #define ENGINE_ATTRIBUTE "engine_win32"
710 #define ENGINEPATH_ATTRIBUTE "enginepath_win32"
711 #define MP_ENGINE_ATTRIBUTE "mp_engine_win32"
712 #elif defined(__linux__) || defined (__FreeBSD__)
713 #define TOOLS_ATTRIBUTE "gametools_linux"
714 #define ENGINE_ATTRIBUTE "engine_linux"
715 #define ENGINEPATH_ATTRIBUTE "enginepath_linux"
716 #define MP_ENGINE_ATTRIBUTE "mp_engine_linux"
717 #elif defined(__APPLE__)
718 #define TOOLS_ATTRIBUTE "gametools_macos"
719 #define ENGINE_ATTRIBUTE "engine_macos"
720 #define ENGINEPATH_ATTRIBUTE "enginepath_macos"
721 #define MP_ENGINE_ATTRIBUTE "mp_engine_macos"
722 #else
723 #error "unsupported platform"
724 #endif
725
726 CGameDescription::CGameDescription(xmlDocPtr pDoc, const Str &GameFile)
727 {
728   char *p, *prop;
729   mpDoc = pDoc;
730   // read the user-friendly game name
731   xmlNodePtr pNode = mpDoc->children;
732
733   while (strcmp((const char*)pNode->name, "game") && pNode != NULL) pNode=pNode->next;
734   if (!pNode)
735   {
736     ///< \todo add the file name (this node and gametools should all be part of CGameDescription anyway)
737     Error("Didn't find 'game' node in the game description file '%s'\n", pDoc->URL);
738   }
739   // on win32, game tools path can now be specified relative to the exe's cwd
740   prop = (char*)xmlGetProp( pNode, (xmlChar*)TOOLS_ATTRIBUTE);
741   if ( prop == NULL ) {
742         Error( "Didn't find '"TOOLS_ATTRIBUTE"' node in the game description file '%s'\n", pDoc->URL );
743   }
744   {
745         char full[PATH_MAX];
746 #ifdef _WIN32
747         _fullpath( full, prop, PATH_MAX );
748 #else
749     strncpy( full, prop, PATH_MAX );
750 #endif
751     xmlFree( prop );
752     prop = NULL;
753     for ( p = full; *p != '\0'; p++ ) {
754           if ( *p == '\\' ) {
755             *p = '/';
756           }
757           mGameToolsPath = full;
758           if ( p != full && *(p-1) != '/' ) {
759             mGameToolsPath += "/";
760           }
761     }
762   }
763
764   prop = (char*)xmlGetProp(pNode, (xmlChar*)"name");
765   if (prop == NULL)
766   {
767     Sys_FPrintf(SYS_WRN, "Warning, 'name' attribute not found in '%s'\n", pDoc->URL);
768     mGameName = pDoc->URL;
769   }
770   else
771   {
772     mGameName = prop;
773     xmlFree(prop);
774   }
775
776   mGameFile = GameFile;
777
778   prop = (char*)xmlGetProp(pNode, (xmlChar*)"quake2");
779   if (prop == NULL)
780   {
781     // default
782     quake2 = false;
783   }
784   else
785   {
786     quake2 = true;
787     xmlFree(prop);
788   }
789
790   // if this is set, the open maps dialoge will open the engine path not the
791   // home dir for map loading and saving
792   prop = (char*)xmlGetProp(pNode, (xmlChar*)"no_maps_in_home");
793   if (prop == NULL)
794   {
795     // default
796     noMapsInHome = false;
797   }
798   else
799   {
800     noMapsInHome = true;
801     xmlFree(prop);
802   }
803
804   prop = (char*)xmlGetProp(pNode, (xmlChar*)"basegame");
805   if (prop == NULL)
806   {
807     // default
808     mBaseGame = "baseq3";
809   }
810   else
811   {
812     mBaseGame = prop;
813     xmlFree(prop);
814   }
815
816
817         prop = (char*)xmlGetProp(pNode, (const xmlChar*)ENGINE_ATTRIBUTE);
818         if (prop == NULL)
819         {
820 #ifdef _WIN32
821                 mEngine = "quake3.exe";
822 #elif __linux__
823                 mEngine = "quake3";
824 #elif __APPLE__
825                 mEngine = "Quake3.app";
826 #endif
827         }
828         else
829         {
830                 mEngine = prop;
831                 xmlFree(prop);
832         }
833
834         prop = (char*)xmlGetProp(pNode, (const xmlChar*)MP_ENGINE_ATTRIBUTE);
835         if (prop == NULL)
836         {
837 #ifdef _WIN32
838                 mMultiplayerEngine = "quake3.exe";
839 #elif __linux__
840                 mMultiplayerEngine = "quake3";
841 #elif __APPLE__
842                 mMultiplayerEngine = "Quake3.app";
843 #endif
844         }
845         else
846         {
847                 mMultiplayerEngine = prop;
848                 xmlFree(prop);
849         }
850
851         {
852                 // on win32, engine path can now be specified relative to the exe's cwd
853                 prop = (char*)xmlGetProp(pNode, (const xmlChar *)ENGINEPATH_ATTRIBUTE);
854                 if ( prop != NULL ) {
855                         char full[PATH_MAX];
856                 #ifdef _WIN32
857                         _fullpath( full, prop, PATH_MAX );
858                 #else
859                         strncpy( full, prop, PATH_MAX );
860                 #endif
861                         xmlFree( prop );
862                         prop = NULL;
863                         // process seperators
864                         for ( p = full; *p != '\0'; p++ ) {
865                                 if ( *p == '\\' ) {
866                                         *p = '/';
867                                 }
868                         }
869                         mEnginePath = full;
870                         if ( p != full && *(p-1) != '/' ) {
871                                 mEnginePath += "/";
872                         }
873                 }
874                 else
875                 {
876                         // if engine path was not specified in the .game, it implies we can guess it from the gametools path
877                         // on win32, and for most game package, the gametools are installed with the game
878                         char aux_path[PATH_MAX]; // aux
879                         strcpy( aux_path, mGameToolsPath.GetBuffer() );
880                         if ( ( aux_path[ strlen(aux_path)-1 ] == '/' ) || ( aux_path[ strlen(aux_path)-1 ] == '\\' ) ) {
881                                 aux_path[strlen(aux_path)-1] = '\0'; // strip ending '/' if any
882                         }
883                         char up_path[PATH_MAX]; // up one level
884                         ExtractFilePath( aux_path, up_path );
885                         mEnginePath = up_path;
886                 }
887         }
888
889 #if defined (__linux__) || defined (__APPLE__)
890   // *nix specific
891   prop = (char*)xmlGetProp(pNode, (const xmlChar *)"prefix");
892   if(prop != NULL)
893   {
894     mUserPathPrefix = prop;
895     xmlFree(prop);
896   }
897 #endif
898   mShaderPath = xmlGetProp(pNode, (const xmlChar *)"shaderpath");
899   if (!mShaderPath.GetLength())
900   {
901     mShaderPath = "scripts/";
902     mShaderlist = "scripts/shaderlist.txt";
903   }
904   else
905   {
906     AddSlash(mShaderPath);
907     mShaderlist = mShaderPath;
908     mShaderlist += "shaderlist.txt";
909   }
910   xmlChar* default_scale = xmlGetProp(pNode, (const xmlChar *)"default_scale");
911   if (default_scale)
912   {
913     mTextureDefaultScale = atof((const char *)default_scale);
914     xmlFree(default_scale);
915   }
916   else
917     mTextureDefaultScale = 0.5f;
918   xmlChar* eclass_singleload = xmlGetProp(pNode, (const xmlChar*)"eclass_singleload");
919   if (eclass_singleload)
920   {
921     mEClassSingleLoad = true;
922     xmlFree(eclass_singleload);
923   }
924   else
925     mEClassSingleLoad = false;
926   xmlChar* no_patch = xmlGetProp(pNode, (const xmlChar *)"no_patch");
927   if (no_patch)
928   {
929     mNoPatch = true;
930     xmlFree(no_patch);
931   }
932   else
933     mNoPatch = false;
934   xmlChar* caulk_shader = xmlGetProp(pNode, (const xmlChar *)"caulk_shader");
935   if (caulk_shader)
936   {
937     mCaulkShader = caulk_shader;
938     xmlFree(caulk_shader);
939   }
940   else
941     mCaulkShader = "textures/common/caulk";
942 }
943
944 void CGameDescription::Dump()
945 {
946 #ifdef _WIN32
947   if (CGameDialog::GetNetrun())
948     Sys_Printf("Running in network mode, prefs path set to '%s'\n", g_strTempPath.GetBuffer());
949 #endif
950   Sys_Printf("game name            : '%s'\n", mGameName.GetBuffer());
951   Sys_Printf("game file            : '%s'\n", mGameFile.GetBuffer());
952   Sys_Printf("game path            : '%s'\n", mGameToolsPath.GetBuffer());
953   Sys_Printf("base game            : '%s'\n", mBaseGame.GetBuffer());
954   Sys_Printf("engine path          : '%s'\n", mEnginePath.GetBuffer());
955   Sys_Printf("engine               : '%s'\n", mEngine.GetBuffer());
956   Sys_Printf("shaderlist           : '%s'\n", mShaderlist.GetBuffer());
957   Sys_Printf("caulk shader: '%s'\n", mCaulkShader.GetBuffer());
958 #if defined (__linux__) || defined (__APPLE__)
959   Sys_Printf("prefix               : '%s'\n", mUserPathPrefix.GetBuffer());
960 #endif
961   Sys_Printf("default texture scale: %g\n", mTextureDefaultScale);
962   Sys_Printf("single eclass load   : %s\n", mEClassSingleLoad ? "Yes" : "No");
963   Sys_Printf("patches supported    : %s\n", mNoPatch ? "No" : "Yes");
964 }
965
966 CPrefAssignment& CPrefAssignment::operator = (const CPrefAssignment& ass)
967 {
968   if (&ass != this)
969   {
970     mName = ass.mName;
971     mType = ass.mType;
972     mVal = ass.mVal;
973   }
974   return *this;
975 }
976
977 CPrefAssignment::CPrefAssignment(const CPrefAssignment& ass)
978 {
979   *this = ass;
980 }
981
982 void CGameDialog::LoadPrefs()
983 {
984   // if we already have a document loaded, we will free and reload from file
985   if (mGlobalPrefs.InUse())
986   {
987     Sys_Printf("Reloading global prefs from file\n");
988     mGlobalPrefs.Clear();
989   }
990
991   // load global .pref file
992   CString strGlobalPref = g_PrefsDlg.m_global_rc_path->str;
993   strGlobalPref += "global.pref";
994
995   mGlobalPrefs.ReadXMLFile(strGlobalPref.GetBuffer());
996
997   mGlobalPrefs.GetPref("gamefile", &m_sGameFile, ""); // NOTE: there's no default, user HAS to select something
998   mGlobalPrefs.GetPref("autoload", &m_bAutoLoadGame, false);
999   mGlobalPrefs.GetPref("log console", &m_bLogConsole, false);
1000   // in a very particular post-.pid startup
1001   // we may have the console turned on and want to keep it that way
1002   // so we use a latching system
1003   if (m_bForceLogConsole)
1004   {
1005     m_bLogConsole = true;
1006     Sys_Printf("console logging has been latched on, saving prefs\n");
1007     SavePrefs();
1008     m_bForceLogConsole = false;
1009   }
1010
1011   // console logging: call Sys_LogConsole to check console logging status
1012   // it is important that we would log console as early as possible to make it useful
1013   Sys_LogFile();
1014
1015   if (mGlobalPrefs.mbEmpty)
1016   {
1017     Sys_Printf("Saving global.pref with default pref values\n");
1018     SavePrefs();
1019   }
1020 }
1021
1022 void CGameDialog::SavePrefs()
1023 {
1024   // update the tree and save it
1025   mGlobalPrefs.UpdatePrefTree();
1026
1027   CString strGlobalPref = g_PrefsDlg.m_global_rc_path->str;
1028   strGlobalPref += "global.pref";
1029
1030   if ( !mGlobalPrefs.WriteXMLFile( strGlobalPref.GetBuffer() ) ) {
1031     Sys_FPrintf(SYS_ERR, "Error occured while saving global prefs file '%s'\n", strGlobalPref.GetBuffer());
1032   }
1033 }
1034
1035 void CGameDialog::DoGameInstall() {
1036         // make sure console logging is on whenever we enter the installation loop
1037     g_PrefsDlg.mGamesDialog.m_bLogConsole = true;
1038         Sys_LogFile();
1039         mGameInstall.Run();
1040 }
1041
1042 void CGameDialog::DoGameDialog() {
1043         // allow looping the game selection dialog with calls to the game configure dialog in between
1044         while ( m_bDoGameInstall ) {
1045
1046                 m_bDoGameInstall = false;
1047
1048                 if ( DoModal() == IDCANCEL ) {
1049                         Error( "game selection dialog canceled, cannot continue" );
1050                         return;
1051                 }
1052
1053                 if ( m_bDoGameInstall ) {
1054                         DoGameInstall();
1055                         ScanForGames();
1056                         // and we will loop to do another DoModal dialog
1057                 }
1058         }
1059
1060         // unhook so we can use in other places
1061         // we manually incref'ed it when creating, it won't be freed (destructor)
1062         gtk_container_remove( GTK_CONTAINER( mTopBox ), GetGlobalFrame() );
1063
1064         // we save the prefs file
1065         SavePrefs();
1066 }
1067
1068 GtkWidget* CGameDialog::GetGlobalFrame()
1069 {
1070   GtkWidget *vbox, *text, *combo, *check;
1071
1072   if ( mFrame != NULL ) {
1073           return mFrame;
1074   }
1075
1076   mFrame = gtk_frame_new( NULL );
1077   gtk_container_set_border_width( GTK_CONTAINER( mFrame ), 5 );
1078   gtk_widget_show( mFrame );
1079
1080   vbox = gtk_vbox_new( FALSE, 6 );
1081   gtk_widget_show( vbox );
1082   gtk_container_add( GTK_CONTAINER( mFrame ), vbox );
1083   gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
1084
1085   text = gtk_label_new( _("Select the game:") );
1086   gtk_widget_show( text );
1087   gtk_box_pack_start( GTK_BOX( vbox ), text, FALSE, FALSE, 0 );
1088
1089   combo = gtk_combo_box_new_text();
1090   gtk_widget_show( combo );
1091   gtk_box_pack_start( GTK_BOX( vbox ), combo, FALSE, FALSE, 0 );
1092   AddDialogData( combo, &m_nComboSelect, DLG_COMBO_BOX_INT );
1093   mGameCombo = GTK_COMBO_BOX( combo );
1094
1095   UpdateGameCombo();
1096
1097   check = gtk_check_button_new_with_label( _("Auto load selected game on startup") );
1098   gtk_widget_show(check);
1099   gtk_box_pack_start (GTK_BOX(vbox), check, FALSE, FALSE, 0);
1100   AddDialogData (check, &m_bAutoLoadGame, DLG_CHECK_BOOL);
1101
1102   text = gtk_label_new(_("(this frame is available in the prefs menu if you set auto-select)"));
1103   gtk_widget_show(text);
1104   gtk_box_pack_start (GTK_BOX(vbox), text, FALSE, FALSE, 0);
1105
1106 #ifdef _WIN32
1107   check = gtk_check_button_new_with_label( _("Networked install - per-user settings") );
1108   gtk_widget_show( check );
1109   gtk_box_pack_start( GTK_BOX( vbox ), check, FALSE, FALSE, 0 );
1110   AddDialogData( check, &m_bNetRun, DLG_CHECK_BOOL );
1111 #endif
1112
1113   check = gtk_check_button_new_with_label( _("Log the console to radiant.log") );
1114   gtk_widget_show( check );
1115   gtk_box_pack_start( GTK_BOX( vbox ), check, FALSE, FALSE, 0 );
1116   AddDialogData( check, &m_bLogConsole, DLG_CHECK_BOOL );
1117
1118   // incref it so we can pass it around
1119   gtk_widget_ref( GTK_WIDGET( mFrame ) );
1120
1121   return mFrame;
1122 }
1123
1124 void CGameDialog::UpdateData( bool retrieve ) {
1125   if (!retrieve)
1126   {
1127     // use m_sGameFile to set m_nComboSelect
1128     list<CGameDescription *>::iterator iGame;
1129     int i = 0;
1130     for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++)
1131     {
1132       if ((*iGame)->mGameFile == m_sGameFile)
1133       {
1134         m_nComboSelect = i;
1135         break;
1136       }
1137       i++;
1138     }
1139 #ifdef _WIN32
1140     UpdateNetrun(false);
1141 #endif
1142   }
1143   Dialog::UpdateData(retrieve);
1144   if (retrieve)
1145   {
1146     // use m_nComboSelect to set m_sGameFile
1147     list<CGameDescription *>::iterator iGame = mGames.begin();
1148     int i;
1149     for(i=0; i<m_nComboSelect; i++)
1150     {
1151       iGame++;
1152     }
1153     m_sGameFile = (*iGame)->mGameFile;
1154 #ifdef _WIN32
1155     UpdateNetrun(true);
1156 #endif
1157   }
1158 }
1159
1160 void CGameDialog::SInstallCallback( GtkWidget *widget, gpointer data ) {
1161         CGameDialog *d = static_cast< CGameDialog* >( data );
1162         d->m_bDoGameInstall = true;
1163         d->EndModal( 0 );
1164 }
1165
1166 void CGameDialog::BuildDialog() {
1167         GtkWidget *dlg, *vbox1, *button, *setup_button;
1168
1169         dlg = m_pWidget;
1170         gtk_window_set_title( GTK_WINDOW( dlg ), _("Select Game") );
1171
1172         vbox1 = gtk_vbox_new( FALSE, 0 );
1173         gtk_widget_show( vbox1 );
1174         gtk_container_add( GTK_CONTAINER( dlg ), vbox1 );
1175
1176         gtk_container_add( GTK_CONTAINER( vbox1 ), GetGlobalFrame() );
1177         mTopBox = vbox1;
1178
1179         setup_button = gtk_button_new_with_label( _("Configure more games") );
1180         gtk_widget_show( setup_button );
1181         gtk_box_pack_start( GTK_BOX( vbox1 ), setup_button, FALSE, FALSE, 0 );
1182         gtk_signal_connect( GTK_OBJECT( setup_button ), "clicked",
1183                                                 GTK_SIGNAL_FUNC( SInstallCallback ), this );
1184
1185         button = gtk_button_new_with_label( _("OK") );
1186         gtk_widget_show( button );
1187         gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 );
1188         AddModalButton( button, IDOK );
1189
1190         button = gtk_button_new_with_label( _("Cancel") );
1191         gtk_widget_show( button );
1192         gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 );
1193         AddModalButton( button, IDCANCEL );
1194
1195         gtk_widget_set_usize( button, 60, -2 );
1196 }
1197
1198 void CGameDialog::UpdateGameCombo() {
1199   // fill in with the game descriptions
1200   list<CGameDescription *>::iterator iGame;
1201
1202   if ( mGameCombo == NULL ) {
1203           Sys_Printf( "mGameCombo == NULL\n" );
1204           return;
1205   }
1206
1207   // clear whatever is in - wtf no way to know how many text entries?
1208   // use set/get active to track
1209   gtk_combo_box_set_active( mGameCombo, 0 );
1210   while ( gtk_combo_box_get_active( mGameCombo ) == 0 ) {
1211           gtk_combo_box_remove_text( mGameCombo, 0 );
1212           gtk_combo_box_set_active( mGameCombo, 0 );
1213   }
1214
1215   for ( iGame = mGames.begin(); iGame != mGames.end(); iGame++ ) {
1216           gtk_combo_box_append_text( mGameCombo, (*iGame)->mGameName.GetBuffer() );
1217   }
1218   gtk_combo_box_set_active( mGameCombo, 0 );
1219 }
1220
1221 void CGameDialog::ScanForGames()
1222 {
1223   CString strPath;
1224   char *dirlist;
1225   GDir *dir;
1226   CString strGamesPath = g_strAppPath.GetBuffer();
1227   strGamesPath += "games";
1228   const char *path = strGamesPath.GetBuffer();
1229
1230   if ( !mGames.empty() ) {
1231           Sys_Printf( "Clearing game list\n" );
1232           list<CGameDescription*>::iterator iGame;
1233           for ( iGame = mGames.begin(); iGame != mGames.end(); iGame++ ) {
1234                   delete (*iGame);
1235           }
1236           mGames.clear();
1237   }
1238
1239   Sys_Printf( "Scanning for game description files: %s\n", path );
1240
1241   /*!
1242   \todo FIXME LINUX:
1243   do we put game description files below g_strAppPath, or in ~/.radiant
1244   i.e. read only or read/write?
1245   my guess .. readonly cause it's an install
1246   we will probably want to add ~/.radiant/<version>/games/ scanning on top of that for developers
1247   (if that's really needed)
1248   */
1249
1250   // FIXME need to catch the 'no game description' situation and exit with a clean error
1251
1252   dir = g_dir_open(path, 0, NULL);
1253
1254   if (dir != NULL)
1255   {
1256     while (1)
1257     {
1258       const gchar* name = g_dir_read_name(dir);
1259       if(name == NULL)
1260         break;
1261
1262       dirlist = g_strdup(name);
1263 #ifdef _WIN32
1264       strlwr (dirlist);
1265 #endif
1266       char *ext = strrchr (dirlist, '.');
1267       if ((ext == NULL) || (strcmp (ext, ".game") != 0))
1268         continue;
1269       strPath.Format("%s/%s", path, dirlist);
1270       Sys_Printf("%s\n", strPath.GetBuffer());
1271       // got one, load it
1272       xmlDocPtr pDoc = xmlParseFile(strPath.GetBuffer());
1273       if (pDoc)
1274       {
1275         mGames.push_front( new CGameDescription( pDoc, dirlist ) );
1276       }
1277       else
1278       {
1279         Sys_FPrintf(SYS_ERR, "XML parser failed on '%s'\n", strPath.GetBuffer());
1280       }
1281
1282       g_free( dirlist );
1283     }
1284     g_dir_close( dir );
1285   }
1286
1287   // entries in the combo need to be updated
1288   UpdateGameCombo();
1289 }
1290
1291 CGameDescription* CGameDialog::GameDescriptionForComboItem()
1292 {
1293   list<CGameDescription *>::iterator iGame;
1294   int i=0;
1295   for( iGame = mGames.begin(); iGame != mGames.end(); iGame++,i++ ) {
1296     if ( i == m_nComboSelect ) {
1297       return (*iGame);
1298     }
1299   }
1300   return NULL; // not found
1301 }
1302
1303 void CGameDialog::InitGlobalPrefPath()
1304 {
1305   GString *global_rc_path;
1306   // configure m_global_rc_path
1307   // this is the g_strTempPath, and it has already been mkdir'ed
1308   global_rc_path = g_string_new(g_strTempPath.GetBuffer());
1309   g_PrefsDlg.m_global_rc_path = global_rc_path;
1310 }
1311
1312 void CGameDialog::Reset()
1313 {
1314   if (!g_PrefsDlg.m_global_rc_path)
1315     InitGlobalPrefPath();
1316   CString strGlobalPref = g_PrefsDlg.m_global_rc_path->str;
1317   strGlobalPref += "global.pref";
1318   remove(strGlobalPref.GetBuffer());
1319 }
1320
1321 void CGameDialog::Init()
1322 {
1323   InitGlobalPrefPath();
1324   ScanForGames();
1325   if ( mGames.empty() ) {
1326           DoGameInstall();
1327           ScanForGames();
1328           if ( mGames.empty() ) {
1329                   Error( "No games setup, aborting\n" );
1330           }
1331   }
1332   LoadPrefs();
1333   if ( m_bAutoLoadGame ) {
1334     // search by .game name
1335     list<CGameDescription *>::iterator iGame;
1336     for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++)
1337     {
1338       if ((*iGame)->mGameFile == m_sGameFile)
1339       {
1340         m_pCurrentGameDescription = (*iGame);
1341         break;
1342       }
1343     }
1344   }
1345   if ( !m_bAutoLoadGame || !m_pCurrentGameDescription ) {
1346     DoGameDialog();
1347     // use m_nComboSelect to identify the game to run as and set the globals
1348     m_pCurrentGameDescription = GameDescriptionForComboItem();
1349     if ( !m_pCurrentGameDescription ) {
1350                 Error("Lookup of game description object failed, can't continue\n");
1351         }
1352   }
1353   g_pGameDescription = m_pCurrentGameDescription;
1354
1355   g_strGameToolsPath = g_pGameDescription->mGameToolsPath;
1356
1357         // NOTE TTimo: this is moved from QE_LoadProject in 1.2
1358         // (probably broken)
1359   // NOTE Hydra: was broken for win32, we don't use m_strHomeGame or m_strFSBasePath
1360 #if defined (__linux__) || defined (__APPLE__)
1361   g_qeglobals.m_strHomeGame = g_get_home_dir();
1362   g_qeglobals.m_strHomeGame += "/";
1363   g_qeglobals.m_strHomeGame += m_pCurrentGameDescription->mUserPathPrefix.GetBuffer();
1364   g_qeglobals.m_strHomeGame += "/";
1365 #else
1366   g_qeglobals.m_strHomeGame = g_pGameDescription->mEnginePath.GetBuffer();
1367 #endif
1368
1369   g_pGameDescription->Dump();
1370 }
1371
1372 CGameDialog::~CGameDialog()
1373 {
1374   if (mFrame)
1375   {
1376     // NOTE I'm not too sure how reliable this is
1377     gtk_widget_unref(GTK_WIDGET(mFrame));
1378   }
1379   // free all the game descriptions
1380   list<CGameDescription *>::iterator iGame;
1381   for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++)
1382   {
1383     delete (*iGame);
1384     *iGame = NULL;
1385   }
1386 }
1387
1388 void CGameDialog::AddPacksURL(Str &URL)
1389 {
1390   // add the URLs for the list of game packs installed
1391   // FIXME: this is kinda hardcoded for now..
1392   list<CGameDescription *>::iterator iGame;
1393   for(iGame=mGames.begin(); iGame!=mGames.end(); iGame++)
1394   {
1395     if ((*iGame)->mGameFile == "q3.game")
1396       URL += "&Games_dlup%5B%5D=1";
1397     else if ((*iGame)->mGameFile == "wolf.game")
1398       URL += "&Games_dlup%5B%5D=2";
1399         // FIXME: double entry
1400     else if ((*iGame)->mGameFile == "wolf.game")
1401       URL += "&Games_dlup%5B%5D=3";
1402     else if ((*iGame)->mGameFile == "jk2.game")
1403       URL += "&Games_dlup%5B%5D=4";
1404     else if ((*iGame)->mGameFile == "stvef.game")
1405       URL += "&Games_dlup%5B%5D=5";
1406     else if ((*iGame)->mGameFile == "sof2.game")
1407       URL += "&Games_dlup%5B%5D=6";
1408     else if ((*iGame)->mGameFile == "ja.game")
1409       URL += "&Games_dlup%5B%5D=7";
1410   }
1411 }
1412
1413 #ifdef _WIN32
1414
1415 #define NETRUN_FILENAME "netrun.conf"
1416
1417 bool CGameDialog::m_bNetRun;
1418
1419 void CGameDialog::UpdateNetrun(bool retrieve)
1420 {
1421   FILE *f_netrun;
1422   CString strNetrun;
1423   strNetrun = g_strAppPath; strNetrun += NETRUN_FILENAME;
1424   if (!retrieve)
1425   {
1426     // now check if we are running from a network installation
1427     // use a dummy file as the flag
1428     f_netrun = fopen(strNetrun.GetBuffer(), "r");
1429     if (f_netrun)
1430     {
1431       fclose(f_netrun);
1432       m_bNetRun = true;
1433     }
1434     else
1435       m_bNetRun = false;
1436   }
1437   else
1438   {
1439     if (m_bNetRun)
1440     {
1441       f_netrun = fopen(strNetrun.GetBuffer(), "w");
1442       if (!f_netrun)
1443       {
1444         Sys_FPrintf(SYS_ERR, "ERROR: Failed to create netrun file '%s'\n", strNetrun.GetBuffer());
1445         m_bNetRun = false;
1446       }
1447       else
1448       {
1449         fclose(f_netrun);
1450         Sys_Printf("Created/Checked '%s'\n", strNetrun.GetBuffer());
1451       }
1452     }
1453     else
1454     {
1455       if (remove(strNetrun.GetBuffer()) == -1)
1456       {
1457         if (errno != ENOENT)
1458           Sys_FPrintf(SYS_ERR, "Failed to remove netrun file '%s'\n", strNetrun.GetBuffer());
1459         m_bNetRun = true;
1460       }
1461       else
1462       {
1463         Sys_Printf("Netrun mode is disabled\n");
1464       }
1465     }
1466   }
1467 }
1468
1469 bool CGameDialog::GetNetrun()
1470 {
1471   return m_bNetRun;
1472 }
1473 #endif
1474
1475 /*
1476 ========
1477
1478 very first prefs init deals with selecting the game and the game tools path
1479 then we can load .ini stuff
1480
1481 using prefs / ini settings:
1482 those are per-game
1483
1484 win32:
1485 look in g_strGameToolsPath for .ini
1486
1487 linux:
1488 look in ~/.radiant/<version>/gamename
1489 ========
1490 */
1491
1492 #define PREFS_LOCAL_FILENAME "local.pref"
1493
1494 void PrefsDlg::Init()
1495 {
1496   mGamesDialog.Init();
1497
1498   // m_global_rc_path has been set above, do m_rc_path with game specific stuff now
1499   // the win32 and linux versions have been unified for network mode
1500 #ifdef _WIN32
1501   if (!CGameDialog::GetNetrun())
1502   {
1503     // legacy prefs settings, this goes where the game pack is installed
1504     m_rc_path = g_string_new (g_strGameToolsPath.GetBuffer() );
1505     m_inipath = g_string_new (m_rc_path->str);
1506     g_string_append (m_inipath, PREFS_LOCAL_FILENAME);
1507     return;
1508   }
1509 #endif
1510   // this is common to win32 and Linux init now
1511   m_rc_path = g_string_new (m_global_rc_path->str);
1512
1513   // game sub-dir
1514   g_string_append (m_rc_path, g_pGameDescription->mGameFile.GetBuffer());
1515   g_string_append (m_rc_path, "/");
1516   Q_mkdir (m_rc_path->str, 0775);
1517
1518   // then the ini file
1519   m_inipath = g_string_new (m_rc_path->str);
1520   g_string_append (m_inipath, PREFS_LOCAL_FILENAME);
1521
1522 }
1523
1524 void PrefsDlg::UpdateData (bool retrieve)
1525 {
1526   // leo: the "changed" signal confuses the update function
1527   if (m_pWidget == NULL)
1528     return;
1529   mGamesDialog.UpdateData (retrieve);
1530   Dialog::UpdateData (retrieve);
1531 }
1532
1533 #ifdef _WIN32
1534 #define PREFSHSPACE 5
1535 #else
1536 #define PREFSHSPACE 0
1537 #endif
1538
1539 static void UpdateSensitivity( GtkWidget *widget, gpointer data )
1540 {
1541   PrefsDlg *dlg = (PrefsDlg*)data;
1542   dlg->DoSensitivity();
1543 }
1544
1545 static void UpdateEditorSensitivity(GtkWidget *widget, gpointer data)
1546 {
1547   PrefsDlg *dlg = (PrefsDlg*)data;
1548   dlg->DoEditorSensitivity();
1549 }
1550
1551 // start new prefs dialog
1552
1553 /*! Utility function for swapping notebook pages for tree list selections */
1554 void PrefsDlg::showPrefPage(int prefpage)
1555 {
1556   if(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)) != prefpage)
1557     gtk_notebook_set_page(GTK_NOTEBOOK(notebook), prefpage);
1558
1559   return;
1560 }
1561
1562 static void treeSelection(GtkTreeSelection* selection, gpointer data)
1563 {
1564   PrefsDlg *dlg = (PrefsDlg*)data;
1565
1566   GtkTreeModel* model;
1567   GtkTreeIter selected;
1568   if(gtk_tree_selection_get_selected(selection, &model, &selected))
1569   {
1570     int prefpage;
1571     gtk_tree_model_get(model, &selected, 1, (gpointer*)&prefpage, -1);
1572     dlg->showPrefPage(prefpage);
1573   }
1574 }
1575
1576 void PrefsDlg::BuildDialog ()
1577 {
1578   // Main Preferences dialog
1579   GtkWidget *dialog, *mainvbox, *hbox, *sc_win, *preflabel;
1580
1581   // Widgets on notebook pages
1582   GtkWidget *check, *label, *scale, *hbox2, *combo,
1583             *table, *spin,  *entry, *pixmap,
1584             *radio, *button, *pageframe, *vbox;
1585
1586   GList *combo_list = (GList*)NULL;
1587
1588   GtkObject *adj;
1589
1590   dialog = m_pWidget;
1591   gtk_window_set_title(GTK_WINDOW(dialog), _("GtkRadiant Preferences"));
1592   gtk_widget_realize(dialog);
1593
1594   mainvbox = gtk_vbox_new(FALSE, 5);
1595   gtk_container_add(GTK_CONTAINER(dialog), mainvbox);
1596   gtk_container_set_border_width(GTK_CONTAINER(mainvbox), 5);
1597   gtk_widget_show(mainvbox);
1598
1599   hbox = gtk_hbox_new(FALSE, 5);
1600   gtk_widget_show(hbox);
1601   gtk_box_pack_end(GTK_BOX(mainvbox), hbox, FALSE, TRUE, 0);
1602
1603   button = gtk_button_new_with_label(_("OK"));
1604   gtk_widget_show(button);
1605   gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1606   gtk_widget_set_usize(button, 60, -2);
1607   AddModalButton(button, IDOK);
1608
1609   button = gtk_button_new_with_label(_("Cancel"));
1610   gtk_widget_show(button);
1611   gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1612   gtk_widget_set_usize(button, 60, -2);
1613   AddModalButton(button, IDCANCEL);
1614
1615   button = gtk_button_new_with_label (_("Clean"));
1616   gtk_widget_show(button);
1617   gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(OnButtonClean), this);
1618   gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1619   gtk_widget_set_usize (button, 60, -2);
1620
1621   hbox = gtk_hbox_new(FALSE, 5);
1622   gtk_box_pack_start(GTK_BOX(mainvbox), hbox, TRUE, TRUE, 0);
1623   gtk_widget_show(hbox);
1624
1625   sc_win = gtk_scrolled_window_new(NULL, NULL);
1626   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sc_win), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1627   gtk_box_pack_start(GTK_BOX(hbox), sc_win, FALSE, FALSE, 0);
1628   gtk_widget_show(sc_win);
1629
1630   // prefs pages notebook
1631   notebook = gtk_notebook_new();
1632   // hide the notebook tabs since its not supposed to look like a notebook
1633   gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
1634   gtk_box_pack_start(GTK_BOX(hbox), notebook, TRUE, TRUE, 0);
1635   gtk_widget_show(notebook);
1636
1637   gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sc_win), GTK_SHADOW_IN);
1638
1639   {
1640     GtkTreeStore* store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
1641
1642     GtkWidget* view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1643     gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
1644
1645     {
1646       GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
1647       GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(_("Preferences"), renderer, "text", 0, NULL);
1648       gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
1649     }
1650
1651     {
1652       GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
1653       g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(treeSelection), this);
1654     }
1655
1656     gtk_widget_show(view);
1657
1658     gtk_container_add(GTK_CONTAINER (sc_win), view);
1659
1660     {
1661       /********************************************************************/
1662       /* Add preference tree options                                      */
1663       /********************************************************************/
1664       {
1665         GtkTreeIter group;
1666         gtk_tree_store_append(store, &group, NULL);
1667         gtk_tree_store_set(store, &group, 0, _("Globals"), 1, PTAB_FRONT, -1);
1668         {
1669           GtkTreeIter tab;
1670           gtk_tree_store_append(store, &tab, &group);
1671           gtk_tree_store_set(store, &tab, 0, _("Game settings"), 1, (gpointer)PTAB_GAME_SETTINGS, -1);
1672         }
1673       }
1674
1675       {
1676         GtkTreeIter group;
1677         gtk_tree_store_append(store, &group, NULL);
1678         gtk_tree_store_set(store, &group, 0, _("Display"), 1, PTAB_FRONT, -1);
1679         {
1680           GtkTreeIter tab;
1681           gtk_tree_store_append(store, &tab, &group);
1682           gtk_tree_store_set(store, &tab, 0, _("2D Display/Rendering"), 1, (gpointer)PTAB_2D, -1);
1683         }
1684         {
1685           GtkTreeIter tab;
1686           gtk_tree_store_append(store, &tab, &group);
1687           gtk_tree_store_set(store, &tab, 0, _("3D View"), 1, (gpointer)PTAB_CAMERA, -1);
1688         }
1689         {
1690           GtkTreeIter tab;
1691           gtk_tree_store_append(store, &tab, &group);
1692           gtk_tree_store_set(store, &tab, 0, _("Texture Settings"), 1, (gpointer)PTAB_TEXTURE, -1);
1693         }
1694       }
1695
1696       {
1697         GtkTreeIter group;
1698         gtk_tree_store_append(store, &group, NULL);
1699         gtk_tree_store_set(store, &group, 0, _("Interface"), 1, PTAB_FRONT, -1);
1700         {
1701           GtkTreeIter tab;
1702           gtk_tree_store_append(store, &tab, &group);
1703           gtk_tree_store_set(store, &tab, 0, _("Layout"), 1, (gpointer)PTAB_LAYOUT, -1);
1704         }
1705         {
1706           GtkTreeIter tab;
1707           gtk_tree_store_append(store, &tab, &group);
1708           gtk_tree_store_set(store, &tab, 0, _("Mouse"), 1, (gpointer)PTAB_MOUSE, -1);
1709         }
1710         {
1711           GtkTreeIter tab;
1712           gtk_tree_store_append(store, &tab, &group);
1713           gtk_tree_store_set(store, &tab, 0, _("Editing"), 1, (gpointer)PTAB_EDITING, -1);
1714         }
1715       }
1716
1717       {
1718         GtkTreeIter group;
1719         gtk_tree_store_append(store, &group, NULL);
1720         gtk_tree_store_set(store, &group, 0, _("Other"), 1, PTAB_FRONT, -1);
1721         {
1722           GtkTreeIter tab;
1723           gtk_tree_store_append(store, &tab, &group);
1724           gtk_tree_store_set(store, &tab, 0, _("Startup/Auto save"), 1, (gpointer)PTAB_STARTUP, -1);
1725         }
1726         {
1727           GtkTreeIter tab;
1728           gtk_tree_store_append(store, &tab, &group);
1729           gtk_tree_store_set(store, &tab, 0, _("Paths"), 1, (gpointer)PTAB_PATHS, -1);
1730         }
1731         {
1732           GtkTreeIter tab;
1733           gtk_tree_store_append(store, &tab, &group);
1734           gtk_tree_store_set(store, &tab, 0, _("Brush"), 1, (gpointer)PTAB_BRUSH, -1);
1735         }
1736         {
1737           GtkTreeIter tab;
1738           gtk_tree_store_append(store, &tab, &group);
1739           gtk_tree_store_set(store, &tab, 0, _("Misc"), 1, (gpointer)PTAB_MISC, -1);
1740         }
1741         if (!g_qeglobals.bBSPFrontendPlugin)
1742         {
1743           GtkTreeIter tab;
1744           gtk_tree_store_append(store, &tab, &group);
1745           gtk_tree_store_set(store, &tab, 0, _("BSP Monitoring"), 1, (gpointer)PTAB_BSPMONITOR, -1);
1746         }
1747       }
1748     }
1749
1750     gtk_tree_view_expand_all(GTK_TREE_VIEW(view));
1751
1752     g_object_unref(G_OBJECT(store));
1753   }
1754
1755   /**********************************************************************/
1756   /* build the prefs pages                                              */
1757   /**********************************************************************/
1758
1759   // Front page...
1760   // todo : add something interesting here
1761   // NOTE TTimo: tip of the day? or a logo?
1762   preflabel = gtk_label_new(_("Front Page"));
1763   gtk_widget_show(preflabel);
1764   pageframe = gtk_frame_new(NULL);
1765   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
1766   gtk_widget_show(pageframe);
1767   vbox = gtk_vbox_new(FALSE, 5);
1768   gtk_widget_show(vbox);
1769   gtk_widget_set_usize(GTK_WIDGET(vbox), 350, -2);
1770   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1771   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
1772
1773   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
1774
1775   /******** global preferences group ****************************/
1776   preflabel = gtk_label_new(_("Globals"));
1777   gtk_widget_show(preflabel);
1778
1779   pageframe = mGamesDialog.GetGlobalFrame();
1780   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
1781
1782   /******** 2D prefs group (xy views/rendering options) *********/
1783   preflabel = gtk_label_new(_("2D Display"));
1784   gtk_widget_show(preflabel);
1785   pageframe = gtk_frame_new(_("2D Display"));
1786   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
1787   gtk_widget_show(pageframe);
1788   vbox = gtk_vbox_new(FALSE, 5);
1789   gtk_widget_show(vbox);
1790   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1791   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
1792
1793   // OpenGL Display Lists
1794   check = gtk_check_button_new_with_label(_("OpenGL Display Lists"));
1795   gtk_widget_show(check);
1796   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
1797   AddDialogData(check, &m_bDisplayLists, DLG_CHECK_BOOL);
1798
1799   // Antialiased points & lines
1800   // Fishman - Add antialiazed points and lines support. 09/03/00
1801   check = gtk_check_button_new_with_label (_("OpenGL antialiased points and lines"));
1802   gtk_widget_show (check);
1803   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1804   AddDialogData (check, &m_bAntialiasedPointsAndLines, DLG_CHECK_BOOL);
1805
1806   // Solid selection boxes
1807   check = gtk_check_button_new_with_label (_("Solid selection boxes"));
1808   gtk_widget_show (check);
1809   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1810   AddDialogData (check, &m_bNoStipple, DLG_CHECK_BOOL);
1811
1812   // Display size info
1813   check = gtk_check_button_new_with_label (_("Display size info"));
1814   gtk_widget_show (check);
1815   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
1816   AddDialogData (check, &m_bSizePaint, DLG_CHECK_BOOL);
1817
1818   // Alternate vertex/edge handles
1819   // Gef: Kyro GL_POINT work around 25-aug-2001
1820   check = gtk_check_button_new_with_label (_("Alternate vertex/edge handles"));
1821   gtk_widget_show(check);
1822   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
1823   AddDialogData(check, &m_bGlPtWorkaround, DLG_CHECK_BOOL);
1824
1825   g_list_free (combo_list);
1826
1827 #ifdef ATIHACK_812
1828         // ATI bugs
1829         check = gtk_check_button_new_with_label (_("ATI cards with broken drivers - bug #802"));
1830         gtk_widget_show(check);
1831         gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
1832         AddDialogData(check, &m_bGlATIHack, DLG_CHECK_BOOL);
1833 #endif
1834
1835   // Add the page to the notebook
1836   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
1837
1838   /******** 3D Camera view group *********/
1839   preflabel = gtk_label_new(_("3D View"));
1840   gtk_widget_show(preflabel);
1841   pageframe = gtk_frame_new(_("3D View"));
1842   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
1843   gtk_widget_show(pageframe);
1844   vbox = gtk_vbox_new(FALSE, 5);
1845   gtk_widget_show(vbox);
1846   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1847   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
1848
1849   // Directional velocity (Movement Velocity)
1850   // label container
1851   hbox2 = gtk_hbox_new (FALSE, 0);
1852   gtk_widget_show (hbox2);
1853   gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
1854
1855   // label
1856   label = gtk_label_new(_("Movement Velocity"));
1857   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1858   gtk_widget_show(label);
1859   gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
1860
1861   // adjustment
1862   adj = gtk_adjustment_new(100, 50, 300, 1, 10, 10);
1863   AddDialogData(adj, &m_nMoveSpeed, DLG_ADJ_INT);
1864
1865   // scale
1866   scale = gtk_hscale_new(GTK_ADJUSTMENT(adj));
1867   gtk_widget_show(scale);
1868   gtk_box_pack_start(GTK_BOX (vbox), scale, FALSE, TRUE, 2);
1869
1870   gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE);
1871
1872   // Angular velocity (Rotational Velocity)
1873   // label container
1874   hbox2 = gtk_hbox_new (FALSE, 0);
1875   gtk_widget_show (hbox2);
1876   gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
1877
1878   // label
1879   label = gtk_label_new (_("Rotational Velocity"));
1880   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1881   gtk_widget_show (label);
1882   gtk_box_pack_start(GTK_BOX(hbox2), label, FALSE, FALSE, 0);
1883
1884   // adjustment
1885   adj = gtk_adjustment_new (3, 1, 180, 1, 10, 10); // value, low, high, step, page_step, page_size
1886   AddDialogData (adj, &m_nAngleSpeed, DLG_ADJ_INT);
1887
1888   // scale
1889   scale = gtk_hscale_new (GTK_ADJUSTMENT (adj));
1890   gtk_widget_show (scale);
1891   gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, TRUE, 2);
1892   gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE);
1893
1894   // Text under the velocity sliders
1895   // container
1896   hbox2 = gtk_hbox_new (FALSE, 0);
1897   gtk_widget_show (hbox2);
1898   gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
1899
1900   // label
1901   label = gtk_label_new (_("slow"));
1902   gtk_widget_show (label);
1903   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
1904
1905   // label
1906   label = gtk_label_new (_("fast"));
1907   gtk_widget_show (label);
1908   gtk_box_pack_end (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
1909
1910   // Allow drag to select multiple faces/brushes
1911   // container
1912   table = gtk_table_new(2, 1, FALSE);
1913   gtk_widget_show(table);
1914   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
1915   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
1916   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
1917
1918   label = gtk_label_new (_("Use paint-select in camera view:"));
1919   gtk_widget_show (label);
1920   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1921   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
1922                   (GtkAttachOptions) (0),
1923                   (GtkAttachOptions) (0), 0, 0);
1924
1925   combo_list = NULL;
1926   combo_list = g_list_append (combo_list, (void *)_("No"));
1927   combo_list = g_list_append (combo_list, (void *)_("Yes"));
1928   combo_list = g_list_append (combo_list, (void *)_("Yes (Classic Key Setup)"));
1929
1930   combo = gtk_combo_new ();
1931   gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo_list);
1932   gtk_widget_show (combo);
1933   gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
1934                   (GtkAttachOptions) (GTK_FILL),
1935                   (GtkAttachOptions) (0), 0, 0);
1936   gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (combo)->entry), FALSE);
1937   AddDialogData (combo, &m_nCamDragMultiSelect, DLG_COMBO_INT);
1938
1939   // Freelook in Camera view
1940   check = gtk_check_button_new_with_label (_("Freelook in Camera view"));
1941   gtk_widget_show (check);
1942   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1943   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1944   AddDialogData (check, &m_bCamFreeLook, DLG_CHECK_BOOL);
1945
1946   // Freelook in Camera view w/ forward & back strafing instead of up and down looking
1947   check = gtk_check_button_new_with_label (_("Freelook strafes Forward and Back"));
1948   gtk_widget_show (check);
1949   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1950   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1951   AddDialogData (check, &m_bCamFreeLookStrafe, DLG_CHECK_BOOL);
1952
1953   // Invert mouse in freelook
1954   check = gtk_check_button_new_with_label (_("Invert mouse in freelook"));
1955   gtk_widget_show (check);
1956   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1957   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1958   AddDialogData (check, &m_bCamInverseMouse, DLG_CHECK_BOOL);
1959
1960   // Discrete movement
1961   check = gtk_check_button_new_with_label (_("Discrete movement"));
1962   gtk_widget_show (check);
1963   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1964   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1965   AddDialogData (check, &m_bCamDiscrete, DLG_CHECK_BOOL);
1966
1967   // Update XY views on camera move
1968   check = gtk_check_button_new_with_label (_("Update XY views on camera move"));
1969   gtk_widget_show (check);
1970   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
1971   gtk_label_set_justify (GTK_LABEL (GTK_BIN (check)->child), GTK_JUSTIFY_LEFT);
1972   AddDialogData (check, &m_bCamXYUpdate, DLG_CHECK_BOOL);
1973
1974   // Add the page to the notebook
1975   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
1976
1977   /******** Texture group *********/
1978   preflabel = gtk_label_new(_("Textures"));
1979   gtk_widget_show(preflabel);
1980   pageframe = gtk_frame_new(_("Textures"));
1981   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
1982   gtk_widget_show(pageframe);
1983   vbox = gtk_vbox_new(FALSE, 6);
1984   gtk_widget_show(vbox);
1985   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1986   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
1987
1988   // Texture quality slider
1989   // label
1990   label = gtk_label_new (_("Texture quality"));
1991   gtk_widget_show (label);
1992   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
1993   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1994   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1995
1996   // adjustment
1997   adj = gtk_adjustment_new (0, 0, 4, 1, 1, 1);
1998   AddDialogData (adj, &m_nLatchedTextureQuality, DLG_ADJ_INT);
1999
2000   // scale
2001   scale = gtk_hscale_new (GTK_ADJUSTMENT (adj));
2002   gtk_widget_show (scale);
2003   gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
2004   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
2005
2006   // text under the texture slider
2007   hbox2 = gtk_hbox_new (FALSE, 0);
2008   gtk_widget_show (hbox2);
2009   gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
2010   label = gtk_label_new (_("low"));
2011   gtk_widget_show (label);
2012   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2013   label = gtk_label_new (_("high"));
2014   gtk_widget_show (label);
2015   gtk_box_pack_end (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2016
2017   // texture subsets
2018   check = gtk_check_button_new_with_label (_("Texture subsets"));
2019   gtk_widget_show (check);
2020   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2021   AddDialogData (check, &m_bTextureWindow, DLG_CHECK_BOOL);
2022
2023   // texture scrollbar
2024   check = gtk_check_button_new_with_label (_("Texture scrollbar"));
2025   gtk_widget_show (check);
2026   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2027   AddDialogData (check, &m_bTextureScrollbar, DLG_CHECK_BOOL);
2028
2029   // texture increment matches grid
2030   check = gtk_check_button_new_with_label (_("Tex increment matches grid"));
2031   gtk_widget_show (check);
2032   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2033   AddDialogData (check, &m_bSnapTToGrid, DLG_CHECK_BOOL);
2034
2035   // RIANT
2036   // Texture compression choice label
2037   // container
2038   table = gtk_table_new(2, 1, FALSE);
2039   gtk_widget_show(table);
2040   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2041   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2042   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2043
2044   label = gtk_label_new (_("Texture Compression (if available):"));
2045   gtk_widget_show (label);
2046   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
2047   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
2048                   (GtkAttachOptions) (0),
2049                   (GtkAttachOptions) (0), 0, 0);
2050   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
2051
2052   // Texture compression choice label
2053   combo_list = NULL;
2054   // NONE will always be in pos 0
2055   combo_list = g_list_append (combo_list, (void *)_("None"));
2056
2057   // if OpenGL compression is enabled it will always be
2058   // in pos 1
2059   if (g_qeglobals.m_bOpenGLCompressionSupported)
2060   {
2061     combo_list = g_list_append (combo_list, (void *)_("OpenGL ARB"));
2062   }
2063
2064   // If S3 is enabled offer all 3 valid compression schemes in RGBA
2065   if (g_qeglobals.m_bS3CompressionSupported)
2066   {
2067     combo_list = g_list_append (combo_list, (void *)_("S3TC DXT1"));
2068     combo_list = g_list_append (combo_list, (void *)_("S3TC DXT3"));
2069     combo_list = g_list_append (combo_list, (void *)_("S3TC DXT5"));
2070   }
2071
2072   combo = gtk_combo_new ();
2073   gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo_list);
2074   gtk_widget_show (combo);
2075   gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
2076                   (GtkAttachOptions) (GTK_FILL),
2077                   (GtkAttachOptions) (0), 0, 0);
2078   gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (combo)->entry), FALSE);
2079   AddDialogData (combo, &m_nTextureCompressionFormat, DLG_COMBO_INT);
2080   g_list_free (combo_list);
2081
2082   // container
2083   table = gtk_table_new(2, 1, FALSE);
2084   gtk_widget_show(table);
2085   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2086   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2087   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2088
2089   // Startup shaders
2090   // label
2091   label = gtk_label_new (_("Startup Shaders:"));
2092   gtk_widget_show (label);
2093   gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
2094   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
2095                   (GtkAttachOptions) (0),
2096                   (GtkAttachOptions) (0), 0, 0);
2097   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
2098
2099   // combo list
2100   combo_list = NULL;
2101   combo_list = g_list_append (combo_list, (void *)_("None"));
2102   if (g_pGameDescription->mGameFile == "jk2.game" || g_pGameDescription->mGameFile == "ja.game")
2103     combo_list = g_list_append (combo_list, (void *)_("System"));
2104   else if (g_pGameDescription->mGameFile == "sof2.game")
2105     combo_list = g_list_append (combo_list, (void *)("Tools"));
2106   else
2107     combo_list = g_list_append (combo_list, (void *)_("Common"));
2108   combo_list = g_list_append (combo_list, (void *)_("All"));
2109   combo = gtk_combo_new ();
2110   gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo_list);
2111   gtk_widget_show (combo);
2112   gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
2113                   (GtkAttachOptions) (GTK_FILL),
2114                   (GtkAttachOptions) (0), 0, 0);
2115   gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (combo)->entry), FALSE);
2116   AddDialogData (combo, &m_nLatchedShader, DLG_COMBO_INT);
2117   g_list_free (combo_list);
2118
2119   // Add the page to the notebook
2120   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2121
2122   /******** Layout group *********/
2123   preflabel = gtk_label_new(_("Layout"));
2124   gtk_widget_show(preflabel);
2125   pageframe = gtk_frame_new(_("Layout"));
2126   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2127   gtk_widget_show(pageframe);
2128   vbox = gtk_vbox_new(FALSE, 5);
2129   gtk_widget_show(vbox);
2130   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2131   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2132
2133   // View types
2134   // table
2135   table = gtk_table_new (2, 4, FALSE);
2136   gtk_widget_show (table);
2137   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2138   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2139   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2140
2141   // view type 1
2142   pixmap = new_pixmap (g_pParentWnd->m_pWidget, "window1.bmp");
2143   gtk_widget_show (pixmap);
2144   gtk_table_attach (GTK_TABLE (table), pixmap, 0, 1, 0, 1,
2145                     (GtkAttachOptions) (0),
2146                     (GtkAttachOptions) (0), 0, 0);
2147
2148   // view type 2
2149   pixmap = new_pixmap (g_pParentWnd->m_pWidget, "window2.bmp");
2150   gtk_widget_show (pixmap);
2151   gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1,
2152                     (GtkAttachOptions) (0),
2153                     (GtkAttachOptions) (0), 0, 0);
2154
2155   // view type 3
2156   pixmap = new_pixmap (g_pParentWnd->m_pWidget, "window3.bmp");
2157   gtk_widget_show (pixmap);
2158   gtk_table_attach (GTK_TABLE (table), pixmap, 2, 3, 0, 1,
2159                     (GtkAttachOptions) (0),
2160                     (GtkAttachOptions) (0), 0, 0);
2161
2162   // view type 4
2163   pixmap = new_pixmap (g_pParentWnd->m_pWidget, "window4.bmp");
2164   gtk_widget_show (pixmap);
2165   gtk_table_attach (GTK_TABLE (table), pixmap, 3, 4, 0, 1,
2166                     (GtkAttachOptions) (0),
2167                     (GtkAttachOptions) (0), 0, 0);
2168
2169   // view type 1 selector
2170   radio = gtk_radio_button_new (NULL);
2171   gtk_widget_show (radio);
2172   gtk_table_attach (GTK_TABLE (table), radio, 0, 1, 1, 2,
2173                     (GtkAttachOptions) (0),
2174                     (GtkAttachOptions) (0), 0, 0);
2175
2176   // view type 2 selector
2177   radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (radio));
2178   gtk_widget_show (radio);
2179   gtk_table_attach (GTK_TABLE (table), radio, 1, 2, 1, 2,
2180                     (GtkAttachOptions) (0),
2181                     (GtkAttachOptions) (0), 0, 0);
2182
2183   // view type 3 selector
2184   radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (radio));
2185   gtk_widget_show (radio);
2186   gtk_table_attach (GTK_TABLE (table), radio, 2, 3, 1, 2,
2187                     (GtkAttachOptions) (0),
2188                     (GtkAttachOptions) (0), 0, 0);
2189
2190   // view type 4 selector
2191   radio = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON (radio));
2192   gtk_widget_show (radio);
2193   gtk_table_attach (GTK_TABLE (table), radio, 3, 4, 1, 2,
2194                     (GtkAttachOptions) (0),
2195                     (GtkAttachOptions) (0), 0, 0);
2196   AddDialogData (radio, &m_nLatchedView, DLG_RADIO_INT);
2197
2198   // Floating Z window
2199   check = gtk_check_button_new_with_label (_("Floating Z Window"));
2200   gtk_widget_show (check);
2201   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2202   AddDialogData (check, &m_bLatchedFloatingZ, DLG_CHECK_BOOL);
2203
2204   // show menu tear-off seperators
2205   check = gtk_check_button_new_with_label (_("Detachable Menus"));
2206   gtk_widget_show (check);
2207   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2208   AddDialogData (check, &m_bLatchedDetachableMenus, DLG_CHECK_BOOL);
2209
2210   if (!g_pGameDescription->mNoPatch)
2211   {
2212     // show patch toolbar
2213     check = gtk_check_button_new_with_label (_("Patch Toolbar"));
2214     gtk_widget_show (check);
2215     gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2216     g_object_set_data (G_OBJECT (dialog), "check_patchtoolbar", check); // Allow to be disabled for Q1/Q2
2217     AddDialogData (check, &m_bLatchedPatchToolbar, DLG_CHECK_BOOL);
2218   }
2219
2220   // use wide toolbar
2221   check = gtk_check_button_new_with_label (_("Wide Toolbar"));
2222   gtk_widget_show (check);
2223   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2224   AddDialogData (check, &m_bLatchedWideToolbar, DLG_CHECK_BOOL);
2225
2226   // use plugin toolbar
2227   check = gtk_check_button_new_with_label (_("Plugin Toolbar"));
2228   gtk_widget_show (check);
2229   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2230   AddDialogData (check, &m_bLatchedPluginToolbar, DLG_CHECK_BOOL);
2231
2232 #ifdef _WIN32
2233   // win32 file dialog
2234   check = gtk_check_button_new_with_label (_("Use win32 file dialog (hacky)"));
2235   gtk_widget_show (check);
2236   // gtk_container_add (GTK_CONTAINER (vbox), check);
2237   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2238   AddDialogData (check, &m_bNativeGUI, DLG_CHECK_BOOL);
2239
2240   // position on primary monitor
2241   check = gtk_check_button_new_with_label (_("Start on Primary Monitor"));
2242   gtk_widget_show (check);
2243   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2244   g_object_set_data (G_OBJECT (dialog), "check_startonprimary", check);
2245   gtk_signal_connect( GTK_OBJECT (check), "clicked", GTK_SIGNAL_FUNC(UpdateSensitivity), this );
2246   AddDialogData (check, &m_bStartOnPrimMon, DLG_CHECK_BOOL);
2247 #endif
2248
2249   // Add the page to the notebook
2250   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2251
2252   /******** Mouse group *********/
2253   preflabel = gtk_label_new(_("Mouse"));
2254   gtk_widget_show(preflabel);
2255   pageframe = gtk_frame_new(_("Mouse"));
2256   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2257   gtk_widget_show(pageframe);
2258   vbox = gtk_vbox_new(FALSE, 5);
2259   gtk_widget_show(vbox);
2260   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2261   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2262
2263   // Buttons
2264   // container
2265   hbox2 = gtk_hbox_new (FALSE, 5);
2266   gtk_widget_show (hbox2);
2267   gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
2268
2269   // 2 button radio
2270   radio = gtk_radio_button_new_with_label (NULL, _("2 button"));
2271   gtk_widget_show (radio);
2272   gtk_box_pack_start (GTK_BOX (hbox2), radio, FALSE, FALSE, 0);
2273
2274   // 3 button radio
2275   radio = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), _("3 button"));
2276   gtk_widget_show (radio);
2277   gtk_box_pack_start (GTK_BOX (hbox2), radio, FALSE, FALSE, 0);
2278   AddDialogData (radio, &m_nMouse, DLG_RADIO_INT);
2279
2280   // right click to drop entity
2281   check = gtk_check_button_new_with_label (_("Right click to drop entities"));
2282   gtk_widget_show (check);
2283   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2284   AddDialogData (check, &m_bRightClick, DLG_CHECK_BOOL);
2285
2286   // Mouse chaser (and this does what?)
2287   check = gtk_check_button_new_with_label (_("Mouse chaser"));
2288   gtk_widget_show (check);
2289   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2290   AddDialogData (check, &m_bChaseMouse, DLG_CHECK_BOOL);
2291
2292   // Alt + multi-drag
2293   check = gtk_check_button_new_with_label (_("ALT + multi-drag"));
2294   gtk_widget_show (check);
2295   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2296   AddDialogData (check, &m_bALTEdge, DLG_CHECK_BOOL);
2297
2298   // Mouse wheel increments
2299   // container
2300   hbox2 = gtk_hbox_new (FALSE, 5);
2301   gtk_widget_show (hbox2);
2302   gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
2303
2304   // label
2305   label = gtk_label_new (_("Wheel Mouse inc:"));
2306   gtk_widget_show (label);
2307   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2308
2309   // entry
2310   entry = gtk_entry_new ();
2311   gtk_widget_show (entry);
2312   gtk_widget_set_usize (entry, 40, -2);
2313   gtk_box_pack_start (GTK_BOX (hbox2), entry, FALSE, FALSE, 0);
2314   AddDialogData (entry, &m_nWheelInc, DLG_ENTRY_INT);
2315
2316   // Add the page to the notebook
2317   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2318
2319   /******** Editing group *********/
2320   preflabel = gtk_label_new(_("Editing"));
2321   gtk_widget_show(preflabel);
2322   pageframe = gtk_frame_new(_("Editing"));
2323   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2324   gtk_widget_show(pageframe);
2325   vbox = gtk_vbox_new(FALSE, 5);
2326   gtk_widget_show(vbox);
2327   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2328   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2329
2330   // Vertex editing splits faces
2331   check = gtk_check_button_new_with_label (_("Vertex editing splits face"));
2332   gtk_widget_show (check);
2333   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2334   AddDialogData (check, &m_bVertexSplit, DLG_CHECK_BOOL);
2335
2336   // Fix target/targetname collisions
2337   check = gtk_check_button_new_with_label (_("Fix target/targetname collisions"));
2338   gtk_widget_show (check);
2339   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2340   AddDialogData (check, &m_bDoTargetFix, DLG_CHECK_BOOL);
2341
2342   // Clipper tool uses caulk
2343   check = gtk_check_button_new_with_label (_("Clipper tool uses caulk"));
2344   gtk_widget_show (check);
2345   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2346   AddDialogData (check, &m_bClipCaulk, DLG_CHECK_BOOL);
2347
2348   // Don't clamp plane points
2349   check = gtk_check_button_new_with_label (_("Don't clamp plane points"));
2350   gtk_widget_show (check);
2351   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2352   AddDialogData (check, &m_bNoClamp, DLG_CHECK_BOOL);
2353
2354   // Snap to grid
2355   check = gtk_check_button_new_with_label (_("Snap to grid"));
2356   gtk_widget_show (check);
2357   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
2358   AddDialogData (check, &m_bSnap, DLG_CHECK_BOOL);
2359
2360   // Select patch by bounding box
2361   check = gtk_check_button_new_with_label (_("Select patches by bounding box"));
2362   gtk_widget_show (check);
2363   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2364   AddDialogData (check, &m_bPatchBBoxSelect, DLG_CHECK_BOOL);
2365
2366   // Rotation increment
2367   // container
2368   table = gtk_table_new (2, 3, FALSE);
2369   gtk_widget_show (table);
2370   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2371   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2372   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2373
2374   // label
2375   label = gtk_label_new (_("Rotation increment:"));
2376   gtk_widget_show (label);
2377   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
2378                    (GtkAttachOptions) (0),
2379                    (GtkAttachOptions) (0), 0, 0);
2380
2381   // entry
2382   entry = gtk_entry_new ();
2383   gtk_widget_show (entry);
2384   gtk_widget_set_usize (entry, 60, -2);
2385   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
2386                    (GtkAttachOptions) (GTK_FILL),
2387                    (GtkAttachOptions) (0), 0, 0);
2388   AddDialogData (entry, &m_nRotation, DLG_ENTRY_INT);
2389
2390   // Undo levels
2391   // label
2392   label = gtk_label_new (_("Undo Levels:"));
2393   gtk_widget_show (label);
2394   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
2395                    (GtkAttachOptions) (0),
2396                    (GtkAttachOptions) (0), 0, 0);
2397
2398   // spinner (allows undo levels to be set to zero)
2399   spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (1, 0, 64, 1, 10, 10)), 1, 0);
2400   gtk_widget_show (spin);
2401   gtk_table_attach (GTK_TABLE (table), spin, 1, 2, 1, 2,
2402                    (GtkAttachOptions) (GTK_FILL),
2403                    (GtkAttachOptions) (0), 0, 0);
2404   gtk_widget_set_usize (spin, 60, -2);
2405   AddDialogData (spin, &m_nUndoLevels, DLG_SPIN_INT);
2406
2407   // Patch subdivisions
2408   // label
2409   label = gtk_label_new (_("Patch subdivisions:"));
2410   gtk_widget_show (label);
2411   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
2412                    (GtkAttachOptions) (0),
2413                    (GtkAttachOptions) (0), 0, 0);
2414
2415   // entry (spinner perhaps? [2-16])
2416   entry = gtk_entry_new ();
2417   gtk_widget_show (entry);
2418   gtk_widget_set_usize (entry, 60, -2);
2419   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 2, 3,
2420                    (GtkAttachOptions) (GTK_FILL),
2421                    (GtkAttachOptions) (0), 0, 0);
2422   AddDialogData (entry, &m_nSubdivisions, DLG_ENTRY_INT);
2423
2424   // Add the page to the notebook
2425   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2426
2427   /******** Save/Load group *********/
2428   preflabel = gtk_label_new(_("Startup/Auto save"));
2429   gtk_widget_show(preflabel);
2430   pageframe = gtk_frame_new(_("Startup/Auto save"));
2431   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2432   gtk_widget_show(pageframe);
2433   vbox = gtk_vbox_new(FALSE, 5);
2434   gtk_widget_show(vbox);
2435   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2436   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2437
2438   // Snapshots
2439   check = gtk_check_button_new_with_label (_("Snapshots"));
2440   gtk_widget_show (check);
2441   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2442   AddDialogData (check, &m_bSnapShots, DLG_CHECK_BOOL);
2443
2444   // load last project on open
2445   check = gtk_check_button_new_with_label (_("Load last project on open"));
2446   gtk_widget_show (check);
2447   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2448   AddDialogData (check, &m_bLoadLast, DLG_CHECK_BOOL);
2449
2450   // load last map on open
2451   check = gtk_check_button_new_with_label (_("Load last map on open"));
2452   gtk_widget_show (check);
2453   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2454   AddDialogData (check, &m_bLoadLastMap, DLG_CHECK_BOOL);
2455
2456   // Auto save..
2457   // container
2458   hbox2 = gtk_hbox_new (FALSE, 5);
2459   gtk_widget_show (hbox2);
2460   gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
2461   gtk_container_set_border_width (GTK_CONTAINER (hbox2), 0);
2462
2463   // label
2464   check = gtk_check_button_new_with_label (_("Auto save every"));
2465   gtk_widget_show (check);
2466   gtk_box_pack_start (GTK_BOX (hbox2), check, FALSE, FALSE, 0);
2467   AddDialogData (check, &m_bAutoSave, DLG_CHECK_BOOL);
2468
2469   // spinner
2470   spin = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (1, 1, 60, 1, 10, 10)), 1, 0);
2471   gtk_widget_show (spin);
2472   gtk_box_pack_start (GTK_BOX (hbox2), spin, FALSE, FALSE, 0);
2473   gtk_widget_set_usize (spin, 60, -2);
2474   AddDialogData (spin, &m_nAutoSave, DLG_SPIN_INT);
2475
2476   // label
2477   label = gtk_label_new (_("minutes"));
2478   gtk_widget_show (label);
2479   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
2480
2481   // Add the page to the notebook
2482   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2483
2484   /******** Paths group *********/
2485   preflabel = gtk_label_new(_("Paths"));
2486   gtk_widget_show(preflabel);
2487   pageframe = gtk_frame_new(_("Paths"));
2488   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2489   gtk_widget_show(pageframe);
2490   vbox = gtk_vbox_new(FALSE, 5);
2491   gtk_widget_show(vbox);
2492   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2493   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2494
2495   // prefab path
2496   // table
2497   table = gtk_table_new (3, 3, FALSE);
2498   gtk_widget_show (table);
2499   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2500   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2501   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2502
2503   // label
2504   label = gtk_label_new (_("Prefab path:"));
2505   gtk_widget_show (label);
2506   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
2507                    (GtkAttachOptions) (0),
2508                    (GtkAttachOptions) (0), 0, 0);
2509   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
2510
2511   // path entry
2512   entry = gtk_entry_new ();
2513   gtk_widget_show (entry);
2514   gtk_widget_set_usize(GTK_WIDGET(entry), 240, -2);
2515   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
2516                    (GtkAttachOptions) (GTK_FILL),
2517                    (GtkAttachOptions) (0), 1, 0);
2518   AddDialogData (entry, &m_strPrefabPath, DLG_ENTRY_TEXT);
2519
2520 #if 0
2521   // browse button
2522   button = gtk_button_new_with_label ("...");
2523   gtk_widget_show (button);
2524   gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (OnBtnBrowseprefab), this);
2525   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
2526                    (GtkAttachOptions) (0),
2527                    (GtkAttachOptions) (0), 0, 0);
2528 #endif
2529
2530   // User ini path
2531   // label
2532   label = gtk_label_new (_("User INI path:"));
2533   gtk_widget_show (label);
2534   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
2535                    (GtkAttachOptions) (0),
2536                    (GtkAttachOptions) (0), 0, 0);
2537   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
2538
2539   // user ini path entry
2540   entry = gtk_entry_new ();
2541   gtk_widget_show (entry);
2542   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2,
2543                    (GtkAttachOptions) (GTK_FILL),
2544                    (GtkAttachOptions) (0), 1, 0);
2545   AddDialogData (entry, &m_strUserPath, DLG_ENTRY_TEXT);
2546
2547   // user ini browse button
2548   button = gtk_button_new_with_label ("...");
2549   gtk_widget_show (button);
2550   gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (OnBtnBrowseuserini), this);
2551   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,
2552                    (GtkAttachOptions) (0),
2553                    (GtkAttachOptions) (0), 0, 0);
2554
2555   // Add the page to the notebook
2556   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2557
2558   /******** Brush group ********/
2559   preflabel = gtk_label_new(_("Brush"));
2560   gtk_widget_show(preflabel);
2561   pageframe = gtk_frame_new(_("Brush"));
2562   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2563   gtk_widget_show(pageframe);
2564   vbox = gtk_vbox_new(FALSE, 5);
2565   gtk_widget_show(vbox);
2566   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2567   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2568
2569   // default texture scale
2570   // table
2571   table = gtk_table_new(2, 1, FALSE); // I believe that the 2 and 1 are switched here, and this is
2572                                       // intentional to be consistent with other calls to gtk_table_new()
2573                                       // [that are probably also switched].
2574   gtk_widget_show(table);
2575   gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, TRUE, 0);
2576   gtk_table_set_row_spacings(GTK_TABLE(table), 5);
2577   gtk_table_set_col_spacings(GTK_TABLE(table), 5);
2578
2579   // label
2580   label = gtk_label_new(_("Default texture scale:"));
2581   gtk_widget_show(label);
2582   gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
2583   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
2584                    (GtkAttachOptions) (0),
2585                    (GtkAttachOptions) (0), 0, 0);
2586
2587   // scale entry
2588   entry = gtk_entry_new();
2589   gtk_widget_show(entry);
2590   gtk_widget_set_usize(GTK_WIDGET(entry), 60, -2);
2591   gtk_table_attach(GTK_TABLE(table), entry, 1, 2, 0, 1,
2592                    (GtkAttachOptions) (GTK_FILL),
2593                    (GtkAttachOptions) (0), 0, 0);
2594   AddDialogData(entry, &m_fDefTextureScale, DLG_ENTRY_FLOAT);
2595
2596   // Add the page to the notebook
2597   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2598
2599   /******** Misc group *********/
2600   preflabel = gtk_label_new(_("Misc"));
2601   gtk_widget_show(preflabel);
2602   pageframe = gtk_frame_new(_("Misc"));
2603   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2604   gtk_widget_show(pageframe);
2605   vbox = gtk_vbox_new(FALSE, 5);
2606   gtk_widget_show(vbox);
2607   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2608   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2609
2610   // Light drawing
2611   check = gtk_check_button_new_with_label (_("Light drawing"));
2612   gtk_widget_show (check);
2613   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2614   AddDialogData (check, &m_bNewLightDraw, DLG_CHECK_BOOL);
2615
2616   // Light radiuses
2617   // container
2618   table = gtk_table_new(2, 1, FALSE);
2619   gtk_widget_show(table);
2620   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2621   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2622   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2623
2624   label = gtk_label_new (_("Light radiuses:"));
2625   gtk_widget_show (label);
2626   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
2627   gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
2628                   (GtkAttachOptions) (0),
2629                   (GtkAttachOptions) (0), 0, 0);
2630
2631   combo_list = NULL;
2632   combo_list = g_list_append (combo_list, (void *)_("Disabled"));
2633   combo_list = g_list_append (combo_list, (void *)_("True Q3Map2 Style"));
2634   combo_list = g_list_append (combo_list, (void *)_("Classic Style"));
2635
2636   combo = gtk_combo_new ();
2637   gtk_combo_set_popdown_strings (GTK_COMBO (combo), combo_list);
2638   gtk_widget_show (combo);
2639   gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
2640                   (GtkAttachOptions) (GTK_FILL),
2641                   (GtkAttachOptions) (0), 0, 0);
2642   gtk_entry_set_editable (GTK_ENTRY (GTK_COMBO (combo)->entry), FALSE);
2643   AddDialogData (combo, &m_nLightRadiuses, DLG_COMBO_INT);
2644
2645 #ifdef _WIN32
2646   check = gtk_check_button_new_with_label (_("Use win32 file associations to open text files instead of builtin editor"));
2647   gtk_widget_show(check);
2648   gtk_box_pack_start(GTK_BOX (vbox), check, FALSE, FALSE, 0);
2649   AddDialogData (check, &g_PrefsDlg.m_bUseWin32Editor, DLG_CHECK_BOOL);
2650 #else
2651   // use custom shader editor
2652   check = gtk_check_button_new_with_label (_("Use Custom Shader Editor"));
2653   gtk_widget_show(check);
2654   gtk_box_pack_start(GTK_BOX (vbox), check, FALSE, FALSE, 0);
2655   gtk_signal_connect( GTK_OBJECT (check), "clicked", GTK_SIGNAL_FUNC(UpdateEditorSensitivity), this);
2656   g_object_set_data (G_OBJECT(dialog), "check_customeditor", check);
2657   AddDialogData (check, &g_PrefsDlg.m_bUseCustomEditor, DLG_CHECK_BOOL);
2658
2659   // custom shader editor executable
2660   // table
2661   table = gtk_table_new (3, 1, FALSE);
2662   gtk_widget_show (table);
2663   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);
2664   gtk_table_set_row_spacings (GTK_TABLE (table), 5);
2665   gtk_table_set_col_spacings (GTK_TABLE (table), 5);
2666
2667   // label
2668   label = gtk_label_new(_("Custom Editor Command"));
2669   gtk_widget_show(label);
2670   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
2671                    (GtkAttachOptions) (0),
2672                    (GtkAttachOptions) (0), 0, 0);
2673   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
2674   g_object_set_data (G_OBJECT(dialog), "label_customeditor", label);
2675   gtk_widget_set_sensitive (label, g_PrefsDlg.m_bUseCustomEditor);
2676
2677   // custom editor command entry
2678   entry = gtk_entry_new ();
2679   gtk_widget_show (entry);
2680   gtk_widget_set_usize(GTK_WIDGET(entry), 240, -2);
2681   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
2682                    (GtkAttachOptions) (GTK_FILL),
2683                    (GtkAttachOptions) (0), 1, 0);
2684   AddDialogData (entry, &m_strEditorCommand, DLG_ENTRY_TEXT);
2685   gtk_widget_set_sensitive (entry, g_PrefsDlg.m_bUseCustomEditor);
2686   g_object_set_data (G_OBJECT(dialog), "entry_customeditor", entry);
2687
2688   // browse button
2689   button = gtk_button_new_with_label (_("..."));
2690   gtk_widget_show (button);
2691   gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (OnBtnBrowseEditor), this);
2692   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
2693                    (GtkAttachOptions) (0),
2694                    (GtkAttachOptions) (0), 0, 0);
2695   g_object_set_data (G_OBJECT(dialog), "button_customeditor", button);
2696   gtk_widget_set_sensitive (button, g_PrefsDlg.m_bUseCustomEditor);
2697 #endif
2698
2699   // Add the page to the notebook
2700   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2701
2702   /******** BSP Monitoring group *********/
2703   // this is never displayed if the plugin isn't available
2704   preflabel = gtk_label_new(_("BSP Monitoring"));
2705   gtk_widget_show(preflabel);
2706   pageframe = gtk_frame_new(_("BSP Monitoring"));
2707   gtk_container_set_border_width(GTK_CONTAINER(pageframe), 5);
2708   gtk_widget_show(pageframe);
2709   vbox = gtk_vbox_new(FALSE, 5);
2710   gtk_widget_show(vbox);
2711   gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
2712   gtk_container_add(GTK_CONTAINER(pageframe), vbox);
2713
2714   // Enable BSP process monitoring
2715   check = gtk_check_button_new_with_label (_("Enable BSP process monitoring"));
2716   gtk_widget_show (check);
2717   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2718   g_object_set_data (G_OBJECT (dialog), "check_monitorbsp", check);
2719   gtk_signal_connect( GTK_OBJECT (check), "clicked", GTK_SIGNAL_FUNC(UpdateSensitivity), this );
2720   AddDialogData (check, &g_PrefsDlg.m_bWatchBSP, DLG_CHECK_BOOL);
2721
2722   // Stop on leak
2723   check = gtk_check_button_new_with_label (_("Stop compilation on leak"));
2724   gtk_widget_show (check);
2725   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2726   g_object_set_data (G_OBJECT (dialog), "check_leakstop", check);
2727   AddDialogData (check, &g_PrefsDlg.m_bLeakStop, DLG_CHECK_BOOL);
2728
2729   // engine after compile
2730   check = gtk_check_button_new_with_label (_("Run engine after compile"));
2731   gtk_widget_show (check);
2732   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2733   g_object_set_data (G_OBJECT (dialog), "check_runengine", check);
2734   gtk_signal_connect( GTK_OBJECT (check), "clicked", GTK_SIGNAL_FUNC(UpdateSensitivity), this );
2735   AddDialogData( check, &g_PrefsDlg.m_bRunQuake, DLG_CHECK_BOOL );
2736
2737   // sleep mode when running engine
2738   check = gtk_check_button_new_with_label (_("Activate sleep mode when running the engine"));
2739   gtk_widget_show (check);
2740   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2741   g_object_set_data (G_OBJECT (dialog), "check_sleep", check);
2742   AddDialogData( check, &g_PrefsDlg.m_bDoSleep, DLG_CHECK_BOOL );
2743
2744   // use q3map2's texture projection
2745   check = gtk_check_button_new_with_label (_("Texturing compatible with q3map2"));
2746   gtk_widget_show (check);
2747   gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
2748   g_object_set_data (G_OBJECT (dialog), "check_q3map2", check);
2749   AddDialogData( check, &g_PrefsDlg.m_bQ3Map2Texturing, DLG_CHECK_BOOL );
2750
2751   // Add the page to the notebook
2752   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pageframe, preflabel);
2753
2754   gtk_notebook_set_page(GTK_NOTEBOOK(notebook), PTAB_FRONT);
2755
2756   return;
2757 }
2758
2759 // end new prefs dialog
2760
2761 void PrefsDlg::LoadTexdefPref(texdef_t* pTexdef, char* pName)
2762 {
2763   char buffer[256];
2764
2765   memset(pTexdef, 0, sizeof(texdef_t));
2766
2767   sprintf(buffer, "%s%s", pName, TD_SCALE1_KEY);
2768   mLocalPrefs.GetPref(buffer, &pTexdef->scale[0],   0.5f);
2769
2770   sprintf(buffer, "%s%s", pName, TD_SCALE2_KEY);
2771   mLocalPrefs.GetPref(buffer, &pTexdef->scale[1],   0.5f);
2772
2773   sprintf(buffer, "%s%s", pName, TD_SHIFT1_KEY);
2774   mLocalPrefs.GetPref(buffer, &pTexdef->shift[0],   8.f);
2775
2776   sprintf(buffer, "%s%s", pName, TD_SHIFT2_KEY);
2777   mLocalPrefs.GetPref(buffer, &pTexdef->shift[1],   8.f);
2778
2779   sprintf(buffer, "%s%s", pName, TD_ROTATE_KEY);
2780   mLocalPrefs.GetPref(buffer, &pTexdef->rotate,     45);
2781 }
2782
2783 void PrefsDlg::UpdateTextureCompression()
2784 {
2785   // if OpenGL is not ready yet, don't do anything
2786   if (!g_qeglobals.m_bOpenGLReady) {
2787     Sys_Printf("OpenGL not ready - postpone texture compression capability check\n");
2788     return;
2789   }
2790
2791   if (g_qeglobals.bTextureCompressionSupported)
2792   {
2793     if (m_nTextureCompressionFormat >= 2 && !g_qeglobals.m_bS3CompressionSupported)
2794     {
2795       Sys_Printf("Inconsistant pref setting for texture compression (%d), rolling back\n", m_nTextureCompressionFormat);
2796       m_nTextureCompressionFormat = 1; // if this is not supported either, see below
2797     }
2798     if (m_nTextureCompressionFormat == 1 && !g_qeglobals.m_bOpenGLCompressionSupported)
2799     {
2800       Sys_Printf("Inconsistant pref setting for texture compression (GL_COMPRESSED_RGBA), rolling back\n");
2801       m_nTextureCompressionFormat = 0;
2802     }
2803     switch (m_nTextureCompressionFormat)
2804     {
2805     case (0):
2806       {
2807         g_qeglobals.texture_components = GL_RGBA;
2808         Sys_Printf("texture compression disabled by preferences settings\n");
2809         break;
2810       }
2811     case (1):
2812       {
2813         g_qeglobals.texture_components = GL_COMPRESSED_RGBA;
2814         Sys_Printf("OpenGL texture compression enabled\n");
2815         break;
2816       }
2817     case (2):
2818       {
2819         g_qeglobals.texture_components = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
2820         Sys_Printf("S3TC DXT1 texture compression enabled\n");
2821         break;
2822       }
2823     case (3):
2824       {
2825         g_qeglobals.texture_components = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
2826         Sys_Printf("S3TC DXT3 texture compression enabled\n");
2827         break;
2828       }
2829     case (4):
2830       {
2831         g_qeglobals.texture_components = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
2832         Sys_Printf("S3TC DXT5 texture compression enabled\n");
2833         break;
2834       }
2835     }
2836   }
2837   else
2838   {
2839     Sys_Printf("texture compression is not supported by your current graphic card/drivers\n");
2840     g_qeglobals.texture_components = GL_RGBA;
2841     m_nTextureCompressionFormat = 0;
2842   }
2843 }
2844
2845 #ifdef ATIHACK_812
2846 void PrefsDlg::UpdateATIHack() {
2847   // if OpenGL is not ready yet, don't do anything
2848   if (!g_qeglobals.m_bOpenGLReady) {
2849     Sys_Printf("OpenGL not ready - postpone ATI bug workaround setup\n");
2850     return;
2851   }
2852
2853   if (m_bGlATIHack) {
2854     qglCullFace = &qglCullFace_ATIHack;
2855     qglDisable = &qglDisable_ATIHack;
2856     qglEnable = &qglEnable_ATIHack;
2857     qglPolygonMode = &qglPolygonMode_ATIHack;
2858     Sys_Printf("ATI bug workaround enabled\n");
2859   } else {
2860     qglCullFace = qglCullFace_real;
2861     qglDisable = qglDisable_real;
2862     qglEnable = qglEnable_real;
2863     qglPolygonMode = qglPolygonMode_real;
2864     Sys_Printf("ATI bug workaround disabled\n");
2865   }
2866 }
2867 #endif
2868
2869 // TTimo: m_strEnginePath has a special status, if not found in registry we need to
2870 // initiliaze it for sure. It is not totally failsafe but we can use the same
2871 // code than in q3map, expecting to find some "quake" above us. If not, we prompt
2872 // for the engine executable path
2873 void PrefsDlg::LoadPrefs ()
2874 {
2875   int i;
2876
2877   // first things first, load prefs from global prefs
2878   mGamesDialog.LoadPrefs();
2879
2880   // if we already have a document loaded, we will free and reload from file
2881   if (mLocalPrefs.InUse()) {
2882     mLocalPrefs.Clear();
2883   }
2884
2885   // load local.pref file
2886   mLocalPrefs.ReadXMLFile(m_inipath->str);
2887
2888   mLocalPrefs.GetPref(PATCHSHOWBOUNDS_KEY,  &g_bPatchShowBounds,  FALSE);
2889   mLocalPrefs.GetPref(MOUSE_KEY,            &m_nMouse,            MOUSE_DEF);
2890   m_nMouseButtons = m_nMouse ? 3 : 2;
2891
2892         // project file
2893         // if it's not found here, mainframe.cpp will take care of finding one
2894   mLocalPrefs.GetPref(LASTPROJ_KEY, &m_strLastProject, "");
2895   mLocalPrefs.GetPref(LASTPROJVER_KEY, &m_nLastProjectVer, -1);
2896
2897         // prefab path
2898   // NOTE TTimo: I'm not sure why this is in prefs
2899   // should probably be a project setting
2900   // and I'm not sure that we really have a way to set this reliably either
2901   CString strPrefab;
2902   strPrefab = g_qeglobals.m_strHomeGame.GetBuffer();
2903   strPrefab += g_pGameDescription->mBaseGame.GetBuffer();
2904   strPrefab += "/prefabs/";
2905   mLocalPrefs.GetPref(PREFAB_KEY, &m_strPrefabPath, strPrefab);
2906
2907   mLocalPrefs.GetPref(LASTLIGHTINTENSITY_KEY, &m_iLastLightIntensity, 300);
2908   mLocalPrefs.GetPref(TLOCK_KEY,              &m_bTextureLock,        TLOCK_DEF);
2909   mLocalPrefs.GetPref(RLOCK_KEY,              &m_bRotateLock,         TLOCK_DEF);
2910   mLocalPrefs.GetPref(LASTMAP_KEY,            &m_strLastMap,          "");
2911   mLocalPrefs.GetPref(LOADLAST_KEY,           &m_bLoadLast,           LOADLAST_DEF);
2912   mLocalPrefs.GetPref(BSP_KEY,                &m_bInternalBSP,        FALSE);
2913   mLocalPrefs.GetPref(RCLICK_KEY,             &m_bRightClick,         TRUE);
2914   mLocalPrefs.GetPref(AUTOSAVE_KEY,           &m_bAutoSave,           TRUE);
2915   mLocalPrefs.GetPref(LOADLASTMAP_KEY,        &m_bLoadLastMap,        FALSE);
2916   mLocalPrefs.GetPref(TINYBRUSH_KEY,          &m_bCleanTiny,          FALSE);
2917   mLocalPrefs.GetPref(TINYSIZE_KEY,           &m_fTinySize,           0.5f);
2918   mLocalPrefs.GetPref(AUTOSAVETIME_KEY,       &m_nAutoSave,           5);
2919   mLocalPrefs.GetPref(SNAPSHOT_KEY,           &m_bSnapShots,          FALSE);
2920   mLocalPrefs.GetPref(MOVESPEED_KEY,          &m_nMoveSpeed,          100);
2921   mLocalPrefs.GetPref(ANGLESPEED_KEY,         &m_nAngleSpeed,         3);
2922   mLocalPrefs.GetPref(SETGAME_KEY,            &m_bSetGame,            FALSE);
2923   mLocalPrefs.GetPref(CAMXYUPDATE_KEY,        &m_bCamXYUpdate,        TRUE);
2924   mLocalPrefs.GetPref(CAMDRAGMULTISELECT_KEY, &m_nCamDragMultiSelect, TRUE);
2925   mLocalPrefs.GetPref(CAMFREELOOK_KEY,        &m_bCamFreeLook,        TRUE);
2926   mLocalPrefs.GetPref(CAMINVERSEMOUSE_KEY,    &m_bCamInverseMouse,    FALSE);
2927   mLocalPrefs.GetPref(CAMDISCRETE_KEY,        &m_bCamDiscrete,        TRUE);
2928   mLocalPrefs.GetPref(LIGHTDRAW_KEY,          &m_bNewLightDraw,       TRUE);
2929   mLocalPrefs.GetPref(CUBICCLIP_KEY,          &m_bCubicClipping,      TRUE);
2930   mLocalPrefs.GetPref(CUBICSCALE_KEY,         &m_nCubicScale,         13);
2931   mLocalPrefs.GetPref(ALTEDGE_KEY,            &m_bALTEdge,            FALSE);
2932   mLocalPrefs.GetPref(FACECOLORS_KEY,         &m_bFaceColors,         FALSE);
2933   mLocalPrefs.GetPref(XZVIS_KEY,              &m_bXZVis,              FALSE);
2934   mLocalPrefs.GetPref(YZVIS_KEY,              &m_bYZVis,              FALSE);
2935   mLocalPrefs.GetPref(ZVIS_KEY,               &m_bZVis,               FALSE);
2936   mLocalPrefs.GetPref(SIZEPAINT_KEY,          &m_bSizePaint,                  FALSE);
2937   mLocalPrefs.GetPref(DLLENTITIES_KEY,        &m_bDLLEntities,                FALSE);
2938
2939   mLocalPrefs.GetPref(DETACHABLEMENUS_KEY,    &m_bLatchedDetachableMenus,            TRUE);
2940   m_bDetachableMenus = m_bLatchedDetachableMenus;
2941
2942   if (g_pGameDescription->mNoPatch)
2943   {
2944     m_bPatchToolbar = false;
2945   }
2946   else
2947   {
2948     mLocalPrefs.GetPref(PATCHTOOLBAR_KEY,       &m_bLatchedPatchToolbar,               TRUE);
2949     m_bPatchToolbar = m_bLatchedPatchToolbar;
2950   }
2951
2952   mLocalPrefs.GetPref(WIDETOOLBAR_KEY,        &m_bLatchedWideToolbar,                TRUE);
2953   m_bWideToolbar = m_bLatchedWideToolbar;
2954
2955   mLocalPrefs.GetPref(PLUGINTOOLBAR_KEY, &m_bLatchedPluginToolbar, TRUE);
2956   m_bPluginToolbar = m_bLatchedPluginToolbar;
2957
2958   mLocalPrefs.GetPref(WINDOW_KEY,             (int*)&m_nLatchedView,  WINDOW_DEF);
2959   m_nView = m_nLatchedView;
2960
2961   mLocalPrefs.GetPref(FLOATINGZ_KEY,          &m_bLatchedFloatingZ,           FALSE);
2962   m_bFloatingZ = m_bLatchedFloatingZ;
2963
2964   mLocalPrefs.GetPref(TEXTUREQUALITY_KEY,     &m_nLatchedTextureQuality,             3);
2965   m_nTextureQuality = m_nLatchedTextureQuality;
2966
2967   mLocalPrefs.GetPref(LOADSHADERS_KEY,        &m_nLatchedShader,                     0);
2968   m_nShader = m_nLatchedShader;
2969
2970   mLocalPrefs.GetPref(NOCLAMP_KEY,            &m_bNoClamp,                    FALSE);
2971   mLocalPrefs.GetPref(SNAP_KEY,               &m_bSnap,                       TRUE);
2972   mLocalPrefs.GetPref(USERINI_KEY,            &m_strUserPath,                 "");
2973   mLocalPrefs.GetPref(ROTATION_KEY,           &m_nRotation,                   45);
2974   mLocalPrefs.GetPref(CHASEMOUSE_KEY,         &m_bChaseMouse,                 TRUE);
2975   mLocalPrefs.GetPref(ENTITYSHOW_KEY,         &m_nEntityShowState,            ENTITY_SKINNED_BOXED);
2976
2977   // this will probably need to be 75 or 100 for Q1.
2978   mLocalPrefs.GetPref(TEXTURESCALE_KEY,       &m_nTextureScale,               50);
2979
2980   // FIXME: Hydra - actually, this stuff is Q1,Q2 and HL specific.
2981   if ( (g_pGameDescription->mGameFile == "hl.game") )
2982   {
2983     // No BSP monitoring in the default compiler tools for Half-life (yet)
2984     mLocalPrefs.GetPref(WATCHBSP_KEY,           &m_bWatchBSP,                   FALSE);
2985
2986     // Texture subset on by default (HL specific really, because of halflife.wad's size)
2987     mLocalPrefs.GetPref(TEXTURE_KEY,            &m_bTextureWindow,              TRUE);
2988   }
2989   else if (g_pGameDescription->quake2)
2990   {
2991     // BSP monitoring is implemented in Quake2 and Heretic2 tools
2992     mLocalPrefs.GetPref(WATCHBSP_KEY,           &m_bWatchBSP,                   TRUE);
2993
2994     // Texture subset on by default (HL specific really, because of halflife.wad's size)
2995     mLocalPrefs.GetPref(TEXTURE_KEY,            &m_bTextureWindow,              TRUE);
2996   }
2997   else
2998   {
2999     mLocalPrefs.GetPref(WATCHBSP_KEY,           &m_bWatchBSP,                   WATCHBSP_DEF);
3000     mLocalPrefs.GetPref(TEXTURE_KEY,            &m_bTextureWindow,              FALSE);
3001   }
3002
3003
3004   mLocalPrefs.GetPref(TEXTURESCROLLBAR_KEY,   &m_bTextureScrollbar,           TRUE);
3005   mLocalPrefs.GetPref(DISPLAYLISTS_KEY,       &m_bDisplayLists,               TRUE);
3006   mLocalPrefs.GetPref(ANTIALIASEDLINES_KEY,   &m_bAntialiasedPointsAndLines,  FALSE);
3007   mLocalPrefs.GetPref(SWITCHCLIP_KEY,         &m_bSwitchClip,                 TRUE);
3008   mLocalPrefs.GetPref(SELWHOLEENTS_KEY,       &m_bSelectWholeEntities,        TRUE);
3009   mLocalPrefs.GetPref(SHOWSHADERS_KEY,        &m_bShowShaders,                TRUE);
3010   mLocalPrefs.GetPref(GLLIGHTING_KEY,         &m_bGLLighting,                 FALSE);
3011   mLocalPrefs.GetPref(NOSTIPPLE_KEY,          &m_bNoStipple,                  FALSE);
3012   mLocalPrefs.GetPref(UNDOLEVELS_KEY,         &m_nUndoLevels,                 30);
3013   mLocalPrefs.GetPref(VERTEXMODE_KEY,         &m_bVertexSplit,                TRUE);
3014   mLocalPrefs.GetPref(RUNQ2_KEY,              &m_bRunQuake,                   RUNQ2_DEF);
3015   mLocalPrefs.GetPref(LEAKSTOP_KEY,           &m_bLeakStop,                   TRUE);
3016   mLocalPrefs.GetPref(DOSLEEP_KEY,            &m_bDoSleep,                    FALSE);
3017   mLocalPrefs.GetPref(SELECTCURVES_KEY,       &m_bSelectCurves,               TRUE);
3018   mLocalPrefs.GetPref(SELECTMODELS_KEY,       &m_bSelectModels,               TRUE);
3019   mLocalPrefs.GetPref(SHADERLISTONLY_KEY,     &m_bTexturesShaderlistOnly,     FALSE);
3020   mLocalPrefs.GetPref(DEFAULTTEXURESCALE_KEY, &m_fDefTextureScale,            g_pGameDescription->mTextureDefaultScale);
3021   mLocalPrefs.GetPref(SUBDIVISIONS_KEY,       &m_nSubdivisions,               SUBDIVISIONS_DEF);
3022   mLocalPrefs.GetPref(CLIPCAULK_KEY,          &m_bClipCaulk,                  FALSE);
3023   mLocalPrefs.GetPref(SNAPTTOGRID_KEY,        &m_bSnapTToGrid,                FALSE);
3024   mLocalPrefs.GetPref(TARGETFIX_KEY,          &m_bDoTargetFix,                TRUE);
3025   mLocalPrefs.GetPref(WHEELINC_KEY,           &m_nWheelInc,                   64);
3026   mLocalPrefs.GetPref(PATCHBBOXSEL_KEY,       &m_bPatchBBoxSelect,            FALSE);
3027
3028   // Gef: Kyro GL_POINT workaround
3029   mLocalPrefs.GetPref(GLPOINTWORKAROUND_KEY,  &m_bGlPtWorkaround,             FALSE);
3030
3031   // window positioning
3032   mLocalPrefs.GetPref(ENTITYSPLIT1_KEY,       &mWindowInfo.nEntitySplit1,     -1);
3033   mLocalPrefs.GetPref(ENTITYSPLIT2_KEY,       &mWindowInfo.nEntitySplit2,     -1);
3034
3035   mLocalPrefs.GetPref(POSITIONX_KEY,          &mWindowInfo.position.x,        -1);
3036   mLocalPrefs.GetPref(POSITIONY_KEY,          &mWindowInfo.position.y,        -1);
3037   mLocalPrefs.GetPref(WIDTH_KEY,              &mWindowInfo.position.w,        -1);
3038   mLocalPrefs.GetPref(HEIGHT_KEY,             &mWindowInfo.position.h,        450);
3039
3040   const window_position_t default_window_pos = { 0, 0, 200, 200, };
3041
3042   mLocalPrefs.GetPref(ENTITYWND_KEY,          &mWindowInfo.posEntityWnd,      default_window_pos);
3043   mLocalPrefs.GetPref(MAPINFOWND_KEY,         &mWindowInfo.posMapInfoWnd,     default_window_pos);
3044   mLocalPrefs.GetPref(CAMWND_KEY,             &mWindowInfo.posCamWnd,         default_window_pos);
3045   mLocalPrefs.GetPref(ZWND_KEY,               &mWindowInfo.posZWnd,           default_window_pos);
3046   mLocalPrefs.GetPref(XYWND_KEY,              &mWindowInfo.posXYWnd,          default_window_pos);
3047   mLocalPrefs.GetPref(YZWND_KEY,              &mWindowInfo.posYZWnd,          default_window_pos);
3048   mLocalPrefs.GetPref(XZWND_KEY,              &mWindowInfo.posXZWnd,          default_window_pos);
3049   mLocalPrefs.GetPref(PATCHWND_KEY,           &mWindowInfo.posPatchWnd,       default_window_pos);
3050   mLocalPrefs.GetPref(SURFACEWND_KEY,         &mWindowInfo.posSurfaceWnd,     default_window_pos);
3051   mLocalPrefs.GetPref(ENTITYINFOWND_KEY,      &mWindowInfo.posEntityInfoWnd,  default_window_pos);
3052
3053   mLocalPrefs.GetPref(ZWIDTH_KEY,             &mWindowInfo.nZWidth,           30);
3054   mLocalPrefs.GetPref(XYHEIGHT_KEY,           &mWindowInfo.nXYHeight,         300);
3055   mLocalPrefs.GetPref(XYWIDTH_KEY,            &mWindowInfo.nXYWidth,          300);
3056   mLocalPrefs.GetPref(CAMWIDTH_KEY,           &mWindowInfo.nCamWidth,         200);
3057   mLocalPrefs.GetPref(CAMHEIGHT_KEY,          &mWindowInfo.nCamHeight,        200);
3058   mLocalPrefs.GetPref(ZFLOATWIDTH_KEY,        &mWindowInfo.nZFloatWidth,      300);
3059 #ifdef _WIN32
3060   mLocalPrefs.GetPref(STATE_KEY,              &mWindowInfo.nState,            SW_SHOW);
3061 #endif
3062
3063   // menu stuff
3064   mLocalPrefs.GetPref(COUNT_KEY,              &m_nMRUCount,                   0);
3065   for(i = 0; i < 4; i++)
3066   {
3067     char buf[64];
3068     sprintf (buf, "%s%d", FILE_KEY, i);
3069     mLocalPrefs.GetPref(buf,                  &m_strMRUFiles[i],              "");
3070   }
3071
3072   // some platform specific prefs
3073 #ifdef _WIN32
3074   mLocalPrefs.GetPref(NATIVEGUI_KEY,          &m_bNativeGUI,                  TRUE);
3075   mLocalPrefs.GetPref(STARTONPRIMMON_KEY,     &m_bStartOnPrimMon,             FALSE);
3076 #endif
3077
3078   mLocalPrefs.GetPref(SI_TEXMENU_KEY,         &g_qeglobals.d_savedinfo.iTexMenu,                ID_VIEW_BILINEARMIPMAP);
3079   mLocalPrefs.GetPref(SI_GAMMA_KEY,           &g_qeglobals.d_savedinfo.fGamma,                  1.0f);
3080   mLocalPrefs.GetPref(SI_EXCLUDE_KEY,         &g_qeglobals.d_savedinfo.exclude,                 0); // nothing filtered by default
3081   mLocalPrefs.GetPref(SI_INCLUDE_KEY,         &g_qeglobals.d_savedinfo.include,                 INCLUDE_NAMES | INCLUDE_COORDS | INCLUDE_ANGLES | INCLUDE_CAMERATINT);
3082   mLocalPrefs.GetPref(SI_SHOWNAMES_KEY,       &g_qeglobals.d_savedinfo.show_names,              FALSE);
3083   mLocalPrefs.GetPref(SI_SHOWCOORDS_KEY,      &g_qeglobals.d_savedinfo.show_coordinates,        TRUE);
3084   mLocalPrefs.GetPref(SI_SHOWANGLES_KEY,      &g_qeglobals.d_savedinfo.show_angles,             TRUE);
3085   mLocalPrefs.GetPref(SI_SHOWOUTLINES_KEY,    &g_qeglobals.d_savedinfo.show_outline,            FALSE);
3086   mLocalPrefs.GetPref(SI_SHOWAXIS_KEY,        &g_qeglobals.d_savedinfo.show_axis,               TRUE);
3087   mLocalPrefs.GetPref(SI_NOSELOUTLINES_KEY,   &g_qeglobals.d_savedinfo.bNoSelectedOutlines,     FALSE);
3088
3089   mLocalPrefs.GetPref(SI_OUTLINESTYLE_KEY,   &g_qeglobals.d_savedinfo.iSelectedOutlinesStyle,  OUTLINE_ZBUF|OUTLINE_BSEL);
3090
3091   LoadTexdefPref(&g_qeglobals.d_savedinfo.m_SIIncrement, SI_SURFACE_TEXDEF_KEY);
3092   LoadTexdefPref(&g_qeglobals.d_savedinfo.m_PIIncrement, SI_PATCH_TEXDEF_KEY);
3093
3094   // text editor binding
3095 #ifdef _WIN32
3096   mLocalPrefs.GetPref(CUSTOMSHADEREDITOR_KEY, &m_bUseWin32Editor, TRUE);
3097 #else
3098   mLocalPrefs.GetPref(CUSTOMSHADEREDITOR_KEY, &m_bUseCustomEditor, FALSE);
3099   mLocalPrefs.GetPref(CUSTOMSHADEREDITORCOMMAND_KEY, &m_strEditorCommand, "");
3100 #endif
3101
3102
3103   vec3_t vDefaultAxisColours[3] = {
3104     {0.f, 0.5f, 0.f},
3105     {0.f, 0.f, 1.f},
3106     {1.f, 0.f, 0.f},
3107   };
3108
3109   for(i = 0; i < 3; i++) {
3110     char buf[64];
3111     sprintf(buf, "%s%d", SI_AXISCOLORS_KEY, i);
3112     mLocalPrefs.GetPref(buf,   g_qeglobals.d_savedinfo.AxisColors[i], vDefaultAxisColours[i]);
3113   }
3114
3115   vec3_t vDefaultColours[COLOR_LAST] = {
3116     {0.25f, 0.25f,  0.25f},
3117     {1.f,   1.f,    1.f},
3118     {0.75f, 0.75f,  0.75f},
3119     {0.5f,  0.5f,   0.5f},
3120     {0.25f, 0.25f,  0.25f},
3121     {0.0f,  0.0f,   0.0f},
3122     {0.f,   0.f,    1.f},
3123     {0.f,   0.f,    0.f},
3124     {0.f,   0.f,    0.f},
3125     {1.f,   0.f,    0.f},
3126     {0.f,   0.f,    1.f},
3127     {0.5f,  0.f,    0.75f},
3128     {1.0f,  0.f,    0.f},
3129     {0.f,   0.f,    0.f},
3130     {0.f,   0.f,    0.f},
3131   };
3132
3133   for(i = 0; i < COLOR_LAST; i++) {
3134     char buf[64];
3135     sprintf(buf, "%s%d", SI_COLORS_KEY, i);
3136     mLocalPrefs.GetPref(buf,   g_qeglobals.d_savedinfo.colors[i], vDefaultColours[i]);
3137   }
3138
3139   mLocalPrefs.GetPref(TEXTURECOMPRESSIONFORMAT_KEY, &m_nTextureCompressionFormat, 1);
3140
3141   mLocalPrefs.GetPref(LIGHTRADIUS_KEY, &m_nLightRadiuses, TRUE);
3142
3143   mLocalPrefs.GetPref(Q3MAP2TEX_KEY, &m_bQ3Map2Texturing, TRUE);
3144
3145 #ifdef ATIHACK_812
3146         mLocalPrefs.GetPref(ATIHACK_KEY, &m_bGlATIHack, FALSE);
3147 #endif
3148
3149   Undo_SetMaxSize(m_nUndoLevels); // set it internally as well / FIXME: why not just have one global value?
3150
3151   UpdateTextureCompression();
3152
3153 #ifdef ATIHACK_812
3154   UpdateATIHack();
3155 #endif
3156
3157   if (mLocalPrefs.mbEmpty)
3158   {
3159     mLocalPrefs.mbEmpty = false;
3160     Sys_Printf("Saving local.pref with default pref values\n");
3161     SavePrefs();
3162   }
3163 }
3164
3165 void PrefsDlg::SavePrefs ()
3166 {
3167   if (g_qeglobals.disable_ini)
3168     return;
3169
3170 #ifdef _DEBUG
3171   Sys_Printf("PrefsDlg::SavePrefs\n");
3172 #endif
3173
3174   // this will take care of copying back from the dialog to the variables
3175   // NOTE: it may be overkill to call systematically before a SavePrefs, but it's safer
3176   // this will also cause an UpdateData for the mGamesDialog
3177   UpdateData(TRUE);
3178
3179   mGamesDialog.SavePrefs();
3180
3181   // update the tree and save it
3182   mLocalPrefs.UpdatePrefTree();
3183   if (!mLocalPrefs.WriteXMLFile(m_inipath->str))
3184     Sys_FPrintf(SYS_ERR, "Error occured while saving local prefs file '%s'\n", m_inipath->str);
3185
3186   if ( m_nMouse == 0 ) {
3187           m_nMouseButtons = 2;
3188   } else {
3189           m_nMouseButtons = 3;
3190   }
3191
3192 }
3193
3194 void PrefsDlg::PostModal (int code)
3195 {
3196   if (code == IDOK)
3197   {
3198     SavePrefs();
3199     // make sure the logfile is ok
3200     Sys_LogFile();
3201     #ifdef ATIHACK_812
3202       UpdateATIHack();
3203     #endif
3204     if (g_pParentWnd)
3205       g_pParentWnd->SetGridStatus();
3206     Sys_UpdateWindows(W_ALL);
3207     if (m_nUndoLevels != 0)
3208                 Undo_SetMaxSize(m_nUndoLevels);
3209   }
3210 }
3211
3212 void PrefsDlg::DoEditorSensitivity()
3213 {
3214   if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data (G_OBJECT(m_pWidget), "check_customeditor"))))
3215   {
3216     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "label_customeditor")), TRUE);
3217     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "entry_customeditor")), TRUE);
3218     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "button_customeditor")), TRUE);
3219   }
3220   else
3221   {
3222     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "label_customeditor")), FALSE);
3223     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "entry_customeditor")), FALSE);
3224     gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data (G_OBJECT(m_pWidget), "button_customeditor")), FALSE);
3225   }
3226 }
3227
3228 void PrefsDlg::DoSensitivity()
3229 {
3230 #if 0
3231   // first, look at the project file version ... will monitoring work?
3232   // project files now XML, guaranteed to be at least version 2
3233   if (0)//IntForKey( g_qeglobals.d_project_entity, "version" ) < 2)
3234   {
3235     if (m_bWarn)
3236     {
3237       Str Msg;
3238       Msg = "The current project file (";
3239       Msg += g_PrefsDlg.m_strLastProject;
3240       Msg += ") is not at least version 2.\nI need version 2 or above to setup BSP monitoring correctly.";
3241       gtk_MessageBox(m_pWidget, Msg.GetBuffer(), MB_OK );
3242
3243       m_bWarn = false;
3244     }
3245
3246     // go ahead, disable everybuddy
3247     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_leakstop" )), FALSE );
3248     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_monitorbsp" )), FALSE );
3249     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_runengine" )), FALSE );
3250     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_sleep" )), FALSE );
3251   }
3252   else
3253   {
3254 #endif
3255 //    m_bWarn = true;
3256
3257     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_leakstop" )), TRUE );
3258     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_monitorbsp" )), TRUE );
3259     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_runengine" )), TRUE );
3260     gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_sleep" )), TRUE );
3261
3262     if ( ! gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_object_get_data( G_OBJECT(m_pWidget), "check_monitorbsp" ) ) ) )
3263     {
3264       gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_leakstop" )), FALSE );
3265       gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_runengine" )), FALSE );
3266       gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_sleep" )), FALSE );
3267     } else if (! gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( g_object_get_data( G_OBJECT(m_pWidget), "check_runengine" ) ) ) )
3268     {
3269       gtk_widget_set_sensitive( GTK_WIDGET(g_object_get_data( G_OBJECT(m_pWidget), "check_sleep" )), FALSE );
3270     }
3271 }
3272
3273 /*
3274 ============================================================
3275 CGameInstall
3276 ============================================================
3277 */
3278
3279 CGameInstall::CGameInstall() {
3280         memset( m_availGames, 0, sizeof( m_availGames ) );
3281 }
3282
3283 void CGameInstall::OnBtnBrowseEngine( GtkWidget *widget, gpointer data ) {
3284         Sys_Printf( "OnBtnBrowseEngine\n" );
3285
3286         CGameInstall* i = static_cast<CGameInstall*>( data );
3287         char *dir = dir_dialog( i->m_pWidget, _("Select game directory"), NULL );
3288
3289         i->UpdateData( TRUE );
3290
3291         if ( dir != NULL ) {
3292                 i->m_strEngine = dir;
3293                 i->UpdateData( FALSE );
3294                 g_free( dir );
3295         }
3296 }
3297
3298 void CGameInstall::OnGameSelectChanged( GtkWidget *widget, gpointer data ) {
3299         Sys_Printf( "OnGameSelectChanged\n" );
3300
3301         CGameInstall* i = static_cast<CGameInstall*>( data );
3302         i->UpdateData( TRUE );
3303         i->m_strName = gtk_combo_box_get_active_text( GTK_COMBO_BOX( widget ) );
3304         i->UpdateData( FALSE );
3305 }
3306
3307 void CGameInstall::BuildDialog() {
3308         GtkWidget *dlg, *vbox1, *button, *text, *combo, *entry, *hbox;
3309
3310         dlg = m_pWidget;
3311         gtk_window_set_title( GTK_WINDOW( dlg ), _("Configure games") );
3312
3313         vbox1 = gtk_vbox_new( FALSE, 0 );
3314         gtk_widget_show( vbox1 );
3315         gtk_container_add( GTK_CONTAINER( dlg ), vbox1 );
3316
3317         text = gtk_label_new( _("Select the game to configure") );
3318         gtk_widget_show( text );
3319         gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 );
3320
3321         combo = gtk_combo_box_new_text();
3322         gtk_widget_show( combo );
3323         gtk_box_pack_start( GTK_BOX( vbox1 ), combo, FALSE, FALSE, 0 );
3324
3325         //      GList *combo_list = NULL;
3326         int iGame = 0;
3327         while ( m_availGames[ iGame ] != GAME_NONE ) {
3328                 switch ( m_availGames[ iGame ] ) {
3329                 case GAME_Q2:
3330                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Quake II") );
3331                         break;
3332                 case GAME_Q3:
3333                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Quake III Arena and mods") );
3334                         break;
3335                 case GAME_URT:
3336                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Urban Terror (standalone)") );
3337                         break;
3338                 case GAME_UFOAI:
3339                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("UFO: Alien Invasion") );
3340                         break;
3341                 case GAME_Q2W:
3342                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Quake2World") );
3343                         break;
3344                 case GAME_WARSOW:
3345                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Warsow") );
3346                         break;
3347                 case GAME_NEXUIZ:
3348                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Nexuiz") );
3349                         break;
3350                 case GAME_TREMULOUS:
3351                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Tremulous") );
3352                         break;
3353                 case GAME_JA:
3354                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Jedi Academy and mods") );
3355                         break;
3356                 case GAME_REACTION:
3357                         gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), _("Reaction Quake 3") );
3358                         break;
3359                 }
3360                 iGame++;
3361         }
3362         AddDialogData( combo, &m_nComboSelect, DLG_COMBO_BOX_INT );
3363         gtk_signal_connect( GTK_OBJECT( combo ), "changed", G_CALLBACK( OnGameSelectChanged ), this );
3364         gtk_combo_box_set_active( GTK_COMBO_BOX( combo ), 0 );  // NOTE: will trigger signal
3365
3366         text = gtk_label_new( _("Name:") );
3367         gtk_widget_show( text );
3368         gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 );
3369
3370         entry = gtk_entry_new();
3371         gtk_widget_show( entry );
3372         gtk_box_pack_start( GTK_BOX( vbox1 ), entry, FALSE, FALSE, 0 );
3373         AddDialogData( entry, &m_strName, DLG_ENTRY_TEXT );
3374
3375         text = gtk_label_new( _("Engine directory:") );
3376         gtk_widget_show( text );
3377         gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 );
3378
3379         hbox = gtk_hbox_new( FALSE, 0 );
3380         gtk_widget_show( hbox );
3381         gtk_box_pack_start( GTK_BOX( vbox1 ), hbox, FALSE, FALSE, 0 );
3382
3383         entry = gtk_entry_new();
3384         gtk_widget_show( entry );
3385         gtk_box_pack_start( GTK_BOX( hbox ), entry, FALSE, FALSE, 0 );
3386         AddDialogData( entry, &m_strEngine, DLG_ENTRY_TEXT );
3387
3388         button = gtk_button_new_with_label (_("..."));
3389         gtk_widget_show( button );
3390         gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( OnBtnBrowseEngine ), this );
3391         gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
3392
3393         // this gets done in the project stuff atm
3394 #if 0
3395         text = gtk_label_new( _("Mod subdirectory:") );
3396         gtk_widget_show( text );
3397         gtk_box_pack_start( GTK_BOX( vbox1 ), text, FALSE, FALSE, 0 );
3398
3399         entry = gtk_entry_new();
3400         gtk_widget_show( entry );
3401         gtk_box_pack_start( GTK_BOX( vbox1 ), entry, FALSE, FALSE, 0 );
3402         AddDialogData( entry, &m_strMod, DLG_ENTRY_TEXT );
3403 #endif
3404
3405         button = gtk_button_new_with_label( _("OK") );
3406         gtk_widget_show( button );
3407         gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 );
3408         AddModalButton( button, IDOK );
3409
3410         button = gtk_button_new_with_label( _("Cancel") );
3411         gtk_widget_show( button );
3412         gtk_box_pack_start( GTK_BOX( vbox1 ), button, FALSE, FALSE, 0 );
3413         AddModalButton( button, IDCANCEL );
3414
3415         gtk_widget_set_usize( button, 60, -2 );
3416 }
3417
3418 void CGameInstall::Run() {
3419         ScanGames();
3420         if ( m_availGames[0] == GAME_NONE ) {
3421                 return;
3422         }
3423         if ( DoModal() == IDCANCEL ) {
3424                 Sys_Printf( "game dialog cancelled\n" );
3425                 return;
3426         }
3427         Sys_Printf( "combo: %d name: %s engine: %s mod: %s\n", m_nComboSelect, m_strName.GetBuffer(), m_strEngine.GetBuffer(), m_strMod.GetBuffer() );
3428
3429         // write out the game file
3430         Str gameFilePath = g_strAppPath.GetBuffer();
3431         gameFilePath += "games/";
3432         gameFilePath += m_strName.GetBuffer();
3433         gameFilePath += ".game";
3434         Sys_Printf( "game file: %s\n", gameFilePath.GetBuffer() );
3435
3436         FILE * fg = fopen( gameFilePath.GetBuffer(), "w" );
3437         if ( fg == NULL ) {
3438                 Error( "Failed to open %s for writing\n", gameFilePath.GetBuffer() );
3439         }
3440         fprintf( fg, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"yes\"?>\n<game\n" );
3441         fprintf( fg, "  name=\"%s\"\n", m_strName.GetBuffer() );
3442         fprintf( fg, "  "ENGINEPATH_ATTRIBUTE"=\"%s\"\n", m_strEngine.GetBuffer() );
3443         switch ( m_availGames[ m_nComboSelect ] ) {
3444         case GAME_Q2: {
3445                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/Quake2Pack/game\"\n", g_strAppPath.GetBuffer() );
3446                 fprintf( fg, "  prefix=\".quake2\"\n" );
3447                 Str source = g_strAppPath.GetBuffer();
3448                 source += "installs/";
3449                 source += Q2_PACK;
3450                 source += "/install/";
3451                 Str dest = m_strEngine.GetBuffer();
3452                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3453                 fprintf( fg, "  basegame=\"baseq2\"\n" );
3454                 break;
3455         }
3456         case GAME_Q3: {
3457                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/Q3Pack/game\"\n", g_strAppPath.GetBuffer() );
3458                 fprintf( fg, "  prefix=\".q3a\"\n" );
3459                 Str source = g_strAppPath.GetBuffer();
3460                 source += "installs/";
3461                 source += Q3_PACK;
3462                 source += "/install/";
3463                 Str dest = m_strEngine.GetBuffer();
3464                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3465                 fprintf( fg, "  basegame=\"baseq3\"\n" );
3466                 break;
3467         }
3468         case GAME_URT: {
3469                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/UrTPack/game\"\n", g_strAppPath.GetBuffer() );
3470                 fprintf( fg, "  prefix=\".q3a\"\n" );
3471                 Str source = g_strAppPath.GetBuffer();
3472                 source += "installs/";
3473                 source += URT_PACK;
3474                 source += "/install/";
3475                 Str dest = m_strEngine.GetBuffer();
3476                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3477                 fprintf( fg, "  basegame=\"q3ut4\"\n" );
3478                 break;
3479         }
3480         case GAME_UFOAI: {
3481                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/UFOAIPack/game\"\n", g_strAppPath.GetBuffer() );
3482                 fprintf( fg, "  prefix=\".ufoai\"\n" );
3483                 Str source = g_strAppPath.GetBuffer();
3484                 source += "installs/";
3485                 source += UFOAI_PACK;
3486                 source += "/install/";
3487                 Str dest = m_strEngine.GetBuffer();
3488                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3489                 fprintf( fg, "  basegame=\"base\"\n" );
3490                 break;
3491         }
3492         case GAME_Q2W: {
3493                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/Q2WPack/game\"\n", g_strAppPath.GetBuffer() );
3494                 fprintf( fg, "  prefix=\".quake2world\"\n" );
3495                 Str source = g_strAppPath.GetBuffer();
3496                 source += "installs/";
3497                 source += Q2W_PACK;
3498                 source += "/install/";
3499                 Str dest = m_strEngine.GetBuffer();
3500                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3501                 fprintf( fg, "  basegame=\"default\"\n" );
3502                 break;
3503         }
3504         case GAME_WARSOW: {
3505                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/WarsowPack/game\"\n", g_strAppPath.GetBuffer() );
3506                 fprintf( fg, "  prefix=\".warsow\"\n" );
3507                 Str source = g_strAppPath.GetBuffer();
3508                 source += "installs/";
3509                 source += WARSOW_PACK;
3510                 source += "/install/";
3511                 Str dest = m_strEngine.GetBuffer();
3512                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3513                 fprintf( fg, "  basegame=\"basewsw\"\n" );
3514                 break;
3515         }
3516         case GAME_NEXUIZ: {
3517                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/NexuizPack/game\"\n", g_strAppPath.GetBuffer() );
3518                 fprintf( fg, "  prefix=\".nexuiz\"\n" );
3519                 Str source = g_strAppPath.GetBuffer();
3520                 source += "installs/";
3521                 source += NEXUIZ_PACK;
3522                 source += "/install/";
3523                 Str dest = m_strEngine.GetBuffer();
3524                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3525                 fprintf( fg, "  basegame=\"data\"\n" );
3526                 break;
3527         }
3528         case GAME_TREMULOUS: {
3529                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/TremulousPack/game\"\n", g_strAppPath.GetBuffer() );
3530                 fprintf( fg, "  prefix=\".tremulous\"\n" );
3531                 Str source = g_strAppPath.GetBuffer();
3532                 source += "installs/";
3533                 source += TREMULOUS_PACK;
3534                 source += "/install/";
3535                 Str dest = m_strEngine.GetBuffer();
3536                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3537                 fprintf( fg, "  basegame=\"base\"\n" );
3538                 break;
3539         }
3540         case GAME_JA: {
3541                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/JAPack/game\"\n", g_strAppPath.GetBuffer() );
3542                 fprintf( fg, "  prefix=\".ja\"\n" );
3543                 Str source = g_strAppPath.GetBuffer();
3544                 source += "installs/";
3545                 source += JA_PACK;
3546                 source += "/install/";
3547                 Str dest = m_strEngine.GetBuffer();
3548                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3549                 fprintf( fg, "  basegame=\"base\"\n" );
3550                 break;
3551         }
3552         case GAME_REACTION: {
3553                 fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/"REACTION_PACK"/game\"\n", g_strAppPath.GetBuffer() );
3554                 fprintf( fg, "  prefix=\".Reaction\"\n" );
3555                 Str source = g_strAppPath.GetBuffer();
3556                 source += "installs/";
3557                 source += REACTION_PACK;
3558                 source += "/install/";
3559                 Str dest = m_strEngine.GetBuffer();
3560                 CopyTree( source.GetBuffer(), dest.GetBuffer() );
3561                 fprintf( fg, "  basegame=\"Boomstick\"\n" );
3562                 fprintf( fg, "  default_scale=\"0.5\"\n" ); // Superfluous because the default is already 0.5,
3563                                                         // but demonstrates how to set the default texture scale
3564                                                         // for a specific game.
3565                 break;
3566         }
3567         }
3568         fprintf( fg, "/>\n" );
3569         fclose( fg );
3570 }
3571
3572 /*
3573 ===============
3574 CGameInstall::ScanGames
3575 scan for active games that can be installed, based on the presence
3576 ===============
3577 */
3578 void CGameInstall::ScanGames() {
3579         Str                             pakPaths = g_strAppPath.GetBuffer();
3580         int                             iGame = 0;
3581         const char              *dirname;
3582
3583         pakPaths +=     "installs/";
3584         FindFiles fileScan( pakPaths.GetBuffer() );
3585         while ( ( dirname = fileScan.NextFile() ) != NULL ) {
3586                 if ( stricmp( dirname, Q3_PACK ) == 0 ) {
3587                         m_availGames[ iGame++ ] = GAME_Q3;
3588                 }
3589                 if ( stricmp( dirname, URT_PACK ) == 0 ) {
3590                         m_availGames[ iGame++ ] = GAME_URT;
3591                 }
3592                 if ( stricmp( dirname, UFOAI_PACK ) == 0 ) {
3593                         m_availGames[ iGame++ ] = GAME_UFOAI;
3594                 }
3595                 if ( stricmp( dirname, Q2W_PACK ) == 0 ) {
3596                         m_availGames[ iGame++ ] = GAME_Q2W;
3597                 }
3598                 if ( stricmp( dirname, WARSOW_PACK ) == 0 ) {
3599                         m_availGames[ iGame++ ] = GAME_WARSOW;
3600                 }
3601                 if ( stricmp( dirname, NEXUIZ_PACK ) == 0 ) {
3602                         m_availGames[ iGame++ ] = GAME_NEXUIZ;
3603                 }
3604                 if ( stricmp( dirname, Q2_PACK ) == 0 ) {
3605                         m_availGames[ iGame++ ] = GAME_Q2;
3606                 }
3607                 if ( stricmp( dirname, TREMULOUS_PACK ) == 0 ) {
3608                         m_availGames[ iGame++ ] = GAME_TREMULOUS;
3609                 }
3610                 if ( stricmp( dirname, JA_PACK ) == 0 ) {
3611                         m_availGames[ iGame++ ] = GAME_JA;
3612                 }
3613                 if ( stricmp( dirname, REACTION_PACK ) == 0 ) {
3614                         m_availGames[ iGame++ ] = GAME_REACTION;
3615                 }
3616         }
3617         Sys_Printf("No installable games found in: %s\n",
3618                 pakPaths.GetBuffer() );
3619 }
3620