2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 // Main Window for Q3Radiant
25 // Leonardo Zide (leo@lokigames.com)
28 #include "mainframe.h"
30 #include "debugging/debugging.h"
33 #include "ifilesystem.h"
41 #include "moduleobserver.h"
45 #include <gdk/gdkkeysyms.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtkvbox.h>
48 #include <gtk/gtkframe.h>
49 #include <gtk/gtklabel.h>
50 #include <gtk/gtkhpaned.h>
51 #include <gtk/gtkvpaned.h>
52 #include <gtk/gtktoolbar.h>
53 #include <gtk/gtkmenubar.h>
54 #include <gtk/gtkimage.h>
55 #include <gtk/gtktable.h>
60 #include "stream/stringstream.h"
61 #include "signal/isignal.h"
64 #include "eclasslib.h"
65 #include "moduleobservers.h"
67 #include "gtkutil/clipboard.h"
68 #include "gtkutil/container.h"
69 #include "gtkutil/frame.h"
70 #include "gtkutil/glfont.h"
71 #include "gtkutil/glwidget.h"
72 #include "gtkutil/image.h"
73 #include "gtkutil/menu.h"
74 #include "gtkutil/paned.h"
75 #include "gtkutil/widget.h"
79 #include "brushmanip.h"
80 #include "brushmodule.h"
81 #include "camwindow.h"
86 #include "entityinspector.h"
87 #include "entitylist.h"
89 #include "findtexturedialog.h"
91 #include "groupdialog.h"
98 #include "patchdialog.h"
99 #include "patchmanip.h"
101 #include "pluginmanager.h"
102 #include "pluginmenu.h"
103 #include "plugintoolbar.h"
105 #include "preferences.h"
110 #include "surfacedialog.h"
111 #include "textures.h"
112 #include "texwindow.h"
114 #include "xywindow.h"
115 #include "windowobservers.h"
116 #include "renderstate.h"
117 #include "feedback.h"
118 #include "referencecache.h"
122 struct layout_globals_t
124 WindowPosition m_position;
134 m_position(-1, -1, 640, 480),
140 nState(GDK_WINDOW_STATE_MAXIMIZED)
145 layout_globals_t g_layout_globals;
146 glwindow_globals_t g_glwindow_globals;
150 class VFSModuleObserver : public ModuleObserver
152 std::size_t m_unrealised;
154 VFSModuleObserver() : m_unrealised(1)
159 if(--m_unrealised == 0)
162 GlobalFileSystem().initialise();
167 if(++m_unrealised == 1)
169 GlobalFileSystem().shutdown();
174 VFSModuleObserver g_VFSModuleObserver;
178 Radiant_attachHomePathsObserver(g_VFSModuleObserver);
182 Radiant_detachHomePathsObserver(g_VFSModuleObserver);
187 void HomePaths_Realise()
190 const char* prefix = g_pGameDescription->getKeyValue("prefix");
191 if(!string_empty(prefix))
193 StringOutputStream path(256);
194 path << DirectoryCleaned(g_get_home_dir()) << prefix << "/";
195 g_qeglobals.m_userEnginePath = path.c_str();
196 Q_mkdir(g_qeglobals.m_userEnginePath.c_str());
201 g_qeglobals.m_userEnginePath = EnginePath_get();
205 StringOutputStream path(256);
206 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
207 g_qeglobals.m_userGamePath = path.c_str();
209 ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "HomePaths_Realise: user-game-path is empty");
210 Q_mkdir(g_qeglobals.m_userGamePath.c_str());
213 ModuleObservers g_homePathObservers;
215 void Radiant_attachHomePathsObserver(ModuleObserver& observer)
217 g_homePathObservers.attach(observer);
220 void Radiant_detachHomePathsObserver(ModuleObserver& observer)
222 g_homePathObservers.detach(observer);
225 class HomePathsModuleObserver : public ModuleObserver
227 std::size_t m_unrealised;
229 HomePathsModuleObserver() : m_unrealised(1)
234 if(--m_unrealised == 0)
237 g_homePathObservers.realise();
242 if(++m_unrealised == 1)
244 g_homePathObservers.unrealise();
249 HomePathsModuleObserver g_HomePathsModuleObserver;
251 void HomePaths_Construct()
253 Radiant_attachEnginePathObserver(g_HomePathsModuleObserver);
255 void HomePaths_Destroy()
257 Radiant_detachEnginePathObserver(g_HomePathsModuleObserver);
263 CopiedString g_strEnginePath;
264 ModuleObservers g_enginePathObservers;
265 std::size_t g_enginepath_unrealised = 1;
267 void Radiant_attachEnginePathObserver(ModuleObserver& observer)
269 g_enginePathObservers.attach(observer);
272 void Radiant_detachEnginePathObserver(ModuleObserver& observer)
274 g_enginePathObservers.detach(observer);
278 void EnginePath_Realise()
280 if(--g_enginepath_unrealised == 0)
282 g_enginePathObservers.realise();
287 const char* EnginePath_get()
289 ASSERT_MESSAGE(g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised");
290 return g_strEnginePath.c_str();
293 void EnginePath_Unrealise()
295 if(++g_enginepath_unrealised == 1)
297 g_enginePathObservers.unrealise();
301 void setEnginePath(const char* path)
303 StringOutputStream buffer(256);
304 buffer << DirectoryCleaned(path);
305 if(!path_equal(buffer.c_str(), g_strEnginePath.c_str()))
308 while(!ConfirmModified("Paths Changed"))
310 if(Map_Unnamed(g_map))
322 ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Changing Engine Path");
324 EnginePath_Unrealise();
326 g_strEnginePath = buffer.c_str();
328 EnginePath_Realise();
335 CopiedString g_strAppPath; ///< holds the full path of the executable
337 const char* AppPath_get()
339 return g_strAppPath.c_str();
342 /// the path to the local rc-dir
343 const char* LocalRcPath_get(void)
345 static CopiedString rc_path;
348 StringOutputStream stream(256);
349 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
350 rc_path = stream.c_str();
352 return rc_path.c_str();
355 /// directory for temp files
356 /// NOTE: on *nix this is were we check for .pid
357 CopiedString g_strSettingsPath;
358 const char* SettingsPath_get()
360 return g_strSettingsPath.c_str();
365 points to the game tools directory, for instance
366 C:/Program Files/Quake III Arena/GtkRadiant
368 this is one of the main variables that are configured by the game selection on startup
369 [GameToolsPath]/plugins
370 [GameToolsPath]/modules
373 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
375 const char* GameToolsPath_get()
377 return g_strGameToolsPath.c_str();
380 void EnginePathImport(CopiedString& self, const char* value)
382 setEnginePath(value);
384 typedef ReferenceCaller1<CopiedString, const char*, EnginePathImport> EnginePathImportCaller;
386 void Paths_constructPreferences(PreferencesPage& page)
388 page.appendPathEntry("Engine Path", true,
389 StringImportCallback(EnginePathImportCaller(g_strEnginePath)),
390 StringExportCallback(StringExportCaller(g_strEnginePath))
393 void Paths_constructPage(PreferenceGroup& group)
395 PreferencesPage page(group.createPage("Paths", "Path Settings"));
396 Paths_constructPreferences(page);
398 void Paths_registerPreferencesPage()
400 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Paths_constructPage>());
404 class PathsDialog : public Dialog
407 GtkWindow* BuildDialog()
409 GtkFrame* frame = create_dialog_frame("Path settings", GTK_SHADOW_ETCHED_IN);
411 GtkVBox* vbox2 = create_dialog_vbox(0, 4);
412 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(vbox2));
415 PreferencesPage preferencesPage(*this, GTK_WIDGET(vbox2));
416 Paths_constructPreferences(preferencesPage);
419 return create_simple_modal_dialog_window("Engine Path Not Found", m_modal, GTK_WIDGET(frame));
423 PathsDialog g_PathsDialog;
425 void EnginePath_verify()
427 if(!file_exists(g_strEnginePath.c_str()))
429 g_PathsDialog.Create();
430 g_PathsDialog.DoModal();
431 g_PathsDialog.Destroy();
437 CopiedString g_gamename;
438 CopiedString g_gamemode;
439 ModuleObservers g_gameNameObservers;
440 ModuleObservers g_gameModeObservers;
443 void Radiant_attachGameNameObserver(ModuleObserver& observer)
445 g_gameNameObservers.attach(observer);
448 void Radiant_detachGameNameObserver(ModuleObserver& observer)
450 g_gameNameObservers.detach(observer);
453 const char* basegame_get()
455 return g_pGameDescription->getRequiredKeyValue("basegame");
458 const char* gamename_get()
460 const char* gamename = g_gamename.c_str();
461 if(string_empty(gamename))
463 return basegame_get();
468 void gamename_set(const char* gamename)
470 if(!string_equal(gamename, g_gamename.c_str()))
472 g_gameNameObservers.unrealise();
473 g_gamename = gamename;
474 g_gameNameObservers.realise();
478 void Radiant_attachGameModeObserver(ModuleObserver& observer)
480 g_gameModeObservers.attach(observer);
483 void Radiant_detachGameModeObserver(ModuleObserver& observer)
485 g_gameModeObservers.detach(observer);
488 const char* gamemode_get()
490 return g_gamemode.c_str();
493 void gamemode_set(const char* gamemode)
495 if(!string_equal(gamemode, g_gamemode.c_str()))
497 g_gameModeObservers.unrealise();
498 g_gamemode = gamemode;
499 g_gameModeObservers.realise();
509 CLoadModule(const char* path) : m_path(path)
512 void operator()(const char* name) const
515 ASSERT_MESSAGE(strlen(m_path) + strlen(name) < 1024, "");
516 strcpy(fullname, m_path);
517 strcat(fullname, name);
518 globalOutputStream() << "Found '" << fullname << "'\n";
519 GlobalModuleServer_loadModule(fullname);
523 const char* const c_library_extension =
526 #elif defined (__APPLE__)
528 #elif defined(__linux__) || defined (__FreeBSD__)
533 void Radiant_loadModules(const char* path)
535 Directory_forEach(path, MatchFileExtension<CLoadModule>(c_library_extension, CLoadModule(path)));
538 void Radiant_loadModulesFromRoot(const char* directory)
541 StringOutputStream path(256);
542 path << directory << g_pluginsDir;
543 Radiant_loadModules(path.c_str());
546 if(!string_equal(g_pluginsDir, g_modulesDir))
548 StringOutputStream path(256);
549 path << directory << g_modulesDir;
550 Radiant_loadModules(path.c_str());
554 //! Make COLOR_BRUSHES override worldspawn eclass colour.
555 void SetWorldspawnColour(const Vector3& colour)
557 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert("worldspawn", true);
558 eclass_release_state(worldspawn);
559 worldspawn->color = colour;
560 eclass_capture_state(worldspawn);
564 class WorldspawnColourEntityClassObserver : public ModuleObserver
566 std::size_t m_unrealised;
568 WorldspawnColourEntityClassObserver() : m_unrealised(1)
573 if(--m_unrealised == 0)
575 SetWorldspawnColour(g_xywindow_globals.color_brushes);
580 if(++m_unrealised == 1)
586 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
589 ModuleObservers g_gameToolsPathObservers;
591 void Radiant_attachGameToolsPathObserver(ModuleObserver& observer)
593 g_gameToolsPathObservers.attach(observer);
596 void Radiant_detachGameToolsPathObserver(ModuleObserver& observer)
598 g_gameToolsPathObservers.detach(observer);
601 void Radiant_Initialise()
603 GlobalModuleServer_Initialise();
605 Radiant_loadModulesFromRoot(AppPath_get());
609 bool success = Radiant_Construct(GlobalModuleServer_get());
610 ASSERT_MESSAGE(success, "module system failed to initialise - see radiant.log for error messages");
612 g_gameToolsPathObservers.realise();
613 g_gameModeObservers.realise();
614 g_gameNameObservers.realise();
617 void Radiant_Shutdown()
619 g_gameNameObservers.unrealise();
620 g_gameModeObservers.unrealise();
621 g_gameToolsPathObservers.unrealise();
623 if (!g_preferences_globals.disable_ini)
625 globalOutputStream() << "Start writing prefs\n";
627 globalOutputStream() << "Done prefs\n";
632 GlobalModuleServer_Shutdown();
637 if(ConfirmModified("Exit Radiant"))
646 GlobalUndoSystem().undo();
652 GlobalUndoSystem().redo();
656 void deleteSelection()
658 UndoableCommand undo("deleteSelected");
662 void Map_ExportSelected(TextOutputStream& ostream)
664 Map_ExportSelected(ostream, Map_getFormat(g_map));
667 void Map_ImportSelected(TextInputStream& istream)
669 Map_ImportSelected(istream, Map_getFormat(g_map));
672 void Selection_Copy()
674 clipboard_copy(Map_ExportSelected);
677 void Selection_Paste()
679 clipboard_paste(Map_ImportSelected);
684 if(SelectedFaces_empty())
690 SelectedFaces_copyTexture();
696 if(SelectedFaces_empty())
698 UndoableCommand undo("paste");
700 GlobalSelectionSystem().setSelectedAll(false);
705 SelectedFaces_pasteTexture();
711 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
712 GlobalSelectionSystem().setSelectedAll(false);
714 UndoableCommand undo("pasteToCamera");
718 // Work out the delta
721 Vector3 delta = vector3_subtracted(vector3_snapped(Camera_getOrigin(camwnd), GetSnapGridSize()), mid);
724 GlobalSelectionSystem().translateSelected(delta);
728 void ColorScheme_Original()
730 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
732 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
733 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
734 CamWnd_Update(*g_pParentWnd->GetCamWnd());
736 g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
737 g_xywindow_globals.color_gridminor = Vector3(0.75f, 0.75f, 0.75f);
738 g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
739 g_xywindow_globals.color_gridminor_alt = Vector3(0.5f, 0.0f, 0.0f);
740 g_xywindow_globals.color_gridmajor_alt = Vector3(1.0f, 0.0f, 0.0f);
741 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
742 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
743 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
744 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
745 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
746 SetWorldspawnColour(g_xywindow_globals.color_brushes);
747 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
748 XY_UpdateAllWindows();
751 void ColorScheme_QER()
753 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
755 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
756 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
757 CamWnd_Update(*g_pParentWnd->GetCamWnd());
759 g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
760 g_xywindow_globals.color_gridminor = Vector3(1.0f, 1.0f, 1.0f);
761 g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
762 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
763 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
764 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
765 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
766 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
767 SetWorldspawnColour(g_xywindow_globals.color_brushes);
768 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
769 XY_UpdateAllWindows();
772 void ColorScheme_Black()
774 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
776 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
777 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
778 CamWnd_Update(*g_pParentWnd->GetCamWnd());
780 g_xywindow_globals.color_gridback = Vector3(0.0f, 0.0f, 0.0f);
781 g_xywindow_globals.color_gridminor = Vector3(0.2f, 0.2f, 0.2f);
782 g_xywindow_globals.color_gridmajor = Vector3(0.3f, 0.5f, 0.5f);
783 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
784 g_xywindow_globals.color_gridtext = Vector3(1.0f, 1.0f, 1.0f);
785 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
786 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
787 g_xywindow_globals.color_brushes = Vector3(1.0f, 1.0f, 1.0f);
788 SetWorldspawnColour(g_xywindow_globals.color_brushes);
789 g_xywindow_globals.color_viewname = Vector3(0.7f, 0.7f, 0.0f);
790 XY_UpdateAllWindows();
793 /* ydnar: to emulate maya/max/lightwave color schemes */
794 void ColorScheme_Ydnar()
796 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
798 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
799 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
800 CamWnd_Update(*g_pParentWnd->GetCamWnd());
802 g_xywindow_globals.color_gridback = Vector3(0.77f, 0.77f, 0.77f);
803 g_xywindow_globals.color_gridminor = Vector3(0.83f, 0.83f, 0.83f);
804 g_xywindow_globals.color_gridmajor = Vector3(0.89f, 0.89f, 0.89f);
805 g_xywindow_globals.color_gridblock = Vector3(1.0f, 1.0f, 1.0f);
806 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
807 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
808 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
809 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
810 SetWorldspawnColour(g_xywindow_globals.color_brushes);
811 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
812 XY_UpdateAllWindows();
815 typedef Callback1<Vector3&> GetColourCallback;
816 typedef Callback1<const Vector3&> SetColourCallback;
820 GetColourCallback m_get;
821 SetColourCallback m_set;
823 ChooseColour(const GetColourCallback& get, const SetColourCallback& set)
824 : m_get(get), m_set(set)
831 color_dialog(GTK_WIDGET(MainFrame_getWindow()), colour);
838 void Colour_get(const Vector3& colour, Vector3& other)
842 typedef ConstReferenceCaller1<Vector3, Vector3&, Colour_get> ColourGetCaller;
844 void Colour_set(Vector3& colour, const Vector3& other)
849 typedef ReferenceCaller1<Vector3, const Vector3&, Colour_set> ColourSetCaller;
851 void BrushColour_set(const Vector3& other)
853 g_xywindow_globals.color_brushes = other;
854 SetWorldspawnColour(g_xywindow_globals.color_brushes);
857 typedef FreeCaller1<const Vector3&, BrushColour_set> BrushColourSetCaller;
859 void ClipperColour_set(const Vector3& other)
861 g_xywindow_globals.color_clipper = other;
862 Brush_clipperColourChanged();
865 typedef FreeCaller1<const Vector3&, ClipperColour_set> ClipperColourSetCaller;
867 void TextureBrowserColour_get(Vector3& other)
869 other = TextureBrowser_getBackgroundColour(GlobalTextureBrowser());
871 typedef FreeCaller1<Vector3&, TextureBrowserColour_get> TextureBrowserColourGetCaller;
873 void TextureBrowserColour_set(const Vector3& other)
875 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), other);
877 typedef FreeCaller1<const Vector3&, TextureBrowserColour_set> TextureBrowserColourSetCaller;
883 ChooseColour m_textureback;
884 ChooseColour m_xyback;
885 ChooseColour m_gridmajor;
886 ChooseColour m_gridminor;
887 ChooseColour m_gridmajor_alt;
888 ChooseColour m_gridminor_alt;
889 ChooseColour m_gridtext;
890 ChooseColour m_gridblock;
891 ChooseColour m_cameraback;
892 ChooseColour m_brush;
893 ChooseColour m_selectedbrush;
894 ChooseColour m_selectedbrush3d;
895 ChooseColour m_clipper;
896 ChooseColour m_viewname;
899 m_textureback(TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller()),
900 m_xyback(ColourGetCaller(g_xywindow_globals.color_gridback), ColourSetCaller(g_xywindow_globals.color_gridback)),
901 m_gridmajor(ColourGetCaller(g_xywindow_globals.color_gridmajor), ColourSetCaller(g_xywindow_globals.color_gridmajor)),
902 m_gridminor(ColourGetCaller(g_xywindow_globals.color_gridminor), ColourSetCaller(g_xywindow_globals.color_gridminor)),
903 m_gridmajor_alt(ColourGetCaller(g_xywindow_globals.color_gridmajor_alt), ColourSetCaller(g_xywindow_globals.color_gridmajor_alt)),
904 m_gridminor_alt(ColourGetCaller(g_xywindow_globals.color_gridminor_alt), ColourSetCaller(g_xywindow_globals.color_gridminor_alt)),
905 m_gridtext(ColourGetCaller(g_xywindow_globals.color_gridtext), ColourSetCaller(g_xywindow_globals.color_gridtext)),
906 m_gridblock(ColourGetCaller(g_xywindow_globals.color_gridblock), ColourSetCaller(g_xywindow_globals.color_gridblock)),
907 m_cameraback(ColourGetCaller(g_camwindow_globals.color_cameraback), ColourSetCaller(g_camwindow_globals.color_cameraback)),
908 m_brush(ColourGetCaller(g_xywindow_globals.color_brushes), BrushColourSetCaller()),
909 m_selectedbrush(ColourGetCaller(g_xywindow_globals.color_selbrushes), ColourSetCaller(g_xywindow_globals.color_selbrushes)),
910 m_selectedbrush3d(ColourGetCaller(g_camwindow_globals.color_selbrushes3d), ColourSetCaller(g_camwindow_globals.color_selbrushes3d)),
911 m_clipper(ColourGetCaller(g_xywindow_globals.color_clipper), ClipperColourSetCaller()),
912 m_viewname(ColourGetCaller(g_xywindow_globals.color_viewname), ColourSetCaller(g_xywindow_globals.color_viewname))
917 ColoursMenu g_ColoursMenu;
919 GtkMenuItem* create_colours_menu()
921 GtkMenuItem* colours_menu_item = new_sub_menu_item_with_mnemonic("Colors");
922 GtkMenu* menu_in_menu = GTK_MENU(gtk_menu_item_get_submenu(colours_menu_item));
923 if (g_Layout_enableDetachableMenus.m_value)
924 menu_tearoff (menu_in_menu);
926 GtkMenu* menu_3 = create_sub_menu_with_mnemonic(menu_in_menu, "Themes");
927 if (g_Layout_enableDetachableMenus.m_value)
928 menu_tearoff (menu_3);
930 create_menu_item_with_mnemonic(menu_3, "QE4 Original", "ColorSchemeOriginal");
931 create_menu_item_with_mnemonic(menu_3, "Q3Radiant Original", "ColorSchemeQER");
932 create_menu_item_with_mnemonic(menu_3, "Black and Green", "ColorSchemeBlackAndGreen");
933 create_menu_item_with_mnemonic(menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar");
935 menu_separator(menu_in_menu);
937 create_menu_item_with_mnemonic(menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor");
938 create_menu_item_with_mnemonic(menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor");
939 create_menu_item_with_mnemonic(menu_in_menu, "Grid Major...", "ChooseGridMajorColor");
940 create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor...", "ChooseGridMinorColor");
941 create_menu_item_with_mnemonic(menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor");
942 create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor");
943 create_menu_item_with_mnemonic(menu_in_menu, "Grid Text...", "ChooseGridTextColor");
944 create_menu_item_with_mnemonic(menu_in_menu, "Grid Block...", "ChooseGridBlockColor");
945 create_menu_item_with_mnemonic(menu_in_menu, "Default Brush...", "ChooseBrushColor");
946 create_menu_item_with_mnemonic(menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor");
947 create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor");
948 create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor");
949 create_menu_item_with_mnemonic(menu_in_menu, "Clipper...", "ChooseClipperColor");
950 create_menu_item_with_mnemonic(menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor");
952 return colours_menu_item;
959 PluginToolbar_clear();
962 Radiant_Initialise();
964 PluginsMenu_populate();
966 PluginToolbar_populate();
972 g_pParentWnd->OnSleep();
978 StringOutputStream URL(256);
979 URL << "http://www.icculus.org/netradiant/?cmd=update&data=dlupdate&query_dlup=1";
982 #elif defined(__APPLE__)
987 URL << "&Version_dlup=" RADIANT_VERSION;
988 g_GamesDialog.AddPacksURL(URL);
989 OpenURL(URL.c_str());
992 // open the Q3Rad manual
995 // at least on win32, AppPath + "docs/index.html"
996 StringOutputStream help(256);
997 help << AppPath_get() << "docs/index.html";
998 OpenURL(help.c_str());
1001 void OpenBugReportURL()
1003 OpenURL("http://www.icculus.org/netradiant/?cmd=bugs");
1007 GtkWidget* g_page_console;
1009 void Console_ToggleShow()
1011 GroupDialog_showPage(g_page_console);
1014 GtkWidget* g_page_entity;
1016 void EntityInspector_ToggleShow()
1018 GroupDialog_showPage(g_page_entity);
1023 void SetClipMode(bool enable);
1024 void ModeChangeNotify();
1026 typedef void(*ToolMode)();
1027 ToolMode g_currentToolMode = 0;
1028 bool g_currentToolModeSupportsComponentEditing = false;
1029 ToolMode g_defaultToolMode = 0;
1033 void SelectionSystem_DefaultMode()
1035 GlobalSelectionSystem().SetMode(SelectionSystem::ePrimitive);
1036 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eDefault);
1043 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1044 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1049 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1050 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1055 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1056 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1059 template<bool (*BoolFunction)()>
1060 class BoolFunctionExport
1063 static void apply(const BoolImportCallback& importCallback)
1065 importCallback(BoolFunction());
1069 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1070 EdgeModeApplyCaller g_edgeMode_button_caller;
1071 BoolExportCallback g_edgeMode_button_callback(g_edgeMode_button_caller);
1072 ToggleItem g_edgeMode_button(g_edgeMode_button_callback);
1074 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1075 VertexModeApplyCaller g_vertexMode_button_caller;
1076 BoolExportCallback g_vertexMode_button_callback(g_vertexMode_button_caller);
1077 ToggleItem g_vertexMode_button(g_vertexMode_button_callback);
1079 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1080 FaceModeApplyCaller g_faceMode_button_caller;
1081 BoolExportCallback g_faceMode_button_callback(g_faceMode_button_caller);
1082 ToggleItem g_faceMode_button(g_faceMode_button_callback);
1084 void ComponentModeChanged()
1086 g_edgeMode_button.update();
1087 g_vertexMode_button.update();
1088 g_faceMode_button.update();
1091 void ComponentMode_SelectionChanged(const Selectable& selectable)
1093 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1094 && GlobalSelectionSystem().countSelected() == 0)
1096 SelectionSystem_DefaultMode();
1097 ComponentModeChanged();
1101 void SelectEdgeMode()
1104 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1106 GlobalSelectionSystem().Select(false);
1112 SelectionSystem_DefaultMode();
1114 else if(GlobalSelectionSystem().countSelected() != 0)
1116 if(!g_currentToolModeSupportsComponentEditing)
1118 g_defaultToolMode();
1121 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1122 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eEdge);
1125 ComponentModeChanged();
1130 void SelectVertexMode()
1133 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1135 GlobalSelectionSystem().Select(false);
1141 SelectionSystem_DefaultMode();
1143 else if(GlobalSelectionSystem().countSelected() != 0)
1145 if(!g_currentToolModeSupportsComponentEditing)
1147 g_defaultToolMode();
1150 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1151 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eVertex);
1154 ComponentModeChanged();
1159 void SelectFaceMode()
1162 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1164 GlobalSelectionSystem().Select(false);
1170 SelectionSystem_DefaultMode();
1172 else if(GlobalSelectionSystem().countSelected() != 0)
1174 if(!g_currentToolModeSupportsComponentEditing)
1176 g_defaultToolMode();
1179 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1180 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eFace);
1183 ComponentModeChanged();
1189 class CloneSelected : public scene::Graph::Walker
1192 NodeSmartReference worldspawn;
1194 CloneSelected(bool d): doMakeUnique(d), worldspawn(Map_FindOrInsertWorldspawn(g_map))
1197 bool pre(const scene::Path& path, scene::Instance& instance) const
1199 if(path.size() == 1)
1202 // ignore worldspawn, but keep checking children
1203 NodeSmartReference me(path.top().get());
1204 if(me == worldspawn)
1207 if(!path.top().get().isRoot())
1209 Selectable* selectable = Instance_getSelectable(instance);
1211 && selectable->isSelected())
1219 void post(const scene::Path& path, scene::Instance& instance) const
1221 if(path.size() == 1)
1224 // ignore worldspawn, but keep checking children
1225 NodeSmartReference me(path.top().get());
1226 if(me == worldspawn)
1229 if(!path.top().get().isRoot())
1231 Selectable* selectable = Instance_getSelectable(instance);
1233 && selectable->isSelected())
1235 NodeSmartReference clone(Node_Clone(path.top()));
1237 Map_gatherNamespaced(clone);
1238 Node_getTraversable(path.parent().get())->insert(clone);
1244 void Scene_Clone_Selected(scene::Graph& graph, bool doMakeUnique)
1246 graph.traverse(CloneSelected(doMakeUnique));
1248 Map_mergeClonedNames();
1251 enum ENudgeDirection
1264 AxisBase(const Vector3& x_, const Vector3& y_, const Vector3& z_)
1265 : x(x_), y(y_), z(z_)
1270 AxisBase AxisBase_forViewType(VIEWTYPE viewtype)
1275 return AxisBase(g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z);
1277 return AxisBase(g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y);
1279 return AxisBase(g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x);
1282 ERROR_MESSAGE("invalid viewtype");
1283 return AxisBase(Vector3(0, 0, 0), Vector3(0, 0, 0), Vector3(0, 0, 0));
1286 Vector3 AxisBase_axisForDirection(const AxisBase& axes, ENudgeDirection direction)
1291 return vector3_negated(axes.x);
1297 return vector3_negated(axes.y);
1300 ERROR_MESSAGE("invalid direction");
1301 return Vector3(0, 0, 0);
1304 void NudgeSelection(ENudgeDirection direction, float fAmount, VIEWTYPE viewtype)
1306 AxisBase axes(AxisBase_forViewType(viewtype));
1307 Vector3 view_direction(vector3_negated(axes.z));
1308 Vector3 nudge(vector3_scaled(AxisBase_axisForDirection(axes, direction), fAmount));
1309 GlobalSelectionSystem().NudgeManipulator(nudge, view_direction);
1312 void Selection_Clone()
1314 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
1316 UndoableCommand undo("cloneSelected");
1318 Scene_Clone_Selected(GlobalSceneGraph(), false);
1320 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1321 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1325 void Selection_Clone_MakeUnique()
1327 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
1329 UndoableCommand undo("cloneSelectedMakeUnique");
1331 Scene_Clone_Selected(GlobalSceneGraph(), true);
1333 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1334 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1338 // called when the escape key is used (either on the main window or on an inspector)
1339 void Selection_Deselect()
1341 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1343 if(GlobalSelectionSystem().countSelectedComponents() != 0)
1345 GlobalSelectionSystem().setSelectedAllComponents(false);
1349 SelectionSystem_DefaultMode();
1350 ComponentModeChanged();
1355 if(GlobalSelectionSystem().countSelectedComponents() != 0)
1357 GlobalSelectionSystem().setSelectedAllComponents(false);
1361 GlobalSelectionSystem().setSelectedAll(false);
1367 void Selection_NudgeUp()
1369 UndoableCommand undo("nudgeSelectedUp");
1370 NudgeSelection(eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1373 void Selection_NudgeDown()
1375 UndoableCommand undo("nudgeSelectedDown");
1376 NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1379 void Selection_NudgeLeft()
1381 UndoableCommand undo("nudgeSelectedLeft");
1382 NudgeSelection(eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1385 void Selection_NudgeRight()
1387 UndoableCommand undo("nudgeSelectedRight");
1388 NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1392 void TranslateToolExport(const BoolImportCallback& importCallback)
1394 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate);
1397 void RotateToolExport(const BoolImportCallback& importCallback)
1399 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate);
1402 void ScaleToolExport(const BoolImportCallback& importCallback)
1404 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale);
1407 void DragToolExport(const BoolImportCallback& importCallback)
1409 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag);
1412 void ClipperToolExport(const BoolImportCallback& importCallback)
1414 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip);
1417 FreeCaller1<const BoolImportCallback&, TranslateToolExport> g_translatemode_button_caller;
1418 BoolExportCallback g_translatemode_button_callback(g_translatemode_button_caller);
1419 ToggleItem g_translatemode_button(g_translatemode_button_callback);
1421 FreeCaller1<const BoolImportCallback&, RotateToolExport> g_rotatemode_button_caller;
1422 BoolExportCallback g_rotatemode_button_callback(g_rotatemode_button_caller);
1423 ToggleItem g_rotatemode_button(g_rotatemode_button_callback);
1425 FreeCaller1<const BoolImportCallback&, ScaleToolExport> g_scalemode_button_caller;
1426 BoolExportCallback g_scalemode_button_callback(g_scalemode_button_caller);
1427 ToggleItem g_scalemode_button(g_scalemode_button_callback);
1429 FreeCaller1<const BoolImportCallback&, DragToolExport> g_dragmode_button_caller;
1430 BoolExportCallback g_dragmode_button_callback(g_dragmode_button_caller);
1431 ToggleItem g_dragmode_button(g_dragmode_button_callback);
1433 FreeCaller1<const BoolImportCallback&, ClipperToolExport> g_clipper_button_caller;
1434 BoolExportCallback g_clipper_button_callback(g_clipper_button_caller);
1435 ToggleItem g_clipper_button(g_clipper_button_callback);
1439 g_translatemode_button.update();
1440 g_rotatemode_button.update();
1441 g_scalemode_button.update();
1442 g_dragmode_button.update();
1443 g_clipper_button.update();
1446 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1450 if(g_currentToolMode == DragMode && g_defaultToolMode != DragMode)
1452 g_defaultToolMode();
1456 g_currentToolMode = DragMode;
1457 g_currentToolModeSupportsComponentEditing = true;
1461 Sys_Status(c_ResizeMode_status);
1462 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eDrag);
1469 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1471 void TranslateMode()
1473 if(g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode)
1475 g_defaultToolMode();
1479 g_currentToolMode = TranslateMode;
1480 g_currentToolModeSupportsComponentEditing = true;
1484 Sys_Status(c_TranslateMode_status);
1485 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eTranslate);
1491 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1495 if(g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode)
1497 g_defaultToolMode();
1501 g_currentToolMode = RotateMode;
1502 g_currentToolModeSupportsComponentEditing = true;
1506 Sys_Status(c_RotateMode_status);
1507 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eRotate);
1513 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1517 if(g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode)
1519 g_defaultToolMode();
1523 g_currentToolMode = ScaleMode;
1524 g_currentToolModeSupportsComponentEditing = true;
1528 Sys_Status(c_ScaleMode_status);
1529 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eScale);
1536 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1541 if(g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode)
1543 g_defaultToolMode();
1547 g_currentToolMode = ClipperMode;
1548 g_currentToolModeSupportsComponentEditing = false;
1550 SelectionSystem_DefaultMode();
1554 Sys_Status(c_ClipperMode_status);
1555 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eClip);
1562 void Texdef_Rotate(float angle)
1564 StringOutputStream command;
1565 command << "brushRotateTexture -angle " << angle;
1566 UndoableCommand undo(command.c_str());
1567 Select_RotateTexture(angle);
1570 void Texdef_RotateClockwise()
1572 Texdef_Rotate(static_cast<float>(fabs(g_si_globals.rotate)));
1575 void Texdef_RotateAntiClockwise()
1577 Texdef_Rotate(static_cast<float>(-fabs(g_si_globals.rotate)));
1580 void Texdef_Scale(float x, float y)
1582 StringOutputStream command;
1583 command << "brushScaleTexture -x " << x << " -y " << y;
1584 UndoableCommand undo(command.c_str());
1585 Select_ScaleTexture(x, y);
1588 void Texdef_ScaleUp()
1590 Texdef_Scale(0, g_si_globals.scale[1]);
1593 void Texdef_ScaleDown()
1595 Texdef_Scale(0, -g_si_globals.scale[1]);
1598 void Texdef_ScaleLeft()
1600 Texdef_Scale(-g_si_globals.scale[0],0);
1603 void Texdef_ScaleRight()
1605 Texdef_Scale(g_si_globals.scale[0],0);
1608 void Texdef_Shift(float x, float y)
1610 StringOutputStream command;
1611 command << "brushShiftTexture -x " << x << " -y " << y;
1612 UndoableCommand undo(command.c_str());
1613 Select_ShiftTexture(x, y);
1616 void Texdef_ShiftLeft()
1618 Texdef_Shift(-g_si_globals.shift[0], 0);
1621 void Texdef_ShiftRight()
1623 Texdef_Shift(g_si_globals.shift[0], 0);
1626 void Texdef_ShiftUp()
1628 Texdef_Shift(0, g_si_globals.shift[1]);
1631 void Texdef_ShiftDown()
1633 Texdef_Shift(0, -g_si_globals.shift[1]);
1638 class SnappableSnapToGridSelected : public scene::Graph::Walker
1642 SnappableSnapToGridSelected(float snap)
1646 bool pre(const scene::Path& path, scene::Instance& instance) const
1648 if(path.top().get().visible())
1650 Snappable* snappable = Node_getSnappable(path.top());
1652 && Instance_getSelectable(instance)->isSelected())
1654 snappable->snapto(m_snap);
1661 void Scene_SnapToGrid_Selected(scene::Graph& graph, float snap)
1663 graph.traverse(SnappableSnapToGridSelected(snap));
1666 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1670 ComponentSnappableSnapToGridSelected(float snap)
1674 bool pre(const scene::Path& path, scene::Instance& instance) const
1676 if(path.top().get().visible())
1678 ComponentSnappable* componentSnappable = Instance_getComponentSnappable(instance);
1679 if(componentSnappable != 0
1680 && Instance_getSelectable(instance)->isSelected())
1682 componentSnappable->snapComponents(m_snap);
1689 void Scene_SnapToGrid_Component_Selected(scene::Graph& graph, float snap)
1691 graph.traverse(ComponentSnappableSnapToGridSelected(snap));
1694 void Selection_SnapToGrid()
1696 StringOutputStream command;
1697 command << "snapSelected -grid " << GetGridSize();
1698 UndoableCommand undo(command.c_str());
1700 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1702 Scene_SnapToGrid_Component_Selected(GlobalSceneGraph(), GetGridSize());
1706 Scene_SnapToGrid_Selected(GlobalSceneGraph(), GetGridSize());
1711 static gint qe_every_second(gpointer data)
1713 GdkModifierType mask;
1715 gdk_window_get_pointer (0, 0, 0, &mask);
1717 if ((mask & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK)) == 0)
1725 guint s_qe_every_second_id = 0;
1727 void EverySecondTimer_enable()
1729 if(s_qe_every_second_id == 0)
1731 s_qe_every_second_id = gtk_timeout_add(1000, qe_every_second, 0);
1735 void EverySecondTimer_disable()
1737 if(s_qe_every_second_id != 0)
1739 gtk_timeout_remove(s_qe_every_second_id);
1740 s_qe_every_second_id = 0;
1744 gint window_realize_remove_decoration(GtkWidget* widget, gpointer data)
1746 gdk_window_set_decorations(widget->window, (GdkWMDecoration)(GDK_DECOR_ALL|GDK_DECOR_MENU|GDK_DECOR_MINIMIZE|GDK_DECOR_MAXIMIZE));
1753 GtkWindow* m_window;
1757 WaitDialog create_wait_dialog(const char* title, const char* text)
1761 dialog.m_window = create_floating_window(title, MainFrame_getWindow());
1762 gtk_window_set_resizable(dialog.m_window, FALSE);
1763 gtk_container_set_border_width(GTK_CONTAINER(dialog.m_window), 0);
1764 gtk_window_set_position(dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT);
1766 g_signal_connect(G_OBJECT(dialog.m_window), "realize", G_CALLBACK(window_realize_remove_decoration), 0);
1769 dialog.m_label = GTK_LABEL(gtk_label_new(text));
1770 gtk_misc_set_alignment(GTK_MISC(dialog.m_label), 0.0, 0.5);
1771 gtk_label_set_justify(dialog.m_label, GTK_JUSTIFY_LEFT);
1772 gtk_widget_show(GTK_WIDGET(dialog.m_label));
1773 gtk_widget_set_size_request(GTK_WIDGET(dialog.m_label), 200, -1);
1775 gtk_container_add(GTK_CONTAINER(dialog.m_window), GTK_WIDGET(dialog.m_label));
1782 clock_t g_lastRedrawTime = 0;
1783 const clock_t c_redrawInterval = clock_t(CLOCKS_PER_SEC / 10);
1785 bool redrawRequired()
1787 clock_t currentTime = std::clock();
1788 if(currentTime - g_lastRedrawTime >= c_redrawInterval)
1790 g_lastRedrawTime = currentTime;
1797 bool MainFrame_isActiveApp()
1799 //globalOutputStream() << "listing\n";
1800 GList* list = gtk_window_list_toplevels();
1801 for(GList* i = list; i != 0; i = g_list_next(i))
1803 //globalOutputStream() << "toplevel.. ";
1804 if(gtk_window_is_active(GTK_WINDOW(i->data)))
1806 //globalOutputStream() << "is active\n";
1809 //globalOutputStream() << "not active\n";
1814 typedef std::list<CopiedString> StringStack;
1815 StringStack g_wait_stack;
1818 bool ScreenUpdates_Enabled()
1820 return g_wait_stack.empty();
1823 void ScreenUpdates_process()
1825 if(redrawRequired() && GTK_WIDGET_VISIBLE(g_wait.m_window))
1832 void ScreenUpdates_Disable(const char* message, const char* title)
1834 if(g_wait_stack.empty())
1836 EverySecondTimer_disable();
1840 bool isActiveApp = MainFrame_isActiveApp();
1842 g_wait = create_wait_dialog(title, message);
1843 gtk_grab_add(GTK_WIDGET(g_wait.m_window));
1847 gtk_widget_show(GTK_WIDGET(g_wait.m_window));
1848 ScreenUpdates_process();
1851 else if(GTK_WIDGET_VISIBLE(g_wait.m_window))
1853 gtk_label_set_text(g_wait.m_label, message);
1854 ScreenUpdates_process();
1856 g_wait_stack.push_back(message);
1859 void ScreenUpdates_Enable()
1861 ASSERT_MESSAGE(!ScreenUpdates_Enabled(), "screen updates already enabled");
1862 g_wait_stack.pop_back();
1863 if(g_wait_stack.empty())
1865 EverySecondTimer_enable();
1866 //gtk_widget_set_sensitive(GTK_WIDGET(MainFrame_getWindow()), TRUE);
1868 gtk_grab_remove(GTK_WIDGET(g_wait.m_window));
1869 destroy_floating_window(g_wait.m_window);
1870 g_wait.m_window = 0;
1872 //gtk_window_present(MainFrame_getWindow());
1874 else if(GTK_WIDGET_VISIBLE(g_wait.m_window))
1876 gtk_label_set_text(g_wait.m_label, g_wait_stack.back().c_str());
1877 ScreenUpdates_process();
1883 void GlobalCamera_UpdateWindow()
1885 if(g_pParentWnd != 0)
1887 CamWnd_Update(*g_pParentWnd->GetCamWnd());
1891 void XY_UpdateWindow(MainFrame& mainframe)
1893 if(mainframe.GetXYWnd() != 0)
1895 XYWnd_Update(*mainframe.GetXYWnd());
1899 void XZ_UpdateWindow(MainFrame& mainframe)
1901 if(mainframe.GetXZWnd() != 0)
1903 XYWnd_Update(*mainframe.GetXZWnd());
1907 void YZ_UpdateWindow(MainFrame& mainframe)
1909 if(mainframe.GetYZWnd() != 0)
1911 XYWnd_Update(*mainframe.GetYZWnd());
1915 void XY_UpdateAllWindows(MainFrame& mainframe)
1917 XY_UpdateWindow(mainframe);
1918 XZ_UpdateWindow(mainframe);
1919 YZ_UpdateWindow(mainframe);
1922 void XY_UpdateAllWindows()
1924 if(g_pParentWnd != 0)
1926 XY_UpdateAllWindows(*g_pParentWnd);
1930 void UpdateAllWindows()
1932 GlobalCamera_UpdateWindow();
1933 XY_UpdateAllWindows();
1937 void ModeChangeNotify()
1939 SceneChangeNotify();
1942 void ClipperChangeNotify()
1944 GlobalCamera_UpdateWindow();
1945 XY_UpdateAllWindows();
1949 LatchedInt g_Layout_viewStyle(0, "Window Layout");
1950 LatchedBool g_Layout_enableDetachableMenus(true, "Detachable Menus");
1951 LatchedBool g_Layout_enablePatchToolbar(true, "Patch Toolbar");
1952 LatchedBool g_Layout_enablePluginToolbar(true, "Plugin Toolbar");
1956 GtkMenuItem* create_file_menu()
1959 GtkMenuItem* file_menu_item = new_sub_menu_item_with_mnemonic("_File");
1960 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(file_menu_item));
1961 if (g_Layout_enableDetachableMenus.m_value)
1962 menu_tearoff (menu);
1964 create_menu_item_with_mnemonic(menu, "_New Map", "NewMap");
1965 menu_separator(menu);
1968 //++timo temporary experimental stuff for sleep mode..
1969 create_menu_item_with_mnemonic(menu, "_Sleep", "Sleep");
1970 menu_separator(menu);
1974 create_menu_item_with_mnemonic(menu, "_Open...", "OpenMap");
1976 create_menu_item_with_mnemonic(menu, "_Import...", "ImportMap");
1977 create_menu_item_with_mnemonic(menu, "_Save", "SaveMap");
1978 create_menu_item_with_mnemonic(menu, "Save _as...", "SaveMapAs");
1979 create_menu_item_with_mnemonic(menu, "Save s_elected...", "SaveSelected");
1980 menu_separator(menu);
1981 create_menu_item_with_mnemonic(menu, "Save re_gion...", "SaveRegion");
1982 menu_separator(menu);
1983 create_menu_item_with_mnemonic(menu, "_Refresh models", "RefreshReferences");
1984 menu_separator(menu);
1985 create_menu_item_with_mnemonic(menu, "Pro_ject settings...", "ProjectSettings");
1986 menu_separator(menu);
1987 create_menu_item_with_mnemonic(menu, "_Pointfile...", "TogglePointfile");
1988 menu_separator(menu);
1989 MRU_constructMenu(menu);
1990 menu_separator(menu);
1991 create_menu_item_with_mnemonic(menu, "Check for NetRadiant update (web)", "CheckForUpdate"); // FIXME
1992 create_menu_item_with_mnemonic(menu, "E_xit", "Exit");
1994 return file_menu_item;
1997 GtkMenuItem* create_edit_menu()
2000 GtkMenuItem* edit_menu_item = new_sub_menu_item_with_mnemonic("_Edit");
2001 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(edit_menu_item));
2002 if (g_Layout_enableDetachableMenus.m_value)
2003 menu_tearoff (menu);
2004 create_menu_item_with_mnemonic(menu, "_Undo", "Undo");
2005 create_menu_item_with_mnemonic(menu, "_Redo", "Redo");
2006 menu_separator(menu);
2007 create_menu_item_with_mnemonic(menu, "_Copy", "Copy");
2008 create_menu_item_with_mnemonic(menu, "_Paste", "Paste");
2009 create_menu_item_with_mnemonic(menu, "P_aste To Camera", "PasteToCamera");
2010 menu_separator(menu);
2011 create_menu_item_with_mnemonic(menu, "_Duplicate", "CloneSelection");
2012 create_menu_item_with_mnemonic(menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique");
2013 create_menu_item_with_mnemonic(menu, "D_elete", "DeleteSelection");
2014 menu_separator(menu);
2015 create_menu_item_with_mnemonic(menu, "Pa_rent", "ParentSelection");
2016 menu_separator(menu);
2017 create_menu_item_with_mnemonic(menu, "C_lear Selection", "UnSelectSelection");
2018 create_menu_item_with_mnemonic(menu, "_Invert Selection", "InvertSelection");
2019 create_menu_item_with_mnemonic(menu, "Select i_nside", "SelectInside");
2020 create_menu_item_with_mnemonic(menu, "Select _touching", "SelectTouching");
2022 GtkMenu* convert_menu = create_sub_menu_with_mnemonic(menu, "E_xpand Selection");
2023 if (g_Layout_enableDetachableMenus.m_value)
2024 menu_tearoff (convert_menu);
2025 create_menu_item_with_mnemonic(convert_menu, "To Whole _Entities", "ExpandSelectionToEntities");
2027 menu_separator(menu);
2028 create_menu_item_with_mnemonic(menu, "Pre_ferences...", "Preferences");
2030 return edit_menu_item;
2033 void fill_view_xy_top_menu(GtkMenu* menu)
2035 create_check_menu_item_with_mnemonic(menu, "XY (Top) View", "ToggleView");
2039 void fill_view_yz_side_menu(GtkMenu* menu)
2041 create_check_menu_item_with_mnemonic(menu, "YZ (Side) View", "ToggleSideView");
2045 void fill_view_xz_front_menu(GtkMenu* menu)
2047 create_check_menu_item_with_mnemonic(menu, "XZ (Front) View", "ToggleFrontView");
2051 GtkWidget* g_toggle_z_item = 0;
2052 GtkWidget* g_toggle_console_item = 0;
2053 GtkWidget* g_toggle_entity_item = 0;
2054 GtkWidget* g_toggle_entitylist_item = 0;
2056 GtkMenuItem* create_view_menu(MainFrame::EViewStyle style)
2059 GtkMenuItem* view_menu_item = new_sub_menu_item_with_mnemonic("Vie_w");
2060 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(view_menu_item));
2061 if (g_Layout_enableDetachableMenus.m_value)
2062 menu_tearoff (menu);
2064 if(style == MainFrame::eFloating)
2066 fill_view_camera_menu(menu);
2067 fill_view_xy_top_menu(menu);
2068 fill_view_yz_side_menu(menu);
2069 fill_view_xz_front_menu(menu);
2071 if(style == MainFrame::eFloating || style == MainFrame::eSplit)
2073 create_menu_item_with_mnemonic(menu, "Console View", "ToggleConsole");
2074 create_menu_item_with_mnemonic(menu, "Texture Browser", "ToggleTextures");
2075 create_menu_item_with_mnemonic(menu, "Entity Inspector", "ToggleEntityInspector");
2079 create_menu_item_with_mnemonic(menu, "Entity Inspector", "ViewEntityInfo");
2081 create_menu_item_with_mnemonic(menu, "_Surface Inspector", "SurfaceInspector");
2082 create_menu_item_with_mnemonic(menu, "Entity List", "EntityList");
2084 menu_separator(menu);
2086 GtkMenu* camera_menu = create_sub_menu_with_mnemonic (menu, "Camera");
2087 if (g_Layout_enableDetachableMenus.m_value)
2088 menu_tearoff (camera_menu);
2089 create_menu_item_with_mnemonic(camera_menu, "_Center", "CenterView");
2090 create_menu_item_with_mnemonic(camera_menu, "_Up Floor", "UpFloor");
2091 create_menu_item_with_mnemonic(camera_menu, "_Down Floor", "DownFloor");
2092 menu_separator(camera_menu);
2093 create_menu_item_with_mnemonic(camera_menu, "Far Clip Plane In", "CubicClipZoomIn");
2094 create_menu_item_with_mnemonic(camera_menu, "Far Clip Plane Out", "CubicClipZoomOut");
2095 menu_separator(camera_menu);
2096 create_menu_item_with_mnemonic(camera_menu, "Next leak spot", "NextLeakSpot");
2097 create_menu_item_with_mnemonic(camera_menu, "Previous leak spot", "PrevLeakSpot");
2098 menu_separator(camera_menu);
2099 create_menu_item_with_mnemonic(camera_menu, "Look Through Selected", "LookThroughSelected");
2100 create_menu_item_with_mnemonic(camera_menu, "Look Through Camera", "LookThroughCamera");
2102 menu_separator(menu);
2104 GtkMenu* orthographic_menu = create_sub_menu_with_mnemonic(menu, "Orthographic");
2105 if (g_Layout_enableDetachableMenus.m_value)
2106 menu_tearoff (orthographic_menu);
2107 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating)
2109 create_menu_item_with_mnemonic(orthographic_menu, "_Next (XY, YZ, XY)", "NextView");
2110 create_menu_item_with_mnemonic(orthographic_menu, "XY (Top)", "ViewTop");
2111 create_menu_item_with_mnemonic(orthographic_menu, "YZ", "ViewSide");
2112 create_menu_item_with_mnemonic(orthographic_menu, "XZ", "ViewFront");
2113 menu_separator(orthographic_menu);
2116 create_menu_item_with_mnemonic(orthographic_menu, "_XY 100%", "Zoom100");
2117 create_menu_item_with_mnemonic(orthographic_menu, "XY Zoom _In", "ZoomIn");
2118 create_menu_item_with_mnemonic(orthographic_menu, "XY Zoom _Out", "ZoomOut");
2121 menu_separator(menu);
2124 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Show");
2125 if (g_Layout_enableDetachableMenus.m_value)
2126 menu_tearoff (menu_in_menu);
2127 create_check_menu_item_with_mnemonic(menu_in_menu, "Show _Angles", "ShowAngles");
2128 create_check_menu_item_with_mnemonic(menu_in_menu, "Show _Names", "ShowNames");
2129 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Blocks", "ShowBlocks");
2130 create_check_menu_item_with_mnemonic(menu_in_menu, "Show C_oordinates", "ShowCoordinates");
2131 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Window Outline", "ShowWindowOutline");
2132 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Axes", "ShowAxes");
2133 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Workzone", "ShowWorkzone");
2134 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Stats", "ShowStats");
2138 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Filter");
2139 if (g_Layout_enableDetachableMenus.m_value)
2140 menu_tearoff (menu_in_menu);
2141 Filters_constructMenu(menu_in_menu);
2143 menu_separator(menu);
2145 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Hide/Show");
2146 if (g_Layout_enableDetachableMenus.m_value)
2147 menu_tearoff (menu_in_menu);
2148 create_menu_item_with_mnemonic(menu_in_menu, "Hide Selected", "HideSelected");
2149 create_menu_item_with_mnemonic(menu_in_menu, "Show Hidden", "ShowHidden");
2151 menu_separator(menu);
2153 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Region");
2154 if (g_Layout_enableDetachableMenus.m_value)
2155 menu_tearoff (menu_in_menu);
2156 create_menu_item_with_mnemonic(menu_in_menu, "_Off", "RegionOff");
2157 create_menu_item_with_mnemonic(menu_in_menu, "_Set XY", "RegionSetXY");
2158 create_menu_item_with_mnemonic(menu_in_menu, "Set _Brush", "RegionSetBrush");
2159 create_menu_item_with_mnemonic(menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection");
2162 command_connect_accelerator("CenterXYView");
2164 return view_menu_item;
2167 GtkMenuItem* create_selection_menu()
2170 GtkMenuItem* selection_menu_item = new_sub_menu_item_with_mnemonic("M_odify");
2171 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(selection_menu_item));
2172 if (g_Layout_enableDetachableMenus.m_value)
2173 menu_tearoff (menu);
2176 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Components");
2177 if (g_Layout_enableDetachableMenus.m_value)
2178 menu_tearoff (menu_in_menu);
2179 create_check_menu_item_with_mnemonic(menu_in_menu, "_Edges", "DragEdges");
2180 create_check_menu_item_with_mnemonic(menu_in_menu, "_Vertices", "DragVertices");
2181 create_check_menu_item_with_mnemonic(menu_in_menu, "_Faces", "DragFaces");
2184 menu_separator(menu);
2187 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic(menu, "Nudge");
2188 if (g_Layout_enableDetachableMenus.m_value)
2189 menu_tearoff (menu_in_menu);
2190 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Left", "SelectNudgeLeft");
2191 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Right", "SelectNudgeRight");
2192 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Up", "SelectNudgeUp");
2193 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Down", "SelectNudgeDown");
2196 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Rotate");
2197 if (g_Layout_enableDetachableMenus.m_value)
2198 menu_tearoff (menu_in_menu);
2199 create_menu_item_with_mnemonic(menu_in_menu, "Rotate X", "RotateSelectionX");
2200 create_menu_item_with_mnemonic(menu_in_menu, "Rotate Y", "RotateSelectionY");
2201 create_menu_item_with_mnemonic(menu_in_menu, "Rotate Z", "RotateSelectionZ");
2204 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Flip");
2205 if (g_Layout_enableDetachableMenus.m_value)
2206 menu_tearoff (menu_in_menu);
2207 create_menu_item_with_mnemonic(menu_in_menu, "Flip _X", "MirrorSelectionX");
2208 create_menu_item_with_mnemonic(menu_in_menu, "Flip _Y", "MirrorSelectionY");
2209 create_menu_item_with_mnemonic(menu_in_menu, "Flip _Z", "MirrorSelectionZ");
2211 menu_separator(menu);
2212 create_menu_item_with_mnemonic(menu, "Arbitrary rotation...", "ArbitraryRotation");
2213 create_menu_item_with_mnemonic(menu, "Arbitrary scale...", "ArbitraryScale");
2215 return selection_menu_item;
2218 GtkMenuItem* create_bsp_menu()
2221 GtkMenuItem* bsp_menu_item = new_sub_menu_item_with_mnemonic("_Build");
2222 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(bsp_menu_item));
2224 if (g_Layout_enableDetachableMenus.m_value)
2229 create_menu_item_with_mnemonic(menu, "Customize...", "BuildMenuCustomize");
2231 menu_separator(menu);
2233 Build_constructMenu(menu);
2237 return bsp_menu_item;
2240 GtkMenuItem* create_grid_menu()
2243 GtkMenuItem* grid_menu_item = new_sub_menu_item_with_mnemonic("_Grid");
2244 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(grid_menu_item));
2245 if (g_Layout_enableDetachableMenus.m_value)
2246 menu_tearoff (menu);
2248 Grid_constructMenu(menu);
2250 return grid_menu_item;
2253 GtkMenuItem* create_misc_menu()
2256 GtkMenuItem* misc_menu_item = new_sub_menu_item_with_mnemonic("M_isc");
2257 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(misc_menu_item));
2258 if (g_Layout_enableDetachableMenus.m_value)
2259 menu_tearoff (menu);
2262 create_menu_item_with_mnemonic(menu, "_Benchmark", FreeCaller<GlobalCamera_Benchmark>());
2264 gtk_container_add(GTK_CONTAINER(menu), GTK_WIDGET(create_colours_menu()));
2266 create_menu_item_with_mnemonic(menu, "Find brush...", "FindBrush");
2267 create_menu_item_with_mnemonic(menu, "Map Info...", "MapInfo");
2268 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2269 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<WXY_Print>());
2270 create_menu_item_with_mnemonic(menu, "_Background select", FreeCaller<WXY_BackgroundSelect>());
2271 return misc_menu_item;
2274 GtkMenuItem* create_entity_menu()
2277 GtkMenuItem* entity_menu_item = new_sub_menu_item_with_mnemonic("E_ntity");
2278 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(entity_menu_item));
2279 if (g_Layout_enableDetachableMenus.m_value)
2280 menu_tearoff (menu);
2282 Entity_constructMenu(menu);
2284 return entity_menu_item;
2287 GtkMenuItem* create_brush_menu()
2290 GtkMenuItem* brush_menu_item = new_sub_menu_item_with_mnemonic("B_rush");
2291 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(brush_menu_item));
2292 if (g_Layout_enableDetachableMenus.m_value)
2293 menu_tearoff (menu);
2295 Brush_constructMenu(menu);
2297 return brush_menu_item;
2300 GtkMenuItem* create_patch_menu()
2303 GtkMenuItem* patch_menu_item = new_sub_menu_item_with_mnemonic("_Curve");
2304 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(patch_menu_item));
2305 if (g_Layout_enableDetachableMenus.m_value)
2310 Patch_constructMenu(menu);
2312 return patch_menu_item;
2315 GtkMenuItem* create_help_menu()
2318 GtkMenuItem* help_menu_item = new_sub_menu_item_with_mnemonic("_Help");
2319 GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(help_menu_item));
2320 if (g_Layout_enableDetachableMenus.m_value)
2321 menu_tearoff (menu);
2323 create_menu_item_with_mnemonic(menu, "Manual", "OpenManual");
2325 // this creates all the per-game drop downs for the game pack helps
2326 // it will take care of hooking the Sys_OpenURL calls etc.
2327 create_game_help_menu(menu);
2329 create_menu_item_with_mnemonic(menu, "Bug report", FreeCaller<OpenBugReportURL>());
2330 create_menu_item_with_mnemonic(menu, "Shortcuts list", FreeCaller<DoCommandListDlg>());
2331 create_menu_item_with_mnemonic(menu, "_About", FreeCaller<DoAbout>());
2333 return help_menu_item;
2336 GtkMenuBar* create_main_menu(MainFrame::EViewStyle style)
2338 GtkMenuBar* menu_bar = GTK_MENU_BAR(gtk_menu_bar_new());
2339 gtk_widget_show(GTK_WIDGET(menu_bar));
2341 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_file_menu()));
2342 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_edit_menu()));
2343 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_view_menu(style)));
2344 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_selection_menu()));
2345 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_bsp_menu()));
2346 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_grid_menu()));
2347 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_misc_menu()));
2348 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_entity_menu()));
2349 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_brush_menu()));
2350 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_patch_menu()));
2351 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_plugins_menu()));
2352 gtk_container_add(GTK_CONTAINER(menu_bar), GTK_WIDGET(create_help_menu()));
2358 void PatchInspector_registerShortcuts()
2360 command_connect_accelerator("PatchInspector");
2363 void Patch_registerShortcuts()
2365 command_connect_accelerator("InvertCurveTextureX");
2366 command_connect_accelerator("InvertCurveTextureY");
2367 command_connect_accelerator("IncPatchColumn");
2368 command_connect_accelerator("IncPatchRow");
2369 command_connect_accelerator("DecPatchColumn");
2370 command_connect_accelerator("DecPatchRow");
2371 command_connect_accelerator("NaturalizePatch");
2372 //command_connect_accelerator("CapCurrentCurve");
2375 void Manipulators_registerShortcuts()
2377 toggle_add_accelerator("MouseRotate");
2378 toggle_add_accelerator("MouseTranslate");
2379 toggle_add_accelerator("MouseScale");
2380 toggle_add_accelerator("MouseDrag");
2381 toggle_add_accelerator("ToggleClipper");
2384 void TexdefNudge_registerShortcuts()
2386 command_connect_accelerator("TexRotateClock");
2387 command_connect_accelerator("TexRotateCounter");
2388 command_connect_accelerator("TexScaleUp");
2389 command_connect_accelerator("TexScaleDown");
2390 command_connect_accelerator("TexScaleLeft");
2391 command_connect_accelerator("TexScaleRight");
2392 command_connect_accelerator("TexShiftUp");
2393 command_connect_accelerator("TexShiftDown");
2394 command_connect_accelerator("TexShiftLeft");
2395 command_connect_accelerator("TexShiftRight");
2398 void SelectNudge_registerShortcuts()
2400 command_connect_accelerator("MoveSelectionDOWN");
2401 command_connect_accelerator("MoveSelectionUP");
2402 //command_connect_accelerator("SelectNudgeLeft");
2403 //command_connect_accelerator("SelectNudgeRight");
2404 //command_connect_accelerator("SelectNudgeUp");
2405 //command_connect_accelerator("SelectNudgeDown");
2408 void SnapToGrid_registerShortcuts()
2410 command_connect_accelerator("SnapToGrid");
2413 void SelectByType_registerShortcuts()
2415 command_connect_accelerator("SelectAllOfType");
2418 void SurfaceInspector_registerShortcuts()
2420 command_connect_accelerator("FitTexture");
2424 void register_shortcuts()
2426 PatchInspector_registerShortcuts();
2427 Patch_registerShortcuts();
2428 Grid_registerShortcuts();
2429 XYWnd_registerShortcuts();
2430 CamWnd_registerShortcuts();
2431 Manipulators_registerShortcuts();
2432 SurfaceInspector_registerShortcuts();
2433 TexdefNudge_registerShortcuts();
2434 SelectNudge_registerShortcuts();
2435 SnapToGrid_registerShortcuts();
2436 SelectByType_registerShortcuts();
2439 void File_constructToolbar(GtkToolbar* toolbar)
2441 toolbar_append_button(toolbar, "Open an existing map (CTRL + O)", "file_open.bmp", "OpenMap");
2442 toolbar_append_button(toolbar, "Save the active map (CTRL + S)", "file_save.bmp", "SaveMap");
2445 void UndoRedo_constructToolbar(GtkToolbar* toolbar)
2447 toolbar_append_button(toolbar, "Undo (CTRL + Z)", "undo.bmp", "Undo");
2448 toolbar_append_button(toolbar, "Redo (CTRL + Y)", "redo.bmp", "Redo");
2451 void RotateFlip_constructToolbar(GtkToolbar* toolbar)
2453 toolbar_append_button(toolbar, "x-axis Flip", "brush_flipx.bmp", "MirrorSelectionX");
2454 toolbar_append_button(toolbar, "x-axis Rotate", "brush_rotatex.bmp", "RotateSelectionX");
2455 toolbar_append_button(toolbar, "y-axis Flip", "brush_flipy.bmp", "MirrorSelectionY");
2456 toolbar_append_button(toolbar, "y-axis Rotate", "brush_rotatey.bmp", "RotateSelectionY");
2457 toolbar_append_button(toolbar, "z-axis Flip", "brush_flipz.bmp", "MirrorSelectionZ");
2458 toolbar_append_button(toolbar, "z-axis Rotate", "brush_rotatez.bmp", "RotateSelectionZ");
2461 void Select_constructToolbar(GtkToolbar* toolbar)
2463 toolbar_append_button(toolbar, "Select touching", "selection_selecttouching.bmp", "SelectTouching");
2464 toolbar_append_button(toolbar, "Select inside", "selection_selectinside.bmp", "SelectInside");
2467 void CSG_constructToolbar(GtkToolbar* toolbar)
2469 toolbar_append_button(toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.bmp", "CSGSubtract");
2470 toolbar_append_button(toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.bmp", "CSGMerge");
2471 toolbar_append_button(toolbar, "Hollow", "selection_makehollow.bmp", "CSGHollow");
2474 void ComponentModes_constructToolbar(GtkToolbar* toolbar)
2476 toolbar_append_toggle_button(toolbar, "Select Vertices (V)", "modify_vertices.bmp", "DragVertices");
2477 toolbar_append_toggle_button(toolbar, "Select Edges (E)", "modify_edges.bmp", "DragEdges");
2478 toolbar_append_toggle_button(toolbar, "Select Faces (F)", "modify_faces.bmp", "DragFaces");
2481 void Clipper_constructToolbar(GtkToolbar* toolbar)
2484 toolbar_append_toggle_button(toolbar, "Clipper (X)", "view_clipper.bmp", "ToggleClipper");
2487 void XYWnd_constructToolbar(GtkToolbar* toolbar)
2489 toolbar_append_button(toolbar, "Change views", "view_change.bmp", "NextView");
2492 void Manipulators_constructToolbar(GtkToolbar* toolbar)
2494 toolbar_append_toggle_button(toolbar, "Translate (W)", "select_mousetranslate.bmp", "MouseTranslate");
2495 toolbar_append_toggle_button(toolbar, "Rotate (R)", "select_mouserotate.bmp", "MouseRotate");
2496 toolbar_append_toggle_button(toolbar, "Scale", "select_mousescale.bmp", "MouseScale");
2497 toolbar_append_toggle_button(toolbar, "Resize (Q)", "select_mouseresize.bmp", "MouseDrag");
2499 Clipper_constructToolbar(toolbar);
2502 GtkToolbar* create_main_toolbar(MainFrame::EViewStyle style)
2504 GtkToolbar* toolbar = GTK_TOOLBAR(gtk_toolbar_new());
2505 gtk_toolbar_set_orientation(toolbar, GTK_ORIENTATION_HORIZONTAL);
2506 gtk_toolbar_set_style(toolbar, GTK_TOOLBAR_ICONS);
2508 gtk_widget_show(GTK_WIDGET(toolbar));
2510 File_constructToolbar(toolbar);
2512 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2514 UndoRedo_constructToolbar(toolbar);
2516 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2518 RotateFlip_constructToolbar(toolbar);
2520 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2522 Select_constructToolbar(toolbar);
2524 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2526 CSG_constructToolbar(toolbar);
2528 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2530 ComponentModes_constructToolbar(toolbar);
2532 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating)
2534 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2536 XYWnd_constructToolbar(toolbar);
2539 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2541 CamWnd_constructToolbar(toolbar);
2543 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2545 Manipulators_constructToolbar(toolbar);
2547 if (g_Layout_enablePatchToolbar.m_value)
2549 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2551 Patch_constructToolbar(toolbar);
2554 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2556 toolbar_append_toggle_button(toolbar, "Texture Lock (SHIFT +T)", "texture_lock.bmp", "TogTexLock");
2558 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2560 GtkButton* g_view_entities_button = toolbar_append_button(toolbar, "Entities (N)", "entities.bmp", "ToggleEntityInspector");
2561 GtkButton* g_view_console_button = toolbar_append_button(toolbar, "Console (O)", "console.bmp", "ToggleConsole");
2562 GtkButton* g_view_textures_button = toolbar_append_button(toolbar, "Texture Browser (T)", "texture_browser.bmp", "ToggleTextures");
2563 // TODO: call light inspector
2564 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.bmp", "ToggleLightInspector");
2566 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
2567 GtkButton* g_refresh_models_button = toolbar_append_button(toolbar, "Refresh Models", "refresh_models.bmp", "RefreshReferences");
2570 // disable the console and texture button in the regular layouts
2571 if(style == MainFrame::eRegular || style == MainFrame::eRegularLeft)
2573 gtk_widget_set_sensitive(GTK_WIDGET(g_view_console_button), FALSE);
2574 gtk_widget_set_sensitive(GTK_WIDGET(g_view_textures_button), FALSE);
2580 GtkWidget* create_main_statusbar(GtkWidget *pStatusLabel[c_count_status])
2582 GtkTable* table = GTK_TABLE(gtk_table_new(1, c_count_status, FALSE));
2583 gtk_widget_show(GTK_WIDGET(table));
2586 GtkLabel* label = GTK_LABEL(gtk_label_new ("Label"));
2587 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
2588 gtk_misc_set_padding(GTK_MISC(label), 4, 2);
2589 gtk_widget_show(GTK_WIDGET(label));
2590 gtk_table_attach_defaults(table, GTK_WIDGET(label), 0, 1, 0, 1);
2591 pStatusLabel[c_command_status] = GTK_WIDGET(label);
2594 for(int i = 1; i < c_count_status; ++i)
2596 GtkFrame* frame = GTK_FRAME(gtk_frame_new(0));
2597 gtk_widget_show(GTK_WIDGET(frame));
2598 gtk_table_attach_defaults(table, GTK_WIDGET(frame), i, i + 1, 0, 1);
2599 gtk_frame_set_shadow_type(frame, GTK_SHADOW_IN);
2601 GtkLabel* label = GTK_LABEL(gtk_label_new ("Label"));
2602 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END);
2603 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
2604 gtk_misc_set_padding(GTK_MISC(label), 4, 2);
2605 gtk_widget_show(GTK_WIDGET(label));
2606 gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(label));
2607 pStatusLabel[i] = GTK_WIDGET(label);
2610 return GTK_WIDGET(table);
2616 WidgetFocusPrinter g_mainframeWidgetFocusPrinter("mainframe");
2618 class WindowFocusPrinter
2622 static gboolean frame_event(GtkWidget *widget, GdkEvent* event, WindowFocusPrinter* self)
2624 globalOutputStream() << self->m_name << " frame_event\n";
2627 static gboolean keys_changed(GtkWidget *widget, WindowFocusPrinter* self)
2629 globalOutputStream() << self->m_name << " keys_changed\n";
2632 static gboolean notify(GtkWindow* window, gpointer dummy, WindowFocusPrinter* self)
2634 if(gtk_window_is_active(window))
2636 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2640 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2645 WindowFocusPrinter(const char* name) : m_name(name)
2648 void connect(GtkWindow* toplevel_window)
2650 g_signal_connect(G_OBJECT(toplevel_window), "notify::has_toplevel_focus", G_CALLBACK(notify), this);
2651 g_signal_connect(G_OBJECT(toplevel_window), "notify::is_active", G_CALLBACK(notify), this);
2652 g_signal_connect(G_OBJECT(toplevel_window), "keys_changed", G_CALLBACK(keys_changed), this);
2653 g_signal_connect(G_OBJECT(toplevel_window), "frame_event", G_CALLBACK(frame_event), this);
2657 WindowFocusPrinter g_mainframeFocusPrinter("mainframe");
2661 class MainWindowActive
2663 static gboolean notify(GtkWindow* window, gpointer dummy, MainWindowActive* self)
2665 if(g_wait.m_window != 0 && gtk_window_is_active(window) && !GTK_WIDGET_VISIBLE(g_wait.m_window))
2667 gtk_widget_show(GTK_WIDGET(g_wait.m_window));
2673 void connect(GtkWindow* toplevel_window)
2675 g_signal_connect(G_OBJECT(toplevel_window), "notify::is-active", G_CALLBACK(notify), this);
2679 MainWindowActive g_MainWindowActive;
2681 SignalHandlerId XYWindowDestroyed_connect(const SignalHandler& handler)
2683 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst(handler);
2686 void XYWindowDestroyed_disconnect(SignalHandlerId id)
2688 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect(id);
2691 MouseEventHandlerId XYWindowMouseDown_connect(const MouseEventHandler& handler)
2693 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst(handler);
2696 void XYWindowMouseDown_disconnect(MouseEventHandlerId id)
2698 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect(id);
2701 // =============================================================================
2704 MainFrame* g_pParentWnd = 0;
2706 GtkWindow* MainFrame_getWindow()
2708 if(g_pParentWnd == 0)
2712 return g_pParentWnd->m_window;
2715 std::vector<GtkWidget*> g_floating_windows;
2717 MainFrame::MainFrame() : m_window(0), m_idleRedrawStatusText(RedrawStatusTextCaller(*this))
2726 for (int n = 0;n < c_count_status;n++)
2728 m_pStatusLabel[n] = 0;
2731 m_bSleeping = false;
2736 MainFrame::~MainFrame()
2740 gtk_widget_hide(GTK_WIDGET(m_window));
2744 for(std::vector<GtkWidget*>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i)
2746 gtk_widget_destroy(*i);
2749 gtk_widget_destroy(GTK_WIDGET(m_window));
2752 void MainFrame::SetActiveXY(XYWnd* p)
2755 m_pActiveXY->SetActive(false);
2760 m_pActiveXY->SetActive(true);
2764 void MainFrame::ReleaseContexts()
2768 m_pXYWnd->DestroyContext();
2770 m_pYZWnd->DestroyContext();
2772 m_pXZWnd->DestroyContext();
2774 m_pCamWnd->DestroyContext();
2776 m_pTexWnd->DestroyContext();
2778 m_pZWnd->DestroyContext();
2782 void MainFrame::CreateContexts()
2786 m_pCamWnd->CreateContext();
2788 m_pXYWnd->CreateContext();
2790 m_pYZWnd->CreateContext();
2792 m_pXZWnd->CreateContext();
2794 m_pTexWnd->CreateContext();
2796 m_pZWnd->CreateContext();
2804 void MainFrame::OnSleep()
2810 // useful when trying to debug crashes in the sleep code
2811 globalOutputStream() << "Going into sleep mode..\n";
2813 globalOutputStream() << "Dispatching sleep msg...";
2814 DispatchRadiantMsg (RADIANT_SLEEP);
2815 globalOutputStream() << "Done.\n";
2817 gtk_window_iconify(m_window);
2818 GlobalSelectionSystem().setSelectedAll(false);
2820 GlobalShaderCache().unrealise();
2822 GlobalOpenGL_debugAssertNoErrors();
2823 ScreenUpdates_Disable();
2826 globalOutputStream() << "Releasing contexts...";
2828 globalOutputStream() << "Done.\n";
2832 globalOutputStream() << "Waking up\n";
2834 gtk_window_deiconify(m_window);
2837 globalOutputStream() << "Creating contexts...";
2839 globalOutputStream() << "Done.\n";
2841 globalOutputStream() << "Making current on camera...";
2842 m_pCamWnd->MakeCurrent();
2843 globalOutputStream() << "Done.\n";
2845 globalOutputStream() << "Reloading shaders...";
2847 GlobalShaderCache().realise();
2848 globalOutputStream() << "Done.\n";
2850 ScreenUpdates_Enable();
2852 globalOutputStream() << "Dispatching wake msg...";
2853 DispatchRadiantMsg (RADIANT_WAKEUP);
2854 globalOutputStream() << "Done\n";
2860 GtkWindow* create_splash()
2862 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
2863 gtk_window_set_decorated(window, FALSE);
2864 gtk_window_set_resizable(window, FALSE);
2865 gtk_window_set_modal(window, TRUE);
2866 gtk_window_set_default_size(window, -1, -1);
2867 gtk_window_set_position(window, GTK_WIN_POS_CENTER);
2868 gtk_container_set_border_width(GTK_CONTAINER(window), 0);
2870 GtkImage* image = new_local_image("splash.bmp");
2871 gtk_widget_show(GTK_WIDGET(image));
2872 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(image));
2874 gtk_widget_set_size_request(GTK_WIDGET(window), -1, -1);
2875 gtk_widget_show(GTK_WIDGET(window));
2880 static GtkWindow *splash_screen = 0;
2884 splash_screen = create_splash();
2891 gtk_widget_destroy(GTK_WIDGET(splash_screen));
2894 WindowPositionTracker g_posCamWnd;
2895 WindowPositionTracker g_posXYWnd;
2896 WindowPositionTracker g_posXZWnd;
2897 WindowPositionTracker g_posYZWnd;
2899 static gint mainframe_delete (GtkWidget *widget, GdkEvent *event, gpointer data)
2901 if(ConfirmModified("Exit Radiant"))
2909 void MainFrame::Create()
2911 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
2913 GlobalWindowObservers_connectTopLevel(window);
2915 gtk_window_set_transient_for(splash_screen, window);
2919 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask("bitmaps/icon.bmp");
2922 gtk_window_set_icon(window, pixbuf);
2923 gdk_pixbuf_unref(pixbuf);
2928 gtk_widget_add_events(GTK_WIDGET(window), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK);
2929 g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(mainframe_delete), this);
2931 m_position_tracker.connect(window);
2934 g_mainframeWidgetFocusPrinter.connect(window);
2935 g_mainframeFocusPrinter.connect(window);
2938 g_MainWindowActive.connect(window);
2940 GetPlugInMgr().Init(GTK_WIDGET(window));
2942 GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
2943 gtk_container_add(GTK_CONTAINER(window), vbox);
2944 gtk_widget_show(vbox);
2946 global_accel_connect_window(window);
2948 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
2950 register_shortcuts();
2952 GtkMenuBar* main_menu = create_main_menu(CurrentStyle());
2953 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(main_menu), FALSE, FALSE, 0);
2955 GtkToolbar* main_toolbar = create_main_toolbar(CurrentStyle());
2956 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(main_toolbar), FALSE, FALSE, 0);
2958 GtkToolbar* plugin_toolbar = create_plugin_toolbar();
2959 if (!g_Layout_enablePluginToolbar.m_value)
2961 gtk_widget_hide(GTK_WIDGET(plugin_toolbar));
2963 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(plugin_toolbar), FALSE, FALSE, 0);
2965 GtkWidget* main_statusbar = create_main_statusbar(m_pStatusLabel);
2966 gtk_box_pack_end(GTK_BOX(vbox), main_statusbar, FALSE, TRUE, 2);
2968 GroupDialog_constructWindow(window);
2969 g_page_entity = GroupDialog_addPage("Entities", EntityInspector_constructWindow(GroupDialog_getWindow()), RawStringExportCaller("Entities"));
2971 if(FloatingGroupDialog())
2973 g_page_console = GroupDialog_addPage("Console", Console_constructWindow(GroupDialog_getWindow()), RawStringExportCaller("Console"));
2977 if( g_multimon_globals.m_bStartOnPrimMon )
2979 PositionWindowOnPrimaryScreen(g_layout_globals.m_position);
2980 window_set_position(window, g_layout_globals.m_position);
2984 if(g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED)
2986 gtk_window_maximize(window);
2987 WindowPosition default_position(-1, -1, 640, 480);
2988 window_set_position(window, default_position);
2992 window_set_position(window, g_layout_globals.m_position);
2997 gtk_widget_show(GTK_WIDGET(window));
2999 if (CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft)
3002 GtkWidget* vsplit = gtk_vpaned_new();
3004 gtk_box_pack_start(GTK_BOX(vbox), vsplit, TRUE, TRUE, 0);
3005 gtk_widget_show (vsplit);
3008 GtkWidget* console_window = Console_constructWindow(window);
3009 gtk_paned_pack2(GTK_PANED(vsplit), console_window, FALSE, TRUE);
3012 GtkWidget* hsplit = gtk_hpaned_new();
3013 gtk_widget_show (hsplit);
3015 gtk_paned_add1(GTK_PANED(vsplit), hsplit);
3018 m_pXYWnd = new XYWnd();
3019 m_pXYWnd->SetViewType(XY);
3020 GtkWidget* xy_window = GTK_WIDGET(create_framed_widget(m_pXYWnd->GetWidget()));
3023 GtkWidget* vsplit2 = gtk_vpaned_new();
3024 gtk_widget_show(vsplit2);
3025 m_vSplit2 = vsplit2;
3027 if (CurrentStyle() == eRegular)
3029 gtk_paned_add1(GTK_PANED(hsplit), xy_window);
3030 gtk_paned_add2(GTK_PANED(hsplit), vsplit2);
3034 gtk_paned_add1(GTK_PANED(hsplit), vsplit2);
3035 gtk_paned_add2(GTK_PANED(hsplit), xy_window);
3040 m_pCamWnd = NewCamWnd();
3041 GlobalCamera_setCamWnd(*m_pCamWnd);
3042 CamWnd_setParent(*m_pCamWnd, window);
3043 GtkFrame* camera_window = create_framed_widget(CamWnd_getWidget(*m_pCamWnd));
3045 gtk_paned_add1(GTK_PANED(vsplit2), GTK_WIDGET(camera_window));
3048 GtkFrame* texture_window = create_framed_widget(TextureBrowser_constructWindow(window));
3050 gtk_paned_add2(GTK_PANED(vsplit2), GTK_WIDGET(texture_window));
3055 gtk_paned_set_position(GTK_PANED(m_vSplit), g_layout_globals.nXYHeight);
3057 if (CurrentStyle() == eRegular)
3059 gtk_paned_set_position(GTK_PANED(m_hSplit), g_layout_globals.nXYWidth);
3063 gtk_paned_set_position(GTK_PANED(m_hSplit), g_layout_globals.nCamWidth);
3066 gtk_paned_set_position(GTK_PANED(m_vSplit2), g_layout_globals.nCamHeight);
3068 else if (CurrentStyle() == eFloating)
3071 GtkWindow* window = create_persistent_floating_window("Camera", m_window);
3072 global_accel_connect_window(window);
3073 g_posCamWnd.connect(window);
3075 gtk_widget_show(GTK_WIDGET(window));
3077 m_pCamWnd = NewCamWnd();
3078 GlobalCamera_setCamWnd(*m_pCamWnd);
3081 GtkFrame* frame = create_framed_widget(CamWnd_getWidget(*m_pCamWnd));
3082 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3084 CamWnd_setParent(*m_pCamWnd, window);
3086 g_floating_windows.push_back(GTK_WIDGET(window));
3090 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(XY), m_window);
3091 global_accel_connect_window(window);
3092 g_posXYWnd.connect(window);
3094 m_pXYWnd = new XYWnd();
3095 m_pXYWnd->m_parent = window;
3096 m_pXYWnd->SetViewType(XY);
3100 GtkFrame* frame = create_framed_widget(m_pXYWnd->GetWidget());
3101 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3103 XY_Top_Shown_Construct(window);
3105 g_floating_windows.push_back(GTK_WIDGET(window));
3109 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(XZ), m_window);
3110 global_accel_connect_window(window);
3111 g_posXZWnd.connect(window);
3113 m_pXZWnd = new XYWnd();
3114 m_pXZWnd->m_parent = window;
3115 m_pXZWnd->SetViewType(XZ);
3118 GtkFrame* frame = create_framed_widget(m_pXZWnd->GetWidget());
3119 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3122 XZ_Front_Shown_Construct(window);
3124 g_floating_windows.push_back(GTK_WIDGET(window));
3128 GtkWindow* window = create_persistent_floating_window(ViewType_getTitle(YZ), m_window);
3129 global_accel_connect_window(window);
3130 g_posYZWnd.connect(window);
3132 m_pYZWnd = new XYWnd();
3133 m_pYZWnd->m_parent = window;
3134 m_pYZWnd->SetViewType(YZ);
3137 GtkFrame* frame = create_framed_widget(m_pYZWnd->GetWidget());
3138 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(frame));
3141 YZ_Side_Shown_Construct(window);
3143 g_floating_windows.push_back(GTK_WIDGET(window));
3147 GtkFrame* frame = create_framed_widget(TextureBrowser_constructWindow(GroupDialog_getWindow()));
3148 g_page_textures = GroupDialog_addPage("Textures", GTK_WIDGET(frame), TextureBrowserExportTitleCaller());
3155 m_pCamWnd = NewCamWnd();
3156 GlobalCamera_setCamWnd(*m_pCamWnd);
3157 CamWnd_setParent(*m_pCamWnd, window);
3159 GtkWidget* camera = CamWnd_getWidget(*m_pCamWnd);
3161 m_pYZWnd = new XYWnd();
3162 m_pYZWnd->SetViewType(YZ);
3164 GtkWidget* yz = m_pYZWnd->GetWidget();
3166 m_pXYWnd = new XYWnd();
3167 m_pXYWnd->SetViewType(XY);
3169 GtkWidget* xy = m_pXYWnd->GetWidget();
3171 m_pXZWnd = new XYWnd();
3172 m_pXZWnd->SetViewType(XZ);
3174 GtkWidget* xz = m_pXZWnd->GetWidget();
3176 GtkHPaned* split = create_split_views(camera, yz, xy, xz);
3177 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(split), TRUE, TRUE, 0);
3180 GtkFrame* frame = create_framed_widget(TextureBrowser_constructWindow(window));
3181 g_page_textures = GroupDialog_addPage("Textures", GTK_WIDGET(frame), TextureBrowserExportTitleCaller());
3185 EntityList_constructWindow(window);
3186 PreferencesDialog_constructWindow(window);
3187 FindTextureDialog_constructWindow(window);
3188 SurfaceInspector_constructWindow(window);
3189 PatchInspector_constructWindow(window);
3191 SetActiveXY(m_pXYWnd);
3193 AddGridChangeCallback(SetGridStatusCaller(*this));
3194 AddGridChangeCallback(ReferenceCaller<MainFrame, XY_UpdateAllWindows>(*this));
3196 g_defaultToolMode = DragMode;
3197 g_defaultToolMode();
3198 SetStatusText(m_command_status, c_TranslateMode_status);
3200 EverySecondTimer_enable();
3202 //GlobalShortcuts_reportUnregistered();
3205 void MainFrame::SaveWindowInfo()
3207 if (!FloatingGroupDialog())
3209 g_layout_globals.nXYHeight = gtk_paned_get_position(GTK_PANED(m_vSplit));
3211 if(CurrentStyle() != eRegular)
3213 g_layout_globals.nCamWidth = gtk_paned_get_position(GTK_PANED(m_hSplit));
3217 g_layout_globals.nXYWidth = gtk_paned_get_position(GTK_PANED(m_hSplit));
3220 g_layout_globals.nCamHeight = gtk_paned_get_position(GTK_PANED(m_vSplit2));
3223 g_layout_globals.m_position = m_position_tracker.getPosition();
3225 g_layout_globals.nState = gdk_window_get_state(GTK_WIDGET(m_window)->window);
3228 void MainFrame::Shutdown()
3230 EverySecondTimer_disable();
3232 EntityList_destroyWindow();
3241 TextureBrowser_destroyWindow();
3243 DeleteCamWnd(m_pCamWnd);
3246 PreferencesDialog_destroyWindow();
3247 SurfaceInspector_destroyWindow();
3248 FindTextureDialog_destroyWindow();
3249 PatchInspector_destroyWindow();
3251 g_DbgDlg.destroyWindow();
3253 // destroying group-dialog last because it may contain texture-browser
3254 GroupDialog_destroyWindow();
3257 void MainFrame::RedrawStatusText()
3259 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_command_status]), m_command_status.c_str());
3260 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_position_status]), m_position_status.c_str());
3261 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_brushcount_status]), m_brushcount_status.c_str());
3262 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_texture_status]), m_texture_status.c_str());
3263 gtk_label_set_text(GTK_LABEL(m_pStatusLabel[c_grid_status]), m_grid_status.c_str());
3266 void MainFrame::UpdateStatusText()
3268 m_idleRedrawStatusText.queueDraw();
3271 void MainFrame::SetStatusText(CopiedString& status_text, const char* pText)
3273 status_text = pText;
3277 void Sys_Status(const char* status)
3279 if(g_pParentWnd != 0)
3281 g_pParentWnd->SetStatusText (g_pParentWnd->m_command_status, status);
3285 int getRotateIncrement()
3287 return static_cast<int>(g_si_globals.rotate);
3290 int getFarClipDistance()
3292 return g_camwindow_globals.m_nCubicScale;
3295 float (*GridStatus_getGridSize)() = GetGridSize;
3296 int (*GridStatus_getRotateIncrement)() = getRotateIncrement;
3297 int (*GridStatus_getFarClipDistance)() = getFarClipDistance;
3298 bool (*GridStatus_getTextureLockEnabled)();
3300 void MainFrame::SetGridStatus()
3302 StringOutputStream status(64);
3303 const char* lock = (GridStatus_getTextureLockEnabled()) ? "ON" : "OFF";
3304 status << (GetSnapGridSize() > 0 ? "G:" : "g:") << GridStatus_getGridSize()
3305 << " R:" << GridStatus_getRotateIncrement()
3306 << " C:" << GridStatus_getFarClipDistance()
3308 SetStatusText(m_grid_status, status.c_str());
3311 void GridStatus_onTextureLockEnabledChanged()
3313 if(g_pParentWnd != 0)
3315 g_pParentWnd->SetGridStatus();
3321 GLFont g_font(0, 0, 0, 0);
3324 void GlobalGL_sharedContextCreated()
3326 // report OpenGL information
3327 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>(glGetString (GL_VENDOR)) << "\n";
3328 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>(glGetString (GL_RENDERER)) << "\n";
3329 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>(glGetString (GL_VERSION)) << "\n";
3330 globalOutputStream() << "GL_EXTENSIONS: " << reinterpret_cast<const char*>(glGetString (GL_EXTENSIONS)) << "\n";
3332 QGL_sharedContextCreated(GlobalOpenGL());
3334 ShaderCache_extensionsInitialised();
3336 GlobalShaderCache().realise();
3340 /* win32 is dodgy here, just use courier new then */
3341 g_font = glfont_create("courier new 8");
3343 /* use default font here (Sans 10 is gtk default) */
3344 GtkSettings *settings = gtk_settings_get_default();
3346 g_object_get(settings, "gtk-font-name", &fontname, NULL);
3347 g_font = glfont_create(fontname);
3350 GlobalOpenGL().m_font = g_font.getDisplayList();
3351 GlobalOpenGL().m_fontHeight = g_font.getPixelHeight();
3352 GlobalOpenGL().m_fontAscent = g_font.getPixelAscent();
3353 GlobalOpenGL().m_fontDescent = g_font.getPixelDescent();
3356 void GlobalGL_sharedContextDestroyed()
3358 Textures_Unrealise();
3359 GlobalShaderCache().unrealise();
3361 QGL_sharedContextDestroyed(GlobalOpenGL());
3365 void Layout_constructPreferences(PreferencesPage& page)
3368 const char* layouts[] = { "window1.bmp", "window2.bmp", "window3.bmp", "window4.bmp" };
3369 page.appendRadioIcons(
3371 STRING_ARRAY_RANGE(layouts),
3372 LatchedIntImportCaller(g_Layout_viewStyle),
3373 IntExportCaller(g_Layout_viewStyle.m_latched)
3376 page.appendCheckBox(
3377 "", "Detachable Menus",
3378 LatchedBoolImportCaller(g_Layout_enableDetachableMenus),
3379 BoolExportCaller(g_Layout_enableDetachableMenus.m_latched)
3381 if (!string_empty(g_pGameDescription->getKeyValue("no_patch")))
3383 page.appendCheckBox(
3384 "", "Patch Toolbar",
3385 LatchedBoolImportCaller(g_Layout_enablePatchToolbar),
3386 BoolExportCaller(g_Layout_enablePatchToolbar.m_latched)
3389 page.appendCheckBox(
3390 "", "Plugin Toolbar",
3391 LatchedBoolImportCaller(g_Layout_enablePluginToolbar),
3392 BoolExportCaller(g_Layout_enablePluginToolbar.m_latched)
3396 void Layout_constructPage(PreferenceGroup& group)
3398 PreferencesPage page(group.createPage("Layout", "Layout Preferences"));
3399 Layout_constructPreferences(page);
3402 void Layout_registerPreferencesPage()
3404 PreferencesDialog_addInterfacePage(FreeCaller1<PreferenceGroup&, Layout_constructPage>());
3408 #include "preferencesystem.h"
3409 #include "stringio.h"
3411 void MainFrame_Construct()
3413 GlobalCommands_insert("OpenManual", FreeCaller<OpenHelpURL>(), Accelerator(GDK_F1));
3415 GlobalCommands_insert("Sleep", FreeCaller<thunk_OnSleep>(), Accelerator('P', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
3416 GlobalCommands_insert("NewMap", FreeCaller<NewMap>());
3417 GlobalCommands_insert("OpenMap", FreeCaller<OpenMap>(), Accelerator('O', (GdkModifierType)GDK_CONTROL_MASK));
3418 GlobalCommands_insert("ImportMap", FreeCaller<ImportMap>());
3419 GlobalCommands_insert("SaveMap", FreeCaller<SaveMap>(), Accelerator('S', (GdkModifierType)GDK_CONTROL_MASK));
3420 GlobalCommands_insert("SaveMapAs", FreeCaller<SaveMapAs>());
3421 GlobalCommands_insert("SaveSelected", FreeCaller<ExportMap>());
3422 GlobalCommands_insert("SaveRegion", FreeCaller<SaveRegion>());
3423 GlobalCommands_insert("RefreshReferences", FreeCaller<RefreshReferences>());
3424 GlobalCommands_insert("ProjectSettings", FreeCaller<DoProjectSettings>());
3425 GlobalCommands_insert("CheckForUpdate", FreeCaller<OpenUpdateURL>());
3426 GlobalCommands_insert("Exit", FreeCaller<Exit>());
3428 GlobalCommands_insert("Undo", FreeCaller<Undo>(), Accelerator('Z', (GdkModifierType)GDK_CONTROL_MASK));
3429 GlobalCommands_insert("Redo", FreeCaller<Redo>(), Accelerator('Y', (GdkModifierType)GDK_CONTROL_MASK));
3430 GlobalCommands_insert("Copy", FreeCaller<Copy>(), Accelerator('C', (GdkModifierType)GDK_CONTROL_MASK));
3431 GlobalCommands_insert("Paste", FreeCaller<Paste>(), Accelerator('V', (GdkModifierType)GDK_CONTROL_MASK));
3432 GlobalCommands_insert("PasteToCamera", FreeCaller<PasteToCamera>(), Accelerator('V', (GdkModifierType)GDK_MOD1_MASK));
3433 GlobalCommands_insert("CloneSelection", FreeCaller<Selection_Clone>(), Accelerator(GDK_space));
3434 GlobalCommands_insert("CloneSelectionAndMakeUnique", FreeCaller<Selection_Clone_MakeUnique>(), Accelerator(GDK_space, (GdkModifierType)GDK_SHIFT_MASK));
3435 GlobalCommands_insert("DeleteSelection", FreeCaller<deleteSelection>(), Accelerator(GDK_BackSpace));
3436 GlobalCommands_insert("ParentSelection", FreeCaller<Scene_parentSelected>());
3437 GlobalCommands_insert("UnSelectSelection", FreeCaller<Selection_Deselect>(), Accelerator(GDK_Escape));
3438 GlobalCommands_insert("InvertSelection", FreeCaller<Select_Invert>(), Accelerator('I'));
3439 GlobalCommands_insert("SelectInside", FreeCaller<Select_Inside>());
3440 GlobalCommands_insert("SelectTouching", FreeCaller<Select_Touching>());
3441 GlobalCommands_insert("ExpandSelectionToEntities", FreeCaller<Scene_ExpandSelectionToEntities>(), Accelerator('E', (GdkModifierType)(GDK_MOD1_MASK|GDK_CONTROL_MASK)));
3442 GlobalCommands_insert("Preferences", FreeCaller<PreferencesDialog_showDialog>(), Accelerator('P'));
3444 GlobalCommands_insert("ToggleConsole", FreeCaller<Console_ToggleShow>(), Accelerator('O'));
3445 GlobalCommands_insert("ToggleEntityInspector", FreeCaller<EntityInspector_ToggleShow>(), Accelerator('N'));
3446 GlobalCommands_insert("EntityList", FreeCaller<EntityList_toggleShown>(), Accelerator('L'));
3448 GlobalCommands_insert("ShowHidden", FreeCaller<Select_ShowAllHidden>(), Accelerator('H', (GdkModifierType)GDK_SHIFT_MASK));
3449 GlobalCommands_insert("HideSelected", FreeCaller<HideSelected>(), Accelerator('H'));
3451 GlobalToggles_insert("DragVertices", FreeCaller<SelectVertexMode>(), ToggleItem::AddCallbackCaller(g_vertexMode_button), Accelerator('V'));
3452 GlobalToggles_insert("DragEdges", FreeCaller<SelectEdgeMode>(), ToggleItem::AddCallbackCaller(g_edgeMode_button), Accelerator('E'));
3453 GlobalToggles_insert("DragFaces", FreeCaller<SelectFaceMode>(), ToggleItem::AddCallbackCaller(g_faceMode_button), Accelerator('F'));
3455 GlobalCommands_insert("MirrorSelectionX", FreeCaller<Selection_Flipx>());
3456 GlobalCommands_insert("RotateSelectionX", FreeCaller<Selection_Rotatex>());
3457 GlobalCommands_insert("MirrorSelectionY", FreeCaller<Selection_Flipy>());
3458 GlobalCommands_insert("RotateSelectionY", FreeCaller<Selection_Rotatey>());
3459 GlobalCommands_insert("MirrorSelectionZ", FreeCaller<Selection_Flipz>());
3460 GlobalCommands_insert("RotateSelectionZ", FreeCaller<Selection_Rotatez>());
3462 GlobalCommands_insert("ArbitraryRotation", FreeCaller<DoRotateDlg>());
3463 GlobalCommands_insert("ArbitraryScale", FreeCaller<DoScaleDlg>());
3465 GlobalCommands_insert("BuildMenuCustomize", FreeCaller<DoBuildMenu>());
3467 GlobalCommands_insert("FindBrush", FreeCaller<DoFind>());
3469 GlobalCommands_insert("MapInfo", FreeCaller<DoMapInfo>(), Accelerator('M'));
3472 GlobalToggles_insert("ToggleClipper", FreeCaller<ClipperMode>(), ToggleItem::AddCallbackCaller(g_clipper_button), Accelerator('X'));
3474 GlobalToggles_insert("MouseTranslate", FreeCaller<TranslateMode>(), ToggleItem::AddCallbackCaller(g_translatemode_button), Accelerator('W'));
3475 GlobalToggles_insert("MouseRotate", FreeCaller<RotateMode>(), ToggleItem::AddCallbackCaller(g_rotatemode_button), Accelerator('R'));
3476 GlobalToggles_insert("MouseScale", FreeCaller<ScaleMode>(), ToggleItem::AddCallbackCaller(g_scalemode_button));
3477 GlobalToggles_insert("MouseDrag", FreeCaller<DragMode>(), ToggleItem::AddCallbackCaller(g_dragmode_button), Accelerator('Q'));
3479 GlobalCommands_insert("ColorSchemeOriginal", FreeCaller<ColorScheme_Original>());
3480 GlobalCommands_insert("ColorSchemeQER", FreeCaller<ColorScheme_QER>());
3481 GlobalCommands_insert("ColorSchemeBlackAndGreen", FreeCaller<ColorScheme_Black>());
3482 GlobalCommands_insert("ColorSchemeYdnar", FreeCaller<ColorScheme_Ydnar>());
3483 GlobalCommands_insert("ChooseTextureBackgroundColor", makeCallback(g_ColoursMenu.m_textureback));
3484 GlobalCommands_insert("ChooseGridBackgroundColor", makeCallback(g_ColoursMenu.m_xyback));
3485 GlobalCommands_insert("ChooseGridMajorColor", makeCallback(g_ColoursMenu.m_gridmajor));
3486 GlobalCommands_insert("ChooseGridMinorColor", makeCallback(g_ColoursMenu.m_gridminor));
3487 GlobalCommands_insert("ChooseSmallGridMajorColor", makeCallback(g_ColoursMenu.m_gridmajor_alt));
3488 GlobalCommands_insert("ChooseSmallGridMinorColor", makeCallback(g_ColoursMenu.m_gridminor_alt));
3489 GlobalCommands_insert("ChooseGridTextColor", makeCallback(g_ColoursMenu.m_gridtext));
3490 GlobalCommands_insert("ChooseGridBlockColor", makeCallback(g_ColoursMenu.m_gridblock));
3491 GlobalCommands_insert("ChooseBrushColor", makeCallback(g_ColoursMenu.m_brush));
3492 GlobalCommands_insert("ChooseCameraBackgroundColor", makeCallback(g_ColoursMenu.m_cameraback));
3493 GlobalCommands_insert("ChooseSelectedBrushColor", makeCallback(g_ColoursMenu.m_selectedbrush));
3494 GlobalCommands_insert("ChooseCameraSelectedBrushColor", makeCallback(g_ColoursMenu.m_selectedbrush3d));
3495 GlobalCommands_insert("ChooseClipperColor", makeCallback(g_ColoursMenu.m_clipper));
3496 GlobalCommands_insert("ChooseOrthoViewNameColor", makeCallback(g_ColoursMenu.m_viewname));
3499 GlobalCommands_insert("CSGSubtract", FreeCaller<CSG_Subtract>(), Accelerator('U', (GdkModifierType)GDK_SHIFT_MASK));
3500 GlobalCommands_insert("CSGMerge", FreeCaller<CSG_Merge>(), Accelerator('U', (GdkModifierType)GDK_CONTROL_MASK));
3501 GlobalCommands_insert("CSGHollow", FreeCaller<CSG_MakeHollow>());
3503 Grid_registerCommands();
3505 GlobalCommands_insert("SnapToGrid", FreeCaller<Selection_SnapToGrid>(), Accelerator('G', (GdkModifierType)GDK_CONTROL_MASK));
3507 GlobalCommands_insert("SelectAllOfType", FreeCaller<Select_AllOfType>(), Accelerator('A', (GdkModifierType)GDK_SHIFT_MASK));
3509 GlobalCommands_insert("TexRotateClock", FreeCaller<Texdef_RotateClockwise>(), Accelerator(GDK_Next, (GdkModifierType)GDK_SHIFT_MASK));
3510 GlobalCommands_insert("TexRotateCounter", FreeCaller<Texdef_RotateAntiClockwise>(), Accelerator(GDK_Prior, (GdkModifierType)GDK_SHIFT_MASK));
3511 GlobalCommands_insert("TexScaleUp", FreeCaller<Texdef_ScaleUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_CONTROL_MASK));
3512 GlobalCommands_insert("TexScaleDown", FreeCaller<Texdef_ScaleDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_CONTROL_MASK));
3513 GlobalCommands_insert("TexScaleLeft", FreeCaller<Texdef_ScaleLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_CONTROL_MASK));
3514 GlobalCommands_insert("TexScaleRight", FreeCaller<Texdef_ScaleRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_CONTROL_MASK));
3515 GlobalCommands_insert("TexShiftUp", FreeCaller<Texdef_ShiftUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_SHIFT_MASK));
3516 GlobalCommands_insert("TexShiftDown", FreeCaller<Texdef_ShiftDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_SHIFT_MASK));
3517 GlobalCommands_insert("TexShiftLeft", FreeCaller<Texdef_ShiftLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_SHIFT_MASK));
3518 GlobalCommands_insert("TexShiftRight", FreeCaller<Texdef_ShiftRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_SHIFT_MASK));
3520 GlobalCommands_insert("MoveSelectionDOWN", FreeCaller<Selection_MoveDown>(), Accelerator(GDK_KP_Subtract));
3521 GlobalCommands_insert("MoveSelectionUP", FreeCaller<Selection_MoveUp>(), Accelerator(GDK_KP_Add));
3523 GlobalCommands_insert("SelectNudgeLeft", FreeCaller<Selection_NudgeLeft>(), Accelerator(GDK_Left, (GdkModifierType)GDK_MOD1_MASK));
3524 GlobalCommands_insert("SelectNudgeRight", FreeCaller<Selection_NudgeRight>(), Accelerator(GDK_Right, (GdkModifierType)GDK_MOD1_MASK));
3525 GlobalCommands_insert("SelectNudgeUp", FreeCaller<Selection_NudgeUp>(), Accelerator(GDK_Up, (GdkModifierType)GDK_MOD1_MASK));
3526 GlobalCommands_insert("SelectNudgeDown", FreeCaller<Selection_NudgeDown>(), Accelerator(GDK_Down, (GdkModifierType)GDK_MOD1_MASK));
3528 Patch_registerCommands();
3529 XYShow_registerCommands();
3531 typedef FreeCaller1<const Selectable&, ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3532 GlobalSelectionSystem().addSelectionChangeCallback(ComponentModeSelectionChangedCaller());
3534 GlobalPreferenceSystem().registerPreference("DetachableMenus", BoolImportStringCaller(g_Layout_enableDetachableMenus.m_latched), BoolExportStringCaller(g_Layout_enableDetachableMenus.m_latched));
3535 GlobalPreferenceSystem().registerPreference("PatchToolBar", BoolImportStringCaller(g_Layout_enablePatchToolbar.m_latched), BoolExportStringCaller(g_Layout_enablePatchToolbar.m_latched));
3536 GlobalPreferenceSystem().registerPreference("PluginToolBar", BoolImportStringCaller(g_Layout_enablePluginToolbar.m_latched), BoolExportStringCaller(g_Layout_enablePluginToolbar.m_latched));
3537 GlobalPreferenceSystem().registerPreference("QE4StyleWindows", IntImportStringCaller(g_Layout_viewStyle.m_latched), IntExportStringCaller(g_Layout_viewStyle.m_latched));
3538 GlobalPreferenceSystem().registerPreference("XYHeight", IntImportStringCaller(g_layout_globals.nXYHeight), IntExportStringCaller(g_layout_globals.nXYHeight));
3539 GlobalPreferenceSystem().registerPreference("XYWidth", IntImportStringCaller(g_layout_globals.nXYWidth), IntExportStringCaller(g_layout_globals.nXYWidth));
3540 GlobalPreferenceSystem().registerPreference("CamWidth", IntImportStringCaller(g_layout_globals.nCamWidth), IntExportStringCaller(g_layout_globals.nCamWidth));
3541 GlobalPreferenceSystem().registerPreference("CamHeight", IntImportStringCaller(g_layout_globals.nCamHeight), IntExportStringCaller(g_layout_globals.nCamHeight));
3543 GlobalPreferenceSystem().registerPreference("State", IntImportStringCaller(g_layout_globals.nState), IntExportStringCaller(g_layout_globals.nState));
3544 GlobalPreferenceSystem().registerPreference("PositionX", IntImportStringCaller(g_layout_globals.m_position.x), IntExportStringCaller(g_layout_globals.m_position.x));
3545 GlobalPreferenceSystem().registerPreference("PositionY", IntImportStringCaller(g_layout_globals.m_position.y), IntExportStringCaller(g_layout_globals.m_position.y));
3546 GlobalPreferenceSystem().registerPreference("Width", IntImportStringCaller(g_layout_globals.m_position.w), IntExportStringCaller(g_layout_globals.m_position.w));
3547 GlobalPreferenceSystem().registerPreference("Height", IntImportStringCaller(g_layout_globals.m_position.h), IntExportStringCaller(g_layout_globals.m_position.h));
3549 GlobalPreferenceSystem().registerPreference("CamWnd", WindowPositionTrackerImportStringCaller(g_posCamWnd), WindowPositionTrackerExportStringCaller(g_posCamWnd));
3550 GlobalPreferenceSystem().registerPreference("XYWnd", WindowPositionTrackerImportStringCaller(g_posXYWnd), WindowPositionTrackerExportStringCaller(g_posXYWnd));
3551 GlobalPreferenceSystem().registerPreference("YZWnd", WindowPositionTrackerImportStringCaller(g_posYZWnd), WindowPositionTrackerExportStringCaller(g_posYZWnd));
3552 GlobalPreferenceSystem().registerPreference("XZWnd", WindowPositionTrackerImportStringCaller(g_posXZWnd), WindowPositionTrackerExportStringCaller(g_posXZWnd));
3555 const char* ENGINEPATH_ATTRIBUTE =
3558 #elif defined(__linux__) || defined (__FreeBSD__)
3560 #elif defined(__APPLE__)
3563 #error "unknown platform"
3566 StringOutputStream path(256);
3567 path << DirectoryCleaned(g_pGameDescription->getRequiredKeyValue(ENGINEPATH_ATTRIBUTE));
3568 g_strEnginePath = path.c_str();
3571 GlobalPreferenceSystem().registerPreference("EnginePath", CopiedStringImportStringCaller(g_strEnginePath), CopiedStringExportStringCaller(g_strEnginePath));
3573 g_Layout_viewStyle.useLatched();
3574 g_Layout_enableDetachableMenus.useLatched();
3575 g_Layout_enablePatchToolbar.useLatched();
3576 g_Layout_enablePluginToolbar.useLatched();
3578 Layout_registerPreferencesPage();
3579 Paths_registerPreferencesPage();
3581 g_brushCount.setCountChangedCallback(FreeCaller<QE_brushCountChanged>());
3582 g_entityCount.setCountChangedCallback(FreeCaller<QE_entityCountChanged>());
3583 GlobalEntityCreator().setCounter(&g_entityCount);
3585 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3586 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3588 GlobalEntityClassManager().attach(g_WorldspawnColourEntityClassObserver);
3591 void MainFrame_Destroy()
3593 GlobalEntityClassManager().detach(g_WorldspawnColourEntityClassObserver);
3595 GlobalEntityCreator().setCounter(0);
3596 g_entityCount.setCountChangedCallback(Callback());
3597 g_brushCount.setCountChangedCallback(Callback());
3601 void GLWindow_Construct()
3603 GlobalPreferenceSystem().registerPreference("MouseButtons", IntImportStringCaller(g_glwindow_globals.m_nMouseType), IntExportStringCaller(g_glwindow_globals.m_nMouseType));
3606 void GLWindow_Destroy()