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"
30 #include "debugging/debugging.h"
33 #include "ifilesystem.h"
41 #include "moduleobserver.h"
45 #include <gdk/gdkkeysyms.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtkvbox.h>
48 #include <gtk/gtkframe.h>
49 #include <gtk/gtklabel.h>
50 #include <gtk/gtkhpaned.h>
51 #include <gtk/gtkvpaned.h>
52 #include <gtk/gtktoolbar.h>
53 #include <gtk/gtkmenubar.h>
54 #include <gtk/gtkimage.h>
55 #include <gtk/gtktable.h>
60 #include "stream/stringstream.h"
61 #include "signal/isignal.h"
64 #include "eclasslib.h"
65 #include "moduleobservers.h"
67 #include "gtkutil/clipboard.h"
68 #include "gtkutil/container.h"
69 #include "gtkutil/frame.h"
70 #include "gtkutil/glfont.h"
71 #include "gtkutil/glwidget.h"
72 #include "gtkutil/image.h"
73 #include "gtkutil/menu.h"
74 #include "gtkutil/paned.h"
75 #include "gtkutil/widget.h"
79 #include "brushmanip.h"
80 #include "brushmodule.h"
81 #include "camwindow.h"
86 #include "entityinspector.h"
87 #include "entitylist.h"
89 #include "findtexturedialog.h"
91 #include "groupdialog.h"
98 #include "patchdialog.h"
99 #include "patchmanip.h"
101 #include "pluginmanager.h"
102 #include "pluginmenu.h"
103 #include "plugintoolbar.h"
105 #include "preferences.h"
110 #include "surfacedialog.h"
111 #include "textures.h"
112 #include "texwindow.h"
114 #include "xywindow.h"
115 #include "windowobservers.h"
116 #include "renderstate.h"
117 #include "feedback.h"
118 #include "referencecache.h"
122 struct layout_globals_t
124 WindowPosition m_position;
134 m_position( -1, -1, 640, 480 ),
140 nState( GDK_WINDOW_STATE_MAXIMIZED ){
144 layout_globals_t g_layout_globals;
145 glwindow_globals_t g_glwindow_globals;
150 bool g_vfsInitialized = false;
153 if ( g_vfsInitialized ) return;
155 GlobalFileSystem().initialise();
156 g_vfsInitialized = true;
159 if ( !g_vfsInitialized ) return;
160 GlobalFileSystem().shutdown();
161 g_vfsInitialized = false;
168 class VFSModuleObserver : public ModuleObserver
179 VFSModuleObserver g_VFSModuleObserver;
181 void VFS_Construct(){
182 Radiant_attachHomePathsObserver( g_VFSModuleObserver );
185 Radiant_detachHomePathsObserver( g_VFSModuleObserver );
193 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
194 #define qREFKNOWNFOLDERID GUID
195 #define qKF_FLAG_CREATE 0x8000
196 #define qKF_FLAG_NO_ALIAS 0x1000
197 typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath );
198 static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath;
200 void HomePaths_Realise(){
203 const char* prefix = g_pGameDescription->getKeyValue( "prefix" );
204 if ( !string_empty( prefix ) ) {
205 StringOutputStream path( 256 );
207 #if defined( __APPLE__ )
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 ){
297 if ( --m_unrealised == 0 ) {
299 g_homePathObservers.realise();
303 if ( ++m_unrealised == 1 ) {
304 g_homePathObservers.unrealise();
309 HomePathsModuleObserver g_HomePathsModuleObserver;
311 void HomePaths_Construct(){
312 Radiant_attachEnginePathObserver( g_HomePathsModuleObserver );
314 void HomePaths_Destroy(){
315 Radiant_detachEnginePathObserver( g_HomePathsModuleObserver );
321 CopiedString g_strEnginePath;
322 ModuleObservers g_enginePathObservers;
323 std::size_t g_enginepath_unrealised = 1;
325 void Radiant_attachEnginePathObserver( ModuleObserver& observer ){
326 g_enginePathObservers.attach( observer );
329 void Radiant_detachEnginePathObserver( ModuleObserver& observer ){
330 g_enginePathObservers.detach( observer );
334 void EnginePath_Realise(){
335 if ( --g_enginepath_unrealised == 0 ) {
336 g_enginePathObservers.realise();
341 const char* EnginePath_get(){
342 ASSERT_MESSAGE( g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised" );
343 return g_strEnginePath.c_str();
346 void EnginePath_Unrealise(){
347 if ( ++g_enginepath_unrealised == 1 ) {
348 g_enginePathObservers.unrealise();
352 void setEnginePath( const char* path ){
353 StringOutputStream buffer( 256 );
354 buffer << DirectoryCleaned( path );
355 if ( !path_equal( buffer.c_str(), g_strEnginePath.c_str() ) ) {
357 while ( !ConfirmModified( "Paths Changed" ) )
359 if ( Map_Unnamed( g_map ) ) {
370 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Changing Engine Path" );
372 EnginePath_Unrealise();
374 g_strEnginePath = buffer.c_str();
376 EnginePath_Realise();
383 CopiedString g_strAppPath; ///< holds the full path of the executable
385 const char* AppPath_get(){
386 return g_strAppPath.c_str();
389 /// the path to the local rc-dir
390 const char* LocalRcPath_get( void ){
391 static CopiedString rc_path;
392 if ( rc_path.empty() ) {
393 StringOutputStream stream( 256 );
394 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
395 rc_path = stream.c_str();
397 return rc_path.c_str();
400 /// directory for temp files
401 /// NOTE: on *nix this is were we check for .pid
402 CopiedString g_strSettingsPath;
403 const char* SettingsPath_get(){
404 return g_strSettingsPath.c_str();
409 points to the game tools directory, for instance
410 C:/Program Files/Quake III Arena/GtkRadiant
412 this is one of the main variables that are configured by the game selection on startup
413 [GameToolsPath]/plugins
414 [GameToolsPath]/modules
417 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
419 const char* GameToolsPath_get(){
420 return g_strGameToolsPath.c_str();
423 void EnginePathImport( CopiedString& self, const char* value ){
424 setEnginePath( value );
426 typedef ReferenceCaller1<CopiedString, const char*, EnginePathImport> EnginePathImportCaller;
428 void Paths_constructPreferences( PreferencesPage& page ){
429 page.appendPathEntry( "Engine Path", true,
430 StringImportCallback( EnginePathImportCaller( g_strEnginePath ) ),
431 StringExportCallback( StringExportCaller( g_strEnginePath ) )
434 void Paths_constructPage( PreferenceGroup& group ){
435 PreferencesPage page( group.createPage( "Paths", "Path Settings" ) );
436 Paths_constructPreferences( page );
438 void Paths_registerPreferencesPage(){
439 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Paths_constructPage>() );
443 class PathsDialog : public Dialog
446 GtkWindow* BuildDialog(){
447 GtkFrame* frame = create_dialog_frame( "Path settings", GTK_SHADOW_ETCHED_IN );
449 GtkVBox* vbox2 = create_dialog_vbox( 0, 4 );
450 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( vbox2 ) );
453 PreferencesPage preferencesPage( *this, GTK_WIDGET( vbox2 ) );
454 Paths_constructPreferences( preferencesPage );
457 return create_simple_modal_dialog_window( "Engine Path Not Found", m_modal, GTK_WIDGET( frame ) );
461 PathsDialog g_PathsDialog;
463 void EnginePath_verify(){
464 if ( !file_exists( g_strEnginePath.c_str() ) ) {
465 g_PathsDialog.Create();
466 g_PathsDialog.DoModal();
467 g_PathsDialog.Destroy();
473 CopiedString g_gamename;
474 CopiedString g_gamemode;
475 ModuleObservers g_gameNameObservers;
476 ModuleObservers g_gameModeObservers;
479 void Radiant_attachGameNameObserver( ModuleObserver& observer ){
480 g_gameNameObservers.attach( observer );
483 void Radiant_detachGameNameObserver( ModuleObserver& observer ){
484 g_gameNameObservers.detach( observer );
487 const char* basegame_get(){
488 return g_pGameDescription->getRequiredKeyValue( "basegame" );
491 const char* gamename_get(){
492 const char* gamename = g_gamename.c_str();
493 if ( string_empty( gamename ) ) {
494 return basegame_get();
499 void gamename_set( const char* gamename ){
500 if ( !string_equal( gamename, g_gamename.c_str() ) ) {
501 g_gameNameObservers.unrealise();
502 g_gamename = gamename;
503 g_gameNameObservers.realise();
507 void Radiant_attachGameModeObserver( ModuleObserver& observer ){
508 g_gameModeObservers.attach( observer );
511 void Radiant_detachGameModeObserver( ModuleObserver& observer ){
512 g_gameModeObservers.detach( observer );
515 const char* gamemode_get(){
516 return g_gamemode.c_str();
519 void gamemode_set( const char* gamemode ){
520 if ( !string_equal( gamemode, g_gamemode.c_str() ) ) {
521 g_gameModeObservers.unrealise();
522 g_gamemode = gamemode;
523 g_gameModeObservers.realise();
534 CLoadModule( const char* path ) : m_path( path ){
536 void operator()( const char* name ) const {
538 ASSERT_MESSAGE( strlen( m_path ) + strlen( name ) < 1024, "" );
539 strcpy( fullname, m_path );
540 strcat( fullname, name );
541 globalOutputStream() << "Found '" << fullname << "'\n";
542 GlobalModuleServer_loadModule( fullname );
546 const char* const c_library_extension =
547 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
548 CMAKE_SHARED_MODULE_SUFFIX
549 #elif defined( WIN32 )
551 #elif defined ( __APPLE__ )
553 #elif defined( __linux__ ) || defined ( __FreeBSD__ )
558 void Radiant_loadModules( const char* path ){
559 Directory_forEach( path, MatchFileExtension<CLoadModule>( c_library_extension, CLoadModule( path ) ) );
562 void Radiant_loadModulesFromRoot( const char* directory ){
564 StringOutputStream path( 256 );
565 path << directory << g_pluginsDir;
566 Radiant_loadModules( path.c_str() );
569 if ( !string_equal( g_pluginsDir, g_modulesDir ) ) {
570 StringOutputStream path( 256 );
571 path << directory << g_modulesDir;
572 Radiant_loadModules( path.c_str() );
576 //! Make COLOR_BRUSHES override worldspawn eclass colour.
577 void SetWorldspawnColour( const Vector3& colour ){
578 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert( "worldspawn", true );
579 eclass_release_state( worldspawn );
580 worldspawn->color = colour;
581 eclass_capture_state( worldspawn );
585 class WorldspawnColourEntityClassObserver : public ModuleObserver
587 std::size_t m_unrealised;
589 WorldspawnColourEntityClassObserver() : m_unrealised( 1 ){
592 if ( --m_unrealised == 0 ) {
593 SetWorldspawnColour( g_xywindow_globals.color_brushes );
597 if ( ++m_unrealised == 1 ) {
602 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
605 ModuleObservers g_gameToolsPathObservers;
607 void Radiant_attachGameToolsPathObserver( ModuleObserver& observer ){
608 g_gameToolsPathObservers.attach( observer );
611 void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ){
612 g_gameToolsPathObservers.detach( observer );
615 void Radiant_Initialise(){
616 GlobalModuleServer_Initialise();
618 Radiant_loadModulesFromRoot( AppPath_get() );
622 bool success = Radiant_Construct( GlobalModuleServer_get() );
623 ASSERT_MESSAGE( success, "module system failed to initialise - see radiant.log for error messages" );
625 g_gameToolsPathObservers.realise();
626 g_gameModeObservers.realise();
627 g_gameNameObservers.realise();
630 void Radiant_Shutdown(){
631 g_gameNameObservers.unrealise();
632 g_gameModeObservers.unrealise();
633 g_gameToolsPathObservers.unrealise();
635 if ( !g_preferences_globals.disable_ini ) {
636 globalOutputStream() << "Start writing prefs\n";
638 globalOutputStream() << "Done prefs\n";
643 GlobalModuleServer_Shutdown();
647 if ( ConfirmModified( "Exit Radiant" ) ) {
654 GlobalUndoSystem().undo();
659 GlobalUndoSystem().redo();
663 void deleteSelection(){
664 UndoableCommand undo( "deleteSelected" );
668 void Map_ExportSelected( TextOutputStream& ostream ){
669 Map_ExportSelected( ostream, Map_getFormat( g_map ) );
672 void Map_ImportSelected( TextInputStream& istream ){
673 Map_ImportSelected( istream, Map_getFormat( g_map ) );
676 void Selection_Copy(){
677 clipboard_copy( Map_ExportSelected );
680 void Selection_Paste(){
681 clipboard_paste( Map_ImportSelected );
685 if ( SelectedFaces_empty() ) {
690 SelectedFaces_copyTexture();
695 if ( SelectedFaces_empty() ) {
696 UndoableCommand undo( "paste" );
698 GlobalSelectionSystem().setSelectedAll( false );
703 SelectedFaces_pasteTexture();
707 void PasteToCamera(){
708 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
709 GlobalSelectionSystem().setSelectedAll( false );
711 UndoableCommand undo( "pasteToCamera" );
715 // Work out the delta
717 Select_GetMid( mid );
718 Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid );
721 GlobalSelectionSystem().translateSelected( delta );
725 void ColorScheme_Original(){
726 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
728 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
729 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
730 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
732 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
733 g_xywindow_globals.color_gridminor = Vector3( 0.75f, 0.75f, 0.75f );
734 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
735 g_xywindow_globals.color_gridminor_alt = Vector3( 0.5f, 0.0f, 0.0f );
736 g_xywindow_globals.color_gridmajor_alt = Vector3( 1.0f, 0.0f, 0.0f );
737 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
738 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
739 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
740 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
741 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
742 SetWorldspawnColour( g_xywindow_globals.color_brushes );
743 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
744 XY_UpdateAllWindows();
747 void ColorScheme_QER(){
748 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
750 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
751 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
752 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
754 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
755 g_xywindow_globals.color_gridminor = Vector3( 1.0f, 1.0f, 1.0f );
756 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
757 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
758 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
759 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
760 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
761 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
762 SetWorldspawnColour( g_xywindow_globals.color_brushes );
763 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
764 XY_UpdateAllWindows();
767 void ColorScheme_Black(){
768 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
770 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
771 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
772 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
774 g_xywindow_globals.color_gridback = Vector3( 0.0f, 0.0f, 0.0f );
775 g_xywindow_globals.color_gridminor = Vector3( 0.2f, 0.2f, 0.2f );
776 g_xywindow_globals.color_gridmajor = Vector3( 0.3f, 0.5f, 0.5f );
777 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
778 g_xywindow_globals.color_gridtext = Vector3( 1.0f, 1.0f, 1.0f );
779 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
780 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
781 g_xywindow_globals.color_brushes = Vector3( 1.0f, 1.0f, 1.0f );
782 SetWorldspawnColour( g_xywindow_globals.color_brushes );
783 g_xywindow_globals.color_viewname = Vector3( 0.7f, 0.7f, 0.0f );
784 XY_UpdateAllWindows();
787 /* ydnar: to emulate maya/max/lightwave color schemes */
788 void ColorScheme_Ydnar(){
789 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
791 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
792 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
793 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
795 g_xywindow_globals.color_gridback = Vector3( 0.77f, 0.77f, 0.77f );
796 g_xywindow_globals.color_gridminor = Vector3( 0.83f, 0.83f, 0.83f );
797 g_xywindow_globals.color_gridmajor = Vector3( 0.89f, 0.89f, 0.89f );
798 g_xywindow_globals.color_gridblock = Vector3( 1.0f, 1.0f, 1.0f );
799 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
800 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
801 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
802 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
803 SetWorldspawnColour( g_xywindow_globals.color_brushes );
804 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
805 XY_UpdateAllWindows();
808 typedef Callback1<Vector3&> GetColourCallback;
809 typedef Callback1<const Vector3&> SetColourCallback;
813 GetColourCallback m_get;
814 SetColourCallback m_set;
816 ChooseColour( const GetColourCallback& get, const SetColourCallback& set )
817 : m_get( get ), m_set( set ){
822 color_dialog( GTK_WIDGET( MainFrame_getWindow() ), colour );
829 void Colour_get( const Vector3& colour, Vector3& other ){
832 typedef ConstReferenceCaller1<Vector3, Vector3&, Colour_get> ColourGetCaller;
834 void Colour_set( Vector3& colour, const Vector3& other ){
838 typedef ReferenceCaller1<Vector3, const Vector3&, Colour_set> ColourSetCaller;
840 void BrushColour_set( const Vector3& other ){
841 g_xywindow_globals.color_brushes = other;
842 SetWorldspawnColour( g_xywindow_globals.color_brushes );
845 typedef FreeCaller1<const Vector3&, BrushColour_set> BrushColourSetCaller;
847 void ClipperColour_set( const Vector3& other ){
848 g_xywindow_globals.color_clipper = other;
849 Brush_clipperColourChanged();
852 typedef FreeCaller1<const Vector3&, ClipperColour_set> ClipperColourSetCaller;
854 void TextureBrowserColour_get( Vector3& other ){
855 other = TextureBrowser_getBackgroundColour( GlobalTextureBrowser() );
857 typedef FreeCaller1<Vector3&, TextureBrowserColour_get> TextureBrowserColourGetCaller;
859 void TextureBrowserColour_set( const Vector3& other ){
860 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), other );
862 typedef FreeCaller1<const Vector3&, TextureBrowserColour_set> TextureBrowserColourSetCaller;
868 ChooseColour m_textureback;
869 ChooseColour m_xyback;
870 ChooseColour m_gridmajor;
871 ChooseColour m_gridminor;
872 ChooseColour m_gridmajor_alt;
873 ChooseColour m_gridminor_alt;
874 ChooseColour m_gridtext;
875 ChooseColour m_gridblock;
876 ChooseColour m_cameraback;
877 ChooseColour m_brush;
878 ChooseColour m_selectedbrush;
879 ChooseColour m_selectedbrush3d;
880 ChooseColour m_clipper;
881 ChooseColour m_viewname;
884 m_textureback( TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller() ),
885 m_xyback( ColourGetCaller( g_xywindow_globals.color_gridback ), ColourSetCaller( g_xywindow_globals.color_gridback ) ),
886 m_gridmajor( ColourGetCaller( g_xywindow_globals.color_gridmajor ), ColourSetCaller( g_xywindow_globals.color_gridmajor ) ),
887 m_gridminor( ColourGetCaller( g_xywindow_globals.color_gridminor ), ColourSetCaller( g_xywindow_globals.color_gridminor ) ),
888 m_gridmajor_alt( ColourGetCaller( g_xywindow_globals.color_gridmajor_alt ), ColourSetCaller( g_xywindow_globals.color_gridmajor_alt ) ),
889 m_gridminor_alt( ColourGetCaller( g_xywindow_globals.color_gridminor_alt ), ColourSetCaller( g_xywindow_globals.color_gridminor_alt ) ),
890 m_gridtext( ColourGetCaller( g_xywindow_globals.color_gridtext ), ColourSetCaller( g_xywindow_globals.color_gridtext ) ),
891 m_gridblock( ColourGetCaller( g_xywindow_globals.color_gridblock ), ColourSetCaller( g_xywindow_globals.color_gridblock ) ),
892 m_cameraback( ColourGetCaller( g_camwindow_globals.color_cameraback ), ColourSetCaller( g_camwindow_globals.color_cameraback ) ),
893 m_brush( ColourGetCaller( g_xywindow_globals.color_brushes ), BrushColourSetCaller() ),
894 m_selectedbrush( ColourGetCaller( g_xywindow_globals.color_selbrushes ), ColourSetCaller( g_xywindow_globals.color_selbrushes ) ),
895 m_selectedbrush3d( ColourGetCaller( g_camwindow_globals.color_selbrushes3d ), ColourSetCaller( g_camwindow_globals.color_selbrushes3d ) ),
896 m_clipper( ColourGetCaller( g_xywindow_globals.color_clipper ), ClipperColourSetCaller() ),
897 m_viewname( ColourGetCaller( g_xywindow_globals.color_viewname ), ColourSetCaller( g_xywindow_globals.color_viewname ) ){
901 ColoursMenu g_ColoursMenu;
903 GtkMenuItem* create_colours_menu(){
904 GtkMenuItem* colours_menu_item = new_sub_menu_item_with_mnemonic( "Colors" );
905 GtkMenu* menu_in_menu = GTK_MENU( gtk_menu_item_get_submenu( colours_menu_item ) );
906 if ( g_Layout_enableDetachableMenus.m_value ) {
907 menu_tearoff( menu_in_menu );
910 GtkMenu* menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Themes" );
911 if ( g_Layout_enableDetachableMenus.m_value ) {
912 menu_tearoff( menu_3 );
915 create_menu_item_with_mnemonic( menu_3, "QE4 Original", "ColorSchemeOriginal" );
916 create_menu_item_with_mnemonic( menu_3, "Q3Radiant Original", "ColorSchemeQER" );
917 create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" );
918 create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" );
920 menu_separator( menu_in_menu );
922 create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" );
923 create_menu_item_with_mnemonic( menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor" );
924 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major...", "ChooseGridMajorColor" );
925 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor...", "ChooseGridMinorColor" );
926 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor" );
927 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor" );
928 create_menu_item_with_mnemonic( menu_in_menu, "Grid Text...", "ChooseGridTextColor" );
929 create_menu_item_with_mnemonic( menu_in_menu, "Grid Block...", "ChooseGridBlockColor" );
930 create_menu_item_with_mnemonic( menu_in_menu, "Default Brush...", "ChooseBrushColor" );
931 create_menu_item_with_mnemonic( menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor" );
932 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor" );
933 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor" );
934 create_menu_item_with_mnemonic( menu_in_menu, "Clipper...", "ChooseClipperColor" );
935 create_menu_item_with_mnemonic( menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor" );
937 return colours_menu_item;
943 PluginToolbar_clear();
946 Radiant_Initialise();
948 PluginsMenu_populate();
950 PluginToolbar_populate();
954 void thunk_OnSleep(){
955 g_pParentWnd->OnSleep();
958 void OpenUpdateURL(){
959 OpenURL( "https://gitlab.com/xonotic/netradiant/tags" );
962 // open the Q3Rad manual
964 OpenURL( "https://gitlab.com/xonotic/xonotic/wikis/Mapping" );
967 void OpenBugReportURL(){
968 OpenURL( "https://gitlab.com/xonotic/netradiant/issues" );
972 GtkWidget* g_page_console;
974 void Console_ToggleShow(){
975 GroupDialog_showPage( g_page_console );
978 GtkWidget* g_page_entity;
980 void EntityInspector_ToggleShow(){
981 GroupDialog_showPage( g_page_entity );
986 void SetClipMode( bool enable );
987 void ModeChangeNotify();
989 typedef void ( *ToolMode )();
990 ToolMode g_currentToolMode = 0;
991 bool g_currentToolModeSupportsComponentEditing = false;
992 ToolMode g_defaultToolMode = 0;
996 void SelectionSystem_DefaultMode(){
997 GlobalSelectionSystem().SetMode( SelectionSystem::ePrimitive );
998 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eDefault );
1004 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1005 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1009 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1010 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1014 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1015 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1018 template<bool( *BoolFunction ) ( )>
1019 class BoolFunctionExport
1022 static void apply( const BoolImportCallback& importCallback ){
1023 importCallback( BoolFunction() );
1027 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1028 EdgeModeApplyCaller g_edgeMode_button_caller;
1029 BoolExportCallback g_edgeMode_button_callback( g_edgeMode_button_caller );
1030 ToggleItem g_edgeMode_button( g_edgeMode_button_callback );
1032 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1033 VertexModeApplyCaller g_vertexMode_button_caller;
1034 BoolExportCallback g_vertexMode_button_callback( g_vertexMode_button_caller );
1035 ToggleItem g_vertexMode_button( g_vertexMode_button_callback );
1037 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1038 FaceModeApplyCaller g_faceMode_button_caller;
1039 BoolExportCallback g_faceMode_button_callback( g_faceMode_button_caller );
1040 ToggleItem g_faceMode_button( g_faceMode_button_callback );
1042 void ComponentModeChanged(){
1043 g_edgeMode_button.update();
1044 g_vertexMode_button.update();
1045 g_faceMode_button.update();
1048 void ComponentMode_SelectionChanged( const Selectable& selectable ){
1049 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1050 && GlobalSelectionSystem().countSelected() == 0 ) {
1051 SelectionSystem_DefaultMode();
1052 ComponentModeChanged();
1056 void SelectEdgeMode(){
1058 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1059 GlobalSelectionSystem().Select( false );
1064 SelectionSystem_DefaultMode();
1066 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1067 if ( !g_currentToolModeSupportsComponentEditing ) {
1068 g_defaultToolMode();
1071 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1072 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eEdge );
1075 ComponentModeChanged();
1080 void SelectVertexMode(){
1082 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1083 GlobalSelectionSystem().Select( false );
1087 if ( VertexMode() ) {
1088 SelectionSystem_DefaultMode();
1090 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1091 if ( !g_currentToolModeSupportsComponentEditing ) {
1092 g_defaultToolMode();
1095 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1096 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eVertex );
1099 ComponentModeChanged();
1104 void SelectFaceMode(){
1106 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1107 GlobalSelectionSystem().Select( false );
1112 SelectionSystem_DefaultMode();
1114 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1115 if ( !g_currentToolModeSupportsComponentEditing ) {
1116 g_defaultToolMode();
1119 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1120 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eFace );
1123 ComponentModeChanged();
1129 class CloneSelected : public scene::Graph::Walker
1132 NodeSmartReference worldspawn;
1134 CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
1136 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1137 if ( path.size() == 1 ) {
1141 // ignore worldspawn, but keep checking children
1142 NodeSmartReference me( path.top().get() );
1143 if ( me == worldspawn ) {
1147 if ( !path.top().get().isRoot() ) {
1148 Selectable* selectable = Instance_getSelectable( instance );
1149 if ( selectable != 0
1150 && selectable->isSelected() ) {
1157 void post( const scene::Path& path, scene::Instance& instance ) const {
1158 if ( path.size() == 1 ) {
1162 // ignore worldspawn, but keep checking children
1163 NodeSmartReference me( path.top().get() );
1164 if ( me == worldspawn ) {
1168 if ( !path.top().get().isRoot() ) {
1169 Selectable* selectable = Instance_getSelectable( instance );
1170 if ( selectable != 0
1171 && selectable->isSelected() ) {
1172 NodeSmartReference clone( Node_Clone( path.top() ) );
1173 if ( doMakeUnique ) {
1174 Map_gatherNamespaced( clone );
1176 Node_getTraversable( path.parent().get() )->insert( clone );
1182 void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){
1183 graph.traverse( CloneSelected( doMakeUnique ) );
1185 Map_mergeClonedNames();
1188 enum ENudgeDirection
1201 AxisBase( const Vector3& x_, const Vector3& y_, const Vector3& z_ )
1202 : x( x_ ), y( y_ ), z( z_ ){
1206 AxisBase AxisBase_forViewType( VIEWTYPE viewtype ){
1210 return AxisBase( g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z );
1212 return AxisBase( g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y );
1214 return AxisBase( g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x );
1217 ERROR_MESSAGE( "invalid viewtype" );
1218 return AxisBase( Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) );
1221 Vector3 AxisBase_axisForDirection( const AxisBase& axes, ENudgeDirection direction ){
1222 switch ( direction )
1225 return vector3_negated( axes.x );
1231 return vector3_negated( axes.y );
1234 ERROR_MESSAGE( "invalid direction" );
1235 return Vector3( 0, 0, 0 );
1238 void NudgeSelection( ENudgeDirection direction, float fAmount, VIEWTYPE viewtype ){
1239 AxisBase axes( AxisBase_forViewType( viewtype ) );
1240 Vector3 view_direction( vector3_negated( axes.z ) );
1241 Vector3 nudge( vector3_scaled( AxisBase_axisForDirection( axes, direction ), fAmount ) );
1242 GlobalSelectionSystem().NudgeManipulator( nudge, view_direction );
1245 void Selection_Clone(){
1246 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1247 UndoableCommand undo( "cloneSelected" );
1249 Scene_Clone_Selected( GlobalSceneGraph(), false );
1251 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1252 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1256 void Selection_Clone_MakeUnique(){
1257 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1258 UndoableCommand undo( "cloneSelectedMakeUnique" );
1260 Scene_Clone_Selected( GlobalSceneGraph(), true );
1262 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1263 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1267 // called when the escape key is used (either on the main window or on an inspector)
1268 void Selection_Deselect(){
1269 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1270 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1271 GlobalSelectionSystem().setSelectedAllComponents( false );
1275 SelectionSystem_DefaultMode();
1276 ComponentModeChanged();
1281 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1282 GlobalSelectionSystem().setSelectedAllComponents( false );
1286 GlobalSelectionSystem().setSelectedAll( false );
1292 void Selection_NudgeUp(){
1293 UndoableCommand undo( "nudgeSelectedUp" );
1294 NudgeSelection( eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1297 void Selection_NudgeDown(){
1298 UndoableCommand undo( "nudgeSelectedDown" );
1299 NudgeSelection( eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1302 void Selection_NudgeLeft(){
1303 UndoableCommand undo( "nudgeSelectedLeft" );
1304 NudgeSelection( eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1307 void Selection_NudgeRight(){
1308 UndoableCommand undo( "nudgeSelectedRight" );
1309 NudgeSelection( eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1313 void TranslateToolExport( const BoolImportCallback& importCallback ){
1314 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate );
1317 void RotateToolExport( const BoolImportCallback& importCallback ){
1318 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate );
1321 void ScaleToolExport( const BoolImportCallback& importCallback ){
1322 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale );
1325 void DragToolExport( const BoolImportCallback& importCallback ){
1326 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag );
1329 void ClipperToolExport( const BoolImportCallback& importCallback ){
1330 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip );
1333 FreeCaller1<const BoolImportCallback&, TranslateToolExport> g_translatemode_button_caller;
1334 BoolExportCallback g_translatemode_button_callback( g_translatemode_button_caller );
1335 ToggleItem g_translatemode_button( g_translatemode_button_callback );
1337 FreeCaller1<const BoolImportCallback&, RotateToolExport> g_rotatemode_button_caller;
1338 BoolExportCallback g_rotatemode_button_callback( g_rotatemode_button_caller );
1339 ToggleItem g_rotatemode_button( g_rotatemode_button_callback );
1341 FreeCaller1<const BoolImportCallback&, ScaleToolExport> g_scalemode_button_caller;
1342 BoolExportCallback g_scalemode_button_callback( g_scalemode_button_caller );
1343 ToggleItem g_scalemode_button( g_scalemode_button_callback );
1345 FreeCaller1<const BoolImportCallback&, DragToolExport> g_dragmode_button_caller;
1346 BoolExportCallback g_dragmode_button_callback( g_dragmode_button_caller );
1347 ToggleItem g_dragmode_button( g_dragmode_button_callback );
1349 FreeCaller1<const BoolImportCallback&, ClipperToolExport> g_clipper_button_caller;
1350 BoolExportCallback g_clipper_button_callback( g_clipper_button_caller );
1351 ToggleItem g_clipper_button( g_clipper_button_callback );
1354 g_translatemode_button.update();
1355 g_rotatemode_button.update();
1356 g_scalemode_button.update();
1357 g_dragmode_button.update();
1358 g_clipper_button.update();
1361 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1364 if ( g_currentToolMode == DragMode && g_defaultToolMode != DragMode ) {
1365 g_defaultToolMode();
1369 g_currentToolMode = DragMode;
1370 g_currentToolModeSupportsComponentEditing = true;
1372 OnClipMode( false );
1374 Sys_Status( c_ResizeMode_status );
1375 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eDrag );
1382 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1384 void TranslateMode(){
1385 if ( g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode ) {
1386 g_defaultToolMode();
1390 g_currentToolMode = TranslateMode;
1391 g_currentToolModeSupportsComponentEditing = true;
1393 OnClipMode( false );
1395 Sys_Status( c_TranslateMode_status );
1396 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eTranslate );
1402 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1405 if ( g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode ) {
1406 g_defaultToolMode();
1410 g_currentToolMode = RotateMode;
1411 g_currentToolModeSupportsComponentEditing = true;
1413 OnClipMode( false );
1415 Sys_Status( c_RotateMode_status );
1416 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eRotate );
1422 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1425 if ( g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode ) {
1426 g_defaultToolMode();
1430 g_currentToolMode = ScaleMode;
1431 g_currentToolModeSupportsComponentEditing = true;
1433 OnClipMode( false );
1435 Sys_Status( c_ScaleMode_status );
1436 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eScale );
1443 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1447 if ( g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode ) {
1448 g_defaultToolMode();
1452 g_currentToolMode = ClipperMode;
1453 g_currentToolModeSupportsComponentEditing = false;
1455 SelectionSystem_DefaultMode();
1459 Sys_Status( c_ClipperMode_status );
1460 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eClip );
1467 void Texdef_Rotate( float angle ){
1468 StringOutputStream command;
1469 command << "brushRotateTexture -angle " << angle;
1470 UndoableCommand undo( command.c_str() );
1471 Select_RotateTexture( angle );
1474 void Texdef_RotateClockwise(){
1475 Texdef_Rotate( static_cast<float>( fabs( g_si_globals.rotate ) ) );
1478 void Texdef_RotateAntiClockwise(){
1479 Texdef_Rotate( static_cast<float>( -fabs( g_si_globals.rotate ) ) );
1482 void Texdef_Scale( float x, float y ){
1483 StringOutputStream command;
1484 command << "brushScaleTexture -x " << x << " -y " << y;
1485 UndoableCommand undo( command.c_str() );
1486 Select_ScaleTexture( x, y );
1489 void Texdef_ScaleUp(){
1490 Texdef_Scale( 0, g_si_globals.scale[1] );
1493 void Texdef_ScaleDown(){
1494 Texdef_Scale( 0, -g_si_globals.scale[1] );
1497 void Texdef_ScaleLeft(){
1498 Texdef_Scale( -g_si_globals.scale[0],0 );
1501 void Texdef_ScaleRight(){
1502 Texdef_Scale( g_si_globals.scale[0],0 );
1505 void Texdef_Shift( float x, float y ){
1506 StringOutputStream command;
1507 command << "brushShiftTexture -x " << x << " -y " << y;
1508 UndoableCommand undo( command.c_str() );
1509 Select_ShiftTexture( x, y );
1512 void Texdef_ShiftLeft(){
1513 Texdef_Shift( -g_si_globals.shift[0], 0 );
1516 void Texdef_ShiftRight(){
1517 Texdef_Shift( g_si_globals.shift[0], 0 );
1520 void Texdef_ShiftUp(){
1521 Texdef_Shift( 0, g_si_globals.shift[1] );
1524 void Texdef_ShiftDown(){
1525 Texdef_Shift( 0, -g_si_globals.shift[1] );
1530 class SnappableSnapToGridSelected : public scene::Graph::Walker
1534 SnappableSnapToGridSelected( float snap )
1537 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1538 if ( path.top().get().visible() ) {
1539 Snappable* snappable = Node_getSnappable( path.top() );
1541 && Instance_getSelectable( instance )->isSelected() ) {
1542 snappable->snapto( m_snap );
1549 void Scene_SnapToGrid_Selected( scene::Graph& graph, float snap ){
1550 graph.traverse( SnappableSnapToGridSelected( snap ) );
1553 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1557 ComponentSnappableSnapToGridSelected( float snap )
1560 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1561 if ( path.top().get().visible() ) {
1562 ComponentSnappable* componentSnappable = Instance_getComponentSnappable( instance );
1563 if ( componentSnappable != 0
1564 && Instance_getSelectable( instance )->isSelected() ) {
1565 componentSnappable->snapComponents( m_snap );
1572 void Scene_SnapToGrid_Component_Selected( scene::Graph& graph, float snap ){
1573 graph.traverse( ComponentSnappableSnapToGridSelected( snap ) );
1576 void Selection_SnapToGrid(){
1577 StringOutputStream command;
1578 command << "snapSelected -grid " << GetGridSize();
1579 UndoableCommand undo( command.c_str() );
1581 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1582 Scene_SnapToGrid_Component_Selected( GlobalSceneGraph(), GetGridSize() );
1586 Scene_SnapToGrid_Selected( GlobalSceneGraph(), GetGridSize() );
1591 static gint qe_every_second( gpointer data ){
1592 GdkModifierType mask;
1594 gdk_window_get_pointer( 0, 0, 0, &mask );
1596 if ( ( mask & ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK ) ) == 0 ) {
1603 guint s_qe_every_second_id = 0;
1605 void EverySecondTimer_enable(){
1606 if ( s_qe_every_second_id == 0 ) {
1607 s_qe_every_second_id = gtk_timeout_add( 1000, qe_every_second, 0 );
1611 void EverySecondTimer_disable(){
1612 if ( s_qe_every_second_id != 0 ) {
1613 gtk_timeout_remove( s_qe_every_second_id );
1614 s_qe_every_second_id = 0;
1618 gint window_realize_remove_decoration( GtkWidget* widget, gpointer data ){
1619 gdk_window_set_decorations( widget->window, (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) );
1626 GtkWindow* m_window;
1630 WaitDialog create_wait_dialog( const char* title, const char* text ){
1633 dialog.m_window = create_floating_window( title, MainFrame_getWindow() );
1634 gtk_window_set_resizable( dialog.m_window, FALSE );
1635 gtk_container_set_border_width( GTK_CONTAINER( dialog.m_window ), 0 );
1636 gtk_window_set_position( dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT );
1638 g_signal_connect( G_OBJECT( dialog.m_window ), "realize", G_CALLBACK( window_realize_remove_decoration ), 0 );
1641 dialog.m_label = GTK_LABEL( gtk_label_new( text ) );
1642 gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 );
1643 gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT );
1644 gtk_widget_show( GTK_WIDGET( dialog.m_label ) );
1645 gtk_widget_set_size_request( GTK_WIDGET( dialog.m_label ), 200, -1 );
1647 gtk_container_add( GTK_CONTAINER( dialog.m_window ), GTK_WIDGET( dialog.m_label ) );
1654 clock_t g_lastRedrawTime = 0;
1655 const clock_t c_redrawInterval = clock_t( CLOCKS_PER_SEC / 10 );
1657 bool redrawRequired(){
1658 clock_t currentTime = std::clock();
1659 if ( currentTime - g_lastRedrawTime >= c_redrawInterval ) {
1660 g_lastRedrawTime = currentTime;
1667 bool MainFrame_isActiveApp(){
1668 //globalOutputStream() << "listing\n";
1669 GList* list = gtk_window_list_toplevels();
1670 for ( GList* i = list; i != 0; i = g_list_next( i ) )
1672 //globalOutputStream() << "toplevel.. ";
1673 if ( gtk_window_is_active( GTK_WINDOW( i->data ) ) ) {
1674 //globalOutputStream() << "is active\n";
1677 //globalOutputStream() << "not active\n";
1682 typedef std::list<CopiedString> StringStack;
1683 StringStack g_wait_stack;
1686 bool ScreenUpdates_Enabled(){
1687 return g_wait_stack.empty();
1690 void ScreenUpdates_process(){
1691 if ( redrawRequired() && GTK_WIDGET_VISIBLE( g_wait.m_window ) ) {
1697 void ScreenUpdates_Disable( const char* message, const char* title ){
1698 if ( g_wait_stack.empty() ) {
1699 EverySecondTimer_disable();
1703 bool isActiveApp = MainFrame_isActiveApp();
1705 g_wait = create_wait_dialog( title, message );
1706 gtk_grab_add( GTK_WIDGET( g_wait.m_window ) );
1708 if ( isActiveApp ) {
1709 gtk_widget_show( GTK_WIDGET( g_wait.m_window ) );
1710 ScreenUpdates_process();
1713 else if ( GTK_WIDGET_VISIBLE( g_wait.m_window ) ) {
1714 gtk_label_set_text( g_wait.m_label, message );
1715 ScreenUpdates_process();
1717 g_wait_stack.push_back( message );
1720 void ScreenUpdates_Enable(){
1721 ASSERT_MESSAGE( !ScreenUpdates_Enabled(), "screen updates already enabled" );
1722 g_wait_stack.pop_back();
1723 if ( g_wait_stack.empty() ) {
1724 EverySecondTimer_enable();
1725 //gtk_widget_set_sensitive(GTK_WIDGET(MainFrame_getWindow()), TRUE);
1727 gtk_grab_remove( GTK_WIDGET( g_wait.m_window ) );
1728 destroy_floating_window( g_wait.m_window );
1729 g_wait.m_window = 0;
1731 //gtk_window_present(MainFrame_getWindow());
1733 else if ( GTK_WIDGET_VISIBLE( g_wait.m_window ) ) {
1734 gtk_label_set_text( g_wait.m_label, g_wait_stack.back().c_str() );
1735 ScreenUpdates_process();
1741 void GlobalCamera_UpdateWindow(){
1742 if ( g_pParentWnd != 0 ) {
1743 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
1747 void XY_UpdateWindow( MainFrame& mainframe ){
1748 if ( mainframe.GetXYWnd() != 0 ) {
1749 XYWnd_Update( *mainframe.GetXYWnd() );
1753 void XZ_UpdateWindow( MainFrame& mainframe ){
1754 if ( mainframe.GetXZWnd() != 0 ) {
1755 XYWnd_Update( *mainframe.GetXZWnd() );
1759 void YZ_UpdateWindow( MainFrame& mainframe ){
1760 if ( mainframe.GetYZWnd() != 0 ) {
1761 XYWnd_Update( *mainframe.GetYZWnd() );
1765 void XY_UpdateAllWindows( MainFrame& mainframe ){
1766 XY_UpdateWindow( mainframe );
1767 XZ_UpdateWindow( mainframe );
1768 YZ_UpdateWindow( mainframe );
1771 void XY_UpdateAllWindows(){
1772 if ( g_pParentWnd != 0 ) {
1773 XY_UpdateAllWindows( *g_pParentWnd );
1777 void UpdateAllWindows(){
1778 GlobalCamera_UpdateWindow();
1779 XY_UpdateAllWindows();
1783 void ModeChangeNotify(){
1784 SceneChangeNotify();
1787 void ClipperChangeNotify(){
1788 GlobalCamera_UpdateWindow();
1789 XY_UpdateAllWindows();
1793 LatchedInt g_Layout_viewStyle( 0, "Window Layout" );
1794 LatchedBool g_Layout_enableDetachableMenus( true, "Detachable Menus" );
1795 LatchedBool g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
1796 LatchedBool g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
1800 GtkMenuItem* create_file_menu(){
1802 GtkMenuItem* file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
1803 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( file_menu_item ) );
1804 if ( g_Layout_enableDetachableMenus.m_value ) {
1805 menu_tearoff( menu );
1808 create_menu_item_with_mnemonic( menu, "_New Map", "NewMap" );
1809 menu_separator( menu );
1812 //++timo temporary experimental stuff for sleep mode..
1813 create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" );
1814 menu_separator( menu );
1818 create_menu_item_with_mnemonic( menu, "_Open...", "OpenMap" );
1820 create_menu_item_with_mnemonic( menu, "_Import...", "ImportMap" );
1821 create_menu_item_with_mnemonic( menu, "_Save", "SaveMap" );
1822 create_menu_item_with_mnemonic( menu, "Save _as...", "SaveMapAs" );
1823 create_menu_item_with_mnemonic( menu, "Save s_elected...", "SaveSelected" );
1824 menu_separator( menu );
1825 create_menu_item_with_mnemonic( menu, "Save re_gion...", "SaveRegion" );
1826 menu_separator( menu );
1827 create_menu_item_with_mnemonic( menu, "_Refresh models", "RefreshReferences" );
1828 menu_separator( menu );
1829 create_menu_item_with_mnemonic( menu, "Pro_ject settings...", "ProjectSettings" );
1830 menu_separator( menu );
1831 create_menu_item_with_mnemonic( menu, "_Pointfile...", "TogglePointfile" );
1832 menu_separator( menu );
1833 MRU_constructMenu( menu );
1834 menu_separator( menu );
1835 create_menu_item_with_mnemonic( menu, "Check for NetRadiant update", "CheckForUpdate" ); // FIXME
1836 create_menu_item_with_mnemonic( menu, "E_xit", "Exit" );
1838 return file_menu_item;
1841 GtkMenuItem* create_edit_menu(){
1843 GtkMenuItem* edit_menu_item = new_sub_menu_item_with_mnemonic( "_Edit" );
1844 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( edit_menu_item ) );
1845 if ( g_Layout_enableDetachableMenus.m_value ) {
1846 menu_tearoff( menu );
1848 create_menu_item_with_mnemonic( menu, "_Undo", "Undo" );
1849 create_menu_item_with_mnemonic( menu, "_Redo", "Redo" );
1850 menu_separator( menu );
1851 create_menu_item_with_mnemonic( menu, "_Copy", "Copy" );
1852 create_menu_item_with_mnemonic( menu, "_Paste", "Paste" );
1853 create_menu_item_with_mnemonic( menu, "P_aste To Camera", "PasteToCamera" );
1854 menu_separator( menu );
1855 create_menu_item_with_mnemonic( menu, "_Duplicate", "CloneSelection" );
1856 create_menu_item_with_mnemonic( menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique" );
1857 create_menu_item_with_mnemonic( menu, "D_elete", "DeleteSelection" );
1858 menu_separator( menu );
1859 create_menu_item_with_mnemonic( menu, "Pa_rent", "ParentSelection" );
1860 menu_separator( menu );
1861 create_menu_item_with_mnemonic( menu, "C_lear Selection", "UnSelectSelection" );
1862 create_menu_item_with_mnemonic( menu, "_Invert Selection", "InvertSelection" );
1863 create_menu_item_with_mnemonic( menu, "Select i_nside", "SelectInside" );
1864 create_menu_item_with_mnemonic( menu, "Select _touching", "SelectTouching" );
1866 GtkMenu* convert_menu = create_sub_menu_with_mnemonic( menu, "E_xpand Selection" );
1867 if ( g_Layout_enableDetachableMenus.m_value ) {
1868 menu_tearoff( convert_menu );
1870 create_menu_item_with_mnemonic( convert_menu, "To Whole _Entities", "ExpandSelectionToEntities" );
1872 menu_separator( menu );
1873 create_menu_item_with_mnemonic( menu, "Pre_ferences...", "Preferences" );
1875 return edit_menu_item;
1878 void fill_view_xy_top_menu( GtkMenu* menu ){
1879 create_check_menu_item_with_mnemonic( menu, "XY (Top) View", "ToggleView" );
1883 void fill_view_yz_side_menu( GtkMenu* menu ){
1884 create_check_menu_item_with_mnemonic( menu, "YZ (Side) View", "ToggleSideView" );
1888 void fill_view_xz_front_menu( GtkMenu* menu ){
1889 create_check_menu_item_with_mnemonic( menu, "XZ (Front) View", "ToggleFrontView" );
1893 GtkWidget* g_toggle_z_item = 0;
1894 GtkWidget* g_toggle_console_item = 0;
1895 GtkWidget* g_toggle_entity_item = 0;
1896 GtkWidget* g_toggle_entitylist_item = 0;
1898 GtkMenuItem* create_view_menu( MainFrame::EViewStyle style ){
1900 GtkMenuItem* view_menu_item = new_sub_menu_item_with_mnemonic( "Vie_w" );
1901 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( view_menu_item ) );
1902 if ( g_Layout_enableDetachableMenus.m_value ) {
1903 menu_tearoff( menu );
1906 if ( style == MainFrame::eFloating ) {
1907 fill_view_camera_menu( menu );
1908 fill_view_xy_top_menu( menu );
1909 fill_view_yz_side_menu( menu );
1910 fill_view_xz_front_menu( menu );
1912 if ( style == MainFrame::eFloating || style == MainFrame::eSplit ) {
1913 create_menu_item_with_mnemonic( menu, "Console View", "ToggleConsole" );
1914 create_menu_item_with_mnemonic( menu, "Texture Browser", "ToggleTextures" );
1915 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ToggleEntityInspector" );
1919 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ViewEntityInfo" );
1921 create_menu_item_with_mnemonic( menu, "_Surface Inspector", "SurfaceInspector" );
1922 create_menu_item_with_mnemonic( menu, "Entity List", "EntityList" );
1924 menu_separator( menu );
1926 GtkMenu* camera_menu = create_sub_menu_with_mnemonic( menu, "Camera" );
1927 if ( g_Layout_enableDetachableMenus.m_value ) {
1928 menu_tearoff( camera_menu );
1930 create_menu_item_with_mnemonic( camera_menu, "_Center", "CenterView" );
1931 create_menu_item_with_mnemonic( camera_menu, "_Up Floor", "UpFloor" );
1932 create_menu_item_with_mnemonic( camera_menu, "_Down Floor", "DownFloor" );
1933 menu_separator( camera_menu );
1934 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane In", "CubicClipZoomIn" );
1935 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane Out", "CubicClipZoomOut" );
1936 menu_separator( camera_menu );
1937 create_menu_item_with_mnemonic( camera_menu, "Next leak spot", "NextLeakSpot" );
1938 create_menu_item_with_mnemonic( camera_menu, "Previous leak spot", "PrevLeakSpot" );
1939 menu_separator( camera_menu );
1940 create_menu_item_with_mnemonic( camera_menu, "Look Through Selected", "LookThroughSelected" );
1941 create_menu_item_with_mnemonic( camera_menu, "Look Through Camera", "LookThroughCamera" );
1943 menu_separator( menu );
1945 GtkMenu* orthographic_menu = create_sub_menu_with_mnemonic( menu, "Orthographic" );
1946 if ( g_Layout_enableDetachableMenus.m_value ) {
1947 menu_tearoff( orthographic_menu );
1949 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
1950 create_menu_item_with_mnemonic( orthographic_menu, "_Next (XY, YZ, XY)", "NextView" );
1951 create_menu_item_with_mnemonic( orthographic_menu, "XY (Top)", "ViewTop" );
1952 create_menu_item_with_mnemonic( orthographic_menu, "YZ", "ViewSide" );
1953 create_menu_item_with_mnemonic( orthographic_menu, "XZ", "ViewFront" );
1954 menu_separator( orthographic_menu );
1957 create_menu_item_with_mnemonic( orthographic_menu, "_XY 100%", "Zoom100" );
1958 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _In", "ZoomIn" );
1959 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _Out", "ZoomOut" );
1962 menu_separator( menu );
1965 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Show" );
1966 if ( g_Layout_enableDetachableMenus.m_value ) {
1967 menu_tearoff( menu_in_menu );
1969 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Angles", "ShowAngles" );
1970 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Names", "ShowNames" );
1971 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Blocks", "ShowBlocks" );
1972 create_check_menu_item_with_mnemonic( menu_in_menu, "Show C_oordinates", "ShowCoordinates" );
1973 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Window Outline", "ShowWindowOutline" );
1974 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Axes", "ShowAxes" );
1975 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Workzone", "ShowWorkzone" );
1976 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Stats", "ShowStats" );
1980 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Filter" );
1981 if ( g_Layout_enableDetachableMenus.m_value ) {
1982 menu_tearoff( menu_in_menu );
1984 Filters_constructMenu( menu_in_menu );
1986 menu_separator( menu );
1988 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Hide/Show" );
1989 if ( g_Layout_enableDetachableMenus.m_value ) {
1990 menu_tearoff( menu_in_menu );
1992 create_menu_item_with_mnemonic( menu_in_menu, "Hide Selected", "HideSelected" );
1993 create_menu_item_with_mnemonic( menu_in_menu, "Show Hidden", "ShowHidden" );
1995 menu_separator( menu );
1997 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Region" );
1998 if ( g_Layout_enableDetachableMenus.m_value ) {
1999 menu_tearoff( menu_in_menu );
2001 create_menu_item_with_mnemonic( menu_in_menu, "_Off", "RegionOff" );
2002 create_menu_item_with_mnemonic( menu_in_menu, "_Set XY", "RegionSetXY" );
2003 create_menu_item_with_mnemonic( menu_in_menu, "Set _Brush", "RegionSetBrush" );
2004 create_menu_item_with_mnemonic( menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection" );
2007 command_connect_accelerator( "CenterXYView" );
2009 return view_menu_item;
2012 GtkMenuItem* create_selection_menu(){
2014 GtkMenuItem* selection_menu_item = new_sub_menu_item_with_mnemonic( "M_odify" );
2015 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( selection_menu_item ) );
2016 if ( g_Layout_enableDetachableMenus.m_value ) {
2017 menu_tearoff( menu );
2021 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Components" );
2022 if ( g_Layout_enableDetachableMenus.m_value ) {
2023 menu_tearoff( menu_in_menu );
2025 create_check_menu_item_with_mnemonic( menu_in_menu, "_Edges", "DragEdges" );
2026 create_check_menu_item_with_mnemonic( menu_in_menu, "_Vertices", "DragVertices" );
2027 create_check_menu_item_with_mnemonic( menu_in_menu, "_Faces", "DragFaces" );
2030 menu_separator( menu );
2033 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Nudge" );
2034 if ( g_Layout_enableDetachableMenus.m_value ) {
2035 menu_tearoff( menu_in_menu );
2037 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Left", "SelectNudgeLeft" );
2038 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Right", "SelectNudgeRight" );
2039 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Up", "SelectNudgeUp" );
2040 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Down", "SelectNudgeDown" );
2043 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Rotate" );
2044 if ( g_Layout_enableDetachableMenus.m_value ) {
2045 menu_tearoff( menu_in_menu );
2047 create_menu_item_with_mnemonic( menu_in_menu, "Rotate X", "RotateSelectionX" );
2048 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Y", "RotateSelectionY" );
2049 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Z", "RotateSelectionZ" );
2052 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Flip" );
2053 if ( g_Layout_enableDetachableMenus.m_value ) {
2054 menu_tearoff( menu_in_menu );
2056 create_menu_item_with_mnemonic( menu_in_menu, "Flip _X", "MirrorSelectionX" );
2057 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Y", "MirrorSelectionY" );
2058 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Z", "MirrorSelectionZ" );
2060 menu_separator( menu );
2061 create_menu_item_with_mnemonic( menu, "Arbitrary rotation...", "ArbitraryRotation" );
2062 create_menu_item_with_mnemonic( menu, "Arbitrary scale...", "ArbitraryScale" );
2064 return selection_menu_item;
2067 GtkMenuItem* create_bsp_menu(){
2069 GtkMenuItem* bsp_menu_item = new_sub_menu_item_with_mnemonic( "_Build" );
2070 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( bsp_menu_item ) );
2072 if ( g_Layout_enableDetachableMenus.m_value ) {
2073 menu_tearoff( menu );
2076 create_menu_item_with_mnemonic( menu, "Customize...", "BuildMenuCustomize" );
2078 menu_separator( menu );
2080 Build_constructMenu( menu );
2084 return bsp_menu_item;
2087 GtkMenuItem* create_grid_menu(){
2089 GtkMenuItem* grid_menu_item = new_sub_menu_item_with_mnemonic( "_Grid" );
2090 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( grid_menu_item ) );
2091 if ( g_Layout_enableDetachableMenus.m_value ) {
2092 menu_tearoff( menu );
2095 Grid_constructMenu( menu );
2097 return grid_menu_item;
2100 GtkMenuItem* create_misc_menu(){
2102 GtkMenuItem* misc_menu_item = new_sub_menu_item_with_mnemonic( "M_isc" );
2103 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( misc_menu_item ) );
2104 if ( g_Layout_enableDetachableMenus.m_value ) {
2105 menu_tearoff( menu );
2109 create_menu_item_with_mnemonic( menu, "_Benchmark", FreeCaller<GlobalCamera_Benchmark>() );
2111 gtk_container_add( GTK_CONTAINER( menu ), GTK_WIDGET( create_colours_menu() ) );
2113 create_menu_item_with_mnemonic( menu, "Find brush...", "FindBrush" );
2114 create_menu_item_with_mnemonic( menu, "Map Info...", "MapInfo" );
2115 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2116 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<WXY_Print>());
2117 create_menu_item_with_mnemonic( menu, "_Background select", FreeCaller<WXY_BackgroundSelect>() );
2118 return misc_menu_item;
2121 GtkMenuItem* create_entity_menu(){
2123 GtkMenuItem* entity_menu_item = new_sub_menu_item_with_mnemonic( "E_ntity" );
2124 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( entity_menu_item ) );
2125 if ( g_Layout_enableDetachableMenus.m_value ) {
2126 menu_tearoff( menu );
2129 Entity_constructMenu( menu );
2131 return entity_menu_item;
2134 GtkMenuItem* create_brush_menu(){
2136 GtkMenuItem* brush_menu_item = new_sub_menu_item_with_mnemonic( "B_rush" );
2137 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( brush_menu_item ) );
2138 if ( g_Layout_enableDetachableMenus.m_value ) {
2139 menu_tearoff( menu );
2142 Brush_constructMenu( menu );
2144 return brush_menu_item;
2147 GtkMenuItem* create_patch_menu(){
2149 GtkMenuItem* patch_menu_item = new_sub_menu_item_with_mnemonic( "_Curve" );
2150 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( patch_menu_item ) );
2151 if ( g_Layout_enableDetachableMenus.m_value ) {
2152 menu_tearoff( menu );
2155 Patch_constructMenu( menu );
2157 return patch_menu_item;
2160 GtkMenuItem* create_help_menu(){
2162 GtkMenuItem* help_menu_item = new_sub_menu_item_with_mnemonic( "_Help" );
2163 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( help_menu_item ) );
2164 if ( g_Layout_enableDetachableMenus.m_value ) {
2165 menu_tearoff( menu );
2168 create_menu_item_with_mnemonic( menu, "Manual", "OpenManual" );
2170 // this creates all the per-game drop downs for the game pack helps
2171 // it will take care of hooking the Sys_OpenURL calls etc.
2172 create_game_help_menu( menu );
2174 create_menu_item_with_mnemonic( menu, "Bug report", FreeCaller<OpenBugReportURL>() );
2175 create_menu_item_with_mnemonic( menu, "Shortcuts list", FreeCaller<DoCommandListDlg>() );
2176 create_menu_item_with_mnemonic( menu, "_About", FreeCaller<DoAbout>() );
2178 return help_menu_item;
2181 GtkMenuBar* create_main_menu( MainFrame::EViewStyle style ){
2182 GtkMenuBar* menu_bar = GTK_MENU_BAR( gtk_menu_bar_new() );
2183 gtk_widget_show( GTK_WIDGET( menu_bar ) );
2185 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_file_menu() ) );
2186 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_edit_menu() ) );
2187 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_view_menu( style ) ) );
2188 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_selection_menu() ) );
2189 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_bsp_menu() ) );
2190 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_grid_menu() ) );
2191 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_misc_menu() ) );
2192 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_entity_menu() ) );
2193 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_brush_menu() ) );
2194 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_patch_menu() ) );
2195 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_plugins_menu() ) );
2196 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_help_menu() ) );
2202 void PatchInspector_registerShortcuts(){
2203 command_connect_accelerator( "PatchInspector" );
2206 void Patch_registerShortcuts(){
2207 command_connect_accelerator( "InvertCurveTextureX" );
2208 command_connect_accelerator( "InvertCurveTextureY" );
2209 command_connect_accelerator( "PatchInsertInsertColumn" );
2210 command_connect_accelerator( "PatchInsertInsertRow" );
2211 command_connect_accelerator( "PatchDeleteLastColumn" );
2212 command_connect_accelerator( "PatchDeleteLastRow" );
2213 command_connect_accelerator( "NaturalizePatch" );
2214 //command_connect_accelerator("CapCurrentCurve");
2217 void Manipulators_registerShortcuts(){
2218 toggle_add_accelerator( "MouseRotate" );
2219 toggle_add_accelerator( "MouseTranslate" );
2220 toggle_add_accelerator( "MouseScale" );
2221 toggle_add_accelerator( "MouseDrag" );
2222 toggle_add_accelerator( "ToggleClipper" );
2225 void TexdefNudge_registerShortcuts(){
2226 command_connect_accelerator( "TexRotateClock" );
2227 command_connect_accelerator( "TexRotateCounter" );
2228 command_connect_accelerator( "TexScaleUp" );
2229 command_connect_accelerator( "TexScaleDown" );
2230 command_connect_accelerator( "TexScaleLeft" );
2231 command_connect_accelerator( "TexScaleRight" );
2232 command_connect_accelerator( "TexShiftUp" );
2233 command_connect_accelerator( "TexShiftDown" );
2234 command_connect_accelerator( "TexShiftLeft" );
2235 command_connect_accelerator( "TexShiftRight" );
2238 void SelectNudge_registerShortcuts(){
2239 command_connect_accelerator( "MoveSelectionDOWN" );
2240 command_connect_accelerator( "MoveSelectionUP" );
2241 //command_connect_accelerator("SelectNudgeLeft");
2242 //command_connect_accelerator("SelectNudgeRight");
2243 //command_connect_accelerator("SelectNudgeUp");
2244 //command_connect_accelerator("SelectNudgeDown");
2247 void SnapToGrid_registerShortcuts(){
2248 command_connect_accelerator( "SnapToGrid" );
2251 void SelectByType_registerShortcuts(){
2252 command_connect_accelerator( "SelectAllOfType" );
2255 void SurfaceInspector_registerShortcuts(){
2256 command_connect_accelerator( "FitTexture" );
2260 void register_shortcuts(){
2261 PatchInspector_registerShortcuts();
2262 Patch_registerShortcuts();
2263 Grid_registerShortcuts();
2264 XYWnd_registerShortcuts();
2265 CamWnd_registerShortcuts();
2266 Manipulators_registerShortcuts();
2267 SurfaceInspector_registerShortcuts();
2268 TexdefNudge_registerShortcuts();
2269 SelectNudge_registerShortcuts();
2270 SnapToGrid_registerShortcuts();
2271 SelectByType_registerShortcuts();
2274 void File_constructToolbar( GtkToolbar* toolbar ){
2275 toolbar_append_button( toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap" );
2276 toolbar_append_button( toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap" );
2279 void UndoRedo_constructToolbar( GtkToolbar* toolbar ){
2280 toolbar_append_button( toolbar, "Undo (CTRL + Z)", "undo.png", "Undo" );
2281 toolbar_append_button( toolbar, "Redo (CTRL + Y)", "redo.png", "Redo" );
2284 void RotateFlip_constructToolbar( GtkToolbar* toolbar ){
2285 toolbar_append_button( toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX" );
2286 toolbar_append_button( toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX" );
2287 toolbar_append_button( toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY" );
2288 toolbar_append_button( toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY" );
2289 toolbar_append_button( toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ" );
2290 toolbar_append_button( toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ" );
2293 void Select_constructToolbar( GtkToolbar* toolbar ){
2294 toolbar_append_button( toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching" );
2295 toolbar_append_button( toolbar, "Select inside", "selection_selectinside.png", "SelectInside" );
2298 void CSG_constructToolbar( GtkToolbar* toolbar ){
2299 toolbar_append_button( toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract" );
2300 toolbar_append_button( toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge" );
2301 toolbar_append_button( toolbar, "Hollow", "selection_makehollow.png", "CSGHollow" );
2304 void ComponentModes_constructToolbar( GtkToolbar* toolbar ){
2305 toolbar_append_toggle_button( toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices" );
2306 toolbar_append_toggle_button( toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges" );
2307 toolbar_append_toggle_button( toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces" );
2310 void Clipper_constructToolbar( GtkToolbar* toolbar ){
2312 toolbar_append_toggle_button( toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper" );
2315 void XYWnd_constructToolbar( GtkToolbar* toolbar ){
2316 toolbar_append_button( toolbar, "Change views", "view_change.png", "NextView" );
2319 void Manipulators_constructToolbar( GtkToolbar* toolbar ){
2320 toolbar_append_toggle_button( toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate" );
2321 toolbar_append_toggle_button( toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate" );
2322 toolbar_append_toggle_button( toolbar, "Scale", "select_mousescale.png", "MouseScale" );
2323 toolbar_append_toggle_button( toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag" );
2325 Clipper_constructToolbar( toolbar );
2328 GtkToolbar* create_main_toolbar( MainFrame::EViewStyle style ){
2329 GtkToolbar* toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
2330 gtk_toolbar_set_orientation( toolbar, GTK_ORIENTATION_HORIZONTAL );
2331 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
2333 gtk_widget_show( GTK_WIDGET( toolbar ) );
2335 File_constructToolbar( toolbar );
2337 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2339 UndoRedo_constructToolbar( toolbar );
2341 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2343 RotateFlip_constructToolbar( toolbar );
2345 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2347 Select_constructToolbar( toolbar );
2349 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2351 CSG_constructToolbar( toolbar );
2353 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2355 ComponentModes_constructToolbar( toolbar );
2357 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2358 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2360 XYWnd_constructToolbar( toolbar );
2363 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2365 CamWnd_constructToolbar( toolbar );
2367 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2369 Manipulators_constructToolbar( toolbar );
2371 if ( g_Layout_enablePatchToolbar.m_value ) {
2372 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2374 Patch_constructToolbar( toolbar );
2377 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2379 toolbar_append_toggle_button( toolbar, "Texture Lock (SHIFT +T)", "texture_lock.png", "TogTexLock" );
2381 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2383 GtkButton* g_view_entities_button = toolbar_append_button( toolbar, "Entities (N)", "entities.png", "ToggleEntityInspector" );
2384 GtkButton* g_view_console_button = toolbar_append_button( toolbar, "Console (O)", "console.png", "ToggleConsole" );
2385 GtkButton* g_view_textures_button = toolbar_append_button( toolbar, "Texture Browser (T)", "texture_browser.png", "ToggleTextures" );
2386 // TODO: call light inspector
2387 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector");
2389 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2390 GtkButton* g_refresh_models_button = toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" );
2393 // disable the console and texture button in the regular layouts
2394 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft ) {
2395 gtk_widget_set_sensitive( GTK_WIDGET( g_view_console_button ), FALSE );
2396 gtk_widget_set_sensitive( GTK_WIDGET( g_view_textures_button ), FALSE );
2402 GtkWidget* create_main_statusbar( GtkWidget *pStatusLabel[c_count_status] ){
2403 GtkTable* table = GTK_TABLE( gtk_table_new( 1, c_count_status, FALSE ) );
2404 gtk_widget_show( GTK_WIDGET( table ) );
2407 GtkLabel* label = GTK_LABEL( gtk_label_new( "Label" ) );
2408 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2409 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2410 gtk_widget_show( GTK_WIDGET( label ) );
2411 gtk_table_attach_defaults( table, GTK_WIDGET( label ), 0, 1, 0, 1 );
2412 pStatusLabel[c_command_status] = GTK_WIDGET( label );
2415 for ( int i = 1; i < c_count_status; ++i )
2417 GtkFrame* frame = GTK_FRAME( gtk_frame_new( 0 ) );
2418 gtk_widget_show( GTK_WIDGET( frame ) );
2419 gtk_table_attach_defaults( table, GTK_WIDGET( frame ), i, i + 1, 0, 1 );
2420 gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
2422 GtkLabel* label = GTK_LABEL( gtk_label_new( "Label" ) );
2423 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END );
2424 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2425 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2426 gtk_widget_show( GTK_WIDGET( label ) );
2427 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( label ) );
2428 pStatusLabel[i] = GTK_WIDGET( label );
2431 return GTK_WIDGET( table );
2437 WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" );
2439 class WindowFocusPrinter
2443 static gboolean frame_event( GtkWidget *widget, GdkEvent* event, WindowFocusPrinter* self ){
2444 globalOutputStream() << self->m_name << " frame_event\n";
2447 static gboolean keys_changed( GtkWidget *widget, WindowFocusPrinter* self ){
2448 globalOutputStream() << self->m_name << " keys_changed\n";
2451 static gboolean notify( GtkWindow* window, gpointer dummy, WindowFocusPrinter* self ){
2452 if ( gtk_window_is_active( window ) ) {
2453 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2457 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2462 WindowFocusPrinter( const char* name ) : m_name( name ){
2464 void connect( GtkWindow* toplevel_window ){
2465 g_signal_connect( G_OBJECT( toplevel_window ), "notify::has_toplevel_focus", G_CALLBACK( notify ), this );
2466 g_signal_connect( G_OBJECT( toplevel_window ), "notify::is_active", G_CALLBACK( notify ), this );
2467 g_signal_connect( G_OBJECT( toplevel_window ), "keys_changed", G_CALLBACK( keys_changed ), this );
2468 g_signal_connect( G_OBJECT( toplevel_window ), "frame_event", G_CALLBACK( frame_event ), this );
2472 WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" );
2476 class MainWindowActive
2478 static gboolean notify( GtkWindow* window, gpointer dummy, MainWindowActive* self ){
2479 if ( g_wait.m_window != 0 && gtk_window_is_active( window ) && !GTK_WIDGET_VISIBLE( g_wait.m_window ) ) {
2480 gtk_widget_show( GTK_WIDGET( g_wait.m_window ) );
2486 void connect( GtkWindow* toplevel_window ){
2487 g_signal_connect( G_OBJECT( toplevel_window ), "notify::is-active", G_CALLBACK( notify ), this );
2491 MainWindowActive g_MainWindowActive;
2493 SignalHandlerId XYWindowDestroyed_connect( const SignalHandler& handler ){
2494 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst( handler );
2497 void XYWindowDestroyed_disconnect( SignalHandlerId id ){
2498 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect( id );
2501 MouseEventHandlerId XYWindowMouseDown_connect( const MouseEventHandler& handler ){
2502 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst( handler );
2505 void XYWindowMouseDown_disconnect( MouseEventHandlerId id ){
2506 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect( id );
2509 // =============================================================================
2512 MainFrame* g_pParentWnd = 0;
2514 GtkWindow* MainFrame_getWindow(){
2515 if ( g_pParentWnd == 0 ) {
2518 return g_pParentWnd->m_window;
2521 std::vector<GtkWidget*> g_floating_windows;
2523 MainFrame::MainFrame() : m_window( 0 ), m_idleRedrawStatusText( RedrawStatusTextCaller( *this ) ){
2531 for ( int n = 0; n < c_count_status; n++ )
2533 m_pStatusLabel[n] = 0;
2536 m_bSleeping = false;
2541 MainFrame::~MainFrame(){
2544 gtk_widget_hide( GTK_WIDGET( m_window ) );
2548 for ( std::vector<GtkWidget*>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i )
2550 gtk_widget_destroy( *i );
2553 gtk_widget_destroy( GTK_WIDGET( m_window ) );
2556 void MainFrame::SetActiveXY( XYWnd* p ){
2557 if ( m_pActiveXY ) {
2558 m_pActiveXY->SetActive( false );
2563 if ( m_pActiveXY ) {
2564 m_pActiveXY->SetActive( true );
2569 void MainFrame::ReleaseContexts(){
2572 m_pXYWnd->DestroyContext();
2575 m_pYZWnd->DestroyContext();
2578 m_pXZWnd->DestroyContext();
2581 m_pCamWnd->DestroyContext();
2584 m_pTexWnd->DestroyContext();
2587 m_pZWnd->DestroyContext();
2592 void MainFrame::CreateContexts(){
2595 m_pCamWnd->CreateContext();
2598 m_pXYWnd->CreateContext();
2601 m_pYZWnd->CreateContext();
2604 m_pXZWnd->CreateContext();
2607 m_pTexWnd->CreateContext();
2610 m_pZWnd->CreateContext();
2619 void MainFrame::OnSleep(){
2622 if ( m_bSleeping ) {
2623 // useful when trying to debug crashes in the sleep code
2624 globalOutputStream() << "Going into sleep mode..\n";
2626 globalOutputStream() << "Dispatching sleep msg...";
2627 DispatchRadiantMsg( RADIANT_SLEEP );
2628 globalOutputStream() << "Done.\n";
2630 gtk_window_iconify( m_window );
2631 GlobalSelectionSystem().setSelectedAll( false );
2633 GlobalShaderCache().unrealise();
2635 GlobalOpenGL_debugAssertNoErrors();
2636 ScreenUpdates_Disable();
2639 globalOutputStream() << "Releasing contexts...";
2641 globalOutputStream() << "Done.\n";
2645 globalOutputStream() << "Waking up\n";
2647 gtk_window_deiconify( m_window );
2650 globalOutputStream() << "Creating contexts...";
2652 globalOutputStream() << "Done.\n";
2654 globalOutputStream() << "Making current on camera...";
2655 m_pCamWnd->MakeCurrent();
2656 globalOutputStream() << "Done.\n";
2658 globalOutputStream() << "Reloading shaders...";
2660 GlobalShaderCache().realise();
2661 globalOutputStream() << "Done.\n";
2663 ScreenUpdates_Enable();
2665 globalOutputStream() << "Dispatching wake msg...";
2666 DispatchRadiantMsg( RADIANT_WAKEUP );
2667 globalOutputStream() << "Done\n";
2673 GtkWindow* create_splash(){
2674 GtkWindow* window = GTK_WINDOW( gtk_window_new( GTK_WINDOW_TOPLEVEL ) );
2675 gtk_window_set_decorated( window, FALSE );
2676 gtk_window_set_resizable( window, FALSE );
2677 gtk_window_set_modal( window, TRUE );
2678 gtk_window_set_default_size( window, -1, -1 );
2679 gtk_window_set_position( window, GTK_WIN_POS_CENTER );
2680 gtk_container_set_border_width( GTK_CONTAINER( window ), 0 );
2682 GtkImage* image = new_local_image( "splash.png" );
2683 gtk_widget_show( GTK_WIDGET( image ) );
2684 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( image ) );
2686 gtk_widget_set_size_request( GTK_WIDGET( window ), -1, -1 );
2687 gtk_widget_show( GTK_WIDGET( window ) );
2692 static GtkWindow *splash_screen = 0;
2695 splash_screen = create_splash();
2701 gtk_widget_destroy( GTK_WIDGET( splash_screen ) );
2704 WindowPositionTracker g_posCamWnd;
2705 WindowPositionTracker g_posXYWnd;
2706 WindowPositionTracker g_posXZWnd;
2707 WindowPositionTracker g_posYZWnd;
2709 static gint mainframe_delete( GtkWidget *widget, GdkEvent *event, gpointer data ){
2710 if ( ConfirmModified( "Exit Radiant" ) ) {
2717 void MainFrame::Create(){
2718 GtkWindow* window = GTK_WINDOW( gtk_window_new( GTK_WINDOW_TOPLEVEL ) );
2720 GlobalWindowObservers_connectTopLevel( window );
2722 gtk_window_set_transient_for( splash_screen, window );
2724 #if !defined( WIN32 )
2726 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
2727 if ( pixbuf != 0 ) {
2728 gtk_window_set_icon( window, pixbuf );
2729 gdk_pixbuf_unref( pixbuf );
2734 gtk_widget_add_events( GTK_WIDGET( window ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
2735 g_signal_connect( G_OBJECT( window ), "delete_event", G_CALLBACK( mainframe_delete ), this );
2737 m_position_tracker.connect( window );
2740 g_mainframeWidgetFocusPrinter.connect( window );
2741 g_mainframeFocusPrinter.connect( window );
2744 g_MainWindowActive.connect( window );
2746 GetPlugInMgr().Init( GTK_WIDGET( window ) );
2748 GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
2749 gtk_container_add( GTK_CONTAINER( window ), vbox );
2750 gtk_widget_show( vbox );
2752 global_accel_connect_window( window );
2754 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
2756 register_shortcuts();
2758 GtkMenuBar* main_menu = create_main_menu( CurrentStyle() );
2759 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_menu ), FALSE, FALSE, 0 );
2761 GtkToolbar* main_toolbar = create_main_toolbar( CurrentStyle() );
2762 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_toolbar ), FALSE, FALSE, 0 );
2764 GtkToolbar* plugin_toolbar = create_plugin_toolbar();
2765 if ( !g_Layout_enablePluginToolbar.m_value ) {
2766 gtk_widget_hide( GTK_WIDGET( plugin_toolbar ) );
2768 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( plugin_toolbar ), FALSE, FALSE, 0 );
2770 GtkWidget* main_statusbar = create_main_statusbar( m_pStatusLabel );
2771 gtk_box_pack_end( GTK_BOX( vbox ), main_statusbar, FALSE, TRUE, 2 );
2773 GroupDialog_constructWindow( window );
2774 g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) );
2776 if ( FloatingGroupDialog() ) {
2777 g_page_console = GroupDialog_addPage( "Console", Console_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Console" ) );
2781 if ( g_multimon_globals.m_bStartOnPrimMon ) {
2782 PositionWindowOnPrimaryScreen( g_layout_globals.m_position );
2783 window_set_position( window, g_layout_globals.m_position );
2787 if ( g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED ) {
2788 gtk_window_maximize( window );
2789 WindowPosition default_position( -1, -1, 640, 480 );
2790 window_set_position( window, default_position );
2794 window_set_position( window, g_layout_globals.m_position );
2799 gtk_widget_show( GTK_WIDGET( window ) );
2801 if ( CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft ) {
2803 GtkWidget* vsplit = gtk_vpaned_new();
2805 gtk_box_pack_start( GTK_BOX( vbox ), vsplit, TRUE, TRUE, 0 );
2806 gtk_widget_show( vsplit );
2809 GtkWidget* console_window = Console_constructWindow( window );
2810 gtk_paned_pack2( GTK_PANED( vsplit ), console_window, FALSE, TRUE );
2813 GtkWidget* hsplit = gtk_hpaned_new();
2814 gtk_widget_show( hsplit );
2816 gtk_paned_add1( GTK_PANED( vsplit ), hsplit );
2819 m_pXYWnd = new XYWnd();
2820 m_pXYWnd->SetViewType( XY );
2821 GtkWidget* xy_window = GTK_WIDGET( create_framed_widget( m_pXYWnd->GetWidget() ) );
2824 GtkWidget* vsplit2 = gtk_vpaned_new();
2825 gtk_widget_show( vsplit2 );
2826 m_vSplit2 = vsplit2;
2828 if ( CurrentStyle() == eRegular ) {
2829 gtk_paned_add1( GTK_PANED( hsplit ), xy_window );
2830 gtk_paned_add2( GTK_PANED( hsplit ), vsplit2 );
2834 gtk_paned_add1( GTK_PANED( hsplit ), vsplit2 );
2835 gtk_paned_add2( GTK_PANED( hsplit ), xy_window );
2840 m_pCamWnd = NewCamWnd();
2841 GlobalCamera_setCamWnd( *m_pCamWnd );
2842 CamWnd_setParent( *m_pCamWnd, window );
2843 GtkFrame* camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
2845 gtk_paned_add1( GTK_PANED( vsplit2 ), GTK_WIDGET( camera_window ) );
2848 GtkFrame* texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
2850 gtk_paned_add2( GTK_PANED( vsplit2 ), GTK_WIDGET( texture_window ) );
2855 gtk_paned_set_position( GTK_PANED( m_vSplit ), g_layout_globals.nXYHeight );
2857 if ( CurrentStyle() == eRegular ) {
2858 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nXYWidth );
2862 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nCamWidth );
2865 gtk_paned_set_position( GTK_PANED( m_vSplit2 ), g_layout_globals.nCamHeight );
2867 else if ( CurrentStyle() == eFloating ) {
2869 GtkWindow* window = create_persistent_floating_window( "Camera", m_window );
2870 global_accel_connect_window( window );
2871 g_posCamWnd.connect( window );
2873 gtk_widget_show( GTK_WIDGET( window ) );
2875 m_pCamWnd = NewCamWnd();
2876 GlobalCamera_setCamWnd( *m_pCamWnd );
2879 GtkFrame* frame = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
2880 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( frame ) );
2882 CamWnd_setParent( *m_pCamWnd, window );
2884 g_floating_windows.push_back( GTK_WIDGET( window ) );
2888 GtkWindow* window = create_persistent_floating_window( ViewType_getTitle( XY ), m_window );
2889 global_accel_connect_window( window );
2890 g_posXYWnd.connect( window );
2892 m_pXYWnd = new XYWnd();
2893 m_pXYWnd->m_parent = window;
2894 m_pXYWnd->SetViewType( XY );
2898 GtkFrame* frame = create_framed_widget( m_pXYWnd->GetWidget() );
2899 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( frame ) );
2901 XY_Top_Shown_Construct( window );
2903 g_floating_windows.push_back( GTK_WIDGET( window ) );
2907 GtkWindow* window = create_persistent_floating_window( ViewType_getTitle( XZ ), m_window );
2908 global_accel_connect_window( window );
2909 g_posXZWnd.connect( window );
2911 m_pXZWnd = new XYWnd();
2912 m_pXZWnd->m_parent = window;
2913 m_pXZWnd->SetViewType( XZ );
2916 GtkFrame* frame = create_framed_widget( m_pXZWnd->GetWidget() );
2917 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( frame ) );
2920 XZ_Front_Shown_Construct( window );
2922 g_floating_windows.push_back( GTK_WIDGET( window ) );
2926 GtkWindow* window = create_persistent_floating_window( ViewType_getTitle( YZ ), m_window );
2927 global_accel_connect_window( window );
2928 g_posYZWnd.connect( window );
2930 m_pYZWnd = new XYWnd();
2931 m_pYZWnd->m_parent = window;
2932 m_pYZWnd->SetViewType( YZ );
2935 GtkFrame* frame = create_framed_widget( m_pYZWnd->GetWidget() );
2936 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( frame ) );
2939 YZ_Side_Shown_Construct( window );
2941 g_floating_windows.push_back( GTK_WIDGET( window ) );
2945 GtkFrame* frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
2946 g_page_textures = GroupDialog_addPage( "Textures", GTK_WIDGET( frame ), TextureBrowserExportTitleCaller() );
2953 m_pCamWnd = NewCamWnd();
2954 GlobalCamera_setCamWnd( *m_pCamWnd );
2955 CamWnd_setParent( *m_pCamWnd, window );
2957 GtkWidget* camera = CamWnd_getWidget( *m_pCamWnd );
2959 m_pYZWnd = new XYWnd();
2960 m_pYZWnd->SetViewType( YZ );
2962 GtkWidget* yz = m_pYZWnd->GetWidget();
2964 m_pXYWnd = new XYWnd();
2965 m_pXYWnd->SetViewType( XY );
2967 GtkWidget* xy = m_pXYWnd->GetWidget();
2969 m_pXZWnd = new XYWnd();
2970 m_pXZWnd->SetViewType( XZ );
2972 GtkWidget* xz = m_pXZWnd->GetWidget();
2974 GtkHPaned* split = create_split_views( camera, yz, xy, xz );
2975 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( split ), TRUE, TRUE, 0 );
2978 GtkFrame* frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
2979 g_page_textures = GroupDialog_addPage( "Textures", GTK_WIDGET( frame ), TextureBrowserExportTitleCaller() );
2983 EntityList_constructWindow( window );
2984 PreferencesDialog_constructWindow( window );
2985 FindTextureDialog_constructWindow( window );
2986 SurfaceInspector_constructWindow( window );
2987 PatchInspector_constructWindow( window );
2989 SetActiveXY( m_pXYWnd );
2991 AddGridChangeCallback( SetGridStatusCaller( *this ) );
2992 AddGridChangeCallback( ReferenceCaller<MainFrame, XY_UpdateAllWindows>( *this ) );
2994 g_defaultToolMode = DragMode;
2995 g_defaultToolMode();
2996 SetStatusText( m_command_status, c_TranslateMode_status );
2998 EverySecondTimer_enable();
3000 //GlobalShortcuts_reportUnregistered();
3003 void MainFrame::SaveWindowInfo(){
3004 if ( !FloatingGroupDialog() ) {
3005 g_layout_globals.nXYHeight = gtk_paned_get_position( GTK_PANED( m_vSplit ) );
3007 if ( CurrentStyle() != eRegular ) {
3008 g_layout_globals.nCamWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3012 g_layout_globals.nXYWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3015 g_layout_globals.nCamHeight = gtk_paned_get_position( GTK_PANED( m_vSplit2 ) );
3018 g_layout_globals.m_position = m_position_tracker.getPosition();
3020 g_layout_globals.nState = gdk_window_get_state( GTK_WIDGET( m_window )->window );
3023 void MainFrame::Shutdown(){
3024 EverySecondTimer_disable();
3026 EntityList_destroyWindow();
3035 TextureBrowser_destroyWindow();
3037 DeleteCamWnd( m_pCamWnd );
3040 PreferencesDialog_destroyWindow();
3041 SurfaceInspector_destroyWindow();
3042 FindTextureDialog_destroyWindow();
3043 PatchInspector_destroyWindow();
3045 g_DbgDlg.destroyWindow();
3047 // destroying group-dialog last because it may contain texture-browser
3048 GroupDialog_destroyWindow();
3051 void MainFrame::RedrawStatusText(){
3052 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_command_status] ), m_command_status.c_str() );
3053 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_position_status] ), m_position_status.c_str() );
3054 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_brushcount_status] ), m_brushcount_status.c_str() );
3055 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_texture_status] ), m_texture_status.c_str() );
3056 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_grid_status] ), m_grid_status.c_str() );
3059 void MainFrame::UpdateStatusText(){
3060 m_idleRedrawStatusText.queueDraw();
3063 void MainFrame::SetStatusText( CopiedString& status_text, const char* pText ){
3064 status_text = pText;
3068 void Sys_Status( const char* status ){
3069 if ( g_pParentWnd != 0 ) {
3070 g_pParentWnd->SetStatusText( g_pParentWnd->m_command_status, status );
3074 int getRotateIncrement(){
3075 return static_cast<int>( g_si_globals.rotate );
3078 int getFarClipDistance(){
3079 return g_camwindow_globals.m_nCubicScale;
3082 float ( *GridStatus_getGridSize )() = GetGridSize;
3083 int ( *GridStatus_getRotateIncrement )() = getRotateIncrement;
3084 int ( *GridStatus_getFarClipDistance )() = getFarClipDistance;
3085 bool ( *GridStatus_getTextureLockEnabled )();
3087 void MainFrame::SetGridStatus(){
3088 StringOutputStream status( 64 );
3089 const char* lock = ( GridStatus_getTextureLockEnabled() ) ? "ON" : "OFF";
3090 status << ( GetSnapGridSize() > 0 ? "G:" : "g:" ) << GridStatus_getGridSize()
3091 << " R:" << GridStatus_getRotateIncrement()
3092 << " C:" << GridStatus_getFarClipDistance()
3094 SetStatusText( m_grid_status, status.c_str() );
3097 void GridStatus_onTextureLockEnabledChanged(){
3098 if ( g_pParentWnd != 0 ) {
3099 g_pParentWnd->SetGridStatus();
3103 void GlobalGL_sharedContextCreated(){
3104 GLFont *g_font = NULL;
3106 // report OpenGL information
3107 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) << "\n";
3108 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) << "\n";
3109 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) << "\n";
3110 globalOutputStream() << "GL_EXTENSIONS: " << reinterpret_cast<const char*>( glGetString( GL_EXTENSIONS ) ) << "\n";
3112 QGL_sharedContextCreated( GlobalOpenGL() );
3114 ShaderCache_extensionsInitialised();
3116 GlobalShaderCache().realise();
3120 /* win32 is dodgy here, just use courier new then */
3121 g_font = glfont_create( "arial 9" );
3123 GtkSettings *settings = gtk_settings_get_default();
3125 g_object_get( settings, "gtk-font-name", &fontname, NULL );
3126 g_font = glfont_create( fontname );
3129 GlobalOpenGL().m_font = g_font;
3132 void GlobalGL_sharedContextDestroyed(){
3133 Textures_Unrealise();
3134 GlobalShaderCache().unrealise();
3136 QGL_sharedContextDestroyed( GlobalOpenGL() );
3140 void Layout_constructPreferences( PreferencesPage& page ){
3142 const char* layouts[] = { "window1.png", "window2.png", "window3.png", "window4.png" };
3143 page.appendRadioIcons(
3145 STRING_ARRAY_RANGE( layouts ),
3146 LatchedIntImportCaller( g_Layout_viewStyle ),
3147 IntExportCaller( g_Layout_viewStyle.m_latched )
3150 page.appendCheckBox(
3151 "", "Detachable Menus",
3152 LatchedBoolImportCaller( g_Layout_enableDetachableMenus ),
3153 BoolExportCaller( g_Layout_enableDetachableMenus.m_latched )
3155 if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) {
3156 page.appendCheckBox(
3157 "", "Patch Toolbar",
3158 LatchedBoolImportCaller( g_Layout_enablePatchToolbar ),
3159 BoolExportCaller( g_Layout_enablePatchToolbar.m_latched )
3162 page.appendCheckBox(
3163 "", "Plugin Toolbar",
3164 LatchedBoolImportCaller( g_Layout_enablePluginToolbar ),
3165 BoolExportCaller( g_Layout_enablePluginToolbar.m_latched )
3169 void Layout_constructPage( PreferenceGroup& group ){
3170 PreferencesPage page( group.createPage( "Layout", "Layout Preferences" ) );
3171 Layout_constructPreferences( page );
3174 void Layout_registerPreferencesPage(){
3175 PreferencesDialog_addInterfacePage( FreeCaller1<PreferenceGroup&, Layout_constructPage>() );
3179 #include "preferencesystem.h"
3180 #include "stringio.h"
3182 void MainFrame_Construct(){
3183 GlobalCommands_insert( "OpenManual", FreeCaller<OpenHelpURL>(), Accelerator( GDK_F1 ) );
3185 GlobalCommands_insert( "Sleep", FreeCaller<thunk_OnSleep>(), Accelerator( 'P', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3186 GlobalCommands_insert( "NewMap", FreeCaller<NewMap>() );
3187 GlobalCommands_insert( "OpenMap", FreeCaller<OpenMap>(), Accelerator( 'O', (GdkModifierType)GDK_CONTROL_MASK ) );
3188 GlobalCommands_insert( "ImportMap", FreeCaller<ImportMap>() );
3189 GlobalCommands_insert( "SaveMap", FreeCaller<SaveMap>(), Accelerator( 'S', (GdkModifierType)GDK_CONTROL_MASK ) );
3190 GlobalCommands_insert( "SaveMapAs", FreeCaller<SaveMapAs>() );
3191 GlobalCommands_insert( "SaveSelected", FreeCaller<ExportMap>() );
3192 GlobalCommands_insert( "SaveRegion", FreeCaller<SaveRegion>() );
3193 GlobalCommands_insert( "RefreshReferences", FreeCaller<RefreshReferences>() );
3194 GlobalCommands_insert( "ProjectSettings", FreeCaller<DoProjectSettings>() );
3195 GlobalCommands_insert( "CheckForUpdate", FreeCaller<OpenUpdateURL>() );
3196 GlobalCommands_insert( "Exit", FreeCaller<Exit>() );
3198 GlobalCommands_insert( "Undo", FreeCaller<Undo>(), Accelerator( 'Z', (GdkModifierType)GDK_CONTROL_MASK ) );
3199 GlobalCommands_insert( "Redo", FreeCaller<Redo>(), Accelerator( 'Y', (GdkModifierType)GDK_CONTROL_MASK ) );
3200 GlobalCommands_insert( "Copy", FreeCaller<Copy>(), Accelerator( 'C', (GdkModifierType)GDK_CONTROL_MASK ) );
3201 GlobalCommands_insert( "Paste", FreeCaller<Paste>(), Accelerator( 'V', (GdkModifierType)GDK_CONTROL_MASK ) );
3202 GlobalCommands_insert( "PasteToCamera", FreeCaller<PasteToCamera>(), Accelerator( 'V', (GdkModifierType)GDK_MOD1_MASK ) );
3203 GlobalCommands_insert( "CloneSelection", FreeCaller<Selection_Clone>(), Accelerator( GDK_space ) );
3204 GlobalCommands_insert( "CloneSelectionAndMakeUnique", FreeCaller<Selection_Clone_MakeUnique>(), Accelerator( GDK_space, (GdkModifierType)GDK_SHIFT_MASK ) );
3205 GlobalCommands_insert( "DeleteSelection", FreeCaller<deleteSelection>(), Accelerator( GDK_BackSpace ) );
3206 GlobalCommands_insert( "ParentSelection", FreeCaller<Scene_parentSelected>() );
3207 GlobalCommands_insert( "UnSelectSelection", FreeCaller<Selection_Deselect>(), Accelerator( GDK_Escape ) );
3208 GlobalCommands_insert( "InvertSelection", FreeCaller<Select_Invert>(), Accelerator( 'I' ) );
3209 GlobalCommands_insert( "SelectInside", FreeCaller<Select_Inside>() );
3210 GlobalCommands_insert( "SelectTouching", FreeCaller<Select_Touching>() );
3211 GlobalCommands_insert( "ExpandSelectionToEntities", FreeCaller<Scene_ExpandSelectionToEntities>(), Accelerator( 'E', (GdkModifierType)( GDK_MOD1_MASK | GDK_CONTROL_MASK ) ) );
3212 GlobalCommands_insert( "Preferences", FreeCaller<PreferencesDialog_showDialog>(), Accelerator( 'P' ) );
3214 GlobalCommands_insert( "ToggleConsole", FreeCaller<Console_ToggleShow>(), Accelerator( 'O' ) );
3215 GlobalCommands_insert( "ToggleEntityInspector", FreeCaller<EntityInspector_ToggleShow>(), Accelerator( 'N' ) );
3216 GlobalCommands_insert( "EntityList", FreeCaller<EntityList_toggleShown>(), Accelerator( 'L' ) );
3218 GlobalCommands_insert( "ShowHidden", FreeCaller<Select_ShowAllHidden>(), Accelerator( 'H', (GdkModifierType)GDK_SHIFT_MASK ) );
3219 GlobalCommands_insert( "HideSelected", FreeCaller<HideSelected>(), Accelerator( 'H' ) );
3221 GlobalToggles_insert( "DragVertices", FreeCaller<SelectVertexMode>(), ToggleItem::AddCallbackCaller( g_vertexMode_button ), Accelerator( 'V' ) );
3222 GlobalToggles_insert( "DragEdges", FreeCaller<SelectEdgeMode>(), ToggleItem::AddCallbackCaller( g_edgeMode_button ), Accelerator( 'E' ) );
3223 GlobalToggles_insert( "DragFaces", FreeCaller<SelectFaceMode>(), ToggleItem::AddCallbackCaller( g_faceMode_button ), Accelerator( 'F' ) );
3225 GlobalCommands_insert( "MirrorSelectionX", FreeCaller<Selection_Flipx>() );
3226 GlobalCommands_insert( "RotateSelectionX", FreeCaller<Selection_Rotatex>() );
3227 GlobalCommands_insert( "MirrorSelectionY", FreeCaller<Selection_Flipy>() );
3228 GlobalCommands_insert( "RotateSelectionY", FreeCaller<Selection_Rotatey>() );
3229 GlobalCommands_insert( "MirrorSelectionZ", FreeCaller<Selection_Flipz>() );
3230 GlobalCommands_insert( "RotateSelectionZ", FreeCaller<Selection_Rotatez>() );
3232 GlobalCommands_insert( "ArbitraryRotation", FreeCaller<DoRotateDlg>() );
3233 GlobalCommands_insert( "ArbitraryScale", FreeCaller<DoScaleDlg>() );
3235 GlobalCommands_insert( "BuildMenuCustomize", FreeCaller<DoBuildMenu>() );
3237 GlobalCommands_insert( "FindBrush", FreeCaller<DoFind>() );
3239 GlobalCommands_insert( "MapInfo", FreeCaller<DoMapInfo>(), Accelerator( 'M' ) );
3242 GlobalToggles_insert( "ToggleClipper", FreeCaller<ClipperMode>(), ToggleItem::AddCallbackCaller( g_clipper_button ), Accelerator( 'X' ) );
3244 GlobalToggles_insert( "MouseTranslate", FreeCaller<TranslateMode>(), ToggleItem::AddCallbackCaller( g_translatemode_button ), Accelerator( 'W' ) );
3245 GlobalToggles_insert( "MouseRotate", FreeCaller<RotateMode>(), ToggleItem::AddCallbackCaller( g_rotatemode_button ), Accelerator( 'R' ) );
3246 GlobalToggles_insert( "MouseScale", FreeCaller<ScaleMode>(), ToggleItem::AddCallbackCaller( g_scalemode_button ) );
3247 GlobalToggles_insert( "MouseDrag", FreeCaller<DragMode>(), ToggleItem::AddCallbackCaller( g_dragmode_button ), Accelerator( 'Q' ) );
3249 GlobalCommands_insert( "ColorSchemeOriginal", FreeCaller<ColorScheme_Original>() );
3250 GlobalCommands_insert( "ColorSchemeQER", FreeCaller<ColorScheme_QER>() );
3251 GlobalCommands_insert( "ColorSchemeBlackAndGreen", FreeCaller<ColorScheme_Black>() );
3252 GlobalCommands_insert( "ColorSchemeYdnar", FreeCaller<ColorScheme_Ydnar>() );
3253 GlobalCommands_insert( "ChooseTextureBackgroundColor", makeCallback( g_ColoursMenu.m_textureback ) );
3254 GlobalCommands_insert( "ChooseGridBackgroundColor", makeCallback( g_ColoursMenu.m_xyback ) );
3255 GlobalCommands_insert( "ChooseGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor ) );
3256 GlobalCommands_insert( "ChooseGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor ) );
3257 GlobalCommands_insert( "ChooseSmallGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor_alt ) );
3258 GlobalCommands_insert( "ChooseSmallGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor_alt ) );
3259 GlobalCommands_insert( "ChooseGridTextColor", makeCallback( g_ColoursMenu.m_gridtext ) );
3260 GlobalCommands_insert( "ChooseGridBlockColor", makeCallback( g_ColoursMenu.m_gridblock ) );
3261 GlobalCommands_insert( "ChooseBrushColor", makeCallback( g_ColoursMenu.m_brush ) );
3262 GlobalCommands_insert( "ChooseCameraBackgroundColor", makeCallback( g_ColoursMenu.m_cameraback ) );
3263 GlobalCommands_insert( "ChooseSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush ) );
3264 GlobalCommands_insert( "ChooseCameraSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush3d ) );
3265 GlobalCommands_insert( "ChooseClipperColor", makeCallback( g_ColoursMenu.m_clipper ) );
3266 GlobalCommands_insert( "ChooseOrthoViewNameColor", makeCallback( g_ColoursMenu.m_viewname ) );
3269 GlobalCommands_insert( "CSGSubtract", FreeCaller<CSG_Subtract>(), Accelerator( 'U', (GdkModifierType)GDK_SHIFT_MASK ) );
3270 GlobalCommands_insert( "CSGMerge", FreeCaller<CSG_Merge>(), Accelerator( 'U', (GdkModifierType)GDK_CONTROL_MASK ) );
3271 GlobalCommands_insert( "CSGHollow", FreeCaller<CSG_MakeHollow>() );
3273 Grid_registerCommands();
3275 GlobalCommands_insert( "SnapToGrid", FreeCaller<Selection_SnapToGrid>(), Accelerator( 'G', (GdkModifierType)GDK_CONTROL_MASK ) );
3277 GlobalCommands_insert( "SelectAllOfType", FreeCaller<Select_AllOfType>(), Accelerator( 'A', (GdkModifierType)GDK_SHIFT_MASK ) );
3279 GlobalCommands_insert( "TexRotateClock", FreeCaller<Texdef_RotateClockwise>(), Accelerator( GDK_Next, (GdkModifierType)GDK_SHIFT_MASK ) );
3280 GlobalCommands_insert( "TexRotateCounter", FreeCaller<Texdef_RotateAntiClockwise>(), Accelerator( GDK_Prior, (GdkModifierType)GDK_SHIFT_MASK ) );
3281 GlobalCommands_insert( "TexScaleUp", FreeCaller<Texdef_ScaleUp>(), Accelerator( GDK_Up, (GdkModifierType)GDK_CONTROL_MASK ) );
3282 GlobalCommands_insert( "TexScaleDown", FreeCaller<Texdef_ScaleDown>(), Accelerator( GDK_Down, (GdkModifierType)GDK_CONTROL_MASK ) );
3283 GlobalCommands_insert( "TexScaleLeft", FreeCaller<Texdef_ScaleLeft>(), Accelerator( GDK_Left, (GdkModifierType)GDK_CONTROL_MASK ) );
3284 GlobalCommands_insert( "TexScaleRight", FreeCaller<Texdef_ScaleRight>(), Accelerator( GDK_Right, (GdkModifierType)GDK_CONTROL_MASK ) );
3285 GlobalCommands_insert( "TexShiftUp", FreeCaller<Texdef_ShiftUp>(), Accelerator( GDK_Up, (GdkModifierType)GDK_SHIFT_MASK ) );
3286 GlobalCommands_insert( "TexShiftDown", FreeCaller<Texdef_ShiftDown>(), Accelerator( GDK_Down, (GdkModifierType)GDK_SHIFT_MASK ) );
3287 GlobalCommands_insert( "TexShiftLeft", FreeCaller<Texdef_ShiftLeft>(), Accelerator( GDK_Left, (GdkModifierType)GDK_SHIFT_MASK ) );
3288 GlobalCommands_insert( "TexShiftRight", FreeCaller<Texdef_ShiftRight>(), Accelerator( GDK_Right, (GdkModifierType)GDK_SHIFT_MASK ) );
3290 GlobalCommands_insert( "MoveSelectionDOWN", FreeCaller<Selection_MoveDown>(), Accelerator( GDK_KP_Subtract ) );
3291 GlobalCommands_insert( "MoveSelectionUP", FreeCaller<Selection_MoveUp>(), Accelerator( GDK_KP_Add ) );
3293 GlobalCommands_insert( "SelectNudgeLeft", FreeCaller<Selection_NudgeLeft>(), Accelerator( GDK_Left, (GdkModifierType)GDK_MOD1_MASK ) );
3294 GlobalCommands_insert( "SelectNudgeRight", FreeCaller<Selection_NudgeRight>(), Accelerator( GDK_Right, (GdkModifierType)GDK_MOD1_MASK ) );
3295 GlobalCommands_insert( "SelectNudgeUp", FreeCaller<Selection_NudgeUp>(), Accelerator( GDK_Up, (GdkModifierType)GDK_MOD1_MASK ) );
3296 GlobalCommands_insert( "SelectNudgeDown", FreeCaller<Selection_NudgeDown>(), Accelerator( GDK_Down, (GdkModifierType)GDK_MOD1_MASK ) );
3298 Patch_registerCommands();
3299 XYShow_registerCommands();
3301 typedef FreeCaller1<const Selectable&, ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3302 GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() );
3304 GlobalPreferenceSystem().registerPreference( "DetachableMenus", BoolImportStringCaller( g_Layout_enableDetachableMenus.m_latched ), BoolExportStringCaller( g_Layout_enableDetachableMenus.m_latched ) );
3305 GlobalPreferenceSystem().registerPreference( "PatchToolBar", BoolImportStringCaller( g_Layout_enablePatchToolbar.m_latched ), BoolExportStringCaller( g_Layout_enablePatchToolbar.m_latched ) );
3306 GlobalPreferenceSystem().registerPreference( "PluginToolBar", BoolImportStringCaller( g_Layout_enablePluginToolbar.m_latched ), BoolExportStringCaller( g_Layout_enablePluginToolbar.m_latched ) );
3307 GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", IntImportStringCaller( g_Layout_viewStyle.m_latched ), IntExportStringCaller( g_Layout_viewStyle.m_latched ) );
3308 GlobalPreferenceSystem().registerPreference( "XYHeight", IntImportStringCaller( g_layout_globals.nXYHeight ), IntExportStringCaller( g_layout_globals.nXYHeight ) );
3309 GlobalPreferenceSystem().registerPreference( "XYWidth", IntImportStringCaller( g_layout_globals.nXYWidth ), IntExportStringCaller( g_layout_globals.nXYWidth ) );
3310 GlobalPreferenceSystem().registerPreference( "CamWidth", IntImportStringCaller( g_layout_globals.nCamWidth ), IntExportStringCaller( g_layout_globals.nCamWidth ) );
3311 GlobalPreferenceSystem().registerPreference( "CamHeight", IntImportStringCaller( g_layout_globals.nCamHeight ), IntExportStringCaller( g_layout_globals.nCamHeight ) );
3313 GlobalPreferenceSystem().registerPreference( "State", IntImportStringCaller( g_layout_globals.nState ), IntExportStringCaller( g_layout_globals.nState ) );
3314 GlobalPreferenceSystem().registerPreference( "PositionX", IntImportStringCaller( g_layout_globals.m_position.x ), IntExportStringCaller( g_layout_globals.m_position.x ) );
3315 GlobalPreferenceSystem().registerPreference( "PositionY", IntImportStringCaller( g_layout_globals.m_position.y ), IntExportStringCaller( g_layout_globals.m_position.y ) );
3316 GlobalPreferenceSystem().registerPreference( "Width", IntImportStringCaller( g_layout_globals.m_position.w ), IntExportStringCaller( g_layout_globals.m_position.w ) );
3317 GlobalPreferenceSystem().registerPreference( "Height", IntImportStringCaller( g_layout_globals.m_position.h ), IntExportStringCaller( g_layout_globals.m_position.h ) );
3319 GlobalPreferenceSystem().registerPreference( "CamWnd", WindowPositionTrackerImportStringCaller( g_posCamWnd ), WindowPositionTrackerExportStringCaller( g_posCamWnd ) );
3320 GlobalPreferenceSystem().registerPreference( "XYWnd", WindowPositionTrackerImportStringCaller( g_posXYWnd ), WindowPositionTrackerExportStringCaller( g_posXYWnd ) );
3321 GlobalPreferenceSystem().registerPreference( "YZWnd", WindowPositionTrackerImportStringCaller( g_posYZWnd ), WindowPositionTrackerExportStringCaller( g_posYZWnd ) );
3322 GlobalPreferenceSystem().registerPreference( "XZWnd", WindowPositionTrackerImportStringCaller( g_posXZWnd ), WindowPositionTrackerExportStringCaller( g_posXZWnd ) );
3325 const char* ENGINEPATH_ATTRIBUTE =
3326 #if defined( WIN32 )
3328 #elif defined( __APPLE__ )
3330 #elif defined( __linux__ ) || defined ( __FreeBSD__ )
3333 #error "unknown platform"
3336 StringOutputStream path( 256 );
3337 path << DirectoryCleaned( g_pGameDescription->getRequiredKeyValue( ENGINEPATH_ATTRIBUTE ) );
3338 g_strEnginePath = path.c_str();
3341 GlobalPreferenceSystem().registerPreference( "EnginePath", CopiedStringImportStringCaller( g_strEnginePath ), CopiedStringExportStringCaller( g_strEnginePath ) );
3343 g_Layout_viewStyle.useLatched();
3344 g_Layout_enableDetachableMenus.useLatched();
3345 g_Layout_enablePatchToolbar.useLatched();
3346 g_Layout_enablePluginToolbar.useLatched();
3348 Layout_registerPreferencesPage();
3349 Paths_registerPreferencesPage();
3351 g_brushCount.setCountChangedCallback( FreeCaller<QE_brushCountChanged>() );
3352 g_entityCount.setCountChangedCallback( FreeCaller<QE_entityCountChanged>() );
3353 GlobalEntityCreator().setCounter( &g_entityCount );
3355 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3356 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3358 GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver );
3361 void MainFrame_Destroy(){
3362 GlobalEntityClassManager().detach( g_WorldspawnColourEntityClassObserver );
3364 GlobalEntityCreator().setCounter( 0 );
3365 g_entityCount.setCountChangedCallback( Callback() );
3366 g_brushCount.setCountChangedCallback( Callback() );
3370 void GLWindow_Construct(){
3371 GlobalPreferenceSystem().registerPreference( "MouseButtons", IntImportStringCaller( g_glwindow_globals.m_nMouseType ), IntExportStringCaller( g_glwindow_globals.m_nMouseType ) );
3374 void GLWindow_Destroy(){