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);
190 void HomePaths_Realise()
193 const char* prefix = g_pGameDescription->getKeyValue("prefix");
194 if(!string_empty(prefix))
196 StringOutputStream path(256);
197 path << DirectoryCleaned(g_get_home_dir()) << prefix << "/";
198 g_qeglobals.m_userEnginePath = path.c_str();
199 Q_mkdir(g_qeglobals.m_userEnginePath.c_str());
203 const char* prefix = g_pGameDescription->getKeyValue("prefix");
204 if(!string_empty(prefix))
206 StringOutputStream path(256);
207 TCHAR mydocsdir[MAX_PATH + 1];
208 if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir))
210 path << DirectoryCleaned(mydocsdir) << "My Games/" << prefix << "/";
211 // win32: only add it if it already exists
212 if(file_is_directory(path.c_str()))
213 g_qeglobals.m_userEnginePath = path.c_str();
215 g_qeglobals.m_userEnginePath = EnginePath_get();
219 g_qeglobals.m_userEnginePath = EnginePath_get();
225 g_qeglobals.m_userEnginePath = EnginePath_get();
229 StringOutputStream path(256);
230 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
231 g_qeglobals.m_userGamePath = path.c_str();
233 ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "HomePaths_Realise: user-game-path is empty");
234 Q_mkdir(g_qeglobals.m_userGamePath.c_str());
237 ModuleObservers g_homePathObservers;
239 void Radiant_attachHomePathsObserver(ModuleObserver& observer)
241 g_homePathObservers.attach(observer);
244 void Radiant_detachHomePathsObserver(ModuleObserver& observer)
246 g_homePathObservers.detach(observer);
249 class HomePathsModuleObserver : public ModuleObserver
251 std::size_t m_unrealised;
253 HomePathsModuleObserver() : m_unrealised(1)
258 if(--m_unrealised == 0)
261 g_homePathObservers.realise();
266 if(++m_unrealised == 1)
268 g_homePathObservers.unrealise();
273 HomePathsModuleObserver g_HomePathsModuleObserver;
275 void HomePaths_Construct()
277 Radiant_attachEnginePathObserver(g_HomePathsModuleObserver);
279 void HomePaths_Destroy()
281 Radiant_detachEnginePathObserver(g_HomePathsModuleObserver);
287 CopiedString g_strEnginePath;
288 ModuleObservers g_enginePathObservers;
289 std::size_t g_enginepath_unrealised = 1;
291 void Radiant_attachEnginePathObserver(ModuleObserver& observer)
293 g_enginePathObservers.attach(observer);
296 void Radiant_detachEnginePathObserver(ModuleObserver& observer)
298 g_enginePathObservers.detach(observer);
302 void EnginePath_Realise()
304 if(--g_enginepath_unrealised == 0)
306 g_enginePathObservers.realise();
311 const char* EnginePath_get()
313 ASSERT_MESSAGE(g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised");
314 return g_strEnginePath.c_str();
317 void EnginePath_Unrealise()
319 if(++g_enginepath_unrealised == 1)
321 g_enginePathObservers.unrealise();
325 void setEnginePath(const char* path)
327 StringOutputStream buffer(256);
328 buffer << DirectoryCleaned(path);
329 if(!path_equal(buffer.c_str(), g_strEnginePath.c_str()))
332 while(!ConfirmModified("Paths Changed"))
334 if(Map_Unnamed(g_map))
346 ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Changing Engine Path");
348 EnginePath_Unrealise();
350 g_strEnginePath = buffer.c_str();
352 EnginePath_Realise();
359 CopiedString g_strAppPath; ///< holds the full path of the executable
361 const char* AppPath_get()
363 return g_strAppPath.c_str();
366 /// the path to the local rc-dir
367 const char* LocalRcPath_get(void)
369 static CopiedString rc_path;
372 StringOutputStream stream(256);
373 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
374 rc_path = stream.c_str();
376 return rc_path.c_str();
379 /// directory for temp files
380 /// NOTE: on *nix this is were we check for .pid
381 CopiedString g_strSettingsPath;
382 const char* SettingsPath_get()
384 return g_strSettingsPath.c_str();
389 points to the game tools directory, for instance
390 C:/Program Files/Quake III Arena/GtkRadiant
392 this is one of the main variables that are configured by the game selection on startup
393 [GameToolsPath]/plugins
394 [GameToolsPath]/modules
397 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
399 const char* GameToolsPath_get()
401 return g_strGameToolsPath.c_str();
404 void EnginePathImport(CopiedString& self, const char* value)
406 setEnginePath(value);
408 typedef ReferenceCaller1<CopiedString, const char*, EnginePathImport> EnginePathImportCaller;
410 void Paths_constructPreferences(PreferencesPage& page)
412 page.appendPathEntry("Engine Path", true,
413 StringImportCallback(EnginePathImportCaller(g_strEnginePath)),
414 StringExportCallback(StringExportCaller(g_strEnginePath))
417 void Paths_constructPage(PreferenceGroup& group)
419 PreferencesPage page(group.createPage("Paths", "Path Settings"));
420 Paths_constructPreferences(page);
422 void Paths_registerPreferencesPage()
424 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Paths_constructPage>());
428 class PathsDialog : public Dialog
431 GtkWindow* BuildDialog()
433 GtkFrame* frame = create_dialog_frame("Path settings", GTK_SHADOW_ETCHED_IN);
435 GtkVBox* vbox2 = create_dialog_vbox(0, 4);
436 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(vbox2));
439 PreferencesPage preferencesPage(*this, GTK_WIDGET(vbox2));
440 Paths_constructPreferences(preferencesPage);
443 return create_simple_modal_dialog_window("Engine Path Not Found", m_modal, GTK_WIDGET(frame));
447 PathsDialog g_PathsDialog;
449 void EnginePath_verify()
451 if(!file_exists(g_strEnginePath.c_str()))
453 g_PathsDialog.Create();
454 g_PathsDialog.DoModal();
455 g_PathsDialog.Destroy();
461 CopiedString g_gamename;
462 CopiedString g_gamemode;
463 ModuleObservers g_gameNameObservers;
464 ModuleObservers g_gameModeObservers;
467 void Radiant_attachGameNameObserver(ModuleObserver& observer)
469 g_gameNameObservers.attach(observer);
472 void Radiant_detachGameNameObserver(ModuleObserver& observer)
474 g_gameNameObservers.detach(observer);
477 const char* basegame_get()
479 return g_pGameDescription->getRequiredKeyValue("basegame");
482 const char* gamename_get()
484 const char* gamename = g_gamename.c_str();
485 if(string_empty(gamename))
487 return basegame_get();
492 void gamename_set(const char* gamename)
494 if(!string_equal(gamename, g_gamename.c_str()))
496 g_gameNameObservers.unrealise();
497 g_gamename = gamename;
498 g_gameNameObservers.realise();
502 void Radiant_attachGameModeObserver(ModuleObserver& observer)
504 g_gameModeObservers.attach(observer);
507 void Radiant_detachGameModeObserver(ModuleObserver& observer)
509 g_gameModeObservers.detach(observer);
512 const char* gamemode_get()
514 return g_gamemode.c_str();
517 void gamemode_set(const char* gamemode)
519 if(!string_equal(gamemode, g_gamemode.c_str()))
521 g_gameModeObservers.unrealise();
522 g_gamemode = gamemode;
523 g_gameModeObservers.realise();
533 CLoadModule(const char* path) : m_path(path)
536 void operator()(const char* name) const
539 ASSERT_MESSAGE(strlen(m_path) + strlen(name) < 1024, "");
540 strcpy(fullname, m_path);
541 strcat(fullname, name);
542 globalOutputStream() << "Found '" << fullname << "'\n";
543 GlobalModuleServer_loadModule(fullname);
547 const char* const c_library_extension =
550 #elif defined (__APPLE__)
552 #elif defined(__linux__) || defined (__FreeBSD__)
557 void Radiant_loadModules(const char* path)
559 Directory_forEach(path, MatchFileExtension<CLoadModule>(c_library_extension, CLoadModule(path)));
562 void Radiant_loadModulesFromRoot(const char* directory)
565 StringOutputStream path(256);
566 path << directory << g_pluginsDir;
567 Radiant_loadModules(path.c_str());
570 if(!string_equal(g_pluginsDir, g_modulesDir))
572 StringOutputStream path(256);
573 path << directory << g_modulesDir;
574 Radiant_loadModules(path.c_str());
578 //! Make COLOR_BRUSHES override worldspawn eclass colour.
579 void SetWorldspawnColour(const Vector3& colour)
581 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert("worldspawn", true);
582 eclass_release_state(worldspawn);
583 worldspawn->color = colour;
584 eclass_capture_state(worldspawn);
588 class WorldspawnColourEntityClassObserver : public ModuleObserver
590 std::size_t m_unrealised;
592 WorldspawnColourEntityClassObserver() : m_unrealised(1)
597 if(--m_unrealised == 0)
599 SetWorldspawnColour(g_xywindow_globals.color_brushes);
604 if(++m_unrealised == 1)
610 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
613 ModuleObservers g_gameToolsPathObservers;
615 void Radiant_attachGameToolsPathObserver(ModuleObserver& observer)
617 g_gameToolsPathObservers.attach(observer);
620 void Radiant_detachGameToolsPathObserver(ModuleObserver& observer)
622 g_gameToolsPathObservers.detach(observer);
625 void Radiant_Initialise()
627 GlobalModuleServer_Initialise();
629 Radiant_loadModulesFromRoot(AppPath_get());
633 bool success = Radiant_Construct(GlobalModuleServer_get());
634 ASSERT_MESSAGE(success, "module system failed to initialise - see radiant.log for error messages");
636 g_gameToolsPathObservers.realise();
637 g_gameModeObservers.realise();
638 g_gameNameObservers.realise();
641 void Radiant_Shutdown()
643 g_gameNameObservers.unrealise();
644 g_gameModeObservers.unrealise();
645 g_gameToolsPathObservers.unrealise();
647 if (!g_preferences_globals.disable_ini)
649 globalOutputStream() << "Start writing prefs\n";
651 globalOutputStream() << "Done prefs\n";
656 GlobalModuleServer_Shutdown();
661 if(ConfirmModified("Exit Radiant"))
670 GlobalUndoSystem().undo();
676 GlobalUndoSystem().redo();
680 void deleteSelection()
682 UndoableCommand undo("deleteSelected");
686 void Map_ExportSelected(TextOutputStream& ostream)
688 Map_ExportSelected(ostream, Map_getFormat(g_map));
691 void Map_ImportSelected(TextInputStream& istream)
693 Map_ImportSelected(istream, Map_getFormat(g_map));
696 void Selection_Copy()
698 clipboard_copy(Map_ExportSelected);
701 void Selection_Paste()
703 clipboard_paste(Map_ImportSelected);
708 if(SelectedFaces_empty())
714 SelectedFaces_copyTexture();
720 if(SelectedFaces_empty())
722 UndoableCommand undo("paste");
724 GlobalSelectionSystem().setSelectedAll(false);
729 SelectedFaces_pasteTexture();
735 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
736 GlobalSelectionSystem().setSelectedAll(false);
738 UndoableCommand undo("pasteToCamera");
742 // Work out the delta
745 Vector3 delta = vector3_subtracted(vector3_snapped(Camera_getOrigin(camwnd), GetSnapGridSize()), mid);
748 GlobalSelectionSystem().translateSelected(delta);
752 void ColorScheme_Original()
754 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
756 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
757 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
758 CamWnd_Update(*g_pParentWnd->GetCamWnd());
760 g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
761 g_xywindow_globals.color_gridminor = Vector3(0.75f, 0.75f, 0.75f);
762 g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
763 g_xywindow_globals.color_gridminor_alt = Vector3(0.5f, 0.0f, 0.0f);
764 g_xywindow_globals.color_gridmajor_alt = Vector3(1.0f, 0.0f, 0.0f);
765 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
766 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
767 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
768 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
769 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
770 SetWorldspawnColour(g_xywindow_globals.color_brushes);
771 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
772 XY_UpdateAllWindows();
775 void ColorScheme_QER()
777 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
779 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
780 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
781 CamWnd_Update(*g_pParentWnd->GetCamWnd());
783 g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
784 g_xywindow_globals.color_gridminor = Vector3(1.0f, 1.0f, 1.0f);
785 g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
786 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
787 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
788 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
789 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
790 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
791 SetWorldspawnColour(g_xywindow_globals.color_brushes);
792 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
793 XY_UpdateAllWindows();
796 void ColorScheme_Black()
798 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
800 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
801 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
802 CamWnd_Update(*g_pParentWnd->GetCamWnd());
804 g_xywindow_globals.color_gridback = Vector3(0.0f, 0.0f, 0.0f);
805 g_xywindow_globals.color_gridminor = Vector3(0.2f, 0.2f, 0.2f);
806 g_xywindow_globals.color_gridmajor = Vector3(0.3f, 0.5f, 0.5f);
807 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
808 g_xywindow_globals.color_gridtext = Vector3(1.0f, 1.0f, 1.0f);
809 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
810 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
811 g_xywindow_globals.color_brushes = Vector3(1.0f, 1.0f, 1.0f);
812 SetWorldspawnColour(g_xywindow_globals.color_brushes);
813 g_xywindow_globals.color_viewname = Vector3(0.7f, 0.7f, 0.0f);
814 XY_UpdateAllWindows();
817 /* ydnar: to emulate maya/max/lightwave color schemes */
818 void ColorScheme_Ydnar()
820 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
822 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
823 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
824 CamWnd_Update(*g_pParentWnd->GetCamWnd());
826 g_xywindow_globals.color_gridback = Vector3(0.77f, 0.77f, 0.77f);
827 g_xywindow_globals.color_gridminor = Vector3(0.83f, 0.83f, 0.83f);
828 g_xywindow_globals.color_gridmajor = Vector3(0.89f, 0.89f, 0.89f);
829 g_xywindow_globals.color_gridblock = Vector3(1.0f, 1.0f, 1.0f);
830 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
831 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
832 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
833 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
834 SetWorldspawnColour(g_xywindow_globals.color_brushes);
835 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
836 XY_UpdateAllWindows();
839 typedef Callback1<Vector3&> GetColourCallback;
840 typedef Callback1<const Vector3&> SetColourCallback;
844 GetColourCallback m_get;
845 SetColourCallback m_set;
847 ChooseColour(const GetColourCallback& get, const SetColourCallback& set)
848 : m_get(get), m_set(set)
855 color_dialog(GTK_WIDGET(MainFrame_getWindow()), colour);
862 void Colour_get(const Vector3& colour, Vector3& other)
866 typedef ConstReferenceCaller1<Vector3, Vector3&, Colour_get> ColourGetCaller;
868 void Colour_set(Vector3& colour, const Vector3& other)
873 typedef ReferenceCaller1<Vector3, const Vector3&, Colour_set> ColourSetCaller;
875 void BrushColour_set(const Vector3& other)
877 g_xywindow_globals.color_brushes = other;
878 SetWorldspawnColour(g_xywindow_globals.color_brushes);
881 typedef FreeCaller1<const Vector3&, BrushColour_set> BrushColourSetCaller;
883 void ClipperColour_set(const Vector3& other)
885 g_xywindow_globals.color_clipper = other;
886 Brush_clipperColourChanged();
889 typedef FreeCaller1<const Vector3&, ClipperColour_set> ClipperColourSetCaller;
891 void TextureBrowserColour_get(Vector3& other)
893 other = TextureBrowser_getBackgroundColour(GlobalTextureBrowser());
895 typedef FreeCaller1<Vector3&, TextureBrowserColour_get> TextureBrowserColourGetCaller;
897 void TextureBrowserColour_set(const Vector3& other)
899 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), other);
901 typedef FreeCaller1<const Vector3&, TextureBrowserColour_set> TextureBrowserColourSetCaller;
907 ChooseColour m_textureback;
908 ChooseColour m_xyback;
909 ChooseColour m_gridmajor;
910 ChooseColour m_gridminor;
911 ChooseColour m_gridmajor_alt;
912 ChooseColour m_gridminor_alt;
913 ChooseColour m_gridtext;
914 ChooseColour m_gridblock;
915 ChooseColour m_cameraback;
916 ChooseColour m_brush;
917 ChooseColour m_selectedbrush;
918 ChooseColour m_selectedbrush3d;
919 ChooseColour m_clipper;
920 ChooseColour m_viewname;
923 m_textureback(TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller()),
924 m_xyback(ColourGetCaller(g_xywindow_globals.color_gridback), ColourSetCaller(g_xywindow_globals.color_gridback)),
925 m_gridmajor(ColourGetCaller(g_xywindow_globals.color_gridmajor), ColourSetCaller(g_xywindow_globals.color_gridmajor)),
926 m_gridminor(ColourGetCaller(g_xywindow_globals.color_gridminor), ColourSetCaller(g_xywindow_globals.color_gridminor)),
927 m_gridmajor_alt(ColourGetCaller(g_xywindow_globals.color_gridmajor_alt), ColourSetCaller(g_xywindow_globals.color_gridmajor_alt)),
928 m_gridminor_alt(ColourGetCaller(g_xywindow_globals.color_gridminor_alt), ColourSetCaller(g_xywindow_globals.color_gridminor_alt)),
929 m_gridtext(ColourGetCaller(g_xywindow_globals.color_gridtext), ColourSetCaller(g_xywindow_globals.color_gridtext)),
930 m_gridblock(ColourGetCaller(g_xywindow_globals.color_gridblock), ColourSetCaller(g_xywindow_globals.color_gridblock)),
931 m_cameraback(ColourGetCaller(g_camwindow_globals.color_cameraback), ColourSetCaller(g_camwindow_globals.color_cameraback)),
932 m_brush(ColourGetCaller(g_xywindow_globals.color_brushes), BrushColourSetCaller()),
933 m_selectedbrush(ColourGetCaller(g_xywindow_globals.color_selbrushes), ColourSetCaller(g_xywindow_globals.color_selbrushes)),
934 m_selectedbrush3d(ColourGetCaller(g_camwindow_globals.color_selbrushes3d), ColourSetCaller(g_camwindow_globals.color_selbrushes3d)),
935 m_clipper(ColourGetCaller(g_xywindow_globals.color_clipper), ClipperColourSetCaller()),
936 m_viewname(ColourGetCaller(g_xywindow_globals.color_viewname), ColourSetCaller(g_xywindow_globals.color_viewname))
941 ColoursMenu g_ColoursMenu;
943 GtkMenuItem* create_colours_menu()
945 GtkMenuItem* colours_menu_item = new_sub_menu_item_with_mnemonic("Colors");
946 GtkMenu* menu_in_menu = GTK_MENU(gtk_menu_item_get_submenu(colours_menu_item));
947 if (g_Layout_enableDetachableMenus.m_value)
948 menu_tearoff (menu_in_menu);
950 GtkMenu* menu_3 = create_sub_menu_with_mnemonic(menu_in_menu, "Themes");
951 if (g_Layout_enableDetachableMenus.m_value)
952 menu_tearoff (menu_3);
954 create_menu_item_with_mnemonic(menu_3, "QE4 Original", "ColorSchemeOriginal");
955 create_menu_item_with_mnemonic(menu_3, "Q3Radiant Original", "ColorSchemeQER");
956 create_menu_item_with_mnemonic(menu_3, "Black and Green", "ColorSchemeBlackAndGreen");
957 create_menu_item_with_mnemonic(menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar");
959 menu_separator(menu_in_menu);
961 create_menu_item_with_mnemonic(menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor");
962 create_menu_item_with_mnemonic(menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor");
963 create_menu_item_with_mnemonic(menu_in_menu, "Grid Major...", "ChooseGridMajorColor");
964 create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor...", "ChooseGridMinorColor");
965 create_menu_item_with_mnemonic(menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor");
966 create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor");
967 create_menu_item_with_mnemonic(menu_in_menu, "Grid Text...", "ChooseGridTextColor");
968 create_menu_item_with_mnemonic(menu_in_menu, "Grid Block...", "ChooseGridBlockColor");
969 create_menu_item_with_mnemonic(menu_in_menu, "Default Brush...", "ChooseBrushColor");
970 create_menu_item_with_mnemonic(menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor");
971 create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor");
972 create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor");
973 create_menu_item_with_mnemonic(menu_in_menu, "Clipper...", "ChooseClipperColor");
974 create_menu_item_with_mnemonic(menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor");
976 return colours_menu_item;
983 PluginToolbar_clear();
986 Radiant_Initialise();
988 PluginsMenu_populate();
990 PluginToolbar_populate();
996 g_pParentWnd->OnSleep();
1002 StringOutputStream URL(256);
1003 URL << "http://www.icculus.org/netradiant/?cmd=update&data=dlupdate&query_dlup=1";
1005 URL << "&OS_dlup=1";
1006 #elif defined(__APPLE__)
1007 URL << "&OS_dlup=2";
1009 URL << "&OS_dlup=3";
1011 URL << "&Version_dlup=" RADIANT_VERSION;
1012 g_GamesDialog.AddPacksURL(URL);
1013 OpenURL(URL.c_str());
1016 // open the Q3Rad manual
1019 // at least on win32, AppPath + "docs/index.html"
1020 StringOutputStream help(256);
1021 help << AppPath_get() << "docs/index.html";
1022 OpenURL(help.c_str());
1025 void OpenBugReportURL()
1027 OpenURL("http://www.icculus.org/netradiant/?cmd=bugs");
1031 GtkWidget* g_page_console;
1033 void Console_ToggleShow()
1035 GroupDialog_showPage(g_page_console);
1038 GtkWidget* g_page_entity;
1040 void EntityInspector_ToggleShow()
1042 GroupDialog_showPage(g_page_entity);
1047 void SetClipMode(bool enable);
1048 void ModeChangeNotify();
1050 typedef void(*ToolMode)();
1051 ToolMode g_currentToolMode = 0;
1052 bool g_currentToolModeSupportsComponentEditing = false;
1053 ToolMode g_defaultToolMode = 0;
1057 void SelectionSystem_DefaultMode()
1059 GlobalSelectionSystem().SetMode(SelectionSystem::ePrimitive);
1060 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eDefault);
1067 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1068 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1073 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1074 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1079 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1080 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1083 template<bool (*BoolFunction)()>
1084 class BoolFunctionExport
1087 static void apply(const BoolImportCallback& importCallback)
1089 importCallback(BoolFunction());
1093 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1094 EdgeModeApplyCaller g_edgeMode_button_caller;
1095 BoolExportCallback g_edgeMode_button_callback(g_edgeMode_button_caller);
1096 ToggleItem g_edgeMode_button(g_edgeMode_button_callback);
1098 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1099 VertexModeApplyCaller g_vertexMode_button_caller;
1100 BoolExportCallback g_vertexMode_button_callback(g_vertexMode_button_caller);
1101 ToggleItem g_vertexMode_button(g_vertexMode_button_callback);
1103 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1104 FaceModeApplyCaller g_faceMode_button_caller;
1105 BoolExportCallback g_faceMode_button_callback(g_faceMode_button_caller);
1106 ToggleItem g_faceMode_button(g_faceMode_button_callback);
1108 void ComponentModeChanged()
1110 g_edgeMode_button.update();
1111 g_vertexMode_button.update();
1112 g_faceMode_button.update();
1115 void ComponentMode_SelectionChanged(const Selectable& selectable)
1117 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1118 && GlobalSelectionSystem().countSelected() == 0)
1120 SelectionSystem_DefaultMode();
1121 ComponentModeChanged();
1125 void SelectEdgeMode()
1128 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1130 GlobalSelectionSystem().Select(false);
1136 SelectionSystem_DefaultMode();
1138 else if(GlobalSelectionSystem().countSelected() != 0)
1140 if(!g_currentToolModeSupportsComponentEditing)
1142 g_defaultToolMode();
1145 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1146 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eEdge);
1149 ComponentModeChanged();
1154 void SelectVertexMode()
1157 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1159 GlobalSelectionSystem().Select(false);
1165 SelectionSystem_DefaultMode();
1167 else if(GlobalSelectionSystem().countSelected() != 0)
1169 if(!g_currentToolModeSupportsComponentEditing)
1171 g_defaultToolMode();
1174 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1175 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eVertex);
1178 ComponentModeChanged();
1183 void SelectFaceMode()
1186 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1188 GlobalSelectionSystem().Select(false);
1194 SelectionSystem_DefaultMode();
1196 else if(GlobalSelectionSystem().countSelected() != 0)
1198 if(!g_currentToolModeSupportsComponentEditing)
1200 g_defaultToolMode();
1203 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1204 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eFace);
1207 ComponentModeChanged();
1213 class CloneSelected : public scene::Graph::Walker
1216 NodeSmartReference worldspawn;
1218 CloneSelected(bool d): doMakeUnique(d), worldspawn(Map_FindOrInsertWorldspawn(g_map))
1221 bool pre(const scene::Path& path, scene::Instance& instance) const
1223 if(path.size() == 1)
1226 // ignore worldspawn, but keep checking children
1227 NodeSmartReference me(path.top().get());
1228 if(me == worldspawn)
1231 if(!path.top().get().isRoot())
1233 Selectable* selectable = Instance_getSelectable(instance);
1235 && selectable->isSelected())
1243 void post(const scene::Path& path, scene::Instance& instance) const
1245 if(path.size() == 1)
1248 // ignore worldspawn, but keep checking children
1249 NodeSmartReference me(path.top().get());
1250 if(me == worldspawn)
1253 if(!path.top().get().isRoot())
1255 Selectable* selectable = Instance_getSelectable(instance);
1257 && selectable->isSelected())
1259 NodeSmartReference clone(Node_Clone(path.top()));
1261 Map_gatherNamespaced(clone);
1262 Node_getTraversable(path.parent().get())->insert(clone);
1268 void Scene_Clone_Selected(scene::Graph& graph, bool doMakeUnique)
1270 graph.traverse(CloneSelected(doMakeUnique));
1272 Map_mergeClonedNames();
1275 enum ENudgeDirection
1288 AxisBase(const Vector3& x_, const Vector3& y_, const Vector3& z_)
1289 : x(x_), y(y_), z(z_)
1294 AxisBase AxisBase_forViewType(VIEWTYPE viewtype)
1299 return AxisBase(g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z);
1301 return AxisBase(g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y);
1303 return AxisBase(g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x);
1306 ERROR_MESSAGE("invalid viewtype");
1307 return AxisBase(Vector3(0, 0, 0), Vector3(0, 0, 0), Vector3(0, 0, 0));
1310 Vector3 AxisBase_axisForDirection(const AxisBase& axes, ENudgeDirection direction)
1315 return vector3_negated(axes.x);
1321 return vector3_negated(axes.y);
1324 ERROR_MESSAGE("invalid direction");
1325 return Vector3(0, 0, 0);
1328 void NudgeSelection(ENudgeDirection direction, float fAmount, VIEWTYPE viewtype)
1330 AxisBase axes(AxisBase_forViewType(viewtype));
1331 Vector3 view_direction(vector3_negated(axes.z));
1332 Vector3 nudge(vector3_scaled(AxisBase_axisForDirection(axes, direction), fAmount));
1333 GlobalSelectionSystem().NudgeManipulator(nudge, view_direction);
1336 void Selection_Clone()
1338 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
1340 UndoableCommand undo("cloneSelected");
1342 Scene_Clone_Selected(GlobalSceneGraph(), false);
1344 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1345 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1349 void Selection_Clone_MakeUnique()
1351 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
1353 UndoableCommand undo("cloneSelectedMakeUnique");
1355 Scene_Clone_Selected(GlobalSceneGraph(), true);
1357 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1358 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1362 // called when the escape key is used (either on the main window or on an inspector)
1363 void Selection_Deselect()
1365 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1367 if(GlobalSelectionSystem().countSelectedComponents() != 0)
1369 GlobalSelectionSystem().setSelectedAllComponents(false);
1373 SelectionSystem_DefaultMode();
1374 ComponentModeChanged();
1379 if(GlobalSelectionSystem().countSelectedComponents() != 0)
1381 GlobalSelectionSystem().setSelectedAllComponents(false);
1385 GlobalSelectionSystem().setSelectedAll(false);
1391 void Selection_NudgeUp()
1393 UndoableCommand undo("nudgeSelectedUp");
1394 NudgeSelection(eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1397 void Selection_NudgeDown()
1399 UndoableCommand undo("nudgeSelectedDown");
1400 NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1403 void Selection_NudgeLeft()
1405 UndoableCommand undo("nudgeSelectedLeft");
1406 NudgeSelection(eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1409 void Selection_NudgeRight()
1411 UndoableCommand undo("nudgeSelectedRight");
1412 NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1416 void TranslateToolExport(const BoolImportCallback& importCallback)
1418 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate);
1421 void RotateToolExport(const BoolImportCallback& importCallback)
1423 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate);
1426 void ScaleToolExport(const BoolImportCallback& importCallback)
1428 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale);
1431 void DragToolExport(const BoolImportCallback& importCallback)
1433 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag);
1436 void ClipperToolExport(const BoolImportCallback& importCallback)
1438 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip);
1441 FreeCaller1<const BoolImportCallback&, TranslateToolExport> g_translatemode_button_caller;
1442 BoolExportCallback g_translatemode_button_callback(g_translatemode_button_caller);
1443 ToggleItem g_translatemode_button(g_translatemode_button_callback);
1445 FreeCaller1<const BoolImportCallback&, RotateToolExport> g_rotatemode_button_caller;
1446 BoolExportCallback g_rotatemode_button_callback(g_rotatemode_button_caller);
1447 ToggleItem g_rotatemode_button(g_rotatemode_button_callback);
1449 FreeCaller1<const BoolImportCallback&, ScaleToolExport> g_scalemode_button_caller;
1450 BoolExportCallback g_scalemode_button_callback(g_scalemode_button_caller);
1451 ToggleItem g_scalemode_button(g_scalemode_button_callback);
1453 FreeCaller1<const BoolImportCallback&, DragToolExport> g_dragmode_button_caller;
1454 BoolExportCallback g_dragmode_button_callback(g_dragmode_button_caller);
1455 ToggleItem g_dragmode_button(g_dragmode_button_callback);
1457 FreeCaller1<const BoolImportCallback&, ClipperToolExport> g_clipper_button_caller;
1458 BoolExportCallback g_clipper_button_callback(g_clipper_button_caller);
1459 ToggleItem g_clipper_button(g_clipper_button_callback);
1463 g_translatemode_button.update();
1464 g_rotatemode_button.update();
1465 g_scalemode_button.update();
1466 g_dragmode_button.update();
1467 g_clipper_button.update();
1470 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1474 if(g_currentToolMode == DragMode && g_defaultToolMode != DragMode)
1476 g_defaultToolMode();
1480 g_currentToolMode = DragMode;
1481 g_currentToolModeSupportsComponentEditing = true;
1485 Sys_Status(c_ResizeMode_status);
1486 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eDrag);
1493 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1495 void TranslateMode()
1497 if(g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode)
1499 g_defaultToolMode();
1503 g_currentToolMode = TranslateMode;
1504 g_currentToolModeSupportsComponentEditing = true;
1508 Sys_Status(c_TranslateMode_status);
1509 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eTranslate);
1515 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1519 if(g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode)
1521 g_defaultToolMode();
1525 g_currentToolMode = RotateMode;
1526 g_currentToolModeSupportsComponentEditing = true;
1530 Sys_Status(c_RotateMode_status);
1531 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eRotate);
1537 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1541 if(g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode)
1543 g_defaultToolMode();
1547 g_currentToolMode = ScaleMode;
1548 g_currentToolModeSupportsComponentEditing = true;
1552 Sys_Status(c_ScaleMode_status);
1553 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eScale);
1560 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1565 if(g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode)
1567 g_defaultToolMode();
1571 g_currentToolMode = ClipperMode;
1572 g_currentToolModeSupportsComponentEditing = false;
1574 SelectionSystem_DefaultMode();
1578 Sys_Status(c_ClipperMode_status);
1579 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eClip);
1586 void Texdef_Rotate(float angle)
1588 StringOutputStream command;
1589 command << "brushRotateTexture -angle " << angle;
1590 UndoableCommand undo(command.c_str());
1591 Select_RotateTexture(angle);
1594 void Texdef_RotateClockwise()
1596 Texdef_Rotate(static_cast<float>(fabs(g_si_globals.rotate)));
1599 void Texdef_RotateAntiClockwise()
1601 Texdef_Rotate(static_cast<float>(-fabs(g_si_globals.rotate)));
1604 void Texdef_Scale(float x, float y)
1606 StringOutputStream command;
1607 command << "brushScaleTexture -x " << x << " -y " << y;
1608 UndoableCommand undo(command.c_str());
1609 Select_ScaleTexture(x, y);
1612 void Texdef_ScaleUp()
1614 Texdef_Scale(0, g_si_globals.scale[1]);
1617 void Texdef_ScaleDown()
1619 Texdef_Scale(0, -g_si_globals.scale[1]);
1622 void Texdef_ScaleLeft()
1624 Texdef_Scale(-g_si_globals.scale[0],0);
1627 void Texdef_ScaleRight()
1629 Texdef_Scale(g_si_globals.scale[0],0);
1632 void Texdef_Shift(float x, float y)
1634 StringOutputStream command;
1635 command << "brushShiftTexture -x " << x << " -y " << y;
1636 UndoableCommand undo(command.c_str());
1637 Select_ShiftTexture(x, y);
1640 void Texdef_ShiftLeft()
1642 Texdef_Shift(-g_si_globals.shift[0], 0);
1645 void Texdef_ShiftRight()
1647 Texdef_Shift(g_si_globals.shift[0], 0);
1650 void Texdef_ShiftUp()
1652 Texdef_Shift(0, g_si_globals.shift[1]);
1655 void Texdef_ShiftDown()
1657 Texdef_Shift(0, -g_si_globals.shift[1]);
1662 class SnappableSnapToGridSelected : public scene::Graph::Walker
1666 SnappableSnapToGridSelected(float snap)
1670 bool pre(const scene::Path& path, scene::Instance& instance) const
1672 if(path.top().get().visible())
1674 Snappable* snappable = Node_getSnappable(path.top());
1676 && Instance_getSelectable(instance)->isSelected())
1678 snappable->snapto(m_snap);
1685 void Scene_SnapToGrid_Selected(scene::Graph& graph, float snap)
1687 graph.traverse(SnappableSnapToGridSelected(snap));
1690 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1694 ComponentSnappableSnapToGridSelected(float snap)
1698 bool pre(const scene::Path& path, scene::Instance& instance) const
1700 if(path.top().get().visible())
1702 ComponentSnappable* componentSnappable = Instance_getComponentSnappable(instance);
1703 if(componentSnappable != 0
1704 && Instance_getSelectable(instance)->isSelected())
1706 componentSnappable->snapComponents(m_snap);
1713 void Scene_SnapToGrid_Component_Selected(scene::Graph& graph, float snap)
1715 graph.traverse(ComponentSnappableSnapToGridSelected(snap));
1718 void Selection_SnapToGrid()
1720 StringOutputStream command;
1721 command << "snapSelected -grid " << GetGridSize();
1722 UndoableCommand undo(command.c_str());
1724 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1726 Scene_SnapToGrid_Component_Selected(GlobalSceneGraph(), GetGridSize());
1730 Scene_SnapToGrid_Selected(GlobalSceneGraph(), GetGridSize());
1735 static gint qe_every_second(gpointer data)
1737 GdkModifierType mask;
1739 gdk_window_get_pointer (0, 0, 0, &mask);
1741 if ((mask & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK)) == 0)
1749 guint s_qe_every_second_id = 0;
1751 void EverySecondTimer_enable()
1753 if(s_qe_every_second_id == 0)
1755 s_qe_every_second_id = gtk_timeout_add(1000, qe_every_second, 0);
1759 void EverySecondTimer_disable()
1761 if(s_qe_every_second_id != 0)
1763 gtk_timeout_remove(s_qe_every_second_id);
1764 s_qe_every_second_id = 0;
1768 gint window_realize_remove_decoration(GtkWidget* widget, gpointer data)
1770 gdk_window_set_decorations(widget->window, (GdkWMDecoration)(GDK_DECOR_ALL|GDK_DECOR_MENU|GDK_DECOR_MINIMIZE|GDK_DECOR_MAXIMIZE));
1777 GtkWindow* m_window;
1781 WaitDialog create_wait_dialog(const char* title, const char* text)
1785 dialog.m_window = create_floating_window(title, MainFrame_getWindow());
1786 gtk_window_set_resizable(dialog.m_window, FALSE);
1787 gtk_container_set_border_width(GTK_CONTAINER(dialog.m_window), 0);
1788 gtk_window_set_position(dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT);
1790 g_signal_connect(G_OBJECT(dialog.m_window), "realize", G_CALLBACK(window_realize_remove_decoration), 0);
1793 dialog.m_label = GTK_LABEL(gtk_label_new(text));
1794 gtk_misc_set_alignment(GTK_MISC(dialog.m_label), 0.0, 0.5);
1795 gtk_label_set_justify(dialog.m_label, GTK_JUSTIFY_LEFT);
1796 gtk_widget_show(GTK_WIDGET(dialog.m_label));
1797 gtk_widget_set_size_request(GTK_WIDGET(dialog.m_label), 200, -1);
1799 gtk_container_add(GTK_CONTAINER(dialog.m_window), GTK_WIDGET(dialog.m_label));
1806 clock_t g_lastRedrawTime = 0;
1807 const clock_t c_redrawInterval = clock_t(CLOCKS_PER_SEC / 10);
1809 bool redrawRequired()
1811 clock_t currentTime = std::clock();
1812 if(currentTime - g_lastRedrawTime >= c_redrawInterval)
1814 g_lastRedrawTime = currentTime;
1821 bool MainFrame_isActiveApp()
1823 //globalOutputStream() << "listing\n";
1824 GList* list = gtk_window_list_toplevels();
1825 for(GList* i = list; i != 0; i = g_list_next(i))
1827 //globalOutputStream() << "toplevel.. ";
1828 if(gtk_window_is_active(GTK_WINDOW(i->data)))
1830 //globalOutputStream() << "is active\n";
1833 //globalOutputStream() << "not active\n";
1838 typedef std::list<CopiedString> StringStack;
1839 StringStack g_wait_stack;
1842 bool ScreenUpdates_Enabled()
1844 return g_wait_stack.empty();
1847 void ScreenUpdates_process()
1849 if(redrawRequired() && GTK_WIDGET_VISIBLE(g_wait.m_window))
1856 void ScreenUpdates_Disable(const char* message, const char* title)
1858 if(g_wait_stack.empty())
1860 EverySecondTimer_disable();
1864 bool isActiveApp = MainFrame_isActiveApp();
1866 g_wait = create_wait_dialog(title, message);
1867 gtk_grab_add(GTK_WIDGET(g_wait.m_window));
1871 gtk_widget_show(GTK_WIDGET(g_wait.m_window));
1872 ScreenUpdates_process();
1875 else if(GTK_WIDGET_VISIBLE(g_wait.m_window))
1877 gtk_label_set_text(g_wait.m_label, message);
1878 ScreenUpdates_process();
1880 g_wait_stack.push_back(message);
1883 void ScreenUpdates_Enable()
1885 ASSERT_MESSAGE(!ScreenUpdates_Enabled(), "screen updates already enabled");
1886 g_wait_stack.pop_back();
1887 if(g_wait_stack.empty())
1889 EverySecondTimer_enable();
1890 //gtk_widget_set_sensitive(GTK_WIDGET(MainFrame_getWindow()), TRUE);
1892 gtk_grab_remove(GTK_WIDGET(g_wait.m_window));
1893 destroy_floating_window(g_wait.m_window);
1894 g_wait.m_window = 0;
1896 //gtk_window_present(MainFrame_getWindow());
1898 else if(GTK_WIDGET_VISIBLE(g_wait.m_window))
1900 gtk_label_set_text(g_wait.m_label, g_wait_stack.back().c_str());
1901 ScreenUpdates_process();
1907 void GlobalCamera_UpdateWindow()
1909 if(g_pParentWnd != 0)
1911 CamWnd_Update(*g_pParentWnd->GetCamWnd());
1915 void XY_UpdateWindow(MainFrame& mainframe)
1917 if(mainframe.GetXYWnd() != 0)
1919 XYWnd_Update(*mainframe.GetXYWnd());
1923 void XZ_UpdateWindow(MainFrame& mainframe)
1925 if(mainframe.GetXZWnd() != 0)
1927 XYWnd_Update(*mainframe.GetXZWnd());
1931 void YZ_UpdateWindow(MainFrame& mainframe)
1933 if(mainframe.GetYZWnd() != 0)
1935 XYWnd_Update(*mainframe.GetYZWnd());
1939 void XY_UpdateAllWindows(MainFrame& mainframe)
1941 XY_UpdateWindow(mainframe);
1942 XZ_UpdateWindow(mainframe);
1943 YZ_UpdateWindow(mainframe);
1946 void XY_UpdateAllWindows()
1948 if(g_pParentWnd != 0)
1950 XY_UpdateAllWindows(*g_pParentWnd);
1954 void UpdateAllWindows()
1956 GlobalCamera_UpdateWindow();
1957 XY_UpdateAllWindows();
1961 void ModeChangeNotify()
1963 SceneChangeNotify();
1966 void ClipperChangeNotify()
1968 GlobalCamera_UpdateWindow();
1969 XY_UpdateAllWindows();
1973 LatchedInt g_Layout_viewStyle(0, "Window Layout");
1974 LatchedBool g_Layout_enableDetachableMenus(true, "Detachable Menus");
1975 LatchedBool g_Layout_enablePatchToolbar(true, "Patch Toolbar");
1976 LatchedBool g_Layout_enablePluginToolbar(true, "Plugin Toolbar");
1980 GtkMenuItem* create_file_menu()
1983 GtkMenuItem* file_menu_item = new_sub_menu_item_with_mnemonic("_File");
1984 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(file_menu_item));
1985 if (g_Layout_enableDetachableMenus.m_value)
1986 menu_tearoff (menu);
1988 create_menu_item_with_mnemonic(menu, "_New Map", "NewMap");
1989 menu_separator(menu);
1992 //++timo temporary experimental stuff for sleep mode..
1993 create_menu_item_with_mnemonic(menu, "_Sleep", "Sleep");
1994 menu_separator(menu);
1998 create_menu_item_with_mnemonic(menu, "_Open...", "OpenMap");
2000 create_menu_item_with_mnemonic(menu, "_Import...", "ImportMap");
2001 create_menu_item_with_mnemonic(menu, "_Save", "SaveMap");
2002 create_menu_item_with_mnemonic(menu, "Save _as...", "SaveMapAs");
2003 create_menu_item_with_mnemonic(menu, "Save s_elected...", "SaveSelected");
2004 menu_separator(menu);
2005 create_menu_item_with_mnemonic(menu, "Save re_gion...", "SaveRegion");
2006 menu_separator(menu);
2007 create_menu_item_with_mnemonic(menu, "_Refresh models", "RefreshReferences");
2008 menu_separator(menu);
2009 create_menu_item_with_mnemonic(menu, "Pro_ject settings...", "ProjectSettings");
2010 menu_separator(menu);
2011 create_menu_item_with_mnemonic(menu, "_Pointfile...", "TogglePointfile");
2012 menu_separator(menu);
2013 MRU_constructMenu(menu);
2014 menu_separator(menu);
2015 create_menu_item_with_mnemonic(menu, "Check for NetRadiant update (web)", "CheckForUpdate"); // FIXME
2016 create_menu_item_with_mnemonic(menu, "E_xit", "Exit");
2018 return file_menu_item;
2021 GtkMenuItem* create_edit_menu()
2024 GtkMenuItem* edit_menu_item = new_sub_menu_item_with_mnemonic("_Edit");
2025 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(edit_menu_item));
2026 if (g_Layout_enableDetachableMenus.m_value)
2027 menu_tearoff (menu);
2028 create_menu_item_with_mnemonic(menu, "_Undo", "Undo");
2029 create_menu_item_with_mnemonic(menu, "_Redo", "Redo");
2030 menu_separator(menu);
2031 create_menu_item_with_mnemonic(menu, "_Copy", "Copy");
2032 create_menu_item_with_mnemonic(menu, "_Paste", "Paste");
2033 create_menu_item_with_mnemonic(menu, "P_aste To Camera", "PasteToCamera");
2034 menu_separator(menu);
2035 create_menu_item_with_mnemonic(menu, "_Duplicate", "CloneSelection");
2036 create_menu_item_with_mnemonic(menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique");
2037 create_menu_item_with_mnemonic(menu, "D_elete", "DeleteSelection");
2038 menu_separator(menu);
2039 create_menu_item_with_mnemonic(menu, "Pa_rent", "ParentSelection");
2040 menu_separator(menu);
2041 create_menu_item_with_mnemonic(menu, "C_lear Selection", "UnSelectSelection");
2042 create_menu_item_with_mnemonic(menu, "_Invert Selection", "InvertSelection");
2043 create_menu_item_with_mnemonic(menu, "Select i_nside", "SelectInside");
2044 create_menu_item_with_mnemonic(menu, "Select _touching", "SelectTouching");
2046 GtkMenu* convert_menu = create_sub_menu_with_mnemonic(menu, "E_xpand Selection");
2047 if (g_Layout_enableDetachableMenus.m_value)
2048 menu_tearoff (convert_menu);
2049 create_menu_item_with_mnemonic(convert_menu, "To Whole _Entities", "ExpandSelectionToEntities");
2051 menu_separator(menu);
2052 create_menu_item_with_mnemonic(menu, "Pre_ferences...", "Preferences");
2054 return edit_menu_item;
2057 void fill_view_xy_top_menu(GtkMenu* menu)
2059 create_check_menu_item_with_mnemonic(menu, "XY (Top) View", "ToggleView");
2063 void fill_view_yz_side_menu(GtkMenu* menu)
2065 create_check_menu_item_with_mnemonic(menu, "YZ (Side) View", "ToggleSideView");
2069 void fill_view_xz_front_menu(GtkMenu* menu)
2071 create_check_menu_item_with_mnemonic(menu, "XZ (Front) View", "ToggleFrontView");
2075 GtkWidget* g_toggle_z_item = 0;
2076 GtkWidget* g_toggle_console_item = 0;
2077 GtkWidget* g_toggle_entity_item = 0;
2078 GtkWidget* g_toggle_entitylist_item = 0;
2080 GtkMenuItem* create_view_menu(MainFrame::EViewStyle style)
2083 GtkMenuItem* view_menu_item = new_sub_menu_item_with_mnemonic("Vie_w");
2084 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(view_menu_item));
2085 if (g_Layout_enableDetachableMenus.m_value)
2086 menu_tearoff (menu);
2088 if(style == MainFrame::eFloating)
2090 fill_view_camera_menu(menu);
2091 fill_view_xy_top_menu(menu);
2092 fill_view_yz_side_menu(menu);
2093 fill_view_xz_front_menu(menu);
2095 if(style == MainFrame::eFloating || style == MainFrame::eSplit)
2097 create_menu_item_with_mnemonic(menu, "Console View", "ToggleConsole");
2098 create_menu_item_with_mnemonic(menu, "Texture Browser", "ToggleTextures");
2099 create_menu_item_with_mnemonic(menu, "Entity Inspector", "ToggleEntityInspector");
2103 create_menu_item_with_mnemonic(menu, "Entity Inspector", "ViewEntityInfo");
2105 create_menu_item_with_mnemonic(menu, "_Surface Inspector", "SurfaceInspector");
2106 create_menu_item_with_mnemonic(menu, "Entity List", "EntityList");
2108 menu_separator(menu);
2110 GtkMenu* camera_menu = create_sub_menu_with_mnemonic (menu, "Camera");
2111 if (g_Layout_enableDetachableMenus.m_value)
2112 menu_tearoff (camera_menu);
2113 create_menu_item_with_mnemonic(camera_menu, "_Center", "CenterView");
2114 create_menu_item_with_mnemonic(camera_menu, "_Up Floor", "UpFloor");
2115 create_menu_item_with_mnemonic(camera_menu, "_Down Floor", "DownFloor");
2116 menu_separator(camera_menu);
2117 create_menu_item_with_mnemonic(camera_menu, "Far Clip Plane In", "CubicClipZoomIn");
2118 create_menu_item_with_mnemonic(camera_menu, "Far Clip Plane Out", "CubicClipZoomOut");
2119 menu_separator(camera_menu);
2120 create_menu_item_with_mnemonic(camera_menu, "Next leak spot", "NextLeakSpot");
2121 create_menu_item_with_mnemonic(camera_menu, "Previous leak spot", "PrevLeakSpot");
2122 menu_separator(camera_menu);
2123 create_menu_item_with_mnemonic(camera_menu, "Look Through Selected", "LookThroughSelected");
2124 create_menu_item_with_mnemonic(camera_menu, "Look Through Camera", "LookThroughCamera");
2126 menu_separator(menu);
2128 GtkMenu* orthographic_menu = create_sub_menu_with_mnemonic(menu, "Orthographic");
2129 if (g_Layout_enableDetachableMenus.m_value)
2130 menu_tearoff (orthographic_menu);
2131 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating)
2133 create_menu_item_with_mnemonic(orthographic_menu, "_Next (XY, YZ, XY)", "NextView");
2134 create_menu_item_with_mnemonic(orthographic_menu, "XY (Top)", "ViewTop");
2135 create_menu_item_with_mnemonic(orthographic_menu, "YZ", "ViewSide");
2136 create_menu_item_with_mnemonic(orthographic_menu, "XZ", "ViewFront");
2137 menu_separator(orthographic_menu);
2140 create_menu_item_with_mnemonic(orthographic_menu, "_XY 100%", "Zoom100");
2141 create_menu_item_with_mnemonic(orthographic_menu, "XY Zoom _In", "ZoomIn");
2142 create_menu_item_with_mnemonic(orthographic_menu, "XY Zoom _Out", "ZoomOut");
2145 menu_separator(menu);
2148 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Show");
2149 if (g_Layout_enableDetachableMenus.m_value)
2150 menu_tearoff (menu_in_menu);
2151 create_check_menu_item_with_mnemonic(menu_in_menu, "Show _Angles", "ShowAngles");
2152 create_check_menu_item_with_mnemonic(menu_in_menu, "Show _Names", "ShowNames");
2153 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Blocks", "ShowBlocks");
2154 create_check_menu_item_with_mnemonic(menu_in_menu, "Show C_oordinates", "ShowCoordinates");
2155 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Window Outline", "ShowWindowOutline");
2156 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Axes", "ShowAxes");
2157 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Workzone", "ShowWorkzone");
2158 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Stats", "ShowStats");
2162 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Filter");
2163 if (g_Layout_enableDetachableMenus.m_value)
2164 menu_tearoff (menu_in_menu);
2165 Filters_constructMenu(menu_in_menu);
2167 menu_separator(menu);
2169 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Hide/Show");
2170 if (g_Layout_enableDetachableMenus.m_value)
2171 menu_tearoff (menu_in_menu);
2172 create_menu_item_with_mnemonic(menu_in_menu, "Hide Selected", "HideSelected");
2173 create_menu_item_with_mnemonic(menu_in_menu, "Show Hidden", "ShowHidden");
2175 menu_separator(menu);
2177 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Region");
2178 if (g_Layout_enableDetachableMenus.m_value)
2179 menu_tearoff (menu_in_menu);
2180 create_menu_item_with_mnemonic(menu_in_menu, "_Off", "RegionOff");
2181 create_menu_item_with_mnemonic(menu_in_menu, "_Set XY", "RegionSetXY");
2182 create_menu_item_with_mnemonic(menu_in_menu, "Set _Brush", "RegionSetBrush");
2183 create_menu_item_with_mnemonic(menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection");
2186 command_connect_accelerator("CenterXYView");
2188 return view_menu_item;
2191 GtkMenuItem* create_selection_menu()
2194 GtkMenuItem* selection_menu_item = new_sub_menu_item_with_mnemonic("M_odify");
2195 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(selection_menu_item));
2196 if (g_Layout_enableDetachableMenus.m_value)
2197 menu_tearoff (menu);
2200 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Components");
2201 if (g_Layout_enableDetachableMenus.m_value)
2202 menu_tearoff (menu_in_menu);
2203 create_check_menu_item_with_mnemonic(menu_in_menu, "_Edges", "DragEdges");
2204 create_check_menu_item_with_mnemonic(menu_in_menu, "_Vertices", "DragVertices");
2205 create_check_menu_item_with_mnemonic(menu_in_menu, "_Faces", "DragFaces");
2208 menu_separator(menu);
2211 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic(menu, "Nudge");
2212 if (g_Layout_enableDetachableMenus.m_value)
2213 menu_tearoff (menu_in_menu);
2214 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Left", "SelectNudgeLeft");
2215 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Right", "SelectNudgeRight");
2216 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Up", "SelectNudgeUp");
2217 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Down", "SelectNudgeDown");
2220 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Rotate");
2221 if (g_Layout_enableDetachableMenus.m_value)
2222 menu_tearoff (menu_in_menu);
2223 create_menu_item_with_mnemonic(menu_in_menu, "Rotate X", "RotateSelectionX");
2224 create_menu_item_with_mnemonic(menu_in_menu, "Rotate Y", "RotateSelectionY");
2225 create_menu_item_with_mnemonic(menu_in_menu, "Rotate Z", "RotateSelectionZ");
2228 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Flip");
2229 if (g_Layout_enableDetachableMenus.m_value)
2230 menu_tearoff (menu_in_menu);
2231 create_menu_item_with_mnemonic(menu_in_menu, "Flip _X", "MirrorSelectionX");
2232 create_menu_item_with_mnemonic(menu_in_menu, "Flip _Y", "MirrorSelectionY");
2233 create_menu_item_with_mnemonic(menu_in_menu, "Flip _Z", "MirrorSelectionZ");
2235 menu_separator(menu);
2236 create_menu_item_with_mnemonic(menu, "Arbitrary rotation...", "ArbitraryRotation");
2237 create_menu_item_with_mnemonic(menu, "Arbitrary scale...", "ArbitraryScale");
2239 return selection_menu_item;
2242 GtkMenuItem* create_bsp_menu()
2245 GtkMenuItem* bsp_menu_item = new_sub_menu_item_with_mnemonic("_Build");
2246 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(bsp_menu_item));
2248 if (g_Layout_enableDetachableMenus.m_value)
2253 create_menu_item_with_mnemonic(menu, "Customize...", "BuildMenuCustomize");
2255 menu_separator(menu);
2257 Build_constructMenu(menu);
2261 return bsp_menu_item;
2264 GtkMenuItem* create_grid_menu()
2267 GtkMenuItem* grid_menu_item = new_sub_menu_item_with_mnemonic("_Grid");
2268 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(grid_menu_item));
2269 if (g_Layout_enableDetachableMenus.m_value)
2270 menu_tearoff (menu);
2272 Grid_constructMenu(menu);
2274 return grid_menu_item;
2277 GtkMenuItem* create_misc_menu()
2280 GtkMenuItem* misc_menu_item = new_sub_menu_item_with_mnemonic("M_isc");
2281 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(misc_menu_item));
2282 if (g_Layout_enableDetachableMenus.m_value)
2283 menu_tearoff (menu);
2286 create_menu_item_with_mnemonic(menu, "_Benchmark", FreeCaller<GlobalCamera_Benchmark>());
2288 gtk_container_add(GTK_CONTAINER(menu), GTK_WIDGET(create_colours_menu()));
2290 create_menu_item_with_mnemonic(menu, "Find brush...", "FindBrush");
2291 create_menu_item_with_mnemonic(menu, "Map Info...", "MapInfo");
2292 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2293 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<WXY_Print>());
2294 create_menu_item_with_mnemonic(menu, "_Background select", FreeCaller<WXY_BackgroundSelect>());
2295 return misc_menu_item;
2298 GtkMenuItem* create_entity_menu()
2301 GtkMenuItem* entity_menu_item = new_sub_menu_item_with_mnemonic("E_ntity");
2302 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(entity_menu_item));
2303 if (g_Layout_enableDetachableMenus.m_value)
2304 menu_tearoff (menu);
2306 Entity_constructMenu(menu);
2308 return entity_menu_item;
2311 GtkMenuItem* create_brush_menu()
2314 GtkMenuItem* brush_menu_item = new_sub_menu_item_with_mnemonic("B_rush");
2315 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(brush_menu_item));
2316 if (g_Layout_enableDetachableMenus.m_value)
2317 menu_tearoff (menu);
2319 Brush_constructMenu(menu);
2321 return brush_menu_item;
2324 GtkMenuItem* create_patch_menu()
2327 GtkMenuItem* patch_menu_item = new_sub_menu_item_with_mnemonic("_Curve");
2328 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(patch_menu_item));
2329 if (g_Layout_enableDetachableMenus.m_value)
2334 Patch_constructMenu(menu);
2336 return patch_menu_item;
2339 GtkMenuItem* create_help_menu()
2342 GtkMenuItem* help_menu_item = new_sub_menu_item_with_mnemonic("_Help");
2343 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(help_menu_item));
2344 if (g_Layout_enableDetachableMenus.m_value)
2345 menu_tearoff (menu);
2347 create_menu_item_with_mnemonic(menu, "Manual", "OpenManual");
2349 // this creates all the per-game drop downs for the game pack helps
2350 // it will take care of hooking the Sys_OpenURL calls etc.
2351 create_game_help_menu(menu);
2353 create_menu_item_with_mnemonic(menu, "Bug report", FreeCaller<OpenBugReportURL>());
2354 create_menu_item_with_mnemonic(menu, "Shortcuts list", FreeCaller<DoCommandListDlg>());
2355 create_menu_item_with_mnemonic(menu, "_About", FreeCaller<DoAbout>());
2357 return help_menu_item;
2360 GtkMenuBar* create_main_menu(MainFrame::EViewStyle style)
2362 GtkMenuBar* menu_bar = GTK_MENU_BAR(gtk_menu_bar_new());
2363 gtk_widget_show(GTK_WIDGET(menu_bar));
2365 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_file_menu()));
2366 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_edit_menu()));
2367 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_view_menu(style)));
2368 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_selection_menu()));
2369 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_bsp_menu()));
2370 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_grid_menu()));
2371 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_misc_menu()));
2372 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_entity_menu()));
2373 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_brush_menu()));
2374 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_patch_menu()));
2375 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_plugins_menu()));
2376 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_help_menu()));
2382 void PatchInspector_registerShortcuts()
2384 command_connect_accelerator("PatchInspector");
2387 void Patch_registerShortcuts()
2389 command_connect_accelerator("InvertCurveTextureX");
2390 command_connect_accelerator("InvertCurveTextureY");
2391 command_connect_accelerator("IncPatchColumn");
2392 command_connect_accelerator("IncPatchRow");
2393 command_connect_accelerator("DecPatchColumn");
2394 command_connect_accelerator("DecPatchRow");
2395 command_connect_accelerator("NaturalizePatch");
2396 //command_connect_accelerator("CapCurrentCurve");
2399 void Manipulators_registerShortcuts()
2401 toggle_add_accelerator("MouseRotate");
2402 toggle_add_accelerator("MouseTranslate");
2403 toggle_add_accelerator("MouseScale");
2404 toggle_add_accelerator("MouseDrag");
2405 toggle_add_accelerator("ToggleClipper");
2408 void TexdefNudge_registerShortcuts()
2410 command_connect_accelerator("TexRotateClock");
2411 command_connect_accelerator("TexRotateCounter");
2412 command_connect_accelerator("TexScaleUp");
2413 command_connect_accelerator("TexScaleDown");
2414 command_connect_accelerator("TexScaleLeft");
2415 command_connect_accelerator("TexScaleRight");
2416 command_connect_accelerator("TexShiftUp");
2417 command_connect_accelerator("TexShiftDown");
2418 command_connect_accelerator("TexShiftLeft");
2419 command_connect_accelerator("TexShiftRight");
2422 void SelectNudge_registerShortcuts()
2424 command_connect_accelerator("MoveSelectionDOWN");
2425 command_connect_accelerator("MoveSelectionUP");
2426 //command_connect_accelerator("SelectNudgeLeft");
2427 //command_connect_accelerator("SelectNudgeRight");
2428 //command_connect_accelerator("SelectNudgeUp");
2429 //command_connect_accelerator("SelectNudgeDown");
2432 void SnapToGrid_registerShortcuts()
2434 command_connect_accelerator("SnapToGrid");
2437 void SelectByType_registerShortcuts()
2439 command_connect_accelerator("SelectAllOfType");
2442 void SurfaceInspector_registerShortcuts()
2444 command_connect_accelerator("FitTexture");
2448 void register_shortcuts()
2450 PatchInspector_registerShortcuts();
2451 Patch_registerShortcuts();
2452 Grid_registerShortcuts();
2453 XYWnd_registerShortcuts();
2454 CamWnd_registerShortcuts();
2455 Manipulators_registerShortcuts();
2456 SurfaceInspector_registerShortcuts();
2457 TexdefNudge_registerShortcuts();
2458 SelectNudge_registerShortcuts();
2459 SnapToGrid_registerShortcuts();
2460 SelectByType_registerShortcuts();
2463 void File_constructToolbar(GtkToolbar* toolbar)
2465 toolbar_append_button(toolbar, "Open an existing map (CTRL + O)", "file_open.bmp", "OpenMap");
2466 toolbar_append_button(toolbar, "Save the active map (CTRL + S)", "file_save.bmp", "SaveMap");
2469 void UndoRedo_constructToolbar(GtkToolbar* toolbar)
2471 toolbar_append_button(toolbar, "Undo (CTRL + Z)", "undo.bmp", "Undo");
2472 toolbar_append_button(toolbar, "Redo (CTRL + Y)", "redo.bmp", "Redo");
2475 void RotateFlip_constructToolbar(GtkToolbar* toolbar)
2477 toolbar_append_button(toolbar, "x-axis Flip", "brush_flipx.bmp", "MirrorSelectionX");
2478 toolbar_append_button(toolbar, "x-axis Rotate", "brush_rotatex.bmp", "RotateSelectionX");
2479 toolbar_append_button(toolbar, "y-axis Flip", "brush_flipy.bmp", "MirrorSelectionY");
2480 toolbar_append_button(toolbar, "y-axis Rotate", "brush_rotatey.bmp", "RotateSelectionY");
2481 toolbar_append_button(toolbar, "z-axis Flip", "brush_flipz.bmp", "MirrorSelectionZ");
2482 toolbar_append_button(toolbar, "z-axis Rotate", "brush_rotatez.bmp", "RotateSelectionZ");
2485 void Select_constructToolbar(GtkToolbar* toolbar)
2487 toolbar_append_button(toolbar, "Select touching", "selection_selecttouching.bmp", "SelectTouching");
2488 toolbar_append_button(toolbar, "Select inside", "selection_selectinside.bmp", "SelectInside");
2491 void CSG_constructToolbar(GtkToolbar* toolbar)
2493 toolbar_append_button(toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.bmp", "CSGSubtract");
2494 toolbar_append_button(toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.bmp", "CSGMerge");
2495 toolbar_append_button(toolbar, "Hollow", "selection_makehollow.bmp", "CSGHollow");
2498 void ComponentModes_constructToolbar(GtkToolbar* toolbar)
2500 toolbar_append_toggle_button(toolbar, "Select Vertices (V)", "modify_vertices.bmp", "DragVertices");
2501 toolbar_append_toggle_button(toolbar, "Select Edges (E)", "modify_edges.bmp", "DragEdges");
2502 toolbar_append_toggle_button(toolbar, "Select Faces (F)", "modify_faces.bmp", "DragFaces");
2505 void Clipper_constructToolbar(GtkToolbar* toolbar)
2508 toolbar_append_toggle_button(toolbar, "Clipper (X)", "view_clipper.bmp", "ToggleClipper");
2511 void XYWnd_constructToolbar(GtkToolbar* toolbar)
2513 toolbar_append_button(toolbar, "Change views", "view_change.bmp", "NextView");
2516 void Manipulators_constructToolbar(GtkToolbar* toolbar)
2518 toolbar_append_toggle_button(toolbar, "Translate (W)", "select_mousetranslate.bmp", "MouseTranslate");
2519 toolbar_append_toggle_button(toolbar, "Rotate (R)", "select_mouserotate.bmp", "MouseRotate");
2520 toolbar_append_toggle_button(toolbar, "Scale", "select_mousescale.bmp", "MouseScale");
2521 toolbar_append_toggle_button(toolbar, "Resize (Q)", "select_mouseresize.bmp", "MouseDrag");
2523 Clipper_constructToolbar(toolbar);
2526 GtkToolbar* create_main_toolbar(MainFrame::EViewStyle style)
2528 GtkToolbar* toolbar = GTK_TOOLBAR(gtk_toolbar_new());
2529 gtk_toolbar_set_orientation(toolbar, GTK_ORIENTATION_HORIZONTAL);
2530 gtk_toolbar_set_style(toolbar, GTK_TOOLBAR_ICONS);
2532 gtk_widget_show(GTK_WIDGET(toolbar));
2534 File_constructToolbar(toolbar);
2536 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2538 UndoRedo_constructToolbar(toolbar);
2540 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2542 RotateFlip_constructToolbar(toolbar);
2544 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2546 Select_constructToolbar(toolbar);
2548 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2550 CSG_constructToolbar(toolbar);
2552 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2554 ComponentModes_constructToolbar(toolbar);
2556 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating)
2558 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2560 XYWnd_constructToolbar(toolbar);
2563 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2565 CamWnd_constructToolbar(toolbar);
2567 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2569 Manipulators_constructToolbar(toolbar);
2571 if (g_Layout_enablePatchToolbar.m_value)
2573 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2575 Patch_constructToolbar(toolbar);
2578 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2580 toolbar_append_toggle_button(toolbar, "Texture Lock (SHIFT +T)", "texture_lock.bmp", "TogTexLock");
2582 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2584 GtkButton* g_view_entities_button = toolbar_append_button(toolbar, "Entities (N)", "entities.bmp", "ToggleEntityInspector");
2585 GtkButton* g_view_console_button = toolbar_append_button(toolbar, "Console (O)", "console.bmp", "ToggleConsole");
2586 GtkButton* g_view_textures_button = toolbar_append_button(toolbar, "Texture Browser (T)", "texture_browser.bmp", "ToggleTextures");
2587 // TODO: call light inspector
2588 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.bmp", "ToggleLightInspector");
2590 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2591 GtkButton* g_refresh_models_button = toolbar_append_button(toolbar, "Refresh Models", "refresh_models.bmp", "RefreshReferences");
2594 // disable the console and texture button in the regular layouts
2595 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft)
2597 gtk_widget_set_sensitive(GTK_WIDGET(g_view_console_button), FALSE);
2598 gtk_widget_set_sensitive(GTK_WIDGET(g_view_textures_button), FALSE);
2604 GtkWidget* create_main_statusbar(GtkWidget *pStatusLabel[c_count_status])
2606 GtkTable* table = GTK_TABLE(gtk_table_new(1, c_count_status, FALSE));
2607 gtk_widget_show(GTK_WIDGET(table));
2610 GtkLabel* label = GTK_LABEL(gtk_label_new ("Label"));
2611 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
2612 gtk_misc_set_padding(GTK_MISC(label), 4, 2);
2613 gtk_widget_show(GTK_WIDGET(label));
2614 gtk_table_attach_defaults(table, GTK_WIDGET(label), 0, 1, 0, 1);
2615 pStatusLabel[c_command_status] = GTK_WIDGET(label);
2618 for(int i = 1; i < c_count_status; ++i)
2620 GtkFrame* frame = GTK_FRAME(gtk_frame_new(0));
2621 gtk_widget_show(GTK_WIDGET(frame));
2622 gtk_table_attach_defaults(table, GTK_WIDGET(frame), i, i + 1, 0, 1);
2623 gtk_frame_set_shadow_type(frame, GTK_SHADOW_IN);
2625 GtkLabel* label = GTK_LABEL(gtk_label_new ("Label"));
2626 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END);
2627 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
2628 gtk_misc_set_padding(GTK_MISC(label), 4, 2);
2629 gtk_widget_show(GTK_WIDGET(label));
2630 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(label));
2631 pStatusLabel[i] = GTK_WIDGET(label);
2634 return GTK_WIDGET(table);
2640 WidgetFocusPrinter g_mainframeWidgetFocusPrinter("mainframe");
2642 class WindowFocusPrinter
2646 static gboolean frame_event(GtkWidget *widget, GdkEvent* event, WindowFocusPrinter* self)
2648 globalOutputStream() << self->m_name << " frame_event\n";
2651 static gboolean keys_changed(GtkWidget *widget, WindowFocusPrinter* self)
2653 globalOutputStream() << self->m_name << " keys_changed\n";
2656 static gboolean notify(GtkWindow* window, gpointer dummy, WindowFocusPrinter* self)
2658 if(gtk_window_is_active(window))
2660 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2664 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2669 WindowFocusPrinter(const char* name) : m_name(name)
2672 void connect(GtkWindow* toplevel_window)
2674 g_signal_connect(G_OBJECT(toplevel_window), "notify::has_toplevel_focus", G_CALLBACK(notify), this);
2675 g_signal_connect(G_OBJECT(toplevel_window), "notify::is_active", G_CALLBACK(notify), this);
2676 g_signal_connect(G_OBJECT(toplevel_window), "keys_changed", G_CALLBACK(keys_changed), this);
2677 g_signal_connect(G_OBJECT(toplevel_window), "frame_event", G_CALLBACK(frame_event), this);
2681 WindowFocusPrinter g_mainframeFocusPrinter("mainframe");
2685 class MainWindowActive
2687 static gboolean notify(GtkWindow* window, gpointer dummy, MainWindowActive* self)
2689 if(g_wait.m_window != 0 && gtk_window_is_active(window) && !GTK_WIDGET_VISIBLE(g_wait.m_window))
2691 gtk_widget_show(GTK_WIDGET(g_wait.m_window));
2697 void connect(GtkWindow* toplevel_window)
2699 g_signal_connect(G_OBJECT(toplevel_window), "notify::is-active", G_CALLBACK(notify), this);
2703 MainWindowActive g_MainWindowActive;
2705 SignalHandlerId XYWindowDestroyed_connect(const SignalHandler& handler)
2707 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst(handler);
2710 void XYWindowDestroyed_disconnect(SignalHandlerId id)
2712 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect(id);
2715 MouseEventHandlerId XYWindowMouseDown_connect(const MouseEventHandler& handler)
2717 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst(handler);
2720 void XYWindowMouseDown_disconnect(MouseEventHandlerId id)
2722 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect(id);
2725 // =============================================================================
2728 MainFrame* g_pParentWnd = 0;
2730 GtkWindow* MainFrame_getWindow()
2732 if(g_pParentWnd == 0)
2736 return g_pParentWnd->m_window;
2739 std::vector<GtkWidget*> g_floating_windows;
2741 MainFrame::MainFrame() : m_window(0), m_idleRedrawStatusText(RedrawStatusTextCaller(*this))
2750 for (int n = 0;n < c_count_status;n++)
2752 m_pStatusLabel[n] = 0;
2755 m_bSleeping = false;
2760 MainFrame::~MainFrame()
2764 gtk_widget_hide(GTK_WIDGET(m_window));
2768 for(std::vector<GtkWidget*>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i)
2770 gtk_widget_destroy(*i);
2773 gtk_widget_destroy(GTK_WIDGET(m_window));
2776 void MainFrame::SetActiveXY(XYWnd* p)
2779 m_pActiveXY->SetActive(false);
2784 m_pActiveXY->SetActive(true);
2788 void MainFrame::ReleaseContexts()
2792 m_pXYWnd->DestroyContext();
2794 m_pYZWnd->DestroyContext();
2796 m_pXZWnd->DestroyContext();
2798 m_pCamWnd->DestroyContext();
2800 m_pTexWnd->DestroyContext();
2802 m_pZWnd->DestroyContext();
2806 void MainFrame::CreateContexts()
2810 m_pCamWnd->CreateContext();
2812 m_pXYWnd->CreateContext();
2814 m_pYZWnd->CreateContext();
2816 m_pXZWnd->CreateContext();
2818 m_pTexWnd->CreateContext();
2820 m_pZWnd->CreateContext();
2828 void MainFrame::OnSleep()
2834 // useful when trying to debug crashes in the sleep code
2835 globalOutputStream() << "Going into sleep mode..\n";
2837 globalOutputStream() << "Dispatching sleep msg...";
2838 DispatchRadiantMsg (RADIANT_SLEEP);
2839 globalOutputStream() << "Done.\n";
2841 gtk_window_iconify(m_window);
2842 GlobalSelectionSystem().setSelectedAll(false);
2844 GlobalShaderCache().unrealise();
2846 GlobalOpenGL_debugAssertNoErrors();
2847 ScreenUpdates_Disable();
2850 globalOutputStream() << "Releasing contexts...";
2852 globalOutputStream() << "Done.\n";
2856 globalOutputStream() << "Waking up\n";
2858 gtk_window_deiconify(m_window);
2861 globalOutputStream() << "Creating contexts...";
2863 globalOutputStream() << "Done.\n";
2865 globalOutputStream() << "Making current on camera...";
2866 m_pCamWnd->MakeCurrent();
2867 globalOutputStream() << "Done.\n";
2869 globalOutputStream() << "Reloading shaders...";
2871 GlobalShaderCache().realise();
2872 globalOutputStream() << "Done.\n";
2874 ScreenUpdates_Enable();
2876 globalOutputStream() << "Dispatching wake msg...";
2877 DispatchRadiantMsg (RADIANT_WAKEUP);
2878 globalOutputStream() << "Done\n";
2884 GtkWindow* create_splash()
2886 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
2887 gtk_window_set_decorated(window, FALSE);
2888 gtk_window_set_resizable(window, FALSE);
2889 gtk_window_set_modal(window, TRUE);
2890 gtk_window_set_default_size(window, -1, -1);
2891 gtk_window_set_position(window, GTK_WIN_POS_CENTER);
2892 gtk_container_set_border_width(GTK_CONTAINER(window), 0);
2894 GtkImage* image = new_local_image("splash.bmp");
2895 gtk_widget_show(GTK_WIDGET(image));
2896 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(image));
2898 gtk_widget_set_size_request(GTK_WIDGET(window), -1, -1);
2899 gtk_widget_show(GTK_WIDGET(window));
2904 static GtkWindow *splash_screen = 0;
2908 splash_screen = create_splash();
2915 gtk_widget_destroy(GTK_WIDGET(splash_screen));
2918 WindowPositionTracker g_posCamWnd;
2919 WindowPositionTracker g_posXYWnd;
2920 WindowPositionTracker g_posXZWnd;
2921 WindowPositionTracker g_posYZWnd;
2923 static gint mainframe_delete (GtkWidget *widget, GdkEvent *event, gpointer data)
2925 if(ConfirmModified("Exit Radiant"))
2933 void MainFrame::Create()
2935 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
2937 GlobalWindowObservers_connectTopLevel(window);
2939 gtk_window_set_transient_for(splash_screen, window);
2943 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask("bitmaps/icon.bmp");
2946 gtk_window_set_icon(window, pixbuf);
2947 gdk_pixbuf_unref(pixbuf);
2952 gtk_widget_add_events(GTK_WIDGET(window), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK);
2953 g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(mainframe_delete), this);
2955 m_position_tracker.connect(window);
2958 g_mainframeWidgetFocusPrinter.connect(window);
2959 g_mainframeFocusPrinter.connect(window);
2962 g_MainWindowActive.connect(window);
2964 GetPlugInMgr().Init(GTK_WIDGET(window));
2966 GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
2967 gtk_container_add(GTK_CONTAINER(window), vbox);
2968 gtk_widget_show(vbox);
2970 global_accel_connect_window(window);
2972 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
2974 register_shortcuts();
2976 GtkMenuBar* main_menu = create_main_menu(CurrentStyle());
2977 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(main_menu), FALSE, FALSE, 0);
2979 GtkToolbar* main_toolbar = create_main_toolbar(CurrentStyle());
2980 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(main_toolbar), FALSE, FALSE, 0);
2982 GtkToolbar* plugin_toolbar = create_plugin_toolbar();
2983 if (!g_Layout_enablePluginToolbar.m_value)
2985 gtk_widget_hide(GTK_WIDGET(plugin_toolbar));
2987 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(plugin_toolbar), FALSE, FALSE, 0);
2989 GtkWidget* main_statusbar = create_main_statusbar(m_pStatusLabel);
2990 gtk_box_pack_end(GTK_BOX(vbox), main_statusbar, FALSE, TRUE, 2);
2992 GroupDialog_constructWindow(window);
2993 g_page_entity = GroupDialog_addPage("Entities", EntityInspector_constructWindow(GroupDialog_getWindow()), RawStringExportCaller("Entities"));
2995 if(FloatingGroupDialog())
2997 g_page_console = GroupDialog_addPage("Console", Console_constructWindow(GroupDialog_getWindow()), RawStringExportCaller("Console"));
3001 if( g_multimon_globals.m_bStartOnPrimMon )
3003 PositionWindowOnPrimaryScreen(g_layout_globals.m_position);
3004 window_set_position(window, g_layout_globals.m_position);
3008 if(g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED)
3010 gtk_window_maximize(window);
3011 WindowPosition default_position(-1, -1, 640, 480);
3012 window_set_position(window, default_position);
3016 window_set_position(window, g_layout_globals.m_position);
3021 gtk_widget_show(GTK_WIDGET(window));
3023 if (CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft)
3026 GtkWidget* vsplit = gtk_vpaned_new();
3028 gtk_box_pack_start(GTK_BOX(vbox), vsplit, TRUE, TRUE, 0);
3029 gtk_widget_show (vsplit);
3032 GtkWidget* console_window = Console_constructWindow(window);
3033 gtk_paned_pack2(GTK_PANED(vsplit), console_window, FALSE, TRUE);
3036 GtkWidget* hsplit = gtk_hpaned_new();
3037 gtk_widget_show (hsplit);
3039 gtk_paned_add1(GTK_PANED(vsplit), hsplit);
3042 m_pXYWnd = new XYWnd();
3043 m_pXYWnd->SetViewType(XY);
3044 GtkWidget* xy_window = GTK_WIDGET(create_framed_widget(m_pXYWnd->GetWidget()));
3047 GtkWidget* vsplit2 = gtk_vpaned_new();
3048 gtk_widget_show(vsplit2);
3049 m_vSplit2 = vsplit2;
3051 if (CurrentStyle() == eRegular)
3053 gtk_paned_add1(GTK_PANED(hsplit), xy_window);
3054 gtk_paned_add2(GTK_PANED(hsplit), vsplit2);
3058 gtk_paned_add1(GTK_PANED(hsplit), vsplit2);
3059 gtk_paned_add2(GTK_PANED(hsplit), xy_window);
3064 m_pCamWnd = NewCamWnd();
3065 GlobalCamera_setCamWnd(*m_pCamWnd);
3066 CamWnd_setParent(*m_pCamWnd, window);
3067 GtkFrame* camera_window = create_framed_widget(CamWnd_getWidget(*m_pCamWnd));
3069 gtk_paned_add1(GTK_PANED(vsplit2), GTK_WIDGET(camera_window));
3072 GtkFrame* texture_window = create_framed_widget(TextureBrowser_constructWindow(window));
3074 gtk_paned_add2(GTK_PANED(vsplit2), GTK_WIDGET(texture_window));
3079 gtk_paned_set_position(GTK_PANED(m_vSplit), g_layout_globals.nXYHeight);
3081 if (CurrentStyle() == eRegular)
3083 gtk_paned_set_position(GTK_PANED(m_hSplit), g_layout_globals.nXYWidth);
3087 gtk_paned_set_position(GTK_PANED(m_hSplit), g_layout_globals.nCamWidth);
3090 gtk_paned_set_position(GTK_PANED(m_vSplit2), g_layout_globals.nCamHeight);
3092 else if (CurrentStyle() == eFloating)
3095 GtkWindow* window = create_persistent_floating_window("Camera", m_window);
3096 global_accel_connect_window(window);
3097 g_posCamWnd.connect(window);
3099 gtk_widget_show(GTK_WIDGET(window));
3101 m_pCamWnd = NewCamWnd();
3102 GlobalCamera_setCamWnd(*m_pCamWnd);
3105 GtkFrame* frame = create_framed_widget(CamWnd_getWidget(*m_pCamWnd));
3106 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3108 CamWnd_setParent(*m_pCamWnd, window);
3110 g_floating_windows.push_back(GTK_WIDGET(window));
3114 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(XY), m_window);
3115 global_accel_connect_window(window);
3116 g_posXYWnd.connect(window);
3118 m_pXYWnd = new XYWnd();
3119 m_pXYWnd->m_parent = window;
3120 m_pXYWnd->SetViewType(XY);
3124 GtkFrame* frame = create_framed_widget(m_pXYWnd->GetWidget());
3125 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3127 XY_Top_Shown_Construct(window);
3129 g_floating_windows.push_back(GTK_WIDGET(window));
3133 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(XZ), m_window);
3134 global_accel_connect_window(window);
3135 g_posXZWnd.connect(window);
3137 m_pXZWnd = new XYWnd();
3138 m_pXZWnd->m_parent = window;
3139 m_pXZWnd->SetViewType(XZ);
3142 GtkFrame* frame = create_framed_widget(m_pXZWnd->GetWidget());
3143 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3146 XZ_Front_Shown_Construct(window);
3148 g_floating_windows.push_back(GTK_WIDGET(window));
3152 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(YZ), m_window);
3153 global_accel_connect_window(window);
3154 g_posYZWnd.connect(window);
3156 m_pYZWnd = new XYWnd();
3157 m_pYZWnd->m_parent = window;
3158 m_pYZWnd->SetViewType(YZ);
3161 GtkFrame* frame = create_framed_widget(m_pYZWnd->GetWidget());
3162 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3165 YZ_Side_Shown_Construct(window);
3167 g_floating_windows.push_back(GTK_WIDGET(window));
3171 GtkFrame* frame = create_framed_widget(TextureBrowser_constructWindow(GroupDialog_getWindow()));
3172 g_page_textures = GroupDialog_addPage("Textures", GTK_WIDGET(frame), TextureBrowserExportTitleCaller());
3179 m_pCamWnd = NewCamWnd();
3180 GlobalCamera_setCamWnd(*m_pCamWnd);
3181 CamWnd_setParent(*m_pCamWnd, window);
3183 GtkWidget* camera = CamWnd_getWidget(*m_pCamWnd);
3185 m_pYZWnd = new XYWnd();
3186 m_pYZWnd->SetViewType(YZ);
3188 GtkWidget* yz = m_pYZWnd->GetWidget();
3190 m_pXYWnd = new XYWnd();
3191 m_pXYWnd->SetViewType(XY);
3193 GtkWidget* xy = m_pXYWnd->GetWidget();
3195 m_pXZWnd = new XYWnd();
3196 m_pXZWnd->SetViewType(XZ);
3198 GtkWidget* xz = m_pXZWnd->GetWidget();
3200 GtkHPaned* split = create_split_views(camera, yz, xy, xz);
3201 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(split), TRUE, TRUE, 0);
3204 GtkFrame* frame = create_framed_widget(TextureBrowser_constructWindow(window));
3205 g_page_textures = GroupDialog_addPage("Textures", GTK_WIDGET(frame), TextureBrowserExportTitleCaller());
3209 EntityList_constructWindow(window);
3210 PreferencesDialog_constructWindow(window);
3211 FindTextureDialog_constructWindow(window);
3212 SurfaceInspector_constructWindow(window);
3213 PatchInspector_constructWindow(window);
3215 SetActiveXY(m_pXYWnd);
3217 AddGridChangeCallback(SetGridStatusCaller(*this));
3218 AddGridChangeCallback(ReferenceCaller<MainFrame, XY_UpdateAllWindows>(*this));
3220 g_defaultToolMode = DragMode;
3221 g_defaultToolMode();
3222 SetStatusText(m_command_status, c_TranslateMode_status);
3224 EverySecondTimer_enable();
3226 //GlobalShortcuts_reportUnregistered();
3229 void MainFrame::SaveWindowInfo()
3231 if (!FloatingGroupDialog())
3233 g_layout_globals.nXYHeight = gtk_paned_get_position(GTK_PANED(m_vSplit));
3235 if(CurrentStyle() != eRegular)
3237 g_layout_globals.nCamWidth = gtk_paned_get_position(GTK_PANED(m_hSplit));
3241 g_layout_globals.nXYWidth = gtk_paned_get_position(GTK_PANED(m_hSplit));
3244 g_layout_globals.nCamHeight = gtk_paned_get_position(GTK_PANED(m_vSplit2));
3247 g_layout_globals.m_position = m_position_tracker.getPosition();
3249 g_layout_globals.nState = gdk_window_get_state(GTK_WIDGET(m_window)->window);
3252 void MainFrame::Shutdown()
3254 EverySecondTimer_disable();
3256 EntityList_destroyWindow();
3265 TextureBrowser_destroyWindow();
3267 DeleteCamWnd(m_pCamWnd);
3270 PreferencesDialog_destroyWindow();
3271 SurfaceInspector_destroyWindow();
3272 FindTextureDialog_destroyWindow();
3273 PatchInspector_destroyWindow();
3275 g_DbgDlg.destroyWindow();
3277 // destroying group-dialog last because it may contain texture-browser
3278 GroupDialog_destroyWindow();
3281 void MainFrame::RedrawStatusText()
3283 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_command_status]), m_command_status.c_str());
3284 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_position_status]), m_position_status.c_str());
3285 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_brushcount_status]), m_brushcount_status.c_str());
3286 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_texture_status]), m_texture_status.c_str());
3287 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_grid_status]), m_grid_status.c_str());
3290 void MainFrame::UpdateStatusText()
3292 m_idleRedrawStatusText.queueDraw();
3295 void MainFrame::SetStatusText(CopiedString& status_text, const char* pText)
3297 status_text = pText;
3301 void Sys_Status(const char* status)
3303 if(g_pParentWnd != 0)
3305 g_pParentWnd->SetStatusText (g_pParentWnd->m_command_status, status);
3309 int getRotateIncrement()
3311 return static_cast<int>(g_si_globals.rotate);
3314 int getFarClipDistance()
3316 return g_camwindow_globals.m_nCubicScale;
3319 float (*GridStatus_getGridSize)() = GetGridSize;
3320 int (*GridStatus_getRotateIncrement)() = getRotateIncrement;
3321 int (*GridStatus_getFarClipDistance)() = getFarClipDistance;
3322 bool (*GridStatus_getTextureLockEnabled)();
3324 void MainFrame::SetGridStatus()
3326 StringOutputStream status(64);
3327 const char* lock = (GridStatus_getTextureLockEnabled()) ? "ON" : "OFF";
3328 status << (GetSnapGridSize() > 0 ? "G:" : "g:") << GridStatus_getGridSize()
3329 << " R:" << GridStatus_getRotateIncrement()
3330 << " C:" << GridStatus_getFarClipDistance()
3332 SetStatusText(m_grid_status, status.c_str());
3335 void GridStatus_onTextureLockEnabledChanged()
3337 if(g_pParentWnd != 0)
3339 g_pParentWnd->SetGridStatus();
3343 void GlobalGL_sharedContextCreated()
3345 GLFont *g_font = NULL;
3347 // report OpenGL information
3348 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>(glGetString (GL_VENDOR)) << "\n";
3349 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>(glGetString (GL_RENDERER)) << "\n";
3350 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>(glGetString (GL_VERSION)) << "\n";
3351 globalOutputStream() << "GL_EXTENSIONS: " << reinterpret_cast<const char*>(glGetString (GL_EXTENSIONS)) << "\n";
3353 QGL_sharedContextCreated(GlobalOpenGL());
3355 ShaderCache_extensionsInitialised();
3357 GlobalShaderCache().realise();
3361 /* win32 is dodgy here, just use courier new then */
3362 g_font = glfont_create("arial 9");
3364 GtkSettings *settings = gtk_settings_get_default();
3366 g_object_get(settings, "gtk-font-name", &fontname, NULL);
3367 g_font = glfont_create(fontname);
3370 GlobalOpenGL().m_font = g_font;
3373 void GlobalGL_sharedContextDestroyed()
3375 Textures_Unrealise();
3376 GlobalShaderCache().unrealise();
3378 QGL_sharedContextDestroyed(GlobalOpenGL());
3382 void Layout_constructPreferences(PreferencesPage& page)
3385 const char* layouts[] = { "window1.bmp", "window2.bmp", "window3.bmp", "window4.bmp" };
3386 page.appendRadioIcons(
3388 STRING_ARRAY_RANGE(layouts),
3389 LatchedIntImportCaller(g_Layout_viewStyle),
3390 IntExportCaller(g_Layout_viewStyle.m_latched)
3393 page.appendCheckBox(
3394 "", "Detachable Menus",
3395 LatchedBoolImportCaller(g_Layout_enableDetachableMenus),
3396 BoolExportCaller(g_Layout_enableDetachableMenus.m_latched)
3398 if (!string_empty(g_pGameDescription->getKeyValue("no_patch")))
3400 page.appendCheckBox(
3401 "", "Patch Toolbar",
3402 LatchedBoolImportCaller(g_Layout_enablePatchToolbar),
3403 BoolExportCaller(g_Layout_enablePatchToolbar.m_latched)
3406 page.appendCheckBox(
3407 "", "Plugin Toolbar",
3408 LatchedBoolImportCaller(g_Layout_enablePluginToolbar),
3409 BoolExportCaller(g_Layout_enablePluginToolbar.m_latched)
3413 void Layout_constructPage(PreferenceGroup& group)
3415 PreferencesPage page(group.createPage("Layout", "Layout Preferences"));
3416 Layout_constructPreferences(page);
3419 void Layout_registerPreferencesPage()
3421 PreferencesDialog_addInterfacePage(FreeCaller1<PreferenceGroup&, Layout_constructPage>());
3425 #include "preferencesystem.h"
3426 #include "stringio.h"
3428 void MainFrame_Construct()
3430 GlobalCommands_insert("OpenManual", FreeCaller<OpenHelpURL>(), Accelerator(GDK_F1));
3432 GlobalCommands_insert("Sleep", FreeCaller<thunk_OnSleep>(), Accelerator('P', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
3433 GlobalCommands_insert("NewMap", FreeCaller<NewMap>());
3434 GlobalCommands_insert("OpenMap", FreeCaller<OpenMap>(), Accelerator('O', (GdkModifierType)GDK_CONTROL_MASK));
3435 GlobalCommands_insert("ImportMap", FreeCaller<ImportMap>());
3436 GlobalCommands_insert("SaveMap", FreeCaller<SaveMap>(), Accelerator('S', (GdkModifierType)GDK_CONTROL_MASK));
3437 GlobalCommands_insert("SaveMapAs", FreeCaller<SaveMapAs>());
3438 GlobalCommands_insert("SaveSelected", FreeCaller<ExportMap>());
3439 GlobalCommands_insert("SaveRegion", FreeCaller<SaveRegion>());
3440 GlobalCommands_insert("RefreshReferences", FreeCaller<RefreshReferences>());
3441 GlobalCommands_insert("ProjectSettings", FreeCaller<DoProjectSettings>());
3442 GlobalCommands_insert("CheckForUpdate", FreeCaller<OpenUpdateURL>());
3443 GlobalCommands_insert("Exit", FreeCaller<Exit>());
3445 GlobalCommands_insert("Undo", FreeCaller<Undo>(), Accelerator('Z', (GdkModifierType)GDK_CONTROL_MASK));
3446 GlobalCommands_insert("Redo", FreeCaller<Redo>(), Accelerator('Y', (GdkModifierType)GDK_CONTROL_MASK));
3447 GlobalCommands_insert("Copy", FreeCaller<Copy>(), Accelerator('C', (GdkModifierType)GDK_CONTROL_MASK));
3448 GlobalCommands_insert("Paste", FreeCaller<Paste>(), Accelerator('V', (GdkModifierType)GDK_CONTROL_MASK));
3449 GlobalCommands_insert("PasteToCamera", FreeCaller<PasteToCamera>(), Accelerator('V', (GdkModifierType)GDK_MOD1_MASK));
3450 GlobalCommands_insert("CloneSelection", FreeCaller<Selection_Clone>(), Accelerator(GDK_space));
3451 GlobalCommands_insert("CloneSelectionAndMakeUnique", FreeCaller<Selection_Clone_MakeUnique>(), Accelerator(GDK_space, (GdkModifierType)GDK_SHIFT_MASK));
3452 GlobalCommands_insert("DeleteSelection", FreeCaller<deleteSelection>(), Accelerator(GDK_BackSpace));
3453 GlobalCommands_insert("ParentSelection", FreeCaller<Scene_parentSelected>());
3454 GlobalCommands_insert("UnSelectSelection", FreeCaller<Selection_Deselect>(), Accelerator(GDK_Escape));
3455 GlobalCommands_insert("InvertSelection", FreeCaller<Select_Invert>(), Accelerator('I'));
3456 GlobalCommands_insert("SelectInside", FreeCaller<Select_Inside>());
3457 GlobalCommands_insert("SelectTouching", FreeCaller<Select_Touching>());
3458 GlobalCommands_insert("ExpandSelectionToEntities", FreeCaller<Scene_ExpandSelectionToEntities>(), Accelerator('E', (GdkModifierType)(GDK_MOD1_MASK|GDK_CONTROL_MASK)));
3459 GlobalCommands_insert("Preferences", FreeCaller<PreferencesDialog_showDialog>(), Accelerator('P'));
3461 GlobalCommands_insert("ToggleConsole", FreeCaller<Console_ToggleShow>(), Accelerator('O'));
3462 GlobalCommands_insert("ToggleEntityInspector", FreeCaller<EntityInspector_ToggleShow>(), Accelerator('N'));
3463 GlobalCommands_insert("EntityList", FreeCaller<EntityList_toggleShown>(), Accelerator('L'));
3465 GlobalCommands_insert("ShowHidden", FreeCaller<Select_ShowAllHidden>(), Accelerator('H', (GdkModifierType)GDK_SHIFT_MASK));
3466 GlobalCommands_insert("HideSelected", FreeCaller<HideSelected>(), Accelerator('H'));
3468 GlobalToggles_insert("DragVertices", FreeCaller<SelectVertexMode>(), ToggleItem::AddCallbackCaller(g_vertexMode_button), Accelerator('V'));
3469 GlobalToggles_insert("DragEdges", FreeCaller<SelectEdgeMode>(), ToggleItem::AddCallbackCaller(g_edgeMode_button), Accelerator('E'));
3470 GlobalToggles_insert("DragFaces", FreeCaller<SelectFaceMode>(), ToggleItem::AddCallbackCaller(g_faceMode_button), Accelerator('F'));
3472 GlobalCommands_insert("MirrorSelectionX", FreeCaller<Selection_Flipx>());
3473 GlobalCommands_insert("RotateSelectionX", FreeCaller<Selection_Rotatex>());
3474 GlobalCommands_insert("MirrorSelectionY", FreeCaller<Selection_Flipy>());
3475 GlobalCommands_insert("RotateSelectionY", FreeCaller<Selection_Rotatey>());
3476 GlobalCommands_insert("MirrorSelectionZ", FreeCaller<Selection_Flipz>());
3477 GlobalCommands_insert("RotateSelectionZ", FreeCaller<Selection_Rotatez>());
3479 GlobalCommands_insert("ArbitraryRotation", FreeCaller<DoRotateDlg>());
3480 GlobalCommands_insert("ArbitraryScale", FreeCaller<DoScaleDlg>());
3482 GlobalCommands_insert("BuildMenuCustomize", FreeCaller<DoBuildMenu>());
3484 GlobalCommands_insert("FindBrush", FreeCaller<DoFind>());
3486 GlobalCommands_insert("MapInfo", FreeCaller<DoMapInfo>(), Accelerator('M'));
3489 GlobalToggles_insert("ToggleClipper", FreeCaller<ClipperMode>(), ToggleItem::AddCallbackCaller(g_clipper_button), Accelerator('X'));
3491 GlobalToggles_insert("MouseTranslate", FreeCaller<TranslateMode>(), ToggleItem::AddCallbackCaller(g_translatemode_button), Accelerator('W'));
3492 GlobalToggles_insert("MouseRotate", FreeCaller<RotateMode>(), ToggleItem::AddCallbackCaller(g_rotatemode_button), Accelerator('R'));
3493 GlobalToggles_insert("MouseScale", FreeCaller<ScaleMode>(), ToggleItem::AddCallbackCaller(g_scalemode_button));
3494 GlobalToggles_insert("MouseDrag", FreeCaller<DragMode>(), ToggleItem::AddCallbackCaller(g_dragmode_button), Accelerator('Q'));
3496 GlobalCommands_insert("ColorSchemeOriginal", FreeCaller<ColorScheme_Original>());
3497 GlobalCommands_insert("ColorSchemeQER", FreeCaller<ColorScheme_QER>());
3498 GlobalCommands_insert("ColorSchemeBlackAndGreen", FreeCaller<ColorScheme_Black>());
3499 GlobalCommands_insert("ColorSchemeYdnar", FreeCaller<ColorScheme_Ydnar>());
3500 GlobalCommands_insert("ChooseTextureBackgroundColor", makeCallback(g_ColoursMenu.m_textureback));
3501 GlobalCommands_insert("ChooseGridBackgroundColor", makeCallback(g_ColoursMenu.m_xyback));
3502 GlobalCommands_insert("ChooseGridMajorColor", makeCallback(g_ColoursMenu.m_gridmajor));
3503 GlobalCommands_insert("ChooseGridMinorColor", makeCallback(g_ColoursMenu.m_gridminor));
3504 GlobalCommands_insert("ChooseSmallGridMajorColor", makeCallback(g_ColoursMenu.m_gridmajor_alt));
3505 GlobalCommands_insert("ChooseSmallGridMinorColor", makeCallback(g_ColoursMenu.m_gridminor_alt));
3506 GlobalCommands_insert("ChooseGridTextColor", makeCallback(g_ColoursMenu.m_gridtext));
3507 GlobalCommands_insert("ChooseGridBlockColor", makeCallback(g_ColoursMenu.m_gridblock));
3508 GlobalCommands_insert("ChooseBrushColor", makeCallback(g_ColoursMenu.m_brush));
3509 GlobalCommands_insert("ChooseCameraBackgroundColor", makeCallback(g_ColoursMenu.m_cameraback));
3510 GlobalCommands_insert("ChooseSelectedBrushColor", makeCallback(g_ColoursMenu.m_selectedbrush));
3511 GlobalCommands_insert("ChooseCameraSelectedBrushColor", makeCallback(g_ColoursMenu.m_selectedbrush3d));
3512 GlobalCommands_insert("ChooseClipperColor", makeCallback(g_ColoursMenu.m_clipper));
3513 GlobalCommands_insert("ChooseOrthoViewNameColor", makeCallback(g_ColoursMenu.m_viewname));
3516 GlobalCommands_insert("CSGSubtract", FreeCaller<CSG_Subtract>(), Accelerator('U', (GdkModifierType)GDK_SHIFT_MASK));
3517 GlobalCommands_insert("CSGMerge", FreeCaller<CSG_Merge>(), Accelerator('U', (GdkModifierType)GDK_CONTROL_MASK));
3518 GlobalCommands_insert("CSGHollow", FreeCaller<CSG_MakeHollow>());
3520 Grid_registerCommands();
3522 GlobalCommands_insert("SnapToGrid", FreeCaller<Selection_SnapToGrid>(), Accelerator('G', (GdkModifierType)GDK_CONTROL_MASK));
3524 GlobalCommands_insert("SelectAllOfType", FreeCaller<Select_AllOfType>(), Accelerator('A', (GdkModifierType)GDK_SHIFT_MASK));
3526 GlobalCommands_insert("TexRotateClock", FreeCaller<Texdef_RotateClockwise>(), Accelerator(GDK_Next, (GdkModifierType)GDK_SHIFT_MASK));
3527 GlobalCommands_insert("TexRotateCounter", FreeCaller<Texdef_RotateAntiClockwise>(), Accelerator(GDK_Prior, (GdkModifierType)GDK_SHIFT_MASK));
3528 GlobalCommands_insert("TexScaleUp", FreeCaller<Texdef_ScaleUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_CONTROL_MASK));
3529 GlobalCommands_insert("TexScaleDown", FreeCaller<Texdef_ScaleDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_CONTROL_MASK));
3530 GlobalCommands_insert("TexScaleLeft", FreeCaller<Texdef_ScaleLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_CONTROL_MASK));
3531 GlobalCommands_insert("TexScaleRight", FreeCaller<Texdef_ScaleRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_CONTROL_MASK));
3532 GlobalCommands_insert("TexShiftUp", FreeCaller<Texdef_ShiftUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_SHIFT_MASK));
3533 GlobalCommands_insert("TexShiftDown", FreeCaller<Texdef_ShiftDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_SHIFT_MASK));
3534 GlobalCommands_insert("TexShiftLeft", FreeCaller<Texdef_ShiftLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_SHIFT_MASK));
3535 GlobalCommands_insert("TexShiftRight", FreeCaller<Texdef_ShiftRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_SHIFT_MASK));
3537 GlobalCommands_insert("MoveSelectionDOWN", FreeCaller<Selection_MoveDown>(), Accelerator(GDK_KP_Subtract));
3538 GlobalCommands_insert("MoveSelectionUP", FreeCaller<Selection_MoveUp>(), Accelerator(GDK_KP_Add));
3540 GlobalCommands_insert("SelectNudgeLeft", FreeCaller<Selection_NudgeLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_MOD1_MASK));
3541 GlobalCommands_insert("SelectNudgeRight", FreeCaller<Selection_NudgeRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_MOD1_MASK));
3542 GlobalCommands_insert("SelectNudgeUp", FreeCaller<Selection_NudgeUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_MOD1_MASK));
3543 GlobalCommands_insert("SelectNudgeDown", FreeCaller<Selection_NudgeDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_MOD1_MASK));
3545 Patch_registerCommands();
3546 XYShow_registerCommands();
3548 typedef FreeCaller1<const Selectable&, ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3549 GlobalSelectionSystem().addSelectionChangeCallback(ComponentModeSelectionChangedCaller());
3551 GlobalPreferenceSystem().registerPreference("DetachableMenus", BoolImportStringCaller(g_Layout_enableDetachableMenus.m_latched), BoolExportStringCaller(g_Layout_enableDetachableMenus.m_latched));
3552 GlobalPreferenceSystem().registerPreference("PatchToolBar", BoolImportStringCaller(g_Layout_enablePatchToolbar.m_latched), BoolExportStringCaller(g_Layout_enablePatchToolbar.m_latched));
3553 GlobalPreferenceSystem().registerPreference("PluginToolBar", BoolImportStringCaller(g_Layout_enablePluginToolbar.m_latched), BoolExportStringCaller(g_Layout_enablePluginToolbar.m_latched));
3554 GlobalPreferenceSystem().registerPreference("QE4StyleWindows", IntImportStringCaller(g_Layout_viewStyle.m_latched), IntExportStringCaller(g_Layout_viewStyle.m_latched));
3555 GlobalPreferenceSystem().registerPreference("XYHeight", IntImportStringCaller(g_layout_globals.nXYHeight), IntExportStringCaller(g_layout_globals.nXYHeight));
3556 GlobalPreferenceSystem().registerPreference("XYWidth", IntImportStringCaller(g_layout_globals.nXYWidth), IntExportStringCaller(g_layout_globals.nXYWidth));
3557 GlobalPreferenceSystem().registerPreference("CamWidth", IntImportStringCaller(g_layout_globals.nCamWidth), IntExportStringCaller(g_layout_globals.nCamWidth));
3558 GlobalPreferenceSystem().registerPreference("CamHeight", IntImportStringCaller(g_layout_globals.nCamHeight), IntExportStringCaller(g_layout_globals.nCamHeight));
3560 GlobalPreferenceSystem().registerPreference("State", IntImportStringCaller(g_layout_globals.nState), IntExportStringCaller(g_layout_globals.nState));
3561 GlobalPreferenceSystem().registerPreference("PositionX", IntImportStringCaller(g_layout_globals.m_position.x), IntExportStringCaller(g_layout_globals.m_position.x));
3562 GlobalPreferenceSystem().registerPreference("PositionY", IntImportStringCaller(g_layout_globals.m_position.y), IntExportStringCaller(g_layout_globals.m_position.y));
3563 GlobalPreferenceSystem().registerPreference("Width", IntImportStringCaller(g_layout_globals.m_position.w), IntExportStringCaller(g_layout_globals.m_position.w));
3564 GlobalPreferenceSystem().registerPreference("Height", IntImportStringCaller(g_layout_globals.m_position.h), IntExportStringCaller(g_layout_globals.m_position.h));
3566 GlobalPreferenceSystem().registerPreference("CamWnd", WindowPositionTrackerImportStringCaller(g_posCamWnd), WindowPositionTrackerExportStringCaller(g_posCamWnd));
3567 GlobalPreferenceSystem().registerPreference("XYWnd", WindowPositionTrackerImportStringCaller(g_posXYWnd), WindowPositionTrackerExportStringCaller(g_posXYWnd));
3568 GlobalPreferenceSystem().registerPreference("YZWnd", WindowPositionTrackerImportStringCaller(g_posYZWnd), WindowPositionTrackerExportStringCaller(g_posYZWnd));
3569 GlobalPreferenceSystem().registerPreference("XZWnd", WindowPositionTrackerImportStringCaller(g_posXZWnd), WindowPositionTrackerExportStringCaller(g_posXZWnd));
3572 const char* ENGINEPATH_ATTRIBUTE =
3575 #elif defined(__linux__) || defined (__FreeBSD__)
3577 #elif defined(__APPLE__)
3580 #error "unknown platform"
3583 StringOutputStream path(256);
3584 path << DirectoryCleaned(g_pGameDescription->getRequiredKeyValue(ENGINEPATH_ATTRIBUTE));
3585 g_strEnginePath = path.c_str();
3588 GlobalPreferenceSystem().registerPreference("EnginePath", CopiedStringImportStringCaller(g_strEnginePath), CopiedStringExportStringCaller(g_strEnginePath));
3590 g_Layout_viewStyle.useLatched();
3591 g_Layout_enableDetachableMenus.useLatched();
3592 g_Layout_enablePatchToolbar.useLatched();
3593 g_Layout_enablePluginToolbar.useLatched();
3595 Layout_registerPreferencesPage();
3596 Paths_registerPreferencesPage();
3598 g_brushCount.setCountChangedCallback(FreeCaller<QE_brushCountChanged>());
3599 g_entityCount.setCountChangedCallback(FreeCaller<QE_entityCountChanged>());
3600 GlobalEntityCreator().setCounter(&g_entityCount);
3602 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3603 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3605 GlobalEntityClassManager().attach(g_WorldspawnColourEntityClassObserver);
3608 void MainFrame_Destroy()
3610 GlobalEntityClassManager().detach(g_WorldspawnColourEntityClassObserver);
3612 GlobalEntityCreator().setCounter(0);
3613 g_entityCount.setCountChangedCallback(Callback());
3614 g_brushCount.setCountChangedCallback(Callback());
3618 void GLWindow_Construct()
3620 GlobalPreferenceSystem().registerPreference("MouseButtons", IntImportStringCaller(g_glwindow_globals.m_nMouseType), IntExportStringCaller(g_glwindow_globals.m_nMouseType));
3623 void GLWindow_Destroy()