| 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 | // XY Window |
| 24 | // |
| 25 | // Leonardo Zide ([email protected]) |
| 26 | // |
| 27 | |
| 28 | #include "xywindow.h" |
| 29 | |
| 30 | #include <gtk/gtk.h> |
| 31 | |
| 32 | #include "debugging/debugging.h" |
| 33 | |
| 34 | #include "ientity.h" |
| 35 | #include "igl.h" |
| 36 | #include "ibrush.h" |
| 37 | #include "iundo.h" |
| 38 | #include "iimage.h" |
| 39 | #include "ifilesystem.h" |
| 40 | #include "os/path.h" |
| 41 | #include "image.h" |
| 42 | #include "gtkutil/messagebox.h" |
| 43 | |
| 44 | #include <uilib/uilib.h> |
| 45 | #include <gdk/gdkkeysyms.h> |
| 46 | |
| 47 | #include "generic/callback.h" |
| 48 | #include "string/string.h" |
| 49 | #include "stream/stringstream.h" |
| 50 | |
| 51 | #include "scenelib.h" |
| 52 | #include "eclasslib.h" |
| 53 | #include "renderer.h" |
| 54 | #include "moduleobserver.h" |
| 55 | |
| 56 | #include "gtkutil/menu.h" |
| 57 | #include "gtkutil/container.h" |
| 58 | #include "gtkutil/widget.h" |
| 59 | #include "gtkutil/glwidget.h" |
| 60 | #include "gtkutil/filechooser.h" |
| 61 | #include "gtkutil/cursor.h" |
| 62 | #include "gtkmisc.h" |
| 63 | #include "select.h" |
| 64 | #include "csg.h" |
| 65 | #include "brushmanip.h" |
| 66 | #include "selection.h" |
| 67 | #include "entity.h" |
| 68 | #include "camwindow.h" |
| 69 | #include "texwindow.h" |
| 70 | #include "mainframe.h" |
| 71 | #include "preferences.h" |
| 72 | #include "commands.h" |
| 73 | #include "feedback.h" |
| 74 | #include "grid.h" |
| 75 | #include "windowobservers.h" |
| 76 | |
| 77 | void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight ); |
| 78 | |
| 79 | // d1223m |
| 80 | extern bool g_brush_always_caulk; |
| 81 | |
| 82 | //!\todo Rewrite. |
| 83 | class ClipPoint |
| 84 | { |
| 85 | public: |
| 86 | Vector3 m_ptClip; // the 3d point |
| 87 | bool m_bSet; |
| 88 | |
| 89 | ClipPoint(){ |
| 90 | Reset(); |
| 91 | }; |
| 92 | void Reset(){ |
| 93 | m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0; |
| 94 | m_bSet = false; |
| 95 | } |
| 96 | bool Set(){ |
| 97 | return m_bSet; |
| 98 | } |
| 99 | void Set( bool b ){ |
| 100 | m_bSet = b; |
| 101 | } |
| 102 | operator Vector3&() |
| 103 | { |
| 104 | return m_ptClip; |
| 105 | }; |
| 106 | |
| 107 | /*! Draw clip/path point with rasterized number label */ |
| 108 | void Draw( int num, float scale ); |
| 109 | /*! Draw clip/path point with rasterized string label */ |
| 110 | void Draw( const char *label, float scale ); |
| 111 | }; |
| 112 | |
| 113 | VIEWTYPE g_clip_viewtype; |
| 114 | bool g_bSwitch = true; |
| 115 | bool g_clip_useCaulk = false; |
| 116 | bool g_quick_clipper = false; |
| 117 | ClipPoint g_Clip1; |
| 118 | ClipPoint g_Clip2; |
| 119 | ClipPoint g_Clip3; |
| 120 | ClipPoint* g_pMovingClip = 0; |
| 121 | |
| 122 | /* Drawing clip points */ |
| 123 | void ClipPoint::Draw( int num, float scale ){ |
| 124 | StringOutputStream label( 4 ); |
| 125 | label << num; |
| 126 | Draw( label.c_str(), scale ); |
| 127 | } |
| 128 | |
| 129 | void ClipPoint::Draw( const char *label, float scale ){ |
| 130 | // draw point |
| 131 | glPointSize( 4 ); |
| 132 | glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) ); |
| 133 | glBegin( GL_POINTS ); |
| 134 | glVertex3fv( vector3_to_array( m_ptClip ) ); |
| 135 | glEnd(); |
| 136 | glPointSize( 1 ); |
| 137 | |
| 138 | float offset = 2.0f / scale; |
| 139 | |
| 140 | // draw label |
| 141 | glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset ); |
| 142 | //glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label ); //fails with GCC |
| 143 | //glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, reinterpret_cast<const GLubyte*>( label ) ); //worx |
| 144 | GlobalOpenGL().drawString( label ); |
| 145 | } |
| 146 | |
| 147 | float fDiff( float f1, float f2 ){ |
| 148 | if ( f1 > f2 ) { |
| 149 | return f1 - f2; |
| 150 | } |
| 151 | else{ |
| 152 | return f2 - f1; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){ |
| 157 | int nDim1 = ( viewtype == YZ ) ? 1 : 0; |
| 158 | int nDim2 = ( viewtype == XY ) ? 1 : 2; |
| 159 | double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) ); |
| 160 | if ( screenDistanceSquared < 8 * 8 ) { |
| 161 | return screenDistanceSquared; |
| 162 | } |
| 163 | return FLT_MAX; |
| 164 | } |
| 165 | |
| 166 | inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){ |
| 167 | if ( clip.Set() ) { |
| 168 | double distance = ClipPoint_Intersect( clip, point, viewtype, scale ); |
| 169 | if ( distance < bestDistance ) { |
| 170 | bestDistance = distance; |
| 171 | bestClip = &clip; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){ |
| 177 | double bestDistance = FLT_MAX; |
| 178 | ClipPoint* bestClip = 0; |
| 179 | ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip ); |
| 180 | ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip ); |
| 181 | ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip ); |
| 182 | return bestClip; |
| 183 | } |
| 184 | |
| 185 | inline void GlobalClipPoints_Draw( float scale ){ |
| 186 | // Draw clip points |
| 187 | if ( g_Clip1.Set() ) { |
| 188 | g_Clip1.Draw( 1, scale ); |
| 189 | } |
| 190 | if ( g_Clip2.Set() ) { |
| 191 | g_Clip2.Draw( 2, scale ); |
| 192 | } |
| 193 | if ( g_Clip3.Set() ) { |
| 194 | g_Clip3.Draw( 3, scale ); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | inline bool GlobalClipPoints_valid(){ |
| 199 | return g_Clip1.Set() && g_Clip2.Set(); |
| 200 | } |
| 201 | |
| 202 | void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){ |
| 203 | ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" ); |
| 204 | planepts[0] = g_Clip1.m_ptClip; |
| 205 | planepts[1] = g_Clip2.m_ptClip; |
| 206 | planepts[2] = g_Clip3.m_ptClip; |
| 207 | Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) ); |
| 208 | Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) ); |
| 209 | if ( !g_Clip3.Set() ) { |
| 210 | int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1; |
| 211 | int x = ( n == 0 ) ? 1 : 0; |
| 212 | int y = ( n == 2 ) ? 1 : 2; |
| 213 | |
| 214 | if ( n == 1 ) { // on viewtype XZ, flip clip points |
| 215 | planepts[0][n] = maxs[n]; |
| 216 | planepts[1][n] = maxs[n]; |
| 217 | planepts[2][x] = g_Clip1.m_ptClip[x]; |
| 218 | planepts[2][y] = g_Clip1.m_ptClip[y]; |
| 219 | planepts[2][n] = mins[n]; |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | planepts[0][n] = mins[n]; |
| 224 | planepts[1][n] = mins[n]; |
| 225 | planepts[2][x] = g_Clip1.m_ptClip[x]; |
| 226 | planepts[2][y] = g_Clip1.m_ptClip[y]; |
| 227 | planepts[2][n] = maxs[n]; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | void Clip_Update(){ |
| 233 | Vector3 planepts[3]; |
| 234 | if ( !GlobalClipPoints_valid() ) { |
| 235 | planepts[0] = Vector3( 0, 0, 0 ); |
| 236 | planepts[1] = Vector3( 0, 0, 0 ); |
| 237 | planepts[2] = Vector3( 0, 0, 0 ); |
| 238 | Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) ); |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) ); |
| 243 | PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype ); |
| 244 | if ( g_bSwitch ) { |
| 245 | std::swap( planepts[0], planepts[1] ); |
| 246 | } |
| 247 | Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) ); |
| 248 | } |
| 249 | ClipperChangeNotify(); |
| 250 | } |
| 251 | |
| 252 | const char* Clip_getShader(){ |
| 253 | return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ); |
| 254 | } |
| 255 | |
| 256 | void Clip(){ |
| 257 | if ( ClipMode() && GlobalClipPoints_valid() ) { |
| 258 | Vector3 planepts[3]; |
| 259 | AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) ); |
| 260 | PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype ); |
| 261 | Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack ); |
| 262 | g_Clip1.Reset(); |
| 263 | g_Clip2.Reset(); |
| 264 | g_Clip3.Reset(); |
| 265 | Clip_Update(); |
| 266 | ClipperChangeNotify(); |
| 267 | if( g_quick_clipper ){ |
| 268 | g_quick_clipper = false; |
| 269 | ClipperMode(); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | void SplitClip(){ |
| 275 | if ( ClipMode() && GlobalClipPoints_valid() ) { |
| 276 | Vector3 planepts[3]; |
| 277 | AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) ); |
| 278 | PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype ); |
| 279 | Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack ); |
| 280 | g_Clip1.Reset(); |
| 281 | g_Clip2.Reset(); |
| 282 | g_Clip3.Reset(); |
| 283 | Clip_Update(); |
| 284 | ClipperChangeNotify(); |
| 285 | if( g_quick_clipper ){ |
| 286 | g_quick_clipper = false; |
| 287 | ClipperMode(); |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | void FlipClip(){ |
| 293 | g_bSwitch = !g_bSwitch; |
| 294 | Clip_Update(); |
| 295 | ClipperChangeNotify(); |
| 296 | } |
| 297 | |
| 298 | void OnClipMode( bool enabled ){ |
| 299 | g_Clip1.Reset(); |
| 300 | g_Clip2.Reset(); |
| 301 | g_Clip3.Reset(); |
| 302 | |
| 303 | if ( !enabled && g_pMovingClip ) { |
| 304 | g_pMovingClip = 0; |
| 305 | } |
| 306 | |
| 307 | Clip_Update(); |
| 308 | ClipperChangeNotify(); |
| 309 | } |
| 310 | |
| 311 | bool ClipMode(){ |
| 312 | return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip; |
| 313 | } |
| 314 | |
| 315 | void NewClipPoint( const Vector3& point ){ |
| 316 | if ( g_Clip1.Set() == false ) { |
| 317 | g_Clip1.m_ptClip = point; |
| 318 | g_Clip1.Set( true ); |
| 319 | } |
| 320 | else if ( g_Clip2.Set() == false ) { |
| 321 | g_Clip2.m_ptClip = point; |
| 322 | g_Clip2.Set( true ); |
| 323 | } |
| 324 | else if ( g_Clip3.Set() == false ) { |
| 325 | g_Clip3.m_ptClip = point; |
| 326 | g_Clip3.Set( true ); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | g_Clip1.Reset(); |
| 331 | g_Clip2.Reset(); |
| 332 | g_Clip3.Reset(); |
| 333 | g_Clip1.m_ptClip = point; |
| 334 | g_Clip1.Set( true ); |
| 335 | } |
| 336 | |
| 337 | Clip_Update(); |
| 338 | ClipperChangeNotify(); |
| 339 | } |
| 340 | |
| 341 | |
| 342 | |
| 343 | struct xywindow_globals_private_t |
| 344 | { |
| 345 | bool d_showgrid; |
| 346 | |
| 347 | // these are in the View > Show menu with Show coordinates |
| 348 | bool show_names; |
| 349 | bool show_coordinates; |
| 350 | bool show_angles; |
| 351 | bool show_outline; |
| 352 | bool show_axis; |
| 353 | |
| 354 | bool d_show_work; |
| 355 | |
| 356 | bool show_blocks; |
| 357 | int blockSize; |
| 358 | |
| 359 | // bool m_bCamXYUpdate; |
| 360 | bool m_bChaseMouse; |
| 361 | bool m_bSizePaint; |
| 362 | |
| 363 | bool g_bCrossHairs; |
| 364 | |
| 365 | xywindow_globals_private_t() : |
| 366 | d_showgrid( true ), |
| 367 | |
| 368 | show_names( false ), |
| 369 | show_coordinates( false ), |
| 370 | show_angles( true ), |
| 371 | show_outline( true ), |
| 372 | show_axis( true ), |
| 373 | |
| 374 | d_show_work( false ), |
| 375 | |
| 376 | show_blocks( false ), |
| 377 | |
| 378 | // m_bCamXYUpdate( true ), |
| 379 | m_bChaseMouse( true ), |
| 380 | m_bSizePaint( true ), |
| 381 | |
| 382 | g_bCrossHairs( false ){ |
| 383 | } |
| 384 | |
| 385 | }; |
| 386 | |
| 387 | xywindow_globals_t g_xywindow_globals; |
| 388 | xywindow_globals_private_t g_xywindow_globals_private; |
| 389 | |
| 390 | const unsigned int RAD_NONE = 0x00; |
| 391 | const unsigned int RAD_SHIFT = 0x01; |
| 392 | const unsigned int RAD_ALT = 0x02; |
| 393 | const unsigned int RAD_CONTROL = 0x04; |
| 394 | const unsigned int RAD_PRESS = 0x08; |
| 395 | const unsigned int RAD_LBUTTON = 0x10; |
| 396 | const unsigned int RAD_MBUTTON = 0x20; |
| 397 | const unsigned int RAD_RBUTTON = 0x40; |
| 398 | |
| 399 | inline ButtonIdentifier button_for_flags( unsigned int flags ){ |
| 400 | if ( flags & RAD_LBUTTON ) { |
| 401 | return c_buttonLeft; |
| 402 | } |
| 403 | if ( flags & RAD_RBUTTON ) { |
| 404 | return c_buttonRight; |
| 405 | } |
| 406 | if ( flags & RAD_MBUTTON ) { |
| 407 | return c_buttonMiddle; |
| 408 | } |
| 409 | return c_buttonInvalid; |
| 410 | } |
| 411 | |
| 412 | inline ModifierFlags modifiers_for_flags( unsigned int flags ){ |
| 413 | ModifierFlags modifiers = c_modifierNone; |
| 414 | if ( flags & RAD_SHIFT ) { |
| 415 | modifiers |= c_modifierShift; |
| 416 | } |
| 417 | if ( flags & RAD_CONTROL ) { |
| 418 | modifiers |= c_modifierControl; |
| 419 | } |
| 420 | if ( flags & RAD_ALT ) { |
| 421 | modifiers |= c_modifierAlt; |
| 422 | } |
| 423 | return modifiers; |
| 424 | } |
| 425 | |
| 426 | inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){ |
| 427 | unsigned int buttons = 0; |
| 428 | |
| 429 | switch ( button.get() ) |
| 430 | { |
| 431 | case ButtonEnumeration::INVALID: break; |
| 432 | case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break; |
| 433 | case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break; |
| 434 | case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break; |
| 435 | } |
| 436 | |
| 437 | if ( bitfield_enabled( flags, c_modifierControl ) ) { |
| 438 | buttons |= RAD_CONTROL; |
| 439 | } |
| 440 | |
| 441 | if ( bitfield_enabled( flags, c_modifierShift ) ) { |
| 442 | buttons |= RAD_SHIFT; |
| 443 | } |
| 444 | |
| 445 | if ( bitfield_enabled( flags, c_modifierAlt ) ) { |
| 446 | buttons |= RAD_ALT; |
| 447 | } |
| 448 | |
| 449 | return buttons; |
| 450 | } |
| 451 | |
| 452 | inline unsigned int buttons_for_event_button( GdkEventButton* event ){ |
| 453 | unsigned int flags = 0; |
| 454 | |
| 455 | switch ( event->button ) |
| 456 | { |
| 457 | case 1: flags |= RAD_LBUTTON; break; |
| 458 | case 2: flags |= RAD_MBUTTON; break; |
| 459 | case 3: flags |= RAD_RBUTTON; break; |
| 460 | } |
| 461 | |
| 462 | if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) { |
| 463 | flags |= RAD_CONTROL; |
| 464 | } |
| 465 | |
| 466 | if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) { |
| 467 | flags |= RAD_SHIFT; |
| 468 | } |
| 469 | |
| 470 | if ( ( event->state & GDK_MOD1_MASK ) != 0 ) { |
| 471 | flags |= RAD_ALT; |
| 472 | } |
| 473 | |
| 474 | return flags; |
| 475 | } |
| 476 | |
| 477 | inline unsigned int buttons_for_state( guint state ){ |
| 478 | unsigned int flags = 0; |
| 479 | |
| 480 | if ( ( state & GDK_BUTTON1_MASK ) != 0 ) { |
| 481 | flags |= RAD_LBUTTON; |
| 482 | } |
| 483 | |
| 484 | if ( ( state & GDK_BUTTON2_MASK ) != 0 ) { |
| 485 | flags |= RAD_MBUTTON; |
| 486 | } |
| 487 | |
| 488 | if ( ( state & GDK_BUTTON3_MASK ) != 0 ) { |
| 489 | flags |= RAD_RBUTTON; |
| 490 | } |
| 491 | |
| 492 | if ( ( state & GDK_CONTROL_MASK ) != 0 ) { |
| 493 | flags |= RAD_CONTROL; |
| 494 | } |
| 495 | |
| 496 | if ( ( state & GDK_SHIFT_MASK ) != 0 ) { |
| 497 | flags |= RAD_SHIFT; |
| 498 | } |
| 499 | |
| 500 | if ( ( state & GDK_MOD1_MASK ) != 0 ) { |
| 501 | flags |= RAD_ALT; |
| 502 | } |
| 503 | |
| 504 | return flags; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | void XYWnd::SetScale( float f ){ |
| 509 | m_fScale = f; |
| 510 | updateProjection(); |
| 511 | updateModelview(); |
| 512 | XYWnd_Update( *this ); |
| 513 | } |
| 514 | |
| 515 | void XYWnd::ZoomIn(){ |
| 516 | float max_scale = 64; |
| 517 | float scale = Scale() * 5.0f / 4.0f; |
| 518 | if ( scale > max_scale ) { |
| 519 | if ( Scale() != max_scale ) { |
| 520 | SetScale( max_scale ); |
| 521 | } |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | SetScale( scale ); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | |
| 530 | // NOTE: the zoom out factor is 4/5, we could think about customizing it |
| 531 | // we don't go below a zoom factor corresponding to 10% of the max world size |
| 532 | // (this has to be computed against the window size) |
| 533 | void XYWnd::ZoomOut(){ |
| 534 | float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) ); |
| 535 | float scale = Scale() * 4.0f / 5.0f; |
| 536 | if ( scale < min_scale ) { |
| 537 | if ( Scale() != min_scale ) { |
| 538 | SetScale( min_scale ); |
| 539 | } |
| 540 | } |
| 541 | else |
| 542 | { |
| 543 | SetScale( scale ); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | void XYWnd::ZoomInWithMouse( int pointx, int pointy ){ |
| 548 | float old_scale = Scale(); |
| 549 | ZoomIn(); |
| 550 | if ( g_xywindow_globals.m_bZoomInToPointer ) { |
| 551 | float scale_diff = 1.0 / old_scale - 1.0 / Scale(); |
| 552 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 553 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 554 | Vector3 origin = GetOrigin(); |
| 555 | origin[nDim1] += scale_diff * (pointx - 0.5 * Width()); |
| 556 | origin[nDim2] -= scale_diff * (pointy - 0.5 * Height()); |
| 557 | SetOrigin( origin ); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | void XYWnd::Redraw() { |
| 562 | if ( glwidget_make_current( m_gl_widget ) != FALSE ) { |
| 563 | if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) { |
| 564 | GlobalOpenGL_debugAssertNoErrors(); |
| 565 | XY_Draw(); |
| 566 | GlobalOpenGL_debugAssertNoErrors(); |
| 567 | |
| 568 | m_XORRectangle.set( rectangle_t() ); |
| 569 | } |
| 570 | glwidget_swap_buffers( m_gl_widget ); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | void XYWnd::FocusOnBounds( AABB& bounds ){ |
| 575 | SetOrigin( bounds.origin ); |
| 576 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 577 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 578 | if( bounds.extents[ nDim1 ] < 128.f ) |
| 579 | bounds.extents[ nDim1 ] = 128.f; |
| 580 | if( bounds.extents[ nDim2 ] < 128.f ) |
| 581 | bounds.extents[ nDim2 ] = 128.f; |
| 582 | float scale1 = Width() / ( 3.f * bounds.extents[ nDim1 ] ); |
| 583 | float scale2 = Height() / ( 3.f * bounds.extents[ nDim2 ] ); |
| 584 | SetScale( MIN( scale1, scale2 ) ); |
| 585 | |
| 586 | } |
| 587 | |
| 588 | VIEWTYPE GlobalXYWnd_getCurrentViewType(){ |
| 589 | ASSERT_NOTNULL( g_pParentWnd ); |
| 590 | ASSERT_NOTNULL( g_pParentWnd->ActiveXY() ); |
| 591 | return g_pParentWnd->ActiveXY()->GetViewType(); |
| 592 | } |
| 593 | |
| 594 | // ============================================================================= |
| 595 | // variables |
| 596 | |
| 597 | ui::Menu XYWnd::m_mnuDrop(ui::null); |
| 598 | |
| 599 | // this is disabled, and broken |
| 600 | // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394 |
| 601 | #if 0 |
| 602 | void WXY_Print(){ |
| 603 | long width, height; |
| 604 | width = g_pParentWnd->ActiveXY()->Width(); |
| 605 | height = g_pParentWnd->ActiveXY()->Height(); |
| 606 | unsigned char* img; |
| 607 | const char* filename; |
| 608 | |
| 609 | filename = ui::file_dialog( MainFrame_getWindow( ), FALSE, "Save Image", 0, FILTER_BMP ); |
| 610 | if ( !filename ) { |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | g_pParentWnd->ActiveXY()->MakeCurrent(); |
| 615 | img = (unsigned char*)malloc( width * height * 3 ); |
| 616 | glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img ); |
| 617 | |
| 618 | FILE *fp; |
| 619 | fp = fopen( filename, "wb" ); |
| 620 | if ( fp ) { |
| 621 | unsigned short bits; |
| 622 | unsigned long cmap, bfSize; |
| 623 | |
| 624 | bits = 24; |
| 625 | cmap = 0; |
| 626 | bfSize = 54 + width * height * 3; |
| 627 | |
| 628 | long byteswritten = 0; |
| 629 | long pixoff = 54 + cmap * 4; |
| 630 | short res = 0; |
| 631 | char m1 = 'B', m2 = 'M'; |
| 632 | fwrite( &m1, 1, 1, fp ); byteswritten++; // B |
| 633 | fwrite( &m2, 1, 1, fp ); byteswritten++; // M |
| 634 | fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize |
| 635 | fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1 |
| 636 | fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2 |
| 637 | fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits |
| 638 | |
| 639 | unsigned long biSize = 40, compress = 0, size = 0; |
| 640 | long pixels = 0; |
| 641 | unsigned short planes = 1; |
| 642 | fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize |
| 643 | fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth |
| 644 | fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight |
| 645 | fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes |
| 646 | fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount |
| 647 | fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression |
| 648 | fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage |
| 649 | fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter |
| 650 | fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter |
| 651 | fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed |
| 652 | fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant |
| 653 | |
| 654 | unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 ); |
| 655 | long row, row_size = width * 3; |
| 656 | for ( row = 0; row < height; row++ ) |
| 657 | { |
| 658 | unsigned char* buf = img + row * row_size; |
| 659 | |
| 660 | // write a row |
| 661 | int col; |
| 662 | for ( col = 0; col < row_size; col += 3 ) |
| 663 | { |
| 664 | putc( buf[col + 2], fp ); |
| 665 | putc( buf[col + 1], fp ); |
| 666 | putc( buf[col], fp ); |
| 667 | } |
| 668 | byteswritten += row_size; |
| 669 | |
| 670 | unsigned long count; |
| 671 | for ( count = row_size; count < widthDW; count++ ) |
| 672 | { |
| 673 | putc( 0, fp ); // dummy |
| 674 | byteswritten++; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | fclose( fp ); |
| 679 | } |
| 680 | |
| 681 | free( img ); |
| 682 | } |
| 683 | #endif |
| 684 | |
| 685 | |
| 686 | #include "timer.h" |
| 687 | |
| 688 | Timer g_chasemouse_timer; |
| 689 | |
| 690 | void XYWnd::ChaseMouse(){ |
| 691 | float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f; |
| 692 | Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) ); |
| 693 | |
| 694 | //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n'; |
| 695 | |
| 696 | XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() ); |
| 697 | g_chasemouse_timer.start(); |
| 698 | } |
| 699 | |
| 700 | gboolean xywnd_chasemouse( gpointer data ){ |
| 701 | reinterpret_cast<XYWnd*>( data )->ChaseMouse(); |
| 702 | return TRUE; |
| 703 | } |
| 704 | |
| 705 | inline const int& min_int( const int& left, const int& right ){ |
| 706 | return std::min( left, right ); |
| 707 | } |
| 708 | |
| 709 | bool XYWnd::chaseMouseMotion( int pointx, int pointy ){ |
| 710 | m_chasemouse_delta_x = 0; |
| 711 | m_chasemouse_delta_y = 0; |
| 712 | |
| 713 | if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) { |
| 714 | const int epsilon = 16; |
| 715 | |
| 716 | if ( pointx < epsilon ) { |
| 717 | m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon; |
| 718 | } |
| 719 | else if ( ( pointx - m_nWidth ) > -epsilon ) { |
| 720 | m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon; |
| 721 | } |
| 722 | |
| 723 | if ( pointy < epsilon ) { |
| 724 | m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon; |
| 725 | } |
| 726 | else if ( ( pointy - m_nHeight ) > -epsilon ) { |
| 727 | m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon; |
| 728 | } |
| 729 | |
| 730 | if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) { |
| 731 | //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... "; |
| 732 | m_chasemouse_current_x = pointx; |
| 733 | m_chasemouse_current_y = pointy; |
| 734 | if ( m_chasemouse_handler == 0 ) { |
| 735 | //globalOutputStream() << "chasemouse timer start... "; |
| 736 | g_chasemouse_timer.start(); |
| 737 | m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this ); |
| 738 | } |
| 739 | return true; |
| 740 | } |
| 741 | else |
| 742 | { |
| 743 | if ( m_chasemouse_handler != 0 ) { |
| 744 | //globalOutputStream() << "chasemouse cancel\n"; |
| 745 | g_source_remove( m_chasemouse_handler ); |
| 746 | m_chasemouse_handler = 0; |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | else |
| 751 | { |
| 752 | if ( m_chasemouse_handler != 0 ) { |
| 753 | //globalOutputStream() << "chasemouse cancel\n"; |
| 754 | g_source_remove( m_chasemouse_handler ); |
| 755 | m_chasemouse_handler = 0; |
| 756 | } |
| 757 | } |
| 758 | return false; |
| 759 | } |
| 760 | |
| 761 | // ============================================================================= |
| 762 | // XYWnd class |
| 763 | Shader* XYWnd::m_state_selected = 0; |
| 764 | |
| 765 | void xy_update_xor_rectangle( XYWnd& self, rect_t area ){ |
| 766 | if ( self.GetWidget().visible() ) { |
| 767 | rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() ); |
| 768 | // int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0; |
| 769 | // int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2; |
| 770 | // rect.x /= self.Scale(); |
| 771 | // rect.y /= self.Scale(); |
| 772 | // rect.w /= self.Scale(); |
| 773 | // rect.h /= self.Scale(); |
| 774 | // rect.x += self.GetOrigin()[nDim1]; |
| 775 | // rect.y += self.GetOrigin()[nDim2]; |
| 776 | self.m_XORRectangle.set( rect ); |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){ |
| 781 | if ( event->type == GDK_BUTTON_PRESS ) { |
| 782 | gtk_widget_grab_focus( xywnd->GetWidget() ); |
| 783 | |
| 784 | if( !xywnd->Active() ){ |
| 785 | g_pParentWnd->SetActiveXY( xywnd ); |
| 786 | } |
| 787 | |
| 788 | xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) ); |
| 789 | |
| 790 | xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) ); |
| 791 | } |
| 792 | return FALSE; |
| 793 | } |
| 794 | |
| 795 | gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){ |
| 796 | if ( event->type == GDK_BUTTON_RELEASE ) { |
| 797 | xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) ); |
| 798 | |
| 799 | xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) ); |
| 800 | } |
| 801 | return FALSE; |
| 802 | } |
| 803 | |
| 804 | gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){ |
| 805 | if ( event->type == GDK_FOCUS_CHANGE ) { |
| 806 | if ( event->in ) { |
| 807 | if( !xywnd->Active() ){ |
| 808 | g_pParentWnd->SetActiveXY( xywnd ); |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | return FALSE; |
| 813 | } |
| 814 | |
| 815 | void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){ |
| 816 | if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) { |
| 817 | return; |
| 818 | } |
| 819 | reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) ); |
| 820 | } |
| 821 | |
| 822 | gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){ |
| 823 | gtk_widget_grab_focus( xywnd->GetWidget() ); |
| 824 | ui::Window window = xywnd->m_parent ? xywnd->m_parent : MainFrame_getWindow(); |
| 825 | if( !gtk_window_is_active( window ) ) |
| 826 | gtk_window_present( window ); |
| 827 | |
| 828 | if( !xywnd->Active() ){ |
| 829 | g_pParentWnd->SetActiveXY( xywnd ); |
| 830 | } |
| 831 | if ( event->direction == GDK_SCROLL_UP ) { |
| 832 | xywnd->ZoomInWithMouse( (int)event->x, (int)event->y ); |
| 833 | } |
| 834 | else if ( event->direction == GDK_SCROLL_DOWN ) { |
| 835 | xywnd->ZoomOut(); |
| 836 | } |
| 837 | return FALSE; |
| 838 | } |
| 839 | |
| 840 | gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){ |
| 841 | xywnd->m_nWidth = allocation->width; |
| 842 | xywnd->m_nHeight = allocation->height; |
| 843 | xywnd->updateProjection(); |
| 844 | xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() ); |
| 845 | return FALSE; |
| 846 | } |
| 847 | |
| 848 | gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){ |
| 849 | xywnd->Redraw(); |
| 850 | return FALSE; |
| 851 | } |
| 852 | |
| 853 | void XYWnd_CameraMoved( XYWnd& xywnd ){ |
| 854 | // if ( g_xywindow_globals_private.m_bCamXYUpdate ) { |
| 855 | #if GTK_TARGET == 3 |
| 856 | XYWnd_Update( xywnd ); |
| 857 | #else |
| 858 | xywnd.UpdateCameraIcon(); |
| 859 | #endif |
| 860 | // } |
| 861 | } |
| 862 | |
| 863 | XYWnd::XYWnd() : |
| 864 | m_gl_widget( glwidget_new( FALSE ) ), |
| 865 | m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ), |
| 866 | m_deferred_motion( xywnd_motion, this ), |
| 867 | m_parent( ui::null ), |
| 868 | m_window_observer( NewWindowObserver() ), |
| 869 | m_XORRectangle( m_gl_widget ), |
| 870 | m_chasemouse_handler( 0 ){ |
| 871 | |
| 872 | m_bActive = false; |
| 873 | m_buttonstate = 0; |
| 874 | |
| 875 | m_bNewBrushDrag = false; |
| 876 | m_move_started = false; |
| 877 | m_zoom_started = false; |
| 878 | |
| 879 | m_nWidth = 0; |
| 880 | m_nHeight = 0; |
| 881 | |
| 882 | m_vOrigin[0] = 0; |
| 883 | m_vOrigin[1] = 20; |
| 884 | m_vOrigin[2] = 46; |
| 885 | m_fScale = 1; |
| 886 | m_viewType = XY; |
| 887 | |
| 888 | m_backgroundActivated = false; |
| 889 | m_alpha = 1.0f; |
| 890 | m_xmin = 0.0f; |
| 891 | m_ymin = 0.0f; |
| 892 | m_xmax = 0.0f; |
| 893 | m_ymax = 0.0f; |
| 894 | |
| 895 | m_entityCreate = false; |
| 896 | |
| 897 | m_mnuDrop = ui::Menu(ui::null); |
| 898 | |
| 899 | GlobalWindowObservers_add( m_window_observer ); |
| 900 | GlobalWindowObservers_connectWidget( m_gl_widget ); |
| 901 | |
| 902 | m_window_observer->setRectangleDrawCallback( ReferenceCaller<XYWnd, void(rect_t), xy_update_xor_rectangle>( *this ) ); |
| 903 | m_window_observer->setView( m_view ); |
| 904 | |
| 905 | g_object_ref( m_gl_widget._handle ); |
| 906 | |
| 907 | gtk_widget_set_events( m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK ); |
| 908 | gtk_widget_set_can_focus( m_gl_widget, true ); |
| 909 | |
| 910 | m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this ); |
| 911 | m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this ); |
| 912 | |
| 913 | m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this ); |
| 914 | m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this ); |
| 915 | m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this ); //works only in floating views layout |
| 916 | m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion ); |
| 917 | |
| 918 | m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this ); |
| 919 | |
| 920 | Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) ); |
| 921 | |
| 922 | // This reconstruct=false argument is used to avoid a circular dependency |
| 923 | // between modelview and projection initialization and a valgrind complaint |
| 924 | updateProjection( false ); |
| 925 | updateModelview( false ); |
| 926 | m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight ); |
| 927 | |
| 928 | AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) ); |
| 929 | AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) ); |
| 930 | |
| 931 | PressedButtons_connect( g_pressedButtons, m_gl_widget ); |
| 932 | |
| 933 | onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) ); |
| 934 | } |
| 935 | |
| 936 | XYWnd::~XYWnd(){ |
| 937 | onDestroyed(); |
| 938 | |
| 939 | if ( m_mnuDrop ) { |
| 940 | m_mnuDrop.destroy(); |
| 941 | m_mnuDrop = ui::Menu(ui::null); |
| 942 | } |
| 943 | |
| 944 | g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler ); |
| 945 | g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler ); |
| 946 | |
| 947 | m_gl_widget.unref(); |
| 948 | |
| 949 | m_window_observer->release(); |
| 950 | } |
| 951 | |
| 952 | void XYWnd::captureStates(){ |
| 953 | m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" ); |
| 954 | } |
| 955 | |
| 956 | void XYWnd::releaseStates(){ |
| 957 | GlobalShaderCache().release( "$XY_OVERLAY" ); |
| 958 | } |
| 959 | |
| 960 | const Vector3& XYWnd::GetOrigin(){ |
| 961 | return m_vOrigin; |
| 962 | } |
| 963 | |
| 964 | void XYWnd::SetOrigin( const Vector3& origin ){ |
| 965 | m_vOrigin = origin; |
| 966 | updateModelview(); |
| 967 | } |
| 968 | |
| 969 | void XYWnd::Scroll( int x, int y ){ |
| 970 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 971 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 972 | m_vOrigin[nDim1] += x / m_fScale; |
| 973 | m_vOrigin[nDim2] += y / m_fScale; |
| 974 | updateModelview(); |
| 975 | queueDraw(); |
| 976 | } |
| 977 | |
| 978 | unsigned int Clipper_buttons(){ |
| 979 | return RAD_LBUTTON; |
| 980 | } |
| 981 | |
| 982 | unsigned int Clipper_quick_buttons(){ |
| 983 | return RAD_LBUTTON | RAD_CONTROL; |
| 984 | } |
| 985 | |
| 986 | void XYWnd::DropClipPoint( int pointx, int pointy ){ |
| 987 | Vector3 point; |
| 988 | |
| 989 | XY_ToPoint( pointx, pointy, point ); |
| 990 | |
| 991 | Vector3 mid; |
| 992 | Select_GetMid( mid ); |
| 993 | g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() ); |
| 994 | const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 ); |
| 995 | point[nDim] = mid[nDim]; |
| 996 | vector3_snap( point, GetSnapGridSize() ); |
| 997 | NewClipPoint( point ); |
| 998 | } |
| 999 | |
| 1000 | void XYWnd::Clipper_OnLButtonDown( int x, int y ){ |
| 1001 | Vector3 mousePosition; |
| 1002 | XY_ToPoint( x, y, mousePosition ); |
| 1003 | g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ); |
| 1004 | if ( !g_pMovingClip ) { |
| 1005 | DropClipPoint( x, y ); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | void XYWnd::Clipper_OnLButtonUp( int x, int y ){ |
| 1010 | if ( g_pMovingClip ) { |
| 1011 | g_pMovingClip = 0; |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | void XYWnd::Clipper_OnMouseMoved( int x, int y ){ |
| 1016 | if ( g_pMovingClip ) { |
| 1017 | XY_ToPoint( x, y, g_pMovingClip->m_ptClip ); |
| 1018 | XY_SnapToGrid( g_pMovingClip->m_ptClip ); |
| 1019 | Clip_Update(); |
| 1020 | ClipperChangeNotify(); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | //#include "gtkutil/image.h" |
| 1025 | |
| 1026 | /* is called on every mouse move fraction; ain't good! */ |
| 1027 | void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){ |
| 1028 | Vector3 mousePosition; |
| 1029 | XY_ToPoint( x, y, mousePosition ); |
| 1030 | #if 0 // NetRadiantCustom |
| 1031 | if ( ClipMode() ) { |
| 1032 | if( GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ){ |
| 1033 | GdkCursor *cursor; |
| 1034 | cursor = gdk_cursor_new( GDK_CROSSHAIR ); |
| 1035 | //cursor = gdk_cursor_new( GDK_FLEUR ); |
| 1036 | gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor ); |
| 1037 | gdk_cursor_unref( cursor ); |
| 1038 | } |
| 1039 | else{ |
| 1040 | GdkCursor *cursor; |
| 1041 | cursor = gdk_cursor_new( GDK_HAND2 ); |
| 1042 | // GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" ); |
| 1043 | // cursor = gdk_cursor_new_from_pixbuf( gdk_display_get_default(), pixbuf, 0, 0 ); |
| 1044 | // g_object_unref( pixbuf ); |
| 1045 | gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor ); |
| 1046 | gdk_cursor_unref( cursor ); |
| 1047 | |
| 1048 | } |
| 1049 | } |
| 1050 | #else |
| 1051 | if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) { |
| 1052 | set_cursor ( m_gl_widget, GDK_CROSSHAIR ); |
| 1053 | } |
| 1054 | #endif |
| 1055 | else |
| 1056 | { |
| 1057 | default_cursor( m_gl_widget ); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | void XYWnd::SetCustomPivotOrigin( int pointx, int pointy ){ |
| 1062 | Vector3 point; |
| 1063 | XY_ToPoint( pointx, pointy, point ); |
| 1064 | VIEWTYPE viewtype = static_cast<VIEWTYPE>( GetViewType() ); |
| 1065 | const int nDim = ( viewtype == YZ ) ? 0 : ( ( viewtype == XZ ) ? 1 : 2 ); |
| 1066 | //vector3_snap( point, GetSnapGridSize() ); |
| 1067 | point[nDim] = 999999; |
| 1068 | |
| 1069 | GlobalSelectionSystem().setCustomPivotOrigin( point ); |
| 1070 | SceneChangeNotify(); |
| 1071 | } |
| 1072 | |
| 1073 | unsigned int MoveCamera_buttons(){ |
| 1074 | // return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON ); |
| 1075 | return RAD_CONTROL | RAD_MBUTTON; |
| 1076 | } |
| 1077 | |
| 1078 | void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){ |
| 1079 | Vector3 origin( Camera_getOrigin( camwnd ) ); |
| 1080 | xywnd->XY_ToPoint( x, y, origin ); |
| 1081 | xywnd->XY_SnapToGrid( origin ); |
| 1082 | Camera_setOrigin( camwnd, origin ); |
| 1083 | } |
| 1084 | |
| 1085 | unsigned int OrientCamera_buttons(){ |
| 1086 | // if ( g_glwindow_globals.m_nMouseType == ETwoButton ) { |
| 1087 | // return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL; |
| 1088 | // } |
| 1089 | return RAD_MBUTTON; |
| 1090 | } |
| 1091 | |
| 1092 | void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){ |
| 1093 | //globalOutputStream() << Camera_getAngles( camwnd ) << " b4\n"; |
| 1094 | Vector3 point = g_vector3_identity; |
| 1095 | xywnd->XY_ToPoint( x, y, point ); |
| 1096 | //xywnd->XY_SnapToGrid( point ); |
| 1097 | vector3_subtract( point, Camera_getOrigin( camwnd ) ); |
| 1098 | |
| 1099 | int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2; |
| 1100 | int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0; |
| 1101 | int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH; |
| 1102 | if ( point[n1] || point[n2] ) { |
| 1103 | Vector3 angles( Camera_getAngles( camwnd ) ); |
| 1104 | angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) ); |
| 1105 | if( angles[CAMERA_YAW] < 0 ) |
| 1106 | angles[CAMERA_YAW] = angles[CAMERA_YAW] + 360; |
| 1107 | if ( nAngle == CAMERA_PITCH ){ |
| 1108 | if( fabs( angles[CAMERA_PITCH] ) > 90 ){ |
| 1109 | angles[CAMERA_PITCH] = ( angles[CAMERA_PITCH] > 0 ) ? ( -angles[CAMERA_PITCH] + 180 ) : ( -angles[CAMERA_PITCH] - 180 ); |
| 1110 | if( xywnd->GetViewType() == YZ ){ |
| 1111 | if( angles[CAMERA_YAW] < 180 ){ |
| 1112 | angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW]; |
| 1113 | } |
| 1114 | } |
| 1115 | else if( angles[CAMERA_YAW] < 90 || angles[CAMERA_YAW] > 270 ){ |
| 1116 | angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW]; |
| 1117 | } |
| 1118 | } |
| 1119 | else{ |
| 1120 | if( xywnd->GetViewType() == YZ ){ |
| 1121 | if( angles[CAMERA_YAW] > 180 ){ |
| 1122 | angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW]; |
| 1123 | } |
| 1124 | } |
| 1125 | else if( angles[CAMERA_YAW] > 90 && angles[CAMERA_YAW] < 270 ){ |
| 1126 | angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW]; |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | Camera_setAngles( camwnd, angles ); |
| 1131 | } |
| 1132 | //globalOutputStream() << Camera_getAngles( camwnd ) << "\n"; |
| 1133 | } |
| 1134 | |
| 1135 | unsigned int SetCustomPivotOrigin_buttons(){ |
| 1136 | return RAD_MBUTTON | RAD_SHIFT; |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | ============== |
| 1141 | NewBrushDrag |
| 1142 | ============== |
| 1143 | */ |
| 1144 | unsigned int NewBrushDrag_buttons(){ |
| 1145 | return RAD_LBUTTON; |
| 1146 | } |
| 1147 | |
| 1148 | void XYWnd::NewBrushDrag_Begin( int x, int y ){ |
| 1149 | m_NewBrushDrag = 0; |
| 1150 | m_nNewBrushPressx = x; |
| 1151 | m_nNewBrushPressy = y; |
| 1152 | |
| 1153 | m_bNewBrushDrag = true; |
| 1154 | } |
| 1155 | |
| 1156 | void XYWnd::NewBrushDrag_End( int x, int y ){ |
| 1157 | if ( m_NewBrushDrag != 0 ) { |
| 1158 | GlobalUndoSystem().finish( "brushDragNew" ); |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | void XYWnd::NewBrushDrag( int x, int y ){ |
| 1163 | Vector3 mins, maxs; |
| 1164 | XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins ); |
| 1165 | XY_SnapToGrid( mins ); |
| 1166 | XY_ToPoint( x, y, maxs ); |
| 1167 | XY_SnapToGrid( maxs ); |
| 1168 | |
| 1169 | int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1; |
| 1170 | |
| 1171 | mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() ); |
| 1172 | maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() ); |
| 1173 | |
| 1174 | if ( maxs[nDim] <= mins[nDim] ) { |
| 1175 | maxs[nDim] = mins[nDim] + GetGridSize(); |
| 1176 | } |
| 1177 | |
| 1178 | for ( int i = 0 ; i < 3 ; i++ ) |
| 1179 | { |
| 1180 | if ( mins[i] == maxs[i] ) { |
| 1181 | return; // don't create a degenerate brush |
| 1182 | } |
| 1183 | if ( mins[i] > maxs[i] ) { |
| 1184 | float temp = mins[i]; |
| 1185 | mins[i] = maxs[i]; |
| 1186 | maxs[i] = temp; |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | if ( m_NewBrushDrag == 0 ) { |
| 1191 | GlobalUndoSystem().start(); |
| 1192 | NodeSmartReference node( GlobalBrushCreator().createBrush() ); |
| 1193 | Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node ); |
| 1194 | |
| 1195 | scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) ); |
| 1196 | brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) ); |
| 1197 | brushpath.push( makeReference( node.get() ) ); |
| 1198 | selectPath( brushpath, true ); |
| 1199 | |
| 1200 | m_NewBrushDrag = node.get_pointer(); |
| 1201 | } |
| 1202 | |
| 1203 | // d1223m |
| 1204 | //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser())); |
| 1205 | Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ), |
| 1206 | g_brush_always_caulk ? |
| 1207 | "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) ); |
| 1208 | } |
| 1209 | |
| 1210 | void entitycreate_activated( ui::Widget item ){ |
| 1211 | scene::Node* world_node = Map_FindWorldspawn( g_map ); |
| 1212 | const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) ); |
| 1213 | |
| 1214 | if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) { |
| 1215 | g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name ); |
| 1216 | } |
| 1217 | else { |
| 1218 | GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(), |
| 1219 | "There's already a worldspawn in your map!", |
| 1220 | "Info", |
| 1221 | eMB_OK, |
| 1222 | eMB_ICONDEFAULT ); |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | void EntityClassMenu_addItem( ui::Menu menu, const char* name ){ |
| 1227 | auto item = ui::MenuItem( name ); |
| 1228 | item.connect( "activate", G_CALLBACK( entitycreate_activated ), item ); |
| 1229 | item.show(); |
| 1230 | menu_add_item( menu, item ); |
| 1231 | } |
| 1232 | |
| 1233 | class EntityClassMenuInserter : public EntityClassVisitor |
| 1234 | { |
| 1235 | typedef std::pair<ui::Menu, CopiedString> MenuPair; |
| 1236 | typedef std::vector<MenuPair> MenuStack; |
| 1237 | MenuStack m_stack; |
| 1238 | CopiedString m_previous; |
| 1239 | public: |
| 1240 | EntityClassMenuInserter( ui::Menu menu ){ |
| 1241 | m_stack.reserve( 2 ); |
| 1242 | m_stack.push_back( MenuPair( menu, "" ) ); |
| 1243 | } |
| 1244 | ~EntityClassMenuInserter(){ |
| 1245 | if ( !string_empty( m_previous.c_str() ) ) { |
| 1246 | addItem( m_previous.c_str(), "" ); |
| 1247 | } |
| 1248 | } |
| 1249 | void visit( EntityClass* e ){ |
| 1250 | ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" ); |
| 1251 | if ( !string_empty( m_previous.c_str() ) ) { |
| 1252 | addItem( m_previous.c_str(), e->name() ); |
| 1253 | } |
| 1254 | m_previous = e->name(); |
| 1255 | } |
| 1256 | void pushMenu( const CopiedString& name ){ |
| 1257 | auto item = ui::MenuItem( name.c_str() ); |
| 1258 | item.show(); |
| 1259 | m_stack.back().first.add(item); |
| 1260 | |
| 1261 | auto submenu = ui::Menu(ui::New); |
| 1262 | gtk_menu_item_set_submenu( item, submenu ); |
| 1263 | |
| 1264 | m_stack.push_back( MenuPair( submenu, name ) ); |
| 1265 | } |
| 1266 | void popMenu(){ |
| 1267 | m_stack.pop_back(); |
| 1268 | } |
| 1269 | void addItem( const char* name, const char* next ){ |
| 1270 | const char* underscore = strchr( name, '_' ); |
| 1271 | |
| 1272 | if ( underscore != 0 && underscore != name ) { |
| 1273 | bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name ); |
| 1274 | const char* parent = m_stack.back().second.c_str(); |
| 1275 | |
| 1276 | if ( !string_empty( parent ) |
| 1277 | && string_length( parent ) == std::size_t( underscore - name ) |
| 1278 | && string_equal_n( name, parent, underscore - name ) ) { // this is a child |
| 1279 | } |
| 1280 | else if ( nextEqual ) { |
| 1281 | if ( m_stack.size() == 2 ) { |
| 1282 | popMenu(); |
| 1283 | } |
| 1284 | pushMenu( CopiedString( StringRange( name, underscore ) ) ); |
| 1285 | } |
| 1286 | else if ( m_stack.size() == 2 ) { |
| 1287 | popMenu(); |
| 1288 | } |
| 1289 | } |
| 1290 | else if ( m_stack.size() == 2 ) { |
| 1291 | popMenu(); |
| 1292 | } |
| 1293 | |
| 1294 | EntityClassMenu_addItem( m_stack.back().first, name ); |
| 1295 | } |
| 1296 | }; |
| 1297 | |
| 1298 | void XYWnd::OnContextMenu(){ |
| 1299 | // if ( g_xywindow_globals.m_bRightClick == false ) { |
| 1300 | // return; |
| 1301 | // } |
| 1302 | |
| 1303 | if ( !m_mnuDrop ) { // first time, load it up |
| 1304 | auto menu = m_mnuDrop = ui::Menu(ui::New); |
| 1305 | |
| 1306 | EntityClassMenuInserter inserter( menu ); |
| 1307 | GlobalEntityClassManager().forEach( inserter ); |
| 1308 | } |
| 1309 | |
| 1310 | gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME ); |
| 1311 | } |
| 1312 | |
| 1313 | FreezePointer g_xywnd_freezePointer; |
| 1314 | |
| 1315 | unsigned int Move_buttons(){ |
| 1316 | return RAD_RBUTTON; |
| 1317 | } |
| 1318 | |
| 1319 | void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){ |
| 1320 | reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y ); |
| 1321 | reinterpret_cast<XYWnd*>( data )->Scroll( -x, y ); |
| 1322 | } |
| 1323 | |
| 1324 | gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){ |
| 1325 | xywnd->Move_End(); |
| 1326 | return FALSE; |
| 1327 | } |
| 1328 | |
| 1329 | void XYWnd::Move_Begin(){ |
| 1330 | if ( m_move_started ) { |
| 1331 | Move_End(); |
| 1332 | } |
| 1333 | m_move_started = true; |
| 1334 | /* NetRadiantCustom did this instead: |
| 1335 | g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this ); */ |
| 1336 | g_xywnd_freezePointer.freeze_pointer( m_gl_widget, XYWnd_moveDelta, this ); |
| 1337 | m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this ); |
| 1338 | } |
| 1339 | |
| 1340 | void XYWnd::Move_End(){ |
| 1341 | m_move_started = false; |
| 1342 | /* NetRadiant did this instead: |
| 1343 | g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false ); */ |
| 1344 | g_xywnd_freezePointer.unfreeze_pointer( m_gl_widget, false ); |
| 1345 | g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut ); |
| 1346 | } |
| 1347 | |
| 1348 | unsigned int Zoom_buttons(){ |
| 1349 | return RAD_RBUTTON | RAD_ALT; |
| 1350 | } |
| 1351 | |
| 1352 | int g_dragZoom = 0; |
| 1353 | int g_zoom2x = 0; |
| 1354 | int g_zoom2y = 0; |
| 1355 | |
| 1356 | void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){ |
| 1357 | if ( y != 0 ) { |
| 1358 | g_dragZoom += y; |
| 1359 | while ( abs( g_dragZoom ) > 8 ) |
| 1360 | { |
| 1361 | if ( g_dragZoom > 0 ) { |
| 1362 | reinterpret_cast<XYWnd*>( data )->ZoomOut(); |
| 1363 | g_dragZoom -= 8; |
| 1364 | } |
| 1365 | else |
| 1366 | { |
| 1367 | if ( g_xywindow_globals.m_bZoomInToPointer ) { |
| 1368 | reinterpret_cast<XYWnd*>( data )->ZoomInWithMouse( g_zoom2x, g_zoom2y ); |
| 1369 | } |
| 1370 | else{ |
| 1371 | reinterpret_cast<XYWnd*>( data )->ZoomIn(); |
| 1372 | } |
| 1373 | g_dragZoom += 8; |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){ |
| 1380 | xywnd->Zoom_End(); |
| 1381 | return FALSE; |
| 1382 | } |
| 1383 | |
| 1384 | void XYWnd::Zoom_Begin( int x, int y ){ |
| 1385 | if ( m_zoom_started ) { |
| 1386 | Zoom_End(); |
| 1387 | } |
| 1388 | m_zoom_started = true; |
| 1389 | g_dragZoom = 0; |
| 1390 | g_zoom2x = x; |
| 1391 | g_zoom2y = y; |
| 1392 | /* NetRadiantCustom did this instead: |
| 1393 | g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this ); */ |
| 1394 | g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this ); |
| 1395 | m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this ); |
| 1396 | } |
| 1397 | |
| 1398 | void XYWnd::Zoom_End(){ |
| 1399 | m_zoom_started = false; |
| 1400 | g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false ); |
| 1401 | g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut ); |
| 1402 | } |
| 1403 | |
| 1404 | // makes sure the selected brush or camera is in view |
| 1405 | void XYWnd::PositionView( const Vector3& position ){ |
| 1406 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 1407 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 1408 | |
| 1409 | m_vOrigin[nDim1] = position[nDim1]; |
| 1410 | m_vOrigin[nDim2] = position[nDim2]; |
| 1411 | |
| 1412 | updateModelview(); |
| 1413 | |
| 1414 | XYWnd_Update( *this ); |
| 1415 | } |
| 1416 | |
| 1417 | void XYWnd::SetViewType( VIEWTYPE viewType ){ |
| 1418 | m_viewType = viewType; |
| 1419 | updateModelview(); |
| 1420 | |
| 1421 | if ( m_parent ) { |
| 1422 | gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) ); |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | |
| 1427 | inline WindowVector WindowVector_forInteger( int x, int y ){ |
| 1428 | return WindowVector( static_cast<float>( x ), static_cast<float>( y ) ); |
| 1429 | } |
| 1430 | |
| 1431 | void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){ |
| 1432 | XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) ); |
| 1433 | } |
| 1434 | void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){ |
| 1435 | if ( buttons == Move_buttons() ) { |
| 1436 | Move_Begin(); |
| 1437 | EntityCreate_MouseDown( x, y ); |
| 1438 | } |
| 1439 | else if ( buttons == Zoom_buttons() ) { |
| 1440 | Zoom_Begin( x, y ); |
| 1441 | } |
| 1442 | else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) { |
| 1443 | Clipper_OnLButtonDown( x, y ); |
| 1444 | } |
| 1445 | else if ( !ClipMode() && buttons == Clipper_quick_buttons() ) { |
| 1446 | ClipperMode(); |
| 1447 | g_quick_clipper = true; |
| 1448 | Clipper_OnLButtonDown( x, y ); |
| 1449 | } |
| 1450 | else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) { |
| 1451 | NewBrushDrag_Begin( x, y ); |
| 1452 | } |
| 1453 | // control mbutton = move camera |
| 1454 | else if ( buttons == MoveCamera_buttons() ) { |
| 1455 | XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() ); |
| 1456 | } |
| 1457 | // mbutton = angle camera |
| 1458 | else if ( buttons == OrientCamera_buttons() ) { |
| 1459 | XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() ); |
| 1460 | } |
| 1461 | else if ( buttons == SetCustomPivotOrigin_buttons() ) { |
| 1462 | SetCustomPivotOrigin( x, y ); |
| 1463 | } |
| 1464 | else |
| 1465 | { |
| 1466 | m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) ); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){ |
| 1471 | if ( m_move_started ) { |
| 1472 | Move_End(); |
| 1473 | EntityCreate_MouseUp( x, y ); |
| 1474 | } |
| 1475 | else if ( m_zoom_started ) { |
| 1476 | Zoom_End(); |
| 1477 | } |
| 1478 | else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) { |
| 1479 | Clipper_OnLButtonUp( x, y ); |
| 1480 | } |
| 1481 | else if ( m_bNewBrushDrag ) { |
| 1482 | m_bNewBrushDrag = false; |
| 1483 | NewBrushDrag_End( x, y ); |
| 1484 | if ( m_NewBrushDrag == 0 ) { |
| 1485 | //L button w/o created brush = tunnel selection |
| 1486 | m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) ); |
| 1487 | } |
| 1488 | } |
| 1489 | else |
| 1490 | { |
| 1491 | m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) ); |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){ |
| 1496 | // rbutton = drag xy origin |
| 1497 | if ( m_move_started ) { |
| 1498 | } |
| 1499 | // zoom in/out |
| 1500 | else if ( m_zoom_started ) { |
| 1501 | } |
| 1502 | |
| 1503 | else if ( ClipMode() && g_pMovingClip != 0 ) { |
| 1504 | Clipper_OnMouseMoved( x, y ); |
| 1505 | } |
| 1506 | // lbutton without selection = drag new brush |
| 1507 | else if ( m_bNewBrushDrag ) { |
| 1508 | NewBrushDrag( x, y ); |
| 1509 | } |
| 1510 | |
| 1511 | // control mbutton = move camera |
| 1512 | else if ( buttons == MoveCamera_buttons() ) { |
| 1513 | XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() ); |
| 1514 | } |
| 1515 | |
| 1516 | // mbutton = angle camera |
| 1517 | else if ( buttons == OrientCamera_buttons() ) { |
| 1518 | XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() ); |
| 1519 | } |
| 1520 | |
| 1521 | else if ( buttons == SetCustomPivotOrigin_buttons() ) { |
| 1522 | SetCustomPivotOrigin( x, y ); |
| 1523 | } |
| 1524 | |
| 1525 | else |
| 1526 | { |
| 1527 | m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) ); |
| 1528 | |
| 1529 | m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0; |
| 1530 | XY_ToPoint( x, y, m_mousePosition ); |
| 1531 | XY_SnapToGrid( m_mousePosition ); |
| 1532 | |
| 1533 | StringOutputStream status( 64 ); |
| 1534 | status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 ) |
| 1535 | << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 ) |
| 1536 | << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 ); |
| 1537 | g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() ); |
| 1538 | |
| 1539 | if ( g_xywindow_globals_private.g_bCrossHairs ) { |
| 1540 | XYWnd_Update( *this ); |
| 1541 | } |
| 1542 | |
| 1543 | Clipper_Crosshair_OnMouseMoved( x, y ); |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | void XYWnd::EntityCreate_MouseDown( int x, int y ){ |
| 1548 | m_entityCreate = true; |
| 1549 | m_entityCreate_x = x; |
| 1550 | m_entityCreate_y = y; |
| 1551 | } |
| 1552 | |
| 1553 | void XYWnd::EntityCreate_MouseMove( int x, int y ){ |
| 1554 | if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) { |
| 1555 | m_entityCreate = false; |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | void XYWnd::EntityCreate_MouseUp( int x, int y ){ |
| 1560 | if ( m_entityCreate ) { |
| 1561 | m_entityCreate = false; |
| 1562 | OnContextMenu(); |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | inline float screen_normalised( int pos, unsigned int size ){ |
| 1567 | return ( ( 2.0f * pos ) / size ) - 1.0f; |
| 1568 | } |
| 1569 | |
| 1570 | inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){ |
| 1571 | return world_origin + normalised * normalised2world_scale; |
| 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | // TTimo: watch it, this doesn't init one of the 3 coords |
| 1576 | void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){ |
| 1577 | float normalised2world_scale_x = m_nWidth / 2 / m_fScale; |
| 1578 | float normalised2world_scale_y = m_nHeight / 2 / m_fScale; |
| 1579 | if ( m_viewType == XY ) { |
| 1580 | point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x ); |
| 1581 | point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y ); |
| 1582 | } |
| 1583 | else if ( m_viewType == YZ ) { |
| 1584 | point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x ); |
| 1585 | point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y ); |
| 1586 | } |
| 1587 | else |
| 1588 | { |
| 1589 | point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x ); |
| 1590 | point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y ); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | void XYWnd::XY_SnapToGrid( Vector3& point ){ |
| 1595 | if ( m_viewType == XY ) { |
| 1596 | point[0] = float_snapped( point[0], GetSnapGridSize() ); |
| 1597 | point[1] = float_snapped( point[1], GetSnapGridSize() ); |
| 1598 | } |
| 1599 | else if ( m_viewType == YZ ) { |
| 1600 | point[1] = float_snapped( point[1], GetSnapGridSize() ); |
| 1601 | point[2] = float_snapped( point[2], GetSnapGridSize() ); |
| 1602 | } |
| 1603 | else |
| 1604 | { |
| 1605 | point[0] = float_snapped( point[0], GetSnapGridSize() ); |
| 1606 | point[2] = float_snapped( point[2], GetSnapGridSize() ); |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | void XYWnd::XY_LoadBackgroundImage( const char *name ){ |
| 1611 | const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) ); |
| 1612 | if ( relative == name ) { |
| 1613 | globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n"; |
| 1614 | } |
| 1615 | |
| 1616 | char fileNameWithoutExt[512]; |
| 1617 | strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 ); |
| 1618 | fileNameWithoutExt[512 - 1] = '\0'; |
| 1619 | fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0'; |
| 1620 | |
| 1621 | Image *image = QERApp_LoadImage( 0, fileNameWithoutExt ); |
| 1622 | if ( !image ) { |
| 1623 | globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n"; |
| 1624 | return; |
| 1625 | } |
| 1626 | g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) ); |
| 1627 | LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() ); |
| 1628 | globalOutputStream() << "Loaded background texture " << relative << "\n"; |
| 1629 | g_pParentWnd->ActiveXY()->m_backgroundActivated = true; |
| 1630 | |
| 1631 | int m_ix = 0, m_iy = 1; |
| 1632 | switch ( g_pParentWnd->ActiveXY()->m_viewType ) |
| 1633 | { |
| 1634 | case XY: |
| 1635 | m_ix = 0; |
| 1636 | m_iy = 1; |
| 1637 | break; |
| 1638 | case XZ: |
| 1639 | m_ix = 0; |
| 1640 | m_iy = 2; |
| 1641 | break; |
| 1642 | case YZ: |
| 1643 | m_ix = 1; |
| 1644 | m_iy = 2; |
| 1645 | break; |
| 1646 | } |
| 1647 | |
| 1648 | Vector3 min, max; |
| 1649 | Select_GetBounds( min, max ); |
| 1650 | g_pParentWnd->ActiveXY()->m_xmin = min[m_ix]; |
| 1651 | g_pParentWnd->ActiveXY()->m_ymin = min[m_iy]; |
| 1652 | g_pParentWnd->ActiveXY()->m_xmax = max[m_ix]; |
| 1653 | g_pParentWnd->ActiveXY()->m_ymax = max[m_iy]; |
| 1654 | } |
| 1655 | |
| 1656 | void XYWnd::XY_DisableBackground( void ){ |
| 1657 | g_pParentWnd->ActiveXY()->m_backgroundActivated = false; |
| 1658 | if ( g_pParentWnd->ActiveXY()->m_tex ) { |
| 1659 | free( g_pParentWnd->ActiveXY()->m_tex ); |
| 1660 | } |
| 1661 | g_pParentWnd->ActiveXY()->m_tex = NULL; |
| 1662 | } |
| 1663 | |
| 1664 | void WXY_BackgroundSelect( void ){ |
| 1665 | bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0; |
| 1666 | |
| 1667 | ui::Window main_window = MainFrame_getWindow(); |
| 1668 | |
| 1669 | if ( !brushesSelected ) { |
| 1670 | ui::alert( main_window, "You have to select some brushes to get the bounding box for.\n", |
| 1671 | "No selection", ui::alert_type::OK, ui::alert_icon::Error ); |
| 1672 | return; |
| 1673 | } |
| 1674 | |
| 1675 | const char *filename = main_window.file_dialog( TRUE, "Background Image", NULL, NULL ); |
| 1676 | |
| 1677 | g_pParentWnd->ActiveXY()->XY_DisableBackground(); |
| 1678 | |
| 1679 | if ( filename ) { |
| 1680 | g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename ); |
| 1681 | } |
| 1682 | |
| 1683 | // Draw the background image immediately (do not wait for user input). |
| 1684 | g_pParentWnd->ActiveXY()->Redraw(); |
| 1685 | } |
| 1686 | |
| 1687 | /* |
| 1688 | ============================================================================ |
| 1689 | |
| 1690 | DRAWING |
| 1691 | |
| 1692 | ============================================================================ |
| 1693 | */ |
| 1694 | |
| 1695 | /* |
| 1696 | ============== |
| 1697 | XY_DrawGrid |
| 1698 | ============== |
| 1699 | */ |
| 1700 | |
| 1701 | double two_to_the_power( int power ){ |
| 1702 | return pow( 2.0f, power ); |
| 1703 | } |
| 1704 | |
| 1705 | void XYWnd::XY_DrawAxis( void ){ |
| 1706 | if ( g_xywindow_globals_private.show_axis ) { |
| 1707 | const char g_AxisName[3] = { 'X', 'Y', 'Z' }; |
| 1708 | const int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 1709 | const int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 1710 | const int w = ( m_nWidth / 2 / m_fScale ); |
| 1711 | const int h = ( m_nHeight / 2 / m_fScale ); |
| 1712 | |
| 1713 | Vector3 colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX; |
| 1714 | Vector3 colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ; |
| 1715 | if( !Active() ){ |
| 1716 | float grayX = vector3_dot( colourX, Vector3( 0.2989, 0.5870, 0.1140 ) ); |
| 1717 | float grayY = vector3_dot( colourY, Vector3( 0.2989, 0.5870, 0.1140 ) ); |
| 1718 | colourX[0] = colourX[1] = colourX[2] = grayX; |
| 1719 | colourY[0] = colourY[1] = colourY[2] = grayY; |
| 1720 | } |
| 1721 | |
| 1722 | // draw two lines with corresponding axis colors to highlight current view |
| 1723 | // horizontal line: nDim1 color |
| 1724 | glLineWidth( 2 ); |
| 1725 | glBegin( GL_LINES ); |
| 1726 | glColor3fv( vector3_to_array( colourX ) ); |
| 1727 | glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale ); |
| 1728 | glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale ); |
| 1729 | glVertex2f( 0, 0 ); |
| 1730 | glVertex2f( 32 / m_fScale, 0 ); |
| 1731 | glColor3fv( vector3_to_array( colourY ) ); |
| 1732 | glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale ); |
| 1733 | glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale ); |
| 1734 | glVertex2f( 0, 0 ); |
| 1735 | glVertex2f( 0, 32 / m_fScale ); |
| 1736 | glEnd(); |
| 1737 | glLineWidth( 1 ); |
| 1738 | // now print axis symbols |
| 1739 | glColor3fv( vector3_to_array( colourX ) ); |
| 1740 | glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale ); |
| 1741 | GlobalOpenGL().drawChar( g_AxisName[nDim1] ); |
| 1742 | glRasterPos2f( 28 / m_fScale, -10 / m_fScale ); |
| 1743 | GlobalOpenGL().drawChar( g_AxisName[nDim1] ); |
| 1744 | glColor3fv( vector3_to_array( colourY ) ); |
| 1745 | glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale ); |
| 1746 | GlobalOpenGL().drawChar( g_AxisName[nDim2] ); |
| 1747 | glRasterPos2f( -10 / m_fScale, 28 / m_fScale ); |
| 1748 | GlobalOpenGL().drawChar( g_AxisName[nDim2] ); |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | void XYWnd::RenderActive( void ){ |
| 1753 | if ( glwidget_make_current( m_gl_widget ) != FALSE ) { |
| 1754 | if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) { |
| 1755 | GlobalOpenGL_debugAssertNoErrors(); |
| 1756 | #if GTK_TARGET == 2 |
| 1757 | glDrawBuffer( GL_FRONT ); |
| 1758 | #endif |
| 1759 | |
| 1760 | if ( g_xywindow_globals_private.show_outline ) { |
| 1761 | glMatrixMode( GL_PROJECTION ); |
| 1762 | glLoadIdentity(); |
| 1763 | glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 ); |
| 1764 | |
| 1765 | glMatrixMode( GL_MODELVIEW ); |
| 1766 | glLoadIdentity(); |
| 1767 | |
| 1768 | if( !Active() ){ //sorta erase |
| 1769 | glColor3fv( vector3_to_array( g_xywindow_globals.color_gridmajor ) ); |
| 1770 | } |
| 1771 | // four view mode doesn't colorize |
| 1772 | else if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) { |
| 1773 | glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) ); |
| 1774 | } |
| 1775 | else |
| 1776 | { |
| 1777 | switch ( m_viewType ) |
| 1778 | { |
| 1779 | case YZ: |
| 1780 | glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) ); |
| 1781 | break; |
| 1782 | case XZ: |
| 1783 | glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) ); |
| 1784 | break; |
| 1785 | case XY: |
| 1786 | glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) ); |
| 1787 | break; |
| 1788 | } |
| 1789 | } |
| 1790 | glBegin( GL_LINE_LOOP ); |
| 1791 | glVertex2f( 0.5, 0.5 ); |
| 1792 | glVertex2f( m_nWidth - 0.5, 1 ); |
| 1793 | glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 ); |
| 1794 | glVertex2f( 0.5, m_nHeight - 0.5 ); |
| 1795 | glEnd(); |
| 1796 | } |
| 1797 | // we do this part (the old way) only if show_axis is disabled |
| 1798 | if ( !g_xywindow_globals_private.show_axis ) { |
| 1799 | glMatrixMode( GL_PROJECTION ); |
| 1800 | glLoadIdentity(); |
| 1801 | glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 ); |
| 1802 | |
| 1803 | glMatrixMode( GL_MODELVIEW ); |
| 1804 | glLoadIdentity(); |
| 1805 | |
| 1806 | if ( Active() ) { |
| 1807 | glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) ); |
| 1808 | } |
| 1809 | else{ |
| 1810 | glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) ); |
| 1811 | } |
| 1812 | |
| 1813 | glDisable( GL_BLEND ); |
| 1814 | glRasterPos2f( 35, m_nHeight - 20 ); |
| 1815 | |
| 1816 | GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) ); |
| 1817 | } |
| 1818 | else{ |
| 1819 | // clear |
| 1820 | glViewport( 0, 0, m_nWidth, m_nHeight ); |
| 1821 | // set up viewpoint |
| 1822 | glMatrixMode( GL_PROJECTION ); |
| 1823 | glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) ); |
| 1824 | |
| 1825 | glMatrixMode( GL_MODELVIEW ); |
| 1826 | glLoadIdentity(); |
| 1827 | glScalef( m_fScale, m_fScale, 1 ); |
| 1828 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 1829 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 1830 | glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 ); |
| 1831 | |
| 1832 | glDisable( GL_LINE_STIPPLE ); |
| 1833 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); |
| 1834 | glDisableClientState( GL_NORMAL_ARRAY ); |
| 1835 | glDisableClientState( GL_COLOR_ARRAY ); |
| 1836 | glDisable( GL_TEXTURE_2D ); |
| 1837 | glDisable( GL_LIGHTING ); |
| 1838 | glDisable( GL_COLOR_MATERIAL ); |
| 1839 | glDisable( GL_DEPTH_TEST ); |
| 1840 | glDisable( GL_TEXTURE_1D ); |
| 1841 | glDisable( GL_BLEND ); |
| 1842 | |
| 1843 | XYWnd::XY_DrawAxis(); |
| 1844 | } |
| 1845 | |
| 1846 | #if GTK_TARGET == 2 |
| 1847 | glDrawBuffer( GL_BACK ); |
| 1848 | #endif |
| 1849 | GlobalOpenGL_debugAssertNoErrors(); |
| 1850 | glwidget_make_current( m_gl_widget ); |
| 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | void XYWnd::XY_DrawBackground( void ){ |
| 1856 | glPushAttrib( GL_ALL_ATTRIB_BITS ); |
| 1857 | |
| 1858 | glEnable( GL_TEXTURE_2D ); |
| 1859 | glEnable( GL_BLEND ); |
| 1860 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
| 1861 | glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); |
| 1862 | glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); |
| 1863 | glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); |
| 1864 | |
| 1865 | glPolygonMode( GL_FRONT, GL_FILL ); |
| 1866 | |
| 1867 | glBindTexture( GL_TEXTURE_2D, m_tex->texture_number ); |
| 1868 | glBegin( GL_QUADS ); |
| 1869 | |
| 1870 | glColor4f( 1.0, 1.0, 1.0, m_alpha ); |
| 1871 | glTexCoord2f( 0.0, 1.0 ); |
| 1872 | glVertex2f( m_xmin, m_ymin ); |
| 1873 | |
| 1874 | glTexCoord2f( 1.0, 1.0 ); |
| 1875 | glVertex2f( m_xmax, m_ymin ); |
| 1876 | |
| 1877 | glTexCoord2f( 1.0, 0.0 ); |
| 1878 | glVertex2f( m_xmax, m_ymax ); |
| 1879 | |
| 1880 | glTexCoord2f( 0.0, 0.0 ); |
| 1881 | glVertex2f( m_xmin, m_ymax ); |
| 1882 | |
| 1883 | glEnd(); |
| 1884 | glBindTexture( GL_TEXTURE_2D, 0 ); |
| 1885 | |
| 1886 | glPopAttrib(); |
| 1887 | } |
| 1888 | |
| 1889 | void XYWnd::XY_DrawGrid( void ) { |
| 1890 | float x, y, xb, xe, yb, ye; |
| 1891 | float w, h, a; |
| 1892 | char text[32]; |
| 1893 | float step, minor_step, stepx, stepy; |
| 1894 | step = minor_step = stepx = stepy = GetGridSize(); |
| 1895 | |
| 1896 | int minor_power = Grid_getPower(); |
| 1897 | int mask; |
| 1898 | |
| 1899 | while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen |
| 1900 | ++minor_power; |
| 1901 | minor_step *= 2; |
| 1902 | } |
| 1903 | int power = minor_power; |
| 1904 | while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen |
| 1905 | ++power; |
| 1906 | step = float(two_to_the_power( power ) ); |
| 1907 | } |
| 1908 | mask = ( 1 << ( power - minor_power ) ) - 1; |
| 1909 | while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32 |
| 1910 | stepx *= 2; |
| 1911 | while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32 |
| 1912 | stepy *= 2; |
| 1913 | |
| 1914 | a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f ); |
| 1915 | |
| 1916 | glDisable( GL_TEXTURE_2D ); |
| 1917 | glDisable( GL_TEXTURE_1D ); |
| 1918 | glDisable( GL_DEPTH_TEST ); |
| 1919 | glDisable( GL_BLEND ); |
| 1920 | glLineWidth( 1 ); |
| 1921 | |
| 1922 | w = ( m_nWidth / 2 / m_fScale ); |
| 1923 | h = ( m_nHeight / 2 / m_fScale ); |
| 1924 | |
| 1925 | const int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 1926 | const int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 1927 | |
| 1928 | xb = m_vOrigin[nDim1] - w; |
| 1929 | if ( xb < region_mins[nDim1] ) { |
| 1930 | xb = region_mins[nDim1]; |
| 1931 | } |
| 1932 | xb = step * floor( xb / step ); |
| 1933 | |
| 1934 | xe = m_vOrigin[nDim1] + w; |
| 1935 | if ( xe > region_maxs[nDim1] ) { |
| 1936 | xe = region_maxs[nDim1]; |
| 1937 | } |
| 1938 | xe = step * ceil( xe / step ); |
| 1939 | |
| 1940 | yb = m_vOrigin[nDim2] - h; |
| 1941 | if ( yb < region_mins[nDim2] ) { |
| 1942 | yb = region_mins[nDim2]; |
| 1943 | } |
| 1944 | yb = step * floor( yb / step ); |
| 1945 | |
| 1946 | ye = m_vOrigin[nDim2] + h; |
| 1947 | if ( ye > region_maxs[nDim2] ) { |
| 1948 | ye = region_maxs[nDim2]; |
| 1949 | } |
| 1950 | ye = step * ceil( ye / step ); |
| 1951 | |
| 1952 | #define COLORS_DIFFER( a,b ) \ |
| 1953 | ( ( a )[0] != ( b )[0] || \ |
| 1954 | ( a )[1] != ( b )[1] || \ |
| 1955 | ( a )[2] != ( b )[2] ) |
| 1956 | |
| 1957 | // djbob |
| 1958 | // draw minor blocks |
| 1959 | if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) { |
| 1960 | if ( a < 1.0f ) { |
| 1961 | glEnable( GL_BLEND ); |
| 1962 | } |
| 1963 | |
| 1964 | if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) { |
| 1965 | glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) ); |
| 1966 | |
| 1967 | glBegin( GL_LINES ); |
| 1968 | int i = 0; |
| 1969 | for ( x = xb ; x < xe ; x += minor_step, ++i ) { |
| 1970 | if ( ( i & mask ) != 0 ) { |
| 1971 | glVertex2f( x, yb ); |
| 1972 | glVertex2f( x, ye ); |
| 1973 | } |
| 1974 | } |
| 1975 | i = 0; |
| 1976 | for ( y = yb ; y < ye ; y += minor_step, ++i ) { |
| 1977 | if ( ( i & mask ) != 0 ) { |
| 1978 | glVertex2f( xb, y ); |
| 1979 | glVertex2f( xe, y ); |
| 1980 | } |
| 1981 | } |
| 1982 | glEnd(); |
| 1983 | } |
| 1984 | |
| 1985 | // draw major blocks |
| 1986 | if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) { |
| 1987 | glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) ); |
| 1988 | |
| 1989 | glBegin( GL_LINES ); |
| 1990 | for ( x = xb ; x <= xe ; x += step ) { |
| 1991 | glVertex2f( x, yb ); |
| 1992 | glVertex2f( x, ye ); |
| 1993 | } |
| 1994 | for ( y = yb ; y <= ye ; y += step ) { |
| 1995 | glVertex2f( xb, y ); |
| 1996 | glVertex2f( xe, y ); |
| 1997 | } |
| 1998 | glEnd(); |
| 1999 | } |
| 2000 | |
| 2001 | if ( a < 1.0f ) { |
| 2002 | glDisable( GL_BLEND ); |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | // draw coordinate text if needed |
| 2007 | if ( g_xywindow_globals_private.show_coordinates ) { |
| 2008 | glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) ); |
| 2009 | float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale; |
| 2010 | float offy = m_vOrigin[nDim1] - w + 4 / m_fScale; |
| 2011 | for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) { |
| 2012 | glRasterPos2f( x, offx ); |
| 2013 | sprintf( text, "%g", x ); |
| 2014 | GlobalOpenGL().drawString( text ); |
| 2015 | } |
| 2016 | for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) { |
| 2017 | glRasterPos2f( offy, y ); |
| 2018 | sprintf( text, "%g", y ); |
| 2019 | GlobalOpenGL().drawString( text ); |
| 2020 | } |
| 2021 | |
| 2022 | } |
| 2023 | // we do this part (the old way) only if show_axis is disabled |
| 2024 | if ( !g_xywindow_globals_private.show_axis ) { |
| 2025 | if ( Active() ) { |
| 2026 | glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) ); |
| 2027 | } |
| 2028 | else{ |
| 2029 | glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) ); |
| 2030 | } |
| 2031 | |
| 2032 | glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale ); |
| 2033 | |
| 2034 | GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) ); |
| 2035 | } |
| 2036 | |
| 2037 | XYWnd::XY_DrawAxis(); |
| 2038 | |
| 2039 | // show current work zone? |
| 2040 | // the work zone is used to place dropped points and brushes |
| 2041 | if ( g_xywindow_globals_private.d_show_work ) { |
| 2042 | glColor4f( 1.0f, 0.0f, 0.0f, 1.0f ); |
| 2043 | glBegin( GL_LINES ); |
| 2044 | glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] ); |
| 2045 | glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] ); |
| 2046 | glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] ); |
| 2047 | glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] ); |
| 2048 | glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb ); |
| 2049 | glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye ); |
| 2050 | glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb ); |
| 2051 | glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye ); |
| 2052 | glEnd(); |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | /* |
| 2057 | ============== |
| 2058 | XY_DrawBlockGrid |
| 2059 | ============== |
| 2060 | */ |
| 2061 | void XYWnd::XY_DrawBlockGrid(){ |
| 2062 | if ( Map_FindWorldspawn( g_map ) == 0 ) { |
| 2063 | return; |
| 2064 | } |
| 2065 | const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" ); |
| 2066 | if ( strlen( value ) ) { |
| 2067 | sscanf( value, "%i", &g_xywindow_globals_private.blockSize ); |
| 2068 | } |
| 2069 | |
| 2070 | if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) { |
| 2071 | // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate |
| 2072 | g_xywindow_globals_private.blockSize = 1024; |
| 2073 | } |
| 2074 | |
| 2075 | float x, y, xb, xe, yb, ye; |
| 2076 | float w, h; |
| 2077 | char text[32]; |
| 2078 | |
| 2079 | glDisable( GL_TEXTURE_2D ); |
| 2080 | glDisable( GL_TEXTURE_1D ); |
| 2081 | glDisable( GL_DEPTH_TEST ); |
| 2082 | glDisable( GL_BLEND ); |
| 2083 | |
| 2084 | w = ( m_nWidth / 2 / m_fScale ); |
| 2085 | h = ( m_nHeight / 2 / m_fScale ); |
| 2086 | |
| 2087 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 2088 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 2089 | |
| 2090 | xb = m_vOrigin[nDim1] - w; |
| 2091 | if ( xb < region_mins[nDim1] ) { |
| 2092 | xb = region_mins[nDim1]; |
| 2093 | } |
| 2094 | xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) ); |
| 2095 | |
| 2096 | xe = m_vOrigin[nDim1] + w; |
| 2097 | if ( xe > region_maxs[nDim1] ) { |
| 2098 | xe = region_maxs[nDim1]; |
| 2099 | } |
| 2100 | xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) ); |
| 2101 | |
| 2102 | yb = m_vOrigin[nDim2] - h; |
| 2103 | if ( yb < region_mins[nDim2] ) { |
| 2104 | yb = region_mins[nDim2]; |
| 2105 | } |
| 2106 | yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) ); |
| 2107 | |
| 2108 | ye = m_vOrigin[nDim2] + h; |
| 2109 | if ( ye > region_maxs[nDim2] ) { |
| 2110 | ye = region_maxs[nDim2]; |
| 2111 | } |
| 2112 | ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) ); |
| 2113 | |
| 2114 | // draw major blocks |
| 2115 | |
| 2116 | glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) ); |
| 2117 | glLineWidth( 2 ); |
| 2118 | |
| 2119 | glBegin( GL_LINES ); |
| 2120 | |
| 2121 | for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize ) |
| 2122 | { |
| 2123 | glVertex2f( x, yb ); |
| 2124 | glVertex2f( x, ye ); |
| 2125 | } |
| 2126 | |
| 2127 | if ( m_viewType == XY ) { |
| 2128 | for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize ) |
| 2129 | { |
| 2130 | glVertex2f( xb, y ); |
| 2131 | glVertex2f( xe, y ); |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | glEnd(); |
| 2136 | glLineWidth( 1 ); |
| 2137 | |
| 2138 | // draw coordinate text if needed |
| 2139 | |
| 2140 | if ( m_viewType == XY && m_fScale > .1 ) { |
| 2141 | for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize ) |
| 2142 | for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize ) |
| 2143 | { |
| 2144 | glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) ); |
| 2145 | sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) ); |
| 2146 | GlobalOpenGL().drawString( text ); |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | glColor4f( 0, 0, 0, 0 ); |
| 2151 | } |
| 2152 | |
| 2153 | void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){ |
| 2154 | Cam.fov = 48 / m_fScale; |
| 2155 | Cam.box = 16 / m_fScale; |
| 2156 | // globalOutputStream() << "pitch " << angles[CAMERA_PITCH] << " yaw " << angles[CAMERA_YAW] << "\n"; |
| 2157 | |
| 2158 | if ( m_viewType == XY ) { |
| 2159 | Cam.x = origin[0]; |
| 2160 | Cam.y = origin[1]; |
| 2161 | Cam.a = degrees_to_radians( angles[CAMERA_YAW] ); |
| 2162 | } |
| 2163 | else if ( m_viewType == YZ ) { |
| 2164 | Cam.x = origin[1]; |
| 2165 | Cam.y = origin[2]; |
| 2166 | Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] > 180 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] ); |
| 2167 | } |
| 2168 | else |
| 2169 | { |
| 2170 | Cam.x = origin[0]; |
| 2171 | Cam.y = origin[2]; |
| 2172 | Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] < 270 && angles[CAMERA_YAW] > 90 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] ); |
| 2173 | } |
| 2174 | |
| 2175 | //glColor3f( 0.0, 0.0, 1.0 ); |
| 2176 | glColor3f( 1.0, 1.0, 1.0 ); |
| 2177 | glBegin( GL_LINE_STRIP ); |
| 2178 | glVertex3f( Cam.x - Cam.box,Cam.y,0 ); |
| 2179 | glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 ); |
| 2180 | glVertex3f( Cam.x + Cam.box,Cam.y,0 ); |
| 2181 | glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 ); |
| 2182 | glVertex3f( Cam.x - Cam.box,Cam.y,0 ); |
| 2183 | glVertex3f( Cam.x + Cam.box,Cam.y,0 ); |
| 2184 | glEnd(); |
| 2185 | |
| 2186 | glBegin( GL_LINE_STRIP ); |
| 2187 | glVertex3f( Cam.x + static_cast<float>( Cam.fov * cos( Cam.a + c_pi / 4 ) ), Cam.y + static_cast<float>( Cam.fov * sin( Cam.a + c_pi / 4 ) ), 0 ); |
| 2188 | glVertex3f( Cam.x, Cam.y, 0 ); |
| 2189 | glVertex3f( Cam.x + static_cast<float>( Cam.fov * cos( Cam.a - c_pi / 4 ) ), Cam.y + static_cast<float>( Cam.fov * sin( Cam.a - c_pi / 4 ) ), 0 ); |
| 2190 | glEnd(); |
| 2191 | |
| 2192 | } |
| 2193 | |
| 2194 | void XYWnd::UpdateCameraIcon( void ){ |
| 2195 | if ( glwidget_make_current( m_gl_widget ) != FALSE ) { |
| 2196 | if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) { |
| 2197 | GlobalOpenGL_debugAssertNoErrors(); |
| 2198 | #if GTK_TARGET == 2 |
| 2199 | glDrawBuffer( GL_FRONT ); |
| 2200 | #endif |
| 2201 | { |
| 2202 | // clear |
| 2203 | glViewport( 0, 0, m_nWidth, m_nHeight ); |
| 2204 | // set up viewpoint |
| 2205 | glMatrixMode( GL_PROJECTION ); |
| 2206 | glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) ); |
| 2207 | |
| 2208 | glMatrixMode( GL_MODELVIEW ); |
| 2209 | glLoadIdentity(); |
| 2210 | glScalef( m_fScale, m_fScale, 1 ); |
| 2211 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 2212 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 2213 | glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 ); |
| 2214 | |
| 2215 | glDisable( GL_LINE_STIPPLE ); |
| 2216 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); |
| 2217 | glDisableClientState( GL_NORMAL_ARRAY ); |
| 2218 | glDisableClientState( GL_COLOR_ARRAY ); |
| 2219 | glDisable( GL_TEXTURE_2D ); |
| 2220 | glDisable( GL_LIGHTING ); |
| 2221 | glDisable( GL_COLOR_MATERIAL ); |
| 2222 | glDisable( GL_DEPTH_TEST ); |
| 2223 | glDisable( GL_TEXTURE_1D ); |
| 2224 | |
| 2225 | glEnable( GL_BLEND ); |
| 2226 | glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO ); |
| 2227 | |
| 2228 | //glColor3f( 0.0, 0.0, 1.0 ); |
| 2229 | glColor3f( 1.0, 1.0, 1.0 ); |
| 2230 | glBegin( GL_LINE_STRIP ); |
| 2231 | glVertex3f( Cam.x - Cam.box,Cam.y,0 ); |
| 2232 | glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 ); |
| 2233 | glVertex3f( Cam.x + Cam.box,Cam.y,0 ); |
| 2234 | glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 ); |
| 2235 | glVertex3f( Cam.x - Cam.box,Cam.y,0 ); |
| 2236 | glVertex3f( Cam.x + Cam.box,Cam.y,0 ); |
| 2237 | glEnd(); |
| 2238 | |
| 2239 | glBegin( GL_LINE_STRIP ); |
| 2240 | glVertex3f( Cam.x + static_cast<float>( Cam.fov * cos( Cam.a + c_pi / 4 ) ), Cam.y + static_cast<float>( Cam.fov * sin( Cam.a + c_pi / 4 ) ), 0 ); |
| 2241 | glVertex3f( Cam.x, Cam.y, 0 ); |
| 2242 | glVertex3f( Cam.x + static_cast<float>( Cam.fov * cos( Cam.a - c_pi / 4 ) ), Cam.y + static_cast<float>( Cam.fov * sin( Cam.a - c_pi / 4 ) ), 0 ); |
| 2243 | glEnd(); |
| 2244 | |
| 2245 | XYWnd::DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) ); |
| 2246 | |
| 2247 | glDisable( GL_BLEND ); |
| 2248 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
| 2249 | } |
| 2250 | |
| 2251 | #if GTK_TARGET == 2 |
| 2252 | glDrawBuffer( GL_BACK ); |
| 2253 | #endif |
| 2254 | GlobalOpenGL_debugAssertNoErrors(); |
| 2255 | glwidget_make_current( m_gl_widget ); |
| 2256 | } |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | |
| 2261 | float Betwixt( float f1, float f2 ){ |
| 2262 | if ( f1 > f2 ) { |
| 2263 | return f2 + ( ( f1 - f2 ) / 2 ); |
| 2264 | } |
| 2265 | else{ |
| 2266 | return f1 + ( ( f2 - f1 ) / 2 ); |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | |
| 2271 | // can be greatly simplified but per usual i am in a hurry |
| 2272 | // which is not an excuse, just a fact |
| 2273 | void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){ |
| 2274 | if ( vector3_equal( vMinBounds, vMaxBounds ) ) { |
| 2275 | return; |
| 2276 | } |
| 2277 | const char* g_pDimStrings[] = {"x:", "y:", "z:"}; |
| 2278 | typedef const char* OrgStrings[2]; |
| 2279 | const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } }; |
| 2280 | |
| 2281 | Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) ); |
| 2282 | |
| 2283 | glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f, |
| 2284 | g_xywindow_globals.color_selbrushes[1] * .65f, |
| 2285 | g_xywindow_globals.color_selbrushes[2] * .65f ); |
| 2286 | |
| 2287 | StringOutputStream dimensions( 16 ); |
| 2288 | |
| 2289 | if ( m_viewType == XY ) { |
| 2290 | glBegin( GL_LINES ); |
| 2291 | |
| 2292 | glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f ); |
| 2293 | glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f ); |
| 2294 | |
| 2295 | glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f ); |
| 2296 | glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f ); |
| 2297 | |
| 2298 | glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f ); |
| 2299 | glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f ); |
| 2300 | |
| 2301 | |
| 2302 | glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f ); |
| 2303 | glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f ); |
| 2304 | |
| 2305 | glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f ); |
| 2306 | glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f ); |
| 2307 | |
| 2308 | glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f ); |
| 2309 | glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f ); |
| 2310 | |
| 2311 | glEnd(); |
| 2312 | |
| 2313 | glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f ); |
| 2314 | dimensions << g_pDimStrings[nDim1] << vSize[nDim1]; |
| 2315 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2316 | dimensions.clear(); |
| 2317 | |
| 2318 | glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f ); |
| 2319 | dimensions << g_pDimStrings[nDim2] << vSize[nDim2]; |
| 2320 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2321 | dimensions.clear(); |
| 2322 | |
| 2323 | glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f ); |
| 2324 | dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")"; |
| 2325 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2326 | } |
| 2327 | else if ( m_viewType == XZ ) { |
| 2328 | glBegin( GL_LINES ); |
| 2329 | |
| 2330 | glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale ); |
| 2331 | glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale ); |
| 2332 | |
| 2333 | glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale ); |
| 2334 | glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale ); |
| 2335 | |
| 2336 | glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale ); |
| 2337 | glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale ); |
| 2338 | |
| 2339 | |
| 2340 | glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] ); |
| 2341 | glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] ); |
| 2342 | |
| 2343 | glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] ); |
| 2344 | glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] ); |
| 2345 | |
| 2346 | glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] ); |
| 2347 | glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] ); |
| 2348 | |
| 2349 | glEnd(); |
| 2350 | |
| 2351 | glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale ); |
| 2352 | dimensions << g_pDimStrings[nDim1] << vSize[nDim1]; |
| 2353 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2354 | dimensions.clear(); |
| 2355 | |
| 2356 | glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) ); |
| 2357 | dimensions << g_pDimStrings[nDim2] << vSize[nDim2]; |
| 2358 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2359 | dimensions.clear(); |
| 2360 | |
| 2361 | glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale ); |
| 2362 | dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")"; |
| 2363 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2364 | } |
| 2365 | else |
| 2366 | { |
| 2367 | glBegin( GL_LINES ); |
| 2368 | |
| 2369 | glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale ); |
| 2370 | glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale ); |
| 2371 | |
| 2372 | glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale ); |
| 2373 | glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale ); |
| 2374 | |
| 2375 | glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale ); |
| 2376 | glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale ); |
| 2377 | |
| 2378 | |
| 2379 | glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] ); |
| 2380 | glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] ); |
| 2381 | |
| 2382 | glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] ); |
| 2383 | glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] ); |
| 2384 | |
| 2385 | glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] ); |
| 2386 | glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] ); |
| 2387 | |
| 2388 | glEnd(); |
| 2389 | |
| 2390 | glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale ); |
| 2391 | dimensions << g_pDimStrings[nDim1] << vSize[nDim1]; |
| 2392 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2393 | dimensions.clear(); |
| 2394 | |
| 2395 | glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) ); |
| 2396 | dimensions << g_pDimStrings[nDim2] << vSize[nDim2]; |
| 2397 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2398 | dimensions.clear(); |
| 2399 | |
| 2400 | glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale ); |
| 2401 | dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")"; |
| 2402 | GlobalOpenGL().drawString( dimensions.c_str() ); |
| 2403 | } |
| 2404 | } |
| 2405 | |
| 2406 | class XYRenderer : public Renderer |
| 2407 | { |
| 2408 | struct state_type |
| 2409 | { |
| 2410 | state_type() : |
| 2411 | m_highlight( 0 ), |
| 2412 | m_state( 0 ){ |
| 2413 | } |
| 2414 | unsigned int m_highlight; |
| 2415 | Shader* m_state; |
| 2416 | }; |
| 2417 | public: |
| 2418 | XYRenderer( RenderStateFlags globalstate, Shader* selected ) : |
| 2419 | m_globalstate( globalstate ), |
| 2420 | m_state_selected( selected ){ |
| 2421 | ASSERT_NOTNULL( selected ); |
| 2422 | m_state_stack.push_back( state_type() ); |
| 2423 | } |
| 2424 | |
| 2425 | void SetState( Shader* state, EStyle style ){ |
| 2426 | ASSERT_NOTNULL( state ); |
| 2427 | if ( style == eWireframeOnly ) { |
| 2428 | m_state_stack.back().m_state = state; |
| 2429 | } |
| 2430 | } |
| 2431 | EStyle getStyle() const { |
| 2432 | return eWireframeOnly; |
| 2433 | } |
| 2434 | void PushState(){ |
| 2435 | m_state_stack.push_back( m_state_stack.back() ); |
| 2436 | } |
| 2437 | void PopState(){ |
| 2438 | ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" ); |
| 2439 | m_state_stack.pop_back(); |
| 2440 | } |
| 2441 | void Highlight( EHighlightMode mode, bool bEnable = true ){ |
| 2442 | ( bEnable ) |
| 2443 | ? m_state_stack.back().m_highlight |= mode |
| 2444 | : m_state_stack.back().m_highlight &= ~mode; |
| 2445 | } |
| 2446 | void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){ |
| 2447 | if ( m_state_stack.back().m_highlight & ePrimitive ) { |
| 2448 | m_state_selected->addRenderable( renderable, localToWorld ); |
| 2449 | } |
| 2450 | else |
| 2451 | { |
| 2452 | m_state_stack.back().m_state->addRenderable( renderable, localToWorld ); |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | void render( const Matrix4& modelview, const Matrix4& projection ){ |
| 2457 | GlobalShaderCache().render( m_globalstate, modelview, projection ); |
| 2458 | } |
| 2459 | private: |
| 2460 | std::vector<state_type> m_state_stack; |
| 2461 | RenderStateFlags m_globalstate; |
| 2462 | Shader* m_state_selected; |
| 2463 | }; |
| 2464 | |
| 2465 | void XYWnd::updateProjection( bool reconstruct ){ |
| 2466 | m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 ); |
| 2467 | m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 ); |
| 2468 | m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale ); |
| 2469 | |
| 2470 | m_projection[12] = 0.0f; |
| 2471 | m_projection[13] = 0.0f; |
| 2472 | m_projection[14] = -1.0f; |
| 2473 | |
| 2474 | m_projection[1] = |
| 2475 | m_projection[2] = |
| 2476 | m_projection[3] = |
| 2477 | |
| 2478 | m_projection[4] = |
| 2479 | m_projection[6] = |
| 2480 | m_projection[7] = |
| 2481 | |
| 2482 | m_projection[8] = |
| 2483 | m_projection[9] = |
| 2484 | m_projection[11] = 0.0f; |
| 2485 | |
| 2486 | m_projection[15] = 1.0f; |
| 2487 | |
| 2488 | if (reconstruct) { |
| 2489 | m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight ); |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator. |
| 2494 | void XYWnd::updateModelview( bool reconstruct ){ |
| 2495 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 2496 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 2497 | |
| 2498 | // translation |
| 2499 | m_modelview[12] = -m_vOrigin[nDim1] * m_fScale; |
| 2500 | m_modelview[13] = -m_vOrigin[nDim2] * m_fScale; |
| 2501 | m_modelview[14] = g_MaxWorldCoord * m_fScale; |
| 2502 | |
| 2503 | // axis base |
| 2504 | switch ( m_viewType ) |
| 2505 | { |
| 2506 | case XY: |
| 2507 | m_modelview[0] = m_fScale; |
| 2508 | m_modelview[1] = 0; |
| 2509 | m_modelview[2] = 0; |
| 2510 | |
| 2511 | m_modelview[4] = 0; |
| 2512 | m_modelview[5] = m_fScale; |
| 2513 | m_modelview[6] = 0; |
| 2514 | |
| 2515 | m_modelview[8] = 0; |
| 2516 | m_modelview[9] = 0; |
| 2517 | m_modelview[10] = -m_fScale; |
| 2518 | break; |
| 2519 | case XZ: |
| 2520 | m_modelview[0] = m_fScale; |
| 2521 | m_modelview[1] = 0; |
| 2522 | m_modelview[2] = 0; |
| 2523 | |
| 2524 | m_modelview[4] = 0; |
| 2525 | m_modelview[5] = 0; |
| 2526 | m_modelview[6] = m_fScale; |
| 2527 | |
| 2528 | m_modelview[8] = 0; |
| 2529 | m_modelview[9] = m_fScale; |
| 2530 | m_modelview[10] = 0; |
| 2531 | break; |
| 2532 | case YZ: |
| 2533 | m_modelview[0] = 0; |
| 2534 | m_modelview[1] = 0; |
| 2535 | m_modelview[2] = -m_fScale; |
| 2536 | |
| 2537 | m_modelview[4] = m_fScale; |
| 2538 | m_modelview[5] = 0; |
| 2539 | m_modelview[6] = 0; |
| 2540 | |
| 2541 | m_modelview[8] = 0; |
| 2542 | m_modelview[9] = m_fScale; |
| 2543 | m_modelview[10] = 0; |
| 2544 | break; |
| 2545 | } |
| 2546 | |
| 2547 | m_modelview[3] = m_modelview[7] = m_modelview[11] = 0; |
| 2548 | m_modelview[15] = 1; |
| 2549 | |
| 2550 | if (reconstruct) { |
| 2551 | m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight ); |
| 2552 | } |
| 2553 | } |
| 2554 | |
| 2555 | /* |
| 2556 | ============== |
| 2557 | XY_Draw |
| 2558 | ============== |
| 2559 | */ |
| 2560 | |
| 2561 | //#define DBG_SCENEDUMP |
| 2562 | |
| 2563 | void XYWnd::XY_Draw(){ |
| 2564 | // |
| 2565 | // clear |
| 2566 | // |
| 2567 | glViewport( 0, 0, m_nWidth, m_nHeight ); |
| 2568 | glClearColor( g_xywindow_globals.color_gridback[0], |
| 2569 | g_xywindow_globals.color_gridback[1], |
| 2570 | g_xywindow_globals.color_gridback[2],0 ); |
| 2571 | |
| 2572 | glClear( GL_COLOR_BUFFER_BIT ); |
| 2573 | |
| 2574 | // |
| 2575 | // set up viewpoint |
| 2576 | // |
| 2577 | |
| 2578 | glMatrixMode( GL_PROJECTION ); |
| 2579 | glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) ); |
| 2580 | |
| 2581 | glMatrixMode( GL_MODELVIEW ); |
| 2582 | glLoadIdentity(); |
| 2583 | glScalef( m_fScale, m_fScale, 1 ); |
| 2584 | int nDim1 = ( m_viewType == YZ ) ? 1 : 0; |
| 2585 | int nDim2 = ( m_viewType == XY ) ? 1 : 2; |
| 2586 | glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 ); |
| 2587 | |
| 2588 | glDisable( GL_LINE_STIPPLE ); |
| 2589 | glLineWidth( 1 ); |
| 2590 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); |
| 2591 | glDisableClientState( GL_NORMAL_ARRAY ); |
| 2592 | glDisableClientState( GL_COLOR_ARRAY ); |
| 2593 | glDisable( GL_TEXTURE_2D ); |
| 2594 | glDisable( GL_LIGHTING ); |
| 2595 | glDisable( GL_COLOR_MATERIAL ); |
| 2596 | glDisable( GL_DEPTH_TEST ); |
| 2597 | |
| 2598 | if ( m_backgroundActivated ) { |
| 2599 | XY_DrawBackground(); |
| 2600 | } |
| 2601 | XY_DrawGrid(); |
| 2602 | |
| 2603 | if ( g_xywindow_globals_private.show_blocks ) { |
| 2604 | XY_DrawBlockGrid(); |
| 2605 | } |
| 2606 | |
| 2607 | glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) ); |
| 2608 | |
| 2609 | unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH; |
| 2610 | if ( !g_xywindow_globals.m_bNoStipple ) { |
| 2611 | globalstate |= RENDER_LINESTIPPLE; |
| 2612 | } |
| 2613 | |
| 2614 | { |
| 2615 | XYRenderer renderer( globalstate, m_state_selected ); |
| 2616 | |
| 2617 | Scene_Render( renderer, m_view ); |
| 2618 | |
| 2619 | GlobalOpenGL_debugAssertNoErrors(); |
| 2620 | renderer.render( m_modelview, m_projection ); |
| 2621 | GlobalOpenGL_debugAssertNoErrors(); |
| 2622 | } |
| 2623 | |
| 2624 | glDepthMask( GL_FALSE ); |
| 2625 | |
| 2626 | GlobalOpenGL_debugAssertNoErrors(); |
| 2627 | |
| 2628 | glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) ); |
| 2629 | |
| 2630 | GlobalOpenGL_debugAssertNoErrors(); |
| 2631 | glDisable( GL_LINE_STIPPLE ); |
| 2632 | GlobalOpenGL_debugAssertNoErrors(); |
| 2633 | glLineWidth( 1 ); |
| 2634 | GlobalOpenGL_debugAssertNoErrors(); |
| 2635 | if ( GlobalOpenGL().GL_1_3() ) { |
| 2636 | glActiveTexture( GL_TEXTURE0 ); |
| 2637 | glClientActiveTexture( GL_TEXTURE0 ); |
| 2638 | } |
| 2639 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); |
| 2640 | GlobalOpenGL_debugAssertNoErrors(); |
| 2641 | glDisableClientState( GL_NORMAL_ARRAY ); |
| 2642 | GlobalOpenGL_debugAssertNoErrors(); |
| 2643 | glDisableClientState( GL_COLOR_ARRAY ); |
| 2644 | GlobalOpenGL_debugAssertNoErrors(); |
| 2645 | glDisable( GL_TEXTURE_2D ); |
| 2646 | GlobalOpenGL_debugAssertNoErrors(); |
| 2647 | glDisable( GL_LIGHTING ); |
| 2648 | GlobalOpenGL_debugAssertNoErrors(); |
| 2649 | glDisable( GL_COLOR_MATERIAL ); |
| 2650 | GlobalOpenGL_debugAssertNoErrors(); |
| 2651 | |
| 2652 | GlobalOpenGL_debugAssertNoErrors(); |
| 2653 | |
| 2654 | |
| 2655 | // size info |
| 2656 | if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) { |
| 2657 | Vector3 min, max; |
| 2658 | Select_GetBounds( min, max ); |
| 2659 | PaintSizeInfo( nDim1, nDim2, min, max ); |
| 2660 | } |
| 2661 | |
| 2662 | if ( g_xywindow_globals_private.g_bCrossHairs ) { |
| 2663 | glColor4f( 0.2f, 0.9f, 0.2f, 0.8f ); |
| 2664 | glBegin( GL_LINES ); |
| 2665 | if ( m_viewType == XY ) { |
| 2666 | glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] ); |
| 2667 | glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] ); |
| 2668 | glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord ); |
| 2669 | glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord ); |
| 2670 | } |
| 2671 | else if ( m_viewType == YZ ) { |
| 2672 | glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] ); |
| 2673 | glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] ); |
| 2674 | glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord ); |
| 2675 | glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord ); |
| 2676 | } |
| 2677 | else |
| 2678 | { |
| 2679 | glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] ); |
| 2680 | glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] ); |
| 2681 | glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord ); |
| 2682 | glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord ); |
| 2683 | } |
| 2684 | glEnd(); |
| 2685 | } |
| 2686 | |
| 2687 | if ( ClipMode() ) { |
| 2688 | GlobalClipPoints_Draw( m_fScale ); |
| 2689 | } |
| 2690 | |
| 2691 | GlobalOpenGL_debugAssertNoErrors(); |
| 2692 | |
| 2693 | // reset modelview |
| 2694 | glLoadIdentity(); |
| 2695 | glScalef( m_fScale, m_fScale, 1 ); |
| 2696 | glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 ); |
| 2697 | |
| 2698 | glEnable( GL_BLEND ); |
| 2699 | glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO ); |
| 2700 | DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) ); |
| 2701 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
| 2702 | glDisable( GL_BLEND ); |
| 2703 | |
| 2704 | Feedback_draw2D( m_viewType ); |
| 2705 | |
| 2706 | if ( g_xywindow_globals_private.show_outline ) { |
| 2707 | if ( Active() ) { |
| 2708 | glMatrixMode( GL_PROJECTION ); |
| 2709 | glLoadIdentity(); |
| 2710 | glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 ); |
| 2711 | |
| 2712 | glMatrixMode( GL_MODELVIEW ); |
| 2713 | glLoadIdentity(); |
| 2714 | |
| 2715 | // four view mode doesn't colorize |
| 2716 | if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) { |
| 2717 | glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) ); |
| 2718 | } |
| 2719 | else |
| 2720 | { |
| 2721 | switch ( m_viewType ) |
| 2722 | { |
| 2723 | case YZ: |
| 2724 | glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) ); |
| 2725 | break; |
| 2726 | case XZ: |
| 2727 | glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) ); |
| 2728 | break; |
| 2729 | case XY: |
| 2730 | glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) ); |
| 2731 | break; |
| 2732 | } |
| 2733 | } |
| 2734 | glBegin( GL_LINE_LOOP ); |
| 2735 | glVertex2f( 0.5, 0.5 ); |
| 2736 | glVertex2f( m_nWidth - 0.5, 1 ); |
| 2737 | glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 ); |
| 2738 | glVertex2f( 0.5, m_nHeight - 0.5 ); |
| 2739 | glEnd(); |
| 2740 | } |
| 2741 | } |
| 2742 | |
| 2743 | GlobalOpenGL_debugAssertNoErrors(); |
| 2744 | |
| 2745 | glFinish(); |
| 2746 | } |
| 2747 | |
| 2748 | void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){ |
| 2749 | xywnd->XY_ToPoint( x, y, point ); |
| 2750 | xywnd->XY_SnapToGrid( point ); |
| 2751 | |
| 2752 | int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1; |
| 2753 | float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] ); |
| 2754 | point[nDim] = float_snapped( fWorkMid, GetGridSize() ); |
| 2755 | } |
| 2756 | |
| 2757 | void XYWnd::OnEntityCreate( const char* item ){ |
| 2758 | StringOutputStream command; |
| 2759 | command << "entityCreate -class " << item; |
| 2760 | UndoableCommand undo( command.c_str() ); |
| 2761 | Vector3 point; |
| 2762 | XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point ); |
| 2763 | Entity_createFromSelection( item, point ); |
| 2764 | } |
| 2765 | |
| 2766 | |
| 2767 | |
| 2768 | void GetCenterPosition( Vector3& position ){ |
| 2769 | if ( GlobalSelectionSystem().countSelected() != 0 ) { |
| 2770 | Select_GetMid( position ); |
| 2771 | } |
| 2772 | else |
| 2773 | { |
| 2774 | position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() ); |
| 2775 | } |
| 2776 | } |
| 2777 | |
| 2778 | void XYWnd_Centralize( XYWnd* xywnd ){ |
| 2779 | Vector3 position; |
| 2780 | GetCenterPosition( position ); |
| 2781 | xywnd->PositionView( position ); |
| 2782 | } |
| 2783 | |
| 2784 | void XY_Split_Centralize(){ |
| 2785 | Vector3 position; |
| 2786 | GetCenterPosition( position ); |
| 2787 | if ( g_pParentWnd->GetXYWnd() ) { |
| 2788 | g_pParentWnd->GetXYWnd()->PositionView( position ); |
| 2789 | } |
| 2790 | if ( g_pParentWnd->GetXZWnd() ) { |
| 2791 | g_pParentWnd->GetXZWnd()->PositionView( position ); |
| 2792 | } |
| 2793 | if ( g_pParentWnd->GetYZWnd() ) { |
| 2794 | g_pParentWnd->GetYZWnd()->PositionView( position ); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | void XY_Centralize(){ |
| 2799 | if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) { |
| 2800 | // centralize all |
| 2801 | XY_Split_Centralize(); |
| 2802 | return; |
| 2803 | } |
| 2804 | |
| 2805 | XYWnd* xywnd = g_pParentWnd->GetXYWnd(); |
| 2806 | XYWnd_Centralize( xywnd ); |
| 2807 | } |
| 2808 | |
| 2809 | |
| 2810 | |
| 2811 | void GetSelectionBbox( AABB& bounds ){ |
| 2812 | if ( GlobalSelectionSystem().countSelected() != 0 ) { |
| 2813 | Scene_BoundsSelected( GlobalSceneGraph(), bounds ); |
| 2814 | } |
| 2815 | else |
| 2816 | { |
| 2817 | bounds = AABB( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Vector3( 128.f, 128.f, 128.f ) ); |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | void XYWnd_Focus( XYWnd* xywnd ){ |
| 2822 | AABB bounds; |
| 2823 | GetSelectionBbox( bounds ); |
| 2824 | xywnd->FocusOnBounds( bounds ); |
| 2825 | } |
| 2826 | |
| 2827 | void XY_Split_Focus(){ |
| 2828 | AABB bounds; |
| 2829 | GetSelectionBbox( bounds ); |
| 2830 | if ( g_pParentWnd->GetXYWnd() ) { |
| 2831 | g_pParentWnd->GetXYWnd()->FocusOnBounds( bounds ); |
| 2832 | } |
| 2833 | if ( g_pParentWnd->GetXZWnd() ) { |
| 2834 | g_pParentWnd->GetXZWnd()->FocusOnBounds( bounds ); |
| 2835 | } |
| 2836 | if ( g_pParentWnd->GetYZWnd() ) { |
| 2837 | g_pParentWnd->GetYZWnd()->FocusOnBounds( bounds ); |
| 2838 | } |
| 2839 | } |
| 2840 | |
| 2841 | void XY_Focus(){ |
| 2842 | if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) { |
| 2843 | // focus all |
| 2844 | XY_Split_Focus(); |
| 2845 | return; |
| 2846 | } |
| 2847 | |
| 2848 | XYWnd* xywnd = g_pParentWnd->GetXYWnd(); |
| 2849 | XYWnd_Focus( xywnd ); |
| 2850 | } |
| 2851 | |
| 2852 | |
| 2853 | |
| 2854 | void XY_TopFrontSide( VIEWTYPE viewtype ){ |
| 2855 | if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) { |
| 2856 | // cannot do this in a split window |
| 2857 | // do something else that the user may want here |
| 2858 | XY_Split_Centralize(); |
| 2859 | return; |
| 2860 | } |
| 2861 | XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd(); |
| 2862 | xywnd->SetViewType( viewtype ); |
| 2863 | XYWnd_Centralize( xywnd ); |
| 2864 | } |
| 2865 | |
| 2866 | void XY_Top(){ |
| 2867 | XY_TopFrontSide( XY ); |
| 2868 | } |
| 2869 | |
| 2870 | void XY_Side(){ |
| 2871 | XY_TopFrontSide( XZ ); |
| 2872 | } |
| 2873 | |
| 2874 | void XY_Front(){ |
| 2875 | XY_TopFrontSide( YZ ); |
| 2876 | } |
| 2877 | |
| 2878 | void XY_NextView( XYWnd* xywnd ){ |
| 2879 | if ( xywnd->GetViewType() == XY ) { |
| 2880 | xywnd->SetViewType( XZ ); |
| 2881 | } |
| 2882 | else if ( xywnd->GetViewType() == XZ ) { |
| 2883 | xywnd->SetViewType( YZ ); |
| 2884 | } |
| 2885 | else{ |
| 2886 | xywnd->SetViewType( XY ); |
| 2887 | } |
| 2888 | XYWnd_Centralize( xywnd ); |
| 2889 | } |
| 2890 | |
| 2891 | void XY_Next(){ |
| 2892 | if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) { |
| 2893 | // cannot do this in a split window |
| 2894 | // do something else that the user may want here |
| 2895 | XY_Split_Centralize(); |
| 2896 | return; |
| 2897 | } |
| 2898 | XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd(); |
| 2899 | XY_NextView( xywnd ); |
| 2900 | } |
| 2901 | |
| 2902 | void XY_Zoom100(){ |
| 2903 | if ( g_pParentWnd->GetXYWnd() ) { |
| 2904 | g_pParentWnd->GetXYWnd()->SetScale( 1 ); |
| 2905 | } |
| 2906 | if ( g_pParentWnd->GetXZWnd() ) { |
| 2907 | g_pParentWnd->GetXZWnd()->SetScale( 1 ); |
| 2908 | } |
| 2909 | if ( g_pParentWnd->GetYZWnd() ) { |
| 2910 | g_pParentWnd->GetYZWnd()->SetScale( 1 ); |
| 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | void XY_ZoomIn(){ |
| 2915 | g_pParentWnd->ActiveXY()->ZoomIn(); |
| 2916 | } |
| 2917 | |
| 2918 | // NOTE: the zoom out factor is 4/5, we could think about customizing it |
| 2919 | // we don't go below a zoom factor corresponding to 10% of the max world size |
| 2920 | // (this has to be computed against the window size) |
| 2921 | void XY_ZoomOut(){ |
| 2922 | g_pParentWnd->ActiveXY()->ZoomOut(); |
| 2923 | } |
| 2924 | |
| 2925 | |
| 2926 | |
| 2927 | void ToggleShowCrosshair(){ |
| 2928 | g_xywindow_globals_private.g_bCrossHairs ^= 1; |
| 2929 | XY_UpdateAllWindows(); |
| 2930 | } |
| 2931 | |
| 2932 | void ToggleShowSizeInfo(){ |
| 2933 | g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint; |
| 2934 | XY_UpdateAllWindows(); |
| 2935 | } |
| 2936 | |
| 2937 | void ToggleShowGrid(){ |
| 2938 | g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid; |
| 2939 | XY_UpdateAllWindows(); |
| 2940 | } |
| 2941 | |
| 2942 | ToggleShown g_xy_top_shown( true ); |
| 2943 | |
| 2944 | void XY_Top_Shown_Construct( ui::Window parent ){ |
| 2945 | g_xy_top_shown.connect( parent ); |
| 2946 | } |
| 2947 | |
| 2948 | ToggleShown g_yz_side_shown( false ); |
| 2949 | |
| 2950 | void YZ_Side_Shown_Construct( ui::Window parent ){ |
| 2951 | g_yz_side_shown.connect( parent ); |
| 2952 | } |
| 2953 | |
| 2954 | ToggleShown g_xz_front_shown( false ); |
| 2955 | |
| 2956 | void XZ_Front_Shown_Construct( ui::Window parent ){ |
| 2957 | g_xz_front_shown.connect( parent ); |
| 2958 | } |
| 2959 | |
| 2960 | |
| 2961 | class EntityClassMenu : public ModuleObserver |
| 2962 | { |
| 2963 | std::size_t m_unrealised; |
| 2964 | public: |
| 2965 | EntityClassMenu() : m_unrealised( 1 ){ |
| 2966 | } |
| 2967 | void realise(){ |
| 2968 | if ( --m_unrealised == 0 ) { |
| 2969 | } |
| 2970 | } |
| 2971 | void unrealise(){ |
| 2972 | if ( ++m_unrealised == 1 ) { |
| 2973 | if ( XYWnd::m_mnuDrop ) { |
| 2974 | XYWnd::m_mnuDrop.destroy(); |
| 2975 | XYWnd::m_mnuDrop = ui::Menu(ui::null); |
| 2976 | } |
| 2977 | } |
| 2978 | } |
| 2979 | }; |
| 2980 | |
| 2981 | EntityClassMenu g_EntityClassMenu; |
| 2982 | |
| 2983 | |
| 2984 | // Names |
| 2985 | void ShowNamesToggle(){ |
| 2986 | GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() ); |
| 2987 | XY_UpdateAllWindows(); |
| 2988 | } |
| 2989 | |
| 2990 | typedef FreeCaller<void(), ShowNamesToggle> ShowNamesToggleCaller; |
| 2991 | |
| 2992 | void ShowNamesExport( const Callback<void(bool)> & importer ){ |
| 2993 | importer( GlobalEntityCreator().getShowNames() ); |
| 2994 | } |
| 2995 | |
| 2996 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller; |
| 2997 | |
| 2998 | // TargetNames |
| 2999 | void ShowTargetNamesToggle(){ |
| 3000 | GlobalEntityCreator().setShowTargetNames( !GlobalEntityCreator().getShowTargetNames() ); |
| 3001 | XY_UpdateAllWindows(); |
| 3002 | } |
| 3003 | |
| 3004 | typedef FreeCaller<void(), ShowTargetNamesToggle> ShowTargetNamesToggleCaller; |
| 3005 | |
| 3006 | void ShowTargetNamesExport( const Callback<void(bool)> & importer ){ |
| 3007 | importer( GlobalEntityCreator().getShowTargetNames() ); |
| 3008 | } |
| 3009 | |
| 3010 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowTargetNamesExport> ShowTargetNamesExportCaller; |
| 3011 | |
| 3012 | // Angles |
| 3013 | void ShowAnglesToggle(){ |
| 3014 | GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() ); |
| 3015 | XY_UpdateAllWindows(); |
| 3016 | } |
| 3017 | |
| 3018 | typedef FreeCaller<void(), ShowAnglesToggle> ShowAnglesToggleCaller; |
| 3019 | |
| 3020 | void ShowAnglesExport( const Callback<void(bool)> & importer ){ |
| 3021 | importer( GlobalEntityCreator().getShowAngles() ); |
| 3022 | } |
| 3023 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowAnglesExport> ShowAnglesExportCaller; |
| 3024 | |
| 3025 | // Blocks |
| 3026 | void ShowBlocksToggle(){ |
| 3027 | g_xywindow_globals_private.show_blocks ^= 1; |
| 3028 | XY_UpdateAllWindows(); |
| 3029 | } |
| 3030 | |
| 3031 | typedef FreeCaller<void(), ShowBlocksToggle> ShowBlocksToggleCaller; |
| 3032 | |
| 3033 | void ShowBlocksExport( const Callback<void(bool)> & importer ){ |
| 3034 | importer( g_xywindow_globals_private.show_blocks ); |
| 3035 | } |
| 3036 | |
| 3037 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowBlocksExport> ShowBlocksExportCaller; |
| 3038 | |
| 3039 | // Coordinates |
| 3040 | void ShowCoordinatesToggle(){ |
| 3041 | g_xywindow_globals_private.show_coordinates ^= 1; |
| 3042 | XY_UpdateAllWindows(); |
| 3043 | } |
| 3044 | |
| 3045 | typedef FreeCaller<void(), ShowCoordinatesToggle> ShowCoordinatesToggleCaller; |
| 3046 | |
| 3047 | void ShowCoordinatesExport( const Callback<void(bool)> & importer ){ |
| 3048 | importer( g_xywindow_globals_private.show_coordinates ); |
| 3049 | } |
| 3050 | |
| 3051 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowCoordinatesExport> ShowCoordinatesExportCaller; |
| 3052 | |
| 3053 | // Outlines |
| 3054 | void ShowOutlineToggle(){ |
| 3055 | g_xywindow_globals_private.show_outline ^= 1; |
| 3056 | XY_UpdateAllWindows(); |
| 3057 | } |
| 3058 | |
| 3059 | typedef FreeCaller<void(), ShowOutlineToggle> ShowOutlineToggleCaller; |
| 3060 | |
| 3061 | void ShowOutlineExport( const Callback<void(bool)> & importer ){ |
| 3062 | importer( g_xywindow_globals_private.show_outline ); |
| 3063 | } |
| 3064 | |
| 3065 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowOutlineExport> ShowOutlineExportCaller; |
| 3066 | |
| 3067 | // Axes |
| 3068 | void ShowAxesToggle(){ |
| 3069 | g_xywindow_globals_private.show_axis ^= 1; |
| 3070 | XY_UpdateAllWindows(); |
| 3071 | } |
| 3072 | typedef FreeCaller<void(), ShowAxesToggle> ShowAxesToggleCaller; |
| 3073 | |
| 3074 | void ShowAxesExport( const Callback<void(bool)> & importer ){ |
| 3075 | importer( g_xywindow_globals_private.show_axis ); |
| 3076 | } |
| 3077 | |
| 3078 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowAxesExport> ShowAxesExportCaller; |
| 3079 | |
| 3080 | // Workzone |
| 3081 | void ShowWorkzoneToggle(){ |
| 3082 | g_xywindow_globals_private.d_show_work ^= 1; |
| 3083 | XY_UpdateAllWindows(); |
| 3084 | } |
| 3085 | typedef FreeCaller<void(), ShowWorkzoneToggle> ShowWorkzoneToggleCaller; |
| 3086 | |
| 3087 | void ShowWorkzoneExport( const Callback<void(bool)> & importer ){ |
| 3088 | importer( g_xywindow_globals_private.d_show_work ); |
| 3089 | } |
| 3090 | |
| 3091 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowWorkzoneExport> ShowWorkzoneExportCaller; |
| 3092 | |
| 3093 | /* |
| 3094 | BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled ); |
| 3095 | ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller ); |
| 3096 | |
| 3097 | void Texdef_ToggleMoveLock(){ |
| 3098 | g_brush_texturelock_enabled = !g_brush_texturelock_enabled; |
| 3099 | g_texdef_movelock_item.update(); |
| 3100 | } |
| 3101 | */ |
| 3102 | |
| 3103 | // Size |
| 3104 | void ShowSizeToggle(){ |
| 3105 | g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint; |
| 3106 | XY_UpdateAllWindows(); |
| 3107 | } |
| 3108 | typedef FreeCaller<void(), ShowSizeToggle> ShowSizeToggleCaller; |
| 3109 | void ShowSizeExport( const Callback<void(bool)> & importer ){ |
| 3110 | importer( g_xywindow_globals_private.m_bSizePaint ); |
| 3111 | } |
| 3112 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowSizeExportCaller; |
| 3113 | |
| 3114 | // Crosshair |
| 3115 | void ShowCrosshairToggle(){ |
| 3116 | g_xywindow_globals_private.g_bCrossHairs ^= 1; |
| 3117 | XY_UpdateAllWindows(); |
| 3118 | } |
| 3119 | typedef FreeCaller<void(), ShowCrosshairToggle> ShowCrosshairToggleCaller; |
| 3120 | void ShowCrosshairExport( const Callback<void(bool)> & importer ){ |
| 3121 | importer( g_xywindow_globals_private.g_bCrossHairs ); |
| 3122 | } |
| 3123 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowCrosshairExport> ShowCrosshairExportCaller; |
| 3124 | |
| 3125 | // Grid |
| 3126 | void ShowGridToggle(){ |
| 3127 | g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid; |
| 3128 | XY_UpdateAllWindows(); |
| 3129 | } |
| 3130 | typedef FreeCaller<void(), ShowGridToggle> ShowGridToggleCaller; |
| 3131 | void ShowGridTExport( const Callback<void(bool)> & importer ){ |
| 3132 | importer( g_xywindow_globals_private.d_showgrid ); |
| 3133 | } |
| 3134 | typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowGridExportCaller; |
| 3135 | |
| 3136 | |
| 3137 | ShowNamesExportCaller g_show_names_caller; |
| 3138 | Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller ); |
| 3139 | ToggleItem g_show_names( g_show_names_callback ); |
| 3140 | |
| 3141 | ShowTargetNamesExportCaller g_show_targetnames_caller; |
| 3142 | Callback<void(const Callback<void(bool)> &)> g_show_targetnames_callback( g_show_targetnames_caller ); |
| 3143 | ToggleItem g_show_targetnames( g_show_targetnames_callback ); |
| 3144 | |
| 3145 | ShowAnglesExportCaller g_show_angles_caller; |
| 3146 | Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller ); |
| 3147 | ToggleItem g_show_angles( g_show_angles_callback ); |
| 3148 | |
| 3149 | ShowBlocksExportCaller g_show_blocks_caller; |
| 3150 | Callback<void(const Callback<void(bool)> &)> g_show_blocks_callback( g_show_blocks_caller ); |
| 3151 | ToggleItem g_show_blocks( g_show_blocks_callback ); |
| 3152 | |
| 3153 | ShowCoordinatesExportCaller g_show_coordinates_caller; |
| 3154 | Callback<void(const Callback<void(bool)> &)> g_show_coordinates_callback( g_show_coordinates_caller ); |
| 3155 | ToggleItem g_show_coordinates( g_show_coordinates_callback ); |
| 3156 | |
| 3157 | ShowOutlineExportCaller g_show_outline_caller; |
| 3158 | Callback<void(const Callback<void(bool)> &)> g_show_outline_callback( g_show_outline_caller ); |
| 3159 | ToggleItem g_show_outline( g_show_outline_callback ); |
| 3160 | |
| 3161 | ShowAxesExportCaller g_show_axes_caller; |
| 3162 | Callback<void(const Callback<void(bool)> &)> g_show_axes_callback( g_show_axes_caller ); |
| 3163 | ToggleItem g_show_axes( g_show_axes_callback ); |
| 3164 | |
| 3165 | ShowWorkzoneExportCaller g_show_workzone_caller; |
| 3166 | Callback<void(const Callback<void(bool)> &)> g_show_workzone_callback( g_show_workzone_caller ); |
| 3167 | ToggleItem g_show_workzone( g_show_workzone_callback ); |
| 3168 | |
| 3169 | ShowSizeExportCaller g_show_size_caller; |
| 3170 | Callback<void(const Callback<void(bool)> &)> g_show_size_callback( g_show_size_caller ); |
| 3171 | ToggleItem g_show_size( g_show_size_callback ); |
| 3172 | |
| 3173 | ShowCrosshairExportCaller g_show_crosshair_caller; |
| 3174 | Callback<void(const Callback<void(bool)> &)> g_show_crosshair_callback( g_show_crosshair_caller ); |
| 3175 | ToggleItem g_show_crosshair( g_show_crosshair_callback ); |
| 3176 | |
| 3177 | ShowGridExportCaller g_show_grid_caller; |
| 3178 | Callback<void(const Callback<void(bool)> &)> g_show_grid_callback( g_show_grid_caller ); |
| 3179 | ToggleItem g_show_grid( g_show_grid_callback ); |
| 3180 | |
| 3181 | |
| 3182 | void XYShow_registerCommands(){ |
| 3183 | GlobalToggles_insert( "ToggleSizePaint", ShowSizeToggleCaller(), ToggleItem::AddCallbackCaller( g_show_size ), Accelerator( 'J' ) ); |
| 3184 | GlobalToggles_insert( "ToggleCrosshairs", ShowCrosshairToggleCaller(), ToggleItem::AddCallbackCaller( g_show_crosshair ), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3185 | GlobalToggles_insert( "ToggleGrid", ShowGridToggleCaller(), ToggleItem::AddCallbackCaller( g_show_grid ), Accelerator( '0' ) ); |
| 3186 | |
| 3187 | GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) ); |
| 3188 | GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) ); |
| 3189 | GlobalToggles_insert( "ShowTargetNames", ShowTargetNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_targetnames ) ); |
| 3190 | GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) ); |
| 3191 | GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) ); |
| 3192 | GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) ); |
| 3193 | GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) ); |
| 3194 | GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) ); |
| 3195 | } |
| 3196 | |
| 3197 | void XYWnd_registerShortcuts(){ |
| 3198 | command_connect_accelerator( "ToggleCrosshairs" ); |
| 3199 | command_connect_accelerator( "ToggleSizePaint" ); |
| 3200 | } |
| 3201 | |
| 3202 | |
| 3203 | |
| 3204 | void Orthographic_constructPreferences( PreferencesPage& page ){ |
| 3205 | page.appendCheckBox( "", "Solid selection boxes ( no stipple )", g_xywindow_globals.m_bNoStipple ); |
| 3206 | //page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint ); |
| 3207 | page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse ); |
| 3208 | // page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate ); |
| 3209 | page.appendCheckBox( "", "Zoom In to Mouse pointer", g_xywindow_globals.m_bZoomInToPointer ); |
| 3210 | } |
| 3211 | void Orthographic_constructPage( PreferenceGroup& group ){ |
| 3212 | PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) ); |
| 3213 | Orthographic_constructPreferences( page ); |
| 3214 | } |
| 3215 | void Orthographic_registerPreferencesPage(){ |
| 3216 | PreferencesDialog_addSettingsPage( makeCallbackF(Orthographic_constructPage) ); |
| 3217 | } |
| 3218 | |
| 3219 | void Clipper_constructPreferences( PreferencesPage& page ){ |
| 3220 | page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk ); |
| 3221 | } |
| 3222 | void Clipper_constructPage( PreferenceGroup& group ){ |
| 3223 | PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) ); |
| 3224 | Clipper_constructPreferences( page ); |
| 3225 | } |
| 3226 | void Clipper_registerPreferencesPage(){ |
| 3227 | PreferencesDialog_addSettingsPage( makeCallbackF(Clipper_constructPage) ); |
| 3228 | } |
| 3229 | |
| 3230 | |
| 3231 | #include "preferencesystem.h" |
| 3232 | #include "stringio.h" |
| 3233 | |
| 3234 | |
| 3235 | struct ToggleShown_Bool { |
| 3236 | static void Export(const ToggleShown &self, const Callback<void(bool)> &returnz) { |
| 3237 | returnz(self.active()); |
| 3238 | } |
| 3239 | |
| 3240 | static void Import(ToggleShown &self, bool value) { |
| 3241 | self.set(value); |
| 3242 | } |
| 3243 | }; |
| 3244 | |
| 3245 | |
| 3246 | void XYWindow_Construct(){ |
| 3247 | // GlobalCommands_insert( "ToggleCrosshairs", makeCallbackF(ToggleShowCrosshair), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) ); |
| 3248 | // GlobalCommands_insert( "ToggleSizePaint", makeCallbackF(ToggleShowSizeInfo), Accelerator( 'J' ) ); |
| 3249 | // GlobalCommands_insert( "ToggleGrid", makeCallbackF(ToggleShowGrid), Accelerator( '0' ) ); |
| 3250 | |
| 3251 | GlobalToggles_insert( "ToggleView", ToggleShown::ToggleCaller( g_xy_top_shown ), ToggleItem::AddCallbackCaller( g_xy_top_shown.m_item ), Accelerator( 'V', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); |
| 3252 | GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) ); |
| 3253 | GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) ); |
| 3254 | GlobalCommands_insert( "NextView", makeCallbackF(XY_Next), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut |
| 3255 | GlobalCommands_insert( "ZoomIn", makeCallbackF(XY_ZoomIn), Accelerator( GDK_KEY_Delete ) ); |
| 3256 | GlobalCommands_insert( "ZoomOut", makeCallbackF(XY_ZoomOut), Accelerator( GDK_KEY_Insert ) ); |
| 3257 | GlobalCommands_insert( "ViewTop", makeCallbackF(XY_Top), Accelerator( GDK_KEY_KP_Home ) ); |
| 3258 | GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) ); |
| 3259 | GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) ); |
| 3260 | GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) ); |
| 3261 | GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Centralize), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); |
| 3262 | GlobalCommands_insert( "XYFocusOnSelected", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_grave ) ); |
| 3263 | |
| 3264 | GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) ); |
| 3265 | |
| 3266 | // GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) ); |
| 3267 | GlobalPreferenceSystem().registerPreference( "2DZoomInToPointer", make_property_string( g_xywindow_globals.m_bZoomInToPointer ) ); |
| 3268 | GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) ); |
| 3269 | GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) ); |
| 3270 | GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) ); |
| 3271 | GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) ); |
| 3272 | GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) ); |
| 3273 | GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) ); |
| 3274 | GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) ); |
| 3275 | // GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) ); |
| 3276 | GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) ); |
| 3277 | |
| 3278 | GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) ); |
| 3279 | GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) ); |
| 3280 | GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) ); |
| 3281 | GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) ); |
| 3282 | GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) ); |
| 3283 | GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) ); |
| 3284 | GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) ); |
| 3285 | GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) ); |
| 3286 | GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) ); |
| 3287 | GlobalPreferenceSystem().registerPreference( "SI_Colors9", make_property_string( g_xywindow_globals.color_viewname ) ); |
| 3288 | GlobalPreferenceSystem().registerPreference( "SI_Colors10", make_property_string( g_xywindow_globals.color_clipper ) ); |
| 3289 | GlobalPreferenceSystem().registerPreference( "SI_Colors11", make_property_string( g_xywindow_globals.color_selbrushes ) ); |
| 3290 | |
| 3291 | |
| 3292 | GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) ); |
| 3293 | GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) ); |
| 3294 | |
| 3295 | Orthographic_registerPreferencesPage(); |
| 3296 | Clipper_registerPreferencesPage(); |
| 3297 | |
| 3298 | XYWnd::captureStates(); |
| 3299 | GlobalEntityClassManager().attach( g_EntityClassMenu ); |
| 3300 | } |
| 3301 | |
| 3302 | void XYWindow_Destroy(){ |
| 3303 | GlobalEntityClassManager().detach( g_EntityClassMenu ); |
| 3304 | XYWnd::releaseStates(); |
| 3305 | } |