2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 // Main Window for Q3Radiant
25 // Leonardo Zide (leo@lokigames.com)
28 #include "mainframe.h"
29 #include "globaldefs.h"
33 #include "ifilesystem.h"
39 #include "moduleobserver.h"
43 #include <gdk/gdkkeysyms.h>
47 #include "stream/stringstream.h"
48 #include "signal/isignal.h"
51 #include "eclasslib.h"
52 #include "moduleobservers.h"
54 #include "gtkutil/clipboard.h"
55 #include "gtkutil/frame.h"
56 #include "gtkutil/glwidget.h"
57 #include "gtkutil/image.h"
58 #include "gtkutil/menu.h"
59 #include "gtkutil/paned.h"
63 #include "brushmanip.h"
64 #include "brushmodule.h"
65 #include "camwindow.h"
70 #include "entityinspector.h"
71 #include "entitylist.h"
73 #include "findtexturedialog.h"
75 #include "groupdialog.h"
82 #include "patchdialog.h"
83 #include "patchmanip.h"
85 #include "pluginmanager.h"
86 #include "pluginmenu.h"
87 #include "plugintoolbar.h"
88 #include "preferences.h"
93 #include "surfacedialog.h"
95 #include "texwindow.h"
98 #include "windowobservers.h"
99 #include "renderstate.h"
100 #include "feedback.h"
101 #include "referencecache.h"
102 #include "texwindow.h"
103 #include "filterbar.h"
105 #define GARUX_DISABLE_GTKTHEME
106 #ifndef GARUX_DISABLE_GTKTHEME
107 #include "gtktheme.h"
111 struct layout_globals_t
113 WindowPosition m_position;
123 m_position( -1, -1, 640, 480 ),
129 nState( GDK_WINDOW_STATE_MAXIMIZED ){
133 layout_globals_t g_layout_globals;
134 glwindow_globals_t g_glwindow_globals;
139 bool g_vfsInitialized = false;
142 if ( g_vfsInitialized ) return;
144 GlobalFileSystem().initialise();
145 g_vfsInitialized = true;
149 if ( !g_vfsInitialized ) return;
150 GlobalFileSystem().shutdown();
151 g_vfsInitialized = false;
155 if ( !g_vfsInitialized ) return;
156 GlobalFileSystem().clear();
158 GlobalFileSystem().refresh();
159 g_vfsInitialized = true;
160 // also refresh models
162 // also refresh texture browser
163 TextureBrowser_RefreshShaders();
171 class VFSModuleObserver : public ModuleObserver
183 VFSModuleObserver g_VFSModuleObserver;
185 void VFS_Construct(){
186 Radiant_attachHomePathsObserver( g_VFSModuleObserver );
190 Radiant_detachHomePathsObserver( g_VFSModuleObserver );
198 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
199 #define qREFKNOWNFOLDERID GUID
200 #define qKF_FLAG_CREATE 0x8000
201 #define qKF_FLAG_NO_ALIAS 0x1000
202 typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath );
203 static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath;
206 void HomePaths_Realise(){
209 const char* prefix = g_pGameDescription->getKeyValue( "prefix" );
210 if ( !string_empty( prefix ) ) {
211 StringOutputStream path( 256 );
215 path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/";
216 if ( file_is_directory( path.c_str() ) ) {
217 g_qeglobals.m_userEnginePath = path.c_str();
221 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
225 TCHAR mydocsdir[MAX_PATH + 1];
227 HMODULE shfolder = LoadLibrary( "shfolder.dll" );
229 qSHGetKnownFolderPath = (qSHGetKnownFolderPath_t *) GetProcAddress( shfolder, "SHGetKnownFolderPath" );
232 qSHGetKnownFolderPath = NULL;
234 CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
235 if ( qSHGetKnownFolderPath && qSHGetKnownFolderPath( qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw ) == S_OK ) {
236 memset( mydocsdir, 0, sizeof( mydocsdir ) );
237 wcstombs( mydocsdir, mydocsdirw, sizeof( mydocsdir ) - 1 );
238 CoTaskMemFree( mydocsdirw );
240 path << DirectoryCleaned( mydocsdir ) << ( prefix + 1 ) << "/";
241 if ( file_is_directory( path.c_str() ) ) {
242 g_qeglobals.m_userEnginePath = path.c_str();
244 FreeLibrary( shfolder );
250 FreeLibrary( shfolder );
252 if ( SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir ) ) {
254 path << DirectoryCleaned( mydocsdir ) << "My Games/" << ( prefix + 1 ) << "/";
255 // win32: only add it if it already exists
256 if ( file_is_directory( path.c_str() ) ) {
257 g_qeglobals.m_userEnginePath = path.c_str();
265 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
266 g_qeglobals.m_userEnginePath = path.c_str();
271 g_qeglobals.m_userEnginePath = EnginePath_get();
275 Q_mkdir( g_qeglobals.m_userEnginePath.c_str() );
278 StringOutputStream path( 256 );
279 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
280 g_qeglobals.m_userGamePath = path.c_str();
282 ASSERT_MESSAGE( !string_empty( g_qeglobals.m_userGamePath.c_str() ), "HomePaths_Realise: user-game-path is empty" );
283 Q_mkdir( g_qeglobals.m_userGamePath.c_str() );
286 ModuleObservers g_homePathObservers;
288 void Radiant_attachHomePathsObserver( ModuleObserver& observer ){
289 g_homePathObservers.attach( observer );
292 void Radiant_detachHomePathsObserver( ModuleObserver& observer ){
293 g_homePathObservers.detach( observer );
296 class HomePathsModuleObserver : public ModuleObserver
298 std::size_t m_unrealised;
300 HomePathsModuleObserver() : m_unrealised( 1 ){
304 if ( --m_unrealised == 0 ) {
306 g_homePathObservers.realise();
311 if ( ++m_unrealised == 1 ) {
312 g_homePathObservers.unrealise();
317 HomePathsModuleObserver g_HomePathsModuleObserver;
319 void HomePaths_Construct(){
320 Radiant_attachEnginePathObserver( g_HomePathsModuleObserver );
323 void HomePaths_Destroy(){
324 Radiant_detachEnginePathObserver( g_HomePathsModuleObserver );
330 CopiedString g_strEnginePath;
331 ModuleObservers g_enginePathObservers;
332 std::size_t g_enginepath_unrealised = 1;
334 void Radiant_attachEnginePathObserver( ModuleObserver& observer ){
335 g_enginePathObservers.attach( observer );
338 void Radiant_detachEnginePathObserver( ModuleObserver& observer ){
339 g_enginePathObservers.detach( observer );
343 void EnginePath_Realise(){
344 if ( --g_enginepath_unrealised == 0 ) {
345 g_enginePathObservers.realise();
350 const char* EnginePath_get(){
351 ASSERT_MESSAGE( g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised" );
352 return g_strEnginePath.c_str();
355 void EnginePath_Unrealise(){
356 if ( ++g_enginepath_unrealised == 1 ) {
357 g_enginePathObservers.unrealise();
361 void setEnginePath( const char* path ){
362 StringOutputStream buffer( 256 );
363 buffer << DirectoryCleaned( path );
364 if ( !path_equal( buffer.c_str(), g_strEnginePath.c_str() ) ) {
366 while ( !ConfirmModified( "Paths Changed" ) )
368 if ( Map_Unnamed( g_map ) ) {
379 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Changing Engine Path" );
381 EnginePath_Unrealise();
383 g_strEnginePath = buffer.c_str();
385 EnginePath_Realise();
391 CopiedString g_strPakPath[g_pakPathCount] = { "", "", "", "", "" };
392 ModuleObservers g_pakPathObservers[g_pakPathCount];
393 std::size_t g_pakpath_unrealised[g_pakPathCount] = { 1, 1, 1, 1, 1 };
395 void Radiant_attachPakPathObserver( int num, ModuleObserver& observer ){
396 g_pakPathObservers[num].attach( observer );
399 void Radiant_detachPakPathObserver( int num, ModuleObserver& observer ){
400 g_pakPathObservers[num].detach( observer );
404 void PakPath_Realise( int num ){
405 if ( --g_pakpath_unrealised[num] == 0 ) {
406 g_pakPathObservers[num].realise();
410 const char* PakPath_get( int num ){
411 std::string message = "PakPath_get: pak path " + std::to_string(num) + " not realised";
412 ASSERT_MESSAGE( g_pakpath_unrealised[num] == 0, message.c_str() );
413 return g_strPakPath[num].c_str();
416 void PakPath_Unrealise( int num ){
417 if ( ++g_pakpath_unrealised[num] == 1 ) {
418 g_pakPathObservers[num].unrealise();
422 void setPakPath( int num, const char* path ){
423 if (!g_strcmp0( path, "")) {
424 g_strPakPath[num] = "";
428 StringOutputStream buffer( 256 );
429 buffer << DirectoryCleaned( path );
430 if ( !path_equal( buffer.c_str(), g_strPakPath[num].c_str() ) ) {
431 std::string message = "Changing Pak Path " + std::to_string(num);
432 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", message.c_str() );
434 PakPath_Unrealise(num);
436 g_strPakPath[num] = buffer.c_str();
438 PakPath_Realise(num);
445 CopiedString g_strAppPath; ///< holds the full path of the executable
447 const char* AppPath_get(){
448 return g_strAppPath.c_str();
451 /// the path to the local rc-dir
452 const char* LocalRcPath_get( void ){
453 static CopiedString rc_path;
454 if ( rc_path.empty() ) {
455 StringOutputStream stream( 256 );
456 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
457 rc_path = stream.c_str();
459 return rc_path.c_str();
462 /// directory for temp files
463 /// NOTE: on *nix this is were we check for .pid
464 CopiedString g_strSettingsPath;
466 const char* SettingsPath_get(){
467 return g_strSettingsPath.c_str();
472 points to the game tools directory, for instance
473 C:/Program Files/Quake III Arena/GtkRadiant
475 this is one of the main variables that are configured by the game selection on startup
476 [GameToolsPath]/plugins
477 [GameToolsPath]/modules
480 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
482 const char* GameToolsPath_get(){
483 return g_strGameToolsPath.c_str();
487 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz) {
488 returnz(self.c_str());
491 static void Import(CopiedString &self, const char *value) {
492 setEnginePath( value );
497 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
498 returnz( self.c_str() );
501 static void Import( CopiedString &self, const char *value ) {
502 setPakPath( 0, value );
507 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
508 returnz( self.c_str() );
511 static void Import( CopiedString &self, const char *value ) {
512 setPakPath( 1, value );
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 setPakPath( 2, 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( 3, 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( 4, value );
546 bool g_disableEnginePath = false;
547 bool g_disableHomePath = false;
549 void Paths_constructPreferences( PreferencesPage& page ){
550 page.appendPathEntry( "Engine Path", true, make_property<EnginePath>(g_strEnginePath) );
553 "", "Do not use Engine Path",
558 "", "Do not use Home Path",
562 for ( int i = 0; i < g_pakPathCount; i++ ) {
563 std::string label = "Pak Path " + std::to_string(i);
566 page.appendPathEntry( label.c_str(), true, make_property<PakPath0>( g_strPakPath[i] ) );
569 page.appendPathEntry( label.c_str(), true, make_property<PakPath1>( g_strPakPath[i] ) );
572 page.appendPathEntry( label.c_str(), true, make_property<PakPath2>( g_strPakPath[i] ) );
575 page.appendPathEntry( label.c_str(), true, make_property<PakPath3>( g_strPakPath[i] ) );
578 page.appendPathEntry( label.c_str(), true, make_property<PakPath4>( g_strPakPath[i] ) );
584 void Paths_constructPage( PreferenceGroup& group ){
585 PreferencesPage page( group.createPage( "Paths", "Path Settings" ) );
586 Paths_constructPreferences( page );
589 void Paths_registerPreferencesPage(){
590 PreferencesDialog_addSettingsPage( makeCallbackF(Paths_constructPage) );
594 class PathsDialog : public Dialog
597 ui::Window BuildDialog(){
598 auto frame = create_dialog_frame( "Path settings", ui::Shadow::ETCHED_IN );
600 auto vbox2 = create_dialog_vbox( 0, 4 );
604 PreferencesPage preferencesPage( *this, vbox2 );
605 Paths_constructPreferences( preferencesPage );
608 return ui::Window(create_simple_modal_dialog_window( "Engine Path Not Found", m_modal, frame ));
612 PathsDialog g_PathsDialog;
614 bool g_strEnginePath_was_empty_1st_start = false;
616 void EnginePath_verify(){
617 if ( !file_exists( g_strEnginePath.c_str() ) || g_strEnginePath_was_empty_1st_start ) {
618 g_PathsDialog.Create();
619 g_PathsDialog.DoModal();
620 g_PathsDialog.Destroy();
626 CopiedString g_gamename;
627 CopiedString g_gamemode;
628 ModuleObservers g_gameNameObservers;
629 ModuleObservers g_gameModeObservers;
632 void Radiant_attachGameNameObserver( ModuleObserver& observer ){
633 g_gameNameObservers.attach( observer );
636 void Radiant_detachGameNameObserver( ModuleObserver& observer ){
637 g_gameNameObservers.detach( observer );
640 const char* basegame_get(){
641 return g_pGameDescription->getRequiredKeyValue( "basegame" );
644 const char* gamename_get(){
645 const char* gamename = g_gamename.c_str();
646 if ( string_empty( gamename ) ) {
647 return basegame_get();
652 void gamename_set( const char* gamename ){
653 if ( !string_equal( gamename, g_gamename.c_str() ) ) {
654 g_gameNameObservers.unrealise();
655 g_gamename = gamename;
656 g_gameNameObservers.realise();
660 void Radiant_attachGameModeObserver( ModuleObserver& observer ){
661 g_gameModeObservers.attach( observer );
664 void Radiant_detachGameModeObserver( ModuleObserver& observer ){
665 g_gameModeObservers.detach( observer );
668 const char* gamemode_get(){
669 return g_gamemode.c_str();
672 void gamemode_set( const char* gamemode ){
673 if ( !string_equal( gamemode, g_gamemode.c_str() ) ) {
674 g_gameModeObservers.unrealise();
675 g_gamemode = gamemode;
676 g_gameModeObservers.realise();
683 const char* const c_library_extension =
684 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
685 CMAKE_SHARED_MODULE_SUFFIX
686 #elif GDEF_OS_WINDOWS
690 #elif GDEF_OS_LINUX || GDEF_OS_BSD
695 void Radiant_loadModules( const char* path ){
696 Directory_forEach(path, matchFileExtension(c_library_extension, [&](const char *name) {
698 ASSERT_MESSAGE(strlen(path) + strlen(name) < 1024, "");
699 strcpy(fullname, path);
700 strcat(fullname, name);
701 globalOutputStream() << "Found '" << fullname << "'\n";
702 GlobalModuleServer_loadModule(fullname);
706 void Radiant_loadModulesFromRoot( const char* directory ){
708 StringOutputStream path( 256 );
709 path << directory << g_pluginsDir;
710 Radiant_loadModules( path.c_str() );
713 if ( !string_equal( g_pluginsDir, g_modulesDir ) ) {
714 StringOutputStream path( 256 );
715 path << directory << g_modulesDir;
716 Radiant_loadModules( path.c_str() );
720 //! Make COLOR_BRUSHES override worldspawn eclass colour.
721 void SetWorldspawnColour( const Vector3& colour ){
722 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert( "worldspawn", true );
723 eclass_release_state( worldspawn );
724 worldspawn->color = colour;
725 eclass_capture_state( worldspawn );
729 class WorldspawnColourEntityClassObserver : public ModuleObserver
731 std::size_t m_unrealised;
733 WorldspawnColourEntityClassObserver() : m_unrealised( 1 ){
737 if ( --m_unrealised == 0 ) {
738 SetWorldspawnColour( g_xywindow_globals.color_brushes );
743 if ( ++m_unrealised == 1 ) {
748 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
751 ModuleObservers g_gameToolsPathObservers;
753 void Radiant_attachGameToolsPathObserver( ModuleObserver& observer ){
754 g_gameToolsPathObservers.attach( observer );
757 void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ){
758 g_gameToolsPathObservers.detach( observer );
761 void Radiant_Initialise(){
762 GlobalModuleServer_Initialise();
764 Radiant_loadModulesFromRoot( AppPath_get() );
768 bool success = Radiant_Construct( GlobalModuleServer_get() );
769 ASSERT_MESSAGE( success, "module system failed to initialise - see radiant.log for error messages" );
771 g_gameToolsPathObservers.realise();
772 g_gameModeObservers.realise();
773 g_gameNameObservers.realise();
776 void Radiant_Shutdown(){
777 g_gameNameObservers.unrealise();
778 g_gameModeObservers.unrealise();
779 g_gameToolsPathObservers.unrealise();
781 if ( !g_preferences_globals.disable_ini ) {
782 globalOutputStream() << "Start writing prefs\n";
784 globalOutputStream() << "Done prefs\n";
789 GlobalModuleServer_Shutdown();
793 if ( ConfirmModified( "Exit Radiant" ) ) {
800 GlobalUndoSystem().undo();
805 GlobalUndoSystem().redo();
809 void deleteSelection(){
810 UndoableCommand undo( "deleteSelected" );
814 void Map_ExportSelected( TextOutputStream& ostream ){
815 Map_ExportSelected( ostream, Map_getFormat( g_map ) );
818 void Map_ImportSelected( TextInputStream& istream ){
819 Map_ImportSelected( istream, Map_getFormat( g_map ) );
822 void Selection_Copy(){
823 clipboard_copy( Map_ExportSelected );
826 void Selection_Paste(){
827 clipboard_paste( Map_ImportSelected );
831 if ( SelectedFaces_empty() ) {
836 SelectedFaces_copyTexture();
841 if ( SelectedFaces_empty() ) {
842 UndoableCommand undo( "paste" );
844 GlobalSelectionSystem().setSelectedAll( false );
849 SelectedFaces_pasteTexture();
853 void PasteToCamera(){
854 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
855 GlobalSelectionSystem().setSelectedAll( false );
857 UndoableCommand undo( "pasteToCamera" );
861 // Work out the delta
863 Select_GetMid( mid );
864 Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid );
867 GlobalSelectionSystem().translateSelected( delta );
871 void ColorScheme_Original(){
872 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
874 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
875 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
876 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
878 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
879 g_xywindow_globals.color_gridminor = Vector3( 0.75f, 0.75f, 0.75f );
880 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
881 g_xywindow_globals.color_gridminor_alt = Vector3( 0.5f, 0.0f, 0.0f );
882 g_xywindow_globals.color_gridmajor_alt = Vector3( 1.0f, 0.0f, 0.0f );
883 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
884 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
885 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
886 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
887 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
888 SetWorldspawnColour( g_xywindow_globals.color_brushes );
889 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
890 XY_UpdateAllWindows();
893 void ColorScheme_QER(){
894 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
896 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
897 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
898 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
900 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
901 g_xywindow_globals.color_gridminor = Vector3( 1.0f, 1.0f, 1.0f );
902 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
903 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
904 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
905 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
906 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
907 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
908 SetWorldspawnColour( g_xywindow_globals.color_brushes );
909 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
910 XY_UpdateAllWindows();
913 void ColorScheme_Black(){
914 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
916 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
917 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
918 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
920 g_xywindow_globals.color_gridback = Vector3( 0.0f, 0.0f, 0.0f );
921 g_xywindow_globals.color_gridminor = Vector3( 0.2f, 0.2f, 0.2f );
922 g_xywindow_globals.color_gridmajor = Vector3( 0.3f, 0.5f, 0.5f );
923 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
924 g_xywindow_globals.color_gridtext = Vector3( 1.0f, 1.0f, 1.0f );
925 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
926 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
927 g_xywindow_globals.color_brushes = Vector3( 1.0f, 1.0f, 1.0f );
928 SetWorldspawnColour( g_xywindow_globals.color_brushes );
929 g_xywindow_globals.color_viewname = Vector3( 0.7f, 0.7f, 0.0f );
930 XY_UpdateAllWindows();
933 /* ydnar: to emulate maya/max/lightwave color schemes */
934 void ColorScheme_Ydnar(){
935 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
937 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
938 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
939 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
941 g_xywindow_globals.color_gridback = Vector3( 0.77f, 0.77f, 0.77f );
942 g_xywindow_globals.color_gridminor = Vector3( 0.83f, 0.83f, 0.83f );
943 g_xywindow_globals.color_gridmajor = Vector3( 0.89f, 0.89f, 0.89f );
944 g_xywindow_globals.color_gridblock = Vector3( 1.0f, 1.0f, 1.0f );
945 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
946 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
947 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
948 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
949 SetWorldspawnColour( g_xywindow_globals.color_brushes );
950 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
951 XY_UpdateAllWindows();
954 typedef Callback<void(Vector3&)> GetColourCallback;
955 typedef Callback<void(const Vector3&)> SetColourCallback;
959 GetColourCallback m_get;
960 SetColourCallback m_set;
962 ChooseColour( const GetColourCallback& get, const SetColourCallback& set )
963 : m_get( get ), m_set( set ){
969 color_dialog( MainFrame_getWindow(), colour );
975 void Colour_get( const Vector3& colour, Vector3& other ){
979 typedef ConstReferenceCaller<Vector3, void(Vector3&), Colour_get> ColourGetCaller;
981 void Colour_set( Vector3& colour, const Vector3& other ){
986 typedef ReferenceCaller<Vector3, void(const Vector3&), Colour_set> ColourSetCaller;
988 void BrushColour_set( const Vector3& other ){
989 g_xywindow_globals.color_brushes = other;
990 SetWorldspawnColour( g_xywindow_globals.color_brushes );
994 typedef FreeCaller<void(const Vector3&), BrushColour_set> BrushColourSetCaller;
996 void ClipperColour_set( const Vector3& other ){
997 g_xywindow_globals.color_clipper = other;
998 Brush_clipperColourChanged();
1002 typedef FreeCaller<void(const Vector3&), ClipperColour_set> ClipperColourSetCaller;
1004 void TextureBrowserColour_get( Vector3& other ){
1005 other = TextureBrowser_getBackgroundColour( GlobalTextureBrowser() );
1008 typedef FreeCaller<void(Vector3&), TextureBrowserColour_get> TextureBrowserColourGetCaller;
1010 void TextureBrowserColour_set( const Vector3& other ){
1011 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), other );
1014 typedef FreeCaller<void(const Vector3&), TextureBrowserColour_set> TextureBrowserColourSetCaller;
1020 ChooseColour m_textureback;
1021 ChooseColour m_xyback;
1022 ChooseColour m_gridmajor;
1023 ChooseColour m_gridminor;
1024 ChooseColour m_gridmajor_alt;
1025 ChooseColour m_gridminor_alt;
1026 ChooseColour m_gridtext;
1027 ChooseColour m_gridblock;
1028 ChooseColour m_cameraback;
1029 ChooseColour m_brush;
1030 ChooseColour m_selectedbrush;
1031 ChooseColour m_selectedbrush3d;
1032 ChooseColour m_clipper;
1033 ChooseColour m_viewname;
1036 m_textureback( TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller() ),
1037 m_xyback( ColourGetCaller( g_xywindow_globals.color_gridback ), ColourSetCaller( g_xywindow_globals.color_gridback ) ),
1038 m_gridmajor( ColourGetCaller( g_xywindow_globals.color_gridmajor ), ColourSetCaller( g_xywindow_globals.color_gridmajor ) ),
1039 m_gridminor( ColourGetCaller( g_xywindow_globals.color_gridminor ), ColourSetCaller( g_xywindow_globals.color_gridminor ) ),
1040 m_gridmajor_alt( ColourGetCaller( g_xywindow_globals.color_gridmajor_alt ), ColourSetCaller( g_xywindow_globals.color_gridmajor_alt ) ),
1041 m_gridminor_alt( ColourGetCaller( g_xywindow_globals.color_gridminor_alt ), ColourSetCaller( g_xywindow_globals.color_gridminor_alt ) ),
1042 m_gridtext( ColourGetCaller( g_xywindow_globals.color_gridtext ), ColourSetCaller( g_xywindow_globals.color_gridtext ) ),
1043 m_gridblock( ColourGetCaller( g_xywindow_globals.color_gridblock ), ColourSetCaller( g_xywindow_globals.color_gridblock ) ),
1044 m_cameraback( ColourGetCaller( g_camwindow_globals.color_cameraback ), ColourSetCaller( g_camwindow_globals.color_cameraback ) ),
1045 m_brush( ColourGetCaller( g_xywindow_globals.color_brushes ), BrushColourSetCaller() ),
1046 m_selectedbrush( ColourGetCaller( g_xywindow_globals.color_selbrushes ), ColourSetCaller( g_xywindow_globals.color_selbrushes ) ),
1047 m_selectedbrush3d( ColourGetCaller( g_camwindow_globals.color_selbrushes3d ), ColourSetCaller( g_camwindow_globals.color_selbrushes3d ) ),
1048 m_clipper( ColourGetCaller( g_xywindow_globals.color_clipper ), ClipperColourSetCaller() ),
1049 m_viewname( ColourGetCaller( g_xywindow_globals.color_viewname ), ColourSetCaller( g_xywindow_globals.color_viewname ) ){
1053 ColoursMenu g_ColoursMenu;
1055 ui::MenuItem create_colours_menu(){
1056 auto colours_menu_item = new_sub_menu_item_with_mnemonic( "Colors" );
1057 auto menu_in_menu = ui::Menu::from( gtk_menu_item_get_submenu( colours_menu_item ) );
1058 if ( g_Layout_enableDetachableMenus.m_value ) {
1059 menu_tearoff( menu_in_menu );
1062 auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Themes" );
1063 if ( g_Layout_enableDetachableMenus.m_value ) {
1064 menu_tearoff( menu_3 );
1067 create_menu_item_with_mnemonic( menu_3, "QE4 Original", "ColorSchemeOriginal" );
1068 create_menu_item_with_mnemonic( menu_3, "Q3Radiant Original", "ColorSchemeQER" );
1069 create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" );
1070 create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" );
1072 #ifndef GARUX_DISABLE_GTKTHEME
1073 create_menu_item_with_mnemonic( menu_in_menu, "GTK Theme...", "gtkThemeDlg" );
1076 menu_separator( menu_in_menu );
1078 create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" );
1079 create_menu_item_with_mnemonic( menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor" );
1080 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major...", "ChooseGridMajorColor" );
1081 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor...", "ChooseGridMinorColor" );
1082 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor" );
1083 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor" );
1084 create_menu_item_with_mnemonic( menu_in_menu, "Grid Text...", "ChooseGridTextColor" );
1085 create_menu_item_with_mnemonic( menu_in_menu, "Grid Block...", "ChooseGridBlockColor" );
1086 create_menu_item_with_mnemonic( menu_in_menu, "Default Brush...", "ChooseBrushColor" );
1087 create_menu_item_with_mnemonic( menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor" );
1088 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor" );
1089 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor" );
1090 create_menu_item_with_mnemonic( menu_in_menu, "Clipper...", "ChooseClipperColor" );
1091 create_menu_item_with_mnemonic( menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor" );
1093 return colours_menu_item;
1098 PluginsMenu_clear();
1099 PluginToolbar_clear();
1102 Radiant_Initialise();
1104 PluginsMenu_populate();
1106 PluginToolbar_populate();
1110 void thunk_OnSleep(){
1111 g_pParentWnd->OnSleep();
1115 OpenURL( "https://gitlab.com/xonotic/xonotic/wikis/Mapping" );
1118 void OpenBugReportURL(){
1119 OpenURL( "https://gitlab.com/xonotic/netradiant/issues" );
1123 ui::Widget g_page_console{ui::null};
1125 void Console_ToggleShow(){
1126 GroupDialog_showPage( g_page_console );
1129 ui::Widget g_page_entity{ui::null};
1131 void EntityInspector_ToggleShow(){
1132 GroupDialog_showPage( g_page_entity );
1136 void SetClipMode( bool enable );
1138 void ModeChangeNotify();
1140 typedef void ( *ToolMode )();
1142 ToolMode g_currentToolMode = 0;
1143 bool g_currentToolModeSupportsComponentEditing = false;
1144 ToolMode g_defaultToolMode = 0;
1147 void SelectionSystem_DefaultMode(){
1148 GlobalSelectionSystem().SetMode( SelectionSystem::ePrimitive );
1149 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eDefault );
1155 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1156 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1160 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1161 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1165 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1166 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1169 template<bool( *BoolFunction ) ( )>
1170 class BoolFunctionExport
1173 static void apply( const Callback<void(bool)> & importCallback ){
1174 importCallback( BoolFunction() );
1178 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1179 EdgeModeApplyCaller g_edgeMode_button_caller;
1180 Callback<void(const Callback<void(bool)> &)> g_edgeMode_button_callback( g_edgeMode_button_caller );
1181 ToggleItem g_edgeMode_button( g_edgeMode_button_callback );
1183 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1184 VertexModeApplyCaller g_vertexMode_button_caller;
1185 Callback<void(const Callback<void(bool)> &)> g_vertexMode_button_callback( g_vertexMode_button_caller );
1186 ToggleItem g_vertexMode_button( g_vertexMode_button_callback );
1188 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1189 FaceModeApplyCaller g_faceMode_button_caller;
1190 Callback<void(const Callback<void(bool)> &)> g_faceMode_button_callback( g_faceMode_button_caller );
1191 ToggleItem g_faceMode_button( g_faceMode_button_callback );
1193 void ComponentModeChanged(){
1194 g_edgeMode_button.update();
1195 g_vertexMode_button.update();
1196 g_faceMode_button.update();
1199 void ComponentMode_SelectionChanged( const Selectable& selectable ){
1200 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1201 && GlobalSelectionSystem().countSelected() == 0 ) {
1202 SelectionSystem_DefaultMode();
1203 ComponentModeChanged();
1207 void SelectEdgeMode(){
1209 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1210 GlobalSelectionSystem().Select( false );
1215 SelectionSystem_DefaultMode();
1217 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1218 if ( !g_currentToolModeSupportsComponentEditing ) {
1219 g_defaultToolMode();
1222 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1223 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eEdge );
1226 ComponentModeChanged();
1231 void SelectVertexMode(){
1233 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1234 GlobalSelectionSystem().Select( false );
1238 if ( VertexMode() ) {
1239 SelectionSystem_DefaultMode();
1241 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1242 if ( !g_currentToolModeSupportsComponentEditing ) {
1243 g_defaultToolMode();
1246 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1247 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eVertex );
1250 ComponentModeChanged();
1255 void SelectFaceMode(){
1257 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1258 GlobalSelectionSystem().Select( false );
1263 SelectionSystem_DefaultMode();
1265 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1266 if ( !g_currentToolModeSupportsComponentEditing ) {
1267 g_defaultToolMode();
1270 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1271 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eFace );
1274 ComponentModeChanged();
1280 class CloneSelected : public scene::Graph::Walker
1283 NodeSmartReference worldspawn;
1285 CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
1288 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1289 if ( path.size() == 1 ) {
1293 // ignore worldspawn, but keep checking children
1294 NodeSmartReference me( path.top().get() );
1295 if ( me == worldspawn ) {
1299 if ( !path.top().get().isRoot() ) {
1300 Selectable* selectable = Instance_getSelectable( instance );
1301 if ( selectable != 0
1302 && selectable->isSelected() ) {
1310 void post( const scene::Path& path, scene::Instance& instance ) const {
1311 if ( path.size() == 1 ) {
1315 // ignore worldspawn, but keep checking children
1316 NodeSmartReference me( path.top().get() );
1317 if ( me == worldspawn ) {
1321 if ( !path.top().get().isRoot() ) {
1322 Selectable* selectable = Instance_getSelectable( instance );
1323 if ( selectable != 0
1324 && selectable->isSelected() ) {
1325 NodeSmartReference clone( Node_Clone( path.top() ) );
1326 if ( doMakeUnique ) {
1327 Map_gatherNamespaced( clone );
1329 Node_getTraversable( path.parent().get() )->insert( clone );
1335 void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){
1336 graph.traverse( CloneSelected( doMakeUnique ) );
1338 Map_mergeClonedNames();
1341 enum ENudgeDirection
1355 AxisBase( const Vector3& x_, const Vector3& y_, const Vector3& z_ )
1356 : x( x_ ), y( y_ ), z( z_ ){
1360 AxisBase AxisBase_forViewType( VIEWTYPE viewtype ){
1364 return AxisBase( g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z );
1366 return AxisBase( g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y );
1368 return AxisBase( g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x );
1371 ERROR_MESSAGE( "invalid viewtype" );
1372 return AxisBase( Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) );
1375 Vector3 AxisBase_axisForDirection( const AxisBase& axes, ENudgeDirection direction ){
1376 switch ( direction )
1379 return vector3_negated( axes.x );
1385 return vector3_negated( axes.y );
1388 ERROR_MESSAGE( "invalid direction" );
1389 return Vector3( 0, 0, 0 );
1392 void NudgeSelection( ENudgeDirection direction, float fAmount, VIEWTYPE viewtype ){
1393 AxisBase axes( AxisBase_forViewType( viewtype ) );
1394 Vector3 view_direction( vector3_negated( axes.z ) );
1395 Vector3 nudge( vector3_scaled( AxisBase_axisForDirection( axes, direction ), fAmount ) );
1396 GlobalSelectionSystem().NudgeManipulator( nudge, view_direction );
1399 void Selection_Clone(){
1400 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1401 UndoableCommand undo( "cloneSelected" );
1403 Scene_Clone_Selected( GlobalSceneGraph(), false );
1405 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1406 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1410 void Selection_Clone_MakeUnique(){
1411 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1412 UndoableCommand undo( "cloneSelectedMakeUnique" );
1414 Scene_Clone_Selected( GlobalSceneGraph(), true );
1416 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1417 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1421 // called when the escape key is used (either on the main window or on an inspector)
1422 void Selection_Deselect(){
1423 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1424 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1425 GlobalSelectionSystem().setSelectedAllComponents( false );
1429 SelectionSystem_DefaultMode();
1430 ComponentModeChanged();
1435 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1436 GlobalSelectionSystem().setSelectedAllComponents( false );
1440 GlobalSelectionSystem().setSelectedAll( false );
1446 void Selection_NudgeUp(){
1447 UndoableCommand undo( "nudgeSelectedUp" );
1448 NudgeSelection( eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1451 void Selection_NudgeDown(){
1452 UndoableCommand undo( "nudgeSelectedDown" );
1453 NudgeSelection( eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1456 void Selection_NudgeLeft(){
1457 UndoableCommand undo( "nudgeSelectedLeft" );
1458 NudgeSelection( eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1461 void Selection_NudgeRight(){
1462 UndoableCommand undo( "nudgeSelectedRight" );
1463 NudgeSelection( eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1467 void TranslateToolExport( const Callback<void(bool)> & importCallback ){
1468 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate );
1471 void RotateToolExport( const Callback<void(bool)> & importCallback ){
1472 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate );
1475 void ScaleToolExport( const Callback<void(bool)> & importCallback ){
1476 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale );
1479 void DragToolExport( const Callback<void(bool)> & importCallback ){
1480 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag );
1483 void ClipperToolExport( const Callback<void(bool)> & importCallback ){
1484 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip );
1487 FreeCaller<void(const Callback<void(bool)> &), TranslateToolExport> g_translatemode_button_caller;
1488 Callback<void(const Callback<void(bool)> &)> g_translatemode_button_callback( g_translatemode_button_caller );
1489 ToggleItem g_translatemode_button( g_translatemode_button_callback );
1491 FreeCaller<void(const Callback<void(bool)> &), RotateToolExport> g_rotatemode_button_caller;
1492 Callback<void(const Callback<void(bool)> &)> g_rotatemode_button_callback( g_rotatemode_button_caller );
1493 ToggleItem g_rotatemode_button( g_rotatemode_button_callback );
1495 FreeCaller<void(const Callback<void(bool)> &), ScaleToolExport> g_scalemode_button_caller;
1496 Callback<void(const Callback<void(bool)> &)> g_scalemode_button_callback( g_scalemode_button_caller );
1497 ToggleItem g_scalemode_button( g_scalemode_button_callback );
1499 FreeCaller<void(const Callback<void(bool)> &), DragToolExport> g_dragmode_button_caller;
1500 Callback<void(const Callback<void(bool)> &)> g_dragmode_button_callback( g_dragmode_button_caller );
1501 ToggleItem g_dragmode_button( g_dragmode_button_callback );
1503 FreeCaller<void(const Callback<void(bool)> &), ClipperToolExport> g_clipper_button_caller;
1504 Callback<void(const Callback<void(bool)> &)> g_clipper_button_callback( g_clipper_button_caller );
1505 ToggleItem g_clipper_button( g_clipper_button_callback );
1508 g_translatemode_button.update();
1509 g_rotatemode_button.update();
1510 g_scalemode_button.update();
1511 g_dragmode_button.update();
1512 g_clipper_button.update();
1515 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1518 if ( g_currentToolMode == DragMode && g_defaultToolMode != DragMode ) {
1519 g_defaultToolMode();
1523 g_currentToolMode = DragMode;
1524 g_currentToolModeSupportsComponentEditing = true;
1526 OnClipMode( false );
1528 Sys_Status( c_ResizeMode_status );
1529 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eDrag );
1536 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1538 void TranslateMode(){
1539 if ( g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode ) {
1540 g_defaultToolMode();
1544 g_currentToolMode = TranslateMode;
1545 g_currentToolModeSupportsComponentEditing = true;
1547 OnClipMode( false );
1549 Sys_Status( c_TranslateMode_status );
1550 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eTranslate );
1556 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1559 if ( g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode ) {
1560 g_defaultToolMode();
1564 g_currentToolMode = RotateMode;
1565 g_currentToolModeSupportsComponentEditing = true;
1567 OnClipMode( false );
1569 Sys_Status( c_RotateMode_status );
1570 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eRotate );
1576 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1579 if ( g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode ) {
1580 g_defaultToolMode();
1584 g_currentToolMode = ScaleMode;
1585 g_currentToolModeSupportsComponentEditing = true;
1587 OnClipMode( false );
1589 Sys_Status( c_ScaleMode_status );
1590 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eScale );
1597 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1601 if ( g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode ) {
1602 g_defaultToolMode();
1606 g_currentToolMode = ClipperMode;
1607 g_currentToolModeSupportsComponentEditing = false;
1609 SelectionSystem_DefaultMode();
1613 Sys_Status( c_ClipperMode_status );
1614 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eClip );
1621 void Texdef_Rotate( float angle ){
1622 StringOutputStream command;
1623 command << "brushRotateTexture -angle " << angle;
1624 UndoableCommand undo( command.c_str() );
1625 Select_RotateTexture( angle );
1628 void Texdef_RotateClockwise(){
1629 Texdef_Rotate( static_cast<float>( fabs( g_si_globals.rotate ) ) );
1632 void Texdef_RotateAntiClockwise(){
1633 Texdef_Rotate( static_cast<float>( -fabs( g_si_globals.rotate ) ) );
1636 void Texdef_Scale( float x, float y ){
1637 StringOutputStream command;
1638 command << "brushScaleTexture -x " << x << " -y " << y;
1639 UndoableCommand undo( command.c_str() );
1640 Select_ScaleTexture( x, y );
1643 void Texdef_ScaleUp(){
1644 Texdef_Scale( 0, g_si_globals.scale[1] );
1647 void Texdef_ScaleDown(){
1648 Texdef_Scale( 0, -g_si_globals.scale[1] );
1651 void Texdef_ScaleLeft(){
1652 Texdef_Scale( -g_si_globals.scale[0],0 );
1655 void Texdef_ScaleRight(){
1656 Texdef_Scale( g_si_globals.scale[0],0 );
1659 void Texdef_Shift( float x, float y ){
1660 StringOutputStream command;
1661 command << "brushShiftTexture -x " << x << " -y " << y;
1662 UndoableCommand undo( command.c_str() );
1663 Select_ShiftTexture( x, y );
1666 void Texdef_ShiftLeft(){
1667 Texdef_Shift( -g_si_globals.shift[0], 0 );
1670 void Texdef_ShiftRight(){
1671 Texdef_Shift( g_si_globals.shift[0], 0 );
1674 void Texdef_ShiftUp(){
1675 Texdef_Shift( 0, g_si_globals.shift[1] );
1678 void Texdef_ShiftDown(){
1679 Texdef_Shift( 0, -g_si_globals.shift[1] );
1684 class SnappableSnapToGridSelected : public scene::Graph::Walker
1688 SnappableSnapToGridSelected( float snap )
1692 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1693 if ( path.top().get().visible() ) {
1694 Snappable* snappable = Node_getSnappable( path.top() );
1696 && Instance_getSelectable( instance )->isSelected() ) {
1697 snappable->snapto( m_snap );
1704 void Scene_SnapToGrid_Selected( scene::Graph& graph, float snap ){
1705 graph.traverse( SnappableSnapToGridSelected( snap ) );
1708 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1712 ComponentSnappableSnapToGridSelected( float snap )
1716 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1717 if ( path.top().get().visible() ) {
1718 ComponentSnappable* componentSnappable = Instance_getComponentSnappable( instance );
1719 if ( componentSnappable != 0
1720 && Instance_getSelectable( instance )->isSelected() ) {
1721 componentSnappable->snapComponents( m_snap );
1728 void Scene_SnapToGrid_Component_Selected( scene::Graph& graph, float snap ){
1729 graph.traverse( ComponentSnappableSnapToGridSelected( snap ) );
1732 void Selection_SnapToGrid(){
1733 StringOutputStream command;
1734 command << "snapSelected -grid " << GetGridSize();
1735 UndoableCommand undo( command.c_str() );
1737 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1738 Scene_SnapToGrid_Component_Selected( GlobalSceneGraph(), GetGridSize() );
1742 Scene_SnapToGrid_Selected( GlobalSceneGraph(), GetGridSize() );
1747 static gint qe_every_second( gpointer data ){
1748 GdkModifierType mask;
1750 gdk_window_get_pointer( 0, 0, 0, &mask );
1752 if ( ( mask & ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK ) ) == 0 ) {
1759 guint s_qe_every_second_id = 0;
1761 void EverySecondTimer_enable(){
1762 if ( s_qe_every_second_id == 0 ) {
1763 s_qe_every_second_id = g_timeout_add( 1000, qe_every_second, 0 );
1767 void EverySecondTimer_disable(){
1768 if ( s_qe_every_second_id != 0 ) {
1769 g_source_remove( s_qe_every_second_id );
1770 s_qe_every_second_id = 0;
1774 gint window_realize_remove_decoration( ui::Widget widget, gpointer data ){
1775 gdk_window_set_decorations( gtk_widget_get_window(widget), (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) );
1782 ui::Window m_window{ui::null};
1783 ui::Label m_label{ui::null};
1786 WaitDialog create_wait_dialog( const char* title, const char* text ){
1789 dialog.m_window = MainFrame_getWindow().create_floating_window(title);
1790 gtk_window_set_resizable( dialog.m_window, FALSE );
1791 gtk_container_set_border_width( GTK_CONTAINER( dialog.m_window ), 0 );
1792 gtk_window_set_position( dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT );
1794 dialog.m_window.connect( "realize", G_CALLBACK( window_realize_remove_decoration ), 0 );
1797 dialog.m_label = ui::Label( text );
1798 gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 );
1799 gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT );
1800 dialog.m_label.show();
1801 dialog.m_label.dimensions(200, -1);
1803 dialog.m_window.add(dialog.m_label);
1810 clock_t g_lastRedrawTime = 0;
1811 const clock_t c_redrawInterval = clock_t( CLOCKS_PER_SEC / 10 );
1813 bool redrawRequired(){
1814 clock_t currentTime = std::clock();
1815 if ( currentTime - g_lastRedrawTime >= c_redrawInterval ) {
1816 g_lastRedrawTime = currentTime;
1823 bool MainFrame_isActiveApp(){
1824 //globalOutputStream() << "listing\n";
1825 GList* list = gtk_window_list_toplevels();
1826 for ( GList* i = list; i != 0; i = g_list_next( i ) )
1828 //globalOutputStream() << "toplevel.. ";
1829 if ( gtk_window_is_active( ui::Window::from( i->data ) ) ) {
1830 //globalOutputStream() << "is active\n";
1833 //globalOutputStream() << "not active\n";
1838 typedef std::list<CopiedString> StringStack;
1839 StringStack g_wait_stack;
1842 bool ScreenUpdates_Enabled(){
1843 return g_wait_stack.empty();
1846 void ScreenUpdates_process(){
1847 if ( redrawRequired() && g_wait.m_window.visible() ) {
1853 void ScreenUpdates_Disable( const char* message, const char* title ){
1854 if ( g_wait_stack.empty() ) {
1855 EverySecondTimer_disable();
1859 bool isActiveApp = MainFrame_isActiveApp();
1861 g_wait = create_wait_dialog( title, message );
1862 gtk_grab_add( g_wait.m_window );
1864 if ( isActiveApp ) {
1865 g_wait.m_window.show();
1866 ScreenUpdates_process();
1869 else if ( g_wait.m_window.visible() ) {
1870 g_wait.m_label.text(message);
1871 ScreenUpdates_process();
1873 g_wait_stack.push_back( message );
1876 void ScreenUpdates_Enable(){
1877 ASSERT_MESSAGE( !ScreenUpdates_Enabled(), "screen updates already enabled" );
1878 g_wait_stack.pop_back();
1879 if ( g_wait_stack.empty() ) {
1880 EverySecondTimer_enable();
1881 //gtk_widget_set_sensitive(MainFrame_getWindow(), TRUE);
1883 gtk_grab_remove( g_wait.m_window );
1884 destroy_floating_window( g_wait.m_window );
1885 g_wait.m_window = ui::Window{ui::null};
1887 //gtk_window_present(MainFrame_getWindow());
1889 else if ( g_wait.m_window.visible() ) {
1890 g_wait.m_label.text(g_wait_stack.back().c_str());
1891 ScreenUpdates_process();
1896 void GlobalCamera_UpdateWindow(){
1897 if ( g_pParentWnd != 0 ) {
1898 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
1902 void XY_UpdateWindow( MainFrame& mainframe ){
1903 if ( mainframe.GetXYWnd() != 0 ) {
1904 XYWnd_Update( *mainframe.GetXYWnd() );
1908 void XZ_UpdateWindow( MainFrame& mainframe ){
1909 if ( mainframe.GetXZWnd() != 0 ) {
1910 XYWnd_Update( *mainframe.GetXZWnd() );
1914 void YZ_UpdateWindow( MainFrame& mainframe ){
1915 if ( mainframe.GetYZWnd() != 0 ) {
1916 XYWnd_Update( *mainframe.GetYZWnd() );
1920 void XY_UpdateAllWindows( MainFrame& mainframe ){
1921 XY_UpdateWindow( mainframe );
1922 XZ_UpdateWindow( mainframe );
1923 YZ_UpdateWindow( mainframe );
1926 void XY_UpdateAllWindows(){
1927 if ( g_pParentWnd != 0 ) {
1928 XY_UpdateAllWindows( *g_pParentWnd );
1932 void UpdateAllWindows(){
1933 GlobalCamera_UpdateWindow();
1934 XY_UpdateAllWindows();
1938 void ModeChangeNotify(){
1939 SceneChangeNotify();
1942 void ClipperChangeNotify(){
1943 GlobalCamera_UpdateWindow();
1944 XY_UpdateAllWindows();
1948 LatchedValue<int> g_Layout_viewStyle( 0, "Window Layout" );
1949 LatchedValue<bool> g_Layout_enableDetachableMenus( true, "Detachable Menus" );
1950 LatchedValue<bool> g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
1951 LatchedValue<bool> g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
1952 LatchedValue<bool> g_Layout_enableFilterToolbar( true, "Filter Toolbar" );
1955 ui::MenuItem create_file_menu(){
1957 auto file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
1958 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( file_menu_item ) );
1959 if ( g_Layout_enableDetachableMenus.m_value ) {
1960 menu_tearoff( menu );
1963 create_menu_item_with_mnemonic( menu, "_New Map", "NewMap" );
1964 menu_separator( menu );
1967 //++timo temporary experimental stuff for sleep mode..
1968 create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" );
1969 menu_separator( menu );
1973 create_menu_item_with_mnemonic( menu, "_Open...", "OpenMap" );
1975 create_menu_item_with_mnemonic( menu, "_Import...", "ImportMap" );
1976 create_menu_item_with_mnemonic( menu, "_Save", "SaveMap" );
1977 create_menu_item_with_mnemonic( menu, "Save _as...", "SaveMapAs" );
1978 create_menu_item_with_mnemonic( menu, "_Export selected...", "ExportSelected" );
1979 menu_separator( menu );
1980 create_menu_item_with_mnemonic( menu, "Save re_gion...", "SaveRegion" );
1981 // menu_separator( menu );
1982 // create_menu_item_with_mnemonic( menu, "_Refresh models", "RefreshReferences" );
1983 // menu_separator( menu );
1984 create_menu_item_with_mnemonic( menu, "Pro_ject settings...", "ProjectSettings" );
1985 menu_separator( menu );
1986 create_menu_item_with_mnemonic( menu, "_Pointfile...", "TogglePointfile" );
1987 menu_separator( menu );
1988 MRU_constructMenu( menu );
1989 menu_separator( menu );
1990 // create_menu_item_with_mnemonic( menu, "Check for NetRadiant update (web)", "CheckForUpdate" ); // FIXME
1991 create_menu_item_with_mnemonic( menu, "E_xit", "Exit" );
1993 return file_menu_item;
1996 ui::MenuItem create_edit_menu(){
1998 auto edit_menu_item = new_sub_menu_item_with_mnemonic( "_Edit" );
1999 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( edit_menu_item ) );
2000 if ( g_Layout_enableDetachableMenus.m_value ) {
2001 menu_tearoff( menu );
2003 create_menu_item_with_mnemonic( menu, "_Undo", "Undo" );
2004 create_menu_item_with_mnemonic( menu, "_Redo", "Redo" );
2005 menu_separator( menu );
2006 create_menu_item_with_mnemonic( menu, "_Copy", "Copy" );
2007 create_menu_item_with_mnemonic( menu, "_Paste", "Paste" );
2008 create_menu_item_with_mnemonic( menu, "P_aste To Camera", "PasteToCamera" );
2009 menu_separator( menu );
2010 create_menu_item_with_mnemonic( menu, "_Duplicate", "CloneSelection" );
2011 create_menu_item_with_mnemonic( menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique" );
2012 create_menu_item_with_mnemonic( menu, "D_elete", "DeleteSelection" );
2013 //create_menu_item_with_mnemonic( menu, "Pa_rent", "ParentSelection" );
2014 menu_separator( menu );
2015 create_menu_item_with_mnemonic( menu, "C_lear Selection", "UnSelectSelection" );
2016 create_menu_item_with_mnemonic( menu, "_Invert Selection", "InvertSelection" );
2017 create_menu_item_with_mnemonic( menu, "Select i_nside", "SelectInside" );
2018 create_menu_item_with_mnemonic( menu, "Select _touching", "SelectTouching" );
2020 menu_separator( menu );
2022 // auto convert_menu = create_sub_menu_with_mnemonic( menu, "E_xpand Selection" );
2023 // if ( g_Layout_enableDetachableMenus.m_value ) {
2024 // menu_tearoff( convert_menu );
2026 create_menu_item_with_mnemonic( menu, "Select All Of Type", "SelectAllOfType" );
2027 create_menu_item_with_mnemonic( menu, "_Expand Selection To Entities", "ExpandSelectionToEntities" );
2029 menu_separator( menu );
2030 create_menu_item_with_mnemonic( menu, "Pre_ferences...", "Preferences" );
2032 return edit_menu_item;
2035 void fill_view_xy_top_menu( ui::Menu menu ){
2036 create_check_menu_item_with_mnemonic( menu, "XY (Top) View", "ToggleView" );
2040 void fill_view_yz_side_menu( ui::Menu menu ){
2041 create_check_menu_item_with_mnemonic( menu, "YZ (Side) View", "ToggleSideView" );
2045 void fill_view_xz_front_menu( ui::Menu menu ){
2046 create_check_menu_item_with_mnemonic( menu, "XZ (Front) View", "ToggleFrontView" );
2050 ui::Widget g_toggle_z_item{ui::null};
2051 ui::Widget g_toggle_console_item{ui::null};
2052 ui::Widget g_toggle_entity_item{ui::null};
2053 ui::Widget g_toggle_entitylist_item{ui::null};
2055 ui::MenuItem create_view_menu( MainFrame::EViewStyle style ){
2057 auto view_menu_item = new_sub_menu_item_with_mnemonic( "Vie_w" );
2058 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( view_menu_item ) );
2059 if ( g_Layout_enableDetachableMenus.m_value ) {
2060 menu_tearoff( menu );
2063 if ( style == MainFrame::eFloating ) {
2064 fill_view_camera_menu( menu );
2065 fill_view_xy_top_menu( menu );
2066 fill_view_yz_side_menu( menu );
2067 fill_view_xz_front_menu( menu );
2069 if ( style == MainFrame::eFloating || style == MainFrame::eSplit ) {
2070 create_menu_item_with_mnemonic( menu, "Console View", "ToggleConsole" );
2071 create_menu_item_with_mnemonic( menu, "Texture Browser", "ToggleTextures" );
2072 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ToggleEntityInspector" );
2076 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ViewEntityInfo" );
2078 create_menu_item_with_mnemonic( menu, "_Surface Inspector", "SurfaceInspector" );
2079 create_menu_item_with_mnemonic( menu, "_Patch Inspector", "PatchInspector" );
2080 create_menu_item_with_mnemonic( menu, "Entity List", "EntityList" );
2082 menu_separator( menu );
2084 auto camera_menu = create_sub_menu_with_mnemonic( menu, "Camera" );
2085 if ( g_Layout_enableDetachableMenus.m_value ) {
2086 menu_tearoff( camera_menu );
2088 create_menu_item_with_mnemonic( camera_menu, "_Center", "CenterView" );
2089 create_menu_item_with_mnemonic( camera_menu, "_Up Floor", "UpFloor" );
2090 create_menu_item_with_mnemonic( camera_menu, "_Down Floor", "DownFloor" );
2091 menu_separator( camera_menu );
2092 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane In", "CubicClipZoomIn" );
2093 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane Out", "CubicClipZoomOut" );
2094 menu_separator( camera_menu );
2095 create_menu_item_with_mnemonic( camera_menu, "Next leak spot", "NextLeakSpot" );
2096 create_menu_item_with_mnemonic( camera_menu, "Previous leak spot", "PrevLeakSpot" );
2097 menu_separator( camera_menu );
2098 create_menu_item_with_mnemonic( camera_menu, "Look Through Selected", "LookThroughSelected" );
2099 create_menu_item_with_mnemonic( camera_menu, "Look Through Camera", "LookThroughCamera" );
2101 menu_separator( menu );
2103 auto orthographic_menu = create_sub_menu_with_mnemonic( menu, "Orthographic" );
2104 if ( g_Layout_enableDetachableMenus.m_value ) {
2105 menu_tearoff( orthographic_menu );
2107 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2108 create_menu_item_with_mnemonic( orthographic_menu, "_Next (XY, YZ, XY)", "NextView" );
2109 create_menu_item_with_mnemonic( orthographic_menu, "XY (Top)", "ViewTop" );
2110 create_menu_item_with_mnemonic( orthographic_menu, "YZ", "ViewSide" );
2111 create_menu_item_with_mnemonic( orthographic_menu, "XZ", "ViewFront" );
2112 menu_separator( orthographic_menu );
2115 create_menu_item_with_mnemonic( orthographic_menu, "Center on Selected", "CenterXYView" );
2116 menu_separator( orthographic_menu );
2117 create_menu_item_with_mnemonic( orthographic_menu, "_XY 100%", "Zoom100" );
2118 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _In", "ZoomIn" );
2119 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _Out", "ZoomOut" );
2122 menu_separator( menu );
2125 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Show" );
2126 if ( g_Layout_enableDetachableMenus.m_value ) {
2127 menu_tearoff( menu_in_menu );
2129 create_menu_item_with_mnemonic( menu_in_menu, "Show Size Info", "ToggleSizePaint" );
2130 create_menu_item_with_mnemonic( menu_in_menu, "Show Crosshair", "ToggleCrosshairs" );
2131 create_menu_item_with_mnemonic( menu_in_menu, "Show Grid", "ToggleGrid" );
2133 menu_separator( menu_in_menu );
2135 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Angles", "ShowAngles" );
2136 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Names", "ShowNames" );
2137 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Blocks", "ShowBlocks" );
2138 create_check_menu_item_with_mnemonic( menu_in_menu, "Show C_oordinates", "ShowCoordinates" );
2139 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Window Outline", "ShowWindowOutline" );
2140 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Axes", "ShowAxes" );
2141 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Workzone", "ShowWorkzone" );
2142 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Stats", "ShowStats" );
2146 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Filter" );
2147 if ( g_Layout_enableDetachableMenus.m_value ) {
2148 menu_tearoff( menu_in_menu );
2150 Filters_constructMenu( menu_in_menu );
2152 menu_separator( menu );
2154 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Hide/Show" );
2155 // if ( g_Layout_enableDetachableMenus.m_value ) {
2156 // menu_tearoff( menu_in_menu );
2158 // create_menu_item_with_mnemonic( menu_in_menu, "Hide Selected", "HideSelected" );
2159 // create_menu_item_with_mnemonic( menu_in_menu, "Show Hidden", "ShowHidden" );
2160 create_menu_item_with_mnemonic( menu, "Hide Selected", "HideSelected" );
2161 create_menu_item_with_mnemonic( menu, "Show Hidden", "ShowHidden" );
2163 menu_separator( menu );
2165 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Region" );
2166 if ( g_Layout_enableDetachableMenus.m_value ) {
2167 menu_tearoff( menu_in_menu );
2169 create_menu_item_with_mnemonic( menu_in_menu, "_Off", "RegionOff" );
2170 create_menu_item_with_mnemonic( menu_in_menu, "_Set XY", "RegionSetXY" );
2171 create_menu_item_with_mnemonic( menu_in_menu, "Set _Brush", "RegionSetBrush" );
2172 create_menu_item_with_mnemonic( menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection" );
2175 command_connect_accelerator( "CenterXYView" );
2177 return view_menu_item;
2180 ui::MenuItem create_selection_menu(){
2182 auto selection_menu_item = new_sub_menu_item_with_mnemonic( "M_odify" );
2183 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( selection_menu_item ) );
2184 if ( g_Layout_enableDetachableMenus.m_value ) {
2185 menu_tearoff( menu );
2189 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Components" );
2190 if ( g_Layout_enableDetachableMenus.m_value ) {
2191 menu_tearoff( menu_in_menu );
2193 create_check_menu_item_with_mnemonic( menu_in_menu, "_Edges", "DragEdges" );
2194 create_check_menu_item_with_mnemonic( menu_in_menu, "_Vertices", "DragVertices" );
2195 create_check_menu_item_with_mnemonic( menu_in_menu, "_Faces", "DragFaces" );
2198 menu_separator( menu );
2199 create_menu_item_with_mnemonic( menu, "Snap To Grid", "SnapToGrid" );
2201 menu_separator( menu );
2204 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Nudge" );
2205 if ( g_Layout_enableDetachableMenus.m_value ) {
2206 menu_tearoff( menu_in_menu );
2208 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Left", "SelectNudgeLeft" );
2209 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Right", "SelectNudgeRight" );
2210 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Up", "SelectNudgeUp" );
2211 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Down", "SelectNudgeDown" );
2214 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Rotate" );
2215 if ( g_Layout_enableDetachableMenus.m_value ) {
2216 menu_tearoff( menu_in_menu );
2218 create_menu_item_with_mnemonic( menu_in_menu, "Rotate X", "RotateSelectionX" );
2219 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Y", "RotateSelectionY" );
2220 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Z", "RotateSelectionZ" );
2223 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Flip" );
2224 if ( g_Layout_enableDetachableMenus.m_value ) {
2225 menu_tearoff( menu_in_menu );
2227 create_menu_item_with_mnemonic( menu_in_menu, "Flip _X", "MirrorSelectionX" );
2228 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Y", "MirrorSelectionY" );
2229 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Z", "MirrorSelectionZ" );
2231 menu_separator( menu );
2232 create_menu_item_with_mnemonic( menu, "Arbitrary rotation...", "ArbitraryRotation" );
2233 create_menu_item_with_mnemonic( menu, "Arbitrary scale...", "ArbitraryScale" );
2235 return selection_menu_item;
2238 ui::MenuItem create_bsp_menu(){
2240 auto bsp_menu_item = new_sub_menu_item_with_mnemonic( "_Build" );
2241 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( bsp_menu_item ) );
2243 if ( g_Layout_enableDetachableMenus.m_value ) {
2244 menu_tearoff( menu );
2247 create_menu_item_with_mnemonic( menu, "Customize...", "BuildMenuCustomize" );
2249 menu_separator( menu );
2251 Build_constructMenu( menu );
2255 return bsp_menu_item;
2258 ui::MenuItem create_grid_menu(){
2260 auto grid_menu_item = new_sub_menu_item_with_mnemonic( "_Grid" );
2261 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( grid_menu_item ) );
2262 if ( g_Layout_enableDetachableMenus.m_value ) {
2263 menu_tearoff( menu );
2266 Grid_constructMenu( menu );
2268 return grid_menu_item;
2271 ui::MenuItem create_misc_menu(){
2273 auto misc_menu_item = new_sub_menu_item_with_mnemonic( "M_isc" );
2274 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( misc_menu_item ) );
2275 if ( g_Layout_enableDetachableMenus.m_value ) {
2276 menu_tearoff( menu );
2280 create_menu_item_with_mnemonic( menu, "_Benchmark", makeCallbackF(GlobalCamera_Benchmark) );
2282 menu.add(create_colours_menu());
2284 create_menu_item_with_mnemonic( menu, "Find brush...", "FindBrush" );
2285 create_menu_item_with_mnemonic( menu, "Map Info...", "MapInfo" );
2286 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2287 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<void(), WXY_Print>());
2288 create_menu_item_with_mnemonic( menu, "_Background select", makeCallbackF(WXY_BackgroundSelect) );
2289 return misc_menu_item;
2292 ui::MenuItem create_entity_menu(){
2294 auto entity_menu_item = new_sub_menu_item_with_mnemonic( "E_ntity" );
2295 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( entity_menu_item ) );
2296 if ( g_Layout_enableDetachableMenus.m_value ) {
2297 menu_tearoff( menu );
2300 Entity_constructMenu( menu );
2302 return entity_menu_item;
2305 ui::MenuItem create_brush_menu(){
2307 auto brush_menu_item = new_sub_menu_item_with_mnemonic( "B_rush" );
2308 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( brush_menu_item ) );
2309 if ( g_Layout_enableDetachableMenus.m_value ) {
2310 menu_tearoff( menu );
2313 Brush_constructMenu( menu );
2315 return brush_menu_item;
2318 ui::MenuItem create_patch_menu(){
2320 auto patch_menu_item = new_sub_menu_item_with_mnemonic( "_Curve" );
2321 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( patch_menu_item ) );
2322 if ( g_Layout_enableDetachableMenus.m_value ) {
2323 menu_tearoff( menu );
2326 Patch_constructMenu( menu );
2328 return patch_menu_item;
2331 ui::MenuItem create_help_menu(){
2333 auto help_menu_item = new_sub_menu_item_with_mnemonic( "_Help" );
2334 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( help_menu_item ) );
2335 if ( g_Layout_enableDetachableMenus.m_value ) {
2336 menu_tearoff( menu );
2339 // create_menu_item_with_mnemonic( menu, "Manual", "OpenManual" );
2341 // this creates all the per-game drop downs for the game pack helps
2342 // it will take care of hooking the Sys_OpenURL calls etc.
2343 create_game_help_menu( menu );
2345 create_menu_item_with_mnemonic( menu, "Bug report", makeCallbackF(OpenBugReportURL) );
2346 create_menu_item_with_mnemonic( menu, "Shortcuts list", makeCallbackF(DoCommandListDlg) );
2347 create_menu_item_with_mnemonic( menu, "_About", makeCallbackF(DoAbout) );
2349 return help_menu_item;
2352 ui::MenuBar create_main_menu( MainFrame::EViewStyle style ){
2353 auto menu_bar = ui::MenuBar::from( gtk_menu_bar_new() );
2356 menu_bar.add(create_file_menu());
2357 menu_bar.add(create_edit_menu());
2358 menu_bar.add(create_view_menu(style));
2359 menu_bar.add(create_selection_menu());
2360 menu_bar.add(create_bsp_menu());
2361 menu_bar.add(create_grid_menu());
2362 menu_bar.add(create_misc_menu());
2363 menu_bar.add(create_entity_menu());
2364 menu_bar.add(create_brush_menu());
2365 menu_bar.add(create_patch_menu());
2366 menu_bar.add(create_plugins_menu());
2367 menu_bar.add(create_help_menu());
2373 void PatchInspector_registerShortcuts(){
2374 command_connect_accelerator( "PatchInspector" );
2377 void Patch_registerShortcuts(){
2378 command_connect_accelerator( "InvertCurveTextureX" );
2379 command_connect_accelerator( "InvertCurveTextureY" );
2380 command_connect_accelerator( "PatchInsertInsertColumn" );
2381 command_connect_accelerator( "PatchInsertInsertRow" );
2382 command_connect_accelerator( "PatchDeleteLastColumn" );
2383 command_connect_accelerator( "PatchDeleteLastRow" );
2384 command_connect_accelerator( "NaturalizePatch" );
2385 command_connect_accelerator( "CapCurrentCurve");
2388 void Manipulators_registerShortcuts(){
2389 toggle_add_accelerator( "MouseRotate" );
2390 toggle_add_accelerator( "MouseTranslate" );
2391 toggle_add_accelerator( "MouseScale" );
2392 toggle_add_accelerator( "MouseDrag" );
2393 toggle_add_accelerator( "ToggleClipper" );
2396 void TexdefNudge_registerShortcuts(){
2397 command_connect_accelerator( "TexRotateClock" );
2398 command_connect_accelerator( "TexRotateCounter" );
2399 command_connect_accelerator( "TexScaleUp" );
2400 command_connect_accelerator( "TexScaleDown" );
2401 command_connect_accelerator( "TexScaleLeft" );
2402 command_connect_accelerator( "TexScaleRight" );
2403 command_connect_accelerator( "TexShiftUp" );
2404 command_connect_accelerator( "TexShiftDown" );
2405 command_connect_accelerator( "TexShiftLeft" );
2406 command_connect_accelerator( "TexShiftRight" );
2409 void SelectNudge_registerShortcuts(){
2410 command_connect_accelerator( "MoveSelectionDOWN" );
2411 command_connect_accelerator( "MoveSelectionUP" );
2412 //command_connect_accelerator("SelectNudgeLeft");
2413 //command_connect_accelerator("SelectNudgeRight");
2414 //command_connect_accelerator("SelectNudgeUp");
2415 //command_connect_accelerator("SelectNudgeDown");
2416 command_connect_accelerator( "UnSelectSelection2" );
2417 command_connect_accelerator( "DeleteSelection2" );
2420 void SnapToGrid_registerShortcuts(){
2421 command_connect_accelerator( "SnapToGrid" );
2424 void SelectByType_registerShortcuts(){
2425 command_connect_accelerator( "SelectAllOfType" );
2428 void SurfaceInspector_registerShortcuts(){
2429 command_connect_accelerator( "FitTexture" );
2433 void register_shortcuts(){
2434 // PatchInspector_registerShortcuts();
2435 Patch_registerShortcuts();
2436 Grid_registerShortcuts();
2437 // XYWnd_registerShortcuts();
2438 CamWnd_registerShortcuts();
2439 Manipulators_registerShortcuts();
2440 SurfaceInspector_registerShortcuts();
2441 TexdefNudge_registerShortcuts();
2442 SelectNudge_registerShortcuts();
2443 // SnapToGrid_registerShortcuts();
2444 // SelectByType_registerShortcuts();
2447 void File_constructToolbar( ui::Toolbar toolbar ){
2448 toolbar_append_button( toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap" );
2449 toolbar_append_button( toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap" );
2452 void UndoRedo_constructToolbar( ui::Toolbar toolbar ){
2453 toolbar_append_button( toolbar, "Undo (CTRL + Z)", "undo.png", "Undo" );
2454 toolbar_append_button( toolbar, "Redo (CTRL + Y)", "redo.png", "Redo" );
2457 void RotateFlip_constructToolbar( ui::Toolbar toolbar ){
2458 toolbar_append_button( toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX" );
2459 toolbar_append_button( toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX" );
2460 toolbar_append_button( toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY" );
2461 toolbar_append_button( toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY" );
2462 toolbar_append_button( toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ" );
2463 toolbar_append_button( toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ" );
2466 void Select_constructToolbar( ui::Toolbar toolbar ){
2467 toolbar_append_button( toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching" );
2468 toolbar_append_button( toolbar, "Select inside", "selection_selectinside.png", "SelectInside" );
2471 void CSG_constructToolbar( ui::Toolbar toolbar ){
2472 toolbar_append_button( toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract" );
2473 toolbar_append_button( toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge" );
2474 toolbar_append_button( toolbar, "Make Hollow", "selection_makehollow.png", "CSGHollow" );
2475 toolbar_append_button( toolbar, "Make Room", "selection_makeroom.png", "CSGRoom" );
2478 void ComponentModes_constructToolbar( ui::Toolbar toolbar ){
2479 toolbar_append_toggle_button( toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices" );
2480 toolbar_append_toggle_button( toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges" );
2481 toolbar_append_toggle_button( toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces" );
2484 void Clipper_constructToolbar( ui::Toolbar toolbar ){
2486 toolbar_append_toggle_button( toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper" );
2489 void XYWnd_constructToolbar( ui::Toolbar toolbar ){
2490 toolbar_append_button( toolbar, "Change views", "view_change.png", "NextView" );
2493 void Manipulators_constructToolbar( ui::Toolbar toolbar ){
2494 toolbar_append_toggle_button( toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate" );
2495 toolbar_append_toggle_button( toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate" );
2496 toolbar_append_toggle_button( toolbar, "Scale", "select_mousescale.png", "MouseScale" );
2497 toolbar_append_toggle_button( toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag" );
2499 Clipper_constructToolbar( toolbar );
2502 ui::Toolbar create_main_toolbar( MainFrame::EViewStyle style ){
2503 auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
2504 gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL );
2505 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
2509 auto space = [&]() {
2510 auto btn = ui::ToolItem::from(gtk_separator_tool_item_new());
2515 File_constructToolbar( toolbar );
2519 UndoRedo_constructToolbar( toolbar );
2523 RotateFlip_constructToolbar( toolbar );
2527 Select_constructToolbar( toolbar );
2531 CSG_constructToolbar( toolbar );
2535 ComponentModes_constructToolbar( toolbar );
2537 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2540 XYWnd_constructToolbar( toolbar );
2545 CamWnd_constructToolbar( toolbar );
2549 Manipulators_constructToolbar( toolbar );
2551 if ( g_Layout_enablePatchToolbar.m_value ) {
2554 Patch_constructToolbar( toolbar );
2559 toolbar_append_toggle_button( toolbar, "Texture Lock (SHIFT +T)", "texture_lock.png", "TogTexLock" );
2563 /*auto g_view_entities_button =*/ toolbar_append_button( toolbar, "Entities (N)", "entities.png", "ToggleEntityInspector" );
2564 auto g_view_console_button = toolbar_append_button( toolbar, "Console (O)", "console.png", "ToggleConsole" );
2565 auto g_view_textures_button = toolbar_append_button( toolbar, "Texture Browser (T)", "texture_browser.png", "ToggleTextures" );
2566 // TODO: call light inspector
2567 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector");
2570 /*auto g_refresh_models_button =*/ toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" );
2573 // disable the console and texture button in the regular layouts
2574 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft ) {
2575 gtk_widget_set_sensitive( g_view_console_button , FALSE );
2576 gtk_widget_set_sensitive( g_view_textures_button , FALSE );
2582 ui::Widget create_main_statusbar( ui::Widget pStatusLabel[c_count_status] ){
2583 auto table = ui::Table( 1, c_count_status, FALSE );
2587 auto label = ui::Label( "Label" );
2588 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2589 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2591 table.attach(label, {0, 1, 0, 1});
2592 pStatusLabel[c_command_status] = ui::Widget(label );
2595 for (unsigned int i = 1; (int) i < c_count_status; ++i)
2597 auto frame = ui::Frame();
2599 table.attach(frame, {i, i + 1, 0, 1});
2600 gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
2602 auto label = ui::Label( "Label" );
2603 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END );
2604 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2605 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2608 pStatusLabel[i] = ui::Widget(label );
2611 return ui::Widget(table );
2617 WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" );
2619 class WindowFocusPrinter
2623 static gboolean frame_event( ui::Widget widget, GdkEvent* event, WindowFocusPrinter* self ){
2624 globalOutputStream() << self->m_name << " frame_event\n";
2627 static gboolean keys_changed( ui::Widget widget, WindowFocusPrinter* self ){
2628 globalOutputStream() << self->m_name << " keys_changed\n";
2631 static gboolean notify( ui::Window window, gpointer dummy, WindowFocusPrinter* self ){
2632 if ( gtk_window_is_active( window ) ) {
2633 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2637 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2642 WindowFocusPrinter( const char* name ) : m_name( name ){
2644 void connect( ui::Window toplevel_window ){
2645 toplevel_window.connect( "notify::has_toplevel_focus", G_CALLBACK( notify ), this );
2646 toplevel_window.connect( "notify::is_active", G_CALLBACK( notify ), this );
2647 toplevel_window.connect( "keys_changed", G_CALLBACK( keys_changed ), this );
2648 toplevel_window.connect( "frame_event", G_CALLBACK( frame_event ), this );
2652 WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" );
2656 class MainWindowActive
2658 static gboolean notify( ui::Window window, gpointer dummy, MainWindowActive* self ){
2659 if ( g_wait.m_window && gtk_window_is_active( window ) && !g_wait.m_window.visible() ) {
2660 g_wait.m_window.show();
2667 void connect( ui::Window toplevel_window ){
2668 toplevel_window.connect( "notify::is-active", G_CALLBACK( notify ), this );
2672 MainWindowActive g_MainWindowActive;
2674 SignalHandlerId XYWindowDestroyed_connect( const SignalHandler& handler ){
2675 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst( handler );
2678 void XYWindowDestroyed_disconnect( SignalHandlerId id ){
2679 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect( id );
2682 MouseEventHandlerId XYWindowMouseDown_connect( const MouseEventHandler& handler ){
2683 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst( handler );
2686 void XYWindowMouseDown_disconnect( MouseEventHandlerId id ){
2687 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect( id );
2690 // =============================================================================
2693 MainFrame* g_pParentWnd = 0;
2695 ui::Window MainFrame_getWindow()
2697 return g_pParentWnd ? g_pParentWnd->m_window : ui::Window{ui::null};
2700 std::vector<ui::Widget> g_floating_windows;
2702 MainFrame::MainFrame() : m_idleRedrawStatusText( RedrawStatusTextCaller( *this ) ){
2710 for (auto &n : m_pStatusLabel) {
2714 m_bSleeping = false;
2719 MainFrame::~MainFrame(){
2726 for ( std::vector<ui::Widget>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i )
2734 void MainFrame::SetActiveXY( XYWnd* p ){
2735 if ( m_pActiveXY ) {
2736 m_pActiveXY->SetActive( false );
2741 if ( m_pActiveXY ) {
2742 m_pActiveXY->SetActive( true );
2747 void MainFrame::ReleaseContexts(){
2750 m_pXYWnd->DestroyContext();
2753 m_pYZWnd->DestroyContext();
2756 m_pXZWnd->DestroyContext();
2759 m_pCamWnd->DestroyContext();
2762 m_pTexWnd->DestroyContext();
2765 m_pZWnd->DestroyContext();
2770 void MainFrame::CreateContexts(){
2773 m_pCamWnd->CreateContext();
2776 m_pXYWnd->CreateContext();
2779 m_pYZWnd->CreateContext();
2782 m_pXZWnd->CreateContext();
2785 m_pTexWnd->CreateContext();
2788 m_pZWnd->CreateContext();
2797 void MainFrame::OnSleep(){
2800 if ( m_bSleeping ) {
2801 // useful when trying to debug crashes in the sleep code
2802 globalOutputStream() << "Going into sleep mode..\n";
2804 globalOutputStream() << "Dispatching sleep msg...";
2805 DispatchRadiantMsg( RADIANT_SLEEP );
2806 globalOutputStream() << "Done.\n";
2808 gtk_window_iconify( m_window );
2809 GlobalSelectionSystem().setSelectedAll( false );
2811 GlobalShaderCache().unrealise();
2813 GlobalOpenGL_debugAssertNoErrors();
2814 ScreenUpdates_Disable();
2817 globalOutputStream() << "Releasing contexts...";
2819 globalOutputStream() << "Done.\n";
2823 globalOutputStream() << "Waking up\n";
2825 gtk_window_deiconify( m_window );
2828 globalOutputStream() << "Creating contexts...";
2830 globalOutputStream() << "Done.\n";
2832 globalOutputStream() << "Making current on camera...";
2833 m_pCamWnd->MakeCurrent();
2834 globalOutputStream() << "Done.\n";
2836 globalOutputStream() << "Reloading shaders...";
2838 GlobalShaderCache().realise();
2839 globalOutputStream() << "Done.\n";
2841 ScreenUpdates_Enable();
2843 globalOutputStream() << "Dispatching wake msg...";
2844 DispatchRadiantMsg( RADIANT_WAKEUP );
2845 globalOutputStream() << "Done\n";
2851 ui::Window create_splash(){
2852 auto window = ui::Window( ui::window_type::TOP );
2853 gtk_window_set_decorated(window, false);
2854 gtk_window_set_resizable(window, false);
2855 gtk_window_set_modal(window, true);
2856 gtk_window_set_default_size( window, -1, -1 );
2857 gtk_window_set_position( window, GTK_WIN_POS_CENTER );
2858 gtk_container_set_border_width(window, 0);
2860 auto image = new_local_image( "splash.png" );
2864 window.dimensions(-1, -1);
2870 static ui::Window splash_screen{ui::null};
2873 splash_screen = create_splash();
2879 splash_screen.destroy();
2882 WindowPositionTracker g_posCamWnd;
2883 WindowPositionTracker g_posXYWnd;
2884 WindowPositionTracker g_posXZWnd;
2885 WindowPositionTracker g_posYZWnd;
2887 static gint mainframe_delete( ui::Widget widget, GdkEvent *event, gpointer data ){
2888 if ( ConfirmModified( "Exit Radiant" ) ) {
2895 void MainFrame::Create(){
2896 ui::Window window = ui::Window( ui::window_type::TOP );
2898 GlobalWindowObservers_connectTopLevel( window );
2900 gtk_window_set_transient_for( splash_screen, window );
2902 #if !GDEF_OS_WINDOWS
2904 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
2905 if ( pixbuf != 0 ) {
2906 gtk_window_set_icon( window, pixbuf );
2907 g_object_unref( pixbuf );
2912 gtk_widget_add_events( window , GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
2913 window.connect( "delete_event", G_CALLBACK( mainframe_delete ), this );
2915 m_position_tracker.connect( window );
2918 g_mainframeWidgetFocusPrinter.connect( window );
2919 g_mainframeFocusPrinter.connect( window );
2922 g_MainWindowActive.connect( window );
2924 GetPlugInMgr().Init( window );
2926 auto vbox = ui::VBox( FALSE, 0 );
2930 global_accel_connect_window( window );
2932 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
2934 register_shortcuts();
2936 auto main_menu = create_main_menu( CurrentStyle() );
2937 vbox.pack_start( main_menu, FALSE, FALSE, 0 );
2939 auto main_toolbar = create_main_toolbar( CurrentStyle() );
2940 vbox.pack_start( main_toolbar, FALSE, FALSE, 0 );
2942 if ( g_Layout_enablePluginToolbar.m_value || g_Layout_enableFilterToolbar.m_value ){
2943 auto PFbox = ui::HBox( FALSE, 3 );
2944 vbox.pack_start( PFbox, FALSE, FALSE, 0 );
2946 if ( g_Layout_enablePluginToolbar.m_value ){
2947 auto plugin_toolbar = create_plugin_toolbar();
2948 if ( g_Layout_enableFilterToolbar.m_value ){
2949 PFbox.pack_start( plugin_toolbar, FALSE, FALSE, 0 );
2952 PFbox.pack_start( plugin_toolbar, TRUE, TRUE, 0 );
2955 if ( g_Layout_enableFilterToolbar.m_value ){
2956 ui::Toolbar filter_toolbar = create_filter_toolbar();
2957 PFbox.pack_start( filter_toolbar, TRUE, TRUE, 0 );
2961 /*GtkToolbar* plugin_toolbar = create_plugin_toolbar();
2962 if ( !g_Layout_enablePluginToolbar.m_value ) {
2963 gtk_widget_hide( GTK_WIDGET( plugin_toolbar ) );
2966 ui::Widget main_statusbar = create_main_statusbar(reinterpret_cast<ui::Widget *>(m_pStatusLabel));
2967 vbox.pack_end(main_statusbar, FALSE, TRUE, 2);
2969 GroupDialog_constructWindow( window );
2970 g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) );
2972 if ( FloatingGroupDialog() ) {
2973 g_page_console = GroupDialog_addPage( "Console", Console_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Console" ) );
2977 if ( g_multimon_globals.m_bStartOnPrimMon ) {
2978 PositionWindowOnPrimaryScreen( g_layout_globals.m_position );
2979 window_set_position( window, g_layout_globals.m_position );
2983 if ( g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED ) {
2984 gtk_window_maximize( window );
2985 WindowPosition default_position( -1, -1, 640, 480 );
2986 window_set_position( window, default_position );
2990 window_set_position( window, g_layout_globals.m_position );
2997 if ( CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft ) {
2999 ui::Widget hsplit = ui::HPaned(ui::New);
3002 vbox.pack_start( hsplit, TRUE, TRUE, 0 );
3006 ui::Widget vsplit = ui::VPaned(ui::New);
3010 ui::Widget vsplit2 = ui::VPaned(ui::New);
3012 m_vSplit2 = vsplit2;
3014 if ( CurrentStyle() == eRegular ){
3015 gtk_paned_add1( GTK_PANED( hsplit ), vsplit );
3016 gtk_paned_add2( GTK_PANED( hsplit ), vsplit2 );
3019 gtk_paned_add2( GTK_PANED( hsplit ), vsplit );
3020 gtk_paned_add1( GTK_PANED( hsplit ), vsplit2 );
3024 ui::Widget console_window = Console_constructWindow( window );
3025 gtk_paned_pack2( GTK_PANED( vsplit ), console_window, FALSE, TRUE );
3028 m_pXYWnd = new XYWnd();
3029 m_pXYWnd->SetViewType( XY );
3030 ui::Widget xy_window = ui::Widget(create_framed_widget( m_pXYWnd->GetWidget( ) ));
3031 gtk_paned_add1( GTK_PANED( vsplit ), xy_window );
3035 m_pCamWnd = NewCamWnd();
3036 GlobalCamera_setCamWnd( *m_pCamWnd );
3037 CamWnd_setParent( *m_pCamWnd, window );
3038 auto camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3040 gtk_paned_add1( GTK_PANED( vsplit2 ), camera_window );
3043 auto texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
3045 gtk_paned_add2( GTK_PANED( vsplit2 ), texture_window );
3050 gtk_paned_set_position( GTK_PANED( m_vSplit ), g_layout_globals.nXYHeight );
3052 if ( CurrentStyle() == eRegular ) {
3053 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nXYWidth );
3057 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nCamWidth );
3060 gtk_paned_set_position( GTK_PANED( m_vSplit2 ), g_layout_globals.nCamHeight );
3062 else if ( CurrentStyle() == eFloating ) {
3064 ui::Window window = ui::Window(create_persistent_floating_window( "Camera", m_window ));
3065 global_accel_connect_window( window );
3066 g_posCamWnd.connect( window );
3070 m_pCamWnd = NewCamWnd();
3071 GlobalCamera_setCamWnd( *m_pCamWnd );
3074 auto frame = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3077 CamWnd_setParent( *m_pCamWnd, window );
3078 #define GARUX_GTK_WORKAROUND
3079 #ifndef GARUX_GTK_WORKAROUND
3080 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3081 g_object_set_data( G_OBJECT( window ), "glwidget", CamWnd_getWidget( *m_pCamWnd ) );
3084 g_floating_windows.push_back( window );
3088 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XY ), m_window ));
3089 global_accel_connect_window( window );
3090 g_posXYWnd.connect( window );
3092 m_pXYWnd = new XYWnd();
3093 m_pXYWnd->m_parent = window;
3094 m_pXYWnd->SetViewType( XY );
3098 auto frame = create_framed_widget( m_pXYWnd->GetWidget() );
3101 XY_Top_Shown_Construct( window );
3102 #ifndef GARUX_GTK_WORKAROUND
3103 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3104 g_object_set_data( G_OBJECT( window ), "glwidget", m_pXYWnd->GetWidget() );
3107 g_floating_windows.push_back( window );
3111 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XZ ), m_window ));
3112 global_accel_connect_window( window );
3113 g_posXZWnd.connect( window );
3115 m_pXZWnd = new XYWnd();
3116 m_pXZWnd->m_parent = window;
3117 m_pXZWnd->SetViewType( XZ );
3120 auto frame = create_framed_widget( m_pXZWnd->GetWidget() );
3124 XZ_Front_Shown_Construct( window );
3125 #ifndef GARUX_GTK_WORKAROUND
3126 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3127 g_object_set_data( G_OBJECT( window ), "glwidget", m_pXZWnd->GetWidget() );
3130 g_floating_windows.push_back( window );
3134 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( YZ ), m_window ));
3135 global_accel_connect_window( window );
3136 g_posYZWnd.connect( window );
3138 m_pYZWnd = new XYWnd();
3139 m_pYZWnd->m_parent = window;
3140 m_pYZWnd->SetViewType( YZ );
3143 auto frame = create_framed_widget( m_pYZWnd->GetWidget() );
3147 YZ_Side_Shown_Construct( window );
3148 #ifndef GARUX_GTK_WORKAROUND
3149 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3150 g_object_set_data( G_OBJECT( window ), "glwidget", m_pYZWnd->GetWidget() );
3153 g_floating_windows.push_back( window );
3157 auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
3158 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3159 #ifndef GARUX_GTK_WORKAROUND
3160 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3161 g_object_set_data( G_OBJECT( GroupDialog_getWindow() ), "glwidget", TextureBrowser_getGLWidget() );
3170 m_pCamWnd = NewCamWnd();
3171 GlobalCamera_setCamWnd( *m_pCamWnd );
3172 CamWnd_setParent( *m_pCamWnd, window );
3174 ui::Widget camera = CamWnd_getWidget( *m_pCamWnd );
3176 m_pYZWnd = new XYWnd();
3177 m_pYZWnd->SetViewType( YZ );
3179 ui::Widget yz = m_pYZWnd->GetWidget();
3181 m_pXYWnd = new XYWnd();
3182 m_pXYWnd->SetViewType( XY );
3184 ui::Widget xy = m_pXYWnd->GetWidget();
3186 m_pXZWnd = new XYWnd();
3187 m_pXZWnd->SetViewType( XZ );
3189 ui::Widget xz = m_pXZWnd->GetWidget();
3191 auto split = create_split_views( camera, yz, xy, xz );
3192 vbox.pack_start( split, TRUE, TRUE, 0 );
3195 auto frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
3196 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3197 #ifndef GARUX_GTK_WORKAROUND
3198 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
3199 g_object_set_data( G_OBJECT( GroupDialog_getWindow() ), "glwidget", TextureBrowser_getGLWidget() );
3204 EntityList_constructWindow( window );
3205 PreferencesDialog_constructWindow( window );
3206 FindTextureDialog_constructWindow( window );
3207 SurfaceInspector_constructWindow( window );
3208 PatchInspector_constructWindow( window );
3210 SetActiveXY( m_pXYWnd );
3212 AddGridChangeCallback( SetGridStatusCaller( *this ) );
3213 AddGridChangeCallback( ReferenceCaller<MainFrame, void(), XY_UpdateAllWindows>( *this ) );
3215 g_defaultToolMode = DragMode;
3216 g_defaultToolMode();
3217 SetStatusText( m_command_status, c_TranslateMode_status );
3219 EverySecondTimer_enable();
3221 //GlobalShortcuts_reportUnregistered();
3224 void MainFrame::SaveWindowInfo(){
3225 if ( !FloatingGroupDialog() ) {
3226 g_layout_globals.nXYHeight = gtk_paned_get_position( GTK_PANED( m_vSplit ) );
3228 if ( CurrentStyle() != eRegular ) {
3229 g_layout_globals.nCamWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3233 g_layout_globals.nXYWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3236 g_layout_globals.nCamHeight = gtk_paned_get_position( GTK_PANED( m_vSplit2 ) );
3239 g_layout_globals.m_position = m_position_tracker.getPosition();
3241 g_layout_globals.nState = gdk_window_get_state( gtk_widget_get_window(m_window ) );
3244 void MainFrame::Shutdown(){
3245 EverySecondTimer_disable();
3247 EntityList_destroyWindow();
3256 TextureBrowser_destroyWindow();
3258 DeleteCamWnd( m_pCamWnd );
3261 PreferencesDialog_destroyWindow();
3262 SurfaceInspector_destroyWindow();
3263 FindTextureDialog_destroyWindow();
3264 PatchInspector_destroyWindow();
3266 g_DbgDlg.destroyWindow();
3268 // destroying group-dialog last because it may contain texture-browser
3269 GroupDialog_destroyWindow();
3272 void MainFrame::RedrawStatusText(){
3273 ui::Label::from(m_pStatusLabel[c_command_status]).text(m_command_status.c_str());
3274 ui::Label::from(m_pStatusLabel[c_position_status]).text(m_position_status.c_str());
3275 ui::Label::from(m_pStatusLabel[c_brushcount_status]).text(m_brushcount_status.c_str());
3276 ui::Label::from(m_pStatusLabel[c_texture_status]).text(m_texture_status.c_str());
3277 ui::Label::from(m_pStatusLabel[c_grid_status]).text(m_grid_status.c_str());
3280 void MainFrame::UpdateStatusText(){
3281 m_idleRedrawStatusText.queueDraw();
3284 void MainFrame::SetStatusText( CopiedString& status_text, const char* pText ){
3285 status_text = pText;
3289 void Sys_Status( const char* status ){
3290 if ( g_pParentWnd != 0 ) {
3291 g_pParentWnd->SetStatusText( g_pParentWnd->m_command_status, status );
3295 int getRotateIncrement(){
3296 return static_cast<int>( g_si_globals.rotate );
3299 int getFarClipDistance(){
3300 return g_camwindow_globals.m_nCubicScale;
3303 float ( *GridStatus_getGridSize )() = GetGridSize;
3305 int ( *GridStatus_getRotateIncrement )() = getRotateIncrement;
3307 int ( *GridStatus_getFarClipDistance )() = getFarClipDistance;
3309 bool ( *GridStatus_getTextureLockEnabled )();
3311 void MainFrame::SetGridStatus(){
3312 StringOutputStream status( 64 );
3313 const char* lock = ( GridStatus_getTextureLockEnabled() ) ? "ON" : "OFF";
3314 status << ( GetSnapGridSize() > 0 ? "G:" : "g:" ) << GridStatus_getGridSize()
3315 << " R:" << GridStatus_getRotateIncrement()
3316 << " C:" << GridStatus_getFarClipDistance()
3318 SetStatusText( m_grid_status, status.c_str() );
3321 void GridStatus_onTextureLockEnabledChanged(){
3322 if ( g_pParentWnd != 0 ) {
3323 g_pParentWnd->SetGridStatus();
3327 void GlobalGL_sharedContextCreated(){
3328 GLFont *g_font = NULL;
3330 // report OpenGL information
3331 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) << "\n";
3332 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) << "\n";
3333 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) << "\n";
3334 const auto extensions = reinterpret_cast<const char*>( glGetString(GL_EXTENSIONS ) );
3335 globalOutputStream() << "GL_EXTENSIONS: " << (extensions ? extensions : "") << "\n";
3337 QGL_sharedContextCreated( GlobalOpenGL() );
3339 ShaderCache_extensionsInitialised();
3341 GlobalShaderCache().realise();
3345 /* win32 is dodgy here, just use courier new then */
3346 g_font = glfont_create( "arial 9" );
3348 auto settings = gtk_settings_get_default();
3350 g_object_get( settings, "gtk-font-name", &fontname, NULL );
3351 g_font = glfont_create( fontname );
3354 GlobalOpenGL().m_font = g_font;
3357 void GlobalGL_sharedContextDestroyed(){
3358 Textures_Unrealise();
3359 GlobalShaderCache().unrealise();
3361 QGL_sharedContextDestroyed( GlobalOpenGL() );
3365 void Layout_constructPreferences( PreferencesPage& page ){
3367 const char* layouts[] = { "window1.png", "window2.png", "window3.png", "window4.png" };
3368 page.appendRadioIcons(
3370 STRING_ARRAY_RANGE( layouts ),
3371 make_property( g_Layout_viewStyle )
3374 page.appendCheckBox(
3375 "", "Detachable Menus",
3376 make_property( g_Layout_enableDetachableMenus )
3378 if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) {
3379 page.appendCheckBox(
3380 "", "Patch Toolbar",
3381 make_property( g_Layout_enablePatchToolbar )
3384 page.appendCheckBox(
3385 "", "Plugin Toolbar",
3386 make_property( g_Layout_enablePluginToolbar )
3388 page.appendCheckBox(
3389 "", "Filter Toolbar",
3390 make_property( g_Layout_enableFilterToolbar )
3394 void Layout_constructPage( PreferenceGroup& group ){
3395 PreferencesPage page( group.createPage( "Layout", "Layout Preferences" ) );
3396 Layout_constructPreferences( page );
3399 void Layout_registerPreferencesPage(){
3400 PreferencesDialog_addInterfacePage( makeCallbackF(Layout_constructPage) );
3404 #include "preferencesystem.h"
3405 #include "stringio.h"
3407 void MainFrame_Construct(){
3408 GlobalCommands_insert( "OpenManual", makeCallbackF(OpenHelpURL), Accelerator( GDK_KEY_F1 ) );
3410 GlobalCommands_insert( "Sleep", makeCallbackF(thunk_OnSleep), Accelerator( 'P', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3411 GlobalCommands_insert( "NewMap", makeCallbackF(NewMap) );
3412 GlobalCommands_insert( "OpenMap", makeCallbackF(OpenMap), Accelerator( 'O', (GdkModifierType)GDK_CONTROL_MASK ) );
3413 GlobalCommands_insert( "ImportMap", makeCallbackF(ImportMap) );
3414 GlobalCommands_insert( "SaveMap", makeCallbackF(SaveMap), Accelerator( 'S', (GdkModifierType)GDK_CONTROL_MASK ) );
3415 GlobalCommands_insert( "SaveMapAs", makeCallbackF(SaveMapAs) );
3416 GlobalCommands_insert( "ExportSelected", makeCallbackF(ExportMap) );
3417 GlobalCommands_insert( "SaveRegion", makeCallbackF(SaveRegion) );
3418 GlobalCommands_insert( "RefreshReferences", makeCallbackF(VFS_Refresh) );
3419 GlobalCommands_insert( "ProjectSettings", makeCallbackF(DoProjectSettings) );
3420 GlobalCommands_insert( "Exit", makeCallbackF(Exit) );
3422 GlobalCommands_insert( "Undo", makeCallbackF(Undo), Accelerator( 'Z', (GdkModifierType)GDK_CONTROL_MASK ) );
3423 GlobalCommands_insert( "Redo", makeCallbackF(Redo), Accelerator( 'Y', (GdkModifierType)GDK_CONTROL_MASK ) );
3424 GlobalCommands_insert( "Copy", makeCallbackF(Copy), Accelerator( 'C', (GdkModifierType)GDK_CONTROL_MASK ) );
3425 GlobalCommands_insert( "Paste", makeCallbackF(Paste), Accelerator( 'V', (GdkModifierType)GDK_CONTROL_MASK ) );
3426 GlobalCommands_insert( "PasteToCamera", makeCallbackF(PasteToCamera), Accelerator( 'V', (GdkModifierType)GDK_MOD1_MASK ) );
3427 GlobalCommands_insert( "CloneSelection", makeCallbackF(Selection_Clone), Accelerator( GDK_KEY_space ) );
3428 GlobalCommands_insert( "CloneSelectionAndMakeUnique", makeCallbackF(Selection_Clone_MakeUnique), Accelerator( GDK_KEY_space, (GdkModifierType)GDK_SHIFT_MASK ) );
3429 // GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) );
3430 GlobalCommands_insert( "DeleteSelection2", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) );
3431 GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( 'Z' ) );
3432 GlobalCommands_insert( "ParentSelection", makeCallbackF(Scene_parentSelected) );
3433 // GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) );
3434 GlobalCommands_insert( "UnSelectSelection2", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) );
3435 GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( 'C' ) );
3436 GlobalCommands_insert( "InvertSelection", makeCallbackF(Select_Invert), Accelerator( 'I' ) );
3437 GlobalCommands_insert( "SelectInside", makeCallbackF(Select_Inside) );
3438 GlobalCommands_insert( "SelectTouching", makeCallbackF(Select_Touching) );
3439 GlobalCommands_insert( "ExpandSelectionToEntities", makeCallbackF(Scene_ExpandSelectionToEntities), Accelerator( 'E', (GdkModifierType)( GDK_MOD1_MASK | GDK_CONTROL_MASK ) ) );
3440 GlobalCommands_insert( "Preferences", makeCallbackF(PreferencesDialog_showDialog), Accelerator( 'P' ) );
3442 GlobalCommands_insert( "ToggleConsole", makeCallbackF(Console_ToggleShow), Accelerator( 'O' ) );
3443 GlobalCommands_insert( "ToggleEntityInspector", makeCallbackF(EntityInspector_ToggleShow), Accelerator( 'N' ) );
3444 GlobalCommands_insert( "EntityList", makeCallbackF(EntityList_toggleShown), Accelerator( 'L' ) );
3446 GlobalCommands_insert( "ShowHidden", makeCallbackF(Select_ShowAllHidden), Accelerator( 'H', (GdkModifierType)GDK_SHIFT_MASK ) );
3447 GlobalCommands_insert( "HideSelected", makeCallbackF(HideSelected), Accelerator( 'H' ) );
3449 GlobalToggles_insert( "DragVertices", makeCallbackF(SelectVertexMode), ToggleItem::AddCallbackCaller( g_vertexMode_button ), Accelerator( 'V' ) );
3450 GlobalToggles_insert( "DragEdges", makeCallbackF(SelectEdgeMode), ToggleItem::AddCallbackCaller( g_edgeMode_button ), Accelerator( 'E' ) );
3451 GlobalToggles_insert( "DragFaces", makeCallbackF(SelectFaceMode), ToggleItem::AddCallbackCaller( g_faceMode_button ), Accelerator( 'F' ) );
3453 GlobalCommands_insert( "MirrorSelectionX", makeCallbackF(Selection_Flipx) );
3454 GlobalCommands_insert( "RotateSelectionX", makeCallbackF(Selection_Rotatex) );
3455 GlobalCommands_insert( "MirrorSelectionY", makeCallbackF(Selection_Flipy) );
3456 GlobalCommands_insert( "RotateSelectionY", makeCallbackF(Selection_Rotatey) );
3457 GlobalCommands_insert( "MirrorSelectionZ", makeCallbackF(Selection_Flipz) );
3458 GlobalCommands_insert( "RotateSelectionZ", makeCallbackF(Selection_Rotatez) );
3460 GlobalCommands_insert( "ArbitraryRotation", makeCallbackF(DoRotateDlg) );
3461 GlobalCommands_insert( "ArbitraryScale", makeCallbackF(DoScaleDlg) );
3463 GlobalCommands_insert( "BuildMenuCustomize", makeCallbackF(DoBuildMenu) );
3465 GlobalCommands_insert( "FindBrush", makeCallbackF(DoFind) );
3467 GlobalCommands_insert( "MapInfo", makeCallbackF(DoMapInfo), Accelerator( 'M' ) );
3470 GlobalToggles_insert( "ToggleClipper", makeCallbackF(ClipperMode), ToggleItem::AddCallbackCaller( g_clipper_button ), Accelerator( 'X' ) );
3472 GlobalToggles_insert( "MouseTranslate", makeCallbackF(TranslateMode), ToggleItem::AddCallbackCaller( g_translatemode_button ), Accelerator( 'W' ) );
3473 GlobalToggles_insert( "MouseRotate", makeCallbackF(RotateMode), ToggleItem::AddCallbackCaller( g_rotatemode_button ), Accelerator( 'R' ) );
3474 GlobalToggles_insert( "MouseScale", makeCallbackF(ScaleMode), ToggleItem::AddCallbackCaller( g_scalemode_button ) );
3475 GlobalToggles_insert( "MouseDrag", makeCallbackF(DragMode), ToggleItem::AddCallbackCaller( g_dragmode_button ), Accelerator( 'Q' ) );
3477 #ifndef GARUX_DISABLE_GTKTHEME
3478 GlobalCommands_insert( "gtkThemeDlg", makeCallbackF(gtkThemeDlg) );
3480 GlobalCommands_insert( "ColorSchemeOriginal", makeCallbackF(ColorScheme_Original) );
3481 GlobalCommands_insert( "ColorSchemeQER", makeCallbackF(ColorScheme_QER) );
3482 GlobalCommands_insert( "ColorSchemeBlackAndGreen", makeCallbackF(ColorScheme_Black) );
3483 GlobalCommands_insert( "ColorSchemeYdnar", makeCallbackF(ColorScheme_Ydnar) );
3484 GlobalCommands_insert( "ChooseTextureBackgroundColor", makeCallback( g_ColoursMenu.m_textureback ) );
3485 GlobalCommands_insert( "ChooseGridBackgroundColor", makeCallback( g_ColoursMenu.m_xyback ) );
3486 GlobalCommands_insert( "ChooseGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor ) );
3487 GlobalCommands_insert( "ChooseGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor ) );
3488 GlobalCommands_insert( "ChooseSmallGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor_alt ) );
3489 GlobalCommands_insert( "ChooseSmallGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor_alt ) );
3490 GlobalCommands_insert( "ChooseGridTextColor", makeCallback( g_ColoursMenu.m_gridtext ) );
3491 GlobalCommands_insert( "ChooseGridBlockColor", makeCallback( g_ColoursMenu.m_gridblock ) );
3492 GlobalCommands_insert( "ChooseBrushColor", makeCallback( g_ColoursMenu.m_brush ) );
3493 GlobalCommands_insert( "ChooseCameraBackgroundColor", makeCallback( g_ColoursMenu.m_cameraback ) );
3494 GlobalCommands_insert( "ChooseSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush ) );
3495 GlobalCommands_insert( "ChooseCameraSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush3d ) );
3496 GlobalCommands_insert( "ChooseClipperColor", makeCallback( g_ColoursMenu.m_clipper ) );
3497 GlobalCommands_insert( "ChooseOrthoViewNameColor", makeCallback( g_ColoursMenu.m_viewname ) );
3500 GlobalCommands_insert( "CSGSubtract", makeCallbackF(CSG_Subtract), Accelerator( 'U', (GdkModifierType)GDK_SHIFT_MASK ) );
3501 GlobalCommands_insert( "CSGMerge", makeCallbackF(CSG_Merge), Accelerator( 'U', (GdkModifierType) GDK_CONTROL_MASK ) );
3502 GlobalCommands_insert( "CSGHollow", makeCallbackF(CSG_MakeHollow) );
3503 GlobalCommands_insert( "CSGRoom", makeCallbackF(CSG_MakeRoom) );
3505 Grid_registerCommands();
3507 GlobalCommands_insert( "SnapToGrid", makeCallbackF(Selection_SnapToGrid), Accelerator( 'G', (GdkModifierType)GDK_CONTROL_MASK ) );
3509 GlobalCommands_insert( "SelectAllOfType", makeCallbackF(Select_AllOfType), Accelerator( 'A', (GdkModifierType)GDK_SHIFT_MASK ) );
3511 GlobalCommands_insert( "TexRotateClock", makeCallbackF(Texdef_RotateClockwise), Accelerator( GDK_KEY_Next, (GdkModifierType)GDK_SHIFT_MASK ) );
3512 GlobalCommands_insert( "TexRotateCounter", makeCallbackF(Texdef_RotateAntiClockwise), Accelerator( GDK_KEY_Prior, (GdkModifierType)GDK_SHIFT_MASK ) );
3513 GlobalCommands_insert( "TexScaleUp", makeCallbackF(Texdef_ScaleUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_CONTROL_MASK ) );
3514 GlobalCommands_insert( "TexScaleDown", makeCallbackF(Texdef_ScaleDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_CONTROL_MASK ) );
3515 GlobalCommands_insert( "TexScaleLeft", makeCallbackF(Texdef_ScaleLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_CONTROL_MASK ) );
3516 GlobalCommands_insert( "TexScaleRight", makeCallbackF(Texdef_ScaleRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_CONTROL_MASK ) );
3517 GlobalCommands_insert( "TexShiftUp", makeCallbackF(Texdef_ShiftUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_SHIFT_MASK ) );
3518 GlobalCommands_insert( "TexShiftDown", makeCallbackF(Texdef_ShiftDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_SHIFT_MASK ) );
3519 GlobalCommands_insert( "TexShiftLeft", makeCallbackF(Texdef_ShiftLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_SHIFT_MASK ) );
3520 GlobalCommands_insert( "TexShiftRight", makeCallbackF(Texdef_ShiftRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_SHIFT_MASK ) );
3522 GlobalCommands_insert( "MoveSelectionDOWN", makeCallbackF(Selection_MoveDown), Accelerator( GDK_KEY_KP_Subtract ) );
3523 GlobalCommands_insert( "MoveSelectionUP", makeCallbackF(Selection_MoveUp), Accelerator( GDK_KEY_KP_Add ) );
3525 GlobalCommands_insert( "SelectNudgeLeft", makeCallbackF(Selection_NudgeLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_MOD1_MASK ) );
3526 GlobalCommands_insert( "SelectNudgeRight", makeCallbackF(Selection_NudgeRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_MOD1_MASK ) );
3527 GlobalCommands_insert( "SelectNudgeUp", makeCallbackF(Selection_NudgeUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_MOD1_MASK ) );
3528 GlobalCommands_insert( "SelectNudgeDown", makeCallbackF(Selection_NudgeDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_MOD1_MASK ) );
3530 Patch_registerCommands();
3531 XYShow_registerCommands();
3533 typedef FreeCaller<void(const Selectable&), ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3534 GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() );
3536 GlobalPreferenceSystem().registerPreference( "DetachableMenus", make_property_string( g_Layout_enableDetachableMenus.m_latched ) );
3537 GlobalPreferenceSystem().registerPreference( "PatchToolBar", make_property_string( g_Layout_enablePatchToolbar.m_latched ) );
3538 GlobalPreferenceSystem().registerPreference( "PluginToolBar", make_property_string( g_Layout_enablePluginToolbar.m_latched ) );
3539 GlobalPreferenceSystem().registerPreference( "FilterToolBar", make_property_string( g_Layout_enableFilterToolbar.m_latched ) );
3540 GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", make_property_string( g_Layout_viewStyle.m_latched ) );
3541 GlobalPreferenceSystem().registerPreference( "XYHeight", make_property_string( g_layout_globals.nXYHeight ) );
3542 GlobalPreferenceSystem().registerPreference( "XYWidth", make_property_string( g_layout_globals.nXYWidth ) );
3543 GlobalPreferenceSystem().registerPreference( "CamWidth", make_property_string( g_layout_globals.nCamWidth ) );
3544 GlobalPreferenceSystem().registerPreference( "CamHeight", make_property_string( g_layout_globals.nCamHeight ) );
3546 GlobalPreferenceSystem().registerPreference( "State", make_property_string( g_layout_globals.nState ) );
3547 GlobalPreferenceSystem().registerPreference( "PositionX", make_property_string( g_layout_globals.m_position.x ) );
3548 GlobalPreferenceSystem().registerPreference( "PositionY", make_property_string( g_layout_globals.m_position.y ) );
3549 GlobalPreferenceSystem().registerPreference( "Width", make_property_string( g_layout_globals.m_position.w ) );
3550 GlobalPreferenceSystem().registerPreference( "Height", make_property_string( g_layout_globals.m_position.h ) );
3552 GlobalPreferenceSystem().registerPreference( "CamWnd", make_property<WindowPositionTracker_String>(g_posCamWnd) );
3553 GlobalPreferenceSystem().registerPreference( "XYWnd", make_property<WindowPositionTracker_String>(g_posXYWnd) );
3554 GlobalPreferenceSystem().registerPreference( "YZWnd", make_property<WindowPositionTracker_String>(g_posYZWnd) );
3555 GlobalPreferenceSystem().registerPreference( "XZWnd", make_property<WindowPositionTracker_String>(g_posXZWnd) );
3557 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3558 if ( g_strEnginePath.empty() )
3560 g_strEnginePath_was_empty_1st_start = true;
3561 const char* ENGINEPATH_ATTRIBUTE =
3566 #elif GDEF_OS_LINUX || GDEF_OS_BSD
3569 #error "unknown platform"
3572 StringOutputStream path( 256 );
3573 path << DirectoryCleaned( g_pGameDescription->getRequiredKeyValue( ENGINEPATH_ATTRIBUTE ) );
3574 g_strEnginePath = path.c_str();
3575 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3578 GlobalPreferenceSystem().registerPreference( "DisableEnginePath", make_property_string( g_disableEnginePath ) );
3579 GlobalPreferenceSystem().registerPreference( "DisableHomePath", make_property_string( g_disableHomePath ) );
3581 for ( int i = 0; i < g_pakPathCount; i++ ) {
3582 std::string label = "PakPath" + std::to_string( i );
3583 GlobalPreferenceSystem().registerPreference( label.c_str(), make_property_string( g_strPakPath[i] ) );
3586 g_Layout_viewStyle.useLatched();
3587 g_Layout_enableDetachableMenus.useLatched();
3588 g_Layout_enablePatchToolbar.useLatched();
3589 g_Layout_enablePluginToolbar.useLatched();
3590 g_Layout_enableFilterToolbar.useLatched();
3592 Layout_registerPreferencesPage();
3593 Paths_registerPreferencesPage();
3595 g_brushCount.setCountChangedCallback( makeCallbackF(QE_brushCountChanged) );
3596 g_entityCount.setCountChangedCallback( makeCallbackF(QE_entityCountChanged) );
3597 GlobalEntityCreator().setCounter( &g_entityCount );
3599 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3600 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3602 GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver );
3605 void MainFrame_Destroy(){
3606 GlobalEntityClassManager().detach( g_WorldspawnColourEntityClassObserver );
3608 GlobalEntityCreator().setCounter( 0 );
3609 g_entityCount.setCountChangedCallback( Callback<void()>() );
3610 g_brushCount.setCountChangedCallback( Callback<void()>() );
3614 void GLWindow_Construct(){
3615 GlobalPreferenceSystem().registerPreference( "MouseButtons", make_property_string( g_glwindow_globals.m_nMouseType ) );
3618 void GLWindow_Destroy(){