2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
23 // Main Window for Q3Radiant
25 // Leonardo Zide (leo@lokigames.com)
28 #include "mainframe.h"
30 #include "debugging/debugging.h"
33 #include "ifilesystem.h"
41 #include "moduleobserver.h"
45 #include <gdk/gdkkeysyms.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtkvbox.h>
48 #include <gtk/gtkframe.h>
49 #include <gtk/gtklabel.h>
50 #include <gtk/gtkhpaned.h>
51 #include <gtk/gtkvpaned.h>
52 #include <gtk/gtktoolbar.h>
53 #include <gtk/gtkmenubar.h>
54 #include <gtk/gtkimage.h>
55 #include <gtk/gtktable.h>
60 #include "stream/stringstream.h"
61 #include "signal/isignal.h"
64 #include "eclasslib.h"
65 #include "moduleobservers.h"
67 #include "gtkutil/clipboard.h"
68 #include "gtkutil/container.h"
69 #include "gtkutil/frame.h"
70 #include "gtkutil/glfont.h"
71 #include "gtkutil/glwidget.h"
72 #include "gtkutil/image.h"
73 #include "gtkutil/menu.h"
74 #include "gtkutil/paned.h"
75 #include "gtkutil/widget.h"
79 #include "brushmanip.h"
80 #include "brushmodule.h"
81 #include "camwindow.h"
86 #include "entityinspector.h"
87 #include "entitylist.h"
89 #include "findtexturedialog.h"
91 #include "groupdialog.h"
98 #include "patchdialog.h"
99 #include "patchmanip.h"
101 #include "pluginmanager.h"
102 #include "pluginmenu.h"
103 #include "plugintoolbar.h"
105 #include "preferences.h"
110 #include "surfacedialog.h"
111 #include "textures.h"
112 #include "texwindow.h"
114 #include "xywindow.h"
115 #include "windowobservers.h"
116 #include "renderstate.h"
117 #include "feedback.h"
118 #include "referencecache.h"
122 struct layout_globals_t
124 WindowPosition m_position;
134 m_position(-1, -1, 640, 480),
140 nState(GDK_WINDOW_STATE_MAXIMIZED)
145 layout_globals_t g_layout_globals;
146 glwindow_globals_t g_glwindow_globals;
150 class VFSModuleObserver : public ModuleObserver
152 std::size_t m_unrealised;
154 VFSModuleObserver() : m_unrealised(1)
159 if(--m_unrealised == 0)
162 GlobalFileSystem().initialise();
167 if(++m_unrealised == 1)
169 GlobalFileSystem().shutdown();
174 VFSModuleObserver g_VFSModuleObserver;
178 Radiant_attachHomePathsObserver(g_VFSModuleObserver);
182 Radiant_detachHomePathsObserver(g_VFSModuleObserver);
187 void HomePaths_Realise()
190 const char* prefix = g_pGameDescription->getKeyValue("prefix");
191 if(!string_empty(prefix))
193 StringOutputStream path(256);
194 path << DirectoryCleaned(g_get_home_dir()) << prefix << "/";
195 g_qeglobals.m_userEnginePath = path.c_str();
196 Q_mkdir(g_qeglobals.m_userEnginePath.c_str());
200 if(!string_empty(prefix))
202 StringOutputStream path(256);
203 TCHAR mydocsdir[MAX_PATH + 1];
204 if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir))
206 path << DirectoryCleaned(mydocsdir) << "My Games/" << prefix << "/";
207 // win32: only add it if it already exists
208 if(file_is_directory(path.c_str()))
209 g_qeglobals.m_userEnginePath = path.c_str();
211 g_qeglobals.m_userEnginePath = EnginePath_get();
215 g_qeglobals.m_userEnginePath = EnginePath_get();
221 g_qeglobals.m_userEnginePath = EnginePath_get();
225 StringOutputStream path(256);
226 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
227 g_qeglobals.m_userGamePath = path.c_str();
229 ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "HomePaths_Realise: user-game-path is empty");
230 Q_mkdir(g_qeglobals.m_userGamePath.c_str());
233 ModuleObservers g_homePathObservers;
235 void Radiant_attachHomePathsObserver(ModuleObserver& observer)
237 g_homePathObservers.attach(observer);
240 void Radiant_detachHomePathsObserver(ModuleObserver& observer)
242 g_homePathObservers.detach(observer);
245 class HomePathsModuleObserver : public ModuleObserver
247 std::size_t m_unrealised;
249 HomePathsModuleObserver() : m_unrealised(1)
254 if(--m_unrealised == 0)
257 g_homePathObservers.realise();
262 if(++m_unrealised == 1)
264 g_homePathObservers.unrealise();
269 HomePathsModuleObserver g_HomePathsModuleObserver;
271 void HomePaths_Construct()
273 Radiant_attachEnginePathObserver(g_HomePathsModuleObserver);
275 void HomePaths_Destroy()
277 Radiant_detachEnginePathObserver(g_HomePathsModuleObserver);
283 CopiedString g_strEnginePath;
284 ModuleObservers g_enginePathObservers;
285 std::size_t g_enginepath_unrealised = 1;
287 void Radiant_attachEnginePathObserver(ModuleObserver& observer)
289 g_enginePathObservers.attach(observer);
292 void Radiant_detachEnginePathObserver(ModuleObserver& observer)
294 g_enginePathObservers.detach(observer);
298 void EnginePath_Realise()
300 if(--g_enginepath_unrealised == 0)
302 g_enginePathObservers.realise();
307 const char* EnginePath_get()
309 ASSERT_MESSAGE(g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised");
310 return g_strEnginePath.c_str();
313 void EnginePath_Unrealise()
315 if(++g_enginepath_unrealised == 1)
317 g_enginePathObservers.unrealise();
321 void setEnginePath(const char* path)
323 StringOutputStream buffer(256);
324 buffer << DirectoryCleaned(path);
325 if(!path_equal(buffer.c_str(), g_strEnginePath.c_str()))
328 while(!ConfirmModified("Paths Changed"))
330 if(Map_Unnamed(g_map))
342 ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Changing Engine Path");
344 EnginePath_Unrealise();
346 g_strEnginePath = buffer.c_str();
348 EnginePath_Realise();
355 CopiedString g_strAppPath; ///< holds the full path of the executable
357 const char* AppPath_get()
359 return g_strAppPath.c_str();
362 /// the path to the local rc-dir
363 const char* LocalRcPath_get(void)
365 static CopiedString rc_path;
368 StringOutputStream stream(256);
369 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
370 rc_path = stream.c_str();
372 return rc_path.c_str();
375 /// directory for temp files
376 /// NOTE: on *nix this is were we check for .pid
377 CopiedString g_strSettingsPath;
378 const char* SettingsPath_get()
380 return g_strSettingsPath.c_str();
385 points to the game tools directory, for instance
386 C:/Program Files/Quake III Arena/GtkRadiant
388 this is one of the main variables that are configured by the game selection on startup
389 [GameToolsPath]/plugins
390 [GameToolsPath]/modules
393 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
395 const char* GameToolsPath_get()
397 return g_strGameToolsPath.c_str();
400 void EnginePathImport(CopiedString& self, const char* value)
402 setEnginePath(value);
404 typedef ReferenceCaller1<CopiedString, const char*, EnginePathImport> EnginePathImportCaller;
406 void Paths_constructPreferences(PreferencesPage& page)
408 page.appendPathEntry("Engine Path", true,
409 StringImportCallback(EnginePathImportCaller(g_strEnginePath)),
410 StringExportCallback(StringExportCaller(g_strEnginePath))
413 void Paths_constructPage(PreferenceGroup& group)
415 PreferencesPage page(group.createPage("Paths", "Path Settings"));
416 Paths_constructPreferences(page);
418 void Paths_registerPreferencesPage()
420 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Paths_constructPage>());
424 class PathsDialog : public Dialog
427 GtkWindow* BuildDialog()
429 GtkFrame* frame = create_dialog_frame("Path settings", GTK_SHADOW_ETCHED_IN);
431 GtkVBox* vbox2 = create_dialog_vbox(0, 4);
432 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(vbox2));
435 PreferencesPage preferencesPage(*this, GTK_WIDGET(vbox2));
436 Paths_constructPreferences(preferencesPage);
439 return create_simple_modal_dialog_window("Engine Path Not Found", m_modal, GTK_WIDGET(frame));
443 PathsDialog g_PathsDialog;
445 void EnginePath_verify()
447 if(!file_exists(g_strEnginePath.c_str()))
449 g_PathsDialog.Create();
450 g_PathsDialog.DoModal();
451 g_PathsDialog.Destroy();
457 CopiedString g_gamename;
458 CopiedString g_gamemode;
459 ModuleObservers g_gameNameObservers;
460 ModuleObservers g_gameModeObservers;
463 void Radiant_attachGameNameObserver(ModuleObserver& observer)
465 g_gameNameObservers.attach(observer);
468 void Radiant_detachGameNameObserver(ModuleObserver& observer)
470 g_gameNameObservers.detach(observer);
473 const char* basegame_get()
475 return g_pGameDescription->getRequiredKeyValue("basegame");
478 const char* gamename_get()
480 const char* gamename = g_gamename.c_str();
481 if(string_empty(gamename))
483 return basegame_get();
488 void gamename_set(const char* gamename)
490 if(!string_equal(gamename, g_gamename.c_str()))
492 g_gameNameObservers.unrealise();
493 g_gamename = gamename;
494 g_gameNameObservers.realise();
498 void Radiant_attachGameModeObserver(ModuleObserver& observer)
500 g_gameModeObservers.attach(observer);
503 void Radiant_detachGameModeObserver(ModuleObserver& observer)
505 g_gameModeObservers.detach(observer);
508 const char* gamemode_get()
510 return g_gamemode.c_str();
513 void gamemode_set(const char* gamemode)
515 if(!string_equal(gamemode, g_gamemode.c_str()))
517 g_gameModeObservers.unrealise();
518 g_gamemode = gamemode;
519 g_gameModeObservers.realise();
529 CLoadModule(const char* path) : m_path(path)
532 void operator()(const char* name) const
535 ASSERT_MESSAGE(strlen(m_path) + strlen(name) < 1024, "");
536 strcpy(fullname, m_path);
537 strcat(fullname, name);
538 globalOutputStream() << "Found '" << fullname << "'\n";
539 GlobalModuleServer_loadModule(fullname);
543 const char* const c_library_extension =
546 #elif defined (__APPLE__)
548 #elif defined(__linux__) || defined (__FreeBSD__)
553 void Radiant_loadModules(const char* path)
555 Directory_forEach(path, MatchFileExtension<CLoadModule>(c_library_extension, CLoadModule(path)));
558 void Radiant_loadModulesFromRoot(const char* directory)
561 StringOutputStream path(256);
562 path << directory << g_pluginsDir;
563 Radiant_loadModules(path.c_str());
566 if(!string_equal(g_pluginsDir, g_modulesDir))
568 StringOutputStream path(256);
569 path << directory << g_modulesDir;
570 Radiant_loadModules(path.c_str());
574 //! Make COLOR_BRUSHES override worldspawn eclass colour.
575 void SetWorldspawnColour(const Vector3& colour)
577 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert("worldspawn", true);
578 eclass_release_state(worldspawn);
579 worldspawn->color = colour;
580 eclass_capture_state(worldspawn);
584 class WorldspawnColourEntityClassObserver : public ModuleObserver
586 std::size_t m_unrealised;
588 WorldspawnColourEntityClassObserver() : m_unrealised(1)
593 if(--m_unrealised == 0)
595 SetWorldspawnColour(g_xywindow_globals.color_brushes);
600 if(++m_unrealised == 1)
606 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
609 ModuleObservers g_gameToolsPathObservers;
611 void Radiant_attachGameToolsPathObserver(ModuleObserver& observer)
613 g_gameToolsPathObservers.attach(observer);
616 void Radiant_detachGameToolsPathObserver(ModuleObserver& observer)
618 g_gameToolsPathObservers.detach(observer);
621 void Radiant_Initialise()
623 GlobalModuleServer_Initialise();
625 Radiant_loadModulesFromRoot(AppPath_get());
629 bool success = Radiant_Construct(GlobalModuleServer_get());
630 ASSERT_MESSAGE(success, "module system failed to initialise - see radiant.log for error messages");
632 g_gameToolsPathObservers.realise();
633 g_gameModeObservers.realise();
634 g_gameNameObservers.realise();
637 void Radiant_Shutdown()
639 g_gameNameObservers.unrealise();
640 g_gameModeObservers.unrealise();
641 g_gameToolsPathObservers.unrealise();
643 if (!g_preferences_globals.disable_ini)
645 globalOutputStream() << "Start writing prefs\n";
647 globalOutputStream() << "Done prefs\n";
652 GlobalModuleServer_Shutdown();
657 if(ConfirmModified("Exit Radiant"))
666 GlobalUndoSystem().undo();
672 GlobalUndoSystem().redo();
676 void deleteSelection()
678 UndoableCommand undo("deleteSelected");
682 void Map_ExportSelected(TextOutputStream& ostream)
684 Map_ExportSelected(ostream, Map_getFormat(g_map));
687 void Map_ImportSelected(TextInputStream& istream)
689 Map_ImportSelected(istream, Map_getFormat(g_map));
692 void Selection_Copy()
694 clipboard_copy(Map_ExportSelected);
697 void Selection_Paste()
699 clipboard_paste(Map_ImportSelected);
704 if(SelectedFaces_empty())
710 SelectedFaces_copyTexture();
716 if(SelectedFaces_empty())
718 UndoableCommand undo("paste");
720 GlobalSelectionSystem().setSelectedAll(false);
725 SelectedFaces_pasteTexture();
731 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
732 GlobalSelectionSystem().setSelectedAll(false);
734 UndoableCommand undo("pasteToCamera");
738 // Work out the delta
741 Vector3 delta = vector3_subtracted(vector3_snapped(Camera_getOrigin(camwnd), GetSnapGridSize()), mid);
744 GlobalSelectionSystem().translateSelected(delta);
748 void ColorScheme_Original()
750 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
752 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
753 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
754 CamWnd_Update(*g_pParentWnd->GetCamWnd());
756 g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
757 g_xywindow_globals.color_gridminor = Vector3(0.75f, 0.75f, 0.75f);
758 g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
759 g_xywindow_globals.color_gridminor_alt = Vector3(0.5f, 0.0f, 0.0f);
760 g_xywindow_globals.color_gridmajor_alt = Vector3(1.0f, 0.0f, 0.0f);
761 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
762 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
763 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
764 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
765 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
766 SetWorldspawnColour(g_xywindow_globals.color_brushes);
767 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
768 XY_UpdateAllWindows();
771 void ColorScheme_QER()
773 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
775 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
776 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
777 CamWnd_Update(*g_pParentWnd->GetCamWnd());
779 g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
780 g_xywindow_globals.color_gridminor = Vector3(1.0f, 1.0f, 1.0f);
781 g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
782 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
783 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
784 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
785 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
786 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
787 SetWorldspawnColour(g_xywindow_globals.color_brushes);
788 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
789 XY_UpdateAllWindows();
792 void ColorScheme_Black()
794 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
796 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
797 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
798 CamWnd_Update(*g_pParentWnd->GetCamWnd());
800 g_xywindow_globals.color_gridback = Vector3(0.0f, 0.0f, 0.0f);
801 g_xywindow_globals.color_gridminor = Vector3(0.2f, 0.2f, 0.2f);
802 g_xywindow_globals.color_gridmajor = Vector3(0.3f, 0.5f, 0.5f);
803 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
804 g_xywindow_globals.color_gridtext = Vector3(1.0f, 1.0f, 1.0f);
805 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
806 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
807 g_xywindow_globals.color_brushes = Vector3(1.0f, 1.0f, 1.0f);
808 SetWorldspawnColour(g_xywindow_globals.color_brushes);
809 g_xywindow_globals.color_viewname = Vector3(0.7f, 0.7f, 0.0f);
810 XY_UpdateAllWindows();
813 /* ydnar: to emulate maya/max/lightwave color schemes */
814 void ColorScheme_Ydnar()
816 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
818 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
819 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
820 CamWnd_Update(*g_pParentWnd->GetCamWnd());
822 g_xywindow_globals.color_gridback = Vector3(0.77f, 0.77f, 0.77f);
823 g_xywindow_globals.color_gridminor = Vector3(0.83f, 0.83f, 0.83f);
824 g_xywindow_globals.color_gridmajor = Vector3(0.89f, 0.89f, 0.89f);
825 g_xywindow_globals.color_gridblock = Vector3(1.0f, 1.0f, 1.0f);
826 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
827 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
828 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
829 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
830 SetWorldspawnColour(g_xywindow_globals.color_brushes);
831 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
832 XY_UpdateAllWindows();
835 typedef Callback1<Vector3&> GetColourCallback;
836 typedef Callback1<const Vector3&> SetColourCallback;
840 GetColourCallback m_get;
841 SetColourCallback m_set;
843 ChooseColour(const GetColourCallback& get, const SetColourCallback& set)
844 : m_get(get), m_set(set)
851 color_dialog(GTK_WIDGET(MainFrame_getWindow()), colour);
858 void Colour_get(const Vector3& colour, Vector3& other)
862 typedef ConstReferenceCaller1<Vector3, Vector3&, Colour_get> ColourGetCaller;
864 void Colour_set(Vector3& colour, const Vector3& other)
869 typedef ReferenceCaller1<Vector3, const Vector3&, Colour_set> ColourSetCaller;
871 void BrushColour_set(const Vector3& other)
873 g_xywindow_globals.color_brushes = other;
874 SetWorldspawnColour(g_xywindow_globals.color_brushes);
877 typedef FreeCaller1<const Vector3&, BrushColour_set> BrushColourSetCaller;
879 void ClipperColour_set(const Vector3& other)
881 g_xywindow_globals.color_clipper = other;
882 Brush_clipperColourChanged();
885 typedef FreeCaller1<const Vector3&, ClipperColour_set> ClipperColourSetCaller;
887 void TextureBrowserColour_get(Vector3& other)
889 other = TextureBrowser_getBackgroundColour(GlobalTextureBrowser());
891 typedef FreeCaller1<Vector3&, TextureBrowserColour_get> TextureBrowserColourGetCaller;
893 void TextureBrowserColour_set(const Vector3& other)
895 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), other);
897 typedef FreeCaller1<const Vector3&, TextureBrowserColour_set> TextureBrowserColourSetCaller;
903 ChooseColour m_textureback;
904 ChooseColour m_xyback;
905 ChooseColour m_gridmajor;
906 ChooseColour m_gridminor;
907 ChooseColour m_gridmajor_alt;
908 ChooseColour m_gridminor_alt;
909 ChooseColour m_gridtext;
910 ChooseColour m_gridblock;
911 ChooseColour m_cameraback;
912 ChooseColour m_brush;
913 ChooseColour m_selectedbrush;
914 ChooseColour m_selectedbrush3d;
915 ChooseColour m_clipper;
916 ChooseColour m_viewname;
919 m_textureback(TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller()),
920 m_xyback(ColourGetCaller(g_xywindow_globals.color_gridback), ColourSetCaller(g_xywindow_globals.color_gridback)),
921 m_gridmajor(ColourGetCaller(g_xywindow_globals.color_gridmajor), ColourSetCaller(g_xywindow_globals.color_gridmajor)),
922 m_gridminor(ColourGetCaller(g_xywindow_globals.color_gridminor), ColourSetCaller(g_xywindow_globals.color_gridminor)),
923 m_gridmajor_alt(ColourGetCaller(g_xywindow_globals.color_gridmajor_alt), ColourSetCaller(g_xywindow_globals.color_gridmajor_alt)),
924 m_gridminor_alt(ColourGetCaller(g_xywindow_globals.color_gridminor_alt), ColourSetCaller(g_xywindow_globals.color_gridminor_alt)),
925 m_gridtext(ColourGetCaller(g_xywindow_globals.color_gridtext), ColourSetCaller(g_xywindow_globals.color_gridtext)),
926 m_gridblock(ColourGetCaller(g_xywindow_globals.color_gridblock), ColourSetCaller(g_xywindow_globals.color_gridblock)),
927 m_cameraback(ColourGetCaller(g_camwindow_globals.color_cameraback), ColourSetCaller(g_camwindow_globals.color_cameraback)),
928 m_brush(ColourGetCaller(g_xywindow_globals.color_brushes), BrushColourSetCaller()),
929 m_selectedbrush(ColourGetCaller(g_xywindow_globals.color_selbrushes), ColourSetCaller(g_xywindow_globals.color_selbrushes)),
930 m_selectedbrush3d(ColourGetCaller(g_camwindow_globals.color_selbrushes3d), ColourSetCaller(g_camwindow_globals.color_selbrushes3d)),
931 m_clipper(ColourGetCaller(g_xywindow_globals.color_clipper), ClipperColourSetCaller()),
932 m_viewname(ColourGetCaller(g_xywindow_globals.color_viewname), ColourSetCaller(g_xywindow_globals.color_viewname))
937 ColoursMenu g_ColoursMenu;
939 GtkMenuItem* create_colours_menu()
941 GtkMenuItem* colours_menu_item = new_sub_menu_item_with_mnemonic("Colors");
942 GtkMenu* menu_in_menu = GTK_MENU(gtk_menu_item_get_submenu(colours_menu_item));
943 if (g_Layout_enableDetachableMenus.m_value)
944 menu_tearoff (menu_in_menu);
946 GtkMenu* menu_3 = create_sub_menu_with_mnemonic(menu_in_menu, "Themes");
947 if (g_Layout_enableDetachableMenus.m_value)
948 menu_tearoff (menu_3);
950 create_menu_item_with_mnemonic(menu_3, "QE4 Original", "ColorSchemeOriginal");
951 create_menu_item_with_mnemonic(menu_3, "Q3Radiant Original", "ColorSchemeQER");
952 create_menu_item_with_mnemonic(menu_3, "Black and Green", "ColorSchemeBlackAndGreen");
953 create_menu_item_with_mnemonic(menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar");
955 menu_separator(menu_in_menu);
957 create_menu_item_with_mnemonic(menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor");
958 create_menu_item_with_mnemonic(menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor");
959 create_menu_item_with_mnemonic(menu_in_menu, "Grid Major...", "ChooseGridMajorColor");
960 create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor...", "ChooseGridMinorColor");
961 create_menu_item_with_mnemonic(menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor");
962 create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor");
963 create_menu_item_with_mnemonic(menu_in_menu, "Grid Text...", "ChooseGridTextColor");
964 create_menu_item_with_mnemonic(menu_in_menu, "Grid Block...", "ChooseGridBlockColor");
965 create_menu_item_with_mnemonic(menu_in_menu, "Default Brush...", "ChooseBrushColor");
966 create_menu_item_with_mnemonic(menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor");
967 create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor");
968 create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor");
969 create_menu_item_with_mnemonic(menu_in_menu, "Clipper...", "ChooseClipperColor");
970 create_menu_item_with_mnemonic(menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor");
972 return colours_menu_item;
979 PluginToolbar_clear();
982 Radiant_Initialise();
984 PluginsMenu_populate();
986 PluginToolbar_populate();
992 g_pParentWnd->OnSleep();
998 StringOutputStream URL(256);
999 URL << "http://www.icculus.org/netradiant/?cmd=update&data=dlupdate&query_dlup=1";
1001 URL << "&OS_dlup=1";
1002 #elif defined(__APPLE__)
1003 URL << "&OS_dlup=2";
1005 URL << "&OS_dlup=3";
1007 URL << "&Version_dlup=" RADIANT_VERSION;
1008 g_GamesDialog.AddPacksURL(URL);
1009 OpenURL(URL.c_str());
1012 // open the Q3Rad manual
1015 // at least on win32, AppPath + "docs/index.html"
1016 StringOutputStream help(256);
1017 help << AppPath_get() << "docs/index.html";
1018 OpenURL(help.c_str());
1021 void OpenBugReportURL()
1023 OpenURL("http://www.icculus.org/netradiant/?cmd=bugs");
1027 GtkWidget* g_page_console;
1029 void Console_ToggleShow()
1031 GroupDialog_showPage(g_page_console);
1034 GtkWidget* g_page_entity;
1036 void EntityInspector_ToggleShow()
1038 GroupDialog_showPage(g_page_entity);
1043 void SetClipMode(bool enable);
1044 void ModeChangeNotify();
1046 typedef void(*ToolMode)();
1047 ToolMode g_currentToolMode = 0;
1048 bool g_currentToolModeSupportsComponentEditing = false;
1049 ToolMode g_defaultToolMode = 0;
1053 void SelectionSystem_DefaultMode()
1055 GlobalSelectionSystem().SetMode(SelectionSystem::ePrimitive);
1056 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eDefault);
1063 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1064 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1069 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1070 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1075 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1076 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1079 template<bool (*BoolFunction)()>
1080 class BoolFunctionExport
1083 static void apply(const BoolImportCallback& importCallback)
1085 importCallback(BoolFunction());
1089 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1090 EdgeModeApplyCaller g_edgeMode_button_caller;
1091 BoolExportCallback g_edgeMode_button_callback(g_edgeMode_button_caller);
1092 ToggleItem g_edgeMode_button(g_edgeMode_button_callback);
1094 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1095 VertexModeApplyCaller g_vertexMode_button_caller;
1096 BoolExportCallback g_vertexMode_button_callback(g_vertexMode_button_caller);
1097 ToggleItem g_vertexMode_button(g_vertexMode_button_callback);
1099 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1100 FaceModeApplyCaller g_faceMode_button_caller;
1101 BoolExportCallback g_faceMode_button_callback(g_faceMode_button_caller);
1102 ToggleItem g_faceMode_button(g_faceMode_button_callback);
1104 void ComponentModeChanged()
1106 g_edgeMode_button.update();
1107 g_vertexMode_button.update();
1108 g_faceMode_button.update();
1111 void ComponentMode_SelectionChanged(const Selectable& selectable)
1113 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1114 && GlobalSelectionSystem().countSelected() == 0)
1116 SelectionSystem_DefaultMode();
1117 ComponentModeChanged();
1121 void SelectEdgeMode()
1124 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1126 GlobalSelectionSystem().Select(false);
1132 SelectionSystem_DefaultMode();
1134 else if(GlobalSelectionSystem().countSelected() != 0)
1136 if(!g_currentToolModeSupportsComponentEditing)
1138 g_defaultToolMode();
1141 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1142 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eEdge);
1145 ComponentModeChanged();
1150 void SelectVertexMode()
1153 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1155 GlobalSelectionSystem().Select(false);
1161 SelectionSystem_DefaultMode();
1163 else if(GlobalSelectionSystem().countSelected() != 0)
1165 if(!g_currentToolModeSupportsComponentEditing)
1167 g_defaultToolMode();
1170 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1171 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eVertex);
1174 ComponentModeChanged();
1179 void SelectFaceMode()
1182 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1184 GlobalSelectionSystem().Select(false);
1190 SelectionSystem_DefaultMode();
1192 else if(GlobalSelectionSystem().countSelected() != 0)
1194 if(!g_currentToolModeSupportsComponentEditing)
1196 g_defaultToolMode();
1199 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1200 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eFace);
1203 ComponentModeChanged();
1209 class CloneSelected : public scene::Graph::Walker
1212 NodeSmartReference worldspawn;
1214 CloneSelected(bool d): doMakeUnique(d), worldspawn(Map_FindOrInsertWorldspawn(g_map))
1217 bool pre(const scene::Path& path, scene::Instance& instance) const
1219 if(path.size() == 1)
1222 // ignore worldspawn, but keep checking children
1223 NodeSmartReference me(path.top().get());
1224 if(me == worldspawn)
1227 if(!path.top().get().isRoot())
1229 Selectable* selectable = Instance_getSelectable(instance);
1231 && selectable->isSelected())
1239 void post(const scene::Path& path, scene::Instance& instance) const
1241 if(path.size() == 1)
1244 // ignore worldspawn, but keep checking children
1245 NodeSmartReference me(path.top().get());
1246 if(me == worldspawn)
1249 if(!path.top().get().isRoot())
1251 Selectable* selectable = Instance_getSelectable(instance);
1253 && selectable->isSelected())
1255 NodeSmartReference clone(Node_Clone(path.top()));
1257 Map_gatherNamespaced(clone);
1258 Node_getTraversable(path.parent().get())->insert(clone);
1264 void Scene_Clone_Selected(scene::Graph& graph, bool doMakeUnique)
1266 graph.traverse(CloneSelected(doMakeUnique));
1268 Map_mergeClonedNames();
1271 enum ENudgeDirection
1284 AxisBase(const Vector3& x_, const Vector3& y_, const Vector3& z_)
1285 : x(x_), y(y_), z(z_)
1290 AxisBase AxisBase_forViewType(VIEWTYPE viewtype)
1295 return AxisBase(g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z);
1297 return AxisBase(g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y);
1299 return AxisBase(g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x);
1302 ERROR_MESSAGE("invalid viewtype");
1303 return AxisBase(Vector3(0, 0, 0), Vector3(0, 0, 0), Vector3(0, 0, 0));
1306 Vector3 AxisBase_axisForDirection(const AxisBase& axes, ENudgeDirection direction)
1311 return vector3_negated(axes.x);
1317 return vector3_negated(axes.y);
1320 ERROR_MESSAGE("invalid direction");
1321 return Vector3(0, 0, 0);
1324 void NudgeSelection(ENudgeDirection direction, float fAmount, VIEWTYPE viewtype)
1326 AxisBase axes(AxisBase_forViewType(viewtype));
1327 Vector3 view_direction(vector3_negated(axes.z));
1328 Vector3 nudge(vector3_scaled(AxisBase_axisForDirection(axes, direction), fAmount));
1329 GlobalSelectionSystem().NudgeManipulator(nudge, view_direction);
1332 void Selection_Clone()
1334 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
1336 UndoableCommand undo("cloneSelected");
1338 Scene_Clone_Selected(GlobalSceneGraph(), false);
1340 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1341 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1345 void Selection_Clone_MakeUnique()
1347 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
1349 UndoableCommand undo("cloneSelectedMakeUnique");
1351 Scene_Clone_Selected(GlobalSceneGraph(), true);
1353 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1354 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1358 // called when the escape key is used (either on the main window or on an inspector)
1359 void Selection_Deselect()
1361 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1363 if(GlobalSelectionSystem().countSelectedComponents() != 0)
1365 GlobalSelectionSystem().setSelectedAllComponents(false);
1369 SelectionSystem_DefaultMode();
1370 ComponentModeChanged();
1375 if(GlobalSelectionSystem().countSelectedComponents() != 0)
1377 GlobalSelectionSystem().setSelectedAllComponents(false);
1381 GlobalSelectionSystem().setSelectedAll(false);
1387 void Selection_NudgeUp()
1389 UndoableCommand undo("nudgeSelectedUp");
1390 NudgeSelection(eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1393 void Selection_NudgeDown()
1395 UndoableCommand undo("nudgeSelectedDown");
1396 NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1399 void Selection_NudgeLeft()
1401 UndoableCommand undo("nudgeSelectedLeft");
1402 NudgeSelection(eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1405 void Selection_NudgeRight()
1407 UndoableCommand undo("nudgeSelectedRight");
1408 NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1412 void TranslateToolExport(const BoolImportCallback& importCallback)
1414 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate);
1417 void RotateToolExport(const BoolImportCallback& importCallback)
1419 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate);
1422 void ScaleToolExport(const BoolImportCallback& importCallback)
1424 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale);
1427 void DragToolExport(const BoolImportCallback& importCallback)
1429 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag);
1432 void ClipperToolExport(const BoolImportCallback& importCallback)
1434 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip);
1437 FreeCaller1<const BoolImportCallback&, TranslateToolExport> g_translatemode_button_caller;
1438 BoolExportCallback g_translatemode_button_callback(g_translatemode_button_caller);
1439 ToggleItem g_translatemode_button(g_translatemode_button_callback);
1441 FreeCaller1<const BoolImportCallback&, RotateToolExport> g_rotatemode_button_caller;
1442 BoolExportCallback g_rotatemode_button_callback(g_rotatemode_button_caller);
1443 ToggleItem g_rotatemode_button(g_rotatemode_button_callback);
1445 FreeCaller1<const BoolImportCallback&, ScaleToolExport> g_scalemode_button_caller;
1446 BoolExportCallback g_scalemode_button_callback(g_scalemode_button_caller);
1447 ToggleItem g_scalemode_button(g_scalemode_button_callback);
1449 FreeCaller1<const BoolImportCallback&, DragToolExport> g_dragmode_button_caller;
1450 BoolExportCallback g_dragmode_button_callback(g_dragmode_button_caller);
1451 ToggleItem g_dragmode_button(g_dragmode_button_callback);
1453 FreeCaller1<const BoolImportCallback&, ClipperToolExport> g_clipper_button_caller;
1454 BoolExportCallback g_clipper_button_callback(g_clipper_button_caller);
1455 ToggleItem g_clipper_button(g_clipper_button_callback);
1459 g_translatemode_button.update();
1460 g_rotatemode_button.update();
1461 g_scalemode_button.update();
1462 g_dragmode_button.update();
1463 g_clipper_button.update();
1466 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1470 if(g_currentToolMode == DragMode && g_defaultToolMode != DragMode)
1472 g_defaultToolMode();
1476 g_currentToolMode = DragMode;
1477 g_currentToolModeSupportsComponentEditing = true;
1481 Sys_Status(c_ResizeMode_status);
1482 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eDrag);
1489 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1491 void TranslateMode()
1493 if(g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode)
1495 g_defaultToolMode();
1499 g_currentToolMode = TranslateMode;
1500 g_currentToolModeSupportsComponentEditing = true;
1504 Sys_Status(c_TranslateMode_status);
1505 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eTranslate);
1511 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1515 if(g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode)
1517 g_defaultToolMode();
1521 g_currentToolMode = RotateMode;
1522 g_currentToolModeSupportsComponentEditing = true;
1526 Sys_Status(c_RotateMode_status);
1527 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eRotate);
1533 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1537 if(g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode)
1539 g_defaultToolMode();
1543 g_currentToolMode = ScaleMode;
1544 g_currentToolModeSupportsComponentEditing = true;
1548 Sys_Status(c_ScaleMode_status);
1549 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eScale);
1556 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1561 if(g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode)
1563 g_defaultToolMode();
1567 g_currentToolMode = ClipperMode;
1568 g_currentToolModeSupportsComponentEditing = false;
1570 SelectionSystem_DefaultMode();
1574 Sys_Status(c_ClipperMode_status);
1575 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eClip);
1582 void Texdef_Rotate(float angle)
1584 StringOutputStream command;
1585 command << "brushRotateTexture -angle " << angle;
1586 UndoableCommand undo(command.c_str());
1587 Select_RotateTexture(angle);
1590 void Texdef_RotateClockwise()
1592 Texdef_Rotate(static_cast<float>(fabs(g_si_globals.rotate)));
1595 void Texdef_RotateAntiClockwise()
1597 Texdef_Rotate(static_cast<float>(-fabs(g_si_globals.rotate)));
1600 void Texdef_Scale(float x, float y)
1602 StringOutputStream command;
1603 command << "brushScaleTexture -x " << x << " -y " << y;
1604 UndoableCommand undo(command.c_str());
1605 Select_ScaleTexture(x, y);
1608 void Texdef_ScaleUp()
1610 Texdef_Scale(0, g_si_globals.scale[1]);
1613 void Texdef_ScaleDown()
1615 Texdef_Scale(0, -g_si_globals.scale[1]);
1618 void Texdef_ScaleLeft()
1620 Texdef_Scale(-g_si_globals.scale[0],0);
1623 void Texdef_ScaleRight()
1625 Texdef_Scale(g_si_globals.scale[0],0);
1628 void Texdef_Shift(float x, float y)
1630 StringOutputStream command;
1631 command << "brushShiftTexture -x " << x << " -y " << y;
1632 UndoableCommand undo(command.c_str());
1633 Select_ShiftTexture(x, y);
1636 void Texdef_ShiftLeft()
1638 Texdef_Shift(-g_si_globals.shift[0], 0);
1641 void Texdef_ShiftRight()
1643 Texdef_Shift(g_si_globals.shift[0], 0);
1646 void Texdef_ShiftUp()
1648 Texdef_Shift(0, g_si_globals.shift[1]);
1651 void Texdef_ShiftDown()
1653 Texdef_Shift(0, -g_si_globals.shift[1]);
1658 class SnappableSnapToGridSelected : public scene::Graph::Walker
1662 SnappableSnapToGridSelected(float snap)
1666 bool pre(const scene::Path& path, scene::Instance& instance) const
1668 if(path.top().get().visible())
1670 Snappable* snappable = Node_getSnappable(path.top());
1672 && Instance_getSelectable(instance)->isSelected())
1674 snappable->snapto(m_snap);
1681 void Scene_SnapToGrid_Selected(scene::Graph& graph, float snap)
1683 graph.traverse(SnappableSnapToGridSelected(snap));
1686 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1690 ComponentSnappableSnapToGridSelected(float snap)
1694 bool pre(const scene::Path& path, scene::Instance& instance) const
1696 if(path.top().get().visible())
1698 ComponentSnappable* componentSnappable = Instance_getComponentSnappable(instance);
1699 if(componentSnappable != 0
1700 && Instance_getSelectable(instance)->isSelected())
1702 componentSnappable->snapComponents(m_snap);
1709 void Scene_SnapToGrid_Component_Selected(scene::Graph& graph, float snap)
1711 graph.traverse(ComponentSnappableSnapToGridSelected(snap));
1714 void Selection_SnapToGrid()
1716 StringOutputStream command;
1717 command << "snapSelected -grid " << GetGridSize();
1718 UndoableCommand undo(command.c_str());
1720 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1722 Scene_SnapToGrid_Component_Selected(GlobalSceneGraph(), GetGridSize());
1726 Scene_SnapToGrid_Selected(GlobalSceneGraph(), GetGridSize());
1731 static gint qe_every_second(gpointer data)
1733 GdkModifierType mask;
1735 gdk_window_get_pointer (0, 0, 0, &mask);
1737 if ((mask & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK)) == 0)
1745 guint s_qe_every_second_id = 0;
1747 void EverySecondTimer_enable()
1749 if(s_qe_every_second_id == 0)
1751 s_qe_every_second_id = gtk_timeout_add(1000, qe_every_second, 0);
1755 void EverySecondTimer_disable()
1757 if(s_qe_every_second_id != 0)
1759 gtk_timeout_remove(s_qe_every_second_id);
1760 s_qe_every_second_id = 0;
1764 gint window_realize_remove_decoration(GtkWidget* widget, gpointer data)
1766 gdk_window_set_decorations(widget->window, (GdkWMDecoration)(GDK_DECOR_ALL|GDK_DECOR_MENU|GDK_DECOR_MINIMIZE|GDK_DECOR_MAXIMIZE));
1773 GtkWindow* m_window;
1777 WaitDialog create_wait_dialog(const char* title, const char* text)
1781 dialog.m_window = create_floating_window(title, MainFrame_getWindow());
1782 gtk_window_set_resizable(dialog.m_window, FALSE);
1783 gtk_container_set_border_width(GTK_CONTAINER(dialog.m_window), 0);
1784 gtk_window_set_position(dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT);
1786 g_signal_connect(G_OBJECT(dialog.m_window), "realize", G_CALLBACK(window_realize_remove_decoration), 0);
1789 dialog.m_label = GTK_LABEL(gtk_label_new(text));
1790 gtk_misc_set_alignment(GTK_MISC(dialog.m_label), 0.0, 0.5);
1791 gtk_label_set_justify(dialog.m_label, GTK_JUSTIFY_LEFT);
1792 gtk_widget_show(GTK_WIDGET(dialog.m_label));
1793 gtk_widget_set_size_request(GTK_WIDGET(dialog.m_label), 200, -1);
1795 gtk_container_add(GTK_CONTAINER(dialog.m_window), GTK_WIDGET(dialog.m_label));
1802 clock_t g_lastRedrawTime = 0;
1803 const clock_t c_redrawInterval = clock_t(CLOCKS_PER_SEC / 10);
1805 bool redrawRequired()
1807 clock_t currentTime = std::clock();
1808 if(currentTime - g_lastRedrawTime >= c_redrawInterval)
1810 g_lastRedrawTime = currentTime;
1817 bool MainFrame_isActiveApp()
1819 //globalOutputStream() << "listing\n";
1820 GList* list = gtk_window_list_toplevels();
1821 for(GList* i = list; i != 0; i = g_list_next(i))
1823 //globalOutputStream() << "toplevel.. ";
1824 if(gtk_window_is_active(GTK_WINDOW(i->data)))
1826 //globalOutputStream() << "is active\n";
1829 //globalOutputStream() << "not active\n";
1834 typedef std::list<CopiedString> StringStack;
1835 StringStack g_wait_stack;
1838 bool ScreenUpdates_Enabled()
1840 return g_wait_stack.empty();
1843 void ScreenUpdates_process()
1845 if(redrawRequired() && GTK_WIDGET_VISIBLE(g_wait.m_window))
1852 void ScreenUpdates_Disable(const char* message, const char* title)
1854 if(g_wait_stack.empty())
1856 EverySecondTimer_disable();
1860 bool isActiveApp = MainFrame_isActiveApp();
1862 g_wait = create_wait_dialog(title, message);
1863 gtk_grab_add(GTK_WIDGET(g_wait.m_window));
1867 gtk_widget_show(GTK_WIDGET(g_wait.m_window));
1868 ScreenUpdates_process();
1871 else if(GTK_WIDGET_VISIBLE(g_wait.m_window))
1873 gtk_label_set_text(g_wait.m_label, message);
1874 ScreenUpdates_process();
1876 g_wait_stack.push_back(message);
1879 void ScreenUpdates_Enable()
1881 ASSERT_MESSAGE(!ScreenUpdates_Enabled(), "screen updates already enabled");
1882 g_wait_stack.pop_back();
1883 if(g_wait_stack.empty())
1885 EverySecondTimer_enable();
1886 //gtk_widget_set_sensitive(GTK_WIDGET(MainFrame_getWindow()), TRUE);
1888 gtk_grab_remove(GTK_WIDGET(g_wait.m_window));
1889 destroy_floating_window(g_wait.m_window);
1890 g_wait.m_window = 0;
1892 //gtk_window_present(MainFrame_getWindow());
1894 else if(GTK_WIDGET_VISIBLE(g_wait.m_window))
1896 gtk_label_set_text(g_wait.m_label, g_wait_stack.back().c_str());
1897 ScreenUpdates_process();
1903 void GlobalCamera_UpdateWindow()
1905 if(g_pParentWnd != 0)
1907 CamWnd_Update(*g_pParentWnd->GetCamWnd());
1911 void XY_UpdateWindow(MainFrame& mainframe)
1913 if(mainframe.GetXYWnd() != 0)
1915 XYWnd_Update(*mainframe.GetXYWnd());
1919 void XZ_UpdateWindow(MainFrame& mainframe)
1921 if(mainframe.GetXZWnd() != 0)
1923 XYWnd_Update(*mainframe.GetXZWnd());
1927 void YZ_UpdateWindow(MainFrame& mainframe)
1929 if(mainframe.GetYZWnd() != 0)
1931 XYWnd_Update(*mainframe.GetYZWnd());
1935 void XY_UpdateAllWindows(MainFrame& mainframe)
1937 XY_UpdateWindow(mainframe);
1938 XZ_UpdateWindow(mainframe);
1939 YZ_UpdateWindow(mainframe);
1942 void XY_UpdateAllWindows()
1944 if(g_pParentWnd != 0)
1946 XY_UpdateAllWindows(*g_pParentWnd);
1950 void UpdateAllWindows()
1952 GlobalCamera_UpdateWindow();
1953 XY_UpdateAllWindows();
1957 void ModeChangeNotify()
1959 SceneChangeNotify();
1962 void ClipperChangeNotify()
1964 GlobalCamera_UpdateWindow();
1965 XY_UpdateAllWindows();
1969 LatchedInt g_Layout_viewStyle(0, "Window Layout");
1970 LatchedBool g_Layout_enableDetachableMenus(true, "Detachable Menus");
1971 LatchedBool g_Layout_enablePatchToolbar(true, "Patch Toolbar");
1972 LatchedBool g_Layout_enablePluginToolbar(true, "Plugin Toolbar");
1976 GtkMenuItem* create_file_menu()
1979 GtkMenuItem* file_menu_item = new_sub_menu_item_with_mnemonic("_File");
1980 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(file_menu_item));
1981 if (g_Layout_enableDetachableMenus.m_value)
1982 menu_tearoff (menu);
1984 create_menu_item_with_mnemonic(menu, "_New Map", "NewMap");
1985 menu_separator(menu);
1988 //++timo temporary experimental stuff for sleep mode..
1989 create_menu_item_with_mnemonic(menu, "_Sleep", "Sleep");
1990 menu_separator(menu);
1994 create_menu_item_with_mnemonic(menu, "_Open...", "OpenMap");
1996 create_menu_item_with_mnemonic(menu, "_Import...", "ImportMap");
1997 create_menu_item_with_mnemonic(menu, "_Save", "SaveMap");
1998 create_menu_item_with_mnemonic(menu, "Save _as...", "SaveMapAs");
1999 create_menu_item_with_mnemonic(menu, "Save s_elected...", "SaveSelected");
2000 menu_separator(menu);
2001 create_menu_item_with_mnemonic(menu, "Save re_gion...", "SaveRegion");
2002 menu_separator(menu);
2003 create_menu_item_with_mnemonic(menu, "_Refresh models", "RefreshReferences");
2004 menu_separator(menu);
2005 create_menu_item_with_mnemonic(menu, "Pro_ject settings...", "ProjectSettings");
2006 menu_separator(menu);
2007 create_menu_item_with_mnemonic(menu, "_Pointfile...", "TogglePointfile");
2008 menu_separator(menu);
2009 MRU_constructMenu(menu);
2010 menu_separator(menu);
2011 create_menu_item_with_mnemonic(menu, "Check for NetRadiant update (web)", "CheckForUpdate"); // FIXME
2012 create_menu_item_with_mnemonic(menu, "E_xit", "Exit");
2014 return file_menu_item;
2017 GtkMenuItem* create_edit_menu()
2020 GtkMenuItem* edit_menu_item = new_sub_menu_item_with_mnemonic("_Edit");
2021 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(edit_menu_item));
2022 if (g_Layout_enableDetachableMenus.m_value)
2023 menu_tearoff (menu);
2024 create_menu_item_with_mnemonic(menu, "_Undo", "Undo");
2025 create_menu_item_with_mnemonic(menu, "_Redo", "Redo");
2026 menu_separator(menu);
2027 create_menu_item_with_mnemonic(menu, "_Copy", "Copy");
2028 create_menu_item_with_mnemonic(menu, "_Paste", "Paste");
2029 create_menu_item_with_mnemonic(menu, "P_aste To Camera", "PasteToCamera");
2030 menu_separator(menu);
2031 create_menu_item_with_mnemonic(menu, "_Duplicate", "CloneSelection");
2032 create_menu_item_with_mnemonic(menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique");
2033 create_menu_item_with_mnemonic(menu, "D_elete", "DeleteSelection");
2034 menu_separator(menu);
2035 create_menu_item_with_mnemonic(menu, "Pa_rent", "ParentSelection");
2036 menu_separator(menu);
2037 create_menu_item_with_mnemonic(menu, "C_lear Selection", "UnSelectSelection");
2038 create_menu_item_with_mnemonic(menu, "_Invert Selection", "InvertSelection");
2039 create_menu_item_with_mnemonic(menu, "Select i_nside", "SelectInside");
2040 create_menu_item_with_mnemonic(menu, "Select _touching", "SelectTouching");
2042 GtkMenu* convert_menu = create_sub_menu_with_mnemonic(menu, "E_xpand Selection");
2043 if (g_Layout_enableDetachableMenus.m_value)
2044 menu_tearoff (convert_menu);
2045 create_menu_item_with_mnemonic(convert_menu, "To Whole _Entities", "ExpandSelectionToEntities");
2047 menu_separator(menu);
2048 create_menu_item_with_mnemonic(menu, "Pre_ferences...", "Preferences");
2050 return edit_menu_item;
2053 void fill_view_xy_top_menu(GtkMenu* menu)
2055 create_check_menu_item_with_mnemonic(menu, "XY (Top) View", "ToggleView");
2059 void fill_view_yz_side_menu(GtkMenu* menu)
2061 create_check_menu_item_with_mnemonic(menu, "YZ (Side) View", "ToggleSideView");
2065 void fill_view_xz_front_menu(GtkMenu* menu)
2067 create_check_menu_item_with_mnemonic(menu, "XZ (Front) View", "ToggleFrontView");
2071 GtkWidget* g_toggle_z_item = 0;
2072 GtkWidget* g_toggle_console_item = 0;
2073 GtkWidget* g_toggle_entity_item = 0;
2074 GtkWidget* g_toggle_entitylist_item = 0;
2076 GtkMenuItem* create_view_menu(MainFrame::EViewStyle style)
2079 GtkMenuItem* view_menu_item = new_sub_menu_item_with_mnemonic("Vie_w");
2080 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(view_menu_item));
2081 if (g_Layout_enableDetachableMenus.m_value)
2082 menu_tearoff (menu);
2084 if(style == MainFrame::eFloating)
2086 fill_view_camera_menu(menu);
2087 fill_view_xy_top_menu(menu);
2088 fill_view_yz_side_menu(menu);
2089 fill_view_xz_front_menu(menu);
2091 if(style == MainFrame::eFloating || style == MainFrame::eSplit)
2093 create_menu_item_with_mnemonic(menu, "Console View", "ToggleConsole");
2094 create_menu_item_with_mnemonic(menu, "Texture Browser", "ToggleTextures");
2095 create_menu_item_with_mnemonic(menu, "Entity Inspector", "ToggleEntityInspector");
2099 create_menu_item_with_mnemonic(menu, "Entity Inspector", "ViewEntityInfo");
2101 create_menu_item_with_mnemonic(menu, "_Surface Inspector", "SurfaceInspector");
2102 create_menu_item_with_mnemonic(menu, "Entity List", "EntityList");
2104 menu_separator(menu);
2106 GtkMenu* camera_menu = create_sub_menu_with_mnemonic (menu, "Camera");
2107 if (g_Layout_enableDetachableMenus.m_value)
2108 menu_tearoff (camera_menu);
2109 create_menu_item_with_mnemonic(camera_menu, "_Center", "CenterView");
2110 create_menu_item_with_mnemonic(camera_menu, "_Up Floor", "UpFloor");
2111 create_menu_item_with_mnemonic(camera_menu, "_Down Floor", "DownFloor");
2112 menu_separator(camera_menu);
2113 create_menu_item_with_mnemonic(camera_menu, "Far Clip Plane In", "CubicClipZoomIn");
2114 create_menu_item_with_mnemonic(camera_menu, "Far Clip Plane Out", "CubicClipZoomOut");
2115 menu_separator(camera_menu);
2116 create_menu_item_with_mnemonic(camera_menu, "Next leak spot", "NextLeakSpot");
2117 create_menu_item_with_mnemonic(camera_menu, "Previous leak spot", "PrevLeakSpot");
2118 menu_separator(camera_menu);
2119 create_menu_item_with_mnemonic(camera_menu, "Look Through Selected", "LookThroughSelected");
2120 create_menu_item_with_mnemonic(camera_menu, "Look Through Camera", "LookThroughCamera");
2122 menu_separator(menu);
2124 GtkMenu* orthographic_menu = create_sub_menu_with_mnemonic(menu, "Orthographic");
2125 if (g_Layout_enableDetachableMenus.m_value)
2126 menu_tearoff (orthographic_menu);
2127 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating)
2129 create_menu_item_with_mnemonic(orthographic_menu, "_Next (XY, YZ, XY)", "NextView");
2130 create_menu_item_with_mnemonic(orthographic_menu, "XY (Top)", "ViewTop");
2131 create_menu_item_with_mnemonic(orthographic_menu, "YZ", "ViewSide");
2132 create_menu_item_with_mnemonic(orthographic_menu, "XZ", "ViewFront");
2133 menu_separator(orthographic_menu);
2136 create_menu_item_with_mnemonic(orthographic_menu, "_XY 100%", "Zoom100");
2137 create_menu_item_with_mnemonic(orthographic_menu, "XY Zoom _In", "ZoomIn");
2138 create_menu_item_with_mnemonic(orthographic_menu, "XY Zoom _Out", "ZoomOut");
2141 menu_separator(menu);
2144 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Show");
2145 if (g_Layout_enableDetachableMenus.m_value)
2146 menu_tearoff (menu_in_menu);
2147 create_check_menu_item_with_mnemonic(menu_in_menu, "Show _Angles", "ShowAngles");
2148 create_check_menu_item_with_mnemonic(menu_in_menu, "Show _Names", "ShowNames");
2149 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Blocks", "ShowBlocks");
2150 create_check_menu_item_with_mnemonic(menu_in_menu, "Show C_oordinates", "ShowCoordinates");
2151 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Window Outline", "ShowWindowOutline");
2152 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Axes", "ShowAxes");
2153 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Workzone", "ShowWorkzone");
2154 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Stats", "ShowStats");
2158 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Filter");
2159 if (g_Layout_enableDetachableMenus.m_value)
2160 menu_tearoff (menu_in_menu);
2161 Filters_constructMenu(menu_in_menu);
2163 menu_separator(menu);
2165 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Hide/Show");
2166 if (g_Layout_enableDetachableMenus.m_value)
2167 menu_tearoff (menu_in_menu);
2168 create_menu_item_with_mnemonic(menu_in_menu, "Hide Selected", "HideSelected");
2169 create_menu_item_with_mnemonic(menu_in_menu, "Show Hidden", "ShowHidden");
2171 menu_separator(menu);
2173 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Region");
2174 if (g_Layout_enableDetachableMenus.m_value)
2175 menu_tearoff (menu_in_menu);
2176 create_menu_item_with_mnemonic(menu_in_menu, "_Off", "RegionOff");
2177 create_menu_item_with_mnemonic(menu_in_menu, "_Set XY", "RegionSetXY");
2178 create_menu_item_with_mnemonic(menu_in_menu, "Set _Brush", "RegionSetBrush");
2179 create_menu_item_with_mnemonic(menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection");
2182 command_connect_accelerator("CenterXYView");
2184 return view_menu_item;
2187 GtkMenuItem* create_selection_menu()
2190 GtkMenuItem* selection_menu_item = new_sub_menu_item_with_mnemonic("M_odify");
2191 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(selection_menu_item));
2192 if (g_Layout_enableDetachableMenus.m_value)
2193 menu_tearoff (menu);
2196 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Components");
2197 if (g_Layout_enableDetachableMenus.m_value)
2198 menu_tearoff (menu_in_menu);
2199 create_check_menu_item_with_mnemonic(menu_in_menu, "_Edges", "DragEdges");
2200 create_check_menu_item_with_mnemonic(menu_in_menu, "_Vertices", "DragVertices");
2201 create_check_menu_item_with_mnemonic(menu_in_menu, "_Faces", "DragFaces");
2204 menu_separator(menu);
2207 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic(menu, "Nudge");
2208 if (g_Layout_enableDetachableMenus.m_value)
2209 menu_tearoff (menu_in_menu);
2210 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Left", "SelectNudgeLeft");
2211 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Right", "SelectNudgeRight");
2212 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Up", "SelectNudgeUp");
2213 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Down", "SelectNudgeDown");
2216 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Rotate");
2217 if (g_Layout_enableDetachableMenus.m_value)
2218 menu_tearoff (menu_in_menu);
2219 create_menu_item_with_mnemonic(menu_in_menu, "Rotate X", "RotateSelectionX");
2220 create_menu_item_with_mnemonic(menu_in_menu, "Rotate Y", "RotateSelectionY");
2221 create_menu_item_with_mnemonic(menu_in_menu, "Rotate Z", "RotateSelectionZ");
2224 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Flip");
2225 if (g_Layout_enableDetachableMenus.m_value)
2226 menu_tearoff (menu_in_menu);
2227 create_menu_item_with_mnemonic(menu_in_menu, "Flip _X", "MirrorSelectionX");
2228 create_menu_item_with_mnemonic(menu_in_menu, "Flip _Y", "MirrorSelectionY");
2229 create_menu_item_with_mnemonic(menu_in_menu, "Flip _Z", "MirrorSelectionZ");
2231 menu_separator(menu);
2232 create_menu_item_with_mnemonic(menu, "Arbitrary rotation...", "ArbitraryRotation");
2233 create_menu_item_with_mnemonic(menu, "Arbitrary scale...", "ArbitraryScale");
2235 return selection_menu_item;
2238 GtkMenuItem* create_bsp_menu()
2241 GtkMenuItem* bsp_menu_item = new_sub_menu_item_with_mnemonic("_Build");
2242 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(bsp_menu_item));
2244 if (g_Layout_enableDetachableMenus.m_value)
2249 create_menu_item_with_mnemonic(menu, "Customize...", "BuildMenuCustomize");
2251 menu_separator(menu);
2253 Build_constructMenu(menu);
2257 return bsp_menu_item;
2260 GtkMenuItem* create_grid_menu()
2263 GtkMenuItem* grid_menu_item = new_sub_menu_item_with_mnemonic("_Grid");
2264 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(grid_menu_item));
2265 if (g_Layout_enableDetachableMenus.m_value)
2266 menu_tearoff (menu);
2268 Grid_constructMenu(menu);
2270 return grid_menu_item;
2273 GtkMenuItem* create_misc_menu()
2276 GtkMenuItem* misc_menu_item = new_sub_menu_item_with_mnemonic("M_isc");
2277 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(misc_menu_item));
2278 if (g_Layout_enableDetachableMenus.m_value)
2279 menu_tearoff (menu);
2282 create_menu_item_with_mnemonic(menu, "_Benchmark", FreeCaller<GlobalCamera_Benchmark>());
2284 gtk_container_add(GTK_CONTAINER(menu), GTK_WIDGET(create_colours_menu()));
2286 create_menu_item_with_mnemonic(menu, "Find brush...", "FindBrush");
2287 create_menu_item_with_mnemonic(menu, "Map Info...", "MapInfo");
2288 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2289 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<WXY_Print>());
2290 create_menu_item_with_mnemonic(menu, "_Background select", FreeCaller<WXY_BackgroundSelect>());
2291 return misc_menu_item;
2294 GtkMenuItem* create_entity_menu()
2297 GtkMenuItem* entity_menu_item = new_sub_menu_item_with_mnemonic("E_ntity");
2298 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(entity_menu_item));
2299 if (g_Layout_enableDetachableMenus.m_value)
2300 menu_tearoff (menu);
2302 Entity_constructMenu(menu);
2304 return entity_menu_item;
2307 GtkMenuItem* create_brush_menu()
2310 GtkMenuItem* brush_menu_item = new_sub_menu_item_with_mnemonic("B_rush");
2311 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(brush_menu_item));
2312 if (g_Layout_enableDetachableMenus.m_value)
2313 menu_tearoff (menu);
2315 Brush_constructMenu(menu);
2317 return brush_menu_item;
2320 GtkMenuItem* create_patch_menu()
2323 GtkMenuItem* patch_menu_item = new_sub_menu_item_with_mnemonic("_Curve");
2324 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(patch_menu_item));
2325 if (g_Layout_enableDetachableMenus.m_value)
2330 Patch_constructMenu(menu);
2332 return patch_menu_item;
2335 GtkMenuItem* create_help_menu()
2338 GtkMenuItem* help_menu_item = new_sub_menu_item_with_mnemonic("_Help");
2339 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(help_menu_item));
2340 if (g_Layout_enableDetachableMenus.m_value)
2341 menu_tearoff (menu);
2343 create_menu_item_with_mnemonic(menu, "Manual", "OpenManual");
2345 // this creates all the per-game drop downs for the game pack helps
2346 // it will take care of hooking the Sys_OpenURL calls etc.
2347 create_game_help_menu(menu);
2349 create_menu_item_with_mnemonic(menu, "Bug report", FreeCaller<OpenBugReportURL>());
2350 create_menu_item_with_mnemonic(menu, "Shortcuts list", FreeCaller<DoCommandListDlg>());
2351 create_menu_item_with_mnemonic(menu, "_About", FreeCaller<DoAbout>());
2353 return help_menu_item;
2356 GtkMenuBar* create_main_menu(MainFrame::EViewStyle style)
2358 GtkMenuBar* menu_bar = GTK_MENU_BAR(gtk_menu_bar_new());
2359 gtk_widget_show(GTK_WIDGET(menu_bar));
2361 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_file_menu()));
2362 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_edit_menu()));
2363 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_view_menu(style)));
2364 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_selection_menu()));
2365 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_bsp_menu()));
2366 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_grid_menu()));
2367 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_misc_menu()));
2368 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_entity_menu()));
2369 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_brush_menu()));
2370 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_patch_menu()));
2371 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_plugins_menu()));
2372 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_help_menu()));
2378 void PatchInspector_registerShortcuts()
2380 command_connect_accelerator("PatchInspector");
2383 void Patch_registerShortcuts()
2385 command_connect_accelerator("InvertCurveTextureX");
2386 command_connect_accelerator("InvertCurveTextureY");
2387 command_connect_accelerator("IncPatchColumn");
2388 command_connect_accelerator("IncPatchRow");
2389 command_connect_accelerator("DecPatchColumn");
2390 command_connect_accelerator("DecPatchRow");
2391 command_connect_accelerator("NaturalizePatch");
2392 //command_connect_accelerator("CapCurrentCurve");
2395 void Manipulators_registerShortcuts()
2397 toggle_add_accelerator("MouseRotate");
2398 toggle_add_accelerator("MouseTranslate");
2399 toggle_add_accelerator("MouseScale");
2400 toggle_add_accelerator("MouseDrag");
2401 toggle_add_accelerator("ToggleClipper");
2404 void TexdefNudge_registerShortcuts()
2406 command_connect_accelerator("TexRotateClock");
2407 command_connect_accelerator("TexRotateCounter");
2408 command_connect_accelerator("TexScaleUp");
2409 command_connect_accelerator("TexScaleDown");
2410 command_connect_accelerator("TexScaleLeft");
2411 command_connect_accelerator("TexScaleRight");
2412 command_connect_accelerator("TexShiftUp");
2413 command_connect_accelerator("TexShiftDown");
2414 command_connect_accelerator("TexShiftLeft");
2415 command_connect_accelerator("TexShiftRight");
2418 void SelectNudge_registerShortcuts()
2420 command_connect_accelerator("MoveSelectionDOWN");
2421 command_connect_accelerator("MoveSelectionUP");
2422 //command_connect_accelerator("SelectNudgeLeft");
2423 //command_connect_accelerator("SelectNudgeRight");
2424 //command_connect_accelerator("SelectNudgeUp");
2425 //command_connect_accelerator("SelectNudgeDown");
2428 void SnapToGrid_registerShortcuts()
2430 command_connect_accelerator("SnapToGrid");
2433 void SelectByType_registerShortcuts()
2435 command_connect_accelerator("SelectAllOfType");
2438 void SurfaceInspector_registerShortcuts()
2440 command_connect_accelerator("FitTexture");
2444 void register_shortcuts()
2446 PatchInspector_registerShortcuts();
2447 Patch_registerShortcuts();
2448 Grid_registerShortcuts();
2449 XYWnd_registerShortcuts();
2450 CamWnd_registerShortcuts();
2451 Manipulators_registerShortcuts();
2452 SurfaceInspector_registerShortcuts();
2453 TexdefNudge_registerShortcuts();
2454 SelectNudge_registerShortcuts();
2455 SnapToGrid_registerShortcuts();
2456 SelectByType_registerShortcuts();
2459 void File_constructToolbar(GtkToolbar* toolbar)
2461 toolbar_append_button(toolbar, "Open an existing map (CTRL + O)", "file_open.bmp", "OpenMap");
2462 toolbar_append_button(toolbar, "Save the active map (CTRL + S)", "file_save.bmp", "SaveMap");
2465 void UndoRedo_constructToolbar(GtkToolbar* toolbar)
2467 toolbar_append_button(toolbar, "Undo (CTRL + Z)", "undo.bmp", "Undo");
2468 toolbar_append_button(toolbar, "Redo (CTRL + Y)", "redo.bmp", "Redo");
2471 void RotateFlip_constructToolbar(GtkToolbar* toolbar)
2473 toolbar_append_button(toolbar, "x-axis Flip", "brush_flipx.bmp", "MirrorSelectionX");
2474 toolbar_append_button(toolbar, "x-axis Rotate", "brush_rotatex.bmp", "RotateSelectionX");
2475 toolbar_append_button(toolbar, "y-axis Flip", "brush_flipy.bmp", "MirrorSelectionY");
2476 toolbar_append_button(toolbar, "y-axis Rotate", "brush_rotatey.bmp", "RotateSelectionY");
2477 toolbar_append_button(toolbar, "z-axis Flip", "brush_flipz.bmp", "MirrorSelectionZ");
2478 toolbar_append_button(toolbar, "z-axis Rotate", "brush_rotatez.bmp", "RotateSelectionZ");
2481 void Select_constructToolbar(GtkToolbar* toolbar)
2483 toolbar_append_button(toolbar, "Select touching", "selection_selecttouching.bmp", "SelectTouching");
2484 toolbar_append_button(toolbar, "Select inside", "selection_selectinside.bmp", "SelectInside");
2487 void CSG_constructToolbar(GtkToolbar* toolbar)
2489 toolbar_append_button(toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.bmp", "CSGSubtract");
2490 toolbar_append_button(toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.bmp", "CSGMerge");
2491 toolbar_append_button(toolbar, "Hollow", "selection_makehollow.bmp", "CSGHollow");
2494 void ComponentModes_constructToolbar(GtkToolbar* toolbar)
2496 toolbar_append_toggle_button(toolbar, "Select Vertices (V)", "modify_vertices.bmp", "DragVertices");
2497 toolbar_append_toggle_button(toolbar, "Select Edges (E)", "modify_edges.bmp", "DragEdges");
2498 toolbar_append_toggle_button(toolbar, "Select Faces (F)", "modify_faces.bmp", "DragFaces");
2501 void Clipper_constructToolbar(GtkToolbar* toolbar)
2504 toolbar_append_toggle_button(toolbar, "Clipper (X)", "view_clipper.bmp", "ToggleClipper");
2507 void XYWnd_constructToolbar(GtkToolbar* toolbar)
2509 toolbar_append_button(toolbar, "Change views", "view_change.bmp", "NextView");
2512 void Manipulators_constructToolbar(GtkToolbar* toolbar)
2514 toolbar_append_toggle_button(toolbar, "Translate (W)", "select_mousetranslate.bmp", "MouseTranslate");
2515 toolbar_append_toggle_button(toolbar, "Rotate (R)", "select_mouserotate.bmp", "MouseRotate");
2516 toolbar_append_toggle_button(toolbar, "Scale", "select_mousescale.bmp", "MouseScale");
2517 toolbar_append_toggle_button(toolbar, "Resize (Q)", "select_mouseresize.bmp", "MouseDrag");
2519 Clipper_constructToolbar(toolbar);
2522 GtkToolbar* create_main_toolbar(MainFrame::EViewStyle style)
2524 GtkToolbar* toolbar = GTK_TOOLBAR(gtk_toolbar_new());
2525 gtk_toolbar_set_orientation(toolbar, GTK_ORIENTATION_HORIZONTAL);
2526 gtk_toolbar_set_style(toolbar, GTK_TOOLBAR_ICONS);
2528 gtk_widget_show(GTK_WIDGET(toolbar));
2530 File_constructToolbar(toolbar);
2532 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2534 UndoRedo_constructToolbar(toolbar);
2536 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2538 RotateFlip_constructToolbar(toolbar);
2540 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2542 Select_constructToolbar(toolbar);
2544 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2546 CSG_constructToolbar(toolbar);
2548 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2550 ComponentModes_constructToolbar(toolbar);
2552 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating)
2554 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2556 XYWnd_constructToolbar(toolbar);
2559 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2561 CamWnd_constructToolbar(toolbar);
2563 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2565 Manipulators_constructToolbar(toolbar);
2567 if (g_Layout_enablePatchToolbar.m_value)
2569 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2571 Patch_constructToolbar(toolbar);
2574 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2576 toolbar_append_toggle_button(toolbar, "Texture Lock (SHIFT +T)", "texture_lock.bmp", "TogTexLock");
2578 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2580 GtkButton* g_view_entities_button = toolbar_append_button(toolbar, "Entities (N)", "entities.bmp", "ToggleEntityInspector");
2581 GtkButton* g_view_console_button = toolbar_append_button(toolbar, "Console (O)", "console.bmp", "ToggleConsole");
2582 GtkButton* g_view_textures_button = toolbar_append_button(toolbar, "Texture Browser (T)", "texture_browser.bmp", "ToggleTextures");
2583 // TODO: call light inspector
2584 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.bmp", "ToggleLightInspector");
2586 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2587 GtkButton* g_refresh_models_button = toolbar_append_button(toolbar, "Refresh Models", "refresh_models.bmp", "RefreshReferences");
2590 // disable the console and texture button in the regular layouts
2591 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft)
2593 gtk_widget_set_sensitive(GTK_WIDGET(g_view_console_button), FALSE);
2594 gtk_widget_set_sensitive(GTK_WIDGET(g_view_textures_button), FALSE);
2600 GtkWidget* create_main_statusbar(GtkWidget *pStatusLabel[c_count_status])
2602 GtkTable* table = GTK_TABLE(gtk_table_new(1, c_count_status, FALSE));
2603 gtk_widget_show(GTK_WIDGET(table));
2606 GtkLabel* label = GTK_LABEL(gtk_label_new ("Label"));
2607 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
2608 gtk_misc_set_padding(GTK_MISC(label), 4, 2);
2609 gtk_widget_show(GTK_WIDGET(label));
2610 gtk_table_attach_defaults(table, GTK_WIDGET(label), 0, 1, 0, 1);
2611 pStatusLabel[c_command_status] = GTK_WIDGET(label);
2614 for(int i = 1; i < c_count_status; ++i)
2616 GtkFrame* frame = GTK_FRAME(gtk_frame_new(0));
2617 gtk_widget_show(GTK_WIDGET(frame));
2618 gtk_table_attach_defaults(table, GTK_WIDGET(frame), i, i + 1, 0, 1);
2619 gtk_frame_set_shadow_type(frame, GTK_SHADOW_IN);
2621 GtkLabel* label = GTK_LABEL(gtk_label_new ("Label"));
2622 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END);
2623 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
2624 gtk_misc_set_padding(GTK_MISC(label), 4, 2);
2625 gtk_widget_show(GTK_WIDGET(label));
2626 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(label));
2627 pStatusLabel[i] = GTK_WIDGET(label);
2630 return GTK_WIDGET(table);
2636 WidgetFocusPrinter g_mainframeWidgetFocusPrinter("mainframe");
2638 class WindowFocusPrinter
2642 static gboolean frame_event(GtkWidget *widget, GdkEvent* event, WindowFocusPrinter* self)
2644 globalOutputStream() << self->m_name << " frame_event\n";
2647 static gboolean keys_changed(GtkWidget *widget, WindowFocusPrinter* self)
2649 globalOutputStream() << self->m_name << " keys_changed\n";
2652 static gboolean notify(GtkWindow* window, gpointer dummy, WindowFocusPrinter* self)
2654 if(gtk_window_is_active(window))
2656 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2660 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2665 WindowFocusPrinter(const char* name) : m_name(name)
2668 void connect(GtkWindow* toplevel_window)
2670 g_signal_connect(G_OBJECT(toplevel_window), "notify::has_toplevel_focus", G_CALLBACK(notify), this);
2671 g_signal_connect(G_OBJECT(toplevel_window), "notify::is_active", G_CALLBACK(notify), this);
2672 g_signal_connect(G_OBJECT(toplevel_window), "keys_changed", G_CALLBACK(keys_changed), this);
2673 g_signal_connect(G_OBJECT(toplevel_window), "frame_event", G_CALLBACK(frame_event), this);
2677 WindowFocusPrinter g_mainframeFocusPrinter("mainframe");
2681 class MainWindowActive
2683 static gboolean notify(GtkWindow* window, gpointer dummy, MainWindowActive* self)
2685 if(g_wait.m_window != 0 && gtk_window_is_active(window) && !GTK_WIDGET_VISIBLE(g_wait.m_window))
2687 gtk_widget_show(GTK_WIDGET(g_wait.m_window));
2693 void connect(GtkWindow* toplevel_window)
2695 g_signal_connect(G_OBJECT(toplevel_window), "notify::is-active", G_CALLBACK(notify), this);
2699 MainWindowActive g_MainWindowActive;
2701 SignalHandlerId XYWindowDestroyed_connect(const SignalHandler& handler)
2703 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst(handler);
2706 void XYWindowDestroyed_disconnect(SignalHandlerId id)
2708 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect(id);
2711 MouseEventHandlerId XYWindowMouseDown_connect(const MouseEventHandler& handler)
2713 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst(handler);
2716 void XYWindowMouseDown_disconnect(MouseEventHandlerId id)
2718 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect(id);
2721 // =============================================================================
2724 MainFrame* g_pParentWnd = 0;
2726 GtkWindow* MainFrame_getWindow()
2728 if(g_pParentWnd == 0)
2732 return g_pParentWnd->m_window;
2735 std::vector<GtkWidget*> g_floating_windows;
2737 MainFrame::MainFrame() : m_window(0), m_idleRedrawStatusText(RedrawStatusTextCaller(*this))
2746 for (int n = 0;n < c_count_status;n++)
2748 m_pStatusLabel[n] = 0;
2751 m_bSleeping = false;
2756 MainFrame::~MainFrame()
2760 gtk_widget_hide(GTK_WIDGET(m_window));
2764 for(std::vector<GtkWidget*>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i)
2766 gtk_widget_destroy(*i);
2769 gtk_widget_destroy(GTK_WIDGET(m_window));
2772 void MainFrame::SetActiveXY(XYWnd* p)
2775 m_pActiveXY->SetActive(false);
2780 m_pActiveXY->SetActive(true);
2784 void MainFrame::ReleaseContexts()
2788 m_pXYWnd->DestroyContext();
2790 m_pYZWnd->DestroyContext();
2792 m_pXZWnd->DestroyContext();
2794 m_pCamWnd->DestroyContext();
2796 m_pTexWnd->DestroyContext();
2798 m_pZWnd->DestroyContext();
2802 void MainFrame::CreateContexts()
2806 m_pCamWnd->CreateContext();
2808 m_pXYWnd->CreateContext();
2810 m_pYZWnd->CreateContext();
2812 m_pXZWnd->CreateContext();
2814 m_pTexWnd->CreateContext();
2816 m_pZWnd->CreateContext();
2824 void MainFrame::OnSleep()
2830 // useful when trying to debug crashes in the sleep code
2831 globalOutputStream() << "Going into sleep mode..\n";
2833 globalOutputStream() << "Dispatching sleep msg...";
2834 DispatchRadiantMsg (RADIANT_SLEEP);
2835 globalOutputStream() << "Done.\n";
2837 gtk_window_iconify(m_window);
2838 GlobalSelectionSystem().setSelectedAll(false);
2840 GlobalShaderCache().unrealise();
2842 GlobalOpenGL_debugAssertNoErrors();
2843 ScreenUpdates_Disable();
2846 globalOutputStream() << "Releasing contexts...";
2848 globalOutputStream() << "Done.\n";
2852 globalOutputStream() << "Waking up\n";
2854 gtk_window_deiconify(m_window);
2857 globalOutputStream() << "Creating contexts...";
2859 globalOutputStream() << "Done.\n";
2861 globalOutputStream() << "Making current on camera...";
2862 m_pCamWnd->MakeCurrent();
2863 globalOutputStream() << "Done.\n";
2865 globalOutputStream() << "Reloading shaders...";
2867 GlobalShaderCache().realise();
2868 globalOutputStream() << "Done.\n";
2870 ScreenUpdates_Enable();
2872 globalOutputStream() << "Dispatching wake msg...";
2873 DispatchRadiantMsg (RADIANT_WAKEUP);
2874 globalOutputStream() << "Done\n";
2880 GtkWindow* create_splash()
2882 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
2883 gtk_window_set_decorated(window, FALSE);
2884 gtk_window_set_resizable(window, FALSE);
2885 gtk_window_set_modal(window, TRUE);
2886 gtk_window_set_default_size(window, -1, -1);
2887 gtk_window_set_position(window, GTK_WIN_POS_CENTER);
2888 gtk_container_set_border_width(GTK_CONTAINER(window), 0);
2890 GtkImage* image = new_local_image("splash.bmp");
2891 gtk_widget_show(GTK_WIDGET(image));
2892 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(image));
2894 gtk_widget_set_size_request(GTK_WIDGET(window), -1, -1);
2895 gtk_widget_show(GTK_WIDGET(window));
2900 static GtkWindow *splash_screen = 0;
2904 splash_screen = create_splash();
2911 gtk_widget_destroy(GTK_WIDGET(splash_screen));
2914 WindowPositionTracker g_posCamWnd;
2915 WindowPositionTracker g_posXYWnd;
2916 WindowPositionTracker g_posXZWnd;
2917 WindowPositionTracker g_posYZWnd;
2919 static gint mainframe_delete (GtkWidget *widget, GdkEvent *event, gpointer data)
2921 if(ConfirmModified("Exit Radiant"))
2929 void MainFrame::Create()
2931 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
2933 GlobalWindowObservers_connectTopLevel(window);
2935 gtk_window_set_transient_for(splash_screen, window);
2939 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask("bitmaps/icon.bmp");
2942 gtk_window_set_icon(window, pixbuf);
2943 gdk_pixbuf_unref(pixbuf);
2948 gtk_widget_add_events(GTK_WIDGET(window), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK);
2949 g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(mainframe_delete), this);
2951 m_position_tracker.connect(window);
2954 g_mainframeWidgetFocusPrinter.connect(window);
2955 g_mainframeFocusPrinter.connect(window);
2958 g_MainWindowActive.connect(window);
2960 GetPlugInMgr().Init(GTK_WIDGET(window));
2962 GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
2963 gtk_container_add(GTK_CONTAINER(window), vbox);
2964 gtk_widget_show(vbox);
2966 global_accel_connect_window(window);
2968 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
2970 register_shortcuts();
2972 GtkMenuBar* main_menu = create_main_menu(CurrentStyle());
2973 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(main_menu), FALSE, FALSE, 0);
2975 GtkToolbar* main_toolbar = create_main_toolbar(CurrentStyle());
2976 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(main_toolbar), FALSE, FALSE, 0);
2978 GtkToolbar* plugin_toolbar = create_plugin_toolbar();
2979 if (!g_Layout_enablePluginToolbar.m_value)
2981 gtk_widget_hide(GTK_WIDGET(plugin_toolbar));
2983 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(plugin_toolbar), FALSE, FALSE, 0);
2985 GtkWidget* main_statusbar = create_main_statusbar(m_pStatusLabel);
2986 gtk_box_pack_end(GTK_BOX(vbox), main_statusbar, FALSE, TRUE, 2);
2988 GroupDialog_constructWindow(window);
2989 g_page_entity = GroupDialog_addPage("Entities", EntityInspector_constructWindow(GroupDialog_getWindow()), RawStringExportCaller("Entities"));
2991 if(FloatingGroupDialog())
2993 g_page_console = GroupDialog_addPage("Console", Console_constructWindow(GroupDialog_getWindow()), RawStringExportCaller("Console"));
2997 if( g_multimon_globals.m_bStartOnPrimMon )
2999 PositionWindowOnPrimaryScreen(g_layout_globals.m_position);
3000 window_set_position(window, g_layout_globals.m_position);
3004 if(g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED)
3006 gtk_window_maximize(window);
3007 WindowPosition default_position(-1, -1, 640, 480);
3008 window_set_position(window, default_position);
3012 window_set_position(window, g_layout_globals.m_position);
3017 gtk_widget_show(GTK_WIDGET(window));
3019 if (CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft)
3022 GtkWidget* vsplit = gtk_vpaned_new();
3024 gtk_box_pack_start(GTK_BOX(vbox), vsplit, TRUE, TRUE, 0);
3025 gtk_widget_show (vsplit);
3028 GtkWidget* console_window = Console_constructWindow(window);
3029 gtk_paned_pack2(GTK_PANED(vsplit), console_window, FALSE, TRUE);
3032 GtkWidget* hsplit = gtk_hpaned_new();
3033 gtk_widget_show (hsplit);
3035 gtk_paned_add1(GTK_PANED(vsplit), hsplit);
3038 m_pXYWnd = new XYWnd();
3039 m_pXYWnd->SetViewType(XY);
3040 GtkWidget* xy_window = GTK_WIDGET(create_framed_widget(m_pXYWnd->GetWidget()));
3043 GtkWidget* vsplit2 = gtk_vpaned_new();
3044 gtk_widget_show(vsplit2);
3045 m_vSplit2 = vsplit2;
3047 if (CurrentStyle() == eRegular)
3049 gtk_paned_add1(GTK_PANED(hsplit), xy_window);
3050 gtk_paned_add2(GTK_PANED(hsplit), vsplit2);
3054 gtk_paned_add1(GTK_PANED(hsplit), vsplit2);
3055 gtk_paned_add2(GTK_PANED(hsplit), xy_window);
3060 m_pCamWnd = NewCamWnd();
3061 GlobalCamera_setCamWnd(*m_pCamWnd);
3062 CamWnd_setParent(*m_pCamWnd, window);
3063 GtkFrame* camera_window = create_framed_widget(CamWnd_getWidget(*m_pCamWnd));
3065 gtk_paned_add1(GTK_PANED(vsplit2), GTK_WIDGET(camera_window));
3068 GtkFrame* texture_window = create_framed_widget(TextureBrowser_constructWindow(window));
3070 gtk_paned_add2(GTK_PANED(vsplit2), GTK_WIDGET(texture_window));
3075 gtk_paned_set_position(GTK_PANED(m_vSplit), g_layout_globals.nXYHeight);
3077 if (CurrentStyle() == eRegular)
3079 gtk_paned_set_position(GTK_PANED(m_hSplit), g_layout_globals.nXYWidth);
3083 gtk_paned_set_position(GTK_PANED(m_hSplit), g_layout_globals.nCamWidth);
3086 gtk_paned_set_position(GTK_PANED(m_vSplit2), g_layout_globals.nCamHeight);
3088 else if (CurrentStyle() == eFloating)
3091 GtkWindow* window = create_persistent_floating_window("Camera", m_window);
3092 global_accel_connect_window(window);
3093 g_posCamWnd.connect(window);
3095 gtk_widget_show(GTK_WIDGET(window));
3097 m_pCamWnd = NewCamWnd();
3098 GlobalCamera_setCamWnd(*m_pCamWnd);
3101 GtkFrame* frame = create_framed_widget(CamWnd_getWidget(*m_pCamWnd));
3102 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3104 CamWnd_setParent(*m_pCamWnd, window);
3106 g_floating_windows.push_back(GTK_WIDGET(window));
3110 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(XY), m_window);
3111 global_accel_connect_window(window);
3112 g_posXYWnd.connect(window);
3114 m_pXYWnd = new XYWnd();
3115 m_pXYWnd->m_parent = window;
3116 m_pXYWnd->SetViewType(XY);
3120 GtkFrame* frame = create_framed_widget(m_pXYWnd->GetWidget());
3121 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3123 XY_Top_Shown_Construct(window);
3125 g_floating_windows.push_back(GTK_WIDGET(window));
3129 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(XZ), m_window);
3130 global_accel_connect_window(window);
3131 g_posXZWnd.connect(window);
3133 m_pXZWnd = new XYWnd();
3134 m_pXZWnd->m_parent = window;
3135 m_pXZWnd->SetViewType(XZ);
3138 GtkFrame* frame = create_framed_widget(m_pXZWnd->GetWidget());
3139 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3142 XZ_Front_Shown_Construct(window);
3144 g_floating_windows.push_back(GTK_WIDGET(window));
3148 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(YZ), m_window);
3149 global_accel_connect_window(window);
3150 g_posYZWnd.connect(window);
3152 m_pYZWnd = new XYWnd();
3153 m_pYZWnd->m_parent = window;
3154 m_pYZWnd->SetViewType(YZ);
3157 GtkFrame* frame = create_framed_widget(m_pYZWnd->GetWidget());
3158 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3161 YZ_Side_Shown_Construct(window);
3163 g_floating_windows.push_back(GTK_WIDGET(window));
3167 GtkFrame* frame = create_framed_widget(TextureBrowser_constructWindow(GroupDialog_getWindow()));
3168 g_page_textures = GroupDialog_addPage("Textures", GTK_WIDGET(frame), TextureBrowserExportTitleCaller());
3175 m_pCamWnd = NewCamWnd();
3176 GlobalCamera_setCamWnd(*m_pCamWnd);
3177 CamWnd_setParent(*m_pCamWnd, window);
3179 GtkWidget* camera = CamWnd_getWidget(*m_pCamWnd);
3181 m_pYZWnd = new XYWnd();
3182 m_pYZWnd->SetViewType(YZ);
3184 GtkWidget* yz = m_pYZWnd->GetWidget();
3186 m_pXYWnd = new XYWnd();
3187 m_pXYWnd->SetViewType(XY);
3189 GtkWidget* xy = m_pXYWnd->GetWidget();
3191 m_pXZWnd = new XYWnd();
3192 m_pXZWnd->SetViewType(XZ);
3194 GtkWidget* xz = m_pXZWnd->GetWidget();
3196 GtkHPaned* split = create_split_views(camera, yz, xy, xz);
3197 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(split), TRUE, TRUE, 0);
3200 GtkFrame* frame = create_framed_widget(TextureBrowser_constructWindow(window));
3201 g_page_textures = GroupDialog_addPage("Textures", GTK_WIDGET(frame), TextureBrowserExportTitleCaller());
3205 EntityList_constructWindow(window);
3206 PreferencesDialog_constructWindow(window);
3207 FindTextureDialog_constructWindow(window);
3208 SurfaceInspector_constructWindow(window);
3209 PatchInspector_constructWindow(window);
3211 SetActiveXY(m_pXYWnd);
3213 AddGridChangeCallback(SetGridStatusCaller(*this));
3214 AddGridChangeCallback(ReferenceCaller<MainFrame, XY_UpdateAllWindows>(*this));
3216 g_defaultToolMode = DragMode;
3217 g_defaultToolMode();
3218 SetStatusText(m_command_status, c_TranslateMode_status);
3220 EverySecondTimer_enable();
3222 //GlobalShortcuts_reportUnregistered();
3225 void MainFrame::SaveWindowInfo()
3227 if (!FloatingGroupDialog())
3229 g_layout_globals.nXYHeight = gtk_paned_get_position(GTK_PANED(m_vSplit));
3231 if(CurrentStyle() != eRegular)
3233 g_layout_globals.nCamWidth = gtk_paned_get_position(GTK_PANED(m_hSplit));
3237 g_layout_globals.nXYWidth = gtk_paned_get_position(GTK_PANED(m_hSplit));
3240 g_layout_globals.nCamHeight = gtk_paned_get_position(GTK_PANED(m_vSplit2));
3243 g_layout_globals.m_position = m_position_tracker.getPosition();
3245 g_layout_globals.nState = gdk_window_get_state(GTK_WIDGET(m_window)->window);
3248 void MainFrame::Shutdown()
3250 EverySecondTimer_disable();
3252 EntityList_destroyWindow();
3261 TextureBrowser_destroyWindow();
3263 DeleteCamWnd(m_pCamWnd);
3266 PreferencesDialog_destroyWindow();
3267 SurfaceInspector_destroyWindow();
3268 FindTextureDialog_destroyWindow();
3269 PatchInspector_destroyWindow();
3271 g_DbgDlg.destroyWindow();
3273 // destroying group-dialog last because it may contain texture-browser
3274 GroupDialog_destroyWindow();
3277 void MainFrame::RedrawStatusText()
3279 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_command_status]), m_command_status.c_str());
3280 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_position_status]), m_position_status.c_str());
3281 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_brushcount_status]), m_brushcount_status.c_str());
3282 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_texture_status]), m_texture_status.c_str());
3283 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_grid_status]), m_grid_status.c_str());
3286 void MainFrame::UpdateStatusText()
3288 m_idleRedrawStatusText.queueDraw();
3291 void MainFrame::SetStatusText(CopiedString& status_text, const char* pText)
3293 status_text = pText;
3297 void Sys_Status(const char* status)
3299 if(g_pParentWnd != 0)
3301 g_pParentWnd->SetStatusText (g_pParentWnd->m_command_status, status);
3305 int getRotateIncrement()
3307 return static_cast<int>(g_si_globals.rotate);
3310 int getFarClipDistance()
3312 return g_camwindow_globals.m_nCubicScale;
3315 float (*GridStatus_getGridSize)() = GetGridSize;
3316 int (*GridStatus_getRotateIncrement)() = getRotateIncrement;
3317 int (*GridStatus_getFarClipDistance)() = getFarClipDistance;
3318 bool (*GridStatus_getTextureLockEnabled)();
3320 void MainFrame::SetGridStatus()
3322 StringOutputStream status(64);
3323 const char* lock = (GridStatus_getTextureLockEnabled()) ? "ON" : "OFF";
3324 status << (GetSnapGridSize() > 0 ? "G:" : "g:") << GridStatus_getGridSize()
3325 << " R:" << GridStatus_getRotateIncrement()
3326 << " C:" << GridStatus_getFarClipDistance()
3328 SetStatusText(m_grid_status, status.c_str());
3331 void GridStatus_onTextureLockEnabledChanged()
3333 if(g_pParentWnd != 0)
3335 g_pParentWnd->SetGridStatus();
3339 void GlobalGL_sharedContextCreated()
3341 GLFont *g_font = NULL;
3343 // report OpenGL information
3344 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>(glGetString (GL_VENDOR)) << "\n";
3345 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>(glGetString (GL_RENDERER)) << "\n";
3346 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>(glGetString (GL_VERSION)) << "\n";
3347 globalOutputStream() << "GL_EXTENSIONS: " << reinterpret_cast<const char*>(glGetString (GL_EXTENSIONS)) << "\n";
3349 QGL_sharedContextCreated(GlobalOpenGL());
3351 ShaderCache_extensionsInitialised();
3353 GlobalShaderCache().realise();
3357 /* win32 is dodgy here, just use courier new then */
3358 g_font = glfont_create("arial 9");
3360 GtkSettings *settings = gtk_settings_get_default();
3362 g_object_get(settings, "gtk-font-name", &fontname, NULL);
3363 g_font = glfont_create(fontname);
3366 GlobalOpenGL().m_font = g_font;
3369 void GlobalGL_sharedContextDestroyed()
3371 Textures_Unrealise();
3372 GlobalShaderCache().unrealise();
3374 QGL_sharedContextDestroyed(GlobalOpenGL());
3378 void Layout_constructPreferences(PreferencesPage& page)
3381 const char* layouts[] = { "window1.bmp", "window2.bmp", "window3.bmp", "window4.bmp" };
3382 page.appendRadioIcons(
3384 STRING_ARRAY_RANGE(layouts),
3385 LatchedIntImportCaller(g_Layout_viewStyle),
3386 IntExportCaller(g_Layout_viewStyle.m_latched)
3389 page.appendCheckBox(
3390 "", "Detachable Menus",
3391 LatchedBoolImportCaller(g_Layout_enableDetachableMenus),
3392 BoolExportCaller(g_Layout_enableDetachableMenus.m_latched)
3394 if (!string_empty(g_pGameDescription->getKeyValue("no_patch")))
3396 page.appendCheckBox(
3397 "", "Patch Toolbar",
3398 LatchedBoolImportCaller(g_Layout_enablePatchToolbar),
3399 BoolExportCaller(g_Layout_enablePatchToolbar.m_latched)
3402 page.appendCheckBox(
3403 "", "Plugin Toolbar",
3404 LatchedBoolImportCaller(g_Layout_enablePluginToolbar),
3405 BoolExportCaller(g_Layout_enablePluginToolbar.m_latched)
3409 void Layout_constructPage(PreferenceGroup& group)
3411 PreferencesPage page(group.createPage("Layout", "Layout Preferences"));
3412 Layout_constructPreferences(page);
3415 void Layout_registerPreferencesPage()
3417 PreferencesDialog_addInterfacePage(FreeCaller1<PreferenceGroup&, Layout_constructPage>());
3421 #include "preferencesystem.h"
3422 #include "stringio.h"
3424 void MainFrame_Construct()
3426 GlobalCommands_insert("OpenManual", FreeCaller<OpenHelpURL>(), Accelerator(GDK_F1));
3428 GlobalCommands_insert("Sleep", FreeCaller<thunk_OnSleep>(), Accelerator('P', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
3429 GlobalCommands_insert("NewMap", FreeCaller<NewMap>());
3430 GlobalCommands_insert("OpenMap", FreeCaller<OpenMap>(), Accelerator('O', (GdkModifierType)GDK_CONTROL_MASK));
3431 GlobalCommands_insert("ImportMap", FreeCaller<ImportMap>());
3432 GlobalCommands_insert("SaveMap", FreeCaller<SaveMap>(), Accelerator('S', (GdkModifierType)GDK_CONTROL_MASK));
3433 GlobalCommands_insert("SaveMapAs", FreeCaller<SaveMapAs>());
3434 GlobalCommands_insert("SaveSelected", FreeCaller<ExportMap>());
3435 GlobalCommands_insert("SaveRegion", FreeCaller<SaveRegion>());
3436 GlobalCommands_insert("RefreshReferences", FreeCaller<RefreshReferences>());
3437 GlobalCommands_insert("ProjectSettings", FreeCaller<DoProjectSettings>());
3438 GlobalCommands_insert("CheckForUpdate", FreeCaller<OpenUpdateURL>());
3439 GlobalCommands_insert("Exit", FreeCaller<Exit>());
3441 GlobalCommands_insert("Undo", FreeCaller<Undo>(), Accelerator('Z', (GdkModifierType)GDK_CONTROL_MASK));
3442 GlobalCommands_insert("Redo", FreeCaller<Redo>(), Accelerator('Y', (GdkModifierType)GDK_CONTROL_MASK));
3443 GlobalCommands_insert("Copy", FreeCaller<Copy>(), Accelerator('C', (GdkModifierType)GDK_CONTROL_MASK));
3444 GlobalCommands_insert("Paste", FreeCaller<Paste>(), Accelerator('V', (GdkModifierType)GDK_CONTROL_MASK));
3445 GlobalCommands_insert("PasteToCamera", FreeCaller<PasteToCamera>(), Accelerator('V', (GdkModifierType)GDK_MOD1_MASK));
3446 GlobalCommands_insert("CloneSelection", FreeCaller<Selection_Clone>(), Accelerator(GDK_space));
3447 GlobalCommands_insert("CloneSelectionAndMakeUnique", FreeCaller<Selection_Clone_MakeUnique>(), Accelerator(GDK_space, (GdkModifierType)GDK_SHIFT_MASK));
3448 GlobalCommands_insert("DeleteSelection", FreeCaller<deleteSelection>(), Accelerator(GDK_BackSpace));
3449 GlobalCommands_insert("ParentSelection", FreeCaller<Scene_parentSelected>());
3450 GlobalCommands_insert("UnSelectSelection", FreeCaller<Selection_Deselect>(), Accelerator(GDK_Escape));
3451 GlobalCommands_insert("InvertSelection", FreeCaller<Select_Invert>(), Accelerator('I'));
3452 GlobalCommands_insert("SelectInside", FreeCaller<Select_Inside>());
3453 GlobalCommands_insert("SelectTouching", FreeCaller<Select_Touching>());
3454 GlobalCommands_insert("ExpandSelectionToEntities", FreeCaller<Scene_ExpandSelectionToEntities>(), Accelerator('E', (GdkModifierType)(GDK_MOD1_MASK|GDK_CONTROL_MASK)));
3455 GlobalCommands_insert("Preferences", FreeCaller<PreferencesDialog_showDialog>(), Accelerator('P'));
3457 GlobalCommands_insert("ToggleConsole", FreeCaller<Console_ToggleShow>(), Accelerator('O'));
3458 GlobalCommands_insert("ToggleEntityInspector", FreeCaller<EntityInspector_ToggleShow>(), Accelerator('N'));
3459 GlobalCommands_insert("EntityList", FreeCaller<EntityList_toggleShown>(), Accelerator('L'));
3461 GlobalCommands_insert("ShowHidden", FreeCaller<Select_ShowAllHidden>(), Accelerator('H', (GdkModifierType)GDK_SHIFT_MASK));
3462 GlobalCommands_insert("HideSelected", FreeCaller<HideSelected>(), Accelerator('H'));
3464 GlobalToggles_insert("DragVertices", FreeCaller<SelectVertexMode>(), ToggleItem::AddCallbackCaller(g_vertexMode_button), Accelerator('V'));
3465 GlobalToggles_insert("DragEdges", FreeCaller<SelectEdgeMode>(), ToggleItem::AddCallbackCaller(g_edgeMode_button), Accelerator('E'));
3466 GlobalToggles_insert("DragFaces", FreeCaller<SelectFaceMode>(), ToggleItem::AddCallbackCaller(g_faceMode_button), Accelerator('F'));
3468 GlobalCommands_insert("MirrorSelectionX", FreeCaller<Selection_Flipx>());
3469 GlobalCommands_insert("RotateSelectionX", FreeCaller<Selection_Rotatex>());
3470 GlobalCommands_insert("MirrorSelectionY", FreeCaller<Selection_Flipy>());
3471 GlobalCommands_insert("RotateSelectionY", FreeCaller<Selection_Rotatey>());
3472 GlobalCommands_insert("MirrorSelectionZ", FreeCaller<Selection_Flipz>());
3473 GlobalCommands_insert("RotateSelectionZ", FreeCaller<Selection_Rotatez>());
3475 GlobalCommands_insert("ArbitraryRotation", FreeCaller<DoRotateDlg>());
3476 GlobalCommands_insert("ArbitraryScale", FreeCaller<DoScaleDlg>());
3478 GlobalCommands_insert("BuildMenuCustomize", FreeCaller<DoBuildMenu>());
3480 GlobalCommands_insert("FindBrush", FreeCaller<DoFind>());
3482 GlobalCommands_insert("MapInfo", FreeCaller<DoMapInfo>(), Accelerator('M'));
3485 GlobalToggles_insert("ToggleClipper", FreeCaller<ClipperMode>(), ToggleItem::AddCallbackCaller(g_clipper_button), Accelerator('X'));
3487 GlobalToggles_insert("MouseTranslate", FreeCaller<TranslateMode>(), ToggleItem::AddCallbackCaller(g_translatemode_button), Accelerator('W'));
3488 GlobalToggles_insert("MouseRotate", FreeCaller<RotateMode>(), ToggleItem::AddCallbackCaller(g_rotatemode_button), Accelerator('R'));
3489 GlobalToggles_insert("MouseScale", FreeCaller<ScaleMode>(), ToggleItem::AddCallbackCaller(g_scalemode_button));
3490 GlobalToggles_insert("MouseDrag", FreeCaller<DragMode>(), ToggleItem::AddCallbackCaller(g_dragmode_button), Accelerator('Q'));
3492 GlobalCommands_insert("ColorSchemeOriginal", FreeCaller<ColorScheme_Original>());
3493 GlobalCommands_insert("ColorSchemeQER", FreeCaller<ColorScheme_QER>());
3494 GlobalCommands_insert("ColorSchemeBlackAndGreen", FreeCaller<ColorScheme_Black>());
3495 GlobalCommands_insert("ColorSchemeYdnar", FreeCaller<ColorScheme_Ydnar>());
3496 GlobalCommands_insert("ChooseTextureBackgroundColor", makeCallback(g_ColoursMenu.m_textureback));
3497 GlobalCommands_insert("ChooseGridBackgroundColor", makeCallback(g_ColoursMenu.m_xyback));
3498 GlobalCommands_insert("ChooseGridMajorColor", makeCallback(g_ColoursMenu.m_gridmajor));
3499 GlobalCommands_insert("ChooseGridMinorColor", makeCallback(g_ColoursMenu.m_gridminor));
3500 GlobalCommands_insert("ChooseSmallGridMajorColor", makeCallback(g_ColoursMenu.m_gridmajor_alt));
3501 GlobalCommands_insert("ChooseSmallGridMinorColor", makeCallback(g_ColoursMenu.m_gridminor_alt));
3502 GlobalCommands_insert("ChooseGridTextColor", makeCallback(g_ColoursMenu.m_gridtext));
3503 GlobalCommands_insert("ChooseGridBlockColor", makeCallback(g_ColoursMenu.m_gridblock));
3504 GlobalCommands_insert("ChooseBrushColor", makeCallback(g_ColoursMenu.m_brush));
3505 GlobalCommands_insert("ChooseCameraBackgroundColor", makeCallback(g_ColoursMenu.m_cameraback));
3506 GlobalCommands_insert("ChooseSelectedBrushColor", makeCallback(g_ColoursMenu.m_selectedbrush));
3507 GlobalCommands_insert("ChooseCameraSelectedBrushColor", makeCallback(g_ColoursMenu.m_selectedbrush3d));
3508 GlobalCommands_insert("ChooseClipperColor", makeCallback(g_ColoursMenu.m_clipper));
3509 GlobalCommands_insert("ChooseOrthoViewNameColor", makeCallback(g_ColoursMenu.m_viewname));
3512 GlobalCommands_insert("CSGSubtract", FreeCaller<CSG_Subtract>(), Accelerator('U', (GdkModifierType)GDK_SHIFT_MASK));
3513 GlobalCommands_insert("CSGMerge", FreeCaller<CSG_Merge>(), Accelerator('U', (GdkModifierType)GDK_CONTROL_MASK));
3514 GlobalCommands_insert("CSGHollow", FreeCaller<CSG_MakeHollow>());
3516 Grid_registerCommands();
3518 GlobalCommands_insert("SnapToGrid", FreeCaller<Selection_SnapToGrid>(), Accelerator('G', (GdkModifierType)GDK_CONTROL_MASK));
3520 GlobalCommands_insert("SelectAllOfType", FreeCaller<Select_AllOfType>(), Accelerator('A', (GdkModifierType)GDK_SHIFT_MASK));
3522 GlobalCommands_insert("TexRotateClock", FreeCaller<Texdef_RotateClockwise>(), Accelerator(GDK_Next, (GdkModifierType)GDK_SHIFT_MASK));
3523 GlobalCommands_insert("TexRotateCounter", FreeCaller<Texdef_RotateAntiClockwise>(), Accelerator(GDK_Prior, (GdkModifierType)GDK_SHIFT_MASK));
3524 GlobalCommands_insert("TexScaleUp", FreeCaller<Texdef_ScaleUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_CONTROL_MASK));
3525 GlobalCommands_insert("TexScaleDown", FreeCaller<Texdef_ScaleDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_CONTROL_MASK));
3526 GlobalCommands_insert("TexScaleLeft", FreeCaller<Texdef_ScaleLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_CONTROL_MASK));
3527 GlobalCommands_insert("TexScaleRight", FreeCaller<Texdef_ScaleRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_CONTROL_MASK));
3528 GlobalCommands_insert("TexShiftUp", FreeCaller<Texdef_ShiftUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_SHIFT_MASK));
3529 GlobalCommands_insert("TexShiftDown", FreeCaller<Texdef_ShiftDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_SHIFT_MASK));
3530 GlobalCommands_insert("TexShiftLeft", FreeCaller<Texdef_ShiftLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_SHIFT_MASK));
3531 GlobalCommands_insert("TexShiftRight", FreeCaller<Texdef_ShiftRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_SHIFT_MASK));
3533 GlobalCommands_insert("MoveSelectionDOWN", FreeCaller<Selection_MoveDown>(), Accelerator(GDK_KP_Subtract));
3534 GlobalCommands_insert("MoveSelectionUP", FreeCaller<Selection_MoveUp>(), Accelerator(GDK_KP_Add));
3536 GlobalCommands_insert("SelectNudgeLeft", FreeCaller<Selection_NudgeLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_MOD1_MASK));
3537 GlobalCommands_insert("SelectNudgeRight", FreeCaller<Selection_NudgeRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_MOD1_MASK));
3538 GlobalCommands_insert("SelectNudgeUp", FreeCaller<Selection_NudgeUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_MOD1_MASK));
3539 GlobalCommands_insert("SelectNudgeDown", FreeCaller<Selection_NudgeDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_MOD1_MASK));
3541 Patch_registerCommands();
3542 XYShow_registerCommands();
3544 typedef FreeCaller1<const Selectable&, ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3545 GlobalSelectionSystem().addSelectionChangeCallback(ComponentModeSelectionChangedCaller());
3547 GlobalPreferenceSystem().registerPreference("DetachableMenus", BoolImportStringCaller(g_Layout_enableDetachableMenus.m_latched), BoolExportStringCaller(g_Layout_enableDetachableMenus.m_latched));
3548 GlobalPreferenceSystem().registerPreference("PatchToolBar", BoolImportStringCaller(g_Layout_enablePatchToolbar.m_latched), BoolExportStringCaller(g_Layout_enablePatchToolbar.m_latched));
3549 GlobalPreferenceSystem().registerPreference("PluginToolBar", BoolImportStringCaller(g_Layout_enablePluginToolbar.m_latched), BoolExportStringCaller(g_Layout_enablePluginToolbar.m_latched));
3550 GlobalPreferenceSystem().registerPreference("QE4StyleWindows", IntImportStringCaller(g_Layout_viewStyle.m_latched), IntExportStringCaller(g_Layout_viewStyle.m_latched));
3551 GlobalPreferenceSystem().registerPreference("XYHeight", IntImportStringCaller(g_layout_globals.nXYHeight), IntExportStringCaller(g_layout_globals.nXYHeight));
3552 GlobalPreferenceSystem().registerPreference("XYWidth", IntImportStringCaller(g_layout_globals.nXYWidth), IntExportStringCaller(g_layout_globals.nXYWidth));
3553 GlobalPreferenceSystem().registerPreference("CamWidth", IntImportStringCaller(g_layout_globals.nCamWidth), IntExportStringCaller(g_layout_globals.nCamWidth));
3554 GlobalPreferenceSystem().registerPreference("CamHeight", IntImportStringCaller(g_layout_globals.nCamHeight), IntExportStringCaller(g_layout_globals.nCamHeight));
3556 GlobalPreferenceSystem().registerPreference("State", IntImportStringCaller(g_layout_globals.nState), IntExportStringCaller(g_layout_globals.nState));
3557 GlobalPreferenceSystem().registerPreference("PositionX", IntImportStringCaller(g_layout_globals.m_position.x), IntExportStringCaller(g_layout_globals.m_position.x));
3558 GlobalPreferenceSystem().registerPreference("PositionY", IntImportStringCaller(g_layout_globals.m_position.y), IntExportStringCaller(g_layout_globals.m_position.y));
3559 GlobalPreferenceSystem().registerPreference("Width", IntImportStringCaller(g_layout_globals.m_position.w), IntExportStringCaller(g_layout_globals.m_position.w));
3560 GlobalPreferenceSystem().registerPreference("Height", IntImportStringCaller(g_layout_globals.m_position.h), IntExportStringCaller(g_layout_globals.m_position.h));
3562 GlobalPreferenceSystem().registerPreference("CamWnd", WindowPositionTrackerImportStringCaller(g_posCamWnd), WindowPositionTrackerExportStringCaller(g_posCamWnd));
3563 GlobalPreferenceSystem().registerPreference("XYWnd", WindowPositionTrackerImportStringCaller(g_posXYWnd), WindowPositionTrackerExportStringCaller(g_posXYWnd));
3564 GlobalPreferenceSystem().registerPreference("YZWnd", WindowPositionTrackerImportStringCaller(g_posYZWnd), WindowPositionTrackerExportStringCaller(g_posYZWnd));
3565 GlobalPreferenceSystem().registerPreference("XZWnd", WindowPositionTrackerImportStringCaller(g_posXZWnd), WindowPositionTrackerExportStringCaller(g_posXZWnd));
3568 const char* ENGINEPATH_ATTRIBUTE =
3571 #elif defined(__linux__) || defined (__FreeBSD__)
3573 #elif defined(__APPLE__)
3576 #error "unknown platform"
3579 StringOutputStream path(256);
3580 path << DirectoryCleaned(g_pGameDescription->getRequiredKeyValue(ENGINEPATH_ATTRIBUTE));
3581 g_strEnginePath = path.c_str();
3584 GlobalPreferenceSystem().registerPreference("EnginePath", CopiedStringImportStringCaller(g_strEnginePath), CopiedStringExportStringCaller(g_strEnginePath));
3586 g_Layout_viewStyle.useLatched();
3587 g_Layout_enableDetachableMenus.useLatched();
3588 g_Layout_enablePatchToolbar.useLatched();
3589 g_Layout_enablePluginToolbar.useLatched();
3591 Layout_registerPreferencesPage();
3592 Paths_registerPreferencesPage();
3594 g_brushCount.setCountChangedCallback(FreeCaller<QE_brushCountChanged>());
3595 g_entityCount.setCountChangedCallback(FreeCaller<QE_entityCountChanged>());
3596 GlobalEntityCreator().setCounter(&g_entityCount);
3598 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3599 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3601 GlobalEntityClassManager().attach(g_WorldspawnColourEntityClassObserver);
3604 void MainFrame_Destroy()
3606 GlobalEntityClassManager().detach(g_WorldspawnColourEntityClassObserver);
3608 GlobalEntityCreator().setCounter(0);
3609 g_entityCount.setCountChangedCallback(Callback());
3610 g_brushCount.setCountChangedCallback(Callback());
3614 void GLWindow_Construct()
3616 GlobalPreferenceSystem().registerPreference("MouseButtons", IntImportStringCaller(g_glwindow_globals.m_nMouseType), IntExportStringCaller(g_glwindow_globals.m_nMouseType));
3619 void GLWindow_Destroy()