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"
110 #ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
111 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
112 #define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget) g_object_set_data( G_OBJECT( window ), "glwidget", G_OBJECT( widget ) )
114 #define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget)
117 struct layout_globals_t
119 WindowPosition m_position;
129 m_position( -1, -1, 640, 480 ),
135 nState( GDK_WINDOW_STATE_MAXIMIZED ){
139 layout_globals_t g_layout_globals;
140 glwindow_globals_t g_glwindow_globals;
145 bool g_vfsInitialized = false;
148 if ( g_vfsInitialized ) return;
150 GlobalFileSystem().initialise();
151 g_vfsInitialized = true;
155 if ( !g_vfsInitialized ) return;
156 GlobalFileSystem().shutdown();
157 g_vfsInitialized = false;
161 if ( !g_vfsInitialized ) return;
162 GlobalFileSystem().clear();
164 GlobalFileSystem().refresh();
165 g_vfsInitialized = true;
166 // also refresh models
168 // also refresh texture browser
169 TextureBrowser_RefreshShaders();
170 // also show textures (all or common)
171 TextureBrowser_ShowStartupShaders( GlobalTextureBrowser() );
179 class VFSModuleObserver : public ModuleObserver
191 VFSModuleObserver g_VFSModuleObserver;
193 void VFS_Construct(){
194 Radiant_attachHomePathsObserver( g_VFSModuleObserver );
198 Radiant_detachHomePathsObserver( g_VFSModuleObserver );
206 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
207 #define qREFKNOWNFOLDERID GUID
208 #define qKF_FLAG_CREATE 0x8000
209 #define qKF_FLAG_NO_ALIAS 0x1000
210 typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath );
211 static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath;
214 void HomePaths_Realise(){
217 const char* prefix = g_pGameDescription->getKeyValue( "prefix" );
218 if ( !string_empty( prefix ) ) {
219 StringOutputStream path( 256 );
223 path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/";
224 if ( file_is_directory( path.c_str() ) ) {
225 g_qeglobals.m_userEnginePath = path.c_str();
229 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
230 #elif GDEF_OS_WINDOWS
231 TCHAR mydocsdir[MAX_PATH + 1];
233 HMODULE shfolder = LoadLibrary( "shfolder.dll" );
235 qSHGetKnownFolderPath = (qSHGetKnownFolderPath_t *) GetProcAddress( shfolder, "SHGetKnownFolderPath" );
238 qSHGetKnownFolderPath = NULL;
240 CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
241 if ( qSHGetKnownFolderPath && qSHGetKnownFolderPath( qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw ) == S_OK ) {
242 memset( mydocsdir, 0, sizeof( mydocsdir ) );
243 wcstombs( mydocsdir, mydocsdirw, sizeof( mydocsdir ) - 1 );
244 CoTaskMemFree( mydocsdirw );
246 path << DirectoryCleaned( mydocsdir ) << ( prefix + 1 ) << "/";
247 if ( file_is_directory( path.c_str() ) ) {
248 g_qeglobals.m_userEnginePath = path.c_str();
250 FreeLibrary( shfolder );
256 FreeLibrary( shfolder );
258 if ( SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir ) ) {
260 path << DirectoryCleaned( mydocsdir ) << "My Games/" << ( prefix + 1 ) << "/";
261 // win32: only add it if it already exists
262 if ( file_is_directory( path.c_str() ) ) {
263 g_qeglobals.m_userEnginePath = path.c_str();
269 path << DirectoryCleaned( g_get_user_data_dir() ) << ( prefix + 1 ) << "/";
270 if ( file_exists( path.c_str() ) && file_is_directory( path.c_str() ) ) {
271 g_qeglobals.m_userEnginePath = path.c_str();
276 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
277 g_qeglobals.m_userEnginePath = path.c_str();
283 g_qeglobals.m_userEnginePath = EnginePath_get();
287 Q_mkdir( g_qeglobals.m_userEnginePath.c_str() );
290 StringOutputStream path( 256 );
291 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
292 g_qeglobals.m_userGamePath = path.c_str();
294 ASSERT_MESSAGE( !string_empty( g_qeglobals.m_userGamePath.c_str() ), "HomePaths_Realise: user-game-path is empty" );
295 Q_mkdir( g_qeglobals.m_userGamePath.c_str() );
298 ModuleObservers g_homePathObservers;
300 void Radiant_attachHomePathsObserver( ModuleObserver& observer ){
301 g_homePathObservers.attach( observer );
304 void Radiant_detachHomePathsObserver( ModuleObserver& observer ){
305 g_homePathObservers.detach( observer );
308 class HomePathsModuleObserver : public ModuleObserver
310 std::size_t m_unrealised;
312 HomePathsModuleObserver() : m_unrealised( 1 ){
316 if ( --m_unrealised == 0 ) {
318 g_homePathObservers.realise();
323 if ( ++m_unrealised == 1 ) {
324 g_homePathObservers.unrealise();
329 HomePathsModuleObserver g_HomePathsModuleObserver;
331 void HomePaths_Construct(){
332 Radiant_attachEnginePathObserver( g_HomePathsModuleObserver );
335 void HomePaths_Destroy(){
336 Radiant_detachEnginePathObserver( g_HomePathsModuleObserver );
342 CopiedString g_strEnginePath;
343 ModuleObservers g_enginePathObservers;
344 std::size_t g_enginepath_unrealised = 1;
346 void Radiant_attachEnginePathObserver( ModuleObserver& observer ){
347 g_enginePathObservers.attach( observer );
350 void Radiant_detachEnginePathObserver( ModuleObserver& observer ){
351 g_enginePathObservers.detach( observer );
355 void EnginePath_Realise(){
356 if ( --g_enginepath_unrealised == 0 ) {
357 g_enginePathObservers.realise();
362 const char* EnginePath_get(){
363 ASSERT_MESSAGE( g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised" );
364 return g_strEnginePath.c_str();
367 void EnginePath_Unrealise(){
368 if ( ++g_enginepath_unrealised == 1 ) {
369 g_enginePathObservers.unrealise();
373 void setEnginePath( const char* path ){
374 StringOutputStream buffer( 256 );
375 buffer << DirectoryCleaned( path );
376 if ( !path_equal( buffer.c_str(), g_strEnginePath.c_str() ) ) {
378 while ( !ConfirmModified( "Paths Changed" ) )
380 if ( Map_Unnamed( g_map ) ) {
391 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Changing Engine Path" );
393 EnginePath_Unrealise();
395 g_strEnginePath = buffer.c_str();
397 EnginePath_Realise();
403 CopiedString g_strPakPath[g_pakPathCount] = { "", "", "", "", "" };
404 ModuleObservers g_pakPathObservers[g_pakPathCount];
405 std::size_t g_pakpath_unrealised[g_pakPathCount] = { 1, 1, 1, 1, 1 };
407 void Radiant_attachPakPathObserver( int num, ModuleObserver& observer ){
408 g_pakPathObservers[num].attach( observer );
411 void Radiant_detachPakPathObserver( int num, ModuleObserver& observer ){
412 g_pakPathObservers[num].detach( observer );
416 void PakPath_Realise( int num ){
417 if ( --g_pakpath_unrealised[num] == 0 ) {
418 g_pakPathObservers[num].realise();
422 const char* PakPath_get( int num ){
423 std::string message = "PakPath_get: pak path " + std::to_string(num) + " not realised";
424 ASSERT_MESSAGE( g_pakpath_unrealised[num] == 0, message.c_str() );
425 return g_strPakPath[num].c_str();
428 void PakPath_Unrealise( int num ){
429 if ( ++g_pakpath_unrealised[num] == 1 ) {
430 g_pakPathObservers[num].unrealise();
434 void setPakPath( int num, const char* path ){
435 if (!g_strcmp0( path, "")) {
436 g_strPakPath[num] = "";
440 StringOutputStream buffer( 256 );
441 buffer << DirectoryCleaned( path );
442 if ( !path_equal( buffer.c_str(), g_strPakPath[num].c_str() ) ) {
443 std::string message = "Changing Pak Path " + std::to_string(num);
444 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", message.c_str() );
446 PakPath_Unrealise(num);
448 g_strPakPath[num] = buffer.c_str();
450 PakPath_Realise(num);
455 // executable file path (full path)
456 CopiedString g_strAppFilePath;
459 CopiedString g_strAppPath;
460 CopiedString g_strLibPath;
461 CopiedString g_strDataPath;
463 const char* AppFilePath_get(){
464 return g_strAppFilePath.c_str();
467 const char* AppPath_get(){
468 return g_strAppPath.c_str();
471 const char *LibPath_get()
473 return g_strLibPath.c_str();
476 const char *DataPath_get()
478 return g_strDataPath.c_str();
481 /// the path to the local rc-dir
482 const char* LocalRcPath_get( void ){
483 static CopiedString rc_path;
484 if ( rc_path.empty() ) {
485 StringOutputStream stream( 256 );
486 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
487 rc_path = stream.c_str();
489 return rc_path.c_str();
492 /// directory for temp files
493 /// NOTE: on *nix this is were we check for .pid
494 CopiedString g_strSettingsPath;
496 const char* SettingsPath_get(){
497 return g_strSettingsPath.c_str();
502 points to the game tools directory, for instance
503 C:/Program Files/Quake III Arena/GtkRadiant
505 this is one of the main variables that are configured by the game selection on startup
506 [GameToolsPath]/plugins
507 [GameToolsPath]/modules
510 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
512 const char* GameToolsPath_get(){
513 return g_strGameToolsPath.c_str();
517 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz) {
518 returnz(self.c_str());
521 static void Import(CopiedString &self, const char *value) {
522 setEnginePath( value );
527 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
528 returnz( self.c_str() );
531 static void Import( CopiedString &self, const char *value ) {
532 setPakPath( 0, value );
537 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
538 returnz( self.c_str() );
541 static void Import( CopiedString &self, const char *value ) {
542 setPakPath( 1, value );
547 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
548 returnz( self.c_str() );
551 static void Import( CopiedString &self, const char *value ) {
552 setPakPath( 2, value );
557 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
558 returnz( self.c_str() );
561 static void Import( CopiedString &self, const char *value ) {
562 setPakPath( 3, value );
567 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
568 returnz( self.c_str() );
571 static void Import( CopiedString &self, const char *value ) {
572 setPakPath( 4, value );
576 bool g_disableEnginePath = false;
577 bool g_disableHomePath = false;
579 void Paths_constructBasicPreferences( PreferencesPage& page ) {
580 page.appendPathEntry( "Engine Path", true, make_property<EnginePath>(g_strEnginePath) );
583 void Paths_constructPreferences( PreferencesPage& page ){
584 Paths_constructBasicPreferences( page );
586 page.appendSpacer( 4 );
587 page.appendLabel( "", "Advanced options" );
588 page.appendCheckBox( "", "Do not use Engine Path", g_disableEnginePath );
589 page.appendCheckBox( "", "Do not use Home Path", g_disableHomePath );
591 page.appendSpacer( 4 );
592 page.appendLabel( "", "Only a very few games support Pak Paths," );
593 page.appendLabel( "", "if you don't know what it is, leave this blank." );
595 const char *label = "Pak Path ";
596 page.appendPathEntry( label, true, make_property<PakPath0>( g_strPakPath[0] ) );
597 page.appendPathEntry( label, true, make_property<PakPath1>( g_strPakPath[1] ) );
598 page.appendPathEntry( label, true, make_property<PakPath2>( g_strPakPath[2] ) );
599 page.appendPathEntry( label, true, make_property<PakPath3>( g_strPakPath[3] ) );
600 page.appendPathEntry( label, true, make_property<PakPath4>( g_strPakPath[4] ) );
603 void Paths_constructPage( PreferenceGroup& group ){
604 PreferencesPage page( group.createPage( "Paths", "Path Settings" ) );
605 Paths_constructPreferences( page );
608 void Paths_registerPreferencesPage(){
609 PreferencesDialog_addSettingsPage( makeCallbackF(Paths_constructPage) );
613 class PathsDialog : public Dialog
616 ui::Window BuildDialog(){
617 auto frame = create_dialog_frame( "Path Settings", ui::Shadow::ETCHED_IN );
619 auto vbox2 = create_dialog_vbox( 0, 4 );
623 PreferencesPage page( *this, vbox2 );
624 Paths_constructBasicPreferences( page );
627 return ui::Window(create_simple_modal_dialog_window( "Engine Path Not Found", m_modal, frame ));
631 PathsDialog g_PathsDialog;
633 bool g_strEnginePath_was_empty_1st_start = false;
635 void EnginePath_verify(){
636 if ( !file_exists( g_strEnginePath.c_str() ) || g_strEnginePath_was_empty_1st_start ) {
637 g_PathsDialog.Create();
638 g_PathsDialog.DoModal();
639 g_PathsDialog.Destroy();
645 CopiedString g_gamename;
646 CopiedString g_gamemode;
647 ModuleObservers g_gameNameObservers;
648 ModuleObservers g_gameModeObservers;
651 void Radiant_attachGameNameObserver( ModuleObserver& observer ){
652 g_gameNameObservers.attach( observer );
655 void Radiant_detachGameNameObserver( ModuleObserver& observer ){
656 g_gameNameObservers.detach( observer );
659 const char* basegame_get(){
660 return g_pGameDescription->getRequiredKeyValue( "basegame" );
663 const char* gamename_get(){
664 const char* gamename = g_gamename.c_str();
665 if ( string_empty( gamename ) ) {
666 return basegame_get();
671 void gamename_set( const char* gamename ){
672 if ( !string_equal( gamename, g_gamename.c_str() ) ) {
673 g_gameNameObservers.unrealise();
674 g_gamename = gamename;
675 g_gameNameObservers.realise();
679 void Radiant_attachGameModeObserver( ModuleObserver& observer ){
680 g_gameModeObservers.attach( observer );
683 void Radiant_detachGameModeObserver( ModuleObserver& observer ){
684 g_gameModeObservers.detach( observer );
687 const char* gamemode_get(){
688 return g_gamemode.c_str();
691 void gamemode_set( const char* gamemode ){
692 if ( !string_equal( gamemode, g_gamemode.c_str() ) ) {
693 g_gameModeObservers.unrealise();
694 g_gamemode = gamemode;
695 g_gameModeObservers.realise();
702 const char* const c_library_extension =
703 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
704 CMAKE_SHARED_MODULE_SUFFIX
705 #elif GDEF_OS_WINDOWS
709 #elif GDEF_OS_LINUX || GDEF_OS_BSD
714 void Radiant_loadModules( const char* path ){
715 Directory_forEach(path, matchFileExtension(c_library_extension, [&](const char *name) {
717 ASSERT_MESSAGE(strlen(path) + strlen(name) < 1024, "");
718 strcpy(fullname, path);
719 strcat(fullname, name);
720 globalOutputStream() << "Found '" << fullname << "'\n";
721 GlobalModuleServer_loadModule(fullname);
725 void Radiant_loadModulesFromRoot( const char* directory ){
727 StringOutputStream path( 256 );
728 path << directory << g_pluginsDir;
729 Radiant_loadModules( path.c_str() );
732 if ( !string_equal( g_pluginsDir, g_modulesDir ) ) {
733 StringOutputStream path( 256 );
734 path << directory << g_modulesDir;
735 Radiant_loadModules( path.c_str() );
739 //! Make COLOR_BRUSHES override worldspawn eclass colour.
740 void SetWorldspawnColour( const Vector3& colour ){
741 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert( "worldspawn", true );
742 eclass_release_state( worldspawn );
743 worldspawn->color = colour;
744 eclass_capture_state( worldspawn );
748 class WorldspawnColourEntityClassObserver : public ModuleObserver
750 std::size_t m_unrealised;
752 WorldspawnColourEntityClassObserver() : m_unrealised( 1 ){
756 if ( --m_unrealised == 0 ) {
757 SetWorldspawnColour( g_xywindow_globals.color_brushes );
762 if ( ++m_unrealised == 1 ) {
767 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
770 ModuleObservers g_gameToolsPathObservers;
772 void Radiant_attachGameToolsPathObserver( ModuleObserver& observer ){
773 g_gameToolsPathObservers.attach( observer );
776 void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ){
777 g_gameToolsPathObservers.detach( observer );
780 void Radiant_Initialise(){
781 GlobalModuleServer_Initialise();
783 Radiant_loadModulesFromRoot( LibPath_get() );
787 bool success = Radiant_Construct( GlobalModuleServer_get() );
788 ASSERT_MESSAGE( success, "module system failed to initialise - see radiant.log for error messages" );
790 g_gameToolsPathObservers.realise();
791 g_gameModeObservers.realise();
792 g_gameNameObservers.realise();
795 void Radiant_Shutdown(){
796 g_gameNameObservers.unrealise();
797 g_gameModeObservers.unrealise();
798 g_gameToolsPathObservers.unrealise();
800 if ( !g_preferences_globals.disable_ini ) {
801 globalOutputStream() << "Start writing prefs\n";
803 globalOutputStream() << "Done prefs\n";
808 GlobalModuleServer_Shutdown();
812 if ( ConfirmModified( "Exit " RADIANT_NAME ) ) {
819 GlobalUndoSystem().undo();
824 GlobalUndoSystem().redo();
828 void deleteSelection(){
829 UndoableCommand undo( "deleteSelected" );
833 void Map_ExportSelected( TextOutputStream& ostream ){
834 Map_ExportSelected( ostream, Map_getFormat( g_map ) );
837 void Map_ImportSelected( TextInputStream& istream ){
838 Map_ImportSelected( istream, Map_getFormat( g_map ) );
841 void Selection_Copy(){
842 clipboard_copy( Map_ExportSelected );
845 void Selection_Paste(){
846 clipboard_paste( Map_ImportSelected );
850 if ( SelectedFaces_empty() ) {
855 SelectedFaces_copyTexture();
860 if ( SelectedFaces_empty() ) {
861 UndoableCommand undo( "paste" );
863 GlobalSelectionSystem().setSelectedAll( false );
868 SelectedFaces_pasteTexture();
872 void PasteToCamera(){
873 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
874 GlobalSelectionSystem().setSelectedAll( false );
876 UndoableCommand undo( "pasteToCamera" );
880 // Work out the delta
882 Select_GetMid( mid );
883 Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid );
886 GlobalSelectionSystem().translateSelected( delta );
890 void ColorScheme_Original(){
891 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
893 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
894 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
895 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
897 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
898 g_xywindow_globals.color_gridminor = Vector3( 0.75f, 0.75f, 0.75f );
899 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
900 g_xywindow_globals.color_gridminor_alt = Vector3( 0.5f, 0.0f, 0.0f );
901 g_xywindow_globals.color_gridmajor_alt = Vector3( 1.0f, 0.0f, 0.0f );
902 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
903 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
904 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
905 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
906 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
907 SetWorldspawnColour( g_xywindow_globals.color_brushes );
908 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
909 XY_UpdateAllWindows();
912 void ColorScheme_QER(){
913 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
915 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
916 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
917 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
919 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
920 g_xywindow_globals.color_gridminor = Vector3( 1.0f, 1.0f, 1.0f );
921 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
922 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
923 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
924 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
925 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
926 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
927 SetWorldspawnColour( g_xywindow_globals.color_brushes );
928 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
929 XY_UpdateAllWindows();
932 void ColorScheme_Black(){
933 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
935 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
936 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
937 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
939 g_xywindow_globals.color_gridback = Vector3( 0.0f, 0.0f, 0.0f );
940 g_xywindow_globals.color_gridminor = Vector3( 0.2f, 0.2f, 0.2f );
941 g_xywindow_globals.color_gridmajor = Vector3( 0.3f, 0.5f, 0.5f );
942 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
943 g_xywindow_globals.color_gridtext = Vector3( 1.0f, 1.0f, 1.0f );
944 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
945 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
946 g_xywindow_globals.color_brushes = Vector3( 1.0f, 1.0f, 1.0f );
947 SetWorldspawnColour( g_xywindow_globals.color_brushes );
948 g_xywindow_globals.color_viewname = Vector3( 0.7f, 0.7f, 0.0f );
949 XY_UpdateAllWindows();
952 /* ydnar: to emulate maya/max/lightwave color schemes */
953 void ColorScheme_Ydnar(){
954 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
956 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
957 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
958 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
960 g_xywindow_globals.color_gridback = Vector3( 0.77f, 0.77f, 0.77f );
961 g_xywindow_globals.color_gridminor = Vector3( 0.83f, 0.83f, 0.83f );
962 g_xywindow_globals.color_gridmajor = Vector3( 0.89f, 0.89f, 0.89f );
963 g_xywindow_globals.color_gridblock = Vector3( 1.0f, 1.0f, 1.0f );
964 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
965 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
966 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
967 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
968 SetWorldspawnColour( g_xywindow_globals.color_brushes );
969 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
970 XY_UpdateAllWindows();
973 /* color scheme to fit the GTK Adwaita Dark theme */
974 void ColorScheme_AdwaitaDark()
977 // GlobalTextureBrowser().color_textureback
978 TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
981 g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
983 g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
984 CamWnd_Update(*g_pParentWnd->GetCamWnd());
987 g_xywindow_globals.color_gridback = Vector3(0.25f, 0.25f, 0.25f);
989 g_xywindow_globals.color_gridminor = Vector3(0.21f, 0.23f, 0.23f);
991 g_xywindow_globals.color_gridmajor = Vector3(0.14f, 0.15f, 0.15f);
993 g_xywindow_globals.color_gridmajor_alt = Vector3(1.0f, 0.0f, 0.0f);
995 g_xywindow_globals.color_gridblock = Vector3(1.0f, 1.0f, 1.0f);
997 g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
999 g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
1001 g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
1003 g_xywindow_globals.color_brushes = Vector3(0.73f, 0.73f, 0.73f);
1006 g_xywindow_globals.AxisColorX = Vector3(1.0f, 0.0f, 0.0f);
1008 g_xywindow_globals.AxisColorY = Vector3(0.0f, 1.0f, 0.0f);
1010 g_xywindow_globals.AxisColorZ = Vector3(0.0f, 0.0f, 1.0f);
1011 SetWorldspawnColour(g_xywindow_globals.color_brushes);
1013 g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
1014 XY_UpdateAllWindows();
1017 // g_entity_globals.color_entity = Vector3(0.0f, 0.0f, 0.0f);
1020 typedef Callback<void(Vector3&)> GetColourCallback;
1021 typedef Callback<void(const Vector3&)> SetColourCallback;
1025 GetColourCallback m_get;
1026 SetColourCallback m_set;
1028 ChooseColour( const GetColourCallback& get, const SetColourCallback& set )
1029 : m_get( get ), m_set( set ){
1035 color_dialog( MainFrame_getWindow(), colour );
1041 void Colour_get( const Vector3& colour, Vector3& other ){
1045 typedef ConstReferenceCaller<Vector3, void(Vector3&), Colour_get> ColourGetCaller;
1047 void Colour_set( Vector3& colour, const Vector3& other ){
1049 SceneChangeNotify();
1052 typedef ReferenceCaller<Vector3, void(const Vector3&), Colour_set> ColourSetCaller;
1054 void BrushColour_set( const Vector3& other ){
1055 g_xywindow_globals.color_brushes = other;
1056 SetWorldspawnColour( g_xywindow_globals.color_brushes );
1057 SceneChangeNotify();
1060 typedef FreeCaller<void(const Vector3&), BrushColour_set> BrushColourSetCaller;
1062 void ClipperColour_set( const Vector3& other ){
1063 g_xywindow_globals.color_clipper = other;
1064 Brush_clipperColourChanged();
1065 SceneChangeNotify();
1068 typedef FreeCaller<void(const Vector3&), ClipperColour_set> ClipperColourSetCaller;
1070 void TextureBrowserColour_get( Vector3& other ){
1071 other = TextureBrowser_getBackgroundColour( GlobalTextureBrowser() );
1074 typedef FreeCaller<void(Vector3&), TextureBrowserColour_get> TextureBrowserColourGetCaller;
1076 void TextureBrowserColour_set( const Vector3& other ){
1077 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), other );
1080 typedef FreeCaller<void(const Vector3&), TextureBrowserColour_set> TextureBrowserColourSetCaller;
1086 ChooseColour m_textureback;
1087 ChooseColour m_xyback;
1088 ChooseColour m_gridmajor;
1089 ChooseColour m_gridminor;
1090 ChooseColour m_gridmajor_alt;
1091 ChooseColour m_gridminor_alt;
1092 ChooseColour m_gridtext;
1093 ChooseColour m_gridblock;
1094 ChooseColour m_cameraback;
1095 ChooseColour m_brush;
1096 ChooseColour m_selectedbrush;
1097 ChooseColour m_selectedbrush3d;
1098 ChooseColour m_clipper;
1099 ChooseColour m_viewname;
1102 m_textureback( TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller() ),
1103 m_xyback( ColourGetCaller( g_xywindow_globals.color_gridback ), ColourSetCaller( g_xywindow_globals.color_gridback ) ),
1104 m_gridmajor( ColourGetCaller( g_xywindow_globals.color_gridmajor ), ColourSetCaller( g_xywindow_globals.color_gridmajor ) ),
1105 m_gridminor( ColourGetCaller( g_xywindow_globals.color_gridminor ), ColourSetCaller( g_xywindow_globals.color_gridminor ) ),
1106 m_gridmajor_alt( ColourGetCaller( g_xywindow_globals.color_gridmajor_alt ), ColourSetCaller( g_xywindow_globals.color_gridmajor_alt ) ),
1107 m_gridminor_alt( ColourGetCaller( g_xywindow_globals.color_gridminor_alt ), ColourSetCaller( g_xywindow_globals.color_gridminor_alt ) ),
1108 m_gridtext( ColourGetCaller( g_xywindow_globals.color_gridtext ), ColourSetCaller( g_xywindow_globals.color_gridtext ) ),
1109 m_gridblock( ColourGetCaller( g_xywindow_globals.color_gridblock ), ColourSetCaller( g_xywindow_globals.color_gridblock ) ),
1110 m_cameraback( ColourGetCaller( g_camwindow_globals.color_cameraback ), ColourSetCaller( g_camwindow_globals.color_cameraback ) ),
1111 m_brush( ColourGetCaller( g_xywindow_globals.color_brushes ), BrushColourSetCaller() ),
1112 m_selectedbrush( ColourGetCaller( g_xywindow_globals.color_selbrushes ), ColourSetCaller( g_xywindow_globals.color_selbrushes ) ),
1113 m_selectedbrush3d( ColourGetCaller( g_camwindow_globals.color_selbrushes3d ), ColourSetCaller( g_camwindow_globals.color_selbrushes3d ) ),
1114 m_clipper( ColourGetCaller( g_xywindow_globals.color_clipper ), ClipperColourSetCaller() ),
1115 m_viewname( ColourGetCaller( g_xywindow_globals.color_viewname ), ColourSetCaller( g_xywindow_globals.color_viewname ) ){
1119 ColoursMenu g_ColoursMenu;
1121 ui::MenuItem create_colours_menu(){
1122 auto colours_menu_item = new_sub_menu_item_with_mnemonic( "Colors" );
1123 auto menu_in_menu = ui::Menu::from( gtk_menu_item_get_submenu( colours_menu_item ) );
1124 if ( g_Layout_enableDetachableMenus.m_value ) {
1125 menu_tearoff( menu_in_menu );
1128 auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Themes" );
1129 if ( g_Layout_enableDetachableMenus.m_value ) {
1130 menu_tearoff( menu_3 );
1133 create_menu_item_with_mnemonic( menu_3, "QE4 Original", "ColorSchemeOriginal" );
1134 create_menu_item_with_mnemonic( menu_3, "Q3Radiant Original", "ColorSchemeQER" );
1135 create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" );
1136 create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" );
1137 create_menu_item_with_mnemonic(menu_3, "Adwaita Dark", "ColorSchemeAdwaitaDark");
1139 menu_separator( menu_in_menu );
1141 create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" );
1142 create_menu_item_with_mnemonic( menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor" );
1143 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major...", "ChooseGridMajorColor" );
1144 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor...", "ChooseGridMinorColor" );
1145 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor" );
1146 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor" );
1147 create_menu_item_with_mnemonic( menu_in_menu, "Grid Text...", "ChooseGridTextColor" );
1148 create_menu_item_with_mnemonic( menu_in_menu, "Grid Block...", "ChooseGridBlockColor" );
1149 create_menu_item_with_mnemonic( menu_in_menu, "Default Brush...", "ChooseBrushColor" );
1150 create_menu_item_with_mnemonic( menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor" );
1151 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor" );
1152 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor" );
1153 create_menu_item_with_mnemonic( menu_in_menu, "Clipper...", "ChooseClipperColor" );
1154 create_menu_item_with_mnemonic( menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor" );
1156 return colours_menu_item;
1161 PluginsMenu_clear();
1162 PluginToolbar_clear();
1165 Radiant_Initialise();
1167 PluginsMenu_populate();
1169 PluginToolbar_populate();
1173 void thunk_OnSleep(){
1174 g_pParentWnd->OnSleep();
1178 OpenURL( "https://gitlab.com/xonotic/xonotic/wikis/Mapping" );
1181 void OpenBugReportURL(){
1182 OpenURL( "https://gitlab.com/xonotic/netradiant/issues" );
1186 ui::Widget g_page_console{ui::null};
1188 void Console_ToggleShow(){
1189 GroupDialog_showPage( g_page_console );
1192 ui::Widget g_page_entity{ui::null};
1194 void EntityInspector_ToggleShow(){
1195 GroupDialog_showPage( g_page_entity );
1199 void SetClipMode( bool enable );
1201 void ModeChangeNotify();
1203 typedef void ( *ToolMode )();
1205 ToolMode g_currentToolMode = 0;
1206 bool g_currentToolModeSupportsComponentEditing = false;
1207 ToolMode g_defaultToolMode = 0;
1210 void SelectionSystem_DefaultMode(){
1211 GlobalSelectionSystem().SetMode( SelectionSystem::ePrimitive );
1212 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eDefault );
1218 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1219 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1223 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1224 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1228 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1229 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1232 template<bool( *BoolFunction ) ( )>
1233 class BoolFunctionExport
1236 static void apply( const Callback<void(bool)> & importCallback ){
1237 importCallback( BoolFunction() );
1241 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1242 EdgeModeApplyCaller g_edgeMode_button_caller;
1243 Callback<void(const Callback<void(bool)> &)> g_edgeMode_button_callback( g_edgeMode_button_caller );
1244 ToggleItem g_edgeMode_button( g_edgeMode_button_callback );
1246 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1247 VertexModeApplyCaller g_vertexMode_button_caller;
1248 Callback<void(const Callback<void(bool)> &)> g_vertexMode_button_callback( g_vertexMode_button_caller );
1249 ToggleItem g_vertexMode_button( g_vertexMode_button_callback );
1251 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1252 FaceModeApplyCaller g_faceMode_button_caller;
1253 Callback<void(const Callback<void(bool)> &)> g_faceMode_button_callback( g_faceMode_button_caller );
1254 ToggleItem g_faceMode_button( g_faceMode_button_callback );
1256 void ComponentModeChanged(){
1257 g_edgeMode_button.update();
1258 g_vertexMode_button.update();
1259 g_faceMode_button.update();
1262 void ComponentMode_SelectionChanged( const Selectable& selectable ){
1263 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1264 && GlobalSelectionSystem().countSelected() == 0 ) {
1265 SelectionSystem_DefaultMode();
1266 ComponentModeChanged();
1270 void SelectEdgeMode(){
1272 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1273 GlobalSelectionSystem().Select( false );
1278 SelectionSystem_DefaultMode();
1280 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1281 if ( !g_currentToolModeSupportsComponentEditing ) {
1282 g_defaultToolMode();
1285 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1286 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eEdge );
1289 ComponentModeChanged();
1294 void SelectVertexMode(){
1296 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1297 GlobalSelectionSystem().Select( false );
1301 if ( VertexMode() ) {
1302 SelectionSystem_DefaultMode();
1304 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1305 if ( !g_currentToolModeSupportsComponentEditing ) {
1306 g_defaultToolMode();
1309 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1310 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eVertex );
1313 ComponentModeChanged();
1318 void SelectFaceMode(){
1320 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1321 GlobalSelectionSystem().Select( false );
1326 SelectionSystem_DefaultMode();
1328 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1329 if ( !g_currentToolModeSupportsComponentEditing ) {
1330 g_defaultToolMode();
1333 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1334 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eFace );
1337 ComponentModeChanged();
1343 class CloneSelected : public scene::Graph::Walker
1346 NodeSmartReference worldspawn;
1348 CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
1351 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1352 if ( path.size() == 1 ) {
1356 // ignore worldspawn, but keep checking children
1357 NodeSmartReference me( path.top().get() );
1358 if ( me == worldspawn ) {
1362 if ( !path.top().get().isRoot() ) {
1363 Selectable* selectable = Instance_getSelectable( instance );
1364 if ( selectable != 0
1365 && selectable->isSelected() ) {
1373 void post( const scene::Path& path, scene::Instance& instance ) const {
1374 if ( path.size() == 1 ) {
1378 // ignore worldspawn, but keep checking children
1379 NodeSmartReference me( path.top().get() );
1380 if ( me == worldspawn ) {
1384 if ( !path.top().get().isRoot() ) {
1385 Selectable* selectable = Instance_getSelectable( instance );
1386 if ( selectable != 0
1387 && selectable->isSelected() ) {
1388 NodeSmartReference clone( Node_Clone( path.top() ) );
1389 if ( doMakeUnique ) {
1390 Map_gatherNamespaced( clone );
1392 Node_getTraversable( path.parent().get() )->insert( clone );
1398 void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){
1399 graph.traverse( CloneSelected( doMakeUnique ) );
1401 Map_mergeClonedNames();
1404 enum ENudgeDirection
1418 AxisBase( const Vector3& x_, const Vector3& y_, const Vector3& z_ )
1419 : x( x_ ), y( y_ ), z( z_ ){
1423 AxisBase AxisBase_forViewType( VIEWTYPE viewtype ){
1427 return AxisBase( g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z );
1429 return AxisBase( g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y );
1431 return AxisBase( g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x );
1434 ERROR_MESSAGE( "invalid viewtype" );
1435 return AxisBase( Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) );
1438 Vector3 AxisBase_axisForDirection( const AxisBase& axes, ENudgeDirection direction ){
1439 switch ( direction )
1442 return vector3_negated( axes.x );
1448 return vector3_negated( axes.y );
1451 ERROR_MESSAGE( "invalid direction" );
1452 return Vector3( 0, 0, 0 );
1455 void NudgeSelection( ENudgeDirection direction, float fAmount, VIEWTYPE viewtype ){
1456 AxisBase axes( AxisBase_forViewType( viewtype ) );
1457 Vector3 view_direction( vector3_negated( axes.z ) );
1458 Vector3 nudge( vector3_scaled( AxisBase_axisForDirection( axes, direction ), fAmount ) );
1459 GlobalSelectionSystem().NudgeManipulator( nudge, view_direction );
1462 void Selection_Clone(){
1463 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1464 UndoableCommand undo( "cloneSelected" );
1466 Scene_Clone_Selected( GlobalSceneGraph(), false );
1468 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1469 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1473 void Selection_Clone_MakeUnique(){
1474 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1475 UndoableCommand undo( "cloneSelectedMakeUnique" );
1477 Scene_Clone_Selected( GlobalSceneGraph(), true );
1479 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1480 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1484 // called when the escape key is used (either on the main window or on an inspector)
1485 void Selection_Deselect(){
1486 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1487 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1488 GlobalSelectionSystem().setSelectedAllComponents( false );
1492 SelectionSystem_DefaultMode();
1493 ComponentModeChanged();
1498 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1499 GlobalSelectionSystem().setSelectedAllComponents( false );
1503 GlobalSelectionSystem().setSelectedAll( false );
1509 void Selection_NudgeUp(){
1510 UndoableCommand undo( "nudgeSelectedUp" );
1511 NudgeSelection( eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1514 void Selection_NudgeDown(){
1515 UndoableCommand undo( "nudgeSelectedDown" );
1516 NudgeSelection( eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1519 void Selection_NudgeLeft(){
1520 UndoableCommand undo( "nudgeSelectedLeft" );
1521 NudgeSelection( eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1524 void Selection_NudgeRight(){
1525 UndoableCommand undo( "nudgeSelectedRight" );
1526 NudgeSelection( eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1530 void TranslateToolExport( const Callback<void(bool)> & importCallback ){
1531 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate );
1534 void RotateToolExport( const Callback<void(bool)> & importCallback ){
1535 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate );
1538 void ScaleToolExport( const Callback<void(bool)> & importCallback ){
1539 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale );
1542 void DragToolExport( const Callback<void(bool)> & importCallback ){
1543 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag );
1546 void ClipperToolExport( const Callback<void(bool)> & importCallback ){
1547 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip );
1550 FreeCaller<void(const Callback<void(bool)> &), TranslateToolExport> g_translatemode_button_caller;
1551 Callback<void(const Callback<void(bool)> &)> g_translatemode_button_callback( g_translatemode_button_caller );
1552 ToggleItem g_translatemode_button( g_translatemode_button_callback );
1554 FreeCaller<void(const Callback<void(bool)> &), RotateToolExport> g_rotatemode_button_caller;
1555 Callback<void(const Callback<void(bool)> &)> g_rotatemode_button_callback( g_rotatemode_button_caller );
1556 ToggleItem g_rotatemode_button( g_rotatemode_button_callback );
1558 FreeCaller<void(const Callback<void(bool)> &), ScaleToolExport> g_scalemode_button_caller;
1559 Callback<void(const Callback<void(bool)> &)> g_scalemode_button_callback( g_scalemode_button_caller );
1560 ToggleItem g_scalemode_button( g_scalemode_button_callback );
1562 FreeCaller<void(const Callback<void(bool)> &), DragToolExport> g_dragmode_button_caller;
1563 Callback<void(const Callback<void(bool)> &)> g_dragmode_button_callback( g_dragmode_button_caller );
1564 ToggleItem g_dragmode_button( g_dragmode_button_callback );
1566 FreeCaller<void(const Callback<void(bool)> &), ClipperToolExport> g_clipper_button_caller;
1567 Callback<void(const Callback<void(bool)> &)> g_clipper_button_callback( g_clipper_button_caller );
1568 ToggleItem g_clipper_button( g_clipper_button_callback );
1571 g_translatemode_button.update();
1572 g_rotatemode_button.update();
1573 g_scalemode_button.update();
1574 g_dragmode_button.update();
1575 g_clipper_button.update();
1578 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1581 if ( g_currentToolMode == DragMode && g_defaultToolMode != DragMode ) {
1582 g_defaultToolMode();
1586 g_currentToolMode = DragMode;
1587 g_currentToolModeSupportsComponentEditing = true;
1589 OnClipMode( false );
1591 Sys_Status( c_ResizeMode_status );
1592 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eDrag );
1599 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1601 void TranslateMode(){
1602 if ( g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode ) {
1603 g_defaultToolMode();
1607 g_currentToolMode = TranslateMode;
1608 g_currentToolModeSupportsComponentEditing = true;
1610 OnClipMode( false );
1612 Sys_Status( c_TranslateMode_status );
1613 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eTranslate );
1619 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1622 if ( g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode ) {
1623 g_defaultToolMode();
1627 g_currentToolMode = RotateMode;
1628 g_currentToolModeSupportsComponentEditing = true;
1630 OnClipMode( false );
1632 Sys_Status( c_RotateMode_status );
1633 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eRotate );
1639 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1642 if ( g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode ) {
1643 g_defaultToolMode();
1647 g_currentToolMode = ScaleMode;
1648 g_currentToolModeSupportsComponentEditing = true;
1650 OnClipMode( false );
1652 Sys_Status( c_ScaleMode_status );
1653 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eScale );
1660 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1664 if ( g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode ) {
1665 g_defaultToolMode();
1669 g_currentToolMode = ClipperMode;
1670 g_currentToolModeSupportsComponentEditing = false;
1672 SelectionSystem_DefaultMode();
1676 Sys_Status( c_ClipperMode_status );
1677 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eClip );
1684 void Texdef_Rotate( float angle ){
1685 StringOutputStream command;
1686 command << "brushRotateTexture -angle " << angle;
1687 UndoableCommand undo( command.c_str() );
1688 Select_RotateTexture( angle );
1691 void Texdef_RotateClockwise(){
1692 Texdef_Rotate( static_cast<float>( fabs( g_si_globals.rotate ) ) );
1695 void Texdef_RotateAntiClockwise(){
1696 Texdef_Rotate( static_cast<float>( -fabs( g_si_globals.rotate ) ) );
1699 void Texdef_Scale( float x, float y ){
1700 StringOutputStream command;
1701 command << "brushScaleTexture -x " << x << " -y " << y;
1702 UndoableCommand undo( command.c_str() );
1703 Select_ScaleTexture( x, y );
1706 void Texdef_ScaleUp(){
1707 Texdef_Scale( 0, g_si_globals.scale[1] );
1710 void Texdef_ScaleDown(){
1711 Texdef_Scale( 0, -g_si_globals.scale[1] );
1714 void Texdef_ScaleLeft(){
1715 Texdef_Scale( -g_si_globals.scale[0],0 );
1718 void Texdef_ScaleRight(){
1719 Texdef_Scale( g_si_globals.scale[0],0 );
1722 void Texdef_Shift( float x, float y ){
1723 StringOutputStream command;
1724 command << "brushShiftTexture -x " << x << " -y " << y;
1725 UndoableCommand undo( command.c_str() );
1726 Select_ShiftTexture( x, y );
1729 void Texdef_ShiftLeft(){
1730 Texdef_Shift( -g_si_globals.shift[0], 0 );
1733 void Texdef_ShiftRight(){
1734 Texdef_Shift( g_si_globals.shift[0], 0 );
1737 void Texdef_ShiftUp(){
1738 Texdef_Shift( 0, g_si_globals.shift[1] );
1741 void Texdef_ShiftDown(){
1742 Texdef_Shift( 0, -g_si_globals.shift[1] );
1747 class SnappableSnapToGridSelected : public scene::Graph::Walker
1751 SnappableSnapToGridSelected( float snap )
1755 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1756 if ( path.top().get().visible() ) {
1757 Snappable* snappable = Node_getSnappable( path.top() );
1759 && Instance_getSelectable( instance )->isSelected() ) {
1760 snappable->snapto( m_snap );
1767 void Scene_SnapToGrid_Selected( scene::Graph& graph, float snap ){
1768 graph.traverse( SnappableSnapToGridSelected( snap ) );
1771 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1775 ComponentSnappableSnapToGridSelected( float snap )
1779 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1780 if ( path.top().get().visible() ) {
1781 ComponentSnappable* componentSnappable = Instance_getComponentSnappable( instance );
1782 if ( componentSnappable != 0
1783 && Instance_getSelectable( instance )->isSelected() ) {
1784 componentSnappable->snapComponents( m_snap );
1791 void Scene_SnapToGrid_Component_Selected( scene::Graph& graph, float snap ){
1792 graph.traverse( ComponentSnappableSnapToGridSelected( snap ) );
1795 void Selection_SnapToGrid(){
1796 StringOutputStream command;
1797 command << "snapSelected -grid " << GetGridSize();
1798 UndoableCommand undo( command.c_str() );
1800 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1801 Scene_SnapToGrid_Component_Selected( GlobalSceneGraph(), GetGridSize() );
1805 Scene_SnapToGrid_Selected( GlobalSceneGraph(), GetGridSize() );
1810 static gint qe_every_second( gpointer data ){
1811 if (g_pParentWnd == nullptr)
1814 GdkModifierType mask;
1815 gdk_window_get_pointer( gtk_widget_get_window(g_pParentWnd->m_window), nullptr, nullptr, &mask );
1817 if ( ( mask & ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK ) ) == 0 ) {
1824 guint s_qe_every_second_id = 0;
1826 void EverySecondTimer_enable(){
1827 if ( s_qe_every_second_id == 0 ) {
1828 s_qe_every_second_id = g_timeout_add( 1000, qe_every_second, 0 );
1832 void EverySecondTimer_disable(){
1833 if ( s_qe_every_second_id != 0 ) {
1834 g_source_remove( s_qe_every_second_id );
1835 s_qe_every_second_id = 0;
1839 gint window_realize_remove_decoration( ui::Widget widget, gpointer data ){
1840 gdk_window_set_decorations( gtk_widget_get_window(widget), (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) );
1847 ui::Window m_window{ui::null};
1848 ui::Label m_label{ui::null};
1851 WaitDialog create_wait_dialog( const char* title, const char* text ){
1854 dialog.m_window = MainFrame_getWindow().create_floating_window(title);
1855 gtk_window_set_resizable( dialog.m_window, FALSE );
1856 gtk_container_set_border_width( GTK_CONTAINER( dialog.m_window ), 0 );
1857 gtk_window_set_position( dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT );
1859 dialog.m_window.connect( "realize", G_CALLBACK( window_realize_remove_decoration ), 0 );
1862 dialog.m_label = ui::Label( text );
1863 gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 );
1864 gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT );
1865 dialog.m_label.show();
1866 dialog.m_label.dimensions(200, -1);
1868 dialog.m_window.add(dialog.m_label);
1875 clock_t g_lastRedrawTime = 0;
1876 const clock_t c_redrawInterval = clock_t( CLOCKS_PER_SEC / 10 );
1878 bool redrawRequired(){
1879 clock_t currentTime = std::clock();
1880 if ( currentTime - g_lastRedrawTime >= c_redrawInterval ) {
1881 g_lastRedrawTime = currentTime;
1888 bool MainFrame_isActiveApp(){
1889 //globalOutputStream() << "listing\n";
1890 GList* list = gtk_window_list_toplevels();
1891 for ( GList* i = list; i != 0; i = g_list_next( i ) )
1893 //globalOutputStream() << "toplevel.. ";
1894 if ( gtk_window_is_active( ui::Window::from( i->data ) ) ) {
1895 //globalOutputStream() << "is active\n";
1898 //globalOutputStream() << "not active\n";
1903 typedef std::list<CopiedString> StringStack;
1904 StringStack g_wait_stack;
1907 bool ScreenUpdates_Enabled(){
1908 return g_wait_stack.empty();
1911 void ScreenUpdates_process(){
1912 if ( redrawRequired() && g_wait.m_window.visible() ) {
1918 void ScreenUpdates_Disable( const char* message, const char* title ){
1919 if ( g_wait_stack.empty() ) {
1920 EverySecondTimer_disable();
1924 bool isActiveApp = MainFrame_isActiveApp();
1926 g_wait = create_wait_dialog( title, message );
1928 if ( isActiveApp ) {
1929 g_wait.m_window.show();
1930 gtk_grab_add( g_wait.m_window );
1931 ScreenUpdates_process();
1934 else if ( g_wait.m_window.visible() ) {
1935 g_wait.m_label.text(message);
1936 if ( GTK_IS_WINDOW(g_wait.m_window) ) {
1937 gtk_grab_add(g_wait.m_window);
1939 ScreenUpdates_process();
1941 g_wait_stack.push_back( message );
1944 void ScreenUpdates_Enable(){
1945 ASSERT_MESSAGE( !ScreenUpdates_Enabled(), "screen updates already enabled" );
1946 g_wait_stack.pop_back();
1947 if ( g_wait_stack.empty() ) {
1948 EverySecondTimer_enable();
1949 //gtk_widget_set_sensitive(MainFrame_getWindow(), TRUE);
1951 gtk_grab_remove( g_wait.m_window );
1952 destroy_floating_window( g_wait.m_window );
1953 g_wait.m_window = ui::Window{ui::null};
1955 //gtk_window_present(MainFrame_getWindow());
1957 else if ( g_wait.m_window.visible() ) {
1958 g_wait.m_label.text(g_wait_stack.back().c_str());
1959 ScreenUpdates_process();
1964 void GlobalCamera_UpdateWindow(){
1965 if ( g_pParentWnd != 0 ) {
1966 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
1970 void XY_UpdateWindow( MainFrame& mainframe ){
1971 if ( mainframe.GetXYWnd() != 0 ) {
1972 XYWnd_Update( *mainframe.GetXYWnd() );
1976 void XZ_UpdateWindow( MainFrame& mainframe ){
1977 if ( mainframe.GetXZWnd() != 0 ) {
1978 XYWnd_Update( *mainframe.GetXZWnd() );
1982 void YZ_UpdateWindow( MainFrame& mainframe ){
1983 if ( mainframe.GetYZWnd() != 0 ) {
1984 XYWnd_Update( *mainframe.GetYZWnd() );
1988 void XY_UpdateAllWindows( MainFrame& mainframe ){
1989 XY_UpdateWindow( mainframe );
1990 XZ_UpdateWindow( mainframe );
1991 YZ_UpdateWindow( mainframe );
1994 void XY_UpdateAllWindows(){
1995 if ( g_pParentWnd != 0 ) {
1996 XY_UpdateAllWindows( *g_pParentWnd );
2000 void UpdateAllWindows(){
2001 GlobalCamera_UpdateWindow();
2002 XY_UpdateAllWindows();
2006 void ModeChangeNotify(){
2007 SceneChangeNotify();
2010 void ClipperChangeNotify(){
2011 GlobalCamera_UpdateWindow();
2012 XY_UpdateAllWindows();
2016 LatchedValue<int> g_Layout_viewStyle( 0, "Window Layout" );
2017 LatchedValue<bool> g_Layout_enableDetachableMenus( true, "Detachable Menus" );
2018 LatchedValue<bool> g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
2019 LatchedValue<bool> g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
2020 LatchedValue<bool> g_Layout_enableFilterToolbar( true, "Filter Toolbar" );
2023 ui::MenuItem create_file_menu(){
2025 auto file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
2026 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( file_menu_item ) );
2027 if ( g_Layout_enableDetachableMenus.m_value ) {
2028 menu_tearoff( menu );
2031 create_menu_item_with_mnemonic( menu, "_New Map", "NewMap" );
2032 menu_separator( menu );
2035 //++timo temporary experimental stuff for sleep mode..
2036 create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" );
2037 menu_separator( menu );
2041 create_menu_item_with_mnemonic( menu, "_Open...", "OpenMap" );
2043 create_menu_item_with_mnemonic( menu, "_Import...", "ImportMap" );
2044 create_menu_item_with_mnemonic( menu, "_Save", "SaveMap" );
2045 create_menu_item_with_mnemonic( menu, "Save _as...", "SaveMapAs" );
2046 create_menu_item_with_mnemonic( menu, "_Export selected...", "ExportSelected" );
2047 menu_separator( menu );
2048 create_menu_item_with_mnemonic( menu, "Save re_gion...", "SaveRegion" );
2049 // menu_separator( menu );
2050 // create_menu_item_with_mnemonic( menu, "_Refresh models", "RefreshReferences" );
2051 // menu_separator( menu );
2052 create_menu_item_with_mnemonic( menu, "Pro_ject settings...", "ProjectSettings" );
2053 menu_separator( menu );
2054 create_menu_item_with_mnemonic( menu, "_Pointfile...", "TogglePointfile" );
2055 menu_separator( menu );
2056 MRU_constructMenu( menu );
2057 menu_separator( menu );
2058 // create_menu_item_with_mnemonic( menu, "Check for NetRadiant update (web)", "CheckForUpdate" ); // FIXME
2059 create_menu_item_with_mnemonic( menu, "E_xit", "Exit" );
2061 return file_menu_item;
2064 ui::MenuItem create_edit_menu(){
2066 auto edit_menu_item = new_sub_menu_item_with_mnemonic( "_Edit" );
2067 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( edit_menu_item ) );
2068 if ( g_Layout_enableDetachableMenus.m_value ) {
2069 menu_tearoff( menu );
2071 create_menu_item_with_mnemonic( menu, "_Undo", "Undo" );
2072 create_menu_item_with_mnemonic( menu, "_Redo", "Redo" );
2073 menu_separator( menu );
2074 create_menu_item_with_mnemonic( menu, "_Copy", "Copy" );
2075 create_menu_item_with_mnemonic( menu, "_Paste", "Paste" );
2076 create_menu_item_with_mnemonic( menu, "P_aste To Camera", "PasteToCamera" );
2077 menu_separator( menu );
2078 create_menu_item_with_mnemonic( menu, "_Duplicate", "CloneSelection" );
2079 create_menu_item_with_mnemonic( menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique" );
2080 create_menu_item_with_mnemonic( menu, "D_elete", "DeleteSelection" );
2081 menu_separator( menu );
2082 create_menu_item_with_mnemonic( menu, "Snap To Grid", "SnapToGrid" );
2083 //create_menu_item_with_mnemonic( menu, "Pa_rent", "ParentSelection" );
2084 menu_separator( menu );
2085 create_menu_item_with_mnemonic( menu, "C_lear Selection", "UnSelectSelection" );
2086 create_menu_item_with_mnemonic( menu, "_Invert Selection", "InvertSelection" );
2087 create_menu_item_with_mnemonic( menu, "Select i_nside", "SelectInside" );
2088 create_menu_item_with_mnemonic( menu, "Select _touching", "SelectTouching" );
2090 menu_separator( menu );
2092 // auto convert_menu = create_sub_menu_with_mnemonic( menu, "E_xpand Selection" );
2093 // if ( g_Layout_enableDetachableMenus.m_value ) {
2094 // menu_tearoff( convert_menu );
2096 create_menu_item_with_mnemonic( menu, "Select All Of Type", "SelectAllOfType" );
2097 create_menu_item_with_mnemonic( menu, "_Expand Selection To Entities", "ExpandSelectionToEntities" );
2099 menu_separator( menu );
2100 create_menu_item_with_mnemonic( menu, "Pre_ferences...", "Preferences" );
2102 return edit_menu_item;
2105 void fill_view_xy_top_menu( ui::Menu menu ){
2106 create_check_menu_item_with_mnemonic( menu, "XY (Top) View", "ToggleView" );
2110 void fill_view_yz_side_menu( ui::Menu menu ){
2111 create_check_menu_item_with_mnemonic( menu, "YZ (Side) View", "ToggleSideView" );
2115 void fill_view_xz_front_menu( ui::Menu menu ){
2116 create_check_menu_item_with_mnemonic( menu, "XZ (Front) View", "ToggleFrontView" );
2120 ui::Widget g_toggle_z_item{ui::null};
2121 ui::Widget g_toggle_console_item{ui::null};
2122 ui::Widget g_toggle_entity_item{ui::null};
2123 ui::Widget g_toggle_entitylist_item{ui::null};
2125 ui::MenuItem create_view_menu( MainFrame::EViewStyle style ){
2127 auto view_menu_item = new_sub_menu_item_with_mnemonic( "Vie_w" );
2128 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( view_menu_item ) );
2129 if ( g_Layout_enableDetachableMenus.m_value ) {
2130 menu_tearoff( menu );
2133 if ( style == MainFrame::eFloating ) {
2134 fill_view_camera_menu( menu );
2135 fill_view_xy_top_menu( menu );
2136 fill_view_yz_side_menu( menu );
2137 fill_view_xz_front_menu( menu );
2139 if ( style == MainFrame::eFloating || style == MainFrame::eSplit ) {
2140 create_menu_item_with_mnemonic( menu, "Console View", "ToggleConsole" );
2141 create_menu_item_with_mnemonic( menu, "Texture Browser", "ToggleTextures" );
2142 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ToggleEntityInspector" );
2146 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ViewEntityInfo" );
2148 create_menu_item_with_mnemonic( menu, "_Surface Inspector", "SurfaceInspector" );
2149 create_menu_item_with_mnemonic( menu, "_Patch Inspector", "PatchInspector" );
2150 create_menu_item_with_mnemonic( menu, "Entity List", "EntityList" );
2152 menu_separator( menu );
2154 auto camera_menu = create_sub_menu_with_mnemonic( menu, "Camera" );
2155 if ( g_Layout_enableDetachableMenus.m_value ) {
2156 menu_tearoff( camera_menu );
2158 create_menu_item_with_mnemonic( camera_menu, "_Center", "CenterView" );
2159 create_menu_item_with_mnemonic( camera_menu, "_Up Floor", "UpFloor" );
2160 create_menu_item_with_mnemonic( camera_menu, "_Down Floor", "DownFloor" );
2161 menu_separator( camera_menu );
2162 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane In", "CubicClipZoomIn" );
2163 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane Out", "CubicClipZoomOut" );
2164 menu_separator( camera_menu );
2165 create_menu_item_with_mnemonic( camera_menu, "Decrease FOV", "FOVDec" );
2166 create_menu_item_with_mnemonic( camera_menu, "Increase FOV", "FOVInc" );
2167 menu_separator( camera_menu );
2168 create_menu_item_with_mnemonic( camera_menu, "Next leak spot", "NextLeakSpot" );
2169 create_menu_item_with_mnemonic( camera_menu, "Previous leak spot", "PrevLeakSpot" );
2170 menu_separator( camera_menu );
2171 create_menu_item_with_mnemonic( camera_menu, "Look Through Selected", "LookThroughSelected" );
2172 create_menu_item_with_mnemonic( camera_menu, "Look Through Camera", "LookThroughCamera" );
2174 menu_separator( menu );
2176 auto orthographic_menu = create_sub_menu_with_mnemonic( menu, "Orthographic" );
2177 if ( g_Layout_enableDetachableMenus.m_value ) {
2178 menu_tearoff( orthographic_menu );
2180 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2181 create_menu_item_with_mnemonic( orthographic_menu, "_Next (XY, YZ, XY)", "NextView" );
2182 create_menu_item_with_mnemonic( orthographic_menu, "XY (Top)", "ViewTop" );
2183 create_menu_item_with_mnemonic( orthographic_menu, "YZ", "ViewSide" );
2184 create_menu_item_with_mnemonic( orthographic_menu, "XZ", "ViewFront" );
2185 menu_separator( orthographic_menu );
2188 create_menu_item_with_mnemonic( orthographic_menu, "Center on Selected", "CenterXYView" );
2189 menu_separator( orthographic_menu );
2190 create_menu_item_with_mnemonic( orthographic_menu, "_XY 100%", "Zoom100" );
2191 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _In", "ZoomIn" );
2192 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _Out", "ZoomOut" );
2195 menu_separator( menu );
2198 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Show" );
2199 if ( g_Layout_enableDetachableMenus.m_value ) {
2200 menu_tearoff( menu_in_menu );
2202 create_menu_item_with_mnemonic( menu_in_menu, "Show Size Info", "ToggleSizePaint" );
2203 create_menu_item_with_mnemonic( menu_in_menu, "Show Crosshair", "ToggleCrosshairs" );
2204 create_menu_item_with_mnemonic( menu_in_menu, "Show Grid", "ToggleGrid" );
2206 menu_separator( menu_in_menu );
2208 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Angles", "ShowAngles" );
2209 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Names", "ShowNames" );
2210 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Blocks", "ShowBlocks" );
2211 create_check_menu_item_with_mnemonic( menu_in_menu, "Show C_oordinates", "ShowCoordinates" );
2212 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Window Outline", "ShowWindowOutline" );
2213 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Axes", "ShowAxes" );
2214 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Workzone", "ShowWorkzone" );
2215 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Stats", "ShowStats" );
2219 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Filter" );
2220 if ( g_Layout_enableDetachableMenus.m_value ) {
2221 menu_tearoff( menu_in_menu );
2223 Filters_constructMenu( menu_in_menu );
2225 menu_separator( menu );
2227 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Hide/Show" );
2228 // if ( g_Layout_enableDetachableMenus.m_value ) {
2229 // menu_tearoff( menu_in_menu );
2231 // create_menu_item_with_mnemonic( menu_in_menu, "Hide Selected", "HideSelected" );
2232 // create_menu_item_with_mnemonic( menu_in_menu, "Show Hidden", "ShowHidden" );
2233 create_menu_item_with_mnemonic( menu, "Hide Selected", "HideSelected" );
2234 create_menu_item_with_mnemonic( menu, "Show Hidden", "ShowHidden" );
2236 menu_separator( menu );
2238 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Region" );
2239 if ( g_Layout_enableDetachableMenus.m_value ) {
2240 menu_tearoff( menu_in_menu );
2242 create_menu_item_with_mnemonic( menu_in_menu, "_Off", "RegionOff" );
2243 create_menu_item_with_mnemonic( menu_in_menu, "_Set XY", "RegionSetXY" );
2244 create_menu_item_with_mnemonic( menu_in_menu, "Set _Brush", "RegionSetBrush" );
2245 create_menu_item_with_mnemonic( menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection" );
2248 command_connect_accelerator( "CenterXYView" );
2250 return view_menu_item;
2253 ui::MenuItem create_selection_menu(){
2255 auto selection_menu_item = new_sub_menu_item_with_mnemonic( "M_odify" );
2256 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( selection_menu_item ) );
2257 if ( g_Layout_enableDetachableMenus.m_value ) {
2258 menu_tearoff( menu );
2262 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Components" );
2263 if ( g_Layout_enableDetachableMenus.m_value ) {
2264 menu_tearoff( menu_in_menu );
2266 create_check_menu_item_with_mnemonic( menu_in_menu, "_Edges", "DragEdges" );
2267 create_check_menu_item_with_mnemonic( menu_in_menu, "_Vertices", "DragVertices" );
2268 create_check_menu_item_with_mnemonic( menu_in_menu, "_Faces", "DragFaces" );
2271 menu_separator( menu );
2274 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Nudge" );
2275 if ( g_Layout_enableDetachableMenus.m_value ) {
2276 menu_tearoff( menu_in_menu );
2278 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Left", "SelectNudgeLeft" );
2279 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Right", "SelectNudgeRight" );
2280 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Up", "SelectNudgeUp" );
2281 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Down", "SelectNudgeDown" );
2284 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Rotate" );
2285 if ( g_Layout_enableDetachableMenus.m_value ) {
2286 menu_tearoff( menu_in_menu );
2288 create_menu_item_with_mnemonic( menu_in_menu, "Rotate X", "RotateSelectionX" );
2289 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Y", "RotateSelectionY" );
2290 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Z", "RotateSelectionZ" );
2293 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Flip" );
2294 if ( g_Layout_enableDetachableMenus.m_value ) {
2295 menu_tearoff( menu_in_menu );
2297 create_menu_item_with_mnemonic( menu_in_menu, "Flip _X", "MirrorSelectionX" );
2298 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Y", "MirrorSelectionY" );
2299 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Z", "MirrorSelectionZ" );
2301 menu_separator( menu );
2302 create_menu_item_with_mnemonic( menu, "Arbitrary rotation...", "ArbitraryRotation" );
2303 create_menu_item_with_mnemonic( menu, "Arbitrary scale...", "ArbitraryScale" );
2305 return selection_menu_item;
2308 ui::MenuItem create_bsp_menu(){
2310 auto bsp_menu_item = new_sub_menu_item_with_mnemonic( "_Build" );
2311 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( bsp_menu_item ) );
2313 if ( g_Layout_enableDetachableMenus.m_value ) {
2314 menu_tearoff( menu );
2317 create_menu_item_with_mnemonic( menu, "Customize...", "BuildMenuCustomize" );
2319 menu_separator( menu );
2321 Build_constructMenu( menu );
2325 return bsp_menu_item;
2328 ui::MenuItem create_grid_menu(){
2330 auto grid_menu_item = new_sub_menu_item_with_mnemonic( "_Grid" );
2331 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( grid_menu_item ) );
2332 if ( g_Layout_enableDetachableMenus.m_value ) {
2333 menu_tearoff( menu );
2336 Grid_constructMenu( menu );
2338 return grid_menu_item;
2341 ui::MenuItem create_misc_menu(){
2343 auto misc_menu_item = new_sub_menu_item_with_mnemonic( "M_isc" );
2344 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( misc_menu_item ) );
2345 if ( g_Layout_enableDetachableMenus.m_value ) {
2346 menu_tearoff( menu );
2350 create_menu_item_with_mnemonic( menu, "_Benchmark", makeCallbackF(GlobalCamera_Benchmark) );
2352 menu.add(create_colours_menu());
2354 create_menu_item_with_mnemonic( menu, "Find brush...", "FindBrush" );
2355 create_menu_item_with_mnemonic( menu, "Map Info...", "MapInfo" );
2356 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2357 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<void(), WXY_Print>());
2358 create_menu_item_with_mnemonic( menu, "_Background select", makeCallbackF(WXY_BackgroundSelect) );
2359 return misc_menu_item;
2362 ui::MenuItem create_entity_menu(){
2364 auto entity_menu_item = new_sub_menu_item_with_mnemonic( "E_ntity" );
2365 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( entity_menu_item ) );
2366 if ( g_Layout_enableDetachableMenus.m_value ) {
2367 menu_tearoff( menu );
2370 Entity_constructMenu( menu );
2372 return entity_menu_item;
2375 ui::MenuItem create_brush_menu(){
2377 auto brush_menu_item = new_sub_menu_item_with_mnemonic( "B_rush" );
2378 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( brush_menu_item ) );
2379 if ( g_Layout_enableDetachableMenus.m_value ) {
2380 menu_tearoff( menu );
2383 Brush_constructMenu( menu );
2385 return brush_menu_item;
2388 ui::MenuItem create_patch_menu(){
2390 auto patch_menu_item = new_sub_menu_item_with_mnemonic( "_Curve" );
2391 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( patch_menu_item ) );
2392 if ( g_Layout_enableDetachableMenus.m_value ) {
2393 menu_tearoff( menu );
2396 Patch_constructMenu( menu );
2398 return patch_menu_item;
2401 ui::MenuItem create_help_menu(){
2403 auto help_menu_item = new_sub_menu_item_with_mnemonic( "_Help" );
2404 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( help_menu_item ) );
2405 if ( g_Layout_enableDetachableMenus.m_value ) {
2406 menu_tearoff( menu );
2409 // create_menu_item_with_mnemonic( menu, "Manual", "OpenManual" );
2411 // this creates all the per-game drop downs for the game pack helps
2412 // it will take care of hooking the Sys_OpenURL calls etc.
2413 create_game_help_menu( menu );
2415 create_menu_item_with_mnemonic( menu, "Bug report", makeCallbackF(OpenBugReportURL) );
2416 create_menu_item_with_mnemonic( menu, "Shortcuts list", makeCallbackF(DoCommandListDlg) );
2417 create_menu_item_with_mnemonic( menu, "_About...", makeCallbackF(DoAbout) );
2419 return help_menu_item;
2422 ui::MenuBar create_main_menu( MainFrame::EViewStyle style ){
2423 auto menu_bar = ui::MenuBar::from( gtk_menu_bar_new() );
2426 menu_bar.add(create_file_menu());
2427 menu_bar.add(create_edit_menu());
2428 menu_bar.add(create_view_menu(style));
2429 menu_bar.add(create_selection_menu());
2430 menu_bar.add(create_bsp_menu());
2431 menu_bar.add(create_grid_menu());
2432 menu_bar.add(create_misc_menu());
2433 menu_bar.add(create_entity_menu());
2434 menu_bar.add(create_brush_menu());
2435 menu_bar.add(create_patch_menu());
2436 menu_bar.add(create_plugins_menu());
2437 menu_bar.add(create_help_menu());
2443 void PatchInspector_registerShortcuts(){
2444 command_connect_accelerator( "PatchInspector" );
2447 void Patch_registerShortcuts(){
2448 command_connect_accelerator( "InvertCurveTextureX" );
2449 command_connect_accelerator( "InvertCurveTextureY" );
2450 command_connect_accelerator( "PatchInsertInsertColumn" );
2451 command_connect_accelerator( "PatchInsertInsertRow" );
2452 command_connect_accelerator( "PatchDeleteLastColumn" );
2453 command_connect_accelerator( "PatchDeleteLastRow" );
2454 command_connect_accelerator( "NaturalizePatch" );
2455 //command_connect_accelerator("CapCurrentCurve");
2458 void Manipulators_registerShortcuts(){
2459 toggle_add_accelerator( "MouseRotate" );
2460 toggle_add_accelerator( "MouseTranslate" );
2461 toggle_add_accelerator( "MouseScale" );
2462 toggle_add_accelerator( "MouseDrag" );
2463 toggle_add_accelerator( "ToggleClipper" );
2466 void TexdefNudge_registerShortcuts(){
2467 command_connect_accelerator( "TexRotateClock" );
2468 command_connect_accelerator( "TexRotateCounter" );
2469 command_connect_accelerator( "TexScaleUp" );
2470 command_connect_accelerator( "TexScaleDown" );
2471 command_connect_accelerator( "TexScaleLeft" );
2472 command_connect_accelerator( "TexScaleRight" );
2473 command_connect_accelerator( "TexShiftUp" );
2474 command_connect_accelerator( "TexShiftDown" );
2475 command_connect_accelerator( "TexShiftLeft" );
2476 command_connect_accelerator( "TexShiftRight" );
2479 void SelectNudge_registerShortcuts(){
2480 command_connect_accelerator( "MoveSelectionDOWN" );
2481 command_connect_accelerator( "MoveSelectionUP" );
2482 //command_connect_accelerator("SelectNudgeLeft");
2483 //command_connect_accelerator("SelectNudgeRight");
2484 //command_connect_accelerator("SelectNudgeUp");
2485 //command_connect_accelerator("SelectNudgeDown");
2488 void SnapToGrid_registerShortcuts(){
2489 command_connect_accelerator( "SnapToGrid" );
2492 void SelectByType_registerShortcuts(){
2493 command_connect_accelerator( "SelectAllOfType" );
2496 void SurfaceInspector_registerShortcuts(){
2497 command_connect_accelerator( "FitTexture" );
2501 void register_shortcuts(){
2502 PatchInspector_registerShortcuts();
2503 Patch_registerShortcuts();
2504 Grid_registerShortcuts();
2505 XYWnd_registerShortcuts();
2506 CamWnd_registerShortcuts();
2507 Manipulators_registerShortcuts();
2508 SurfaceInspector_registerShortcuts();
2509 TexdefNudge_registerShortcuts();
2510 SelectNudge_registerShortcuts();
2511 SnapToGrid_registerShortcuts();
2512 SelectByType_registerShortcuts();
2515 void File_constructToolbar( ui::Toolbar toolbar ){
2516 toolbar_append_button( toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap" );
2517 toolbar_append_button( toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap" );
2520 void UndoRedo_constructToolbar( ui::Toolbar toolbar ){
2521 toolbar_append_button( toolbar, "Undo (CTRL + Z)", "undo.png", "Undo" );
2522 toolbar_append_button( toolbar, "Redo (CTRL + Y)", "redo.png", "Redo" );
2525 void RotateFlip_constructToolbar( ui::Toolbar toolbar ){
2526 toolbar_append_button( toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX" );
2527 toolbar_append_button( toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX" );
2528 toolbar_append_button( toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY" );
2529 toolbar_append_button( toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY" );
2530 toolbar_append_button( toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ" );
2531 toolbar_append_button( toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ" );
2534 void Select_constructToolbar( ui::Toolbar toolbar ){
2535 toolbar_append_button( toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching" );
2536 toolbar_append_button( toolbar, "Select inside", "selection_selectinside.png", "SelectInside" );
2539 void CSG_constructToolbar( ui::Toolbar toolbar ){
2540 toolbar_append_button( toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract" );
2541 toolbar_append_button( toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge" );
2542 toolbar_append_button( toolbar, "Make Hollow", "selection_makehollow.png", "CSGHollow" );
2543 toolbar_append_button( toolbar, "Make Room", "selection_makeroom.png", "CSGRoom" );
2546 void ComponentModes_constructToolbar( ui::Toolbar toolbar ){
2547 toolbar_append_toggle_button( toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices" );
2548 toolbar_append_toggle_button( toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges" );
2549 toolbar_append_toggle_button( toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces" );
2552 void Clipper_constructToolbar( ui::Toolbar toolbar ){
2554 toolbar_append_toggle_button( toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper" );
2557 void XYWnd_constructToolbar( ui::Toolbar toolbar ){
2558 toolbar_append_button( toolbar, "Change views", "view_change.png", "NextView" );
2561 void Manipulators_constructToolbar( ui::Toolbar toolbar ){
2562 toolbar_append_toggle_button( toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate" );
2563 toolbar_append_toggle_button( toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate" );
2564 toolbar_append_toggle_button( toolbar, "Scale", "select_mousescale.png", "MouseScale" );
2565 toolbar_append_toggle_button( toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag" );
2567 Clipper_constructToolbar( toolbar );
2570 ui::Toolbar create_main_toolbar( MainFrame::EViewStyle style ){
2571 auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
2572 gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL );
2573 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
2577 auto space = [&]() {
2578 auto btn = ui::ToolItem::from(gtk_separator_tool_item_new());
2583 File_constructToolbar( toolbar );
2587 UndoRedo_constructToolbar( toolbar );
2591 RotateFlip_constructToolbar( toolbar );
2595 Select_constructToolbar( toolbar );
2599 CSG_constructToolbar( toolbar );
2603 ComponentModes_constructToolbar( toolbar );
2605 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2608 XYWnd_constructToolbar( toolbar );
2613 CamWnd_constructToolbar( toolbar );
2617 Manipulators_constructToolbar( toolbar );
2619 if ( g_Layout_enablePatchToolbar.m_value ) {
2622 Patch_constructToolbar( toolbar );
2627 toolbar_append_toggle_button( toolbar, "Texture Lock (SHIFT +T)", "texture_lock.png", "TogTexLock" );
2631 /*auto g_view_entities_button =*/ toolbar_append_button( toolbar, "Entities (N)", "entities.png", "ToggleEntityInspector" );
2632 auto g_view_console_button = toolbar_append_button( toolbar, "Console (O)", "console.png", "ToggleConsole" );
2633 auto g_view_textures_button = toolbar_append_button( toolbar, "Texture Browser (T)", "texture_browser.png", "ToggleTextures" );
2634 // TODO: call light inspector
2635 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector");
2638 /*auto g_refresh_models_button =*/ toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" );
2641 // disable the console and texture button in the regular layouts
2642 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft ) {
2643 gtk_widget_set_sensitive( g_view_console_button , FALSE );
2644 gtk_widget_set_sensitive( g_view_textures_button , FALSE );
2650 ui::Widget create_main_statusbar( ui::Widget pStatusLabel[c_count_status] ){
2651 auto table = ui::Table( 1, c_count_status, FALSE );
2655 auto label = ui::Label( "Label" );
2656 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2657 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2659 table.attach(label, {0, 1, 0, 1});
2660 pStatusLabel[c_command_status] = ui::Widget(label );
2663 for (unsigned int i = 1; (int) i < c_count_status; ++i)
2665 auto frame = ui::Frame();
2667 table.attach(frame, {i, i + 1, 0, 1});
2668 gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
2670 auto label = ui::Label( "Label" );
2671 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END );
2672 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2673 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2676 pStatusLabel[i] = ui::Widget(label );
2679 return ui::Widget(table );
2685 WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" );
2687 class WindowFocusPrinter
2691 static gboolean frame_event( ui::Widget widget, GdkEvent* event, WindowFocusPrinter* self ){
2692 globalOutputStream() << self->m_name << " frame_event\n";
2695 static gboolean keys_changed( ui::Widget widget, WindowFocusPrinter* self ){
2696 globalOutputStream() << self->m_name << " keys_changed\n";
2699 static gboolean notify( ui::Window window, gpointer dummy, WindowFocusPrinter* self ){
2700 if ( gtk_window_is_active( window ) ) {
2701 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2705 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2710 WindowFocusPrinter( const char* name ) : m_name( name ){
2712 void connect( ui::Window toplevel_window ){
2713 toplevel_window.connect( "notify::has_toplevel_focus", G_CALLBACK( notify ), this );
2714 toplevel_window.connect( "notify::is_active", G_CALLBACK( notify ), this );
2715 toplevel_window.connect( "keys_changed", G_CALLBACK( keys_changed ), this );
2716 toplevel_window.connect( "frame_event", G_CALLBACK( frame_event ), this );
2720 WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" );
2724 class MainWindowActive
2726 static gboolean notify( ui::Window window, gpointer dummy, MainWindowActive* self ){
2727 if ( g_wait.m_window && gtk_window_is_active( window ) && !g_wait.m_window.visible() ) {
2728 g_wait.m_window.show();
2735 void connect( ui::Window toplevel_window ){
2736 toplevel_window.connect( "notify::is-active", G_CALLBACK( notify ), this );
2740 MainWindowActive g_MainWindowActive;
2742 SignalHandlerId XYWindowDestroyed_connect( const SignalHandler& handler ){
2743 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst( handler );
2746 void XYWindowDestroyed_disconnect( SignalHandlerId id ){
2747 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect( id );
2750 MouseEventHandlerId XYWindowMouseDown_connect( const MouseEventHandler& handler ){
2751 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst( handler );
2754 void XYWindowMouseDown_disconnect( MouseEventHandlerId id ){
2755 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect( id );
2758 // =============================================================================
2761 MainFrame* g_pParentWnd = 0;
2763 ui::Window MainFrame_getWindow()
2765 return g_pParentWnd ? g_pParentWnd->m_window : ui::Window{ui::null};
2768 std::vector<ui::Widget> g_floating_windows;
2770 MainFrame::MainFrame() : m_idleRedrawStatusText( RedrawStatusTextCaller( *this ) ){
2778 for (auto &n : m_pStatusLabel) {
2782 m_bSleeping = false;
2787 MainFrame::~MainFrame(){
2794 for ( std::vector<ui::Widget>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i )
2796 #ifndef WORKAROUND_MACOS_GTK2_DESTROY
2801 #ifndef WORKAROUND_MACOS_GTK2_DESTROY
2806 void MainFrame::SetActiveXY( XYWnd* p ){
2807 if ( m_pActiveXY ) {
2808 m_pActiveXY->SetActive( false );
2813 if ( m_pActiveXY ) {
2814 m_pActiveXY->SetActive( true );
2819 void MainFrame::ReleaseContexts(){
2822 m_pXYWnd->DestroyContext();
2825 m_pYZWnd->DestroyContext();
2828 m_pXZWnd->DestroyContext();
2831 m_pCamWnd->DestroyContext();
2834 m_pTexWnd->DestroyContext();
2837 m_pZWnd->DestroyContext();
2842 void MainFrame::CreateContexts(){
2845 m_pCamWnd->CreateContext();
2848 m_pXYWnd->CreateContext();
2851 m_pYZWnd->CreateContext();
2854 m_pXZWnd->CreateContext();
2857 m_pTexWnd->CreateContext();
2860 m_pZWnd->CreateContext();
2869 void MainFrame::OnSleep(){
2872 if ( m_bSleeping ) {
2873 // useful when trying to debug crashes in the sleep code
2874 globalOutputStream() << "Going into sleep mode..\n";
2876 globalOutputStream() << "Dispatching sleep msg...";
2877 DispatchRadiantMsg( RADIANT_SLEEP );
2878 globalOutputStream() << "Done.\n";
2880 gtk_window_iconify( m_window );
2881 GlobalSelectionSystem().setSelectedAll( false );
2883 GlobalShaderCache().unrealise();
2885 GlobalOpenGL_debugAssertNoErrors();
2886 ScreenUpdates_Disable();
2889 globalOutputStream() << "Releasing contexts...";
2891 globalOutputStream() << "Done.\n";
2895 globalOutputStream() << "Waking up\n";
2897 gtk_window_deiconify( m_window );
2900 globalOutputStream() << "Creating contexts...";
2902 globalOutputStream() << "Done.\n";
2904 globalOutputStream() << "Making current on camera...";
2905 m_pCamWnd->MakeCurrent();
2906 globalOutputStream() << "Done.\n";
2908 globalOutputStream() << "Reloading shaders...";
2910 GlobalShaderCache().realise();
2911 globalOutputStream() << "Done.\n";
2913 ScreenUpdates_Enable();
2915 globalOutputStream() << "Dispatching wake msg...";
2916 DispatchRadiantMsg( RADIANT_WAKEUP );
2917 globalOutputStream() << "Done\n";
2923 ui::Window create_splash(){
2924 auto window = ui::Window( ui::window_type::TOP );
2925 gtk_window_set_decorated(window, false);
2926 gtk_window_set_resizable(window, false);
2927 gtk_window_set_modal(window, true);
2928 gtk_window_set_default_size( window, -1, -1 );
2929 gtk_window_set_position( window, GTK_WIN_POS_CENTER );
2930 gtk_container_set_border_width(window, 0);
2932 auto image = new_local_image( "splash.png" );
2936 window.dimensions(-1, -1);
2942 static ui::Window splash_screen{ui::null};
2945 splash_screen = create_splash();
2951 splash_screen.destroy();
2954 WindowPositionTracker g_posCamWnd;
2955 WindowPositionTracker g_posXYWnd;
2956 WindowPositionTracker g_posXZWnd;
2957 WindowPositionTracker g_posYZWnd;
2959 static gint mainframe_delete( ui::Widget widget, GdkEvent *event, gpointer data ){
2960 if ( ConfirmModified( "Exit " RADIANT_NAME ) ) {
2967 PanedState g_single_hpaned = { 0.75f, -1, };
2968 PanedState g_single_vpaned = { 0.75f, -1, };
2970 void MainFrame::Create(){
2971 ui::Window window = ui::Window( ui::window_type::TOP );
2973 GlobalWindowObservers_connectTopLevel( window );
2975 gtk_window_set_transient_for( splash_screen, window );
2977 #if !GDEF_OS_WINDOWS
2979 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
2980 if ( pixbuf != 0 ) {
2981 gtk_window_set_icon( window, pixbuf );
2982 g_object_unref( pixbuf );
2987 gtk_widget_add_events( window , GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
2988 window.connect( "delete_event", G_CALLBACK( mainframe_delete ), this );
2990 m_position_tracker.connect( window );
2993 g_mainframeWidgetFocusPrinter.connect( window );
2994 g_mainframeFocusPrinter.connect( window );
2997 g_MainWindowActive.connect( window );
2999 GetPlugInMgr().Init( window );
3001 auto vbox = ui::VBox( FALSE, 0 );
3005 global_accel_connect_window( window );
3007 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
3009 register_shortcuts();
3011 auto main_menu = create_main_menu( CurrentStyle() );
3012 vbox.pack_start( main_menu, FALSE, FALSE, 0 );
3014 auto main_toolbar = create_main_toolbar( CurrentStyle() );
3015 vbox.pack_start( main_toolbar, FALSE, FALSE, 0 );
3017 auto plugin_toolbar = create_plugin_toolbar();
3018 if ( !g_Layout_enablePluginToolbar.m_value ) {
3019 plugin_toolbar.hide();
3022 if ( g_Layout_enableFilterToolbar.m_value ) {
3023 auto space = [&]() {
3024 auto btn = gtk_separator_tool_item_new();
3025 gtk_widget_show(GTK_WIDGET(btn));
3026 gtk_container_add(GTK_CONTAINER(plugin_toolbar), GTK_WIDGET(btn));
3030 toolbar_append_toggle_button( plugin_toolbar, "World (ALT + 1)", "f-world.bmp", "FilterWorldBrushes" );
3031 toolbar_append_toggle_button( plugin_toolbar, "Details (CTRL + D)", "f-details.bmp", "FilterDetails" );
3032 toolbar_append_toggle_button( plugin_toolbar, "Structural (CTRL + SHIFT + D)", "f-structural.bmp", "FilterStructural" );
3033 toolbar_append_toggle_button( plugin_toolbar, "Patches (CTRL + P)", "patch_wireframe.png", "FilterPatches" );
3035 toolbar_append_toggle_button( plugin_toolbar, "Areaportals (ALT + 3)", "f-areaportal.bmp", "FilterAreaportals" );
3036 toolbar_append_toggle_button( plugin_toolbar, "Translucent (ALT + 4)", "f-translucent.bmp", "FilterTranslucent" );
3037 toolbar_append_toggle_button( plugin_toolbar, "Liquids (ALT + 5)", "f-liquids.bmp", "FilterLiquids" );
3038 toolbar_append_toggle_button( plugin_toolbar, "Caulk (ALT + 6)", "f-caulk.bmp", "FilterCaulk" );
3039 toolbar_append_toggle_button( plugin_toolbar, "Clips (ALT + 7)", "f-clip.bmp", "FilterClips" );
3040 toolbar_append_toggle_button( plugin_toolbar, "HintsSkips (CTRL + H)", "f-hint.bmp", "FilterHintsSkips" );
3041 //toolbar_append_toggle_button( plugin_toolbar, "Paths (ALT + 8)", "texture_lock.bmp", "FilterPaths" );
3043 toolbar_append_toggle_button( plugin_toolbar, "Entities (ALT + 2)", "f-entities.bmp", "FilterEntities" );
3044 toolbar_append_toggle_button( plugin_toolbar, "Lights (ALT + 0)", "lightinspector.png", "FilterLights" );
3045 toolbar_append_toggle_button( plugin_toolbar, "Models (SHIFT + M)", "f-models.bmp", "FilterModels" );
3046 toolbar_append_toggle_button( plugin_toolbar, "Triggers (CTRL + SHIFT + T)", "f-triggers.bmp", "FilterTriggers" );
3047 toolbar_append_toggle_button( plugin_toolbar, "Decals (SHIFT + D)", "f-decals.bmp", "FilterDecals" );
3049 toolbar_append_button( plugin_toolbar, "InvertFilters", "f-invert.bmp", "InvertFilters" );
3050 toolbar_append_button( plugin_toolbar, "ResetFilters", "f-reset.bmp", "ResetFilters" );
3052 vbox.pack_start( plugin_toolbar, FALSE, FALSE, 0 );
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);
3090 vbox.pack_start( hsplit, TRUE, TRUE, 0 );
3093 ui::Widget vsplit = ui::VPaned(ui::New);
3096 ui::Widget vsplit2 = ui::VPaned(ui::New);
3099 if ( CurrentStyle() == eRegular ){
3100 gtk_paned_add1( GTK_PANED( hsplit ), vsplit );
3101 gtk_paned_add2( GTK_PANED( hsplit ), vsplit2 );
3104 gtk_paned_add2( GTK_PANED( hsplit ), vsplit );
3105 gtk_paned_add1( GTK_PANED( hsplit ), vsplit2 );
3109 ui::Widget console_window = Console_constructWindow( window );
3110 gtk_paned_pack2( GTK_PANED( vsplit ), console_window, FALSE, TRUE );
3113 m_pXYWnd = new XYWnd();
3114 m_pXYWnd->SetViewType( XY );
3115 ui::Widget xy_window = ui::Widget(create_framed_widget( m_pXYWnd->GetWidget( ) ));
3117 gtk_paned_add1( GTK_PANED( vsplit ), xy_window );
3120 m_pCamWnd = NewCamWnd();
3121 GlobalCamera_setCamWnd( *m_pCamWnd );
3122 CamWnd_setParent( *m_pCamWnd, window );
3123 auto camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3125 gtk_paned_add1( GTK_PANED( vsplit2 ), camera_window );
3128 auto texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
3130 gtk_paned_add2( GTK_PANED( vsplit2 ), texture_window );
3135 gtk_paned_set_position( GTK_PANED( m_vSplit ), g_layout_globals.nXYHeight );
3137 if ( CurrentStyle() == eRegular ) {
3138 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nXYWidth );
3142 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nCamWidth );
3145 gtk_paned_set_position( GTK_PANED( m_vSplit2 ), g_layout_globals.nCamHeight );
3147 else if ( CurrentStyle() == eFloating )
3150 ui::Window window = ui::Window(create_persistent_floating_window( "Camera", m_window ));
3151 global_accel_connect_window( window );
3152 g_posCamWnd.connect( window );
3156 m_pCamWnd = NewCamWnd();
3157 GlobalCamera_setCamWnd( *m_pCamWnd );
3160 auto frame = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3163 CamWnd_setParent( *m_pCamWnd, window );
3165 WORKAROUND_GOBJECT_SET_GLWIDGET( window, CamWnd_getWidget( *m_pCamWnd ) );
3167 g_floating_windows.push_back( window );
3171 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XY ), m_window ));
3172 global_accel_connect_window( window );
3173 g_posXYWnd.connect( window );
3175 m_pXYWnd = new XYWnd();
3176 m_pXYWnd->m_parent = window;
3177 m_pXYWnd->SetViewType( XY );
3181 auto frame = create_framed_widget( m_pXYWnd->GetWidget() );
3184 XY_Top_Shown_Construct( window );
3186 WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXYWnd->GetWidget() );
3188 g_floating_windows.push_back( window );
3192 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XZ ), m_window ));
3193 global_accel_connect_window( window );
3194 g_posXZWnd.connect( window );
3196 m_pXZWnd = new XYWnd();
3197 m_pXZWnd->m_parent = window;
3198 m_pXZWnd->SetViewType( XZ );
3201 auto frame = create_framed_widget( m_pXZWnd->GetWidget() );
3205 XZ_Front_Shown_Construct( window );
3207 WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXZWnd->GetWidget() );
3209 g_floating_windows.push_back( window );
3213 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( YZ ), m_window ));
3214 global_accel_connect_window( window );
3215 g_posYZWnd.connect( window );
3217 m_pYZWnd = new XYWnd();
3218 m_pYZWnd->m_parent = window;
3219 m_pYZWnd->SetViewType( YZ );
3222 auto frame = create_framed_widget( m_pYZWnd->GetWidget() );
3226 YZ_Side_Shown_Construct( window );
3228 WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pYZWnd->GetWidget() );
3230 g_floating_windows.push_back( window );
3234 auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
3235 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3237 WORKAROUND_GOBJECT_SET_GLWIDGET( GroupDialog_getWindow(), TextureBrowser_getGLWidget() );
3242 else if ( CurrentStyle() == eSplit )
3244 m_pCamWnd = NewCamWnd();
3245 GlobalCamera_setCamWnd( *m_pCamWnd );
3246 CamWnd_setParent( *m_pCamWnd, window );
3248 ui::Widget camera = CamWnd_getWidget( *m_pCamWnd );
3250 m_pYZWnd = new XYWnd();
3251 m_pYZWnd->SetViewType( YZ );
3253 ui::Widget yz = m_pYZWnd->GetWidget();
3255 m_pXYWnd = new XYWnd();
3256 m_pXYWnd->SetViewType( XY );
3258 ui::Widget xy = m_pXYWnd->GetWidget();
3260 m_pXZWnd = new XYWnd();
3261 m_pXZWnd->SetViewType( XZ );
3263 ui::Widget xz = m_pXZWnd->GetWidget();
3265 auto split = create_split_views( camera, yz, xy, xz );
3266 vbox.pack_start( split, TRUE, TRUE, 0 );
3269 auto frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
3270 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3272 WORKAROUND_GOBJECT_SET_GLWIDGET( window, TextureBrowser_getGLWidget() );
3275 else // single window
3277 m_pCamWnd = NewCamWnd();
3278 GlobalCamera_setCamWnd( *m_pCamWnd );
3279 CamWnd_setParent( *m_pCamWnd, window );
3281 ui::Widget camera = CamWnd_getWidget( *m_pCamWnd );
3283 m_pYZWnd = new XYWnd();
3284 m_pYZWnd->SetViewType( YZ );
3286 ui::Widget yz = m_pYZWnd->GetWidget();
3288 m_pXYWnd = new XYWnd();
3289 m_pXYWnd->SetViewType( XY );
3291 ui::Widget xy = m_pXYWnd->GetWidget();
3293 m_pXZWnd = new XYWnd();
3294 m_pXZWnd->SetViewType( XZ );
3296 ui::Widget xz = m_pXZWnd->GetWidget();
3298 ui::Widget hsplit = ui::HPaned(ui::New);
3299 vbox.pack_start( hsplit, TRUE, TRUE, 0 );
3302 ui::Widget split = create_split_views( camera, yz, xy, xz );
3304 ui::Widget vsplit = ui::VPaned(ui::New);
3308 ui::Widget texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
3311 ui::Widget console_window = create_framed_widget( Console_constructWindow( window ) );
3313 gtk_paned_add1( GTK_PANED( hsplit ), split );
3314 gtk_paned_add2( GTK_PANED( hsplit ), vsplit );
3316 gtk_paned_add1( GTK_PANED( vsplit ), texture_window );
3317 gtk_paned_add2( GTK_PANED( vsplit ), console_window );
3319 hsplit.connect( "size_allocate", G_CALLBACK( hpaned_allocate ), &g_single_hpaned );
3320 hsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_single_hpaned );
3322 vsplit.connect( "size_allocate", G_CALLBACK( vpaned_allocate ), &g_single_vpaned );
3323 vsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_single_vpaned );
3326 EntityList_constructWindow( window );
3327 PreferencesDialog_constructWindow( window );
3328 FindTextureDialog_constructWindow( window );
3329 SurfaceInspector_constructWindow( window );
3330 PatchInspector_constructWindow( window );
3332 SetActiveXY( m_pXYWnd );
3334 AddGridChangeCallback( SetGridStatusCaller( *this ) );
3335 AddGridChangeCallback( ReferenceCaller<MainFrame, void(), XY_UpdateAllWindows>( *this ) );
3337 g_defaultToolMode = DragMode;
3338 g_defaultToolMode();
3339 SetStatusText( m_command_status, c_TranslateMode_status );
3341 EverySecondTimer_enable();
3343 //GlobalShortcuts_reportUnregistered();
3346 void MainFrame::SaveWindowInfo(){
3347 if ( !FloatingGroupDialog() ) {
3348 g_layout_globals.nXYHeight = gtk_paned_get_position( GTK_PANED( m_vSplit ) );
3350 if ( CurrentStyle() != eRegular ) {
3351 g_layout_globals.nCamWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3355 g_layout_globals.nXYWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3358 g_layout_globals.nCamHeight = gtk_paned_get_position( GTK_PANED( m_vSplit2 ) );
3361 g_layout_globals.m_position = m_position_tracker.getPosition();
3363 g_layout_globals.nState = gdk_window_get_state( gtk_widget_get_window(m_window ) );
3366 void MainFrame::Shutdown(){
3367 EverySecondTimer_disable();
3369 EntityList_destroyWindow();
3378 TextureBrowser_destroyWindow();
3380 DeleteCamWnd( m_pCamWnd );
3383 PreferencesDialog_destroyWindow();
3384 SurfaceInspector_destroyWindow();
3385 FindTextureDialog_destroyWindow();
3386 PatchInspector_destroyWindow();
3388 g_DbgDlg.destroyWindow();
3390 // destroying group-dialog last because it may contain texture-browser
3391 GroupDialog_destroyWindow();
3394 void MainFrame::RedrawStatusText(){
3395 ui::Label::from(m_pStatusLabel[c_command_status]).text(m_command_status.c_str());
3396 ui::Label::from(m_pStatusLabel[c_position_status]).text(m_position_status.c_str());
3397 ui::Label::from(m_pStatusLabel[c_brushcount_status]).text(m_brushcount_status.c_str());
3398 ui::Label::from(m_pStatusLabel[c_texture_status]).text(m_texture_status.c_str());
3399 ui::Label::from(m_pStatusLabel[c_grid_status]).text(m_grid_status.c_str());
3402 void MainFrame::UpdateStatusText(){
3403 m_idleRedrawStatusText.queueDraw();
3406 void MainFrame::SetStatusText( CopiedString& status_text, const char* pText ){
3407 status_text = pText;
3411 void Sys_Status( const char* status ){
3412 if ( g_pParentWnd != nullptr ) {
3413 g_pParentWnd->SetStatusText( g_pParentWnd->m_command_status, status );
3417 int getRotateIncrement(){
3418 return static_cast<int>( g_si_globals.rotate );
3421 int getFarClipDistance(){
3422 return g_camwindow_globals.m_nCubicScale;
3425 float ( *GridStatus_getGridSize )() = GetGridSize;
3427 int ( *GridStatus_getRotateIncrement )() = getRotateIncrement;
3429 int ( *GridStatus_getFarClipDistance )() = getFarClipDistance;
3431 bool ( *GridStatus_getTextureLockEnabled )();
3433 void MainFrame::SetGridStatus(){
3434 StringOutputStream status( 64 );
3435 const char* lock = ( GridStatus_getTextureLockEnabled() ) ? "ON" : "OFF";
3436 status << ( GetSnapGridSize() > 0 ? "G:" : "g:" ) << GridStatus_getGridSize()
3437 << " R:" << GridStatus_getRotateIncrement()
3438 << " C:" << GridStatus_getFarClipDistance()
3440 SetStatusText( m_grid_status, status.c_str() );
3443 void GridStatus_onTextureLockEnabledChanged(){
3444 if ( g_pParentWnd != nullptr ) {
3445 g_pParentWnd->SetGridStatus();
3449 void GlobalGL_sharedContextCreated(){
3450 GLFont *g_font = NULL;
3452 // report OpenGL information
3453 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) << "\n";
3454 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) << "\n";
3455 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) << "\n";
3456 const auto extensions = reinterpret_cast<const char*>( glGetString(GL_EXTENSIONS ) );
3457 globalOutputStream() << "GL_EXTENSIONS: " << (extensions ? extensions : "") << "\n";
3459 QGL_sharedContextCreated( GlobalOpenGL() );
3461 ShaderCache_extensionsInitialised();
3463 GlobalShaderCache().realise();
3467 /* win32 is dodgy here, just use courier new then */
3468 g_font = glfont_create( "arial 9" );
3470 auto settings = gtk_settings_get_default();
3472 g_object_get( settings, "gtk-font-name", &fontname, NULL );
3473 g_font = glfont_create( fontname );
3476 GlobalOpenGL().m_font = g_font;
3479 void GlobalGL_sharedContextDestroyed(){
3480 Textures_Unrealise();
3481 GlobalShaderCache().unrealise();
3483 QGL_sharedContextDestroyed( GlobalOpenGL() );
3487 void Layout_constructPreferences( PreferencesPage& page ){
3489 const char* layouts[] = { "window1.png", "window2.png", "window3.png", "window4.png", "window5.png" };
3490 page.appendRadioIcons(
3492 STRING_ARRAY_RANGE( layouts ),
3493 make_property( g_Layout_viewStyle )
3496 page.appendCheckBox(
3497 "", "Detachable Menus",
3498 make_property( g_Layout_enableDetachableMenus )
3500 if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) {
3501 page.appendCheckBox(
3502 "", "Patch Toolbar",
3503 make_property( g_Layout_enablePatchToolbar )
3506 page.appendCheckBox(
3507 "", "Plugin Toolbar",
3508 make_property( g_Layout_enablePluginToolbar )
3510 page.appendCheckBox(
3511 "", "Filter Toolbar",
3512 make_property( g_Layout_enableFilterToolbar )
3516 void Layout_constructPage( PreferenceGroup& group ){
3517 PreferencesPage page( group.createPage( "Layout", "Layout Preferences" ) );
3518 Layout_constructPreferences( page );
3521 void Layout_registerPreferencesPage(){
3522 PreferencesDialog_addInterfacePage( makeCallbackF(Layout_constructPage) );
3525 #include "preferencesystem.h"
3526 #include "stringio.h"
3527 #include "transformpath/transformpath.h"
3529 void MainFrame_Construct(){
3530 GlobalCommands_insert( "OpenManual", makeCallbackF(OpenHelpURL), Accelerator( GDK_KEY_F1 ) );
3532 GlobalCommands_insert( "Sleep", makeCallbackF(thunk_OnSleep), Accelerator( 'P', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3533 GlobalCommands_insert( "NewMap", makeCallbackF(NewMap) );
3534 GlobalCommands_insert( "OpenMap", makeCallbackF(OpenMap), Accelerator( 'O', (GdkModifierType)GDK_CONTROL_MASK ) );
3535 GlobalCommands_insert( "ImportMap", makeCallbackF(ImportMap) );
3536 GlobalCommands_insert( "SaveMap", makeCallbackF(SaveMap), Accelerator( 'S', (GdkModifierType)GDK_CONTROL_MASK ) );
3537 GlobalCommands_insert( "SaveMapAs", makeCallbackF(SaveMapAs) );
3538 GlobalCommands_insert( "ExportSelected", makeCallbackF(ExportMap) );
3539 GlobalCommands_insert( "SaveRegion", makeCallbackF(SaveRegion) );
3540 GlobalCommands_insert( "RefreshReferences", makeCallbackF(VFS_Refresh) );
3541 GlobalCommands_insert( "ProjectSettings", makeCallbackF(DoProjectSettings) );
3542 GlobalCommands_insert( "Exit", makeCallbackF(Exit) );
3544 GlobalCommands_insert( "Undo", makeCallbackF(Undo), Accelerator( 'Z', (GdkModifierType)GDK_CONTROL_MASK ) );
3545 GlobalCommands_insert( "Redo", makeCallbackF(Redo), Accelerator( 'Y', (GdkModifierType)GDK_CONTROL_MASK ) );
3546 GlobalCommands_insert( "Copy", makeCallbackF(Copy), Accelerator( 'C', (GdkModifierType)GDK_CONTROL_MASK ) );
3547 GlobalCommands_insert( "Paste", makeCallbackF(Paste), Accelerator( 'V', (GdkModifierType)GDK_CONTROL_MASK ) );
3548 GlobalCommands_insert( "PasteToCamera", makeCallbackF(PasteToCamera), Accelerator( 'V', (GdkModifierType)GDK_MOD1_MASK ) );
3549 GlobalCommands_insert( "CloneSelection", makeCallbackF(Selection_Clone), Accelerator( GDK_KEY_space ) );
3550 GlobalCommands_insert( "CloneSelectionAndMakeUnique", makeCallbackF(Selection_Clone_MakeUnique), Accelerator( GDK_KEY_space, (GdkModifierType)GDK_SHIFT_MASK ) );
3551 GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) );
3552 GlobalCommands_insert( "ParentSelection", makeCallbackF(Scene_parentSelected) );
3553 GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) );
3554 GlobalCommands_insert( "InvertSelection", makeCallbackF(Select_Invert), Accelerator( 'I' ) );
3555 GlobalCommands_insert( "SelectInside", makeCallbackF(Select_Inside) );
3556 GlobalCommands_insert( "SelectTouching", makeCallbackF(Select_Touching) );
3557 GlobalCommands_insert( "ExpandSelectionToEntities", makeCallbackF(Scene_ExpandSelectionToEntities), Accelerator( 'E', (GdkModifierType)( GDK_MOD1_MASK | GDK_CONTROL_MASK ) ) );
3558 GlobalCommands_insert( "Preferences", makeCallbackF(PreferencesDialog_showDialog), Accelerator( 'P' ) );
3560 GlobalCommands_insert( "ToggleConsole", makeCallbackF(Console_ToggleShow), Accelerator( 'O' ) );
3561 GlobalCommands_insert( "ToggleEntityInspector", makeCallbackF(EntityInspector_ToggleShow), Accelerator( 'N' ) );
3562 GlobalCommands_insert( "EntityList", makeCallbackF(EntityList_toggleShown), Accelerator( 'L' ) );
3564 GlobalCommands_insert( "ShowHidden", makeCallbackF(Select_ShowAllHidden), Accelerator( 'H', (GdkModifierType)GDK_SHIFT_MASK ) );
3565 GlobalCommands_insert( "HideSelected", makeCallbackF(HideSelected), Accelerator( 'H' ) );
3567 GlobalToggles_insert( "DragVertices", makeCallbackF(SelectVertexMode), ToggleItem::AddCallbackCaller( g_vertexMode_button ), Accelerator( 'V' ) );
3568 GlobalToggles_insert( "DragEdges", makeCallbackF(SelectEdgeMode), ToggleItem::AddCallbackCaller( g_edgeMode_button ), Accelerator( 'E' ) );
3569 GlobalToggles_insert( "DragFaces", makeCallbackF(SelectFaceMode), ToggleItem::AddCallbackCaller( g_faceMode_button ), Accelerator( 'F' ) );
3571 GlobalCommands_insert( "MirrorSelectionX", makeCallbackF(Selection_Flipx) );
3572 GlobalCommands_insert( "RotateSelectionX", makeCallbackF(Selection_Rotatex) );
3573 GlobalCommands_insert( "MirrorSelectionY", makeCallbackF(Selection_Flipy) );
3574 GlobalCommands_insert( "RotateSelectionY", makeCallbackF(Selection_Rotatey) );
3575 GlobalCommands_insert( "MirrorSelectionZ", makeCallbackF(Selection_Flipz) );
3576 GlobalCommands_insert( "RotateSelectionZ", makeCallbackF(Selection_Rotatez) );
3578 GlobalCommands_insert( "ArbitraryRotation", makeCallbackF(DoRotateDlg) );
3579 GlobalCommands_insert( "ArbitraryScale", makeCallbackF(DoScaleDlg) );
3581 GlobalCommands_insert( "BuildMenuCustomize", makeCallbackF(DoBuildMenu) );
3583 GlobalCommands_insert( "FindBrush", makeCallbackF(DoFind) );
3585 GlobalCommands_insert( "MapInfo", makeCallbackF(DoMapInfo), Accelerator( 'M' ) );
3588 GlobalToggles_insert( "ToggleClipper", makeCallbackF(ClipperMode), ToggleItem::AddCallbackCaller( g_clipper_button ), Accelerator( 'X' ) );
3590 GlobalToggles_insert( "MouseTranslate", makeCallbackF(TranslateMode), ToggleItem::AddCallbackCaller( g_translatemode_button ), Accelerator( 'W' ) );
3591 GlobalToggles_insert( "MouseRotate", makeCallbackF(RotateMode), ToggleItem::AddCallbackCaller( g_rotatemode_button ), Accelerator( 'R' ) );
3592 GlobalToggles_insert( "MouseScale", makeCallbackF(ScaleMode), ToggleItem::AddCallbackCaller( g_scalemode_button ) );
3593 GlobalToggles_insert( "MouseDrag", makeCallbackF(DragMode), ToggleItem::AddCallbackCaller( g_dragmode_button ), Accelerator( 'Q' ) );
3595 GlobalCommands_insert( "ColorSchemeOriginal", makeCallbackF(ColorScheme_Original) );
3596 GlobalCommands_insert( "ColorSchemeQER", makeCallbackF(ColorScheme_QER) );
3597 GlobalCommands_insert( "ColorSchemeBlackAndGreen", makeCallbackF(ColorScheme_Black) );
3598 GlobalCommands_insert( "ColorSchemeYdnar", makeCallbackF(ColorScheme_Ydnar) );
3599 GlobalCommands_insert("ColorSchemeAdwaitaDark", makeCallbackF(ColorScheme_AdwaitaDark));
3600 GlobalCommands_insert( "ChooseTextureBackgroundColor", makeCallback( g_ColoursMenu.m_textureback ) );
3601 GlobalCommands_insert( "ChooseGridBackgroundColor", makeCallback( g_ColoursMenu.m_xyback ) );
3602 GlobalCommands_insert( "ChooseGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor ) );
3603 GlobalCommands_insert( "ChooseGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor ) );
3604 GlobalCommands_insert( "ChooseSmallGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor_alt ) );
3605 GlobalCommands_insert( "ChooseSmallGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor_alt ) );
3606 GlobalCommands_insert( "ChooseGridTextColor", makeCallback( g_ColoursMenu.m_gridtext ) );
3607 GlobalCommands_insert( "ChooseGridBlockColor", makeCallback( g_ColoursMenu.m_gridblock ) );
3608 GlobalCommands_insert( "ChooseBrushColor", makeCallback( g_ColoursMenu.m_brush ) );
3609 GlobalCommands_insert( "ChooseCameraBackgroundColor", makeCallback( g_ColoursMenu.m_cameraback ) );
3610 GlobalCommands_insert( "ChooseSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush ) );
3611 GlobalCommands_insert( "ChooseCameraSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush3d ) );
3612 GlobalCommands_insert( "ChooseClipperColor", makeCallback( g_ColoursMenu.m_clipper ) );
3613 GlobalCommands_insert( "ChooseOrthoViewNameColor", makeCallback( g_ColoursMenu.m_viewname ) );
3616 GlobalCommands_insert( "CSGSubtract", makeCallbackF(CSG_Subtract), Accelerator( 'U', (GdkModifierType)GDK_SHIFT_MASK ) );
3617 GlobalCommands_insert( "CSGMerge", makeCallbackF(CSG_Merge), Accelerator( 'U', (GdkModifierType) GDK_CONTROL_MASK ) );
3618 GlobalCommands_insert( "CSGHollow", makeCallbackF(CSG_MakeHollow) );
3619 GlobalCommands_insert( "CSGRoom", makeCallbackF(CSG_MakeRoom) );
3621 Grid_registerCommands();
3623 GlobalCommands_insert( "SnapToGrid", makeCallbackF(Selection_SnapToGrid), Accelerator( 'G', (GdkModifierType)GDK_CONTROL_MASK ) );
3625 GlobalCommands_insert( "SelectAllOfType", makeCallbackF(Select_AllOfType), Accelerator( 'A', (GdkModifierType)GDK_SHIFT_MASK ) );
3627 GlobalCommands_insert( "TexRotateClock", makeCallbackF(Texdef_RotateClockwise), Accelerator( GDK_KEY_Next, (GdkModifierType)GDK_SHIFT_MASK ) );
3628 GlobalCommands_insert( "TexRotateCounter", makeCallbackF(Texdef_RotateAntiClockwise), Accelerator( GDK_KEY_Prior, (GdkModifierType)GDK_SHIFT_MASK ) );
3629 GlobalCommands_insert( "TexScaleUp", makeCallbackF(Texdef_ScaleUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_CONTROL_MASK ) );
3630 GlobalCommands_insert( "TexScaleDown", makeCallbackF(Texdef_ScaleDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_CONTROL_MASK ) );
3631 GlobalCommands_insert( "TexScaleLeft", makeCallbackF(Texdef_ScaleLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_CONTROL_MASK ) );
3632 GlobalCommands_insert( "TexScaleRight", makeCallbackF(Texdef_ScaleRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_CONTROL_MASK ) );
3633 GlobalCommands_insert( "TexShiftUp", makeCallbackF(Texdef_ShiftUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_SHIFT_MASK ) );
3634 GlobalCommands_insert( "TexShiftDown", makeCallbackF(Texdef_ShiftDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_SHIFT_MASK ) );
3635 GlobalCommands_insert( "TexShiftLeft", makeCallbackF(Texdef_ShiftLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_SHIFT_MASK ) );
3636 GlobalCommands_insert( "TexShiftRight", makeCallbackF(Texdef_ShiftRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_SHIFT_MASK ) );
3638 GlobalCommands_insert( "MoveSelectionDOWN", makeCallbackF(Selection_MoveDown), Accelerator( GDK_KEY_KP_Subtract ) );
3639 GlobalCommands_insert( "MoveSelectionUP", makeCallbackF(Selection_MoveUp), Accelerator( GDK_KEY_KP_Add ) );
3641 GlobalCommands_insert( "SelectNudgeLeft", makeCallbackF(Selection_NudgeLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_MOD1_MASK ) );
3642 GlobalCommands_insert( "SelectNudgeRight", makeCallbackF(Selection_NudgeRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_MOD1_MASK ) );
3643 GlobalCommands_insert( "SelectNudgeUp", makeCallbackF(Selection_NudgeUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_MOD1_MASK ) );
3644 GlobalCommands_insert( "SelectNudgeDown", makeCallbackF(Selection_NudgeDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_MOD1_MASK ) );
3646 Patch_registerCommands();
3647 XYShow_registerCommands();
3649 typedef FreeCaller<void(const Selectable&), ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3650 GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() );
3652 GlobalPreferenceSystem().registerPreference( "DetachableMenus", make_property_string( g_Layout_enableDetachableMenus.m_latched ) );
3653 GlobalPreferenceSystem().registerPreference( "PatchToolBar", make_property_string( g_Layout_enablePatchToolbar.m_latched ) );
3654 GlobalPreferenceSystem().registerPreference( "PluginToolBar", make_property_string( g_Layout_enablePluginToolbar.m_latched ) );
3655 GlobalPreferenceSystem().registerPreference( "FilterToolBar", make_property_string( g_Layout_enableFilterToolbar.m_latched ) );
3656 GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", make_property_string( g_Layout_viewStyle.m_latched ) );
3657 GlobalPreferenceSystem().registerPreference( "XYHeight", make_property_string( g_layout_globals.nXYHeight ) );
3658 GlobalPreferenceSystem().registerPreference( "XYWidth", make_property_string( g_layout_globals.nXYWidth ) );
3659 GlobalPreferenceSystem().registerPreference( "CamWidth", make_property_string( g_layout_globals.nCamWidth ) );
3660 GlobalPreferenceSystem().registerPreference( "CamHeight", make_property_string( g_layout_globals.nCamHeight ) );
3662 GlobalPreferenceSystem().registerPreference( "State", make_property_string( g_layout_globals.nState ) );
3663 GlobalPreferenceSystem().registerPreference( "PositionX", make_property_string( g_layout_globals.m_position.x ) );
3664 GlobalPreferenceSystem().registerPreference( "PositionY", make_property_string( g_layout_globals.m_position.y ) );
3665 GlobalPreferenceSystem().registerPreference( "Width", make_property_string( g_layout_globals.m_position.w ) );
3666 GlobalPreferenceSystem().registerPreference( "Height", make_property_string( g_layout_globals.m_position.h ) );
3668 GlobalPreferenceSystem().registerPreference( "CamWnd", make_property<WindowPositionTracker_String>(g_posCamWnd) );
3669 GlobalPreferenceSystem().registerPreference( "XYWnd", make_property<WindowPositionTracker_String>(g_posXYWnd) );
3670 GlobalPreferenceSystem().registerPreference( "YZWnd", make_property<WindowPositionTracker_String>(g_posYZWnd) );
3671 GlobalPreferenceSystem().registerPreference( "XZWnd", make_property<WindowPositionTracker_String>(g_posXZWnd) );
3673 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3674 if ( g_strEnginePath.empty() )
3676 g_strEnginePath_was_empty_1st_start = true;
3677 const char* ENGINEPATH_ATTRIBUTE =
3682 #elif GDEF_OS_LINUX || GDEF_OS_BSD
3685 #error "unknown platform"
3689 StringOutputStream path( 256 );
3690 path << DirectoryCleaned( g_pGameDescription->getRequiredKeyValue( ENGINEPATH_ATTRIBUTE ) );
3692 g_strEnginePath = transformPath( path.c_str() ).c_str();
3693 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3696 GlobalPreferenceSystem().registerPreference( "DisableEnginePath", make_property_string( g_disableEnginePath ) );
3697 GlobalPreferenceSystem().registerPreference( "DisableHomePath", make_property_string( g_disableHomePath ) );
3699 for ( int i = 0; i < g_pakPathCount; i++ ) {
3700 std::string label = "PakPath" + std::to_string( i );
3701 GlobalPreferenceSystem().registerPreference( label.c_str(), make_property_string( g_strPakPath[i] ) );
3704 g_Layout_viewStyle.useLatched();
3705 g_Layout_enableDetachableMenus.useLatched();
3706 g_Layout_enablePatchToolbar.useLatched();
3707 g_Layout_enablePluginToolbar.useLatched();
3708 g_Layout_enableFilterToolbar.useLatched();
3710 Layout_registerPreferencesPage();
3711 Paths_registerPreferencesPage();
3713 g_brushCount.setCountChangedCallback( makeCallbackF(QE_brushCountChanged) );
3714 g_entityCount.setCountChangedCallback( makeCallbackF(QE_entityCountChanged) );
3715 GlobalEntityCreator().setCounter( &g_entityCount );
3717 glwidget_set_shared_context_constructors( GlobalGL_sharedContextCreated, GlobalGL_sharedContextDestroyed);
3719 GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver );
3722 void MainFrame_Destroy(){
3723 GlobalEntityClassManager().detach( g_WorldspawnColourEntityClassObserver );
3725 GlobalEntityCreator().setCounter( 0 );
3726 g_entityCount.setCountChangedCallback( Callback<void()>() );
3727 g_brushCount.setCountChangedCallback( Callback<void()>() );
3731 void GLWindow_Construct(){
3732 GlobalPreferenceSystem().registerPreference( "MouseButtons", make_property_string( g_glwindow_globals.m_nMouseType ) );
3735 void GLWindow_Destroy(){
3738 /* HACK: If ui::main is not called yet,
3739 gtk_main_quit will not quit, so tell main
3740 to not call ui::main. This happens when a
3741 map is loaded from command line and require
3742 a restart because of wrong format.
3743 Delete this when the code to not have to
3744 restart to load another format is merged. */
3745 extern bool g_dontStart;
3747 void Radiant_Restart(){
3748 // preferences are expected to be already saved in any way
3749 // this is just to be sure and be future proof
3752 // this asks user for saving if map is modified
3753 // user can chose to not save, it's ok
3754 ConfirmModified( "Restart " RADIANT_NAME );
3759 char exe_file[ 256 ];
3760 char map_file[ 256 ];
3761 bool with_map = false;
3763 strncpy( exe_file, g_strAppFilePath.c_str(), 256 );
3765 if ( !Map_Unnamed( g_map ) ) {
3766 strncpy( map_file, Map_Name( g_map ), 256 );
3770 argv[ 0 ] = exe_file;
3771 argv[ 1 ] = with_map ? map_file : NULL;
3775 status = !_spawnvpe( P_NOWAIT, exe_file, argv, environ );
3779 status = posix_spawn( &pid, exe_file, NULL, NULL, argv, environ );
3782 // quit if radiant successfully started
3783 if ( status == 0 ) {
3785 /* HACK: If ui::main is not called yet,
3786 gtk_main_quit will not quit, so tell main
3787 to not call ui::main. This happens when a
3788 map is loaded from command line and require
3789 a restart because of wrong format.
3790 Delete this when the code to not have to
3791 restart to load another format is merged. */