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"
111 #ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
112 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
113 #define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget) g_object_set_data( G_OBJECT( window ), "glwidget", G_OBJECT( widget ) )
115 #define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget)
118 #define GARUX_DISABLE_GTKTHEME
119 #ifndef GARUX_DISABLE_GTKTHEME
120 #include "gtktheme.h"
123 struct layout_globals_t
125 WindowPosition m_position;
135 m_position( -1, -1, 640, 480 ),
141 nState( GDK_WINDOW_STATE_MAXIMIZED ){
145 layout_globals_t g_layout_globals;
146 glwindow_globals_t g_glwindow_globals;
151 bool g_vfsInitialized = false;
154 if ( g_vfsInitialized ) return;
156 GlobalFileSystem().initialise();
157 g_vfsInitialized = true;
161 if ( !g_vfsInitialized ) return;
162 GlobalFileSystem().shutdown();
163 g_vfsInitialized = false;
167 if ( !g_vfsInitialized ) return;
168 GlobalFileSystem().clear();
170 GlobalFileSystem().refresh();
171 g_vfsInitialized = true;
172 // also refresh models
174 // also refresh texture browser
175 TextureBrowser_RefreshShaders();
176 // also show textures (all or common)
177 TextureBrowser_ShowStartupShaders( GlobalTextureBrowser() );
185 class VFSModuleObserver : public ModuleObserver
197 VFSModuleObserver g_VFSModuleObserver;
199 void VFS_Construct(){
200 Radiant_attachHomePathsObserver( g_VFSModuleObserver );
204 Radiant_detachHomePathsObserver( g_VFSModuleObserver );
212 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
213 #define qREFKNOWNFOLDERID GUID
214 #define qKF_FLAG_CREATE 0x8000
215 #define qKF_FLAG_NO_ALIAS 0x1000
216 typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath );
217 static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath;
220 void HomePaths_Realise(){
223 const char* prefix = g_pGameDescription->getKeyValue( "prefix" );
224 if ( !string_empty( prefix ) ) {
225 StringOutputStream path( 256 );
229 path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/";
230 if ( file_is_directory( path.c_str() ) ) {
231 g_qeglobals.m_userEnginePath = path.c_str();
235 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
236 #elif GDEF_OS_WINDOWS
237 TCHAR mydocsdir[MAX_PATH + 1];
239 HMODULE shfolder = LoadLibrary( "shfolder.dll" );
241 qSHGetKnownFolderPath = (qSHGetKnownFolderPath_t *) GetProcAddress( shfolder, "SHGetKnownFolderPath" );
244 qSHGetKnownFolderPath = NULL;
246 CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
247 if ( qSHGetKnownFolderPath && qSHGetKnownFolderPath( qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw ) == S_OK ) {
248 memset( mydocsdir, 0, sizeof( mydocsdir ) );
249 wcstombs( mydocsdir, mydocsdirw, sizeof( mydocsdir ) - 1 );
250 CoTaskMemFree( mydocsdirw );
252 path << DirectoryCleaned( mydocsdir ) << ( prefix + 1 ) << "/";
253 if ( file_is_directory( path.c_str() ) ) {
254 g_qeglobals.m_userEnginePath = path.c_str();
256 FreeLibrary( shfolder );
262 FreeLibrary( shfolder );
264 if ( SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir ) ) {
266 path << DirectoryCleaned( mydocsdir ) << "My Games/" << ( prefix + 1 ) << "/";
267 // win32: only add it if it already exists
268 if ( file_is_directory( path.c_str() ) ) {
269 g_qeglobals.m_userEnginePath = path.c_str();
275 path << DirectoryCleaned( g_get_user_data_dir() ) << ( prefix + 1 ) << "/";
276 if ( file_exists( path.c_str() ) && file_is_directory( path.c_str() ) ) {
277 g_qeglobals.m_userEnginePath = path.c_str();
282 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
283 g_qeglobals.m_userEnginePath = path.c_str();
289 g_qeglobals.m_userEnginePath = EnginePath_get();
293 Q_mkdir( g_qeglobals.m_userEnginePath.c_str() );
296 StringOutputStream path( 256 );
297 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
298 g_qeglobals.m_userGamePath = path.c_str();
300 ASSERT_MESSAGE( !string_empty( g_qeglobals.m_userGamePath.c_str() ), "HomePaths_Realise: user-game-path is empty" );
301 Q_mkdir( g_qeglobals.m_userGamePath.c_str() );
304 ModuleObservers g_homePathObservers;
306 void Radiant_attachHomePathsObserver( ModuleObserver& observer ){
307 g_homePathObservers.attach( observer );
310 void Radiant_detachHomePathsObserver( ModuleObserver& observer ){
311 g_homePathObservers.detach( observer );
314 class HomePathsModuleObserver : public ModuleObserver
316 std::size_t m_unrealised;
318 HomePathsModuleObserver() : m_unrealised( 1 ){
322 if ( --m_unrealised == 0 ) {
324 g_homePathObservers.realise();
329 if ( ++m_unrealised == 1 ) {
330 g_homePathObservers.unrealise();
335 HomePathsModuleObserver g_HomePathsModuleObserver;
337 void HomePaths_Construct(){
338 Radiant_attachEnginePathObserver( g_HomePathsModuleObserver );
341 void HomePaths_Destroy(){
342 Radiant_detachEnginePathObserver( g_HomePathsModuleObserver );
348 CopiedString g_strEnginePath;
349 ModuleObservers g_enginePathObservers;
350 std::size_t g_enginepath_unrealised = 1;
352 void Radiant_attachEnginePathObserver( ModuleObserver& observer ){
353 g_enginePathObservers.attach( observer );
356 void Radiant_detachEnginePathObserver( ModuleObserver& observer ){
357 g_enginePathObservers.detach( observer );
361 void EnginePath_Realise(){
362 if ( --g_enginepath_unrealised == 0 ) {
363 g_enginePathObservers.realise();
368 const char* EnginePath_get(){
369 ASSERT_MESSAGE( g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised" );
370 return g_strEnginePath.c_str();
373 void EnginePath_Unrealise(){
374 if ( ++g_enginepath_unrealised == 1 ) {
375 g_enginePathObservers.unrealise();
379 void setEnginePath( const char* path ){
380 StringOutputStream buffer( 256 );
381 buffer << DirectoryCleaned( path );
382 if ( !path_equal( buffer.c_str(), g_strEnginePath.c_str() ) ) {
384 while ( !ConfirmModified( "Paths Changed" ) )
386 if ( Map_Unnamed( g_map ) ) {
397 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Changing Engine Path" );
399 EnginePath_Unrealise();
401 g_strEnginePath = buffer.c_str();
403 EnginePath_Realise();
409 CopiedString g_strPakPath[g_pakPathCount] = { "", "", "", "", "" };
410 ModuleObservers g_pakPathObservers[g_pakPathCount];
411 std::size_t g_pakpath_unrealised[g_pakPathCount] = { 1, 1, 1, 1, 1 };
413 void Radiant_attachPakPathObserver( int num, ModuleObserver& observer ){
414 g_pakPathObservers[num].attach( observer );
417 void Radiant_detachPakPathObserver( int num, ModuleObserver& observer ){
418 g_pakPathObservers[num].detach( observer );
422 void PakPath_Realise( int num ){
423 if ( --g_pakpath_unrealised[num] == 0 ) {
424 g_pakPathObservers[num].realise();
428 const char* PakPath_get( int num ){
429 std::string message = "PakPath_get: pak path " + std::to_string(num) + " not realised";
430 ASSERT_MESSAGE( g_pakpath_unrealised[num] == 0, message.c_str() );
431 return g_strPakPath[num].c_str();
434 void PakPath_Unrealise( int num ){
435 if ( ++g_pakpath_unrealised[num] == 1 ) {
436 g_pakPathObservers[num].unrealise();
440 void setPakPath( int num, const char* path ){
441 if (!g_strcmp0( path, "")) {
442 g_strPakPath[num] = "";
446 StringOutputStream buffer( 256 );
447 buffer << DirectoryCleaned( path );
448 if ( !path_equal( buffer.c_str(), g_strPakPath[num].c_str() ) ) {
449 std::string message = "Changing Pak Path " + std::to_string(num);
450 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", message.c_str() );
452 PakPath_Unrealise(num);
454 g_strPakPath[num] = buffer.c_str();
456 PakPath_Realise(num);
461 // executable file path (full path)
462 CopiedString g_strAppFilePath;
465 CopiedString g_strAppPath;
466 CopiedString g_strLibPath;
467 CopiedString g_strDataPath;
469 const char* AppFilePath_get(){
470 return g_strAppFilePath.c_str();
473 const char* AppPath_get(){
474 return g_strAppPath.c_str();
477 const char *LibPath_get()
479 return g_strLibPath.c_str();
482 const char *DataPath_get()
484 return g_strDataPath.c_str();
487 /// the path to the local rc-dir
488 const char* LocalRcPath_get( void ){
489 static CopiedString rc_path;
490 if ( rc_path.empty() ) {
491 StringOutputStream stream( 256 );
492 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
493 rc_path = stream.c_str();
495 return rc_path.c_str();
498 /// directory for temp files
499 /// NOTE: on *nix this is were we check for .pid
500 CopiedString g_strSettingsPath;
502 const char* SettingsPath_get(){
503 return g_strSettingsPath.c_str();
508 points to the game tools directory, for instance
509 C:/Program Files/Quake III Arena/GtkRadiant
511 this is one of the main variables that are configured by the game selection on startup
512 [GameToolsPath]/plugins
513 [GameToolsPath]/modules
516 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
518 const char* GameToolsPath_get(){
519 return g_strGameToolsPath.c_str();
523 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz) {
524 returnz(self.c_str());
527 static void Import(CopiedString &self, const char *value) {
528 setEnginePath( value );
533 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
534 returnz( self.c_str() );
537 static void Import( CopiedString &self, const char *value ) {
538 setPakPath( 0, value );
543 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
544 returnz( self.c_str() );
547 static void Import( CopiedString &self, const char *value ) {
548 setPakPath( 1, value );
553 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
554 returnz( self.c_str() );
557 static void Import( CopiedString &self, const char *value ) {
558 setPakPath( 2, value );
563 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
564 returnz( self.c_str() );
567 static void Import( CopiedString &self, const char *value ) {
568 setPakPath( 3, value );
573 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
574 returnz( self.c_str() );
577 static void Import( CopiedString &self, const char *value ) {
578 setPakPath( 4, value );
582 bool g_disableEnginePath = false;
583 bool g_disableHomePath = false;
585 void Paths_constructBasicPreferences( PreferencesPage& page ) {
586 page.appendPathEntry( "Engine Path", true, make_property<EnginePath>(g_strEnginePath) );
589 void Paths_constructPreferences( PreferencesPage& page ){
590 Paths_constructBasicPreferences( page );
592 page.appendSpacer( 4 );
593 page.appendLabel( "", "Advanced options" );
594 page.appendCheckBox( "", "Do not use Engine Path", g_disableEnginePath );
595 page.appendCheckBox( "", "Do not use Home Path", g_disableHomePath );
597 page.appendSpacer( 4 );
598 page.appendLabel( "", "Only a very few games support Pak Paths," );
599 page.appendLabel( "", "if you don't know what it is, leave this blank." );
601 const char *label = "Pak Path ";
602 page.appendPathEntry( label, true, make_property<PakPath0>( g_strPakPath[0] ) );
603 page.appendPathEntry( label, true, make_property<PakPath1>( g_strPakPath[1] ) );
604 page.appendPathEntry( label, true, make_property<PakPath2>( g_strPakPath[2] ) );
605 page.appendPathEntry( label, true, make_property<PakPath3>( g_strPakPath[3] ) );
606 page.appendPathEntry( label, true, make_property<PakPath4>( g_strPakPath[4] ) );
609 void Paths_constructPage( PreferenceGroup& group ){
610 PreferencesPage page( group.createPage( "Paths", "Path Settings" ) );
611 Paths_constructPreferences( page );
614 void Paths_registerPreferencesPage(){
615 PreferencesDialog_addSettingsPage( makeCallbackF(Paths_constructPage) );
619 class PathsDialog : public Dialog
622 ui::Window BuildDialog(){
623 auto frame = create_dialog_frame( "Path Settings", ui::Shadow::ETCHED_IN );
625 auto vbox2 = create_dialog_vbox( 0, 4 );
629 PreferencesPage page( *this, vbox2 );
630 Paths_constructBasicPreferences( page );
633 return ui::Window(create_simple_modal_dialog_window( "Engine Path Not Found", m_modal, frame ));
637 PathsDialog g_PathsDialog;
639 bool g_strEnginePath_was_empty_1st_start = false;
641 void EnginePath_verify(){
642 if ( !file_exists( g_strEnginePath.c_str() ) || g_strEnginePath_was_empty_1st_start ) {
643 g_PathsDialog.Create();
644 g_PathsDialog.DoModal();
645 g_PathsDialog.Destroy();
651 CopiedString g_gamename;
652 CopiedString g_gamemode;
653 ModuleObservers g_gameNameObservers;
654 ModuleObservers g_gameModeObservers;
657 void Radiant_attachGameNameObserver( ModuleObserver& observer ){
658 g_gameNameObservers.attach( observer );
661 void Radiant_detachGameNameObserver( ModuleObserver& observer ){
662 g_gameNameObservers.detach( observer );
665 const char* basegame_get(){
666 return g_pGameDescription->getRequiredKeyValue( "basegame" );
669 const char* gamename_get(){
670 const char* gamename = g_gamename.c_str();
671 if ( string_empty( gamename ) ) {
672 return basegame_get();
677 void gamename_set( const char* gamename ){
678 if ( !string_equal( gamename, g_gamename.c_str() ) ) {
679 g_gameNameObservers.unrealise();
680 g_gamename = gamename;
681 g_gameNameObservers.realise();
685 void Radiant_attachGameModeObserver( ModuleObserver& observer ){
686 g_gameModeObservers.attach( observer );
689 void Radiant_detachGameModeObserver( ModuleObserver& observer ){
690 g_gameModeObservers.detach( observer );
693 const char* gamemode_get(){
694 return g_gamemode.c_str();
697 void gamemode_set( const char* gamemode ){
698 if ( !string_equal( gamemode, g_gamemode.c_str() ) ) {
699 g_gameModeObservers.unrealise();
700 g_gamemode = gamemode;
701 g_gameModeObservers.realise();
708 const char* const c_library_extension =
709 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
710 CMAKE_SHARED_MODULE_SUFFIX
711 #elif GDEF_OS_WINDOWS
715 #elif GDEF_OS_LINUX || GDEF_OS_BSD
720 void Radiant_loadModules( const char* path ){
721 Directory_forEach(path, matchFileExtension(c_library_extension, [&](const char *name) {
723 ASSERT_MESSAGE(strlen(path) + strlen(name) < 1024, "");
724 strcpy(fullname, path);
725 strcat(fullname, name);
726 globalOutputStream() << "Found '" << fullname << "'\n";
727 GlobalModuleServer_loadModule(fullname);
731 void Radiant_loadModulesFromRoot( const char* directory ){
733 StringOutputStream path( 256 );
734 path << directory << g_pluginsDir;
735 Radiant_loadModules( path.c_str() );
738 if ( !string_equal( g_pluginsDir, g_modulesDir ) ) {
739 StringOutputStream path( 256 );
740 path << directory << g_modulesDir;
741 Radiant_loadModules( path.c_str() );
745 //! Make COLOR_BRUSHES override worldspawn eclass colour.
746 void SetWorldspawnColour( const Vector3& colour ){
747 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert( "worldspawn", true );
748 eclass_release_state( worldspawn );
749 worldspawn->color = colour;
750 eclass_capture_state( worldspawn );
754 class WorldspawnColourEntityClassObserver : public ModuleObserver
756 std::size_t m_unrealised;
758 WorldspawnColourEntityClassObserver() : m_unrealised( 1 ){
762 if ( --m_unrealised == 0 ) {
763 SetWorldspawnColour( g_xywindow_globals.color_brushes );
768 if ( ++m_unrealised == 1 ) {
773 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
776 ModuleObservers g_gameToolsPathObservers;
778 void Radiant_attachGameToolsPathObserver( ModuleObserver& observer ){
779 g_gameToolsPathObservers.attach( observer );
782 void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ){
783 g_gameToolsPathObservers.detach( observer );
786 void Radiant_Initialise(){
787 GlobalModuleServer_Initialise();
789 Radiant_loadModulesFromRoot( LibPath_get() );
793 bool success = Radiant_Construct( GlobalModuleServer_get() );
794 ASSERT_MESSAGE( success, "module system failed to initialise - see radiant.log for error messages" );
796 g_gameToolsPathObservers.realise();
797 g_gameModeObservers.realise();
798 g_gameNameObservers.realise();
801 void Radiant_Shutdown(){
802 g_gameNameObservers.unrealise();
803 g_gameModeObservers.unrealise();
804 g_gameToolsPathObservers.unrealise();
806 if ( !g_preferences_globals.disable_ini ) {
807 globalOutputStream() << "Start writing prefs\n";
809 globalOutputStream() << "Done prefs\n";
814 GlobalModuleServer_Shutdown();
818 if ( ConfirmModified( "Exit " RADIANT_NAME ) ) {
825 GlobalUndoSystem().undo();
830 GlobalUndoSystem().redo();
834 void deleteSelection(){
835 UndoableCommand undo( "deleteSelected" );
839 void Map_ExportSelected( TextOutputStream& ostream ){
840 Map_ExportSelected( ostream, Map_getFormat( g_map ) );
843 void Map_ImportSelected( TextInputStream& istream ){
844 Map_ImportSelected( istream, Map_getFormat( g_map ) );
847 void Selection_Copy(){
848 clipboard_copy( Map_ExportSelected );
851 void Selection_Paste(){
852 clipboard_paste( Map_ImportSelected );
856 if ( SelectedFaces_empty() ) {
861 SelectedFaces_copyTexture();
866 if ( SelectedFaces_empty() ) {
867 UndoableCommand undo( "paste" );
869 GlobalSelectionSystem().setSelectedAll( false );
874 SelectedFaces_pasteTexture();
878 void PasteToCamera(){
879 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
880 GlobalSelectionSystem().setSelectedAll( false );
882 UndoableCommand undo( "pasteToCamera" );
886 // Work out the delta
888 Select_GetMid( mid );
889 Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid );
892 GlobalSelectionSystem().translateSelected( delta );
896 void ColorScheme_Original(){
897 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
899 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
900 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
901 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
903 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
904 g_xywindow_globals.color_gridminor = Vector3( 0.75f, 0.75f, 0.75f );
905 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
906 g_xywindow_globals.color_gridminor_alt = Vector3( 0.5f, 0.0f, 0.0f );
907 g_xywindow_globals.color_gridmajor_alt = Vector3( 1.0f, 0.0f, 0.0f );
908 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
909 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
910 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
911 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
912 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
913 SetWorldspawnColour( g_xywindow_globals.color_brushes );
914 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
915 XY_UpdateAllWindows();
918 void ColorScheme_QER(){
919 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
921 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
922 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
923 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
925 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
926 g_xywindow_globals.color_gridminor = Vector3( 1.0f, 1.0f, 1.0f );
927 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
928 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
929 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
930 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
931 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
932 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
933 SetWorldspawnColour( g_xywindow_globals.color_brushes );
934 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
935 XY_UpdateAllWindows();
938 void ColorScheme_Black(){
939 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
941 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
942 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
943 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
945 g_xywindow_globals.color_gridback = Vector3( 0.0f, 0.0f, 0.0f );
946 g_xywindow_globals.color_gridminor = Vector3( 0.2f, 0.2f, 0.2f );
947 g_xywindow_globals.color_gridmajor = Vector3( 0.3f, 0.5f, 0.5f );
948 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
949 g_xywindow_globals.color_gridtext = Vector3( 1.0f, 1.0f, 1.0f );
950 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
951 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
952 g_xywindow_globals.color_brushes = Vector3( 1.0f, 1.0f, 1.0f );
953 SetWorldspawnColour( g_xywindow_globals.color_brushes );
954 g_xywindow_globals.color_viewname = Vector3( 0.7f, 0.7f, 0.0f );
955 XY_UpdateAllWindows();
958 /* ydnar: to emulate maya/max/lightwave color schemes */
959 void ColorScheme_Ydnar(){
960 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
962 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
963 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
964 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
966 g_xywindow_globals.color_gridback = Vector3( 0.77f, 0.77f, 0.77f );
967 g_xywindow_globals.color_gridminor = Vector3( 0.83f, 0.83f, 0.83f );
968 g_xywindow_globals.color_gridmajor = Vector3( 0.89f, 0.89f, 0.89f );
969 g_xywindow_globals.color_gridblock = Vector3( 1.0f, 1.0f, 1.0f );
970 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
971 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
972 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
973 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
974 SetWorldspawnColour( g_xywindow_globals.color_brushes );
975 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
976 XY_UpdateAllWindows();
979 /* color scheme to fit the GTK Adwaita Dark theme */
980 void ColorScheme_AdwaitaDark()
983 // GlobalTextureBrowser().color_textureback
984 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
987 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
989 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
990 CamWnd_Update(*g_pParentWnd->GetCamWnd());
993 g_xywindow_globals.color_gridback = Vector3(0.25f, 0.25f, 0.25f);
995 g_xywindow_globals.color_gridminor = Vector3(0.21f, 0.23f, 0.23f);
997 g_xywindow_globals.color_gridmajor = Vector3(0.14f, 0.15f, 0.15f);
999 g_xywindow_globals.color_gridmajor_alt = Vector3(1.0f, 0.0f, 0.0f);
1001 g_xywindow_globals.color_gridblock = Vector3(1.0f, 1.0f, 1.0f);
1003 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
1005 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
1007 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
1009 g_xywindow_globals.color_brushes = Vector3(0.73f, 0.73f, 0.73f);
1012 g_xywindow_globals.AxisColorX = Vector3(1.0f, 0.0f, 0.0f);
1014 g_xywindow_globals.AxisColorY = Vector3(0.0f, 1.0f, 0.0f);
1016 g_xywindow_globals.AxisColorZ = Vector3(0.0f, 0.0f, 1.0f);
1017 SetWorldspawnColour(g_xywindow_globals.color_brushes);
1019 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
1020 XY_UpdateAllWindows();
1023 // g_entity_globals.color_entity = Vector3(0.0f, 0.0f, 0.0f);
1026 typedef Callback<void(Vector3&)> GetColourCallback;
1027 typedef Callback<void(const Vector3&)> SetColourCallback;
1031 GetColourCallback m_get;
1032 SetColourCallback m_set;
1034 ChooseColour( const GetColourCallback& get, const SetColourCallback& set )
1035 : m_get( get ), m_set( set ){
1041 color_dialog( MainFrame_getWindow(), colour );
1047 void Colour_get( const Vector3& colour, Vector3& other ){
1051 typedef ConstReferenceCaller<Vector3, void(Vector3&), Colour_get> ColourGetCaller;
1053 void Colour_set( Vector3& colour, const Vector3& other ){
1055 SceneChangeNotify();
1058 typedef ReferenceCaller<Vector3, void(const Vector3&), Colour_set> ColourSetCaller;
1060 void BrushColour_set( const Vector3& other ){
1061 g_xywindow_globals.color_brushes = other;
1062 SetWorldspawnColour( g_xywindow_globals.color_brushes );
1063 SceneChangeNotify();
1066 typedef FreeCaller<void(const Vector3&), BrushColour_set> BrushColourSetCaller;
1068 void ClipperColour_set( const Vector3& other ){
1069 g_xywindow_globals.color_clipper = other;
1070 Brush_clipperColourChanged();
1071 SceneChangeNotify();
1074 typedef FreeCaller<void(const Vector3&), ClipperColour_set> ClipperColourSetCaller;
1076 void TextureBrowserColour_get( Vector3& other ){
1077 other = TextureBrowser_getBackgroundColour( GlobalTextureBrowser() );
1080 typedef FreeCaller<void(Vector3&), TextureBrowserColour_get> TextureBrowserColourGetCaller;
1082 void TextureBrowserColour_set( const Vector3& other ){
1083 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), other );
1086 typedef FreeCaller<void(const Vector3&), TextureBrowserColour_set> TextureBrowserColourSetCaller;
1092 ChooseColour m_textureback;
1093 ChooseColour m_xyback;
1094 ChooseColour m_gridmajor;
1095 ChooseColour m_gridminor;
1096 ChooseColour m_gridmajor_alt;
1097 ChooseColour m_gridminor_alt;
1098 ChooseColour m_gridtext;
1099 ChooseColour m_gridblock;
1100 ChooseColour m_cameraback;
1101 ChooseColour m_brush;
1102 ChooseColour m_selectedbrush;
1103 ChooseColour m_selectedbrush3d;
1104 ChooseColour m_clipper;
1105 ChooseColour m_viewname;
1108 m_textureback( TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller() ),
1109 m_xyback( ColourGetCaller( g_xywindow_globals.color_gridback ), ColourSetCaller( g_xywindow_globals.color_gridback ) ),
1110 m_gridmajor( ColourGetCaller( g_xywindow_globals.color_gridmajor ), ColourSetCaller( g_xywindow_globals.color_gridmajor ) ),
1111 m_gridminor( ColourGetCaller( g_xywindow_globals.color_gridminor ), ColourSetCaller( g_xywindow_globals.color_gridminor ) ),
1112 m_gridmajor_alt( ColourGetCaller( g_xywindow_globals.color_gridmajor_alt ), ColourSetCaller( g_xywindow_globals.color_gridmajor_alt ) ),
1113 m_gridminor_alt( ColourGetCaller( g_xywindow_globals.color_gridminor_alt ), ColourSetCaller( g_xywindow_globals.color_gridminor_alt ) ),
1114 m_gridtext( ColourGetCaller( g_xywindow_globals.color_gridtext ), ColourSetCaller( g_xywindow_globals.color_gridtext ) ),
1115 m_gridblock( ColourGetCaller( g_xywindow_globals.color_gridblock ), ColourSetCaller( g_xywindow_globals.color_gridblock ) ),
1116 m_cameraback( ColourGetCaller( g_camwindow_globals.color_cameraback ), ColourSetCaller( g_camwindow_globals.color_cameraback ) ),
1117 m_brush( ColourGetCaller( g_xywindow_globals.color_brushes ), BrushColourSetCaller() ),
1118 m_selectedbrush( ColourGetCaller( g_xywindow_globals.color_selbrushes ), ColourSetCaller( g_xywindow_globals.color_selbrushes ) ),
1119 m_selectedbrush3d( ColourGetCaller( g_camwindow_globals.color_selbrushes3d ), ColourSetCaller( g_camwindow_globals.color_selbrushes3d ) ),
1120 m_clipper( ColourGetCaller( g_xywindow_globals.color_clipper ), ClipperColourSetCaller() ),
1121 m_viewname( ColourGetCaller( g_xywindow_globals.color_viewname ), ColourSetCaller( g_xywindow_globals.color_viewname ) ){
1125 ColoursMenu g_ColoursMenu;
1127 ui::MenuItem create_colours_menu(){
1128 auto colours_menu_item = new_sub_menu_item_with_mnemonic( "Colors" );
1129 auto menu_in_menu = ui::Menu::from( gtk_menu_item_get_submenu( colours_menu_item ) );
1130 if ( g_Layout_enableDetachableMenus.m_value ) {
1131 menu_tearoff( menu_in_menu );
1134 auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Themes" );
1135 if ( g_Layout_enableDetachableMenus.m_value ) {
1136 menu_tearoff( menu_3 );
1139 create_menu_item_with_mnemonic( menu_3, "QE4 Original", "ColorSchemeOriginal" );
1140 create_menu_item_with_mnemonic( menu_3, "Q3Radiant Original", "ColorSchemeQER" );
1141 create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" );
1142 create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" );
1143 create_menu_item_with_mnemonic(menu_3, "Adwaita Dark", "ColorSchemeAdwaitaDark");
1145 #ifndef GARUX_DISABLE_GTKTHEME
1146 create_menu_item_with_mnemonic( menu_in_menu, "GTK Theme...", "gtkThemeDlg" );
1149 menu_separator( menu_in_menu );
1151 create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" );
1152 create_menu_item_with_mnemonic( menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor" );
1153 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major...", "ChooseGridMajorColor" );
1154 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor...", "ChooseGridMinorColor" );
1155 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor" );
1156 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor" );
1157 create_menu_item_with_mnemonic( menu_in_menu, "Grid Text...", "ChooseGridTextColor" );
1158 create_menu_item_with_mnemonic( menu_in_menu, "Grid Block...", "ChooseGridBlockColor" );
1159 create_menu_item_with_mnemonic( menu_in_menu, "Default Brush...", "ChooseBrushColor" );
1160 create_menu_item_with_mnemonic( menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor" );
1161 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor" );
1162 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor" );
1163 create_menu_item_with_mnemonic( menu_in_menu, "Clipper...", "ChooseClipperColor" );
1164 create_menu_item_with_mnemonic( menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor" );
1166 return colours_menu_item;
1171 PluginsMenu_clear();
1172 PluginToolbar_clear();
1175 Radiant_Initialise();
1177 PluginsMenu_populate();
1179 PluginToolbar_populate();
1183 void thunk_OnSleep(){
1184 g_pParentWnd->OnSleep();
1188 OpenURL( "https://gitlab.com/xonotic/xonotic/wikis/Mapping" );
1191 void OpenBugReportURL(){
1192 OpenURL( "https://gitlab.com/xonotic/netradiant/issues" );
1196 ui::Widget g_page_console{ui::null};
1198 void Console_ToggleShow(){
1199 GroupDialog_showPage( g_page_console );
1202 ui::Widget g_page_entity{ui::null};
1204 void EntityInspector_ToggleShow(){
1205 GroupDialog_showPage( g_page_entity );
1209 void SetClipMode( bool enable );
1211 void ModeChangeNotify();
1213 typedef void ( *ToolMode )();
1215 ToolMode g_currentToolMode = 0;
1216 bool g_currentToolModeSupportsComponentEditing = false;
1217 ToolMode g_defaultToolMode = 0;
1220 void SelectionSystem_DefaultMode(){
1221 GlobalSelectionSystem().SetMode( SelectionSystem::ePrimitive );
1222 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eDefault );
1228 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1229 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1233 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1234 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1238 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1239 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1242 template<bool( *BoolFunction ) ( )>
1243 class BoolFunctionExport
1246 static void apply( const Callback<void(bool)> & importCallback ){
1247 importCallback( BoolFunction() );
1251 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1252 EdgeModeApplyCaller g_edgeMode_button_caller;
1253 Callback<void(const Callback<void(bool)> &)> g_edgeMode_button_callback( g_edgeMode_button_caller );
1254 ToggleItem g_edgeMode_button( g_edgeMode_button_callback );
1256 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1257 VertexModeApplyCaller g_vertexMode_button_caller;
1258 Callback<void(const Callback<void(bool)> &)> g_vertexMode_button_callback( g_vertexMode_button_caller );
1259 ToggleItem g_vertexMode_button( g_vertexMode_button_callback );
1261 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1262 FaceModeApplyCaller g_faceMode_button_caller;
1263 Callback<void(const Callback<void(bool)> &)> g_faceMode_button_callback( g_faceMode_button_caller );
1264 ToggleItem g_faceMode_button( g_faceMode_button_callback );
1266 void ComponentModeChanged(){
1267 g_edgeMode_button.update();
1268 g_vertexMode_button.update();
1269 g_faceMode_button.update();
1272 void ComponentMode_SelectionChanged( const Selectable& selectable ){
1273 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1274 && GlobalSelectionSystem().countSelected() == 0 ) {
1275 SelectionSystem_DefaultMode();
1276 ComponentModeChanged();
1280 void SelectEdgeMode(){
1282 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1283 GlobalSelectionSystem().Select( false );
1288 SelectionSystem_DefaultMode();
1290 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1291 if ( !g_currentToolModeSupportsComponentEditing ) {
1292 g_defaultToolMode();
1295 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1296 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eEdge );
1299 ComponentModeChanged();
1304 void SelectVertexMode(){
1306 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1307 GlobalSelectionSystem().Select( false );
1311 if ( VertexMode() ) {
1312 SelectionSystem_DefaultMode();
1314 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1315 if ( !g_currentToolModeSupportsComponentEditing ) {
1316 g_defaultToolMode();
1319 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1320 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eVertex );
1323 ComponentModeChanged();
1328 void SelectFaceMode(){
1330 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1331 GlobalSelectionSystem().Select( false );
1336 SelectionSystem_DefaultMode();
1338 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1339 if ( !g_currentToolModeSupportsComponentEditing ) {
1340 g_defaultToolMode();
1343 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1344 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eFace );
1347 ComponentModeChanged();
1353 class CloneSelected : public scene::Graph::Walker
1356 NodeSmartReference worldspawn;
1358 CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
1361 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1362 if ( path.size() == 1 ) {
1366 // ignore worldspawn, but keep checking children
1367 NodeSmartReference me( path.top().get() );
1368 if ( me == worldspawn ) {
1372 if ( !path.top().get().isRoot() ) {
1373 Selectable* selectable = Instance_getSelectable( instance );
1374 if ( selectable != 0
1375 && selectable->isSelected() ) {
1383 void post( const scene::Path& path, scene::Instance& instance ) const {
1384 if ( path.size() == 1 ) {
1388 // ignore worldspawn, but keep checking children
1389 NodeSmartReference me( path.top().get() );
1390 if ( me == worldspawn ) {
1394 if ( !path.top().get().isRoot() ) {
1395 Selectable* selectable = Instance_getSelectable( instance );
1396 if ( selectable != 0
1397 && selectable->isSelected() ) {
1398 NodeSmartReference clone( Node_Clone( path.top() ) );
1399 if ( doMakeUnique ) {
1400 Map_gatherNamespaced( clone );
1402 Node_getTraversable( path.parent().get() )->insert( clone );
1408 void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){
1409 graph.traverse( CloneSelected( doMakeUnique ) );
1411 Map_mergeClonedNames();
1414 enum ENudgeDirection
1428 AxisBase( const Vector3& x_, const Vector3& y_, const Vector3& z_ )
1429 : x( x_ ), y( y_ ), z( z_ ){
1433 AxisBase AxisBase_forViewType( VIEWTYPE viewtype ){
1437 return AxisBase( g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z );
1439 return AxisBase( g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y );
1441 return AxisBase( g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x );
1444 ERROR_MESSAGE( "invalid viewtype" );
1445 return AxisBase( Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) );
1448 Vector3 AxisBase_axisForDirection( const AxisBase& axes, ENudgeDirection direction ){
1449 switch ( direction )
1452 return vector3_negated( axes.x );
1458 return vector3_negated( axes.y );
1461 ERROR_MESSAGE( "invalid direction" );
1462 return Vector3( 0, 0, 0 );
1465 void NudgeSelection( ENudgeDirection direction, float fAmount, VIEWTYPE viewtype ){
1466 AxisBase axes( AxisBase_forViewType( viewtype ) );
1467 Vector3 view_direction( vector3_negated( axes.z ) );
1468 Vector3 nudge( vector3_scaled( AxisBase_axisForDirection( axes, direction ), fAmount ) );
1469 GlobalSelectionSystem().NudgeManipulator( nudge, view_direction );
1472 void Selection_Clone(){
1473 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1474 UndoableCommand undo( "cloneSelected" );
1476 Scene_Clone_Selected( GlobalSceneGraph(), false );
1478 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1479 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1483 void Selection_Clone_MakeUnique(){
1484 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1485 UndoableCommand undo( "cloneSelectedMakeUnique" );
1487 Scene_Clone_Selected( GlobalSceneGraph(), true );
1489 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1490 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1494 // called when the escape key is used (either on the main window or on an inspector)
1495 void Selection_Deselect(){
1496 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1497 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1498 GlobalSelectionSystem().setSelectedAllComponents( false );
1502 SelectionSystem_DefaultMode();
1503 ComponentModeChanged();
1508 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1509 GlobalSelectionSystem().setSelectedAllComponents( false );
1513 GlobalSelectionSystem().setSelectedAll( false );
1519 void Selection_NudgeUp(){
1520 UndoableCommand undo( "nudgeSelectedUp" );
1521 NudgeSelection( eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1524 void Selection_NudgeDown(){
1525 UndoableCommand undo( "nudgeSelectedDown" );
1526 NudgeSelection( eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1529 void Selection_NudgeLeft(){
1530 UndoableCommand undo( "nudgeSelectedLeft" );
1531 NudgeSelection( eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1534 void Selection_NudgeRight(){
1535 UndoableCommand undo( "nudgeSelectedRight" );
1536 NudgeSelection( eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1540 void TranslateToolExport( const Callback<void(bool)> & importCallback ){
1541 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate );
1544 void RotateToolExport( const Callback<void(bool)> & importCallback ){
1545 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate );
1548 void ScaleToolExport( const Callback<void(bool)> & importCallback ){
1549 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale );
1552 void DragToolExport( const Callback<void(bool)> & importCallback ){
1553 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag );
1556 void ClipperToolExport( const Callback<void(bool)> & importCallback ){
1557 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip );
1560 FreeCaller<void(const Callback<void(bool)> &), TranslateToolExport> g_translatemode_button_caller;
1561 Callback<void(const Callback<void(bool)> &)> g_translatemode_button_callback( g_translatemode_button_caller );
1562 ToggleItem g_translatemode_button( g_translatemode_button_callback );
1564 FreeCaller<void(const Callback<void(bool)> &), RotateToolExport> g_rotatemode_button_caller;
1565 Callback<void(const Callback<void(bool)> &)> g_rotatemode_button_callback( g_rotatemode_button_caller );
1566 ToggleItem g_rotatemode_button( g_rotatemode_button_callback );
1568 FreeCaller<void(const Callback<void(bool)> &), ScaleToolExport> g_scalemode_button_caller;
1569 Callback<void(const Callback<void(bool)> &)> g_scalemode_button_callback( g_scalemode_button_caller );
1570 ToggleItem g_scalemode_button( g_scalemode_button_callback );
1572 FreeCaller<void(const Callback<void(bool)> &), DragToolExport> g_dragmode_button_caller;
1573 Callback<void(const Callback<void(bool)> &)> g_dragmode_button_callback( g_dragmode_button_caller );
1574 ToggleItem g_dragmode_button( g_dragmode_button_callback );
1576 FreeCaller<void(const Callback<void(bool)> &), ClipperToolExport> g_clipper_button_caller;
1577 Callback<void(const Callback<void(bool)> &)> g_clipper_button_callback( g_clipper_button_caller );
1578 ToggleItem g_clipper_button( g_clipper_button_callback );
1581 g_translatemode_button.update();
1582 g_rotatemode_button.update();
1583 g_scalemode_button.update();
1584 g_dragmode_button.update();
1585 g_clipper_button.update();
1588 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1591 if ( g_currentToolMode == DragMode && g_defaultToolMode != DragMode ) {
1592 g_defaultToolMode();
1596 g_currentToolMode = DragMode;
1597 g_currentToolModeSupportsComponentEditing = true;
1599 OnClipMode( false );
1601 Sys_Status( c_ResizeMode_status );
1602 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eDrag );
1609 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1611 void TranslateMode(){
1612 if ( g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode ) {
1613 g_defaultToolMode();
1617 g_currentToolMode = TranslateMode;
1618 g_currentToolModeSupportsComponentEditing = true;
1620 OnClipMode( false );
1622 Sys_Status( c_TranslateMode_status );
1623 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eTranslate );
1629 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1632 if ( g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode ) {
1633 g_defaultToolMode();
1637 g_currentToolMode = RotateMode;
1638 g_currentToolModeSupportsComponentEditing = true;
1640 OnClipMode( false );
1642 Sys_Status( c_RotateMode_status );
1643 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eRotate );
1649 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1652 if ( g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode ) {
1653 g_defaultToolMode();
1657 g_currentToolMode = ScaleMode;
1658 g_currentToolModeSupportsComponentEditing = true;
1660 OnClipMode( false );
1662 Sys_Status( c_ScaleMode_status );
1663 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eScale );
1670 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1674 if ( g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode ) {
1675 g_defaultToolMode();
1679 g_currentToolMode = ClipperMode;
1680 g_currentToolModeSupportsComponentEditing = false;
1682 SelectionSystem_DefaultMode();
1686 Sys_Status( c_ClipperMode_status );
1687 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eClip );
1694 void Texdef_Rotate( float angle ){
1695 StringOutputStream command;
1696 command << "brushRotateTexture -angle " << angle;
1697 UndoableCommand undo( command.c_str() );
1698 Select_RotateTexture( angle );
1701 void Texdef_RotateClockwise(){
1702 Texdef_Rotate( static_cast<float>( fabs( g_si_globals.rotate ) ) );
1705 void Texdef_RotateAntiClockwise(){
1706 Texdef_Rotate( static_cast<float>( -fabs( g_si_globals.rotate ) ) );
1709 void Texdef_Scale( float x, float y ){
1710 StringOutputStream command;
1711 command << "brushScaleTexture -x " << x << " -y " << y;
1712 UndoableCommand undo( command.c_str() );
1713 Select_ScaleTexture( x, y );
1716 void Texdef_ScaleUp(){
1717 Texdef_Scale( 0, g_si_globals.scale[1] );
1720 void Texdef_ScaleDown(){
1721 Texdef_Scale( 0, -g_si_globals.scale[1] );
1724 void Texdef_ScaleLeft(){
1725 Texdef_Scale( -g_si_globals.scale[0],0 );
1728 void Texdef_ScaleRight(){
1729 Texdef_Scale( g_si_globals.scale[0],0 );
1732 void Texdef_Shift( float x, float y ){
1733 StringOutputStream command;
1734 command << "brushShiftTexture -x " << x << " -y " << y;
1735 UndoableCommand undo( command.c_str() );
1736 Select_ShiftTexture( x, y );
1739 void Texdef_ShiftLeft(){
1740 Texdef_Shift( -g_si_globals.shift[0], 0 );
1743 void Texdef_ShiftRight(){
1744 Texdef_Shift( g_si_globals.shift[0], 0 );
1747 void Texdef_ShiftUp(){
1748 Texdef_Shift( 0, g_si_globals.shift[1] );
1751 void Texdef_ShiftDown(){
1752 Texdef_Shift( 0, -g_si_globals.shift[1] );
1757 class SnappableSnapToGridSelected : public scene::Graph::Walker
1761 SnappableSnapToGridSelected( float snap )
1765 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1766 if ( path.top().get().visible() ) {
1767 Snappable* snappable = Node_getSnappable( path.top() );
1769 && Instance_getSelectable( instance )->isSelected() ) {
1770 snappable->snapto( m_snap );
1777 void Scene_SnapToGrid_Selected( scene::Graph& graph, float snap ){
1778 graph.traverse( SnappableSnapToGridSelected( snap ) );
1781 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1785 ComponentSnappableSnapToGridSelected( float snap )
1789 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1790 if ( path.top().get().visible() ) {
1791 ComponentSnappable* componentSnappable = Instance_getComponentSnappable( instance );
1792 if ( componentSnappable != 0
1793 && Instance_getSelectable( instance )->isSelected() ) {
1794 componentSnappable->snapComponents( m_snap );
1801 void Scene_SnapToGrid_Component_Selected( scene::Graph& graph, float snap ){
1802 graph.traverse( ComponentSnappableSnapToGridSelected( snap ) );
1805 void Selection_SnapToGrid(){
1806 StringOutputStream command;
1807 command << "snapSelected -grid " << GetGridSize();
1808 UndoableCommand undo( command.c_str() );
1810 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1811 Scene_SnapToGrid_Component_Selected( GlobalSceneGraph(), GetGridSize() );
1815 Scene_SnapToGrid_Selected( GlobalSceneGraph(), GetGridSize() );
1820 static gint qe_every_second( gpointer data ){
1821 if (g_pParentWnd == nullptr)
1824 GdkModifierType mask;
1825 gdk_window_get_pointer( gtk_widget_get_window(g_pParentWnd->m_window), nullptr, nullptr, &mask );
1827 if ( ( mask & ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK ) ) == 0 ) {
1834 guint s_qe_every_second_id = 0;
1836 void EverySecondTimer_enable(){
1837 if ( s_qe_every_second_id == 0 ) {
1838 s_qe_every_second_id = g_timeout_add( 1000, qe_every_second, 0 );
1842 void EverySecondTimer_disable(){
1843 if ( s_qe_every_second_id != 0 ) {
1844 g_source_remove( s_qe_every_second_id );
1845 s_qe_every_second_id = 0;
1849 gint window_realize_remove_decoration( ui::Widget widget, gpointer data ){
1850 gdk_window_set_decorations( gtk_widget_get_window(widget), (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) );
1857 ui::Window m_window{ui::null};
1858 ui::Label m_label{ui::null};
1861 WaitDialog create_wait_dialog( const char* title, const char* text ){
1864 dialog.m_window = MainFrame_getWindow().create_floating_window(title);
1865 gtk_window_set_resizable( dialog.m_window, FALSE );
1866 gtk_container_set_border_width( GTK_CONTAINER( dialog.m_window ), 0 );
1867 gtk_window_set_position( dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT );
1869 dialog.m_window.connect( "realize", G_CALLBACK( window_realize_remove_decoration ), 0 );
1872 dialog.m_label = ui::Label( text );
1873 gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 );
1874 gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT );
1875 dialog.m_label.show();
1876 dialog.m_label.dimensions(200, -1);
1878 dialog.m_window.add(dialog.m_label);
1885 clock_t g_lastRedrawTime = 0;
1886 const clock_t c_redrawInterval = clock_t( CLOCKS_PER_SEC / 10 );
1888 bool redrawRequired(){
1889 clock_t currentTime = std::clock();
1890 if ( currentTime - g_lastRedrawTime >= c_redrawInterval ) {
1891 g_lastRedrawTime = currentTime;
1898 bool MainFrame_isActiveApp(){
1899 //globalOutputStream() << "listing\n";
1900 GList* list = gtk_window_list_toplevels();
1901 for ( GList* i = list; i != 0; i = g_list_next( i ) )
1903 //globalOutputStream() << "toplevel.. ";
1904 if ( gtk_window_is_active( ui::Window::from( i->data ) ) ) {
1905 //globalOutputStream() << "is active\n";
1908 //globalOutputStream() << "not active\n";
1913 typedef std::list<CopiedString> StringStack;
1914 StringStack g_wait_stack;
1917 bool ScreenUpdates_Enabled(){
1918 return g_wait_stack.empty();
1921 void ScreenUpdates_process(){
1922 if ( redrawRequired() && g_wait.m_window.visible() ) {
1928 void ScreenUpdates_Disable( const char* message, const char* title ){
1929 if ( g_wait_stack.empty() ) {
1930 EverySecondTimer_disable();
1934 bool isActiveApp = MainFrame_isActiveApp();
1936 g_wait = create_wait_dialog( title, message );
1938 if ( isActiveApp ) {
1939 g_wait.m_window.show();
1940 gtk_grab_add( g_wait.m_window );
1941 ScreenUpdates_process();
1944 else if ( g_wait.m_window.visible() ) {
1945 g_wait.m_label.text(message);
1946 if ( GTK_IS_WINDOW(g_wait.m_window) ) {
1947 gtk_grab_add(g_wait.m_window);
1949 ScreenUpdates_process();
1951 g_wait_stack.push_back( message );
1954 void ScreenUpdates_Enable(){
1955 ASSERT_MESSAGE( !ScreenUpdates_Enabled(), "screen updates already enabled" );
1956 g_wait_stack.pop_back();
1957 if ( g_wait_stack.empty() ) {
1958 EverySecondTimer_enable();
1959 //gtk_widget_set_sensitive(MainFrame_getWindow(), TRUE);
1961 gtk_grab_remove( g_wait.m_window );
1962 destroy_floating_window( g_wait.m_window );
1963 g_wait.m_window = ui::Window{ui::null};
1965 //gtk_window_present(MainFrame_getWindow());
1967 else if ( g_wait.m_window.visible() ) {
1968 g_wait.m_label.text(g_wait_stack.back().c_str());
1969 ScreenUpdates_process();
1974 void GlobalCamera_UpdateWindow(){
1975 if ( g_pParentWnd != 0 ) {
1976 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
1980 void XY_UpdateWindow( MainFrame& mainframe ){
1981 if ( mainframe.GetXYWnd() != 0 ) {
1982 XYWnd_Update( *mainframe.GetXYWnd() );
1986 void XZ_UpdateWindow( MainFrame& mainframe ){
1987 if ( mainframe.GetXZWnd() != 0 ) {
1988 XYWnd_Update( *mainframe.GetXZWnd() );
1992 void YZ_UpdateWindow( MainFrame& mainframe ){
1993 if ( mainframe.GetYZWnd() != 0 ) {
1994 XYWnd_Update( *mainframe.GetYZWnd() );
1998 void XY_UpdateAllWindows( MainFrame& mainframe ){
1999 XY_UpdateWindow( mainframe );
2000 XZ_UpdateWindow( mainframe );
2001 YZ_UpdateWindow( mainframe );
2004 void XY_UpdateAllWindows(){
2005 if ( g_pParentWnd != 0 ) {
2006 XY_UpdateAllWindows( *g_pParentWnd );
2010 void UpdateAllWindows(){
2011 GlobalCamera_UpdateWindow();
2012 XY_UpdateAllWindows();
2016 void ModeChangeNotify(){
2017 SceneChangeNotify();
2020 void ClipperChangeNotify(){
2021 GlobalCamera_UpdateWindow();
2022 XY_UpdateAllWindows();
2026 LatchedValue<int> g_Layout_viewStyle( 0, "Window Layout" );
2027 LatchedValue<bool> g_Layout_enableDetachableMenus( true, "Detachable Menus" );
2028 LatchedValue<bool> g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
2029 LatchedValue<bool> g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
2030 LatchedValue<bool> g_Layout_enableFilterToolbar( true, "Filter Toolbar" );
2033 ui::MenuItem create_file_menu(){
2035 auto file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
2036 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( file_menu_item ) );
2037 if ( g_Layout_enableDetachableMenus.m_value ) {
2038 menu_tearoff( menu );
2041 create_menu_item_with_mnemonic( menu, "_New Map", "NewMap" );
2042 menu_separator( menu );
2045 //++timo temporary experimental stuff for sleep mode..
2046 create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" );
2047 menu_separator( menu );
2051 create_menu_item_with_mnemonic( menu, "_Open...", "OpenMap" );
2053 create_menu_item_with_mnemonic( menu, "_Import...", "ImportMap" );
2054 create_menu_item_with_mnemonic( menu, "_Save", "SaveMap" );
2055 create_menu_item_with_mnemonic( menu, "Save _as...", "SaveMapAs" );
2056 create_menu_item_with_mnemonic( menu, "_Export selected...", "ExportSelected" );
2057 menu_separator( menu );
2058 create_menu_item_with_mnemonic( menu, "Save re_gion...", "SaveRegion" );
2059 // menu_separator( menu );
2060 // create_menu_item_with_mnemonic( menu, "_Refresh models", "RefreshReferences" );
2061 // menu_separator( menu );
2062 create_menu_item_with_mnemonic( menu, "Pro_ject settings...", "ProjectSettings" );
2063 menu_separator( menu );
2064 create_menu_item_with_mnemonic( menu, "_Pointfile...", "TogglePointfile" );
2065 menu_separator( menu );
2066 MRU_constructMenu( menu );
2067 menu_separator( menu );
2068 // create_menu_item_with_mnemonic( menu, "Check for NetRadiant update (web)", "CheckForUpdate" ); // FIXME
2069 create_menu_item_with_mnemonic( menu, "E_xit", "Exit" );
2071 return file_menu_item;
2074 ui::MenuItem create_edit_menu(){
2076 auto edit_menu_item = new_sub_menu_item_with_mnemonic( "_Edit" );
2077 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( edit_menu_item ) );
2078 if ( g_Layout_enableDetachableMenus.m_value ) {
2079 menu_tearoff( menu );
2081 create_menu_item_with_mnemonic( menu, "_Undo", "Undo" );
2082 create_menu_item_with_mnemonic( menu, "_Redo", "Redo" );
2083 menu_separator( menu );
2084 create_menu_item_with_mnemonic( menu, "_Copy", "Copy" );
2085 create_menu_item_with_mnemonic( menu, "_Paste", "Paste" );
2086 create_menu_item_with_mnemonic( menu, "P_aste To Camera", "PasteToCamera" );
2087 menu_separator( menu );
2088 create_menu_item_with_mnemonic( menu, "_Duplicate", "CloneSelection" );
2089 create_menu_item_with_mnemonic( menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique" );
2090 create_menu_item_with_mnemonic( menu, "D_elete", "DeleteSelection" );
2091 //create_menu_item_with_mnemonic( menu, "Pa_rent", "ParentSelection" );
2092 menu_separator( menu );
2093 create_menu_item_with_mnemonic( menu, "C_lear Selection", "UnSelectSelection" );
2094 create_menu_item_with_mnemonic( menu, "_Invert Selection", "InvertSelection" );
2095 create_menu_item_with_mnemonic( menu, "Select i_nside", "SelectInside" );
2096 create_menu_item_with_mnemonic( menu, "Select _touching", "SelectTouching" );
2098 menu_separator( menu );
2100 // auto convert_menu = create_sub_menu_with_mnemonic( menu, "E_xpand Selection" );
2101 // if ( g_Layout_enableDetachableMenus.m_value ) {
2102 // menu_tearoff( convert_menu );
2104 create_menu_item_with_mnemonic( menu, "Select All Of Type", "SelectAllOfType" );
2105 create_menu_item_with_mnemonic( menu, "_Expand Selection To Entities", "ExpandSelectionToEntities" );
2107 menu_separator( menu );
2108 create_menu_item_with_mnemonic( menu, "Pre_ferences...", "Preferences" );
2110 return edit_menu_item;
2113 void fill_view_xy_top_menu( ui::Menu menu ){
2114 create_check_menu_item_with_mnemonic( menu, "XY (Top) View", "ToggleView" );
2118 void fill_view_yz_side_menu( ui::Menu menu ){
2119 create_check_menu_item_with_mnemonic( menu, "YZ (Side) View", "ToggleSideView" );
2123 void fill_view_xz_front_menu( ui::Menu menu ){
2124 create_check_menu_item_with_mnemonic( menu, "XZ (Front) View", "ToggleFrontView" );
2128 ui::Widget g_toggle_z_item{ui::null};
2129 ui::Widget g_toggle_console_item{ui::null};
2130 ui::Widget g_toggle_entity_item{ui::null};
2131 ui::Widget g_toggle_entitylist_item{ui::null};
2133 ui::MenuItem create_view_menu( MainFrame::EViewStyle style ){
2135 auto view_menu_item = new_sub_menu_item_with_mnemonic( "Vie_w" );
2136 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( view_menu_item ) );
2137 if ( g_Layout_enableDetachableMenus.m_value ) {
2138 menu_tearoff( menu );
2141 if ( style == MainFrame::eFloating ) {
2142 fill_view_camera_menu( menu );
2143 fill_view_xy_top_menu( menu );
2144 fill_view_yz_side_menu( menu );
2145 fill_view_xz_front_menu( menu );
2147 if ( style == MainFrame::eFloating || style == MainFrame::eSplit ) {
2148 create_menu_item_with_mnemonic( menu, "Console View", "ToggleConsole" );
2149 create_menu_item_with_mnemonic( menu, "Texture Browser", "ToggleTextures" );
2150 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ToggleEntityInspector" );
2154 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ViewEntityInfo" );
2156 create_menu_item_with_mnemonic( menu, "_Surface Inspector", "SurfaceInspector" );
2157 create_menu_item_with_mnemonic( menu, "_Patch Inspector", "PatchInspector" );
2158 create_menu_item_with_mnemonic( menu, "Entity List", "EntityList" );
2160 menu_separator( menu );
2162 auto camera_menu = create_sub_menu_with_mnemonic( menu, "Camera" );
2163 if ( g_Layout_enableDetachableMenus.m_value ) {
2164 menu_tearoff( camera_menu );
2166 create_menu_item_with_mnemonic( camera_menu, "_Center", "CenterView" );
2167 create_menu_item_with_mnemonic( camera_menu, "_Up Floor", "UpFloor" );
2168 create_menu_item_with_mnemonic( camera_menu, "_Down Floor", "DownFloor" );
2169 menu_separator( camera_menu );
2170 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane In", "CubicClipZoomIn" );
2171 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane Out", "CubicClipZoomOut" );
2172 menu_separator( camera_menu );
2173 create_menu_item_with_mnemonic( camera_menu, "Decrease FOV", "FOVDec" );
2174 create_menu_item_with_mnemonic( camera_menu, "Increase FOV", "FOVInc" );
2175 menu_separator( camera_menu );
2176 create_menu_item_with_mnemonic( camera_menu, "Next leak spot", "NextLeakSpot" );
2177 create_menu_item_with_mnemonic( camera_menu, "Previous leak spot", "PrevLeakSpot" );
2178 menu_separator( camera_menu );
2179 create_menu_item_with_mnemonic( camera_menu, "Look Through Selected", "LookThroughSelected" );
2180 create_menu_item_with_mnemonic( camera_menu, "Look Through Camera", "LookThroughCamera" );
2182 menu_separator( menu );
2184 auto orthographic_menu = create_sub_menu_with_mnemonic( menu, "Orthographic" );
2185 if ( g_Layout_enableDetachableMenus.m_value ) {
2186 menu_tearoff( orthographic_menu );
2188 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2189 create_menu_item_with_mnemonic( orthographic_menu, "_Next (XY, YZ, XY)", "NextView" );
2190 create_menu_item_with_mnemonic( orthographic_menu, "XY (Top)", "ViewTop" );
2191 create_menu_item_with_mnemonic( orthographic_menu, "YZ", "ViewSide" );
2192 create_menu_item_with_mnemonic( orthographic_menu, "XZ", "ViewFront" );
2193 menu_separator( orthographic_menu );
2196 create_menu_item_with_mnemonic( orthographic_menu, "Center on Selected", "CenterXYView" );
2197 menu_separator( orthographic_menu );
2198 create_menu_item_with_mnemonic( orthographic_menu, "_XY 100%", "Zoom100" );
2199 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _In", "ZoomIn" );
2200 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _Out", "ZoomOut" );
2203 menu_separator( menu );
2206 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Show" );
2207 if ( g_Layout_enableDetachableMenus.m_value ) {
2208 menu_tearoff( menu_in_menu );
2210 create_menu_item_with_mnemonic( menu_in_menu, "Show Size Info", "ToggleSizePaint" );
2211 create_menu_item_with_mnemonic( menu_in_menu, "Show Crosshair", "ToggleCrosshairs" );
2212 create_menu_item_with_mnemonic( menu_in_menu, "Show Grid", "ToggleGrid" );
2214 menu_separator( menu_in_menu );
2216 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Angles", "ShowAngles" );
2217 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Names", "ShowNames" );
2218 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Blocks", "ShowBlocks" );
2219 create_check_menu_item_with_mnemonic( menu_in_menu, "Show C_oordinates", "ShowCoordinates" );
2220 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Window Outline", "ShowWindowOutline" );
2221 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Axes", "ShowAxes" );
2222 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Workzone", "ShowWorkzone" );
2223 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Stats", "ShowStats" );
2227 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Filter" );
2228 if ( g_Layout_enableDetachableMenus.m_value ) {
2229 menu_tearoff( menu_in_menu );
2231 Filters_constructMenu( menu_in_menu );
2233 menu_separator( menu );
2235 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Hide/Show" );
2236 // if ( g_Layout_enableDetachableMenus.m_value ) {
2237 // menu_tearoff( menu_in_menu );
2239 // create_menu_item_with_mnemonic( menu_in_menu, "Hide Selected", "HideSelected" );
2240 // create_menu_item_with_mnemonic( menu_in_menu, "Show Hidden", "ShowHidden" );
2241 create_menu_item_with_mnemonic( menu, "Hide Selected", "HideSelected" );
2242 create_menu_item_with_mnemonic( menu, "Show Hidden", "ShowHidden" );
2244 menu_separator( menu );
2246 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Region" );
2247 if ( g_Layout_enableDetachableMenus.m_value ) {
2248 menu_tearoff( menu_in_menu );
2250 create_menu_item_with_mnemonic( menu_in_menu, "_Off", "RegionOff" );
2251 create_menu_item_with_mnemonic( menu_in_menu, "_Set XY", "RegionSetXY" );
2252 create_menu_item_with_mnemonic( menu_in_menu, "Set _Brush", "RegionSetBrush" );
2253 create_menu_item_with_mnemonic( menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection" );
2256 command_connect_accelerator( "CenterXYView" );
2258 return view_menu_item;
2261 ui::MenuItem create_selection_menu(){
2263 auto selection_menu_item = new_sub_menu_item_with_mnemonic( "M_odify" );
2264 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( selection_menu_item ) );
2265 if ( g_Layout_enableDetachableMenus.m_value ) {
2266 menu_tearoff( menu );
2270 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Components" );
2271 if ( g_Layout_enableDetachableMenus.m_value ) {
2272 menu_tearoff( menu_in_menu );
2274 create_check_menu_item_with_mnemonic( menu_in_menu, "_Edges", "DragEdges" );
2275 create_check_menu_item_with_mnemonic( menu_in_menu, "_Vertices", "DragVertices" );
2276 create_check_menu_item_with_mnemonic( menu_in_menu, "_Faces", "DragFaces" );
2279 menu_separator( menu );
2280 create_menu_item_with_mnemonic( menu, "Snap To Grid", "SnapToGrid" );
2282 menu_separator( menu );
2285 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Nudge" );
2286 if ( g_Layout_enableDetachableMenus.m_value ) {
2287 menu_tearoff( menu_in_menu );
2289 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Left", "SelectNudgeLeft" );
2290 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Right", "SelectNudgeRight" );
2291 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Up", "SelectNudgeUp" );
2292 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Down", "SelectNudgeDown" );
2295 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Rotate" );
2296 if ( g_Layout_enableDetachableMenus.m_value ) {
2297 menu_tearoff( menu_in_menu );
2299 create_menu_item_with_mnemonic( menu_in_menu, "Rotate X", "RotateSelectionX" );
2300 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Y", "RotateSelectionY" );
2301 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Z", "RotateSelectionZ" );
2304 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Flip" );
2305 if ( g_Layout_enableDetachableMenus.m_value ) {
2306 menu_tearoff( menu_in_menu );
2308 create_menu_item_with_mnemonic( menu_in_menu, "Flip _X", "MirrorSelectionX" );
2309 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Y", "MirrorSelectionY" );
2310 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Z", "MirrorSelectionZ" );
2312 menu_separator( menu );
2313 create_menu_item_with_mnemonic( menu, "Arbitrary rotation...", "ArbitraryRotation" );
2314 create_menu_item_with_mnemonic( menu, "Arbitrary scale...", "ArbitraryScale" );
2316 return selection_menu_item;
2319 ui::MenuItem create_bsp_menu(){
2321 auto bsp_menu_item = new_sub_menu_item_with_mnemonic( "_Build" );
2322 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( bsp_menu_item ) );
2324 if ( g_Layout_enableDetachableMenus.m_value ) {
2325 menu_tearoff( menu );
2328 create_menu_item_with_mnemonic( menu, "Customize...", "BuildMenuCustomize" );
2330 menu_separator( menu );
2332 Build_constructMenu( menu );
2336 return bsp_menu_item;
2339 ui::MenuItem create_grid_menu(){
2341 auto grid_menu_item = new_sub_menu_item_with_mnemonic( "_Grid" );
2342 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( grid_menu_item ) );
2343 if ( g_Layout_enableDetachableMenus.m_value ) {
2344 menu_tearoff( menu );
2347 Grid_constructMenu( menu );
2349 return grid_menu_item;
2352 ui::MenuItem create_misc_menu(){
2354 auto misc_menu_item = new_sub_menu_item_with_mnemonic( "M_isc" );
2355 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( misc_menu_item ) );
2356 if ( g_Layout_enableDetachableMenus.m_value ) {
2357 menu_tearoff( menu );
2361 create_menu_item_with_mnemonic( menu, "_Benchmark", makeCallbackF(GlobalCamera_Benchmark) );
2363 menu.add(create_colours_menu());
2365 create_menu_item_with_mnemonic( menu, "Find brush...", "FindBrush" );
2366 create_menu_item_with_mnemonic( menu, "Map Info...", "MapInfo" );
2367 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2368 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<void(), WXY_Print>());
2369 create_menu_item_with_mnemonic( menu, "_Background select", makeCallbackF(WXY_BackgroundSelect) );
2370 return misc_menu_item;
2373 ui::MenuItem create_entity_menu(){
2375 auto entity_menu_item = new_sub_menu_item_with_mnemonic( "E_ntity" );
2376 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( entity_menu_item ) );
2377 if ( g_Layout_enableDetachableMenus.m_value ) {
2378 menu_tearoff( menu );
2381 Entity_constructMenu( menu );
2383 return entity_menu_item;
2386 ui::MenuItem create_brush_menu(){
2388 auto brush_menu_item = new_sub_menu_item_with_mnemonic( "B_rush" );
2389 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( brush_menu_item ) );
2390 if ( g_Layout_enableDetachableMenus.m_value ) {
2391 menu_tearoff( menu );
2394 Brush_constructMenu( menu );
2396 return brush_menu_item;
2399 ui::MenuItem create_patch_menu(){
2401 auto patch_menu_item = new_sub_menu_item_with_mnemonic( "_Curve" );
2402 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( patch_menu_item ) );
2403 if ( g_Layout_enableDetachableMenus.m_value ) {
2404 menu_tearoff( menu );
2407 Patch_constructMenu( menu );
2409 return patch_menu_item;
2412 ui::MenuItem create_help_menu(){
2414 auto help_menu_item = new_sub_menu_item_with_mnemonic( "_Help" );
2415 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( help_menu_item ) );
2416 if ( g_Layout_enableDetachableMenus.m_value ) {
2417 menu_tearoff( menu );
2420 // create_menu_item_with_mnemonic( menu, "Manual", "OpenManual" );
2422 // this creates all the per-game drop downs for the game pack helps
2423 // it will take care of hooking the Sys_OpenURL calls etc.
2424 create_game_help_menu( menu );
2426 create_menu_item_with_mnemonic( menu, "Bug report", makeCallbackF(OpenBugReportURL) );
2427 create_menu_item_with_mnemonic( menu, "Shortcuts list", makeCallbackF(DoCommandListDlg) );
2428 create_menu_item_with_mnemonic( menu, "_About...", makeCallbackF(DoAbout) );
2430 return help_menu_item;
2433 ui::MenuBar create_main_menu( MainFrame::EViewStyle style ){
2434 auto menu_bar = ui::MenuBar::from( gtk_menu_bar_new() );
2437 menu_bar.add(create_file_menu());
2438 menu_bar.add(create_edit_menu());
2439 menu_bar.add(create_view_menu(style));
2440 menu_bar.add(create_selection_menu());
2441 menu_bar.add(create_bsp_menu());
2442 menu_bar.add(create_grid_menu());
2443 menu_bar.add(create_misc_menu());
2444 menu_bar.add(create_entity_menu());
2445 menu_bar.add(create_brush_menu());
2446 menu_bar.add(create_patch_menu());
2447 menu_bar.add(create_plugins_menu());
2448 menu_bar.add(create_help_menu());
2454 void PatchInspector_registerShortcuts(){
2455 command_connect_accelerator( "PatchInspector" );
2458 void Patch_registerShortcuts(){
2459 command_connect_accelerator( "InvertCurveTextureX" );
2460 command_connect_accelerator( "InvertCurveTextureY" );
2461 command_connect_accelerator( "PatchInsertInsertColumn" );
2462 command_connect_accelerator( "PatchInsertInsertRow" );
2463 command_connect_accelerator( "PatchDeleteLastColumn" );
2464 command_connect_accelerator( "PatchDeleteLastRow" );
2465 command_connect_accelerator( "NaturalizePatch" );
2466 command_connect_accelerator( "CapCurrentCurve");
2469 void Manipulators_registerShortcuts(){
2470 toggle_add_accelerator( "MouseRotate" );
2471 toggle_add_accelerator( "MouseTranslate" );
2472 toggle_add_accelerator( "MouseScale" );
2473 toggle_add_accelerator( "MouseDrag" );
2474 toggle_add_accelerator( "ToggleClipper" );
2477 void TexdefNudge_registerShortcuts(){
2478 command_connect_accelerator( "TexRotateClock" );
2479 command_connect_accelerator( "TexRotateCounter" );
2480 command_connect_accelerator( "TexScaleUp" );
2481 command_connect_accelerator( "TexScaleDown" );
2482 command_connect_accelerator( "TexScaleLeft" );
2483 command_connect_accelerator( "TexScaleRight" );
2484 command_connect_accelerator( "TexShiftUp" );
2485 command_connect_accelerator( "TexShiftDown" );
2486 command_connect_accelerator( "TexShiftLeft" );
2487 command_connect_accelerator( "TexShiftRight" );
2490 void SelectNudge_registerShortcuts(){
2491 command_connect_accelerator( "MoveSelectionDOWN" );
2492 command_connect_accelerator( "MoveSelectionUP" );
2493 //command_connect_accelerator("SelectNudgeLeft");
2494 //command_connect_accelerator("SelectNudgeRight");
2495 //command_connect_accelerator("SelectNudgeUp");
2496 //command_connect_accelerator("SelectNudgeDown");
2497 command_connect_accelerator( "UnSelectSelection2" );
2498 command_connect_accelerator( "DeleteSelection2" );
2501 void SnapToGrid_registerShortcuts(){
2502 command_connect_accelerator( "SnapToGrid" );
2505 void SelectByType_registerShortcuts(){
2506 command_connect_accelerator( "SelectAllOfType" );
2509 void SurfaceInspector_registerShortcuts(){
2510 command_connect_accelerator( "FitTexture" );
2514 void register_shortcuts(){
2515 // PatchInspector_registerShortcuts();
2516 Patch_registerShortcuts();
2517 Grid_registerShortcuts();
2518 // XYWnd_registerShortcuts();
2519 CamWnd_registerShortcuts();
2520 Manipulators_registerShortcuts();
2521 SurfaceInspector_registerShortcuts();
2522 TexdefNudge_registerShortcuts();
2523 SelectNudge_registerShortcuts();
2524 // SnapToGrid_registerShortcuts();
2525 // SelectByType_registerShortcuts();
2528 void File_constructToolbar( ui::Toolbar toolbar ){
2529 toolbar_append_button( toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap" );
2530 toolbar_append_button( toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap" );
2533 void UndoRedo_constructToolbar( ui::Toolbar toolbar ){
2534 toolbar_append_button( toolbar, "Undo (CTRL + Z)", "undo.png", "Undo" );
2535 toolbar_append_button( toolbar, "Redo (CTRL + Y)", "redo.png", "Redo" );
2538 void RotateFlip_constructToolbar( ui::Toolbar toolbar ){
2539 toolbar_append_button( toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX" );
2540 toolbar_append_button( toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX" );
2541 toolbar_append_button( toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY" );
2542 toolbar_append_button( toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY" );
2543 toolbar_append_button( toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ" );
2544 toolbar_append_button( toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ" );
2547 void Select_constructToolbar( ui::Toolbar toolbar ){
2548 toolbar_append_button( toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching" );
2549 toolbar_append_button( toolbar, "Select inside", "selection_selectinside.png", "SelectInside" );
2552 void CSG_constructToolbar( ui::Toolbar toolbar ){
2553 toolbar_append_button( toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract" );
2554 toolbar_append_button( toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge" );
2555 toolbar_append_button( toolbar, "Make Hollow", "selection_makehollow.png", "CSGHollow" );
2556 toolbar_append_button( toolbar, "Make Room", "selection_makeroom.png", "CSGRoom" );
2559 void ComponentModes_constructToolbar( ui::Toolbar toolbar ){
2560 toolbar_append_toggle_button( toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices" );
2561 toolbar_append_toggle_button( toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges" );
2562 toolbar_append_toggle_button( toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces" );
2565 void Clipper_constructToolbar( ui::Toolbar toolbar ){
2567 toolbar_append_toggle_button( toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper" );
2570 void XYWnd_constructToolbar( ui::Toolbar toolbar ){
2571 toolbar_append_button( toolbar, "Change views", "view_change.png", "NextView" );
2574 void Manipulators_constructToolbar( ui::Toolbar toolbar ){
2575 toolbar_append_toggle_button( toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate" );
2576 toolbar_append_toggle_button( toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate" );
2577 toolbar_append_toggle_button( toolbar, "Scale", "select_mousescale.png", "MouseScale" );
2578 toolbar_append_toggle_button( toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag" );
2580 Clipper_constructToolbar( toolbar );
2583 ui::Toolbar create_main_toolbar( MainFrame::EViewStyle style ){
2584 auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
2585 gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL );
2586 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
2590 auto space = [&]() {
2591 auto btn = ui::ToolItem::from(gtk_separator_tool_item_new());
2596 File_constructToolbar( toolbar );
2600 UndoRedo_constructToolbar( toolbar );
2604 RotateFlip_constructToolbar( toolbar );
2608 Select_constructToolbar( toolbar );
2612 CSG_constructToolbar( toolbar );
2616 ComponentModes_constructToolbar( toolbar );
2618 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2621 XYWnd_constructToolbar( toolbar );
2626 CamWnd_constructToolbar( toolbar );
2630 Manipulators_constructToolbar( toolbar );
2632 if ( g_Layout_enablePatchToolbar.m_value ) {
2635 Patch_constructToolbar( toolbar );
2640 toolbar_append_toggle_button( toolbar, "Texture Lock (SHIFT +T)", "texture_lock.png", "TogTexLock" );
2644 /*auto g_view_entities_button =*/ toolbar_append_button( toolbar, "Entities (N)", "entities.png", "ToggleEntityInspector" );
2645 auto g_view_console_button = toolbar_append_button( toolbar, "Console (O)", "console.png", "ToggleConsole" );
2646 auto g_view_textures_button = toolbar_append_button( toolbar, "Texture Browser (T)", "texture_browser.png", "ToggleTextures" );
2647 // TODO: call light inspector
2648 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector");
2651 /*auto g_refresh_models_button =*/ toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" );
2654 // disable the console and texture button in the regular layouts
2655 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft ) {
2656 gtk_widget_set_sensitive( g_view_console_button , FALSE );
2657 gtk_widget_set_sensitive( g_view_textures_button , FALSE );
2663 ui::Widget create_main_statusbar( ui::Widget pStatusLabel[c_count_status] ){
2664 auto table = ui::Table( 1, c_count_status, FALSE );
2668 auto label = ui::Label( "Label" );
2669 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2670 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2672 table.attach(label, {0, 1, 0, 1});
2673 pStatusLabel[c_command_status] = ui::Widget(label );
2676 for (unsigned int i = 1; (int) i < c_count_status; ++i)
2678 auto frame = ui::Frame();
2680 table.attach(frame, {i, i + 1, 0, 1});
2681 gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
2683 auto label = ui::Label( "Label" );
2684 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END );
2685 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2686 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2689 pStatusLabel[i] = ui::Widget(label );
2692 return ui::Widget(table );
2698 WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" );
2700 class WindowFocusPrinter
2704 static gboolean frame_event( ui::Widget widget, GdkEvent* event, WindowFocusPrinter* self ){
2705 globalOutputStream() << self->m_name << " frame_event\n";
2708 static gboolean keys_changed( ui::Widget widget, WindowFocusPrinter* self ){
2709 globalOutputStream() << self->m_name << " keys_changed\n";
2712 static gboolean notify( ui::Window window, gpointer dummy, WindowFocusPrinter* self ){
2713 if ( gtk_window_is_active( window ) ) {
2714 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2718 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2723 WindowFocusPrinter( const char* name ) : m_name( name ){
2725 void connect( ui::Window toplevel_window ){
2726 toplevel_window.connect( "notify::has_toplevel_focus", G_CALLBACK( notify ), this );
2727 toplevel_window.connect( "notify::is_active", G_CALLBACK( notify ), this );
2728 toplevel_window.connect( "keys_changed", G_CALLBACK( keys_changed ), this );
2729 toplevel_window.connect( "frame_event", G_CALLBACK( frame_event ), this );
2733 WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" );
2737 class MainWindowActive
2739 static gboolean notify( ui::Window window, gpointer dummy, MainWindowActive* self ){
2740 if ( g_wait.m_window && gtk_window_is_active( window ) && !g_wait.m_window.visible() ) {
2741 g_wait.m_window.show();
2748 void connect( ui::Window toplevel_window ){
2749 toplevel_window.connect( "notify::is-active", G_CALLBACK( notify ), this );
2753 MainWindowActive g_MainWindowActive;
2755 SignalHandlerId XYWindowDestroyed_connect( const SignalHandler& handler ){
2756 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst( handler );
2759 void XYWindowDestroyed_disconnect( SignalHandlerId id ){
2760 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect( id );
2763 MouseEventHandlerId XYWindowMouseDown_connect( const MouseEventHandler& handler ){
2764 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst( handler );
2767 void XYWindowMouseDown_disconnect( MouseEventHandlerId id ){
2768 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect( id );
2771 // =============================================================================
2774 MainFrame* g_pParentWnd = 0;
2776 ui::Window MainFrame_getWindow()
2778 return g_pParentWnd ? g_pParentWnd->m_window : ui::Window{ui::null};
2781 std::vector<ui::Widget> g_floating_windows;
2783 MainFrame::MainFrame() : m_idleRedrawStatusText( RedrawStatusTextCaller( *this ) ){
2791 for (auto &n : m_pStatusLabel) {
2795 m_bSleeping = false;
2800 MainFrame::~MainFrame(){
2807 for ( std::vector<ui::Widget>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i )
2809 #ifndef WORKAROUND_MACOS_GTK2_DESTROY
2814 #ifndef WORKAROUND_MACOS_GTK2_DESTROY
2819 void MainFrame::SetActiveXY( XYWnd* p ){
2820 if ( m_pActiveXY ) {
2821 m_pActiveXY->SetActive( false );
2826 if ( m_pActiveXY ) {
2827 m_pActiveXY->SetActive( true );
2832 void MainFrame::ReleaseContexts(){
2835 m_pXYWnd->DestroyContext();
2838 m_pYZWnd->DestroyContext();
2841 m_pXZWnd->DestroyContext();
2844 m_pCamWnd->DestroyContext();
2847 m_pTexWnd->DestroyContext();
2850 m_pZWnd->DestroyContext();
2855 void MainFrame::CreateContexts(){
2858 m_pCamWnd->CreateContext();
2861 m_pXYWnd->CreateContext();
2864 m_pYZWnd->CreateContext();
2867 m_pXZWnd->CreateContext();
2870 m_pTexWnd->CreateContext();
2873 m_pZWnd->CreateContext();
2882 void MainFrame::OnSleep(){
2885 if ( m_bSleeping ) {
2886 // useful when trying to debug crashes in the sleep code
2887 globalOutputStream() << "Going into sleep mode..\n";
2889 globalOutputStream() << "Dispatching sleep msg...";
2890 DispatchRadiantMsg( RADIANT_SLEEP );
2891 globalOutputStream() << "Done.\n";
2893 gtk_window_iconify( m_window );
2894 GlobalSelectionSystem().setSelectedAll( false );
2896 GlobalShaderCache().unrealise();
2898 GlobalOpenGL_debugAssertNoErrors();
2899 ScreenUpdates_Disable();
2902 globalOutputStream() << "Releasing contexts...";
2904 globalOutputStream() << "Done.\n";
2908 globalOutputStream() << "Waking up\n";
2910 gtk_window_deiconify( m_window );
2913 globalOutputStream() << "Creating contexts...";
2915 globalOutputStream() << "Done.\n";
2917 globalOutputStream() << "Making current on camera...";
2918 m_pCamWnd->MakeCurrent();
2919 globalOutputStream() << "Done.\n";
2921 globalOutputStream() << "Reloading shaders...";
2923 GlobalShaderCache().realise();
2924 globalOutputStream() << "Done.\n";
2926 ScreenUpdates_Enable();
2928 globalOutputStream() << "Dispatching wake msg...";
2929 DispatchRadiantMsg( RADIANT_WAKEUP );
2930 globalOutputStream() << "Done\n";
2936 ui::Window create_splash(){
2937 auto window = ui::Window( ui::window_type::TOP );
2938 gtk_window_set_decorated(window, false);
2939 gtk_window_set_resizable(window, false);
2940 gtk_window_set_modal(window, true);
2941 gtk_window_set_default_size( window, -1, -1 );
2942 gtk_window_set_position( window, GTK_WIN_POS_CENTER );
2943 gtk_container_set_border_width(window, 0);
2945 auto image = new_local_image( "splash.png" );
2949 window.dimensions(-1, -1);
2955 static ui::Window splash_screen{ui::null};
2958 splash_screen = create_splash();
2964 splash_screen.destroy();
2967 WindowPositionTracker g_posCamWnd;
2968 WindowPositionTracker g_posXYWnd;
2969 WindowPositionTracker g_posXZWnd;
2970 WindowPositionTracker g_posYZWnd;
2972 static gint mainframe_delete( ui::Widget widget, GdkEvent *event, gpointer data ){
2973 if ( ConfirmModified( "Exit " RADIANT_NAME ) ) {
2980 PanedState g_single_hpaned = { 0.75f, -1, };
2981 PanedState g_single_vpaned = { 0.75f, -1, };
2983 void MainFrame::Create(){
2984 ui::Window window = ui::Window( ui::window_type::TOP );
2986 GlobalWindowObservers_connectTopLevel( window );
2988 gtk_window_set_transient_for( splash_screen, window );
2990 #if !GDEF_OS_WINDOWS
2992 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
2993 if ( pixbuf != 0 ) {
2994 gtk_window_set_icon( window, pixbuf );
2995 g_object_unref( pixbuf );
3000 gtk_widget_add_events( window , GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
3001 window.connect( "delete_event", G_CALLBACK( mainframe_delete ), this );
3003 m_position_tracker.connect( window );
3006 g_mainframeWidgetFocusPrinter.connect( window );
3007 g_mainframeFocusPrinter.connect( window );
3010 g_MainWindowActive.connect( window );
3012 GetPlugInMgr().Init( window );
3014 auto vbox = ui::VBox( FALSE, 0 );
3018 global_accel_connect_window( window );
3020 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
3022 register_shortcuts();
3024 auto main_menu = create_main_menu( CurrentStyle() );
3025 vbox.pack_start( main_menu, FALSE, FALSE, 0 );
3027 auto main_toolbar = create_main_toolbar( CurrentStyle() );
3028 vbox.pack_start( main_toolbar, FALSE, FALSE, 0 );
3030 if ( g_Layout_enablePluginToolbar.m_value || g_Layout_enableFilterToolbar.m_value ){
3031 auto PFbox = ui::HBox( FALSE, 3 );
3032 vbox.pack_start( PFbox, FALSE, FALSE, 0 );
3034 if ( g_Layout_enablePluginToolbar.m_value ){
3035 auto plugin_toolbar = create_plugin_toolbar();
3036 if ( g_Layout_enableFilterToolbar.m_value ){
3037 PFbox.pack_start( plugin_toolbar, FALSE, FALSE, 0 );
3040 PFbox.pack_start( plugin_toolbar, TRUE, TRUE, 0 );
3043 if ( g_Layout_enableFilterToolbar.m_value ){
3044 ui::Toolbar filter_toolbar = create_filter_toolbar();
3045 PFbox.pack_start( filter_toolbar, TRUE, TRUE, 0 );
3049 /*GtkToolbar* plugin_toolbar = create_plugin_toolbar();
3050 if ( !g_Layout_enablePluginToolbar.m_value ) {
3051 gtk_widget_hide( GTK_WIDGET( plugin_toolbar ) );
3054 ui::Widget main_statusbar = create_main_statusbar(reinterpret_cast<ui::Widget *>(m_pStatusLabel));
3055 vbox.pack_end(main_statusbar, FALSE, TRUE, 2);
3057 GroupDialog_constructWindow( window );
3058 g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) );
3060 if ( FloatingGroupDialog() ) {
3061 g_page_console = GroupDialog_addPage( "Console", Console_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Console" ) );
3065 if ( g_multimon_globals.m_bStartOnPrimMon ) {
3066 PositionWindowOnPrimaryScreen( g_layout_globals.m_position );
3067 window_set_position( window, g_layout_globals.m_position );
3071 if ( g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED ) {
3072 gtk_window_maximize( window );
3073 WindowPosition default_position( -1, -1, 640, 480 );
3074 window_set_position( window, default_position );
3078 window_set_position( window, g_layout_globals.m_position );
3085 if ( CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft )
3088 ui::Widget hsplit = ui::HPaned(ui::New);
3091 vbox.pack_start( hsplit, TRUE, TRUE, 0 );
3095 ui::Widget vsplit = ui::VPaned(ui::New);
3099 ui::Widget vsplit2 = ui::VPaned(ui::New);
3101 m_vSplit2 = vsplit2;
3103 if ( CurrentStyle() == eRegular ){
3104 gtk_paned_add1( GTK_PANED( hsplit ), vsplit );
3105 gtk_paned_add2( GTK_PANED( hsplit ), vsplit2 );
3108 gtk_paned_add2( GTK_PANED( hsplit ), vsplit );
3109 gtk_paned_add1( GTK_PANED( hsplit ), vsplit2 );
3113 ui::Widget console_window = Console_constructWindow( window );
3114 gtk_paned_pack2( GTK_PANED( vsplit ), console_window, FALSE, TRUE );
3117 m_pXYWnd = new XYWnd();
3118 m_pXYWnd->SetViewType( XY );
3119 ui::Widget xy_window = ui::Widget(create_framed_widget( m_pXYWnd->GetWidget( ) ));
3120 gtk_paned_add1( GTK_PANED( vsplit ), xy_window );
3124 m_pCamWnd = NewCamWnd();
3125 GlobalCamera_setCamWnd( *m_pCamWnd );
3126 CamWnd_setParent( *m_pCamWnd, window );
3127 auto camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3129 gtk_paned_add1( GTK_PANED( vsplit2 ), camera_window );
3132 auto texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
3134 gtk_paned_add2( GTK_PANED( vsplit2 ), texture_window );
3139 gtk_paned_set_position( GTK_PANED( m_vSplit ), g_layout_globals.nXYHeight );
3141 if ( CurrentStyle() == eRegular ) {
3142 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nXYWidth );
3146 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nCamWidth );
3149 gtk_paned_set_position( GTK_PANED( m_vSplit2 ), g_layout_globals.nCamHeight );
3151 else if ( CurrentStyle() == eFloating )
3154 ui::Window window = ui::Window(create_persistent_floating_window( "Camera", m_window ));
3155 global_accel_connect_window( window );
3156 g_posCamWnd.connect( window );
3160 m_pCamWnd = NewCamWnd();
3161 GlobalCamera_setCamWnd( *m_pCamWnd );
3164 auto frame = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3167 CamWnd_setParent( *m_pCamWnd, window );
3169 WORKAROUND_GOBJECT_SET_GLWIDGET( window, CamWnd_getWidget( *m_pCamWnd ) );
3171 g_floating_windows.push_back( window );
3175 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XY ), m_window ));
3176 global_accel_connect_window( window );
3177 g_posXYWnd.connect( window );
3179 m_pXYWnd = new XYWnd();
3180 m_pXYWnd->m_parent = window;
3181 m_pXYWnd->SetViewType( XY );
3185 auto frame = create_framed_widget( m_pXYWnd->GetWidget() );
3188 XY_Top_Shown_Construct( window );
3190 WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXYWnd->GetWidget() );
3192 g_floating_windows.push_back( window );
3196 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XZ ), m_window ));
3197 global_accel_connect_window( window );
3198 g_posXZWnd.connect( window );
3200 m_pXZWnd = new XYWnd();
3201 m_pXZWnd->m_parent = window;
3202 m_pXZWnd->SetViewType( XZ );
3205 auto frame = create_framed_widget( m_pXZWnd->GetWidget() );
3209 XZ_Front_Shown_Construct( window );
3211 WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXZWnd->GetWidget() );
3213 g_floating_windows.push_back( window );
3217 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( YZ ), m_window ));
3218 global_accel_connect_window( window );
3219 g_posYZWnd.connect( window );
3221 m_pYZWnd = new XYWnd();
3222 m_pYZWnd->m_parent = window;
3223 m_pYZWnd->SetViewType( YZ );
3226 auto frame = create_framed_widget( m_pYZWnd->GetWidget() );
3230 YZ_Side_Shown_Construct( window );
3232 WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pYZWnd->GetWidget() );
3234 g_floating_windows.push_back( window );
3238 auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
3239 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3241 WORKAROUND_GOBJECT_SET_GLWIDGET( GroupDialog_getWindow(), TextureBrowser_getGLWidget() );
3246 else if ( CurrentStyle() == eSplit )
3248 m_pCamWnd = NewCamWnd();
3249 GlobalCamera_setCamWnd( *m_pCamWnd );
3250 CamWnd_setParent( *m_pCamWnd, window );
3252 ui::Widget camera = CamWnd_getWidget( *m_pCamWnd );
3254 m_pYZWnd = new XYWnd();
3255 m_pYZWnd->SetViewType( YZ );
3257 ui::Widget yz = m_pYZWnd->GetWidget();
3259 m_pXYWnd = new XYWnd();
3260 m_pXYWnd->SetViewType( XY );
3262 ui::Widget xy = m_pXYWnd->GetWidget();
3264 m_pXZWnd = new XYWnd();
3265 m_pXZWnd->SetViewType( XZ );
3267 ui::Widget xz = m_pXZWnd->GetWidget();
3269 auto split = create_split_views( camera, yz, xy, xz );
3270 vbox.pack_start( split, TRUE, TRUE, 0 );
3273 auto frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
3274 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3276 WORKAROUND_GOBJECT_SET_GLWIDGET( window, TextureBrowser_getGLWidget() );
3279 else // single window
3281 m_pCamWnd = NewCamWnd();
3282 GlobalCamera_setCamWnd( *m_pCamWnd );
3283 CamWnd_setParent( *m_pCamWnd, window );
3285 ui::Widget camera = CamWnd_getWidget( *m_pCamWnd );
3287 m_pYZWnd = new XYWnd();
3288 m_pYZWnd->SetViewType( YZ );
3290 ui::Widget yz = m_pYZWnd->GetWidget();
3292 m_pXYWnd = new XYWnd();
3293 m_pXYWnd->SetViewType( XY );
3295 ui::Widget xy = m_pXYWnd->GetWidget();
3297 m_pXZWnd = new XYWnd();
3298 m_pXZWnd->SetViewType( XZ );
3300 ui::Widget xz = m_pXZWnd->GetWidget();
3302 ui::Widget hsplit = ui::HPaned(ui::New);
3303 vbox.pack_start( hsplit, TRUE, TRUE, 0 );
3306 ui::Widget split = create_split_views( camera, yz, xy, xz );
3308 ui::Widget vsplit = ui::VPaned(ui::New);
3312 ui::Widget texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
3315 ui::Widget console_window = create_framed_widget( Console_constructWindow( window ) );
3317 gtk_paned_add1( GTK_PANED( hsplit ), split );
3318 gtk_paned_add2( GTK_PANED( hsplit ), vsplit );
3320 gtk_paned_add1( GTK_PANED( vsplit ), texture_window );
3321 gtk_paned_add2( GTK_PANED( vsplit ), console_window );
3323 hsplit.connect( "size_allocate", G_CALLBACK( hpaned_allocate ), &g_single_hpaned );
3324 hsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_single_hpaned );
3326 vsplit.connect( "size_allocate", G_CALLBACK( vpaned_allocate ), &g_single_vpaned );
3327 vsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_single_vpaned );
3330 EntityList_constructWindow( window );
3331 PreferencesDialog_constructWindow( window );
3332 FindTextureDialog_constructWindow( window );
3333 SurfaceInspector_constructWindow( window );
3334 PatchInspector_constructWindow( window );
3336 SetActiveXY( m_pXYWnd );
3338 AddGridChangeCallback( SetGridStatusCaller( *this ) );
3339 AddGridChangeCallback( ReferenceCaller<MainFrame, void(), XY_UpdateAllWindows>( *this ) );
3341 g_defaultToolMode = DragMode;
3342 g_defaultToolMode();
3343 SetStatusText( m_command_status, c_TranslateMode_status );
3345 EverySecondTimer_enable();
3347 //GlobalShortcuts_reportUnregistered();
3350 void MainFrame::SaveWindowInfo(){
3351 if ( !FloatingGroupDialog() ) {
3352 g_layout_globals.nXYHeight = gtk_paned_get_position( GTK_PANED( m_vSplit ) );
3354 if ( CurrentStyle() != eRegular ) {
3355 g_layout_globals.nCamWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3359 g_layout_globals.nXYWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3362 g_layout_globals.nCamHeight = gtk_paned_get_position( GTK_PANED( m_vSplit2 ) );
3365 g_layout_globals.m_position = m_position_tracker.getPosition();
3367 g_layout_globals.nState = gdk_window_get_state( gtk_widget_get_window(m_window ) );
3370 void MainFrame::Shutdown(){
3371 EverySecondTimer_disable();
3373 EntityList_destroyWindow();
3382 TextureBrowser_destroyWindow();
3384 DeleteCamWnd( m_pCamWnd );
3387 PreferencesDialog_destroyWindow();
3388 SurfaceInspector_destroyWindow();
3389 FindTextureDialog_destroyWindow();
3390 PatchInspector_destroyWindow();
3392 g_DbgDlg.destroyWindow();
3394 // destroying group-dialog last because it may contain texture-browser
3395 GroupDialog_destroyWindow();
3398 void MainFrame::RedrawStatusText(){
3399 ui::Label::from(m_pStatusLabel[c_command_status]).text(m_command_status.c_str());
3400 ui::Label::from(m_pStatusLabel[c_position_status]).text(m_position_status.c_str());
3401 ui::Label::from(m_pStatusLabel[c_brushcount_status]).text(m_brushcount_status.c_str());
3402 ui::Label::from(m_pStatusLabel[c_texture_status]).text(m_texture_status.c_str());
3403 ui::Label::from(m_pStatusLabel[c_grid_status]).text(m_grid_status.c_str());
3406 void MainFrame::UpdateStatusText(){
3407 m_idleRedrawStatusText.queueDraw();
3410 void MainFrame::SetStatusText( CopiedString& status_text, const char* pText ){
3411 status_text = pText;
3415 void Sys_Status( const char* status ){
3416 if ( g_pParentWnd != nullptr ) {
3417 g_pParentWnd->SetStatusText( g_pParentWnd->m_command_status, status );
3421 int getRotateIncrement(){
3422 return static_cast<int>( g_si_globals.rotate );
3425 int getFarClipDistance(){
3426 return g_camwindow_globals.m_nCubicScale;
3429 float ( *GridStatus_getGridSize )() = GetGridSize;
3431 int ( *GridStatus_getRotateIncrement )() = getRotateIncrement;
3433 int ( *GridStatus_getFarClipDistance )() = getFarClipDistance;
3435 bool ( *GridStatus_getTextureLockEnabled )();
3437 void MainFrame::SetGridStatus(){
3438 StringOutputStream status( 64 );
3439 const char* lock = ( GridStatus_getTextureLockEnabled() ) ? "ON" : "OFF";
3440 status << ( GetSnapGridSize() > 0 ? "G:" : "g:" ) << GridStatus_getGridSize()
3441 << " R:" << GridStatus_getRotateIncrement()
3442 << " C:" << GridStatus_getFarClipDistance()
3444 SetStatusText( m_grid_status, status.c_str() );
3447 void GridStatus_onTextureLockEnabledChanged(){
3448 if ( g_pParentWnd != nullptr ) {
3449 g_pParentWnd->SetGridStatus();
3453 void GlobalGL_sharedContextCreated(){
3454 GLFont *g_font = NULL;
3456 // report OpenGL information
3457 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) << "\n";
3458 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) << "\n";
3459 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) << "\n";
3460 const auto extensions = reinterpret_cast<const char*>( glGetString(GL_EXTENSIONS ) );
3461 globalOutputStream() << "GL_EXTENSIONS: " << (extensions ? extensions : "") << "\n";
3463 QGL_sharedContextCreated( GlobalOpenGL() );
3465 ShaderCache_extensionsInitialised();
3467 GlobalShaderCache().realise();
3471 /* win32 is dodgy here, just use courier new then */
3472 g_font = glfont_create( "arial 9" );
3474 auto settings = gtk_settings_get_default();
3476 g_object_get( settings, "gtk-font-name", &fontname, NULL );
3477 g_font = glfont_create( fontname );
3480 GlobalOpenGL().m_font = g_font;
3483 void GlobalGL_sharedContextDestroyed(){
3484 Textures_Unrealise();
3485 GlobalShaderCache().unrealise();
3487 QGL_sharedContextDestroyed( GlobalOpenGL() );
3491 void Layout_constructPreferences( PreferencesPage& page ){
3493 const char* layouts[] = { "window1.png", "window2.png", "window3.png", "window4.png", "window5.png" };
3494 page.appendRadioIcons(
3496 STRING_ARRAY_RANGE( layouts ),
3497 make_property( g_Layout_viewStyle )
3500 page.appendCheckBox(
3501 "", "Detachable Menus",
3502 make_property( g_Layout_enableDetachableMenus )
3504 if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) {
3505 page.appendCheckBox(
3506 "", "Patch Toolbar",
3507 make_property( g_Layout_enablePatchToolbar )
3510 page.appendCheckBox(
3511 "", "Plugin Toolbar",
3512 make_property( g_Layout_enablePluginToolbar )
3514 page.appendCheckBox(
3515 "", "Filter Toolbar",
3516 make_property( g_Layout_enableFilterToolbar )
3520 void Layout_constructPage( PreferenceGroup& group ){
3521 PreferencesPage page( group.createPage( "Layout", "Layout Preferences" ) );
3522 Layout_constructPreferences( page );
3525 void Layout_registerPreferencesPage(){
3526 PreferencesDialog_addInterfacePage( makeCallbackF(Layout_constructPage) );
3529 #include "preferencesystem.h"
3530 #include "stringio.h"
3531 #include "transformpath/transformpath.h"
3533 void MainFrame_Construct(){
3534 GlobalCommands_insert( "OpenManual", makeCallbackF(OpenHelpURL), Accelerator( GDK_KEY_F1 ) );
3536 GlobalCommands_insert( "Sleep", makeCallbackF(thunk_OnSleep), Accelerator( 'P', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3537 GlobalCommands_insert( "NewMap", makeCallbackF(NewMap) );
3538 GlobalCommands_insert( "OpenMap", makeCallbackF(OpenMap), Accelerator( 'O', (GdkModifierType)GDK_CONTROL_MASK ) );
3539 GlobalCommands_insert( "ImportMap", makeCallbackF(ImportMap) );
3540 GlobalCommands_insert( "SaveMap", makeCallbackF(SaveMap), Accelerator( 'S', (GdkModifierType)GDK_CONTROL_MASK ) );
3541 GlobalCommands_insert( "SaveMapAs", makeCallbackF(SaveMapAs) );
3542 GlobalCommands_insert( "ExportSelected", makeCallbackF(ExportMap) );
3543 GlobalCommands_insert( "SaveRegion", makeCallbackF(SaveRegion) );
3544 GlobalCommands_insert( "RefreshReferences", makeCallbackF(VFS_Refresh) );
3545 GlobalCommands_insert( "ProjectSettings", makeCallbackF(DoProjectSettings) );
3546 GlobalCommands_insert( "Exit", makeCallbackF(Exit) );
3548 GlobalCommands_insert( "Undo", makeCallbackF(Undo), Accelerator( 'Z', (GdkModifierType)GDK_CONTROL_MASK ) );
3549 GlobalCommands_insert( "Redo", makeCallbackF(Redo), Accelerator( 'Y', (GdkModifierType)GDK_CONTROL_MASK ) );
3550 GlobalCommands_insert( "Copy", makeCallbackF(Copy), Accelerator( 'C', (GdkModifierType)GDK_CONTROL_MASK ) );
3551 GlobalCommands_insert( "Paste", makeCallbackF(Paste), Accelerator( 'V', (GdkModifierType)GDK_CONTROL_MASK ) );
3552 GlobalCommands_insert( "PasteToCamera", makeCallbackF(PasteToCamera), Accelerator( 'V', (GdkModifierType)GDK_MOD1_MASK ) );
3553 GlobalCommands_insert( "CloneSelection", makeCallbackF(Selection_Clone), Accelerator( GDK_KEY_space ) );
3554 GlobalCommands_insert( "CloneSelectionAndMakeUnique", makeCallbackF(Selection_Clone_MakeUnique), Accelerator( GDK_KEY_space, (GdkModifierType)GDK_SHIFT_MASK ) );
3555 // GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) );
3556 GlobalCommands_insert( "DeleteSelection2", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) );
3557 GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( 'Z' ) );
3558 GlobalCommands_insert( "ParentSelection", makeCallbackF(Scene_parentSelected) );
3559 // GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) );
3560 GlobalCommands_insert( "UnSelectSelection2", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) );
3561 GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( 'C' ) );
3562 GlobalCommands_insert( "InvertSelection", makeCallbackF(Select_Invert), Accelerator( 'I' ) );
3563 GlobalCommands_insert( "SelectInside", makeCallbackF(Select_Inside) );
3564 GlobalCommands_insert( "SelectTouching", makeCallbackF(Select_Touching) );
3565 GlobalCommands_insert( "ExpandSelectionToEntities", makeCallbackF(Scene_ExpandSelectionToEntities), Accelerator( 'E', (GdkModifierType)( GDK_MOD1_MASK | GDK_CONTROL_MASK ) ) );
3566 GlobalCommands_insert( "Preferences", makeCallbackF(PreferencesDialog_showDialog), Accelerator( 'P' ) );
3568 GlobalCommands_insert( "ToggleConsole", makeCallbackF(Console_ToggleShow), Accelerator( 'O' ) );
3569 GlobalCommands_insert( "ToggleEntityInspector", makeCallbackF(EntityInspector_ToggleShow), Accelerator( 'N' ) );
3570 GlobalCommands_insert( "EntityList", makeCallbackF(EntityList_toggleShown), Accelerator( 'L' ) );
3572 GlobalCommands_insert( "ShowHidden", makeCallbackF(Select_ShowAllHidden), Accelerator( 'H', (GdkModifierType)GDK_SHIFT_MASK ) );
3573 GlobalCommands_insert( "HideSelected", makeCallbackF(HideSelected), Accelerator( 'H' ) );
3575 GlobalToggles_insert( "DragVertices", makeCallbackF(SelectVertexMode), ToggleItem::AddCallbackCaller( g_vertexMode_button ), Accelerator( 'V' ) );
3576 GlobalToggles_insert( "DragEdges", makeCallbackF(SelectEdgeMode), ToggleItem::AddCallbackCaller( g_edgeMode_button ), Accelerator( 'E' ) );
3577 GlobalToggles_insert( "DragFaces", makeCallbackF(SelectFaceMode), ToggleItem::AddCallbackCaller( g_faceMode_button ), Accelerator( 'F' ) );
3579 GlobalCommands_insert( "MirrorSelectionX", makeCallbackF(Selection_Flipx) );
3580 GlobalCommands_insert( "RotateSelectionX", makeCallbackF(Selection_Rotatex) );
3581 GlobalCommands_insert( "MirrorSelectionY", makeCallbackF(Selection_Flipy) );
3582 GlobalCommands_insert( "RotateSelectionY", makeCallbackF(Selection_Rotatey) );
3583 GlobalCommands_insert( "MirrorSelectionZ", makeCallbackF(Selection_Flipz) );
3584 GlobalCommands_insert( "RotateSelectionZ", makeCallbackF(Selection_Rotatez) );
3586 GlobalCommands_insert( "ArbitraryRotation", makeCallbackF(DoRotateDlg) );
3587 GlobalCommands_insert( "ArbitraryScale", makeCallbackF(DoScaleDlg) );
3589 GlobalCommands_insert( "BuildMenuCustomize", makeCallbackF(DoBuildMenu) );
3591 GlobalCommands_insert( "FindBrush", makeCallbackF(DoFind) );
3593 GlobalCommands_insert( "MapInfo", makeCallbackF(DoMapInfo), Accelerator( 'M' ) );
3596 GlobalToggles_insert( "ToggleClipper", makeCallbackF(ClipperMode), ToggleItem::AddCallbackCaller( g_clipper_button ), Accelerator( 'X' ) );
3598 GlobalToggles_insert( "MouseTranslate", makeCallbackF(TranslateMode), ToggleItem::AddCallbackCaller( g_translatemode_button ), Accelerator( 'W' ) );
3599 GlobalToggles_insert( "MouseRotate", makeCallbackF(RotateMode), ToggleItem::AddCallbackCaller( g_rotatemode_button ), Accelerator( 'R' ) );
3600 GlobalToggles_insert( "MouseScale", makeCallbackF(ScaleMode), ToggleItem::AddCallbackCaller( g_scalemode_button ) );
3601 GlobalToggles_insert( "MouseDrag", makeCallbackF(DragMode), ToggleItem::AddCallbackCaller( g_dragmode_button ), Accelerator( 'Q' ) );
3603 #ifndef GARUX_DISABLE_GTKTHEME
3604 GlobalCommands_insert( "gtkThemeDlg", makeCallbackF(gtkThemeDlg) );
3606 GlobalCommands_insert( "ColorSchemeOriginal", makeCallbackF(ColorScheme_Original) );
3607 GlobalCommands_insert( "ColorSchemeQER", makeCallbackF(ColorScheme_QER) );
3608 GlobalCommands_insert( "ColorSchemeBlackAndGreen", makeCallbackF(ColorScheme_Black) );
3609 GlobalCommands_insert( "ColorSchemeYdnar", makeCallbackF(ColorScheme_Ydnar) );
3610 GlobalCommands_insert("ColorSchemeAdwaitaDark", makeCallbackF(ColorScheme_AdwaitaDark));
3611 GlobalCommands_insert( "ChooseTextureBackgroundColor", makeCallback( g_ColoursMenu.m_textureback ) );
3612 GlobalCommands_insert( "ChooseGridBackgroundColor", makeCallback( g_ColoursMenu.m_xyback ) );
3613 GlobalCommands_insert( "ChooseGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor ) );
3614 GlobalCommands_insert( "ChooseGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor ) );
3615 GlobalCommands_insert( "ChooseSmallGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor_alt ) );
3616 GlobalCommands_insert( "ChooseSmallGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor_alt ) );
3617 GlobalCommands_insert( "ChooseGridTextColor", makeCallback( g_ColoursMenu.m_gridtext ) );
3618 GlobalCommands_insert( "ChooseGridBlockColor", makeCallback( g_ColoursMenu.m_gridblock ) );
3619 GlobalCommands_insert( "ChooseBrushColor", makeCallback( g_ColoursMenu.m_brush ) );
3620 GlobalCommands_insert( "ChooseCameraBackgroundColor", makeCallback( g_ColoursMenu.m_cameraback ) );
3621 GlobalCommands_insert( "ChooseSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush ) );
3622 GlobalCommands_insert( "ChooseCameraSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush3d ) );
3623 GlobalCommands_insert( "ChooseClipperColor", makeCallback( g_ColoursMenu.m_clipper ) );
3624 GlobalCommands_insert( "ChooseOrthoViewNameColor", makeCallback( g_ColoursMenu.m_viewname ) );
3627 GlobalCommands_insert( "CSGSubtract", makeCallbackF(CSG_Subtract), Accelerator( 'U', (GdkModifierType)GDK_SHIFT_MASK ) );
3628 GlobalCommands_insert( "CSGMerge", makeCallbackF(CSG_Merge), Accelerator( 'U', (GdkModifierType) GDK_CONTROL_MASK ) );
3629 GlobalCommands_insert( "CSGHollow", makeCallbackF(CSG_MakeHollow) );
3630 GlobalCommands_insert( "CSGRoom", makeCallbackF(CSG_MakeRoom) );
3632 Grid_registerCommands();
3634 GlobalCommands_insert( "SnapToGrid", makeCallbackF(Selection_SnapToGrid), Accelerator( 'G', (GdkModifierType)GDK_CONTROL_MASK ) );
3636 GlobalCommands_insert( "SelectAllOfType", makeCallbackF(Select_AllOfType), Accelerator( 'A', (GdkModifierType)GDK_SHIFT_MASK ) );
3638 GlobalCommands_insert( "TexRotateClock", makeCallbackF(Texdef_RotateClockwise), Accelerator( GDK_KEY_Next, (GdkModifierType)GDK_SHIFT_MASK ) );
3639 GlobalCommands_insert( "TexRotateCounter", makeCallbackF(Texdef_RotateAntiClockwise), Accelerator( GDK_KEY_Prior, (GdkModifierType)GDK_SHIFT_MASK ) );
3640 GlobalCommands_insert( "TexScaleUp", makeCallbackF(Texdef_ScaleUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_CONTROL_MASK ) );
3641 GlobalCommands_insert( "TexScaleDown", makeCallbackF(Texdef_ScaleDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_CONTROL_MASK ) );
3642 GlobalCommands_insert( "TexScaleLeft", makeCallbackF(Texdef_ScaleLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_CONTROL_MASK ) );
3643 GlobalCommands_insert( "TexScaleRight", makeCallbackF(Texdef_ScaleRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_CONTROL_MASK ) );
3644 GlobalCommands_insert( "TexShiftUp", makeCallbackF(Texdef_ShiftUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_SHIFT_MASK ) );
3645 GlobalCommands_insert( "TexShiftDown", makeCallbackF(Texdef_ShiftDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_SHIFT_MASK ) );
3646 GlobalCommands_insert( "TexShiftLeft", makeCallbackF(Texdef_ShiftLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_SHIFT_MASK ) );
3647 GlobalCommands_insert( "TexShiftRight", makeCallbackF(Texdef_ShiftRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_SHIFT_MASK ) );
3649 GlobalCommands_insert( "MoveSelectionDOWN", makeCallbackF(Selection_MoveDown), Accelerator( GDK_KEY_KP_Subtract ) );
3650 GlobalCommands_insert( "MoveSelectionUP", makeCallbackF(Selection_MoveUp), Accelerator( GDK_KEY_KP_Add ) );
3652 GlobalCommands_insert( "SelectNudgeLeft", makeCallbackF(Selection_NudgeLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_MOD1_MASK ) );
3653 GlobalCommands_insert( "SelectNudgeRight", makeCallbackF(Selection_NudgeRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_MOD1_MASK ) );
3654 GlobalCommands_insert( "SelectNudgeUp", makeCallbackF(Selection_NudgeUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_MOD1_MASK ) );
3655 GlobalCommands_insert( "SelectNudgeDown", makeCallbackF(Selection_NudgeDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_MOD1_MASK ) );
3657 Patch_registerCommands();
3658 XYShow_registerCommands();
3660 typedef FreeCaller<void(const Selectable&), ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3661 GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() );
3663 GlobalPreferenceSystem().registerPreference( "DetachableMenus", make_property_string( g_Layout_enableDetachableMenus.m_latched ) );
3664 GlobalPreferenceSystem().registerPreference( "PatchToolBar", make_property_string( g_Layout_enablePatchToolbar.m_latched ) );
3665 GlobalPreferenceSystem().registerPreference( "PluginToolBar", make_property_string( g_Layout_enablePluginToolbar.m_latched ) );
3666 GlobalPreferenceSystem().registerPreference( "FilterToolBar", make_property_string( g_Layout_enableFilterToolbar.m_latched ) );
3667 GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", make_property_string( g_Layout_viewStyle.m_latched ) );
3668 GlobalPreferenceSystem().registerPreference( "XYHeight", make_property_string( g_layout_globals.nXYHeight ) );
3669 GlobalPreferenceSystem().registerPreference( "XYWidth", make_property_string( g_layout_globals.nXYWidth ) );
3670 GlobalPreferenceSystem().registerPreference( "CamWidth", make_property_string( g_layout_globals.nCamWidth ) );
3671 GlobalPreferenceSystem().registerPreference( "CamHeight", make_property_string( g_layout_globals.nCamHeight ) );
3673 GlobalPreferenceSystem().registerPreference( "State", make_property_string( g_layout_globals.nState ) );
3674 GlobalPreferenceSystem().registerPreference( "PositionX", make_property_string( g_layout_globals.m_position.x ) );
3675 GlobalPreferenceSystem().registerPreference( "PositionY", make_property_string( g_layout_globals.m_position.y ) );
3676 GlobalPreferenceSystem().registerPreference( "Width", make_property_string( g_layout_globals.m_position.w ) );
3677 GlobalPreferenceSystem().registerPreference( "Height", make_property_string( g_layout_globals.m_position.h ) );
3679 GlobalPreferenceSystem().registerPreference( "CamWnd", make_property<WindowPositionTracker_String>(g_posCamWnd) );
3680 GlobalPreferenceSystem().registerPreference( "XYWnd", make_property<WindowPositionTracker_String>(g_posXYWnd) );
3681 GlobalPreferenceSystem().registerPreference( "YZWnd", make_property<WindowPositionTracker_String>(g_posYZWnd) );
3682 GlobalPreferenceSystem().registerPreference( "XZWnd", make_property<WindowPositionTracker_String>(g_posXZWnd) );
3684 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3685 if ( g_strEnginePath.empty() )
3687 g_strEnginePath_was_empty_1st_start = true;
3688 const char* ENGINEPATH_ATTRIBUTE =
3693 #elif GDEF_OS_LINUX || GDEF_OS_BSD
3696 #error "unknown platform"
3700 StringOutputStream path( 256 );
3701 path << DirectoryCleaned( g_pGameDescription->getRequiredKeyValue( ENGINEPATH_ATTRIBUTE ) );
3703 g_strEnginePath = transformPath( path.c_str() ).c_str();
3704 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3707 GlobalPreferenceSystem().registerPreference( "DisableEnginePath", make_property_string( g_disableEnginePath ) );
3708 GlobalPreferenceSystem().registerPreference( "DisableHomePath", make_property_string( g_disableHomePath ) );
3710 for ( int i = 0; i < g_pakPathCount; i++ ) {
3711 std::string label = "PakPath" + std::to_string( i );
3712 GlobalPreferenceSystem().registerPreference( label.c_str(), make_property_string( g_strPakPath[i] ) );
3715 g_Layout_viewStyle.useLatched();
3716 g_Layout_enableDetachableMenus.useLatched();
3717 g_Layout_enablePatchToolbar.useLatched();
3718 g_Layout_enablePluginToolbar.useLatched();
3719 g_Layout_enableFilterToolbar.useLatched();
3721 Layout_registerPreferencesPage();
3722 Paths_registerPreferencesPage();
3724 g_brushCount.setCountChangedCallback( makeCallbackF(QE_brushCountChanged) );
3725 g_entityCount.setCountChangedCallback( makeCallbackF(QE_entityCountChanged) );
3726 GlobalEntityCreator().setCounter( &g_entityCount );
3728 glwidget_set_shared_context_constructors( GlobalGL_sharedContextCreated, GlobalGL_sharedContextDestroyed);
3730 GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver );
3733 void MainFrame_Destroy(){
3734 GlobalEntityClassManager().detach( g_WorldspawnColourEntityClassObserver );
3736 GlobalEntityCreator().setCounter( 0 );
3737 g_entityCount.setCountChangedCallback( Callback<void()>() );
3738 g_brushCount.setCountChangedCallback( Callback<void()>() );
3742 void GLWindow_Construct(){
3743 GlobalPreferenceSystem().registerPreference( "MouseButtons", make_property_string( g_glwindow_globals.m_nMouseType ) );
3746 void GLWindow_Destroy(){
3749 /* HACK: If ui::main is not called yet,
3750 gtk_main_quit will not quit, so tell main
3751 to not call ui::main. This happens when a
3752 map is loaded from command line and require
3753 a restart because of wrong format.
3754 Delete this when the code to not have to
3755 restart to load another format is merged. */
3756 extern bool g_dontStart;
3758 void Radiant_Restart(){
3759 // preferences are expected to be already saved in any way
3760 // this is just to be sure and be future proof
3763 // this asks user for saving if map is modified
3764 // user can chose to not save, it's ok
3765 ConfirmModified( "Restart " RADIANT_NAME );
3770 char exe_file[ 256 ];
3771 char map_file[ 256 ];
3772 bool with_map = false;
3774 strncpy( exe_file, g_strAppFilePath.c_str(), 256 );
3776 if ( !Map_Unnamed( g_map ) ) {
3777 strncpy( map_file, Map_Name( g_map ), 256 );
3781 argv[ 0 ] = exe_file;
3782 argv[ 1 ] = with_map ? map_file : NULL;
3786 status = !_spawnvpe( P_NOWAIT, exe_file, argv, environ );
3790 status = posix_spawn( &pid, exe_file, NULL, NULL, argv, environ );
3793 // quit if radiant successfully started
3794 if ( status == 0 ) {
3796 /* HACK: If ui::main is not called yet,
3797 gtk_main_quit will not quit, so tell main
3798 to not call ui::main. This happens when a
3799 map is loaded from command line and require
3800 a restart because of wrong format.
3801 Delete this when the code to not have to
3802 restart to load another format is merged. */