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"
103 #include "filterbar.h"
106 struct layout_globals_t
108 WindowPosition m_position;
118 m_position( -1, -1, 640, 480 ),
124 nState( GDK_WINDOW_STATE_MAXIMIZED ){
128 layout_globals_t g_layout_globals;
129 glwindow_globals_t g_glwindow_globals;
134 bool g_vfsInitialized = false;
137 if ( g_vfsInitialized ) return;
139 GlobalFileSystem().initialise();
140 g_vfsInitialized = true;
144 if ( !g_vfsInitialized ) return;
145 GlobalFileSystem().shutdown();
146 g_vfsInitialized = false;
150 if ( !g_vfsInitialized ) return;
151 GlobalFileSystem().clear();
153 GlobalFileSystem().refresh();
154 g_vfsInitialized = true;
155 // also refresh models
157 // also refresh texture browser
158 TextureBrowser_RefreshShaders();
166 class VFSModuleObserver : public ModuleObserver
178 VFSModuleObserver g_VFSModuleObserver;
180 void VFS_Construct(){
181 Radiant_attachHomePathsObserver( g_VFSModuleObserver );
185 Radiant_detachHomePathsObserver( g_VFSModuleObserver );
193 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
194 #define qREFKNOWNFOLDERID GUID
195 #define qKF_FLAG_CREATE 0x8000
196 #define qKF_FLAG_NO_ALIAS 0x1000
197 typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath );
198 static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath;
201 void HomePaths_Realise(){
204 const char* prefix = g_pGameDescription->getKeyValue( "prefix" );
205 if ( !string_empty( prefix ) ) {
206 StringOutputStream path( 256 );
210 path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/";
211 if ( file_is_directory( path.c_str() ) ) {
212 g_qeglobals.m_userEnginePath = path.c_str();
216 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
220 TCHAR mydocsdir[MAX_PATH + 1];
222 HMODULE shfolder = LoadLibrary( "shfolder.dll" );
224 qSHGetKnownFolderPath = (qSHGetKnownFolderPath_t *) GetProcAddress( shfolder, "SHGetKnownFolderPath" );
227 qSHGetKnownFolderPath = NULL;
229 CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
230 if ( qSHGetKnownFolderPath && qSHGetKnownFolderPath( qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw ) == S_OK ) {
231 memset( mydocsdir, 0, sizeof( mydocsdir ) );
232 wcstombs( mydocsdir, mydocsdirw, sizeof( mydocsdir ) - 1 );
233 CoTaskMemFree( mydocsdirw );
235 path << DirectoryCleaned( mydocsdir ) << ( prefix + 1 ) << "/";
236 if ( file_is_directory( path.c_str() ) ) {
237 g_qeglobals.m_userEnginePath = path.c_str();
239 FreeLibrary( shfolder );
245 FreeLibrary( shfolder );
247 if ( SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir ) ) {
249 path << DirectoryCleaned( mydocsdir ) << "My Games/" << ( prefix + 1 ) << "/";
250 // win32: only add it if it already exists
251 if ( file_is_directory( path.c_str() ) ) {
252 g_qeglobals.m_userEnginePath = path.c_str();
260 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
261 g_qeglobals.m_userEnginePath = path.c_str();
266 g_qeglobals.m_userEnginePath = EnginePath_get();
270 Q_mkdir( g_qeglobals.m_userEnginePath.c_str() );
273 StringOutputStream path( 256 );
274 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
275 g_qeglobals.m_userGamePath = path.c_str();
277 ASSERT_MESSAGE( !string_empty( g_qeglobals.m_userGamePath.c_str() ), "HomePaths_Realise: user-game-path is empty" );
278 Q_mkdir( g_qeglobals.m_userGamePath.c_str() );
281 ModuleObservers g_homePathObservers;
283 void Radiant_attachHomePathsObserver( ModuleObserver& observer ){
284 g_homePathObservers.attach( observer );
287 void Radiant_detachHomePathsObserver( ModuleObserver& observer ){
288 g_homePathObservers.detach( observer );
291 class HomePathsModuleObserver : public ModuleObserver
293 std::size_t m_unrealised;
295 HomePathsModuleObserver() : m_unrealised( 1 ){
299 if ( --m_unrealised == 0 ) {
301 g_homePathObservers.realise();
306 if ( ++m_unrealised == 1 ) {
307 g_homePathObservers.unrealise();
312 HomePathsModuleObserver g_HomePathsModuleObserver;
314 void HomePaths_Construct(){
315 Radiant_attachEnginePathObserver( g_HomePathsModuleObserver );
318 void HomePaths_Destroy(){
319 Radiant_detachEnginePathObserver( g_HomePathsModuleObserver );
325 CopiedString g_strEnginePath;
326 ModuleObservers g_enginePathObservers;
327 std::size_t g_enginepath_unrealised = 1;
329 void Radiant_attachEnginePathObserver( ModuleObserver& observer ){
330 g_enginePathObservers.attach( observer );
333 void Radiant_detachEnginePathObserver( ModuleObserver& observer ){
334 g_enginePathObservers.detach( observer );
338 void EnginePath_Realise(){
339 if ( --g_enginepath_unrealised == 0 ) {
340 g_enginePathObservers.realise();
345 const char* EnginePath_get(){
346 ASSERT_MESSAGE( g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised" );
347 return g_strEnginePath.c_str();
350 void EnginePath_Unrealise(){
351 if ( ++g_enginepath_unrealised == 1 ) {
352 g_enginePathObservers.unrealise();
356 void setEnginePath( const char* path ){
357 StringOutputStream buffer( 256 );
358 buffer << DirectoryCleaned( path );
359 if ( !path_equal( buffer.c_str(), g_strEnginePath.c_str() ) ) {
361 while ( !ConfirmModified( "Paths Changed" ) )
363 if ( Map_Unnamed( g_map ) ) {
374 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Changing Engine Path" );
376 EnginePath_Unrealise();
378 g_strEnginePath = buffer.c_str();
380 EnginePath_Realise();
386 CopiedString g_strPakPath[g_pakPathCount] = { "", "", "", "", "" };
387 ModuleObservers g_pakPathObservers[g_pakPathCount];
388 std::size_t g_pakpath_unrealised[g_pakPathCount] = { 1, 1, 1, 1, 1 };
390 void Radiant_attachPakPathObserver( int num, ModuleObserver& observer ){
391 g_pakPathObservers[num].attach( observer );
394 void Radiant_detachPakPathObserver( int num, ModuleObserver& observer ){
395 g_pakPathObservers[num].detach( observer );
399 void PakPath_Realise( int num ){
400 if ( --g_pakpath_unrealised[num] == 0 ) {
401 g_pakPathObservers[num].realise();
405 const char* PakPath_get( int num ){
406 std::string message = "PakPath_get: pak path " + std::to_string(num) + " not realised";
407 ASSERT_MESSAGE( g_pakpath_unrealised[num] == 0, message.c_str() );
408 return g_strPakPath[num].c_str();
411 void PakPath_Unrealise( int num ){
412 if ( ++g_pakpath_unrealised[num] == 1 ) {
413 g_pakPathObservers[num].unrealise();
417 void setPakPath( int num, const char* path ){
418 if (!g_strcmp0( path, "")) {
419 g_strPakPath[num] = "";
423 StringOutputStream buffer( 256 );
424 buffer << DirectoryCleaned( path );
425 if ( !path_equal( buffer.c_str(), g_strPakPath[num].c_str() ) ) {
426 std::string message = "Changing Pak Path " + std::to_string(num);
427 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", message.c_str() );
429 PakPath_Unrealise(num);
431 g_strPakPath[num] = buffer.c_str();
433 PakPath_Realise(num);
440 CopiedString g_strAppPath; ///< holds the full path of the executable
442 const char* AppPath_get(){
443 return g_strAppPath.c_str();
446 /// the path to the local rc-dir
447 const char* LocalRcPath_get( void ){
448 static CopiedString rc_path;
449 if ( rc_path.empty() ) {
450 StringOutputStream stream( 256 );
451 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
452 rc_path = stream.c_str();
454 return rc_path.c_str();
457 /// directory for temp files
458 /// NOTE: on *nix this is were we check for .pid
459 CopiedString g_strSettingsPath;
461 const char* SettingsPath_get(){
462 return g_strSettingsPath.c_str();
467 points to the game tools directory, for instance
468 C:/Program Files/Quake III Arena/GtkRadiant
470 this is one of the main variables that are configured by the game selection on startup
471 [GameToolsPath]/plugins
472 [GameToolsPath]/modules
475 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
477 const char* GameToolsPath_get(){
478 return g_strGameToolsPath.c_str();
482 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz) {
483 returnz(self.c_str());
486 static void Import(CopiedString &self, const char *value) {
487 setEnginePath( value );
492 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
493 returnz( self.c_str() );
496 static void Import( CopiedString &self, const char *value ) {
497 setPakPath( 0, value );
502 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
503 returnz( self.c_str() );
506 static void Import( CopiedString &self, const char *value ) {
507 setPakPath( 1, value );
512 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
513 returnz( self.c_str() );
516 static void Import( CopiedString &self, const char *value ) {
517 setPakPath( 2, value );
522 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 ) {
527 setPakPath( 3, value );
532 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
533 returnz( self.c_str() );
536 static void Import( CopiedString &self, const char *value ) {
537 setPakPath( 4, value );
541 bool g_disableEnginePath = false;
542 bool g_disableHomePath = false;
544 void Paths_constructPreferences( PreferencesPage& page ){
545 page.appendPathEntry( "Engine Path", true, make_property<EnginePath>(g_strEnginePath) );
548 "", "Do not use Engine Path",
553 "", "Do not use Home Path",
557 for ( int i = 0; i < g_pakPathCount; i++ ) {
558 std::string label = "Pak Path " + std::to_string(i);
561 page.appendPathEntry( label.c_str(), true, make_property<PakPath0>( g_strPakPath[i] ) );
564 page.appendPathEntry( label.c_str(), true, make_property<PakPath1>( g_strPakPath[i] ) );
567 page.appendPathEntry( label.c_str(), true, make_property<PakPath2>( g_strPakPath[i] ) );
570 page.appendPathEntry( label.c_str(), true, make_property<PakPath3>( g_strPakPath[i] ) );
573 page.appendPathEntry( label.c_str(), true, make_property<PakPath4>( g_strPakPath[i] ) );
579 void Paths_constructPage( PreferenceGroup& group ){
580 PreferencesPage page( group.createPage( "Paths", "Path Settings" ) );
581 Paths_constructPreferences( page );
584 void Paths_registerPreferencesPage(){
585 PreferencesDialog_addSettingsPage( makeCallbackF(Paths_constructPage) );
589 class PathsDialog : public Dialog
592 ui::Window BuildDialog(){
593 auto frame = create_dialog_frame( "Path settings", ui::Shadow::ETCHED_IN );
595 auto vbox2 = create_dialog_vbox( 0, 4 );
599 PreferencesPage preferencesPage( *this, vbox2 );
600 Paths_constructPreferences( preferencesPage );
603 return ui::Window(create_simple_modal_dialog_window( "Engine Path Not Found", m_modal, frame ));
607 PathsDialog g_PathsDialog;
609 bool g_strEnginePath_was_empty_1st_start = false;
611 void EnginePath_verify(){
612 if ( !file_exists( g_strEnginePath.c_str() ) || g_strEnginePath_was_empty_1st_start ) {
613 g_PathsDialog.Create();
614 g_PathsDialog.DoModal();
615 g_PathsDialog.Destroy();
621 CopiedString g_gamename;
622 CopiedString g_gamemode;
623 ModuleObservers g_gameNameObservers;
624 ModuleObservers g_gameModeObservers;
627 void Radiant_attachGameNameObserver( ModuleObserver& observer ){
628 g_gameNameObservers.attach( observer );
631 void Radiant_detachGameNameObserver( ModuleObserver& observer ){
632 g_gameNameObservers.detach( observer );
635 const char* basegame_get(){
636 return g_pGameDescription->getRequiredKeyValue( "basegame" );
639 const char* gamename_get(){
640 const char* gamename = g_gamename.c_str();
641 if ( string_empty( gamename ) ) {
642 return basegame_get();
647 void gamename_set( const char* gamename ){
648 if ( !string_equal( gamename, g_gamename.c_str() ) ) {
649 g_gameNameObservers.unrealise();
650 g_gamename = gamename;
651 g_gameNameObservers.realise();
655 void Radiant_attachGameModeObserver( ModuleObserver& observer ){
656 g_gameModeObservers.attach( observer );
659 void Radiant_detachGameModeObserver( ModuleObserver& observer ){
660 g_gameModeObservers.detach( observer );
663 const char* gamemode_get(){
664 return g_gamemode.c_str();
667 void gamemode_set( const char* gamemode ){
668 if ( !string_equal( gamemode, g_gamemode.c_str() ) ) {
669 g_gameModeObservers.unrealise();
670 g_gamemode = gamemode;
671 g_gameModeObservers.realise();
678 const char* const c_library_extension =
679 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
680 CMAKE_SHARED_MODULE_SUFFIX
681 #elif GDEF_OS_WINDOWS
685 #elif GDEF_OS_LINUX || GDEF_OS_BSD
690 void Radiant_loadModules( const char* path ){
691 Directory_forEach(path, matchFileExtension(c_library_extension, [&](const char *name) {
693 ASSERT_MESSAGE(strlen(path) + strlen(name) < 1024, "");
694 strcpy(fullname, path);
695 strcat(fullname, name);
696 globalOutputStream() << "Found '" << fullname << "'\n";
697 GlobalModuleServer_loadModule(fullname);
701 void Radiant_loadModulesFromRoot( const char* directory ){
703 StringOutputStream path( 256 );
704 path << directory << g_pluginsDir;
705 Radiant_loadModules( path.c_str() );
708 if ( !string_equal( g_pluginsDir, g_modulesDir ) ) {
709 StringOutputStream path( 256 );
710 path << directory << g_modulesDir;
711 Radiant_loadModules( path.c_str() );
715 //! Make COLOR_BRUSHES override worldspawn eclass colour.
716 void SetWorldspawnColour( const Vector3& colour ){
717 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert( "worldspawn", true );
718 eclass_release_state( worldspawn );
719 worldspawn->color = colour;
720 eclass_capture_state( worldspawn );
724 class WorldspawnColourEntityClassObserver : public ModuleObserver
726 std::size_t m_unrealised;
728 WorldspawnColourEntityClassObserver() : m_unrealised( 1 ){
732 if ( --m_unrealised == 0 ) {
733 SetWorldspawnColour( g_xywindow_globals.color_brushes );
738 if ( ++m_unrealised == 1 ) {
743 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
746 ModuleObservers g_gameToolsPathObservers;
748 void Radiant_attachGameToolsPathObserver( ModuleObserver& observer ){
749 g_gameToolsPathObservers.attach( observer );
752 void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ){
753 g_gameToolsPathObservers.detach( observer );
756 void Radiant_Initialise(){
757 GlobalModuleServer_Initialise();
759 Radiant_loadModulesFromRoot( AppPath_get() );
763 bool success = Radiant_Construct( GlobalModuleServer_get() );
764 ASSERT_MESSAGE( success, "module system failed to initialise - see radiant.log for error messages" );
766 g_gameToolsPathObservers.realise();
767 g_gameModeObservers.realise();
768 g_gameNameObservers.realise();
771 void Radiant_Shutdown(){
772 g_gameNameObservers.unrealise();
773 g_gameModeObservers.unrealise();
774 g_gameToolsPathObservers.unrealise();
776 if ( !g_preferences_globals.disable_ini ) {
777 globalOutputStream() << "Start writing prefs\n";
779 globalOutputStream() << "Done prefs\n";
784 GlobalModuleServer_Shutdown();
788 if ( ConfirmModified( "Exit Radiant" ) ) {
795 GlobalUndoSystem().undo();
800 GlobalUndoSystem().redo();
804 void deleteSelection(){
805 UndoableCommand undo( "deleteSelected" );
809 void Map_ExportSelected( TextOutputStream& ostream ){
810 Map_ExportSelected( ostream, Map_getFormat( g_map ) );
813 void Map_ImportSelected( TextInputStream& istream ){
814 Map_ImportSelected( istream, Map_getFormat( g_map ) );
817 void Selection_Copy(){
818 clipboard_copy( Map_ExportSelected );
821 void Selection_Paste(){
822 clipboard_paste( Map_ImportSelected );
826 if ( SelectedFaces_empty() ) {
831 SelectedFaces_copyTexture();
836 if ( SelectedFaces_empty() ) {
837 UndoableCommand undo( "paste" );
839 GlobalSelectionSystem().setSelectedAll( false );
844 SelectedFaces_pasteTexture();
848 void PasteToCamera(){
849 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
850 GlobalSelectionSystem().setSelectedAll( false );
852 UndoableCommand undo( "pasteToCamera" );
856 // Work out the delta
858 Select_GetMid( mid );
859 Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid );
862 GlobalSelectionSystem().translateSelected( delta );
866 void ColorScheme_Original(){
867 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
869 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
870 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
871 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
873 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
874 g_xywindow_globals.color_gridminor = Vector3( 0.75f, 0.75f, 0.75f );
875 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
876 g_xywindow_globals.color_gridminor_alt = Vector3( 0.5f, 0.0f, 0.0f );
877 g_xywindow_globals.color_gridmajor_alt = Vector3( 1.0f, 0.0f, 0.0f );
878 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
879 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
880 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
881 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
882 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
883 SetWorldspawnColour( g_xywindow_globals.color_brushes );
884 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
885 XY_UpdateAllWindows();
888 void ColorScheme_QER(){
889 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
891 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
892 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
893 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
895 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
896 g_xywindow_globals.color_gridminor = Vector3( 1.0f, 1.0f, 1.0f );
897 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
898 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
899 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
900 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
901 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
902 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
903 SetWorldspawnColour( g_xywindow_globals.color_brushes );
904 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
905 XY_UpdateAllWindows();
908 void ColorScheme_Black(){
909 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
911 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
912 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
913 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
915 g_xywindow_globals.color_gridback = Vector3( 0.0f, 0.0f, 0.0f );
916 g_xywindow_globals.color_gridminor = Vector3( 0.2f, 0.2f, 0.2f );
917 g_xywindow_globals.color_gridmajor = Vector3( 0.3f, 0.5f, 0.5f );
918 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
919 g_xywindow_globals.color_gridtext = Vector3( 1.0f, 1.0f, 1.0f );
920 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
921 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
922 g_xywindow_globals.color_brushes = Vector3( 1.0f, 1.0f, 1.0f );
923 SetWorldspawnColour( g_xywindow_globals.color_brushes );
924 g_xywindow_globals.color_viewname = Vector3( 0.7f, 0.7f, 0.0f );
925 XY_UpdateAllWindows();
928 /* ydnar: to emulate maya/max/lightwave color schemes */
929 void ColorScheme_Ydnar(){
930 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
932 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
933 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
934 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
936 g_xywindow_globals.color_gridback = Vector3( 0.77f, 0.77f, 0.77f );
937 g_xywindow_globals.color_gridminor = Vector3( 0.83f, 0.83f, 0.83f );
938 g_xywindow_globals.color_gridmajor = Vector3( 0.89f, 0.89f, 0.89f );
939 g_xywindow_globals.color_gridblock = Vector3( 1.0f, 1.0f, 1.0f );
940 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
941 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
942 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
943 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
944 SetWorldspawnColour( g_xywindow_globals.color_brushes );
945 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
946 XY_UpdateAllWindows();
949 typedef Callback<void(Vector3&)> GetColourCallback;
950 typedef Callback<void(const Vector3&)> SetColourCallback;
954 GetColourCallback m_get;
955 SetColourCallback m_set;
957 ChooseColour( const GetColourCallback& get, const SetColourCallback& set )
958 : m_get( get ), m_set( set ){
964 color_dialog( MainFrame_getWindow(), colour );
970 void Colour_get( const Vector3& colour, Vector3& other ){
974 typedef ConstReferenceCaller<Vector3, void(Vector3&), Colour_get> ColourGetCaller;
976 void Colour_set( Vector3& colour, const Vector3& other ){
981 typedef ReferenceCaller<Vector3, void(const Vector3&), Colour_set> ColourSetCaller;
983 void BrushColour_set( const Vector3& other ){
984 g_xywindow_globals.color_brushes = other;
985 SetWorldspawnColour( g_xywindow_globals.color_brushes );
989 typedef FreeCaller<void(const Vector3&), BrushColour_set> BrushColourSetCaller;
991 void ClipperColour_set( const Vector3& other ){
992 g_xywindow_globals.color_clipper = other;
993 Brush_clipperColourChanged();
997 typedef FreeCaller<void(const Vector3&), ClipperColour_set> ClipperColourSetCaller;
999 void TextureBrowserColour_get( Vector3& other ){
1000 other = TextureBrowser_getBackgroundColour( GlobalTextureBrowser() );
1003 typedef FreeCaller<void(Vector3&), TextureBrowserColour_get> TextureBrowserColourGetCaller;
1005 void TextureBrowserColour_set( const Vector3& other ){
1006 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), other );
1009 typedef FreeCaller<void(const Vector3&), TextureBrowserColour_set> TextureBrowserColourSetCaller;
1015 ChooseColour m_textureback;
1016 ChooseColour m_xyback;
1017 ChooseColour m_gridmajor;
1018 ChooseColour m_gridminor;
1019 ChooseColour m_gridmajor_alt;
1020 ChooseColour m_gridminor_alt;
1021 ChooseColour m_gridtext;
1022 ChooseColour m_gridblock;
1023 ChooseColour m_cameraback;
1024 ChooseColour m_brush;
1025 ChooseColour m_selectedbrush;
1026 ChooseColour m_selectedbrush3d;
1027 ChooseColour m_clipper;
1028 ChooseColour m_viewname;
1031 m_textureback( TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller() ),
1032 m_xyback( ColourGetCaller( g_xywindow_globals.color_gridback ), ColourSetCaller( g_xywindow_globals.color_gridback ) ),
1033 m_gridmajor( ColourGetCaller( g_xywindow_globals.color_gridmajor ), ColourSetCaller( g_xywindow_globals.color_gridmajor ) ),
1034 m_gridminor( ColourGetCaller( g_xywindow_globals.color_gridminor ), ColourSetCaller( g_xywindow_globals.color_gridminor ) ),
1035 m_gridmajor_alt( ColourGetCaller( g_xywindow_globals.color_gridmajor_alt ), ColourSetCaller( g_xywindow_globals.color_gridmajor_alt ) ),
1036 m_gridminor_alt( ColourGetCaller( g_xywindow_globals.color_gridminor_alt ), ColourSetCaller( g_xywindow_globals.color_gridminor_alt ) ),
1037 m_gridtext( ColourGetCaller( g_xywindow_globals.color_gridtext ), ColourSetCaller( g_xywindow_globals.color_gridtext ) ),
1038 m_gridblock( ColourGetCaller( g_xywindow_globals.color_gridblock ), ColourSetCaller( g_xywindow_globals.color_gridblock ) ),
1039 m_cameraback( ColourGetCaller( g_camwindow_globals.color_cameraback ), ColourSetCaller( g_camwindow_globals.color_cameraback ) ),
1040 m_brush( ColourGetCaller( g_xywindow_globals.color_brushes ), BrushColourSetCaller() ),
1041 m_selectedbrush( ColourGetCaller( g_xywindow_globals.color_selbrushes ), ColourSetCaller( g_xywindow_globals.color_selbrushes ) ),
1042 m_selectedbrush3d( ColourGetCaller( g_camwindow_globals.color_selbrushes3d ), ColourSetCaller( g_camwindow_globals.color_selbrushes3d ) ),
1043 m_clipper( ColourGetCaller( g_xywindow_globals.color_clipper ), ClipperColourSetCaller() ),
1044 m_viewname( ColourGetCaller( g_xywindow_globals.color_viewname ), ColourSetCaller( g_xywindow_globals.color_viewname ) ){
1048 ColoursMenu g_ColoursMenu;
1050 ui::MenuItem create_colours_menu(){
1051 auto colours_menu_item = new_sub_menu_item_with_mnemonic( "Colors" );
1052 auto menu_in_menu = ui::Menu::from( gtk_menu_item_get_submenu( colours_menu_item ) );
1053 if ( g_Layout_enableDetachableMenus.m_value ) {
1054 menu_tearoff( menu_in_menu );
1057 auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Themes" );
1058 if ( g_Layout_enableDetachableMenus.m_value ) {
1059 menu_tearoff( menu_3 );
1062 create_menu_item_with_mnemonic( menu_3, "QE4 Original", "ColorSchemeOriginal" );
1063 create_menu_item_with_mnemonic( menu_3, "Q3Radiant Original", "ColorSchemeQER" );
1064 create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" );
1065 create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" );
1067 menu_separator( menu_in_menu );
1069 create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" );
1070 create_menu_item_with_mnemonic( menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor" );
1071 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major...", "ChooseGridMajorColor" );
1072 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor...", "ChooseGridMinorColor" );
1073 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor" );
1074 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor" );
1075 create_menu_item_with_mnemonic( menu_in_menu, "Grid Text...", "ChooseGridTextColor" );
1076 create_menu_item_with_mnemonic( menu_in_menu, "Grid Block...", "ChooseGridBlockColor" );
1077 create_menu_item_with_mnemonic( menu_in_menu, "Default Brush...", "ChooseBrushColor" );
1078 create_menu_item_with_mnemonic( menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor" );
1079 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor" );
1080 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor" );
1081 create_menu_item_with_mnemonic( menu_in_menu, "Clipper...", "ChooseClipperColor" );
1082 create_menu_item_with_mnemonic( menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor" );
1084 return colours_menu_item;
1089 PluginsMenu_clear();
1090 PluginToolbar_clear();
1093 Radiant_Initialise();
1095 PluginsMenu_populate();
1097 PluginToolbar_populate();
1101 void thunk_OnSleep(){
1102 g_pParentWnd->OnSleep();
1106 OpenURL( "https://gitlab.com/xonotic/xonotic/wikis/Mapping" );
1109 void OpenBugReportURL(){
1110 OpenURL( "https://gitlab.com/xonotic/netradiant/issues" );
1114 ui::Widget g_page_console{ui::null};
1116 void Console_ToggleShow(){
1117 GroupDialog_showPage( g_page_console );
1120 ui::Widget g_page_entity{ui::null};
1122 void EntityInspector_ToggleShow(){
1123 GroupDialog_showPage( g_page_entity );
1127 void SetClipMode( bool enable );
1129 void ModeChangeNotify();
1131 typedef void ( *ToolMode )();
1133 ToolMode g_currentToolMode = 0;
1134 bool g_currentToolModeSupportsComponentEditing = false;
1135 ToolMode g_defaultToolMode = 0;
1138 void SelectionSystem_DefaultMode(){
1139 GlobalSelectionSystem().SetMode( SelectionSystem::ePrimitive );
1140 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eDefault );
1146 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1147 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1151 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1152 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1156 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1157 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1160 template<bool( *BoolFunction ) ( )>
1161 class BoolFunctionExport
1164 static void apply( const Callback<void(bool)> & importCallback ){
1165 importCallback( BoolFunction() );
1169 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1170 EdgeModeApplyCaller g_edgeMode_button_caller;
1171 Callback<void(const Callback<void(bool)> &)> g_edgeMode_button_callback( g_edgeMode_button_caller );
1172 ToggleItem g_edgeMode_button( g_edgeMode_button_callback );
1174 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1175 VertexModeApplyCaller g_vertexMode_button_caller;
1176 Callback<void(const Callback<void(bool)> &)> g_vertexMode_button_callback( g_vertexMode_button_caller );
1177 ToggleItem g_vertexMode_button( g_vertexMode_button_callback );
1179 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1180 FaceModeApplyCaller g_faceMode_button_caller;
1181 Callback<void(const Callback<void(bool)> &)> g_faceMode_button_callback( g_faceMode_button_caller );
1182 ToggleItem g_faceMode_button( g_faceMode_button_callback );
1184 void ComponentModeChanged(){
1185 g_edgeMode_button.update();
1186 g_vertexMode_button.update();
1187 g_faceMode_button.update();
1190 void ComponentMode_SelectionChanged( const Selectable& selectable ){
1191 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1192 && GlobalSelectionSystem().countSelected() == 0 ) {
1193 SelectionSystem_DefaultMode();
1194 ComponentModeChanged();
1198 void SelectEdgeMode(){
1200 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1201 GlobalSelectionSystem().Select( false );
1206 SelectionSystem_DefaultMode();
1208 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1209 if ( !g_currentToolModeSupportsComponentEditing ) {
1210 g_defaultToolMode();
1213 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1214 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eEdge );
1217 ComponentModeChanged();
1222 void SelectVertexMode(){
1224 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1225 GlobalSelectionSystem().Select( false );
1229 if ( VertexMode() ) {
1230 SelectionSystem_DefaultMode();
1232 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1233 if ( !g_currentToolModeSupportsComponentEditing ) {
1234 g_defaultToolMode();
1237 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1238 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eVertex );
1241 ComponentModeChanged();
1246 void SelectFaceMode(){
1248 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1249 GlobalSelectionSystem().Select( false );
1254 SelectionSystem_DefaultMode();
1256 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1257 if ( !g_currentToolModeSupportsComponentEditing ) {
1258 g_defaultToolMode();
1261 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1262 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eFace );
1265 ComponentModeChanged();
1271 class CloneSelected : public scene::Graph::Walker
1274 NodeSmartReference worldspawn;
1276 CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
1279 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1280 if ( path.size() == 1 ) {
1284 // ignore worldspawn, but keep checking children
1285 NodeSmartReference me( path.top().get() );
1286 if ( me == worldspawn ) {
1290 if ( !path.top().get().isRoot() ) {
1291 Selectable* selectable = Instance_getSelectable( instance );
1292 if ( selectable != 0
1293 && selectable->isSelected() ) {
1301 void post( const scene::Path& path, scene::Instance& instance ) const {
1302 if ( path.size() == 1 ) {
1306 // ignore worldspawn, but keep checking children
1307 NodeSmartReference me( path.top().get() );
1308 if ( me == worldspawn ) {
1312 if ( !path.top().get().isRoot() ) {
1313 Selectable* selectable = Instance_getSelectable( instance );
1314 if ( selectable != 0
1315 && selectable->isSelected() ) {
1316 NodeSmartReference clone( Node_Clone( path.top() ) );
1317 if ( doMakeUnique ) {
1318 Map_gatherNamespaced( clone );
1320 Node_getTraversable( path.parent().get() )->insert( clone );
1326 void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){
1327 graph.traverse( CloneSelected( doMakeUnique ) );
1329 Map_mergeClonedNames();
1332 enum ENudgeDirection
1346 AxisBase( const Vector3& x_, const Vector3& y_, const Vector3& z_ )
1347 : x( x_ ), y( y_ ), z( z_ ){
1351 AxisBase AxisBase_forViewType( VIEWTYPE viewtype ){
1355 return AxisBase( g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z );
1357 return AxisBase( g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y );
1359 return AxisBase( g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x );
1362 ERROR_MESSAGE( "invalid viewtype" );
1363 return AxisBase( Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) );
1366 Vector3 AxisBase_axisForDirection( const AxisBase& axes, ENudgeDirection direction ){
1367 switch ( direction )
1370 return vector3_negated( axes.x );
1376 return vector3_negated( axes.y );
1379 ERROR_MESSAGE( "invalid direction" );
1380 return Vector3( 0, 0, 0 );
1383 void NudgeSelection( ENudgeDirection direction, float fAmount, VIEWTYPE viewtype ){
1384 AxisBase axes( AxisBase_forViewType( viewtype ) );
1385 Vector3 view_direction( vector3_negated( axes.z ) );
1386 Vector3 nudge( vector3_scaled( AxisBase_axisForDirection( axes, direction ), fAmount ) );
1387 GlobalSelectionSystem().NudgeManipulator( nudge, view_direction );
1390 void Selection_Clone(){
1391 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1392 UndoableCommand undo( "cloneSelected" );
1394 Scene_Clone_Selected( GlobalSceneGraph(), false );
1396 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1397 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1401 void Selection_Clone_MakeUnique(){
1402 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1403 UndoableCommand undo( "cloneSelectedMakeUnique" );
1405 Scene_Clone_Selected( GlobalSceneGraph(), true );
1407 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1408 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1412 // called when the escape key is used (either on the main window or on an inspector)
1413 void Selection_Deselect(){
1414 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1415 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1416 GlobalSelectionSystem().setSelectedAllComponents( false );
1420 SelectionSystem_DefaultMode();
1421 ComponentModeChanged();
1426 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1427 GlobalSelectionSystem().setSelectedAllComponents( false );
1431 GlobalSelectionSystem().setSelectedAll( false );
1437 void Selection_NudgeUp(){
1438 UndoableCommand undo( "nudgeSelectedUp" );
1439 NudgeSelection( eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1442 void Selection_NudgeDown(){
1443 UndoableCommand undo( "nudgeSelectedDown" );
1444 NudgeSelection( eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1447 void Selection_NudgeLeft(){
1448 UndoableCommand undo( "nudgeSelectedLeft" );
1449 NudgeSelection( eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1452 void Selection_NudgeRight(){
1453 UndoableCommand undo( "nudgeSelectedRight" );
1454 NudgeSelection( eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1458 void TranslateToolExport( const Callback<void(bool)> & importCallback ){
1459 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate );
1462 void RotateToolExport( const Callback<void(bool)> & importCallback ){
1463 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate );
1466 void ScaleToolExport( const Callback<void(bool)> & importCallback ){
1467 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale );
1470 void DragToolExport( const Callback<void(bool)> & importCallback ){
1471 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag );
1474 void ClipperToolExport( const Callback<void(bool)> & importCallback ){
1475 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip );
1478 FreeCaller<void(const Callback<void(bool)> &), TranslateToolExport> g_translatemode_button_caller;
1479 Callback<void(const Callback<void(bool)> &)> g_translatemode_button_callback( g_translatemode_button_caller );
1480 ToggleItem g_translatemode_button( g_translatemode_button_callback );
1482 FreeCaller<void(const Callback<void(bool)> &), RotateToolExport> g_rotatemode_button_caller;
1483 Callback<void(const Callback<void(bool)> &)> g_rotatemode_button_callback( g_rotatemode_button_caller );
1484 ToggleItem g_rotatemode_button( g_rotatemode_button_callback );
1486 FreeCaller<void(const Callback<void(bool)> &), ScaleToolExport> g_scalemode_button_caller;
1487 Callback<void(const Callback<void(bool)> &)> g_scalemode_button_callback( g_scalemode_button_caller );
1488 ToggleItem g_scalemode_button( g_scalemode_button_callback );
1490 FreeCaller<void(const Callback<void(bool)> &), DragToolExport> g_dragmode_button_caller;
1491 Callback<void(const Callback<void(bool)> &)> g_dragmode_button_callback( g_dragmode_button_caller );
1492 ToggleItem g_dragmode_button( g_dragmode_button_callback );
1494 FreeCaller<void(const Callback<void(bool)> &), ClipperToolExport> g_clipper_button_caller;
1495 Callback<void(const Callback<void(bool)> &)> g_clipper_button_callback( g_clipper_button_caller );
1496 ToggleItem g_clipper_button( g_clipper_button_callback );
1499 g_translatemode_button.update();
1500 g_rotatemode_button.update();
1501 g_scalemode_button.update();
1502 g_dragmode_button.update();
1503 g_clipper_button.update();
1506 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1509 if ( g_currentToolMode == DragMode && g_defaultToolMode != DragMode ) {
1510 g_defaultToolMode();
1514 g_currentToolMode = DragMode;
1515 g_currentToolModeSupportsComponentEditing = true;
1517 OnClipMode( false );
1519 Sys_Status( c_ResizeMode_status );
1520 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eDrag );
1527 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1529 void TranslateMode(){
1530 if ( g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode ) {
1531 g_defaultToolMode();
1535 g_currentToolMode = TranslateMode;
1536 g_currentToolModeSupportsComponentEditing = true;
1538 OnClipMode( false );
1540 Sys_Status( c_TranslateMode_status );
1541 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eTranslate );
1547 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1550 if ( g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode ) {
1551 g_defaultToolMode();
1555 g_currentToolMode = RotateMode;
1556 g_currentToolModeSupportsComponentEditing = true;
1558 OnClipMode( false );
1560 Sys_Status( c_RotateMode_status );
1561 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eRotate );
1567 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1570 if ( g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode ) {
1571 g_defaultToolMode();
1575 g_currentToolMode = ScaleMode;
1576 g_currentToolModeSupportsComponentEditing = true;
1578 OnClipMode( false );
1580 Sys_Status( c_ScaleMode_status );
1581 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eScale );
1588 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1592 if ( g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode ) {
1593 g_defaultToolMode();
1597 g_currentToolMode = ClipperMode;
1598 g_currentToolModeSupportsComponentEditing = false;
1600 SelectionSystem_DefaultMode();
1604 Sys_Status( c_ClipperMode_status );
1605 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eClip );
1612 void Texdef_Rotate( float angle ){
1613 StringOutputStream command;
1614 command << "brushRotateTexture -angle " << angle;
1615 UndoableCommand undo( command.c_str() );
1616 Select_RotateTexture( angle );
1619 void Texdef_RotateClockwise(){
1620 Texdef_Rotate( static_cast<float>( fabs( g_si_globals.rotate ) ) );
1623 void Texdef_RotateAntiClockwise(){
1624 Texdef_Rotate( static_cast<float>( -fabs( g_si_globals.rotate ) ) );
1627 void Texdef_Scale( float x, float y ){
1628 StringOutputStream command;
1629 command << "brushScaleTexture -x " << x << " -y " << y;
1630 UndoableCommand undo( command.c_str() );
1631 Select_ScaleTexture( x, y );
1634 void Texdef_ScaleUp(){
1635 Texdef_Scale( 0, g_si_globals.scale[1] );
1638 void Texdef_ScaleDown(){
1639 Texdef_Scale( 0, -g_si_globals.scale[1] );
1642 void Texdef_ScaleLeft(){
1643 Texdef_Scale( -g_si_globals.scale[0],0 );
1646 void Texdef_ScaleRight(){
1647 Texdef_Scale( g_si_globals.scale[0],0 );
1650 void Texdef_Shift( float x, float y ){
1651 StringOutputStream command;
1652 command << "brushShiftTexture -x " << x << " -y " << y;
1653 UndoableCommand undo( command.c_str() );
1654 Select_ShiftTexture( x, y );
1657 void Texdef_ShiftLeft(){
1658 Texdef_Shift( -g_si_globals.shift[0], 0 );
1661 void Texdef_ShiftRight(){
1662 Texdef_Shift( g_si_globals.shift[0], 0 );
1665 void Texdef_ShiftUp(){
1666 Texdef_Shift( 0, g_si_globals.shift[1] );
1669 void Texdef_ShiftDown(){
1670 Texdef_Shift( 0, -g_si_globals.shift[1] );
1675 class SnappableSnapToGridSelected : public scene::Graph::Walker
1679 SnappableSnapToGridSelected( float snap )
1683 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1684 if ( path.top().get().visible() ) {
1685 Snappable* snappable = Node_getSnappable( path.top() );
1687 && Instance_getSelectable( instance )->isSelected() ) {
1688 snappable->snapto( m_snap );
1695 void Scene_SnapToGrid_Selected( scene::Graph& graph, float snap ){
1696 graph.traverse( SnappableSnapToGridSelected( snap ) );
1699 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1703 ComponentSnappableSnapToGridSelected( float snap )
1707 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1708 if ( path.top().get().visible() ) {
1709 ComponentSnappable* componentSnappable = Instance_getComponentSnappable( instance );
1710 if ( componentSnappable != 0
1711 && Instance_getSelectable( instance )->isSelected() ) {
1712 componentSnappable->snapComponents( m_snap );
1719 void Scene_SnapToGrid_Component_Selected( scene::Graph& graph, float snap ){
1720 graph.traverse( ComponentSnappableSnapToGridSelected( snap ) );
1723 void Selection_SnapToGrid(){
1724 StringOutputStream command;
1725 command << "snapSelected -grid " << GetGridSize();
1726 UndoableCommand undo( command.c_str() );
1728 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1729 Scene_SnapToGrid_Component_Selected( GlobalSceneGraph(), GetGridSize() );
1733 Scene_SnapToGrid_Selected( GlobalSceneGraph(), GetGridSize() );
1738 static gint qe_every_second( gpointer data ){
1739 GdkModifierType mask;
1741 gdk_window_get_pointer( 0, 0, 0, &mask );
1743 if ( ( mask & ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK ) ) == 0 ) {
1750 guint s_qe_every_second_id = 0;
1752 void EverySecondTimer_enable(){
1753 if ( s_qe_every_second_id == 0 ) {
1754 s_qe_every_second_id = g_timeout_add( 1000, qe_every_second, 0 );
1758 void EverySecondTimer_disable(){
1759 if ( s_qe_every_second_id != 0 ) {
1760 g_source_remove( s_qe_every_second_id );
1761 s_qe_every_second_id = 0;
1765 gint window_realize_remove_decoration( ui::Widget widget, gpointer data ){
1766 gdk_window_set_decorations( gtk_widget_get_window(widget), (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) );
1773 ui::Window m_window{ui::null};
1774 ui::Label m_label{ui::null};
1777 WaitDialog create_wait_dialog( const char* title, const char* text ){
1780 dialog.m_window = MainFrame_getWindow().create_floating_window(title);
1781 gtk_window_set_resizable( dialog.m_window, FALSE );
1782 gtk_container_set_border_width( GTK_CONTAINER( dialog.m_window ), 0 );
1783 gtk_window_set_position( dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT );
1785 dialog.m_window.connect( "realize", G_CALLBACK( window_realize_remove_decoration ), 0 );
1788 dialog.m_label = ui::Label( text );
1789 gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 );
1790 gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT );
1791 dialog.m_label.show();
1792 dialog.m_label.dimensions(200, -1);
1794 dialog.m_window.add(dialog.m_label);
1801 clock_t g_lastRedrawTime = 0;
1802 const clock_t c_redrawInterval = clock_t( CLOCKS_PER_SEC / 10 );
1804 bool redrawRequired(){
1805 clock_t currentTime = std::clock();
1806 if ( currentTime - g_lastRedrawTime >= c_redrawInterval ) {
1807 g_lastRedrawTime = currentTime;
1814 bool MainFrame_isActiveApp(){
1815 //globalOutputStream() << "listing\n";
1816 GList* list = gtk_window_list_toplevels();
1817 for ( GList* i = list; i != 0; i = g_list_next( i ) )
1819 //globalOutputStream() << "toplevel.. ";
1820 if ( gtk_window_is_active( ui::Window::from( i->data ) ) ) {
1821 //globalOutputStream() << "is active\n";
1824 //globalOutputStream() << "not active\n";
1829 typedef std::list<CopiedString> StringStack;
1830 StringStack g_wait_stack;
1833 bool ScreenUpdates_Enabled(){
1834 return g_wait_stack.empty();
1837 void ScreenUpdates_process(){
1838 if ( redrawRequired() && g_wait.m_window.visible() ) {
1844 void ScreenUpdates_Disable( const char* message, const char* title ){
1845 if ( g_wait_stack.empty() ) {
1846 EverySecondTimer_disable();
1850 bool isActiveApp = MainFrame_isActiveApp();
1852 g_wait = create_wait_dialog( title, message );
1853 gtk_grab_add( g_wait.m_window );
1855 if ( isActiveApp ) {
1856 g_wait.m_window.show();
1857 ScreenUpdates_process();
1860 else if ( g_wait.m_window.visible() ) {
1861 g_wait.m_label.text(message);
1862 ScreenUpdates_process();
1864 g_wait_stack.push_back( message );
1867 void ScreenUpdates_Enable(){
1868 ASSERT_MESSAGE( !ScreenUpdates_Enabled(), "screen updates already enabled" );
1869 g_wait_stack.pop_back();
1870 if ( g_wait_stack.empty() ) {
1871 EverySecondTimer_enable();
1872 //gtk_widget_set_sensitive(MainFrame_getWindow(), TRUE);
1874 gtk_grab_remove( g_wait.m_window );
1875 destroy_floating_window( g_wait.m_window );
1876 g_wait.m_window = ui::Window{ui::null};
1878 //gtk_window_present(MainFrame_getWindow());
1880 else if ( g_wait.m_window.visible() ) {
1881 g_wait.m_label.text(g_wait_stack.back().c_str());
1882 ScreenUpdates_process();
1887 void GlobalCamera_UpdateWindow(){
1888 if ( g_pParentWnd != 0 ) {
1889 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
1893 void XY_UpdateWindow( MainFrame& mainframe ){
1894 if ( mainframe.GetXYWnd() != 0 ) {
1895 XYWnd_Update( *mainframe.GetXYWnd() );
1899 void XZ_UpdateWindow( MainFrame& mainframe ){
1900 if ( mainframe.GetXZWnd() != 0 ) {
1901 XYWnd_Update( *mainframe.GetXZWnd() );
1905 void YZ_UpdateWindow( MainFrame& mainframe ){
1906 if ( mainframe.GetYZWnd() != 0 ) {
1907 XYWnd_Update( *mainframe.GetYZWnd() );
1911 void XY_UpdateAllWindows( MainFrame& mainframe ){
1912 XY_UpdateWindow( mainframe );
1913 XZ_UpdateWindow( mainframe );
1914 YZ_UpdateWindow( mainframe );
1917 void XY_UpdateAllWindows(){
1918 if ( g_pParentWnd != 0 ) {
1919 XY_UpdateAllWindows( *g_pParentWnd );
1923 void UpdateAllWindows(){
1924 GlobalCamera_UpdateWindow();
1925 XY_UpdateAllWindows();
1929 void ModeChangeNotify(){
1930 SceneChangeNotify();
1933 void ClipperChangeNotify(){
1934 GlobalCamera_UpdateWindow();
1935 XY_UpdateAllWindows();
1939 LatchedValue<int> g_Layout_viewStyle( 0, "Window Layout" );
1940 LatchedValue<bool> g_Layout_enableDetachableMenus( true, "Detachable Menus" );
1941 LatchedValue<bool> g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
1942 LatchedValue<bool> g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
1943 LatchedValue<bool> g_Layout_enableFilterToolbar( true, "Filter Toolbar" );
1946 ui::MenuItem create_file_menu(){
1948 auto file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
1949 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( file_menu_item ) );
1950 if ( g_Layout_enableDetachableMenus.m_value ) {
1951 menu_tearoff( menu );
1954 create_menu_item_with_mnemonic( menu, "_New Map", "NewMap" );
1955 menu_separator( menu );
1958 //++timo temporary experimental stuff for sleep mode..
1959 create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" );
1960 menu_separator( menu );
1964 create_menu_item_with_mnemonic( menu, "_Open...", "OpenMap" );
1966 create_menu_item_with_mnemonic( menu, "_Import...", "ImportMap" );
1967 create_menu_item_with_mnemonic( menu, "_Save", "SaveMap" );
1968 create_menu_item_with_mnemonic( menu, "Save _as...", "SaveMapAs" );
1969 create_menu_item_with_mnemonic( menu, "_Export selected...", "ExportSelected" );
1970 menu_separator( menu );
1971 create_menu_item_with_mnemonic( menu, "Save re_gion...", "SaveRegion" );
1972 // menu_separator( menu );
1973 // create_menu_item_with_mnemonic( menu, "_Refresh models", "RefreshReferences" );
1974 // menu_separator( menu );
1975 create_menu_item_with_mnemonic( menu, "Pro_ject settings...", "ProjectSettings" );
1976 menu_separator( menu );
1977 create_menu_item_with_mnemonic( menu, "_Pointfile...", "TogglePointfile" );
1978 menu_separator( menu );
1979 MRU_constructMenu( menu );
1980 menu_separator( menu );
1981 // create_menu_item_with_mnemonic( menu, "Check for NetRadiant update (web)", "CheckForUpdate" ); // FIXME
1982 create_menu_item_with_mnemonic( menu, "E_xit", "Exit" );
1984 return file_menu_item;
1987 ui::MenuItem create_edit_menu(){
1989 auto edit_menu_item = new_sub_menu_item_with_mnemonic( "_Edit" );
1990 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( edit_menu_item ) );
1991 if ( g_Layout_enableDetachableMenus.m_value ) {
1992 menu_tearoff( menu );
1994 create_menu_item_with_mnemonic( menu, "_Undo", "Undo" );
1995 create_menu_item_with_mnemonic( menu, "_Redo", "Redo" );
1996 menu_separator( menu );
1997 create_menu_item_with_mnemonic( menu, "_Copy", "Copy" );
1998 create_menu_item_with_mnemonic( menu, "_Paste", "Paste" );
1999 create_menu_item_with_mnemonic( menu, "P_aste To Camera", "PasteToCamera" );
2000 menu_separator( menu );
2001 create_menu_item_with_mnemonic( menu, "_Duplicate", "CloneSelection" );
2002 create_menu_item_with_mnemonic( menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique" );
2003 create_menu_item_with_mnemonic( menu, "D_elete", "DeleteSelection" );
2004 menu_separator( menu );
2005 create_menu_item_with_mnemonic( menu, "Snap To Grid", "SnapToGrid" );
2006 //create_menu_item_with_mnemonic( menu, "Pa_rent", "ParentSelection" );
2007 menu_separator( menu );
2008 create_menu_item_with_mnemonic( menu, "C_lear Selection", "UnSelectSelection" );
2009 create_menu_item_with_mnemonic( menu, "_Invert Selection", "InvertSelection" );
2010 create_menu_item_with_mnemonic( menu, "Select i_nside", "SelectInside" );
2011 create_menu_item_with_mnemonic( menu, "Select _touching", "SelectTouching" );
2013 menu_separator( menu );
2015 // auto convert_menu = create_sub_menu_with_mnemonic( menu, "E_xpand Selection" );
2016 // if ( g_Layout_enableDetachableMenus.m_value ) {
2017 // menu_tearoff( convert_menu );
2019 create_menu_item_with_mnemonic( menu, "Select All Of Type", "SelectAllOfType" );
2020 create_menu_item_with_mnemonic( menu, "_Expand Selection To Entities", "ExpandSelectionToEntities" );
2022 menu_separator( menu );
2023 create_menu_item_with_mnemonic( menu, "Pre_ferences...", "Preferences" );
2025 return edit_menu_item;
2028 void fill_view_xy_top_menu( ui::Menu menu ){
2029 create_check_menu_item_with_mnemonic( menu, "XY (Top) View", "ToggleView" );
2033 void fill_view_yz_side_menu( ui::Menu menu ){
2034 create_check_menu_item_with_mnemonic( menu, "YZ (Side) View", "ToggleSideView" );
2038 void fill_view_xz_front_menu( ui::Menu menu ){
2039 create_check_menu_item_with_mnemonic( menu, "XZ (Front) View", "ToggleFrontView" );
2043 ui::Widget g_toggle_z_item{ui::null};
2044 ui::Widget g_toggle_console_item{ui::null};
2045 ui::Widget g_toggle_entity_item{ui::null};
2046 ui::Widget g_toggle_entitylist_item{ui::null};
2048 ui::MenuItem create_view_menu( MainFrame::EViewStyle style ){
2050 auto view_menu_item = new_sub_menu_item_with_mnemonic( "Vie_w" );
2051 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( view_menu_item ) );
2052 if ( g_Layout_enableDetachableMenus.m_value ) {
2053 menu_tearoff( menu );
2056 if ( style == MainFrame::eFloating ) {
2057 fill_view_camera_menu( menu );
2058 fill_view_xy_top_menu( menu );
2059 fill_view_yz_side_menu( menu );
2060 fill_view_xz_front_menu( menu );
2062 if ( style == MainFrame::eFloating || style == MainFrame::eSplit ) {
2063 create_menu_item_with_mnemonic( menu, "Console View", "ToggleConsole" );
2064 create_menu_item_with_mnemonic( menu, "Texture Browser", "ToggleTextures" );
2065 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ToggleEntityInspector" );
2069 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ViewEntityInfo" );
2071 create_menu_item_with_mnemonic( menu, "_Surface Inspector", "SurfaceInspector" );
2072 create_menu_item_with_mnemonic( menu, "_Patch Inspector", "PatchInspector" );
2073 create_menu_item_with_mnemonic( menu, "Entity List", "EntityList" );
2075 menu_separator( menu );
2077 auto camera_menu = create_sub_menu_with_mnemonic( menu, "Camera" );
2078 if ( g_Layout_enableDetachableMenus.m_value ) {
2079 menu_tearoff( camera_menu );
2081 create_menu_item_with_mnemonic( camera_menu, "_Center", "CenterView" );
2082 create_menu_item_with_mnemonic( camera_menu, "_Up Floor", "UpFloor" );
2083 create_menu_item_with_mnemonic( camera_menu, "_Down Floor", "DownFloor" );
2084 menu_separator( camera_menu );
2085 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane In", "CubicClipZoomIn" );
2086 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane Out", "CubicClipZoomOut" );
2087 menu_separator( camera_menu );
2088 create_menu_item_with_mnemonic( camera_menu, "Next leak spot", "NextLeakSpot" );
2089 create_menu_item_with_mnemonic( camera_menu, "Previous leak spot", "PrevLeakSpot" );
2090 menu_separator( camera_menu );
2091 create_menu_item_with_mnemonic( camera_menu, "Look Through Selected", "LookThroughSelected" );
2092 create_menu_item_with_mnemonic( camera_menu, "Look Through Camera", "LookThroughCamera" );
2094 menu_separator( menu );
2096 auto orthographic_menu = create_sub_menu_with_mnemonic( menu, "Orthographic" );
2097 if ( g_Layout_enableDetachableMenus.m_value ) {
2098 menu_tearoff( orthographic_menu );
2100 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2101 create_menu_item_with_mnemonic( orthographic_menu, "_Next (XY, YZ, XY)", "NextView" );
2102 create_menu_item_with_mnemonic( orthographic_menu, "XY (Top)", "ViewTop" );
2103 create_menu_item_with_mnemonic( orthographic_menu, "YZ", "ViewSide" );
2104 create_menu_item_with_mnemonic( orthographic_menu, "XZ", "ViewFront" );
2105 menu_separator( orthographic_menu );
2108 create_menu_item_with_mnemonic( orthographic_menu, "Center on Selected", "CenterXYView" );
2109 menu_separator( orthographic_menu );
2110 create_menu_item_with_mnemonic( orthographic_menu, "_XY 100%", "Zoom100" );
2111 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _In", "ZoomIn" );
2112 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _Out", "ZoomOut" );
2115 menu_separator( menu );
2118 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Show" );
2119 if ( g_Layout_enableDetachableMenus.m_value ) {
2120 menu_tearoff( menu_in_menu );
2122 create_menu_item_with_mnemonic( menu_in_menu, "Show Size Info", "ToggleSizePaint" );
2123 create_menu_item_with_mnemonic( menu_in_menu, "Show Crosshair", "ToggleCrosshairs" );
2124 create_menu_item_with_mnemonic( menu_in_menu, "Show Grid", "ToggleGrid" );
2126 menu_separator( menu_in_menu );
2128 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Angles", "ShowAngles" );
2129 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Names", "ShowNames" );
2130 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Blocks", "ShowBlocks" );
2131 create_check_menu_item_with_mnemonic( menu_in_menu, "Show C_oordinates", "ShowCoordinates" );
2132 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Window Outline", "ShowWindowOutline" );
2133 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Axes", "ShowAxes" );
2134 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Workzone", "ShowWorkzone" );
2135 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Stats", "ShowStats" );
2139 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Filter" );
2140 if ( g_Layout_enableDetachableMenus.m_value ) {
2141 menu_tearoff( menu_in_menu );
2143 Filters_constructMenu( menu_in_menu );
2145 menu_separator( menu );
2147 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Hide/Show" );
2148 // if ( g_Layout_enableDetachableMenus.m_value ) {
2149 // menu_tearoff( menu_in_menu );
2151 // create_menu_item_with_mnemonic( menu_in_menu, "Hide Selected", "HideSelected" );
2152 // create_menu_item_with_mnemonic( menu_in_menu, "Show Hidden", "ShowHidden" );
2153 create_menu_item_with_mnemonic( menu, "Hide Selected", "HideSelected" );
2154 create_menu_item_with_mnemonic( menu, "Show Hidden", "ShowHidden" );
2156 menu_separator( menu );
2158 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Region" );
2159 if ( g_Layout_enableDetachableMenus.m_value ) {
2160 menu_tearoff( menu_in_menu );
2162 create_menu_item_with_mnemonic( menu_in_menu, "_Off", "RegionOff" );
2163 create_menu_item_with_mnemonic( menu_in_menu, "_Set XY", "RegionSetXY" );
2164 create_menu_item_with_mnemonic( menu_in_menu, "Set _Brush", "RegionSetBrush" );
2165 create_menu_item_with_mnemonic( menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection" );
2168 command_connect_accelerator( "CenterXYView" );
2170 return view_menu_item;
2173 ui::MenuItem create_selection_menu(){
2175 auto selection_menu_item = new_sub_menu_item_with_mnemonic( "M_odify" );
2176 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( selection_menu_item ) );
2177 if ( g_Layout_enableDetachableMenus.m_value ) {
2178 menu_tearoff( menu );
2182 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Components" );
2183 if ( g_Layout_enableDetachableMenus.m_value ) {
2184 menu_tearoff( menu_in_menu );
2186 create_check_menu_item_with_mnemonic( menu_in_menu, "_Edges", "DragEdges" );
2187 create_check_menu_item_with_mnemonic( menu_in_menu, "_Vertices", "DragVertices" );
2188 create_check_menu_item_with_mnemonic( menu_in_menu, "_Faces", "DragFaces" );
2191 menu_separator( menu );
2194 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Nudge" );
2195 if ( g_Layout_enableDetachableMenus.m_value ) {
2196 menu_tearoff( menu_in_menu );
2198 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Left", "SelectNudgeLeft" );
2199 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Right", "SelectNudgeRight" );
2200 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Up", "SelectNudgeUp" );
2201 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Down", "SelectNudgeDown" );
2204 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Rotate" );
2205 if ( g_Layout_enableDetachableMenus.m_value ) {
2206 menu_tearoff( menu_in_menu );
2208 create_menu_item_with_mnemonic( menu_in_menu, "Rotate X", "RotateSelectionX" );
2209 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Y", "RotateSelectionY" );
2210 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Z", "RotateSelectionZ" );
2213 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Flip" );
2214 if ( g_Layout_enableDetachableMenus.m_value ) {
2215 menu_tearoff( menu_in_menu );
2217 create_menu_item_with_mnemonic( menu_in_menu, "Flip _X", "MirrorSelectionX" );
2218 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Y", "MirrorSelectionY" );
2219 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Z", "MirrorSelectionZ" );
2221 menu_separator( menu );
2222 create_menu_item_with_mnemonic( menu, "Arbitrary rotation...", "ArbitraryRotation" );
2223 create_menu_item_with_mnemonic( menu, "Arbitrary scale...", "ArbitraryScale" );
2225 return selection_menu_item;
2228 ui::MenuItem create_bsp_menu(){
2230 auto bsp_menu_item = new_sub_menu_item_with_mnemonic( "_Build" );
2231 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( bsp_menu_item ) );
2233 if ( g_Layout_enableDetachableMenus.m_value ) {
2234 menu_tearoff( menu );
2237 create_menu_item_with_mnemonic( menu, "Customize...", "BuildMenuCustomize" );
2239 menu_separator( menu );
2241 Build_constructMenu( menu );
2245 return bsp_menu_item;
2248 ui::MenuItem create_grid_menu(){
2250 auto grid_menu_item = new_sub_menu_item_with_mnemonic( "_Grid" );
2251 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( grid_menu_item ) );
2252 if ( g_Layout_enableDetachableMenus.m_value ) {
2253 menu_tearoff( menu );
2256 Grid_constructMenu( menu );
2258 return grid_menu_item;
2261 ui::MenuItem create_misc_menu(){
2263 auto misc_menu_item = new_sub_menu_item_with_mnemonic( "M_isc" );
2264 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( misc_menu_item ) );
2265 if ( g_Layout_enableDetachableMenus.m_value ) {
2266 menu_tearoff( menu );
2270 create_menu_item_with_mnemonic( menu, "_Benchmark", makeCallbackF(GlobalCamera_Benchmark) );
2272 menu.add(create_colours_menu());
2274 create_menu_item_with_mnemonic( menu, "Find brush...", "FindBrush" );
2275 create_menu_item_with_mnemonic( menu, "Map Info...", "MapInfo" );
2276 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2277 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<void(), WXY_Print>());
2278 create_menu_item_with_mnemonic( menu, "_Background select", makeCallbackF(WXY_BackgroundSelect) );
2279 return misc_menu_item;
2282 ui::MenuItem create_entity_menu(){
2284 auto entity_menu_item = new_sub_menu_item_with_mnemonic( "E_ntity" );
2285 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( entity_menu_item ) );
2286 if ( g_Layout_enableDetachableMenus.m_value ) {
2287 menu_tearoff( menu );
2290 Entity_constructMenu( menu );
2292 return entity_menu_item;
2295 ui::MenuItem create_brush_menu(){
2297 auto brush_menu_item = new_sub_menu_item_with_mnemonic( "B_rush" );
2298 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( brush_menu_item ) );
2299 if ( g_Layout_enableDetachableMenus.m_value ) {
2300 menu_tearoff( menu );
2303 Brush_constructMenu( menu );
2305 return brush_menu_item;
2308 ui::MenuItem create_patch_menu(){
2310 auto patch_menu_item = new_sub_menu_item_with_mnemonic( "_Curve" );
2311 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( patch_menu_item ) );
2312 if ( g_Layout_enableDetachableMenus.m_value ) {
2313 menu_tearoff( menu );
2316 Patch_constructMenu( menu );
2318 return patch_menu_item;
2321 ui::MenuItem create_help_menu(){
2323 auto help_menu_item = new_sub_menu_item_with_mnemonic( "_Help" );
2324 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( help_menu_item ) );
2325 if ( g_Layout_enableDetachableMenus.m_value ) {
2326 menu_tearoff( menu );
2329 // create_menu_item_with_mnemonic( menu, "Manual", "OpenManual" );
2331 // this creates all the per-game drop downs for the game pack helps
2332 // it will take care of hooking the Sys_OpenURL calls etc.
2333 create_game_help_menu( menu );
2335 create_menu_item_with_mnemonic( menu, "Bug report", makeCallbackF(OpenBugReportURL) );
2336 create_menu_item_with_mnemonic( menu, "Shortcuts list", makeCallbackF(DoCommandListDlg) );
2337 create_menu_item_with_mnemonic( menu, "_About", makeCallbackF(DoAbout) );
2339 return help_menu_item;
2342 ui::MenuBar create_main_menu( MainFrame::EViewStyle style ){
2343 auto menu_bar = ui::MenuBar::from( gtk_menu_bar_new() );
2346 menu_bar.add(create_file_menu());
2347 menu_bar.add(create_edit_menu());
2348 menu_bar.add(create_view_menu(style));
2349 menu_bar.add(create_selection_menu());
2350 menu_bar.add(create_bsp_menu());
2351 menu_bar.add(create_grid_menu());
2352 menu_bar.add(create_misc_menu());
2353 menu_bar.add(create_entity_menu());
2354 menu_bar.add(create_brush_menu());
2355 menu_bar.add(create_patch_menu());
2356 menu_bar.add(create_plugins_menu());
2357 menu_bar.add(create_help_menu());
2363 void PatchInspector_registerShortcuts(){
2364 command_connect_accelerator( "PatchInspector" );
2367 void Patch_registerShortcuts(){
2368 // command_connect_accelerator( "InvertCurveTextureX" );
2369 // command_connect_accelerator( "InvertCurveTextureY" );
2370 command_connect_accelerator( "PatchInsertInsertColumn" );
2371 command_connect_accelerator( "PatchInsertInsertRow" );
2372 command_connect_accelerator( "PatchDeleteLastColumn" );
2373 command_connect_accelerator( "PatchDeleteLastRow" );
2374 // command_connect_accelerator( "NaturalizePatch" );
2375 //command_connect_accelerator("CapCurrentCurve");
2378 void Manipulators_registerShortcuts(){
2379 toggle_add_accelerator( "MouseRotate" );
2380 toggle_add_accelerator( "MouseTranslate" );
2381 toggle_add_accelerator( "MouseScale" );
2382 toggle_add_accelerator( "MouseDrag" );
2383 toggle_add_accelerator( "ToggleClipper" );
2386 void TexdefNudge_registerShortcuts(){
2387 command_connect_accelerator( "TexRotateClock" );
2388 command_connect_accelerator( "TexRotateCounter" );
2389 command_connect_accelerator( "TexScaleUp" );
2390 command_connect_accelerator( "TexScaleDown" );
2391 command_connect_accelerator( "TexScaleLeft" );
2392 command_connect_accelerator( "TexScaleRight" );
2393 command_connect_accelerator( "TexShiftUp" );
2394 command_connect_accelerator( "TexShiftDown" );
2395 command_connect_accelerator( "TexShiftLeft" );
2396 command_connect_accelerator( "TexShiftRight" );
2399 void SelectNudge_registerShortcuts(){
2400 command_connect_accelerator( "MoveSelectionDOWN" );
2401 command_connect_accelerator( "MoveSelectionUP" );
2402 //command_connect_accelerator("SelectNudgeLeft");
2403 //command_connect_accelerator("SelectNudgeRight");
2404 //command_connect_accelerator("SelectNudgeUp");
2405 //command_connect_accelerator("SelectNudgeDown");
2406 command_connect_accelerator( "UnSelectSelection2" );
2407 command_connect_accelerator( "DeleteSelection2" );
2410 void SnapToGrid_registerShortcuts(){
2411 command_connect_accelerator( "SnapToGrid" );
2414 void SelectByType_registerShortcuts(){
2415 command_connect_accelerator( "SelectAllOfType" );
2418 void SurfaceInspector_registerShortcuts(){
2419 command_connect_accelerator( "FitTexture" );
2423 void register_shortcuts(){
2424 // PatchInspector_registerShortcuts();
2425 Patch_registerShortcuts();
2426 Grid_registerShortcuts();
2427 // XYWnd_registerShortcuts();
2428 CamWnd_registerShortcuts();
2429 Manipulators_registerShortcuts();
2430 SurfaceInspector_registerShortcuts();
2431 TexdefNudge_registerShortcuts();
2432 SelectNudge_registerShortcuts();
2433 // SnapToGrid_registerShortcuts();
2434 // SelectByType_registerShortcuts();
2437 void File_constructToolbar( ui::Toolbar toolbar ){
2438 toolbar_append_button( toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap" );
2439 toolbar_append_button( toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap" );
2442 void UndoRedo_constructToolbar( ui::Toolbar toolbar ){
2443 toolbar_append_button( toolbar, "Undo (CTRL + Z)", "undo.png", "Undo" );
2444 toolbar_append_button( toolbar, "Redo (CTRL + Y)", "redo.png", "Redo" );
2447 void RotateFlip_constructToolbar( ui::Toolbar toolbar ){
2448 toolbar_append_button( toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX" );
2449 toolbar_append_button( toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX" );
2450 toolbar_append_button( toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY" );
2451 toolbar_append_button( toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY" );
2452 toolbar_append_button( toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ" );
2453 toolbar_append_button( toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ" );
2456 void Select_constructToolbar( ui::Toolbar toolbar ){
2457 toolbar_append_button( toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching" );
2458 toolbar_append_button( toolbar, "Select inside", "selection_selectinside.png", "SelectInside" );
2461 void CSG_constructToolbar( ui::Toolbar toolbar ){
2462 toolbar_append_button( toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract" );
2463 toolbar_append_button( toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge" );
2464 toolbar_append_button( toolbar, "Make Hollow", "selection_makehollow.png", "CSGHollow" );
2465 toolbar_append_button( toolbar, "Make Room", "selection_makeroom.png", "CSGRoom" );
2468 void ComponentModes_constructToolbar( ui::Toolbar toolbar ){
2469 toolbar_append_toggle_button( toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices" );
2470 toolbar_append_toggle_button( toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges" );
2471 toolbar_append_toggle_button( toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces" );
2474 void Clipper_constructToolbar( ui::Toolbar toolbar ){
2476 toolbar_append_toggle_button( toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper" );
2479 void XYWnd_constructToolbar( ui::Toolbar toolbar ){
2480 toolbar_append_button( toolbar, "Change views", "view_change.png", "NextView" );
2483 void Manipulators_constructToolbar( ui::Toolbar toolbar ){
2484 toolbar_append_toggle_button( toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate" );
2485 toolbar_append_toggle_button( toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate" );
2486 toolbar_append_toggle_button( toolbar, "Scale", "select_mousescale.png", "MouseScale" );
2487 toolbar_append_toggle_button( toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag" );
2489 Clipper_constructToolbar( toolbar );
2492 ui::Toolbar create_main_toolbar( MainFrame::EViewStyle style ){
2493 auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
2494 gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL );
2495 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
2499 auto space = [&]() {
2500 auto btn = ui::ToolItem::from(gtk_separator_tool_item_new());
2505 File_constructToolbar( toolbar );
2509 UndoRedo_constructToolbar( toolbar );
2513 RotateFlip_constructToolbar( toolbar );
2517 Select_constructToolbar( toolbar );
2521 CSG_constructToolbar( toolbar );
2525 ComponentModes_constructToolbar( toolbar );
2527 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2530 XYWnd_constructToolbar( toolbar );
2535 CamWnd_constructToolbar( toolbar );
2539 Manipulators_constructToolbar( toolbar );
2541 if ( g_Layout_enablePatchToolbar.m_value ) {
2544 Patch_constructToolbar( toolbar );
2549 toolbar_append_toggle_button( toolbar, "Texture Lock (SHIFT +T)", "texture_lock.png", "TogTexLock" );
2553 /*auto g_view_entities_button =*/ toolbar_append_button( toolbar, "Entities (N)", "entities.png", "ToggleEntityInspector" );
2554 auto g_view_console_button = toolbar_append_button( toolbar, "Console (O)", "console.png", "ToggleConsole" );
2555 auto g_view_textures_button = toolbar_append_button( toolbar, "Texture Browser (T)", "texture_browser.png", "ToggleTextures" );
2556 // TODO: call light inspector
2557 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector");
2560 /*auto g_refresh_models_button =*/ toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" );
2563 // disable the console and texture button in the regular layouts
2564 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft ) {
2565 gtk_widget_set_sensitive( g_view_console_button , FALSE );
2566 gtk_widget_set_sensitive( g_view_textures_button , FALSE );
2572 ui::Widget create_main_statusbar( ui::Widget pStatusLabel[c_count_status] ){
2573 auto table = ui::Table( 1, c_count_status, FALSE );
2577 auto label = ui::Label( "Label" );
2578 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2579 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2581 table.attach(label, {0, 1, 0, 1});
2582 pStatusLabel[c_command_status] = ui::Widget(label );
2585 for (unsigned int i = 1; (int) i < c_count_status; ++i)
2587 auto frame = ui::Frame();
2589 table.attach(frame, {i, i + 1, 0, 1});
2590 gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
2592 auto label = ui::Label( "Label" );
2593 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END );
2594 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2595 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2598 pStatusLabel[i] = ui::Widget(label );
2601 return ui::Widget(table );
2607 WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" );
2609 class WindowFocusPrinter
2613 static gboolean frame_event( ui::Widget widget, GdkEvent* event, WindowFocusPrinter* self ){
2614 globalOutputStream() << self->m_name << " frame_event\n";
2617 static gboolean keys_changed( ui::Widget widget, WindowFocusPrinter* self ){
2618 globalOutputStream() << self->m_name << " keys_changed\n";
2621 static gboolean notify( ui::Window window, gpointer dummy, WindowFocusPrinter* self ){
2622 if ( gtk_window_is_active( window ) ) {
2623 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2627 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2632 WindowFocusPrinter( const char* name ) : m_name( name ){
2634 void connect( ui::Window toplevel_window ){
2635 toplevel_window.connect( "notify::has_toplevel_focus", G_CALLBACK( notify ), this );
2636 toplevel_window.connect( "notify::is_active", G_CALLBACK( notify ), this );
2637 toplevel_window.connect( "keys_changed", G_CALLBACK( keys_changed ), this );
2638 toplevel_window.connect( "frame_event", G_CALLBACK( frame_event ), this );
2642 WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" );
2646 class MainWindowActive
2648 static gboolean notify( ui::Window window, gpointer dummy, MainWindowActive* self ){
2649 if ( g_wait.m_window && gtk_window_is_active( window ) && !g_wait.m_window.visible() ) {
2650 g_wait.m_window.show();
2657 void connect( ui::Window toplevel_window ){
2658 toplevel_window.connect( "notify::is-active", G_CALLBACK( notify ), this );
2662 MainWindowActive g_MainWindowActive;
2664 SignalHandlerId XYWindowDestroyed_connect( const SignalHandler& handler ){
2665 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst( handler );
2668 void XYWindowDestroyed_disconnect( SignalHandlerId id ){
2669 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect( id );
2672 MouseEventHandlerId XYWindowMouseDown_connect( const MouseEventHandler& handler ){
2673 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst( handler );
2676 void XYWindowMouseDown_disconnect( MouseEventHandlerId id ){
2677 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect( id );
2680 // =============================================================================
2683 MainFrame* g_pParentWnd = 0;
2685 ui::Window MainFrame_getWindow()
2687 return g_pParentWnd ? g_pParentWnd->m_window : ui::Window{ui::null};
2690 std::vector<ui::Widget> g_floating_windows;
2692 MainFrame::MainFrame() : m_idleRedrawStatusText( RedrawStatusTextCaller( *this ) ){
2700 for (auto &n : m_pStatusLabel) {
2704 m_bSleeping = false;
2709 MainFrame::~MainFrame(){
2716 for ( std::vector<ui::Widget>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i )
2724 void MainFrame::SetActiveXY( XYWnd* p ){
2725 if ( m_pActiveXY ) {
2726 m_pActiveXY->SetActive( false );
2731 if ( m_pActiveXY ) {
2732 m_pActiveXY->SetActive( true );
2737 void MainFrame::ReleaseContexts(){
2740 m_pXYWnd->DestroyContext();
2743 m_pYZWnd->DestroyContext();
2746 m_pXZWnd->DestroyContext();
2749 m_pCamWnd->DestroyContext();
2752 m_pTexWnd->DestroyContext();
2755 m_pZWnd->DestroyContext();
2760 void MainFrame::CreateContexts(){
2763 m_pCamWnd->CreateContext();
2766 m_pXYWnd->CreateContext();
2769 m_pYZWnd->CreateContext();
2772 m_pXZWnd->CreateContext();
2775 m_pTexWnd->CreateContext();
2778 m_pZWnd->CreateContext();
2787 void MainFrame::OnSleep(){
2790 if ( m_bSleeping ) {
2791 // useful when trying to debug crashes in the sleep code
2792 globalOutputStream() << "Going into sleep mode..\n";
2794 globalOutputStream() << "Dispatching sleep msg...";
2795 DispatchRadiantMsg( RADIANT_SLEEP );
2796 globalOutputStream() << "Done.\n";
2798 gtk_window_iconify( m_window );
2799 GlobalSelectionSystem().setSelectedAll( false );
2801 GlobalShaderCache().unrealise();
2803 GlobalOpenGL_debugAssertNoErrors();
2804 ScreenUpdates_Disable();
2807 globalOutputStream() << "Releasing contexts...";
2809 globalOutputStream() << "Done.\n";
2813 globalOutputStream() << "Waking up\n";
2815 gtk_window_deiconify( m_window );
2818 globalOutputStream() << "Creating contexts...";
2820 globalOutputStream() << "Done.\n";
2822 globalOutputStream() << "Making current on camera...";
2823 m_pCamWnd->MakeCurrent();
2824 globalOutputStream() << "Done.\n";
2826 globalOutputStream() << "Reloading shaders...";
2828 GlobalShaderCache().realise();
2829 globalOutputStream() << "Done.\n";
2831 ScreenUpdates_Enable();
2833 globalOutputStream() << "Dispatching wake msg...";
2834 DispatchRadiantMsg( RADIANT_WAKEUP );
2835 globalOutputStream() << "Done\n";
2841 ui::Window create_splash(){
2842 auto window = ui::Window( ui::window_type::TOP );
2843 gtk_window_set_decorated(window, false);
2844 gtk_window_set_resizable(window, false);
2845 gtk_window_set_modal(window, true);
2846 gtk_window_set_default_size( window, -1, -1 );
2847 gtk_window_set_position( window, GTK_WIN_POS_CENTER );
2848 gtk_container_set_border_width(window, 0);
2850 auto image = new_local_image( "splash.png" );
2854 window.dimensions(-1, -1);
2860 static ui::Window splash_screen{ui::null};
2863 splash_screen = create_splash();
2869 splash_screen.destroy();
2872 WindowPositionTracker g_posCamWnd;
2873 WindowPositionTracker g_posXYWnd;
2874 WindowPositionTracker g_posXZWnd;
2875 WindowPositionTracker g_posYZWnd;
2877 static gint mainframe_delete( ui::Widget widget, GdkEvent *event, gpointer data ){
2878 if ( ConfirmModified( "Exit Radiant" ) ) {
2885 void MainFrame::Create(){
2886 ui::Window window = ui::Window( ui::window_type::TOP );
2888 GlobalWindowObservers_connectTopLevel( window );
2890 gtk_window_set_transient_for( splash_screen, window );
2892 #if !GDEF_OS_WINDOWS
2894 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
2895 if ( pixbuf != 0 ) {
2896 gtk_window_set_icon( window, pixbuf );
2897 g_object_unref( pixbuf );
2902 gtk_widget_add_events( window , GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
2903 window.connect( "delete_event", G_CALLBACK( mainframe_delete ), this );
2905 m_position_tracker.connect( window );
2908 g_mainframeWidgetFocusPrinter.connect( window );
2909 g_mainframeFocusPrinter.connect( window );
2912 g_MainWindowActive.connect( window );
2914 GetPlugInMgr().Init( window );
2916 auto vbox = ui::VBox( FALSE, 0 );
2920 global_accel_connect_window( window );
2922 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
2924 register_shortcuts();
2926 auto main_menu = create_main_menu( CurrentStyle() );
2927 vbox.pack_start( main_menu, FALSE, FALSE, 0 );
2929 auto main_toolbar = create_main_toolbar( CurrentStyle() );
2930 vbox.pack_start( main_toolbar, FALSE, FALSE, 0 );
2932 if ( g_Layout_enablePluginToolbar.m_value || g_Layout_enableFilterToolbar.m_value ){
2933 auto PFbox = ui::HBox( FALSE, 3 );
2934 vbox.pack_start( PFbox, FALSE, FALSE, 0 );
2936 if ( g_Layout_enablePluginToolbar.m_value ){
2937 auto plugin_toolbar = create_plugin_toolbar();
2938 if ( g_Layout_enableFilterToolbar.m_value ){
2939 PFbox.pack_start( plugin_toolbar, FALSE, FALSE, 0 );
2942 PFbox.pack_start( plugin_toolbar, TRUE, TRUE, 0 );
2945 if ( g_Layout_enableFilterToolbar.m_value ){
2946 ui::Toolbar filter_toolbar = create_filter_toolbar();
2947 PFbox.pack_start( filter_toolbar, TRUE, TRUE, 0 );
2951 /*GtkToolbar* plugin_toolbar = create_plugin_toolbar();
2952 if ( !g_Layout_enablePluginToolbar.m_value ) {
2953 gtk_widget_hide( GTK_WIDGET( plugin_toolbar ) );
2956 ui::Widget main_statusbar = create_main_statusbar(reinterpret_cast<ui::Widget *>(m_pStatusLabel));
2957 vbox.pack_end(main_statusbar, FALSE, TRUE, 2);
2959 GroupDialog_constructWindow( window );
2960 g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) );
2962 if ( FloatingGroupDialog() ) {
2963 g_page_console = GroupDialog_addPage( "Console", Console_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Console" ) );
2967 if ( g_multimon_globals.m_bStartOnPrimMon ) {
2968 PositionWindowOnPrimaryScreen( g_layout_globals.m_position );
2969 window_set_position( window, g_layout_globals.m_position );
2973 if ( g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED ) {
2974 gtk_window_maximize( window );
2975 WindowPosition default_position( -1, -1, 640, 480 );
2976 window_set_position( window, default_position );
2980 window_set_position( window, g_layout_globals.m_position );
2987 if ( CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft ) {
2989 ui::Widget hsplit = ui::HPaned(ui::New);
2991 vbox.pack_start( hsplit, TRUE, TRUE, 0 );
2994 ui::Widget vsplit = ui::VPaned(ui::New);
2997 ui::Widget vsplit2 = ui::VPaned(ui::New);
3000 if ( CurrentStyle() == eRegular ){
3001 gtk_paned_add1( GTK_PANED( hsplit ), vsplit );
3002 gtk_paned_add2( GTK_PANED( hsplit ), vsplit2 );
3005 gtk_paned_add2( GTK_PANED( hsplit ), vsplit );
3006 gtk_paned_add1( GTK_PANED( hsplit ), vsplit2 );
3010 ui::Widget console_window = Console_constructWindow( window );
3011 gtk_paned_pack2( GTK_PANED( vsplit ), console_window, FALSE, TRUE );
3014 m_pXYWnd = new XYWnd();
3015 m_pXYWnd->SetViewType( XY );
3016 ui::Widget xy_window = ui::Widget(create_framed_widget( m_pXYWnd->GetWidget( ) ));
3018 gtk_paned_add1( GTK_PANED( vsplit ), xy_window );
3021 m_pCamWnd = NewCamWnd();
3022 GlobalCamera_setCamWnd( *m_pCamWnd );
3023 CamWnd_setParent( *m_pCamWnd, window );
3024 auto camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3026 gtk_paned_add1( GTK_PANED( vsplit2 ), camera_window );
3029 auto texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
3031 gtk_paned_add2( GTK_PANED( vsplit2 ), texture_window );
3036 gtk_paned_set_position( GTK_PANED( m_vSplit ), g_layout_globals.nXYHeight );
3038 if ( CurrentStyle() == eRegular ) {
3039 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nXYWidth );
3043 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nCamWidth );
3046 gtk_paned_set_position( GTK_PANED( m_vSplit2 ), g_layout_globals.nCamHeight );
3048 else if ( CurrentStyle() == eFloating ) {
3050 ui::Window window = ui::Window(create_persistent_floating_window( "Camera", m_window ));
3051 global_accel_connect_window( window );
3052 g_posCamWnd.connect( window );
3056 m_pCamWnd = NewCamWnd();
3057 GlobalCamera_setCamWnd( *m_pCamWnd );
3060 auto frame = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3063 CamWnd_setParent( *m_pCamWnd, window );
3064 #define GARUX_GTK_WORKAROUND
3065 #ifndef GARUX_GTK_WORKAROUND
3066 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3067 g_object_set_data( G_OBJECT( window ), "glwidget", CamWnd_getWidget( *m_pCamWnd ) );
3070 g_floating_windows.push_back( window );
3074 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XY ), m_window ));
3075 global_accel_connect_window( window );
3076 g_posXYWnd.connect( window );
3078 m_pXYWnd = new XYWnd();
3079 m_pXYWnd->m_parent = window;
3080 m_pXYWnd->SetViewType( XY );
3084 auto frame = create_framed_widget( m_pXYWnd->GetWidget() );
3087 XY_Top_Shown_Construct( window );
3088 #ifndef GARUX_GTK_WORKAROUND
3089 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3090 g_object_set_data( G_OBJECT( window ), "glwidget", m_pXYWnd->GetWidget() );
3093 g_floating_windows.push_back( window );
3097 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XZ ), m_window ));
3098 global_accel_connect_window( window );
3099 g_posXZWnd.connect( window );
3101 m_pXZWnd = new XYWnd();
3102 m_pXZWnd->m_parent = window;
3103 m_pXZWnd->SetViewType( XZ );
3106 auto frame = create_framed_widget( m_pXZWnd->GetWidget() );
3110 XZ_Front_Shown_Construct( window );
3111 #ifndef GARUX_GTK_WORKAROUND
3112 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3113 g_object_set_data( G_OBJECT( window ), "glwidget", m_pXZWnd->GetWidget() );
3116 g_floating_windows.push_back( window );
3120 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( YZ ), m_window ));
3121 global_accel_connect_window( window );
3122 g_posYZWnd.connect( window );
3124 m_pYZWnd = new XYWnd();
3125 m_pYZWnd->m_parent = window;
3126 m_pYZWnd->SetViewType( YZ );
3129 auto frame = create_framed_widget( m_pYZWnd->GetWidget() );
3133 YZ_Side_Shown_Construct( window );
3134 #ifndef GARUX_GTK_WORKAROUND
3135 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3136 g_object_set_data( G_OBJECT( window ), "glwidget", m_pYZWnd->GetWidget() );
3139 g_floating_windows.push_back( window );
3143 auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
3144 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3145 #ifndef GARUX_GTK_WORKAROUND
3146 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3147 g_object_set_data( G_OBJECT( GroupDialog_getWindow() ), "glwidget", TextureBrowser_getGLWidget() );
3156 m_pCamWnd = NewCamWnd();
3157 GlobalCamera_setCamWnd( *m_pCamWnd );
3158 CamWnd_setParent( *m_pCamWnd, window );
3160 ui::Widget camera = CamWnd_getWidget( *m_pCamWnd );
3162 m_pYZWnd = new XYWnd();
3163 m_pYZWnd->SetViewType( YZ );
3165 ui::Widget yz = m_pYZWnd->GetWidget();
3167 m_pXYWnd = new XYWnd();
3168 m_pXYWnd->SetViewType( XY );
3170 ui::Widget xy = m_pXYWnd->GetWidget();
3172 m_pXZWnd = new XYWnd();
3173 m_pXZWnd->SetViewType( XZ );
3175 ui::Widget xz = m_pXZWnd->GetWidget();
3177 auto split = create_split_views( camera, yz, xy, xz );
3178 vbox.pack_start( split, TRUE, TRUE, 0 );
3181 auto frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
3182 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3183 #ifndef GARUX_GTK_WORKAROUND
3184 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3185 g_object_set_data( G_OBJECT( GroupDialog_getWindow() ), "glwidget", TextureBrowser_getGLWidget() );
3190 EntityList_constructWindow( window );
3191 PreferencesDialog_constructWindow( window );
3192 FindTextureDialog_constructWindow( window );
3193 SurfaceInspector_constructWindow( window );
3194 PatchInspector_constructWindow( window );
3196 SetActiveXY( m_pXYWnd );
3198 AddGridChangeCallback( SetGridStatusCaller( *this ) );
3199 AddGridChangeCallback( ReferenceCaller<MainFrame, void(), XY_UpdateAllWindows>( *this ) );
3201 g_defaultToolMode = DragMode;
3202 g_defaultToolMode();
3203 SetStatusText( m_command_status, c_TranslateMode_status );
3205 EverySecondTimer_enable();
3207 //GlobalShortcuts_reportUnregistered();
3210 void MainFrame::SaveWindowInfo(){
3211 if ( !FloatingGroupDialog() ) {
3212 g_layout_globals.nXYHeight = gtk_paned_get_position( GTK_PANED( m_vSplit ) );
3214 if ( CurrentStyle() != eRegular ) {
3215 g_layout_globals.nCamWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3219 g_layout_globals.nXYWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3222 g_layout_globals.nCamHeight = gtk_paned_get_position( GTK_PANED( m_vSplit2 ) );
3225 g_layout_globals.m_position = m_position_tracker.getPosition();
3227 g_layout_globals.nState = gdk_window_get_state( gtk_widget_get_window(m_window ) );
3230 void MainFrame::Shutdown(){
3231 EverySecondTimer_disable();
3233 EntityList_destroyWindow();
3242 TextureBrowser_destroyWindow();
3244 DeleteCamWnd( m_pCamWnd );
3247 PreferencesDialog_destroyWindow();
3248 SurfaceInspector_destroyWindow();
3249 FindTextureDialog_destroyWindow();
3250 PatchInspector_destroyWindow();
3252 g_DbgDlg.destroyWindow();
3254 // destroying group-dialog last because it may contain texture-browser
3255 GroupDialog_destroyWindow();
3258 void MainFrame::RedrawStatusText(){
3259 ui::Label::from(m_pStatusLabel[c_command_status]).text(m_command_status.c_str());
3260 ui::Label::from(m_pStatusLabel[c_position_status]).text(m_position_status.c_str());
3261 ui::Label::from(m_pStatusLabel[c_brushcount_status]).text(m_brushcount_status.c_str());
3262 ui::Label::from(m_pStatusLabel[c_texture_status]).text(m_texture_status.c_str());
3263 ui::Label::from(m_pStatusLabel[c_grid_status]).text(m_grid_status.c_str());
3266 void MainFrame::UpdateStatusText(){
3267 m_idleRedrawStatusText.queueDraw();
3270 void MainFrame::SetStatusText( CopiedString& status_text, const char* pText ){
3271 status_text = pText;
3275 void Sys_Status( const char* status ){
3276 if ( g_pParentWnd != 0 ) {
3277 g_pParentWnd->SetStatusText( g_pParentWnd->m_command_status, status );
3281 int getRotateIncrement(){
3282 return static_cast<int>( g_si_globals.rotate );
3285 int getFarClipDistance(){
3286 return g_camwindow_globals.m_nCubicScale;
3289 float ( *GridStatus_getGridSize )() = GetGridSize;
3291 int ( *GridStatus_getRotateIncrement )() = getRotateIncrement;
3293 int ( *GridStatus_getFarClipDistance )() = getFarClipDistance;
3295 bool ( *GridStatus_getTextureLockEnabled )();
3297 void MainFrame::SetGridStatus(){
3298 StringOutputStream status( 64 );
3299 const char* lock = ( GridStatus_getTextureLockEnabled() ) ? "ON" : "OFF";
3300 status << ( GetSnapGridSize() > 0 ? "G:" : "g:" ) << GridStatus_getGridSize()
3301 << " R:" << GridStatus_getRotateIncrement()
3302 << " C:" << GridStatus_getFarClipDistance()
3304 SetStatusText( m_grid_status, status.c_str() );
3307 void GridStatus_onTextureLockEnabledChanged(){
3308 if ( g_pParentWnd != 0 ) {
3309 g_pParentWnd->SetGridStatus();
3313 void GlobalGL_sharedContextCreated(){
3314 GLFont *g_font = NULL;
3316 // report OpenGL information
3317 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) << "\n";
3318 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) << "\n";
3319 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) << "\n";
3320 const auto extensions = reinterpret_cast<const char*>( glGetString(GL_EXTENSIONS ) );
3321 globalOutputStream() << "GL_EXTENSIONS: " << (extensions ? extensions : "") << "\n";
3323 QGL_sharedContextCreated( GlobalOpenGL() );
3325 ShaderCache_extensionsInitialised();
3327 GlobalShaderCache().realise();
3331 /* win32 is dodgy here, just use courier new then */
3332 g_font = glfont_create( "arial 9" );
3334 auto settings = gtk_settings_get_default();
3336 g_object_get( settings, "gtk-font-name", &fontname, NULL );
3337 g_font = glfont_create( fontname );
3340 GlobalOpenGL().m_font = g_font;
3343 void GlobalGL_sharedContextDestroyed(){
3344 Textures_Unrealise();
3345 GlobalShaderCache().unrealise();
3347 QGL_sharedContextDestroyed( GlobalOpenGL() );
3351 void Layout_constructPreferences( PreferencesPage& page ){
3353 const char* layouts[] = { "window1.png", "window2.png", "window3.png", "window4.png" };
3354 page.appendRadioIcons(
3356 STRING_ARRAY_RANGE( layouts ),
3357 make_property( g_Layout_viewStyle )
3360 page.appendCheckBox(
3361 "", "Detachable Menus",
3362 make_property( g_Layout_enableDetachableMenus )
3364 if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) {
3365 page.appendCheckBox(
3366 "", "Patch Toolbar",
3367 make_property( g_Layout_enablePatchToolbar )
3370 page.appendCheckBox(
3371 "", "Plugin Toolbar",
3372 make_property( g_Layout_enablePluginToolbar )
3374 page.appendCheckBox(
3375 "", "Filter Toolbar",
3376 make_property( g_Layout_enableFilterToolbar )
3380 void Layout_constructPage( PreferenceGroup& group ){
3381 PreferencesPage page( group.createPage( "Layout", "Layout Preferences" ) );
3382 Layout_constructPreferences( page );
3385 void Layout_registerPreferencesPage(){
3386 PreferencesDialog_addInterfacePage( makeCallbackF(Layout_constructPage) );
3390 #include "preferencesystem.h"
3391 #include "stringio.h"
3393 void MainFrame_Construct(){
3394 GlobalCommands_insert( "OpenManual", makeCallbackF(OpenHelpURL), Accelerator( GDK_KEY_F1 ) );
3396 GlobalCommands_insert( "Sleep", makeCallbackF(thunk_OnSleep), Accelerator( 'P', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3397 GlobalCommands_insert( "NewMap", makeCallbackF(NewMap) );
3398 GlobalCommands_insert( "OpenMap", makeCallbackF(OpenMap), Accelerator( 'O', (GdkModifierType)GDK_CONTROL_MASK ) );
3399 GlobalCommands_insert( "ImportMap", makeCallbackF(ImportMap) );
3400 GlobalCommands_insert( "SaveMap", makeCallbackF(SaveMap), Accelerator( 'S', (GdkModifierType)GDK_CONTROL_MASK ) );
3401 GlobalCommands_insert( "SaveMapAs", makeCallbackF(SaveMapAs) );
3402 GlobalCommands_insert( "ExportSelected", makeCallbackF(ExportMap) );
3403 GlobalCommands_insert( "SaveRegion", makeCallbackF(SaveRegion) );
3404 GlobalCommands_insert( "RefreshReferences", makeCallbackF(VFS_Refresh) );
3405 GlobalCommands_insert( "ProjectSettings", makeCallbackF(DoProjectSettings) );
3406 GlobalCommands_insert( "Exit", makeCallbackF(Exit) );
3408 GlobalCommands_insert( "Undo", makeCallbackF(Undo), Accelerator( 'Z', (GdkModifierType)GDK_CONTROL_MASK ) );
3409 GlobalCommands_insert( "Redo", makeCallbackF(Redo), Accelerator( 'Y', (GdkModifierType)GDK_CONTROL_MASK ) );
3410 GlobalCommands_insert( "Copy", makeCallbackF(Copy), Accelerator( 'C', (GdkModifierType)GDK_CONTROL_MASK ) );
3411 GlobalCommands_insert( "Paste", makeCallbackF(Paste), Accelerator( 'V', (GdkModifierType)GDK_CONTROL_MASK ) );
3412 GlobalCommands_insert( "PasteToCamera", makeCallbackF(PasteToCamera), Accelerator( 'V', (GdkModifierType)GDK_MOD1_MASK ) );
3413 GlobalCommands_insert( "CloneSelection", makeCallbackF(Selection_Clone), Accelerator( GDK_KEY_space ) );
3414 GlobalCommands_insert( "CloneSelectionAndMakeUnique", makeCallbackF(Selection_Clone_MakeUnique), Accelerator( GDK_KEY_space, (GdkModifierType)GDK_SHIFT_MASK ) );
3415 // GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) );
3416 GlobalCommands_insert( "DeleteSelection2", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) );
3417 GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( 'Z' ) );
3418 GlobalCommands_insert( "ParentSelection", makeCallbackF(Scene_parentSelected) );
3419 // GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) );
3420 GlobalCommands_insert( "UnSelectSelection2", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) );
3421 GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( 'C' ) );
3422 GlobalCommands_insert( "InvertSelection", makeCallbackF(Select_Invert), Accelerator( 'I' ) );
3423 GlobalCommands_insert( "SelectInside", makeCallbackF(Select_Inside) );
3424 GlobalCommands_insert( "SelectTouching", makeCallbackF(Select_Touching) );
3425 GlobalCommands_insert( "ExpandSelectionToEntities", makeCallbackF(Scene_ExpandSelectionToEntities), Accelerator( 'E', (GdkModifierType)( GDK_MOD1_MASK | GDK_CONTROL_MASK ) ) );
3426 GlobalCommands_insert( "Preferences", makeCallbackF(PreferencesDialog_showDialog), Accelerator( 'P' ) );
3428 GlobalCommands_insert( "ToggleConsole", makeCallbackF(Console_ToggleShow), Accelerator( 'O' ) );
3429 GlobalCommands_insert( "ToggleEntityInspector", makeCallbackF(EntityInspector_ToggleShow), Accelerator( 'N' ) );
3430 GlobalCommands_insert( "EntityList", makeCallbackF(EntityList_toggleShown), Accelerator( 'L' ) );
3432 GlobalCommands_insert( "ShowHidden", makeCallbackF(Select_ShowAllHidden), Accelerator( 'H', (GdkModifierType)GDK_SHIFT_MASK ) );
3433 GlobalCommands_insert( "HideSelected", makeCallbackF(HideSelected), Accelerator( 'H' ) );
3435 GlobalToggles_insert( "DragVertices", makeCallbackF(SelectVertexMode), ToggleItem::AddCallbackCaller( g_vertexMode_button ), Accelerator( 'V' ) );
3436 GlobalToggles_insert( "DragEdges", makeCallbackF(SelectEdgeMode), ToggleItem::AddCallbackCaller( g_edgeMode_button ), Accelerator( 'E' ) );
3437 GlobalToggles_insert( "DragFaces", makeCallbackF(SelectFaceMode), ToggleItem::AddCallbackCaller( g_faceMode_button ), Accelerator( 'F' ) );
3439 GlobalCommands_insert( "MirrorSelectionX", makeCallbackF(Selection_Flipx) );
3440 GlobalCommands_insert( "RotateSelectionX", makeCallbackF(Selection_Rotatex) );
3441 GlobalCommands_insert( "MirrorSelectionY", makeCallbackF(Selection_Flipy) );
3442 GlobalCommands_insert( "RotateSelectionY", makeCallbackF(Selection_Rotatey) );
3443 GlobalCommands_insert( "MirrorSelectionZ", makeCallbackF(Selection_Flipz) );
3444 GlobalCommands_insert( "RotateSelectionZ", makeCallbackF(Selection_Rotatez) );
3446 GlobalCommands_insert( "ArbitraryRotation", makeCallbackF(DoRotateDlg) );
3447 GlobalCommands_insert( "ArbitraryScale", makeCallbackF(DoScaleDlg) );
3449 GlobalCommands_insert( "BuildMenuCustomize", makeCallbackF(DoBuildMenu) );
3451 GlobalCommands_insert( "FindBrush", makeCallbackF(DoFind) );
3453 GlobalCommands_insert( "MapInfo", makeCallbackF(DoMapInfo), Accelerator( 'M' ) );
3456 GlobalToggles_insert( "ToggleClipper", makeCallbackF(ClipperMode), ToggleItem::AddCallbackCaller( g_clipper_button ), Accelerator( 'X' ) );
3458 GlobalToggles_insert( "MouseTranslate", makeCallbackF(TranslateMode), ToggleItem::AddCallbackCaller( g_translatemode_button ), Accelerator( 'W' ) );
3459 GlobalToggles_insert( "MouseRotate", makeCallbackF(RotateMode), ToggleItem::AddCallbackCaller( g_rotatemode_button ), Accelerator( 'R' ) );
3460 GlobalToggles_insert( "MouseScale", makeCallbackF(ScaleMode), ToggleItem::AddCallbackCaller( g_scalemode_button ) );
3461 GlobalToggles_insert( "MouseDrag", makeCallbackF(DragMode), ToggleItem::AddCallbackCaller( g_dragmode_button ), Accelerator( 'Q' ) );
3463 GlobalCommands_insert( "ColorSchemeOriginal", makeCallbackF(ColorScheme_Original) );
3464 GlobalCommands_insert( "ColorSchemeQER", makeCallbackF(ColorScheme_QER) );
3465 GlobalCommands_insert( "ColorSchemeBlackAndGreen", makeCallbackF(ColorScheme_Black) );
3466 GlobalCommands_insert( "ColorSchemeYdnar", makeCallbackF(ColorScheme_Ydnar) );
3467 GlobalCommands_insert( "ChooseTextureBackgroundColor", makeCallback( g_ColoursMenu.m_textureback ) );
3468 GlobalCommands_insert( "ChooseGridBackgroundColor", makeCallback( g_ColoursMenu.m_xyback ) );
3469 GlobalCommands_insert( "ChooseGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor ) );
3470 GlobalCommands_insert( "ChooseGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor ) );
3471 GlobalCommands_insert( "ChooseSmallGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor_alt ) );
3472 GlobalCommands_insert( "ChooseSmallGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor_alt ) );
3473 GlobalCommands_insert( "ChooseGridTextColor", makeCallback( g_ColoursMenu.m_gridtext ) );
3474 GlobalCommands_insert( "ChooseGridBlockColor", makeCallback( g_ColoursMenu.m_gridblock ) );
3475 GlobalCommands_insert( "ChooseBrushColor", makeCallback( g_ColoursMenu.m_brush ) );
3476 GlobalCommands_insert( "ChooseCameraBackgroundColor", makeCallback( g_ColoursMenu.m_cameraback ) );
3477 GlobalCommands_insert( "ChooseSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush ) );
3478 GlobalCommands_insert( "ChooseCameraSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush3d ) );
3479 GlobalCommands_insert( "ChooseClipperColor", makeCallback( g_ColoursMenu.m_clipper ) );
3480 GlobalCommands_insert( "ChooseOrthoViewNameColor", makeCallback( g_ColoursMenu.m_viewname ) );
3483 GlobalCommands_insert( "CSGSubtract", makeCallbackF(CSG_Subtract), Accelerator( 'U', (GdkModifierType)GDK_SHIFT_MASK ) );
3484 GlobalCommands_insert( "CSGMerge", makeCallbackF(CSG_Merge), Accelerator( 'U', (GdkModifierType) GDK_CONTROL_MASK ) );
3485 GlobalCommands_insert( "CSGHollow", makeCallbackF(CSG_MakeHollow) );
3486 GlobalCommands_insert( "CSGRoom", makeCallbackF(CSG_MakeRoom) );
3488 Grid_registerCommands();
3490 GlobalCommands_insert( "SnapToGrid", makeCallbackF(Selection_SnapToGrid), Accelerator( 'G', (GdkModifierType)GDK_CONTROL_MASK ) );
3492 GlobalCommands_insert( "SelectAllOfType", makeCallbackF(Select_AllOfType), Accelerator( 'A', (GdkModifierType)GDK_SHIFT_MASK ) );
3494 GlobalCommands_insert( "TexRotateClock", makeCallbackF(Texdef_RotateClockwise), Accelerator( GDK_KEY_Next, (GdkModifierType)GDK_SHIFT_MASK ) );
3495 GlobalCommands_insert( "TexRotateCounter", makeCallbackF(Texdef_RotateAntiClockwise), Accelerator( GDK_KEY_Prior, (GdkModifierType)GDK_SHIFT_MASK ) );
3496 GlobalCommands_insert( "TexScaleUp", makeCallbackF(Texdef_ScaleUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_CONTROL_MASK ) );
3497 GlobalCommands_insert( "TexScaleDown", makeCallbackF(Texdef_ScaleDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_CONTROL_MASK ) );
3498 GlobalCommands_insert( "TexScaleLeft", makeCallbackF(Texdef_ScaleLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_CONTROL_MASK ) );
3499 GlobalCommands_insert( "TexScaleRight", makeCallbackF(Texdef_ScaleRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_CONTROL_MASK ) );
3500 GlobalCommands_insert( "TexShiftUp", makeCallbackF(Texdef_ShiftUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_SHIFT_MASK ) );
3501 GlobalCommands_insert( "TexShiftDown", makeCallbackF(Texdef_ShiftDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_SHIFT_MASK ) );
3502 GlobalCommands_insert( "TexShiftLeft", makeCallbackF(Texdef_ShiftLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_SHIFT_MASK ) );
3503 GlobalCommands_insert( "TexShiftRight", makeCallbackF(Texdef_ShiftRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_SHIFT_MASK ) );
3505 GlobalCommands_insert( "MoveSelectionDOWN", makeCallbackF(Selection_MoveDown), Accelerator( GDK_KEY_KP_Subtract ) );
3506 GlobalCommands_insert( "MoveSelectionUP", makeCallbackF(Selection_MoveUp), Accelerator( GDK_KEY_KP_Add ) );
3508 GlobalCommands_insert( "SelectNudgeLeft", makeCallbackF(Selection_NudgeLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_MOD1_MASK ) );
3509 GlobalCommands_insert( "SelectNudgeRight", makeCallbackF(Selection_NudgeRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_MOD1_MASK ) );
3510 GlobalCommands_insert( "SelectNudgeUp", makeCallbackF(Selection_NudgeUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_MOD1_MASK ) );
3511 GlobalCommands_insert( "SelectNudgeDown", makeCallbackF(Selection_NudgeDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_MOD1_MASK ) );
3513 Patch_registerCommands();
3514 XYShow_registerCommands();
3516 typedef FreeCaller<void(const Selectable&), ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3517 GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() );
3519 GlobalPreferenceSystem().registerPreference( "DetachableMenus", make_property_string( g_Layout_enableDetachableMenus.m_latched ) );
3520 GlobalPreferenceSystem().registerPreference( "PatchToolBar", make_property_string( g_Layout_enablePatchToolbar.m_latched ) );
3521 GlobalPreferenceSystem().registerPreference( "PluginToolBar", make_property_string( g_Layout_enablePluginToolbar.m_latched ) );
3522 GlobalPreferenceSystem().registerPreference( "FilterToolBar", make_property_string( g_Layout_enableFilterToolbar.m_latched ) );
3523 GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", make_property_string( g_Layout_viewStyle.m_latched ) );
3524 GlobalPreferenceSystem().registerPreference( "XYHeight", make_property_string( g_layout_globals.nXYHeight ) );
3525 GlobalPreferenceSystem().registerPreference( "XYWidth", make_property_string( g_layout_globals.nXYWidth ) );
3526 GlobalPreferenceSystem().registerPreference( "CamWidth", make_property_string( g_layout_globals.nCamWidth ) );
3527 GlobalPreferenceSystem().registerPreference( "CamHeight", make_property_string( g_layout_globals.nCamHeight ) );
3529 GlobalPreferenceSystem().registerPreference( "State", make_property_string( g_layout_globals.nState ) );
3530 GlobalPreferenceSystem().registerPreference( "PositionX", make_property_string( g_layout_globals.m_position.x ) );
3531 GlobalPreferenceSystem().registerPreference( "PositionY", make_property_string( g_layout_globals.m_position.y ) );
3532 GlobalPreferenceSystem().registerPreference( "Width", make_property_string( g_layout_globals.m_position.w ) );
3533 GlobalPreferenceSystem().registerPreference( "Height", make_property_string( g_layout_globals.m_position.h ) );
3535 GlobalPreferenceSystem().registerPreference( "CamWnd", make_property<WindowPositionTracker_String>(g_posCamWnd) );
3536 GlobalPreferenceSystem().registerPreference( "XYWnd", make_property<WindowPositionTracker_String>(g_posXYWnd) );
3537 GlobalPreferenceSystem().registerPreference( "YZWnd", make_property<WindowPositionTracker_String>(g_posYZWnd) );
3538 GlobalPreferenceSystem().registerPreference( "XZWnd", make_property<WindowPositionTracker_String>(g_posXZWnd) );
3540 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3541 if ( g_strEnginePath.empty() )
3543 g_strEnginePath_was_empty_1st_start = true;
3544 const char* ENGINEPATH_ATTRIBUTE =
3549 #elif GDEF_OS_LINUX || GDEF_OS_BSD
3552 #error "unknown platform"
3555 StringOutputStream path( 256 );
3556 path << DirectoryCleaned( g_pGameDescription->getRequiredKeyValue( ENGINEPATH_ATTRIBUTE ) );
3557 g_strEnginePath = path.c_str();
3558 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3561 GlobalPreferenceSystem().registerPreference( "DisableEnginePath", make_property_string( g_disableEnginePath ) );
3562 GlobalPreferenceSystem().registerPreference( "DisableHomePath", make_property_string( g_disableHomePath ) );
3564 for ( int i = 0; i < g_pakPathCount; i++ ) {
3565 std::string label = "PakPath" + std::to_string( i );
3566 GlobalPreferenceSystem().registerPreference( label.c_str(), make_property_string( g_strPakPath[i] ) );
3569 g_Layout_viewStyle.useLatched();
3570 g_Layout_enableDetachableMenus.useLatched();
3571 g_Layout_enablePatchToolbar.useLatched();
3572 g_Layout_enablePluginToolbar.useLatched();
3573 g_Layout_enableFilterToolbar.useLatched();
3575 Layout_registerPreferencesPage();
3576 Paths_registerPreferencesPage();
3578 g_brushCount.setCountChangedCallback( makeCallbackF(QE_brushCountChanged) );
3579 g_entityCount.setCountChangedCallback( makeCallbackF(QE_entityCountChanged) );
3580 GlobalEntityCreator().setCounter( &g_entityCount );
3582 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3583 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3585 GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver );
3588 void MainFrame_Destroy(){
3589 GlobalEntityClassManager().detach( g_WorldspawnColourEntityClassObserver );
3591 GlobalEntityCreator().setCounter( 0 );
3592 g_entityCount.setCountChangedCallback( Callback<void()>() );
3593 g_brushCount.setCountChangedCallback( Callback<void()>() );
3597 void GLWindow_Construct(){
3598 GlobalPreferenceSystem().registerPreference( "MouseButtons", make_property_string( g_glwindow_globals.m_nMouseType ) );
3601 void GLWindow_Destroy(){