2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // Leonardo Zide (leo@lokigames.com)
32 #include "debugging/debugging.h"
39 #include "ifilesystem.h"
42 #include "gtkutil/messagebox.h"
44 #include <uilib/uilib.h>
45 #include <gdk/gdkkeysyms.h>
47 #include "generic/callback.h"
48 #include "string/string.h"
49 #include "stream/stringstream.h"
52 #include "eclasslib.h"
54 #include "moduleobserver.h"
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"
64 #include "brushmanip.h"
65 #include "selection.h"
67 #include "camwindow.h"
68 #include "texwindow.h"
69 #include "mainframe.h"
70 #include "preferences.h"
74 #include "windowobservers.h"
76 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
79 extern bool g_brush_always_caulk;
85 Vector3 m_ptClip; // the 3d point
92 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
106 /*! Draw clip/path point with rasterized number label */
107 void Draw( int num, float scale );
108 /*! Draw clip/path point with rasterized string label */
109 void Draw( const char *label, float scale );
112 VIEWTYPE g_clip_viewtype;
113 bool g_bSwitch = true;
114 bool g_clip_useCaulk = false;
115 bool g_quick_clipper = false;
119 ClipPoint* g_pMovingClip = 0;
121 /* Drawing clip points */
122 void ClipPoint::Draw( int num, float scale ){
123 StringOutputStream label( 4 );
125 Draw( label.c_str(), scale );
128 void ClipPoint::Draw( const char *label, float scale ){
131 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
132 glBegin( GL_POINTS );
133 glVertex3fv( vector3_to_array( m_ptClip ) );
137 float offset = 2.0f / scale;
140 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
141 //glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label ); //fails with GCC
142 //glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, reinterpret_cast<const GLubyte*>( label ) ); //worx
143 GlobalOpenGL().drawString( label );
146 float fDiff( float f1, float f2 ){
155 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
156 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
157 int nDim2 = ( viewtype == XY ) ? 1 : 2;
158 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
159 if ( screenDistanceSquared < 8 * 8 ) {
160 return screenDistanceSquared;
165 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
167 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
168 if ( distance < bestDistance ) {
169 bestDistance = distance;
175 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
176 double bestDistance = FLT_MAX;
177 ClipPoint* bestClip = 0;
178 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
179 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
180 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
184 inline void GlobalClipPoints_Draw( float scale ){
186 if ( g_Clip1.Set() ) {
187 g_Clip1.Draw( 1, scale );
189 if ( g_Clip2.Set() ) {
190 g_Clip2.Draw( 2, scale );
192 if ( g_Clip3.Set() ) {
193 g_Clip3.Draw( 3, scale );
197 inline bool GlobalClipPoints_valid(){
198 return g_Clip1.Set() && g_Clip2.Set();
201 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
202 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
203 planepts[0] = g_Clip1.m_ptClip;
204 planepts[1] = g_Clip2.m_ptClip;
205 planepts[2] = g_Clip3.m_ptClip;
206 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
207 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
208 if ( !g_Clip3.Set() ) {
209 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
210 int x = ( n == 0 ) ? 1 : 0;
211 int y = ( n == 2 ) ? 1 : 2;
213 if ( n == 1 ) { // on viewtype XZ, flip clip points
214 planepts[0][n] = maxs[n];
215 planepts[1][n] = maxs[n];
216 planepts[2][x] = g_Clip1.m_ptClip[x];
217 planepts[2][y] = g_Clip1.m_ptClip[y];
218 planepts[2][n] = mins[n];
222 planepts[0][n] = mins[n];
223 planepts[1][n] = mins[n];
224 planepts[2][x] = g_Clip1.m_ptClip[x];
225 planepts[2][y] = g_Clip1.m_ptClip[y];
226 planepts[2][n] = maxs[n];
233 if ( !GlobalClipPoints_valid() ) {
234 planepts[0] = Vector3( 0, 0, 0 );
235 planepts[1] = Vector3( 0, 0, 0 );
236 planepts[2] = Vector3( 0, 0, 0 );
237 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
241 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
242 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
244 std::swap( planepts[0], planepts[1] );
246 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
248 ClipperChangeNotify();
251 const char* Clip_getShader(){
252 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
256 if ( ClipMode() && GlobalClipPoints_valid() ) {
258 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
259 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
260 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
265 ClipperChangeNotify();
266 if( g_quick_clipper ){
267 g_quick_clipper = false;
274 if ( ClipMode() && GlobalClipPoints_valid() ) {
276 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
277 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
278 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
283 ClipperChangeNotify();
284 if( g_quick_clipper ){
285 g_quick_clipper = false;
292 g_bSwitch = !g_bSwitch;
294 ClipperChangeNotify();
297 void OnClipMode( bool enabled ){
302 if ( !enabled && g_pMovingClip ) {
307 ClipperChangeNotify();
311 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
314 void NewClipPoint( const Vector3& point ){
315 if ( g_Clip1.Set() == false ) {
316 g_Clip1.m_ptClip = point;
319 else if ( g_Clip2.Set() == false ) {
320 g_Clip2.m_ptClip = point;
323 else if ( g_Clip3.Set() == false ) {
324 g_Clip3.m_ptClip = point;
332 g_Clip1.m_ptClip = point;
337 ClipperChangeNotify();
342 struct xywindow_globals_private_t
346 // these are in the View > Show menu with Show coordinates
348 bool show_coordinates;
358 // bool m_bCamXYUpdate;
364 xywindow_globals_private_t() :
368 show_coordinates( false ),
370 show_outline( true ),
373 d_show_work( false ),
375 show_blocks( false ),
377 // m_bCamXYUpdate( true ),
378 m_bChaseMouse( true ),
379 m_bSizePaint( true ),
381 g_bCrossHairs( false ){
386 xywindow_globals_t g_xywindow_globals;
387 xywindow_globals_private_t g_xywindow_globals_private;
389 const unsigned int RAD_NONE = 0x00;
390 const unsigned int RAD_SHIFT = 0x01;
391 const unsigned int RAD_ALT = 0x02;
392 const unsigned int RAD_CONTROL = 0x04;
393 const unsigned int RAD_PRESS = 0x08;
394 const unsigned int RAD_LBUTTON = 0x10;
395 const unsigned int RAD_MBUTTON = 0x20;
396 const unsigned int RAD_RBUTTON = 0x40;
398 inline ButtonIdentifier button_for_flags( unsigned int flags ){
399 if ( flags & RAD_LBUTTON ) {
402 if ( flags & RAD_RBUTTON ) {
403 return c_buttonRight;
405 if ( flags & RAD_MBUTTON ) {
406 return c_buttonMiddle;
408 return c_buttonInvalid;
411 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
412 ModifierFlags modifiers = c_modifierNone;
413 if ( flags & RAD_SHIFT ) {
414 modifiers |= c_modifierShift;
416 if ( flags & RAD_CONTROL ) {
417 modifiers |= c_modifierControl;
419 if ( flags & RAD_ALT ) {
420 modifiers |= c_modifierAlt;
425 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
426 unsigned int buttons = 0;
428 switch ( button.get() )
430 case ButtonEnumeration::INVALID: break;
431 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
432 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
433 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
436 if ( bitfield_enabled( flags, c_modifierControl ) ) {
437 buttons |= RAD_CONTROL;
440 if ( bitfield_enabled( flags, c_modifierShift ) ) {
441 buttons |= RAD_SHIFT;
444 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
451 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
452 unsigned int flags = 0;
454 switch ( event->button )
456 case 1: flags |= RAD_LBUTTON; break;
457 case 2: flags |= RAD_MBUTTON; break;
458 case 3: flags |= RAD_RBUTTON; break;
461 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
462 flags |= RAD_CONTROL;
465 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
469 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
476 inline unsigned int buttons_for_state( guint state ){
477 unsigned int flags = 0;
479 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
480 flags |= RAD_LBUTTON;
483 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
484 flags |= RAD_MBUTTON;
487 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
488 flags |= RAD_RBUTTON;
491 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
492 flags |= RAD_CONTROL;
495 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
499 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
507 void XYWnd::SetScale( float f ){
511 XYWnd_Update( *this );
514 void XYWnd::ZoomIn(){
515 float max_scale = 64;
516 float scale = Scale() * 5.0f / 4.0f;
517 if ( scale > max_scale ) {
518 if ( Scale() != max_scale ) {
519 SetScale( max_scale );
529 // NOTE: the zoom out factor is 4/5, we could think about customizing it
530 // we don't go below a zoom factor corresponding to 10% of the max world size
531 // (this has to be computed against the window size)
532 void XYWnd::ZoomOut(){
533 float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
534 float scale = Scale() * 4.0f / 5.0f;
535 if ( scale < min_scale ) {
536 if ( Scale() != min_scale ) {
537 SetScale( min_scale );
546 void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
547 float old_scale = Scale();
549 if ( g_xywindow_globals.m_bZoomInToPointer ) {
550 float scale_diff = 1.0 / old_scale - 1.0 / Scale();
551 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
552 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
553 Vector3 origin = GetOrigin();
554 origin[nDim1] += scale_diff * (pointx - 0.5 * Width());
555 origin[nDim2] -= scale_diff * (pointy - 0.5 * Height());
560 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
561 ASSERT_NOTNULL( g_pParentWnd );
562 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
563 return g_pParentWnd->ActiveXY()->GetViewType();
566 // =============================================================================
569 ui::Menu XYWnd::m_mnuDrop(ui::null);
571 // this is disabled, and broken
572 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
576 width = g_pParentWnd->ActiveXY()->Width();
577 height = g_pParentWnd->ActiveXY()->Height();
579 const char* filename;
581 filename = ui::file_dialog( MainFrame_getWindow( ), FALSE, "Save Image", 0, FILTER_BMP );
586 g_pParentWnd->ActiveXY()->MakeCurrent();
587 img = (unsigned char*)malloc( width * height * 3 );
588 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
591 fp = fopen( filename, "wb" );
594 unsigned long cmap, bfSize;
598 bfSize = 54 + width * height * 3;
600 long byteswritten = 0;
601 long pixoff = 54 + cmap * 4;
603 char m1 = 'B', m2 = 'M';
604 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
605 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
606 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
607 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
608 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
609 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
611 unsigned long biSize = 40, compress = 0, size = 0;
613 unsigned short planes = 1;
614 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
615 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
616 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
617 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
618 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
619 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
620 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
621 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
622 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
623 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
624 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
626 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
627 long row, row_size = width * 3;
628 for ( row = 0; row < height; row++ )
630 unsigned char* buf = img + row * row_size;
634 for ( col = 0; col < row_size; col += 3 )
636 putc( buf[col + 2], fp );
637 putc( buf[col + 1], fp );
638 putc( buf[col], fp );
640 byteswritten += row_size;
643 for ( count = row_size; count < widthDW; count++ )
645 putc( 0, fp ); // dummy
660 Timer g_chasemouse_timer;
662 void XYWnd::ChaseMouse(){
663 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
664 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
666 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
668 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
669 g_chasemouse_timer.start();
672 gboolean xywnd_chasemouse( gpointer data ){
673 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
677 inline const int& min_int( const int& left, const int& right ){
678 return std::min( left, right );
681 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
682 m_chasemouse_delta_x = 0;
683 m_chasemouse_delta_y = 0;
685 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
686 const int epsilon = 16;
688 if ( pointx < epsilon ) {
689 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
691 else if ( ( pointx - m_nWidth ) > -epsilon ) {
692 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
695 if ( pointy < epsilon ) {
696 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
698 else if ( ( pointy - m_nHeight ) > -epsilon ) {
699 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
702 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
703 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
704 m_chasemouse_current_x = pointx;
705 m_chasemouse_current_y = pointy;
706 if ( m_chasemouse_handler == 0 ) {
707 //globalOutputStream() << "chasemouse timer start... ";
708 g_chasemouse_timer.start();
709 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
715 if ( m_chasemouse_handler != 0 ) {
716 //globalOutputStream() << "chasemouse cancel\n";
717 g_source_remove( m_chasemouse_handler );
718 m_chasemouse_handler = 0;
724 if ( m_chasemouse_handler != 0 ) {
725 //globalOutputStream() << "chasemouse cancel\n";
726 g_source_remove( m_chasemouse_handler );
727 m_chasemouse_handler = 0;
733 // =============================================================================
735 Shader* XYWnd::m_state_selected = 0;
737 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
738 if ( self.GetWidget().visible() ) {
739 rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() );
740 // int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0;
741 // int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2;
742 // rect.x /= self.Scale();
743 // rect.y /= self.Scale();
744 // rect.w /= self.Scale();
745 // rect.h /= self.Scale();
746 // rect.x += self.GetOrigin()[nDim1];
747 // rect.y += self.GetOrigin()[nDim2];
748 self.m_XORRectangle.set( rect );
752 gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
753 if ( event->type == GDK_BUTTON_PRESS ) {
754 if( !xywnd->Active() ){
755 g_pParentWnd->SetActiveXY( xywnd );
758 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
760 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
765 gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
766 if ( event->type == GDK_BUTTON_RELEASE ) {
767 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
769 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
774 gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
775 if ( event->type == GDK_FOCUS_CHANGE ) {
777 if( !xywnd->Active() ){
778 g_pParentWnd->SetActiveXY( xywnd );
785 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
786 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
789 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
792 gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
793 if( !xywnd->Active() ){
794 g_pParentWnd->SetActiveXY( xywnd );
796 if ( event->direction == GDK_SCROLL_UP ) {
797 xywnd->ZoomInWithMouse( (int)event->x, (int)event->y );
799 else if ( event->direction == GDK_SCROLL_DOWN ) {
805 gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){
806 xywnd->m_nWidth = allocation->width;
807 xywnd->m_nHeight = allocation->height;
808 xywnd->updateProjection();
809 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
813 gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
814 if ( glwidget_make_current( xywnd->GetWidget() ) != FALSE ) {
815 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
816 GlobalOpenGL_debugAssertNoErrors();
818 GlobalOpenGL_debugAssertNoErrors();
820 xywnd->m_XORRectangle.set( rectangle_t() );
822 glwidget_swap_buffers( xywnd->GetWidget() );
828 void XYWnd_CameraMoved( XYWnd& xywnd ){
829 // if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
830 //XYWnd_Update( xywnd );
831 xywnd.UpdateCameraIcon();
836 m_gl_widget( glwidget_new( FALSE ) ),
837 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
838 m_deferred_motion( xywnd_motion, this ),
839 m_parent( ui::null ),
840 m_window_observer( NewWindowObserver() ),
841 m_XORRectangle( m_gl_widget ),
842 m_chasemouse_handler( 0 ){
846 m_bNewBrushDrag = false;
847 m_move_started = false;
848 m_zoom_started = false;
859 m_backgroundActivated = false;
866 m_entityCreate = false;
868 m_mnuDrop = ui::Menu(ui::null);
870 GlobalWindowObservers_add( m_window_observer );
871 GlobalWindowObservers_connectWidget( m_gl_widget );
873 m_window_observer->setRectangleDrawCallback( ReferenceCaller<XYWnd, void(rect_t), xy_update_xor_rectangle>( *this ) );
874 m_window_observer->setView( m_view );
876 g_object_ref( m_gl_widget._handle );
878 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 );
879 gtk_widget_set_can_focus( m_gl_widget, true );
881 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
882 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
884 m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
885 m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
886 m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this ); //works only in floating views layout
887 m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
889 m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
891 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
896 AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) );
897 AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) );
899 PressedButtons_connect( g_pressedButtons, m_gl_widget );
901 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
909 m_mnuDrop = ui::Menu(ui::null);
912 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
913 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
917 m_window_observer->release();
920 void XYWnd::captureStates(){
921 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
924 void XYWnd::releaseStates(){
925 GlobalShaderCache().release( "$XY_OVERLAY" );
928 const Vector3& XYWnd::GetOrigin(){
932 void XYWnd::SetOrigin( const Vector3& origin ){
937 void XYWnd::Scroll( int x, int y ){
938 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
939 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
940 m_vOrigin[nDim1] += x / m_fScale;
941 m_vOrigin[nDim2] += y / m_fScale;
946 unsigned int Clipper_buttons(){
950 unsigned int Clipper_quick_buttons(){
951 return RAD_LBUTTON | RAD_CONTROL;
954 void XYWnd::DropClipPoint( int pointx, int pointy ){
957 XY_ToPoint( pointx, pointy, point );
960 Select_GetMid( mid );
961 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
962 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
963 point[nDim] = mid[nDim];
964 vector3_snap( point, GetSnapGridSize() );
965 NewClipPoint( point );
968 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
969 Vector3 mousePosition;
970 XY_ToPoint( x, y, mousePosition );
971 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
972 if ( !g_pMovingClip ) {
973 DropClipPoint( x, y );
977 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
978 if ( g_pMovingClip ) {
983 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
984 if ( g_pMovingClip ) {
985 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
986 XY_SnapToGrid( g_pMovingClip->m_ptClip );
988 ClipperChangeNotify();
992 //#include "gtkutil/image.h"
994 /* is called on every mouse move fraction; ain't good! */
995 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
996 Vector3 mousePosition;
997 XY_ToPoint( x, y, mousePosition );
999 if( GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ){
1001 cursor = gdk_cursor_new( GDK_CROSSHAIR );
1002 //cursor = gdk_cursor_new( GDK_FLEUR );
1003 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
1004 gdk_cursor_unref( cursor );
1008 cursor = gdk_cursor_new( GDK_HAND2 );
1009 // GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
1010 // cursor = gdk_cursor_new_from_pixbuf( gdk_display_get_default(), pixbuf, 0, 0 );
1011 // g_object_unref( pixbuf );
1012 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
1013 gdk_cursor_unref( cursor );
1019 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), 0 );
1023 void XYWnd::SetCustomPivotOrigin( int pointx, int pointy ){
1025 XY_ToPoint( pointx, pointy, point );
1026 VIEWTYPE viewtype = static_cast<VIEWTYPE>( GetViewType() );
1027 const int nDim = ( viewtype == YZ ) ? 0 : ( ( viewtype == XZ ) ? 1 : 2 );
1028 //vector3_snap( point, GetSnapGridSize() );
1029 point[nDim] = 999999;
1031 GlobalSelectionSystem().setCustomPivotOrigin( point );
1032 SceneChangeNotify();
1035 unsigned int MoveCamera_buttons(){
1036 // return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
1037 return RAD_CONTROL | RAD_MBUTTON;
1040 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1041 Vector3 origin( Camera_getOrigin( camwnd ) );
1042 xywnd->XY_ToPoint( x, y, origin );
1043 xywnd->XY_SnapToGrid( origin );
1044 Camera_setOrigin( camwnd, origin );
1047 unsigned int OrientCamera_buttons(){
1048 // if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
1049 // return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1054 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1055 //globalOutputStream() << Camera_getAngles( camwnd ) << " b4\n";
1056 Vector3 point = g_vector3_identity;
1057 xywnd->XY_ToPoint( x, y, point );
1058 //xywnd->XY_SnapToGrid( point );
1059 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1061 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1062 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1063 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1064 if ( point[n1] || point[n2] ) {
1065 Vector3 angles( Camera_getAngles( camwnd ) );
1066 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1067 if( angles[CAMERA_YAW] < 0 )
1068 angles[CAMERA_YAW] = angles[CAMERA_YAW] + 360;
1069 if ( nAngle == CAMERA_PITCH ){
1070 if( fabs( angles[CAMERA_PITCH] ) > 90 ){
1071 angles[CAMERA_PITCH] = ( angles[CAMERA_PITCH] > 0 ) ? ( -angles[CAMERA_PITCH] + 180 ) : ( -angles[CAMERA_PITCH] - 180 );
1072 if( xywnd->GetViewType() == YZ ){
1073 if( angles[CAMERA_YAW] < 180 ){
1074 angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
1077 else if( angles[CAMERA_YAW] < 90 || angles[CAMERA_YAW] > 270 ){
1078 angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW];
1082 if( xywnd->GetViewType() == YZ ){
1083 if( angles[CAMERA_YAW] > 180 ){
1084 angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
1087 else if( angles[CAMERA_YAW] > 90 && angles[CAMERA_YAW] < 270 ){
1088 angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW];
1092 Camera_setAngles( camwnd, angles );
1094 //globalOutputStream() << Camera_getAngles( camwnd ) << "\n";
1097 unsigned int SetCustomPivotOrigin_buttons(){
1098 return RAD_MBUTTON | RAD_SHIFT;
1106 unsigned int NewBrushDrag_buttons(){
1110 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1112 m_nNewBrushPressx = x;
1113 m_nNewBrushPressy = y;
1115 m_bNewBrushDrag = true;
1118 void XYWnd::NewBrushDrag_End( int x, int y ){
1119 if ( m_NewBrushDrag != 0 ) {
1120 GlobalUndoSystem().finish( "brushDragNew" );
1124 void XYWnd::NewBrushDrag( int x, int y ){
1126 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1127 XY_SnapToGrid( mins );
1128 XY_ToPoint( x, y, maxs );
1129 XY_SnapToGrid( maxs );
1131 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1133 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1134 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1136 if ( maxs[nDim] <= mins[nDim] ) {
1137 maxs[nDim] = mins[nDim] + GetGridSize();
1140 for ( int i = 0 ; i < 3 ; i++ )
1142 if ( mins[i] == maxs[i] ) {
1143 return; // don't create a degenerate brush
1145 if ( mins[i] > maxs[i] ) {
1146 float temp = mins[i];
1152 if ( m_NewBrushDrag == 0 ) {
1153 GlobalUndoSystem().start();
1154 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1155 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1157 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1158 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1159 brushpath.push( makeReference( node.get() ) );
1160 selectPath( brushpath, true );
1162 m_NewBrushDrag = node.get_pointer();
1166 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1167 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1168 g_brush_always_caulk ?
1169 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1172 void entitycreate_activated( ui::Widget item ){
1173 scene::Node* world_node = Map_FindWorldspawn( g_map );
1174 const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) );
1176 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1177 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1180 GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(), "There's already a worldspawn in your map!"
1188 void EntityClassMenu_addItem( ui::Menu menu, const char* name ){
1189 auto item = ui::MenuItem( name );
1190 item.connect( "activate", G_CALLBACK( entitycreate_activated ), item );
1192 menu_add_item( menu, item );
1195 class EntityClassMenuInserter : public EntityClassVisitor
1197 typedef std::pair<ui::Menu, CopiedString> MenuPair;
1198 typedef std::vector<MenuPair> MenuStack;
1200 CopiedString m_previous;
1202 EntityClassMenuInserter( ui::Menu menu ){
1203 m_stack.reserve( 2 );
1204 m_stack.push_back( MenuPair( menu, "" ) );
1206 ~EntityClassMenuInserter(){
1207 if ( !string_empty( m_previous.c_str() ) ) {
1208 addItem( m_previous.c_str(), "" );
1211 void visit( EntityClass* e ){
1212 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1213 if ( !string_empty( m_previous.c_str() ) ) {
1214 addItem( m_previous.c_str(), e->name() );
1216 m_previous = e->name();
1218 void pushMenu( const CopiedString& name ){
1219 auto item = ui::MenuItem( name.c_str() );
1221 m_stack.back().first.add(item);
1223 auto submenu = ui::Menu(ui::New);
1224 gtk_menu_item_set_submenu( item, submenu );
1226 m_stack.push_back( MenuPair( submenu, name ) );
1231 void addItem( const char* name, const char* next ){
1232 const char* underscore = strchr( name, '_' );
1234 if ( underscore != 0 && underscore != name ) {
1235 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1236 const char* parent = m_stack.back().second.c_str();
1238 if ( !string_empty( parent )
1239 && string_length( parent ) == std::size_t( underscore - name )
1240 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1242 else if ( nextEqual ) {
1243 if ( m_stack.size() == 2 ) {
1246 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1248 else if ( m_stack.size() == 2 ) {
1252 else if ( m_stack.size() == 2 ) {
1256 EntityClassMenu_addItem( m_stack.back().first, name );
1260 void XYWnd::OnContextMenu(){
1261 // if ( g_xywindow_globals.m_bRightClick == false ) {
1265 if ( !m_mnuDrop ) { // first time, load it up
1266 auto menu = m_mnuDrop = ui::Menu(ui::New);
1268 EntityClassMenuInserter inserter( menu );
1269 GlobalEntityClassManager().forEach( inserter );
1272 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1275 FreezePointer g_xywnd_freezePointer;
1277 unsigned int Move_buttons(){
1281 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1282 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1283 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1286 gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1291 void XYWnd::Move_Begin(){
1292 if ( m_move_started ) {
1295 m_move_started = true;
1296 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this );
1297 m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1300 void XYWnd::Move_End(){
1301 m_move_started = false;
1302 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false );
1303 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1306 unsigned int Zoom_buttons(){
1307 return RAD_RBUTTON | RAD_ALT;
1314 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1317 while ( abs( g_dragZoom ) > 8 )
1319 if ( g_dragZoom > 0 ) {
1320 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1325 if ( g_xywindow_globals.m_bZoomInToPointer ) {
1326 reinterpret_cast<XYWnd*>( data )->ZoomInWithMouse( g_zoom2x, g_zoom2y );
1329 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1337 gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1342 void XYWnd::Zoom_Begin( int x, int y ){
1343 if ( m_zoom_started ) {
1346 m_zoom_started = true;
1350 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this );
1351 m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1354 void XYWnd::Zoom_End(){
1355 m_zoom_started = false;
1356 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false );
1357 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1360 // makes sure the selected brush or camera is in view
1361 void XYWnd::PositionView( const Vector3& position ){
1362 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1363 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1365 m_vOrigin[nDim1] = position[nDim1];
1366 m_vOrigin[nDim2] = position[nDim2];
1370 XYWnd_Update( *this );
1373 void XYWnd::SetViewType( VIEWTYPE viewType ){
1374 m_viewType = viewType;
1378 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1383 inline WindowVector WindowVector_forInteger( int x, int y ){
1384 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1387 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1388 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1390 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1391 if ( buttons == Move_buttons() ) {
1393 EntityCreate_MouseDown( x, y );
1395 else if ( buttons == Zoom_buttons() ) {
1398 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1399 Clipper_OnLButtonDown( x, y );
1401 else if ( !ClipMode() && buttons == Clipper_quick_buttons() ) {
1403 g_quick_clipper = true;
1404 Clipper_OnLButtonDown( x, y );
1406 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1407 NewBrushDrag_Begin( x, y );
1409 // control mbutton = move camera
1410 else if ( buttons == MoveCamera_buttons() ) {
1411 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1413 // mbutton = angle camera
1414 else if ( buttons == OrientCamera_buttons() ) {
1415 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1417 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1418 SetCustomPivotOrigin( x, y );
1422 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1426 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1427 if ( m_move_started ) {
1429 EntityCreate_MouseUp( x, y );
1431 else if ( m_zoom_started ) {
1434 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1435 Clipper_OnLButtonUp( x, y );
1437 else if ( m_bNewBrushDrag ) {
1438 m_bNewBrushDrag = false;
1439 NewBrushDrag_End( x, y );
1440 if ( m_NewBrushDrag == 0 ) {
1441 //L button w/o created brush = tunnel selection
1442 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1447 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1451 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1452 // rbutton = drag xy origin
1453 if ( m_move_started ) {
1456 else if ( m_zoom_started ) {
1459 else if ( ClipMode() && g_pMovingClip != 0 ) {
1460 Clipper_OnMouseMoved( x, y );
1462 // lbutton without selection = drag new brush
1463 else if ( m_bNewBrushDrag ) {
1464 NewBrushDrag( x, y );
1467 // control mbutton = move camera
1468 else if ( buttons == MoveCamera_buttons() ) {
1469 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1472 // mbutton = angle camera
1473 else if ( buttons == OrientCamera_buttons() ) {
1474 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1477 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1478 SetCustomPivotOrigin( x, y );
1483 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1485 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1486 XY_ToPoint( x, y, m_mousePosition );
1487 XY_SnapToGrid( m_mousePosition );
1489 StringOutputStream status( 64 );
1490 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1491 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1492 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1493 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1495 if ( g_xywindow_globals_private.g_bCrossHairs ) {
1496 XYWnd_Update( *this );
1499 Clipper_Crosshair_OnMouseMoved( x, y );
1503 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1504 m_entityCreate = true;
1505 m_entityCreate_x = x;
1506 m_entityCreate_y = y;
1509 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1510 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1511 m_entityCreate = false;
1515 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1516 if ( m_entityCreate ) {
1517 m_entityCreate = false;
1522 inline float screen_normalised( int pos, unsigned int size ){
1523 return ( ( 2.0f * pos ) / size ) - 1.0f;
1526 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1527 return world_origin + normalised * normalised2world_scale;
1531 // TTimo: watch it, this doesn't init one of the 3 coords
1532 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1533 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1534 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1535 if ( m_viewType == XY ) {
1536 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1537 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1539 else if ( m_viewType == YZ ) {
1540 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1541 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1545 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1546 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1550 void XYWnd::XY_SnapToGrid( Vector3& point ){
1551 if ( m_viewType == XY ) {
1552 point[0] = float_snapped( point[0], GetSnapGridSize() );
1553 point[1] = float_snapped( point[1], GetSnapGridSize() );
1555 else if ( m_viewType == YZ ) {
1556 point[1] = float_snapped( point[1], GetSnapGridSize() );
1557 point[2] = float_snapped( point[2], GetSnapGridSize() );
1561 point[0] = float_snapped( point[0], GetSnapGridSize() );
1562 point[2] = float_snapped( point[2], GetSnapGridSize() );
1566 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1567 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1568 if ( relative == name ) {
1569 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1572 char fileNameWithoutExt[512];
1573 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1574 fileNameWithoutExt[512 - 1] = '\0';
1575 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1577 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1579 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1582 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1583 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1584 globalOutputStream() << "Loaded background texture " << relative << "\n";
1585 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1588 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1605 Select_GetBounds( min, max );
1606 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1607 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1608 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1609 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1612 void XYWnd::XY_DisableBackground( void ){
1613 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1614 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1615 free( g_pParentWnd->ActiveXY()->m_tex );
1617 g_pParentWnd->ActiveXY()->m_tex = NULL;
1620 void WXY_BackgroundSelect( void ){
1621 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1622 if ( !brushesSelected ) {
1623 ui::alert( ui::root, "You have to select some brushes to get the bounding box for.\n",
1624 "No selection", ui::alert_type::OK, ui::alert_icon::Error );
1628 const char *filename = MainFrame_getWindow().file_dialog( TRUE, "Background Image", NULL, NULL );
1629 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1631 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1636 ============================================================================
1640 ============================================================================
1649 double two_to_the_power( int power ){
1650 return pow( 2.0f, power );
1653 void XYWnd::XY_DrawAxis( void ){
1654 if ( g_xywindow_globals_private.show_axis ) {
1655 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1656 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1657 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1658 const int w = ( m_nWidth / 2 / m_fScale );
1659 const int h = ( m_nHeight / 2 / m_fScale );
1661 Vector3 colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1662 Vector3 colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1664 float grayX = vector3_dot( colourX, Vector3( 0.2989, 0.5870, 0.1140 ) );
1665 float grayY = vector3_dot( colourY, Vector3( 0.2989, 0.5870, 0.1140 ) );
1666 colourX[0] = colourX[1] = colourX[2] = grayX;
1667 colourY[0] = colourY[1] = colourY[2] = grayY;
1670 // draw two lines with corresponding axis colors to highlight current view
1671 // horizontal line: nDim1 color
1673 glBegin( GL_LINES );
1674 glColor3fv( vector3_to_array( colourX ) );
1675 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1676 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1678 glVertex2f( 32 / m_fScale, 0 );
1679 glColor3fv( vector3_to_array( colourY ) );
1680 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1681 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1683 glVertex2f( 0, 32 / m_fScale );
1686 // now print axis symbols
1687 glColor3fv( vector3_to_array( colourX ) );
1688 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1689 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1690 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1691 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1692 glColor3fv( vector3_to_array( colourY ) );
1693 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1694 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1695 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1696 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1700 void XYWnd::RenderActive( void ){
1701 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1702 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1703 GlobalOpenGL_debugAssertNoErrors();
1704 glDrawBuffer( GL_FRONT );
1706 if ( g_xywindow_globals_private.show_outline ) {
1707 glMatrixMode( GL_PROJECTION );
1709 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1711 glMatrixMode( GL_MODELVIEW );
1714 if( !Active() ){ //sorta erase
1715 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridmajor ) );
1717 // four view mode doesn't colorize
1718 else if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
1719 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1723 switch ( m_viewType )
1726 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
1729 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
1732 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
1736 glBegin( GL_LINE_LOOP );
1737 glVertex2f( 0.5, 0.5 );
1738 glVertex2f( m_nWidth - 0.5, 1 );
1739 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
1740 glVertex2f( 0.5, m_nHeight - 0.5 );
1743 // we do this part (the old way) only if show_axis is disabled
1744 if ( !g_xywindow_globals_private.show_axis ) {
1745 glMatrixMode( GL_PROJECTION );
1747 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1749 glMatrixMode( GL_MODELVIEW );
1753 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1756 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1759 glDisable( GL_BLEND );
1760 glRasterPos2f( 35, m_nHeight - 20 );
1762 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1766 glViewport( 0, 0, m_nWidth, m_nHeight );
1768 glMatrixMode( GL_PROJECTION );
1769 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
1771 glMatrixMode( GL_MODELVIEW );
1773 glScalef( m_fScale, m_fScale, 1 );
1774 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1775 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1776 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
1778 glDisable( GL_LINE_STIPPLE );
1779 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1780 glDisableClientState( GL_NORMAL_ARRAY );
1781 glDisableClientState( GL_COLOR_ARRAY );
1782 glDisable( GL_TEXTURE_2D );
1783 glDisable( GL_LIGHTING );
1784 glDisable( GL_COLOR_MATERIAL );
1785 glDisable( GL_DEPTH_TEST );
1786 glDisable( GL_TEXTURE_1D );
1787 glDisable( GL_BLEND );
1789 XYWnd::XY_DrawAxis();
1792 glDrawBuffer( GL_BACK );
1793 GlobalOpenGL_debugAssertNoErrors();
1794 glwidget_make_current( m_gl_widget );
1799 void XYWnd::XY_DrawBackground( void ){
1800 glPushAttrib( GL_ALL_ATTRIB_BITS );
1802 glEnable( GL_TEXTURE_2D );
1803 glEnable( GL_BLEND );
1804 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1805 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1806 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1807 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1809 glPolygonMode( GL_FRONT, GL_FILL );
1811 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1812 glBegin( GL_QUADS );
1814 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1815 glTexCoord2f( 0.0, 1.0 );
1816 glVertex2f( m_xmin, m_ymin );
1818 glTexCoord2f( 1.0, 1.0 );
1819 glVertex2f( m_xmax, m_ymin );
1821 glTexCoord2f( 1.0, 0.0 );
1822 glVertex2f( m_xmax, m_ymax );
1824 glTexCoord2f( 0.0, 0.0 );
1825 glVertex2f( m_xmin, m_ymax );
1828 glBindTexture( GL_TEXTURE_2D, 0 );
1833 void XYWnd::XY_DrawGrid( void ) {
1834 float x, y, xb, xe, yb, ye;
1837 float step, minor_step, stepx, stepy;
1838 step = minor_step = stepx = stepy = GetGridSize();
1840 int minor_power = Grid_getPower();
1843 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1847 int power = minor_power;
1848 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1850 step = float(two_to_the_power( power ) );
1852 mask = ( 1 << ( power - minor_power ) ) - 1;
1853 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1855 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1858 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1860 glDisable( GL_TEXTURE_2D );
1861 glDisable( GL_TEXTURE_1D );
1862 glDisable( GL_DEPTH_TEST );
1863 glDisable( GL_BLEND );
1866 w = ( m_nWidth / 2 / m_fScale );
1867 h = ( m_nHeight / 2 / m_fScale );
1869 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1870 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1872 xb = m_vOrigin[nDim1] - w;
1873 if ( xb < region_mins[nDim1] ) {
1874 xb = region_mins[nDim1];
1876 xb = step * floor( xb / step );
1878 xe = m_vOrigin[nDim1] + w;
1879 if ( xe > region_maxs[nDim1] ) {
1880 xe = region_maxs[nDim1];
1882 xe = step * ceil( xe / step );
1884 yb = m_vOrigin[nDim2] - h;
1885 if ( yb < region_mins[nDim2] ) {
1886 yb = region_mins[nDim2];
1888 yb = step * floor( yb / step );
1890 ye = m_vOrigin[nDim2] + h;
1891 if ( ye > region_maxs[nDim2] ) {
1892 ye = region_maxs[nDim2];
1894 ye = step * ceil( ye / step );
1896 #define COLORS_DIFFER( a,b ) \
1897 ( ( a )[0] != ( b )[0] || \
1898 ( a )[1] != ( b )[1] || \
1899 ( a )[2] != ( b )[2] )
1902 // draw minor blocks
1903 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1905 glEnable( GL_BLEND );
1908 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1909 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1911 glBegin( GL_LINES );
1913 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1914 if ( ( i & mask ) != 0 ) {
1915 glVertex2f( x, yb );
1916 glVertex2f( x, ye );
1920 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1921 if ( ( i & mask ) != 0 ) {
1922 glVertex2f( xb, y );
1923 glVertex2f( xe, y );
1929 // draw major blocks
1930 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1931 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1933 glBegin( GL_LINES );
1934 for ( x = xb ; x <= xe ; x += step ) {
1935 glVertex2f( x, yb );
1936 glVertex2f( x, ye );
1938 for ( y = yb ; y <= ye ; y += step ) {
1939 glVertex2f( xb, y );
1940 glVertex2f( xe, y );
1946 glDisable( GL_BLEND );
1950 // draw coordinate text if needed
1951 if ( g_xywindow_globals_private.show_coordinates ) {
1952 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1953 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1954 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1955 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1956 glRasterPos2f( x, offx );
1957 sprintf( text, "%g", x );
1958 GlobalOpenGL().drawString( text );
1960 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1961 glRasterPos2f( offy, y );
1962 sprintf( text, "%g", y );
1963 GlobalOpenGL().drawString( text );
1967 // we do this part (the old way) only if show_axis is disabled
1968 if ( !g_xywindow_globals_private.show_axis ) {
1970 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1973 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1976 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1978 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1981 XYWnd::XY_DrawAxis();
1983 // show current work zone?
1984 // the work zone is used to place dropped points and brushes
1985 if ( g_xywindow_globals_private.d_show_work ) {
1986 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1987 glBegin( GL_LINES );
1988 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1989 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1990 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1991 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1992 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1993 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1994 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1995 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
2005 void XYWnd::XY_DrawBlockGrid(){
2006 if ( Map_FindWorldspawn( g_map ) == 0 ) {
2009 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
2010 if ( strlen( value ) ) {
2011 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
2014 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
2015 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
2016 g_xywindow_globals_private.blockSize = 1024;
2019 float x, y, xb, xe, yb, ye;
2023 glDisable( GL_TEXTURE_2D );
2024 glDisable( GL_TEXTURE_1D );
2025 glDisable( GL_DEPTH_TEST );
2026 glDisable( GL_BLEND );
2028 w = ( m_nWidth / 2 / m_fScale );
2029 h = ( m_nHeight / 2 / m_fScale );
2031 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2032 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2034 xb = m_vOrigin[nDim1] - w;
2035 if ( xb < region_mins[nDim1] ) {
2036 xb = region_mins[nDim1];
2038 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
2040 xe = m_vOrigin[nDim1] + w;
2041 if ( xe > region_maxs[nDim1] ) {
2042 xe = region_maxs[nDim1];
2044 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
2046 yb = m_vOrigin[nDim2] - h;
2047 if ( yb < region_mins[nDim2] ) {
2048 yb = region_mins[nDim2];
2050 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
2052 ye = m_vOrigin[nDim2] + h;
2053 if ( ye > region_maxs[nDim2] ) {
2054 ye = region_maxs[nDim2];
2056 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
2058 // draw major blocks
2060 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
2063 glBegin( GL_LINES );
2065 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
2067 glVertex2f( x, yb );
2068 glVertex2f( x, ye );
2071 if ( m_viewType == XY ) {
2072 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
2074 glVertex2f( xb, y );
2075 glVertex2f( xe, y );
2082 // draw coordinate text if needed
2084 if ( m_viewType == XY && m_fScale > .1 ) {
2085 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
2086 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
2088 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
2089 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
2090 GlobalOpenGL().drawString( text );
2094 glColor4f( 0, 0, 0, 0 );
2097 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
2098 Cam.fov = 48 / m_fScale;
2099 Cam.box = 16 / m_fScale;
2100 // globalOutputStream() << "pitch " << angles[CAMERA_PITCH] << " yaw " << angles[CAMERA_YAW] << "\n";
2102 if ( m_viewType == XY ) {
2105 Cam.a = degrees_to_radians( angles[CAMERA_YAW] );
2107 else if ( m_viewType == YZ ) {
2110 Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] > 180 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] );
2116 Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] < 270 && angles[CAMERA_YAW] > 90 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] );
2119 //glColor3f( 0.0, 0.0, 1.0 );
2120 glColor3f( 1.0, 1.0, 1.0 );
2121 glBegin( GL_LINE_STRIP );
2122 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2123 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2124 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2125 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2126 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2127 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2130 glBegin( GL_LINE_STRIP );
2131 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 );
2132 glVertex3f( Cam.x, Cam.y, 0 );
2133 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 );
2138 void XYWnd::UpdateCameraIcon( void ){
2139 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
2140 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
2141 GlobalOpenGL_debugAssertNoErrors();
2142 glDrawBuffer( GL_FRONT );
2145 glViewport( 0, 0, m_nWidth, m_nHeight );
2147 glMatrixMode( GL_PROJECTION );
2148 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2150 glMatrixMode( GL_MODELVIEW );
2152 glScalef( m_fScale, m_fScale, 1 );
2153 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2154 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2155 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2157 glDisable( GL_LINE_STIPPLE );
2158 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2159 glDisableClientState( GL_NORMAL_ARRAY );
2160 glDisableClientState( GL_COLOR_ARRAY );
2161 glDisable( GL_TEXTURE_2D );
2162 glDisable( GL_LIGHTING );
2163 glDisable( GL_COLOR_MATERIAL );
2164 glDisable( GL_DEPTH_TEST );
2165 glDisable( GL_TEXTURE_1D );
2167 glEnable( GL_BLEND );
2168 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2170 //glColor3f( 0.0, 0.0, 1.0 );
2171 glColor3f( 1.0, 1.0, 1.0 );
2172 glBegin( GL_LINE_STRIP );
2173 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2174 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2175 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2176 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2177 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2178 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2181 glBegin( GL_LINE_STRIP );
2182 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 );
2183 glVertex3f( Cam.x, Cam.y, 0 );
2184 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 );
2187 XYWnd::DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2189 glDisable( GL_BLEND );
2190 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
2193 glDrawBuffer( GL_BACK );
2194 GlobalOpenGL_debugAssertNoErrors();
2195 glwidget_make_current( m_gl_widget );
2201 float Betwixt( float f1, float f2 ){
2203 return f2 + ( ( f1 - f2 ) / 2 );
2206 return f1 + ( ( f2 - f1 ) / 2 );
2211 // can be greatly simplified but per usual i am in a hurry
2212 // which is not an excuse, just a fact
2213 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
2214 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
2217 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
2218 typedef const char* OrgStrings[2];
2219 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
2221 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
2223 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
2224 g_xywindow_globals.color_selbrushes[1] * .65f,
2225 g_xywindow_globals.color_selbrushes[2] * .65f );
2227 StringOutputStream dimensions( 16 );
2229 if ( m_viewType == XY ) {
2230 glBegin( GL_LINES );
2232 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2233 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2235 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2236 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2238 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2239 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2242 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2243 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2245 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2246 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2248 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2249 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2253 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
2254 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2255 GlobalOpenGL().drawString( dimensions.c_str() );
2258 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
2259 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2260 GlobalOpenGL().drawString( dimensions.c_str() );
2263 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
2264 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2265 GlobalOpenGL().drawString( dimensions.c_str() );
2267 else if ( m_viewType == XZ ) {
2268 glBegin( GL_LINES );
2270 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
2271 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
2273 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2274 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2276 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2277 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2280 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2281 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2283 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2284 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2286 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2287 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2291 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2292 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2293 GlobalOpenGL().drawString( dimensions.c_str() );
2296 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2297 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2298 GlobalOpenGL().drawString( dimensions.c_str() );
2301 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2302 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2303 GlobalOpenGL().drawString( dimensions.c_str() );
2307 glBegin( GL_LINES );
2309 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2310 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2312 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2313 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2315 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2316 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2319 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2320 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2322 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2323 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2325 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2326 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2330 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2331 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2332 GlobalOpenGL().drawString( dimensions.c_str() );
2335 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2336 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2337 GlobalOpenGL().drawString( dimensions.c_str() );
2340 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2341 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2342 GlobalOpenGL().drawString( dimensions.c_str() );
2346 class XYRenderer : public Renderer
2354 unsigned int m_highlight;
2358 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2359 m_globalstate( globalstate ),
2360 m_state_selected( selected ){
2361 ASSERT_NOTNULL( selected );
2362 m_state_stack.push_back( state_type() );
2365 void SetState( Shader* state, EStyle style ){
2366 ASSERT_NOTNULL( state );
2367 if ( style == eWireframeOnly ) {
2368 m_state_stack.back().m_state = state;
2371 EStyle getStyle() const {
2372 return eWireframeOnly;
2375 m_state_stack.push_back( m_state_stack.back() );
2378 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2379 m_state_stack.pop_back();
2381 void Highlight( EHighlightMode mode, bool bEnable = true ){
2383 ? m_state_stack.back().m_highlight |= mode
2384 : m_state_stack.back().m_highlight &= ~mode;
2386 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2387 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2388 m_state_selected->addRenderable( renderable, localToWorld );
2392 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2396 void render( const Matrix4& modelview, const Matrix4& projection ){
2397 GlobalShaderCache().render( m_globalstate, modelview, projection );
2400 std::vector<state_type> m_state_stack;
2401 RenderStateFlags m_globalstate;
2402 Shader* m_state_selected;
2405 void XYWnd::updateProjection(){
2406 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2407 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2408 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2410 m_projection[12] = 0.0f;
2411 m_projection[13] = 0.0f;
2412 m_projection[14] = -1.0f;
2424 m_projection[11] = 0.0f;
2426 m_projection[15] = 1.0f;
2428 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2431 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2432 void XYWnd::updateModelview(){
2433 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2434 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2437 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2438 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2439 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2442 switch ( m_viewType )
2445 m_modelview[0] = m_fScale;
2450 m_modelview[5] = m_fScale;
2455 m_modelview[10] = -m_fScale;
2458 m_modelview[0] = m_fScale;
2464 m_modelview[6] = m_fScale;
2467 m_modelview[9] = m_fScale;
2468 m_modelview[10] = 0;
2473 m_modelview[2] = -m_fScale;
2475 m_modelview[4] = m_fScale;
2480 m_modelview[9] = m_fScale;
2481 m_modelview[10] = 0;
2485 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2486 m_modelview[15] = 1;
2488 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2497 //#define DBG_SCENEDUMP
2499 void XYWnd::XY_Draw(){
2503 glViewport( 0, 0, m_nWidth, m_nHeight );
2504 glClearColor( g_xywindow_globals.color_gridback[0],
2505 g_xywindow_globals.color_gridback[1],
2506 g_xywindow_globals.color_gridback[2],0 );
2508 glClear( GL_COLOR_BUFFER_BIT );
2514 glMatrixMode( GL_PROJECTION );
2515 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2517 glMatrixMode( GL_MODELVIEW );
2519 glScalef( m_fScale, m_fScale, 1 );
2520 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2521 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2522 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2524 glDisable( GL_LINE_STIPPLE );
2526 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2527 glDisableClientState( GL_NORMAL_ARRAY );
2528 glDisableClientState( GL_COLOR_ARRAY );
2529 glDisable( GL_TEXTURE_2D );
2530 glDisable( GL_LIGHTING );
2531 glDisable( GL_COLOR_MATERIAL );
2532 glDisable( GL_DEPTH_TEST );
2534 if ( m_backgroundActivated ) {
2535 XY_DrawBackground();
2539 if ( g_xywindow_globals_private.show_blocks ) {
2543 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2545 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2546 if ( !g_xywindow_globals.m_bNoStipple ) {
2547 globalstate |= RENDER_LINESTIPPLE;
2551 XYRenderer renderer( globalstate, m_state_selected );
2553 Scene_Render( renderer, m_view );
2555 GlobalOpenGL_debugAssertNoErrors();
2556 renderer.render( m_modelview, m_projection );
2557 GlobalOpenGL_debugAssertNoErrors();
2560 glDepthMask( GL_FALSE );
2562 GlobalOpenGL_debugAssertNoErrors();
2564 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2566 GlobalOpenGL_debugAssertNoErrors();
2567 glDisable( GL_LINE_STIPPLE );
2568 GlobalOpenGL_debugAssertNoErrors();
2570 GlobalOpenGL_debugAssertNoErrors();
2571 if ( GlobalOpenGL().GL_1_3() ) {
2572 glActiveTexture( GL_TEXTURE0 );
2573 glClientActiveTexture( GL_TEXTURE0 );
2575 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2576 GlobalOpenGL_debugAssertNoErrors();
2577 glDisableClientState( GL_NORMAL_ARRAY );
2578 GlobalOpenGL_debugAssertNoErrors();
2579 glDisableClientState( GL_COLOR_ARRAY );
2580 GlobalOpenGL_debugAssertNoErrors();
2581 glDisable( GL_TEXTURE_2D );
2582 GlobalOpenGL_debugAssertNoErrors();
2583 glDisable( GL_LIGHTING );
2584 GlobalOpenGL_debugAssertNoErrors();
2585 glDisable( GL_COLOR_MATERIAL );
2586 GlobalOpenGL_debugAssertNoErrors();
2588 GlobalOpenGL_debugAssertNoErrors();
2592 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2594 Select_GetBounds( min, max );
2595 PaintSizeInfo( nDim1, nDim2, min, max );
2598 if ( g_xywindow_globals_private.g_bCrossHairs ) {
2599 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2600 glBegin( GL_LINES );
2601 if ( m_viewType == XY ) {
2602 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2603 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2604 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2605 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2607 else if ( m_viewType == YZ ) {
2608 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2609 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2610 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2611 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2615 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2616 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2617 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2618 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2624 GlobalClipPoints_Draw( m_fScale );
2627 GlobalOpenGL_debugAssertNoErrors();
2631 glScalef( m_fScale, m_fScale, 1 );
2632 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2634 glEnable( GL_BLEND );
2635 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2636 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2637 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
2638 glDisable( GL_BLEND );
2640 Feedback_draw2D( m_viewType );
2642 if ( g_xywindow_globals_private.show_outline ) {
2644 glMatrixMode( GL_PROJECTION );
2646 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2648 glMatrixMode( GL_MODELVIEW );
2651 // four view mode doesn't colorize
2652 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2653 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2657 switch ( m_viewType )
2660 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2663 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2666 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2670 glBegin( GL_LINE_LOOP );
2671 glVertex2f( 0.5, 0.5 );
2672 glVertex2f( m_nWidth - 0.5, 1 );
2673 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2674 glVertex2f( 0.5, m_nHeight - 0.5 );
2679 GlobalOpenGL_debugAssertNoErrors();
2684 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2685 xywnd->XY_ToPoint( x, y, point );
2686 xywnd->XY_SnapToGrid( point );
2688 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2689 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2690 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2693 void XYWnd::OnEntityCreate( const char* item ){
2694 StringOutputStream command;
2695 command << "entityCreate -class " << item;
2696 UndoableCommand undo( command.c_str() );
2698 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2699 Entity_createFromSelection( item, point );
2704 void GetFocusPosition( Vector3& position ){
2705 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2706 Select_GetMid( position );
2710 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2714 void XYWnd_Focus( XYWnd* xywnd ){
2716 GetFocusPosition( position );
2717 xywnd->PositionView( position );
2720 void XY_Split_Focus(){
2722 GetFocusPosition( position );
2723 if ( g_pParentWnd->GetXYWnd() ) {
2724 g_pParentWnd->GetXYWnd()->PositionView( position );
2726 if ( g_pParentWnd->GetXZWnd() ) {
2727 g_pParentWnd->GetXZWnd()->PositionView( position );
2729 if ( g_pParentWnd->GetYZWnd() ) {
2730 g_pParentWnd->GetYZWnd()->PositionView( position );
2735 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2736 // cannot do this in a split window
2737 // do something else that the user may want here
2742 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2743 XYWnd_Focus( xywnd );
2746 void XY_TopFrontSide( VIEWTYPE viewtype ){
2747 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2748 // cannot do this in a split window
2749 // do something else that the user may want here
2753 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2754 xywnd->SetViewType( viewtype );
2755 XYWnd_Focus( xywnd );
2759 XY_TopFrontSide( XY );
2763 XY_TopFrontSide( XZ );
2767 XY_TopFrontSide( YZ );
2770 void XY_NextView( XYWnd* xywnd ){
2771 if ( xywnd->GetViewType() == XY ) {
2772 xywnd->SetViewType( XZ );
2774 else if ( xywnd->GetViewType() == XZ ) {
2775 xywnd->SetViewType( YZ );
2778 xywnd->SetViewType( XY );
2780 XYWnd_Focus( xywnd );
2784 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2785 // cannot do this in a split window
2786 // do something else that the user may want here
2790 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2791 XY_NextView( xywnd );
2795 if ( g_pParentWnd->GetXYWnd() ) {
2796 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2798 if ( g_pParentWnd->GetXZWnd() ) {
2799 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2801 if ( g_pParentWnd->GetYZWnd() ) {
2802 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2807 g_pParentWnd->ActiveXY()->ZoomIn();
2810 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2811 // we don't go below a zoom factor corresponding to 10% of the max world size
2812 // (this has to be computed against the window size)
2814 g_pParentWnd->ActiveXY()->ZoomOut();
2819 void ToggleShowCrosshair(){
2820 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2821 XY_UpdateAllWindows();
2824 void ToggleShowSizeInfo(){
2825 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2826 XY_UpdateAllWindows();
2829 void ToggleShowGrid(){
2830 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2831 XY_UpdateAllWindows();
2834 ToggleShown g_xy_top_shown( true );
2836 void XY_Top_Shown_Construct( ui::Window parent ){
2837 g_xy_top_shown.connect( parent );
2840 ToggleShown g_yz_side_shown( false );
2842 void YZ_Side_Shown_Construct( ui::Window parent ){
2843 g_yz_side_shown.connect( parent );
2846 ToggleShown g_xz_front_shown( false );
2848 void XZ_Front_Shown_Construct( ui::Window parent ){
2849 g_xz_front_shown.connect( parent );
2853 class EntityClassMenu : public ModuleObserver
2855 std::size_t m_unrealised;
2857 EntityClassMenu() : m_unrealised( 1 ){
2860 if ( --m_unrealised == 0 ) {
2864 if ( ++m_unrealised == 1 ) {
2865 if ( XYWnd::m_mnuDrop ) {
2866 XYWnd::m_mnuDrop.destroy();
2867 XYWnd::m_mnuDrop = ui::Menu(ui::null);
2873 EntityClassMenu g_EntityClassMenu;
2877 void ShowNamesToggle(){
2878 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2879 XY_UpdateAllWindows();
2882 typedef FreeCaller<void(), ShowNamesToggle> ShowNamesToggleCaller;
2884 void ShowNamesExport( const Callback<void(bool)> & importer ){
2885 importer( GlobalEntityCreator().getShowNames() );
2888 typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller;
2891 void ShowTargetNamesToggle(){
2892 GlobalEntityCreator().setShowTargetNames( !GlobalEntityCreator().getShowTargetNames() );
2893 XY_UpdateAllWindows();
2896 typedef FreeCaller<void(), ShowTargetNamesToggle> ShowTargetNamesToggleCaller;
2898 void ShowTargetNamesExport( const Callback<void(bool)> & importer ){
2899 importer( GlobalEntityCreator().getShowTargetNames() );
2902 typedef FreeCaller<void(const Callback<void(bool)> &), ShowTargetNamesExport> ShowTargetNamesExportCaller;
2905 void ShowAnglesToggle(){
2906 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2907 XY_UpdateAllWindows();
2910 typedef FreeCaller<void(), ShowAnglesToggle> ShowAnglesToggleCaller;
2912 void ShowAnglesExport( const Callback<void(bool)> & importer ){
2913 importer( GlobalEntityCreator().getShowAngles() );
2915 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAnglesExport> ShowAnglesExportCaller;
2918 void ShowBlocksToggle(){
2919 g_xywindow_globals_private.show_blocks ^= 1;
2920 XY_UpdateAllWindows();
2923 typedef FreeCaller<void(), ShowBlocksToggle> ShowBlocksToggleCaller;
2925 void ShowBlocksExport( const Callback<void(bool)> & importer ){
2926 importer( g_xywindow_globals_private.show_blocks );
2929 typedef FreeCaller<void(const Callback<void(bool)> &), ShowBlocksExport> ShowBlocksExportCaller;
2932 void ShowCoordinatesToggle(){
2933 g_xywindow_globals_private.show_coordinates ^= 1;
2934 XY_UpdateAllWindows();
2937 typedef FreeCaller<void(), ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2939 void ShowCoordinatesExport( const Callback<void(bool)> & importer ){
2940 importer( g_xywindow_globals_private.show_coordinates );
2943 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCoordinatesExport> ShowCoordinatesExportCaller;
2946 void ShowOutlineToggle(){
2947 g_xywindow_globals_private.show_outline ^= 1;
2948 XY_UpdateAllWindows();
2951 typedef FreeCaller<void(), ShowOutlineToggle> ShowOutlineToggleCaller;
2953 void ShowOutlineExport( const Callback<void(bool)> & importer ){
2954 importer( g_xywindow_globals_private.show_outline );
2957 typedef FreeCaller<void(const Callback<void(bool)> &), ShowOutlineExport> ShowOutlineExportCaller;
2960 void ShowAxesToggle(){
2961 g_xywindow_globals_private.show_axis ^= 1;
2962 XY_UpdateAllWindows();
2964 typedef FreeCaller<void(), ShowAxesToggle> ShowAxesToggleCaller;
2966 void ShowAxesExport( const Callback<void(bool)> & importer ){
2967 importer( g_xywindow_globals_private.show_axis );
2970 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAxesExport> ShowAxesExportCaller;
2973 void ShowWorkzoneToggle(){
2974 g_xywindow_globals_private.d_show_work ^= 1;
2975 XY_UpdateAllWindows();
2977 typedef FreeCaller<void(), ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2979 void ShowWorkzoneExport( const Callback<void(bool)> & importer ){
2980 importer( g_xywindow_globals_private.d_show_work );
2983 typedef FreeCaller<void(const Callback<void(bool)> &), ShowWorkzoneExport> ShowWorkzoneExportCaller;
2986 BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled );
2987 ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller );
2989 void Texdef_ToggleMoveLock(){
2990 g_brush_texturelock_enabled = !g_brush_texturelock_enabled;
2991 g_texdef_movelock_item.update();
2996 void ShowSizeToggle(){
2997 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2998 XY_UpdateAllWindows();
3000 typedef FreeCaller<void(), ShowSizeToggle> ShowSizeToggleCaller;
3001 void ShowSizeExport( const Callback<void(bool)> & importer ){
3002 importer( g_xywindow_globals_private.m_bSizePaint );
3004 typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowSizeExportCaller;
3007 void ShowCrosshairToggle(){
3008 g_xywindow_globals_private.g_bCrossHairs ^= 1;
3009 XY_UpdateAllWindows();
3011 typedef FreeCaller<void(), ShowCrosshairToggle> ShowCrosshairToggleCaller;
3012 void ShowCrosshairExport( const Callback<void(bool)> & importer ){
3013 importer( g_xywindow_globals_private.g_bCrossHairs );
3015 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCrosshairExport> ShowCrosshairExportCaller;
3018 void ShowGridToggle(){
3019 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
3020 XY_UpdateAllWindows();
3022 typedef FreeCaller<void(), ShowGridToggle> ShowGridToggleCaller;
3023 void ShowGridTExport( const Callback<void(bool)> & importer ){
3024 importer( g_xywindow_globals_private.d_showgrid );
3026 typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowGridExportCaller;
3029 ShowNamesExportCaller g_show_names_caller;
3030 Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller );
3031 ToggleItem g_show_names( g_show_names_callback );
3033 ShowTargetNamesExportCaller g_show_targetnames_caller;
3034 Callback<void(const Callback<void(bool)> &)> g_show_targetnames_callback( g_show_targetnames_caller );
3035 ToggleItem g_show_targetnames( g_show_targetnames_callback );
3037 ShowAnglesExportCaller g_show_angles_caller;
3038 Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller );
3039 ToggleItem g_show_angles( g_show_angles_callback );
3041 ShowBlocksExportCaller g_show_blocks_caller;
3042 Callback<void(const Callback<void(bool)> &)> g_show_blocks_callback( g_show_blocks_caller );
3043 ToggleItem g_show_blocks( g_show_blocks_callback );
3045 ShowCoordinatesExportCaller g_show_coordinates_caller;
3046 Callback<void(const Callback<void(bool)> &)> g_show_coordinates_callback( g_show_coordinates_caller );
3047 ToggleItem g_show_coordinates( g_show_coordinates_callback );
3049 ShowOutlineExportCaller g_show_outline_caller;
3050 Callback<void(const Callback<void(bool)> &)> g_show_outline_callback( g_show_outline_caller );
3051 ToggleItem g_show_outline( g_show_outline_callback );
3053 ShowAxesExportCaller g_show_axes_caller;
3054 Callback<void(const Callback<void(bool)> &)> g_show_axes_callback( g_show_axes_caller );
3055 ToggleItem g_show_axes( g_show_axes_callback );
3057 ShowWorkzoneExportCaller g_show_workzone_caller;
3058 Callback<void(const Callback<void(bool)> &)> g_show_workzone_callback( g_show_workzone_caller );
3059 ToggleItem g_show_workzone( g_show_workzone_callback );
3061 ShowSizeExportCaller g_show_size_caller;
3062 Callback<void(const Callback<void(bool)> &)> g_show_size_callback( g_show_size_caller );
3063 ToggleItem g_show_size( g_show_size_callback );
3065 ShowCrosshairExportCaller g_show_crosshair_caller;
3066 Callback<void(const Callback<void(bool)> &)> g_show_crosshair_callback( g_show_crosshair_caller );
3067 ToggleItem g_show_crosshair( g_show_crosshair_callback );
3069 ShowGridExportCaller g_show_grid_caller;
3070 Callback<void(const Callback<void(bool)> &)> g_show_grid_callback( g_show_grid_caller );
3071 ToggleItem g_show_grid( g_show_grid_callback );
3074 void XYShow_registerCommands(){
3075 GlobalToggles_insert( "ToggleSizePaint", ShowSizeToggleCaller(), ToggleItem::AddCallbackCaller( g_show_size ), Accelerator( 'J' ) );
3076 GlobalToggles_insert( "ToggleCrosshairs", ShowCrosshairToggleCaller(), ToggleItem::AddCallbackCaller( g_show_crosshair ), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
3077 GlobalToggles_insert( "ToggleGrid", ShowGridToggleCaller(), ToggleItem::AddCallbackCaller( g_show_grid ), Accelerator( '0' ) );
3079 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
3080 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
3081 GlobalToggles_insert( "ShowTargetNames", ShowTargetNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_targetnames ) );
3082 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
3083 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
3084 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
3085 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
3086 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
3089 void XYWnd_registerShortcuts(){
3090 command_connect_accelerator( "ToggleCrosshairs" );
3091 command_connect_accelerator( "ToggleSizePaint" );
3096 void Orthographic_constructPreferences( PreferencesPage& page ){
3097 page.appendCheckBox( "", "Solid selection boxes ( no stipple )", g_xywindow_globals.m_bNoStipple );
3098 //page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
3099 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
3100 // page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
3101 page.appendCheckBox( "", "Zoom In to Mouse pointer", g_xywindow_globals.m_bZoomInToPointer );
3103 void Orthographic_constructPage( PreferenceGroup& group ){
3104 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
3105 Orthographic_constructPreferences( page );
3107 void Orthographic_registerPreferencesPage(){
3108 PreferencesDialog_addSettingsPage( makeCallbackF(Orthographic_constructPage) );
3111 void Clipper_constructPreferences( PreferencesPage& page ){
3112 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
3114 void Clipper_constructPage( PreferenceGroup& group ){
3115 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
3116 Clipper_constructPreferences( page );
3118 void Clipper_registerPreferencesPage(){
3119 PreferencesDialog_addSettingsPage( makeCallbackF(Clipper_constructPage) );
3123 #include "preferencesystem.h"
3124 #include "stringio.h"
3127 struct ToggleShown_Bool {
3128 static void Export(const ToggleShown &self, const Callback<void(bool)> &returnz) {
3129 returnz(self.active());
3132 static void Import(ToggleShown &self, bool value) {
3138 void XYWindow_Construct(){
3139 // GlobalCommands_insert( "ToggleCrosshairs", makeCallbackF(ToggleShowCrosshair), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
3140 // GlobalCommands_insert( "ToggleSizePaint", makeCallbackF(ToggleShowSizeInfo), Accelerator( 'J' ) );
3141 // GlobalCommands_insert( "ToggleGrid", makeCallbackF(ToggleShowGrid), Accelerator( '0' ) );
3143 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 ) ) );
3144 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
3145 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
3146 GlobalCommands_insert( "NextView", makeCallbackF(XY_Next), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut
3147 GlobalCommands_insert( "ZoomIn", makeCallbackF(XY_ZoomIn), Accelerator( GDK_KEY_Delete ) );
3148 GlobalCommands_insert( "ZoomOut", makeCallbackF(XY_ZoomOut), Accelerator( GDK_KEY_Insert ) );
3149 GlobalCommands_insert( "ViewTop", makeCallbackF(XY_Top), Accelerator( GDK_KEY_KP_Home ) );
3150 GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) );
3151 GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) );
3152 GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) );
3153 GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3155 GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) );
3157 // GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
3158 GlobalPreferenceSystem().registerPreference( "2DZoomInToPointer", make_property_string( g_xywindow_globals.m_bZoomInToPointer ) );
3159 GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) );
3160 GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) );
3161 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );
3162 GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) );
3163 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) );
3164 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) );
3165 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) );
3166 // GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
3167 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) );
3169 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) );
3170 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) );
3171 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) );
3172 GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) );
3173 GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) );
3174 GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) );
3175 GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) );
3176 GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) );
3177 GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) );
3178 GlobalPreferenceSystem().registerPreference( "SI_Colors9", make_property_string( g_xywindow_globals.color_viewname ) );
3179 GlobalPreferenceSystem().registerPreference( "SI_Colors10", make_property_string( g_xywindow_globals.color_clipper ) );
3180 GlobalPreferenceSystem().registerPreference( "SI_Colors11", make_property_string( g_xywindow_globals.color_selbrushes ) );
3185 GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) );
3186 GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) );
3188 Orthographic_registerPreferencesPage();
3189 Clipper_registerPreferencesPage();
3191 XYWnd::captureStates();
3192 GlobalEntityClassManager().attach( g_EntityClassMenu );
3195 void XYWindow_Destroy(){
3196 GlobalEntityClassManager().detach( g_EntityClassMenu );
3197 XYWnd::releaseStates();