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"
119 #include "texwindow.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;
164 if ( !g_vfsInitialized ) return;
165 GlobalFileSystem().clear();
167 GlobalFileSystem().refresh();
168 g_vfsInitialized = true;
169 // also refresh texture browser
170 TextureBrowser_RefreshShaders();
177 class VFSModuleObserver : public ModuleObserver
188 VFSModuleObserver g_VFSModuleObserver;
190 void VFS_Construct(){
191 Radiant_attachHomePathsObserver( g_VFSModuleObserver );
194 Radiant_detachHomePathsObserver( g_VFSModuleObserver );
202 const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}};
203 #define qREFKNOWNFOLDERID GUID
204 #define qKF_FLAG_CREATE 0x8000
205 #define qKF_FLAG_NO_ALIAS 0x1000
206 typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath );
207 static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath;
209 void HomePaths_Realise(){
212 const char* prefix = g_pGameDescription->getKeyValue( "prefix" );
213 if ( !string_empty( prefix ) ) {
214 StringOutputStream path( 256 );
216 #if defined( __APPLE__ )
218 path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/";
219 if ( file_is_directory( path.c_str() ) ) {
220 g_qeglobals.m_userEnginePath = path.c_str();
224 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
228 TCHAR mydocsdir[MAX_PATH + 1];
230 HMODULE shfolder = LoadLibrary( "shfolder.dll" );
232 qSHGetKnownFolderPath = (qSHGetKnownFolderPath_t *) GetProcAddress( shfolder, "SHGetKnownFolderPath" );
235 qSHGetKnownFolderPath = NULL;
237 CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
238 if ( qSHGetKnownFolderPath && qSHGetKnownFolderPath( qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw ) == S_OK ) {
239 memset( mydocsdir, 0, sizeof( mydocsdir ) );
240 wcstombs( mydocsdir, mydocsdirw, sizeof( mydocsdir ) - 1 );
241 CoTaskMemFree( mydocsdirw );
243 path << DirectoryCleaned( mydocsdir ) << ( prefix + 1 ) << "/";
244 if ( file_is_directory( path.c_str() ) ) {
245 g_qeglobals.m_userEnginePath = path.c_str();
247 FreeLibrary( shfolder );
253 FreeLibrary( shfolder );
255 if ( SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir ) ) {
257 path << DirectoryCleaned( mydocsdir ) << "My Games/" << ( prefix + 1 ) << "/";
258 // win32: only add it if it already exists
259 if ( file_is_directory( path.c_str() ) ) {
260 g_qeglobals.m_userEnginePath = path.c_str();
268 path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/";
269 g_qeglobals.m_userEnginePath = path.c_str();
274 g_qeglobals.m_userEnginePath = EnginePath_get();
278 Q_mkdir( g_qeglobals.m_userEnginePath.c_str() );
281 StringOutputStream path( 256 );
282 path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
283 g_qeglobals.m_userGamePath = path.c_str();
285 ASSERT_MESSAGE( !string_empty( g_qeglobals.m_userGamePath.c_str() ), "HomePaths_Realise: user-game-path is empty" );
286 Q_mkdir( g_qeglobals.m_userGamePath.c_str() );
289 ModuleObservers g_homePathObservers;
291 void Radiant_attachHomePathsObserver( ModuleObserver& observer ){
292 g_homePathObservers.attach( observer );
295 void Radiant_detachHomePathsObserver( ModuleObserver& observer ){
296 g_homePathObservers.detach( observer );
299 class HomePathsModuleObserver : public ModuleObserver
301 std::size_t m_unrealised;
303 HomePathsModuleObserver() : m_unrealised( 1 ){
306 if ( --m_unrealised == 0 ) {
308 g_homePathObservers.realise();
312 if ( ++m_unrealised == 1 ) {
313 g_homePathObservers.unrealise();
318 HomePathsModuleObserver g_HomePathsModuleObserver;
320 void HomePaths_Construct(){
321 Radiant_attachEnginePathObserver( g_HomePathsModuleObserver );
323 void HomePaths_Destroy(){
324 Radiant_detachEnginePathObserver( g_HomePathsModuleObserver );
330 CopiedString g_strEnginePath;
331 ModuleObservers g_enginePathObservers;
332 std::size_t g_enginepath_unrealised = 1;
334 void Radiant_attachEnginePathObserver( ModuleObserver& observer ){
335 g_enginePathObservers.attach( observer );
338 void Radiant_detachEnginePathObserver( ModuleObserver& observer ){
339 g_enginePathObservers.detach( observer );
343 void EnginePath_Realise(){
344 if ( --g_enginepath_unrealised == 0 ) {
345 g_enginePathObservers.realise();
350 const char* EnginePath_get(){
351 ASSERT_MESSAGE( g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised" );
352 return g_strEnginePath.c_str();
355 void EnginePath_Unrealise(){
356 if ( ++g_enginepath_unrealised == 1 ) {
357 g_enginePathObservers.unrealise();
361 void setEnginePath( const char* path ){
362 StringOutputStream buffer( 256 );
363 buffer << DirectoryCleaned( path );
364 if ( !path_equal( buffer.c_str(), g_strEnginePath.c_str() ) ) {
366 while ( !ConfirmModified( "Paths Changed" ) )
368 if ( Map_Unnamed( g_map ) ) {
379 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Changing Engine Path" );
381 EnginePath_Unrealise();
383 g_strEnginePath = buffer.c_str();
385 EnginePath_Realise();
392 CopiedString g_strAppPath; ///< holds the full path of the executable
394 const char* AppPath_get(){
395 return g_strAppPath.c_str();
398 /// the path to the local rc-dir
399 const char* LocalRcPath_get( void ){
400 static CopiedString rc_path;
401 if ( rc_path.empty() ) {
402 StringOutputStream stream( 256 );
403 stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
404 rc_path = stream.c_str();
406 return rc_path.c_str();
409 /// directory for temp files
410 /// NOTE: on *nix this is were we check for .pid
411 CopiedString g_strSettingsPath;
412 const char* SettingsPath_get(){
413 return g_strSettingsPath.c_str();
418 points to the game tools directory, for instance
419 C:/Program Files/Quake III Arena/GtkRadiant
421 this is one of the main variables that are configured by the game selection on startup
422 [GameToolsPath]/plugins
423 [GameToolsPath]/modules
426 CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog
428 const char* GameToolsPath_get(){
429 return g_strGameToolsPath.c_str();
432 void EnginePathImport( CopiedString& self, const char* value ){
433 setEnginePath( value );
435 typedef ReferenceCaller1<CopiedString, const char*, EnginePathImport> EnginePathImportCaller;
437 void Paths_constructPreferences( PreferencesPage& page ){
438 page.appendPathEntry( "Engine Path", true,
439 StringImportCallback( EnginePathImportCaller( g_strEnginePath ) ),
440 StringExportCallback( StringExportCaller( g_strEnginePath ) )
443 void Paths_constructPage( PreferenceGroup& group ){
444 PreferencesPage page( group.createPage( "Paths", "Path Settings" ) );
445 Paths_constructPreferences( page );
447 void Paths_registerPreferencesPage(){
448 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Paths_constructPage>() );
452 class PathsDialog : public Dialog
455 GtkWindow* BuildDialog(){
456 GtkFrame* frame = create_dialog_frame( "Path settings", GTK_SHADOW_ETCHED_IN );
458 GtkVBox* vbox2 = create_dialog_vbox( 0, 4 );
459 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( vbox2 ) );
462 PreferencesPage preferencesPage( *this, GTK_WIDGET( vbox2 ) );
463 Paths_constructPreferences( preferencesPage );
466 return create_simple_modal_dialog_window( "Engine Path Not Found", m_modal, GTK_WIDGET( frame ) );
470 PathsDialog g_PathsDialog;
472 void EnginePath_verify(){
473 if ( !file_exists( g_strEnginePath.c_str() ) ) {
474 g_PathsDialog.Create();
475 g_PathsDialog.DoModal();
476 g_PathsDialog.Destroy();
482 CopiedString g_gamename;
483 CopiedString g_gamemode;
484 ModuleObservers g_gameNameObservers;
485 ModuleObservers g_gameModeObservers;
488 void Radiant_attachGameNameObserver( ModuleObserver& observer ){
489 g_gameNameObservers.attach( observer );
492 void Radiant_detachGameNameObserver( ModuleObserver& observer ){
493 g_gameNameObservers.detach( observer );
496 const char* basegame_get(){
497 return g_pGameDescription->getRequiredKeyValue( "basegame" );
500 const char* gamename_get(){
501 const char* gamename = g_gamename.c_str();
502 if ( string_empty( gamename ) ) {
503 return basegame_get();
508 void gamename_set( const char* gamename ){
509 if ( !string_equal( gamename, g_gamename.c_str() ) ) {
510 g_gameNameObservers.unrealise();
511 g_gamename = gamename;
512 g_gameNameObservers.realise();
516 void Radiant_attachGameModeObserver( ModuleObserver& observer ){
517 g_gameModeObservers.attach( observer );
520 void Radiant_detachGameModeObserver( ModuleObserver& observer ){
521 g_gameModeObservers.detach( observer );
524 const char* gamemode_get(){
525 return g_gamemode.c_str();
528 void gamemode_set( const char* gamemode ){
529 if ( !string_equal( gamemode, g_gamemode.c_str() ) ) {
530 g_gameModeObservers.unrealise();
531 g_gamemode = gamemode;
532 g_gameModeObservers.realise();
543 CLoadModule( const char* path ) : m_path( path ){
545 void operator()( const char* name ) const {
547 ASSERT_MESSAGE( strlen( m_path ) + strlen( name ) < 1024, "" );
548 strcpy( fullname, m_path );
549 strcat( fullname, name );
550 globalOutputStream() << "Found '" << fullname << "'\n";
551 GlobalModuleServer_loadModule( fullname );
555 const char* const c_library_extension =
556 #if defined( CMAKE_SHARED_MODULE_SUFFIX )
557 CMAKE_SHARED_MODULE_SUFFIX
558 #elif defined( WIN32 )
560 #elif defined ( __APPLE__ )
562 #elif defined( __linux__ ) || defined ( __FreeBSD__ )
567 void Radiant_loadModules( const char* path ){
568 Directory_forEach( path, MatchFileExtension<CLoadModule>( c_library_extension, CLoadModule( path ) ) );
571 void Radiant_loadModulesFromRoot( const char* directory ){
573 StringOutputStream path( 256 );
574 path << directory << g_pluginsDir;
575 Radiant_loadModules( path.c_str() );
578 if ( !string_equal( g_pluginsDir, g_modulesDir ) ) {
579 StringOutputStream path( 256 );
580 path << directory << g_modulesDir;
581 Radiant_loadModules( path.c_str() );
585 //! Make COLOR_BRUSHES override worldspawn eclass colour.
586 void SetWorldspawnColour( const Vector3& colour ){
587 EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert( "worldspawn", true );
588 eclass_release_state( worldspawn );
589 worldspawn->color = colour;
590 eclass_capture_state( worldspawn );
594 class WorldspawnColourEntityClassObserver : public ModuleObserver
596 std::size_t m_unrealised;
598 WorldspawnColourEntityClassObserver() : m_unrealised( 1 ){
601 if ( --m_unrealised == 0 ) {
602 SetWorldspawnColour( g_xywindow_globals.color_brushes );
606 if ( ++m_unrealised == 1 ) {
611 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
614 ModuleObservers g_gameToolsPathObservers;
616 void Radiant_attachGameToolsPathObserver( ModuleObserver& observer ){
617 g_gameToolsPathObservers.attach( observer );
620 void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ){
621 g_gameToolsPathObservers.detach( observer );
624 void Radiant_Initialise(){
625 GlobalModuleServer_Initialise();
627 Radiant_loadModulesFromRoot( AppPath_get() );
631 bool success = Radiant_Construct( GlobalModuleServer_get() );
632 ASSERT_MESSAGE( success, "module system failed to initialise - see radiant.log for error messages" );
634 g_gameToolsPathObservers.realise();
635 g_gameModeObservers.realise();
636 g_gameNameObservers.realise();
639 void Radiant_Shutdown(){
640 g_gameNameObservers.unrealise();
641 g_gameModeObservers.unrealise();
642 g_gameToolsPathObservers.unrealise();
644 if ( !g_preferences_globals.disable_ini ) {
645 globalOutputStream() << "Start writing prefs\n";
647 globalOutputStream() << "Done prefs\n";
652 GlobalModuleServer_Shutdown();
656 if ( ConfirmModified( "Exit Radiant" ) ) {
663 GlobalUndoSystem().undo();
668 GlobalUndoSystem().redo();
672 void deleteSelection(){
673 UndoableCommand undo( "deleteSelected" );
677 void Map_ExportSelected( TextOutputStream& ostream ){
678 Map_ExportSelected( ostream, Map_getFormat( g_map ) );
681 void Map_ImportSelected( TextInputStream& istream ){
682 Map_ImportSelected( istream, Map_getFormat( g_map ) );
685 void Selection_Copy(){
686 clipboard_copy( Map_ExportSelected );
689 void Selection_Paste(){
690 clipboard_paste( Map_ImportSelected );
694 if ( SelectedFaces_empty() ) {
699 SelectedFaces_copyTexture();
704 if ( SelectedFaces_empty() ) {
705 UndoableCommand undo( "paste" );
707 GlobalSelectionSystem().setSelectedAll( false );
712 SelectedFaces_pasteTexture();
716 void PasteToCamera(){
717 CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
718 GlobalSelectionSystem().setSelectedAll( false );
720 UndoableCommand undo( "pasteToCamera" );
724 // Work out the delta
726 Select_GetMid( mid );
727 Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid );
730 GlobalSelectionSystem().translateSelected( delta );
734 void ColorScheme_Original(){
735 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
737 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
738 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
739 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
741 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
742 g_xywindow_globals.color_gridminor = Vector3( 0.75f, 0.75f, 0.75f );
743 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
744 g_xywindow_globals.color_gridminor_alt = Vector3( 0.5f, 0.0f, 0.0f );
745 g_xywindow_globals.color_gridmajor_alt = Vector3( 1.0f, 0.0f, 0.0f );
746 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
747 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
748 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
749 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
750 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
751 SetWorldspawnColour( g_xywindow_globals.color_brushes );
752 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
753 XY_UpdateAllWindows();
756 void ColorScheme_QER(){
757 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
759 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
760 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
761 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
763 g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f );
764 g_xywindow_globals.color_gridminor = Vector3( 1.0f, 1.0f, 1.0f );
765 g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f );
766 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
767 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
768 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
769 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
770 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
771 SetWorldspawnColour( g_xywindow_globals.color_brushes );
772 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
773 XY_UpdateAllWindows();
776 void ColorScheme_Black(){
777 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
779 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
780 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
781 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
783 g_xywindow_globals.color_gridback = Vector3( 0.0f, 0.0f, 0.0f );
784 g_xywindow_globals.color_gridminor = Vector3( 0.2f, 0.2f, 0.2f );
785 g_xywindow_globals.color_gridmajor = Vector3( 0.3f, 0.5f, 0.5f );
786 g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f );
787 g_xywindow_globals.color_gridtext = Vector3( 1.0f, 1.0f, 1.0f );
788 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
789 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
790 g_xywindow_globals.color_brushes = Vector3( 1.0f, 1.0f, 1.0f );
791 SetWorldspawnColour( g_xywindow_globals.color_brushes );
792 g_xywindow_globals.color_viewname = Vector3( 0.7f, 0.7f, 0.0f );
793 XY_UpdateAllWindows();
796 /* ydnar: to emulate maya/max/lightwave color schemes */
797 void ColorScheme_Ydnar(){
798 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) );
800 g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f );
801 g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f );
802 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
804 g_xywindow_globals.color_gridback = Vector3( 0.77f, 0.77f, 0.77f );
805 g_xywindow_globals.color_gridminor = Vector3( 0.83f, 0.83f, 0.83f );
806 g_xywindow_globals.color_gridmajor = Vector3( 0.89f, 0.89f, 0.89f );
807 g_xywindow_globals.color_gridblock = Vector3( 1.0f, 1.0f, 1.0f );
808 g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f );
809 g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f );
810 g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f );
811 g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f );
812 SetWorldspawnColour( g_xywindow_globals.color_brushes );
813 g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f );
814 XY_UpdateAllWindows();
817 typedef Callback1<Vector3&> GetColourCallback;
818 typedef Callback1<const Vector3&> SetColourCallback;
822 GetColourCallback m_get;
823 SetColourCallback m_set;
825 ChooseColour( const GetColourCallback& get, const SetColourCallback& set )
826 : m_get( get ), m_set( set ){
831 color_dialog( GTK_WIDGET( MainFrame_getWindow() ), colour );
838 void Colour_get( const Vector3& colour, Vector3& other ){
841 typedef ConstReferenceCaller1<Vector3, Vector3&, Colour_get> ColourGetCaller;
843 void Colour_set( Vector3& colour, const Vector3& other ){
847 typedef ReferenceCaller1<Vector3, const Vector3&, Colour_set> ColourSetCaller;
849 void BrushColour_set( const Vector3& other ){
850 g_xywindow_globals.color_brushes = other;
851 SetWorldspawnColour( g_xywindow_globals.color_brushes );
854 typedef FreeCaller1<const Vector3&, BrushColour_set> BrushColourSetCaller;
856 void ClipperColour_set( const Vector3& other ){
857 g_xywindow_globals.color_clipper = other;
858 Brush_clipperColourChanged();
861 typedef FreeCaller1<const Vector3&, ClipperColour_set> ClipperColourSetCaller;
863 void TextureBrowserColour_get( Vector3& other ){
864 other = TextureBrowser_getBackgroundColour( GlobalTextureBrowser() );
866 typedef FreeCaller1<Vector3&, TextureBrowserColour_get> TextureBrowserColourGetCaller;
868 void TextureBrowserColour_set( const Vector3& other ){
869 TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), other );
871 typedef FreeCaller1<const Vector3&, TextureBrowserColour_set> TextureBrowserColourSetCaller;
877 ChooseColour m_textureback;
878 ChooseColour m_xyback;
879 ChooseColour m_gridmajor;
880 ChooseColour m_gridminor;
881 ChooseColour m_gridmajor_alt;
882 ChooseColour m_gridminor_alt;
883 ChooseColour m_gridtext;
884 ChooseColour m_gridblock;
885 ChooseColour m_cameraback;
886 ChooseColour m_brush;
887 ChooseColour m_selectedbrush;
888 ChooseColour m_selectedbrush3d;
889 ChooseColour m_clipper;
890 ChooseColour m_viewname;
893 m_textureback( TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller() ),
894 m_xyback( ColourGetCaller( g_xywindow_globals.color_gridback ), ColourSetCaller( g_xywindow_globals.color_gridback ) ),
895 m_gridmajor( ColourGetCaller( g_xywindow_globals.color_gridmajor ), ColourSetCaller( g_xywindow_globals.color_gridmajor ) ),
896 m_gridminor( ColourGetCaller( g_xywindow_globals.color_gridminor ), ColourSetCaller( g_xywindow_globals.color_gridminor ) ),
897 m_gridmajor_alt( ColourGetCaller( g_xywindow_globals.color_gridmajor_alt ), ColourSetCaller( g_xywindow_globals.color_gridmajor_alt ) ),
898 m_gridminor_alt( ColourGetCaller( g_xywindow_globals.color_gridminor_alt ), ColourSetCaller( g_xywindow_globals.color_gridminor_alt ) ),
899 m_gridtext( ColourGetCaller( g_xywindow_globals.color_gridtext ), ColourSetCaller( g_xywindow_globals.color_gridtext ) ),
900 m_gridblock( ColourGetCaller( g_xywindow_globals.color_gridblock ), ColourSetCaller( g_xywindow_globals.color_gridblock ) ),
901 m_cameraback( ColourGetCaller( g_camwindow_globals.color_cameraback ), ColourSetCaller( g_camwindow_globals.color_cameraback ) ),
902 m_brush( ColourGetCaller( g_xywindow_globals.color_brushes ), BrushColourSetCaller() ),
903 m_selectedbrush( ColourGetCaller( g_xywindow_globals.color_selbrushes ), ColourSetCaller( g_xywindow_globals.color_selbrushes ) ),
904 m_selectedbrush3d( ColourGetCaller( g_camwindow_globals.color_selbrushes3d ), ColourSetCaller( g_camwindow_globals.color_selbrushes3d ) ),
905 m_clipper( ColourGetCaller( g_xywindow_globals.color_clipper ), ClipperColourSetCaller() ),
906 m_viewname( ColourGetCaller( g_xywindow_globals.color_viewname ), ColourSetCaller( g_xywindow_globals.color_viewname ) ){
910 ColoursMenu g_ColoursMenu;
912 GtkMenuItem* create_colours_menu(){
913 GtkMenuItem* colours_menu_item = new_sub_menu_item_with_mnemonic( "Colors" );
914 GtkMenu* menu_in_menu = GTK_MENU( gtk_menu_item_get_submenu( colours_menu_item ) );
915 if ( g_Layout_enableDetachableMenus.m_value ) {
916 menu_tearoff( menu_in_menu );
919 GtkMenu* menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Themes" );
920 if ( g_Layout_enableDetachableMenus.m_value ) {
921 menu_tearoff( menu_3 );
924 create_menu_item_with_mnemonic( menu_3, "QE4 Original", "ColorSchemeOriginal" );
925 create_menu_item_with_mnemonic( menu_3, "Q3Radiant Original", "ColorSchemeQER" );
926 create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" );
927 create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" );
929 menu_separator( menu_in_menu );
931 create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" );
932 create_menu_item_with_mnemonic( menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor" );
933 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major...", "ChooseGridMajorColor" );
934 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor...", "ChooseGridMinorColor" );
935 create_menu_item_with_mnemonic( menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor" );
936 create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor" );
937 create_menu_item_with_mnemonic( menu_in_menu, "Grid Text...", "ChooseGridTextColor" );
938 create_menu_item_with_mnemonic( menu_in_menu, "Grid Block...", "ChooseGridBlockColor" );
939 create_menu_item_with_mnemonic( menu_in_menu, "Default Brush...", "ChooseBrushColor" );
940 create_menu_item_with_mnemonic( menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor" );
941 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor" );
942 create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor" );
943 create_menu_item_with_mnemonic( menu_in_menu, "Clipper...", "ChooseClipperColor" );
944 create_menu_item_with_mnemonic( menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor" );
946 return colours_menu_item;
952 PluginToolbar_clear();
955 Radiant_Initialise();
957 PluginsMenu_populate();
959 PluginToolbar_populate();
963 void thunk_OnSleep(){
964 g_pParentWnd->OnSleep();
968 OpenURL( "https://gitlab.com/xonotic/xonotic/wikis/Mapping" );
971 void OpenBugReportURL(){
972 OpenURL( "https://gitlab.com/xonotic/netradiant/issues" );
976 GtkWidget* g_page_console;
978 void Console_ToggleShow(){
979 GroupDialog_showPage( g_page_console );
982 GtkWidget* g_page_entity;
984 void EntityInspector_ToggleShow(){
985 GroupDialog_showPage( g_page_entity );
990 void SetClipMode( bool enable );
991 void ModeChangeNotify();
993 typedef void ( *ToolMode )();
994 ToolMode g_currentToolMode = 0;
995 bool g_currentToolModeSupportsComponentEditing = false;
996 ToolMode g_defaultToolMode = 0;
1000 void SelectionSystem_DefaultMode(){
1001 GlobalSelectionSystem().SetMode( SelectionSystem::ePrimitive );
1002 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eDefault );
1008 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1009 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1013 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1014 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1018 return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1019 && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1022 template<bool( *BoolFunction ) ( )>
1023 class BoolFunctionExport
1026 static void apply( const BoolImportCallback& importCallback ){
1027 importCallback( BoolFunction() );
1031 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1032 EdgeModeApplyCaller g_edgeMode_button_caller;
1033 BoolExportCallback g_edgeMode_button_callback( g_edgeMode_button_caller );
1034 ToggleItem g_edgeMode_button( g_edgeMode_button_callback );
1036 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1037 VertexModeApplyCaller g_vertexMode_button_caller;
1038 BoolExportCallback g_vertexMode_button_callback( g_vertexMode_button_caller );
1039 ToggleItem g_vertexMode_button( g_vertexMode_button_callback );
1041 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1042 FaceModeApplyCaller g_faceMode_button_caller;
1043 BoolExportCallback g_faceMode_button_callback( g_faceMode_button_caller );
1044 ToggleItem g_faceMode_button( g_faceMode_button_callback );
1046 void ComponentModeChanged(){
1047 g_edgeMode_button.update();
1048 g_vertexMode_button.update();
1049 g_faceMode_button.update();
1052 void ComponentMode_SelectionChanged( const Selectable& selectable ){
1053 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1054 && GlobalSelectionSystem().countSelected() == 0 ) {
1055 SelectionSystem_DefaultMode();
1056 ComponentModeChanged();
1060 void SelectEdgeMode(){
1062 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1063 GlobalSelectionSystem().Select( false );
1068 SelectionSystem_DefaultMode();
1070 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1071 if ( !g_currentToolModeSupportsComponentEditing ) {
1072 g_defaultToolMode();
1075 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1076 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eEdge );
1079 ComponentModeChanged();
1084 void SelectVertexMode(){
1086 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1087 GlobalSelectionSystem().Select( false );
1091 if ( VertexMode() ) {
1092 SelectionSystem_DefaultMode();
1094 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1095 if ( !g_currentToolModeSupportsComponentEditing ) {
1096 g_defaultToolMode();
1099 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1100 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eVertex );
1103 ComponentModeChanged();
1108 void SelectFaceMode(){
1110 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1111 GlobalSelectionSystem().Select( false );
1116 SelectionSystem_DefaultMode();
1118 else if ( GlobalSelectionSystem().countSelected() != 0 ) {
1119 if ( !g_currentToolModeSupportsComponentEditing ) {
1120 g_defaultToolMode();
1123 GlobalSelectionSystem().SetMode( SelectionSystem::eComponent );
1124 GlobalSelectionSystem().SetComponentMode( SelectionSystem::eFace );
1127 ComponentModeChanged();
1133 class CloneSelected : public scene::Graph::Walker
1136 NodeSmartReference worldspawn;
1138 CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
1140 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1141 if ( path.size() == 1 ) {
1145 // ignore worldspawn, but keep checking children
1146 NodeSmartReference me( path.top().get() );
1147 if ( me == worldspawn ) {
1151 if ( !path.top().get().isRoot() ) {
1152 Selectable* selectable = Instance_getSelectable( instance );
1153 if ( selectable != 0
1154 && selectable->isSelected() ) {
1161 void post( const scene::Path& path, scene::Instance& instance ) const {
1162 if ( path.size() == 1 ) {
1166 // ignore worldspawn, but keep checking children
1167 NodeSmartReference me( path.top().get() );
1168 if ( me == worldspawn ) {
1172 if ( !path.top().get().isRoot() ) {
1173 Selectable* selectable = Instance_getSelectable( instance );
1174 if ( selectable != 0
1175 && selectable->isSelected() ) {
1176 NodeSmartReference clone( Node_Clone( path.top() ) );
1177 if ( doMakeUnique ) {
1178 Map_gatherNamespaced( clone );
1180 Node_getTraversable( path.parent().get() )->insert( clone );
1186 void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){
1187 graph.traverse( CloneSelected( doMakeUnique ) );
1189 Map_mergeClonedNames();
1192 enum ENudgeDirection
1205 AxisBase( const Vector3& x_, const Vector3& y_, const Vector3& z_ )
1206 : x( x_ ), y( y_ ), z( z_ ){
1210 AxisBase AxisBase_forViewType( VIEWTYPE viewtype ){
1214 return AxisBase( g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z );
1216 return AxisBase( g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y );
1218 return AxisBase( g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x );
1221 ERROR_MESSAGE( "invalid viewtype" );
1222 return AxisBase( Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) );
1225 Vector3 AxisBase_axisForDirection( const AxisBase& axes, ENudgeDirection direction ){
1226 switch ( direction )
1229 return vector3_negated( axes.x );
1235 return vector3_negated( axes.y );
1238 ERROR_MESSAGE( "invalid direction" );
1239 return Vector3( 0, 0, 0 );
1242 void NudgeSelection( ENudgeDirection direction, float fAmount, VIEWTYPE viewtype ){
1243 AxisBase axes( AxisBase_forViewType( viewtype ) );
1244 Vector3 view_direction( vector3_negated( axes.z ) );
1245 Vector3 nudge( vector3_scaled( AxisBase_axisForDirection( axes, direction ), fAmount ) );
1246 GlobalSelectionSystem().NudgeManipulator( nudge, view_direction );
1249 void Selection_Clone(){
1250 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1251 UndoableCommand undo( "cloneSelected" );
1253 Scene_Clone_Selected( GlobalSceneGraph(), false );
1255 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1256 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1260 void Selection_Clone_MakeUnique(){
1261 if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
1262 UndoableCommand undo( "cloneSelectedMakeUnique" );
1264 Scene_Clone_Selected( GlobalSceneGraph(), true );
1266 //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1267 //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1271 // called when the escape key is used (either on the main window or on an inspector)
1272 void Selection_Deselect(){
1273 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1274 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1275 GlobalSelectionSystem().setSelectedAllComponents( false );
1279 SelectionSystem_DefaultMode();
1280 ComponentModeChanged();
1285 if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) {
1286 GlobalSelectionSystem().setSelectedAllComponents( false );
1290 GlobalSelectionSystem().setSelectedAll( false );
1296 void Selection_NudgeUp(){
1297 UndoableCommand undo( "nudgeSelectedUp" );
1298 NudgeSelection( eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1301 void Selection_NudgeDown(){
1302 UndoableCommand undo( "nudgeSelectedDown" );
1303 NudgeSelection( eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1306 void Selection_NudgeLeft(){
1307 UndoableCommand undo( "nudgeSelectedLeft" );
1308 NudgeSelection( eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1311 void Selection_NudgeRight(){
1312 UndoableCommand undo( "nudgeSelectedRight" );
1313 NudgeSelection( eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType() );
1317 void TranslateToolExport( const BoolImportCallback& importCallback ){
1318 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate );
1321 void RotateToolExport( const BoolImportCallback& importCallback ){
1322 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate );
1325 void ScaleToolExport( const BoolImportCallback& importCallback ){
1326 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale );
1329 void DragToolExport( const BoolImportCallback& importCallback ){
1330 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag );
1333 void ClipperToolExport( const BoolImportCallback& importCallback ){
1334 importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip );
1337 FreeCaller1<const BoolImportCallback&, TranslateToolExport> g_translatemode_button_caller;
1338 BoolExportCallback g_translatemode_button_callback( g_translatemode_button_caller );
1339 ToggleItem g_translatemode_button( g_translatemode_button_callback );
1341 FreeCaller1<const BoolImportCallback&, RotateToolExport> g_rotatemode_button_caller;
1342 BoolExportCallback g_rotatemode_button_callback( g_rotatemode_button_caller );
1343 ToggleItem g_rotatemode_button( g_rotatemode_button_callback );
1345 FreeCaller1<const BoolImportCallback&, ScaleToolExport> g_scalemode_button_caller;
1346 BoolExportCallback g_scalemode_button_callback( g_scalemode_button_caller );
1347 ToggleItem g_scalemode_button( g_scalemode_button_callback );
1349 FreeCaller1<const BoolImportCallback&, DragToolExport> g_dragmode_button_caller;
1350 BoolExportCallback g_dragmode_button_callback( g_dragmode_button_caller );
1351 ToggleItem g_dragmode_button( g_dragmode_button_callback );
1353 FreeCaller1<const BoolImportCallback&, ClipperToolExport> g_clipper_button_caller;
1354 BoolExportCallback g_clipper_button_callback( g_clipper_button_caller );
1355 ToggleItem g_clipper_button( g_clipper_button_callback );
1358 g_translatemode_button.update();
1359 g_rotatemode_button.update();
1360 g_scalemode_button.update();
1361 g_dragmode_button.update();
1362 g_clipper_button.update();
1365 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1368 if ( g_currentToolMode == DragMode && g_defaultToolMode != DragMode ) {
1369 g_defaultToolMode();
1373 g_currentToolMode = DragMode;
1374 g_currentToolModeSupportsComponentEditing = true;
1376 OnClipMode( false );
1378 Sys_Status( c_ResizeMode_status );
1379 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eDrag );
1386 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1388 void TranslateMode(){
1389 if ( g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode ) {
1390 g_defaultToolMode();
1394 g_currentToolMode = TranslateMode;
1395 g_currentToolModeSupportsComponentEditing = true;
1397 OnClipMode( false );
1399 Sys_Status( c_TranslateMode_status );
1400 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eTranslate );
1406 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1409 if ( g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode ) {
1410 g_defaultToolMode();
1414 g_currentToolMode = RotateMode;
1415 g_currentToolModeSupportsComponentEditing = true;
1417 OnClipMode( false );
1419 Sys_Status( c_RotateMode_status );
1420 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eRotate );
1426 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1429 if ( g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode ) {
1430 g_defaultToolMode();
1434 g_currentToolMode = ScaleMode;
1435 g_currentToolModeSupportsComponentEditing = true;
1437 OnClipMode( false );
1439 Sys_Status( c_ScaleMode_status );
1440 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eScale );
1447 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1451 if ( g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode ) {
1452 g_defaultToolMode();
1456 g_currentToolMode = ClipperMode;
1457 g_currentToolModeSupportsComponentEditing = false;
1459 SelectionSystem_DefaultMode();
1463 Sys_Status( c_ClipperMode_status );
1464 GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eClip );
1471 void Texdef_Rotate( float angle ){
1472 StringOutputStream command;
1473 command << "brushRotateTexture -angle " << angle;
1474 UndoableCommand undo( command.c_str() );
1475 Select_RotateTexture( angle );
1478 void Texdef_RotateClockwise(){
1479 Texdef_Rotate( static_cast<float>( fabs( g_si_globals.rotate ) ) );
1482 void Texdef_RotateAntiClockwise(){
1483 Texdef_Rotate( static_cast<float>( -fabs( g_si_globals.rotate ) ) );
1486 void Texdef_Scale( float x, float y ){
1487 StringOutputStream command;
1488 command << "brushScaleTexture -x " << x << " -y " << y;
1489 UndoableCommand undo( command.c_str() );
1490 Select_ScaleTexture( x, y );
1493 void Texdef_ScaleUp(){
1494 Texdef_Scale( 0, g_si_globals.scale[1] );
1497 void Texdef_ScaleDown(){
1498 Texdef_Scale( 0, -g_si_globals.scale[1] );
1501 void Texdef_ScaleLeft(){
1502 Texdef_Scale( -g_si_globals.scale[0],0 );
1505 void Texdef_ScaleRight(){
1506 Texdef_Scale( g_si_globals.scale[0],0 );
1509 void Texdef_Shift( float x, float y ){
1510 StringOutputStream command;
1511 command << "brushShiftTexture -x " << x << " -y " << y;
1512 UndoableCommand undo( command.c_str() );
1513 Select_ShiftTexture( x, y );
1516 void Texdef_ShiftLeft(){
1517 Texdef_Shift( -g_si_globals.shift[0], 0 );
1520 void Texdef_ShiftRight(){
1521 Texdef_Shift( g_si_globals.shift[0], 0 );
1524 void Texdef_ShiftUp(){
1525 Texdef_Shift( 0, g_si_globals.shift[1] );
1528 void Texdef_ShiftDown(){
1529 Texdef_Shift( 0, -g_si_globals.shift[1] );
1534 class SnappableSnapToGridSelected : public scene::Graph::Walker
1538 SnappableSnapToGridSelected( float snap )
1541 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1542 if ( path.top().get().visible() ) {
1543 Snappable* snappable = Node_getSnappable( path.top() );
1545 && Instance_getSelectable( instance )->isSelected() ) {
1546 snappable->snapto( m_snap );
1553 void Scene_SnapToGrid_Selected( scene::Graph& graph, float snap ){
1554 graph.traverse( SnappableSnapToGridSelected( snap ) );
1557 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1561 ComponentSnappableSnapToGridSelected( float snap )
1564 bool pre( const scene::Path& path, scene::Instance& instance ) const {
1565 if ( path.top().get().visible() ) {
1566 ComponentSnappable* componentSnappable = Instance_getComponentSnappable( instance );
1567 if ( componentSnappable != 0
1568 && Instance_getSelectable( instance )->isSelected() ) {
1569 componentSnappable->snapComponents( m_snap );
1576 void Scene_SnapToGrid_Component_Selected( scene::Graph& graph, float snap ){
1577 graph.traverse( ComponentSnappableSnapToGridSelected( snap ) );
1580 void Selection_SnapToGrid(){
1581 StringOutputStream command;
1582 command << "snapSelected -grid " << GetGridSize();
1583 UndoableCommand undo( command.c_str() );
1585 if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) {
1586 Scene_SnapToGrid_Component_Selected( GlobalSceneGraph(), GetGridSize() );
1590 Scene_SnapToGrid_Selected( GlobalSceneGraph(), GetGridSize() );
1595 static gint qe_every_second( gpointer data ){
1596 GdkModifierType mask;
1598 gdk_window_get_pointer( 0, 0, 0, &mask );
1600 if ( ( mask & ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK ) ) == 0 ) {
1607 guint s_qe_every_second_id = 0;
1609 void EverySecondTimer_enable(){
1610 if ( s_qe_every_second_id == 0 ) {
1611 s_qe_every_second_id = gtk_timeout_add( 1000, qe_every_second, 0 );
1615 void EverySecondTimer_disable(){
1616 if ( s_qe_every_second_id != 0 ) {
1617 gtk_timeout_remove( s_qe_every_second_id );
1618 s_qe_every_second_id = 0;
1622 gint window_realize_remove_decoration( GtkWidget* widget, gpointer data ){
1623 gdk_window_set_decorations( widget->window, (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) );
1630 GtkWindow* m_window;
1634 WaitDialog create_wait_dialog( const char* title, const char* text ){
1637 dialog.m_window = create_floating_window( title, MainFrame_getWindow() );
1638 gtk_window_set_resizable( dialog.m_window, FALSE );
1639 gtk_container_set_border_width( GTK_CONTAINER( dialog.m_window ), 0 );
1640 gtk_window_set_position( dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT );
1642 g_signal_connect( G_OBJECT( dialog.m_window ), "realize", G_CALLBACK( window_realize_remove_decoration ), 0 );
1645 dialog.m_label = GTK_LABEL( gtk_label_new( text ) );
1646 gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 );
1647 gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT );
1648 gtk_widget_show( GTK_WIDGET( dialog.m_label ) );
1649 gtk_widget_set_size_request( GTK_WIDGET( dialog.m_label ), 200, -1 );
1651 gtk_container_add( GTK_CONTAINER( dialog.m_window ), GTK_WIDGET( dialog.m_label ) );
1658 clock_t g_lastRedrawTime = 0;
1659 const clock_t c_redrawInterval = clock_t( CLOCKS_PER_SEC / 10 );
1661 bool redrawRequired(){
1662 clock_t currentTime = std::clock();
1663 if ( currentTime - g_lastRedrawTime >= c_redrawInterval ) {
1664 g_lastRedrawTime = currentTime;
1671 bool MainFrame_isActiveApp(){
1672 //globalOutputStream() << "listing\n";
1673 GList* list = gtk_window_list_toplevels();
1674 for ( GList* i = list; i != 0; i = g_list_next( i ) )
1676 //globalOutputStream() << "toplevel.. ";
1677 if ( gtk_window_is_active( GTK_WINDOW( i->data ) ) ) {
1678 //globalOutputStream() << "is active\n";
1681 //globalOutputStream() << "not active\n";
1686 typedef std::list<CopiedString> StringStack;
1687 StringStack g_wait_stack;
1690 bool ScreenUpdates_Enabled(){
1691 return g_wait_stack.empty();
1694 void ScreenUpdates_process(){
1695 if ( redrawRequired() && GTK_WIDGET_VISIBLE( g_wait.m_window ) ) {
1701 void ScreenUpdates_Disable( const char* message, const char* title ){
1702 if ( g_wait_stack.empty() ) {
1703 EverySecondTimer_disable();
1707 bool isActiveApp = MainFrame_isActiveApp();
1709 g_wait = create_wait_dialog( title, message );
1710 gtk_grab_add( GTK_WIDGET( g_wait.m_window ) );
1712 if ( isActiveApp ) {
1713 gtk_widget_show( GTK_WIDGET( g_wait.m_window ) );
1714 ScreenUpdates_process();
1717 else if ( GTK_WIDGET_VISIBLE( g_wait.m_window ) ) {
1718 gtk_label_set_text( g_wait.m_label, message );
1719 ScreenUpdates_process();
1721 g_wait_stack.push_back( message );
1724 void ScreenUpdates_Enable(){
1725 ASSERT_MESSAGE( !ScreenUpdates_Enabled(), "screen updates already enabled" );
1726 g_wait_stack.pop_back();
1727 if ( g_wait_stack.empty() ) {
1728 EverySecondTimer_enable();
1729 //gtk_widget_set_sensitive(GTK_WIDGET(MainFrame_getWindow()), TRUE);
1731 gtk_grab_remove( GTK_WIDGET( g_wait.m_window ) );
1732 destroy_floating_window( g_wait.m_window );
1733 g_wait.m_window = 0;
1735 //gtk_window_present(MainFrame_getWindow());
1737 else if ( GTK_WIDGET_VISIBLE( g_wait.m_window ) ) {
1738 gtk_label_set_text( g_wait.m_label, g_wait_stack.back().c_str() );
1739 ScreenUpdates_process();
1745 void GlobalCamera_UpdateWindow(){
1746 if ( g_pParentWnd != 0 ) {
1747 CamWnd_Update( *g_pParentWnd->GetCamWnd() );
1751 void XY_UpdateWindow( MainFrame& mainframe ){
1752 if ( mainframe.GetXYWnd() != 0 ) {
1753 XYWnd_Update( *mainframe.GetXYWnd() );
1757 void XZ_UpdateWindow( MainFrame& mainframe ){
1758 if ( mainframe.GetXZWnd() != 0 ) {
1759 XYWnd_Update( *mainframe.GetXZWnd() );
1763 void YZ_UpdateWindow( MainFrame& mainframe ){
1764 if ( mainframe.GetYZWnd() != 0 ) {
1765 XYWnd_Update( *mainframe.GetYZWnd() );
1769 void XY_UpdateAllWindows( MainFrame& mainframe ){
1770 XY_UpdateWindow( mainframe );
1771 XZ_UpdateWindow( mainframe );
1772 YZ_UpdateWindow( mainframe );
1775 void XY_UpdateAllWindows(){
1776 if ( g_pParentWnd != 0 ) {
1777 XY_UpdateAllWindows( *g_pParentWnd );
1781 void UpdateAllWindows(){
1782 GlobalCamera_UpdateWindow();
1783 XY_UpdateAllWindows();
1787 void ModeChangeNotify(){
1788 SceneChangeNotify();
1791 void ClipperChangeNotify(){
1792 GlobalCamera_UpdateWindow();
1793 XY_UpdateAllWindows();
1797 LatchedInt g_Layout_viewStyle( 0, "Window Layout" );
1798 LatchedBool g_Layout_enableDetachableMenus( true, "Detachable Menus" );
1799 LatchedBool g_Layout_enablePatchToolbar( true, "Patch Toolbar" );
1800 LatchedBool g_Layout_enablePluginToolbar( true, "Plugin Toolbar" );
1804 GtkMenuItem* create_file_menu(){
1806 GtkMenuItem* file_menu_item = new_sub_menu_item_with_mnemonic( "_File" );
1807 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( file_menu_item ) );
1808 if ( g_Layout_enableDetachableMenus.m_value ) {
1809 menu_tearoff( menu );
1812 create_menu_item_with_mnemonic( menu, "_New Map", "NewMap" );
1813 menu_separator( menu );
1816 //++timo temporary experimental stuff for sleep mode..
1817 create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" );
1818 menu_separator( menu );
1822 create_menu_item_with_mnemonic( menu, "_Open...", "OpenMap" );
1824 create_menu_item_with_mnemonic( menu, "_Import...", "ImportMap" );
1825 create_menu_item_with_mnemonic( menu, "_Save", "SaveMap" );
1826 create_menu_item_with_mnemonic( menu, "Save _as...", "SaveMapAs" );
1827 create_menu_item_with_mnemonic( menu, "_Export selected...", "ExportSelected" );
1828 menu_separator( menu );
1829 create_menu_item_with_mnemonic( menu, "Save re_gion...", "SaveRegion" );
1830 menu_separator( menu );
1831 create_menu_item_with_mnemonic( menu, "_Refresh models", "RefreshReferences" );
1832 menu_separator( menu );
1833 create_menu_item_with_mnemonic( menu, "Pro_ject settings...", "ProjectSettings" );
1834 menu_separator( menu );
1835 create_menu_item_with_mnemonic( menu, "_Pointfile...", "TogglePointfile" );
1836 menu_separator( menu );
1837 MRU_constructMenu( menu );
1838 menu_separator( menu );
1839 create_menu_item_with_mnemonic( menu, "E_xit", "Exit" );
1841 return file_menu_item;
1844 GtkMenuItem* create_edit_menu(){
1846 GtkMenuItem* edit_menu_item = new_sub_menu_item_with_mnemonic( "_Edit" );
1847 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( edit_menu_item ) );
1848 if ( g_Layout_enableDetachableMenus.m_value ) {
1849 menu_tearoff( menu );
1851 create_menu_item_with_mnemonic( menu, "_Undo", "Undo" );
1852 create_menu_item_with_mnemonic( menu, "_Redo", "Redo" );
1853 menu_separator( menu );
1854 create_menu_item_with_mnemonic( menu, "_Copy", "Copy" );
1855 create_menu_item_with_mnemonic( menu, "_Paste", "Paste" );
1856 create_menu_item_with_mnemonic( menu, "P_aste To Camera", "PasteToCamera" );
1857 menu_separator( menu );
1858 create_menu_item_with_mnemonic( menu, "_Duplicate", "CloneSelection" );
1859 create_menu_item_with_mnemonic( menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique" );
1860 create_menu_item_with_mnemonic( menu, "D_elete", "DeleteSelection" );
1861 menu_separator( menu );
1862 create_menu_item_with_mnemonic( menu, "Pa_rent", "ParentSelection" );
1863 menu_separator( menu );
1864 create_menu_item_with_mnemonic( menu, "C_lear Selection", "UnSelectSelection" );
1865 create_menu_item_with_mnemonic( menu, "_Invert Selection", "InvertSelection" );
1866 create_menu_item_with_mnemonic( menu, "Select i_nside", "SelectInside" );
1867 create_menu_item_with_mnemonic( menu, "Select _touching", "SelectTouching" );
1869 GtkMenu* convert_menu = create_sub_menu_with_mnemonic( menu, "E_xpand Selection" );
1870 if ( g_Layout_enableDetachableMenus.m_value ) {
1871 menu_tearoff( convert_menu );
1873 create_menu_item_with_mnemonic( convert_menu, "To Whole _Entities", "ExpandSelectionToEntities" );
1875 menu_separator( menu );
1876 create_menu_item_with_mnemonic( menu, "Pre_ferences...", "Preferences" );
1878 return edit_menu_item;
1881 void fill_view_xy_top_menu( GtkMenu* menu ){
1882 create_check_menu_item_with_mnemonic( menu, "XY (Top) View", "ToggleView" );
1886 void fill_view_yz_side_menu( GtkMenu* menu ){
1887 create_check_menu_item_with_mnemonic( menu, "YZ (Side) View", "ToggleSideView" );
1891 void fill_view_xz_front_menu( GtkMenu* menu ){
1892 create_check_menu_item_with_mnemonic( menu, "XZ (Front) View", "ToggleFrontView" );
1896 GtkWidget* g_toggle_z_item = 0;
1897 GtkWidget* g_toggle_console_item = 0;
1898 GtkWidget* g_toggle_entity_item = 0;
1899 GtkWidget* g_toggle_entitylist_item = 0;
1901 GtkMenuItem* create_view_menu( MainFrame::EViewStyle style ){
1903 GtkMenuItem* view_menu_item = new_sub_menu_item_with_mnemonic( "Vie_w" );
1904 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( view_menu_item ) );
1905 if ( g_Layout_enableDetachableMenus.m_value ) {
1906 menu_tearoff( menu );
1909 if ( style == MainFrame::eFloating ) {
1910 fill_view_camera_menu( menu );
1911 fill_view_xy_top_menu( menu );
1912 fill_view_yz_side_menu( menu );
1913 fill_view_xz_front_menu( menu );
1915 if ( style == MainFrame::eFloating || style == MainFrame::eSplit ) {
1916 create_menu_item_with_mnemonic( menu, "Console View", "ToggleConsole" );
1917 create_menu_item_with_mnemonic( menu, "Texture Browser", "ToggleTextures" );
1918 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ToggleEntityInspector" );
1922 create_menu_item_with_mnemonic( menu, "Entity Inspector", "ViewEntityInfo" );
1924 create_menu_item_with_mnemonic( menu, "_Surface Inspector", "SurfaceInspector" );
1925 create_menu_item_with_mnemonic( menu, "Entity List", "EntityList" );
1927 menu_separator( menu );
1929 GtkMenu* camera_menu = create_sub_menu_with_mnemonic( menu, "Camera" );
1930 if ( g_Layout_enableDetachableMenus.m_value ) {
1931 menu_tearoff( camera_menu );
1933 create_menu_item_with_mnemonic( camera_menu, "_Center", "CenterView" );
1934 create_menu_item_with_mnemonic( camera_menu, "_Up Floor", "UpFloor" );
1935 create_menu_item_with_mnemonic( camera_menu, "_Down Floor", "DownFloor" );
1936 menu_separator( camera_menu );
1937 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane In", "CubicClipZoomIn" );
1938 create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane Out", "CubicClipZoomOut" );
1939 menu_separator( camera_menu );
1940 create_menu_item_with_mnemonic( camera_menu, "Next leak spot", "NextLeakSpot" );
1941 create_menu_item_with_mnemonic( camera_menu, "Previous leak spot", "PrevLeakSpot" );
1942 menu_separator( camera_menu );
1943 create_menu_item_with_mnemonic( camera_menu, "Look Through Selected", "LookThroughSelected" );
1944 create_menu_item_with_mnemonic( camera_menu, "Look Through Camera", "LookThroughCamera" );
1946 menu_separator( menu );
1948 GtkMenu* orthographic_menu = create_sub_menu_with_mnemonic( menu, "Orthographic" );
1949 if ( g_Layout_enableDetachableMenus.m_value ) {
1950 menu_tearoff( orthographic_menu );
1952 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
1953 create_menu_item_with_mnemonic( orthographic_menu, "_Next (XY, YZ, XY)", "NextView" );
1954 create_menu_item_with_mnemonic( orthographic_menu, "XY (Top)", "ViewTop" );
1955 create_menu_item_with_mnemonic( orthographic_menu, "YZ", "ViewSide" );
1956 create_menu_item_with_mnemonic( orthographic_menu, "XZ", "ViewFront" );
1957 menu_separator( orthographic_menu );
1960 create_menu_item_with_mnemonic( orthographic_menu, "_XY 100%", "Zoom100" );
1961 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _In", "ZoomIn" );
1962 create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _Out", "ZoomOut" );
1965 menu_separator( menu );
1968 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Show" );
1969 if ( g_Layout_enableDetachableMenus.m_value ) {
1970 menu_tearoff( menu_in_menu );
1972 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Angles", "ShowAngles" );
1973 create_check_menu_item_with_mnemonic( menu_in_menu, "Show _Names", "ShowNames" );
1974 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Blocks", "ShowBlocks" );
1975 create_check_menu_item_with_mnemonic( menu_in_menu, "Show C_oordinates", "ShowCoordinates" );
1976 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Window Outline", "ShowWindowOutline" );
1977 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Axes", "ShowAxes" );
1978 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Workzone", "ShowWorkzone" );
1979 create_check_menu_item_with_mnemonic( menu_in_menu, "Show Stats", "ShowStats" );
1983 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Filter" );
1984 if ( g_Layout_enableDetachableMenus.m_value ) {
1985 menu_tearoff( menu_in_menu );
1987 Filters_constructMenu( menu_in_menu );
1989 menu_separator( menu );
1991 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Hide/Show" );
1992 if ( g_Layout_enableDetachableMenus.m_value ) {
1993 menu_tearoff( menu_in_menu );
1995 create_menu_item_with_mnemonic( menu_in_menu, "Hide Selected", "HideSelected" );
1996 create_menu_item_with_mnemonic( menu_in_menu, "Show Hidden", "ShowHidden" );
1998 menu_separator( menu );
2000 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Region" );
2001 if ( g_Layout_enableDetachableMenus.m_value ) {
2002 menu_tearoff( menu_in_menu );
2004 create_menu_item_with_mnemonic( menu_in_menu, "_Off", "RegionOff" );
2005 create_menu_item_with_mnemonic( menu_in_menu, "_Set XY", "RegionSetXY" );
2006 create_menu_item_with_mnemonic( menu_in_menu, "Set _Brush", "RegionSetBrush" );
2007 create_menu_item_with_mnemonic( menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection" );
2010 command_connect_accelerator( "CenterXYView" );
2012 return view_menu_item;
2015 GtkMenuItem* create_selection_menu(){
2017 GtkMenuItem* selection_menu_item = new_sub_menu_item_with_mnemonic( "M_odify" );
2018 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( selection_menu_item ) );
2019 if ( g_Layout_enableDetachableMenus.m_value ) {
2020 menu_tearoff( menu );
2024 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Components" );
2025 if ( g_Layout_enableDetachableMenus.m_value ) {
2026 menu_tearoff( menu_in_menu );
2028 create_check_menu_item_with_mnemonic( menu_in_menu, "_Edges", "DragEdges" );
2029 create_check_menu_item_with_mnemonic( menu_in_menu, "_Vertices", "DragVertices" );
2030 create_check_menu_item_with_mnemonic( menu_in_menu, "_Faces", "DragFaces" );
2033 menu_separator( menu );
2036 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Nudge" );
2037 if ( g_Layout_enableDetachableMenus.m_value ) {
2038 menu_tearoff( menu_in_menu );
2040 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Left", "SelectNudgeLeft" );
2041 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Right", "SelectNudgeRight" );
2042 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Up", "SelectNudgeUp" );
2043 create_menu_item_with_mnemonic( menu_in_menu, "Nudge Down", "SelectNudgeDown" );
2046 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Rotate" );
2047 if ( g_Layout_enableDetachableMenus.m_value ) {
2048 menu_tearoff( menu_in_menu );
2050 create_menu_item_with_mnemonic( menu_in_menu, "Rotate X", "RotateSelectionX" );
2051 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Y", "RotateSelectionY" );
2052 create_menu_item_with_mnemonic( menu_in_menu, "Rotate Z", "RotateSelectionZ" );
2055 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Flip" );
2056 if ( g_Layout_enableDetachableMenus.m_value ) {
2057 menu_tearoff( menu_in_menu );
2059 create_menu_item_with_mnemonic( menu_in_menu, "Flip _X", "MirrorSelectionX" );
2060 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Y", "MirrorSelectionY" );
2061 create_menu_item_with_mnemonic( menu_in_menu, "Flip _Z", "MirrorSelectionZ" );
2063 menu_separator( menu );
2064 create_menu_item_with_mnemonic( menu, "Arbitrary rotation...", "ArbitraryRotation" );
2065 create_menu_item_with_mnemonic( menu, "Arbitrary scale...", "ArbitraryScale" );
2067 return selection_menu_item;
2070 GtkMenuItem* create_bsp_menu(){
2072 GtkMenuItem* bsp_menu_item = new_sub_menu_item_with_mnemonic( "_Build" );
2073 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( bsp_menu_item ) );
2075 if ( g_Layout_enableDetachableMenus.m_value ) {
2076 menu_tearoff( menu );
2079 create_menu_item_with_mnemonic( menu, "Customize...", "BuildMenuCustomize" );
2081 menu_separator( menu );
2083 Build_constructMenu( menu );
2087 return bsp_menu_item;
2090 GtkMenuItem* create_grid_menu(){
2092 GtkMenuItem* grid_menu_item = new_sub_menu_item_with_mnemonic( "_Grid" );
2093 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( grid_menu_item ) );
2094 if ( g_Layout_enableDetachableMenus.m_value ) {
2095 menu_tearoff( menu );
2098 Grid_constructMenu( menu );
2100 return grid_menu_item;
2103 GtkMenuItem* create_misc_menu(){
2105 GtkMenuItem* misc_menu_item = new_sub_menu_item_with_mnemonic( "M_isc" );
2106 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( misc_menu_item ) );
2107 if ( g_Layout_enableDetachableMenus.m_value ) {
2108 menu_tearoff( menu );
2112 create_menu_item_with_mnemonic( menu, "_Benchmark", FreeCaller<GlobalCamera_Benchmark>() );
2114 gtk_container_add( GTK_CONTAINER( menu ), GTK_WIDGET( create_colours_menu() ) );
2116 create_menu_item_with_mnemonic( menu, "Find brush...", "FindBrush" );
2117 create_menu_item_with_mnemonic( menu, "Map Info...", "MapInfo" );
2118 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
2119 // create_menu_item_with_mnemonic(menu, "_Print XY View", FreeCaller<WXY_Print>());
2120 create_menu_item_with_mnemonic( menu, "_Background select", FreeCaller<WXY_BackgroundSelect>() );
2121 return misc_menu_item;
2124 GtkMenuItem* create_entity_menu(){
2126 GtkMenuItem* entity_menu_item = new_sub_menu_item_with_mnemonic( "E_ntity" );
2127 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( entity_menu_item ) );
2128 if ( g_Layout_enableDetachableMenus.m_value ) {
2129 menu_tearoff( menu );
2132 Entity_constructMenu( menu );
2134 return entity_menu_item;
2137 GtkMenuItem* create_brush_menu(){
2139 GtkMenuItem* brush_menu_item = new_sub_menu_item_with_mnemonic( "B_rush" );
2140 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( brush_menu_item ) );
2141 if ( g_Layout_enableDetachableMenus.m_value ) {
2142 menu_tearoff( menu );
2145 Brush_constructMenu( menu );
2147 return brush_menu_item;
2150 GtkMenuItem* create_patch_menu(){
2152 GtkMenuItem* patch_menu_item = new_sub_menu_item_with_mnemonic( "_Curve" );
2153 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( patch_menu_item ) );
2154 if ( g_Layout_enableDetachableMenus.m_value ) {
2155 menu_tearoff( menu );
2158 Patch_constructMenu( menu );
2160 return patch_menu_item;
2163 GtkMenuItem* create_help_menu(){
2165 GtkMenuItem* help_menu_item = new_sub_menu_item_with_mnemonic( "_Help" );
2166 GtkMenu* menu = GTK_MENU( gtk_menu_item_get_submenu( help_menu_item ) );
2167 if ( g_Layout_enableDetachableMenus.m_value ) {
2168 menu_tearoff( menu );
2171 create_menu_item_with_mnemonic( menu, "Manual", "OpenManual" );
2173 // this creates all the per-game drop downs for the game pack helps
2174 // it will take care of hooking the Sys_OpenURL calls etc.
2175 create_game_help_menu( menu );
2177 create_menu_item_with_mnemonic( menu, "Bug report", FreeCaller<OpenBugReportURL>() );
2178 create_menu_item_with_mnemonic( menu, "Shortcuts list", FreeCaller<DoCommandListDlg>() );
2179 create_menu_item_with_mnemonic( menu, "_About", FreeCaller<DoAbout>() );
2181 return help_menu_item;
2184 GtkMenuBar* create_main_menu( MainFrame::EViewStyle style ){
2185 GtkMenuBar* menu_bar = GTK_MENU_BAR( gtk_menu_bar_new() );
2186 gtk_widget_show( GTK_WIDGET( menu_bar ) );
2188 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_file_menu() ) );
2189 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_edit_menu() ) );
2190 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_view_menu( style ) ) );
2191 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_selection_menu() ) );
2192 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_bsp_menu() ) );
2193 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_grid_menu() ) );
2194 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_misc_menu() ) );
2195 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_entity_menu() ) );
2196 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_brush_menu() ) );
2197 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_patch_menu() ) );
2198 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_plugins_menu() ) );
2199 gtk_container_add( GTK_CONTAINER( menu_bar ), GTK_WIDGET( create_help_menu() ) );
2205 void PatchInspector_registerShortcuts(){
2206 command_connect_accelerator( "PatchInspector" );
2209 void Patch_registerShortcuts(){
2210 command_connect_accelerator( "InvertCurveTextureX" );
2211 command_connect_accelerator( "InvertCurveTextureY" );
2212 command_connect_accelerator( "PatchInsertInsertColumn" );
2213 command_connect_accelerator( "PatchInsertInsertRow" );
2214 command_connect_accelerator( "PatchDeleteLastColumn" );
2215 command_connect_accelerator( "PatchDeleteLastRow" );
2216 command_connect_accelerator( "NaturalizePatch" );
2217 //command_connect_accelerator("CapCurrentCurve");
2220 void Manipulators_registerShortcuts(){
2221 toggle_add_accelerator( "MouseRotate" );
2222 toggle_add_accelerator( "MouseTranslate" );
2223 toggle_add_accelerator( "MouseScale" );
2224 toggle_add_accelerator( "MouseDrag" );
2225 toggle_add_accelerator( "ToggleClipper" );
2228 void TexdefNudge_registerShortcuts(){
2229 command_connect_accelerator( "TexRotateClock" );
2230 command_connect_accelerator( "TexRotateCounter" );
2231 command_connect_accelerator( "TexScaleUp" );
2232 command_connect_accelerator( "TexScaleDown" );
2233 command_connect_accelerator( "TexScaleLeft" );
2234 command_connect_accelerator( "TexScaleRight" );
2235 command_connect_accelerator( "TexShiftUp" );
2236 command_connect_accelerator( "TexShiftDown" );
2237 command_connect_accelerator( "TexShiftLeft" );
2238 command_connect_accelerator( "TexShiftRight" );
2241 void SelectNudge_registerShortcuts(){
2242 command_connect_accelerator( "MoveSelectionDOWN" );
2243 command_connect_accelerator( "MoveSelectionUP" );
2244 //command_connect_accelerator("SelectNudgeLeft");
2245 //command_connect_accelerator("SelectNudgeRight");
2246 //command_connect_accelerator("SelectNudgeUp");
2247 //command_connect_accelerator("SelectNudgeDown");
2250 void SnapToGrid_registerShortcuts(){
2251 command_connect_accelerator( "SnapToGrid" );
2254 void SelectByType_registerShortcuts(){
2255 command_connect_accelerator( "SelectAllOfType" );
2258 void SurfaceInspector_registerShortcuts(){
2259 command_connect_accelerator( "FitTexture" );
2263 void register_shortcuts(){
2264 PatchInspector_registerShortcuts();
2265 Patch_registerShortcuts();
2266 Grid_registerShortcuts();
2267 XYWnd_registerShortcuts();
2268 CamWnd_registerShortcuts();
2269 Manipulators_registerShortcuts();
2270 SurfaceInspector_registerShortcuts();
2271 TexdefNudge_registerShortcuts();
2272 SelectNudge_registerShortcuts();
2273 SnapToGrid_registerShortcuts();
2274 SelectByType_registerShortcuts();
2277 void File_constructToolbar( GtkToolbar* toolbar ){
2278 toolbar_append_button( toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap" );
2279 toolbar_append_button( toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap" );
2282 void UndoRedo_constructToolbar( GtkToolbar* toolbar ){
2283 toolbar_append_button( toolbar, "Undo (CTRL + Z)", "undo.png", "Undo" );
2284 toolbar_append_button( toolbar, "Redo (CTRL + Y)", "redo.png", "Redo" );
2287 void RotateFlip_constructToolbar( GtkToolbar* toolbar ){
2288 toolbar_append_button( toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX" );
2289 toolbar_append_button( toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX" );
2290 toolbar_append_button( toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY" );
2291 toolbar_append_button( toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY" );
2292 toolbar_append_button( toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ" );
2293 toolbar_append_button( toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ" );
2296 void Select_constructToolbar( GtkToolbar* toolbar ){
2297 toolbar_append_button( toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching" );
2298 toolbar_append_button( toolbar, "Select inside", "selection_selectinside.png", "SelectInside" );
2301 void CSG_constructToolbar( GtkToolbar* toolbar ){
2302 toolbar_append_button( toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract" );
2303 toolbar_append_button( toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge" );
2304 toolbar_append_button( toolbar, "Hollow", "selection_makehollow.png", "CSGHollow" );
2307 void ComponentModes_constructToolbar( GtkToolbar* toolbar ){
2308 toolbar_append_toggle_button( toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices" );
2309 toolbar_append_toggle_button( toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges" );
2310 toolbar_append_toggle_button( toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces" );
2313 void Clipper_constructToolbar( GtkToolbar* toolbar ){
2315 toolbar_append_toggle_button( toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper" );
2318 void XYWnd_constructToolbar( GtkToolbar* toolbar ){
2319 toolbar_append_button( toolbar, "Change views", "view_change.png", "NextView" );
2322 void Manipulators_constructToolbar( GtkToolbar* toolbar ){
2323 toolbar_append_toggle_button( toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate" );
2324 toolbar_append_toggle_button( toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate" );
2325 toolbar_append_toggle_button( toolbar, "Scale", "select_mousescale.png", "MouseScale" );
2326 toolbar_append_toggle_button( toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag" );
2328 Clipper_constructToolbar( toolbar );
2331 GtkToolbar* create_main_toolbar( MainFrame::EViewStyle style ){
2332 GtkToolbar* toolbar = GTK_TOOLBAR( gtk_toolbar_new() );
2333 gtk_toolbar_set_orientation( toolbar, GTK_ORIENTATION_HORIZONTAL );
2334 gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS );
2336 gtk_widget_show( GTK_WIDGET( toolbar ) );
2338 File_constructToolbar( toolbar );
2340 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2342 UndoRedo_constructToolbar( toolbar );
2344 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2346 RotateFlip_constructToolbar( toolbar );
2348 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2350 Select_constructToolbar( toolbar );
2352 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2354 CSG_constructToolbar( toolbar );
2356 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2358 ComponentModes_constructToolbar( toolbar );
2360 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) {
2361 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2363 XYWnd_constructToolbar( toolbar );
2366 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2368 CamWnd_constructToolbar( toolbar );
2370 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2372 Manipulators_constructToolbar( toolbar );
2374 if ( g_Layout_enablePatchToolbar.m_value ) {
2375 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2377 Patch_constructToolbar( toolbar );
2380 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2382 toolbar_append_toggle_button( toolbar, "Texture Lock (SHIFT +T)", "texture_lock.png", "TogTexLock" );
2384 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2386 GtkButton* g_view_entities_button = toolbar_append_button( toolbar, "Entities (N)", "entities.png", "ToggleEntityInspector" );
2387 GtkButton* g_view_console_button = toolbar_append_button( toolbar, "Console (O)", "console.png", "ToggleConsole" );
2388 GtkButton* g_view_textures_button = toolbar_append_button( toolbar, "Texture Browser (T)", "texture_browser.png", "ToggleTextures" );
2389 // TODO: call light inspector
2390 //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector");
2392 gtk_toolbar_append_space( GTK_TOOLBAR( toolbar ) );
2393 GtkButton* g_refresh_models_button = toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" );
2396 // disable the console and texture button in the regular layouts
2397 if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft ) {
2398 gtk_widget_set_sensitive( GTK_WIDGET( g_view_console_button ), FALSE );
2399 gtk_widget_set_sensitive( GTK_WIDGET( g_view_textures_button ), FALSE );
2405 GtkWidget* create_main_statusbar( GtkWidget *pStatusLabel[c_count_status] ){
2406 GtkTable* table = GTK_TABLE( gtk_table_new( 1, c_count_status, FALSE ) );
2407 gtk_widget_show( GTK_WIDGET( table ) );
2410 GtkLabel* label = GTK_LABEL( gtk_label_new( "Label" ) );
2411 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2412 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2413 gtk_widget_show( GTK_WIDGET( label ) );
2414 gtk_table_attach_defaults( table, GTK_WIDGET( label ), 0, 1, 0, 1 );
2415 pStatusLabel[c_command_status] = GTK_WIDGET( label );
2418 for ( int i = 1; i < c_count_status; ++i )
2420 GtkFrame* frame = GTK_FRAME( gtk_frame_new( 0 ) );
2421 gtk_widget_show( GTK_WIDGET( frame ) );
2422 gtk_table_attach_defaults( table, GTK_WIDGET( frame ), i, i + 1, 0, 1 );
2423 gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
2425 GtkLabel* label = GTK_LABEL( gtk_label_new( "Label" ) );
2426 gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END );
2427 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
2428 gtk_misc_set_padding( GTK_MISC( label ), 4, 2 );
2429 gtk_widget_show( GTK_WIDGET( label ) );
2430 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( label ) );
2431 pStatusLabel[i] = GTK_WIDGET( label );
2434 return GTK_WIDGET( table );
2440 WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" );
2442 class WindowFocusPrinter
2446 static gboolean frame_event( GtkWidget *widget, GdkEvent* event, WindowFocusPrinter* self ){
2447 globalOutputStream() << self->m_name << " frame_event\n";
2450 static gboolean keys_changed( GtkWidget *widget, WindowFocusPrinter* self ){
2451 globalOutputStream() << self->m_name << " keys_changed\n";
2454 static gboolean notify( GtkWindow* window, gpointer dummy, WindowFocusPrinter* self ){
2455 if ( gtk_window_is_active( window ) ) {
2456 globalOutputStream() << self->m_name << " takes toplevel focus\n";
2460 globalOutputStream() << self->m_name << " loses toplevel focus\n";
2465 WindowFocusPrinter( const char* name ) : m_name( name ){
2467 void connect( GtkWindow* toplevel_window ){
2468 g_signal_connect( G_OBJECT( toplevel_window ), "notify::has_toplevel_focus", G_CALLBACK( notify ), this );
2469 g_signal_connect( G_OBJECT( toplevel_window ), "notify::is_active", G_CALLBACK( notify ), this );
2470 g_signal_connect( G_OBJECT( toplevel_window ), "keys_changed", G_CALLBACK( keys_changed ), this );
2471 g_signal_connect( G_OBJECT( toplevel_window ), "frame_event", G_CALLBACK( frame_event ), this );
2475 WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" );
2479 class MainWindowActive
2481 static gboolean notify( GtkWindow* window, gpointer dummy, MainWindowActive* self ){
2482 if ( g_wait.m_window != 0 && gtk_window_is_active( window ) && !GTK_WIDGET_VISIBLE( g_wait.m_window ) ) {
2483 gtk_widget_show( GTK_WIDGET( g_wait.m_window ) );
2489 void connect( GtkWindow* toplevel_window ){
2490 g_signal_connect( G_OBJECT( toplevel_window ), "notify::is-active", G_CALLBACK( notify ), this );
2494 MainWindowActive g_MainWindowActive;
2496 SignalHandlerId XYWindowDestroyed_connect( const SignalHandler& handler ){
2497 return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst( handler );
2500 void XYWindowDestroyed_disconnect( SignalHandlerId id ){
2501 g_pParentWnd->GetXYWnd()->onDestroyed.disconnect( id );
2504 MouseEventHandlerId XYWindowMouseDown_connect( const MouseEventHandler& handler ){
2505 return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst( handler );
2508 void XYWindowMouseDown_disconnect( MouseEventHandlerId id ){
2509 g_pParentWnd->GetXYWnd()->onMouseDown.disconnect( id );
2512 // =============================================================================
2515 MainFrame* g_pParentWnd = 0;
2517 GtkWindow* MainFrame_getWindow(){
2518 if ( g_pParentWnd == 0 ) {
2521 return g_pParentWnd->m_window;
2524 std::vector<GtkWidget*> g_floating_windows;
2526 MainFrame::MainFrame() : m_window( 0 ), m_idleRedrawStatusText( RedrawStatusTextCaller( *this ) ){
2534 for ( int n = 0; n < c_count_status; n++ )
2536 m_pStatusLabel[n] = 0;
2539 m_bSleeping = false;
2544 MainFrame::~MainFrame(){
2547 gtk_widget_hide( GTK_WIDGET( m_window ) );
2551 for ( std::vector<GtkWidget*>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i )
2553 gtk_widget_destroy( *i );
2556 gtk_widget_destroy( GTK_WIDGET( m_window ) );
2559 void MainFrame::SetActiveXY( XYWnd* p ){
2560 if ( m_pActiveXY ) {
2561 m_pActiveXY->SetActive( false );
2566 if ( m_pActiveXY ) {
2567 m_pActiveXY->SetActive( true );
2572 void MainFrame::ReleaseContexts(){
2575 m_pXYWnd->DestroyContext();
2578 m_pYZWnd->DestroyContext();
2581 m_pXZWnd->DestroyContext();
2584 m_pCamWnd->DestroyContext();
2587 m_pTexWnd->DestroyContext();
2590 m_pZWnd->DestroyContext();
2595 void MainFrame::CreateContexts(){
2598 m_pCamWnd->CreateContext();
2601 m_pXYWnd->CreateContext();
2604 m_pYZWnd->CreateContext();
2607 m_pXZWnd->CreateContext();
2610 m_pTexWnd->CreateContext();
2613 m_pZWnd->CreateContext();
2622 void MainFrame::OnSleep(){
2625 if ( m_bSleeping ) {
2626 // useful when trying to debug crashes in the sleep code
2627 globalOutputStream() << "Going into sleep mode..\n";
2629 globalOutputStream() << "Dispatching sleep msg...";
2630 DispatchRadiantMsg( RADIANT_SLEEP );
2631 globalOutputStream() << "Done.\n";
2633 gtk_window_iconify( m_window );
2634 GlobalSelectionSystem().setSelectedAll( false );
2636 GlobalShaderCache().unrealise();
2638 GlobalOpenGL_debugAssertNoErrors();
2639 ScreenUpdates_Disable();
2642 globalOutputStream() << "Releasing contexts...";
2644 globalOutputStream() << "Done.\n";
2648 globalOutputStream() << "Waking up\n";
2650 gtk_window_deiconify( m_window );
2653 globalOutputStream() << "Creating contexts...";
2655 globalOutputStream() << "Done.\n";
2657 globalOutputStream() << "Making current on camera...";
2658 m_pCamWnd->MakeCurrent();
2659 globalOutputStream() << "Done.\n";
2661 globalOutputStream() << "Reloading shaders...";
2663 GlobalShaderCache().realise();
2664 globalOutputStream() << "Done.\n";
2666 ScreenUpdates_Enable();
2668 globalOutputStream() << "Dispatching wake msg...";
2669 DispatchRadiantMsg( RADIANT_WAKEUP );
2670 globalOutputStream() << "Done\n";
2676 GtkWindow* create_splash(){
2677 GtkWindow* window = GTK_WINDOW( gtk_window_new( GTK_WINDOW_TOPLEVEL ) );
2678 gtk_window_set_decorated( window, FALSE );
2679 gtk_window_set_resizable( window, FALSE );
2680 gtk_window_set_modal( window, TRUE );
2681 gtk_window_set_default_size( window, -1, -1 );
2682 gtk_window_set_position( window, GTK_WIN_POS_CENTER );
2683 gtk_container_set_border_width( GTK_CONTAINER( window ), 0 );
2685 GtkImage* image = new_local_image( "splash.png" );
2686 gtk_widget_show( GTK_WIDGET( image ) );
2687 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( image ) );
2689 gtk_widget_set_size_request( GTK_WIDGET( window ), -1, -1 );
2690 gtk_widget_show( GTK_WIDGET( window ) );
2695 static GtkWindow *splash_screen = 0;
2698 splash_screen = create_splash();
2704 gtk_widget_destroy( GTK_WIDGET( splash_screen ) );
2707 WindowPositionTracker g_posCamWnd;
2708 WindowPositionTracker g_posXYWnd;
2709 WindowPositionTracker g_posXZWnd;
2710 WindowPositionTracker g_posYZWnd;
2712 static gint mainframe_delete( GtkWidget *widget, GdkEvent *event, gpointer data ){
2713 if ( ConfirmModified( "Exit Radiant" ) ) {
2720 void MainFrame::Create(){
2721 GtkWindow* window = GTK_WINDOW( gtk_window_new( GTK_WINDOW_TOPLEVEL ) );
2723 GlobalWindowObservers_connectTopLevel( window );
2725 gtk_window_set_transient_for( splash_screen, window );
2727 #if !defined( WIN32 )
2729 GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
2730 if ( pixbuf != 0 ) {
2731 gtk_window_set_icon( window, pixbuf );
2732 gdk_pixbuf_unref( pixbuf );
2737 gtk_widget_add_events( GTK_WIDGET( window ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK );
2738 g_signal_connect( G_OBJECT( window ), "delete_event", G_CALLBACK( mainframe_delete ), this );
2740 m_position_tracker.connect( window );
2743 g_mainframeWidgetFocusPrinter.connect( window );
2744 g_mainframeFocusPrinter.connect( window );
2747 g_MainWindowActive.connect( window );
2749 GetPlugInMgr().Init( GTK_WIDGET( window ) );
2751 GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
2752 gtk_container_add( GTK_CONTAINER( window ), vbox );
2753 gtk_widget_show( vbox );
2755 global_accel_connect_window( window );
2757 m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value;
2759 register_shortcuts();
2761 GtkMenuBar* main_menu = create_main_menu( CurrentStyle() );
2762 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_menu ), FALSE, FALSE, 0 );
2764 GtkToolbar* main_toolbar = create_main_toolbar( CurrentStyle() );
2765 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_toolbar ), FALSE, FALSE, 0 );
2767 GtkToolbar* plugin_toolbar = create_plugin_toolbar();
2768 if ( !g_Layout_enablePluginToolbar.m_value ) {
2769 gtk_widget_hide( GTK_WIDGET( plugin_toolbar ) );
2771 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( plugin_toolbar ), FALSE, FALSE, 0 );
2773 GtkWidget* main_statusbar = create_main_statusbar( m_pStatusLabel );
2774 gtk_box_pack_end( GTK_BOX( vbox ), main_statusbar, FALSE, TRUE, 2 );
2776 GroupDialog_constructWindow( window );
2777 g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) );
2779 if ( FloatingGroupDialog() ) {
2780 g_page_console = GroupDialog_addPage( "Console", Console_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Console" ) );
2784 if ( g_multimon_globals.m_bStartOnPrimMon ) {
2785 PositionWindowOnPrimaryScreen( g_layout_globals.m_position );
2786 window_set_position( window, g_layout_globals.m_position );
2790 if ( g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED ) {
2791 gtk_window_maximize( window );
2792 WindowPosition default_position( -1, -1, 640, 480 );
2793 window_set_position( window, default_position );
2797 window_set_position( window, g_layout_globals.m_position );
2802 gtk_widget_show( GTK_WIDGET( window ) );
2804 if ( CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft ) {
2806 GtkWidget* vsplit = gtk_vpaned_new();
2808 gtk_box_pack_start( GTK_BOX( vbox ), vsplit, TRUE, TRUE, 0 );
2809 gtk_widget_show( vsplit );
2812 GtkWidget* console_window = Console_constructWindow( window );
2813 gtk_paned_pack2( GTK_PANED( vsplit ), console_window, FALSE, TRUE );
2816 GtkWidget* hsplit = gtk_hpaned_new();
2817 gtk_widget_show( hsplit );
2819 gtk_paned_add1( GTK_PANED( vsplit ), hsplit );
2822 m_pXYWnd = new XYWnd();
2823 m_pXYWnd->SetViewType( XY );
2824 GtkWidget* xy_window = GTK_WIDGET( create_framed_widget( m_pXYWnd->GetWidget() ) );
2827 GtkWidget* vsplit2 = gtk_vpaned_new();
2828 gtk_widget_show( vsplit2 );
2829 m_vSplit2 = vsplit2;
2831 if ( CurrentStyle() == eRegular ) {
2832 gtk_paned_add1( GTK_PANED( hsplit ), xy_window );
2833 gtk_paned_add2( GTK_PANED( hsplit ), vsplit2 );
2837 gtk_paned_add1( GTK_PANED( hsplit ), vsplit2 );
2838 gtk_paned_add2( GTK_PANED( hsplit ), xy_window );
2843 m_pCamWnd = NewCamWnd();
2844 GlobalCamera_setCamWnd( *m_pCamWnd );
2845 CamWnd_setParent( *m_pCamWnd, window );
2846 GtkFrame* camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
2848 gtk_paned_add1( GTK_PANED( vsplit2 ), GTK_WIDGET( camera_window ) );
2851 GtkFrame* texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) );
2853 gtk_paned_add2( GTK_PANED( vsplit2 ), GTK_WIDGET( texture_window ) );
2858 gtk_paned_set_position( GTK_PANED( m_vSplit ), g_layout_globals.nXYHeight );
2860 if ( CurrentStyle() == eRegular ) {
2861 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nXYWidth );
2865 gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nCamWidth );
2868 gtk_paned_set_position( GTK_PANED( m_vSplit2 ), g_layout_globals.nCamHeight );
2870 else if ( CurrentStyle() == eFloating ) {
2872 GtkWindow* window = create_persistent_floating_window( "Camera", m_window );
2873 global_accel_connect_window( window );
2874 g_posCamWnd.connect( window );
2876 gtk_widget_show( GTK_WIDGET( window ) );
2878 m_pCamWnd = NewCamWnd();
2879 GlobalCamera_setCamWnd( *m_pCamWnd );
2882 GtkFrame* frame = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) );
2883 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( frame ) );
2885 CamWnd_setParent( *m_pCamWnd, window );
2887 g_floating_windows.push_back( GTK_WIDGET( window ) );
2891 GtkWindow* window = create_persistent_floating_window( ViewType_getTitle( XY ), m_window );
2892 global_accel_connect_window( window );
2893 g_posXYWnd.connect( window );
2895 m_pXYWnd = new XYWnd();
2896 m_pXYWnd->m_parent = window;
2897 m_pXYWnd->SetViewType( XY );
2901 GtkFrame* frame = create_framed_widget( m_pXYWnd->GetWidget() );
2902 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( frame ) );
2904 XY_Top_Shown_Construct( window );
2906 g_floating_windows.push_back( GTK_WIDGET( window ) );
2910 GtkWindow* window = create_persistent_floating_window( ViewType_getTitle( XZ ), m_window );
2911 global_accel_connect_window( window );
2912 g_posXZWnd.connect( window );
2914 m_pXZWnd = new XYWnd();
2915 m_pXZWnd->m_parent = window;
2916 m_pXZWnd->SetViewType( XZ );
2919 GtkFrame* frame = create_framed_widget( m_pXZWnd->GetWidget() );
2920 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( frame ) );
2923 XZ_Front_Shown_Construct( window );
2925 g_floating_windows.push_back( GTK_WIDGET( window ) );
2929 GtkWindow* window = create_persistent_floating_window( ViewType_getTitle( YZ ), m_window );
2930 global_accel_connect_window( window );
2931 g_posYZWnd.connect( window );
2933 m_pYZWnd = new XYWnd();
2934 m_pYZWnd->m_parent = window;
2935 m_pYZWnd->SetViewType( YZ );
2938 GtkFrame* frame = create_framed_widget( m_pYZWnd->GetWidget() );
2939 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( frame ) );
2942 YZ_Side_Shown_Construct( window );
2944 g_floating_windows.push_back( GTK_WIDGET( window ) );
2948 GtkFrame* frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
2949 g_page_textures = GroupDialog_addPage( "Textures", GTK_WIDGET( frame ), TextureBrowserExportTitleCaller() );
2956 m_pCamWnd = NewCamWnd();
2957 GlobalCamera_setCamWnd( *m_pCamWnd );
2958 CamWnd_setParent( *m_pCamWnd, window );
2960 GtkWidget* camera = CamWnd_getWidget( *m_pCamWnd );
2962 m_pYZWnd = new XYWnd();
2963 m_pYZWnd->SetViewType( YZ );
2965 GtkWidget* yz = m_pYZWnd->GetWidget();
2967 m_pXYWnd = new XYWnd();
2968 m_pXYWnd->SetViewType( XY );
2970 GtkWidget* xy = m_pXYWnd->GetWidget();
2972 m_pXZWnd = new XYWnd();
2973 m_pXZWnd->SetViewType( XZ );
2975 GtkWidget* xz = m_pXZWnd->GetWidget();
2977 GtkHPaned* split = create_split_views( camera, yz, xy, xz );
2978 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( split ), TRUE, TRUE, 0 );
2981 GtkFrame* frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
2982 g_page_textures = GroupDialog_addPage( "Textures", GTK_WIDGET( frame ), TextureBrowserExportTitleCaller() );
2986 EntityList_constructWindow( window );
2987 PreferencesDialog_constructWindow( window );
2988 FindTextureDialog_constructWindow( window );
2989 SurfaceInspector_constructWindow( window );
2990 PatchInspector_constructWindow( window );
2992 SetActiveXY( m_pXYWnd );
2994 AddGridChangeCallback( SetGridStatusCaller( *this ) );
2995 AddGridChangeCallback( ReferenceCaller<MainFrame, XY_UpdateAllWindows>( *this ) );
2997 g_defaultToolMode = DragMode;
2998 g_defaultToolMode();
2999 SetStatusText( m_command_status, c_TranslateMode_status );
3001 EverySecondTimer_enable();
3003 //GlobalShortcuts_reportUnregistered();
3006 void MainFrame::SaveWindowInfo(){
3007 if ( !FloatingGroupDialog() ) {
3008 g_layout_globals.nXYHeight = gtk_paned_get_position( GTK_PANED( m_vSplit ) );
3010 if ( CurrentStyle() != eRegular ) {
3011 g_layout_globals.nCamWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3015 g_layout_globals.nXYWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) );
3018 g_layout_globals.nCamHeight = gtk_paned_get_position( GTK_PANED( m_vSplit2 ) );
3021 g_layout_globals.m_position = m_position_tracker.getPosition();
3023 g_layout_globals.nState = gdk_window_get_state( GTK_WIDGET( m_window )->window );
3026 void MainFrame::Shutdown(){
3027 EverySecondTimer_disable();
3029 EntityList_destroyWindow();
3038 TextureBrowser_destroyWindow();
3040 DeleteCamWnd( m_pCamWnd );
3043 PreferencesDialog_destroyWindow();
3044 SurfaceInspector_destroyWindow();
3045 FindTextureDialog_destroyWindow();
3046 PatchInspector_destroyWindow();
3048 g_DbgDlg.destroyWindow();
3050 // destroying group-dialog last because it may contain texture-browser
3051 GroupDialog_destroyWindow();
3054 void MainFrame::RedrawStatusText(){
3055 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_command_status] ), m_command_status.c_str() );
3056 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_position_status] ), m_position_status.c_str() );
3057 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_brushcount_status] ), m_brushcount_status.c_str() );
3058 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_texture_status] ), m_texture_status.c_str() );
3059 gtk_label_set_text( GTK_LABEL( m_pStatusLabel[c_grid_status] ), m_grid_status.c_str() );
3062 void MainFrame::UpdateStatusText(){
3063 m_idleRedrawStatusText.queueDraw();
3066 void MainFrame::SetStatusText( CopiedString& status_text, const char* pText ){
3067 status_text = pText;
3071 void Sys_Status( const char* status ){
3072 if ( g_pParentWnd != 0 ) {
3073 g_pParentWnd->SetStatusText( g_pParentWnd->m_command_status, status );
3077 int getRotateIncrement(){
3078 return static_cast<int>( g_si_globals.rotate );
3081 int getFarClipDistance(){
3082 return g_camwindow_globals.m_nCubicScale;
3085 float ( *GridStatus_getGridSize )() = GetGridSize;
3086 int ( *GridStatus_getRotateIncrement )() = getRotateIncrement;
3087 int ( *GridStatus_getFarClipDistance )() = getFarClipDistance;
3088 bool ( *GridStatus_getTextureLockEnabled )();
3090 void MainFrame::SetGridStatus(){
3091 StringOutputStream status( 64 );
3092 const char* lock = ( GridStatus_getTextureLockEnabled() ) ? "ON" : "OFF";
3093 status << ( GetSnapGridSize() > 0 ? "G:" : "g:" ) << GridStatus_getGridSize()
3094 << " R:" << GridStatus_getRotateIncrement()
3095 << " C:" << GridStatus_getFarClipDistance()
3097 SetStatusText( m_grid_status, status.c_str() );
3100 void GridStatus_onTextureLockEnabledChanged(){
3101 if ( g_pParentWnd != 0 ) {
3102 g_pParentWnd->SetGridStatus();
3106 void GlobalGL_sharedContextCreated(){
3107 GLFont *g_font = NULL;
3109 // report OpenGL information
3110 globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) << "\n";
3111 globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) << "\n";
3112 globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) << "\n";
3113 globalOutputStream() << "GL_EXTENSIONS: " << reinterpret_cast<const char*>( glGetString( GL_EXTENSIONS ) ) << "\n";
3115 QGL_sharedContextCreated( GlobalOpenGL() );
3117 ShaderCache_extensionsInitialised();
3119 GlobalShaderCache().realise();
3123 /* win32 is dodgy here, just use courier new then */
3124 g_font = glfont_create( "arial 9" );
3126 GtkSettings *settings = gtk_settings_get_default();
3128 g_object_get( settings, "gtk-font-name", &fontname, NULL );
3129 g_font = glfont_create( fontname );
3132 GlobalOpenGL().m_font = g_font;
3135 void GlobalGL_sharedContextDestroyed(){
3136 Textures_Unrealise();
3137 GlobalShaderCache().unrealise();
3139 QGL_sharedContextDestroyed( GlobalOpenGL() );
3143 void Layout_constructPreferences( PreferencesPage& page ){
3145 const char* layouts[] = { "window1.png", "window2.png", "window3.png", "window4.png" };
3146 page.appendRadioIcons(
3148 STRING_ARRAY_RANGE( layouts ),
3149 LatchedIntImportCaller( g_Layout_viewStyle ),
3150 IntExportCaller( g_Layout_viewStyle.m_latched )
3153 page.appendCheckBox(
3154 "", "Detachable Menus",
3155 LatchedBoolImportCaller( g_Layout_enableDetachableMenus ),
3156 BoolExportCaller( g_Layout_enableDetachableMenus.m_latched )
3158 if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) {
3159 page.appendCheckBox(
3160 "", "Patch Toolbar",
3161 LatchedBoolImportCaller( g_Layout_enablePatchToolbar ),
3162 BoolExportCaller( g_Layout_enablePatchToolbar.m_latched )
3165 page.appendCheckBox(
3166 "", "Plugin Toolbar",
3167 LatchedBoolImportCaller( g_Layout_enablePluginToolbar ),
3168 BoolExportCaller( g_Layout_enablePluginToolbar.m_latched )
3172 void Layout_constructPage( PreferenceGroup& group ){
3173 PreferencesPage page( group.createPage( "Layout", "Layout Preferences" ) );
3174 Layout_constructPreferences( page );
3177 void Layout_registerPreferencesPage(){
3178 PreferencesDialog_addInterfacePage( FreeCaller1<PreferenceGroup&, Layout_constructPage>() );
3182 #include "preferencesystem.h"
3183 #include "stringio.h"
3185 void MainFrame_Construct(){
3186 GlobalCommands_insert( "OpenManual", FreeCaller<OpenHelpURL>(), Accelerator( GDK_F1 ) );
3188 GlobalCommands_insert( "Sleep", FreeCaller<thunk_OnSleep>(), Accelerator( 'P', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3189 GlobalCommands_insert( "NewMap", FreeCaller<NewMap>() );
3190 GlobalCommands_insert( "OpenMap", FreeCaller<OpenMap>(), Accelerator( 'O', (GdkModifierType)GDK_CONTROL_MASK ) );
3191 GlobalCommands_insert( "ImportMap", FreeCaller<ImportMap>() );
3192 GlobalCommands_insert( "SaveMap", FreeCaller<SaveMap>(), Accelerator( 'S', (GdkModifierType)GDK_CONTROL_MASK ) );
3193 GlobalCommands_insert( "SaveMapAs", FreeCaller<SaveMapAs>() );
3194 GlobalCommands_insert( "ExportSelected", FreeCaller<ExportMap>() );
3195 GlobalCommands_insert( "SaveRegion", FreeCaller<SaveRegion>() );
3196 GlobalCommands_insert( "RefreshReferences", FreeCaller<RefreshReferences>() );
3197 GlobalCommands_insert( "ProjectSettings", FreeCaller<DoProjectSettings>() );
3198 GlobalCommands_insert( "Exit", FreeCaller<Exit>() );
3200 GlobalCommands_insert( "Undo", FreeCaller<Undo>(), Accelerator( 'Z', (GdkModifierType)GDK_CONTROL_MASK ) );
3201 GlobalCommands_insert( "Redo", FreeCaller<Redo>(), Accelerator( 'Y', (GdkModifierType)GDK_CONTROL_MASK ) );
3202 GlobalCommands_insert( "Copy", FreeCaller<Copy>(), Accelerator( 'C', (GdkModifierType)GDK_CONTROL_MASK ) );
3203 GlobalCommands_insert( "Paste", FreeCaller<Paste>(), Accelerator( 'V', (GdkModifierType)GDK_CONTROL_MASK ) );
3204 GlobalCommands_insert( "PasteToCamera", FreeCaller<PasteToCamera>(), Accelerator( 'V', (GdkModifierType)GDK_MOD1_MASK ) );
3205 GlobalCommands_insert( "CloneSelection", FreeCaller<Selection_Clone>(), Accelerator( GDK_space ) );
3206 GlobalCommands_insert( "CloneSelectionAndMakeUnique", FreeCaller<Selection_Clone_MakeUnique>(), Accelerator( GDK_space, (GdkModifierType)GDK_SHIFT_MASK ) );
3207 GlobalCommands_insert( "DeleteSelection", FreeCaller<deleteSelection>(), Accelerator( GDK_BackSpace ) );
3208 GlobalCommands_insert( "ParentSelection", FreeCaller<Scene_parentSelected>() );
3209 GlobalCommands_insert( "UnSelectSelection", FreeCaller<Selection_Deselect>(), Accelerator( GDK_Escape ) );
3210 GlobalCommands_insert( "InvertSelection", FreeCaller<Select_Invert>(), Accelerator( 'I' ) );
3211 GlobalCommands_insert( "SelectInside", FreeCaller<Select_Inside>() );
3212 GlobalCommands_insert( "SelectTouching", FreeCaller<Select_Touching>() );
3213 GlobalCommands_insert( "ExpandSelectionToEntities", FreeCaller<Scene_ExpandSelectionToEntities>(), Accelerator( 'E', (GdkModifierType)( GDK_MOD1_MASK | GDK_CONTROL_MASK ) ) );
3214 GlobalCommands_insert( "Preferences", FreeCaller<PreferencesDialog_showDialog>(), Accelerator( 'P' ) );
3216 GlobalCommands_insert( "ToggleConsole", FreeCaller<Console_ToggleShow>(), Accelerator( 'O' ) );
3217 GlobalCommands_insert( "ToggleEntityInspector", FreeCaller<EntityInspector_ToggleShow>(), Accelerator( 'N' ) );
3218 GlobalCommands_insert( "EntityList", FreeCaller<EntityList_toggleShown>(), Accelerator( 'L' ) );
3220 GlobalCommands_insert( "ShowHidden", FreeCaller<Select_ShowAllHidden>(), Accelerator( 'H', (GdkModifierType)GDK_SHIFT_MASK ) );
3221 GlobalCommands_insert( "HideSelected", FreeCaller<HideSelected>(), Accelerator( 'H' ) );
3223 GlobalToggles_insert( "DragVertices", FreeCaller<SelectVertexMode>(), ToggleItem::AddCallbackCaller( g_vertexMode_button ), Accelerator( 'V' ) );
3224 GlobalToggles_insert( "DragEdges", FreeCaller<SelectEdgeMode>(), ToggleItem::AddCallbackCaller( g_edgeMode_button ), Accelerator( 'E' ) );
3225 GlobalToggles_insert( "DragFaces", FreeCaller<SelectFaceMode>(), ToggleItem::AddCallbackCaller( g_faceMode_button ), Accelerator( 'F' ) );
3227 GlobalCommands_insert( "MirrorSelectionX", FreeCaller<Selection_Flipx>() );
3228 GlobalCommands_insert( "RotateSelectionX", FreeCaller<Selection_Rotatex>() );
3229 GlobalCommands_insert( "MirrorSelectionY", FreeCaller<Selection_Flipy>() );
3230 GlobalCommands_insert( "RotateSelectionY", FreeCaller<Selection_Rotatey>() );
3231 GlobalCommands_insert( "MirrorSelectionZ", FreeCaller<Selection_Flipz>() );
3232 GlobalCommands_insert( "RotateSelectionZ", FreeCaller<Selection_Rotatez>() );
3234 GlobalCommands_insert( "ArbitraryRotation", FreeCaller<DoRotateDlg>() );
3235 GlobalCommands_insert( "ArbitraryScale", FreeCaller<DoScaleDlg>() );
3237 GlobalCommands_insert( "BuildMenuCustomize", FreeCaller<DoBuildMenu>() );
3239 GlobalCommands_insert( "FindBrush", FreeCaller<DoFind>() );
3241 GlobalCommands_insert( "MapInfo", FreeCaller<DoMapInfo>(), Accelerator( 'M' ) );
3244 GlobalToggles_insert( "ToggleClipper", FreeCaller<ClipperMode>(), ToggleItem::AddCallbackCaller( g_clipper_button ), Accelerator( 'X' ) );
3246 GlobalToggles_insert( "MouseTranslate", FreeCaller<TranslateMode>(), ToggleItem::AddCallbackCaller( g_translatemode_button ), Accelerator( 'W' ) );
3247 GlobalToggles_insert( "MouseRotate", FreeCaller<RotateMode>(), ToggleItem::AddCallbackCaller( g_rotatemode_button ), Accelerator( 'R' ) );
3248 GlobalToggles_insert( "MouseScale", FreeCaller<ScaleMode>(), ToggleItem::AddCallbackCaller( g_scalemode_button ) );
3249 GlobalToggles_insert( "MouseDrag", FreeCaller<DragMode>(), ToggleItem::AddCallbackCaller( g_dragmode_button ), Accelerator( 'Q' ) );
3251 GlobalCommands_insert( "ColorSchemeOriginal", FreeCaller<ColorScheme_Original>() );
3252 GlobalCommands_insert( "ColorSchemeQER", FreeCaller<ColorScheme_QER>() );
3253 GlobalCommands_insert( "ColorSchemeBlackAndGreen", FreeCaller<ColorScheme_Black>() );
3254 GlobalCommands_insert( "ColorSchemeYdnar", FreeCaller<ColorScheme_Ydnar>() );
3255 GlobalCommands_insert( "ChooseTextureBackgroundColor", makeCallback( g_ColoursMenu.m_textureback ) );
3256 GlobalCommands_insert( "ChooseGridBackgroundColor", makeCallback( g_ColoursMenu.m_xyback ) );
3257 GlobalCommands_insert( "ChooseGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor ) );
3258 GlobalCommands_insert( "ChooseGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor ) );
3259 GlobalCommands_insert( "ChooseSmallGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor_alt ) );
3260 GlobalCommands_insert( "ChooseSmallGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor_alt ) );
3261 GlobalCommands_insert( "ChooseGridTextColor", makeCallback( g_ColoursMenu.m_gridtext ) );
3262 GlobalCommands_insert( "ChooseGridBlockColor", makeCallback( g_ColoursMenu.m_gridblock ) );
3263 GlobalCommands_insert( "ChooseBrushColor", makeCallback( g_ColoursMenu.m_brush ) );
3264 GlobalCommands_insert( "ChooseCameraBackgroundColor", makeCallback( g_ColoursMenu.m_cameraback ) );
3265 GlobalCommands_insert( "ChooseSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush ) );
3266 GlobalCommands_insert( "ChooseCameraSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush3d ) );
3267 GlobalCommands_insert( "ChooseClipperColor", makeCallback( g_ColoursMenu.m_clipper ) );
3268 GlobalCommands_insert( "ChooseOrthoViewNameColor", makeCallback( g_ColoursMenu.m_viewname ) );
3271 GlobalCommands_insert( "CSGSubtract", FreeCaller<CSG_Subtract>(), Accelerator( 'U', (GdkModifierType)GDK_SHIFT_MASK ) );
3272 GlobalCommands_insert( "CSGMerge", FreeCaller<CSG_Merge>(), Accelerator( 'U', (GdkModifierType)GDK_CONTROL_MASK ) );
3273 GlobalCommands_insert( "CSGHollow", FreeCaller<CSG_MakeHollow>() );
3275 Grid_registerCommands();
3277 GlobalCommands_insert( "SnapToGrid", FreeCaller<Selection_SnapToGrid>(), Accelerator( 'G', (GdkModifierType)GDK_CONTROL_MASK ) );
3279 GlobalCommands_insert( "SelectAllOfType", FreeCaller<Select_AllOfType>(), Accelerator( 'A', (GdkModifierType)GDK_SHIFT_MASK ) );
3281 GlobalCommands_insert( "TexRotateClock", FreeCaller<Texdef_RotateClockwise>(), Accelerator( GDK_Next, (GdkModifierType)GDK_SHIFT_MASK ) );
3282 GlobalCommands_insert( "TexRotateCounter", FreeCaller<Texdef_RotateAntiClockwise>(), Accelerator( GDK_Prior, (GdkModifierType)GDK_SHIFT_MASK ) );
3283 GlobalCommands_insert( "TexScaleUp", FreeCaller<Texdef_ScaleUp>(), Accelerator( GDK_Up, (GdkModifierType)GDK_CONTROL_MASK ) );
3284 GlobalCommands_insert( "TexScaleDown", FreeCaller<Texdef_ScaleDown>(), Accelerator( GDK_Down, (GdkModifierType)GDK_CONTROL_MASK ) );
3285 GlobalCommands_insert( "TexScaleLeft", FreeCaller<Texdef_ScaleLeft>(), Accelerator( GDK_Left, (GdkModifierType)GDK_CONTROL_MASK ) );
3286 GlobalCommands_insert( "TexScaleRight", FreeCaller<Texdef_ScaleRight>(), Accelerator( GDK_Right, (GdkModifierType)GDK_CONTROL_MASK ) );
3287 GlobalCommands_insert( "TexShiftUp", FreeCaller<Texdef_ShiftUp>(), Accelerator( GDK_Up, (GdkModifierType)GDK_SHIFT_MASK ) );
3288 GlobalCommands_insert( "TexShiftDown", FreeCaller<Texdef_ShiftDown>(), Accelerator( GDK_Down, (GdkModifierType)GDK_SHIFT_MASK ) );
3289 GlobalCommands_insert( "TexShiftLeft", FreeCaller<Texdef_ShiftLeft>(), Accelerator( GDK_Left, (GdkModifierType)GDK_SHIFT_MASK ) );
3290 GlobalCommands_insert( "TexShiftRight", FreeCaller<Texdef_ShiftRight>(), Accelerator( GDK_Right, (GdkModifierType)GDK_SHIFT_MASK ) );
3292 GlobalCommands_insert( "MoveSelectionDOWN", FreeCaller<Selection_MoveDown>(), Accelerator( GDK_KP_Subtract ) );
3293 GlobalCommands_insert( "MoveSelectionUP", FreeCaller<Selection_MoveUp>(), Accelerator( GDK_KP_Add ) );
3295 GlobalCommands_insert( "SelectNudgeLeft", FreeCaller<Selection_NudgeLeft>(), Accelerator( GDK_Left, (GdkModifierType)GDK_MOD1_MASK ) );
3296 GlobalCommands_insert( "SelectNudgeRight", FreeCaller<Selection_NudgeRight>(), Accelerator( GDK_Right, (GdkModifierType)GDK_MOD1_MASK ) );
3297 GlobalCommands_insert( "SelectNudgeUp", FreeCaller<Selection_NudgeUp>(), Accelerator( GDK_Up, (GdkModifierType)GDK_MOD1_MASK ) );
3298 GlobalCommands_insert( "SelectNudgeDown", FreeCaller<Selection_NudgeDown>(), Accelerator( GDK_Down, (GdkModifierType)GDK_MOD1_MASK ) );
3300 Patch_registerCommands();
3301 XYShow_registerCommands();
3303 typedef FreeCaller1<const Selectable&, ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller;
3304 GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() );
3306 GlobalPreferenceSystem().registerPreference( "DetachableMenus", BoolImportStringCaller( g_Layout_enableDetachableMenus.m_latched ), BoolExportStringCaller( g_Layout_enableDetachableMenus.m_latched ) );
3307 GlobalPreferenceSystem().registerPreference( "PatchToolBar", BoolImportStringCaller( g_Layout_enablePatchToolbar.m_latched ), BoolExportStringCaller( g_Layout_enablePatchToolbar.m_latched ) );
3308 GlobalPreferenceSystem().registerPreference( "PluginToolBar", BoolImportStringCaller( g_Layout_enablePluginToolbar.m_latched ), BoolExportStringCaller( g_Layout_enablePluginToolbar.m_latched ) );
3309 GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", IntImportStringCaller( g_Layout_viewStyle.m_latched ), IntExportStringCaller( g_Layout_viewStyle.m_latched ) );
3310 GlobalPreferenceSystem().registerPreference( "XYHeight", IntImportStringCaller( g_layout_globals.nXYHeight ), IntExportStringCaller( g_layout_globals.nXYHeight ) );
3311 GlobalPreferenceSystem().registerPreference( "XYWidth", IntImportStringCaller( g_layout_globals.nXYWidth ), IntExportStringCaller( g_layout_globals.nXYWidth ) );
3312 GlobalPreferenceSystem().registerPreference( "CamWidth", IntImportStringCaller( g_layout_globals.nCamWidth ), IntExportStringCaller( g_layout_globals.nCamWidth ) );
3313 GlobalPreferenceSystem().registerPreference( "CamHeight", IntImportStringCaller( g_layout_globals.nCamHeight ), IntExportStringCaller( g_layout_globals.nCamHeight ) );
3315 GlobalPreferenceSystem().registerPreference( "State", IntImportStringCaller( g_layout_globals.nState ), IntExportStringCaller( g_layout_globals.nState ) );
3316 GlobalPreferenceSystem().registerPreference( "PositionX", IntImportStringCaller( g_layout_globals.m_position.x ), IntExportStringCaller( g_layout_globals.m_position.x ) );
3317 GlobalPreferenceSystem().registerPreference( "PositionY", IntImportStringCaller( g_layout_globals.m_position.y ), IntExportStringCaller( g_layout_globals.m_position.y ) );
3318 GlobalPreferenceSystem().registerPreference( "Width", IntImportStringCaller( g_layout_globals.m_position.w ), IntExportStringCaller( g_layout_globals.m_position.w ) );
3319 GlobalPreferenceSystem().registerPreference( "Height", IntImportStringCaller( g_layout_globals.m_position.h ), IntExportStringCaller( g_layout_globals.m_position.h ) );
3321 GlobalPreferenceSystem().registerPreference( "CamWnd", WindowPositionTrackerImportStringCaller( g_posCamWnd ), WindowPositionTrackerExportStringCaller( g_posCamWnd ) );
3322 GlobalPreferenceSystem().registerPreference( "XYWnd", WindowPositionTrackerImportStringCaller( g_posXYWnd ), WindowPositionTrackerExportStringCaller( g_posXYWnd ) );
3323 GlobalPreferenceSystem().registerPreference( "YZWnd", WindowPositionTrackerImportStringCaller( g_posYZWnd ), WindowPositionTrackerExportStringCaller( g_posYZWnd ) );
3324 GlobalPreferenceSystem().registerPreference( "XZWnd", WindowPositionTrackerImportStringCaller( g_posXZWnd ), WindowPositionTrackerExportStringCaller( g_posXZWnd ) );
3327 const char* ENGINEPATH_ATTRIBUTE =
3328 #if defined( WIN32 )
3330 #elif defined( __APPLE__ )
3332 #elif defined( __linux__ ) || defined ( __FreeBSD__ )
3335 #error "unknown platform"
3338 StringOutputStream path( 256 );
3339 path << DirectoryCleaned( g_pGameDescription->getRequiredKeyValue( ENGINEPATH_ATTRIBUTE ) );
3340 g_strEnginePath = path.c_str();
3343 GlobalPreferenceSystem().registerPreference( "EnginePath", CopiedStringImportStringCaller( g_strEnginePath ), CopiedStringExportStringCaller( g_strEnginePath ) );
3345 g_Layout_viewStyle.useLatched();
3346 g_Layout_enableDetachableMenus.useLatched();
3347 g_Layout_enablePatchToolbar.useLatched();
3348 g_Layout_enablePluginToolbar.useLatched();
3350 Layout_registerPreferencesPage();
3351 Paths_registerPreferencesPage();
3353 g_brushCount.setCountChangedCallback( FreeCaller<QE_brushCountChanged>() );
3354 g_entityCount.setCountChangedCallback( FreeCaller<QE_entityCountChanged>() );
3355 GlobalEntityCreator().setCounter( &g_entityCount );
3357 GLWidget_sharedContextCreated = GlobalGL_sharedContextCreated;
3358 GLWidget_sharedContextDestroyed = GlobalGL_sharedContextDestroyed;
3360 GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver );
3363 void MainFrame_Destroy(){
3364 GlobalEntityClassManager().detach( g_WorldspawnColourEntityClassObserver );
3366 GlobalEntityCreator().setCounter( 0 );
3367 g_entityCount.setCountChangedCallback( Callback() );
3368 g_brushCount.setCountChangedCallback( Callback() );
3372 void GLWindow_Construct(){
3373 GlobalPreferenceSystem().registerPreference( "MouseButtons", IntImportStringCaller( g_glwindow_globals.m_nMouseType ), IntExportStringCaller( g_glwindow_globals.m_nMouseType ) );
3376 void GLWindow_Destroy(){