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"
29 #include "globaldefs.h"
33 #include "ifilesystem.h"
39 #include "moduleobserver.h"
43 #include <gdk/gdkkeysyms.h>
47 #include "stream/stringstream.h"
48 #include "signal/isignal.h"
51 #include "eclasslib.h"
52 #include "moduleobservers.h"
54 #include "gtkutil/clipboard.h"
55 #include "gtkutil/frame.h"
56 #include "gtkutil/glwidget.h"
57 #include "gtkutil/image.h"
58 #include "gtkutil/menu.h"
59 #include "gtkutil/paned.h"
63 #include "brushmanip.h"
64 #include "brushmodule.h"
65 #include "camwindow.h"
70 #include "entityinspector.h"
71 #include "entitylist.h"
73 #include "findtexturedialog.h"
75 #include "groupdialog.h"
82 #include "patchdialog.h"
83 #include "patchmanip.h"
85 #include "pluginmanager.h"
86 #include "pluginmenu.h"
87 #include "plugintoolbar.h"
88 #include "preferences.h"
93 #include "surfacedialog.h"
95 #include "texwindow.h"
98 #include "windowobservers.h"
99 #include "renderstate.h"
100 #include "feedback.h"
101 #include "referencecache.h"
102 #include "texwindow.h"
105 struct layout_globals_t {
106 WindowPosition m_position;
116 m_position(-1, -1, 640, 480),
122 nState(GDK_WINDOW_STATE_MAXIMIZED)
127 layout_globals_t g_layout_globals;
128 glwindow_globals_t g_glwindow_globals;
133 bool g_vfsInitialized = false;
137 if (g_vfsInitialized) { return; }
139 GlobalFileSystem().initialise();
140 g_vfsInitialized = true;
145 if (!g_vfsInitialized) { return; }
146 GlobalFileSystem().shutdown();
147 g_vfsInitialized = false;
152 if (!g_vfsInitialized) { return; }
153 GlobalFileSystem().clear();
155 GlobalFileSystem().refresh();
156 g_vfsInitialized = true;
157 // also refresg models
159 // also refresh texture browser
160 TextureBrowser_RefreshShaders();
169 class VFSModuleObserver : public ModuleObserver {
182 VFSModuleObserver g_VFSModuleObserver;
186 Radiant_attachHomePathsObserver(g_VFSModuleObserver);
191 Radiant_detachHomePathsObserver(g_VFSModuleObserver);
199 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
200 #define qREFKNOWNFOLDERID GUID
201 #define qKF_FLAG_CREATE 0x8000
202 #define qKF_FLAG_NO_ALIAS 0x1000
203 typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath );
204 static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath;
207 void HomePaths_Realise()
210 const char *prefix = g_pGameDescription->getKeyValue("prefix");
211 if (!string_empty(prefix)) {
212 StringOutputStream path(256);
216 path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/";
217 if ( file_is_directory( path.c_str() ) ) {
218 g_qeglobals.m_userEnginePath = path.c_str();
222 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
226 TCHAR mydocsdir[MAX_PATH + 1];
228 HMODULE shfolder = LoadLibrary( "shfolder.dll" );
230 qSHGetKnownFolderPath = (qSHGetKnownFolderPath_t *) GetProcAddress( shfolder, "SHGetKnownFolderPath" );
233 qSHGetKnownFolderPath = NULL;
235 CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
236 if ( qSHGetKnownFolderPath && qSHGetKnownFolderPath( qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw ) == S_OK ) {
237 memset( mydocsdir, 0, sizeof( mydocsdir ) );
238 wcstombs( mydocsdir, mydocsdirw, sizeof( mydocsdir ) - 1 );
239 CoTaskMemFree( mydocsdirw );
241 path << DirectoryCleaned( mydocsdir ) << ( prefix + 1 ) << "/";
242 if ( file_is_directory( path.c_str() ) ) {
243 g_qeglobals.m_userEnginePath = path.c_str();
245 FreeLibrary( shfolder );
251 FreeLibrary( shfolder );
253 if ( SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir ) ) {
255 path << DirectoryCleaned( mydocsdir ) << "My Games/" << ( prefix + 1 ) << "/";
256 // win32: only add it if it already exists
257 if ( file_is_directory( path.c_str() ) ) {
258 g_qeglobals.m_userEnginePath = path.c_str();
266 path << DirectoryCleaned(g_get_home_dir()) << prefix << "/";
267 g_qeglobals.m_userEnginePath = path.c_str();
272 g_qeglobals.m_userEnginePath = EnginePath_get();
275 Q_mkdir(g_qeglobals.m_userEnginePath.c_str());
278 StringOutputStream path(256);
279 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
280 g_qeglobals.m_userGamePath = path.c_str();
282 ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "HomePaths_Realise: user-game-path is empty");
283 Q_mkdir(g_qeglobals.m_userGamePath.c_str());
286 ModuleObservers g_homePathObservers;
288 void Radiant_attachHomePathsObserver(ModuleObserver &observer)
290 g_homePathObservers.attach(observer);
293 void Radiant_detachHomePathsObserver(ModuleObserver &observer)
295 g_homePathObservers.detach(observer);
298 class HomePathsModuleObserver : public ModuleObserver {
299 std::size_t m_unrealised;
301 HomePathsModuleObserver() : m_unrealised(1)
307 if (--m_unrealised == 0) {
309 g_homePathObservers.realise();
315 if (++m_unrealised == 1) {
316 g_homePathObservers.unrealise();
321 HomePathsModuleObserver g_HomePathsModuleObserver;
323 void HomePaths_Construct()
325 Radiant_attachEnginePathObserver(g_HomePathsModuleObserver);
328 void HomePaths_Destroy()
330 Radiant_detachEnginePathObserver(g_HomePathsModuleObserver);
336 CopiedString g_strEnginePath;
337 ModuleObservers g_enginePathObservers;
338 std::size_t g_enginepath_unrealised = 1;
340 void Radiant_attachEnginePathObserver(ModuleObserver &observer)
342 g_enginePathObservers.attach(observer);
345 void Radiant_detachEnginePathObserver(ModuleObserver &observer)
347 g_enginePathObservers.detach(observer);
351 void EnginePath_Realise()
353 if (--g_enginepath_unrealised == 0) {
354 g_enginePathObservers.realise();
359 const char *EnginePath_get()
361 ASSERT_MESSAGE(g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised");
362 return g_strEnginePath.c_str();
365 void EnginePath_Unrealise()
367 if (++g_enginepath_unrealised == 1) {
368 g_enginePathObservers.unrealise();
372 void setEnginePath(const char *path)
374 StringOutputStream buffer(256);
375 buffer << DirectoryCleaned(path);
376 if (!path_equal(buffer.c_str(), g_strEnginePath.c_str())) {
378 while ( !ConfirmModified( "Paths Changed" ) )
380 if ( Map_Unnamed( g_map ) ) {
391 ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Changing Engine Path");
393 EnginePath_Unrealise();
395 g_strEnginePath = buffer.c_str();
397 EnginePath_Realise();
403 CopiedString g_strPakPath[g_pakPathCount] = {"", "", "", "", ""};
404 ModuleObservers g_pakPathObservers[g_pakPathCount];
405 std::size_t g_pakpath_unrealised[g_pakPathCount] = {1, 1, 1, 1, 1};
407 void Radiant_attachPakPathObserver(int num, ModuleObserver &observer)
409 g_pakPathObservers[num].attach(observer);
412 void Radiant_detachPakPathObserver(int num, ModuleObserver &observer)
414 g_pakPathObservers[num].detach(observer);
418 void PakPath_Realise(int num)
420 if (--g_pakpath_unrealised[num] == 0) {
421 g_pakPathObservers[num].realise();
425 const char *PakPath_get(int num)
427 std::string message = "PakPath_get: pak path " + std::to_string(num) + " not realised";
428 ASSERT_MESSAGE(g_pakpath_unrealised[num] == 0, message.c_str());
429 return g_strPakPath[num].c_str();
432 void PakPath_Unrealise(int num)
434 if (++g_pakpath_unrealised[num] == 1) {
435 g_pakPathObservers[num].unrealise();
439 void setPakPath(int num, const char *path)
441 if (!g_strcmp0(path, "")) {
442 g_strPakPath[num] = "";
446 StringOutputStream buffer(256);
447 buffer << DirectoryCleaned(path);
448 if (!path_equal(buffer.c_str(), g_strPakPath[num].c_str())) {
449 std::string message = "Changing Pak Path " + std::to_string(num);
450 ScopeDisableScreenUpdates disableScreenUpdates("Processing...", message.c_str());
452 PakPath_Unrealise(num);
454 g_strPakPath[num] = buffer.c_str();
456 PakPath_Realise(num);
463 CopiedString g_strAppPath; ///< holds the full path of the executable
465 const char *AppPath_get()
467 return g_strAppPath.c_str();
470 /// the path to the local rc-dir
471 const char *LocalRcPath_get(void)
473 static CopiedString rc_path;
474 if (rc_path.empty()) {
475 StringOutputStream stream(256);
476 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
477 rc_path = stream.c_str();
479 return rc_path.c_str();
482 /// directory for temp files
483 /// NOTE: on *nix this is were we check for .pid
484 CopiedString g_strSettingsPath;
486 const char *SettingsPath_get()
488 return g_strSettingsPath.c_str();
493 points to the game tools directory, for instance
494 C:/Program Files/Quake III Arena/GtkRadiant
496 this is one of the main variables that are configured by the game selection on startup
497 [GameToolsPath]/plugins
498 [GameToolsPath]/modules
501 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
503 const char *GameToolsPath_get()
505 return g_strGameToolsPath.c_str();
509 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz)
511 returnz(self.c_str());
514 static void Import(CopiedString &self, const char *value)
516 setEnginePath(value);
521 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz)
523 returnz(self.c_str());
526 static void Import(CopiedString &self, const char *value)
528 setPakPath(0, value);
533 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz)
535 returnz(self.c_str());
538 static void Import(CopiedString &self, const char *value)
540 setPakPath(1, value);
545 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz)
547 returnz(self.c_str());
550 static void Import(CopiedString &self, const char *value)
552 setPakPath(2, value);
557 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz)
559 returnz(self.c_str());
562 static void Import(CopiedString &self, const char *value)
564 setPakPath(3, value);
569 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz)
571 returnz(self.c_str());
574 static void Import(CopiedString &self, const char *value)
576 setPakPath(4, value);
580 bool g_disableEnginePath = false;
581 bool g_disableHomePath = false;
583 void Paths_constructPreferences(PreferencesPage &page)
585 page.appendPathEntry("Engine Path", true, make_property<EnginePath>(g_strEnginePath));
588 "", "Do not use Engine Path",
593 "", "Do not use Home Path",
597 for (int i = 0; i < g_pakPathCount; i++) {
598 std::string label = "Pak Path " + std::to_string(i);
601 page.appendPathEntry(label.c_str(), true, make_property<PakPath0>(g_strPakPath[i]));
604 page.appendPathEntry(label.c_str(), true, make_property<PakPath1>(g_strPakPath[i]));
607 page.appendPathEntry(label.c_str(), true, make_property<PakPath2>(g_strPakPath[i]));
610 page.appendPathEntry(label.c_str(), true, make_property<PakPath3>(g_strPakPath[i]));
613 page.appendPathEntry(label.c_str(), true, make_property<PakPath4>(g_strPakPath[i]));
619 void Paths_constructPage(PreferenceGroup &group)
621 PreferencesPage page(group.createPage("Paths", "Path Settings"));
622 Paths_constructPreferences(page);
625 void Paths_registerPreferencesPage()
627 PreferencesDialog_addSettingsPage(makeCallbackF(Paths_constructPage));
631 class PathsDialog : public Dialog {
633 ui::Window BuildDialog()
635 auto frame = create_dialog_frame("Path settings", ui::Shadow::ETCHED_IN);
637 auto vbox2 = create_dialog_vbox(0, 4);
641 PreferencesPage preferencesPage(*this, vbox2);
642 Paths_constructPreferences(preferencesPage);
645 return ui::Window(create_simple_modal_dialog_window("Engine Path Not Found", m_modal, frame));
649 PathsDialog g_PathsDialog;
651 void EnginePath_verify()
653 if (!file_exists(g_strEnginePath.c_str())) {
654 g_PathsDialog.Create();
655 g_PathsDialog.DoModal();
656 g_PathsDialog.Destroy();
661 CopiedString g_gamename;
662 CopiedString g_gamemode;
663 ModuleObservers g_gameNameObservers;
664 ModuleObservers g_gameModeObservers;
667 void Radiant_attachGameNameObserver(ModuleObserver &observer)
669 g_gameNameObservers.attach(observer);
672 void Radiant_detachGameNameObserver(ModuleObserver &observer)
674 g_gameNameObservers.detach(observer);
677 const char *basegame_get()
679 return g_pGameDescription->getRequiredKeyValue("basegame");
682 const char *gamename_get()
684 const char *gamename = g_gamename.c_str();
685 if (string_empty(gamename)) {
686 return basegame_get();
691 void gamename_set(const char *gamename)
693 if (!string_equal(gamename, g_gamename.c_str())) {
694 g_gameNameObservers.unrealise();
695 g_gamename = gamename;
696 g_gameNameObservers.realise();
700 void Radiant_attachGameModeObserver(ModuleObserver &observer)
702 g_gameModeObservers.attach(observer);
705 void Radiant_detachGameModeObserver(ModuleObserver &observer)
707 g_gameModeObservers.detach(observer);
710 const char *gamemode_get()
712 return g_gamemode.c_str();
715 void gamemode_set(const char *gamemode)
717 if (!string_equal(gamemode, g_gamemode.c_str())) {
718 g_gameModeObservers.unrealise();
719 g_gamemode = gamemode;
720 g_gameModeObservers.realise();
727 const char *const c_library_extension =
728 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
729 CMAKE_SHARED_MODULE_SUFFIX
730 #elif GDEF_OS_WINDOWS
734 #elif GDEF_OS_LINUX || GDEF_OS_BSD
739 void Radiant_loadModules(const char *path)
741 Directory_forEach(path, matchFileExtension(c_library_extension, [&](const char *name) {
743 ASSERT_MESSAGE(strlen(path) + strlen(name) < 1024, "");
744 strcpy(fullname, path);
745 strcat(fullname, name);
746 globalOutputStream() << "Found '" << fullname << "'\n";
747 GlobalModuleServer_loadModule(fullname);
751 void Radiant_loadModulesFromRoot(const char *directory)
754 StringOutputStream path(256);
755 path << directory << g_pluginsDir;
756 Radiant_loadModules(path.c_str());
759 if (!string_equal(g_pluginsDir, g_modulesDir)) {
760 StringOutputStream path(256);
761 path << directory << g_modulesDir;
762 Radiant_loadModules(path.c_str());
766 //! Make COLOR_BRUSHES override worldspawn eclass colour.
767 void SetWorldspawnColour(const Vector3 &colour)
769 EntityClass *worldspawn = GlobalEntityClassManager().findOrInsert("worldspawn", true);
770 eclass_release_state(worldspawn);
771 worldspawn->color = colour;
772 eclass_capture_state(worldspawn);
776 class WorldspawnColourEntityClassObserver : public ModuleObserver {
777 std::size_t m_unrealised;
779 WorldspawnColourEntityClassObserver() : m_unrealised(1)
785 if (--m_unrealised == 0) {
786 SetWorldspawnColour(g_xywindow_globals.color_brushes);
792 if (++m_unrealised == 1) {
797 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
800 ModuleObservers g_gameToolsPathObservers;
802 void Radiant_attachGameToolsPathObserver(ModuleObserver &observer)
804 g_gameToolsPathObservers.attach(observer);
807 void Radiant_detachGameToolsPathObserver(ModuleObserver &observer)
809 g_gameToolsPathObservers.detach(observer);
812 void Radiant_Initialise()
814 GlobalModuleServer_Initialise();
816 Radiant_loadModulesFromRoot(AppPath_get());
820 bool success = Radiant_Construct(GlobalModuleServer_get());
821 ASSERT_MESSAGE(success, "module system failed to initialise - see radiant.log for error messages");
823 g_gameToolsPathObservers.realise();
824 g_gameModeObservers.realise();
825 g_gameNameObservers.realise();
828 void Radiant_Shutdown()
830 g_gameNameObservers.unrealise();
831 g_gameModeObservers.unrealise();
832 g_gameToolsPathObservers.unrealise();
834 if (!g_preferences_globals.disable_ini) {
835 globalOutputStream() << "Start writing prefs\n";
837 globalOutputStream() << "Done prefs\n";
842 GlobalModuleServer_Shutdown();
847 if (ConfirmModified("Exit Radiant")) {
855 GlobalUndoSystem().undo();
861 GlobalUndoSystem().redo();
865 void deleteSelection()
867 UndoableCommand undo("deleteSelected");
871 void Map_ExportSelected(TextOutputStream &ostream)
873 Map_ExportSelected(ostream, Map_getFormat(g_map));
876 void Map_ImportSelected(TextInputStream &istream)
878 Map_ImportSelected(istream, Map_getFormat(g_map));
881 void Selection_Copy()
883 clipboard_copy(Map_ExportSelected);
886 void Selection_Paste()
888 clipboard_paste(Map_ImportSelected);
893 if (SelectedFaces_empty()) {
896 SelectedFaces_copyTexture();
902 if (SelectedFaces_empty()) {
903 UndoableCommand undo("paste");
905 GlobalSelectionSystem().setSelectedAll(false);
908 SelectedFaces_pasteTexture();
914 CamWnd &camwnd = *g_pParentWnd->GetCamWnd();
915 GlobalSelectionSystem().setSelectedAll(false);
917 UndoableCommand undo("pasteToCamera");
921 // Work out the delta
924 Vector3 delta = vector3_subtracted(vector3_snapped(Camera_getOrigin(camwnd), GetSnapGridSize()), mid);
927 GlobalSelectionSystem().translateSelected(delta);
931 void ColorScheme_Original()
933 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
935 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
936 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
937 CamWnd_Update(*g_pParentWnd->GetCamWnd());
939 g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
940 g_xywindow_globals.color_gridminor = Vector3(0.75f, 0.75f, 0.75f);
941 g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
942 g_xywindow_globals.color_gridminor_alt = Vector3(0.5f, 0.0f, 0.0f);
943 g_xywindow_globals.color_gridmajor_alt = Vector3(1.0f, 0.0f, 0.0f);
944 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
945 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
946 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
947 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
948 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
949 SetWorldspawnColour(g_xywindow_globals.color_brushes);
950 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
951 XY_UpdateAllWindows();
954 void ColorScheme_QER()
956 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
958 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
959 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
960 CamWnd_Update(*g_pParentWnd->GetCamWnd());
962 g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
963 g_xywindow_globals.color_gridminor = Vector3(1.0f, 1.0f, 1.0f);
964 g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
965 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
966 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
967 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
968 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
969 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
970 SetWorldspawnColour(g_xywindow_globals.color_brushes);
971 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
972 XY_UpdateAllWindows();
975 void ColorScheme_Black()
977 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
979 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
980 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
981 CamWnd_Update(*g_pParentWnd->GetCamWnd());
983 g_xywindow_globals.color_gridback = Vector3(0.0f, 0.0f, 0.0f);
984 g_xywindow_globals.color_gridminor = Vector3(0.2f, 0.2f, 0.2f);
985 g_xywindow_globals.color_gridmajor = Vector3(0.3f, 0.5f, 0.5f);
986 g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
987 g_xywindow_globals.color_gridtext = Vector3(1.0f, 1.0f, 1.0f);
988 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
989 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
990 g_xywindow_globals.color_brushes = Vector3(1.0f, 1.0f, 1.0f);
991 SetWorldspawnColour(g_xywindow_globals.color_brushes);
992 g_xywindow_globals.color_viewname = Vector3(0.7f, 0.7f, 0.0f);
993 XY_UpdateAllWindows();
996 /* ydnar: to emulate maya/max/lightwave color schemes */
997 void ColorScheme_Ydnar()
999 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
1001 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
1002 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
1003 CamWnd_Update(*g_pParentWnd->GetCamWnd());
1005 g_xywindow_globals.color_gridback = Vector3(0.77f, 0.77f, 0.77f);
1006 g_xywindow_globals.color_gridminor = Vector3(0.83f, 0.83f, 0.83f);
1007 g_xywindow_globals.color_gridmajor = Vector3(0.89f, 0.89f, 0.89f);
1008 g_xywindow_globals.color_gridblock = Vector3(1.0f, 1.0f, 1.0f);
1009 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
1010 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
1011 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
1012 g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
1013 SetWorldspawnColour(g_xywindow_globals.color_brushes);
1014 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
1015 XY_UpdateAllWindows();
1018 typedef Callback<void(Vector3 &)> GetColourCallback;
1019 typedef Callback<void(const Vector3 &)> SetColourCallback;
1021 class ChooseColour {
1022 GetColourCallback m_get;
1023 SetColourCallback m_set;
1025 ChooseColour(const GetColourCallback &get, const SetColourCallback &set)
1026 : m_get(get), m_set(set)
1034 color_dialog(MainFrame_getWindow(), colour);
1040 void Colour_get(const Vector3 &colour, Vector3 &other)
1045 typedef ConstReferenceCaller<Vector3, void(Vector3 &), Colour_get> ColourGetCaller;
1047 void Colour_set(Vector3 &colour, const Vector3 &other)
1050 SceneChangeNotify();
1053 typedef ReferenceCaller<Vector3, void(const Vector3 &), Colour_set> ColourSetCaller;
1055 void BrushColour_set(const Vector3 &other)
1057 g_xywindow_globals.color_brushes = other;
1058 SetWorldspawnColour(g_xywindow_globals.color_brushes);
1059 SceneChangeNotify();
1062 typedef FreeCaller<void(const Vector3 &), BrushColour_set> BrushColourSetCaller;
1064 void ClipperColour_set(const Vector3 &other)
1066 g_xywindow_globals.color_clipper = other;
1067 Brush_clipperColourChanged();
1068 SceneChangeNotify();
1071 typedef FreeCaller<void(const Vector3 &), ClipperColour_set> ClipperColourSetCaller;
1073 void TextureBrowserColour_get(Vector3 &other)
1075 other = TextureBrowser_getBackgroundColour(GlobalTextureBrowser());
1078 typedef FreeCaller<void(Vector3 &), TextureBrowserColour_get> TextureBrowserColourGetCaller;
1080 void TextureBrowserColour_set(const Vector3 &other)
1082 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), other);
1085 typedef FreeCaller<void(const Vector3 &), TextureBrowserColour_set> TextureBrowserColourSetCaller;
1090 ChooseColour m_textureback;
1091 ChooseColour m_xyback;
1092 ChooseColour m_gridmajor;
1093 ChooseColour m_gridminor;
1094 ChooseColour m_gridmajor_alt;
1095 ChooseColour m_gridminor_alt;
1096 ChooseColour m_gridtext;
1097 ChooseColour m_gridblock;
1098 ChooseColour m_cameraback;
1099 ChooseColour m_brush;
1100 ChooseColour m_selectedbrush;
1101 ChooseColour m_selectedbrush3d;
1102 ChooseColour m_clipper;
1103 ChooseColour m_viewname;
1106 m_textureback(TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller()),
1107 m_xyback(ColourGetCaller(g_xywindow_globals.color_gridback),
1108 ColourSetCaller(g_xywindow_globals.color_gridback)),
1109 m_gridmajor(ColourGetCaller(g_xywindow_globals.color_gridmajor),
1110 ColourSetCaller(g_xywindow_globals.color_gridmajor)),
1111 m_gridminor(ColourGetCaller(g_xywindow_globals.color_gridminor),
1112 ColourSetCaller(g_xywindow_globals.color_gridminor)),
1113 m_gridmajor_alt(ColourGetCaller(g_xywindow_globals.color_gridmajor_alt),
1114 ColourSetCaller(g_xywindow_globals.color_gridmajor_alt)),
1115 m_gridminor_alt(ColourGetCaller(g_xywindow_globals.color_gridminor_alt),
1116 ColourSetCaller(g_xywindow_globals.color_gridminor_alt)),
1117 m_gridtext(ColourGetCaller(g_xywindow_globals.color_gridtext),
1118 ColourSetCaller(g_xywindow_globals.color_gridtext)),
1119 m_gridblock(ColourGetCaller(g_xywindow_globals.color_gridblock),
1120 ColourSetCaller(g_xywindow_globals.color_gridblock)),
1121 m_cameraback(ColourGetCaller(g_camwindow_globals.color_cameraback),
1122 ColourSetCaller(g_camwindow_globals.color_cameraback)),
1123 m_brush(ColourGetCaller(g_xywindow_globals.color_brushes), BrushColourSetCaller()),
1124 m_selectedbrush(ColourGetCaller(g_xywindow_globals.color_selbrushes),
1125 ColourSetCaller(g_xywindow_globals.color_selbrushes)),
1126 m_selectedbrush3d(ColourGetCaller(g_camwindow_globals.color_selbrushes3d),
1127 ColourSetCaller(g_camwindow_globals.color_selbrushes3d)),
1128 m_clipper(ColourGetCaller(g_xywindow_globals.color_clipper), ClipperColourSetCaller()),
1129 m_viewname(ColourGetCaller(g_xywindow_globals.color_viewname),
1130 ColourSetCaller(g_xywindow_globals.color_viewname))
1135 ColoursMenu g_ColoursMenu;
1137 ui::MenuItem create_colours_menu()
1139 auto colours_menu_item = new_sub_menu_item_with_mnemonic("Colors");
1140 auto menu_in_menu = ui::Menu::from(gtk_menu_item_get_submenu(colours_menu_item));
1141 if (g_Layout_enableDetachableMenus.m_value) {
1142 menu_tearoff(menu_in_menu);
1145 auto menu_3 = create_sub_menu_with_mnemonic(menu_in_menu, "Themes");
1146 if (g_Layout_enableDetachableMenus.m_value) {
1147 menu_tearoff(menu_3);
1150 create_menu_item_with_mnemonic(menu_3, "QE4 Original", "ColorSchemeOriginal");
1151 create_menu_item_with_mnemonic(menu_3, "Q3Radiant Original", "ColorSchemeQER");
1152 create_menu_item_with_mnemonic(menu_3, "Black and Green", "ColorSchemeBlackAndGreen");
1153 create_menu_item_with_mnemonic(menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar");
1155 menu_separator(menu_in_menu);
1157 create_menu_item_with_mnemonic(menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor");
1158 create_menu_item_with_mnemonic(menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor");
1159 create_menu_item_with_mnemonic(menu_in_menu, "Grid Major...", "ChooseGridMajorColor");
1160 create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor...", "ChooseGridMinorColor");
1161 create_menu_item_with_mnemonic(menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor");
1162 create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor");
1163 create_menu_item_with_mnemonic(menu_in_menu, "Grid Text...", "ChooseGridTextColor");
1164 create_menu_item_with_mnemonic(menu_in_menu, "Grid Block...", "ChooseGridBlockColor");
1165 create_menu_item_with_mnemonic(menu_in_menu, "Default Brush...", "ChooseBrushColor");
1166 create_menu_item_with_mnemonic(menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor");
1167 create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor");
1168 create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor");
1169 create_menu_item_with_mnemonic(menu_in_menu, "Clipper...", "ChooseClipperColor");
1170 create_menu_item_with_mnemonic(menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor");
1172 return colours_menu_item;
1178 PluginsMenu_clear();
1179 PluginToolbar_clear();
1182 Radiant_Initialise();
1184 PluginsMenu_populate();
1186 PluginToolbar_populate();
1190 void thunk_OnSleep()
1192 g_pParentWnd->OnSleep();
1197 OpenURL("https://gitlab.com/xonotic/xonotic/wikis/Mapping");
1200 void OpenBugReportURL()
1202 OpenURL("https://gitlab.com/xonotic/netradiant/issues");
1206 ui::Widget g_page_console{ui::null};
1208 void Console_ToggleShow()
1210 GroupDialog_showPage(g_page_console);
1213 ui::Widget g_page_entity{ui::null};
1215 void EntityInspector_ToggleShow()
1217 GroupDialog_showPage(g_page_entity);
1221 void SetClipMode(bool enable);
1223 void ModeChangeNotify();
1225 typedef void ( *ToolMode )();
1227 ToolMode g_currentToolMode = 0;
1228 bool g_currentToolModeSupportsComponentEditing = false;
1229 ToolMode g_defaultToolMode = 0;
1232 void SelectionSystem_DefaultMode()
1234 GlobalSelectionSystem().SetMode(SelectionSystem::ePrimitive);
1235 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eDefault);
1242 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1243 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1248 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1249 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1254 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1255 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1258 template<bool( *BoolFunction )()>
1259 class BoolFunctionExport {
1261 static void apply(const Callback<void(bool)> &importCallback)
1263 importCallback(BoolFunction());
1267 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1268 EdgeModeApplyCaller g_edgeMode_button_caller;
1269 Callback<void(const Callback<void(bool)> &)> g_edgeMode_button_callback(g_edgeMode_button_caller);
1270 ToggleItem g_edgeMode_button(g_edgeMode_button_callback);
1272 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1273 VertexModeApplyCaller g_vertexMode_button_caller;
1274 Callback<void(const Callback<void(bool)> &)> g_vertexMode_button_callback(g_vertexMode_button_caller);
1275 ToggleItem g_vertexMode_button(g_vertexMode_button_callback);
1277 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1278 FaceModeApplyCaller g_faceMode_button_caller;
1279 Callback<void(const Callback<void(bool)> &)> g_faceMode_button_callback(g_faceMode_button_caller);
1280 ToggleItem g_faceMode_button(g_faceMode_button_callback);
1282 void ComponentModeChanged()
1284 g_edgeMode_button.update();
1285 g_vertexMode_button.update();
1286 g_faceMode_button.update();
1289 void ComponentMode_SelectionChanged(const Selectable &selectable)
1291 if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1292 && GlobalSelectionSystem().countSelected() == 0) {
1293 SelectionSystem_DefaultMode();
1294 ComponentModeChanged();
1298 void SelectEdgeMode()
1301 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1302 GlobalSelectionSystem().Select( false );
1307 SelectionSystem_DefaultMode();
1308 } else if (GlobalSelectionSystem().countSelected() != 0) {
1309 if (!g_currentToolModeSupportsComponentEditing) {
1310 g_defaultToolMode();
1313 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1314 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eEdge);
1317 ComponentModeChanged();
1322 void SelectVertexMode()
1325 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1326 GlobalSelectionSystem().Select( false );
1331 SelectionSystem_DefaultMode();
1332 } else if (GlobalSelectionSystem().countSelected() != 0) {
1333 if (!g_currentToolModeSupportsComponentEditing) {
1334 g_defaultToolMode();
1337 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1338 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eVertex);
1341 ComponentModeChanged();
1346 void SelectFaceMode()
1349 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1350 GlobalSelectionSystem().Select( false );
1355 SelectionSystem_DefaultMode();
1356 } else if (GlobalSelectionSystem().countSelected() != 0) {
1357 if (!g_currentToolModeSupportsComponentEditing) {
1358 g_defaultToolMode();
1361 GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1362 GlobalSelectionSystem().SetComponentMode(SelectionSystem::eFace);
1365 ComponentModeChanged();
1371 class CloneSelected : public scene::Graph::Walker {
1373 NodeSmartReference worldspawn;
1375 CloneSelected(bool d) : doMakeUnique(d), worldspawn(Map_FindOrInsertWorldspawn(g_map))
1379 bool pre(const scene::Path &path, scene::Instance &instance) const
1381 if (path.size() == 1) {
1385 // ignore worldspawn, but keep checking children
1386 NodeSmartReference me(path.top().get());
1387 if (me == worldspawn) {
1391 if (!path.top().get().isRoot()) {
1392 Selectable *selectable = Instance_getSelectable(instance);
1394 && selectable->isSelected()) {
1402 void post(const scene::Path &path, scene::Instance &instance) const
1404 if (path.size() == 1) {
1408 // ignore worldspawn, but keep checking children
1409 NodeSmartReference me(path.top().get());
1410 if (me == worldspawn) {
1414 if (!path.top().get().isRoot()) {
1415 Selectable *selectable = Instance_getSelectable(instance);
1417 && selectable->isSelected()) {
1418 NodeSmartReference clone(Node_Clone(path.top()));
1420 Map_gatherNamespaced(clone);
1422 Node_getTraversable(path.parent().get())->insert(clone);
1428 void Scene_Clone_Selected(scene::Graph &graph, bool doMakeUnique)
1430 graph.traverse(CloneSelected(doMakeUnique));
1432 Map_mergeClonedNames();
1435 enum ENudgeDirection {
1447 AxisBase(const Vector3 &x_, const Vector3 &y_, const Vector3 &z_)
1448 : x(x_), y(y_), z(z_)
1453 AxisBase AxisBase_forViewType(VIEWTYPE viewtype)
1457 return AxisBase(g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z);
1459 return AxisBase(g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y);
1461 return AxisBase(g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x);
1464 ERROR_MESSAGE("invalid viewtype");
1465 return AxisBase(Vector3(0, 0, 0), Vector3(0, 0, 0), Vector3(0, 0, 0));
1468 Vector3 AxisBase_axisForDirection(const AxisBase &axes, ENudgeDirection direction)
1470 switch (direction) {
1472 return vector3_negated(axes.x);
1478 return vector3_negated(axes.y);
1481 ERROR_MESSAGE("invalid direction");
1482 return Vector3(0, 0, 0);
1485 void NudgeSelection(ENudgeDirection direction, float fAmount, VIEWTYPE viewtype)
1487 AxisBase axes(AxisBase_forViewType(viewtype));
1488 Vector3 view_direction(vector3_negated(axes.z));
1489 Vector3 nudge(vector3_scaled(AxisBase_axisForDirection(axes, direction), fAmount));
1490 GlobalSelectionSystem().NudgeManipulator(nudge, view_direction);
1493 void Selection_Clone()
1495 if (GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive) {
1496 UndoableCommand undo("cloneSelected");
1498 Scene_Clone_Selected(GlobalSceneGraph(), false);
1500 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1501 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1505 void Selection_Clone_MakeUnique()
1507 if (GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive) {
1508 UndoableCommand undo("cloneSelectedMakeUnique");
1510 Scene_Clone_Selected(GlobalSceneGraph(), true);
1512 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1513 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1517 // called when the escape key is used (either on the main window or on an inspector)
1518 void Selection_Deselect()
1520 if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent) {
1521 if (GlobalSelectionSystem().countSelectedComponents() != 0) {
1522 GlobalSelectionSystem().setSelectedAllComponents(false);
1524 SelectionSystem_DefaultMode();
1525 ComponentModeChanged();
1528 if (GlobalSelectionSystem().countSelectedComponents() != 0) {
1529 GlobalSelectionSystem().setSelectedAllComponents(false);
1531 GlobalSelectionSystem().setSelectedAll(false);
1537 void Selection_NudgeUp()
1539 UndoableCommand undo("nudgeSelectedUp");
1540 NudgeSelection(eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1543 void Selection_NudgeDown()
1545 UndoableCommand undo("nudgeSelectedDown");
1546 NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1549 void Selection_NudgeLeft()
1551 UndoableCommand undo("nudgeSelectedLeft");
1552 NudgeSelection(eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1555 void Selection_NudgeRight()
1557 UndoableCommand undo("nudgeSelectedRight");
1558 NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1562 void TranslateToolExport(const Callback<void(bool)> &importCallback)
1564 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate);
1567 void RotateToolExport(const Callback<void(bool)> &importCallback)
1569 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate);
1572 void ScaleToolExport(const Callback<void(bool)> &importCallback)
1574 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale);
1577 void DragToolExport(const Callback<void(bool)> &importCallback)
1579 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag);
1582 void ClipperToolExport(const Callback<void(bool)> &importCallback)
1584 importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip);
1587 FreeCaller<void(const Callback<void(bool)> &), TranslateToolExport> g_translatemode_button_caller;
1588 Callback<void(const Callback<void(bool)> &)> g_translatemode_button_callback(g_translatemode_button_caller);
1589 ToggleItem g_translatemode_button(g_translatemode_button_callback);
1591 FreeCaller<void(const Callback<void(bool)> &), RotateToolExport> g_rotatemode_button_caller;
1592 Callback<void(const Callback<void(bool)> &)> g_rotatemode_button_callback(g_rotatemode_button_caller);
1593 ToggleItem g_rotatemode_button(g_rotatemode_button_callback);
1595 FreeCaller<void(const Callback<void(bool)> &), ScaleToolExport> g_scalemode_button_caller;
1596 Callback<void(const Callback<void(bool)> &)> g_scalemode_button_callback(g_scalemode_button_caller);
1597 ToggleItem g_scalemode_button(g_scalemode_button_callback);
1599 FreeCaller<void(const Callback<void(bool)> &), DragToolExport> g_dragmode_button_caller;
1600 Callback<void(const Callback<void(bool)> &)> g_dragmode_button_callback(g_dragmode_button_caller);
1601 ToggleItem g_dragmode_button(g_dragmode_button_callback);
1603 FreeCaller<void(const Callback<void(bool)> &), ClipperToolExport> g_clipper_button_caller;
1604 Callback<void(const Callback<void(bool)> &)> g_clipper_button_callback(g_clipper_button_caller);
1605 ToggleItem g_clipper_button(g_clipper_button_callback);
1609 g_translatemode_button.update();
1610 g_rotatemode_button.update();
1611 g_scalemode_button.update();
1612 g_dragmode_button.update();
1613 g_clipper_button.update();
1616 const char *const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1620 if (g_currentToolMode == DragMode && g_defaultToolMode != DragMode) {
1621 g_defaultToolMode();
1623 g_currentToolMode = DragMode;
1624 g_currentToolModeSupportsComponentEditing = true;
1628 Sys_Status(c_ResizeMode_status);
1629 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eDrag);
1636 const char *const c_TranslateMode_status = "Translate Tool: translate objects and components";
1638 void TranslateMode()
1640 if (g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode) {
1641 g_defaultToolMode();
1643 g_currentToolMode = TranslateMode;
1644 g_currentToolModeSupportsComponentEditing = true;
1648 Sys_Status(c_TranslateMode_status);
1649 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eTranslate);
1655 const char *const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1659 if (g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode) {
1660 g_defaultToolMode();
1662 g_currentToolMode = RotateMode;
1663 g_currentToolModeSupportsComponentEditing = true;
1667 Sys_Status(c_RotateMode_status);
1668 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eRotate);
1674 const char *const c_ScaleMode_status = "Scale Tool: scale objects and components";
1678 if (g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode) {
1679 g_defaultToolMode();
1681 g_currentToolMode = ScaleMode;
1682 g_currentToolModeSupportsComponentEditing = true;
1686 Sys_Status(c_ScaleMode_status);
1687 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eScale);
1694 const char *const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1699 if (g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode) {
1700 g_defaultToolMode();
1702 g_currentToolMode = ClipperMode;
1703 g_currentToolModeSupportsComponentEditing = false;
1705 SelectionSystem_DefaultMode();
1709 Sys_Status(c_ClipperMode_status);
1710 GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eClip);
1717 void Texdef_Rotate(float angle)
1719 StringOutputStream command;
1720 command << "brushRotateTexture -angle " << angle;
1721 UndoableCommand undo(command.c_str());
1722 Select_RotateTexture(angle);
1725 void Texdef_RotateClockwise()
1727 Texdef_Rotate(static_cast<float>( fabs(g_si_globals.rotate)));
1730 void Texdef_RotateAntiClockwise()
1732 Texdef_Rotate(static_cast<float>( -fabs(g_si_globals.rotate)));
1735 void Texdef_Scale(float x, float y)
1737 StringOutputStream command;
1738 command << "brushScaleTexture -x " << x << " -y " << y;
1739 UndoableCommand undo(command.c_str());
1740 Select_ScaleTexture(x, y);
1743 void Texdef_ScaleUp()
1745 Texdef_Scale(0, g_si_globals.scale[1]);
1748 void Texdef_ScaleDown()
1750 Texdef_Scale(0, -g_si_globals.scale[1]);
1753 void Texdef_ScaleLeft()
1755 Texdef_Scale(-g_si_globals.scale[0], 0);
1758 void Texdef_ScaleRight()
1760 Texdef_Scale(g_si_globals.scale[0], 0);
1763 void Texdef_Shift(float x, float y)
1765 StringOutputStream command;
1766 command << "brushShiftTexture -x " << x << " -y " << y;
1767 UndoableCommand undo(command.c_str());
1768 Select_ShiftTexture(x, y);
1771 void Texdef_ShiftLeft()
1773 Texdef_Shift(-g_si_globals.shift[0], 0);
1776 void Texdef_ShiftRight()
1778 Texdef_Shift(g_si_globals.shift[0], 0);
1781 void Texdef_ShiftUp()
1783 Texdef_Shift(0, g_si_globals.shift[1]);
1786 void Texdef_ShiftDown()
1788 Texdef_Shift(0, -g_si_globals.shift[1]);
1792 class SnappableSnapToGridSelected : public scene::Graph::Walker {
1795 SnappableSnapToGridSelected(float snap)
1800 bool pre(const scene::Path &path, scene::Instance &instance) const
1802 if (path.top().get().visible()) {
1803 Snappable *snappable = Node_getSnappable(path.top());
1805 && Instance_getSelectable(instance)->isSelected()) {
1806 snappable->snapto(m_snap);
1813 void Scene_SnapToGrid_Selected(scene::Graph &graph, float snap)
1815 graph.traverse(SnappableSnapToGridSelected(snap));
1818 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker {
1821 ComponentSnappableSnapToGridSelected(float snap)
1826 bool pre(const scene::Path &path, scene::Instance &instance) const
1828 if (path.top().get().visible()) {
1829 ComponentSnappable *componentSnappable = Instance_getComponentSnappable(instance);
1830 if (componentSnappable != 0
1831 && Instance_getSelectable(instance)->isSelected()) {
1832 componentSnappable->snapComponents(m_snap);
1839 void Scene_SnapToGrid_Component_Selected(scene::Graph &graph, float snap)
1841 graph.traverse(ComponentSnappableSnapToGridSelected(snap));
1844 void Selection_SnapToGrid()
1846 StringOutputStream command;
1847 command << "snapSelected -grid " << GetGridSize();
1848 UndoableCommand undo(command.c_str());
1850 if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent) {
1851 Scene_SnapToGrid_Component_Selected(GlobalSceneGraph(), GetGridSize());
1853 Scene_SnapToGrid_Selected(GlobalSceneGraph(), GetGridSize());
1858 static gint qe_every_second(gpointer data)
1860 GdkModifierType mask;
1862 gdk_window_get_pointer(0, 0, 0, &mask);
1864 if ((mask & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) == 0) {
1871 guint s_qe_every_second_id = 0;
1873 void EverySecondTimer_enable()
1875 if (s_qe_every_second_id == 0) {
1876 s_qe_every_second_id = g_timeout_add(1000, qe_every_second, 0);
1880 void EverySecondTimer_disable()
1882 if (s_qe_every_second_id != 0) {
1883 g_source_remove(s_qe_every_second_id);
1884 s_qe_every_second_id = 0;
1888 gint window_realize_remove_decoration(ui::Widget widget, gpointer data)
1890 gdk_window_set_decorations(gtk_widget_get_window(widget),
1891 (GdkWMDecoration) (GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE |
1892 GDK_DECOR_MAXIMIZE));
1898 ui::Window m_window{ui::null};
1899 ui::Label m_label{ui::null};
1902 WaitDialog create_wait_dialog(const char *title, const char *text)
1906 dialog.m_window = MainFrame_getWindow().create_floating_window(title);
1907 gtk_window_set_resizable(dialog.m_window, FALSE);
1908 gtk_container_set_border_width(GTK_CONTAINER(dialog.m_window), 0);
1909 gtk_window_set_position(dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT);
1911 dialog.m_window.connect("realize", G_CALLBACK(window_realize_remove_decoration), 0);
1914 dialog.m_label = ui::Label(text);
1915 gtk_misc_set_alignment(GTK_MISC(dialog.m_label), 0.0, 0.5);
1916 gtk_label_set_justify(dialog.m_label, GTK_JUSTIFY_LEFT);
1917 dialog.m_label.show();
1918 dialog.m_label.dimensions(200, -1);
1920 dialog.m_window.add(dialog.m_label);
1926 clock_t g_lastRedrawTime = 0;
1927 const clock_t c_redrawInterval = clock_t(CLOCKS_PER_SEC / 10);
1929 bool redrawRequired()
1931 clock_t currentTime = std::clock();
1932 if (currentTime - g_lastRedrawTime >= c_redrawInterval) {
1933 g_lastRedrawTime = currentTime;
1940 bool MainFrame_isActiveApp()
1942 //globalOutputStream() << "listing\n";
1943 GList *list = gtk_window_list_toplevels();
1944 for (GList *i = list; i != 0; i = g_list_next(i)) {
1945 //globalOutputStream() << "toplevel.. ";
1946 if (gtk_window_is_active(ui::Window::from(i->data))) {
1947 //globalOutputStream() << "is active\n";
1950 //globalOutputStream() << "not active\n";
1955 typedef std::list<CopiedString> StringStack;
1956 StringStack g_wait_stack;
1959 bool ScreenUpdates_Enabled()
1961 return g_wait_stack.empty();
1964 void ScreenUpdates_process()
1966 if (redrawRequired() && g_wait.m_window.visible()) {
1972 void ScreenUpdates_Disable(const char *message, const char *title)
1974 if (g_wait_stack.empty()) {
1975 EverySecondTimer_disable();
1979 bool isActiveApp = MainFrame_isActiveApp();
1981 g_wait = create_wait_dialog(title, message);
1982 gtk_grab_add(g_wait.m_window);
1985 g_wait.m_window.show();
1986 ScreenUpdates_process();
1988 } else if (g_wait.m_window.visible()) {
1989 g_wait.m_label.text(message);
1990 ScreenUpdates_process();
1992 g_wait_stack.push_back(message);
1995 void ScreenUpdates_Enable()
1997 ASSERT_MESSAGE(!ScreenUpdates_Enabled(), "screen updates already enabled");
1998 g_wait_stack.pop_back();
1999 if (g_wait_stack.empty()) {
2000 EverySecondTimer_enable();
2001 //gtk_widget_set_sensitive(MainFrame_getWindow(), TRUE);
2003 gtk_grab_remove(g_wait.m_window);
2004 destroy_floating_window(g_wait.m_window);
2005 g_wait.m_window = ui::Window{ui::null};
2007 //gtk_window_present(MainFrame_getWindow());
2008 } else if (g_wait.m_window.visible()) {
2009 g_wait.m_label.text(g_wait_stack.back().c_str());
2010 ScreenUpdates_process();
2015 void GlobalCamera_UpdateWindow()
2017 if (g_pParentWnd != 0) {
2018 CamWnd_Update(*g_pParentWnd->GetCamWnd());
2022 void XY_UpdateWindow(MainFrame &mainframe)
2024 if (mainframe.GetXYWnd() != 0) {
2025 XYWnd_Update(*mainframe.GetXYWnd());
2029 void XZ_UpdateWindow(MainFrame &mainframe)
2031 if (mainframe.GetXZWnd() != 0) {
2032 XYWnd_Update(*mainframe.GetXZWnd());
2036 void YZ_UpdateWindow(MainFrame &mainframe)
2038 if (mainframe.GetYZWnd() != 0) {
2039 XYWnd_Update(*mainframe.GetYZWnd());
2043 void XY_UpdateAllWindows(MainFrame &mainframe)
2045 XY_UpdateWindow(mainframe);
2046 XZ_UpdateWindow(mainframe);
2047 YZ_UpdateWindow(mainframe);
2050 void XY_UpdateAllWindows()
2052 if (g_pParentWnd != 0) {
2053 XY_UpdateAllWindows(*g_pParentWnd);
2057 void UpdateAllWindows()
2059 GlobalCamera_UpdateWindow();
2060 XY_UpdateAllWindows();
2064 void ModeChangeNotify()
2066 SceneChangeNotify();
2069 void ClipperChangeNotify()
2071 GlobalCamera_UpdateWindow();
2072 XY_UpdateAllWindows();
2076 LatchedValue<int> g_Layout_viewStyle(0, "Window Layout");
2077 LatchedValue<bool> g_Layout_enableDetachableMenus(true, "Detachable Menus");
2078 LatchedValue<bool> g_Layout_enablePatchToolbar(true, "Patch Toolbar");
2079 LatchedValue<bool> g_Layout_enablePluginToolbar(true, "Plugin Toolbar");
2082 ui::MenuItem create_file_menu()
2085 auto file_menu_item = new_sub_menu_item_with_mnemonic("_File");
2086 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(file_menu_item));
2087 if (g_Layout_enableDetachableMenus.m_value) {
2091 create_menu_item_with_mnemonic(menu, "_New Map", "NewMap");
2092 menu_separator(menu);
2095 //++timo temporary experimental stuff for sleep mode..
2096 create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" );
2097 menu_separator( menu );
2101 create_menu_item_with_mnemonic(menu, "_Open...", "OpenMap");
2103 create_menu_item_with_mnemonic(menu, "_Import...", "ImportMap");
2104 create_menu_item_with_mnemonic(menu, "_Save", "SaveMap");
2105 create_menu_item_with_mnemonic(menu, "Save _as...", "SaveMapAs");
2106 create_menu_item_with_mnemonic(menu, "_Export selected...", "ExportSelected");
2107 menu_separator(menu);
2108 create_menu_item_with_mnemonic(menu, "Save re_gion...", "SaveRegion");
2109 menu_separator(menu);
2110 create_menu_item_with_mnemonic(menu, "_Refresh models", "RefreshReferences");
2111 menu_separator(menu);
2112 create_menu_item_with_mnemonic(menu, "Pro_ject settings...", "ProjectSettings");
2113 menu_separator(menu);
2114 create_menu_item_with_mnemonic(menu, "_Pointfile...", "TogglePointfile");
2115 menu_separator(menu);
2116 MRU_constructMenu(menu);
2117 menu_separator(menu);
2118 create_menu_item_with_mnemonic(menu, "E_xit", "Exit");
2120 return file_menu_item;
2123 ui::MenuItem create_edit_menu()
2126 auto edit_menu_item = new_sub_menu_item_with_mnemonic("_Edit");
2127 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(edit_menu_item));
2128 if (g_Layout_enableDetachableMenus.m_value) {
2131 create_menu_item_with_mnemonic(menu, "_Undo", "Undo");
2132 create_menu_item_with_mnemonic(menu, "_Redo", "Redo");
2133 menu_separator(menu);
2134 create_menu_item_with_mnemonic(menu, "_Copy", "Copy");
2135 create_menu_item_with_mnemonic(menu, "_Paste", "Paste");
2136 create_menu_item_with_mnemonic(menu, "P_aste To Camera", "PasteToCamera");
2137 menu_separator(menu);
2138 create_menu_item_with_mnemonic(menu, "_Duplicate", "CloneSelection");
2139 create_menu_item_with_mnemonic(menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique");
2140 create_menu_item_with_mnemonic(menu, "D_elete", "DeleteSelection");
2141 menu_separator(menu);
2142 create_menu_item_with_mnemonic(menu, "Pa_rent", "ParentSelection");
2143 menu_separator(menu);
2144 create_menu_item_with_mnemonic(menu, "C_lear Selection", "UnSelectSelection");
2145 create_menu_item_with_mnemonic(menu, "_Invert Selection", "InvertSelection");
2146 create_menu_item_with_mnemonic(menu, "Select i_nside", "SelectInside");
2147 create_menu_item_with_mnemonic(menu, "Select _touching", "SelectTouching");
2149 auto convert_menu = create_sub_menu_with_mnemonic(menu, "E_xpand Selection");
2150 if (g_Layout_enableDetachableMenus.m_value) {
2151 menu_tearoff(convert_menu);
2153 create_menu_item_with_mnemonic(convert_menu, "To Whole _Entities", "ExpandSelectionToEntities");
2155 menu_separator(menu);
2156 create_menu_item_with_mnemonic(menu, "Pre_ferences...", "Preferences");
2158 return edit_menu_item;
2161 void fill_view_xy_top_menu(ui::Menu menu)
2163 create_check_menu_item_with_mnemonic(menu, "XY (Top) View", "ToggleView");
2167 void fill_view_yz_side_menu(ui::Menu menu)
2169 create_check_menu_item_with_mnemonic(menu, "YZ (Side) View", "ToggleSideView");
2173 void fill_view_xz_front_menu(ui::Menu menu)
2175 create_check_menu_item_with_mnemonic(menu, "XZ (Front) View", "ToggleFrontView");
2179 ui::Widget g_toggle_z_item{ui::null};
2180 ui::Widget g_toggle_console_item{ui::null};
2181 ui::Widget g_toggle_entity_item{ui::null};
2182 ui::Widget g_toggle_entitylist_item{ui::null};
2184 ui::MenuItem create_view_menu(MainFrame::EViewStyle style)
2187 auto view_menu_item = new_sub_menu_item_with_mnemonic("Vie_w");
2188 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(view_menu_item));
2189 if (g_Layout_enableDetachableMenus.m_value) {
2193 if (style == MainFrame::eFloating) {
2194 fill_view_camera_menu(menu);
2195 fill_view_xy_top_menu(menu);
2196 fill_view_yz_side_menu(menu);
2197 fill_view_xz_front_menu(menu);
2199 if (style == MainFrame::eFloating || style == MainFrame::eSplit) {
2200 create_menu_item_with_mnemonic(menu, "Console View", "ToggleConsole");
2201 create_menu_item_with_mnemonic(menu, "Texture Browser", "ToggleTextures");
2202 create_menu_item_with_mnemonic(menu, "Entity Inspector", "ToggleEntityInspector");
2204 create_menu_item_with_mnemonic(menu, "Entity Inspector", "ViewEntityInfo");
2206 create_menu_item_with_mnemonic(menu, "_Surface Inspector", "SurfaceInspector");
2207 create_menu_item_with_mnemonic(menu, "Entity List", "EntityList");
2209 menu_separator(menu);
2211 auto camera_menu = create_sub_menu_with_mnemonic(menu, "Camera");
2212 if (g_Layout_enableDetachableMenus.m_value) {
2213 menu_tearoff(camera_menu);
2215 create_menu_item_with_mnemonic(camera_menu, "_Center", "CenterView");
2216 create_menu_item_with_mnemonic(camera_menu, "_Up Floor", "UpFloor");
2217 create_menu_item_with_mnemonic(camera_menu, "_Down Floor", "DownFloor");
2218 menu_separator(camera_menu);
2219 create_menu_item_with_mnemonic(camera_menu, "Far Clip Plane In", "CubicClipZoomIn");
2220 create_menu_item_with_mnemonic(camera_menu, "Far Clip Plane Out", "CubicClipZoomOut");
2221 menu_separator(camera_menu);
2222 create_menu_item_with_mnemonic(camera_menu, "Next leak spot", "NextLeakSpot");
2223 create_menu_item_with_mnemonic(camera_menu, "Previous leak spot", "PrevLeakSpot");
2224 menu_separator(camera_menu);
2225 create_menu_item_with_mnemonic(camera_menu, "Look Through Selected", "LookThroughSelected");
2226 create_menu_item_with_mnemonic(camera_menu, "Look Through Camera", "LookThroughCamera");
2228 menu_separator(menu);
2230 auto orthographic_menu = create_sub_menu_with_mnemonic(menu, "Orthographic");
2231 if (g_Layout_enableDetachableMenus.m_value) {
2232 menu_tearoff(orthographic_menu);
2234 if (style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating) {
2235 create_menu_item_with_mnemonic(orthographic_menu, "_Next (XY, YZ, XY)", "NextView");
2236 create_menu_item_with_mnemonic(orthographic_menu, "XY (Top)", "ViewTop");
2237 create_menu_item_with_mnemonic(orthographic_menu, "YZ", "ViewSide");
2238 create_menu_item_with_mnemonic(orthographic_menu, "XZ", "ViewFront");
2239 menu_separator(orthographic_menu);
2242 create_menu_item_with_mnemonic(orthographic_menu, "_XY 100%", "Zoom100");
2243 create_menu_item_with_mnemonic(orthographic_menu, "XY Zoom _In", "ZoomIn");
2244 create_menu_item_with_mnemonic(orthographic_menu, "XY Zoom _Out", "ZoomOut");
2247 menu_separator(menu);
2250 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, "Show");
2251 if (g_Layout_enableDetachableMenus.m_value) {
2252 menu_tearoff(menu_in_menu);
2254 create_check_menu_item_with_mnemonic(menu_in_menu, "Show _Angles", "ShowAngles");
2255 create_check_menu_item_with_mnemonic(menu_in_menu, "Show _Names", "ShowNames");
2256 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Blocks", "ShowBlocks");
2257 create_check_menu_item_with_mnemonic(menu_in_menu, "Show C_oordinates", "ShowCoordinates");
2258 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Window Outline", "ShowWindowOutline");
2259 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Axes", "ShowAxes");
2260 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Workzone", "ShowWorkzone");
2261 create_check_menu_item_with_mnemonic(menu_in_menu, "Show Stats", "ShowStats");
2265 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, "Filter");
2266 if (g_Layout_enableDetachableMenus.m_value) {
2267 menu_tearoff(menu_in_menu);
2269 Filters_constructMenu(menu_in_menu);
2271 menu_separator(menu);
2273 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, "Hide/Show");
2274 if (g_Layout_enableDetachableMenus.m_value) {
2275 menu_tearoff(menu_in_menu);
2277 create_menu_item_with_mnemonic(menu_in_menu, "Hide Selected", "HideSelected");
2278 create_menu_item_with_mnemonic(menu_in_menu, "Show Hidden", "ShowHidden");
2280 menu_separator(menu);
2282 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, "Region");
2283 if (g_Layout_enableDetachableMenus.m_value) {
2284 menu_tearoff(menu_in_menu);
2286 create_menu_item_with_mnemonic(menu_in_menu, "_Off", "RegionOff");
2287 create_menu_item_with_mnemonic(menu_in_menu, "_Set XY", "RegionSetXY");
2288 create_menu_item_with_mnemonic(menu_in_menu, "Set _Brush", "RegionSetBrush");
2289 create_menu_item_with_mnemonic(menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection");
2292 command_connect_accelerator("CenterXYView");
2294 return view_menu_item;
2297 ui::MenuItem create_selection_menu()
2300 auto selection_menu_item = new_sub_menu_item_with_mnemonic("M_odify");
2301 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(selection_menu_item));
2302 if (g_Layout_enableDetachableMenus.m_value) {
2307 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, "Components");
2308 if (g_Layout_enableDetachableMenus.m_value) {
2309 menu_tearoff(menu_in_menu);
2311 create_check_menu_item_with_mnemonic(menu_in_menu, "_Edges", "DragEdges");
2312 create_check_menu_item_with_mnemonic(menu_in_menu, "_Vertices", "DragVertices");
2313 create_check_menu_item_with_mnemonic(menu_in_menu, "_Faces", "DragFaces");
2316 menu_separator(menu);
2319 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, "Nudge");
2320 if (g_Layout_enableDetachableMenus.m_value) {
2321 menu_tearoff(menu_in_menu);
2323 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Left", "SelectNudgeLeft");
2324 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Right", "SelectNudgeRight");
2325 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Up", "SelectNudgeUp");
2326 create_menu_item_with_mnemonic(menu_in_menu, "Nudge Down", "SelectNudgeDown");
2329 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, "Rotate");
2330 if (g_Layout_enableDetachableMenus.m_value) {
2331 menu_tearoff(menu_in_menu);
2333 create_menu_item_with_mnemonic(menu_in_menu, "Rotate X", "RotateSelectionX");
2334 create_menu_item_with_mnemonic(menu_in_menu, "Rotate Y", "RotateSelectionY");
2335 create_menu_item_with_mnemonic(menu_in_menu, "Rotate Z", "RotateSelectionZ");
2338 auto menu_in_menu = create_sub_menu_with_mnemonic(menu, "Flip");
2339 if (g_Layout_enableDetachableMenus.m_value) {
2340 menu_tearoff(menu_in_menu);
2342 create_menu_item_with_mnemonic(menu_in_menu, "Flip _X", "MirrorSelectionX");
2343 create_menu_item_with_mnemonic(menu_in_menu, "Flip _Y", "MirrorSelectionY");
2344 create_menu_item_with_mnemonic(menu_in_menu, "Flip _Z", "MirrorSelectionZ");
2346 menu_separator(menu);
2347 create_menu_item_with_mnemonic(menu, "Arbitrary rotation...", "ArbitraryRotation");
2348 create_menu_item_with_mnemonic(menu, "Arbitrary scale...", "ArbitraryScale");
2350 return selection_menu_item;
2353 ui::MenuItem create_bsp_menu()
2356 auto bsp_menu_item = new_sub_menu_item_with_mnemonic("_Build");
2357 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(bsp_menu_item));
2359 if (g_Layout_enableDetachableMenus.m_value) {
2363 create_menu_item_with_mnemonic(menu, "Customize...", "BuildMenuCustomize");
2365 menu_separator(menu);
2367 Build_constructMenu(menu);
2371 return bsp_menu_item;
2374 ui::MenuItem create_grid_menu()
2377 auto grid_menu_item = new_sub_menu_item_with_mnemonic("_Grid");
2378 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(grid_menu_item));
2379 if (g_Layout_enableDetachableMenus.m_value) {
2383 Grid_constructMenu(menu);
2385 return grid_menu_item;
2388 ui::MenuItem create_misc_menu()
2391 auto misc_menu_item = new_sub_menu_item_with_mnemonic("M_isc");
2392 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(misc_menu_item));
2393 if (g_Layout_enableDetachableMenus.m_value) {
2398 create_menu_item_with_mnemonic( menu, "_Benchmark", makeCallbackF(GlobalCamera_Benchmark) );
2400 menu.add(create_colours_menu());
2402 create_menu_item_with_mnemonic(menu, "Find brush...", "FindBrush");
2403 create_menu_item_with_mnemonic(menu, "Map Info...", "MapInfo");
2404 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2405 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<void(), WXY_Print>());
2406 create_menu_item_with_mnemonic(menu, "_Background select", makeCallbackF(WXY_BackgroundSelect));
2407 return misc_menu_item;
2410 ui::MenuItem create_entity_menu()
2413 auto entity_menu_item = new_sub_menu_item_with_mnemonic("E_ntity");
2414 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(entity_menu_item));
2415 if (g_Layout_enableDetachableMenus.m_value) {
2419 Entity_constructMenu(menu);
2421 return entity_menu_item;
2424 ui::MenuItem create_brush_menu()
2427 auto brush_menu_item = new_sub_menu_item_with_mnemonic("B_rush");
2428 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(brush_menu_item));
2429 if (g_Layout_enableDetachableMenus.m_value) {
2433 Brush_constructMenu(menu);
2435 return brush_menu_item;
2438 ui::MenuItem create_patch_menu()
2441 auto patch_menu_item = new_sub_menu_item_with_mnemonic("_Curve");
2442 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(patch_menu_item));
2443 if (g_Layout_enableDetachableMenus.m_value) {
2447 Patch_constructMenu(menu);
2449 return patch_menu_item;
2452 ui::MenuItem create_help_menu()
2455 auto help_menu_item = new_sub_menu_item_with_mnemonic("_Help");
2456 auto menu = ui::Menu::from(gtk_menu_item_get_submenu(help_menu_item));
2457 if (g_Layout_enableDetachableMenus.m_value) {
2461 create_menu_item_with_mnemonic(menu, "Manual", "OpenManual");
2463 // this creates all the per-game drop downs for the game pack helps
2464 // it will take care of hooking the Sys_OpenURL calls etc.
2465 create_game_help_menu(menu);
2467 create_menu_item_with_mnemonic(menu, "Bug report", makeCallbackF(OpenBugReportURL));
2468 create_menu_item_with_mnemonic(menu, "Shortcuts list", makeCallbackF(DoCommandListDlg));
2469 create_menu_item_with_mnemonic(menu, "_About", makeCallbackF(DoAbout));
2471 return help_menu_item;
2474 ui::MenuBar create_main_menu(MainFrame::EViewStyle style)
2476 auto menu_bar = ui::MenuBar::from(gtk_menu_bar_new());
2479 menu_bar.add(create_file_menu());
2480 menu_bar.add(create_edit_menu());
2481 menu_bar.add(create_view_menu(style));
2482 menu_bar.add(create_selection_menu());
2483 menu_bar.add(create_bsp_menu());
2484 menu_bar.add(create_grid_menu());
2485 menu_bar.add(create_misc_menu());
2486 menu_bar.add(create_entity_menu());
2487 menu_bar.add(create_brush_menu());
2488 menu_bar.add(create_patch_menu());
2489 menu_bar.add(create_plugins_menu());
2490 menu_bar.add(create_help_menu());
2496 void PatchInspector_registerShortcuts()
2498 command_connect_accelerator("PatchInspector");
2501 void Patch_registerShortcuts()
2503 command_connect_accelerator("InvertCurveTextureX");
2504 command_connect_accelerator("InvertCurveTextureY");
2505 command_connect_accelerator("PatchInsertInsertColumn");
2506 command_connect_accelerator("PatchInsertInsertRow");
2507 command_connect_accelerator("PatchDeleteLastColumn");
2508 command_connect_accelerator("PatchDeleteLastRow");
2509 command_connect_accelerator("NaturalizePatch");
2510 //command_connect_accelerator("CapCurrentCurve");
2513 void Manipulators_registerShortcuts()
2515 toggle_add_accelerator("MouseRotate");
2516 toggle_add_accelerator("MouseTranslate");
2517 toggle_add_accelerator("MouseScale");
2518 toggle_add_accelerator("MouseDrag");
2519 toggle_add_accelerator("ToggleClipper");
2522 void TexdefNudge_registerShortcuts()
2524 command_connect_accelerator("TexRotateClock");
2525 command_connect_accelerator("TexRotateCounter");
2526 command_connect_accelerator("TexScaleUp");
2527 command_connect_accelerator("TexScaleDown");
2528 command_connect_accelerator("TexScaleLeft");
2529 command_connect_accelerator("TexScaleRight");
2530 command_connect_accelerator("TexShiftUp");
2531 command_connect_accelerator("TexShiftDown");
2532 command_connect_accelerator("TexShiftLeft");
2533 command_connect_accelerator("TexShiftRight");
2536 void SelectNudge_registerShortcuts()
2538 command_connect_accelerator("MoveSelectionDOWN");
2539 command_connect_accelerator("MoveSelectionUP");
2540 //command_connect_accelerator("SelectNudgeLeft");
2541 //command_connect_accelerator("SelectNudgeRight");
2542 //command_connect_accelerator("SelectNudgeUp");
2543 //command_connect_accelerator("SelectNudgeDown");
2546 void SnapToGrid_registerShortcuts()
2548 command_connect_accelerator("SnapToGrid");
2551 void SelectByType_registerShortcuts()
2553 command_connect_accelerator("SelectAllOfType");
2556 void SurfaceInspector_registerShortcuts()
2558 command_connect_accelerator("FitTexture");
2562 void register_shortcuts()
2564 PatchInspector_registerShortcuts();
2565 Patch_registerShortcuts();
2566 Grid_registerShortcuts();
2567 XYWnd_registerShortcuts();
2568 CamWnd_registerShortcuts();
2569 Manipulators_registerShortcuts();
2570 SurfaceInspector_registerShortcuts();
2571 TexdefNudge_registerShortcuts();
2572 SelectNudge_registerShortcuts();
2573 SnapToGrid_registerShortcuts();
2574 SelectByType_registerShortcuts();
2577 void File_constructToolbar(ui::Toolbar toolbar)
2579 toolbar_append_button(toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap");
2580 toolbar_append_button(toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap");
2583 void UndoRedo_constructToolbar(ui::Toolbar toolbar)
2585 toolbar_append_button(toolbar, "Undo (CTRL + Z)", "undo.png", "Undo");
2586 toolbar_append_button(toolbar, "Redo (CTRL + Y)", "redo.png", "Redo");
2589 void RotateFlip_constructToolbar(ui::Toolbar toolbar)
2591 toolbar_append_button(toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX");
2592 toolbar_append_button(toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX");
2593 toolbar_append_button(toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY");
2594 toolbar_append_button(toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY");
2595 toolbar_append_button(toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ");
2596 toolbar_append_button(toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ");
2599 void Select_constructToolbar(ui::Toolbar toolbar)
2601 toolbar_append_button(toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching");
2602 toolbar_append_button(toolbar, "Select inside", "selection_selectinside.png", "SelectInside");
2605 void CSG_constructToolbar(ui::Toolbar toolbar)
2607 toolbar_append_button(toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract");
2608 toolbar_append_button(toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge");
2609 toolbar_append_button(toolbar, "Make Hollow", "selection_makehollow.png", "CSGMakeHollow");
2610 toolbar_append_button(toolbar, "Make Room", "selection_makeroom.png", "CSGMakeRoom");
2613 void ComponentModes_constructToolbar(ui::Toolbar toolbar)
2615 toolbar_append_toggle_button(toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices");
2616 toolbar_append_toggle_button(toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges");
2617 toolbar_append_toggle_button(toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces");
2620 void Clipper_constructToolbar(ui::Toolbar toolbar)
2623 toolbar_append_toggle_button(toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper");
2626 void XYWnd_constructToolbar(ui::Toolbar toolbar)
2628 toolbar_append_button(toolbar, "Change views", "view_change.png", "NextView");
2631 void Manipulators_constructToolbar(ui::Toolbar toolbar)
2633 toolbar_append_toggle_button(toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate");
2634 toolbar_append_toggle_button(toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate");
2635 toolbar_append_toggle_button(toolbar, "Scale", "select_mousescale.png", "MouseScale");
2636 toolbar_append_toggle_button(toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag");
2638 Clipper_constructToolbar(toolbar);
2641 ui::Toolbar create_main_toolbar(MainFrame::EViewStyle style)
2643 auto toolbar = ui::Toolbar::from(gtk_toolbar_new());
2644 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
2645 gtk_toolbar_set_style(toolbar, GTK_TOOLBAR_ICONS);
2649 auto space = [&]() {
2650 auto btn = ui::ToolItem::from(gtk_separator_tool_item_new());
2655 File_constructToolbar(toolbar);
2659 UndoRedo_constructToolbar(toolbar);
2663 RotateFlip_constructToolbar(toolbar);
2667 Select_constructToolbar(toolbar);
2671 CSG_constructToolbar(toolbar);
2675 ComponentModes_constructToolbar(toolbar);
2677 if (style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating) {
2680 XYWnd_constructToolbar(toolbar);
2685 CamWnd_constructToolbar(toolbar);
2689 Manipulators_constructToolbar(toolbar);
2691 if (g_Layout_enablePatchToolbar.m_value) {
2694 Patch_constructToolbar(toolbar);
2699 toolbar_append_toggle_button(toolbar, "Texture Lock (SHIFT +T)", "texture_lock.png", "TogTexLock");
2703 /*auto g_view_entities_button =*/ toolbar_append_button(toolbar, "Entities (N)", "entities.png",
2704 "ToggleEntityInspector");
2705 auto g_view_console_button = toolbar_append_button(toolbar, "Console (O)", "console.png", "ToggleConsole");
2706 auto g_view_textures_button = toolbar_append_button(toolbar, "Texture Browser (T)", "texture_browser.png",
2708 // TODO: call light inspector
2709 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector");
2712 /*auto g_refresh_models_button =*/ toolbar_append_button(toolbar, "Refresh Models", "refresh_models.png",
2713 "RefreshReferences");
2716 // disable the console and texture button in the regular layouts
2717 if (style == MainFrame::eRegular || style == MainFrame::eRegularLeft) {
2718 gtk_widget_set_sensitive(g_view_console_button, FALSE);
2719 gtk_widget_set_sensitive(g_view_textures_button, FALSE);
2725 ui::Widget create_main_statusbar(ui::Widget pStatusLabel[c_count_status])
2727 auto table = ui::Table(1, c_count_status, FALSE);
2731 auto label = ui::Label("Label");
2732 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
2733 gtk_misc_set_padding(GTK_MISC(label), 4, 2);
2735 table.attach(label, {0, 1, 0, 1});
2736 pStatusLabel[c_command_status] = ui::Widget(label);
2739 for (unsigned int i = 1; (int) i < c_count_status; ++i) {
2740 auto frame = ui::Frame();
2742 table.attach(frame, {i, i + 1, 0, 1});
2743 gtk_frame_set_shadow_type(frame, GTK_SHADOW_IN);
2745 auto label = ui::Label("Label");
2746 gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_END);
2747 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
2748 gtk_misc_set_padding(GTK_MISC(label), 4, 2);
2751 pStatusLabel[i] = ui::Widget(label);
2754 return ui::Widget(table);
2760 WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" );
2762 class WindowFocusPrinter
2766 static gboolean frame_event( ui::Widget widget, GdkEvent* event, WindowFocusPrinter* self ){
2767 globalOutputStream() << self->m_name << " frame_event\n";
2770 static gboolean keys_changed( ui::Widget widget, WindowFocusPrinter* self ){
2771 globalOutputStream() << self->m_name << " keys_changed\n";
2774 static gboolean notify( ui::Window window, gpointer dummy, WindowFocusPrinter* self ){
2775 if ( gtk_window_is_active( window ) ) {
2776 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2780 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2785 WindowFocusPrinter( const char* name ) : m_name( name ){
2787 void connect( ui::Window toplevel_window ){
2788 toplevel_window.connect( "notify::has_toplevel_focus", G_CALLBACK( notify ), this );
2789 toplevel_window.connect( "notify::is_active", G_CALLBACK( notify ), this );
2790 toplevel_window.connect( "keys_changed", G_CALLBACK( keys_changed ), this );
2791 toplevel_window.connect( "frame_event", G_CALLBACK( frame_event ), this );
2795 WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" );
2799 class MainWindowActive {
2800 static gboolean notify(ui::Window window, gpointer dummy, MainWindowActive *self)
2802 if (g_wait.m_window && gtk_window_is_active(window) && !g_wait.m_window.visible()) {
2803 g_wait.m_window.show();
2810 void connect(ui::Window toplevel_window)
2812 toplevel_window.connect("notify::is-active", G_CALLBACK(notify), this);
2816 MainWindowActive g_MainWindowActive;
2818 SignalHandlerId XYWindowDestroyed_connect(const SignalHandler &handler)
2820 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst(handler);
2823 void XYWindowDestroyed_disconnect(SignalHandlerId id)
2825 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect(id);
2828 MouseEventHandlerId XYWindowMouseDown_connect(const MouseEventHandler &handler)
2830 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst(handler);
2833 void XYWindowMouseDown_disconnect(MouseEventHandlerId id)
2835 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect(id);
2838 // =============================================================================
2841 MainFrame *g_pParentWnd = 0;
2843 ui::Window MainFrame_getWindow()
2845 return g_pParentWnd ? g_pParentWnd->m_window : ui::Window{ui::null};
2848 std::vector<ui::Widget> g_floating_windows;
2850 MainFrame::MainFrame() : m_idleRedrawStatusText(RedrawStatusTextCaller(*this))
2859 for (auto &n : m_pStatusLabel) {
2863 m_bSleeping = false;
2868 MainFrame::~MainFrame()
2876 for (std::vector<ui::Widget>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i) {
2883 void MainFrame::SetActiveXY(XYWnd *p)
2886 m_pActiveXY->SetActive(false);
2892 m_pActiveXY->SetActive(true);
2897 void MainFrame::ReleaseContexts()
2901 m_pXYWnd->DestroyContext();
2904 m_pYZWnd->DestroyContext();
2907 m_pXZWnd->DestroyContext();
2910 m_pCamWnd->DestroyContext();
2913 m_pTexWnd->DestroyContext();
2916 m_pZWnd->DestroyContext();
2921 void MainFrame::CreateContexts()
2925 m_pCamWnd->CreateContext();
2928 m_pXYWnd->CreateContext();
2931 m_pYZWnd->CreateContext();
2934 m_pXZWnd->CreateContext();
2937 m_pTexWnd->CreateContext();
2940 m_pZWnd->CreateContext();
2949 void MainFrame::OnSleep()
2953 if ( m_bSleeping ) {
2954 // useful when trying to debug crashes in the sleep code
2955 globalOutputStream() << "Going into sleep mode..\n";
2957 globalOutputStream() << "Dispatching sleep msg...";
2958 DispatchRadiantMsg( RADIANT_SLEEP );
2959 globalOutputStream() << "Done.\n";
2961 gtk_window_iconify( m_window );
2962 GlobalSelectionSystem().setSelectedAll( false );
2964 GlobalShaderCache().unrealise();
2966 GlobalOpenGL_debugAssertNoErrors();
2967 ScreenUpdates_Disable();
2970 globalOutputStream() << "Releasing contexts...";
2972 globalOutputStream() << "Done.\n";
2976 globalOutputStream() << "Waking up\n";
2978 gtk_window_deiconify( m_window );
2981 globalOutputStream() << "Creating contexts...";
2983 globalOutputStream() << "Done.\n";
2985 globalOutputStream() << "Making current on camera...";
2986 m_pCamWnd->MakeCurrent();
2987 globalOutputStream() << "Done.\n";
2989 globalOutputStream() << "Reloading shaders...";
2991 GlobalShaderCache().realise();
2992 globalOutputStream() << "Done.\n";
2994 ScreenUpdates_Enable();
2996 globalOutputStream() << "Dispatching wake msg...";
2997 DispatchRadiantMsg( RADIANT_WAKEUP );
2998 globalOutputStream() << "Done\n";
3004 ui::Window create_splash()
3006 auto window = ui::Window(ui::window_type::TOP);
3007 gtk_window_set_decorated(window, false);
3008 gtk_window_set_resizable(window, false);
3009 gtk_window_set_modal(window, true);
3010 gtk_window_set_default_size(window, -1, -1);
3011 gtk_window_set_position(window, GTK_WIN_POS_CENTER);
3012 gtk_container_set_border_width(window, 0);
3014 auto image = new_local_image("splash.png");
3018 window.dimensions(-1, -1);
3024 static ui::Window splash_screen{ui::null};
3028 splash_screen = create_splash();
3035 splash_screen.destroy();
3038 WindowPositionTracker g_posCamWnd;
3039 WindowPositionTracker g_posXYWnd;
3040 WindowPositionTracker g_posXZWnd;
3041 WindowPositionTracker g_posYZWnd;
3043 static gint mainframe_delete(ui::Widget widget, GdkEvent *event, gpointer data)
3045 if (ConfirmModified("Exit Radiant")) {
3052 void MainFrame::Create()
3054 ui::Window window = ui::Window(ui::window_type::TOP);
3056 GlobalWindowObservers_connectTopLevel(window);
3058 gtk_window_set_transient_for(splash_screen, window);
3060 #if !GDEF_OS_WINDOWS
3062 GdkPixbuf *pixbuf = pixbuf_new_from_file_with_mask("bitmaps/icon.png");
3064 gtk_window_set_icon(window, pixbuf);
3065 g_object_unref(pixbuf);
3070 gtk_widget_add_events(window, GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK);
3071 window.connect("delete_event", G_CALLBACK(mainframe_delete), this);
3073 m_position_tracker.connect(window);
3076 g_mainframeWidgetFocusPrinter.connect( window );
3077 g_mainframeFocusPrinter.connect( window );
3080 g_MainWindowActive.connect(window);
3082 GetPlugInMgr().Init(window);
3084 auto vbox = ui::VBox(FALSE, 0);
3088 global_accel_connect_window(window);
3090 m_nCurrentStyle = (EViewStyle) g_Layout_viewStyle.m_value;
3092 register_shortcuts();
3094 auto main_menu = create_main_menu(CurrentStyle());
3095 vbox.pack_start(main_menu, FALSE, FALSE, 0);
3097 auto main_toolbar = create_main_toolbar(CurrentStyle());
3098 vbox.pack_start(main_toolbar, FALSE, FALSE, 0);
3100 auto plugin_toolbar = create_plugin_toolbar();
3101 if (!g_Layout_enablePluginToolbar.m_value) {
3102 plugin_toolbar.hide();
3104 vbox.pack_start(plugin_toolbar, FALSE, FALSE, 0);
3106 ui::Widget main_statusbar = create_main_statusbar(reinterpret_cast<ui::Widget *>(m_pStatusLabel));
3107 vbox.pack_end(main_statusbar, FALSE, TRUE, 2);
3109 GroupDialog_constructWindow(window);
3110 g_page_entity = GroupDialog_addPage("Entities", EntityInspector_constructWindow(GroupDialog_getWindow()),
3111 RawStringExportCaller("Entities"));
3113 if (FloatingGroupDialog()) {
3114 g_page_console = GroupDialog_addPage("Console", Console_constructWindow(GroupDialog_getWindow()),
3115 RawStringExportCaller("Console"));
3119 if ( g_multimon_globals.m_bStartOnPrimMon ) {
3120 PositionWindowOnPrimaryScreen( g_layout_globals.m_position );
3121 window_set_position( window, g_layout_globals.m_position );
3125 if (g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED) {
3126 gtk_window_maximize(window);
3127 WindowPosition default_position(-1, -1, 640, 480);
3128 window_set_position(window, default_position);
3130 window_set_position(window, g_layout_globals.m_position);
3137 if (CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft) {
3139 ui::Widget vsplit = ui::VPaned(ui::New);
3141 vbox.pack_start(vsplit, TRUE, TRUE, 0);
3145 ui::Widget console_window = Console_constructWindow(window);
3146 gtk_paned_pack2(GTK_PANED(vsplit), console_window, FALSE, TRUE);
3149 ui::Widget hsplit = ui::HPaned(ui::New);
3152 gtk_paned_add1(GTK_PANED(vsplit), hsplit);
3155 m_pXYWnd = new XYWnd();
3156 m_pXYWnd->SetViewType(XY);
3157 ui::Widget xy_window = ui::Widget(create_framed_widget(m_pXYWnd->GetWidget()));
3160 ui::Widget vsplit2 = ui::VPaned(ui::New);
3162 m_vSplit2 = vsplit2;
3164 if (CurrentStyle() == eRegular) {
3165 gtk_paned_add1(GTK_PANED(hsplit), xy_window);
3166 gtk_paned_add2(GTK_PANED(hsplit), vsplit2);
3168 gtk_paned_add1(GTK_PANED(hsplit), vsplit2);
3169 gtk_paned_add2(GTK_PANED(hsplit), xy_window);
3174 m_pCamWnd = NewCamWnd();
3175 GlobalCamera_setCamWnd(*m_pCamWnd);
3176 CamWnd_setParent(*m_pCamWnd, window);
3177 auto camera_window = create_framed_widget(CamWnd_getWidget(*m_pCamWnd));
3179 gtk_paned_add1(GTK_PANED(vsplit2), camera_window);
3182 auto texture_window = create_framed_widget(TextureBrowser_constructWindow(window));
3184 gtk_paned_add2(GTK_PANED(vsplit2), texture_window);
3189 gtk_paned_set_position(GTK_PANED(m_vSplit), g_layout_globals.nXYHeight);
3191 if (CurrentStyle() == eRegular) {
3192 gtk_paned_set_position(GTK_PANED(m_hSplit), g_layout_globals.nXYWidth);
3194 gtk_paned_set_position(GTK_PANED(m_hSplit), g_layout_globals.nCamWidth);
3197 gtk_paned_set_position(GTK_PANED(m_vSplit2), g_layout_globals.nCamHeight);
3198 } else if (CurrentStyle() == eFloating) {
3200 ui::Window window = ui::Window(create_persistent_floating_window("Camera", m_window));
3201 global_accel_connect_window(window);
3202 g_posCamWnd.connect(window);
3206 m_pCamWnd = NewCamWnd();
3207 GlobalCamera_setCamWnd(*m_pCamWnd);
3210 auto frame = create_framed_widget(CamWnd_getWidget(*m_pCamWnd));
3213 CamWnd_setParent(*m_pCamWnd, window);
3215 g_floating_windows.push_back(window);
3219 ui::Window window = ui::Window(create_persistent_floating_window(ViewType_getTitle(XY), m_window));
3220 global_accel_connect_window(window);
3221 g_posXYWnd.connect(window);
3223 m_pXYWnd = new XYWnd();
3224 m_pXYWnd->m_parent = window;
3225 m_pXYWnd->SetViewType(XY);
3229 auto frame = create_framed_widget(m_pXYWnd->GetWidget());
3232 XY_Top_Shown_Construct(window);
3234 g_floating_windows.push_back(window);
3238 ui::Window window = ui::Window(create_persistent_floating_window(ViewType_getTitle(XZ), m_window));
3239 global_accel_connect_window(window);
3240 g_posXZWnd.connect(window);
3242 m_pXZWnd = new XYWnd();
3243 m_pXZWnd->m_parent = window;
3244 m_pXZWnd->SetViewType(XZ);
3247 auto frame = create_framed_widget(m_pXZWnd->GetWidget());
3251 XZ_Front_Shown_Construct(window);
3253 g_floating_windows.push_back(window);
3257 ui::Window window = ui::Window(create_persistent_floating_window(ViewType_getTitle(YZ), m_window));
3258 global_accel_connect_window(window);
3259 g_posYZWnd.connect(window);
3261 m_pYZWnd = new XYWnd();
3262 m_pYZWnd->m_parent = window;
3263 m_pYZWnd->SetViewType(YZ);
3266 auto frame = create_framed_widget(m_pYZWnd->GetWidget());
3270 YZ_Side_Shown_Construct(window);
3272 g_floating_windows.push_back(window);
3276 auto frame = create_framed_widget(TextureBrowser_constructWindow(GroupDialog_getWindow()));
3277 g_page_textures = GroupDialog_addPage("Textures", frame, TextureBrowserExportTitleCaller());
3283 m_pCamWnd = NewCamWnd();
3284 GlobalCamera_setCamWnd(*m_pCamWnd);
3285 CamWnd_setParent(*m_pCamWnd, window);
3287 ui::Widget camera = CamWnd_getWidget(*m_pCamWnd);
3289 m_pYZWnd = new XYWnd();
3290 m_pYZWnd->SetViewType(YZ);
3292 ui::Widget yz = m_pYZWnd->GetWidget();
3294 m_pXYWnd = new XYWnd();
3295 m_pXYWnd->SetViewType(XY);
3297 ui::Widget xy = m_pXYWnd->GetWidget();
3299 m_pXZWnd = new XYWnd();
3300 m_pXZWnd->SetViewType(XZ);
3302 ui::Widget xz = m_pXZWnd->GetWidget();
3304 auto split = create_split_views(camera, yz, xy, xz);
3305 vbox.pack_start(split, TRUE, TRUE, 0);
3308 auto frame = create_framed_widget(TextureBrowser_constructWindow(window));
3309 g_page_textures = GroupDialog_addPage("Textures", frame, TextureBrowserExportTitleCaller());
3313 EntityList_constructWindow(window);
3314 PreferencesDialog_constructWindow(window);
3315 FindTextureDialog_constructWindow(window);
3316 SurfaceInspector_constructWindow(window);
3317 PatchInspector_constructWindow(window);
3319 SetActiveXY(m_pXYWnd);
3321 AddGridChangeCallback(SetGridStatusCaller(*this));
3322 AddGridChangeCallback(ReferenceCaller<MainFrame, void(), XY_UpdateAllWindows>(*this));
3324 g_defaultToolMode = DragMode;
3325 g_defaultToolMode();
3326 SetStatusText(m_command_status, c_TranslateMode_status);
3328 EverySecondTimer_enable();
3330 //GlobalShortcuts_reportUnregistered();
3333 void MainFrame::SaveWindowInfo()
3335 if (!FloatingGroupDialog()) {
3336 g_layout_globals.nXYHeight = gtk_paned_get_position(GTK_PANED(m_vSplit));
3338 if (CurrentStyle() != eRegular) {
3339 g_layout_globals.nCamWidth = gtk_paned_get_position(GTK_PANED(m_hSplit));
3341 g_layout_globals.nXYWidth = gtk_paned_get_position(GTK_PANED(m_hSplit));
3344 g_layout_globals.nCamHeight = gtk_paned_get_position(GTK_PANED(m_vSplit2));
3347 g_layout_globals.m_position = m_position_tracker.getPosition();
3349 g_layout_globals.nState = gdk_window_get_state(gtk_widget_get_window(m_window));
3352 void MainFrame::Shutdown()
3354 EverySecondTimer_disable();
3356 EntityList_destroyWindow();
3365 TextureBrowser_destroyWindow();
3367 DeleteCamWnd(m_pCamWnd);
3370 PreferencesDialog_destroyWindow();
3371 SurfaceInspector_destroyWindow();
3372 FindTextureDialog_destroyWindow();
3373 PatchInspector_destroyWindow();
3375 g_DbgDlg.destroyWindow();
3377 // destroying group-dialog last because it may contain texture-browser
3378 GroupDialog_destroyWindow();
3381 void MainFrame::RedrawStatusText()
3383 ui::Label::from(m_pStatusLabel[c_command_status]).text(m_command_status.c_str());
3384 ui::Label::from(m_pStatusLabel[c_position_status]).text(m_position_status.c_str());
3385 ui::Label::from(m_pStatusLabel[c_brushcount_status]).text(m_brushcount_status.c_str());
3386 ui::Label::from(m_pStatusLabel[c_texture_status]).text(m_texture_status.c_str());
3387 ui::Label::from(m_pStatusLabel[c_grid_status]).text(m_grid_status.c_str());
3390 void MainFrame::UpdateStatusText()
3392 m_idleRedrawStatusText.queueDraw();
3395 void MainFrame::SetStatusText(CopiedString &status_text, const char *pText)
3397 status_text = pText;
3401 void Sys_Status(const char *status)
3403 if (g_pParentWnd != 0) {
3404 g_pParentWnd->SetStatusText(g_pParentWnd->m_command_status, status);
3408 int getRotateIncrement()
3410 return static_cast<int>( g_si_globals.rotate );
3413 int getFarClipDistance()
3415 return g_camwindow_globals.m_nCubicScale;
3418 float ( *GridStatus_getGridSize )() = GetGridSize;
3420 int ( *GridStatus_getRotateIncrement )() = getRotateIncrement;
3422 int ( *GridStatus_getFarClipDistance )() = getFarClipDistance;
3424 bool ( *GridStatus_getTextureLockEnabled )();
3426 void MainFrame::SetGridStatus()
3428 StringOutputStream status(64);
3429 const char *lock = (GridStatus_getTextureLockEnabled()) ? "ON" : "OFF";
3430 status << (GetSnapGridSize() > 0 ? "G:" : "g:") << GridStatus_getGridSize()
3431 << " R:" << GridStatus_getRotateIncrement()
3432 << " C:" << GridStatus_getFarClipDistance()
3434 SetStatusText(m_grid_status, status.c_str());
3437 void GridStatus_onTextureLockEnabledChanged()
3439 if (g_pParentWnd != 0) {
3440 g_pParentWnd->SetGridStatus();
3444 void GlobalGL_sharedContextCreated()
3446 GLFont *g_font = NULL;
3448 // report OpenGL information
3449 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char *>( glGetString(GL_VENDOR)) << "\n";
3450 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char *>( glGetString(GL_RENDERER)) << "\n";
3451 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char *>( glGetString(GL_VERSION)) << "\n";
3452 const auto extensions = reinterpret_cast<const char *>( glGetString(GL_EXTENSIONS));
3453 globalOutputStream() << "GL_EXTENSIONS: " << (extensions ? extensions : "") << "\n";
3455 QGL_sharedContextCreated(GlobalOpenGL());
3457 ShaderCache_extensionsInitialised();
3459 GlobalShaderCache().realise();
3463 /* win32 is dodgy here, just use courier new then */
3464 g_font = glfont_create( "arial 9" );
3466 auto settings = gtk_settings_get_default();
3468 g_object_get(settings, "gtk-font-name", &fontname, NULL);
3469 g_font = glfont_create(fontname);
3472 GlobalOpenGL().m_font = g_font;
3475 void GlobalGL_sharedContextDestroyed()
3477 Textures_Unrealise();
3478 GlobalShaderCache().unrealise();
3480 QGL_sharedContextDestroyed(GlobalOpenGL());
3484 void Layout_constructPreferences(PreferencesPage &page)
3487 const char *layouts[] = {"window1.png", "window2.png", "window3.png", "window4.png"};
3488 page.appendRadioIcons(
3490 STRING_ARRAY_RANGE(layouts),
3491 make_property(g_Layout_viewStyle)
3494 page.appendCheckBox(
3495 "", "Detachable Menus",
3496 make_property(g_Layout_enableDetachableMenus)
3498 if (!string_empty(g_pGameDescription->getKeyValue("no_patch"))) {
3499 page.appendCheckBox(
3500 "", "Patch Toolbar",
3501 make_property(g_Layout_enablePatchToolbar)
3504 page.appendCheckBox(
3505 "", "Plugin Toolbar",
3506 make_property(g_Layout_enablePluginToolbar)
3510 void Layout_constructPage(PreferenceGroup &group)
3512 PreferencesPage page(group.createPage("Layout", "Layout Preferences"));
3513 Layout_constructPreferences(page);
3516 void Layout_registerPreferencesPage()
3518 PreferencesDialog_addInterfacePage(makeCallbackF(Layout_constructPage));
3522 #include "preferencesystem.h"
3523 #include "stringio.h"
3525 void MainFrame_Construct()
3527 GlobalCommands_insert("OpenManual", makeCallbackF(OpenHelpURL), Accelerator(GDK_KEY_F1));
3529 GlobalCommands_insert("Sleep", makeCallbackF(thunk_OnSleep),
3530 Accelerator('P', (GdkModifierType) (GDK_SHIFT_MASK | GDK_CONTROL_MASK)));
3531 GlobalCommands_insert("NewMap", makeCallbackF(NewMap));
3532 GlobalCommands_insert("OpenMap", makeCallbackF(OpenMap), Accelerator('O', (GdkModifierType) GDK_CONTROL_MASK));
3533 GlobalCommands_insert("ImportMap", makeCallbackF(ImportMap));
3534 GlobalCommands_insert("SaveMap", makeCallbackF(SaveMap), Accelerator('S', (GdkModifierType) GDK_CONTROL_MASK));
3535 GlobalCommands_insert("SaveMapAs", makeCallbackF(SaveMapAs));
3536 GlobalCommands_insert("ExportSelected", makeCallbackF(ExportMap));
3537 GlobalCommands_insert("SaveRegion", makeCallbackF(SaveRegion));
3538 GlobalCommands_insert("RefreshReferences", makeCallbackF(VFS_Refresh));
3539 GlobalCommands_insert("ProjectSettings", makeCallbackF(DoProjectSettings));
3540 GlobalCommands_insert("Exit", makeCallbackF(Exit));
3542 GlobalCommands_insert("Undo", makeCallbackF(Undo), Accelerator('Z', (GdkModifierType) GDK_CONTROL_MASK));
3543 GlobalCommands_insert("Redo", makeCallbackF(Redo), Accelerator('Y', (GdkModifierType) GDK_CONTROL_MASK));
3544 GlobalCommands_insert("Copy", makeCallbackF(Copy), Accelerator('C', (GdkModifierType) GDK_CONTROL_MASK));
3545 GlobalCommands_insert("Paste", makeCallbackF(Paste), Accelerator('V', (GdkModifierType) GDK_CONTROL_MASK));
3546 GlobalCommands_insert("PasteToCamera", makeCallbackF(PasteToCamera),
3547 Accelerator('V', (GdkModifierType) GDK_MOD1_MASK));
3548 GlobalCommands_insert("CloneSelection", makeCallbackF(Selection_Clone), Accelerator(GDK_KEY_space));
3549 GlobalCommands_insert("CloneSelectionAndMakeUnique", makeCallbackF(Selection_Clone_MakeUnique),
3550 Accelerator(GDK_KEY_space, (GdkModifierType) GDK_SHIFT_MASK));
3551 GlobalCommands_insert("DeleteSelection", makeCallbackF(deleteSelection), Accelerator(GDK_KEY_BackSpace));
3552 GlobalCommands_insert("ParentSelection", makeCallbackF(Scene_parentSelected));
3553 GlobalCommands_insert("UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator(GDK_KEY_Escape));
3554 GlobalCommands_insert("InvertSelection", makeCallbackF(Select_Invert), Accelerator('I'));
3555 GlobalCommands_insert("SelectInside", makeCallbackF(Select_Inside));
3556 GlobalCommands_insert("SelectTouching", makeCallbackF(Select_Touching));
3557 GlobalCommands_insert("ExpandSelectionToEntities", makeCallbackF(Scene_ExpandSelectionToEntities),
3558 Accelerator('E', (GdkModifierType) (GDK_MOD1_MASK | GDK_CONTROL_MASK)));
3559 GlobalCommands_insert("Preferences", makeCallbackF(PreferencesDialog_showDialog), Accelerator('P'));
3561 GlobalCommands_insert("ToggleConsole", makeCallbackF(Console_ToggleShow), Accelerator('O'));
3562 GlobalCommands_insert("ToggleEntityInspector", makeCallbackF(EntityInspector_ToggleShow), Accelerator('N'));
3563 GlobalCommands_insert("EntityList", makeCallbackF(EntityList_toggleShown), Accelerator('L'));
3565 GlobalCommands_insert("ShowHidden", makeCallbackF(Select_ShowAllHidden),
3566 Accelerator('H', (GdkModifierType) GDK_SHIFT_MASK));
3567 GlobalCommands_insert("HideSelected", makeCallbackF(HideSelected), Accelerator('H'));
3569 GlobalToggles_insert("DragVertices", makeCallbackF(SelectVertexMode),
3570 ToggleItem::AddCallbackCaller(g_vertexMode_button), Accelerator('V'));
3571 GlobalToggles_insert("DragEdges", makeCallbackF(SelectEdgeMode), ToggleItem::AddCallbackCaller(g_edgeMode_button),
3573 GlobalToggles_insert("DragFaces", makeCallbackF(SelectFaceMode), ToggleItem::AddCallbackCaller(g_faceMode_button),
3576 GlobalCommands_insert("MirrorSelectionX", makeCallbackF(Selection_Flipx));
3577 GlobalCommands_insert("RotateSelectionX", makeCallbackF(Selection_Rotatex));
3578 GlobalCommands_insert("MirrorSelectionY", makeCallbackF(Selection_Flipy));
3579 GlobalCommands_insert("RotateSelectionY", makeCallbackF(Selection_Rotatey));
3580 GlobalCommands_insert("MirrorSelectionZ", makeCallbackF(Selection_Flipz));
3581 GlobalCommands_insert("RotateSelectionZ", makeCallbackF(Selection_Rotatez));
3583 GlobalCommands_insert("ArbitraryRotation", makeCallbackF(DoRotateDlg));
3584 GlobalCommands_insert("ArbitraryScale", makeCallbackF(DoScaleDlg));
3586 GlobalCommands_insert("BuildMenuCustomize", makeCallbackF(DoBuildMenu));
3588 GlobalCommands_insert("FindBrush", makeCallbackF(DoFind));
3590 GlobalCommands_insert("MapInfo", makeCallbackF(DoMapInfo), Accelerator('M'));
3593 GlobalToggles_insert("ToggleClipper", makeCallbackF(ClipperMode), ToggleItem::AddCallbackCaller(g_clipper_button),
3596 GlobalToggles_insert("MouseTranslate", makeCallbackF(TranslateMode),
3597 ToggleItem::AddCallbackCaller(g_translatemode_button), Accelerator('W'));
3598 GlobalToggles_insert("MouseRotate", makeCallbackF(RotateMode), ToggleItem::AddCallbackCaller(g_rotatemode_button),
3600 GlobalToggles_insert("MouseScale", makeCallbackF(ScaleMode), ToggleItem::AddCallbackCaller(g_scalemode_button));
3601 GlobalToggles_insert("MouseDrag", makeCallbackF(DragMode), ToggleItem::AddCallbackCaller(g_dragmode_button),
3604 GlobalCommands_insert("ColorSchemeOriginal", makeCallbackF(ColorScheme_Original));
3605 GlobalCommands_insert("ColorSchemeQER", makeCallbackF(ColorScheme_QER));
3606 GlobalCommands_insert("ColorSchemeBlackAndGreen", makeCallbackF(ColorScheme_Black));
3607 GlobalCommands_insert("ColorSchemeYdnar", makeCallbackF(ColorScheme_Ydnar));
3608 GlobalCommands_insert("ChooseTextureBackgroundColor", makeCallback(g_ColoursMenu.m_textureback));
3609 GlobalCommands_insert("ChooseGridBackgroundColor", makeCallback(g_ColoursMenu.m_xyback));
3610 GlobalCommands_insert("ChooseGridMajorColor", makeCallback(g_ColoursMenu.m_gridmajor));
3611 GlobalCommands_insert("ChooseGridMinorColor", makeCallback(g_ColoursMenu.m_gridminor));
3612 GlobalCommands_insert("ChooseSmallGridMajorColor", makeCallback(g_ColoursMenu.m_gridmajor_alt));
3613 GlobalCommands_insert("ChooseSmallGridMinorColor", makeCallback(g_ColoursMenu.m_gridminor_alt));
3614 GlobalCommands_insert("ChooseGridTextColor", makeCallback(g_ColoursMenu.m_gridtext));
3615 GlobalCommands_insert("ChooseGridBlockColor", makeCallback(g_ColoursMenu.m_gridblock));
3616 GlobalCommands_insert("ChooseBrushColor", makeCallback(g_ColoursMenu.m_brush));
3617 GlobalCommands_insert("ChooseCameraBackgroundColor", makeCallback(g_ColoursMenu.m_cameraback));
3618 GlobalCommands_insert("ChooseSelectedBrushColor", makeCallback(g_ColoursMenu.m_selectedbrush));
3619 GlobalCommands_insert("ChooseCameraSelectedBrushColor", makeCallback(g_ColoursMenu.m_selectedbrush3d));
3620 GlobalCommands_insert("ChooseClipperColor", makeCallback(g_ColoursMenu.m_clipper));
3621 GlobalCommands_insert("ChooseOrthoViewNameColor", makeCallback(g_ColoursMenu.m_viewname));
3624 GlobalCommands_insert("CSGSubtract", makeCallbackF(CSG_Subtract),
3625 Accelerator('U', (GdkModifierType) GDK_SHIFT_MASK));
3626 GlobalCommands_insert("CSGMerge", makeCallbackF(CSG_Merge), Accelerator('U', (GdkModifierType) GDK_CONTROL_MASK));
3627 GlobalCommands_insert("CSGMakeHollow", makeCallbackF(CSG_MakeHollow));
3628 GlobalCommands_insert("CSGMakeRoom", makeCallbackF(CSG_MakeRoom));
3630 Grid_registerCommands();
3632 GlobalCommands_insert("SnapToGrid", makeCallbackF(Selection_SnapToGrid),
3633 Accelerator('G', (GdkModifierType) GDK_CONTROL_MASK));
3635 GlobalCommands_insert("SelectAllOfType", makeCallbackF(Select_AllOfType),
3636 Accelerator('A', (GdkModifierType) GDK_SHIFT_MASK));
3638 GlobalCommands_insert("TexRotateClock", makeCallbackF(Texdef_RotateClockwise),
3639 Accelerator(GDK_KEY_Next, (GdkModifierType) GDK_SHIFT_MASK));
3640 GlobalCommands_insert("TexRotateCounter", makeCallbackF(Texdef_RotateAntiClockwise),
3641 Accelerator(GDK_KEY_Prior, (GdkModifierType) GDK_SHIFT_MASK));
3642 GlobalCommands_insert("TexScaleUp", makeCallbackF(Texdef_ScaleUp),
3643 Accelerator(GDK_KEY_Up, (GdkModifierType) GDK_CONTROL_MASK));
3644 GlobalCommands_insert("TexScaleDown", makeCallbackF(Texdef_ScaleDown),
3645 Accelerator(GDK_KEY_Down, (GdkModifierType) GDK_CONTROL_MASK));
3646 GlobalCommands_insert("TexScaleLeft", makeCallbackF(Texdef_ScaleLeft),
3647 Accelerator(GDK_KEY_Left, (GdkModifierType) GDK_CONTROL_MASK));
3648 GlobalCommands_insert("TexScaleRight", makeCallbackF(Texdef_ScaleRight),
3649 Accelerator(GDK_KEY_Right, (GdkModifierType) GDK_CONTROL_MASK));
3650 GlobalCommands_insert("TexShiftUp", makeCallbackF(Texdef_ShiftUp),
3651 Accelerator(GDK_KEY_Up, (GdkModifierType) GDK_SHIFT_MASK));
3652 GlobalCommands_insert("TexShiftDown", makeCallbackF(Texdef_ShiftDown),
3653 Accelerator(GDK_KEY_Down, (GdkModifierType) GDK_SHIFT_MASK));
3654 GlobalCommands_insert("TexShiftLeft", makeCallbackF(Texdef_ShiftLeft),
3655 Accelerator(GDK_KEY_Left, (GdkModifierType) GDK_SHIFT_MASK));
3656 GlobalCommands_insert("TexShiftRight", makeCallbackF(Texdef_ShiftRight),
3657 Accelerator(GDK_KEY_Right, (GdkModifierType) GDK_SHIFT_MASK));
3659 GlobalCommands_insert("MoveSelectionDOWN", makeCallbackF(Selection_MoveDown), Accelerator(GDK_KEY_KP_Subtract));
3660 GlobalCommands_insert("MoveSelectionUP", makeCallbackF(Selection_MoveUp), Accelerator(GDK_KEY_KP_Add));
3662 GlobalCommands_insert("SelectNudgeLeft", makeCallbackF(Selection_NudgeLeft),
3663 Accelerator(GDK_KEY_Left, (GdkModifierType) GDK_MOD1_MASK));
3664 GlobalCommands_insert("SelectNudgeRight", makeCallbackF(Selection_NudgeRight),
3665 Accelerator(GDK_KEY_Right, (GdkModifierType) GDK_MOD1_MASK));
3666 GlobalCommands_insert("SelectNudgeUp", makeCallbackF(Selection_NudgeUp),
3667 Accelerator(GDK_KEY_Up, (GdkModifierType) GDK_MOD1_MASK));
3668 GlobalCommands_insert("SelectNudgeDown", makeCallbackF(Selection_NudgeDown),
3669 Accelerator(GDK_KEY_Down, (GdkModifierType) GDK_MOD1_MASK));
3671 Patch_registerCommands();
3672 XYShow_registerCommands();
3674 typedef FreeCaller<void(const Selectable &), ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3675 GlobalSelectionSystem().addSelectionChangeCallback(ComponentModeSelectionChangedCaller());
3677 GlobalPreferenceSystem().registerPreference("DetachableMenus",
3678 make_property_string(g_Layout_enableDetachableMenus.m_latched));
3679 GlobalPreferenceSystem().registerPreference("PatchToolBar",
3680 make_property_string(g_Layout_enablePatchToolbar.m_latched));
3681 GlobalPreferenceSystem().registerPreference("PluginToolBar",
3682 make_property_string(g_Layout_enablePluginToolbar.m_latched));
3683 GlobalPreferenceSystem().registerPreference("QE4StyleWindows", make_property_string(g_Layout_viewStyle.m_latched));
3684 GlobalPreferenceSystem().registerPreference("XYHeight", make_property_string(g_layout_globals.nXYHeight));
3685 GlobalPreferenceSystem().registerPreference("XYWidth", make_property_string(g_layout_globals.nXYWidth));
3686 GlobalPreferenceSystem().registerPreference("CamWidth", make_property_string(g_layout_globals.nCamWidth));
3687 GlobalPreferenceSystem().registerPreference("CamHeight", make_property_string(g_layout_globals.nCamHeight));
3689 GlobalPreferenceSystem().registerPreference("State", make_property_string(g_layout_globals.nState));
3690 GlobalPreferenceSystem().registerPreference("PositionX", make_property_string(g_layout_globals.m_position.x));
3691 GlobalPreferenceSystem().registerPreference("PositionY", make_property_string(g_layout_globals.m_position.y));
3692 GlobalPreferenceSystem().registerPreference("Width", make_property_string(g_layout_globals.m_position.w));
3693 GlobalPreferenceSystem().registerPreference("Height", make_property_string(g_layout_globals.m_position.h));
3695 GlobalPreferenceSystem().registerPreference("CamWnd", make_property<WindowPositionTracker_String>(g_posCamWnd));
3696 GlobalPreferenceSystem().registerPreference("XYWnd", make_property<WindowPositionTracker_String>(g_posXYWnd));
3697 GlobalPreferenceSystem().registerPreference("YZWnd", make_property<WindowPositionTracker_String>(g_posYZWnd));
3698 GlobalPreferenceSystem().registerPreference("XZWnd", make_property<WindowPositionTracker_String>(g_posXZWnd));
3701 const char *ENGINEPATH_ATTRIBUTE =
3706 #elif GDEF_OS_LINUX || GDEF_OS_BSD
3709 #error "unknown platform"
3712 StringOutputStream path(256);
3713 path << DirectoryCleaned(g_pGameDescription->getRequiredKeyValue(ENGINEPATH_ATTRIBUTE));
3714 g_strEnginePath = path.c_str();
3717 GlobalPreferenceSystem().registerPreference("EnginePath", make_property_string(g_strEnginePath));
3719 GlobalPreferenceSystem().registerPreference("DisableEnginePath", make_property_string(g_disableEnginePath));
3720 GlobalPreferenceSystem().registerPreference("DisableHomePath", make_property_string(g_disableHomePath));
3722 for (int i = 0; i < g_pakPathCount; i++) {
3723 std::string label = "PakPath" + std::to_string(i);
3724 GlobalPreferenceSystem().registerPreference(label.c_str(), make_property_string(g_strPakPath[i]));
3727 g_Layout_viewStyle.useLatched();
3728 g_Layout_enableDetachableMenus.useLatched();
3729 g_Layout_enablePatchToolbar.useLatched();
3730 g_Layout_enablePluginToolbar.useLatched();
3732 Layout_registerPreferencesPage();
3733 Paths_registerPreferencesPage();
3735 g_brushCount.setCountChangedCallback(makeCallbackF(QE_brushCountChanged));
3736 g_entityCount.setCountChangedCallback(makeCallbackF(QE_entityCountChanged));
3737 GlobalEntityCreator().setCounter(&g_entityCount);
3739 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3740 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3742 GlobalEntityClassManager().attach(g_WorldspawnColourEntityClassObserver);
3745 void MainFrame_Destroy()
3747 GlobalEntityClassManager().detach(g_WorldspawnColourEntityClassObserver);
3749 GlobalEntityCreator().setCounter(0);
3750 g_entityCount.setCountChangedCallback(Callback<void()>());
3751 g_brushCount.setCountChangedCallback(Callback<void()>());
3755 void GLWindow_Construct()
3757 GlobalPreferenceSystem().registerPreference("MouseButtons", make_property_string(g_glwindow_globals.m_nMouseType));
3760 void GLWindow_Destroy()