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"
61 #include "gtkutil/cursor.h"
65 #include "brushmanip.h"
66 #include "selection.h"
68 #include "camwindow.h"
69 #include "texwindow.h"
70 #include "mainframe.h"
71 #include "preferences.h"
75 #include "windowobservers.h"
77 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
80 extern bool g_brush_always_caulk;
86 Vector3 m_ptClip; // the 3d point
93 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
107 /*! Draw clip/path point with rasterized number label */
108 void Draw( int num, float scale );
109 /*! Draw clip/path point with rasterized string label */
110 void Draw( const char *label, float scale );
113 VIEWTYPE g_clip_viewtype;
114 bool g_bSwitch = true;
115 bool g_clip_useCaulk = false;
116 bool g_quick_clipper = false;
120 ClipPoint* g_pMovingClip = 0;
122 /* Drawing clip points */
123 void ClipPoint::Draw( int num, float scale ){
124 StringOutputStream label( 4 );
126 Draw( label.c_str(), scale );
129 void ClipPoint::Draw( const char *label, float scale ){
132 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
133 glBegin( GL_POINTS );
134 glVertex3fv( vector3_to_array( m_ptClip ) );
138 float offset = 2.0f / scale;
141 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
142 //glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label ); //fails with GCC
143 //glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, reinterpret_cast<const GLubyte*>( label ) ); //worx
144 GlobalOpenGL().drawString( label );
147 float fDiff( float f1, float f2 ){
156 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
157 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
158 int nDim2 = ( viewtype == XY ) ? 1 : 2;
159 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
160 if ( screenDistanceSquared < 8 * 8 ) {
161 return screenDistanceSquared;
166 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
168 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
169 if ( distance < bestDistance ) {
170 bestDistance = distance;
176 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
177 double bestDistance = FLT_MAX;
178 ClipPoint* bestClip = 0;
179 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
180 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
181 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
185 inline void GlobalClipPoints_Draw( float scale ){
187 if ( g_Clip1.Set() ) {
188 g_Clip1.Draw( 1, scale );
190 if ( g_Clip2.Set() ) {
191 g_Clip2.Draw( 2, scale );
193 if ( g_Clip3.Set() ) {
194 g_Clip3.Draw( 3, scale );
198 inline bool GlobalClipPoints_valid(){
199 return g_Clip1.Set() && g_Clip2.Set();
202 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
203 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
204 planepts[0] = g_Clip1.m_ptClip;
205 planepts[1] = g_Clip2.m_ptClip;
206 planepts[2] = g_Clip3.m_ptClip;
207 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
208 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
209 if ( !g_Clip3.Set() ) {
210 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
211 int x = ( n == 0 ) ? 1 : 0;
212 int y = ( n == 2 ) ? 1 : 2;
214 if ( n == 1 ) { // on viewtype XZ, flip clip points
215 planepts[0][n] = maxs[n];
216 planepts[1][n] = maxs[n];
217 planepts[2][x] = g_Clip1.m_ptClip[x];
218 planepts[2][y] = g_Clip1.m_ptClip[y];
219 planepts[2][n] = mins[n];
223 planepts[0][n] = mins[n];
224 planepts[1][n] = mins[n];
225 planepts[2][x] = g_Clip1.m_ptClip[x];
226 planepts[2][y] = g_Clip1.m_ptClip[y];
227 planepts[2][n] = maxs[n];
234 if ( !GlobalClipPoints_valid() ) {
235 planepts[0] = Vector3( 0, 0, 0 );
236 planepts[1] = Vector3( 0, 0, 0 );
237 planepts[2] = Vector3( 0, 0, 0 );
238 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
242 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
243 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
245 std::swap( planepts[0], planepts[1] );
247 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
249 ClipperChangeNotify();
252 const char* Clip_getShader(){
253 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
257 if ( ClipMode() && GlobalClipPoints_valid() ) {
259 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
260 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
261 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
266 ClipperChangeNotify();
267 if( g_quick_clipper ){
268 g_quick_clipper = false;
275 if ( ClipMode() && GlobalClipPoints_valid() ) {
277 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
278 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
279 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
284 ClipperChangeNotify();
285 if( g_quick_clipper ){
286 g_quick_clipper = false;
293 g_bSwitch = !g_bSwitch;
295 ClipperChangeNotify();
298 void OnClipMode( bool enabled ){
303 if ( !enabled && g_pMovingClip ) {
308 ClipperChangeNotify();
312 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
315 void NewClipPoint( const Vector3& point ){
316 if ( g_Clip1.Set() == false ) {
317 g_Clip1.m_ptClip = point;
320 else if ( g_Clip2.Set() == false ) {
321 g_Clip2.m_ptClip = point;
324 else if ( g_Clip3.Set() == false ) {
325 g_Clip3.m_ptClip = point;
333 g_Clip1.m_ptClip = point;
338 ClipperChangeNotify();
343 struct xywindow_globals_private_t
347 // these are in the View > Show menu with Show coordinates
349 bool show_coordinates;
359 // bool m_bCamXYUpdate;
365 xywindow_globals_private_t() :
369 show_coordinates( false ),
371 show_outline( true ),
374 d_show_work( false ),
376 show_blocks( false ),
378 // m_bCamXYUpdate( true ),
379 m_bChaseMouse( true ),
380 m_bSizePaint( true ),
382 g_bCrossHairs( false ){
387 xywindow_globals_t g_xywindow_globals;
388 xywindow_globals_private_t g_xywindow_globals_private;
390 const unsigned int RAD_NONE = 0x00;
391 const unsigned int RAD_SHIFT = 0x01;
392 const unsigned int RAD_ALT = 0x02;
393 const unsigned int RAD_CONTROL = 0x04;
394 const unsigned int RAD_PRESS = 0x08;
395 const unsigned int RAD_LBUTTON = 0x10;
396 const unsigned int RAD_MBUTTON = 0x20;
397 const unsigned int RAD_RBUTTON = 0x40;
399 inline ButtonIdentifier button_for_flags( unsigned int flags ){
400 if ( flags & RAD_LBUTTON ) {
403 if ( flags & RAD_RBUTTON ) {
404 return c_buttonRight;
406 if ( flags & RAD_MBUTTON ) {
407 return c_buttonMiddle;
409 return c_buttonInvalid;
412 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
413 ModifierFlags modifiers = c_modifierNone;
414 if ( flags & RAD_SHIFT ) {
415 modifiers |= c_modifierShift;
417 if ( flags & RAD_CONTROL ) {
418 modifiers |= c_modifierControl;
420 if ( flags & RAD_ALT ) {
421 modifiers |= c_modifierAlt;
426 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
427 unsigned int buttons = 0;
429 switch ( button.get() )
431 case ButtonEnumeration::INVALID: break;
432 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
433 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
434 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
437 if ( bitfield_enabled( flags, c_modifierControl ) ) {
438 buttons |= RAD_CONTROL;
441 if ( bitfield_enabled( flags, c_modifierShift ) ) {
442 buttons |= RAD_SHIFT;
445 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
452 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
453 unsigned int flags = 0;
455 switch ( event->button )
457 case 1: flags |= RAD_LBUTTON; break;
458 case 2: flags |= RAD_MBUTTON; break;
459 case 3: flags |= RAD_RBUTTON; break;
462 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
463 flags |= RAD_CONTROL;
466 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
470 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
477 inline unsigned int buttons_for_state( guint state ){
478 unsigned int flags = 0;
480 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
481 flags |= RAD_LBUTTON;
484 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
485 flags |= RAD_MBUTTON;
488 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
489 flags |= RAD_RBUTTON;
492 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
493 flags |= RAD_CONTROL;
496 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
500 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
508 void XYWnd::SetScale( float f ){
512 XYWnd_Update( *this );
515 void XYWnd::ZoomIn(){
516 float max_scale = 64;
517 float scale = Scale() * 5.0f / 4.0f;
518 if ( scale > max_scale ) {
519 if ( Scale() != max_scale ) {
520 SetScale( max_scale );
530 // NOTE: the zoom out factor is 4/5, we could think about customizing it
531 // we don't go below a zoom factor corresponding to 10% of the max world size
532 // (this has to be computed against the window size)
533 void XYWnd::ZoomOut(){
534 float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
535 float scale = Scale() * 4.0f / 5.0f;
536 if ( scale < min_scale ) {
537 if ( Scale() != min_scale ) {
538 SetScale( min_scale );
547 void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
548 float old_scale = Scale();
550 if ( g_xywindow_globals.m_bZoomInToPointer ) {
551 float scale_diff = 1.0 / old_scale - 1.0 / Scale();
552 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
553 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
554 Vector3 origin = GetOrigin();
555 origin[nDim1] += scale_diff * (pointx - 0.5 * Width());
556 origin[nDim2] -= scale_diff * (pointy - 0.5 * Height());
561 void XYWnd::Redraw() {
562 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
563 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
564 GlobalOpenGL_debugAssertNoErrors();
566 GlobalOpenGL_debugAssertNoErrors();
568 m_XORRectangle.set( rectangle_t() );
570 glwidget_swap_buffers( m_gl_widget );
574 void XYWnd::FocusOnBounds( AABB& bounds ){
575 SetOrigin( bounds.origin );
576 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
577 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
578 if( bounds.extents[ nDim1 ] < 128.f )
579 bounds.extents[ nDim1 ] = 128.f;
580 if( bounds.extents[ nDim2 ] < 128.f )
581 bounds.extents[ nDim2 ] = 128.f;
582 float scale1 = Width() / ( 3.f * bounds.extents[ nDim1 ] );
583 float scale2 = Height() / ( 3.f * bounds.extents[ nDim2 ] );
584 SetScale( MIN( scale1, scale2 ) );
588 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
589 ASSERT_NOTNULL( g_pParentWnd );
590 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
591 return g_pParentWnd->ActiveXY()->GetViewType();
594 // =============================================================================
597 ui::Menu XYWnd::m_mnuDrop(ui::null);
599 // this is disabled, and broken
600 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
604 width = g_pParentWnd->ActiveXY()->Width();
605 height = g_pParentWnd->ActiveXY()->Height();
607 const char* filename;
609 filename = ui::file_dialog( MainFrame_getWindow( ), FALSE, "Save Image", 0, FILTER_BMP );
614 g_pParentWnd->ActiveXY()->MakeCurrent();
615 img = (unsigned char*)malloc( width * height * 3 );
616 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
619 fp = fopen( filename, "wb" );
622 unsigned long cmap, bfSize;
626 bfSize = 54 + width * height * 3;
628 long byteswritten = 0;
629 long pixoff = 54 + cmap * 4;
631 char m1 = 'B', m2 = 'M';
632 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
633 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
634 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
635 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
636 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
637 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
639 unsigned long biSize = 40, compress = 0, size = 0;
641 unsigned short planes = 1;
642 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
643 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
644 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
645 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
646 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
647 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
648 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
649 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
650 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
651 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
652 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
654 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
655 long row, row_size = width * 3;
656 for ( row = 0; row < height; row++ )
658 unsigned char* buf = img + row * row_size;
662 for ( col = 0; col < row_size; col += 3 )
664 putc( buf[col + 2], fp );
665 putc( buf[col + 1], fp );
666 putc( buf[col], fp );
668 byteswritten += row_size;
671 for ( count = row_size; count < widthDW; count++ )
673 putc( 0, fp ); // dummy
688 Timer g_chasemouse_timer;
690 void XYWnd::ChaseMouse(){
691 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
692 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
694 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
696 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
697 g_chasemouse_timer.start();
700 gboolean xywnd_chasemouse( gpointer data ){
701 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
705 inline const int& min_int( const int& left, const int& right ){
706 return std::min( left, right );
709 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
710 m_chasemouse_delta_x = 0;
711 m_chasemouse_delta_y = 0;
713 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
714 const int epsilon = 16;
716 if ( pointx < epsilon ) {
717 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
719 else if ( ( pointx - m_nWidth ) > -epsilon ) {
720 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
723 if ( pointy < epsilon ) {
724 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
726 else if ( ( pointy - m_nHeight ) > -epsilon ) {
727 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
730 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
731 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
732 m_chasemouse_current_x = pointx;
733 m_chasemouse_current_y = pointy;
734 if ( m_chasemouse_handler == 0 ) {
735 //globalOutputStream() << "chasemouse timer start... ";
736 g_chasemouse_timer.start();
737 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
743 if ( m_chasemouse_handler != 0 ) {
744 //globalOutputStream() << "chasemouse cancel\n";
745 g_source_remove( m_chasemouse_handler );
746 m_chasemouse_handler = 0;
752 if ( m_chasemouse_handler != 0 ) {
753 //globalOutputStream() << "chasemouse cancel\n";
754 g_source_remove( m_chasemouse_handler );
755 m_chasemouse_handler = 0;
761 // =============================================================================
763 Shader* XYWnd::m_state_selected = 0;
765 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
766 if ( self.GetWidget().visible() ) {
767 rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() );
768 // int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0;
769 // int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2;
770 // rect.x /= self.Scale();
771 // rect.y /= self.Scale();
772 // rect.w /= self.Scale();
773 // rect.h /= self.Scale();
774 // rect.x += self.GetOrigin()[nDim1];
775 // rect.y += self.GetOrigin()[nDim2];
776 self.m_XORRectangle.set( rect );
780 gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
781 if ( event->type == GDK_BUTTON_PRESS ) {
782 gtk_widget_grab_focus( xywnd->GetWidget() );
784 if( !xywnd->Active() ){
785 g_pParentWnd->SetActiveXY( xywnd );
788 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
790 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
795 gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
796 if ( event->type == GDK_BUTTON_RELEASE ) {
797 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
799 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
804 gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
805 if ( event->type == GDK_FOCUS_CHANGE ) {
807 if( !xywnd->Active() ){
808 g_pParentWnd->SetActiveXY( xywnd );
815 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
816 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
819 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
822 gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
823 gtk_widget_grab_focus( xywnd->GetWidget() );
824 ui::Window window = xywnd->m_parent ? xywnd->m_parent : MainFrame_getWindow();
825 if( !gtk_window_is_active( window ) )
826 gtk_window_present( window );
828 if( !xywnd->Active() ){
829 g_pParentWnd->SetActiveXY( xywnd );
831 if ( event->direction == GDK_SCROLL_UP ) {
832 xywnd->ZoomInWithMouse( (int)event->x, (int)event->y );
834 else if ( event->direction == GDK_SCROLL_DOWN ) {
840 gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){
841 xywnd->m_nWidth = allocation->width;
842 xywnd->m_nHeight = allocation->height;
843 xywnd->updateProjection();
844 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
848 gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
853 void XYWnd_CameraMoved( XYWnd& xywnd ){
854 // if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
855 //XYWnd_Update( xywnd );
856 xywnd.UpdateCameraIcon();
861 m_gl_widget( glwidget_new( FALSE ) ),
862 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
863 m_deferred_motion( xywnd_motion, this ),
864 m_parent( ui::null ),
865 m_window_observer( NewWindowObserver() ),
866 m_XORRectangle( m_gl_widget ),
867 m_chasemouse_handler( 0 ){
872 m_bNewBrushDrag = false;
873 m_move_started = false;
874 m_zoom_started = false;
885 m_backgroundActivated = false;
892 m_entityCreate = false;
894 m_mnuDrop = ui::Menu(ui::null);
896 GlobalWindowObservers_add( m_window_observer );
897 GlobalWindowObservers_connectWidget( m_gl_widget );
899 m_window_observer->setRectangleDrawCallback( ReferenceCaller<XYWnd, void(rect_t), xy_update_xor_rectangle>( *this ) );
900 m_window_observer->setView( m_view );
902 g_object_ref( m_gl_widget._handle );
904 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 );
905 gtk_widget_set_can_focus( m_gl_widget, true );
907 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
908 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
910 m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
911 m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
912 m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this ); //works only in floating views layout
913 m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
915 m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
917 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
919 // This reconstruct=false argument is used to avoid a circular dependency
920 // between modelview and projection initialization and a valgrind complaint
921 updateProjection( false );
922 updateModelview( false );
923 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
925 AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) );
926 AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) );
928 PressedButtons_connect( g_pressedButtons, m_gl_widget );
930 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
938 m_mnuDrop = ui::Menu(ui::null);
941 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
942 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
946 m_window_observer->release();
949 void XYWnd::captureStates(){
950 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
953 void XYWnd::releaseStates(){
954 GlobalShaderCache().release( "$XY_OVERLAY" );
957 const Vector3& XYWnd::GetOrigin(){
961 void XYWnd::SetOrigin( const Vector3& origin ){
966 void XYWnd::Scroll( int x, int y ){
967 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
968 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
969 m_vOrigin[nDim1] += x / m_fScale;
970 m_vOrigin[nDim2] += y / m_fScale;
975 unsigned int Clipper_buttons(){
979 unsigned int Clipper_quick_buttons(){
980 return RAD_LBUTTON | RAD_CONTROL;
983 void XYWnd::DropClipPoint( int pointx, int pointy ){
986 XY_ToPoint( pointx, pointy, point );
989 Select_GetMid( mid );
990 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
991 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
992 point[nDim] = mid[nDim];
993 vector3_snap( point, GetSnapGridSize() );
994 NewClipPoint( point );
997 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
998 Vector3 mousePosition;
999 XY_ToPoint( x, y, mousePosition );
1000 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
1001 if ( !g_pMovingClip ) {
1002 DropClipPoint( x, y );
1006 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
1007 if ( g_pMovingClip ) {
1012 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
1013 if ( g_pMovingClip ) {
1014 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
1015 XY_SnapToGrid( g_pMovingClip->m_ptClip );
1017 ClipperChangeNotify();
1021 //#include "gtkutil/image.h"
1023 /* is called on every mouse move fraction; ain't good! */
1024 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
1025 Vector3 mousePosition;
1026 XY_ToPoint( x, y, mousePosition );
1027 #if 0 // NetRadiantCustom
1029 if( GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ){
1031 cursor = gdk_cursor_new( GDK_CROSSHAIR );
1032 //cursor = gdk_cursor_new( GDK_FLEUR );
1033 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
1034 gdk_cursor_unref( cursor );
1038 cursor = gdk_cursor_new( GDK_HAND2 );
1039 // GdkPixbuf* pixbuf = pixbuf_new_from_file_with_mask( "bitmaps/icon.png" );
1040 // cursor = gdk_cursor_new_from_pixbuf( gdk_display_get_default(), pixbuf, 0, 0 );
1041 // g_object_unref( pixbuf );
1042 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
1043 gdk_cursor_unref( cursor );
1048 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
1049 set_cursor ( m_gl_widget, GDK_CROSSHAIR );
1054 default_cursor( m_gl_widget );
1058 void XYWnd::SetCustomPivotOrigin( int pointx, int pointy ){
1060 XY_ToPoint( pointx, pointy, point );
1061 VIEWTYPE viewtype = static_cast<VIEWTYPE>( GetViewType() );
1062 const int nDim = ( viewtype == YZ ) ? 0 : ( ( viewtype == XZ ) ? 1 : 2 );
1063 //vector3_snap( point, GetSnapGridSize() );
1064 point[nDim] = 999999;
1066 GlobalSelectionSystem().setCustomPivotOrigin( point );
1067 SceneChangeNotify();
1070 unsigned int MoveCamera_buttons(){
1071 // return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
1072 return RAD_CONTROL | RAD_MBUTTON;
1075 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1076 Vector3 origin( Camera_getOrigin( camwnd ) );
1077 xywnd->XY_ToPoint( x, y, origin );
1078 xywnd->XY_SnapToGrid( origin );
1079 Camera_setOrigin( camwnd, origin );
1082 unsigned int OrientCamera_buttons(){
1083 // if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
1084 // return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1089 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1090 //globalOutputStream() << Camera_getAngles( camwnd ) << " b4\n";
1091 Vector3 point = g_vector3_identity;
1092 xywnd->XY_ToPoint( x, y, point );
1093 //xywnd->XY_SnapToGrid( point );
1094 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1096 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1097 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1098 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1099 if ( point[n1] || point[n2] ) {
1100 Vector3 angles( Camera_getAngles( camwnd ) );
1101 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1102 if( angles[CAMERA_YAW] < 0 )
1103 angles[CAMERA_YAW] = angles[CAMERA_YAW] + 360;
1104 if ( nAngle == CAMERA_PITCH ){
1105 if( fabs( angles[CAMERA_PITCH] ) > 90 ){
1106 angles[CAMERA_PITCH] = ( angles[CAMERA_PITCH] > 0 ) ? ( -angles[CAMERA_PITCH] + 180 ) : ( -angles[CAMERA_PITCH] - 180 );
1107 if( xywnd->GetViewType() == YZ ){
1108 if( angles[CAMERA_YAW] < 180 ){
1109 angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
1112 else if( angles[CAMERA_YAW] < 90 || angles[CAMERA_YAW] > 270 ){
1113 angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW];
1117 if( xywnd->GetViewType() == YZ ){
1118 if( angles[CAMERA_YAW] > 180 ){
1119 angles[CAMERA_YAW] = 360 - angles[CAMERA_YAW];
1122 else if( angles[CAMERA_YAW] > 90 && angles[CAMERA_YAW] < 270 ){
1123 angles[CAMERA_YAW] = 180 - angles[CAMERA_YAW];
1127 Camera_setAngles( camwnd, angles );
1129 //globalOutputStream() << Camera_getAngles( camwnd ) << "\n";
1132 unsigned int SetCustomPivotOrigin_buttons(){
1133 return RAD_MBUTTON | RAD_SHIFT;
1141 unsigned int NewBrushDrag_buttons(){
1145 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1147 m_nNewBrushPressx = x;
1148 m_nNewBrushPressy = y;
1150 m_bNewBrushDrag = true;
1153 void XYWnd::NewBrushDrag_End( int x, int y ){
1154 if ( m_NewBrushDrag != 0 ) {
1155 GlobalUndoSystem().finish( "brushDragNew" );
1159 void XYWnd::NewBrushDrag( int x, int y ){
1161 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1162 XY_SnapToGrid( mins );
1163 XY_ToPoint( x, y, maxs );
1164 XY_SnapToGrid( maxs );
1166 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1168 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1169 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1171 if ( maxs[nDim] <= mins[nDim] ) {
1172 maxs[nDim] = mins[nDim] + GetGridSize();
1175 for ( int i = 0 ; i < 3 ; i++ )
1177 if ( mins[i] == maxs[i] ) {
1178 return; // don't create a degenerate brush
1180 if ( mins[i] > maxs[i] ) {
1181 float temp = mins[i];
1187 if ( m_NewBrushDrag == 0 ) {
1188 GlobalUndoSystem().start();
1189 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1190 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1192 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1193 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1194 brushpath.push( makeReference( node.get() ) );
1195 selectPath( brushpath, true );
1197 m_NewBrushDrag = node.get_pointer();
1201 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1202 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1203 g_brush_always_caulk ?
1204 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1207 void entitycreate_activated( ui::Widget item ){
1208 scene::Node* world_node = Map_FindWorldspawn( g_map );
1209 const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) );
1211 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1212 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1215 GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(),
1216 "There's already a worldspawn in your map!",
1223 void EntityClassMenu_addItem( ui::Menu menu, const char* name ){
1224 auto item = ui::MenuItem( name );
1225 item.connect( "activate", G_CALLBACK( entitycreate_activated ), item );
1227 menu_add_item( menu, item );
1230 class EntityClassMenuInserter : public EntityClassVisitor
1232 typedef std::pair<ui::Menu, CopiedString> MenuPair;
1233 typedef std::vector<MenuPair> MenuStack;
1235 CopiedString m_previous;
1237 EntityClassMenuInserter( ui::Menu menu ){
1238 m_stack.reserve( 2 );
1239 m_stack.push_back( MenuPair( menu, "" ) );
1241 ~EntityClassMenuInserter(){
1242 if ( !string_empty( m_previous.c_str() ) ) {
1243 addItem( m_previous.c_str(), "" );
1246 void visit( EntityClass* e ){
1247 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1248 if ( !string_empty( m_previous.c_str() ) ) {
1249 addItem( m_previous.c_str(), e->name() );
1251 m_previous = e->name();
1253 void pushMenu( const CopiedString& name ){
1254 auto item = ui::MenuItem( name.c_str() );
1256 m_stack.back().first.add(item);
1258 auto submenu = ui::Menu(ui::New);
1259 gtk_menu_item_set_submenu( item, submenu );
1261 m_stack.push_back( MenuPair( submenu, name ) );
1266 void addItem( const char* name, const char* next ){
1267 const char* underscore = strchr( name, '_' );
1269 if ( underscore != 0 && underscore != name ) {
1270 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1271 const char* parent = m_stack.back().second.c_str();
1273 if ( !string_empty( parent )
1274 && string_length( parent ) == std::size_t( underscore - name )
1275 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1277 else if ( nextEqual ) {
1278 if ( m_stack.size() == 2 ) {
1281 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1283 else if ( m_stack.size() == 2 ) {
1287 else if ( m_stack.size() == 2 ) {
1291 EntityClassMenu_addItem( m_stack.back().first, name );
1295 void XYWnd::OnContextMenu(){
1296 // if ( g_xywindow_globals.m_bRightClick == false ) {
1300 if ( !m_mnuDrop ) { // first time, load it up
1301 auto menu = m_mnuDrop = ui::Menu(ui::New);
1303 EntityClassMenuInserter inserter( menu );
1304 GlobalEntityClassManager().forEach( inserter );
1307 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1310 FreezePointer g_xywnd_freezePointer;
1312 unsigned int Move_buttons(){
1316 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1317 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1318 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1321 gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1326 void XYWnd::Move_Begin(){
1327 if ( m_move_started ) {
1330 m_move_started = true;
1331 /* NetRadiantCustom did this instead:
1332 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this ); */
1333 g_xywnd_freezePointer.freeze_pointer( m_gl_widget, XYWnd_moveDelta, this );
1334 m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1337 void XYWnd::Move_End(){
1338 m_move_started = false;
1339 /* NetRadiant did this instead:
1340 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false ); */
1341 g_xywnd_freezePointer.unfreeze_pointer( m_gl_widget, false );
1342 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1345 unsigned int Zoom_buttons(){
1346 return RAD_RBUTTON | RAD_ALT;
1353 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1356 while ( abs( g_dragZoom ) > 8 )
1358 if ( g_dragZoom > 0 ) {
1359 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1364 if ( g_xywindow_globals.m_bZoomInToPointer ) {
1365 reinterpret_cast<XYWnd*>( data )->ZoomInWithMouse( g_zoom2x, g_zoom2y );
1368 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1376 gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1381 void XYWnd::Zoom_Begin( int x, int y ){
1382 if ( m_zoom_started ) {
1385 m_zoom_started = true;
1389 /* NetRadiantCustom did this instead:
1390 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this ); */
1391 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
1392 m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1395 void XYWnd::Zoom_End(){
1396 m_zoom_started = false;
1397 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), false );
1398 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1401 // makes sure the selected brush or camera is in view
1402 void XYWnd::PositionView( const Vector3& position ){
1403 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1404 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1406 m_vOrigin[nDim1] = position[nDim1];
1407 m_vOrigin[nDim2] = position[nDim2];
1411 XYWnd_Update( *this );
1414 void XYWnd::SetViewType( VIEWTYPE viewType ){
1415 m_viewType = viewType;
1419 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1424 inline WindowVector WindowVector_forInteger( int x, int y ){
1425 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1428 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1429 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1431 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1432 if ( buttons == Move_buttons() ) {
1434 EntityCreate_MouseDown( x, y );
1436 else if ( buttons == Zoom_buttons() ) {
1439 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1440 Clipper_OnLButtonDown( x, y );
1442 else if ( !ClipMode() && buttons == Clipper_quick_buttons() ) {
1444 g_quick_clipper = true;
1445 Clipper_OnLButtonDown( x, y );
1447 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1448 NewBrushDrag_Begin( x, y );
1450 // control mbutton = move camera
1451 else if ( buttons == MoveCamera_buttons() ) {
1452 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1454 // mbutton = angle camera
1455 else if ( buttons == OrientCamera_buttons() ) {
1456 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1458 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1459 SetCustomPivotOrigin( x, y );
1463 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1467 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1468 if ( m_move_started ) {
1470 EntityCreate_MouseUp( x, y );
1472 else if ( m_zoom_started ) {
1475 else if ( ClipMode() && ( buttons == Clipper_buttons() || buttons == Clipper_quick_buttons() ) ) {
1476 Clipper_OnLButtonUp( x, y );
1478 else if ( m_bNewBrushDrag ) {
1479 m_bNewBrushDrag = false;
1480 NewBrushDrag_End( x, y );
1481 if ( m_NewBrushDrag == 0 ) {
1482 //L button w/o created brush = tunnel selection
1483 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1488 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1492 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1493 // rbutton = drag xy origin
1494 if ( m_move_started ) {
1497 else if ( m_zoom_started ) {
1500 else if ( ClipMode() && g_pMovingClip != 0 ) {
1501 Clipper_OnMouseMoved( x, y );
1503 // lbutton without selection = drag new brush
1504 else if ( m_bNewBrushDrag ) {
1505 NewBrushDrag( x, y );
1508 // control mbutton = move camera
1509 else if ( buttons == MoveCamera_buttons() ) {
1510 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1513 // mbutton = angle camera
1514 else if ( buttons == OrientCamera_buttons() ) {
1515 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1518 else if ( buttons == SetCustomPivotOrigin_buttons() ) {
1519 SetCustomPivotOrigin( x, y );
1524 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1526 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1527 XY_ToPoint( x, y, m_mousePosition );
1528 XY_SnapToGrid( m_mousePosition );
1530 StringOutputStream status( 64 );
1531 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1532 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1533 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1534 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1536 if ( g_xywindow_globals_private.g_bCrossHairs ) {
1537 XYWnd_Update( *this );
1540 Clipper_Crosshair_OnMouseMoved( x, y );
1544 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1545 m_entityCreate = true;
1546 m_entityCreate_x = x;
1547 m_entityCreate_y = y;
1550 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1551 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1552 m_entityCreate = false;
1556 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1557 if ( m_entityCreate ) {
1558 m_entityCreate = false;
1563 inline float screen_normalised( int pos, unsigned int size ){
1564 return ( ( 2.0f * pos ) / size ) - 1.0f;
1567 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1568 return world_origin + normalised * normalised2world_scale;
1572 // TTimo: watch it, this doesn't init one of the 3 coords
1573 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1574 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1575 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1576 if ( m_viewType == XY ) {
1577 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1578 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1580 else if ( m_viewType == YZ ) {
1581 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1582 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1586 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1587 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1591 void XYWnd::XY_SnapToGrid( Vector3& point ){
1592 if ( m_viewType == XY ) {
1593 point[0] = float_snapped( point[0], GetSnapGridSize() );
1594 point[1] = float_snapped( point[1], GetSnapGridSize() );
1596 else if ( m_viewType == YZ ) {
1597 point[1] = float_snapped( point[1], GetSnapGridSize() );
1598 point[2] = float_snapped( point[2], GetSnapGridSize() );
1602 point[0] = float_snapped( point[0], GetSnapGridSize() );
1603 point[2] = float_snapped( point[2], GetSnapGridSize() );
1607 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1608 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1609 if ( relative == name ) {
1610 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1613 char fileNameWithoutExt[512];
1614 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1615 fileNameWithoutExt[512 - 1] = '\0';
1616 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1618 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1620 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1623 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1624 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1625 globalOutputStream() << "Loaded background texture " << relative << "\n";
1626 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1629 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1646 Select_GetBounds( min, max );
1647 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1648 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1649 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1650 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1653 void XYWnd::XY_DisableBackground( void ){
1654 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1655 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1656 free( g_pParentWnd->ActiveXY()->m_tex );
1658 g_pParentWnd->ActiveXY()->m_tex = NULL;
1661 void WXY_BackgroundSelect( void ){
1662 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1664 ui::Window main_window = MainFrame_getWindow();
1666 if ( !brushesSelected ) {
1667 ui::alert( main_window, "You have to select some brushes to get the bounding box for.\n",
1668 "No selection", ui::alert_type::OK, ui::alert_icon::Error );
1672 const char *filename = main_window.file_dialog( TRUE, "Background Image", NULL, NULL );
1674 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1677 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1680 // Draw the background image immediately (do not wait for user input).
1681 g_pParentWnd->ActiveXY()->Redraw();
1685 ============================================================================
1689 ============================================================================
1698 double two_to_the_power( int power ){
1699 return pow( 2.0f, power );
1702 void XYWnd::XY_DrawAxis( void ){
1703 if ( g_xywindow_globals_private.show_axis ) {
1704 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1705 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1706 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1707 const int w = ( m_nWidth / 2 / m_fScale );
1708 const int h = ( m_nHeight / 2 / m_fScale );
1710 Vector3 colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1711 Vector3 colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1713 float grayX = vector3_dot( colourX, Vector3( 0.2989, 0.5870, 0.1140 ) );
1714 float grayY = vector3_dot( colourY, Vector3( 0.2989, 0.5870, 0.1140 ) );
1715 colourX[0] = colourX[1] = colourX[2] = grayX;
1716 colourY[0] = colourY[1] = colourY[2] = grayY;
1719 // draw two lines with corresponding axis colors to highlight current view
1720 // horizontal line: nDim1 color
1722 glBegin( GL_LINES );
1723 glColor3fv( vector3_to_array( colourX ) );
1724 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1725 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1727 glVertex2f( 32 / m_fScale, 0 );
1728 glColor3fv( vector3_to_array( colourY ) );
1729 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1730 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1732 glVertex2f( 0, 32 / m_fScale );
1735 // now print axis symbols
1736 glColor3fv( vector3_to_array( colourX ) );
1737 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1738 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1739 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1740 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1741 glColor3fv( vector3_to_array( colourY ) );
1742 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1743 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1744 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1745 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1749 void XYWnd::RenderActive( void ){
1750 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
1751 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
1752 GlobalOpenGL_debugAssertNoErrors();
1753 glDrawBuffer( GL_FRONT );
1755 if ( g_xywindow_globals_private.show_outline ) {
1756 glMatrixMode( GL_PROJECTION );
1758 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1760 glMatrixMode( GL_MODELVIEW );
1763 if( !Active() ){ //sorta erase
1764 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridmajor ) );
1766 // four view mode doesn't colorize
1767 else if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
1768 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1772 switch ( m_viewType )
1775 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
1778 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
1781 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
1785 glBegin( GL_LINE_LOOP );
1786 glVertex2f( 0.5, 0.5 );
1787 glVertex2f( m_nWidth - 0.5, 1 );
1788 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
1789 glVertex2f( 0.5, m_nHeight - 0.5 );
1792 // we do this part (the old way) only if show_axis is disabled
1793 if ( !g_xywindow_globals_private.show_axis ) {
1794 glMatrixMode( GL_PROJECTION );
1796 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
1798 glMatrixMode( GL_MODELVIEW );
1802 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1805 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1808 glDisable( GL_BLEND );
1809 glRasterPos2f( 35, m_nHeight - 20 );
1811 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1815 glViewport( 0, 0, m_nWidth, m_nHeight );
1817 glMatrixMode( GL_PROJECTION );
1818 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
1820 glMatrixMode( GL_MODELVIEW );
1822 glScalef( m_fScale, m_fScale, 1 );
1823 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1824 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1825 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
1827 glDisable( GL_LINE_STIPPLE );
1828 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
1829 glDisableClientState( GL_NORMAL_ARRAY );
1830 glDisableClientState( GL_COLOR_ARRAY );
1831 glDisable( GL_TEXTURE_2D );
1832 glDisable( GL_LIGHTING );
1833 glDisable( GL_COLOR_MATERIAL );
1834 glDisable( GL_DEPTH_TEST );
1835 glDisable( GL_TEXTURE_1D );
1836 glDisable( GL_BLEND );
1838 XYWnd::XY_DrawAxis();
1841 glDrawBuffer( GL_BACK );
1842 GlobalOpenGL_debugAssertNoErrors();
1843 glwidget_make_current( m_gl_widget );
1848 void XYWnd::XY_DrawBackground( void ){
1849 glPushAttrib( GL_ALL_ATTRIB_BITS );
1851 glEnable( GL_TEXTURE_2D );
1852 glEnable( GL_BLEND );
1853 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1854 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1855 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1856 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1858 glPolygonMode( GL_FRONT, GL_FILL );
1860 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1861 glBegin( GL_QUADS );
1863 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1864 glTexCoord2f( 0.0, 1.0 );
1865 glVertex2f( m_xmin, m_ymin );
1867 glTexCoord2f( 1.0, 1.0 );
1868 glVertex2f( m_xmax, m_ymin );
1870 glTexCoord2f( 1.0, 0.0 );
1871 glVertex2f( m_xmax, m_ymax );
1873 glTexCoord2f( 0.0, 0.0 );
1874 glVertex2f( m_xmin, m_ymax );
1877 glBindTexture( GL_TEXTURE_2D, 0 );
1882 void XYWnd::XY_DrawGrid( void ) {
1883 float x, y, xb, xe, yb, ye;
1886 float step, minor_step, stepx, stepy;
1887 step = minor_step = stepx = stepy = GetGridSize();
1889 int minor_power = Grid_getPower();
1892 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1896 int power = minor_power;
1897 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1899 step = float(two_to_the_power( power ) );
1901 mask = ( 1 << ( power - minor_power ) ) - 1;
1902 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1904 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1907 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1909 glDisable( GL_TEXTURE_2D );
1910 glDisable( GL_TEXTURE_1D );
1911 glDisable( GL_DEPTH_TEST );
1912 glDisable( GL_BLEND );
1915 w = ( m_nWidth / 2 / m_fScale );
1916 h = ( m_nHeight / 2 / m_fScale );
1918 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1919 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1921 xb = m_vOrigin[nDim1] - w;
1922 if ( xb < region_mins[nDim1] ) {
1923 xb = region_mins[nDim1];
1925 xb = step * floor( xb / step );
1927 xe = m_vOrigin[nDim1] + w;
1928 if ( xe > region_maxs[nDim1] ) {
1929 xe = region_maxs[nDim1];
1931 xe = step * ceil( xe / step );
1933 yb = m_vOrigin[nDim2] - h;
1934 if ( yb < region_mins[nDim2] ) {
1935 yb = region_mins[nDim2];
1937 yb = step * floor( yb / step );
1939 ye = m_vOrigin[nDim2] + h;
1940 if ( ye > region_maxs[nDim2] ) {
1941 ye = region_maxs[nDim2];
1943 ye = step * ceil( ye / step );
1945 #define COLORS_DIFFER( a,b ) \
1946 ( ( a )[0] != ( b )[0] || \
1947 ( a )[1] != ( b )[1] || \
1948 ( a )[2] != ( b )[2] )
1951 // draw minor blocks
1952 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1954 glEnable( GL_BLEND );
1957 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1958 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1960 glBegin( GL_LINES );
1962 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1963 if ( ( i & mask ) != 0 ) {
1964 glVertex2f( x, yb );
1965 glVertex2f( x, ye );
1969 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1970 if ( ( i & mask ) != 0 ) {
1971 glVertex2f( xb, y );
1972 glVertex2f( xe, y );
1978 // draw major blocks
1979 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1980 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1982 glBegin( GL_LINES );
1983 for ( x = xb ; x <= xe ; x += step ) {
1984 glVertex2f( x, yb );
1985 glVertex2f( x, ye );
1987 for ( y = yb ; y <= ye ; y += step ) {
1988 glVertex2f( xb, y );
1989 glVertex2f( xe, y );
1995 glDisable( GL_BLEND );
1999 // draw coordinate text if needed
2000 if ( g_xywindow_globals_private.show_coordinates ) {
2001 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
2002 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
2003 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
2004 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
2005 glRasterPos2f( x, offx );
2006 sprintf( text, "%g", x );
2007 GlobalOpenGL().drawString( text );
2009 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
2010 glRasterPos2f( offy, y );
2011 sprintf( text, "%g", y );
2012 GlobalOpenGL().drawString( text );
2016 // we do this part (the old way) only if show_axis is disabled
2017 if ( !g_xywindow_globals_private.show_axis ) {
2019 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2022 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
2025 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
2027 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
2030 XYWnd::XY_DrawAxis();
2032 // show current work zone?
2033 // the work zone is used to place dropped points and brushes
2034 if ( g_xywindow_globals_private.d_show_work ) {
2035 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
2036 glBegin( GL_LINES );
2037 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
2038 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
2039 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
2040 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
2041 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
2042 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
2043 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
2044 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
2054 void XYWnd::XY_DrawBlockGrid(){
2055 if ( Map_FindWorldspawn( g_map ) == 0 ) {
2058 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
2059 if ( strlen( value ) ) {
2060 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
2063 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
2064 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
2065 g_xywindow_globals_private.blockSize = 1024;
2068 float x, y, xb, xe, yb, ye;
2072 glDisable( GL_TEXTURE_2D );
2073 glDisable( GL_TEXTURE_1D );
2074 glDisable( GL_DEPTH_TEST );
2075 glDisable( GL_BLEND );
2077 w = ( m_nWidth / 2 / m_fScale );
2078 h = ( m_nHeight / 2 / m_fScale );
2080 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2081 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2083 xb = m_vOrigin[nDim1] - w;
2084 if ( xb < region_mins[nDim1] ) {
2085 xb = region_mins[nDim1];
2087 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
2089 xe = m_vOrigin[nDim1] + w;
2090 if ( xe > region_maxs[nDim1] ) {
2091 xe = region_maxs[nDim1];
2093 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
2095 yb = m_vOrigin[nDim2] - h;
2096 if ( yb < region_mins[nDim2] ) {
2097 yb = region_mins[nDim2];
2099 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
2101 ye = m_vOrigin[nDim2] + h;
2102 if ( ye > region_maxs[nDim2] ) {
2103 ye = region_maxs[nDim2];
2105 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
2107 // draw major blocks
2109 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
2112 glBegin( GL_LINES );
2114 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
2116 glVertex2f( x, yb );
2117 glVertex2f( x, ye );
2120 if ( m_viewType == XY ) {
2121 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
2123 glVertex2f( xb, y );
2124 glVertex2f( xe, y );
2131 // draw coordinate text if needed
2133 if ( m_viewType == XY && m_fScale > .1 ) {
2134 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
2135 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
2137 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
2138 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
2139 GlobalOpenGL().drawString( text );
2143 glColor4f( 0, 0, 0, 0 );
2146 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
2147 Cam.fov = 48 / m_fScale;
2148 Cam.box = 16 / m_fScale;
2149 // globalOutputStream() << "pitch " << angles[CAMERA_PITCH] << " yaw " << angles[CAMERA_YAW] << "\n";
2151 if ( m_viewType == XY ) {
2154 Cam.a = degrees_to_radians( angles[CAMERA_YAW] );
2156 else if ( m_viewType == YZ ) {
2159 Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] > 180 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] );
2165 Cam.a = degrees_to_radians( ( angles[CAMERA_YAW] < 270 && angles[CAMERA_YAW] > 90 ) ? ( 180.0f - angles[CAMERA_PITCH] ) : angles[CAMERA_PITCH] );
2168 //glColor3f( 0.0, 0.0, 1.0 );
2169 glColor3f( 1.0, 1.0, 1.0 );
2170 glBegin( GL_LINE_STRIP );
2171 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2172 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
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.box,Cam.y,0 );
2179 glBegin( GL_LINE_STRIP );
2180 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 );
2181 glVertex3f( Cam.x, Cam.y, 0 );
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 );
2187 void XYWnd::UpdateCameraIcon( void ){
2188 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
2189 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
2190 GlobalOpenGL_debugAssertNoErrors();
2191 glDrawBuffer( GL_FRONT );
2194 glViewport( 0, 0, m_nWidth, m_nHeight );
2196 glMatrixMode( GL_PROJECTION );
2197 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2199 glMatrixMode( GL_MODELVIEW );
2201 glScalef( m_fScale, m_fScale, 1 );
2202 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2203 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2204 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2206 glDisable( GL_LINE_STIPPLE );
2207 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2208 glDisableClientState( GL_NORMAL_ARRAY );
2209 glDisableClientState( GL_COLOR_ARRAY );
2210 glDisable( GL_TEXTURE_2D );
2211 glDisable( GL_LIGHTING );
2212 glDisable( GL_COLOR_MATERIAL );
2213 glDisable( GL_DEPTH_TEST );
2214 glDisable( GL_TEXTURE_1D );
2216 glEnable( GL_BLEND );
2217 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2219 //glColor3f( 0.0, 0.0, 1.0 );
2220 glColor3f( 1.0, 1.0, 1.0 );
2221 glBegin( GL_LINE_STRIP );
2222 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2223 glVertex3f( Cam.x,Cam.y + ( Cam.box / 2 ),0 );
2224 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2225 glVertex3f( Cam.x,Cam.y - ( Cam.box / 2 ),0 );
2226 glVertex3f( Cam.x - Cam.box,Cam.y,0 );
2227 glVertex3f( Cam.x + Cam.box,Cam.y,0 );
2230 glBegin( GL_LINE_STRIP );
2231 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 );
2232 glVertex3f( Cam.x, Cam.y, 0 );
2233 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 );
2236 XYWnd::DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2238 glDisable( GL_BLEND );
2239 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
2242 glDrawBuffer( GL_BACK );
2243 GlobalOpenGL_debugAssertNoErrors();
2244 glwidget_make_current( m_gl_widget );
2250 float Betwixt( float f1, float f2 ){
2252 return f2 + ( ( f1 - f2 ) / 2 );
2255 return f1 + ( ( f2 - f1 ) / 2 );
2260 // can be greatly simplified but per usual i am in a hurry
2261 // which is not an excuse, just a fact
2262 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
2263 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
2266 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
2267 typedef const char* OrgStrings[2];
2268 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
2270 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
2272 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
2273 g_xywindow_globals.color_selbrushes[1] * .65f,
2274 g_xywindow_globals.color_selbrushes[2] * .65f );
2276 StringOutputStream dimensions( 16 );
2278 if ( m_viewType == XY ) {
2279 glBegin( GL_LINES );
2281 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2282 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2284 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2285 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2287 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
2288 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
2291 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2292 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2294 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
2295 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2297 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2298 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
2302 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
2303 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2304 GlobalOpenGL().drawString( dimensions.c_str() );
2307 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
2308 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2309 GlobalOpenGL().drawString( dimensions.c_str() );
2312 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
2313 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2314 GlobalOpenGL().drawString( dimensions.c_str() );
2316 else if ( m_viewType == XZ ) {
2317 glBegin( GL_LINES );
2319 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
2320 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
2322 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2323 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2325 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2326 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2329 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2330 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2332 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2333 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2335 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2336 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2340 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2341 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2342 GlobalOpenGL().drawString( dimensions.c_str() );
2345 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2346 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2347 GlobalOpenGL().drawString( dimensions.c_str() );
2350 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2351 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2352 GlobalOpenGL().drawString( dimensions.c_str() );
2356 glBegin( GL_LINES );
2358 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2359 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2361 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2362 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2364 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2365 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2368 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2369 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2371 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2372 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2374 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2375 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2379 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2380 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2381 GlobalOpenGL().drawString( dimensions.c_str() );
2384 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2385 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2386 GlobalOpenGL().drawString( dimensions.c_str() );
2389 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2390 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2391 GlobalOpenGL().drawString( dimensions.c_str() );
2395 class XYRenderer : public Renderer
2403 unsigned int m_highlight;
2407 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2408 m_globalstate( globalstate ),
2409 m_state_selected( selected ){
2410 ASSERT_NOTNULL( selected );
2411 m_state_stack.push_back( state_type() );
2414 void SetState( Shader* state, EStyle style ){
2415 ASSERT_NOTNULL( state );
2416 if ( style == eWireframeOnly ) {
2417 m_state_stack.back().m_state = state;
2420 EStyle getStyle() const {
2421 return eWireframeOnly;
2424 m_state_stack.push_back( m_state_stack.back() );
2427 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2428 m_state_stack.pop_back();
2430 void Highlight( EHighlightMode mode, bool bEnable = true ){
2432 ? m_state_stack.back().m_highlight |= mode
2433 : m_state_stack.back().m_highlight &= ~mode;
2435 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2436 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2437 m_state_selected->addRenderable( renderable, localToWorld );
2441 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2445 void render( const Matrix4& modelview, const Matrix4& projection ){
2446 GlobalShaderCache().render( m_globalstate, modelview, projection );
2449 std::vector<state_type> m_state_stack;
2450 RenderStateFlags m_globalstate;
2451 Shader* m_state_selected;
2454 void XYWnd::updateProjection( bool reconstruct ){
2455 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2456 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2457 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2459 m_projection[12] = 0.0f;
2460 m_projection[13] = 0.0f;
2461 m_projection[14] = -1.0f;
2473 m_projection[11] = 0.0f;
2475 m_projection[15] = 1.0f;
2478 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2482 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2483 void XYWnd::updateModelview( bool reconstruct ){
2484 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2485 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2488 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2489 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2490 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2493 switch ( m_viewType )
2496 m_modelview[0] = m_fScale;
2501 m_modelview[5] = m_fScale;
2506 m_modelview[10] = -m_fScale;
2509 m_modelview[0] = m_fScale;
2515 m_modelview[6] = m_fScale;
2518 m_modelview[9] = m_fScale;
2519 m_modelview[10] = 0;
2524 m_modelview[2] = -m_fScale;
2526 m_modelview[4] = m_fScale;
2531 m_modelview[9] = m_fScale;
2532 m_modelview[10] = 0;
2536 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2537 m_modelview[15] = 1;
2540 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2550 //#define DBG_SCENEDUMP
2552 void XYWnd::XY_Draw(){
2556 glViewport( 0, 0, m_nWidth, m_nHeight );
2557 glClearColor( g_xywindow_globals.color_gridback[0],
2558 g_xywindow_globals.color_gridback[1],
2559 g_xywindow_globals.color_gridback[2],0 );
2561 glClear( GL_COLOR_BUFFER_BIT );
2567 glMatrixMode( GL_PROJECTION );
2568 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2570 glMatrixMode( GL_MODELVIEW );
2572 glScalef( m_fScale, m_fScale, 1 );
2573 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2574 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2575 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2577 glDisable( GL_LINE_STIPPLE );
2579 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2580 glDisableClientState( GL_NORMAL_ARRAY );
2581 glDisableClientState( GL_COLOR_ARRAY );
2582 glDisable( GL_TEXTURE_2D );
2583 glDisable( GL_LIGHTING );
2584 glDisable( GL_COLOR_MATERIAL );
2585 glDisable( GL_DEPTH_TEST );
2587 if ( m_backgroundActivated ) {
2588 XY_DrawBackground();
2592 if ( g_xywindow_globals_private.show_blocks ) {
2596 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2598 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2599 if ( !g_xywindow_globals.m_bNoStipple ) {
2600 globalstate |= RENDER_LINESTIPPLE;
2604 XYRenderer renderer( globalstate, m_state_selected );
2606 Scene_Render( renderer, m_view );
2608 GlobalOpenGL_debugAssertNoErrors();
2609 renderer.render( m_modelview, m_projection );
2610 GlobalOpenGL_debugAssertNoErrors();
2613 glDepthMask( GL_FALSE );
2615 GlobalOpenGL_debugAssertNoErrors();
2617 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2619 GlobalOpenGL_debugAssertNoErrors();
2620 glDisable( GL_LINE_STIPPLE );
2621 GlobalOpenGL_debugAssertNoErrors();
2623 GlobalOpenGL_debugAssertNoErrors();
2624 if ( GlobalOpenGL().GL_1_3() ) {
2625 glActiveTexture( GL_TEXTURE0 );
2626 glClientActiveTexture( GL_TEXTURE0 );
2628 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2629 GlobalOpenGL_debugAssertNoErrors();
2630 glDisableClientState( GL_NORMAL_ARRAY );
2631 GlobalOpenGL_debugAssertNoErrors();
2632 glDisableClientState( GL_COLOR_ARRAY );
2633 GlobalOpenGL_debugAssertNoErrors();
2634 glDisable( GL_TEXTURE_2D );
2635 GlobalOpenGL_debugAssertNoErrors();
2636 glDisable( GL_LIGHTING );
2637 GlobalOpenGL_debugAssertNoErrors();
2638 glDisable( GL_COLOR_MATERIAL );
2639 GlobalOpenGL_debugAssertNoErrors();
2641 GlobalOpenGL_debugAssertNoErrors();
2645 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2647 Select_GetBounds( min, max );
2648 PaintSizeInfo( nDim1, nDim2, min, max );
2651 if ( g_xywindow_globals_private.g_bCrossHairs ) {
2652 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2653 glBegin( GL_LINES );
2654 if ( m_viewType == XY ) {
2655 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2656 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2657 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2658 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2660 else if ( m_viewType == YZ ) {
2661 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2662 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2663 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2664 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2668 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2669 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2670 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2671 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2677 GlobalClipPoints_Draw( m_fScale );
2680 GlobalOpenGL_debugAssertNoErrors();
2684 glScalef( m_fScale, m_fScale, 1 );
2685 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2687 glEnable( GL_BLEND );
2688 glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ZERO );
2689 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2690 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
2691 glDisable( GL_BLEND );
2693 Feedback_draw2D( m_viewType );
2695 if ( g_xywindow_globals_private.show_outline ) {
2697 glMatrixMode( GL_PROJECTION );
2699 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2701 glMatrixMode( GL_MODELVIEW );
2704 // four view mode doesn't colorize
2705 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2706 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2710 switch ( m_viewType )
2713 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2716 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2719 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2723 glBegin( GL_LINE_LOOP );
2724 glVertex2f( 0.5, 0.5 );
2725 glVertex2f( m_nWidth - 0.5, 1 );
2726 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2727 glVertex2f( 0.5, m_nHeight - 0.5 );
2732 GlobalOpenGL_debugAssertNoErrors();
2737 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2738 xywnd->XY_ToPoint( x, y, point );
2739 xywnd->XY_SnapToGrid( point );
2741 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2742 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2743 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2746 void XYWnd::OnEntityCreate( const char* item ){
2747 StringOutputStream command;
2748 command << "entityCreate -class " << item;
2749 UndoableCommand undo( command.c_str() );
2751 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2752 Entity_createFromSelection( item, point );
2757 void GetCenterPosition( Vector3& position ){
2758 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2759 Select_GetMid( position );
2763 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2767 void XYWnd_Centralize( XYWnd* xywnd ){
2769 GetCenterPosition( position );
2770 xywnd->PositionView( position );
2773 void XY_Split_Centralize(){
2775 GetCenterPosition( position );
2776 if ( g_pParentWnd->GetXYWnd() ) {
2777 g_pParentWnd->GetXYWnd()->PositionView( position );
2779 if ( g_pParentWnd->GetXZWnd() ) {
2780 g_pParentWnd->GetXZWnd()->PositionView( position );
2782 if ( g_pParentWnd->GetYZWnd() ) {
2783 g_pParentWnd->GetYZWnd()->PositionView( position );
2787 void XY_Centralize(){
2788 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2790 XY_Split_Centralize();
2794 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2795 XYWnd_Centralize( xywnd );
2800 void GetSelectionBbox( AABB& bounds ){
2801 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2802 Scene_BoundsSelected( GlobalSceneGraph(), bounds );
2806 bounds = AABB( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Vector3( 128.f, 128.f, 128.f ) );
2810 void XYWnd_Focus( XYWnd* xywnd ){
2812 GetSelectionBbox( bounds );
2813 xywnd->FocusOnBounds( bounds );
2816 void XY_Split_Focus(){
2818 GetSelectionBbox( bounds );
2819 if ( g_pParentWnd->GetXYWnd() ) {
2820 g_pParentWnd->GetXYWnd()->FocusOnBounds( bounds );
2822 if ( g_pParentWnd->GetXZWnd() ) {
2823 g_pParentWnd->GetXZWnd()->FocusOnBounds( bounds );
2825 if ( g_pParentWnd->GetYZWnd() ) {
2826 g_pParentWnd->GetYZWnd()->FocusOnBounds( bounds );
2831 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2837 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2838 XYWnd_Focus( xywnd );
2843 void XY_TopFrontSide( VIEWTYPE viewtype ){
2844 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2845 // cannot do this in a split window
2846 // do something else that the user may want here
2847 XY_Split_Centralize();
2850 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2851 xywnd->SetViewType( viewtype );
2852 XYWnd_Centralize( xywnd );
2856 XY_TopFrontSide( XY );
2860 XY_TopFrontSide( XZ );
2864 XY_TopFrontSide( YZ );
2867 void XY_NextView( XYWnd* xywnd ){
2868 if ( xywnd->GetViewType() == XY ) {
2869 xywnd->SetViewType( XZ );
2871 else if ( xywnd->GetViewType() == XZ ) {
2872 xywnd->SetViewType( YZ );
2875 xywnd->SetViewType( XY );
2877 XYWnd_Centralize( xywnd );
2881 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2882 // cannot do this in a split window
2883 // do something else that the user may want here
2884 XY_Split_Centralize();
2887 XYWnd* xywnd = g_pParentWnd->CurrentStyle() == MainFrame::eFloating ? g_pParentWnd->ActiveXY() : g_pParentWnd->GetXYWnd();
2888 XY_NextView( xywnd );
2892 if ( g_pParentWnd->GetXYWnd() ) {
2893 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2895 if ( g_pParentWnd->GetXZWnd() ) {
2896 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2898 if ( g_pParentWnd->GetYZWnd() ) {
2899 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2904 g_pParentWnd->ActiveXY()->ZoomIn();
2907 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2908 // we don't go below a zoom factor corresponding to 10% of the max world size
2909 // (this has to be computed against the window size)
2911 g_pParentWnd->ActiveXY()->ZoomOut();
2916 void ToggleShowCrosshair(){
2917 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2918 XY_UpdateAllWindows();
2921 void ToggleShowSizeInfo(){
2922 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2923 XY_UpdateAllWindows();
2926 void ToggleShowGrid(){
2927 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2928 XY_UpdateAllWindows();
2931 ToggleShown g_xy_top_shown( true );
2933 void XY_Top_Shown_Construct( ui::Window parent ){
2934 g_xy_top_shown.connect( parent );
2937 ToggleShown g_yz_side_shown( false );
2939 void YZ_Side_Shown_Construct( ui::Window parent ){
2940 g_yz_side_shown.connect( parent );
2943 ToggleShown g_xz_front_shown( false );
2945 void XZ_Front_Shown_Construct( ui::Window parent ){
2946 g_xz_front_shown.connect( parent );
2950 class EntityClassMenu : public ModuleObserver
2952 std::size_t m_unrealised;
2954 EntityClassMenu() : m_unrealised( 1 ){
2957 if ( --m_unrealised == 0 ) {
2961 if ( ++m_unrealised == 1 ) {
2962 if ( XYWnd::m_mnuDrop ) {
2963 XYWnd::m_mnuDrop.destroy();
2964 XYWnd::m_mnuDrop = ui::Menu(ui::null);
2970 EntityClassMenu g_EntityClassMenu;
2974 void ShowNamesToggle(){
2975 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2976 XY_UpdateAllWindows();
2979 typedef FreeCaller<void(), ShowNamesToggle> ShowNamesToggleCaller;
2981 void ShowNamesExport( const Callback<void(bool)> & importer ){
2982 importer( GlobalEntityCreator().getShowNames() );
2985 typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller;
2988 void ShowTargetNamesToggle(){
2989 GlobalEntityCreator().setShowTargetNames( !GlobalEntityCreator().getShowTargetNames() );
2990 XY_UpdateAllWindows();
2993 typedef FreeCaller<void(), ShowTargetNamesToggle> ShowTargetNamesToggleCaller;
2995 void ShowTargetNamesExport( const Callback<void(bool)> & importer ){
2996 importer( GlobalEntityCreator().getShowTargetNames() );
2999 typedef FreeCaller<void(const Callback<void(bool)> &), ShowTargetNamesExport> ShowTargetNamesExportCaller;
3002 void ShowAnglesToggle(){
3003 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
3004 XY_UpdateAllWindows();
3007 typedef FreeCaller<void(), ShowAnglesToggle> ShowAnglesToggleCaller;
3009 void ShowAnglesExport( const Callback<void(bool)> & importer ){
3010 importer( GlobalEntityCreator().getShowAngles() );
3012 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAnglesExport> ShowAnglesExportCaller;
3015 void ShowBlocksToggle(){
3016 g_xywindow_globals_private.show_blocks ^= 1;
3017 XY_UpdateAllWindows();
3020 typedef FreeCaller<void(), ShowBlocksToggle> ShowBlocksToggleCaller;
3022 void ShowBlocksExport( const Callback<void(bool)> & importer ){
3023 importer( g_xywindow_globals_private.show_blocks );
3026 typedef FreeCaller<void(const Callback<void(bool)> &), ShowBlocksExport> ShowBlocksExportCaller;
3029 void ShowCoordinatesToggle(){
3030 g_xywindow_globals_private.show_coordinates ^= 1;
3031 XY_UpdateAllWindows();
3034 typedef FreeCaller<void(), ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
3036 void ShowCoordinatesExport( const Callback<void(bool)> & importer ){
3037 importer( g_xywindow_globals_private.show_coordinates );
3040 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCoordinatesExport> ShowCoordinatesExportCaller;
3043 void ShowOutlineToggle(){
3044 g_xywindow_globals_private.show_outline ^= 1;
3045 XY_UpdateAllWindows();
3048 typedef FreeCaller<void(), ShowOutlineToggle> ShowOutlineToggleCaller;
3050 void ShowOutlineExport( const Callback<void(bool)> & importer ){
3051 importer( g_xywindow_globals_private.show_outline );
3054 typedef FreeCaller<void(const Callback<void(bool)> &), ShowOutlineExport> ShowOutlineExportCaller;
3057 void ShowAxesToggle(){
3058 g_xywindow_globals_private.show_axis ^= 1;
3059 XY_UpdateAllWindows();
3061 typedef FreeCaller<void(), ShowAxesToggle> ShowAxesToggleCaller;
3063 void ShowAxesExport( const Callback<void(bool)> & importer ){
3064 importer( g_xywindow_globals_private.show_axis );
3067 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAxesExport> ShowAxesExportCaller;
3070 void ShowWorkzoneToggle(){
3071 g_xywindow_globals_private.d_show_work ^= 1;
3072 XY_UpdateAllWindows();
3074 typedef FreeCaller<void(), ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
3076 void ShowWorkzoneExport( const Callback<void(bool)> & importer ){
3077 importer( g_xywindow_globals_private.d_show_work );
3080 typedef FreeCaller<void(const Callback<void(bool)> &), ShowWorkzoneExport> ShowWorkzoneExportCaller;
3083 BoolExportCaller g_texdef_movelock_caller( g_brush_texturelock_enabled );
3084 ToggleItem g_texdef_movelock_item( g_texdef_movelock_caller );
3086 void Texdef_ToggleMoveLock(){
3087 g_brush_texturelock_enabled = !g_brush_texturelock_enabled;
3088 g_texdef_movelock_item.update();
3093 void ShowSizeToggle(){
3094 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
3095 XY_UpdateAllWindows();
3097 typedef FreeCaller<void(), ShowSizeToggle> ShowSizeToggleCaller;
3098 void ShowSizeExport( const Callback<void(bool)> & importer ){
3099 importer( g_xywindow_globals_private.m_bSizePaint );
3101 typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowSizeExportCaller;
3104 void ShowCrosshairToggle(){
3105 g_xywindow_globals_private.g_bCrossHairs ^= 1;
3106 XY_UpdateAllWindows();
3108 typedef FreeCaller<void(), ShowCrosshairToggle> ShowCrosshairToggleCaller;
3109 void ShowCrosshairExport( const Callback<void(bool)> & importer ){
3110 importer( g_xywindow_globals_private.g_bCrossHairs );
3112 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCrosshairExport> ShowCrosshairExportCaller;
3115 void ShowGridToggle(){
3116 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
3117 XY_UpdateAllWindows();
3119 typedef FreeCaller<void(), ShowGridToggle> ShowGridToggleCaller;
3120 void ShowGridTExport( const Callback<void(bool)> & importer ){
3121 importer( g_xywindow_globals_private.d_showgrid );
3123 typedef FreeCaller<void(const Callback<void(bool)> &), ShowSizeExport> ShowGridExportCaller;
3126 ShowNamesExportCaller g_show_names_caller;
3127 Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller );
3128 ToggleItem g_show_names( g_show_names_callback );
3130 ShowTargetNamesExportCaller g_show_targetnames_caller;
3131 Callback<void(const Callback<void(bool)> &)> g_show_targetnames_callback( g_show_targetnames_caller );
3132 ToggleItem g_show_targetnames( g_show_targetnames_callback );
3134 ShowAnglesExportCaller g_show_angles_caller;
3135 Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller );
3136 ToggleItem g_show_angles( g_show_angles_callback );
3138 ShowBlocksExportCaller g_show_blocks_caller;
3139 Callback<void(const Callback<void(bool)> &)> g_show_blocks_callback( g_show_blocks_caller );
3140 ToggleItem g_show_blocks( g_show_blocks_callback );
3142 ShowCoordinatesExportCaller g_show_coordinates_caller;
3143 Callback<void(const Callback<void(bool)> &)> g_show_coordinates_callback( g_show_coordinates_caller );
3144 ToggleItem g_show_coordinates( g_show_coordinates_callback );
3146 ShowOutlineExportCaller g_show_outline_caller;
3147 Callback<void(const Callback<void(bool)> &)> g_show_outline_callback( g_show_outline_caller );
3148 ToggleItem g_show_outline( g_show_outline_callback );
3150 ShowAxesExportCaller g_show_axes_caller;
3151 Callback<void(const Callback<void(bool)> &)> g_show_axes_callback( g_show_axes_caller );
3152 ToggleItem g_show_axes( g_show_axes_callback );
3154 ShowWorkzoneExportCaller g_show_workzone_caller;
3155 Callback<void(const Callback<void(bool)> &)> g_show_workzone_callback( g_show_workzone_caller );
3156 ToggleItem g_show_workzone( g_show_workzone_callback );
3158 ShowSizeExportCaller g_show_size_caller;
3159 Callback<void(const Callback<void(bool)> &)> g_show_size_callback( g_show_size_caller );
3160 ToggleItem g_show_size( g_show_size_callback );
3162 ShowCrosshairExportCaller g_show_crosshair_caller;
3163 Callback<void(const Callback<void(bool)> &)> g_show_crosshair_callback( g_show_crosshair_caller );
3164 ToggleItem g_show_crosshair( g_show_crosshair_callback );
3166 ShowGridExportCaller g_show_grid_caller;
3167 Callback<void(const Callback<void(bool)> &)> g_show_grid_callback( g_show_grid_caller );
3168 ToggleItem g_show_grid( g_show_grid_callback );
3171 void XYShow_registerCommands(){
3172 GlobalToggles_insert( "ToggleSizePaint", ShowSizeToggleCaller(), ToggleItem::AddCallbackCaller( g_show_size ), Accelerator( 'J' ) );
3173 GlobalToggles_insert( "ToggleCrosshairs", ShowCrosshairToggleCaller(), ToggleItem::AddCallbackCaller( g_show_crosshair ), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
3174 GlobalToggles_insert( "ToggleGrid", ShowGridToggleCaller(), ToggleItem::AddCallbackCaller( g_show_grid ), Accelerator( '0' ) );
3176 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
3177 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
3178 GlobalToggles_insert( "ShowTargetNames", ShowTargetNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_targetnames ) );
3179 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
3180 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
3181 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
3182 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
3183 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
3186 void XYWnd_registerShortcuts(){
3187 command_connect_accelerator( "ToggleCrosshairs" );
3188 command_connect_accelerator( "ToggleSizePaint" );
3193 void Orthographic_constructPreferences( PreferencesPage& page ){
3194 page.appendCheckBox( "", "Solid selection boxes ( no stipple )", g_xywindow_globals.m_bNoStipple );
3195 //page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
3196 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
3197 // page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
3198 page.appendCheckBox( "", "Zoom In to Mouse pointer", g_xywindow_globals.m_bZoomInToPointer );
3200 void Orthographic_constructPage( PreferenceGroup& group ){
3201 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
3202 Orthographic_constructPreferences( page );
3204 void Orthographic_registerPreferencesPage(){
3205 PreferencesDialog_addSettingsPage( makeCallbackF(Orthographic_constructPage) );
3208 void Clipper_constructPreferences( PreferencesPage& page ){
3209 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
3211 void Clipper_constructPage( PreferenceGroup& group ){
3212 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
3213 Clipper_constructPreferences( page );
3215 void Clipper_registerPreferencesPage(){
3216 PreferencesDialog_addSettingsPage( makeCallbackF(Clipper_constructPage) );
3220 #include "preferencesystem.h"
3221 #include "stringio.h"
3224 struct ToggleShown_Bool {
3225 static void Export(const ToggleShown &self, const Callback<void(bool)> &returnz) {
3226 returnz(self.active());
3229 static void Import(ToggleShown &self, bool value) {
3235 void XYWindow_Construct(){
3236 // GlobalCommands_insert( "ToggleCrosshairs", makeCallbackF(ToggleShowCrosshair), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
3237 // GlobalCommands_insert( "ToggleSizePaint", makeCallbackF(ToggleShowSizeInfo), Accelerator( 'J' ) );
3238 // GlobalCommands_insert( "ToggleGrid", makeCallbackF(ToggleShowGrid), Accelerator( '0' ) );
3240 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 ) ) );
3241 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
3242 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
3243 GlobalCommands_insert( "NextView", makeCallbackF(XY_Next), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut
3244 GlobalCommands_insert( "ZoomIn", makeCallbackF(XY_ZoomIn), Accelerator( GDK_KEY_Delete ) );
3245 GlobalCommands_insert( "ZoomOut", makeCallbackF(XY_ZoomOut), Accelerator( GDK_KEY_Insert ) );
3246 GlobalCommands_insert( "ViewTop", makeCallbackF(XY_Top), Accelerator( GDK_KEY_KP_Home ) );
3247 GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) );
3248 GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) );
3249 GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) );
3250 GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Centralize), Accelerator( GDK_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
3251 GlobalCommands_insert( "XYFocusOnSelected", makeCallbackF(XY_Focus), Accelerator( GDK_grave ) );
3253 GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) );
3255 // GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
3256 GlobalPreferenceSystem().registerPreference( "2DZoomInToPointer", make_property_string( g_xywindow_globals.m_bZoomInToPointer ) );
3257 GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) );
3258 GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) );
3259 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );
3260 GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) );
3261 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) );
3262 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) );
3263 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) );
3264 // GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
3265 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) );
3267 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) );
3268 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) );
3269 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) );
3270 GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) );
3271 GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) );
3272 GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) );
3273 GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) );
3274 GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) );
3275 GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) );
3276 GlobalPreferenceSystem().registerPreference( "SI_Colors9", make_property_string( g_xywindow_globals.color_viewname ) );
3277 GlobalPreferenceSystem().registerPreference( "SI_Colors10", make_property_string( g_xywindow_globals.color_clipper ) );
3278 GlobalPreferenceSystem().registerPreference( "SI_Colors11", make_property_string( g_xywindow_globals.color_selbrushes ) );
3281 GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) );
3282 GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) );
3284 Orthographic_registerPreferencesPage();
3285 Clipper_registerPreferencesPage();
3287 XYWnd::captureStates();
3288 GlobalEntityClassManager().attach( g_EntityClassMenu );
3291 void XYWindow_Destroy(){
3292 GlobalEntityClassManager().detach( g_EntityClassMenu );
3293 XYWnd::releaseStates();