2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 // Main Window for Q3Radiant
25 // Leonardo Zide (leo@lokigames.com)
28 #include "mainframe.h"
29 #include "globaldefs.h"
33 #include "ifilesystem.h"
39 #include "moduleobserver.h"
43 #include <gdk/gdkkeysyms.h>
47 #include "stream/stringstream.h"
48 #include "signal/isignal.h"
51 #include "eclasslib.h"
52 #include "moduleobservers.h"
54 #include "gtkutil/clipboard.h"
55 #include "gtkutil/frame.h"
56 #include "gtkutil/glwidget.h"
57 #include "gtkutil/image.h"
58 #include "gtkutil/menu.h"
59 #include "gtkutil/paned.h"
63 #include "brushmanip.h"
64 #include "brushmodule.h"
65 #include "camwindow.h"
70 #include "entityinspector.h"
71 #include "entitylist.h"
73 #include "findtexturedialog.h"
75 #include "groupdialog.h"
82 #include "patchdialog.h"
83 #include "patchmanip.h"
85 #include "pluginmanager.h"
86 #include "pluginmenu.h"
87 #include "plugintoolbar.h"
88 #include "preferences.h"
93 #include "surfacedialog.h"
95 #include "texwindow.h"
98 #include "windowobservers.h"
99 #include "renderstate.h"
100 #include "feedback.h"
101 #include "referencecache.h"
102 #include "texwindow.h"
105 struct layout_globals_t
107 WindowPosition m_position;
117 m_position( -1, -1, 640, 480 ),
123 nState( GDK_WINDOW_STATE_MAXIMIZED ){
127 layout_globals_t g_layout_globals;
128 glwindow_globals_t g_glwindow_globals;
133 bool g_vfsInitialized = false;
136 if ( g_vfsInitialized ) return;
138 GlobalFileSystem().initialise();
139 g_vfsInitialized = true;
143 if ( !g_vfsInitialized ) return;
144 GlobalFileSystem().shutdown();
145 g_vfsInitialized = false;
149 if ( !g_vfsInitialized ) return;
150 GlobalFileSystem().clear();
152 GlobalFileSystem().refresh();
153 g_vfsInitialized = true;
154 // also refresh models
156 // also refresh texture browser
157 TextureBrowser_RefreshShaders();
165 class VFSModuleObserver : public ModuleObserver
177 VFSModuleObserver g_VFSModuleObserver;
179 void VFS_Construct(){
180 Radiant_attachHomePathsObserver( g_VFSModuleObserver );
184 Radiant_detachHomePathsObserver( g_VFSModuleObserver );
192 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
193 #define qREFKNOWNFOLDERID GUID
194 #define qKF_FLAG_CREATE 0x8000
195 #define qKF_FLAG_NO_ALIAS 0x1000
196 typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath );
197 static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath;
200 void HomePaths_Realise(){
203 const char* prefix = g_pGameDescription->getKeyValue( "prefix" );
204 if ( !string_empty( prefix ) ) {
205 StringOutputStream path( 256 );
209 path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/";
210 if ( file_is_directory( path.c_str() ) ) {
211 g_qeglobals.m_userEnginePath = path.c_str();
215 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
219 TCHAR mydocsdir[MAX_PATH + 1];
221 HMODULE shfolder = LoadLibrary( "shfolder.dll" );
223 qSHGetKnownFolderPath = (qSHGetKnownFolderPath_t *) GetProcAddress( shfolder, "SHGetKnownFolderPath" );
226 qSHGetKnownFolderPath = NULL;
228 CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
229 if ( qSHGetKnownFolderPath && qSHGetKnownFolderPath( qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw ) == S_OK ) {
230 memset( mydocsdir, 0, sizeof( mydocsdir ) );
231 wcstombs( mydocsdir, mydocsdirw, sizeof( mydocsdir ) - 1 );
232 CoTaskMemFree( mydocsdirw );
234 path << DirectoryCleaned( mydocsdir ) << ( prefix + 1 ) << "/";
235 if ( file_is_directory( path.c_str() ) ) {
236 g_qeglobals.m_userEnginePath = path.c_str();
238 FreeLibrary( shfolder );
244 FreeLibrary( shfolder );
246 if ( SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir ) ) {
248 path << DirectoryCleaned( mydocsdir ) << "My Games/" << ( prefix + 1 ) << "/";
249 // win32: only add it if it already exists
250 if ( file_is_directory( path.c_str() ) ) {
251 g_qeglobals.m_userEnginePath = path.c_str();
259 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
260 g_qeglobals.m_userEnginePath = path.c_str();
265 g_qeglobals.m_userEnginePath = EnginePath_get();
269 Q_mkdir( g_qeglobals.m_userEnginePath.c_str() );
272 StringOutputStream path( 256 );
273 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
274 g_qeglobals.m_userGamePath = path.c_str();
276 ASSERT_MESSAGE( !string_empty( g_qeglobals.m_userGamePath.c_str() ), "HomePaths_Realise: user-game-path is empty" );
277 Q_mkdir( g_qeglobals.m_userGamePath.c_str() );
280 ModuleObservers g_homePathObservers;
282 void Radiant_attachHomePathsObserver( ModuleObserver& observer ){
283 g_homePathObservers.attach( observer );
286 void Radiant_detachHomePathsObserver( ModuleObserver& observer ){
287 g_homePathObservers.detach( observer );
290 class HomePathsModuleObserver : public ModuleObserver
292 std::size_t m_unrealised;
294 HomePathsModuleObserver() : m_unrealised( 1 ){
298 if ( --m_unrealised == 0 ) {
300 g_homePathObservers.realise();
305 if ( ++m_unrealised == 1 ) {
306 g_homePathObservers.unrealise();
311 HomePathsModuleObserver g_HomePathsModuleObserver;
313 void HomePaths_Construct(){
314 Radiant_attachEnginePathObserver( g_HomePathsModuleObserver );
317 void HomePaths_Destroy(){
318 Radiant_detachEnginePathObserver( g_HomePathsModuleObserver );
324 CopiedString g_strEnginePath;
325 ModuleObservers g_enginePathObservers;
326 std::size_t g_enginepath_unrealised = 1;
328 void Radiant_attachEnginePathObserver( ModuleObserver& observer ){
329 g_enginePathObservers.attach( observer );
332 void Radiant_detachEnginePathObserver( ModuleObserver& observer ){
333 g_enginePathObservers.detach( observer );
337 void EnginePath_Realise(){
338 if ( --g_enginepath_unrealised == 0 ) {
339 g_enginePathObservers.realise();
344 const char* EnginePath_get(){
345 ASSERT_MESSAGE( g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised" );
346 return g_strEnginePath.c_str();
349 void EnginePath_Unrealise(){
350 if ( ++g_enginepath_unrealised == 1 ) {
351 g_enginePathObservers.unrealise();
355 void setEnginePath( const char* path ){
356 StringOutputStream buffer( 256 );
357 buffer << DirectoryCleaned( path );
358 if ( !path_equal( buffer.c_str(), g_strEnginePath.c_str() ) ) {
360 while ( !ConfirmModified( "Paths Changed" ) )
362 if ( Map_Unnamed( g_map ) ) {
373 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Changing Engine Path" );
375 EnginePath_Unrealise();
377 g_strEnginePath = buffer.c_str();
379 EnginePath_Realise();
385 CopiedString g_strPakPath[g_pakPathCount] = { "", "", "", "", "" };
386 ModuleObservers g_pakPathObservers[g_pakPathCount];
387 std::size_t g_pakpath_unrealised[g_pakPathCount] = { 1, 1, 1, 1, 1 };
389 void Radiant_attachPakPathObserver( int num, ModuleObserver& observer ){
390 g_pakPathObservers[num].attach( observer );
393 void Radiant_detachPakPathObserver( int num, ModuleObserver& observer ){
394 g_pakPathObservers[num].detach( observer );
398 void PakPath_Realise( int num ){
399 if ( --g_pakpath_unrealised[num] == 0 ) {
400 g_pakPathObservers[num].realise();
404 const char* PakPath_get( int num ){
405 std::string message = "PakPath_get: pak path " + std::to_string(num) + " not realised";
406 ASSERT_MESSAGE( g_pakpath_unrealised[num] == 0, message.c_str() );
407 return g_strPakPath[num].c_str();
410 void PakPath_Unrealise( int num ){
411 if ( ++g_pakpath_unrealised[num] == 1 ) {
412 g_pakPathObservers[num].unrealise();
416 void setPakPath( int num, const char* path ){
417 if (!g_strcmp0( path, "")) {
418 g_strPakPath[num] = "";
422 StringOutputStream buffer( 256 );
423 buffer << DirectoryCleaned( path );
424 if ( !path_equal( buffer.c_str(), g_strPakPath[num].c_str() ) ) {
425 std::string message = "Changing Pak Path " + std::to_string(num);
426 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", message.c_str() );
428 PakPath_Unrealise(num);
430 g_strPakPath[num] = buffer.c_str();
432 PakPath_Realise(num);
439 CopiedString g_strAppPath; ///< holds the full path of the executable
441 const char* AppPath_get(){
442 return g_strAppPath.c_str();
445 /// the path to the local rc-dir
446 const char* LocalRcPath_get( void ){
447 static CopiedString rc_path;
448 if ( rc_path.empty() ) {
449 StringOutputStream stream( 256 );
450 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
451 rc_path = stream.c_str();
453 return rc_path.c_str();
456 /// directory for temp files
457 /// NOTE: on *nix this is were we check for .pid
458 CopiedString g_strSettingsPath;
460 const char* SettingsPath_get(){
461 return g_strSettingsPath.c_str();
466 points to the game tools directory, for instance
467 C:/Program Files/Quake III Arena/GtkRadiant
469 this is one of the main variables that are configured by the game selection on startup
470 [GameToolsPath]/plugins
471 [GameToolsPath]/modules
474 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
476 const char* GameToolsPath_get(){
477 return g_strGameToolsPath.c_str();
481 static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz) {
482 returnz(self.c_str());
485 static void Import(CopiedString &self, const char *value) {
486 setEnginePath( value );
491 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
492 returnz( self.c_str() );
495 static void Import( CopiedString &self, const char *value ) {
496 setPakPath( 0, value );
501 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
502 returnz( self.c_str() );
505 static void Import( CopiedString &self, const char *value ) {
506 setPakPath( 1, value );
511 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
512 returnz( self.c_str() );
515 static void Import( CopiedString &self, const char *value ) {
516 setPakPath( 2, value );
521 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
522 returnz( self.c_str() );
525 static void Import( CopiedString &self, const char *value ) {
526 setPakPath( 3, value );
531 static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) {
532 returnz( self.c_str() );
535 static void Import( CopiedString &self, const char *value ) {
536 setPakPath( 4, value );
540 bool g_disableEnginePath = false;
541 bool g_disableHomePath = false;
543 void Paths_constructPreferences( PreferencesPage& page ){
544 page.appendPathEntry( "Engine Path", true, make_property<EnginePath>(g_strEnginePath) );
547 "", "Do not use Engine Path",
552 "", "Do not use Home Path",
556 for ( int i = 0; i < g_pakPathCount; i++ ) {
557 std::string label = "Pak Path " + std::to_string(i);
560 page.appendPathEntry( label.c_str(), true, make_property<PakPath0>( g_strPakPath[i] ) );
563 page.appendPathEntry( label.c_str(), true, make_property<PakPath1>( g_strPakPath[i] ) );
566 page.appendPathEntry( label.c_str(), true, make_property<PakPath2>( g_strPakPath[i] ) );
569 page.appendPathEntry( label.c_str(), true, make_property<PakPath3>( g_strPakPath[i] ) );
572 page.appendPathEntry( label.c_str(), true, make_property<PakPath4>( g_strPakPath[i] ) );
578 void Paths_constructPage( PreferenceGroup& group ){
579 PreferencesPage page( group.createPage( "Paths", "Path Settings" ) );
580 Paths_constructPreferences( page );
583 void Paths_registerPreferencesPage(){
584 PreferencesDialog_addSettingsPage( makeCallbackF(Paths_constructPage) );
588 class PathsDialog : public Dialog
591 ui::Window BuildDialog(){
592 auto frame = create_dialog_frame( "Path settings", ui::Shadow::ETCHED_IN );
594 auto vbox2 = create_dialog_vbox( 0, 4 );
598 PreferencesPage preferencesPage( *this, vbox2 );
599 Paths_constructPreferences( preferencesPage );
602 return ui::Window(create_simple_modal_dialog_window( "Engine Path Not Found", m_modal, frame ));
606 PathsDialog g_PathsDialog;
608 void EnginePath_verify(){
609 if ( !file_exists( g_strEnginePath.c_str() ) ) {
610 g_PathsDialog.Create();
611 g_PathsDialog.DoModal();
612 g_PathsDialog.Destroy();
618 CopiedString g_gamename;
619 CopiedString g_gamemode;
620 ModuleObservers g_gameNameObservers;
621 ModuleObservers g_gameModeObservers;
624 void Radiant_attachGameNameObserver( ModuleObserver& observer ){
625 g_gameNameObservers.attach( observer );
628 void Radiant_detachGameNameObserver( ModuleObserver& observer ){
629 g_gameNameObservers.detach( observer );
632 const char* basegame_get(){
633 return g_pGameDescription->getRequiredKeyValue( "basegame" );
636 const char* gamename_get(){
637 const char* gamename = g_gamename.c_str();
638 if ( string_empty( gamename ) ) {
639 return basegame_get();
644 void gamename_set( const char* gamename ){
645 if ( !string_equal( gamename, g_gamename.c_str() ) ) {
646 g_gameNameObservers.unrealise();
647 g_gamename = gamename;
648 g_gameNameObservers.realise();
652 void Radiant_attachGameModeObserver( ModuleObserver& observer ){
653 g_gameModeObservers.attach( observer );
656 void Radiant_detachGameModeObserver( ModuleObserver& observer ){
657 g_gameModeObservers.detach( observer );
660 const char* gamemode_get(){
661 return g_gamemode.c_str();
664 void gamemode_set( const char* gamemode ){
665 if ( !string_equal( gamemode, g_gamemode.c_str() ) ) {
666 g_gameModeObservers.unrealise();
667 g_gamemode = gamemode;
668 g_gameModeObservers.realise();
675 const char* const c_library_extension =
676 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
677 CMAKE_SHARED_MODULE_SUFFIX
678 #elif GDEF_OS_WINDOWS
682 #elif GDEF_OS_LINUX || GDEF_OS_BSD
687 void Radiant_loadModules( const char* path ){
688 Directory_forEach(path, matchFileExtension(c_library_extension, [&](const char *name) {
690 ASSERT_MESSAGE(strlen(path) + strlen(name) < 1024, "");
691 strcpy(fullname, path);
692 strcat(fullname, name);
693 globalOutputStream() << "Found '" << fullname << "'\n";
694 GlobalModuleServer_loadModule(fullname);
698 void Radiant_loadModulesFromRoot( const char* directory ){
700 StringOutputStream path( 256 );
701 path << directory << g_pluginsDir;
702 Radiant_loadModules( path.c_str() );
705 if ( !string_equal( g_pluginsDir, g_modulesDir ) ) {
706 StringOutputStream path( 256 );
707 path << directory << g_modulesDir;
708 Radiant_loadModules( path.c_str() );
712 //! Make COLOR_BRUSHES override worldspawn eclass colour.
713 void SetWorldspawnColour( const Vector3& colour ){
714 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert( "worldspawn", true );
715 eclass_release_state( worldspawn );
716 worldspawn->color = colour;
717 eclass_capture_state( worldspawn );
721 class WorldspawnColourEntityClassObserver : public ModuleObserver
723 std::size_t m_unrealised;
725 WorldspawnColourEntityClassObserver() : m_unrealised( 1 ){
729 if ( --m_unrealised == 0 ) {
730 SetWorldspawnColour( g_xywindow_globals.color_brushes );
735 if ( ++m_unrealised == 1 ) {
740 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
743 ModuleObservers g_gameToolsPathObservers;
745 void Radiant_attachGameToolsPathObserver( ModuleObserver& observer ){
746 g_gameToolsPathObservers.attach( observer );
749 void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ){
750 g_gameToolsPathObservers.detach( observer );
753 void Radiant_Initialise(){
754 GlobalModuleServer_Initialise();
756 Radiant_loadModulesFromRoot( AppPath_get() );
760 bool success = Radiant_Construct( GlobalModuleServer_get() );
761 ASSERT_MESSAGE( success, "module system failed to initialise - see radiant.log for error messages" );
763 g_gameToolsPathObservers.realise();
764 g_gameModeObservers.realise();
765 g_gameNameObservers.realise();
768 void Radiant_Shutdown(){
769 g_gameNameObservers.unrealise();
770 g_gameModeObservers.unrealise();
771 g_gameToolsPathObservers.unrealise();
773 if ( !g_preferences_globals.disable_ini ) {
774 globalOutputStream() << "Start writing prefs\n";
776 globalOutputStream() << "Done prefs\n";
781 GlobalModuleServer_Shutdown();
785 if ( ConfirmModified( "Exit Radiant" ) ) {
792 GlobalUndoSystem().undo();
797 GlobalUndoSystem().redo();
801 void deleteSelection(){
802 UndoableCommand undo( "deleteSelected" );
806 void Map_ExportSelected( TextOutputStream& ostream ){
807 Map_ExportSelected( ostream, Map_getFormat( g_map ) );
810 void Map_ImportSelected( TextInputStream& istream ){
811 Map_ImportSelected( istream, Map_getFormat( g_map ) );
814 void Selection_Copy(){
815 clipboard_copy( Map_ExportSelected );
818 void Selection_Paste(){
819 clipboard_paste( Map_ImportSelected );
823 if ( SelectedFaces_empty() ) {
828 SelectedFaces_copyTexture();
833 if ( SelectedFaces_empty() ) {
834 UndoableCommand undo( "paste" );
836 GlobalSelectionSystem().setSelectedAll( false );
841 SelectedFaces_pasteTexture();
845 void PasteToCamera(){
846 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
847 GlobalSelectionSystem().setSelectedAll( false );
849 UndoableCommand undo( "pasteToCamera" );
853 // Work out the delta
855 Select_GetMid( mid );
856 Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid );
859 GlobalSelectionSystem().translateSelected( delta );
863 void ColorScheme_Original(){
864 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
866 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
867 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
868 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
870 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
871 g_xywindow_globals.color_gridminor = Vector3( 0.75f, 0.75f, 0.75f );
872 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
873 g_xywindow_globals.color_gridminor_alt = Vector3( 0.5f, 0.0f, 0.0f );
874 g_xywindow_globals.color_gridmajor_alt = Vector3( 1.0f, 0.0f, 0.0f );
875 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
876 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
877 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
878 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
879 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
880 SetWorldspawnColour( g_xywindow_globals.color_brushes );
881 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
882 XY_UpdateAllWindows();
885 void ColorScheme_QER(){
886 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
888 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
889 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
890 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
892 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
893 g_xywindow_globals.color_gridminor = Vector3( 1.0f, 1.0f, 1.0f );
894 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
895 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
896 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
897 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
898 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
899 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
900 SetWorldspawnColour( g_xywindow_globals.color_brushes );
901 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
902 XY_UpdateAllWindows();
905 void ColorScheme_Black(){
906 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
908 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
909 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
910 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
912 g_xywindow_globals.color_gridback = Vector3( 0.0f, 0.0f, 0.0f );
913 g_xywindow_globals.color_gridminor = Vector3( 0.2f, 0.2f, 0.2f );
914 g_xywindow_globals.color_gridmajor = Vector3( 0.3f, 0.5f, 0.5f );
915 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
916 g_xywindow_globals.color_gridtext = Vector3( 1.0f, 1.0f, 1.0f );
917 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
918 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
919 g_xywindow_globals.color_brushes = Vector3( 1.0f, 1.0f, 1.0f );
920 SetWorldspawnColour( g_xywindow_globals.color_brushes );
921 g_xywindow_globals.color_viewname = Vector3( 0.7f, 0.7f, 0.0f );
922 XY_UpdateAllWindows();
925 /* ydnar: to emulate maya/max/lightwave color schemes */
926 void ColorScheme_Ydnar(){
927 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
929 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
930 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
931 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
933 g_xywindow_globals.color_gridback = Vector3( 0.77f, 0.77f, 0.77f );
934 g_xywindow_globals.color_gridminor = Vector3( 0.83f, 0.83f, 0.83f );
935 g_xywindow_globals.color_gridmajor = Vector3( 0.89f, 0.89f, 0.89f );
936 g_xywindow_globals.color_gridblock = Vector3( 1.0f, 1.0f, 1.0f );
937 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
938 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
939 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
940 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
941 SetWorldspawnColour( g_xywindow_globals.color_brushes );
942 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
943 XY_UpdateAllWindows();
946 typedef Callback<void(Vector3&)> GetColourCallback;
947 typedef Callback<void(const Vector3&)> SetColourCallback;
951 GetColourCallback m_get;
952 SetColourCallback m_set;
954 ChooseColour( const GetColourCallback& get, const SetColourCallback& set )
955 : m_get( get ), m_set( set ){
961 color_dialog( MainFrame_getWindow(), colour );
967 void Colour_get( const Vector3& colour, Vector3& other ){
971 typedef ConstReferenceCaller<Vector3, void(Vector3&), Colour_get> ColourGetCaller;
973 void Colour_set( Vector3& colour, const Vector3& other ){
978 typedef ReferenceCaller<Vector3, void(const Vector3&), Colour_set> ColourSetCaller;
980 void BrushColour_set( const Vector3& other ){
981 g_xywindow_globals.color_brushes = other;
982 SetWorldspawnColour( g_xywindow_globals.color_brushes );
986 typedef FreeCaller<void(const Vector3&), BrushColour_set> BrushColourSetCaller;
988 void ClipperColour_set( const Vector3& other ){
989 g_xywindow_globals.color_clipper = other;
990 Brush_clipperColourChanged();
994 typedef FreeCaller<void(const Vector3&), ClipperColour_set> ClipperColourSetCaller;
996 void TextureBrowserColour_get( Vector3& other ){
997 other = TextureBrowser_getBackgroundColour( GlobalTextureBrowser() );
1000 typedef FreeCaller<void(Vector3&), TextureBrowserColour_get> TextureBrowserColourGetCaller;
1002 void TextureBrowserColour_set( const Vector3& other ){
1003 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), other );
1006 typedef FreeCaller<void(const Vector3&), TextureBrowserColour_set> TextureBrowserColourSetCaller;
1012 ChooseColour m_textureback;
1013 ChooseColour m_xyback;
1014 ChooseColour m_gridmajor;
1015 ChooseColour m_gridminor;
1016 ChooseColour m_gridmajor_alt;
1017 ChooseColour m_gridminor_alt;
1018 ChooseColour m_gridtext;
1019 ChooseColour m_gridblock;
1020 ChooseColour m_cameraback;
1021 ChooseColour m_brush;
1022 ChooseColour m_selectedbrush;
1023 ChooseColour m_selectedbrush3d;
1024 ChooseColour m_clipper;
1025 ChooseColour m_viewname;
1028 m_textureback( TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller() ),
1029 m_xyback( ColourGetCaller( g_xywindow_globals.color_gridback ), ColourSetCaller( g_xywindow_globals.color_gridback ) ),
1030 m_gridmajor( ColourGetCaller( g_xywindow_globals.color_gridmajor ), ColourSetCaller( g_xywindow_globals.color_gridmajor ) ),
1031 m_gridminor( ColourGetCaller( g_xywindow_globals.color_gridminor ), ColourSetCaller( g_xywindow_globals.color_gridminor ) ),
1032 m_gridmajor_alt( ColourGetCaller( g_xywindow_globals.color_gridmajor_alt ), ColourSetCaller( g_xywindow_globals.color_gridmajor_alt ) ),
1033 m_gridminor_alt( ColourGetCaller( g_xywindow_globals.color_gridminor_alt ), ColourSetCaller( g_xywindow_globals.color_gridminor_alt ) ),
1034 m_gridtext( ColourGetCaller( g_xywindow_globals.color_gridtext ), ColourSetCaller( g_xywindow_globals.color_gridtext ) ),
1035 m_gridblock( ColourGetCaller( g_xywindow_globals.color_gridblock ), ColourSetCaller( g_xywindow_globals.color_gridblock ) ),
1036 m_cameraback( ColourGetCaller( g_camwindow_globals.color_cameraback ), ColourSetCaller( g_camwindow_globals.color_cameraback ) ),
1037 m_brush( ColourGetCaller( g_xywindow_globals.color_brushes ), BrushColourSetCaller() ),
1038 m_selectedbrush( ColourGetCaller( g_xywindow_globals.color_selbrushes ), ColourSetCaller( g_xywindow_globals.color_selbrushes ) ),
1039 m_selectedbrush3d( ColourGetCaller( g_camwindow_globals.color_selbrushes3d ), ColourSetCaller( g_camwindow_globals.color_selbrushes3d ) ),
1040 m_clipper( ColourGetCaller( g_xywindow_globals.color_clipper ), ClipperColourSetCaller() ),
1041 m_viewname( ColourGetCaller( g_xywindow_globals.color_viewname ), ColourSetCaller( g_xywindow_globals.color_viewname ) ){
1045 ColoursMenu g_ColoursMenu;
1047 ui::MenuItem create_colours_menu(){
1048 auto colours_menu_item = new_sub_menu_item_with_mnemonic( "Colors" );
1049 auto menu_in_menu = ui::Menu::from( gtk_menu_item_get_submenu( colours_menu_item ) );
1050 if ( g_Layout_enableDetachableMenus.m_value ) {
1051 menu_tearoff( menu_in_menu );
1054 auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Themes" );
1055 if ( g_Layout_enableDetachableMenus.m_value ) {
1056 menu_tearoff( menu_3 );
1059 create_menu_item_with_mnemonic( menu_3, "QE4 Original", "ColorSchemeOriginal" );
1060 create_menu_item_with_mnemonic( menu_3, "Q3Radiant Original", "ColorSchemeQER" );
1061 create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" );
1062 create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" );
1064 menu_separator( menu_in_menu );
1066 create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" );
1067 create_menu_item_with_mnemonic( menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor" );
1068 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major...", "ChooseGridMajorColor" );
1069 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor...", "ChooseGridMinorColor" );
1070 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor" );
1071 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor" );
1072 create_menu_item_with_mnemonic( menu_in_menu, "Grid Text...", "ChooseGridTextColor" );
1073 create_menu_item_with_mnemonic( menu_in_menu, "Grid Block...", "ChooseGridBlockColor" );
1074 create_menu_item_with_mnemonic( menu_in_menu, "Default Brush...", "ChooseBrushColor" );
1075 create_menu_item_with_mnemonic( menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor" );
1076 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor" );
1077 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor" );
1078 create_menu_item_with_mnemonic( menu_in_menu, "Clipper...", "ChooseClipperColor" );
1079 create_menu_item_with_mnemonic( menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor" );
1081 return colours_menu_item;
1086 PluginsMenu_clear();
1087 PluginToolbar_clear();
1090 Radiant_Initialise();
1092 PluginsMenu_populate();
1094 PluginToolbar_populate();
1098 void thunk_OnSleep(){
1099 g_pParentWnd->OnSleep();
1103 OpenURL( "https://gitlab.com/xonotic/xonotic/wikis/Mapping" );
1106 void OpenBugReportURL(){
1107 OpenURL( "https://gitlab.com/xonotic/netradiant/issues" );
1111 ui::Widget g_page_console{ui::null};
1113 void Console_ToggleShow(){
1114 GroupDialog_showPage( g_page_console );
1117 ui::Widget g_page_entity{ui::null};
1119 void EntityInspector_ToggleShow(){
1120 GroupDialog_showPage( g_page_entity );
1124 void SetClipMode( bool enable );
1126 void ModeChangeNotify();
1128 typedef void ( *ToolMode )();
1130 ToolMode g_currentToolMode = 0;
1131 bool g_currentToolModeSupportsComponentEditing = false;
1132 ToolMode g_defaultToolMode = 0;
1135 void SelectionSystem_DefaultMode(){
1136 GlobalSelectionSystem().SetMode( SelectionSystem::ePrimitive );
1137 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eDefault );
1143 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1144 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1148 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1149 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1153 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1154 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1157 template<bool( *BoolFunction ) ( )>
1158 class BoolFunctionExport
1161 static void apply( const Callback<void(bool)> & importCallback ){
1162 importCallback( BoolFunction() );
1166 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1167 EdgeModeApplyCaller g_edgeMode_button_caller;
1168 Callback<void(const Callback<void(bool)> &)> g_edgeMode_button_callback( g_edgeMode_button_caller );
1169 ToggleItem g_edgeMode_button( g_edgeMode_button_callback );
1171 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1172 VertexModeApplyCaller g_vertexMode_button_caller;
1173 Callback<void(const Callback<void(bool)> &)> g_vertexMode_button_callback( g_vertexMode_button_caller );
1174 ToggleItem g_vertexMode_button( g_vertexMode_button_callback );
1176 typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1177 FaceModeApplyCaller g_faceMode_button_caller;
1178 Callback<void(const Callback<void(bool)> &)> g_faceMode_button_callback( g_faceMode_button_caller );
1179 ToggleItem g_faceMode_button( g_faceMode_button_callback );
1181 void ComponentModeChanged(){
1182 g_edgeMode_button.update();
1183 g_vertexMode_button.update();
1184 g_faceMode_button.update();
1187 void ComponentMode_SelectionChanged( const Selectable& selectable ){
1188 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1189 && GlobalSelectionSystem().countSelected() == 0 ) {
1190 SelectionSystem_DefaultMode();
1191 ComponentModeChanged();
1195 void SelectEdgeMode(){
1197 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1198 GlobalSelectionSystem().Select( false );
1203 SelectionSystem_DefaultMode();
1205 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1206 if ( !g_currentToolModeSupportsComponentEditing ) {
1207 g_defaultToolMode();
1210 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1211 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eEdge );
1214 ComponentModeChanged();
1219 void SelectVertexMode(){
1221 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1222 GlobalSelectionSystem().Select( false );
1226 if ( VertexMode() ) {
1227 SelectionSystem_DefaultMode();
1229 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1230 if ( !g_currentToolModeSupportsComponentEditing ) {
1231 g_defaultToolMode();
1234 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1235 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eVertex );
1238 ComponentModeChanged();
1243 void SelectFaceMode(){
1245 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1246 GlobalSelectionSystem().Select( false );
1251 SelectionSystem_DefaultMode();
1253 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1254 if ( !g_currentToolModeSupportsComponentEditing ) {
1255 g_defaultToolMode();
1258 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1259 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eFace );
1262 ComponentModeChanged();
1268 class CloneSelected : public scene::Graph::Walker
1271 NodeSmartReference worldspawn;
1273 CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
1276 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1277 if ( path.size() == 1 ) {
1281 // ignore worldspawn, but keep checking children
1282 NodeSmartReference me( path.top().get() );
1283 if ( me == worldspawn ) {
1287 if ( !path.top().get().isRoot() ) {
1288 Selectable* selectable = Instance_getSelectable( instance );
1289 if ( selectable != 0
1290 && selectable->isSelected() ) {
1298 void post( const scene::Path& path, scene::Instance& instance ) const {
1299 if ( path.size() == 1 ) {
1303 // ignore worldspawn, but keep checking children
1304 NodeSmartReference me( path.top().get() );
1305 if ( me == worldspawn ) {
1309 if ( !path.top().get().isRoot() ) {
1310 Selectable* selectable = Instance_getSelectable( instance );
1311 if ( selectable != 0
1312 && selectable->isSelected() ) {
1313 NodeSmartReference clone( Node_Clone( path.top() ) );
1314 if ( doMakeUnique ) {
1315 Map_gatherNamespaced( clone );
1317 Node_getTraversable( path.parent().get() )->insert( clone );
1323 void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){
1324 graph.traverse( CloneSelected( doMakeUnique ) );
1326 Map_mergeClonedNames();
1329 enum ENudgeDirection
1343 AxisBase( const Vector3& x_, const Vector3& y_, const Vector3& z_ )
1344 : x( x_ ), y( y_ ), z( z_ ){
1348 AxisBase AxisBase_forViewType( VIEWTYPE viewtype ){
1352 return AxisBase( g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z );
1354 return AxisBase( g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y );
1356 return AxisBase( g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x );
1359 ERROR_MESSAGE( "invalid viewtype" );
1360 return AxisBase( Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) );
1363 Vector3 AxisBase_axisForDirection( const AxisBase& axes, ENudgeDirection direction ){
1364 switch ( direction )
1367 return vector3_negated( axes.x );
1373 return vector3_negated( axes.y );
1376 ERROR_MESSAGE( "invalid direction" );
1377 return Vector3( 0, 0, 0 );
1380 void NudgeSelection( ENudgeDirection direction, float fAmount, VIEWTYPE viewtype ){
1381 AxisBase axes( AxisBase_forViewType( viewtype ) );
1382 Vector3 view_direction( vector3_negated( axes.z ) );
1383 Vector3 nudge( vector3_scaled( AxisBase_axisForDirection( axes, direction ), fAmount ) );
1384 GlobalSelectionSystem().NudgeManipulator( nudge, view_direction );
1387 void Selection_Clone(){
1388 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1389 UndoableCommand undo( "cloneSelected" );
1391 Scene_Clone_Selected( GlobalSceneGraph(), false );
1393 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1394 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1398 void Selection_Clone_MakeUnique(){
1399 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1400 UndoableCommand undo( "cloneSelectedMakeUnique" );
1402 Scene_Clone_Selected( GlobalSceneGraph(), true );
1404 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1405 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1409 // called when the escape key is used (either on the main window or on an inspector)
1410 void Selection_Deselect(){
1411 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1412 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1413 GlobalSelectionSystem().setSelectedAllComponents( false );
1417 SelectionSystem_DefaultMode();
1418 ComponentModeChanged();
1423 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1424 GlobalSelectionSystem().setSelectedAllComponents( false );
1428 GlobalSelectionSystem().setSelectedAll( false );
1434 void Selection_NudgeUp(){
1435 UndoableCommand undo( "nudgeSelectedUp" );
1436 NudgeSelection( eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1439 void Selection_NudgeDown(){
1440 UndoableCommand undo( "nudgeSelectedDown" );
1441 NudgeSelection( eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1444 void Selection_NudgeLeft(){
1445 UndoableCommand undo( "nudgeSelectedLeft" );
1446 NudgeSelection( eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1449 void Selection_NudgeRight(){
1450 UndoableCommand undo( "nudgeSelectedRight" );
1451 NudgeSelection( eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1455 void TranslateToolExport( const Callback<void(bool)> & importCallback ){
1456 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate );
1459 void RotateToolExport( const Callback<void(bool)> & importCallback ){
1460 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate );
1463 void ScaleToolExport( const Callback<void(bool)> & importCallback ){
1464 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale );
1467 void DragToolExport( const Callback<void(bool)> & importCallback ){
1468 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag );
1471 void ClipperToolExport( const Callback<void(bool)> & importCallback ){
1472 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip );
1475 FreeCaller<void(const Callback<void(bool)> &), TranslateToolExport> g_translatemode_button_caller;
1476 Callback<void(const Callback<void(bool)> &)> g_translatemode_button_callback( g_translatemode_button_caller );
1477 ToggleItem g_translatemode_button( g_translatemode_button_callback );
1479 FreeCaller<void(const Callback<void(bool)> &), RotateToolExport> g_rotatemode_button_caller;
1480 Callback<void(const Callback<void(bool)> &)> g_rotatemode_button_callback( g_rotatemode_button_caller );
1481 ToggleItem g_rotatemode_button( g_rotatemode_button_callback );
1483 FreeCaller<void(const Callback<void(bool)> &), ScaleToolExport> g_scalemode_button_caller;
1484 Callback<void(const Callback<void(bool)> &)> g_scalemode_button_callback( g_scalemode_button_caller );
1485 ToggleItem g_scalemode_button( g_scalemode_button_callback );
1487 FreeCaller<void(const Callback<void(bool)> &), DragToolExport> g_dragmode_button_caller;
1488 Callback<void(const Callback<void(bool)> &)> g_dragmode_button_callback( g_dragmode_button_caller );
1489 ToggleItem g_dragmode_button( g_dragmode_button_callback );
1491 FreeCaller<void(const Callback<void(bool)> &), ClipperToolExport> g_clipper_button_caller;
1492 Callback<void(const Callback<void(bool)> &)> g_clipper_button_callback( g_clipper_button_caller );
1493 ToggleItem g_clipper_button( g_clipper_button_callback );
1496 g_translatemode_button.update();
1497 g_rotatemode_button.update();
1498 g_scalemode_button.update();
1499 g_dragmode_button.update();
1500 g_clipper_button.update();
1503 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1506 if ( g_currentToolMode == DragMode && g_defaultToolMode != DragMode ) {
1507 g_defaultToolMode();
1511 g_currentToolMode = DragMode;
1512 g_currentToolModeSupportsComponentEditing = true;
1514 OnClipMode( false );
1516 Sys_Status( c_ResizeMode_status );
1517 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eDrag );
1524 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1526 void TranslateMode(){
1527 if ( g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode ) {
1528 g_defaultToolMode();
1532 g_currentToolMode = TranslateMode;
1533 g_currentToolModeSupportsComponentEditing = true;
1535 OnClipMode( false );
1537 Sys_Status( c_TranslateMode_status );
1538 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eTranslate );
1544 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1547 if ( g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode ) {
1548 g_defaultToolMode();
1552 g_currentToolMode = RotateMode;
1553 g_currentToolModeSupportsComponentEditing = true;
1555 OnClipMode( false );
1557 Sys_Status( c_RotateMode_status );
1558 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eRotate );
1564 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1567 if ( g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode ) {
1568 g_defaultToolMode();
1572 g_currentToolMode = ScaleMode;
1573 g_currentToolModeSupportsComponentEditing = true;
1575 OnClipMode( false );
1577 Sys_Status( c_ScaleMode_status );
1578 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eScale );
1585 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1589 if ( g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode ) {
1590 g_defaultToolMode();
1594 g_currentToolMode = ClipperMode;
1595 g_currentToolModeSupportsComponentEditing = false;
1597 SelectionSystem_DefaultMode();
1601 Sys_Status( c_ClipperMode_status );
1602 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eClip );
1609 void Texdef_Rotate( float angle ){
1610 StringOutputStream command;
1611 command << "brushRotateTexture -angle " << angle;
1612 UndoableCommand undo( command.c_str() );
1613 Select_RotateTexture( angle );
1616 void Texdef_RotateClockwise(){
1617 Texdef_Rotate( static_cast<float>( fabs( g_si_globals.rotate ) ) );
1620 void Texdef_RotateAntiClockwise(){
1621 Texdef_Rotate( static_cast<float>( -fabs( g_si_globals.rotate ) ) );
1624 void Texdef_Scale( float x, float y ){
1625 StringOutputStream command;
1626 command << "brushScaleTexture -x " << x << " -y " << y;
1627 UndoableCommand undo( command.c_str() );
1628 Select_ScaleTexture( x, y );
1631 void Texdef_ScaleUp(){
1632 Texdef_Scale( 0, g_si_globals.scale[1] );
1635 void Texdef_ScaleDown(){
1636 Texdef_Scale( 0, -g_si_globals.scale[1] );
1639 void Texdef_ScaleLeft(){
1640 Texdef_Scale( -g_si_globals.scale[0],0 );
1643 void Texdef_ScaleRight(){
1644 Texdef_Scale( g_si_globals.scale[0],0 );
1647 void Texdef_Shift( float x, float y ){
1648 StringOutputStream command;
1649 command << "brushShiftTexture -x " << x << " -y " << y;
1650 UndoableCommand undo( command.c_str() );
1651 Select_ShiftTexture( x, y );
1654 void Texdef_ShiftLeft(){
1655 Texdef_Shift( -g_si_globals.shift[0], 0 );
1658 void Texdef_ShiftRight(){
1659 Texdef_Shift( g_si_globals.shift[0], 0 );
1662 void Texdef_ShiftUp(){
1663 Texdef_Shift( 0, g_si_globals.shift[1] );
1666 void Texdef_ShiftDown(){
1667 Texdef_Shift( 0, -g_si_globals.shift[1] );
1672 class SnappableSnapToGridSelected : public scene::Graph::Walker
1676 SnappableSnapToGridSelected( float snap )
1680 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1681 if ( path.top().get().visible() ) {
1682 Snappable* snappable = Node_getSnappable( path.top() );
1684 && Instance_getSelectable( instance )->isSelected() ) {
1685 snappable->snapto( m_snap );
1692 void Scene_SnapToGrid_Selected( scene::Graph& graph, float snap ){
1693 graph.traverse( SnappableSnapToGridSelected( snap ) );
1696 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1700 ComponentSnappableSnapToGridSelected( float snap )
1704 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1705 if ( path.top().get().visible() ) {
1706 ComponentSnappable* componentSnappable = Instance_getComponentSnappable( instance );
1707 if ( componentSnappable != 0
1708 && Instance_getSelectable( instance )->isSelected() ) {
1709 componentSnappable->snapComponents( m_snap );
1716 void Scene_SnapToGrid_Component_Selected( scene::Graph& graph, float snap ){
1717 graph.traverse( ComponentSnappableSnapToGridSelected( snap ) );
1720 void Selection_SnapToGrid(){
1721 StringOutputStream command;
1722 command << "snapSelected -grid " << GetGridSize();
1723 UndoableCommand undo( command.c_str() );
1725 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1726 Scene_SnapToGrid_Component_Selected( GlobalSceneGraph(), GetGridSize() );
1730 Scene_SnapToGrid_Selected( GlobalSceneGraph(), GetGridSize() );
1735 static gint qe_every_second( gpointer data ){
1736 GdkModifierType mask;
1738 gdk_window_get_pointer( 0, 0, 0, &mask );
1740 if ( ( mask & ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK ) ) == 0 ) {
1747 guint s_qe_every_second_id = 0;
1749 void EverySecondTimer_enable(){
1750 if ( s_qe_every_second_id == 0 ) {
1751 s_qe_every_second_id = g_timeout_add( 1000, qe_every_second, 0 );
1755 void EverySecondTimer_disable(){
1756 if ( s_qe_every_second_id != 0 ) {
1757 g_source_remove( s_qe_every_second_id );
1758 s_qe_every_second_id = 0;
1762 gint window_realize_remove_decoration( ui::Widget widget, gpointer data ){
1763 gdk_window_set_decorations( gtk_widget_get_window(widget), (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) );
1770 ui::Window m_window{ui::null};
1771 ui::Label m_label{ui::null};
1774 WaitDialog create_wait_dialog( const char* title, const char* text ){
1777 dialog.m_window = MainFrame_getWindow().create_floating_window(title);
1778 gtk_window_set_resizable( dialog.m_window, FALSE );
1779 gtk_container_set_border_width( GTK_CONTAINER( dialog.m_window ), 0 );
1780 gtk_window_set_position( dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT );
1782 dialog.m_window.connect( "realize", G_CALLBACK( window_realize_remove_decoration ), 0 );
1785 dialog.m_label = ui::Label( text );
1786 gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 );
1787 gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT );
1788 dialog.m_label.show();
1789 dialog.m_label.dimensions(200, -1);
1791 dialog.m_window.add(dialog.m_label);
1798 clock_t g_lastRedrawTime = 0;
1799 const clock_t c_redrawInterval = clock_t( CLOCKS_PER_SEC / 10 );
1801 bool redrawRequired(){
1802 clock_t currentTime = std::clock();
1803 if ( currentTime - g_lastRedrawTime >= c_redrawInterval ) {
1804 g_lastRedrawTime = currentTime;
1811 bool MainFrame_isActiveApp(){
1812 //globalOutputStream() << "listing\n";
1813 GList* list = gtk_window_list_toplevels();
1814 for ( GList* i = list; i != 0; i = g_list_next( i ) )
1816 //globalOutputStream() << "toplevel.. ";
1817 if ( gtk_window_is_active( ui::Window::from( i->data ) ) ) {
1818 //globalOutputStream() << "is active\n";
1821 //globalOutputStream() << "not active\n";
1826 typedef std::list<CopiedString> StringStack;
1827 StringStack g_wait_stack;
1830 bool ScreenUpdates_Enabled(){
1831 return g_wait_stack.empty();
1834 void ScreenUpdates_process(){
1835 if ( redrawRequired() && g_wait.m_window.visible() ) {
1841 void ScreenUpdates_Disable( const char* message, const char* title ){
1842 if ( g_wait_stack.empty() ) {
1843 EverySecondTimer_disable();
1847 bool isActiveApp = MainFrame_isActiveApp();
1849 g_wait = create_wait_dialog( title, message );
1850 gtk_grab_add( g_wait.m_window );
1852 if ( isActiveApp ) {
1853 g_wait.m_window.show();
1854 ScreenUpdates_process();
1857 else if ( g_wait.m_window.visible() ) {
1858 g_wait.m_label.text(message);
1859 ScreenUpdates_process();
1861 g_wait_stack.push_back( message );
1864 void ScreenUpdates_Enable(){
1865 ASSERT_MESSAGE( !ScreenUpdates_Enabled(), "screen updates already enabled" );
1866 g_wait_stack.pop_back();
1867 if ( g_wait_stack.empty() ) {
1868 EverySecondTimer_enable();
1869 //gtk_widget_set_sensitive(MainFrame_getWindow(), TRUE);
1871 gtk_grab_remove( g_wait.m_window );
1872 destroy_floating_window( g_wait.m_window );
1873 g_wait.m_window = ui::Window{ui::null};
1875 //gtk_window_present(MainFrame_getWindow());
1877 else if ( g_wait.m_window.visible() ) {
1878 g_wait.m_label.text(g_wait_stack.back().c_str());
1879 ScreenUpdates_process();
1884 void GlobalCamera_UpdateWindow(){
1885 if ( g_pParentWnd != 0 ) {
1886 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
1890 void XY_UpdateWindow( MainFrame& mainframe ){
1891 if ( mainframe.GetXYWnd() != 0 ) {
1892 XYWnd_Update( *mainframe.GetXYWnd() );
1896 void XZ_UpdateWindow( MainFrame& mainframe ){
1897 if ( mainframe.GetXZWnd() != 0 ) {
1898 XYWnd_Update( *mainframe.GetXZWnd() );
1902 void YZ_UpdateWindow( MainFrame& mainframe ){
1903 if ( mainframe.GetYZWnd() != 0 ) {
1904 XYWnd_Update( *mainframe.GetYZWnd() );
1908 void XY_UpdateAllWindows( MainFrame& mainframe ){
1909 XY_UpdateWindow( mainframe );
1910 XZ_UpdateWindow( mainframe );
1911 YZ_UpdateWindow( mainframe );
1914 void XY_UpdateAllWindows(){
1915 if ( g_pParentWnd != 0 ) {
1916 XY_UpdateAllWindows( *g_pParentWnd );
1920 void UpdateAllWindows(){
1921 GlobalCamera_UpdateWindow();
1922 XY_UpdateAllWindows();
1926 void ModeChangeNotify(){
1927 SceneChangeNotify();
1930 void ClipperChangeNotify(){
1931 GlobalCamera_UpdateWindow();
1932 XY_UpdateAllWindows();
1936 LatchedValue<int> g_Layout_viewStyle( 0, "Window Layout" );
1937 LatchedValue<bool> g_Layout_enableDetachableMenus( true, "Detachable Menus" );
1938 LatchedValue<bool> g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
1939 LatchedValue<bool> g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
1942 ui::MenuItem create_file_menu(){
1944 auto file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
1945 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( file_menu_item ) );
1946 if ( g_Layout_enableDetachableMenus.m_value ) {
1947 menu_tearoff( menu );
1950 create_menu_item_with_mnemonic( menu, "_New Map", "NewMap" );
1951 menu_separator( menu );
1954 //++timo temporary experimental stuff for sleep mode..
1955 create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" );
1956 menu_separator( menu );
1960 create_menu_item_with_mnemonic( menu, "_Open...", "OpenMap" );
1962 create_menu_item_with_mnemonic( menu, "_Import...", "ImportMap" );
1963 create_menu_item_with_mnemonic( menu, "_Save", "SaveMap" );
1964 create_menu_item_with_mnemonic( menu, "Save _as...", "SaveMapAs" );
1965 create_menu_item_with_mnemonic( menu, "_Export selected...", "ExportSelected" );
1966 menu_separator( menu );
1967 create_menu_item_with_mnemonic( menu, "Save re_gion...", "SaveRegion" );
1968 // menu_separator( menu );
1969 // create_menu_item_with_mnemonic( menu, "_Refresh models", "RefreshReferences" );
1970 // menu_separator( menu );
1971 create_menu_item_with_mnemonic( menu, "Pro_ject settings...", "ProjectSettings" );
1972 menu_separator( menu );
1973 create_menu_item_with_mnemonic( menu, "_Pointfile...", "TogglePointfile" );
1974 menu_separator( menu );
1975 MRU_constructMenu( menu );
1976 menu_separator( menu );
1977 // create_menu_item_with_mnemonic( menu, "Check for NetRadiant update (web)", "CheckForUpdate" ); // FIXME
1978 create_menu_item_with_mnemonic( menu, "E_xit", "Exit" );
1980 return file_menu_item;
1983 ui::MenuItem create_edit_menu(){
1985 auto edit_menu_item = new_sub_menu_item_with_mnemonic( "_Edit" );
1986 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( edit_menu_item ) );
1987 if ( g_Layout_enableDetachableMenus.m_value ) {
1988 menu_tearoff( menu );
1990 create_menu_item_with_mnemonic( menu, "_Undo", "Undo" );
1991 create_menu_item_with_mnemonic( menu, "_Redo", "Redo" );
1992 menu_separator( menu );
1993 create_menu_item_with_mnemonic( menu, "_Copy", "Copy" );
1994 create_menu_item_with_mnemonic( menu, "_Paste", "Paste" );
1995 create_menu_item_with_mnemonic( menu, "P_aste To Camera", "PasteToCamera" );
1996 menu_separator( menu );
1997 create_menu_item_with_mnemonic( menu, "_Duplicate", "CloneSelection" );
1998 create_menu_item_with_mnemonic( menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique" );
1999 create_menu_item_with_mnemonic( menu, "D_elete", "DeleteSelection" );
2000 menu_separator( menu );
2001 create_menu_item_with_mnemonic( menu, "Snap To Grid", "SnapToGrid" );
2002 //create_menu_item_with_mnemonic( menu, "Pa_rent", "ParentSelection" );
2003 menu_separator( menu );
2004 create_menu_item_with_mnemonic( menu, "C_lear Selection", "UnSelectSelection" );
2005 create_menu_item_with_mnemonic( menu, "_Invert Selection", "InvertSelection" );
2006 create_menu_item_with_mnemonic( menu, "Select i_nside", "SelectInside" );
2007 create_menu_item_with_mnemonic( menu, "Select _touching", "SelectTouching" );
2009 menu_separator( menu );
2011 // auto convert_menu = create_sub_menu_with_mnemonic( menu, "E_xpand Selection" );
2012 // if ( g_Layout_enableDetachableMenus.m_value ) {
2013 // menu_tearoff( convert_menu );
2015 create_menu_item_with_mnemonic( menu, "Select All Of Type", "SelectAllOfType" );
2016 create_menu_item_with_mnemonic( menu, "_Expand Selection To Entities", "ExpandSelectionToEntities" );
2018 menu_separator( menu );
2019 create_menu_item_with_mnemonic( menu, "Pre_ferences...", "Preferences" );
2021 return edit_menu_item;
2024 void fill_view_xy_top_menu( ui::Menu menu ){
2025 create_check_menu_item_with_mnemonic( menu, "XY (Top) View", "ToggleView" );
2029 void fill_view_yz_side_menu( ui::Menu menu ){
2030 create_check_menu_item_with_mnemonic( menu, "YZ (Side) View", "ToggleSideView" );
2034 void fill_view_xz_front_menu( ui::Menu menu ){
2035 create_check_menu_item_with_mnemonic( menu, "XZ (Front) View", "ToggleFrontView" );
2039 ui::Widget g_toggle_z_item{ui::null};
2040 ui::Widget g_toggle_console_item{ui::null};
2041 ui::Widget g_toggle_entity_item{ui::null};
2042 ui::Widget g_toggle_entitylist_item{ui::null};
2044 ui::MenuItem create_view_menu( MainFrame::EViewStyle style ){
2046 auto view_menu_item = new_sub_menu_item_with_mnemonic( "Vie_w" );
2047 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( view_menu_item ) );
2048 if ( g_Layout_enableDetachableMenus.m_value ) {
2049 menu_tearoff( menu );
2052 if ( style == MainFrame::eFloating ) {
2053 fill_view_camera_menu( menu );
2054 fill_view_xy_top_menu( menu );
2055 fill_view_yz_side_menu( menu );
2056 fill_view_xz_front_menu( menu );
2058 if ( style == MainFrame::eFloating || style == MainFrame::eSplit ) {
2059 create_menu_item_with_mnemonic( menu, "Console View", "ToggleConsole" );
2060 create_menu_item_with_mnemonic( menu, "Texture Browser", "ToggleTextures" );
2061 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ToggleEntityInspector" );
2065 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ViewEntityInfo" );
2067 create_menu_item_with_mnemonic( menu, "_Surface Inspector", "SurfaceInspector" );
2068 create_menu_item_with_mnemonic( menu, "_Patch Inspector", "PatchInspector" );
2069 create_menu_item_with_mnemonic( menu, "Entity List", "EntityList" );
2071 menu_separator( menu );
2073 auto camera_menu = create_sub_menu_with_mnemonic( menu, "Camera" );
2074 if ( g_Layout_enableDetachableMenus.m_value ) {
2075 menu_tearoff( camera_menu );
2077 create_menu_item_with_mnemonic( camera_menu, "_Center", "CenterView" );
2078 create_menu_item_with_mnemonic( camera_menu, "_Up Floor", "UpFloor" );
2079 create_menu_item_with_mnemonic( camera_menu, "_Down Floor", "DownFloor" );
2080 menu_separator( camera_menu );
2081 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane In", "CubicClipZoomIn" );
2082 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane Out", "CubicClipZoomOut" );
2083 menu_separator( camera_menu );
2084 create_menu_item_with_mnemonic( camera_menu, "Next leak spot", "NextLeakSpot" );
2085 create_menu_item_with_mnemonic( camera_menu, "Previous leak spot", "PrevLeakSpot" );
2086 menu_separator( camera_menu );
2087 create_menu_item_with_mnemonic( camera_menu, "Look Through Selected", "LookThroughSelected" );
2088 create_menu_item_with_mnemonic( camera_menu, "Look Through Camera", "LookThroughCamera" );
2090 menu_separator( menu );
2092 auto orthographic_menu = create_sub_menu_with_mnemonic( menu, "Orthographic" );
2093 if ( g_Layout_enableDetachableMenus.m_value ) {
2094 menu_tearoff( orthographic_menu );
2096 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2097 create_menu_item_with_mnemonic( orthographic_menu, "_Next (XY, YZ, XY)", "NextView" );
2098 create_menu_item_with_mnemonic( orthographic_menu, "XY (Top)", "ViewTop" );
2099 create_menu_item_with_mnemonic( orthographic_menu, "YZ", "ViewSide" );
2100 create_menu_item_with_mnemonic( orthographic_menu, "XZ", "ViewFront" );
2101 menu_separator( orthographic_menu );
2104 create_menu_item_with_mnemonic( orthographic_menu, "Center on Selected", "CenterXYView" );
2105 menu_separator( orthographic_menu );
2106 create_menu_item_with_mnemonic( orthographic_menu, "_XY 100%", "Zoom100" );
2107 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _In", "ZoomIn" );
2108 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _Out", "ZoomOut" );
2111 menu_separator( menu );
2114 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Show" );
2115 if ( g_Layout_enableDetachableMenus.m_value ) {
2116 menu_tearoff( menu_in_menu );
2118 create_menu_item_with_mnemonic( menu_in_menu, "Show Size Info", "ToggleSizePaint" );
2119 create_menu_item_with_mnemonic( menu_in_menu, "Show Crosshair", "ToggleCrosshairs" );
2120 create_menu_item_with_mnemonic( menu_in_menu, "Show Grid", "ToggleGrid" );
2122 menu_separator( menu_in_menu );
2124 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Angles", "ShowAngles" );
2125 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Names", "ShowNames" );
2126 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Blocks", "ShowBlocks" );
2127 create_check_menu_item_with_mnemonic( menu_in_menu, "Show C_oordinates", "ShowCoordinates" );
2128 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Window Outline", "ShowWindowOutline" );
2129 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Axes", "ShowAxes" );
2130 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Workzone", "ShowWorkzone" );
2131 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Stats", "ShowStats" );
2135 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Filter" );
2136 if ( g_Layout_enableDetachableMenus.m_value ) {
2137 menu_tearoff( menu_in_menu );
2139 Filters_constructMenu( menu_in_menu );
2141 menu_separator( menu );
2143 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Hide/Show" );
2144 // if ( g_Layout_enableDetachableMenus.m_value ) {
2145 // menu_tearoff( menu_in_menu );
2147 // create_menu_item_with_mnemonic( menu_in_menu, "Hide Selected", "HideSelected" );
2148 // create_menu_item_with_mnemonic( menu_in_menu, "Show Hidden", "ShowHidden" );
2149 create_menu_item_with_mnemonic( menu, "Hide Selected", "HideSelected" );
2150 create_menu_item_with_mnemonic( menu, "Show Hidden", "ShowHidden" );
2152 menu_separator( menu );
2154 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Region" );
2155 if ( g_Layout_enableDetachableMenus.m_value ) {
2156 menu_tearoff( menu_in_menu );
2158 create_menu_item_with_mnemonic( menu_in_menu, "_Off", "RegionOff" );
2159 create_menu_item_with_mnemonic( menu_in_menu, "_Set XY", "RegionSetXY" );
2160 create_menu_item_with_mnemonic( menu_in_menu, "Set _Brush", "RegionSetBrush" );
2161 create_menu_item_with_mnemonic( menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection" );
2164 command_connect_accelerator( "CenterXYView" );
2166 return view_menu_item;
2169 ui::MenuItem create_selection_menu(){
2171 auto selection_menu_item = new_sub_menu_item_with_mnemonic( "M_odify" );
2172 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( selection_menu_item ) );
2173 if ( g_Layout_enableDetachableMenus.m_value ) {
2174 menu_tearoff( menu );
2178 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Components" );
2179 if ( g_Layout_enableDetachableMenus.m_value ) {
2180 menu_tearoff( menu_in_menu );
2182 create_check_menu_item_with_mnemonic( menu_in_menu, "_Edges", "DragEdges" );
2183 create_check_menu_item_with_mnemonic( menu_in_menu, "_Vertices", "DragVertices" );
2184 create_check_menu_item_with_mnemonic( menu_in_menu, "_Faces", "DragFaces" );
2187 menu_separator( menu );
2190 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Nudge" );
2191 if ( g_Layout_enableDetachableMenus.m_value ) {
2192 menu_tearoff( menu_in_menu );
2194 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Left", "SelectNudgeLeft" );
2195 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Right", "SelectNudgeRight" );
2196 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Up", "SelectNudgeUp" );
2197 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Down", "SelectNudgeDown" );
2200 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Rotate" );
2201 if ( g_Layout_enableDetachableMenus.m_value ) {
2202 menu_tearoff( menu_in_menu );
2204 create_menu_item_with_mnemonic( menu_in_menu, "Rotate X", "RotateSelectionX" );
2205 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Y", "RotateSelectionY" );
2206 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Z", "RotateSelectionZ" );
2209 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Flip" );
2210 if ( g_Layout_enableDetachableMenus.m_value ) {
2211 menu_tearoff( menu_in_menu );
2213 create_menu_item_with_mnemonic( menu_in_menu, "Flip _X", "MirrorSelectionX" );
2214 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Y", "MirrorSelectionY" );
2215 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Z", "MirrorSelectionZ" );
2217 menu_separator( menu );
2218 create_menu_item_with_mnemonic( menu, "Arbitrary rotation...", "ArbitraryRotation" );
2219 create_menu_item_with_mnemonic( menu, "Arbitrary scale...", "ArbitraryScale" );
2221 return selection_menu_item;
2224 ui::MenuItem create_bsp_menu(){
2226 auto bsp_menu_item = new_sub_menu_item_with_mnemonic( "_Build" );
2227 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( bsp_menu_item ) );
2229 if ( g_Layout_enableDetachableMenus.m_value ) {
2230 menu_tearoff( menu );
2233 create_menu_item_with_mnemonic( menu, "Customize...", "BuildMenuCustomize" );
2235 menu_separator( menu );
2237 Build_constructMenu( menu );
2241 return bsp_menu_item;
2244 ui::MenuItem create_grid_menu(){
2246 auto grid_menu_item = new_sub_menu_item_with_mnemonic( "_Grid" );
2247 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( grid_menu_item ) );
2248 if ( g_Layout_enableDetachableMenus.m_value ) {
2249 menu_tearoff( menu );
2252 Grid_constructMenu( menu );
2254 return grid_menu_item;
2257 ui::MenuItem create_misc_menu(){
2259 auto misc_menu_item = new_sub_menu_item_with_mnemonic( "M_isc" );
2260 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( misc_menu_item ) );
2261 if ( g_Layout_enableDetachableMenus.m_value ) {
2262 menu_tearoff( menu );
2266 create_menu_item_with_mnemonic( menu, "_Benchmark", makeCallbackF(GlobalCamera_Benchmark) );
2268 menu.add(create_colours_menu());
2270 create_menu_item_with_mnemonic( menu, "Find brush...", "FindBrush" );
2271 create_menu_item_with_mnemonic( menu, "Map Info...", "MapInfo" );
2272 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2273 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<void(), WXY_Print>());
2274 create_menu_item_with_mnemonic( menu, "_Background select", makeCallbackF(WXY_BackgroundSelect) );
2275 return misc_menu_item;
2278 ui::MenuItem create_entity_menu(){
2280 auto entity_menu_item = new_sub_menu_item_with_mnemonic( "E_ntity" );
2281 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( entity_menu_item ) );
2282 if ( g_Layout_enableDetachableMenus.m_value ) {
2283 menu_tearoff( menu );
2286 Entity_constructMenu( menu );
2288 return entity_menu_item;
2291 ui::MenuItem create_brush_menu(){
2293 auto brush_menu_item = new_sub_menu_item_with_mnemonic( "B_rush" );
2294 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( brush_menu_item ) );
2295 if ( g_Layout_enableDetachableMenus.m_value ) {
2296 menu_tearoff( menu );
2299 Brush_constructMenu( menu );
2301 return brush_menu_item;
2304 ui::MenuItem create_patch_menu(){
2306 auto patch_menu_item = new_sub_menu_item_with_mnemonic( "_Curve" );
2307 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( patch_menu_item ) );
2308 if ( g_Layout_enableDetachableMenus.m_value ) {
2309 menu_tearoff( menu );
2312 Patch_constructMenu( menu );
2314 return patch_menu_item;
2317 ui::MenuItem create_help_menu(){
2319 auto help_menu_item = new_sub_menu_item_with_mnemonic( "_Help" );
2320 auto menu = ui::Menu::from( gtk_menu_item_get_submenu( help_menu_item ) );
2321 if ( g_Layout_enableDetachableMenus.m_value ) {
2322 menu_tearoff( menu );
2325 // create_menu_item_with_mnemonic( menu, "Manual", "OpenManual" );
2327 // this creates all the per-game drop downs for the game pack helps
2328 // it will take care of hooking the Sys_OpenURL calls etc.
2329 create_game_help_menu( menu );
2331 create_menu_item_with_mnemonic( menu, "Bug report", makeCallbackF(OpenBugReportURL) );
2332 create_menu_item_with_mnemonic( menu, "Shortcuts list", makeCallbackF(DoCommandListDlg) );
2333 create_menu_item_with_mnemonic( menu, "_About", makeCallbackF(DoAbout) );
2335 return help_menu_item;
2338 ui::MenuBar create_main_menu( MainFrame::EViewStyle style ){
2339 auto menu_bar = ui::MenuBar::from( gtk_menu_bar_new() );
2342 menu_bar.add(create_file_menu());
2343 menu_bar.add(create_edit_menu());
2344 menu_bar.add(create_view_menu(style));
2345 menu_bar.add(create_selection_menu());
2346 menu_bar.add(create_bsp_menu());
2347 menu_bar.add(create_grid_menu());
2348 menu_bar.add(create_misc_menu());
2349 menu_bar.add(create_entity_menu());
2350 menu_bar.add(create_brush_menu());
2351 menu_bar.add(create_patch_menu());
2352 menu_bar.add(create_plugins_menu());
2353 menu_bar.add(create_help_menu());
2359 void PatchInspector_registerShortcuts(){
2360 command_connect_accelerator( "PatchInspector" );
2363 void Patch_registerShortcuts(){
2364 command_connect_accelerator( "InvertCurveTextureX" );
2365 command_connect_accelerator( "InvertCurveTextureY" );
2366 command_connect_accelerator( "PatchInsertInsertColumn" );
2367 command_connect_accelerator( "PatchInsertInsertRow" );
2368 command_connect_accelerator( "PatchDeleteLastColumn" );
2369 command_connect_accelerator( "PatchDeleteLastRow" );
2370 command_connect_accelerator( "NaturalizePatch" );
2371 //command_connect_accelerator("CapCurrentCurve");
2374 void Manipulators_registerShortcuts(){
2375 toggle_add_accelerator( "MouseRotate" );
2376 toggle_add_accelerator( "MouseTranslate" );
2377 toggle_add_accelerator( "MouseScale" );
2378 toggle_add_accelerator( "MouseDrag" );
2379 toggle_add_accelerator( "ToggleClipper" );
2382 void TexdefNudge_registerShortcuts(){
2383 command_connect_accelerator( "TexRotateClock" );
2384 command_connect_accelerator( "TexRotateCounter" );
2385 command_connect_accelerator( "TexScaleUp" );
2386 command_connect_accelerator( "TexScaleDown" );
2387 command_connect_accelerator( "TexScaleLeft" );
2388 command_connect_accelerator( "TexScaleRight" );
2389 command_connect_accelerator( "TexShiftUp" );
2390 command_connect_accelerator( "TexShiftDown" );
2391 command_connect_accelerator( "TexShiftLeft" );
2392 command_connect_accelerator( "TexShiftRight" );
2395 void SelectNudge_registerShortcuts(){
2396 command_connect_accelerator( "MoveSelectionDOWN" );
2397 command_connect_accelerator( "MoveSelectionUP" );
2398 //command_connect_accelerator("SelectNudgeLeft");
2399 //command_connect_accelerator("SelectNudgeRight");
2400 //command_connect_accelerator("SelectNudgeUp");
2401 //command_connect_accelerator("SelectNudgeDown");
2404 void SnapToGrid_registerShortcuts(){
2405 command_connect_accelerator( "SnapToGrid" );
2408 void SelectByType_registerShortcuts(){
2409 command_connect_accelerator( "SelectAllOfType" );
2412 void SurfaceInspector_registerShortcuts(){
2413 command_connect_accelerator( "FitTexture" );
2417 void register_shortcuts(){
2418 PatchInspector_registerShortcuts();
2419 Patch_registerShortcuts();
2420 Grid_registerShortcuts();
2421 XYWnd_registerShortcuts();
2422 CamWnd_registerShortcuts();
2423 Manipulators_registerShortcuts();
2424 SurfaceInspector_registerShortcuts();
2425 TexdefNudge_registerShortcuts();
2426 SelectNudge_registerShortcuts();
2427 SnapToGrid_registerShortcuts();
2428 SelectByType_registerShortcuts();
2431 void File_constructToolbar( ui::Toolbar toolbar ){
2432 toolbar_append_button( toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap" );
2433 toolbar_append_button( toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap" );
2436 void UndoRedo_constructToolbar( ui::Toolbar toolbar ){
2437 toolbar_append_button( toolbar, "Undo (CTRL + Z)", "undo.png", "Undo" );
2438 toolbar_append_button( toolbar, "Redo (CTRL + Y)", "redo.png", "Redo" );
2441 void RotateFlip_constructToolbar( ui::Toolbar toolbar ){
2442 toolbar_append_button( toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX" );
2443 toolbar_append_button( toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX" );
2444 toolbar_append_button( toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY" );
2445 toolbar_append_button( toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY" );
2446 toolbar_append_button( toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ" );
2447 toolbar_append_button( toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ" );
2450 void Select_constructToolbar( ui::Toolbar toolbar ){
2451 toolbar_append_button( toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching" );
2452 toolbar_append_button( toolbar, "Select inside", "selection_selectinside.png", "SelectInside" );
2455 void CSG_constructToolbar( ui::Toolbar toolbar ){
2456 toolbar_append_button( toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract" );
2457 toolbar_append_button( toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge" );
2458 toolbar_append_button( toolbar, "Make Hollow", "selection_makehollow.png", "CSGMakeHollow" );
2459 toolbar_append_button( toolbar, "Make Room", "selection_makeroom.png", "CSGMakeRoom" );
2462 void ComponentModes_constructToolbar( ui::Toolbar toolbar ){
2463 toolbar_append_toggle_button( toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices" );
2464 toolbar_append_toggle_button( toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges" );
2465 toolbar_append_toggle_button( toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces" );
2468 void Clipper_constructToolbar( ui::Toolbar toolbar ){
2470 toolbar_append_toggle_button( toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper" );
2473 void XYWnd_constructToolbar( ui::Toolbar toolbar ){
2474 toolbar_append_button( toolbar, "Change views", "view_change.png", "NextView" );
2477 void Manipulators_constructToolbar( ui::Toolbar toolbar ){
2478 toolbar_append_toggle_button( toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate" );
2479 toolbar_append_toggle_button( toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate" );
2480 toolbar_append_toggle_button( toolbar, "Scale", "select_mousescale.png", "MouseScale" );
2481 toolbar_append_toggle_button( toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag" );
2483 Clipper_constructToolbar( toolbar );
2486 ui::Toolbar create_main_toolbar( MainFrame::EViewStyle style ){
2487 auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
2488 gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL );
2489 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
2493 auto space = [&]() {
2494 auto btn = ui::ToolItem::from(gtk_separator_tool_item_new());
2499 File_constructToolbar( toolbar );
2503 UndoRedo_constructToolbar( toolbar );
2507 RotateFlip_constructToolbar( toolbar );
2511 Select_constructToolbar( toolbar );
2515 CSG_constructToolbar( toolbar );
2519 ComponentModes_constructToolbar( toolbar );
2521 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2524 XYWnd_constructToolbar( toolbar );
2529 CamWnd_constructToolbar( toolbar );
2533 Manipulators_constructToolbar( toolbar );
2535 if ( g_Layout_enablePatchToolbar.m_value ) {
2538 Patch_constructToolbar( toolbar );
2543 toolbar_append_toggle_button( toolbar, "Texture Lock (SHIFT +T)", "texture_lock.png", "TogTexLock" );
2547 /*auto g_view_entities_button =*/ toolbar_append_button( toolbar, "Entities (N)", "entities.png", "ToggleEntityInspector" );
2548 auto g_view_console_button = toolbar_append_button( toolbar, "Console (O)", "console.png", "ToggleConsole" );
2549 auto g_view_textures_button = toolbar_append_button( toolbar, "Texture Browser (T)", "texture_browser.png", "ToggleTextures" );
2550 // TODO: call light inspector
2551 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector");
2554 /*auto g_refresh_models_button =*/ toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" );
2557 // disable the console and texture button in the regular layouts
2558 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft ) {
2559 gtk_widget_set_sensitive( g_view_console_button , FALSE );
2560 gtk_widget_set_sensitive( g_view_textures_button , FALSE );
2566 ui::Widget create_main_statusbar( ui::Widget pStatusLabel[c_count_status] ){
2567 auto table = ui::Table( 1, c_count_status, FALSE );
2571 auto label = ui::Label( "Label" );
2572 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2573 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2575 table.attach(label, {0, 1, 0, 1});
2576 pStatusLabel[c_command_status] = ui::Widget(label );
2579 for (unsigned int i = 1; (int) i < c_count_status; ++i)
2581 auto frame = ui::Frame();
2583 table.attach(frame, {i, i + 1, 0, 1});
2584 gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
2586 auto label = ui::Label( "Label" );
2587 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END );
2588 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2589 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2592 pStatusLabel[i] = ui::Widget(label );
2595 return ui::Widget(table );
2601 WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" );
2603 class WindowFocusPrinter
2607 static gboolean frame_event( ui::Widget widget, GdkEvent* event, WindowFocusPrinter* self ){
2608 globalOutputStream() << self->m_name << " frame_event\n";
2611 static gboolean keys_changed( ui::Widget widget, WindowFocusPrinter* self ){
2612 globalOutputStream() << self->m_name << " keys_changed\n";
2615 static gboolean notify( ui::Window window, gpointer dummy, WindowFocusPrinter* self ){
2616 if ( gtk_window_is_active( window ) ) {
2617 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2621 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2626 WindowFocusPrinter( const char* name ) : m_name( name ){
2628 void connect( ui::Window toplevel_window ){
2629 toplevel_window.connect( "notify::has_toplevel_focus", G_CALLBACK( notify ), this );
2630 toplevel_window.connect( "notify::is_active", G_CALLBACK( notify ), this );
2631 toplevel_window.connect( "keys_changed", G_CALLBACK( keys_changed ), this );
2632 toplevel_window.connect( "frame_event", G_CALLBACK( frame_event ), this );
2636 WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" );
2640 class MainWindowActive
2642 static gboolean notify( ui::Window window, gpointer dummy, MainWindowActive* self ){
2643 if ( g_wait.m_window && gtk_window_is_active( window ) && !g_wait.m_window.visible() ) {
2644 g_wait.m_window.show();
2651 void connect( ui::Window toplevel_window ){
2652 toplevel_window.connect( "notify::is-active", G_CALLBACK( notify ), this );
2656 MainWindowActive g_MainWindowActive;
2658 SignalHandlerId XYWindowDestroyed_connect( const SignalHandler& handler ){
2659 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst( handler );
2662 void XYWindowDestroyed_disconnect( SignalHandlerId id ){
2663 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect( id );
2666 MouseEventHandlerId XYWindowMouseDown_connect( const MouseEventHandler& handler ){
2667 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst( handler );
2670 void XYWindowMouseDown_disconnect( MouseEventHandlerId id ){
2671 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect( id );
2674 // =============================================================================
2677 MainFrame* g_pParentWnd = 0;
2679 ui::Window MainFrame_getWindow()
2681 return g_pParentWnd ? g_pParentWnd->m_window : ui::Window{ui::null};
2684 std::vector<ui::Widget> g_floating_windows;
2686 MainFrame::MainFrame() : m_idleRedrawStatusText( RedrawStatusTextCaller( *this ) ){
2694 for (auto &n : m_pStatusLabel) {
2698 m_bSleeping = false;
2703 MainFrame::~MainFrame(){
2710 for ( std::vector<ui::Widget>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i )
2718 void MainFrame::SetActiveXY( XYWnd* p ){
2719 if ( m_pActiveXY ) {
2720 m_pActiveXY->SetActive( false );
2725 if ( m_pActiveXY ) {
2726 m_pActiveXY->SetActive( true );
2731 void MainFrame::ReleaseContexts(){
2734 m_pXYWnd->DestroyContext();
2737 m_pYZWnd->DestroyContext();
2740 m_pXZWnd->DestroyContext();
2743 m_pCamWnd->DestroyContext();
2746 m_pTexWnd->DestroyContext();
2749 m_pZWnd->DestroyContext();
2754 void MainFrame::CreateContexts(){
2757 m_pCamWnd->CreateContext();
2760 m_pXYWnd->CreateContext();
2763 m_pYZWnd->CreateContext();
2766 m_pXZWnd->CreateContext();
2769 m_pTexWnd->CreateContext();
2772 m_pZWnd->CreateContext();
2781 void MainFrame::OnSleep(){
2784 if ( m_bSleeping ) {
2785 // useful when trying to debug crashes in the sleep code
2786 globalOutputStream() << "Going into sleep mode..\n";
2788 globalOutputStream() << "Dispatching sleep msg...";
2789 DispatchRadiantMsg( RADIANT_SLEEP );
2790 globalOutputStream() << "Done.\n";
2792 gtk_window_iconify( m_window );
2793 GlobalSelectionSystem().setSelectedAll( false );
2795 GlobalShaderCache().unrealise();
2797 GlobalOpenGL_debugAssertNoErrors();
2798 ScreenUpdates_Disable();
2801 globalOutputStream() << "Releasing contexts...";
2803 globalOutputStream() << "Done.\n";
2807 globalOutputStream() << "Waking up\n";
2809 gtk_window_deiconify( m_window );
2812 globalOutputStream() << "Creating contexts...";
2814 globalOutputStream() << "Done.\n";
2816 globalOutputStream() << "Making current on camera...";
2817 m_pCamWnd->MakeCurrent();
2818 globalOutputStream() << "Done.\n";
2820 globalOutputStream() << "Reloading shaders...";
2822 GlobalShaderCache().realise();
2823 globalOutputStream() << "Done.\n";
2825 ScreenUpdates_Enable();
2827 globalOutputStream() << "Dispatching wake msg...";
2828 DispatchRadiantMsg( RADIANT_WAKEUP );
2829 globalOutputStream() << "Done\n";
2835 ui::Window create_splash(){
2836 auto window = ui::Window( ui::window_type::TOP );
2837 gtk_window_set_decorated(window, false);
2838 gtk_window_set_resizable(window, false);
2839 gtk_window_set_modal(window, true);
2840 gtk_window_set_default_size( window, -1, -1 );
2841 gtk_window_set_position( window, GTK_WIN_POS_CENTER );
2842 gtk_container_set_border_width(window, 0);
2844 auto image = new_local_image( "splash.png" );
2848 window.dimensions(-1, -1);
2854 static ui::Window splash_screen{ui::null};
2857 splash_screen = create_splash();
2863 splash_screen.destroy();
2866 WindowPositionTracker g_posCamWnd;
2867 WindowPositionTracker g_posXYWnd;
2868 WindowPositionTracker g_posXZWnd;
2869 WindowPositionTracker g_posYZWnd;
2871 static gint mainframe_delete( ui::Widget widget, GdkEvent *event, gpointer data ){
2872 if ( ConfirmModified( "Exit Radiant" ) ) {
2879 void MainFrame::Create(){
2880 ui::Window window = ui::Window( ui::window_type::TOP );
2882 GlobalWindowObservers_connectTopLevel( window );
2884 gtk_window_set_transient_for( splash_screen, window );
2886 #if !GDEF_OS_WINDOWS
2888 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
2889 if ( pixbuf != 0 ) {
2890 gtk_window_set_icon( window, pixbuf );
2891 g_object_unref( pixbuf );
2896 gtk_widget_add_events( window , GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
2897 window.connect( "delete_event", G_CALLBACK( mainframe_delete ), this );
2899 m_position_tracker.connect( window );
2902 g_mainframeWidgetFocusPrinter.connect( window );
2903 g_mainframeFocusPrinter.connect( window );
2906 g_MainWindowActive.connect( window );
2908 GetPlugInMgr().Init( window );
2910 auto vbox = ui::VBox( FALSE, 0 );
2914 global_accel_connect_window( window );
2916 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
2918 register_shortcuts();
2920 auto main_menu = create_main_menu( CurrentStyle() );
2921 vbox.pack_start( main_menu, FALSE, FALSE, 0 );
2923 auto main_toolbar = create_main_toolbar( CurrentStyle() );
2924 vbox.pack_start( main_toolbar, FALSE, FALSE, 0 );
2926 auto plugin_toolbar = create_plugin_toolbar();
2927 if ( !g_Layout_enablePluginToolbar.m_value ) {
2928 plugin_toolbar.hide();
2930 vbox.pack_start( plugin_toolbar, FALSE, FALSE, 0 );
2932 ui::Widget main_statusbar = create_main_statusbar(reinterpret_cast<ui::Widget *>(m_pStatusLabel));
2933 vbox.pack_end(main_statusbar, FALSE, TRUE, 2);
2935 GroupDialog_constructWindow( window );
2936 g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) );
2938 if ( FloatingGroupDialog() ) {
2939 g_page_console = GroupDialog_addPage( "Console", Console_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Console" ) );
2943 if ( g_multimon_globals.m_bStartOnPrimMon ) {
2944 PositionWindowOnPrimaryScreen( g_layout_globals.m_position );
2945 window_set_position( window, g_layout_globals.m_position );
2949 if ( g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED ) {
2950 gtk_window_maximize( window );
2951 WindowPosition default_position( -1, -1, 640, 480 );
2952 window_set_position( window, default_position );
2956 window_set_position( window, g_layout_globals.m_position );
2963 if ( CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft ) {
2965 ui::Widget vsplit = ui::VPaned(ui::New);
2967 vbox.pack_start( vsplit, TRUE, TRUE, 0 );
2971 ui::Widget console_window = Console_constructWindow( window );
2972 gtk_paned_pack2( GTK_PANED( vsplit ), console_window, FALSE, TRUE );
2975 ui::Widget hsplit = ui::HPaned(ui::New);
2978 gtk_paned_add1( GTK_PANED( vsplit ), hsplit );
2981 m_pXYWnd = new XYWnd();
2982 m_pXYWnd->SetViewType( XY );
2983 ui::Widget xy_window = ui::Widget(create_framed_widget( m_pXYWnd->GetWidget( ) ));
2986 ui::Widget vsplit2 = ui::VPaned(ui::New);
2988 m_vSplit2 = vsplit2;
2990 if ( CurrentStyle() == eRegular ) {
2991 gtk_paned_add1( GTK_PANED( hsplit ), xy_window );
2992 gtk_paned_add2( GTK_PANED( hsplit ), vsplit2 );
2996 gtk_paned_add1( GTK_PANED( hsplit ), vsplit2 );
2997 gtk_paned_add2( GTK_PANED( hsplit ), xy_window );
3002 m_pCamWnd = NewCamWnd();
3003 GlobalCamera_setCamWnd( *m_pCamWnd );
3004 CamWnd_setParent( *m_pCamWnd, window );
3005 auto camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3007 gtk_paned_add1( GTK_PANED( vsplit2 ), camera_window );
3010 auto texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
3012 gtk_paned_add2( GTK_PANED( vsplit2 ), texture_window );
3017 gtk_paned_set_position( GTK_PANED( m_vSplit ), g_layout_globals.nXYHeight );
3019 if ( CurrentStyle() == eRegular ) {
3020 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nXYWidth );
3024 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nCamWidth );
3027 gtk_paned_set_position( GTK_PANED( m_vSplit2 ), g_layout_globals.nCamHeight );
3029 else if ( CurrentStyle() == eFloating ) {
3031 ui::Window window = ui::Window(create_persistent_floating_window( "Camera", m_window ));
3032 global_accel_connect_window( window );
3033 g_posCamWnd.connect( window );
3037 m_pCamWnd = NewCamWnd();
3038 GlobalCamera_setCamWnd( *m_pCamWnd );
3041 auto frame = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
3044 CamWnd_setParent( *m_pCamWnd, window );
3046 g_floating_windows.push_back( window );
3050 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XY ), m_window ));
3051 global_accel_connect_window( window );
3052 g_posXYWnd.connect( window );
3054 m_pXYWnd = new XYWnd();
3055 m_pXYWnd->m_parent = window;
3056 m_pXYWnd->SetViewType( XY );
3060 auto frame = create_framed_widget( m_pXYWnd->GetWidget() );
3063 XY_Top_Shown_Construct( window );
3065 g_floating_windows.push_back( window );
3069 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XZ ), m_window ));
3070 global_accel_connect_window( window );
3071 g_posXZWnd.connect( window );
3073 m_pXZWnd = new XYWnd();
3074 m_pXZWnd->m_parent = window;
3075 m_pXZWnd->SetViewType( XZ );
3078 auto frame = create_framed_widget( m_pXZWnd->GetWidget() );
3082 XZ_Front_Shown_Construct( window );
3084 g_floating_windows.push_back( window );
3088 ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( YZ ), m_window ));
3089 global_accel_connect_window( window );
3090 g_posYZWnd.connect( window );
3092 m_pYZWnd = new XYWnd();
3093 m_pYZWnd->m_parent = window;
3094 m_pYZWnd->SetViewType( YZ );
3097 auto frame = create_framed_widget( m_pYZWnd->GetWidget() );
3101 YZ_Side_Shown_Construct( window );
3103 g_floating_windows.push_back( window );
3107 auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
3108 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3115 m_pCamWnd = NewCamWnd();
3116 GlobalCamera_setCamWnd( *m_pCamWnd );
3117 CamWnd_setParent( *m_pCamWnd, window );
3119 ui::Widget camera = CamWnd_getWidget( *m_pCamWnd );
3121 m_pYZWnd = new XYWnd();
3122 m_pYZWnd->SetViewType( YZ );
3124 ui::Widget yz = m_pYZWnd->GetWidget();
3126 m_pXYWnd = new XYWnd();
3127 m_pXYWnd->SetViewType( XY );
3129 ui::Widget xy = m_pXYWnd->GetWidget();
3131 m_pXZWnd = new XYWnd();
3132 m_pXZWnd->SetViewType( XZ );
3134 ui::Widget xz = m_pXZWnd->GetWidget();
3136 auto split = create_split_views( camera, yz, xy, xz );
3137 vbox.pack_start( split, TRUE, TRUE, 0 );
3140 auto frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
3141 g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
3145 EntityList_constructWindow( window );
3146 PreferencesDialog_constructWindow( window );
3147 FindTextureDialog_constructWindow( window );
3148 SurfaceInspector_constructWindow( window );
3149 PatchInspector_constructWindow( window );
3151 SetActiveXY( m_pXYWnd );
3153 AddGridChangeCallback( SetGridStatusCaller( *this ) );
3154 AddGridChangeCallback( ReferenceCaller<MainFrame, void(), XY_UpdateAllWindows>( *this ) );
3156 g_defaultToolMode = DragMode;
3157 g_defaultToolMode();
3158 SetStatusText( m_command_status, c_TranslateMode_status );
3160 EverySecondTimer_enable();
3162 //GlobalShortcuts_reportUnregistered();
3165 void MainFrame::SaveWindowInfo(){
3166 if ( !FloatingGroupDialog() ) {
3167 g_layout_globals.nXYHeight = gtk_paned_get_position( GTK_PANED( m_vSplit ) );
3169 if ( CurrentStyle() != eRegular ) {
3170 g_layout_globals.nCamWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3174 g_layout_globals.nXYWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3177 g_layout_globals.nCamHeight = gtk_paned_get_position( GTK_PANED( m_vSplit2 ) );
3180 g_layout_globals.m_position = m_position_tracker.getPosition();
3182 g_layout_globals.nState = gdk_window_get_state( gtk_widget_get_window(m_window ) );
3185 void MainFrame::Shutdown(){
3186 EverySecondTimer_disable();
3188 EntityList_destroyWindow();
3197 TextureBrowser_destroyWindow();
3199 DeleteCamWnd( m_pCamWnd );
3202 PreferencesDialog_destroyWindow();
3203 SurfaceInspector_destroyWindow();
3204 FindTextureDialog_destroyWindow();
3205 PatchInspector_destroyWindow();
3207 g_DbgDlg.destroyWindow();
3209 // destroying group-dialog last because it may contain texture-browser
3210 GroupDialog_destroyWindow();
3213 void MainFrame::RedrawStatusText(){
3214 ui::Label::from(m_pStatusLabel[c_command_status]).text(m_command_status.c_str());
3215 ui::Label::from(m_pStatusLabel[c_position_status]).text(m_position_status.c_str());
3216 ui::Label::from(m_pStatusLabel[c_brushcount_status]).text(m_brushcount_status.c_str());
3217 ui::Label::from(m_pStatusLabel[c_texture_status]).text(m_texture_status.c_str());
3218 ui::Label::from(m_pStatusLabel[c_grid_status]).text(m_grid_status.c_str());
3221 void MainFrame::UpdateStatusText(){
3222 m_idleRedrawStatusText.queueDraw();
3225 void MainFrame::SetStatusText( CopiedString& status_text, const char* pText ){
3226 status_text = pText;
3230 void Sys_Status( const char* status ){
3231 if ( g_pParentWnd != 0 ) {
3232 g_pParentWnd->SetStatusText( g_pParentWnd->m_command_status, status );
3236 int getRotateIncrement(){
3237 return static_cast<int>( g_si_globals.rotate );
3240 int getFarClipDistance(){
3241 return g_camwindow_globals.m_nCubicScale;
3244 float ( *GridStatus_getGridSize )() = GetGridSize;
3246 int ( *GridStatus_getRotateIncrement )() = getRotateIncrement;
3248 int ( *GridStatus_getFarClipDistance )() = getFarClipDistance;
3250 bool ( *GridStatus_getTextureLockEnabled )();
3252 void MainFrame::SetGridStatus(){
3253 StringOutputStream status( 64 );
3254 const char* lock = ( GridStatus_getTextureLockEnabled() ) ? "ON" : "OFF";
3255 status << ( GetSnapGridSize() > 0 ? "G:" : "g:" ) << GridStatus_getGridSize()
3256 << " R:" << GridStatus_getRotateIncrement()
3257 << " C:" << GridStatus_getFarClipDistance()
3259 SetStatusText( m_grid_status, status.c_str() );
3262 void GridStatus_onTextureLockEnabledChanged(){
3263 if ( g_pParentWnd != 0 ) {
3264 g_pParentWnd->SetGridStatus();
3268 void GlobalGL_sharedContextCreated(){
3269 GLFont *g_font = NULL;
3271 // report OpenGL information
3272 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) << "\n";
3273 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) << "\n";
3274 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) << "\n";
3275 const auto extensions = reinterpret_cast<const char*>( glGetString(GL_EXTENSIONS ) );
3276 globalOutputStream() << "GL_EXTENSIONS: " << (extensions ? extensions : "") << "\n";
3278 QGL_sharedContextCreated( GlobalOpenGL() );
3280 ShaderCache_extensionsInitialised();
3282 GlobalShaderCache().realise();
3286 /* win32 is dodgy here, just use courier new then */
3287 g_font = glfont_create( "arial 9" );
3289 auto settings = gtk_settings_get_default();
3291 g_object_get( settings, "gtk-font-name", &fontname, NULL );
3292 g_font = glfont_create( fontname );
3295 GlobalOpenGL().m_font = g_font;
3298 void GlobalGL_sharedContextDestroyed(){
3299 Textures_Unrealise();
3300 GlobalShaderCache().unrealise();
3302 QGL_sharedContextDestroyed( GlobalOpenGL() );
3306 void Layout_constructPreferences( PreferencesPage& page ){
3308 const char* layouts[] = { "window1.png", "window2.png", "window3.png", "window4.png" };
3309 page.appendRadioIcons(
3311 STRING_ARRAY_RANGE( layouts ),
3312 make_property( g_Layout_viewStyle )
3315 page.appendCheckBox(
3316 "", "Detachable Menus",
3317 make_property( g_Layout_enableDetachableMenus )
3319 if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) {
3320 page.appendCheckBox(
3321 "", "Patch Toolbar",
3322 make_property( g_Layout_enablePatchToolbar )
3325 page.appendCheckBox(
3326 "", "Plugin Toolbar",
3327 make_property( g_Layout_enablePluginToolbar )
3331 void Layout_constructPage( PreferenceGroup& group ){
3332 PreferencesPage page( group.createPage( "Layout", "Layout Preferences" ) );
3333 Layout_constructPreferences( page );
3336 void Layout_registerPreferencesPage(){
3337 PreferencesDialog_addInterfacePage( makeCallbackF(Layout_constructPage) );
3341 #include "preferencesystem.h"
3342 #include "stringio.h"
3344 void MainFrame_Construct(){
3345 GlobalCommands_insert( "OpenManual", makeCallbackF(OpenHelpURL), Accelerator( GDK_KEY_F1 ) );
3347 GlobalCommands_insert( "Sleep", makeCallbackF(thunk_OnSleep), Accelerator( 'P', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3348 GlobalCommands_insert( "NewMap", makeCallbackF(NewMap) );
3349 GlobalCommands_insert( "OpenMap", makeCallbackF(OpenMap), Accelerator( 'O', (GdkModifierType)GDK_CONTROL_MASK ) );
3350 GlobalCommands_insert( "ImportMap", makeCallbackF(ImportMap) );
3351 GlobalCommands_insert( "SaveMap", makeCallbackF(SaveMap), Accelerator( 'S', (GdkModifierType)GDK_CONTROL_MASK ) );
3352 GlobalCommands_insert( "SaveMapAs", makeCallbackF(SaveMapAs) );
3353 GlobalCommands_insert( "ExportSelected", makeCallbackF(ExportMap) );
3354 GlobalCommands_insert( "SaveRegion", makeCallbackF(SaveRegion) );
3355 GlobalCommands_insert( "RefreshReferences", makeCallbackF(VFS_Refresh) );
3356 GlobalCommands_insert( "ProjectSettings", makeCallbackF(DoProjectSettings) );
3357 GlobalCommands_insert( "Exit", makeCallbackF(Exit) );
3359 GlobalCommands_insert( "Undo", makeCallbackF(Undo), Accelerator( 'Z', (GdkModifierType)GDK_CONTROL_MASK ) );
3360 GlobalCommands_insert( "Redo", makeCallbackF(Redo), Accelerator( 'Y', (GdkModifierType)GDK_CONTROL_MASK ) );
3361 GlobalCommands_insert( "Copy", makeCallbackF(Copy), Accelerator( 'C', (GdkModifierType)GDK_CONTROL_MASK ) );
3362 GlobalCommands_insert( "Paste", makeCallbackF(Paste), Accelerator( 'V', (GdkModifierType)GDK_CONTROL_MASK ) );
3363 GlobalCommands_insert( "PasteToCamera", makeCallbackF(PasteToCamera), Accelerator( 'V', (GdkModifierType)GDK_MOD1_MASK ) );
3364 GlobalCommands_insert( "CloneSelection", makeCallbackF(Selection_Clone), Accelerator( GDK_KEY_space ) );
3365 GlobalCommands_insert( "CloneSelectionAndMakeUnique", makeCallbackF(Selection_Clone_MakeUnique), Accelerator( GDK_KEY_space, (GdkModifierType)GDK_SHIFT_MASK ) );
3366 GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) );
3367 GlobalCommands_insert( "ParentSelection", makeCallbackF(Scene_parentSelected) );
3368 GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) );
3369 GlobalCommands_insert( "InvertSelection", makeCallbackF(Select_Invert), Accelerator( 'I' ) );
3370 GlobalCommands_insert( "SelectInside", makeCallbackF(Select_Inside) );
3371 GlobalCommands_insert( "SelectTouching", makeCallbackF(Select_Touching) );
3372 GlobalCommands_insert( "ExpandSelectionToEntities", makeCallbackF(Scene_ExpandSelectionToEntities), Accelerator( 'E', (GdkModifierType)( GDK_MOD1_MASK | GDK_CONTROL_MASK ) ) );
3373 GlobalCommands_insert( "Preferences", makeCallbackF(PreferencesDialog_showDialog), Accelerator( 'P' ) );
3375 GlobalCommands_insert( "ToggleConsole", makeCallbackF(Console_ToggleShow), Accelerator( 'O' ) );
3376 GlobalCommands_insert( "ToggleEntityInspector", makeCallbackF(EntityInspector_ToggleShow), Accelerator( 'N' ) );
3377 GlobalCommands_insert( "EntityList", makeCallbackF(EntityList_toggleShown), Accelerator( 'L' ) );
3379 GlobalCommands_insert( "ShowHidden", makeCallbackF(Select_ShowAllHidden), Accelerator( 'H', (GdkModifierType)GDK_SHIFT_MASK ) );
3380 GlobalCommands_insert( "HideSelected", makeCallbackF(HideSelected), Accelerator( 'H' ) );
3382 GlobalToggles_insert( "DragVertices", makeCallbackF(SelectVertexMode), ToggleItem::AddCallbackCaller( g_vertexMode_button ), Accelerator( 'V' ) );
3383 GlobalToggles_insert( "DragEdges", makeCallbackF(SelectEdgeMode), ToggleItem::AddCallbackCaller( g_edgeMode_button ), Accelerator( 'E' ) );
3384 GlobalToggles_insert( "DragFaces", makeCallbackF(SelectFaceMode), ToggleItem::AddCallbackCaller( g_faceMode_button ), Accelerator( 'F' ) );
3386 GlobalCommands_insert( "MirrorSelectionX", makeCallbackF(Selection_Flipx) );
3387 GlobalCommands_insert( "RotateSelectionX", makeCallbackF(Selection_Rotatex) );
3388 GlobalCommands_insert( "MirrorSelectionY", makeCallbackF(Selection_Flipy) );
3389 GlobalCommands_insert( "RotateSelectionY", makeCallbackF(Selection_Rotatey) );
3390 GlobalCommands_insert( "MirrorSelectionZ", makeCallbackF(Selection_Flipz) );
3391 GlobalCommands_insert( "RotateSelectionZ", makeCallbackF(Selection_Rotatez) );
3393 GlobalCommands_insert( "ArbitraryRotation", makeCallbackF(DoRotateDlg) );
3394 GlobalCommands_insert( "ArbitraryScale", makeCallbackF(DoScaleDlg) );
3396 GlobalCommands_insert( "BuildMenuCustomize", makeCallbackF(DoBuildMenu) );
3398 GlobalCommands_insert( "FindBrush", makeCallbackF(DoFind) );
3400 GlobalCommands_insert( "MapInfo", makeCallbackF(DoMapInfo), Accelerator( 'M' ) );
3403 GlobalToggles_insert( "ToggleClipper", makeCallbackF(ClipperMode), ToggleItem::AddCallbackCaller( g_clipper_button ), Accelerator( 'X' ) );
3405 GlobalToggles_insert( "MouseTranslate", makeCallbackF(TranslateMode), ToggleItem::AddCallbackCaller( g_translatemode_button ), Accelerator( 'W' ) );
3406 GlobalToggles_insert( "MouseRotate", makeCallbackF(RotateMode), ToggleItem::AddCallbackCaller( g_rotatemode_button ), Accelerator( 'R' ) );
3407 GlobalToggles_insert( "MouseScale", makeCallbackF(ScaleMode), ToggleItem::AddCallbackCaller( g_scalemode_button ) );
3408 GlobalToggles_insert( "MouseDrag", makeCallbackF(DragMode), ToggleItem::AddCallbackCaller( g_dragmode_button ), Accelerator( 'Q' ) );
3410 GlobalCommands_insert( "ColorSchemeOriginal", makeCallbackF(ColorScheme_Original) );
3411 GlobalCommands_insert( "ColorSchemeQER", makeCallbackF(ColorScheme_QER) );
3412 GlobalCommands_insert( "ColorSchemeBlackAndGreen", makeCallbackF(ColorScheme_Black) );
3413 GlobalCommands_insert( "ColorSchemeYdnar", makeCallbackF(ColorScheme_Ydnar) );
3414 GlobalCommands_insert( "ChooseTextureBackgroundColor", makeCallback( g_ColoursMenu.m_textureback ) );
3415 GlobalCommands_insert( "ChooseGridBackgroundColor", makeCallback( g_ColoursMenu.m_xyback ) );
3416 GlobalCommands_insert( "ChooseGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor ) );
3417 GlobalCommands_insert( "ChooseGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor ) );
3418 GlobalCommands_insert( "ChooseSmallGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor_alt ) );
3419 GlobalCommands_insert( "ChooseSmallGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor_alt ) );
3420 GlobalCommands_insert( "ChooseGridTextColor", makeCallback( g_ColoursMenu.m_gridtext ) );
3421 GlobalCommands_insert( "ChooseGridBlockColor", makeCallback( g_ColoursMenu.m_gridblock ) );
3422 GlobalCommands_insert( "ChooseBrushColor", makeCallback( g_ColoursMenu.m_brush ) );
3423 GlobalCommands_insert( "ChooseCameraBackgroundColor", makeCallback( g_ColoursMenu.m_cameraback ) );
3424 GlobalCommands_insert( "ChooseSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush ) );
3425 GlobalCommands_insert( "ChooseCameraSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush3d ) );
3426 GlobalCommands_insert( "ChooseClipperColor", makeCallback( g_ColoursMenu.m_clipper ) );
3427 GlobalCommands_insert( "ChooseOrthoViewNameColor", makeCallback( g_ColoursMenu.m_viewname ) );
3430 GlobalCommands_insert( "CSGSubtract", makeCallbackF(CSG_Subtract), Accelerator( 'U', (GdkModifierType)GDK_SHIFT_MASK ) );
3431 GlobalCommands_insert( "CSGMerge", makeCallbackF(CSG_Merge), Accelerator( 'U', (GdkModifierType) GDK_CONTROL_MASK ) );
3432 GlobalCommands_insert( "CSGMakeHollow", makeCallbackF(CSG_MakeHollow) );
3433 GlobalCommands_insert( "CSGMakeRoom", makeCallbackF(CSG_MakeRoom) );
3435 Grid_registerCommands();
3437 GlobalCommands_insert( "SnapToGrid", makeCallbackF(Selection_SnapToGrid), Accelerator( 'G', (GdkModifierType)GDK_CONTROL_MASK ) );
3439 GlobalCommands_insert( "SelectAllOfType", makeCallbackF(Select_AllOfType), Accelerator( 'A', (GdkModifierType)GDK_SHIFT_MASK ) );
3441 GlobalCommands_insert( "TexRotateClock", makeCallbackF(Texdef_RotateClockwise), Accelerator( GDK_KEY_Next, (GdkModifierType)GDK_SHIFT_MASK ) );
3442 GlobalCommands_insert( "TexRotateCounter", makeCallbackF(Texdef_RotateAntiClockwise), Accelerator( GDK_KEY_Prior, (GdkModifierType)GDK_SHIFT_MASK ) );
3443 GlobalCommands_insert( "TexScaleUp", makeCallbackF(Texdef_ScaleUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_CONTROL_MASK ) );
3444 GlobalCommands_insert( "TexScaleDown", makeCallbackF(Texdef_ScaleDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_CONTROL_MASK ) );
3445 GlobalCommands_insert( "TexScaleLeft", makeCallbackF(Texdef_ScaleLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_CONTROL_MASK ) );
3446 GlobalCommands_insert( "TexScaleRight", makeCallbackF(Texdef_ScaleRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_CONTROL_MASK ) );
3447 GlobalCommands_insert( "TexShiftUp", makeCallbackF(Texdef_ShiftUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_SHIFT_MASK ) );
3448 GlobalCommands_insert( "TexShiftDown", makeCallbackF(Texdef_ShiftDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_SHIFT_MASK ) );
3449 GlobalCommands_insert( "TexShiftLeft", makeCallbackF(Texdef_ShiftLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_SHIFT_MASK ) );
3450 GlobalCommands_insert( "TexShiftRight", makeCallbackF(Texdef_ShiftRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_SHIFT_MASK ) );
3452 GlobalCommands_insert( "MoveSelectionDOWN", makeCallbackF(Selection_MoveDown), Accelerator( GDK_KEY_KP_Subtract ) );
3453 GlobalCommands_insert( "MoveSelectionUP", makeCallbackF(Selection_MoveUp), Accelerator( GDK_KEY_KP_Add ) );
3455 GlobalCommands_insert( "SelectNudgeLeft", makeCallbackF(Selection_NudgeLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_MOD1_MASK ) );
3456 GlobalCommands_insert( "SelectNudgeRight", makeCallbackF(Selection_NudgeRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_MOD1_MASK ) );
3457 GlobalCommands_insert( "SelectNudgeUp", makeCallbackF(Selection_NudgeUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_MOD1_MASK ) );
3458 GlobalCommands_insert( "SelectNudgeDown", makeCallbackF(Selection_NudgeDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_MOD1_MASK ) );
3460 Patch_registerCommands();
3461 XYShow_registerCommands();
3463 typedef FreeCaller<void(const Selectable&), ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3464 GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() );
3466 GlobalPreferenceSystem().registerPreference( "DetachableMenus", make_property_string( g_Layout_enableDetachableMenus.m_latched ) );
3467 GlobalPreferenceSystem().registerPreference( "PatchToolBar", make_property_string( g_Layout_enablePatchToolbar.m_latched ) );
3468 GlobalPreferenceSystem().registerPreference( "PluginToolBar", make_property_string( g_Layout_enablePluginToolbar.m_latched ) );
3469 GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", make_property_string( g_Layout_viewStyle.m_latched ) );
3470 GlobalPreferenceSystem().registerPreference( "XYHeight", make_property_string( g_layout_globals.nXYHeight ) );
3471 GlobalPreferenceSystem().registerPreference( "XYWidth", make_property_string( g_layout_globals.nXYWidth ) );
3472 GlobalPreferenceSystem().registerPreference( "CamWidth", make_property_string( g_layout_globals.nCamWidth ) );
3473 GlobalPreferenceSystem().registerPreference( "CamHeight", make_property_string( g_layout_globals.nCamHeight ) );
3475 GlobalPreferenceSystem().registerPreference( "State", make_property_string( g_layout_globals.nState ) );
3476 GlobalPreferenceSystem().registerPreference( "PositionX", make_property_string( g_layout_globals.m_position.x ) );
3477 GlobalPreferenceSystem().registerPreference( "PositionY", make_property_string( g_layout_globals.m_position.y ) );
3478 GlobalPreferenceSystem().registerPreference( "Width", make_property_string( g_layout_globals.m_position.w ) );
3479 GlobalPreferenceSystem().registerPreference( "Height", make_property_string( g_layout_globals.m_position.h ) );
3481 GlobalPreferenceSystem().registerPreference( "CamWnd", make_property<WindowPositionTracker_String>(g_posCamWnd) );
3482 GlobalPreferenceSystem().registerPreference( "XYWnd", make_property<WindowPositionTracker_String>(g_posXYWnd) );
3483 GlobalPreferenceSystem().registerPreference( "YZWnd", make_property<WindowPositionTracker_String>(g_posYZWnd) );
3484 GlobalPreferenceSystem().registerPreference( "XZWnd", make_property<WindowPositionTracker_String>(g_posXZWnd) );
3487 const char* ENGINEPATH_ATTRIBUTE =
3492 #elif GDEF_OS_LINUX || GDEF_OS_BSD
3495 #error "unknown platform"
3498 StringOutputStream path( 256 );
3499 path << DirectoryCleaned( g_pGameDescription->getRequiredKeyValue( ENGINEPATH_ATTRIBUTE ) );
3500 g_strEnginePath = path.c_str();
3503 GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) );
3505 GlobalPreferenceSystem().registerPreference( "DisableEnginePath", make_property_string( g_disableEnginePath ) );
3506 GlobalPreferenceSystem().registerPreference( "DisableHomePath", make_property_string( g_disableHomePath ) );
3508 for ( int i = 0; i < g_pakPathCount; i++ ) {
3509 std::string label = "PakPath" + std::to_string( i );
3510 GlobalPreferenceSystem().registerPreference( label.c_str(), make_property_string( g_strPakPath[i] ) );
3513 g_Layout_viewStyle.useLatched();
3514 g_Layout_enableDetachableMenus.useLatched();
3515 g_Layout_enablePatchToolbar.useLatched();
3516 g_Layout_enablePluginToolbar.useLatched();
3518 Layout_registerPreferencesPage();
3519 Paths_registerPreferencesPage();
3521 g_brushCount.setCountChangedCallback( makeCallbackF(QE_brushCountChanged) );
3522 g_entityCount.setCountChangedCallback( makeCallbackF(QE_entityCountChanged) );
3523 GlobalEntityCreator().setCounter( &g_entityCount );
3525 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3526 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3528 GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver );
3531 void MainFrame_Destroy(){
3532 GlobalEntityClassManager().detach( g_WorldspawnColourEntityClassObserver );
3534 GlobalEntityCreator().setCounter( 0 );
3535 g_entityCount.setCountChangedCallback( Callback<void()>() );
3536 g_brushCount.setCountChangedCallback( Callback<void()>() );
3540 void GLWindow_Construct(){
3541 GlobalPreferenceSystem().registerPreference( "MouseButtons", make_property_string( g_glwindow_globals.m_nMouseType ) );
3544 void GLWindow_Destroy(){