| 1 | /* |
| 2 | Copyright (C) 1999-2006 Id Software, Inc. and contributors. |
| 3 | For a list of contributors, see the accompanying CONTRIBUTORS file. |
| 4 | |
| 5 | This file is part of GtkRadiant. |
| 6 | |
| 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. |
| 11 | |
| 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. |
| 16 | |
| 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 |
| 20 | */ |
| 21 | |
| 22 | // |
| 23 | // Main Window for Q3Radiant |
| 24 | // |
| 25 | // Leonardo Zide ([email protected]) |
| 26 | // |
| 27 | |
| 28 | #include "mainframe.h" |
| 29 | #include "globaldefs.h" |
| 30 | |
| 31 | #include <gtk/gtk.h> |
| 32 | |
| 33 | #include "ifilesystem.h" |
| 34 | #include "iundo.h" |
| 35 | #include "editable.h" |
| 36 | #include "ientity.h" |
| 37 | #include "ishaders.h" |
| 38 | #include "igl.h" |
| 39 | #include "moduleobserver.h" |
| 40 | |
| 41 | #include <ctime> |
| 42 | |
| 43 | #include <gdk/gdkkeysyms.h> |
| 44 | |
| 45 | |
| 46 | #include "cmdlib.h" |
| 47 | #include "stream/stringstream.h" |
| 48 | #include "signal/isignal.h" |
| 49 | #include "os/path.h" |
| 50 | #include "os/file.h" |
| 51 | #include "eclasslib.h" |
| 52 | #include "moduleobservers.h" |
| 53 | |
| 54 | #include "gtkutil/clipboard.h" |
| 55 | #include "gtkutil/frame.h" |
| 56 | #include "gtkutil/glwidget.h" |
| 57 | #include "gtkutil/image.h" |
| 58 | #include "gtkutil/menu.h" |
| 59 | #include "gtkutil/paned.h" |
| 60 | |
| 61 | #include "autosave.h" |
| 62 | #include "build.h" |
| 63 | #include "brushmanip.h" |
| 64 | #include "brushmodule.h" |
| 65 | #include "camwindow.h" |
| 66 | #include "csg.h" |
| 67 | #include "commands.h" |
| 68 | #include "console.h" |
| 69 | #include "entity.h" |
| 70 | #include "entityinspector.h" |
| 71 | #include "entitylist.h" |
| 72 | #include "filters.h" |
| 73 | #include "findtexturedialog.h" |
| 74 | #include "grid.h" |
| 75 | #include "groupdialog.h" |
| 76 | #include "gtkdlgs.h" |
| 77 | #include "gtkmisc.h" |
| 78 | #include "help.h" |
| 79 | #include "map.h" |
| 80 | #include "mru.h" |
| 81 | #include "multimon.h" |
| 82 | #include "patchdialog.h" |
| 83 | #include "patchmanip.h" |
| 84 | #include "plugin.h" |
| 85 | #include "pluginmanager.h" |
| 86 | #include "pluginmenu.h" |
| 87 | #include "plugintoolbar.h" |
| 88 | #include "preferences.h" |
| 89 | #include "qe3.h" |
| 90 | #include "qgl.h" |
| 91 | #include "select.h" |
| 92 | #include "server.h" |
| 93 | #include "surfacedialog.h" |
| 94 | #include "textures.h" |
| 95 | #include "texwindow.h" |
| 96 | #include "modelbrowser.h" |
| 97 | #include "url.h" |
| 98 | #include "xywindow.h" |
| 99 | #include "windowobservers.h" |
| 100 | #include "renderstate.h" |
| 101 | #include "feedback.h" |
| 102 | #include "referencecache.h" |
| 103 | #include "texwindow.h" |
| 104 | #include "filterbar.h" |
| 105 | |
| 106 | #if GDEF_OS_WINDOWS |
| 107 | #include <process.h> |
| 108 | #else |
| 109 | #include <spawn.h> |
| 110 | #endif |
| 111 | |
| 112 | #ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET |
| 113 | /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */ |
| 114 | #define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget) g_object_set_data( G_OBJECT( window ), "glwidget", G_OBJECT( widget ) ) |
| 115 | #else |
| 116 | #define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget) |
| 117 | #endif |
| 118 | |
| 119 | #define GARUX_DISABLE_GTKTHEME |
| 120 | #ifndef GARUX_DISABLE_GTKTHEME |
| 121 | #include "gtktheme.h" |
| 122 | #endif |
| 123 | |
| 124 | struct layout_globals_t |
| 125 | { |
| 126 | WindowPosition m_position; |
| 127 | |
| 128 | |
| 129 | int nXYHeight; |
| 130 | int nXYWidth; |
| 131 | int nCamWidth; |
| 132 | int nCamHeight; |
| 133 | int nState; |
| 134 | |
| 135 | layout_globals_t() : |
| 136 | m_position( -1, -1, 640, 480 ), |
| 137 | |
| 138 | nXYHeight( 350 ), |
| 139 | nXYWidth( 600 ), |
| 140 | nCamWidth( 300 ), |
| 141 | nCamHeight( 210 ), |
| 142 | nState( 0 ){ |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | layout_globals_t g_layout_globals; |
| 147 | //glwindow_globals_t g_glwindow_globals; |
| 148 | |
| 149 | |
| 150 | // VFS |
| 151 | |
| 152 | bool g_vfsInitialized = false; |
| 153 | |
| 154 | void VFS_Init(){ |
| 155 | if ( g_vfsInitialized ) return; |
| 156 | QE_InitVFS(); |
| 157 | GlobalFileSystem().initialise(); |
| 158 | g_vfsInitialized = true; |
| 159 | } |
| 160 | |
| 161 | void VFS_Shutdown(){ |
| 162 | if ( !g_vfsInitialized ) return; |
| 163 | GlobalFileSystem().shutdown(); |
| 164 | g_vfsInitialized = false; |
| 165 | } |
| 166 | |
| 167 | void VFS_Refresh(){ |
| 168 | if ( !g_vfsInitialized ) return; |
| 169 | GlobalFileSystem().clear(); |
| 170 | QE_InitVFS(); |
| 171 | GlobalFileSystem().refresh(); |
| 172 | g_vfsInitialized = true; |
| 173 | // also refresh models |
| 174 | RefreshReferences(); |
| 175 | // also refresh texture browser |
| 176 | TextureBrowser_RefreshShaders(); |
| 177 | // also show textures (all or common) |
| 178 | TextureBrowser_ShowStartupShaders( GlobalTextureBrowser() ); |
| 179 | } |
| 180 | |
| 181 | void VFS_Restart(){ |
| 182 | VFS_Shutdown(); |
| 183 | VFS_Init(); |
| 184 | } |
| 185 | |
| 186 | class VFSModuleObserver : public ModuleObserver |
| 187 | { |
| 188 | public: |
| 189 | void realise(){ |
| 190 | VFS_Init(); |
| 191 | } |
| 192 | |
| 193 | void unrealise(){ |
| 194 | VFS_Shutdown(); |
| 195 | } |
| 196 | }; |
| 197 | |
| 198 | VFSModuleObserver g_VFSModuleObserver; |
| 199 | |
| 200 | void VFS_Construct(){ |
| 201 | Radiant_attachHomePathsObserver( g_VFSModuleObserver ); |
| 202 | } |
| 203 | |
| 204 | void VFS_Destroy(){ |
| 205 | Radiant_detachHomePathsObserver( g_VFSModuleObserver ); |
| 206 | } |
| 207 | |
| 208 | // Home Paths |
| 209 | |
| 210 | #if GDEF_OS_WINDOWS |
| 211 | #include <shlobj.h> |
| 212 | #include <objbase.h> |
| 213 | const GUID qFOLDERID_SavedGames = {0x4C5C32FF, 0xBB9D, 0x43b0, {0xB5, 0xB4, 0x2D, 0x72, 0xE5, 0x4E, 0xAA, 0xA4}}; |
| 214 | #define qREFKNOWNFOLDERID GUID |
| 215 | #define qKF_FLAG_CREATE 0x8000 |
| 216 | #define qKF_FLAG_NO_ALIAS 0x1000 |
| 217 | typedef HRESULT ( WINAPI qSHGetKnownFolderPath_t )( qREFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath ); |
| 218 | static qSHGetKnownFolderPath_t *qSHGetKnownFolderPath; |
| 219 | #endif |
| 220 | |
| 221 | void HomePaths_Realise(){ |
| 222 | do |
| 223 | { |
| 224 | const char* prefix = g_pGameDescription->getKeyValue( "prefix" ); |
| 225 | if ( !string_empty( prefix ) ) { |
| 226 | StringOutputStream path( 256 ); |
| 227 | |
| 228 | #if GDEF_OS_MACOS |
| 229 | path.clear(); |
| 230 | path << DirectoryCleaned( g_get_home_dir() ) << "Library/Application Support" << ( prefix + 1 ) << "/"; |
| 231 | if ( file_is_directory( path.c_str() ) ) { |
| 232 | g_qeglobals.m_userEnginePath = path.c_str(); |
| 233 | break; |
| 234 | } |
| 235 | path.clear(); |
| 236 | path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/"; |
| 237 | #elif GDEF_OS_WINDOWS |
| 238 | TCHAR mydocsdir[MAX_PATH + 1]; |
| 239 | wchar_t *mydocsdirw; |
| 240 | HMODULE shfolder = LoadLibrary( "shfolder.dll" ); |
| 241 | if ( shfolder ) { |
| 242 | qSHGetKnownFolderPath = (qSHGetKnownFolderPath_t *) GetProcAddress( shfolder, "SHGetKnownFolderPath" ); |
| 243 | } |
| 244 | else{ |
| 245 | qSHGetKnownFolderPath = NULL; |
| 246 | } |
| 247 | CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ); |
| 248 | if ( qSHGetKnownFolderPath && qSHGetKnownFolderPath( qFOLDERID_SavedGames, qKF_FLAG_CREATE | qKF_FLAG_NO_ALIAS, NULL, &mydocsdirw ) == S_OK ) { |
| 249 | memset( mydocsdir, 0, sizeof( mydocsdir ) ); |
| 250 | wcstombs( mydocsdir, mydocsdirw, sizeof( mydocsdir ) - 1 ); |
| 251 | CoTaskMemFree( mydocsdirw ); |
| 252 | path.clear(); |
| 253 | path << DirectoryCleaned( mydocsdir ) << ( prefix + 1 ) << "/"; |
| 254 | if ( file_is_directory( path.c_str() ) ) { |
| 255 | g_qeglobals.m_userEnginePath = path.c_str(); |
| 256 | CoUninitialize(); |
| 257 | FreeLibrary( shfolder ); |
| 258 | break; |
| 259 | } |
| 260 | } |
| 261 | CoUninitialize(); |
| 262 | if ( shfolder ) { |
| 263 | FreeLibrary( shfolder ); |
| 264 | } |
| 265 | if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir ) ) ) { |
| 266 | path.clear(); |
| 267 | path << DirectoryCleaned( mydocsdir ) << "My Games/" << ( prefix + 1 ) << "/"; |
| 268 | // win32: only add it if it already exists |
| 269 | if ( file_is_directory( path.c_str() ) ) { |
| 270 | g_qeglobals.m_userEnginePath = path.c_str(); |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | #elif GDEF_OS_XDG |
| 275 | path.clear(); |
| 276 | path << DirectoryCleaned( g_get_user_data_dir() ) << ( prefix + 1 ) << "/"; |
| 277 | if ( file_exists( path.c_str() ) && file_is_directory( path.c_str() ) ) { |
| 278 | g_qeglobals.m_userEnginePath = path.c_str(); |
| 279 | break; |
| 280 | } |
| 281 | else { |
| 282 | path.clear(); |
| 283 | path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/"; |
| 284 | g_qeglobals.m_userEnginePath = path.c_str(); |
| 285 | break; |
| 286 | } |
| 287 | #endif |
| 288 | } |
| 289 | |
| 290 | g_qeglobals.m_userEnginePath = EnginePath_get(); |
| 291 | } |
| 292 | while ( 0 ); |
| 293 | |
| 294 | Q_mkdir( g_qeglobals.m_userEnginePath.c_str() ); |
| 295 | |
| 296 | { |
| 297 | StringOutputStream path( 256 ); |
| 298 | path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/'; |
| 299 | g_qeglobals.m_userGamePath = path.c_str(); |
| 300 | } |
| 301 | ASSERT_MESSAGE( !string_empty( g_qeglobals.m_userGamePath.c_str() ), "HomePaths_Realise: user-game-path is empty" ); |
| 302 | Q_mkdir( g_qeglobals.m_userGamePath.c_str() ); |
| 303 | } |
| 304 | |
| 305 | ModuleObservers g_homePathObservers; |
| 306 | |
| 307 | void Radiant_attachHomePathsObserver( ModuleObserver& observer ){ |
| 308 | g_homePathObservers.attach( observer ); |
| 309 | } |
| 310 | |
| 311 | void Radiant_detachHomePathsObserver( ModuleObserver& observer ){ |
| 312 | g_homePathObservers.detach( observer ); |
| 313 | } |
| 314 | |
| 315 | class HomePathsModuleObserver : public ModuleObserver |
| 316 | { |
| 317 | std::size_t m_unrealised; |
| 318 | public: |
| 319 | HomePathsModuleObserver() : m_unrealised( 1 ){ |
| 320 | } |
| 321 | |
| 322 | void realise(){ |
| 323 | if ( --m_unrealised == 0 ) { |
| 324 | HomePaths_Realise(); |
| 325 | g_homePathObservers.realise(); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | void unrealise(){ |
| 330 | if ( ++m_unrealised == 1 ) { |
| 331 | g_homePathObservers.unrealise(); |
| 332 | } |
| 333 | } |
| 334 | }; |
| 335 | |
| 336 | HomePathsModuleObserver g_HomePathsModuleObserver; |
| 337 | |
| 338 | void HomePaths_Construct(){ |
| 339 | Radiant_attachEnginePathObserver( g_HomePathsModuleObserver ); |
| 340 | } |
| 341 | |
| 342 | void HomePaths_Destroy(){ |
| 343 | Radiant_detachEnginePathObserver( g_HomePathsModuleObserver ); |
| 344 | } |
| 345 | |
| 346 | |
| 347 | // Engine Path |
| 348 | |
| 349 | CopiedString g_strEnginePath; |
| 350 | ModuleObservers g_enginePathObservers; |
| 351 | std::size_t g_enginepath_unrealised = 1; |
| 352 | |
| 353 | void Radiant_attachEnginePathObserver( ModuleObserver& observer ){ |
| 354 | g_enginePathObservers.attach( observer ); |
| 355 | } |
| 356 | |
| 357 | void Radiant_detachEnginePathObserver( ModuleObserver& observer ){ |
| 358 | g_enginePathObservers.detach( observer ); |
| 359 | } |
| 360 | |
| 361 | |
| 362 | void EnginePath_Realise(){ |
| 363 | if ( --g_enginepath_unrealised == 0 ) { |
| 364 | g_enginePathObservers.realise(); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | |
| 369 | const char* EnginePath_get(){ |
| 370 | ASSERT_MESSAGE( g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised" ); |
| 371 | return g_strEnginePath.c_str(); |
| 372 | } |
| 373 | |
| 374 | void EnginePath_Unrealise(){ |
| 375 | if ( ++g_enginepath_unrealised == 1 ) { |
| 376 | g_enginePathObservers.unrealise(); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | void setEnginePath( const char* path ){ |
| 381 | StringOutputStream buffer( 256 ); |
| 382 | buffer << DirectoryCleaned( path ); |
| 383 | if ( !path_equal( buffer.c_str(), g_strEnginePath.c_str() ) ) { |
| 384 | #if 0 |
| 385 | while ( !ConfirmModified( "Paths Changed" ) ) |
| 386 | { |
| 387 | if ( Map_Unnamed( g_map ) ) { |
| 388 | Map_SaveAs(); |
| 389 | } |
| 390 | else |
| 391 | { |
| 392 | Map_Save(); |
| 393 | } |
| 394 | } |
| 395 | Map_RegionOff(); |
| 396 | #endif |
| 397 | |
| 398 | ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Changing Engine Path" ); |
| 399 | |
| 400 | EnginePath_Unrealise(); |
| 401 | |
| 402 | g_strEnginePath = buffer.c_str(); |
| 403 | |
| 404 | EnginePath_Realise(); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | // Pak Path |
| 409 | |
| 410 | CopiedString g_strPakPath[g_pakPathCount] = { "", "", "", "", "" }; |
| 411 | ModuleObservers g_pakPathObservers[g_pakPathCount]; |
| 412 | std::size_t g_pakpath_unrealised[g_pakPathCount] = { 1, 1, 1, 1, 1 }; |
| 413 | |
| 414 | void Radiant_attachPakPathObserver( int num, ModuleObserver& observer ){ |
| 415 | g_pakPathObservers[num].attach( observer ); |
| 416 | } |
| 417 | |
| 418 | void Radiant_detachPakPathObserver( int num, ModuleObserver& observer ){ |
| 419 | g_pakPathObservers[num].detach( observer ); |
| 420 | } |
| 421 | |
| 422 | |
| 423 | void PakPath_Realise( int num ){ |
| 424 | if ( --g_pakpath_unrealised[num] == 0 ) { |
| 425 | g_pakPathObservers[num].realise(); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | const char* PakPath_get( int num ){ |
| 430 | std::string message = "PakPath_get: pak path " + std::to_string(num) + " not realised"; |
| 431 | ASSERT_MESSAGE( g_pakpath_unrealised[num] == 0, message.c_str() ); |
| 432 | return g_strPakPath[num].c_str(); |
| 433 | } |
| 434 | |
| 435 | void PakPath_Unrealise( int num ){ |
| 436 | if ( ++g_pakpath_unrealised[num] == 1 ) { |
| 437 | g_pakPathObservers[num].unrealise(); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | void setPakPath( int num, const char* path ){ |
| 442 | if (!g_strcmp0( path, "")) { |
| 443 | g_strPakPath[num] = ""; |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | StringOutputStream buffer( 256 ); |
| 448 | buffer << DirectoryCleaned( path ); |
| 449 | if ( !path_equal( buffer.c_str(), g_strPakPath[num].c_str() ) ) { |
| 450 | std::string message = "Changing Pak Path " + std::to_string(num); |
| 451 | ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", message.c_str() ); |
| 452 | |
| 453 | PakPath_Unrealise(num); |
| 454 | |
| 455 | g_strPakPath[num] = buffer.c_str(); |
| 456 | |
| 457 | PakPath_Realise(num); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | |
| 462 | // executable file path (full path) |
| 463 | CopiedString g_strAppFilePath; |
| 464 | |
| 465 | // directory paths |
| 466 | CopiedString g_strAppPath; |
| 467 | CopiedString g_strLibPath; |
| 468 | CopiedString g_strDataPath; |
| 469 | |
| 470 | const char* AppFilePath_get(){ |
| 471 | return g_strAppFilePath.c_str(); |
| 472 | } |
| 473 | |
| 474 | const char* AppPath_get(){ |
| 475 | return g_strAppPath.c_str(); |
| 476 | } |
| 477 | |
| 478 | const char *LibPath_get() |
| 479 | { |
| 480 | return g_strLibPath.c_str(); |
| 481 | } |
| 482 | |
| 483 | const char *DataPath_get() |
| 484 | { |
| 485 | return g_strDataPath.c_str(); |
| 486 | } |
| 487 | |
| 488 | /// the path to the local rc-dir |
| 489 | const char* LocalRcPath_get( void ){ |
| 490 | static CopiedString rc_path; |
| 491 | if ( rc_path.empty() ) { |
| 492 | StringOutputStream stream( 256 ); |
| 493 | stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/"; |
| 494 | rc_path = stream.c_str(); |
| 495 | } |
| 496 | return rc_path.c_str(); |
| 497 | } |
| 498 | |
| 499 | /// directory for temp files |
| 500 | /// NOTE: on *nix this is were we check for .pid |
| 501 | CopiedString g_strSettingsPath; |
| 502 | |
| 503 | const char* SettingsPath_get(){ |
| 504 | return g_strSettingsPath.c_str(); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | /*! |
| 509 | points to the game tools directory, for instance |
| 510 | C:/Program Files/Quake III Arena/GtkRadiant |
| 511 | (or other games) |
| 512 | this is one of the main variables that are configured by the game selection on startup |
| 513 | [GameToolsPath]/plugins |
| 514 | [GameToolsPath]/modules |
| 515 | and also q3map, bspc |
| 516 | */ |
| 517 | CopiedString g_strGameToolsPath; ///< this is set by g_GamesDialog |
| 518 | |
| 519 | const char* GameToolsPath_get(){ |
| 520 | return g_strGameToolsPath.c_str(); |
| 521 | } |
| 522 | |
| 523 | struct EnginePath { |
| 524 | static void Export(const CopiedString &self, const Callback<void(const char *)> &returnz) { |
| 525 | returnz(self.c_str()); |
| 526 | } |
| 527 | |
| 528 | static void Import(CopiedString &self, const char *value) { |
| 529 | setEnginePath( value ); |
| 530 | } |
| 531 | }; |
| 532 | |
| 533 | struct PakPath0 { |
| 534 | static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) { |
| 535 | returnz( self.c_str() ); |
| 536 | } |
| 537 | |
| 538 | static void Import( CopiedString &self, const char *value ) { |
| 539 | setPakPath( 0, value ); |
| 540 | } |
| 541 | }; |
| 542 | |
| 543 | struct PakPath1 { |
| 544 | static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) { |
| 545 | returnz( self.c_str() ); |
| 546 | } |
| 547 | |
| 548 | static void Import( CopiedString &self, const char *value ) { |
| 549 | setPakPath( 1, value ); |
| 550 | } |
| 551 | }; |
| 552 | |
| 553 | struct PakPath2 { |
| 554 | static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) { |
| 555 | returnz( self.c_str() ); |
| 556 | } |
| 557 | |
| 558 | static void Import( CopiedString &self, const char *value ) { |
| 559 | setPakPath( 2, value ); |
| 560 | } |
| 561 | }; |
| 562 | |
| 563 | struct PakPath3 { |
| 564 | static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) { |
| 565 | returnz( self.c_str() ); |
| 566 | } |
| 567 | |
| 568 | static void Import( CopiedString &self, const char *value ) { |
| 569 | setPakPath( 3, value ); |
| 570 | } |
| 571 | }; |
| 572 | |
| 573 | struct PakPath4 { |
| 574 | static void Export( const CopiedString &self, const Callback<void(const char*)> &returnz ) { |
| 575 | returnz( self.c_str() ); |
| 576 | } |
| 577 | |
| 578 | static void Import( CopiedString &self, const char *value ) { |
| 579 | setPakPath( 4, value ); |
| 580 | } |
| 581 | }; |
| 582 | |
| 583 | bool g_disableEnginePath = false; |
| 584 | bool g_disableHomePath = false; |
| 585 | |
| 586 | void Paths_constructBasicPreferences( PreferencesPage& page ) { |
| 587 | page.appendPathEntry( "Engine Path", true, make_property<EnginePath>(g_strEnginePath) ); |
| 588 | } |
| 589 | |
| 590 | void Paths_constructPreferences( PreferencesPage& page ){ |
| 591 | Paths_constructBasicPreferences( page ); |
| 592 | |
| 593 | page.appendSpacer( 4 ); |
| 594 | page.appendLabel( "", "Advanced options" ); |
| 595 | page.appendCheckBox( "", "Do not use Engine Path", g_disableEnginePath ); |
| 596 | page.appendCheckBox( "", "Do not use Home Path", g_disableHomePath ); |
| 597 | |
| 598 | page.appendSpacer( 4 ); |
| 599 | page.appendLabel( "", "Only a very few games support Pak Paths," ); |
| 600 | page.appendLabel( "", "if you don't know what it is, leave this blank." ); |
| 601 | |
| 602 | const char *label = "Pak Path "; |
| 603 | page.appendPathEntry( label, true, make_property<PakPath0>( g_strPakPath[0] ) ); |
| 604 | page.appendPathEntry( label, true, make_property<PakPath1>( g_strPakPath[1] ) ); |
| 605 | page.appendPathEntry( label, true, make_property<PakPath2>( g_strPakPath[2] ) ); |
| 606 | page.appendPathEntry( label, true, make_property<PakPath3>( g_strPakPath[3] ) ); |
| 607 | page.appendPathEntry( label, true, make_property<PakPath4>( g_strPakPath[4] ) ); |
| 608 | } |
| 609 | |
| 610 | void Paths_constructPage( PreferenceGroup& group ){ |
| 611 | PreferencesPage page( group.createPage( "Paths", "Path Settings" ) ); |
| 612 | Paths_constructPreferences( page ); |
| 613 | } |
| 614 | |
| 615 | void Paths_registerPreferencesPage(){ |
| 616 | PreferencesDialog_addSettingsPage( makeCallbackF(Paths_constructPage) ); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | class PathsDialog : public Dialog |
| 621 | { |
| 622 | public: |
| 623 | ui::Window BuildDialog(){ |
| 624 | auto frame = create_dialog_frame( "Path Settings", ui::Shadow::ETCHED_IN ); |
| 625 | |
| 626 | auto vbox2 = create_dialog_vbox( 0, 4 ); |
| 627 | frame.add(vbox2); |
| 628 | |
| 629 | const char* engine; |
| 630 | #if defined( WIN32 ) |
| 631 | engine = g_pGameDescription->getRequiredKeyValue( "engine_win32" ); |
| 632 | #elif defined( __linux__ ) || defined ( __FreeBSD__ ) |
| 633 | engine = g_pGameDescription->getRequiredKeyValue( "engine_linux" ); |
| 634 | #elif defined( __APPLE__ ) |
| 635 | engine = g_pGameDescription->getRequiredKeyValue( "engine_macos" ); |
| 636 | #else |
| 637 | #error "unsupported platform" |
| 638 | #endif |
| 639 | StringOutputStream text( 256 ); |
| 640 | text << "Select directory, where game executable sits (typically \"" << engine << "\")\n"; |
| 641 | GtkLabel* label = GTK_LABEL( gtk_label_new( text.c_str() ) ); |
| 642 | gtk_widget_show( GTK_WIDGET( label ) ); |
| 643 | gtk_container_add( GTK_CONTAINER( vbox2 ), GTK_WIDGET( label ) ); |
| 644 | |
| 645 | { |
| 646 | PreferencesPage page( *this, vbox2 ); |
| 647 | Paths_constructBasicPreferences( page ); |
| 648 | } |
| 649 | |
| 650 | return ui::Window(create_simple_modal_dialog_window( "Engine Path Configuration", m_modal, frame )); |
| 651 | } |
| 652 | }; |
| 653 | |
| 654 | PathsDialog g_PathsDialog; |
| 655 | |
| 656 | bool g_strEnginePath_was_empty_1st_start = false; |
| 657 | |
| 658 | void EnginePath_verify(){ |
| 659 | if ( !file_exists( g_strEnginePath.c_str() ) || g_strEnginePath_was_empty_1st_start ) { |
| 660 | g_PathsDialog.Create(); |
| 661 | g_PathsDialog.DoModal(); |
| 662 | g_PathsDialog.Destroy(); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | namespace |
| 667 | { |
| 668 | CopiedString g_gamename; |
| 669 | CopiedString g_gamemode; |
| 670 | ModuleObservers g_gameNameObservers; |
| 671 | ModuleObservers g_gameModeObservers; |
| 672 | } |
| 673 | |
| 674 | void Radiant_attachGameNameObserver( ModuleObserver& observer ){ |
| 675 | g_gameNameObservers.attach( observer ); |
| 676 | } |
| 677 | |
| 678 | void Radiant_detachGameNameObserver( ModuleObserver& observer ){ |
| 679 | g_gameNameObservers.detach( observer ); |
| 680 | } |
| 681 | |
| 682 | const char* basegame_get(){ |
| 683 | return g_pGameDescription->getRequiredKeyValue( "basegame" ); |
| 684 | } |
| 685 | |
| 686 | const char* gamename_get(){ |
| 687 | const char* gamename = g_gamename.c_str(); |
| 688 | if ( string_empty( gamename ) ) { |
| 689 | return basegame_get(); |
| 690 | } |
| 691 | return gamename; |
| 692 | } |
| 693 | |
| 694 | void gamename_set( const char* gamename ){ |
| 695 | if ( !string_equal( gamename, g_gamename.c_str() ) ) { |
| 696 | g_gameNameObservers.unrealise(); |
| 697 | g_gamename = gamename; |
| 698 | g_gameNameObservers.realise(); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | void Radiant_attachGameModeObserver( ModuleObserver& observer ){ |
| 703 | g_gameModeObservers.attach( observer ); |
| 704 | } |
| 705 | |
| 706 | void Radiant_detachGameModeObserver( ModuleObserver& observer ){ |
| 707 | g_gameModeObservers.detach( observer ); |
| 708 | } |
| 709 | |
| 710 | const char* gamemode_get(){ |
| 711 | return g_gamemode.c_str(); |
| 712 | } |
| 713 | |
| 714 | void gamemode_set( const char* gamemode ){ |
| 715 | if ( !string_equal( gamemode, g_gamemode.c_str() ) ) { |
| 716 | g_gameModeObservers.unrealise(); |
| 717 | g_gamemode = gamemode; |
| 718 | g_gameModeObservers.realise(); |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | |
| 723 | #include "os/dir.h" |
| 724 | |
| 725 | const char* const c_library_extension = |
| 726 | #if defined( CMAKE_SHARED_MODULE_SUFFIX ) |
| 727 | CMAKE_SHARED_MODULE_SUFFIX |
| 728 | #elif GDEF_OS_WINDOWS |
| 729 | "dll" |
| 730 | #elif GDEF_OS_MACOS |
| 731 | "dylib" |
| 732 | #elif GDEF_OS_LINUX || GDEF_OS_BSD |
| 733 | "so" |
| 734 | #endif |
| 735 | ; |
| 736 | |
| 737 | void Radiant_loadModules( const char* path ){ |
| 738 | Directory_forEach(path, matchFileExtension(c_library_extension, [&](const char *name) { |
| 739 | char fullname[1024]; |
| 740 | ASSERT_MESSAGE(strlen(path) + strlen(name) < 1024, ""); |
| 741 | strcpy(fullname, path); |
| 742 | strcat(fullname, name); |
| 743 | globalOutputStream() << "Found '" << fullname << "'\n"; |
| 744 | GlobalModuleServer_loadModule(fullname); |
| 745 | })); |
| 746 | } |
| 747 | |
| 748 | void Radiant_loadModulesFromRoot( const char* directory ){ |
| 749 | { |
| 750 | StringOutputStream path( 256 ); |
| 751 | path << directory << g_pluginsDir; |
| 752 | Radiant_loadModules( path.c_str() ); |
| 753 | } |
| 754 | |
| 755 | if ( !string_equal( g_pluginsDir, g_modulesDir ) ) { |
| 756 | StringOutputStream path( 256 ); |
| 757 | path << directory << g_modulesDir; |
| 758 | Radiant_loadModules( path.c_str() ); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | //! Make COLOR_BRUSHES override worldspawn eclass colour. |
| 763 | void SetWorldspawnColour( const Vector3& colour ){ |
| 764 | EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert( "worldspawn", true ); |
| 765 | eclass_release_state( worldspawn ); |
| 766 | worldspawn->color = colour; |
| 767 | eclass_capture_state( worldspawn ); |
| 768 | } |
| 769 | |
| 770 | |
| 771 | class WorldspawnColourEntityClassObserver : public ModuleObserver |
| 772 | { |
| 773 | std::size_t m_unrealised; |
| 774 | public: |
| 775 | WorldspawnColourEntityClassObserver() : m_unrealised( 1 ){ |
| 776 | } |
| 777 | |
| 778 | void realise(){ |
| 779 | if ( --m_unrealised == 0 ) { |
| 780 | SetWorldspawnColour( g_xywindow_globals.color_brushes ); |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | void unrealise(){ |
| 785 | if ( ++m_unrealised == 1 ) { |
| 786 | } |
| 787 | } |
| 788 | }; |
| 789 | |
| 790 | WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver; |
| 791 | |
| 792 | |
| 793 | ModuleObservers g_gameToolsPathObservers; |
| 794 | |
| 795 | void Radiant_attachGameToolsPathObserver( ModuleObserver& observer ){ |
| 796 | g_gameToolsPathObservers.attach( observer ); |
| 797 | } |
| 798 | |
| 799 | void Radiant_detachGameToolsPathObserver( ModuleObserver& observer ){ |
| 800 | g_gameToolsPathObservers.detach( observer ); |
| 801 | } |
| 802 | |
| 803 | void Radiant_Initialise(){ |
| 804 | GlobalModuleServer_Initialise(); |
| 805 | |
| 806 | Radiant_loadModulesFromRoot( LibPath_get() ); |
| 807 | |
| 808 | Preferences_Load(); |
| 809 | |
| 810 | bool success = Radiant_Construct( GlobalModuleServer_get() ); |
| 811 | ASSERT_MESSAGE( success, "module system failed to initialise - see radiant.log for error messages" ); |
| 812 | |
| 813 | g_gameToolsPathObservers.realise(); |
| 814 | g_gameModeObservers.realise(); |
| 815 | g_gameNameObservers.realise(); |
| 816 | } |
| 817 | |
| 818 | void Radiant_Shutdown(){ |
| 819 | g_gameNameObservers.unrealise(); |
| 820 | g_gameModeObservers.unrealise(); |
| 821 | g_gameToolsPathObservers.unrealise(); |
| 822 | |
| 823 | if ( !g_preferences_globals.disable_ini ) { |
| 824 | globalOutputStream() << "Start writing prefs\n"; |
| 825 | Preferences_Save(); |
| 826 | globalOutputStream() << "Done prefs\n"; |
| 827 | } |
| 828 | |
| 829 | Radiant_Destroy(); |
| 830 | |
| 831 | GlobalModuleServer_Shutdown(); |
| 832 | } |
| 833 | |
| 834 | void Exit(){ |
| 835 | if ( ConfirmModified( "Exit " RADIANT_NAME ) ) { |
| 836 | gtk_main_quit(); |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | |
| 841 | void Undo(){ |
| 842 | GlobalUndoSystem().undo(); |
| 843 | SceneChangeNotify(); |
| 844 | } |
| 845 | |
| 846 | void Redo(){ |
| 847 | GlobalUndoSystem().redo(); |
| 848 | SceneChangeNotify(); |
| 849 | } |
| 850 | |
| 851 | void deleteSelection(){ |
| 852 | UndoableCommand undo( "deleteSelected" ); |
| 853 | Select_Delete(); |
| 854 | } |
| 855 | |
| 856 | void Map_ExportSelected( TextOutputStream& ostream ){ |
| 857 | Map_ExportSelected( ostream, Map_getFormat( g_map ) ); |
| 858 | } |
| 859 | |
| 860 | void Map_ImportSelected( TextInputStream& istream ){ |
| 861 | Map_ImportSelected( istream, Map_getFormat( g_map ) ); |
| 862 | } |
| 863 | |
| 864 | void Selection_Copy(){ |
| 865 | clipboard_copy( Map_ExportSelected ); |
| 866 | } |
| 867 | |
| 868 | void Selection_Paste(){ |
| 869 | clipboard_paste( Map_ImportSelected ); |
| 870 | } |
| 871 | |
| 872 | void Copy(){ |
| 873 | if ( SelectedFaces_empty() ) { |
| 874 | Selection_Copy(); |
| 875 | } |
| 876 | else |
| 877 | { |
| 878 | SelectedFaces_copyTexture(); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | void Paste(){ |
| 883 | if ( SelectedFaces_empty() ) { |
| 884 | UndoableCommand undo( "paste" ); |
| 885 | |
| 886 | GlobalSelectionSystem().setSelectedAll( false ); |
| 887 | Selection_Paste(); |
| 888 | } |
| 889 | else |
| 890 | { |
| 891 | SelectedFaces_pasteTexture(); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | void PasteToCamera(){ |
| 896 | CamWnd& camwnd = *g_pParentWnd->GetCamWnd(); |
| 897 | GlobalSelectionSystem().setSelectedAll( false ); |
| 898 | |
| 899 | UndoableCommand undo( "pasteToCamera" ); |
| 900 | |
| 901 | Selection_Paste(); |
| 902 | |
| 903 | // Work out the delta |
| 904 | Vector3 mid; |
| 905 | Select_GetMid( mid ); |
| 906 | Vector3 delta = vector3_subtracted( vector3_snapped( Camera_getOrigin( camwnd ), GetSnapGridSize() ), mid ); |
| 907 | |
| 908 | // Move to camera |
| 909 | GlobalSelectionSystem().translateSelected( delta ); |
| 910 | } |
| 911 | |
| 912 | |
| 913 | void ColorScheme_Original(){ |
| 914 | TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) ); |
| 915 | |
| 916 | g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f ); |
| 917 | g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f ); |
| 918 | CamWnd_Update( *g_pParentWnd->GetCamWnd() ); |
| 919 | |
| 920 | g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f ); |
| 921 | g_xywindow_globals.color_gridminor = Vector3( 0.75f, 0.75f, 0.75f ); |
| 922 | g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f ); |
| 923 | g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f ); |
| 924 | g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f ); |
| 925 | g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f ); |
| 926 | g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f ); |
| 927 | g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f ); |
| 928 | SetWorldspawnColour( g_xywindow_globals.color_brushes ); |
| 929 | g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f ); |
| 930 | XY_UpdateAllWindows(); |
| 931 | } |
| 932 | |
| 933 | void ColorScheme_QER(){ |
| 934 | TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) ); |
| 935 | |
| 936 | g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f ); |
| 937 | g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f ); |
| 938 | CamWnd_Update( *g_pParentWnd->GetCamWnd() ); |
| 939 | |
| 940 | g_xywindow_globals.color_gridback = Vector3( 1.0f, 1.0f, 1.0f ); |
| 941 | g_xywindow_globals.color_gridminor = Vector3( 1.0f, 1.0f, 1.0f ); |
| 942 | g_xywindow_globals.color_gridmajor = Vector3( 0.5f, 0.5f, 0.5f ); |
| 943 | g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f ); |
| 944 | g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f ); |
| 945 | g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f ); |
| 946 | g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f ); |
| 947 | g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f ); |
| 948 | SetWorldspawnColour( g_xywindow_globals.color_brushes ); |
| 949 | g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f ); |
| 950 | XY_UpdateAllWindows(); |
| 951 | } |
| 952 | |
| 953 | void ColorScheme_Black(){ |
| 954 | TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) ); |
| 955 | |
| 956 | g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f ); |
| 957 | g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f ); |
| 958 | CamWnd_Update( *g_pParentWnd->GetCamWnd() ); |
| 959 | |
| 960 | g_xywindow_globals.color_gridback = Vector3( 0.0f, 0.0f, 0.0f ); |
| 961 | g_xywindow_globals.color_gridminor = Vector3( 0.2f, 0.2f, 0.2f ); |
| 962 | g_xywindow_globals.color_gridmajor = Vector3( 0.3f, 0.5f, 0.5f ); |
| 963 | g_xywindow_globals.color_gridblock = Vector3( 0.0f, 0.0f, 1.0f ); |
| 964 | g_xywindow_globals.color_gridtext = Vector3( 1.0f, 1.0f, 1.0f ); |
| 965 | g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f ); |
| 966 | g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f ); |
| 967 | g_xywindow_globals.color_brushes = Vector3( 1.0f, 1.0f, 1.0f ); |
| 968 | SetWorldspawnColour( g_xywindow_globals.color_brushes ); |
| 969 | g_xywindow_globals.color_viewname = Vector3( 0.7f, 0.7f, 0.0f ); |
| 970 | XY_UpdateAllWindows(); |
| 971 | } |
| 972 | |
| 973 | /* ydnar: to emulate maya/max/lightwave color schemes */ |
| 974 | void ColorScheme_Ydnar(){ |
| 975 | TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), Vector3( 0.25f, 0.25f, 0.25f ) ); |
| 976 | |
| 977 | g_camwindow_globals.color_cameraback = Vector3( 0.25f, 0.25f, 0.25f ); |
| 978 | g_camwindow_globals.color_selbrushes3d = Vector3( 1.0f, 0.0f, 0.0f ); |
| 979 | CamWnd_Update( *g_pParentWnd->GetCamWnd() ); |
| 980 | |
| 981 | g_xywindow_globals.color_gridback = Vector3( 0.77f, 0.77f, 0.77f ); |
| 982 | g_xywindow_globals.color_gridminor = Vector3( 0.83f, 0.83f, 0.83f ); |
| 983 | g_xywindow_globals.color_gridmajor = Vector3( 0.89f, 0.89f, 0.89f ); |
| 984 | g_xywindow_globals.color_gridblock = Vector3( 1.0f, 1.0f, 1.0f ); |
| 985 | g_xywindow_globals.color_gridtext = Vector3( 0.0f, 0.0f, 0.0f ); |
| 986 | g_xywindow_globals.color_selbrushes = Vector3( 1.0f, 0.0f, 0.0f ); |
| 987 | g_xywindow_globals.color_clipper = Vector3( 0.0f, 0.0f, 1.0f ); |
| 988 | g_xywindow_globals.color_brushes = Vector3( 0.0f, 0.0f, 0.0f ); |
| 989 | SetWorldspawnColour( g_xywindow_globals.color_brushes ); |
| 990 | g_xywindow_globals.color_viewname = Vector3( 0.5f, 0.0f, 0.75f ); |
| 991 | XY_UpdateAllWindows(); |
| 992 | } |
| 993 | |
| 994 | /* color scheme to fit the GTK Adwaita Dark theme */ |
| 995 | void ColorScheme_AdwaitaDark() |
| 996 | { |
| 997 | // SI_Colors0 |
| 998 | // GlobalTextureBrowser().color_textureback |
| 999 | TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f)); |
| 1000 | |
| 1001 | // SI_Colors4 |
| 1002 | g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f); |
| 1003 | // SI_Colors12 |
| 1004 | g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f); |
| 1005 | CamWnd_Update(*g_pParentWnd->GetCamWnd()); |
| 1006 | |
| 1007 | // SI_Colors1 |
| 1008 | g_xywindow_globals.color_gridback = Vector3(0.25f, 0.25f, 0.25f); |
| 1009 | // SI_Colors2 |
| 1010 | g_xywindow_globals.color_gridminor = Vector3(0.21f, 0.23f, 0.23f); |
| 1011 | // SI_Colors3 |
| 1012 | g_xywindow_globals.color_gridmajor = Vector3(0.14f, 0.15f, 0.15f); |
| 1013 | // SI_Colors14 |
| 1014 | g_xywindow_globals.color_gridmajor_alt = Vector3(1.0f, 0.0f, 0.0f); |
| 1015 | // SI_Colors6 |
| 1016 | g_xywindow_globals.color_gridblock = Vector3(1.0f, 1.0f, 1.0f); |
| 1017 | // SI_Colors7 |
| 1018 | g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f); |
| 1019 | // ?? |
| 1020 | g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f); |
| 1021 | // ?? |
| 1022 | g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f); |
| 1023 | // SI_Colors8 |
| 1024 | g_xywindow_globals.color_brushes = Vector3(0.73f, 0.73f, 0.73f); |
| 1025 | |
| 1026 | // SI_AxisColors0 |
| 1027 | g_xywindow_globals.AxisColorX = Vector3(1.0f, 0.0f, 0.0f); |
| 1028 | // SI_AxisColors1 |
| 1029 | g_xywindow_globals.AxisColorY = Vector3(0.0f, 1.0f, 0.0f); |
| 1030 | // SI_AxisColors2 |
| 1031 | g_xywindow_globals.AxisColorZ = Vector3(0.0f, 0.0f, 1.0f); |
| 1032 | SetWorldspawnColour(g_xywindow_globals.color_brushes); |
| 1033 | // ?? |
| 1034 | g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f); |
| 1035 | XY_UpdateAllWindows(); |
| 1036 | |
| 1037 | // SI_Colors5 |
| 1038 | // g_entity_globals.color_entity = Vector3(0.0f, 0.0f, 0.0f); |
| 1039 | } |
| 1040 | |
| 1041 | typedef Callback<void(Vector3&)> GetColourCallback; |
| 1042 | typedef Callback<void(const Vector3&)> SetColourCallback; |
| 1043 | |
| 1044 | class ChooseColour |
| 1045 | { |
| 1046 | GetColourCallback m_get; |
| 1047 | SetColourCallback m_set; |
| 1048 | public: |
| 1049 | ChooseColour( const GetColourCallback& get, const SetColourCallback& set ) |
| 1050 | : m_get( get ), m_set( set ){ |
| 1051 | } |
| 1052 | |
| 1053 | void operator()(){ |
| 1054 | Vector3 colour; |
| 1055 | m_get( colour ); |
| 1056 | color_dialog( MainFrame_getWindow(), colour ); |
| 1057 | m_set( colour ); |
| 1058 | } |
| 1059 | }; |
| 1060 | |
| 1061 | |
| 1062 | void Colour_get( const Vector3& colour, Vector3& other ){ |
| 1063 | other = colour; |
| 1064 | } |
| 1065 | |
| 1066 | typedef ConstReferenceCaller<Vector3, void(Vector3&), Colour_get> ColourGetCaller; |
| 1067 | |
| 1068 | void Colour_set( Vector3& colour, const Vector3& other ){ |
| 1069 | colour = other; |
| 1070 | SceneChangeNotify(); |
| 1071 | } |
| 1072 | |
| 1073 | typedef ReferenceCaller<Vector3, void(const Vector3&), Colour_set> ColourSetCaller; |
| 1074 | |
| 1075 | void BrushColour_set( const Vector3& other ){ |
| 1076 | g_xywindow_globals.color_brushes = other; |
| 1077 | SetWorldspawnColour( g_xywindow_globals.color_brushes ); |
| 1078 | SceneChangeNotify(); |
| 1079 | } |
| 1080 | |
| 1081 | typedef FreeCaller<void(const Vector3&), BrushColour_set> BrushColourSetCaller; |
| 1082 | |
| 1083 | void ClipperColour_set( const Vector3& other ){ |
| 1084 | g_xywindow_globals.color_clipper = other; |
| 1085 | Brush_clipperColourChanged(); |
| 1086 | SceneChangeNotify(); |
| 1087 | } |
| 1088 | |
| 1089 | typedef FreeCaller<void(const Vector3&), ClipperColour_set> ClipperColourSetCaller; |
| 1090 | |
| 1091 | void TextureBrowserColour_get( Vector3& other ){ |
| 1092 | other = TextureBrowser_getBackgroundColour( GlobalTextureBrowser() ); |
| 1093 | } |
| 1094 | |
| 1095 | typedef FreeCaller<void(Vector3&), TextureBrowserColour_get> TextureBrowserColourGetCaller; |
| 1096 | |
| 1097 | void TextureBrowserColour_set( const Vector3& other ){ |
| 1098 | TextureBrowser_setBackgroundColour( GlobalTextureBrowser(), other ); |
| 1099 | } |
| 1100 | |
| 1101 | typedef FreeCaller<void(const Vector3&), TextureBrowserColour_set> TextureBrowserColourSetCaller; |
| 1102 | |
| 1103 | |
| 1104 | class ColoursMenu |
| 1105 | { |
| 1106 | public: |
| 1107 | ChooseColour m_textureback; |
| 1108 | ChooseColour m_xyback; |
| 1109 | ChooseColour m_gridmajor; |
| 1110 | ChooseColour m_gridminor; |
| 1111 | ChooseColour m_gridtext; |
| 1112 | ChooseColour m_gridblock; |
| 1113 | ChooseColour m_cameraback; |
| 1114 | ChooseColour m_brush; |
| 1115 | ChooseColour m_selectedbrush; |
| 1116 | ChooseColour m_selectedbrush3d; |
| 1117 | ChooseColour m_clipper; |
| 1118 | ChooseColour m_viewname; |
| 1119 | |
| 1120 | ColoursMenu() : |
| 1121 | m_textureback( TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller() ), |
| 1122 | m_xyback( ColourGetCaller( g_xywindow_globals.color_gridback ), ColourSetCaller( g_xywindow_globals.color_gridback ) ), |
| 1123 | m_gridmajor( ColourGetCaller( g_xywindow_globals.color_gridmajor ), ColourSetCaller( g_xywindow_globals.color_gridmajor ) ), |
| 1124 | m_gridminor( ColourGetCaller( g_xywindow_globals.color_gridminor ), ColourSetCaller( g_xywindow_globals.color_gridminor ) ), |
| 1125 | m_gridtext( ColourGetCaller( g_xywindow_globals.color_gridtext ), ColourSetCaller( g_xywindow_globals.color_gridtext ) ), |
| 1126 | m_gridblock( ColourGetCaller( g_xywindow_globals.color_gridblock ), ColourSetCaller( g_xywindow_globals.color_gridblock ) ), |
| 1127 | m_cameraback( ColourGetCaller( g_camwindow_globals.color_cameraback ), ColourSetCaller( g_camwindow_globals.color_cameraback ) ), |
| 1128 | m_brush( ColourGetCaller( g_xywindow_globals.color_brushes ), BrushColourSetCaller() ), |
| 1129 | m_selectedbrush( ColourGetCaller( g_xywindow_globals.color_selbrushes ), ColourSetCaller( g_xywindow_globals.color_selbrushes ) ), |
| 1130 | m_selectedbrush3d( ColourGetCaller( g_camwindow_globals.color_selbrushes3d ), ColourSetCaller( g_camwindow_globals.color_selbrushes3d ) ), |
| 1131 | m_clipper( ColourGetCaller( g_xywindow_globals.color_clipper ), ClipperColourSetCaller() ), |
| 1132 | m_viewname( ColourGetCaller( g_xywindow_globals.color_viewname ), ColourSetCaller( g_xywindow_globals.color_viewname ) ){ |
| 1133 | } |
| 1134 | }; |
| 1135 | |
| 1136 | ColoursMenu g_ColoursMenu; |
| 1137 | |
| 1138 | ui::MenuItem create_colours_menu(){ |
| 1139 | auto colours_menu_item = new_sub_menu_item_with_mnemonic( "Colors" ); |
| 1140 | auto menu_in_menu = ui::Menu::from( gtk_menu_item_get_submenu( colours_menu_item ) ); |
| 1141 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 1142 | menu_tearoff( menu_in_menu ); |
| 1143 | } |
| 1144 | |
| 1145 | auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Themes" ); |
| 1146 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 1147 | menu_tearoff( menu_3 ); |
| 1148 | } |
| 1149 | |
| 1150 | create_menu_item_with_mnemonic( menu_3, "QE4 Original", "ColorSchemeOriginal" ); |
| 1151 | create_menu_item_with_mnemonic( menu_3, "Q3Radiant Original", "ColorSchemeQER" ); |
| 1152 | create_menu_item_with_mnemonic( menu_3, "Black and Green", "ColorSchemeBlackAndGreen" ); |
| 1153 | create_menu_item_with_mnemonic( menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar" ); |
| 1154 | create_menu_item_with_mnemonic(menu_3, "Adwaita Dark", "ColorSchemeAdwaitaDark"); |
| 1155 | |
| 1156 | #ifndef GARUX_DISABLE_GTKTHEME |
| 1157 | create_menu_item_with_mnemonic( menu_in_menu, "GTK Theme...", "gtkThemeDlg" ); |
| 1158 | #endif |
| 1159 | |
| 1160 | menu_separator( menu_in_menu ); |
| 1161 | |
| 1162 | create_menu_item_with_mnemonic( menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor" ); |
| 1163 | create_menu_item_with_mnemonic( menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor" ); |
| 1164 | create_menu_item_with_mnemonic( menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor" ); |
| 1165 | create_menu_item_with_mnemonic( menu_in_menu, "Grid Major...", "ChooseGridMajorColor" ); |
| 1166 | create_menu_item_with_mnemonic( menu_in_menu, "Grid Minor...", "ChooseGridMinorColor" ); |
| 1167 | create_menu_item_with_mnemonic( menu_in_menu, "Grid Text...", "ChooseGridTextColor" ); |
| 1168 | create_menu_item_with_mnemonic( menu_in_menu, "Grid Block...", "ChooseGridBlockColor" ); |
| 1169 | create_menu_item_with_mnemonic( menu_in_menu, "Default Brush (2D)...", "ChooseBrushColor" ); |
| 1170 | create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush and Sizing (2D)...", "ChooseSelectedBrushColor" ); |
| 1171 | create_menu_item_with_mnemonic( menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor" ); |
| 1172 | create_menu_item_with_mnemonic( menu_in_menu, "Clipper...", "ChooseClipperColor" ); |
| 1173 | create_menu_item_with_mnemonic( menu_in_menu, "Active View Name and Outline...", "ChooseOrthoViewNameColor" ); |
| 1174 | |
| 1175 | return colours_menu_item; |
| 1176 | } |
| 1177 | |
| 1178 | |
| 1179 | void Restart(){ |
| 1180 | PluginsMenu_clear(); |
| 1181 | PluginToolbar_clear(); |
| 1182 | |
| 1183 | Radiant_Shutdown(); |
| 1184 | Radiant_Initialise(); |
| 1185 | |
| 1186 | PluginsMenu_populate(); |
| 1187 | |
| 1188 | PluginToolbar_populate(); |
| 1189 | } |
| 1190 | |
| 1191 | |
| 1192 | void thunk_OnSleep(){ |
| 1193 | g_pParentWnd->OnSleep(); |
| 1194 | } |
| 1195 | |
| 1196 | void OpenHelpURL(){ |
| 1197 | OpenURL( "https://gitlab.com/xonotic/xonotic/wikis/Mapping" ); |
| 1198 | } |
| 1199 | |
| 1200 | void OpenBugReportURL(){ |
| 1201 | OpenURL( "https://gitlab.com/xonotic/netradiant/issues" ); |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | ui::Widget g_page_console{ui::null}; |
| 1206 | |
| 1207 | void Console_ToggleShow(){ |
| 1208 | GroupDialog_showPage( g_page_console ); |
| 1209 | } |
| 1210 | |
| 1211 | ui::Widget g_page_entity{ui::null}; |
| 1212 | |
| 1213 | void EntityInspector_ToggleShow(){ |
| 1214 | GroupDialog_showPage( g_page_entity ); |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | void SetClipMode( bool enable ); |
| 1219 | |
| 1220 | void ModeChangeNotify(); |
| 1221 | |
| 1222 | typedef void ( *ToolMode )(); |
| 1223 | |
| 1224 | ToolMode g_currentToolMode = 0; |
| 1225 | bool g_currentToolModeSupportsComponentEditing = false; |
| 1226 | ToolMode g_defaultToolMode = 0; |
| 1227 | |
| 1228 | |
| 1229 | void SelectionSystem_DefaultMode(){ |
| 1230 | GlobalSelectionSystem().SetMode( SelectionSystem::ePrimitive ); |
| 1231 | GlobalSelectionSystem().SetComponentMode( SelectionSystem::eDefault ); |
| 1232 | ModeChangeNotify(); |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | bool EdgeMode(){ |
| 1237 | return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent |
| 1238 | && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge; |
| 1239 | } |
| 1240 | |
| 1241 | bool VertexMode(){ |
| 1242 | return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent |
| 1243 | && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex; |
| 1244 | } |
| 1245 | |
| 1246 | bool FaceMode(){ |
| 1247 | return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent |
| 1248 | && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace; |
| 1249 | } |
| 1250 | |
| 1251 | template<bool( *BoolFunction ) ( )> |
| 1252 | class BoolFunctionExport |
| 1253 | { |
| 1254 | public: |
| 1255 | static void apply( const Callback<void(bool)> & importCallback ){ |
| 1256 | importCallback( BoolFunction() ); |
| 1257 | } |
| 1258 | }; |
| 1259 | |
| 1260 | typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller; |
| 1261 | EdgeModeApplyCaller g_edgeMode_button_caller; |
| 1262 | Callback<void(const Callback<void(bool)> &)> g_edgeMode_button_callback( g_edgeMode_button_caller ); |
| 1263 | ToggleItem g_edgeMode_button( g_edgeMode_button_callback ); |
| 1264 | |
| 1265 | typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller; |
| 1266 | VertexModeApplyCaller g_vertexMode_button_caller; |
| 1267 | Callback<void(const Callback<void(bool)> &)> g_vertexMode_button_callback( g_vertexMode_button_caller ); |
| 1268 | ToggleItem g_vertexMode_button( g_vertexMode_button_callback ); |
| 1269 | |
| 1270 | typedef FreeCaller<void(const Callback<void(bool)> &), &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller; |
| 1271 | FaceModeApplyCaller g_faceMode_button_caller; |
| 1272 | Callback<void(const Callback<void(bool)> &)> g_faceMode_button_callback( g_faceMode_button_caller ); |
| 1273 | ToggleItem g_faceMode_button( g_faceMode_button_callback ); |
| 1274 | |
| 1275 | void ComponentModeChanged(){ |
| 1276 | g_edgeMode_button.update(); |
| 1277 | g_vertexMode_button.update(); |
| 1278 | g_faceMode_button.update(); |
| 1279 | } |
| 1280 | |
| 1281 | void ComponentMode_SelectionChanged( const Selectable& selectable ){ |
| 1282 | if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent |
| 1283 | && GlobalSelectionSystem().countSelected() == 0 ) { |
| 1284 | SelectionSystem_DefaultMode(); |
| 1285 | ComponentModeChanged(); |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | void SelectEdgeMode(){ |
| 1290 | #if 0 |
| 1291 | if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) { |
| 1292 | GlobalSelectionSystem().Select( false ); |
| 1293 | } |
| 1294 | #endif |
| 1295 | |
| 1296 | if ( EdgeMode() ) { |
| 1297 | SelectionSystem_DefaultMode(); |
| 1298 | } |
| 1299 | else if ( GlobalSelectionSystem().countSelected() != 0 ) { |
| 1300 | if ( !g_currentToolModeSupportsComponentEditing ) { |
| 1301 | g_defaultToolMode(); |
| 1302 | } |
| 1303 | |
| 1304 | GlobalSelectionSystem().SetMode( SelectionSystem::eComponent ); |
| 1305 | GlobalSelectionSystem().SetComponentMode( SelectionSystem::eEdge ); |
| 1306 | } |
| 1307 | |
| 1308 | ComponentModeChanged(); |
| 1309 | |
| 1310 | ModeChangeNotify(); |
| 1311 | } |
| 1312 | |
| 1313 | void SelectVertexMode(){ |
| 1314 | #if 0 |
| 1315 | if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) { |
| 1316 | GlobalSelectionSystem().Select( false ); |
| 1317 | } |
| 1318 | #endif |
| 1319 | |
| 1320 | if ( VertexMode() ) { |
| 1321 | SelectionSystem_DefaultMode(); |
| 1322 | } |
| 1323 | else if ( GlobalSelectionSystem().countSelected() != 0 ) { |
| 1324 | if ( !g_currentToolModeSupportsComponentEditing ) { |
| 1325 | g_defaultToolMode(); |
| 1326 | } |
| 1327 | |
| 1328 | GlobalSelectionSystem().SetMode( SelectionSystem::eComponent ); |
| 1329 | GlobalSelectionSystem().SetComponentMode( SelectionSystem::eVertex ); |
| 1330 | } |
| 1331 | |
| 1332 | ComponentModeChanged(); |
| 1333 | |
| 1334 | ModeChangeNotify(); |
| 1335 | } |
| 1336 | |
| 1337 | void SelectFaceMode(){ |
| 1338 | #if 0 |
| 1339 | if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) { |
| 1340 | GlobalSelectionSystem().Select( false ); |
| 1341 | } |
| 1342 | #endif |
| 1343 | |
| 1344 | if ( FaceMode() ) { |
| 1345 | SelectionSystem_DefaultMode(); |
| 1346 | } |
| 1347 | else if ( GlobalSelectionSystem().countSelected() != 0 ) { |
| 1348 | if ( !g_currentToolModeSupportsComponentEditing ) { |
| 1349 | g_defaultToolMode(); |
| 1350 | } |
| 1351 | |
| 1352 | GlobalSelectionSystem().SetMode( SelectionSystem::eComponent ); |
| 1353 | GlobalSelectionSystem().SetComponentMode( SelectionSystem::eFace ); |
| 1354 | } |
| 1355 | |
| 1356 | ComponentModeChanged(); |
| 1357 | |
| 1358 | ModeChangeNotify(); |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | class CloneSelected : public scene::Graph::Walker |
| 1363 | { |
| 1364 | bool doMakeUnique; |
| 1365 | NodeSmartReference worldspawn; |
| 1366 | public: |
| 1367 | CloneSelected( bool d ) : doMakeUnique( d ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){ |
| 1368 | } |
| 1369 | |
| 1370 | bool pre( const scene::Path& path, scene::Instance& instance ) const { |
| 1371 | if ( path.size() == 1 ) { |
| 1372 | return true; |
| 1373 | } |
| 1374 | |
| 1375 | // ignore worldspawn, but keep checking children |
| 1376 | NodeSmartReference me( path.top().get() ); |
| 1377 | if ( me == worldspawn ) { |
| 1378 | return true; |
| 1379 | } |
| 1380 | |
| 1381 | if ( !path.top().get().isRoot() ) { |
| 1382 | Selectable* selectable = Instance_getSelectable( instance ); |
| 1383 | if ( selectable != 0 |
| 1384 | && selectable->isSelected() ) { |
| 1385 | return false; |
| 1386 | } |
| 1387 | if( doMakeUnique && instance.childSelected() ){ |
| 1388 | NodeSmartReference clone( Node_Clone_Selected( path.top() ) ); |
| 1389 | Map_gatherNamespaced( clone ); |
| 1390 | Node_getTraversable( path.parent().get() )->insert( clone ); |
| 1391 | return false; |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | return true; |
| 1396 | } |
| 1397 | |
| 1398 | void post( const scene::Path& path, scene::Instance& instance ) const { |
| 1399 | if ( path.size() == 1 ) { |
| 1400 | return; |
| 1401 | } |
| 1402 | |
| 1403 | // ignore worldspawn, but keep checking children |
| 1404 | NodeSmartReference me( path.top().get() ); |
| 1405 | if ( me == worldspawn ) { |
| 1406 | return; |
| 1407 | } |
| 1408 | |
| 1409 | if ( !path.top().get().isRoot() ) { |
| 1410 | Selectable* selectable = Instance_getSelectable( instance ); |
| 1411 | if ( selectable != 0 |
| 1412 | && selectable->isSelected() ) { |
| 1413 | NodeSmartReference clone( Node_Clone( path.top() ) ); |
| 1414 | if ( doMakeUnique ) { |
| 1415 | Map_gatherNamespaced( clone ); |
| 1416 | } |
| 1417 | Node_getTraversable( path.parent().get() )->insert( clone ); |
| 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | }; |
| 1422 | |
| 1423 | void Scene_Clone_Selected( scene::Graph& graph, bool doMakeUnique ){ |
| 1424 | graph.traverse( CloneSelected( doMakeUnique ) ); |
| 1425 | |
| 1426 | Map_mergeClonedNames(); |
| 1427 | } |
| 1428 | |
| 1429 | enum ENudgeDirection |
| 1430 | { |
| 1431 | eNudgeUp = 1, |
| 1432 | eNudgeDown = 3, |
| 1433 | eNudgeLeft = 0, |
| 1434 | eNudgeRight = 2, |
| 1435 | }; |
| 1436 | |
| 1437 | struct AxisBase |
| 1438 | { |
| 1439 | Vector3 x; |
| 1440 | Vector3 y; |
| 1441 | Vector3 z; |
| 1442 | |
| 1443 | AxisBase( const Vector3& x_, const Vector3& y_, const Vector3& z_ ) |
| 1444 | : x( x_ ), y( y_ ), z( z_ ){ |
| 1445 | } |
| 1446 | }; |
| 1447 | |
| 1448 | AxisBase AxisBase_forViewType( VIEWTYPE viewtype ){ |
| 1449 | switch ( viewtype ) |
| 1450 | { |
| 1451 | case XY: |
| 1452 | return AxisBase( g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z ); |
| 1453 | case XZ: |
| 1454 | return AxisBase( g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y ); |
| 1455 | case YZ: |
| 1456 | return AxisBase( g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x ); |
| 1457 | } |
| 1458 | |
| 1459 | ERROR_MESSAGE( "invalid viewtype" ); |
| 1460 | return AxisBase( Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ) ); |
| 1461 | } |
| 1462 | |
| 1463 | Vector3 AxisBase_axisForDirection( const AxisBase& axes, ENudgeDirection direction ){ |
| 1464 | switch ( direction ) |
| 1465 | { |
| 1466 | case eNudgeLeft: |
| 1467 | return vector3_negated( axes.x ); |
| 1468 | case eNudgeUp: |
| 1469 | return axes.y; |
| 1470 | case eNudgeRight: |
| 1471 | return axes.x; |
| 1472 | case eNudgeDown: |
| 1473 | return vector3_negated( axes.y ); |
| 1474 | } |
| 1475 | |
| 1476 | ERROR_MESSAGE( "invalid direction" ); |
| 1477 | return Vector3( 0, 0, 0 ); |
| 1478 | } |
| 1479 | |
| 1480 | bool g_bNudgeAfterClone = false; |
| 1481 | |
| 1482 | void Nudge_constructPreferences( PreferencesPage& page ){ |
| 1483 | page.appendCheckBox( "", "Nudge selected after duplication", g_bNudgeAfterClone ); |
| 1484 | } |
| 1485 | |
| 1486 | void NudgeSelection( ENudgeDirection direction, float fAmount, VIEWTYPE viewtype ){ |
| 1487 | AxisBase axes( AxisBase_forViewType( viewtype ) ); |
| 1488 | Vector3 view_direction( vector3_negated( axes.z ) ); |
| 1489 | Vector3 nudge( vector3_scaled( AxisBase_axisForDirection( axes, direction ), fAmount ) ); |
| 1490 | GlobalSelectionSystem().NudgeManipulator( nudge, view_direction ); |
| 1491 | } |
| 1492 | |
| 1493 | void Selection_Clone(){ |
| 1494 | if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) { |
| 1495 | UndoableCommand undo( "cloneSelected" ); |
| 1496 | |
| 1497 | Scene_Clone_Selected( GlobalSceneGraph(), false ); |
| 1498 | |
| 1499 | if( g_bNudgeAfterClone ){ |
| 1500 | NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType()); |
| 1501 | NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType()); |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | void Selection_Clone_MakeUnique(){ |
| 1507 | if ( GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) { |
| 1508 | UndoableCommand undo( "cloneSelectedMakeUnique" ); |
| 1509 | |
| 1510 | Scene_Clone_Selected( GlobalSceneGraph(), true ); |
| 1511 | |
| 1512 | if( g_bNudgeAfterClone ){ |
| 1513 | NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType()); |
| 1514 | NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType()); |
| 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | // called when the escape key is used (either on the main window or on an inspector) |
| 1520 | void Selection_Deselect(){ |
| 1521 | if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) { |
| 1522 | if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) { |
| 1523 | GlobalSelectionSystem().setSelectedAllComponents( false ); |
| 1524 | } |
| 1525 | else |
| 1526 | { |
| 1527 | SelectionSystem_DefaultMode(); |
| 1528 | ComponentModeChanged(); |
| 1529 | } |
| 1530 | } |
| 1531 | else |
| 1532 | { |
| 1533 | if ( GlobalSelectionSystem().countSelectedComponents() != 0 ) { |
| 1534 | GlobalSelectionSystem().setSelectedAllComponents( false ); |
| 1535 | } |
| 1536 | else |
| 1537 | { |
| 1538 | GlobalSelectionSystem().setSelectedAll( false ); |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | |
| 1544 | void Selection_NudgeUp(){ |
| 1545 | UndoableCommand undo( "nudgeSelectedUp" ); |
| 1546 | NudgeSelection( eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType() ); |
| 1547 | } |
| 1548 | |
| 1549 | void Selection_NudgeDown(){ |
| 1550 | UndoableCommand undo( "nudgeSelectedDown" ); |
| 1551 | NudgeSelection( eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType() ); |
| 1552 | } |
| 1553 | |
| 1554 | void Selection_NudgeLeft(){ |
| 1555 | UndoableCommand undo( "nudgeSelectedLeft" ); |
| 1556 | NudgeSelection( eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType() ); |
| 1557 | } |
| 1558 | |
| 1559 | void Selection_NudgeRight(){ |
| 1560 | UndoableCommand undo( "nudgeSelectedRight" ); |
| 1561 | NudgeSelection( eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType() ); |
| 1562 | } |
| 1563 | |
| 1564 | |
| 1565 | void TranslateToolExport( const Callback<void(bool)> & importCallback ){ |
| 1566 | importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate ); |
| 1567 | } |
| 1568 | |
| 1569 | void RotateToolExport( const Callback<void(bool)> & importCallback ){ |
| 1570 | importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate ); |
| 1571 | } |
| 1572 | |
| 1573 | void ScaleToolExport( const Callback<void(bool)> & importCallback ){ |
| 1574 | importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale ); |
| 1575 | } |
| 1576 | |
| 1577 | void DragToolExport( const Callback<void(bool)> & importCallback ){ |
| 1578 | importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag ); |
| 1579 | } |
| 1580 | |
| 1581 | void ClipperToolExport( const Callback<void(bool)> & importCallback ){ |
| 1582 | importCallback( GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip ); |
| 1583 | } |
| 1584 | |
| 1585 | FreeCaller<void(const Callback<void(bool)> &), TranslateToolExport> g_translatemode_button_caller; |
| 1586 | Callback<void(const Callback<void(bool)> &)> g_translatemode_button_callback( g_translatemode_button_caller ); |
| 1587 | ToggleItem g_translatemode_button( g_translatemode_button_callback ); |
| 1588 | |
| 1589 | FreeCaller<void(const Callback<void(bool)> &), RotateToolExport> g_rotatemode_button_caller; |
| 1590 | Callback<void(const Callback<void(bool)> &)> g_rotatemode_button_callback( g_rotatemode_button_caller ); |
| 1591 | ToggleItem g_rotatemode_button( g_rotatemode_button_callback ); |
| 1592 | |
| 1593 | FreeCaller<void(const Callback<void(bool)> &), ScaleToolExport> g_scalemode_button_caller; |
| 1594 | Callback<void(const Callback<void(bool)> &)> g_scalemode_button_callback( g_scalemode_button_caller ); |
| 1595 | ToggleItem g_scalemode_button( g_scalemode_button_callback ); |
| 1596 | |
| 1597 | FreeCaller<void(const Callback<void(bool)> &), DragToolExport> g_dragmode_button_caller; |
| 1598 | Callback<void(const Callback<void(bool)> &)> g_dragmode_button_callback( g_dragmode_button_caller ); |
| 1599 | ToggleItem g_dragmode_button( g_dragmode_button_callback ); |
| 1600 | |
| 1601 | FreeCaller<void(const Callback<void(bool)> &), ClipperToolExport> g_clipper_button_caller; |
| 1602 | Callback<void(const Callback<void(bool)> &)> g_clipper_button_callback( g_clipper_button_caller ); |
| 1603 | ToggleItem g_clipper_button( g_clipper_button_callback ); |
| 1604 | |
| 1605 | void ToolChanged(){ |
| 1606 | g_translatemode_button.update(); |
| 1607 | g_rotatemode_button.update(); |
| 1608 | g_scalemode_button.update(); |
| 1609 | g_dragmode_button.update(); |
| 1610 | g_clipper_button.update(); |
| 1611 | } |
| 1612 | |
| 1613 | const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects"; |
| 1614 | |
| 1615 | void DragMode(){ |
| 1616 | if ( g_currentToolMode == DragMode && g_defaultToolMode != DragMode ) { |
| 1617 | g_defaultToolMode(); |
| 1618 | } |
| 1619 | else |
| 1620 | { |
| 1621 | g_currentToolMode = DragMode; |
| 1622 | g_currentToolModeSupportsComponentEditing = true; |
| 1623 | |
| 1624 | OnClipMode( false ); |
| 1625 | |
| 1626 | Sys_Status( c_ResizeMode_status ); |
| 1627 | GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eDrag ); |
| 1628 | ToolChanged(); |
| 1629 | ModeChangeNotify(); |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | |
| 1634 | const char* const c_TranslateMode_status = "Translate Tool: translate objects and components"; |
| 1635 | |
| 1636 | void TranslateMode(){ |
| 1637 | if ( g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode ) { |
| 1638 | g_defaultToolMode(); |
| 1639 | } |
| 1640 | else |
| 1641 | { |
| 1642 | g_currentToolMode = TranslateMode; |
| 1643 | g_currentToolModeSupportsComponentEditing = true; |
| 1644 | |
| 1645 | OnClipMode( false ); |
| 1646 | |
| 1647 | Sys_Status( c_TranslateMode_status ); |
| 1648 | GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eTranslate ); |
| 1649 | ToolChanged(); |
| 1650 | ModeChangeNotify(); |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components"; |
| 1655 | |
| 1656 | void RotateMode(){ |
| 1657 | if ( g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode ) { |
| 1658 | g_defaultToolMode(); |
| 1659 | } |
| 1660 | else |
| 1661 | { |
| 1662 | g_currentToolMode = RotateMode; |
| 1663 | g_currentToolModeSupportsComponentEditing = true; |
| 1664 | |
| 1665 | OnClipMode( false ); |
| 1666 | |
| 1667 | Sys_Status( c_RotateMode_status ); |
| 1668 | GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eRotate ); |
| 1669 | ToolChanged(); |
| 1670 | ModeChangeNotify(); |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | const char* const c_ScaleMode_status = "Scale Tool: scale objects and components"; |
| 1675 | |
| 1676 | void ScaleMode(){ |
| 1677 | if ( g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode ) { |
| 1678 | g_defaultToolMode(); |
| 1679 | } |
| 1680 | else |
| 1681 | { |
| 1682 | g_currentToolMode = ScaleMode; |
| 1683 | g_currentToolModeSupportsComponentEditing = true; |
| 1684 | |
| 1685 | OnClipMode( false ); |
| 1686 | |
| 1687 | Sys_Status( c_ScaleMode_status ); |
| 1688 | GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eScale ); |
| 1689 | ToolChanged(); |
| 1690 | ModeChangeNotify(); |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | |
| 1695 | const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects"; |
| 1696 | |
| 1697 | |
| 1698 | void ClipperMode(){ |
| 1699 | if ( g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode ) { |
| 1700 | g_defaultToolMode(); |
| 1701 | } |
| 1702 | else |
| 1703 | { |
| 1704 | g_currentToolMode = ClipperMode; |
| 1705 | g_currentToolModeSupportsComponentEditing = false; |
| 1706 | |
| 1707 | SelectionSystem_DefaultMode(); |
| 1708 | |
| 1709 | OnClipMode( true ); |
| 1710 | |
| 1711 | Sys_Status( c_ClipperMode_status ); |
| 1712 | GlobalSelectionSystem().SetManipulatorMode( SelectionSystem::eClip ); |
| 1713 | ToolChanged(); |
| 1714 | ModeChangeNotify(); |
| 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | void ToggleRotateScaleModes(){ |
| 1720 | if ( g_currentToolMode == RotateMode ) { |
| 1721 | ScaleMode(); |
| 1722 | } |
| 1723 | else |
| 1724 | { |
| 1725 | RotateMode(); |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | void ToggleDragScaleModes(){ |
| 1730 | if ( g_currentToolMode == DragMode ) { |
| 1731 | ScaleMode(); |
| 1732 | } |
| 1733 | else |
| 1734 | { |
| 1735 | DragMode(); |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | |
| 1740 | void Texdef_Rotate( float angle ){ |
| 1741 | StringOutputStream command; |
| 1742 | command << "brushRotateTexture -angle " << angle; |
| 1743 | UndoableCommand undo( command.c_str() ); |
| 1744 | Select_RotateTexture( angle ); |
| 1745 | } |
| 1746 | |
| 1747 | void Texdef_RotateClockwise(){ |
| 1748 | Texdef_Rotate( static_cast<float>( fabs( g_si_globals.rotate ) ) ); |
| 1749 | } |
| 1750 | |
| 1751 | void Texdef_RotateAntiClockwise(){ |
| 1752 | Texdef_Rotate( static_cast<float>( -fabs( g_si_globals.rotate ) ) ); |
| 1753 | } |
| 1754 | |
| 1755 | void Texdef_Scale( float x, float y ){ |
| 1756 | StringOutputStream command; |
| 1757 | command << "brushScaleTexture -x " << x << " -y " << y; |
| 1758 | UndoableCommand undo( command.c_str() ); |
| 1759 | Select_ScaleTexture( x, y ); |
| 1760 | } |
| 1761 | |
| 1762 | void Texdef_ScaleUp(){ |
| 1763 | Texdef_Scale( 0, g_si_globals.scale[1] ); |
| 1764 | } |
| 1765 | |
| 1766 | void Texdef_ScaleDown(){ |
| 1767 | Texdef_Scale( 0, -g_si_globals.scale[1] ); |
| 1768 | } |
| 1769 | |
| 1770 | void Texdef_ScaleLeft(){ |
| 1771 | Texdef_Scale( -g_si_globals.scale[0],0 ); |
| 1772 | } |
| 1773 | |
| 1774 | void Texdef_ScaleRight(){ |
| 1775 | Texdef_Scale( g_si_globals.scale[0],0 ); |
| 1776 | } |
| 1777 | |
| 1778 | void Texdef_Shift( float x, float y ){ |
| 1779 | StringOutputStream command; |
| 1780 | command << "brushShiftTexture -x " << x << " -y " << y; |
| 1781 | UndoableCommand undo( command.c_str() ); |
| 1782 | Select_ShiftTexture( x, y ); |
| 1783 | } |
| 1784 | |
| 1785 | void Texdef_ShiftLeft(){ |
| 1786 | Texdef_Shift( -g_si_globals.shift[0], 0 ); |
| 1787 | } |
| 1788 | |
| 1789 | void Texdef_ShiftRight(){ |
| 1790 | Texdef_Shift( g_si_globals.shift[0], 0 ); |
| 1791 | } |
| 1792 | |
| 1793 | void Texdef_ShiftUp(){ |
| 1794 | Texdef_Shift( 0, g_si_globals.shift[1] ); |
| 1795 | } |
| 1796 | |
| 1797 | void Texdef_ShiftDown(){ |
| 1798 | Texdef_Shift( 0, -g_si_globals.shift[1] ); |
| 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | class SnappableSnapToGridSelected : public scene::Graph::Walker |
| 1804 | { |
| 1805 | float m_snap; |
| 1806 | public: |
| 1807 | SnappableSnapToGridSelected( float snap ) |
| 1808 | : m_snap( snap ){ |
| 1809 | } |
| 1810 | |
| 1811 | bool pre( const scene::Path& path, scene::Instance& instance ) const { |
| 1812 | if ( path.top().get().visible() ) { |
| 1813 | Snappable* snappable = Node_getSnappable( path.top() ); |
| 1814 | if ( snappable != 0 |
| 1815 | && Instance_getSelectable( instance )->isSelected() ) { |
| 1816 | snappable->snapto( m_snap ); |
| 1817 | } |
| 1818 | } |
| 1819 | return true; |
| 1820 | } |
| 1821 | }; |
| 1822 | |
| 1823 | void Scene_SnapToGrid_Selected( scene::Graph& graph, float snap ){ |
| 1824 | graph.traverse( SnappableSnapToGridSelected( snap ) ); |
| 1825 | } |
| 1826 | |
| 1827 | class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker |
| 1828 | { |
| 1829 | float m_snap; |
| 1830 | public: |
| 1831 | ComponentSnappableSnapToGridSelected( float snap ) |
| 1832 | : m_snap( snap ){ |
| 1833 | } |
| 1834 | |
| 1835 | bool pre( const scene::Path& path, scene::Instance& instance ) const { |
| 1836 | if ( path.top().get().visible() ) { |
| 1837 | ComponentSnappable* componentSnappable = Instance_getComponentSnappable( instance ); |
| 1838 | if ( componentSnappable != 0 |
| 1839 | && Instance_getSelectable( instance )->isSelected() ) { |
| 1840 | componentSnappable->snapComponents( m_snap ); |
| 1841 | } |
| 1842 | } |
| 1843 | return true; |
| 1844 | } |
| 1845 | }; |
| 1846 | |
| 1847 | void Scene_SnapToGrid_Component_Selected( scene::Graph& graph, float snap ){ |
| 1848 | graph.traverse( ComponentSnappableSnapToGridSelected( snap ) ); |
| 1849 | } |
| 1850 | |
| 1851 | void Selection_SnapToGrid(){ |
| 1852 | StringOutputStream command; |
| 1853 | command << "snapSelected -grid " << GetGridSize(); |
| 1854 | UndoableCommand undo( command.c_str() ); |
| 1855 | |
| 1856 | if ( GlobalSelectionSystem().Mode() == SelectionSystem::eComponent ) { |
| 1857 | Scene_SnapToGrid_Component_Selected( GlobalSceneGraph(), GetGridSize() ); |
| 1858 | } |
| 1859 | else |
| 1860 | { |
| 1861 | Scene_SnapToGrid_Selected( GlobalSceneGraph(), GetGridSize() ); |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | |
| 1866 | static gint qe_every_second( gpointer data ){ |
| 1867 | if (g_pParentWnd == nullptr) |
| 1868 | return TRUE; |
| 1869 | |
| 1870 | GdkModifierType mask; |
| 1871 | gdk_window_get_pointer( gtk_widget_get_window(g_pParentWnd->m_window), nullptr, nullptr, &mask ); |
| 1872 | |
| 1873 | if ( ( mask & ( GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK ) ) == 0 ) { |
| 1874 | QE_CheckAutoSave(); |
| 1875 | } |
| 1876 | |
| 1877 | return TRUE; |
| 1878 | } |
| 1879 | |
| 1880 | guint s_qe_every_second_id = 0; |
| 1881 | |
| 1882 | void EverySecondTimer_enable(){ |
| 1883 | if ( s_qe_every_second_id == 0 ) { |
| 1884 | s_qe_every_second_id = g_timeout_add( 1000, qe_every_second, 0 ); |
| 1885 | } |
| 1886 | } |
| 1887 | |
| 1888 | void EverySecondTimer_disable(){ |
| 1889 | if ( s_qe_every_second_id != 0 ) { |
| 1890 | g_source_remove( s_qe_every_second_id ); |
| 1891 | s_qe_every_second_id = 0; |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | gint window_realize_remove_decoration( ui::Widget widget, gpointer data ){ |
| 1896 | gdk_window_set_decorations( gtk_widget_get_window(widget), (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) ); |
| 1897 | return FALSE; |
| 1898 | } |
| 1899 | |
| 1900 | class WaitDialog |
| 1901 | { |
| 1902 | public: |
| 1903 | ui::Window m_window{ui::null}; |
| 1904 | ui::Label m_label{ui::null}; |
| 1905 | }; |
| 1906 | |
| 1907 | WaitDialog create_wait_dialog( const char* title, const char* text ){ |
| 1908 | WaitDialog dialog; |
| 1909 | |
| 1910 | dialog.m_window = MainFrame_getWindow().create_floating_window(title); |
| 1911 | gtk_window_set_resizable( dialog.m_window, FALSE ); |
| 1912 | gtk_container_set_border_width( GTK_CONTAINER( dialog.m_window ), 0 ); |
| 1913 | gtk_window_set_position( dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT ); |
| 1914 | |
| 1915 | dialog.m_window.connect( "realize", G_CALLBACK( window_realize_remove_decoration ), 0 ); |
| 1916 | |
| 1917 | { |
| 1918 | dialog.m_label = ui::Label( text ); |
| 1919 | gtk_misc_set_alignment( GTK_MISC( dialog.m_label ), 0.0, 0.5 ); |
| 1920 | gtk_label_set_justify( dialog.m_label, GTK_JUSTIFY_LEFT ); |
| 1921 | dialog.m_label.show(); |
| 1922 | dialog.m_label.dimensions(200, -1); |
| 1923 | |
| 1924 | dialog.m_window.add(dialog.m_label); |
| 1925 | } |
| 1926 | return dialog; |
| 1927 | } |
| 1928 | |
| 1929 | namespace |
| 1930 | { |
| 1931 | clock_t g_lastRedrawTime = 0; |
| 1932 | const clock_t c_redrawInterval = clock_t( CLOCKS_PER_SEC / 10 ); |
| 1933 | |
| 1934 | bool redrawRequired(){ |
| 1935 | clock_t currentTime = std::clock(); |
| 1936 | if ( currentTime - g_lastRedrawTime >= c_redrawInterval ) { |
| 1937 | g_lastRedrawTime = currentTime; |
| 1938 | return true; |
| 1939 | } |
| 1940 | return false; |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | bool MainFrame_isActiveApp(){ |
| 1945 | //globalOutputStream() << "listing\n"; |
| 1946 | GList* list = gtk_window_list_toplevels(); |
| 1947 | for ( GList* i = list; i != 0; i = g_list_next( i ) ) |
| 1948 | { |
| 1949 | //globalOutputStream() << "toplevel.. "; |
| 1950 | if ( gtk_window_is_active( ui::Window::from( i->data ) ) ) { |
| 1951 | //globalOutputStream() << "is active\n"; |
| 1952 | return true; |
| 1953 | } |
| 1954 | //globalOutputStream() << "not active\n"; |
| 1955 | } |
| 1956 | return false; |
| 1957 | } |
| 1958 | |
| 1959 | typedef std::list<CopiedString> StringStack; |
| 1960 | StringStack g_wait_stack; |
| 1961 | WaitDialog g_wait; |
| 1962 | |
| 1963 | bool ScreenUpdates_Enabled(){ |
| 1964 | return g_wait_stack.empty(); |
| 1965 | } |
| 1966 | |
| 1967 | void ScreenUpdates_process(){ |
| 1968 | if ( redrawRequired() && g_wait.m_window.visible() ) { |
| 1969 | ui::process(); |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | |
| 1974 | void ScreenUpdates_Disable( const char* message, const char* title ){ |
| 1975 | if ( g_wait_stack.empty() ) { |
| 1976 | EverySecondTimer_disable(); |
| 1977 | |
| 1978 | ui::process(); |
| 1979 | |
| 1980 | bool isActiveApp = MainFrame_isActiveApp(); |
| 1981 | |
| 1982 | g_wait = create_wait_dialog( title, message ); |
| 1983 | |
| 1984 | if ( isActiveApp ) { |
| 1985 | g_wait.m_window.show(); |
| 1986 | gtk_grab_add( g_wait.m_window ); |
| 1987 | ScreenUpdates_process(); |
| 1988 | } |
| 1989 | } |
| 1990 | else if ( g_wait.m_window.visible() ) { |
| 1991 | g_wait.m_label.text(message); |
| 1992 | if ( GTK_IS_WINDOW(g_wait.m_window) ) { |
| 1993 | gtk_grab_add(g_wait.m_window); |
| 1994 | } |
| 1995 | ScreenUpdates_process(); |
| 1996 | } |
| 1997 | g_wait_stack.push_back( message ); |
| 1998 | } |
| 1999 | |
| 2000 | void ScreenUpdates_Enable(){ |
| 2001 | ASSERT_MESSAGE( !ScreenUpdates_Enabled(), "screen updates already enabled" ); |
| 2002 | g_wait_stack.pop_back(); |
| 2003 | if ( g_wait_stack.empty() ) { |
| 2004 | EverySecondTimer_enable(); |
| 2005 | //gtk_widget_set_sensitive(MainFrame_getWindow(), TRUE); |
| 2006 | |
| 2007 | gtk_grab_remove( g_wait.m_window ); |
| 2008 | destroy_floating_window( g_wait.m_window ); |
| 2009 | g_wait.m_window = ui::Window{ui::null}; |
| 2010 | |
| 2011 | //gtk_window_present(MainFrame_getWindow()); |
| 2012 | } |
| 2013 | else if ( g_wait.m_window.visible() ) { |
| 2014 | g_wait.m_label.text(g_wait_stack.back().c_str()); |
| 2015 | ScreenUpdates_process(); |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | |
| 2020 | void GlobalCamera_UpdateWindow(){ |
| 2021 | if ( g_pParentWnd != 0 ) { |
| 2022 | CamWnd_Update( *g_pParentWnd->GetCamWnd() ); |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | void XY_UpdateWindow( MainFrame& mainframe ){ |
| 2027 | if ( mainframe.GetXYWnd() != 0 ) { |
| 2028 | XYWnd_Update( *mainframe.GetXYWnd() ); |
| 2029 | } |
| 2030 | } |
| 2031 | |
| 2032 | void XZ_UpdateWindow( MainFrame& mainframe ){ |
| 2033 | if ( mainframe.GetXZWnd() != 0 ) { |
| 2034 | XYWnd_Update( *mainframe.GetXZWnd() ); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | void YZ_UpdateWindow( MainFrame& mainframe ){ |
| 2039 | if ( mainframe.GetYZWnd() != 0 ) { |
| 2040 | XYWnd_Update( *mainframe.GetYZWnd() ); |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | void XY_UpdateAllWindows( MainFrame& mainframe ){ |
| 2045 | XY_UpdateWindow( mainframe ); |
| 2046 | XZ_UpdateWindow( mainframe ); |
| 2047 | YZ_UpdateWindow( mainframe ); |
| 2048 | } |
| 2049 | |
| 2050 | void XY_UpdateAllWindows(){ |
| 2051 | if ( g_pParentWnd != 0 ) { |
| 2052 | XY_UpdateAllWindows( *g_pParentWnd ); |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | void UpdateAllWindows(){ |
| 2057 | GlobalCamera_UpdateWindow(); |
| 2058 | XY_UpdateAllWindows(); |
| 2059 | } |
| 2060 | |
| 2061 | |
| 2062 | void ModeChangeNotify(){ |
| 2063 | SceneChangeNotify(); |
| 2064 | } |
| 2065 | |
| 2066 | void ClipperChangeNotify(){ |
| 2067 | GlobalCamera_UpdateWindow(); |
| 2068 | XY_UpdateAllWindows(); |
| 2069 | } |
| 2070 | |
| 2071 | |
| 2072 | LatchedValue<int> g_Layout_viewStyle( 0, "Window Layout" ); |
| 2073 | LatchedValue<bool> g_Layout_enableDetachableMenus( true, "Detachable Menus" ); |
| 2074 | LatchedValue<bool> g_Layout_enableMainToolbar( true, "Main Toolbar" ); |
| 2075 | LatchedValue<bool> g_Layout_enablePatchToolbar( true, "Patch Toolbar" ); |
| 2076 | LatchedValue<bool> g_Layout_enablePluginToolbar( true, "Plugin Toolbar" ); |
| 2077 | LatchedValue<bool> g_Layout_enableFilterToolbar( true, "Filter Toolbar" ); |
| 2078 | |
| 2079 | |
| 2080 | ui::MenuItem create_file_menu(){ |
| 2081 | // File menu |
| 2082 | auto file_menu_item = new_sub_menu_item_with_mnemonic( "_File" ); |
| 2083 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( file_menu_item ) ); |
| 2084 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2085 | menu_tearoff( menu ); |
| 2086 | } |
| 2087 | |
| 2088 | create_menu_item_with_mnemonic( menu, "_New Map", "NewMap" ); |
| 2089 | menu_separator( menu ); |
| 2090 | |
| 2091 | #if 0 |
| 2092 | //++timo temporary experimental stuff for sleep mode.. |
| 2093 | create_menu_item_with_mnemonic( menu, "_Sleep", "Sleep" ); |
| 2094 | menu_separator( menu ); |
| 2095 | // end experimental |
| 2096 | #endif |
| 2097 | |
| 2098 | create_menu_item_with_mnemonic( menu, "_Open...", "OpenMap" ); |
| 2099 | create_menu_item_with_mnemonic( menu, "_Import...", "ImportMap" ); |
| 2100 | menu_separator( menu ); |
| 2101 | create_menu_item_with_mnemonic( menu, "_Save", "SaveMap" ); |
| 2102 | create_menu_item_with_mnemonic( menu, "Save _as...", "SaveMapAs" ); |
| 2103 | create_menu_item_with_mnemonic( menu, "_Export selected...", "ExportSelected" ); |
| 2104 | create_menu_item_with_mnemonic( menu, "Save re_gion...", "SaveRegion" ); |
| 2105 | menu_separator( menu ); |
| 2106 | // menu_separator( menu ); |
| 2107 | // create_menu_item_with_mnemonic( menu, "_Refresh models", "RefreshReferences" ); |
| 2108 | // menu_separator( menu ); |
| 2109 | create_menu_item_with_mnemonic( menu, "Pro_ject settings...", "ProjectSettings" ); |
| 2110 | //menu_separator( menu ); |
| 2111 | create_menu_item_with_mnemonic( menu, "_Pointfile", "TogglePointfile" ); |
| 2112 | menu_separator( menu ); |
| 2113 | MRU_constructMenu( menu ); |
| 2114 | menu_separator( menu ); |
| 2115 | // create_menu_item_with_mnemonic( menu, "Check for NetRadiant update (web)", "CheckForUpdate" ); // FIXME |
| 2116 | create_menu_item_with_mnemonic( menu, "E_xit", "Exit" ); |
| 2117 | |
| 2118 | return file_menu_item; |
| 2119 | } |
| 2120 | |
| 2121 | ui::MenuItem create_edit_menu(){ |
| 2122 | // Edit menu |
| 2123 | auto edit_menu_item = new_sub_menu_item_with_mnemonic( "_Edit" ); |
| 2124 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( edit_menu_item ) ); |
| 2125 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2126 | menu_tearoff( menu ); |
| 2127 | } |
| 2128 | create_menu_item_with_mnemonic( menu, "_Undo", "Undo" ); |
| 2129 | create_menu_item_with_mnemonic( menu, "_Redo", "Redo" ); |
| 2130 | menu_separator( menu ); |
| 2131 | create_menu_item_with_mnemonic( menu, "_Copy", "Copy" ); |
| 2132 | create_menu_item_with_mnemonic( menu, "_Paste", "Paste" ); |
| 2133 | create_menu_item_with_mnemonic( menu, "P_aste To Camera", "PasteToCamera" ); |
| 2134 | menu_separator( menu ); |
| 2135 | create_menu_item_with_mnemonic( menu, "_Duplicate", "CloneSelection" ); |
| 2136 | create_menu_item_with_mnemonic( menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique" ); |
| 2137 | create_menu_item_with_mnemonic( menu, "D_elete", "DeleteSelection" ); |
| 2138 | //create_menu_item_with_mnemonic( menu, "Pa_rent", "ParentSelection" ); |
| 2139 | menu_separator( menu ); |
| 2140 | create_menu_item_with_mnemonic( menu, "C_lear Selection", "UnSelectSelection" ); |
| 2141 | create_menu_item_with_mnemonic( menu, "_Invert Selection", "InvertSelection" ); |
| 2142 | create_menu_item_with_mnemonic( menu, "Select i_nside", "SelectInside" ); |
| 2143 | create_menu_item_with_mnemonic( menu, "Select _touching", "SelectTouching" ); |
| 2144 | |
| 2145 | menu_separator( menu ); |
| 2146 | |
| 2147 | // auto convert_menu = create_sub_menu_with_mnemonic( menu, "E_xpand Selection" ); |
| 2148 | // if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2149 | // menu_tearoff( convert_menu ); |
| 2150 | // } |
| 2151 | create_menu_item_with_mnemonic( menu, "Select All Of Type", "SelectAllOfType" ); |
| 2152 | create_menu_item_with_mnemonic( menu, "_Expand Selection To Entities", "ExpandSelectionToEntities" ); |
| 2153 | create_menu_item_with_mnemonic( menu, "Select Connected Entities", "SelectConnectedEntities" ); |
| 2154 | |
| 2155 | menu_separator( menu ); |
| 2156 | create_menu_item_with_mnemonic( menu, "Pre_ferences...", "Preferences" ); |
| 2157 | |
| 2158 | return edit_menu_item; |
| 2159 | } |
| 2160 | |
| 2161 | |
| 2162 | ui::Widget g_toggle_z_item{ui::null}; |
| 2163 | ui::Widget g_toggle_console_item{ui::null}; |
| 2164 | ui::Widget g_toggle_entity_item{ui::null}; |
| 2165 | ui::Widget g_toggle_entitylist_item{ui::null}; |
| 2166 | |
| 2167 | ui::MenuItem create_view_menu( MainFrame::EViewStyle style ){ |
| 2168 | // View menu |
| 2169 | auto view_menu_item = new_sub_menu_item_with_mnemonic( "Vie_w" ); |
| 2170 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( view_menu_item ) ); |
| 2171 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2172 | menu_tearoff( menu ); |
| 2173 | } |
| 2174 | |
| 2175 | if ( style == MainFrame::eFloating ) { |
| 2176 | create_check_menu_item_with_mnemonic( menu, "Camera View", "ToggleCamera" ); |
| 2177 | create_check_menu_item_with_mnemonic( menu, "XY (Top) View", "ToggleView" ); |
| 2178 | create_check_menu_item_with_mnemonic( menu, "XZ (Front) View", "ToggleFrontView" ); |
| 2179 | create_check_menu_item_with_mnemonic( menu, "YZ (Side) View", "ToggleSideView" ); |
| 2180 | } |
| 2181 | if ( style == MainFrame::eFloating || style == MainFrame::eSplit ) { |
| 2182 | create_menu_item_with_mnemonic( menu, "Console", "ToggleConsole" ); |
| 2183 | create_menu_item_with_mnemonic( menu, "Texture Browser", "ToggleTextures" ); |
| 2184 | create_menu_item_with_mnemonic( menu, "Entity Inspector", "ToggleEntityInspector" ); |
| 2185 | } |
| 2186 | else |
| 2187 | { |
| 2188 | create_menu_item_with_mnemonic( menu, "Entity Inspector", "ViewEntityInfo" ); |
| 2189 | } |
| 2190 | create_menu_item_with_mnemonic( menu, "_Surface Inspector", "SurfaceInspector" ); |
| 2191 | create_menu_item_with_mnemonic( menu, "_Patch Inspector", "PatchInspector" ); |
| 2192 | create_menu_item_with_mnemonic( menu, "Entity List", "EntityList" ); |
| 2193 | |
| 2194 | menu_separator( menu ); |
| 2195 | { |
| 2196 | auto camera_menu = create_sub_menu_with_mnemonic( menu, "Camera" ); |
| 2197 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2198 | menu_tearoff( camera_menu ); |
| 2199 | } |
| 2200 | create_menu_item_with_mnemonic( camera_menu, "Focus on Selected", "CameraFocusOnSelected" ); |
| 2201 | create_menu_item_with_mnemonic( camera_menu, "_Center", "CenterView" ); |
| 2202 | create_menu_item_with_mnemonic( camera_menu, "_Up Floor", "UpFloor" ); |
| 2203 | create_menu_item_with_mnemonic( camera_menu, "_Down Floor", "DownFloor" ); |
| 2204 | menu_separator( camera_menu ); |
| 2205 | create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane In", "CubicClipZoomIn" ); |
| 2206 | create_menu_item_with_mnemonic( camera_menu, "Far Clip Plane Out", "CubicClipZoomOut" ); |
| 2207 | menu_separator( camera_menu ); |
| 2208 | create_menu_item_with_mnemonic( camera_menu, "Decrease FOV", "FOVDec" ); |
| 2209 | create_menu_item_with_mnemonic( camera_menu, "Increase FOV", "FOVInc" ); |
| 2210 | menu_separator( camera_menu ); |
| 2211 | create_menu_item_with_mnemonic( camera_menu, "Next leak spot", "NextLeakSpot" ); |
| 2212 | create_menu_item_with_mnemonic( camera_menu, "Previous leak spot", "PrevLeakSpot" ); |
| 2213 | //cameramodel is not implemented in instances, thus useless |
| 2214 | // menu_separator( camera_menu ); |
| 2215 | // create_menu_item_with_mnemonic( camera_menu, "Look Through Selected", "LookThroughSelected" ); |
| 2216 | // create_menu_item_with_mnemonic( camera_menu, "Look Through Camera", "LookThroughCamera" ); |
| 2217 | } |
| 2218 | menu_separator( menu ); |
| 2219 | { |
| 2220 | auto orthographic_menu = create_sub_menu_with_mnemonic( menu, "Orthographic" ); |
| 2221 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2222 | menu_tearoff( orthographic_menu ); |
| 2223 | } |
| 2224 | if ( style == MainFrame::eRegular || style == MainFrame::eRegularLeft || style == MainFrame::eFloating ) { |
| 2225 | create_menu_item_with_mnemonic( orthographic_menu, "_Next (XY, YZ, XY)", "NextView" ); |
| 2226 | create_menu_item_with_mnemonic( orthographic_menu, "XY (Top)", "ViewTop" ); |
| 2227 | create_menu_item_with_mnemonic( orthographic_menu, "XZ (Front)", "ViewFront" ); |
| 2228 | create_menu_item_with_mnemonic( orthographic_menu, "YZ (Side)", "ViewSide" ); |
| 2229 | menu_separator( orthographic_menu ); |
| 2230 | } |
| 2231 | else{ |
| 2232 | create_menu_item_with_mnemonic( orthographic_menu, "Center on Selected", "NextView" ); |
| 2233 | } |
| 2234 | |
| 2235 | create_menu_item_with_mnemonic( orthographic_menu, "Focus on Selected", "XYFocusOnSelected" ); |
| 2236 | create_menu_item_with_mnemonic( orthographic_menu, "Center on Selected", "CenterXYView" ); |
| 2237 | menu_separator( orthographic_menu ); |
| 2238 | create_menu_item_with_mnemonic( orthographic_menu, "_XY 100%", "Zoom100" ); |
| 2239 | create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _In", "ZoomIn" ); |
| 2240 | create_menu_item_with_mnemonic( orthographic_menu, "XY Zoom _Out", "ZoomOut" ); |
| 2241 | } |
| 2242 | |
| 2243 | menu_separator( menu ); |
| 2244 | |
| 2245 | { |
| 2246 | auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Show" ); |
| 2247 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2248 | menu_tearoff( menu_in_menu ); |
| 2249 | } |
| 2250 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Entity _Angles", "ShowAngles" ); |
| 2251 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Entity _Names", "ShowNames" ); |
| 2252 | create_check_menu_item_with_mnemonic( menu_in_menu, "Entity Names = Targetnames", "ShowTargetNames" ); |
| 2253 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Light Radiuses", "ShowLightRadiuses" ); |
| 2254 | |
| 2255 | menu_separator( menu_in_menu ); |
| 2256 | |
| 2257 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Size Info", "ToggleSizePaint" ); |
| 2258 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Crosshair", "ToggleCrosshairs" ); |
| 2259 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Grid", "ToggleGrid" ); |
| 2260 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Blocks", "ShowBlocks" ); |
| 2261 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show C_oordinates", "ShowCoordinates" ); |
| 2262 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Window Outline", "ShowWindowOutline" ); |
| 2263 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Axes", "ShowAxes" ); |
| 2264 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Workzone", "ShowWorkzone" ); |
| 2265 | create_check_menu_item_with_mnemonic( menu_in_menu, "Show Camera Stats", "ShowStats" ); |
| 2266 | } |
| 2267 | |
| 2268 | { |
| 2269 | auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Filter" ); |
| 2270 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2271 | menu_tearoff( menu_in_menu ); |
| 2272 | } |
| 2273 | Filters_constructMenu( menu_in_menu ); |
| 2274 | } |
| 2275 | menu_separator( menu ); |
| 2276 | { |
| 2277 | create_check_menu_item_with_mnemonic( menu, "Hide Selected", "HideSelected" ); |
| 2278 | create_menu_item_with_mnemonic( menu, "Show Hidden", "ShowHidden" ); |
| 2279 | } |
| 2280 | menu_separator( menu ); |
| 2281 | { |
| 2282 | auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Region" ); |
| 2283 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2284 | menu_tearoff( menu_in_menu ); |
| 2285 | } |
| 2286 | create_menu_item_with_mnemonic( menu_in_menu, "_Off", "RegionOff" ); |
| 2287 | create_menu_item_with_mnemonic( menu_in_menu, "_Set XY", "RegionSetXY" ); |
| 2288 | create_menu_item_with_mnemonic( menu_in_menu, "Set _Brush", "RegionSetBrush" ); |
| 2289 | create_check_menu_item_with_mnemonic( menu_in_menu, "Set Se_lected Brushes", "RegionSetSelection" ); |
| 2290 | } |
| 2291 | |
| 2292 | //command_connect_accelerator( "CenterXYView" ); |
| 2293 | |
| 2294 | return view_menu_item; |
| 2295 | } |
| 2296 | |
| 2297 | ui::MenuItem create_selection_menu(){ |
| 2298 | // Selection menu |
| 2299 | auto selection_menu_item = new_sub_menu_item_with_mnemonic( "M_odify" ); |
| 2300 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( selection_menu_item ) ); |
| 2301 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2302 | menu_tearoff( menu ); |
| 2303 | } |
| 2304 | |
| 2305 | { |
| 2306 | auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Components" ); |
| 2307 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2308 | menu_tearoff( menu_in_menu ); |
| 2309 | } |
| 2310 | create_check_menu_item_with_mnemonic( menu_in_menu, "_Edges", "DragEdges" ); |
| 2311 | create_check_menu_item_with_mnemonic( menu_in_menu, "_Vertices", "DragVertices" ); |
| 2312 | create_check_menu_item_with_mnemonic( menu_in_menu, "_Faces", "DragFaces" ); |
| 2313 | } |
| 2314 | |
| 2315 | menu_separator( menu ); |
| 2316 | create_menu_item_with_mnemonic( menu, "Snap To Grid", "SnapToGrid" ); |
| 2317 | |
| 2318 | menu_separator( menu ); |
| 2319 | |
| 2320 | { |
| 2321 | auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Nudge" ); |
| 2322 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2323 | menu_tearoff( menu_in_menu ); |
| 2324 | } |
| 2325 | create_menu_item_with_mnemonic( menu_in_menu, "Nudge Left", "SelectNudgeLeft" ); |
| 2326 | create_menu_item_with_mnemonic( menu_in_menu, "Nudge Right", "SelectNudgeRight" ); |
| 2327 | create_menu_item_with_mnemonic( menu_in_menu, "Nudge Up", "SelectNudgeUp" ); |
| 2328 | create_menu_item_with_mnemonic( menu_in_menu, "Nudge Down", "SelectNudgeDown" ); |
| 2329 | menu_separator( menu_in_menu ); |
| 2330 | create_menu_item_with_mnemonic( menu_in_menu, "Nudge +Z", "MoveSelectionUP" ); |
| 2331 | create_menu_item_with_mnemonic( menu_in_menu, "Nudge -Z", "MoveSelectionDOWN" ); |
| 2332 | } |
| 2333 | { |
| 2334 | auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Rotate" ); |
| 2335 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2336 | menu_tearoff( menu_in_menu ); |
| 2337 | } |
| 2338 | create_menu_item_with_mnemonic( menu_in_menu, "Rotate X", "RotateSelectionX" ); |
| 2339 | create_menu_item_with_mnemonic( menu_in_menu, "Rotate Y", "RotateSelectionY" ); |
| 2340 | create_menu_item_with_mnemonic( menu_in_menu, "Rotate Z", "RotateSelectionZ" ); |
| 2341 | menu_separator( menu_in_menu ); |
| 2342 | create_menu_item_with_mnemonic( menu_in_menu, "Rotate Clockwise", "RotateSelectionClockwise" ); |
| 2343 | create_menu_item_with_mnemonic( menu_in_menu, "Rotate Anticlockwise", "RotateSelectionAnticlockwise" ); |
| 2344 | } |
| 2345 | { |
| 2346 | auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Flip" ); |
| 2347 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2348 | menu_tearoff( menu_in_menu ); |
| 2349 | } |
| 2350 | create_menu_item_with_mnemonic( menu_in_menu, "Flip _X", "MirrorSelectionX" ); |
| 2351 | create_menu_item_with_mnemonic( menu_in_menu, "Flip _Y", "MirrorSelectionY" ); |
| 2352 | create_menu_item_with_mnemonic( menu_in_menu, "Flip _Z", "MirrorSelectionZ" ); |
| 2353 | menu_separator( menu_in_menu ); |
| 2354 | create_menu_item_with_mnemonic( menu_in_menu, "Flip Horizontally", "MirrorSelectionHorizontally" ); |
| 2355 | create_menu_item_with_mnemonic( menu_in_menu, "Flip Vertically", "MirrorSelectionVertically" ); |
| 2356 | } |
| 2357 | menu_separator( menu ); |
| 2358 | create_menu_item_with_mnemonic( menu, "Arbitrary rotation...", "ArbitraryRotation" ); |
| 2359 | create_menu_item_with_mnemonic( menu, "Arbitrary scale...", "ArbitraryScale" ); |
| 2360 | |
| 2361 | return selection_menu_item; |
| 2362 | } |
| 2363 | |
| 2364 | ui::MenuItem create_bsp_menu(){ |
| 2365 | // BSP menu |
| 2366 | auto bsp_menu_item = new_sub_menu_item_with_mnemonic( "_Build" ); |
| 2367 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( bsp_menu_item ) ); |
| 2368 | |
| 2369 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2370 | menu_tearoff( menu ); |
| 2371 | } |
| 2372 | |
| 2373 | create_menu_item_with_mnemonic( menu, "Customize...", "BuildMenuCustomize" ); |
| 2374 | create_menu_item_with_mnemonic( menu, "Run recent build", "Build_runRecentExecutedBuild" ); |
| 2375 | |
| 2376 | menu_separator( menu ); |
| 2377 | |
| 2378 | Build_constructMenu( menu ); |
| 2379 | |
| 2380 | g_bsp_menu = menu; |
| 2381 | |
| 2382 | return bsp_menu_item; |
| 2383 | } |
| 2384 | |
| 2385 | ui::MenuItem create_grid_menu(){ |
| 2386 | // Grid menu |
| 2387 | auto grid_menu_item = new_sub_menu_item_with_mnemonic( "_Grid" ); |
| 2388 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( grid_menu_item ) ); |
| 2389 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2390 | menu_tearoff( menu ); |
| 2391 | } |
| 2392 | |
| 2393 | Grid_constructMenu( menu ); |
| 2394 | |
| 2395 | return grid_menu_item; |
| 2396 | } |
| 2397 | |
| 2398 | ui::MenuItem create_misc_menu(){ |
| 2399 | // Misc menu |
| 2400 | auto misc_menu_item = new_sub_menu_item_with_mnemonic( "M_isc" ); |
| 2401 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( misc_menu_item ) ); |
| 2402 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2403 | menu_tearoff( menu ); |
| 2404 | } |
| 2405 | |
| 2406 | #if 0 |
| 2407 | create_menu_item_with_mnemonic( menu, "_Benchmark", makeCallbackF(GlobalCamera_Benchmark) ); |
| 2408 | #endif |
| 2409 | menu.add(create_colours_menu()); |
| 2410 | |
| 2411 | create_menu_item_with_mnemonic( menu, "Find brush...", "FindBrush" ); |
| 2412 | create_menu_item_with_mnemonic( menu, "Map Info...", "MapInfo" ); |
| 2413 | // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394 |
| 2414 | // create_menu_item_with_mnemonic(menu, "_Print XY View", makeCallbackF( WXY_Print )); |
| 2415 | create_menu_item_with_mnemonic( menu, "_Background image...", makeCallbackF(WXY_BackgroundSelect) ); |
| 2416 | create_menu_item_with_mnemonic( menu, "Fullscreen", "Fullscreen" ); |
| 2417 | create_menu_item_with_mnemonic( menu, "Maximize view", "MaximizeView" ); |
| 2418 | return misc_menu_item; |
| 2419 | } |
| 2420 | |
| 2421 | ui::MenuItem create_entity_menu(){ |
| 2422 | // Brush menu |
| 2423 | auto entity_menu_item = new_sub_menu_item_with_mnemonic( "E_ntity" ); |
| 2424 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( entity_menu_item ) ); |
| 2425 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2426 | menu_tearoff( menu ); |
| 2427 | } |
| 2428 | |
| 2429 | Entity_constructMenu( menu ); |
| 2430 | |
| 2431 | return entity_menu_item; |
| 2432 | } |
| 2433 | |
| 2434 | ui::MenuItem create_brush_menu(){ |
| 2435 | // Brush menu |
| 2436 | auto brush_menu_item = new_sub_menu_item_with_mnemonic( "B_rush" ); |
| 2437 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( brush_menu_item ) ); |
| 2438 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2439 | menu_tearoff( menu ); |
| 2440 | } |
| 2441 | |
| 2442 | Brush_constructMenu( menu ); |
| 2443 | |
| 2444 | return brush_menu_item; |
| 2445 | } |
| 2446 | |
| 2447 | ui::MenuItem create_patch_menu(){ |
| 2448 | // Curve menu |
| 2449 | auto patch_menu_item = new_sub_menu_item_with_mnemonic( "_Curve" ); |
| 2450 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( patch_menu_item ) ); |
| 2451 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2452 | menu_tearoff( menu ); |
| 2453 | } |
| 2454 | |
| 2455 | Patch_constructMenu( menu ); |
| 2456 | |
| 2457 | return patch_menu_item; |
| 2458 | } |
| 2459 | |
| 2460 | ui::MenuItem create_help_menu(){ |
| 2461 | // Help menu |
| 2462 | auto help_menu_item = new_sub_menu_item_with_mnemonic( "_Help" ); |
| 2463 | auto menu = ui::Menu::from( gtk_menu_item_get_submenu( help_menu_item ) ); |
| 2464 | if ( g_Layout_enableDetachableMenus.m_value ) { |
| 2465 | menu_tearoff( menu ); |
| 2466 | } |
| 2467 | |
| 2468 | // create_menu_item_with_mnemonic( menu, "Manual", "OpenManual" ); |
| 2469 | |
| 2470 | // this creates all the per-game drop downs for the game pack helps |
| 2471 | // it will take care of hooking the Sys_OpenURL calls etc. |
| 2472 | create_game_help_menu( menu ); |
| 2473 | |
| 2474 | create_menu_item_with_mnemonic( menu, "Bug report", makeCallbackF(OpenBugReportURL) ); |
| 2475 | create_menu_item_with_mnemonic( menu, "Shortcuts", makeCallbackF(DoCommandListDlg) ); |
| 2476 | create_menu_item_with_mnemonic( menu, "_About...", makeCallbackF(DoAbout) ); |
| 2477 | |
| 2478 | return help_menu_item; |
| 2479 | } |
| 2480 | |
| 2481 | ui::MenuBar create_main_menu( MainFrame::EViewStyle style ){ |
| 2482 | auto menu_bar = ui::MenuBar::from( gtk_menu_bar_new() ); |
| 2483 | menu_bar.show(); |
| 2484 | |
| 2485 | menu_bar.add(create_file_menu()); |
| 2486 | menu_bar.add(create_edit_menu()); |
| 2487 | menu_bar.add(create_view_menu(style)); |
| 2488 | menu_bar.add(create_selection_menu()); |
| 2489 | menu_bar.add(create_bsp_menu()); |
| 2490 | menu_bar.add(create_grid_menu()); |
| 2491 | menu_bar.add(create_misc_menu()); |
| 2492 | menu_bar.add(create_entity_menu()); |
| 2493 | menu_bar.add(create_brush_menu()); |
| 2494 | menu_bar.add(create_patch_menu()); |
| 2495 | menu_bar.add(create_plugins_menu()); |
| 2496 | menu_bar.add(create_help_menu()); |
| 2497 | |
| 2498 | return menu_bar; |
| 2499 | } |
| 2500 | |
| 2501 | |
| 2502 | void PatchInspector_registerShortcuts(){ |
| 2503 | command_connect_accelerator( "PatchInspector" ); |
| 2504 | } |
| 2505 | |
| 2506 | void Patch_registerShortcuts(){ |
| 2507 | command_connect_accelerator( "InvertCurveTextureX" ); |
| 2508 | command_connect_accelerator( "InvertCurveTextureY" ); |
| 2509 | command_connect_accelerator( "PatchInsertInsertColumn" ); |
| 2510 | command_connect_accelerator( "PatchInsertInsertRow" ); |
| 2511 | command_connect_accelerator( "PatchDeleteLastColumn" ); |
| 2512 | command_connect_accelerator( "PatchDeleteLastRow" ); |
| 2513 | command_connect_accelerator( "NaturalizePatch" ); |
| 2514 | command_connect_accelerator( "CapCurrentCurve"); |
| 2515 | } |
| 2516 | |
| 2517 | void Manipulators_registerShortcuts(){ |
| 2518 | toggle_add_accelerator( "MouseRotate" ); |
| 2519 | toggle_add_accelerator( "MouseTranslate" ); |
| 2520 | toggle_add_accelerator( "MouseScale" ); |
| 2521 | toggle_add_accelerator( "MouseDrag" ); |
| 2522 | toggle_add_accelerator( "ToggleClipper" ); |
| 2523 | } |
| 2524 | |
| 2525 | void TexdefNudge_registerShortcuts(){ |
| 2526 | command_connect_accelerator( "TexRotateClock" ); |
| 2527 | command_connect_accelerator( "TexRotateCounter" ); |
| 2528 | command_connect_accelerator( "TexScaleUp" ); |
| 2529 | command_connect_accelerator( "TexScaleDown" ); |
| 2530 | command_connect_accelerator( "TexScaleLeft" ); |
| 2531 | command_connect_accelerator( "TexScaleRight" ); |
| 2532 | command_connect_accelerator( "TexShiftUp" ); |
| 2533 | command_connect_accelerator( "TexShiftDown" ); |
| 2534 | command_connect_accelerator( "TexShiftLeft" ); |
| 2535 | command_connect_accelerator( "TexShiftRight" ); |
| 2536 | } |
| 2537 | |
| 2538 | void SelectNudge_registerShortcuts(){ |
| 2539 | //command_connect_accelerator( "MoveSelectionDOWN" ); |
| 2540 | //command_connect_accelerator( "MoveSelectionUP" ); |
| 2541 | //command_connect_accelerator("SelectNudgeLeft"); |
| 2542 | //command_connect_accelerator("SelectNudgeRight"); |
| 2543 | //command_connect_accelerator("SelectNudgeUp"); |
| 2544 | //command_connect_accelerator("SelectNudgeDown"); |
| 2545 | command_connect_accelerator( "UnSelectSelection2" ); |
| 2546 | command_connect_accelerator( "DeleteSelection2" ); |
| 2547 | } |
| 2548 | |
| 2549 | void SnapToGrid_registerShortcuts(){ |
| 2550 | command_connect_accelerator( "SnapToGrid" ); |
| 2551 | } |
| 2552 | |
| 2553 | void SelectByType_registerShortcuts(){ |
| 2554 | command_connect_accelerator( "SelectAllOfType" ); |
| 2555 | } |
| 2556 | |
| 2557 | void SurfaceInspector_registerShortcuts(){ |
| 2558 | command_connect_accelerator( "FitTexture" ); |
| 2559 | } |
| 2560 | |
| 2561 | void TexBro_registerShortcuts(){ |
| 2562 | command_connect_accelerator( "FindReplaceTextures" ); |
| 2563 | command_connect_accelerator( "RefreshShaders" ); |
| 2564 | } |
| 2565 | |
| 2566 | void Misc_registerShortcuts(){ |
| 2567 | //refresh models |
| 2568 | command_connect_accelerator( "RefreshReferences" ); |
| 2569 | command_connect_accelerator( "MouseRotateOrScale" ); |
| 2570 | command_connect_accelerator( "MouseDragOrScale" ); |
| 2571 | } |
| 2572 | |
| 2573 | |
| 2574 | void register_shortcuts(){ |
| 2575 | // PatchInspector_registerShortcuts(); |
| 2576 | //Patch_registerShortcuts(); |
| 2577 | Grid_registerShortcuts(); |
| 2578 | // XYWnd_registerShortcuts(); |
| 2579 | CamWnd_registerShortcuts(); |
| 2580 | Manipulators_registerShortcuts(); |
| 2581 | SurfaceInspector_registerShortcuts(); |
| 2582 | TexdefNudge_registerShortcuts(); |
| 2583 | SelectNudge_registerShortcuts(); |
| 2584 | // SnapToGrid_registerShortcuts(); |
| 2585 | // SelectByType_registerShortcuts(); |
| 2586 | TexBro_registerShortcuts(); |
| 2587 | Misc_registerShortcuts(); |
| 2588 | } |
| 2589 | |
| 2590 | void File_constructToolbar( ui::Toolbar toolbar ){ |
| 2591 | toolbar_append_button( toolbar, "Open an existing map (CTRL + O)", "file_open.png", "OpenMap" ); |
| 2592 | toolbar_append_button( toolbar, "Save the active map (CTRL + S)", "file_save.png", "SaveMap" ); |
| 2593 | } |
| 2594 | |
| 2595 | void UndoRedo_constructToolbar( ui::Toolbar toolbar ){ |
| 2596 | toolbar_append_button( toolbar, "Undo (CTRL + Z)", "undo.png", "Undo" ); |
| 2597 | toolbar_append_button( toolbar, "Redo (CTRL + Y)", "redo.png", "Redo" ); |
| 2598 | } |
| 2599 | |
| 2600 | void RotateFlip_constructToolbar( ui::Toolbar toolbar ){ |
| 2601 | // toolbar_append_button( toolbar, "x-axis Flip", "brush_flipx.png", "MirrorSelectionX" ); |
| 2602 | // toolbar_append_button( toolbar, "x-axis Rotate", "brush_rotatex.png", "RotateSelectionX" ); |
| 2603 | // toolbar_append_button( toolbar, "y-axis Flip", "brush_flipy.png", "MirrorSelectionY" ); |
| 2604 | // toolbar_append_button( toolbar, "y-axis Rotate", "brush_rotatey.png", "RotateSelectionY" ); |
| 2605 | // toolbar_append_button( toolbar, "z-axis Flip", "brush_flipz.png", "MirrorSelectionZ" ); |
| 2606 | // toolbar_append_button( toolbar, "z-axis Rotate", "brush_rotatez.png", "RotateSelectionZ" ); |
| 2607 | toolbar_append_button( toolbar, "Flip Horizontally", "brush_flip_hor.png", "MirrorSelectionHorizontally" ); |
| 2608 | toolbar_append_button( toolbar, "Flip Vertically", "brush_flip_vert.png", "MirrorSelectionVertically" ); |
| 2609 | |
| 2610 | toolbar_append_button( toolbar, "Rotate Clockwise", "brush_rotate_clock.png", "RotateSelectionClockwise" ); |
| 2611 | toolbar_append_button( toolbar, "Rotate Anticlockwise", "brush_rotate_anti.png", "RotateSelectionAnticlockwise" ); |
| 2612 | } |
| 2613 | |
| 2614 | void Select_constructToolbar( ui::Toolbar toolbar ){ |
| 2615 | toolbar_append_button( toolbar, "Select touching", "selection_selecttouching.png", "SelectTouching" ); |
| 2616 | toolbar_append_button( toolbar, "Select inside", "selection_selectinside.png", "SelectInside" ); |
| 2617 | } |
| 2618 | |
| 2619 | void CSG_constructToolbar( ui::Toolbar toolbar ){ |
| 2620 | toolbar_append_button( toolbar, "CSG Subtract (SHIFT + U)", "selection_csgsubtract.png", "CSGSubtract" ); |
| 2621 | toolbar_append_button( toolbar, "CSG Merge (CTRL + U)", "selection_csgmerge.png", "CSGMerge" ); |
| 2622 | toolbar_append_button( toolbar, "Make Room", "selection_makeroom.png", "CSGRoom" ); |
| 2623 | toolbar_append_button( toolbar, "CSG Tool", "ellipsis.png", "CSGTool" ); |
| 2624 | } |
| 2625 | |
| 2626 | void ComponentModes_constructToolbar( ui::Toolbar toolbar ){ |
| 2627 | toolbar_append_toggle_button( toolbar, "Select Vertices (V)", "modify_vertices.png", "DragVertices" ); |
| 2628 | toolbar_append_toggle_button( toolbar, "Select Edges (E)", "modify_edges.png", "DragEdges" ); |
| 2629 | toolbar_append_toggle_button( toolbar, "Select Faces (F)", "modify_faces.png", "DragFaces" ); |
| 2630 | } |
| 2631 | |
| 2632 | void Clipper_constructToolbar( ui::Toolbar toolbar ){ |
| 2633 | |
| 2634 | toolbar_append_toggle_button( toolbar, "Clipper (X)", "view_clipper.png", "ToggleClipper" ); |
| 2635 | } |
| 2636 | |
| 2637 | void XYWnd_constructToolbar( ui::Toolbar toolbar ){ |
| 2638 | toolbar_append_button( toolbar, "Change views (CTRL + TAB)", "view_change.png", "NextView" ); |
| 2639 | } |
| 2640 | |
| 2641 | void Manipulators_constructToolbar( ui::Toolbar toolbar ){ |
| 2642 | toolbar_append_toggle_button( toolbar, "Translate (W)", "select_mousetranslate.png", "MouseTranslate" ); |
| 2643 | toolbar_append_toggle_button( toolbar, "Rotate (R)", "select_mouserotate.png", "MouseRotate" ); |
| 2644 | toolbar_append_toggle_button( toolbar, "Scale (Q)", "select_mousescale.png", "MouseScale" ); |
| 2645 | toolbar_append_toggle_button( toolbar, "Resize (Q)", "select_mouseresize.png", "MouseDrag" ); |
| 2646 | |
| 2647 | Clipper_constructToolbar( toolbar ); |
| 2648 | } |
| 2649 | |
| 2650 | ui::Toolbar create_main_toolbar( MainFrame::EViewStyle style ){ |
| 2651 | auto toolbar = ui::Toolbar::from( gtk_toolbar_new() ); |
| 2652 | gtk_orientable_set_orientation( GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL ); |
| 2653 | gtk_toolbar_set_style( toolbar, GTK_TOOLBAR_ICONS ); |
| 2654 | // gtk_toolbar_set_show_arrow( toolbar, TRUE ); |
| 2655 | //gtk_orientable_set_orientation( GTK_ORIENTABLE( toolbar ), GTK_ORIENTATION_HORIZONTAL ); |
| 2656 | //toolbar_append_space( toolbar ); |
| 2657 | toolbar.show(); |
| 2658 | |
| 2659 | auto space = [&]() { |
| 2660 | auto btn = ui::ToolItem::from(gtk_separator_tool_item_new()); |
| 2661 | btn.show(); |
| 2662 | toolbar.add(btn); |
| 2663 | }; |
| 2664 | |
| 2665 | File_constructToolbar( toolbar ); |
| 2666 | |
| 2667 | space(); |
| 2668 | |
| 2669 | UndoRedo_constructToolbar( toolbar ); |
| 2670 | |
| 2671 | space(); |
| 2672 | |
| 2673 | RotateFlip_constructToolbar( toolbar ); |
| 2674 | |
| 2675 | space(); |
| 2676 | |
| 2677 | Select_constructToolbar( toolbar ); |
| 2678 | |
| 2679 | space(); |
| 2680 | |
| 2681 | CSG_constructToolbar( toolbar ); |
| 2682 | |
| 2683 | space(); |
| 2684 | |
| 2685 | ComponentModes_constructToolbar( toolbar ); |
| 2686 | |
| 2687 | if ( style != MainFrame::eSplit ) { |
| 2688 | space(); |
| 2689 | |
| 2690 | XYWnd_constructToolbar( toolbar ); |
| 2691 | } |
| 2692 | |
| 2693 | space(); |
| 2694 | |
| 2695 | CamWnd_constructToolbar( toolbar ); |
| 2696 | |
| 2697 | space(); |
| 2698 | |
| 2699 | Manipulators_constructToolbar( toolbar ); |
| 2700 | |
| 2701 | if ( g_Layout_enablePatchToolbar.m_value ) { |
| 2702 | space(); |
| 2703 | |
| 2704 | Patch_constructToolbar( toolbar ); |
| 2705 | } |
| 2706 | |
| 2707 | space(); |
| 2708 | |
| 2709 | toolbar_append_toggle_button( toolbar, "Texture Lock (SHIFT + T)", "texture_lock.png", "TogTexLock" ); |
| 2710 | |
| 2711 | space(); |
| 2712 | |
| 2713 | toolbar_append_button( toolbar, "Entities (N)", "entities.png", "ToggleEntityInspector" ); |
| 2714 | // disable the console and texture button in the regular layouts |
| 2715 | if ( style != MainFrame::eRegular && style != MainFrame::eRegularLeft ) { |
| 2716 | toolbar_append_button( toolbar, "Console (O)", "console.png", "ToggleConsole" ); |
| 2717 | toolbar_append_button( toolbar, "Texture Browser (T)", "texture_browser.png", "ToggleTextures" ); |
| 2718 | } |
| 2719 | // TODO: call light inspector |
| 2720 | //GtkButton* g_view_lightinspector_button = toolbar_append_button(toolbar, "Light Inspector", "lightinspector.png", "ToggleLightInspector"); |
| 2721 | |
| 2722 | space(); |
| 2723 | |
| 2724 | toolbar_append_button( toolbar, "Refresh Models", "refresh_models.png", "RefreshReferences" ); |
| 2725 | |
| 2726 | return toolbar; |
| 2727 | } |
| 2728 | |
| 2729 | ui::Widget create_main_statusbar( ui::Widget pStatusLabel[c_count_status] ){ |
| 2730 | auto table = ui::Table( 1, c_count_status, FALSE ); |
| 2731 | table.show(); |
| 2732 | |
| 2733 | { |
| 2734 | auto label = ui::Label( "Label" ); |
| 2735 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 ); |
| 2736 | gtk_misc_set_padding( GTK_MISC( label ), 4, 2 ); |
| 2737 | label.show(); |
| 2738 | table.attach(label, {0, 1, 0, 1}); |
| 2739 | pStatusLabel[c_command_status] = ui::Widget(label ); |
| 2740 | } |
| 2741 | |
| 2742 | for (unsigned int i = 1; (int) i < c_count_status; ++i) |
| 2743 | { |
| 2744 | auto frame = ui::Frame(); |
| 2745 | frame.show(); |
| 2746 | table.attach(frame, {i, i + 1, 0, 1}); |
| 2747 | gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN ); |
| 2748 | |
| 2749 | auto label = ui::Label( "Label" ); |
| 2750 | if( i == c_texture_status ) |
| 2751 | gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_START ); |
| 2752 | else |
| 2753 | gtk_label_set_ellipsize( label, PANGO_ELLIPSIZE_END ); |
| 2754 | |
| 2755 | gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 ); |
| 2756 | gtk_misc_set_padding( GTK_MISC( label ), 4, 2 ); |
| 2757 | label.show(); |
| 2758 | frame.add(label); |
| 2759 | pStatusLabel[i] = ui::Widget(label ); |
| 2760 | } |
| 2761 | |
| 2762 | return ui::Widget(table ); |
| 2763 | } |
| 2764 | |
| 2765 | #if 0 |
| 2766 | |
| 2767 | |
| 2768 | WidgetFocusPrinter g_mainframeWidgetFocusPrinter( "mainframe" ); |
| 2769 | |
| 2770 | class WindowFocusPrinter |
| 2771 | { |
| 2772 | const char* m_name; |
| 2773 | |
| 2774 | static gboolean frame_event( ui::Widget widget, GdkEvent* event, WindowFocusPrinter* self ){ |
| 2775 | globalOutputStream() << self->m_name << " frame_event\n"; |
| 2776 | return FALSE; |
| 2777 | } |
| 2778 | static gboolean keys_changed( ui::Widget widget, WindowFocusPrinter* self ){ |
| 2779 | globalOutputStream() << self->m_name << " keys_changed\n"; |
| 2780 | return FALSE; |
| 2781 | } |
| 2782 | static gboolean notify( ui::Window window, gpointer dummy, WindowFocusPrinter* self ){ |
| 2783 | if ( gtk_window_is_active( window ) ) { |
| 2784 | globalOutputStream() << self->m_name << " takes toplevel focus\n"; |
| 2785 | } |
| 2786 | else |
| 2787 | { |
| 2788 | globalOutputStream() << self->m_name << " loses toplevel focus\n"; |
| 2789 | } |
| 2790 | return FALSE; |
| 2791 | } |
| 2792 | public: |
| 2793 | WindowFocusPrinter( const char* name ) : m_name( name ){ |
| 2794 | } |
| 2795 | void connect( ui::Window toplevel_window ){ |
| 2796 | toplevel_window.connect( "notify::has_toplevel_focus", G_CALLBACK( notify ), this ); |
| 2797 | toplevel_window.connect( "notify::is_active", G_CALLBACK( notify ), this ); |
| 2798 | toplevel_window.connect( "keys_changed", G_CALLBACK( keys_changed ), this ); |
| 2799 | toplevel_window.connect( "frame_event", G_CALLBACK( frame_event ), this ); |
| 2800 | } |
| 2801 | }; |
| 2802 | |
| 2803 | WindowFocusPrinter g_mainframeFocusPrinter( "mainframe" ); |
| 2804 | |
| 2805 | #endif |
| 2806 | |
| 2807 | class MainWindowActive |
| 2808 | { |
| 2809 | static gboolean notify( ui::Window window, gpointer dummy, MainWindowActive* self ){ |
| 2810 | if ( g_wait.m_window && gtk_window_is_active( window ) && !g_wait.m_window.visible() ) { |
| 2811 | g_wait.m_window.show(); |
| 2812 | } |
| 2813 | |
| 2814 | return FALSE; |
| 2815 | } |
| 2816 | |
| 2817 | public: |
| 2818 | void connect( ui::Window toplevel_window ){ |
| 2819 | toplevel_window.connect( "notify::is-active", G_CALLBACK( notify ), this ); |
| 2820 | } |
| 2821 | }; |
| 2822 | |
| 2823 | MainWindowActive g_MainWindowActive; |
| 2824 | |
| 2825 | SignalHandlerId XYWindowDestroyed_connect( const SignalHandler& handler ){ |
| 2826 | return g_pParentWnd->GetXYWnd()->onDestroyed.connectFirst( handler ); |
| 2827 | } |
| 2828 | |
| 2829 | void XYWindowDestroyed_disconnect( SignalHandlerId id ){ |
| 2830 | g_pParentWnd->GetXYWnd()->onDestroyed.disconnect( id ); |
| 2831 | } |
| 2832 | |
| 2833 | MouseEventHandlerId XYWindowMouseDown_connect( const MouseEventHandler& handler ){ |
| 2834 | return g_pParentWnd->GetXYWnd()->onMouseDown.connectFirst( handler ); |
| 2835 | } |
| 2836 | |
| 2837 | void XYWindowMouseDown_disconnect( MouseEventHandlerId id ){ |
| 2838 | g_pParentWnd->GetXYWnd()->onMouseDown.disconnect( id ); |
| 2839 | } |
| 2840 | |
| 2841 | // ============================================================================= |
| 2842 | // MainFrame class |
| 2843 | |
| 2844 | MainFrame* g_pParentWnd = 0; |
| 2845 | |
| 2846 | ui::Window MainFrame_getWindow() |
| 2847 | { |
| 2848 | return g_pParentWnd ? g_pParentWnd->m_window : ui::Window{ui::null}; |
| 2849 | } |
| 2850 | |
| 2851 | std::vector<ui::Widget> g_floating_windows; |
| 2852 | |
| 2853 | MainFrame::MainFrame() : m_idleRedrawStatusText( RedrawStatusTextCaller( *this ) ){ |
| 2854 | m_pXYWnd = 0; |
| 2855 | m_pCamWnd = 0; |
| 2856 | m_pZWnd = 0; |
| 2857 | m_pYZWnd = 0; |
| 2858 | m_pXZWnd = 0; |
| 2859 | m_pActiveXY = 0; |
| 2860 | |
| 2861 | for (auto &n : m_pStatusLabel) { |
| 2862 | n = NULL; |
| 2863 | } |
| 2864 | |
| 2865 | m_bSleeping = false; |
| 2866 | |
| 2867 | Create(); |
| 2868 | } |
| 2869 | |
| 2870 | MainFrame::~MainFrame(){ |
| 2871 | SaveWindowInfo(); |
| 2872 | |
| 2873 | m_window.hide(); |
| 2874 | |
| 2875 | Shutdown(); |
| 2876 | |
| 2877 | for ( std::vector<ui::Widget>::iterator i = g_floating_windows.begin(); i != g_floating_windows.end(); ++i ) |
| 2878 | { |
| 2879 | #ifndef WORKAROUND_MACOS_GTK2_DESTROY |
| 2880 | i->destroy(); |
| 2881 | #endif |
| 2882 | } |
| 2883 | |
| 2884 | #ifndef WORKAROUND_MACOS_GTK2_DESTROY |
| 2885 | m_window.destroy(); |
| 2886 | #endif |
| 2887 | } |
| 2888 | |
| 2889 | void MainFrame::SetActiveXY( XYWnd* p ){ |
| 2890 | if ( m_pActiveXY ) { |
| 2891 | m_pActiveXY->SetActive( false ); |
| 2892 | } |
| 2893 | |
| 2894 | m_pActiveXY = p; |
| 2895 | |
| 2896 | if ( m_pActiveXY ) { |
| 2897 | m_pActiveXY->SetActive( true ); |
| 2898 | } |
| 2899 | |
| 2900 | } |
| 2901 | |
| 2902 | void MainFrame::ReleaseContexts(){ |
| 2903 | #if 0 |
| 2904 | if ( m_pXYWnd ) { |
| 2905 | m_pXYWnd->DestroyContext(); |
| 2906 | } |
| 2907 | if ( m_pYZWnd ) { |
| 2908 | m_pYZWnd->DestroyContext(); |
| 2909 | } |
| 2910 | if ( m_pXZWnd ) { |
| 2911 | m_pXZWnd->DestroyContext(); |
| 2912 | } |
| 2913 | if ( m_pCamWnd ) { |
| 2914 | m_pCamWnd->DestroyContext(); |
| 2915 | } |
| 2916 | if ( m_pTexWnd ) { |
| 2917 | m_pTexWnd->DestroyContext(); |
| 2918 | } |
| 2919 | if ( m_pZWnd ) { |
| 2920 | m_pZWnd->DestroyContext(); |
| 2921 | } |
| 2922 | #endif |
| 2923 | } |
| 2924 | |
| 2925 | void MainFrame::CreateContexts(){ |
| 2926 | #if 0 |
| 2927 | if ( m_pCamWnd ) { |
| 2928 | m_pCamWnd->CreateContext(); |
| 2929 | } |
| 2930 | if ( m_pXYWnd ) { |
| 2931 | m_pXYWnd->CreateContext(); |
| 2932 | } |
| 2933 | if ( m_pYZWnd ) { |
| 2934 | m_pYZWnd->CreateContext(); |
| 2935 | } |
| 2936 | if ( m_pXZWnd ) { |
| 2937 | m_pXZWnd->CreateContext(); |
| 2938 | } |
| 2939 | if ( m_pTexWnd ) { |
| 2940 | m_pTexWnd->CreateContext(); |
| 2941 | } |
| 2942 | if ( m_pZWnd ) { |
| 2943 | m_pZWnd->CreateContext(); |
| 2944 | } |
| 2945 | #endif |
| 2946 | } |
| 2947 | |
| 2948 | #if GDEF_DEBUG |
| 2949 | //#define DBG_SLEEP |
| 2950 | #endif |
| 2951 | |
| 2952 | void MainFrame::OnSleep(){ |
| 2953 | #if 0 |
| 2954 | m_bSleeping ^= 1; |
| 2955 | if ( m_bSleeping ) { |
| 2956 | // useful when trying to debug crashes in the sleep code |
| 2957 | globalOutputStream() << "Going into sleep mode..\n"; |
| 2958 | |
| 2959 | globalOutputStream() << "Dispatching sleep msg..."; |
| 2960 | DispatchRadiantMsg( RADIANT_SLEEP ); |
| 2961 | globalOutputStream() << "Done.\n"; |
| 2962 | |
| 2963 | gtk_window_iconify( m_window ); |
| 2964 | GlobalSelectionSystem().setSelectedAll( false ); |
| 2965 | |
| 2966 | GlobalShaderCache().unrealise(); |
| 2967 | Shaders_Free(); |
| 2968 | GlobalOpenGL_debugAssertNoErrors(); |
| 2969 | ScreenUpdates_Disable(); |
| 2970 | |
| 2971 | // release contexts |
| 2972 | globalOutputStream() << "Releasing contexts..."; |
| 2973 | ReleaseContexts(); |
| 2974 | globalOutputStream() << "Done.\n"; |
| 2975 | } |
| 2976 | else |
| 2977 | { |
| 2978 | globalOutputStream() << "Waking up\n"; |
| 2979 | |
| 2980 | gtk_window_deiconify( m_window ); |
| 2981 | |
| 2982 | // create contexts |
| 2983 | globalOutputStream() << "Creating contexts..."; |
| 2984 | CreateContexts(); |
| 2985 | globalOutputStream() << "Done.\n"; |
| 2986 | |
| 2987 | globalOutputStream() << "Making current on camera..."; |
| 2988 | m_pCamWnd->MakeCurrent(); |
| 2989 | globalOutputStream() << "Done.\n"; |
| 2990 | |
| 2991 | globalOutputStream() << "Reloading shaders..."; |
| 2992 | Shaders_Load(); |
| 2993 | GlobalShaderCache().realise(); |
| 2994 | globalOutputStream() << "Done.\n"; |
| 2995 | |
| 2996 | ScreenUpdates_Enable(); |
| 2997 | |
| 2998 | globalOutputStream() << "Dispatching wake msg..."; |
| 2999 | DispatchRadiantMsg( RADIANT_WAKEUP ); |
| 3000 | globalOutputStream() << "Done\n"; |
| 3001 | } |
| 3002 | #endif |
| 3003 | } |
| 3004 | |
| 3005 | |
| 3006 | ui::Window create_splash(){ |
| 3007 | auto window = ui::Window( ui::window_type::TOP ); |
| 3008 | gtk_window_set_decorated(window, false); |
| 3009 | gtk_window_set_resizable(window, false); |
| 3010 | gtk_window_set_modal(window, true); |
| 3011 | gtk_window_set_default_size( window, -1, -1 ); |
| 3012 | gtk_window_set_position( window, GTK_WIN_POS_CENTER ); |
| 3013 | gtk_container_set_border_width(window, 0); |
| 3014 | |
| 3015 | auto image = new_local_image( "splash.png" ); |
| 3016 | image.show(); |
| 3017 | window.add(image); |
| 3018 | |
| 3019 | #if GTK_TARGET == 2 |
| 3020 | if( gtk_image_get_storage_type( image ) == GTK_IMAGE_PIXBUF ){ |
| 3021 | GdkBitmap* mask; |
| 3022 | GdkPixbuf* pix = gtk_image_get_pixbuf( image ); |
| 3023 | gdk_pixbuf_render_pixmap_and_mask( pix, NULL, &mask, 255 ); |
| 3024 | gtk_widget_shape_combine_mask ( GTK_WIDGET( window ), mask, 0, 0 ); |
| 3025 | } |
| 3026 | #endif |
| 3027 | |
| 3028 | window.dimensions(-1, -1); |
| 3029 | window.show(); |
| 3030 | |
| 3031 | return window; |
| 3032 | } |
| 3033 | |
| 3034 | static ui::Window splash_screen{ui::null}; |
| 3035 | |
| 3036 | void show_splash(){ |
| 3037 | splash_screen = create_splash(); |
| 3038 | |
| 3039 | ui::process(); |
| 3040 | } |
| 3041 | |
| 3042 | void hide_splash(){ |
| 3043 | splash_screen.destroy(); |
| 3044 | } |
| 3045 | |
| 3046 | WindowPositionTracker g_posCamWnd; |
| 3047 | WindowPositionTracker g_posXYWnd; |
| 3048 | WindowPositionTracker g_posXZWnd; |
| 3049 | WindowPositionTracker g_posYZWnd; |
| 3050 | |
| 3051 | static gint mainframe_delete( ui::Widget widget, GdkEvent *event, gpointer data ){ |
| 3052 | if ( ConfirmModified( "Exit " RADIANT_NAME ) ) { |
| 3053 | gtk_main_quit(); |
| 3054 | } |
| 3055 | |
| 3056 | return TRUE; |
| 3057 | } |
| 3058 | |
| 3059 | PanedState g_single_hpaned = { 0.75f, -1, }; |
| 3060 | PanedState g_single_vpaned = { 0.75f, -1, }; |
| 3061 | |
| 3062 | void MainFrame::Create(){ |
| 3063 | ui::Window window = ui::Window( ui::window_type::TOP ); |
| 3064 | |
| 3065 | GlobalWindowObservers_connectTopLevel( window ); |
| 3066 | |
| 3067 | gtk_window_set_transient_for( splash_screen, window ); |
| 3068 | |
| 3069 | #if !GDEF_OS_WINDOWS |
| 3070 | { |
| 3071 | GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" ); |
| 3072 | if ( pixbuf != 0 ) { |
| 3073 | gtk_window_set_icon( window, pixbuf ); |
| 3074 | g_object_unref( pixbuf ); |
| 3075 | } |
| 3076 | } |
| 3077 | #endif |
| 3078 | |
| 3079 | gtk_widget_add_events( window , GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK ); |
| 3080 | window.connect( "delete_event", G_CALLBACK( mainframe_delete ), this ); |
| 3081 | |
| 3082 | m_position_tracker.connect( window ); |
| 3083 | |
| 3084 | #if 0 |
| 3085 | g_mainframeWidgetFocusPrinter.connect( window ); |
| 3086 | g_mainframeFocusPrinter.connect( window ); |
| 3087 | #endif |
| 3088 | |
| 3089 | g_MainWindowActive.connect( window ); |
| 3090 | |
| 3091 | GetPlugInMgr().Init( window ); |
| 3092 | |
| 3093 | auto vbox = ui::VBox( FALSE, 0 ); |
| 3094 | window.add(vbox); |
| 3095 | vbox.show(); |
| 3096 | gtk_container_set_focus_chain( GTK_CONTAINER( vbox ), NULL ); |
| 3097 | |
| 3098 | global_accel_connect_window( window ); |
| 3099 | |
| 3100 | m_nCurrentStyle = (EViewStyle)g_Layout_viewStyle.m_value; |
| 3101 | |
| 3102 | register_shortcuts(); |
| 3103 | |
| 3104 | auto main_menu = create_main_menu( CurrentStyle() ); |
| 3105 | vbox.pack_start( main_menu, FALSE, FALSE, 0 ); |
| 3106 | |
| 3107 | if( g_Layout_enableMainToolbar.m_value ){ |
| 3108 | GtkToolbar* main_toolbar = create_main_toolbar( CurrentStyle() ); |
| 3109 | gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( main_toolbar ), FALSE, FALSE, 0 ); |
| 3110 | } |
| 3111 | |
| 3112 | if ( g_Layout_enablePluginToolbar.m_value || g_Layout_enableFilterToolbar.m_value ){ |
| 3113 | auto PFbox = ui::HBox( FALSE, 3 ); |
| 3114 | vbox.pack_start( PFbox, FALSE, FALSE, 0 ); |
| 3115 | PFbox.show(); |
| 3116 | if ( g_Layout_enablePluginToolbar.m_value ){ |
| 3117 | auto plugin_toolbar = create_plugin_toolbar(); |
| 3118 | if ( g_Layout_enableFilterToolbar.m_value ){ |
| 3119 | PFbox.pack_start( plugin_toolbar, FALSE, FALSE, 0 ); |
| 3120 | // Force the toolbar to display all childrens |
| 3121 | // without collapsing them to a menu. |
| 3122 | gtk_toolbar_set_show_arrow( plugin_toolbar, FALSE ); |
| 3123 | } |
| 3124 | else{ |
| 3125 | PFbox.pack_start( plugin_toolbar, TRUE, TRUE, 0 ); |
| 3126 | } |
| 3127 | } |
| 3128 | if ( g_Layout_enableFilterToolbar.m_value ){ |
| 3129 | ui::Toolbar filter_toolbar = create_filter_toolbar(); |
| 3130 | PFbox.pack_start( filter_toolbar, TRUE, TRUE, 0 ); |
| 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | /*GtkToolbar* plugin_toolbar = create_plugin_toolbar(); |
| 3135 | if ( !g_Layout_enablePluginToolbar.m_value ) { |
| 3136 | gtk_widget_hide( GTK_WIDGET( plugin_toolbar ) ); |
| 3137 | }*/ |
| 3138 | |
| 3139 | ui::Widget main_statusbar = create_main_statusbar(reinterpret_cast<ui::Widget *>(m_pStatusLabel)); |
| 3140 | vbox.pack_end(main_statusbar, FALSE, TRUE, 2); |
| 3141 | |
| 3142 | GroupDialog_constructWindow( window ); |
| 3143 | |
| 3144 | /* want to realize it immediately; otherwise gtk paned splits positions wont be set correctly for floating group dlg */ |
| 3145 | gtk_widget_realize ( GTK_WIDGET( GroupDialog_getWindow() ) ); |
| 3146 | |
| 3147 | g_page_entity = GroupDialog_addPage( "Entities", EntityInspector_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Entities" ) ); |
| 3148 | |
| 3149 | GroupDialog_addPage( "Models", ModelBrowser_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Models" ) ); |
| 3150 | |
| 3151 | if ( FloatingGroupDialog() ) { |
| 3152 | g_page_console = GroupDialog_addPage( "Console", Console_constructWindow( GroupDialog_getWindow() ), RawStringExportCaller( "Console" ) ); |
| 3153 | } |
| 3154 | |
| 3155 | #if GDEF_OS_WINDOWS |
| 3156 | if ( g_multimon_globals.m_bStartOnPrimMon ) { |
| 3157 | PositionWindowOnPrimaryScreen( g_layout_globals.m_position ); |
| 3158 | } |
| 3159 | #endif |
| 3160 | window_set_position( window, g_layout_globals.m_position ); |
| 3161 | |
| 3162 | m_window = window; |
| 3163 | |
| 3164 | window.show(); |
| 3165 | |
| 3166 | if ( CurrentStyle() == eRegular || CurrentStyle() == eRegularLeft ) |
| 3167 | { |
| 3168 | { |
| 3169 | ui::Widget hsplit = ui::HPaned(ui::New); |
| 3170 | m_hSplit = hsplit; |
| 3171 | |
| 3172 | vbox.pack_start( hsplit, TRUE, TRUE, 0 ); |
| 3173 | hsplit.show(); |
| 3174 | |
| 3175 | { |
| 3176 | ui::Widget vsplit = ui::VPaned(ui::New); |
| 3177 | vsplit.show(); |
| 3178 | m_vSplit = vsplit; |
| 3179 | |
| 3180 | ui::Widget vsplit2 = ui::VPaned(ui::New); |
| 3181 | vsplit2.show(); |
| 3182 | m_vSplit2 = vsplit2; |
| 3183 | |
| 3184 | if ( CurrentStyle() == eRegular ){ |
| 3185 | gtk_paned_pack1( GTK_PANED( hsplit ), vsplit, TRUE, TRUE ); |
| 3186 | gtk_paned_pack2( GTK_PANED( hsplit ), vsplit2, TRUE, TRUE ); |
| 3187 | } |
| 3188 | else{ |
| 3189 | gtk_paned_pack2( GTK_PANED( hsplit ), vsplit, TRUE, TRUE ); |
| 3190 | gtk_paned_pack1( GTK_PANED( hsplit ), vsplit2, TRUE, TRUE ); |
| 3191 | } |
| 3192 | |
| 3193 | // console |
| 3194 | ui::Widget console_window = Console_constructWindow( window ); |
| 3195 | gtk_paned_pack2( GTK_PANED( vsplit ), console_window, TRUE, TRUE ); |
| 3196 | |
| 3197 | // xy |
| 3198 | m_pXYWnd = new XYWnd(); |
| 3199 | m_pXYWnd->SetViewType( XY ); |
| 3200 | ui::Widget xy_window = ui::Widget(create_framed_widget( m_pXYWnd->GetWidget( ) )); |
| 3201 | gtk_paned_pack1( GTK_PANED( vsplit ), xy_window, TRUE, TRUE ); |
| 3202 | |
| 3203 | { |
| 3204 | // camera |
| 3205 | m_pCamWnd = NewCamWnd(); |
| 3206 | GlobalCamera_setCamWnd( *m_pCamWnd ); |
| 3207 | CamWnd_setParent( *m_pCamWnd, window ); |
| 3208 | auto camera_window = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) ); |
| 3209 | |
| 3210 | gtk_paned_pack1( GTK_PANED( vsplit2 ), GTK_WIDGET( camera_window ) , TRUE, TRUE); |
| 3211 | |
| 3212 | // textures |
| 3213 | auto texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) ); |
| 3214 | |
| 3215 | gtk_paned_pack2( GTK_PANED( vsplit2 ), GTK_WIDGET( texture_window ), TRUE, TRUE ); |
| 3216 | } |
| 3217 | } |
| 3218 | } |
| 3219 | } |
| 3220 | else if ( CurrentStyle() == eFloating ) |
| 3221 | { |
| 3222 | { |
| 3223 | ui::Window window = ui::Window(create_persistent_floating_window( "Camera", m_window )); |
| 3224 | global_accel_connect_window( window ); |
| 3225 | g_posCamWnd.connect( window ); |
| 3226 | |
| 3227 | window.show(); |
| 3228 | |
| 3229 | m_pCamWnd = NewCamWnd(); |
| 3230 | GlobalCamera_setCamWnd( *m_pCamWnd ); |
| 3231 | |
| 3232 | { |
| 3233 | auto frame = create_framed_widget( CamWnd_getWidget( *m_pCamWnd ) ); |
| 3234 | window.add(frame); |
| 3235 | } |
| 3236 | CamWnd_setParent( *m_pCamWnd, window ); |
| 3237 | |
| 3238 | WORKAROUND_GOBJECT_SET_GLWIDGET( window, CamWnd_getWidget( *m_pCamWnd ) ); |
| 3239 | |
| 3240 | g_floating_windows.push_back( window ); |
| 3241 | } |
| 3242 | |
| 3243 | { |
| 3244 | ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XY ), m_window )); |
| 3245 | global_accel_connect_window( window ); |
| 3246 | g_posXYWnd.connect( window ); |
| 3247 | |
| 3248 | m_pXYWnd = new XYWnd(); |
| 3249 | m_pXYWnd->m_parent = window; |
| 3250 | m_pXYWnd->SetViewType( XY ); |
| 3251 | |
| 3252 | |
| 3253 | { |
| 3254 | auto frame = create_framed_widget( m_pXYWnd->GetWidget() ); |
| 3255 | window.add(frame); |
| 3256 | } |
| 3257 | XY_Top_Shown_Construct( window ); |
| 3258 | |
| 3259 | WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXYWnd->GetWidget() ); |
| 3260 | |
| 3261 | g_floating_windows.push_back( window ); |
| 3262 | } |
| 3263 | |
| 3264 | { |
| 3265 | ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( XZ ), m_window )); |
| 3266 | global_accel_connect_window( window ); |
| 3267 | g_posXZWnd.connect( window ); |
| 3268 | |
| 3269 | m_pXZWnd = new XYWnd(); |
| 3270 | m_pXZWnd->m_parent = window; |
| 3271 | m_pXZWnd->SetViewType( XZ ); |
| 3272 | |
| 3273 | { |
| 3274 | auto frame = create_framed_widget( m_pXZWnd->GetWidget() ); |
| 3275 | window.add(frame); |
| 3276 | } |
| 3277 | |
| 3278 | XZ_Front_Shown_Construct( window ); |
| 3279 | |
| 3280 | WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXZWnd->GetWidget() ); |
| 3281 | |
| 3282 | g_floating_windows.push_back( window ); |
| 3283 | } |
| 3284 | |
| 3285 | { |
| 3286 | ui::Window window = ui::Window(create_persistent_floating_window( ViewType_getTitle( YZ ), m_window )); |
| 3287 | global_accel_connect_window( window ); |
| 3288 | g_posYZWnd.connect( window ); |
| 3289 | |
| 3290 | m_pYZWnd = new XYWnd(); |
| 3291 | m_pYZWnd->m_parent = window; |
| 3292 | m_pYZWnd->SetViewType( YZ ); |
| 3293 | |
| 3294 | { |
| 3295 | auto frame = create_framed_widget( m_pYZWnd->GetWidget() ); |
| 3296 | window.add(frame); |
| 3297 | } |
| 3298 | |
| 3299 | YZ_Side_Shown_Construct( window ); |
| 3300 | |
| 3301 | WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pYZWnd->GetWidget() ); |
| 3302 | |
| 3303 | g_floating_windows.push_back( window ); |
| 3304 | } |
| 3305 | |
| 3306 | { |
| 3307 | auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) ); |
| 3308 | g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() ); |
| 3309 | WORKAROUND_GOBJECT_SET_GLWIDGET( GroupDialog_getWindow(), TextureBrowser_getGLWidget() ); |
| 3310 | } |
| 3311 | |
| 3312 | // FIXME: find a way to do it with newer syntax |
| 3313 | // m_vSplit = 0; |
| 3314 | // m_hSplit = 0; |
| 3315 | // m_vSplit2 = 0; |
| 3316 | |
| 3317 | GroupDialog_show(); |
| 3318 | } |
| 3319 | else if ( CurrentStyle() == eSplit ) |
| 3320 | { |
| 3321 | m_pCamWnd = NewCamWnd(); |
| 3322 | GlobalCamera_setCamWnd( *m_pCamWnd ); |
| 3323 | CamWnd_setParent( *m_pCamWnd, window ); |
| 3324 | |
| 3325 | ui::Widget camera = CamWnd_getWidget( *m_pCamWnd ); |
| 3326 | |
| 3327 | m_pYZWnd = new XYWnd(); |
| 3328 | m_pYZWnd->SetViewType( YZ ); |
| 3329 | |
| 3330 | ui::Widget yz = m_pYZWnd->GetWidget(); |
| 3331 | |
| 3332 | m_pXYWnd = new XYWnd(); |
| 3333 | m_pXYWnd->SetViewType( XY ); |
| 3334 | |
| 3335 | ui::Widget xy = m_pXYWnd->GetWidget(); |
| 3336 | |
| 3337 | m_pXZWnd = new XYWnd(); |
| 3338 | m_pXZWnd->SetViewType( XZ ); |
| 3339 | |
| 3340 | ui::Widget xz = m_pXZWnd->GetWidget(); |
| 3341 | |
| 3342 | m_hSplit = create_split_views( camera, xy, yz, xz, m_vSplit, m_vSplit2 ); |
| 3343 | vbox.pack_start( m_hSplit, TRUE, TRUE, 0 ); |
| 3344 | |
| 3345 | { |
| 3346 | auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) ); |
| 3347 | g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() ); |
| 3348 | |
| 3349 | WORKAROUND_GOBJECT_SET_GLWIDGET( window, TextureBrowser_getGLWidget() ); |
| 3350 | } |
| 3351 | } |
| 3352 | else // single window |
| 3353 | { |
| 3354 | m_pCamWnd = NewCamWnd(); |
| 3355 | GlobalCamera_setCamWnd( *m_pCamWnd ); |
| 3356 | CamWnd_setParent( *m_pCamWnd, window ); |
| 3357 | |
| 3358 | ui::Widget camera = CamWnd_getWidget( *m_pCamWnd ); |
| 3359 | |
| 3360 | m_pYZWnd = new XYWnd(); |
| 3361 | m_pYZWnd->SetViewType( YZ ); |
| 3362 | |
| 3363 | ui::Widget yz = m_pYZWnd->GetWidget(); |
| 3364 | |
| 3365 | m_pXYWnd = new XYWnd(); |
| 3366 | m_pXYWnd->SetViewType( XY ); |
| 3367 | |
| 3368 | ui::Widget xy = m_pXYWnd->GetWidget(); |
| 3369 | |
| 3370 | m_pXZWnd = new XYWnd(); |
| 3371 | m_pXZWnd->SetViewType( XZ ); |
| 3372 | |
| 3373 | ui::Widget xz = m_pXZWnd->GetWidget(); |
| 3374 | |
| 3375 | ui::Widget hsplit = ui::HPaned(ui::New); |
| 3376 | vbox.pack_start( hsplit, TRUE, TRUE, 0 ); |
| 3377 | hsplit.show(); |
| 3378 | |
| 3379 | /* Before merging NetRadiantCustom: |
| 3380 | ui::Widget split = create_split_views( camera, xy, yz, xz ); */ |
| 3381 | m_hSplit = create_split_views( camera, xy, yz, xz, m_vSplit, m_vSplit2 ); |
| 3382 | |
| 3383 | ui::Widget vsplit = ui::VPaned(ui::New); |
| 3384 | vsplit.show(); |
| 3385 | |
| 3386 | // textures |
| 3387 | ui::Widget texture_window = create_framed_widget( TextureBrowser_constructWindow( window ) ); |
| 3388 | |
| 3389 | // console |
| 3390 | ui::Widget console_window = create_framed_widget( Console_constructWindow( window ) ); |
| 3391 | |
| 3392 | /* Before merging NetRadiantCustom: |
| 3393 | gtk_paned_add1( GTK_PANED( hsplit ), m_hSplit ); |
| 3394 | gtk_paned_add2( GTK_PANED( hsplit ), vsplit ); |
| 3395 | |
| 3396 | gtk_paned_add1( GTK_PANED( vsplit ), texture_window ); |
| 3397 | gtk_paned_add2( GTK_PANED( vsplit ), console_window ); |
| 3398 | */ |
| 3399 | |
| 3400 | gtk_paned_pack1( GTK_PANED( hsplit ), m_hSplit, TRUE, TRUE ); |
| 3401 | gtk_paned_pack2( GTK_PANED( hsplit ), vsplit, TRUE, TRUE); |
| 3402 | |
| 3403 | gtk_paned_pack1( GTK_PANED( vsplit ), texture_window, TRUE, TRUE ); |
| 3404 | gtk_paned_pack2( GTK_PANED( vsplit ), console_window, TRUE, TRUE ); |
| 3405 | |
| 3406 | hsplit.connect( "size_allocate", G_CALLBACK( hpaned_allocate ), &g_single_hpaned ); |
| 3407 | hsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_single_hpaned ); |
| 3408 | |
| 3409 | vsplit.connect( "size_allocate", G_CALLBACK( vpaned_allocate ), &g_single_vpaned ); |
| 3410 | vsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_single_vpaned ); |
| 3411 | } |
| 3412 | |
| 3413 | EntityList_constructWindow( window ); |
| 3414 | PreferencesDialog_constructWindow( window ); |
| 3415 | FindTextureDialog_constructWindow( window ); |
| 3416 | SurfaceInspector_constructWindow( window ); |
| 3417 | PatchInspector_constructWindow( window ); |
| 3418 | |
| 3419 | SetActiveXY( m_pXYWnd ); |
| 3420 | |
| 3421 | AddGridChangeCallback( SetGridStatusCaller( *this ) ); |
| 3422 | AddGridChangeCallback( ReferenceCaller<MainFrame, void(), XY_UpdateAllWindows>( *this ) ); |
| 3423 | |
| 3424 | g_defaultToolMode = DragMode; |
| 3425 | g_defaultToolMode(); |
| 3426 | SetStatusText( m_command_status, c_TranslateMode_status ); |
| 3427 | |
| 3428 | EverySecondTimer_enable(); |
| 3429 | |
| 3430 | if ( g_layout_globals.nState & GDK_WINDOW_STATE_MAXIMIZED || |
| 3431 | g_layout_globals.nState & GDK_WINDOW_STATE_ICONIFIED ) { |
| 3432 | gtk_window_maximize( window ); |
| 3433 | } |
| 3434 | if ( g_layout_globals.nState & GDK_WINDOW_STATE_FULLSCREEN ) { |
| 3435 | gtk_window_fullscreen( window ); |
| 3436 | } |
| 3437 | |
| 3438 | if ( !FloatingGroupDialog() ) { |
| 3439 | gtk_paned_set_position( GTK_PANED( m_vSplit ), g_layout_globals.nXYHeight ); |
| 3440 | |
| 3441 | if ( CurrentStyle() == eRegular ) { |
| 3442 | gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nXYWidth ); |
| 3443 | } |
| 3444 | else |
| 3445 | { |
| 3446 | gtk_paned_set_position( GTK_PANED( m_hSplit ), g_layout_globals.nCamWidth ); |
| 3447 | } |
| 3448 | |
| 3449 | gtk_paned_set_position( GTK_PANED( m_vSplit2 ), g_layout_globals.nCamHeight ); |
| 3450 | } |
| 3451 | //GlobalShortcuts_reportUnregistered(); |
| 3452 | } |
| 3453 | |
| 3454 | void MainFrame::SaveWindowInfo(){ |
| 3455 | if ( !FloatingGroupDialog() ) { |
| 3456 | g_layout_globals.nXYHeight = gtk_paned_get_position( GTK_PANED( m_vSplit ) ); |
| 3457 | |
| 3458 | if ( CurrentStyle() != eRegular ) { |
| 3459 | g_layout_globals.nCamWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) ); |
| 3460 | } |
| 3461 | else |
| 3462 | { |
| 3463 | g_layout_globals.nXYWidth = gtk_paned_get_position( GTK_PANED( m_hSplit ) ); |
| 3464 | } |
| 3465 | |
| 3466 | g_layout_globals.nCamHeight = gtk_paned_get_position( GTK_PANED( m_vSplit2 ) ); |
| 3467 | } |
| 3468 | |
| 3469 | if( gdk_window_get_state( gtk_widget_get_window( GTK_WIDGET( m_window ) ) ) == 0 ){ |
| 3470 | g_layout_globals.m_position = m_position_tracker.getPosition(); |
| 3471 | } |
| 3472 | |
| 3473 | g_layout_globals.nState = gdk_window_get_state( gtk_widget_get_window(m_window ) ); |
| 3474 | } |
| 3475 | |
| 3476 | void MainFrame::Shutdown(){ |
| 3477 | EverySecondTimer_disable(); |
| 3478 | |
| 3479 | EntityList_destroyWindow(); |
| 3480 | |
| 3481 | delete m_pXYWnd; |
| 3482 | m_pXYWnd = 0; |
| 3483 | delete m_pYZWnd; |
| 3484 | m_pYZWnd = 0; |
| 3485 | delete m_pXZWnd; |
| 3486 | m_pXZWnd = 0; |
| 3487 | |
| 3488 | TextureBrowser_destroyWindow(); |
| 3489 | |
| 3490 | DeleteCamWnd( m_pCamWnd ); |
| 3491 | m_pCamWnd = 0; |
| 3492 | |
| 3493 | PreferencesDialog_destroyWindow(); |
| 3494 | SurfaceInspector_destroyWindow(); |
| 3495 | FindTextureDialog_destroyWindow(); |
| 3496 | PatchInspector_destroyWindow(); |
| 3497 | |
| 3498 | g_DbgDlg.destroyWindow(); |
| 3499 | |
| 3500 | // destroying group-dialog last because it may contain texture-browser |
| 3501 | GroupDialog_destroyWindow(); |
| 3502 | } |
| 3503 | |
| 3504 | void MainFrame::RedrawStatusText(){ |
| 3505 | ui::Label::from(m_pStatusLabel[c_command_status]).text(m_command_status.c_str()); |
| 3506 | ui::Label::from(m_pStatusLabel[c_position_status]).text(m_position_status.c_str()); |
| 3507 | ui::Label::from(m_pStatusLabel[c_brushcount_status]).text(m_brushcount_status.c_str()); |
| 3508 | ui::Label::from(m_pStatusLabel[c_texture_status]).text(m_texture_status.c_str()); |
| 3509 | ui::Label::from(m_pStatusLabel[c_grid_status]).text(m_grid_status.c_str()); |
| 3510 | } |
| 3511 | |
| 3512 | void MainFrame::UpdateStatusText(){ |
| 3513 | m_idleRedrawStatusText.queueDraw(); |
| 3514 | } |
| 3515 | |
| 3516 | void MainFrame::SetStatusText( CopiedString& status_text, const char* pText ){ |
| 3517 | status_text = pText; |
| 3518 | UpdateStatusText(); |
| 3519 | } |
| 3520 | |
| 3521 | void Sys_Status( const char* status ){ |
| 3522 | if ( g_pParentWnd != nullptr ) { |
| 3523 | g_pParentWnd->SetStatusText( g_pParentWnd->m_command_status, status ); |
| 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | int getRotateIncrement(){ |
| 3528 | return static_cast<int>( g_si_globals.rotate ); |
| 3529 | } |
| 3530 | |
| 3531 | int getFarClipDistance(){ |
| 3532 | return g_camwindow_globals.m_nCubicScale; |
| 3533 | } |
| 3534 | |
| 3535 | float ( *GridStatus_getGridSize )() = GetGridSize; |
| 3536 | |
| 3537 | int ( *GridStatus_getRotateIncrement )() = getRotateIncrement; |
| 3538 | |
| 3539 | int ( *GridStatus_getFarClipDistance )() = getFarClipDistance; |
| 3540 | |
| 3541 | bool ( *GridStatus_getTextureLockEnabled )(); |
| 3542 | |
| 3543 | void MainFrame::SetGridStatus(){ |
| 3544 | StringOutputStream status( 64 ); |
| 3545 | const char* lock = ( GridStatus_getTextureLockEnabled() ) ? "ON" : "OFF"; |
| 3546 | status << ( GetSnapGridSize() > 0 ? "G:" : "g:" ) << GridStatus_getGridSize() |
| 3547 | << " R:" << GridStatus_getRotateIncrement() |
| 3548 | << " C:" << GridStatus_getFarClipDistance() |
| 3549 | << " L:" << lock; |
| 3550 | SetStatusText( m_grid_status, status.c_str() ); |
| 3551 | } |
| 3552 | |
| 3553 | void GridStatus_onTextureLockEnabledChanged(){ |
| 3554 | if ( g_pParentWnd != nullptr ) { |
| 3555 | g_pParentWnd->SetGridStatus(); |
| 3556 | } |
| 3557 | } |
| 3558 | |
| 3559 | void GlobalGL_sharedContextCreated(){ |
| 3560 | GLFont *g_font = NULL; |
| 3561 | |
| 3562 | // report OpenGL information |
| 3563 | globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) << "\n"; |
| 3564 | globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) << "\n"; |
| 3565 | globalOutputStream() << "GL_VERSION: " << reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) << "\n"; |
| 3566 | const auto extensions = reinterpret_cast<const char*>( glGetString(GL_EXTENSIONS ) ); |
| 3567 | globalOutputStream() << "GL_EXTENSIONS: " << (extensions ? extensions : "") << "\n"; |
| 3568 | |
| 3569 | QGL_sharedContextCreated( GlobalOpenGL() ); |
| 3570 | |
| 3571 | ShaderCache_extensionsInitialised(); |
| 3572 | |
| 3573 | GlobalShaderCache().realise(); |
| 3574 | Textures_Realise(); |
| 3575 | |
| 3576 | #if GDEF_OS_WINDOWS |
| 3577 | /* win32 is dodgy here, just use courier new then */ |
| 3578 | g_font = glfont_create( "arial 9" ); |
| 3579 | #else |
| 3580 | auto settings = gtk_settings_get_default(); |
| 3581 | gchar *fontname; |
| 3582 | g_object_get( settings, "gtk-font-name", &fontname, NULL ); |
| 3583 | g_font = glfont_create( fontname ); |
| 3584 | #endif |
| 3585 | |
| 3586 | GlobalOpenGL().m_font = g_font; |
| 3587 | } |
| 3588 | |
| 3589 | void GlobalGL_sharedContextDestroyed(){ |
| 3590 | Textures_Unrealise(); |
| 3591 | GlobalShaderCache().unrealise(); |
| 3592 | |
| 3593 | QGL_sharedContextDestroyed( GlobalOpenGL() ); |
| 3594 | } |
| 3595 | |
| 3596 | |
| 3597 | void Layout_constructPreferences( PreferencesPage& page ){ |
| 3598 | { |
| 3599 | #if defined(WORKAROUND_GTK3_SINGLE_WINDOW_LAYOUT) |
| 3600 | /* HACK: Disable the floating windows layouts because |
| 3601 | GTK3 doesn't support context sharing accross windows. */ |
| 3602 | const char* layouts[] = { "window1.png", "window2-disabled.png", "window3-disabled.png", "window4.png", "window5.png" }; |
| 3603 | #else |
| 3604 | const char* layouts[] = { "window1.png", "window2.png", "window3.png", "window4.png", "window5.png" }; |
| 3605 | #endif |
| 3606 | page.appendRadioIcons( |
| 3607 | "Window Layout", |
| 3608 | STRING_ARRAY_RANGE( layouts ), |
| 3609 | make_property( g_Layout_viewStyle ) |
| 3610 | ); |
| 3611 | } |
| 3612 | page.appendCheckBox( |
| 3613 | "", "Detachable Menus", |
| 3614 | make_property( g_Layout_enableDetachableMenus ) |
| 3615 | ); |
| 3616 | page.appendCheckBox( |
| 3617 | "", "Main Toolbar", |
| 3618 | make_property( g_Layout_enableMainToolbar ) |
| 3619 | ); |
| 3620 | if ( !string_empty( g_pGameDescription->getKeyValue( "no_patch" ) ) ) { |
| 3621 | page.appendCheckBox( |
| 3622 | "", "Patch Toolbar", |
| 3623 | make_property( g_Layout_enablePatchToolbar ) |
| 3624 | ); |
| 3625 | } |
| 3626 | page.appendCheckBox( |
| 3627 | "", "Plugin Toolbar", |
| 3628 | make_property( g_Layout_enablePluginToolbar ) |
| 3629 | ); |
| 3630 | page.appendCheckBox( |
| 3631 | "", "Filter Toolbar", |
| 3632 | make_property( g_Layout_enableFilterToolbar ) |
| 3633 | ); |
| 3634 | } |
| 3635 | |
| 3636 | void Layout_constructPage( PreferenceGroup& group ){ |
| 3637 | PreferencesPage page( group.createPage( "Layout", "Layout Preferences" ) ); |
| 3638 | Layout_constructPreferences( page ); |
| 3639 | } |
| 3640 | |
| 3641 | void Layout_registerPreferencesPage(){ |
| 3642 | PreferencesDialog_addInterfacePage( makeCallbackF(Layout_constructPage) ); |
| 3643 | } |
| 3644 | |
| 3645 | void MainFrame_toggleFullscreen(){ |
| 3646 | GtkWindow* wnd = MainFrame_getWindow(); |
| 3647 | if( gdk_window_get_state( gtk_widget_get_window( GTK_WIDGET( wnd ) ) ) & GDK_WINDOW_STATE_FULLSCREEN ){ |
| 3648 | //some portion of buttsex, because gtk_window_unfullscreen doesn't work correctly after calling some modal window |
| 3649 | bool maximize = ( gdk_window_get_state( gtk_widget_get_window( GTK_WIDGET( wnd ) ) ) & GDK_WINDOW_STATE_MAXIMIZED ); |
| 3650 | gtk_window_unfullscreen( wnd ); |
| 3651 | if( maximize ){ |
| 3652 | gtk_window_unmaximize( wnd ); |
| 3653 | gtk_window_maximize( wnd ); |
| 3654 | } |
| 3655 | else{ |
| 3656 | gtk_window_move( wnd, g_layout_globals.m_position.x, g_layout_globals.m_position.y ); |
| 3657 | gtk_window_resize( wnd, g_layout_globals.m_position.w, g_layout_globals.m_position.h ); |
| 3658 | } |
| 3659 | } |
| 3660 | else{ |
| 3661 | gtk_window_fullscreen( wnd ); |
| 3662 | } |
| 3663 | } |
| 3664 | |
| 3665 | class MaximizeView |
| 3666 | { |
| 3667 | public: |
| 3668 | MaximizeView(): m_maximized( false ){ |
| 3669 | } |
| 3670 | void toggle(){ |
| 3671 | return m_maximized ? restore() : maximize(); |
| 3672 | } |
| 3673 | private: |
| 3674 | bool m_maximized; |
| 3675 | int m_vSplitPos; |
| 3676 | int m_vSplit2Pos; |
| 3677 | int m_hSplitPos; |
| 3678 | |
| 3679 | void restore(){ |
| 3680 | m_maximized = false; |
| 3681 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_vSplit ), m_vSplitPos ); |
| 3682 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_vSplit2 ), m_vSplit2Pos ); |
| 3683 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_hSplit ), m_hSplitPos ); |
| 3684 | } |
| 3685 | |
| 3686 | void maximize(){ |
| 3687 | m_maximized = true; |
| 3688 | m_vSplitPos = gtk_paned_get_position( GTK_PANED( g_pParentWnd->m_vSplit ) ); |
| 3689 | m_vSplit2Pos = gtk_paned_get_position( GTK_PANED( g_pParentWnd->m_vSplit2 ) ); |
| 3690 | m_hSplitPos = gtk_paned_get_position( GTK_PANED( g_pParentWnd->m_hSplit ) ); |
| 3691 | |
| 3692 | int vSplitX, vSplitY, vSplit2X, vSplit2Y, hSplitX, hSplitY; |
| 3693 | gdk_window_get_origin( gtk_widget_get_window( GTK_WIDGET( g_pParentWnd->m_vSplit ) ), &vSplitX, &vSplitY ); |
| 3694 | gdk_window_get_origin( gtk_widget_get_window( GTK_WIDGET( g_pParentWnd->m_vSplit2 ) ), &vSplit2X, &vSplit2Y ); |
| 3695 | gdk_window_get_origin( gtk_widget_get_window( GTK_WIDGET( g_pParentWnd->m_hSplit ) ), &hSplitX, &hSplitY ); |
| 3696 | |
| 3697 | vSplitY += m_vSplitPos; |
| 3698 | vSplit2Y += m_vSplit2Pos; |
| 3699 | hSplitX += m_hSplitPos; |
| 3700 | |
| 3701 | int cur_x, cur_y; |
| 3702 | Sys_GetCursorPos( MainFrame_getWindow(), &cur_x, &cur_y ); |
| 3703 | |
| 3704 | if( cur_x > hSplitX ){ |
| 3705 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_hSplit ), 0 ); |
| 3706 | } |
| 3707 | else{ |
| 3708 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_hSplit ), 9999 ); |
| 3709 | } |
| 3710 | if( cur_y > vSplitY ){ |
| 3711 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_vSplit ), 0 ); |
| 3712 | } |
| 3713 | else{ |
| 3714 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_vSplit ), 9999 ); |
| 3715 | } |
| 3716 | if( cur_y > vSplit2Y ){ |
| 3717 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_vSplit2 ), 0 ); |
| 3718 | } |
| 3719 | else{ |
| 3720 | gtk_paned_set_position( GTK_PANED( g_pParentWnd->m_vSplit2 ), 9999 ); |
| 3721 | } |
| 3722 | } |
| 3723 | }; |
| 3724 | |
| 3725 | MaximizeView g_maximizeview; |
| 3726 | |
| 3727 | void Maximize_View(){ |
| 3728 | if( g_pParentWnd != 0 && g_pParentWnd->m_vSplit != 0 && g_pParentWnd->m_vSplit2 != 0 && g_pParentWnd->m_hSplit != 0 ) |
| 3729 | g_maximizeview.toggle(); |
| 3730 | } |
| 3731 | |
| 3732 | void FocusAllViews(){ |
| 3733 | XY_Centralize(); //using centralizing here, not focusing function |
| 3734 | GlobalCamera_FocusOnSelected(); |
| 3735 | } |
| 3736 | #include "preferencesystem.h" |
| 3737 | #include "stringio.h" |
| 3738 | #include "transformpath/transformpath.h" |
| 3739 | |
| 3740 | void MainFrame_Construct(){ |
| 3741 | GlobalCommands_insert( "OpenManual", makeCallbackF(OpenHelpURL), Accelerator( GDK_KEY_F1 ) ); |
| 3742 | |
| 3743 | GlobalCommands_insert( "Sleep", makeCallbackF(thunk_OnSleep), Accelerator( 'P', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); |
| 3744 | GlobalCommands_insert( "NewMap", makeCallbackF(NewMap) ); |
| 3745 | GlobalCommands_insert( "OpenMap", makeCallbackF(OpenMap), Accelerator( 'O', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3746 | GlobalCommands_insert( "ImportMap", makeCallbackF(ImportMap) ); |
| 3747 | GlobalCommands_insert( "SaveMap", makeCallbackF(SaveMap), Accelerator( 'S', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3748 | GlobalCommands_insert( "SaveMapAs", makeCallbackF(SaveMapAs) ); |
| 3749 | GlobalCommands_insert( "ExportSelected", makeCallbackF(ExportMap) ); |
| 3750 | GlobalCommands_insert( "SaveRegion", makeCallbackF(SaveRegion) ); |
| 3751 | GlobalCommands_insert( "RefreshReferences", makeCallbackF(VFS_Refresh) ); |
| 3752 | GlobalCommands_insert( "ProjectSettings", makeCallbackF(DoProjectSettings) ); |
| 3753 | GlobalCommands_insert( "Exit", makeCallbackF(Exit) ); |
| 3754 | |
| 3755 | GlobalCommands_insert( "Undo", makeCallbackF(Undo), Accelerator( 'Z', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3756 | GlobalCommands_insert( "Redo", makeCallbackF(Redo), Accelerator( 'Y', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3757 | GlobalCommands_insert( "Copy", makeCallbackF(Copy), Accelerator( 'C', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3758 | GlobalCommands_insert( "Paste", makeCallbackF(Paste), Accelerator( 'V', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3759 | GlobalCommands_insert( "PasteToCamera", makeCallbackF(PasteToCamera), Accelerator( 'V', (GdkModifierType)GDK_MOD1_MASK ) ); |
| 3760 | GlobalCommands_insert( "CloneSelection", makeCallbackF(Selection_Clone), Accelerator( GDK_KEY_space ) ); |
| 3761 | GlobalCommands_insert( "CloneSelectionAndMakeUnique", makeCallbackF(Selection_Clone_MakeUnique), Accelerator( GDK_KEY_space, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3762 | // GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) ); |
| 3763 | GlobalCommands_insert( "DeleteSelection2", makeCallbackF(deleteSelection), Accelerator( GDK_KEY_BackSpace ) ); |
| 3764 | GlobalCommands_insert( "DeleteSelection", makeCallbackF(deleteSelection), Accelerator( 'Z' ) ); |
| 3765 | GlobalCommands_insert( "ParentSelection", makeCallbackF(Scene_parentSelected) ); |
| 3766 | // GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) ); |
| 3767 | GlobalCommands_insert( "UnSelectSelection2", makeCallbackF(Selection_Deselect), Accelerator( GDK_KEY_Escape ) ); |
| 3768 | GlobalCommands_insert( "UnSelectSelection", makeCallbackF(Selection_Deselect), Accelerator( 'C' ) ); |
| 3769 | GlobalCommands_insert( "InvertSelection", makeCallbackF(Select_Invert), Accelerator( 'I' ) ); |
| 3770 | GlobalCommands_insert( "SelectInside", makeCallbackF(Select_Inside) ); |
| 3771 | GlobalCommands_insert( "SelectTouching", makeCallbackF(Select_Touching) ); |
| 3772 | GlobalCommands_insert( "ExpandSelectionToEntities", makeCallbackF(Scene_ExpandSelectionToEntities), Accelerator( 'E', (GdkModifierType)( GDK_MOD1_MASK | GDK_CONTROL_MASK ) ) ); |
| 3773 | GlobalCommands_insert( "SelectConnectedEntities", makeCallbackF(SelectConnectedEntities), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); |
| 3774 | GlobalCommands_insert( "Preferences", makeCallbackF(PreferencesDialog_showDialog), Accelerator( 'P' ) ); |
| 3775 | |
| 3776 | GlobalCommands_insert( "ToggleConsole", makeCallbackF(Console_ToggleShow), Accelerator( 'O' ) ); |
| 3777 | GlobalCommands_insert( "ToggleEntityInspector", makeCallbackF(EntityInspector_ToggleShow), Accelerator( 'N' ) ); |
| 3778 | GlobalCommands_insert( "EntityList", makeCallbackF(EntityList_toggleShown), Accelerator( 'L' ) ); |
| 3779 | |
| 3780 | // GlobalCommands_insert( "ShowHidden", makeCallbackF( Select_ShowAllHidden ), Accelerator( 'H', (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3781 | // GlobalCommands_insert( "HideSelected", makeCallbackF( HideSelected ), Accelerator( 'H' ) ); |
| 3782 | |
| 3783 | Select_registerCommands(); |
| 3784 | |
| 3785 | GlobalToggles_insert( "DragVertices", makeCallbackF(SelectVertexMode), ToggleItem::AddCallbackCaller( g_vertexMode_button ), Accelerator( 'V' ) ); |
| 3786 | GlobalToggles_insert( "DragEdges", makeCallbackF(SelectEdgeMode), ToggleItem::AddCallbackCaller( g_edgeMode_button ), Accelerator( 'E' ) ); |
| 3787 | GlobalToggles_insert( "DragFaces", makeCallbackF(SelectFaceMode), ToggleItem::AddCallbackCaller( g_faceMode_button ), Accelerator( 'F' ) ); |
| 3788 | |
| 3789 | GlobalCommands_insert( "ArbitraryRotation", makeCallbackF(DoRotateDlg), Accelerator( 'R', (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3790 | GlobalCommands_insert( "ArbitraryScale", makeCallbackF(DoScaleDlg), Accelerator( 'S', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); |
| 3791 | |
| 3792 | GlobalCommands_insert( "BuildMenuCustomize", makeCallbackF(DoBuildMenu) ); |
| 3793 | GlobalCommands_insert( "Build_runRecentExecutedBuild", makeCallbackF(Build_runRecentExecutedBuild), Accelerator( GDK_KEY_F5 ) ); |
| 3794 | |
| 3795 | GlobalCommands_insert( "FindBrush", makeCallbackF(DoFind) ); |
| 3796 | |
| 3797 | GlobalCommands_insert( "MapInfo", makeCallbackF(DoMapInfo), Accelerator( 'M' ) ); |
| 3798 | |
| 3799 | |
| 3800 | GlobalToggles_insert( "ToggleClipper", makeCallbackF(ClipperMode), ToggleItem::AddCallbackCaller( g_clipper_button ), Accelerator( 'X' ) ); |
| 3801 | |
| 3802 | GlobalToggles_insert( "MouseTranslate", makeCallbackF(TranslateMode), ToggleItem::AddCallbackCaller( g_translatemode_button ), Accelerator( 'W' ) ); |
| 3803 | GlobalToggles_insert( "MouseRotate", makeCallbackF(RotateMode), ToggleItem::AddCallbackCaller( g_rotatemode_button ), Accelerator( 'R' ) ); |
| 3804 | GlobalToggles_insert( "MouseScale", makeCallbackF(ScaleMode), ToggleItem::AddCallbackCaller( g_scalemode_button ) ); |
| 3805 | GlobalToggles_insert( "MouseDrag", makeCallbackF(DragMode), ToggleItem::AddCallbackCaller( g_dragmode_button ) ); |
| 3806 | GlobalCommands_insert( "MouseRotateOrScale", makeCallbackF(ToggleRotateScaleModes) ); |
| 3807 | GlobalCommands_insert( "MouseDragOrScale", makeCallbackF(ToggleDragScaleModes), Accelerator( 'Q' ) ); |
| 3808 | |
| 3809 | #ifndef GARUX_DISABLE_GTKTHEME |
| 3810 | GlobalCommands_insert( "gtkThemeDlg", makeCallbackF(gtkThemeDlg) ); |
| 3811 | #endif |
| 3812 | GlobalCommands_insert( "ColorSchemeOriginal", makeCallbackF(ColorScheme_Original) ); |
| 3813 | GlobalCommands_insert( "ColorSchemeQER", makeCallbackF(ColorScheme_QER) ); |
| 3814 | GlobalCommands_insert( "ColorSchemeBlackAndGreen", makeCallbackF(ColorScheme_Black) ); |
| 3815 | GlobalCommands_insert( "ColorSchemeYdnar", makeCallbackF(ColorScheme_Ydnar) ); |
| 3816 | GlobalCommands_insert( "ColorSchemeAdwaitaDark", makeCallbackF(ColorScheme_AdwaitaDark)); |
| 3817 | GlobalCommands_insert( "ChooseTextureBackgroundColor", makeCallback( g_ColoursMenu.m_textureback ) ); |
| 3818 | GlobalCommands_insert( "ChooseGridBackgroundColor", makeCallback( g_ColoursMenu.m_xyback ) ); |
| 3819 | GlobalCommands_insert( "ChooseGridMajorColor", makeCallback( g_ColoursMenu.m_gridmajor ) ); |
| 3820 | GlobalCommands_insert( "ChooseGridMinorColor", makeCallback( g_ColoursMenu.m_gridminor ) ); |
| 3821 | GlobalCommands_insert( "ChooseGridTextColor", makeCallback( g_ColoursMenu.m_gridtext ) ); |
| 3822 | GlobalCommands_insert( "ChooseGridBlockColor", makeCallback( g_ColoursMenu.m_gridblock ) ); |
| 3823 | GlobalCommands_insert( "ChooseBrushColor", makeCallback( g_ColoursMenu.m_brush ) ); |
| 3824 | GlobalCommands_insert( "ChooseCameraBackgroundColor", makeCallback( g_ColoursMenu.m_cameraback ) ); |
| 3825 | GlobalCommands_insert( "ChooseSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush ) ); |
| 3826 | GlobalCommands_insert( "ChooseCameraSelectedBrushColor", makeCallback( g_ColoursMenu.m_selectedbrush3d ) ); |
| 3827 | GlobalCommands_insert( "ChooseClipperColor", makeCallback( g_ColoursMenu.m_clipper ) ); |
| 3828 | GlobalCommands_insert( "ChooseOrthoViewNameColor", makeCallback( g_ColoursMenu.m_viewname ) ); |
| 3829 | |
| 3830 | GlobalCommands_insert( "Fullscreen", makeCallbackF( MainFrame_toggleFullscreen ), Accelerator( GDK_KEY_F11 ) ); |
| 3831 | GlobalCommands_insert( "MaximizeView", makeCallbackF( Maximize_View ), Accelerator( GDK_KEY_F12 ) ); |
| 3832 | |
| 3833 | |
| 3834 | GlobalCommands_insert( "CSGSubtract", makeCallbackF(CSG_Subtract), Accelerator( 'U', (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3835 | GlobalCommands_insert( "CSGMerge", makeCallbackF(CSG_Merge), Accelerator( 'U', (GdkModifierType) GDK_CONTROL_MASK ) ); |
| 3836 | GlobalCommands_insert( "CSGRoom", makeCallbackF(CSG_MakeRoom) ); |
| 3837 | GlobalCommands_insert( "CSGTool", makeCallbackF(CSG_Tool) ); |
| 3838 | |
| 3839 | Grid_registerCommands(); |
| 3840 | |
| 3841 | GlobalCommands_insert( "SnapToGrid", makeCallbackF(Selection_SnapToGrid), Accelerator( 'G', (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3842 | |
| 3843 | GlobalCommands_insert( "SelectAllOfType", makeCallbackF(Select_AllOfType), Accelerator( 'A', (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3844 | |
| 3845 | GlobalCommands_insert( "TexRotateClock", makeCallbackF(Texdef_RotateClockwise), Accelerator( GDK_KEY_Next, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3846 | GlobalCommands_insert( "TexRotateCounter", makeCallbackF(Texdef_RotateAntiClockwise), Accelerator( GDK_KEY_Prior, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3847 | GlobalCommands_insert( "TexScaleUp", makeCallbackF(Texdef_ScaleUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3848 | GlobalCommands_insert( "TexScaleDown", makeCallbackF(Texdef_ScaleDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3849 | GlobalCommands_insert( "TexScaleLeft", makeCallbackF(Texdef_ScaleLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3850 | GlobalCommands_insert( "TexScaleRight", makeCallbackF(Texdef_ScaleRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_CONTROL_MASK ) ); |
| 3851 | GlobalCommands_insert( "TexShiftUp", makeCallbackF(Texdef_ShiftUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3852 | GlobalCommands_insert( "TexShiftDown", makeCallbackF(Texdef_ShiftDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3853 | GlobalCommands_insert( "TexShiftLeft", makeCallbackF(Texdef_ShiftLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3854 | GlobalCommands_insert( "TexShiftRight", makeCallbackF(Texdef_ShiftRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3855 | |
| 3856 | GlobalCommands_insert( "MoveSelectionDOWN", makeCallbackF(Selection_MoveDown), Accelerator( GDK_KEY_KP_Subtract ) ); |
| 3857 | GlobalCommands_insert( "MoveSelectionUP", makeCallbackF(Selection_MoveUp), Accelerator( GDK_KEY_KP_Add ) ); |
| 3858 | |
| 3859 | GlobalCommands_insert( "SelectNudgeLeft", makeCallbackF(Selection_NudgeLeft), Accelerator( GDK_KEY_Left, (GdkModifierType)GDK_MOD1_MASK ) ); |
| 3860 | GlobalCommands_insert( "SelectNudgeRight", makeCallbackF(Selection_NudgeRight), Accelerator( GDK_KEY_Right, (GdkModifierType)GDK_MOD1_MASK ) ); |
| 3861 | GlobalCommands_insert( "SelectNudgeUp", makeCallbackF(Selection_NudgeUp), Accelerator( GDK_KEY_Up, (GdkModifierType)GDK_MOD1_MASK ) ); |
| 3862 | GlobalCommands_insert( "SelectNudgeDown", makeCallbackF(Selection_NudgeDown), Accelerator( GDK_KEY_Down, (GdkModifierType)GDK_MOD1_MASK ) ); |
| 3863 | |
| 3864 | Patch_registerCommands(); |
| 3865 | XYShow_registerCommands(); |
| 3866 | |
| 3867 | typedef FreeCaller<void(const Selectable&), ComponentMode_SelectionChanged> ComponentModeSelectionChangedCaller; |
| 3868 | GlobalSelectionSystem().addSelectionChangeCallback( ComponentModeSelectionChangedCaller() ); |
| 3869 | |
| 3870 | GlobalPreferenceSystem().registerPreference( "DetachableMenus", make_property_string( g_Layout_enableDetachableMenus.m_latched ) ); |
| 3871 | GlobalPreferenceSystem().registerPreference( "MainToolBar", make_property_string( g_Layout_enableMainToolbar.m_latched ) ); |
| 3872 | GlobalPreferenceSystem().registerPreference( "PatchToolBar", make_property_string( g_Layout_enablePatchToolbar.m_latched ) ); |
| 3873 | GlobalPreferenceSystem().registerPreference( "PluginToolBar", make_property_string( g_Layout_enablePluginToolbar.m_latched ) ); |
| 3874 | GlobalPreferenceSystem().registerPreference( "FilterToolBar", make_property_string( g_Layout_enableFilterToolbar.m_latched ) ); |
| 3875 | GlobalPreferenceSystem().registerPreference( "QE4StyleWindows", make_property_string( g_Layout_viewStyle.m_latched ) ); |
| 3876 | GlobalPreferenceSystem().registerPreference( "XYHeight", make_property_string( g_layout_globals.nXYHeight ) ); |
| 3877 | GlobalPreferenceSystem().registerPreference( "XYWidth", make_property_string( g_layout_globals.nXYWidth ) ); |
| 3878 | GlobalPreferenceSystem().registerPreference( "CamWidth", make_property_string( g_layout_globals.nCamWidth ) ); |
| 3879 | GlobalPreferenceSystem().registerPreference( "CamHeight", make_property_string( g_layout_globals.nCamHeight ) ); |
| 3880 | |
| 3881 | GlobalPreferenceSystem().registerPreference( "State", make_property_string( g_layout_globals.nState ) ); |
| 3882 | GlobalPreferenceSystem().registerPreference( "PositionX", make_property_string( g_layout_globals.m_position.x ) ); |
| 3883 | GlobalPreferenceSystem().registerPreference( "PositionY", make_property_string( g_layout_globals.m_position.y ) ); |
| 3884 | GlobalPreferenceSystem().registerPreference( "Width", make_property_string( g_layout_globals.m_position.w ) ); |
| 3885 | GlobalPreferenceSystem().registerPreference( "Height", make_property_string( g_layout_globals.m_position.h ) ); |
| 3886 | |
| 3887 | GlobalPreferenceSystem().registerPreference( "CamWnd", make_property<WindowPositionTracker_String>(g_posCamWnd) ); |
| 3888 | GlobalPreferenceSystem().registerPreference( "XYWnd", make_property<WindowPositionTracker_String>(g_posXYWnd) ); |
| 3889 | GlobalPreferenceSystem().registerPreference( "YZWnd", make_property<WindowPositionTracker_String>(g_posYZWnd) ); |
| 3890 | GlobalPreferenceSystem().registerPreference( "XZWnd", make_property<WindowPositionTracker_String>(g_posXZWnd) ); |
| 3891 | |
| 3892 | GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) ); |
| 3893 | |
| 3894 | GlobalPreferenceSystem().registerPreference( "NudgeAfterClone", make_property_string( g_bNudgeAfterClone ) ); |
| 3895 | if ( g_strEnginePath.empty() ) |
| 3896 | { |
| 3897 | g_strEnginePath_was_empty_1st_start = true; |
| 3898 | const char* ENGINEPATH_ATTRIBUTE = |
| 3899 | #if GDEF_OS_WINDOWS |
| 3900 | "enginepath_win32" |
| 3901 | #elif GDEF_OS_MACOS |
| 3902 | "enginepath_macos" |
| 3903 | #elif GDEF_OS_LINUX || GDEF_OS_BSD |
| 3904 | "enginepath_linux" |
| 3905 | #else |
| 3906 | #error "unknown platform" |
| 3907 | #endif |
| 3908 | ; |
| 3909 | |
| 3910 | StringOutputStream path( 256 ); |
| 3911 | path << DirectoryCleaned( g_pGameDescription->getRequiredKeyValue( ENGINEPATH_ATTRIBUTE ) ); |
| 3912 | |
| 3913 | g_strEnginePath = transformPath( path.c_str() ).c_str(); |
| 3914 | GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) ); |
| 3915 | } |
| 3916 | |
| 3917 | GlobalPreferenceSystem().registerPreference( "DisableEnginePath", make_property_string( g_disableEnginePath ) ); |
| 3918 | GlobalPreferenceSystem().registerPreference( "DisableHomePath", make_property_string( g_disableHomePath ) ); |
| 3919 | |
| 3920 | for ( int i = 0; i < g_pakPathCount; i++ ) { |
| 3921 | std::string label = "PakPath" + std::to_string( i ); |
| 3922 | GlobalPreferenceSystem().registerPreference( label.c_str(), make_property_string( g_strPakPath[i] ) ); |
| 3923 | } |
| 3924 | |
| 3925 | g_Layout_viewStyle.useLatched(); |
| 3926 | g_Layout_enableDetachableMenus.useLatched(); |
| 3927 | g_Layout_enableMainToolbar.useLatched(); |
| 3928 | g_Layout_enablePatchToolbar.useLatched(); |
| 3929 | g_Layout_enablePluginToolbar.useLatched(); |
| 3930 | g_Layout_enableFilterToolbar.useLatched(); |
| 3931 | |
| 3932 | Layout_registerPreferencesPage(); |
| 3933 | Paths_registerPreferencesPage(); |
| 3934 | PreferencesDialog_addSettingsPreferences( FreeCaller<void(PreferencesPage&), Nudge_constructPreferences>() ); |
| 3935 | |
| 3936 | g_brushCount.setCountChangedCallback( makeCallbackF(QE_brushCountChanged) ); |
| 3937 | g_entityCount.setCountChangedCallback( makeCallbackF(QE_entityCountChanged) ); |
| 3938 | GlobalEntityCreator().setCounter( &g_entityCount ); |
| 3939 | |
| 3940 | glwidget_set_shared_context_constructors( GlobalGL_sharedContextCreated, GlobalGL_sharedContextDestroyed); |
| 3941 | |
| 3942 | GlobalEntityClassManager().attach( g_WorldspawnColourEntityClassObserver ); |
| 3943 | } |
| 3944 | |
| 3945 | void MainFrame_Destroy(){ |
| 3946 | GlobalEntityClassManager().detach( g_WorldspawnColourEntityClassObserver ); |
| 3947 | |
| 3948 | GlobalEntityCreator().setCounter( 0 ); |
| 3949 | g_entityCount.setCountChangedCallback( Callback<void()>() ); |
| 3950 | g_brushCount.setCountChangedCallback( Callback<void()>() ); |
| 3951 | } |
| 3952 | |
| 3953 | |
| 3954 | void GLWindow_Construct(){ |
| 3955 | // GlobalPreferenceSystem().registerPreference( "MouseButtons", make_property_string( g_glwindow_globals.m_nMouseType ) ); |
| 3956 | } |
| 3957 | |
| 3958 | void GLWindow_Destroy(){ |
| 3959 | } |
| 3960 | |
| 3961 | /* HACK: If ui::main is not called yet, |
| 3962 | gtk_main_quit will not quit, so tell main |
| 3963 | to not call ui::main. This happens when a |
| 3964 | map is loaded from command line and require |
| 3965 | a restart because of wrong format. |
| 3966 | Delete this when the code to not have to |
| 3967 | restart to load another format is merged. */ |
| 3968 | extern bool g_dontStart; |
| 3969 | |
| 3970 | void Radiant_Restart(){ |
| 3971 | // preferences are expected to be already saved in any way |
| 3972 | // this is just to be sure and be future proof |
| 3973 | Preferences_Save(); |
| 3974 | |
| 3975 | // this asks user for saving if map is modified |
| 3976 | // user can chose to not save, it's ok |
| 3977 | ConfirmModified( "Restart " RADIANT_NAME ); |
| 3978 | |
| 3979 | int status; |
| 3980 | |
| 3981 | char *argv[ 3 ]; |
| 3982 | char exe_file[ 256 ]; |
| 3983 | char map_file[ 256 ]; |
| 3984 | bool with_map = false; |
| 3985 | |
| 3986 | strncpy( exe_file, g_strAppFilePath.c_str(), sizeof( exe_file ) - 1 ); |
| 3987 | |
| 3988 | if ( !Map_Unnamed( g_map ) ) { |
| 3989 | strncpy( map_file, Map_Name( g_map ), sizeof( map_file ) - 1 ); |
| 3990 | with_map = true; |
| 3991 | } |
| 3992 | |
| 3993 | argv[ 0 ] = exe_file; |
| 3994 | argv[ 1 ] = with_map ? map_file : NULL; |
| 3995 | argv[ 2 ] = NULL; |
| 3996 | |
| 3997 | #if GDEF_OS_WINDOWS |
| 3998 | status = !_spawnvpe( P_NOWAIT, exe_file, argv, environ ); |
| 3999 | #else |
| 4000 | pid_t pid; |
| 4001 | |
| 4002 | status = posix_spawn( &pid, exe_file, NULL, NULL, argv, environ ); |
| 4003 | #endif |
| 4004 | |
| 4005 | // quit if radiant successfully started |
| 4006 | if ( status == 0 ) { |
| 4007 | gtk_main_quit(); |
| 4008 | /* HACK: If ui::main is not called yet, |
| 4009 | gtk_main_quit will not quit, so tell main |
| 4010 | to not call ui::main. This happens when a |
| 4011 | map is loaded from command line and require |
| 4012 | a restart because of wrong format. |
| 4013 | Delete this when the code to not have to |
| 4014 | restart to load another format is merged. */ |
| 4015 | g_dontStart = true; |
| 4016 | } |
| 4017 | } |