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)
30 #include "debugging/debugging.h"
37 #include "ifilesystem.h"
40 #include "gtkutil/messagebox.h"
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtkmenuitem.h>
45 #include "generic/callback.h"
46 #include "string/string.h"
47 #include "stream/stringstream.h"
50 #include "eclasslib.h"
52 #include "moduleobserver.h"
54 #include "gtkutil/menu.h"
55 #include "gtkutil/container.h"
56 #include "gtkutil/widget.h"
57 #include "gtkutil/glwidget.h"
58 #include "gtkutil/filechooser.h"
62 #include "brushmanip.h"
63 #include "selection.h"
65 #include "camwindow.h"
66 #include "texwindow.h"
67 #include "mainframe.h"
68 #include "preferences.h"
72 #include "windowobservers.h"
74 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
77 extern bool g_brush_always_caulk;
83 Vector3 m_ptClip; // the 3d point
90 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
104 /*! Draw clip/path point with rasterized number label */
105 void Draw( int num, float scale );
106 /*! Draw clip/path point with rasterized string label */
107 void Draw( const char *label, float scale );
110 VIEWTYPE g_clip_viewtype;
111 bool g_bSwitch = true;
112 bool g_clip_useCaulk = false;
116 ClipPoint* g_pMovingClip = 0;
118 /* Drawing clip points */
119 void ClipPoint::Draw( int num, float scale ){
120 StringOutputStream label( 4 );
122 Draw( label.c_str(), scale );
125 void ClipPoint::Draw( const char *label, float scale ){
128 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
129 glBegin( GL_POINTS );
130 glVertex3fv( vector3_to_array( m_ptClip ) );
134 float offset = 2.0f / scale;
137 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
138 glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label );
141 float fDiff( float f1, float f2 ){
150 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
151 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
152 int nDim2 = ( viewtype == XY ) ? 1 : 2;
153 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
154 if ( screenDistanceSquared < 8 * 8 ) {
155 return screenDistanceSquared;
160 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
162 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
163 if ( distance < bestDistance ) {
164 bestDistance = distance;
170 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
171 double bestDistance = FLT_MAX;
172 ClipPoint* bestClip = 0;
173 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
174 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
175 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
179 inline void GlobalClipPoints_Draw( float scale ){
181 if ( g_Clip1.Set() ) {
182 g_Clip1.Draw( 1, scale );
184 if ( g_Clip2.Set() ) {
185 g_Clip2.Draw( 2, scale );
187 if ( g_Clip3.Set() ) {
188 g_Clip3.Draw( 3, scale );
192 inline bool GlobalClipPoints_valid(){
193 return g_Clip1.Set() && g_Clip2.Set();
196 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
197 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
198 planepts[0] = g_Clip1.m_ptClip;
199 planepts[1] = g_Clip2.m_ptClip;
200 planepts[2] = g_Clip3.m_ptClip;
201 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
202 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
203 if ( !g_Clip3.Set() ) {
204 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
205 int x = ( n == 0 ) ? 1 : 0;
206 int y = ( n == 2 ) ? 1 : 2;
208 if ( n == 1 ) { // on viewtype XZ, flip clip points
209 planepts[0][n] = maxs[n];
210 planepts[1][n] = maxs[n];
211 planepts[2][x] = g_Clip1.m_ptClip[x];
212 planepts[2][y] = g_Clip1.m_ptClip[y];
213 planepts[2][n] = mins[n];
217 planepts[0][n] = mins[n];
218 planepts[1][n] = mins[n];
219 planepts[2][x] = g_Clip1.m_ptClip[x];
220 planepts[2][y] = g_Clip1.m_ptClip[y];
221 planepts[2][n] = maxs[n];
228 if ( !GlobalClipPoints_valid() ) {
229 planepts[0] = Vector3( 0, 0, 0 );
230 planepts[1] = Vector3( 0, 0, 0 );
231 planepts[2] = Vector3( 0, 0, 0 );
232 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
236 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
237 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
239 std::swap( planepts[0], planepts[1] );
241 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
243 ClipperChangeNotify();
246 const char* Clip_getShader(){
247 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
251 if ( ClipMode() && GlobalClipPoints_valid() ) {
253 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
254 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
255 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
260 ClipperChangeNotify();
265 if ( ClipMode() && GlobalClipPoints_valid() ) {
267 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
268 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
269 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
274 ClipperChangeNotify();
279 g_bSwitch = !g_bSwitch;
281 ClipperChangeNotify();
284 void OnClipMode( bool enabled ){
289 if ( !enabled && g_pMovingClip ) {
294 ClipperChangeNotify();
298 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
301 void NewClipPoint( const Vector3& point ){
302 if ( g_Clip1.Set() == false ) {
303 g_Clip1.m_ptClip = point;
306 else if ( g_Clip2.Set() == false ) {
307 g_Clip2.m_ptClip = point;
310 else if ( g_Clip3.Set() == false ) {
311 g_Clip3.m_ptClip = point;
319 g_Clip1.m_ptClip = point;
324 ClipperChangeNotify();
329 struct xywindow_globals_private_t
333 // these are in the View > Show menu with Show coordinates
335 bool show_coordinates;
349 xywindow_globals_private_t() :
353 show_coordinates( true ),
355 show_outline( false ),
358 d_show_work( false ),
360 show_blocks( false ),
362 m_bCamXYUpdate( true ),
363 m_bChaseMouse( true ),
364 m_bSizePaint( true ){
369 xywindow_globals_t g_xywindow_globals;
370 xywindow_globals_private_t g_xywindow_globals_private;
372 const unsigned int RAD_NONE = 0x00;
373 const unsigned int RAD_SHIFT = 0x01;
374 const unsigned int RAD_ALT = 0x02;
375 const unsigned int RAD_CONTROL = 0x04;
376 const unsigned int RAD_PRESS = 0x08;
377 const unsigned int RAD_LBUTTON = 0x10;
378 const unsigned int RAD_MBUTTON = 0x20;
379 const unsigned int RAD_RBUTTON = 0x40;
381 inline ButtonIdentifier button_for_flags( unsigned int flags ){
382 if ( flags & RAD_LBUTTON ) {
385 if ( flags & RAD_RBUTTON ) {
386 return c_buttonRight;
388 if ( flags & RAD_MBUTTON ) {
389 return c_buttonMiddle;
391 return c_buttonInvalid;
394 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
395 ModifierFlags modifiers = c_modifierNone;
396 if ( flags & RAD_SHIFT ) {
397 modifiers |= c_modifierShift;
399 if ( flags & RAD_CONTROL ) {
400 modifiers |= c_modifierControl;
402 if ( flags & RAD_ALT ) {
403 modifiers |= c_modifierAlt;
408 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
409 unsigned int buttons = 0;
411 switch ( button.get() )
413 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
414 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
415 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
418 if ( bitfield_enabled( flags, c_modifierControl ) ) {
419 buttons |= RAD_CONTROL;
422 if ( bitfield_enabled( flags, c_modifierShift ) ) {
423 buttons |= RAD_SHIFT;
426 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
433 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
434 unsigned int flags = 0;
436 switch ( event->button )
438 case 1: flags |= RAD_LBUTTON; break;
439 case 2: flags |= RAD_MBUTTON; break;
440 case 3: flags |= RAD_RBUTTON; break;
443 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
444 flags |= RAD_CONTROL;
447 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
451 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
458 inline unsigned int buttons_for_state( guint state ){
459 unsigned int flags = 0;
461 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
462 flags |= RAD_LBUTTON;
465 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
466 flags |= RAD_MBUTTON;
469 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
470 flags |= RAD_RBUTTON;
473 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
474 flags |= RAD_CONTROL;
477 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
481 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
489 void XYWnd::SetScale( float f ){
493 XYWnd_Update( *this );
496 void XYWnd_ZoomIn( XYWnd* xy ){
497 float max_scale = 64;
498 float scale = xy->Scale() * 5.0f / 4.0f;
499 if ( scale > max_scale ) {
500 if ( xy->Scale() != max_scale ) {
501 xy->SetScale( max_scale );
506 xy->SetScale( scale );
511 // NOTE: the zoom out factor is 4/5, we could think about customizing it
512 // we don't go below a zoom factor corresponding to 10% of the max world size
513 // (this has to be computed against the window size)
514 void XYWnd_ZoomOut( XYWnd* xy ){
515 float min_scale = MIN( xy->Width(),xy->Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
516 float scale = xy->Scale() * 4.0f / 5.0f;
517 if ( scale < min_scale ) {
518 if ( xy->Scale() != min_scale ) {
519 xy->SetScale( min_scale );
524 xy->SetScale( scale );
528 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
529 ASSERT_NOTNULL( g_pParentWnd );
530 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
531 return g_pParentWnd->ActiveXY()->GetViewType();
534 // =============================================================================
537 bool g_bCrossHairs = false;
539 GtkMenu* XYWnd::m_mnuDrop = 0;
544 Timer g_chasemouse_timer;
546 void XYWnd::ChaseMouse(){
547 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
548 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
550 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
552 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
553 g_chasemouse_timer.start();
556 gboolean xywnd_chasemouse( gpointer data ){
557 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
561 inline const int& min_int( const int& left, const int& right ){
562 return std::min( left, right );
565 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
566 m_chasemouse_delta_x = 0;
567 m_chasemouse_delta_y = 0;
569 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
570 const int epsilon = 16;
572 if ( pointx < epsilon ) {
573 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
575 else if ( ( pointx - m_nWidth ) > -epsilon ) {
576 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
579 if ( pointy < epsilon ) {
580 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
582 else if ( ( pointy - m_nHeight ) > -epsilon ) {
583 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
586 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
587 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
588 m_chasemouse_current_x = pointx;
589 m_chasemouse_current_y = pointy;
590 if ( m_chasemouse_handler == 0 ) {
591 //globalOutputStream() << "chasemouse timer start... ";
592 g_chasemouse_timer.start();
593 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
599 if ( m_chasemouse_handler != 0 ) {
600 //globalOutputStream() << "chasemouse cancel\n";
601 g_source_remove( m_chasemouse_handler );
602 m_chasemouse_handler = 0;
608 if ( m_chasemouse_handler != 0 ) {
609 //globalOutputStream() << "chasemouse cancel\n";
610 g_source_remove( m_chasemouse_handler );
611 m_chasemouse_handler = 0;
617 // =============================================================================
619 Shader* XYWnd::m_state_selected = 0;
621 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
622 if ( GTK_WIDGET_VISIBLE( self.GetWidget() ) ) {
623 self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.Width(), self.Height() ) );
627 gboolean xywnd_button_press( GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd ){
628 if ( event->type == GDK_BUTTON_PRESS ) {
629 g_pParentWnd->SetActiveXY( xywnd );
631 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
633 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
638 gboolean xywnd_button_release( GtkWidget* widget, GdkEventButton* event, XYWnd* xywnd ){
639 if ( event->type == GDK_BUTTON_RELEASE ) {
640 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
642 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
647 gboolean xywnd_focus_in( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
648 if ( event->type == GDK_FOCUS_CHANGE ) {
650 g_pParentWnd->SetActiveXY( xywnd );
656 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
657 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
660 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
663 gboolean xywnd_wheel_scroll( GtkWidget* widget, GdkEventScroll* event, XYWnd* xywnd ){
664 if ( event->direction == GDK_SCROLL_UP ) {
665 XYWnd_ZoomIn( xywnd );
667 else if ( event->direction == GDK_SCROLL_DOWN ) {
668 XYWnd_ZoomOut( xywnd );
673 gboolean xywnd_size_allocate( GtkWidget* widget, GtkAllocation* allocation, XYWnd* xywnd ){
674 xywnd->m_nWidth = allocation->width;
675 xywnd->m_nHeight = allocation->height;
676 xywnd->updateProjection();
677 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
681 gboolean xywnd_expose( GtkWidget* widget, GdkEventExpose* event, XYWnd* xywnd ){
682 if ( glwidget_make_current( xywnd->GetWidget() ) != FALSE ) {
683 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
684 GlobalOpenGL_debugAssertNoErrors();
686 GlobalOpenGL_debugAssertNoErrors();
688 xywnd->m_XORRectangle.set( rectangle_t() );
690 glwidget_swap_buffers( xywnd->GetWidget() );
696 void XYWnd_CameraMoved( XYWnd& xywnd ){
697 if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
698 XYWnd_Update( xywnd );
703 m_gl_widget( glwidget_new( FALSE ) ),
704 m_deferredDraw( WidgetQueueDrawCaller( *m_gl_widget ) ),
705 m_deferred_motion( xywnd_motion, this ),
707 m_window_observer( NewWindowObserver() ),
708 m_XORRectangle( m_gl_widget ),
709 m_chasemouse_handler( 0 ){
713 m_bNewBrushDrag = false;
714 m_move_started = false;
715 m_zoom_started = false;
726 m_backgroundActivated = false;
733 m_entityCreate = false;
737 GlobalWindowObservers_add( m_window_observer );
738 GlobalWindowObservers_connectWidget( m_gl_widget );
740 m_window_observer->setRectangleDrawCallback( ReferenceCaller1<XYWnd, rect_t, xy_update_xor_rectangle>( *this ) );
741 m_window_observer->setView( m_view );
743 gtk_widget_ref( m_gl_widget );
745 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 );
746 GTK_WIDGET_SET_FLAGS( m_gl_widget, GTK_CAN_FOCUS );
748 m_sizeHandler = g_signal_connect( G_OBJECT( m_gl_widget ), "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
749 m_exposeHandler = g_signal_connect( G_OBJECT( m_gl_widget ), "expose_event", G_CALLBACK( xywnd_expose ), this );
751 g_signal_connect( G_OBJECT( m_gl_widget ), "button_press_event", G_CALLBACK( xywnd_button_press ), this );
752 g_signal_connect( G_OBJECT( m_gl_widget ), "button_release_event", G_CALLBACK( xywnd_button_release ), this );
753 g_signal_connect( G_OBJECT( m_gl_widget ), "focus_in_event", G_CALLBACK( xywnd_focus_in ), this );
754 g_signal_connect( G_OBJECT( m_gl_widget ), "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
756 g_signal_connect( G_OBJECT( m_gl_widget ), "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
758 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
763 AddSceneChangeCallback( ReferenceCaller<XYWnd, &XYWnd_Update>( *this ) );
764 AddCameraMovedCallback( ReferenceCaller<XYWnd, &XYWnd_CameraMoved>( *this ) );
766 PressedButtons_connect( g_pressedButtons, m_gl_widget );
768 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
774 if ( m_mnuDrop != 0 ) {
775 gtk_widget_destroy( GTK_WIDGET( m_mnuDrop ) );
779 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
780 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
782 gtk_widget_unref( m_gl_widget );
784 m_window_observer->release();
787 void XYWnd::captureStates(){
788 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
791 void XYWnd::releaseStates(){
792 GlobalShaderCache().release( "$XY_OVERLAY" );
795 const Vector3& XYWnd::GetOrigin(){
799 void XYWnd::SetOrigin( const Vector3& origin ){
804 void XYWnd::Scroll( int x, int y ){
805 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
806 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
807 m_vOrigin[nDim1] += x / m_fScale;
808 m_vOrigin[nDim2] += y / m_fScale;
813 unsigned int Clipper_buttons(){
817 void XYWnd::DropClipPoint( int pointx, int pointy ){
820 XY_ToPoint( pointx, pointy, point );
823 Select_GetMid( mid );
824 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
825 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
826 point[nDim] = mid[nDim];
827 vector3_snap( point, GetSnapGridSize() );
828 NewClipPoint( point );
831 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
832 Vector3 mousePosition;
833 XY_ToPoint( x, y, mousePosition );
834 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
835 if ( !g_pMovingClip ) {
836 DropClipPoint( x, y );
840 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
841 if ( g_pMovingClip ) {
846 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
847 if ( g_pMovingClip ) {
848 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
849 XY_SnapToGrid( g_pMovingClip->m_ptClip );
851 ClipperChangeNotify();
855 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
856 Vector3 mousePosition;
857 XY_ToPoint( x, y, mousePosition );
858 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
860 cursor = gdk_cursor_new( GDK_CROSSHAIR );
861 gdk_window_set_cursor( m_gl_widget->window, cursor );
862 gdk_cursor_unref( cursor );
866 gdk_window_set_cursor( m_gl_widget->window, 0 );
870 unsigned int MoveCamera_buttons(){
871 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
874 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
875 Vector3 origin( Camera_getOrigin( camwnd ) );
876 xywnd->XY_ToPoint( x, y, origin );
877 xywnd->XY_SnapToGrid( origin );
878 Camera_setOrigin( camwnd, origin );
881 unsigned int OrientCamera_buttons(){
882 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
883 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
888 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
889 Vector3 point = g_vector3_identity;
890 xywnd->XY_ToPoint( x, y, point );
891 xywnd->XY_SnapToGrid( point );
892 vector3_subtract( point, Camera_getOrigin( camwnd ) );
894 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
895 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
896 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
897 if ( point[n1] || point[n2] ) {
898 Vector3 angles( Camera_getAngles( camwnd ) );
899 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
900 Camera_setAngles( camwnd, angles );
909 unsigned int NewBrushDrag_buttons(){
913 void XYWnd::NewBrushDrag_Begin( int x, int y ){
915 m_nNewBrushPressx = x;
916 m_nNewBrushPressy = y;
918 m_bNewBrushDrag = true;
919 GlobalUndoSystem().start();
922 void XYWnd::NewBrushDrag_End( int x, int y ){
923 if ( m_NewBrushDrag != 0 ) {
924 GlobalUndoSystem().finish( "brushDragNew" );
928 void XYWnd::NewBrushDrag( int x, int y ){
930 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
931 XY_SnapToGrid( mins );
932 XY_ToPoint( x, y, maxs );
933 XY_SnapToGrid( maxs );
935 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
937 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
938 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
940 if ( maxs[nDim] <= mins[nDim] ) {
941 maxs[nDim] = mins[nDim] + GetGridSize();
944 for ( int i = 0 ; i < 3 ; i++ )
946 if ( mins[i] == maxs[i] ) {
947 return; // don't create a degenerate brush
949 if ( mins[i] > maxs[i] ) {
950 float temp = mins[i];
956 if ( m_NewBrushDrag == 0 ) {
957 NodeSmartReference node( GlobalBrushCreator().createBrush() );
958 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
960 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
961 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
962 brushpath.push( makeReference( node.get() ) );
963 selectPath( brushpath, true );
965 m_NewBrushDrag = node.get_pointer();
969 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
970 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
971 g_brush_always_caulk ?
972 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
975 void entitycreate_activated( GtkWidget* item ){
976 scene::Node* world_node = Map_FindWorldspawn( g_map );
977 const char* entity_name = gtk_label_get_text( GTK_LABEL( GTK_BIN( item )->child ) );
979 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
980 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
983 GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( MainFrame_getWindow() ), "There's already a worldspawn in your map!"
991 void EntityClassMenu_addItem( GtkMenu* menu, const char* name ){
992 GtkMenuItem* item = GTK_MENU_ITEM( gtk_menu_item_new_with_label( name ) );
993 g_signal_connect( G_OBJECT( item ), "activate", G_CALLBACK( entitycreate_activated ), item );
994 gtk_widget_show( GTK_WIDGET( item ) );
995 menu_add_item( menu, item );
998 class EntityClassMenuInserter : public EntityClassVisitor
1000 typedef std::pair<GtkMenu*, CopiedString> MenuPair;
1001 typedef std::vector<MenuPair> MenuStack;
1003 CopiedString m_previous;
1005 EntityClassMenuInserter( GtkMenu* menu ){
1006 m_stack.reserve( 2 );
1007 m_stack.push_back( MenuPair( menu, "" ) );
1009 ~EntityClassMenuInserter(){
1010 if ( !string_empty( m_previous.c_str() ) ) {
1011 addItem( m_previous.c_str(), "" );
1014 void visit( EntityClass* e ){
1015 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1016 if ( !string_empty( m_previous.c_str() ) ) {
1017 addItem( m_previous.c_str(), e->name() );
1019 m_previous = e->name();
1021 void pushMenu( const CopiedString& name ){
1022 GtkMenuItem* item = GTK_MENU_ITEM( gtk_menu_item_new_with_label( name.c_str() ) );
1023 gtk_widget_show( GTK_WIDGET( item ) );
1024 container_add_widget( GTK_CONTAINER( m_stack.back().first ), GTK_WIDGET( item ) );
1026 GtkMenu* submenu = GTK_MENU( gtk_menu_new() );
1027 gtk_menu_item_set_submenu( item, GTK_WIDGET( submenu ) );
1029 m_stack.push_back( MenuPair( submenu, name ) );
1034 void addItem( const char* name, const char* next ){
1035 const char* underscore = strchr( name, '_' );
1037 if ( underscore != 0 && underscore != name ) {
1038 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1039 const char* parent = m_stack.back().second.c_str();
1041 if ( !string_empty( parent )
1042 && string_length( parent ) == std::size_t( underscore - name )
1043 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1045 else if ( nextEqual ) {
1046 if ( m_stack.size() == 2 ) {
1049 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1051 else if ( m_stack.size() == 2 ) {
1055 else if ( m_stack.size() == 2 ) {
1059 EntityClassMenu_addItem( m_stack.back().first, name );
1063 void XYWnd::OnContextMenu(){
1064 if ( g_xywindow_globals.m_bRightClick == false ) {
1068 if ( m_mnuDrop == 0 ) { // first time, load it up
1069 GtkMenu* menu = m_mnuDrop = GTK_MENU( gtk_menu_new() );
1071 EntityClassMenuInserter inserter( menu );
1072 GlobalEntityClassManager().forEach( inserter );
1075 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1078 FreezePointer g_xywnd_freezePointer;
1080 unsigned int Move_buttons(){
1084 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1085 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1086 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1089 gboolean XYWnd_Move_focusOut( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
1094 void XYWnd::Move_Begin(){
1095 if ( m_move_started ) {
1098 m_move_started = true;
1099 g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this );
1100 m_move_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1103 void XYWnd::Move_End(){
1104 m_move_started = false;
1105 g_xywnd_freezePointer.unfreeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow() );
1106 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1109 unsigned int Zoom_buttons(){
1110 return RAD_RBUTTON | RAD_SHIFT;
1115 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1119 while ( abs( g_dragZoom ) > 8 )
1121 if ( g_dragZoom > 0 ) {
1122 XYWnd_ZoomOut( reinterpret_cast<XYWnd*>( data ) );
1127 XYWnd_ZoomIn( reinterpret_cast<XYWnd*>( data ) );
1134 gboolean XYWnd_Zoom_focusOut( GtkWidget* widget, GdkEventFocus* event, XYWnd* xywnd ){
1139 void XYWnd::Zoom_Begin(){
1140 if ( m_zoom_started ) {
1143 m_zoom_started = true;
1145 g_xywnd_freezePointer.freeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
1146 m_zoom_focusOut = g_signal_connect( G_OBJECT( m_gl_widget ), "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1149 void XYWnd::Zoom_End(){
1150 m_zoom_started = false;
1151 g_xywnd_freezePointer.unfreeze_pointer( m_parent != 0 ? m_parent : MainFrame_getWindow() );
1152 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1155 // makes sure the selected brush or camera is in view
1156 void XYWnd::PositionView( const Vector3& position ){
1157 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1158 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1160 m_vOrigin[nDim1] = position[nDim1];
1161 m_vOrigin[nDim2] = position[nDim2];
1165 XYWnd_Update( *this );
1168 void XYWnd::SetViewType( VIEWTYPE viewType ){
1169 m_viewType = viewType;
1172 if ( m_parent != 0 ) {
1173 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1178 inline WindowVector WindowVector_forInteger( int x, int y ){
1179 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1182 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1183 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1185 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1186 if ( buttons == Move_buttons() ) {
1188 EntityCreate_MouseDown( x, y );
1190 else if ( buttons == Zoom_buttons() ) {
1193 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1194 Clipper_OnLButtonDown( x, y );
1196 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1197 NewBrushDrag_Begin( x, y );
1199 // control mbutton = move camera
1200 else if ( buttons == MoveCamera_buttons() ) {
1201 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1203 // mbutton = angle camera
1204 else if ( buttons == OrientCamera_buttons() ) {
1205 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1209 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1213 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1214 if ( m_move_started ) {
1216 EntityCreate_MouseUp( x, y );
1218 else if ( m_zoom_started ) {
1221 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1222 Clipper_OnLButtonUp( x, y );
1224 else if ( m_bNewBrushDrag ) {
1225 m_bNewBrushDrag = false;
1226 NewBrushDrag_End( x, y );
1230 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1234 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1235 // rbutton = drag xy origin
1236 if ( m_move_started ) {
1239 else if ( m_zoom_started ) {
1242 else if ( ClipMode() && g_pMovingClip != 0 ) {
1243 Clipper_OnMouseMoved( x, y );
1245 // lbutton without selection = drag new brush
1246 else if ( m_bNewBrushDrag ) {
1247 NewBrushDrag( x, y );
1250 // control mbutton = move camera
1251 else if ( getButtonState() == MoveCamera_buttons() ) {
1252 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1255 // mbutton = angle camera
1256 else if ( getButtonState() == OrientCamera_buttons() ) {
1257 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1262 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1264 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1265 XY_ToPoint( x, y, m_mousePosition );
1266 XY_SnapToGrid( m_mousePosition );
1268 StringOutputStream status( 64 );
1269 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1270 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1271 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1272 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1274 if ( g_bCrossHairs ) {
1275 XYWnd_Update( *this );
1278 Clipper_Crosshair_OnMouseMoved( x, y );
1282 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1283 m_entityCreate = true;
1284 m_entityCreate_x = x;
1285 m_entityCreate_y = y;
1288 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1289 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1290 m_entityCreate = false;
1294 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1295 if ( m_entityCreate ) {
1296 m_entityCreate = false;
1301 inline float screen_normalised( int pos, unsigned int size ){
1302 return ( ( 2.0f * pos ) / size ) - 1.0f;
1305 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1306 return world_origin + normalised * normalised2world_scale;
1310 // TTimo: watch it, this doesn't init one of the 3 coords
1311 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1312 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1313 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1314 if ( m_viewType == XY ) {
1315 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1316 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1318 else if ( m_viewType == YZ ) {
1319 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1320 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1324 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1325 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1329 void XYWnd::XY_SnapToGrid( Vector3& point ){
1330 if ( m_viewType == XY ) {
1331 point[0] = float_snapped( point[0], GetSnapGridSize() );
1332 point[1] = float_snapped( point[1], GetSnapGridSize() );
1334 else if ( m_viewType == YZ ) {
1335 point[1] = float_snapped( point[1], GetSnapGridSize() );
1336 point[2] = float_snapped( point[2], GetSnapGridSize() );
1340 point[0] = float_snapped( point[0], GetSnapGridSize() );
1341 point[2] = float_snapped( point[2], GetSnapGridSize() );
1345 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1346 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1347 if ( relative == name ) {
1348 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1351 char fileNameWithoutExt[512];
1352 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1353 fileNameWithoutExt[512 - 1] = '\0';
1354 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1356 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1358 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1361 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1362 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1363 globalOutputStream() << "Loaded background texture " << relative << "\n";
1364 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1367 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1384 Select_GetBounds( min, max );
1385 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1386 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1387 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1388 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1391 void XYWnd::XY_DisableBackground( void ){
1392 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1393 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1394 free( g_pParentWnd->ActiveXY()->m_tex );
1396 g_pParentWnd->ActiveXY()->m_tex = NULL;
1399 void WXY_BackgroundSelect( void ){
1400 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1401 if ( !brushesSelected ) {
1402 gtk_MessageBox( 0, "You have to select some brushes to get the bounding box for.\n",
1403 "No selection", eMB_OK, eMB_ICONERROR );
1407 const char *filename = file_dialog( GTK_WIDGET( MainFrame_getWindow() ), TRUE, "Background Image", NULL, NULL );
1408 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1410 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1415 ============================================================================
1419 ============================================================================
1428 double two_to_the_power( int power ){
1429 return pow( 2.0f, power );
1432 void XYWnd::XY_DrawAxis( void ){
1433 if ( g_xywindow_globals_private.show_axis ) {
1434 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1435 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1436 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1437 const int w = ( m_nWidth / 2 / m_fScale );
1438 const int h = ( m_nHeight / 2 / m_fScale );
1440 const Vector3& colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1441 const Vector3& colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1443 // draw two lines with corresponding axis colors to highlight current view
1444 // horizontal line: nDim1 color
1446 glBegin( GL_LINES );
1447 glColor3fv( vector3_to_array( colourX ) );
1448 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1449 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1451 glVertex2f( 32 / m_fScale, 0 );
1452 glColor3fv( vector3_to_array( colourY ) );
1453 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1454 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1456 glVertex2f( 0, 32 / m_fScale );
1459 // now print axis symbols
1460 glColor3fv( vector3_to_array( colourX ) );
1461 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1462 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1463 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1464 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1465 glColor3fv( vector3_to_array( colourY ) );
1466 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1467 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1468 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1469 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1473 void XYWnd::XY_DrawBackground( void ){
1474 glPushAttrib( GL_ALL_ATTRIB_BITS );
1476 glEnable( GL_TEXTURE_2D );
1477 glEnable( GL_BLEND );
1478 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1479 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1480 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1481 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1483 glPolygonMode( GL_FRONT, GL_FILL );
1485 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1486 glBegin( GL_QUADS );
1488 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1489 glTexCoord2f( 0.0, 1.0 );
1490 glVertex2f( m_xmin, m_ymin );
1492 glTexCoord2f( 1.0, 1.0 );
1493 glVertex2f( m_xmax, m_ymin );
1495 glTexCoord2f( 1.0, 0.0 );
1496 glVertex2f( m_xmax, m_ymax );
1498 glTexCoord2f( 0.0, 0.0 );
1499 glVertex2f( m_xmin, m_ymax );
1502 glBindTexture( GL_TEXTURE_2D, 0 );
1507 void XYWnd::XY_DrawGrid( void ) {
1508 float x, y, xb, xe, yb, ye;
1511 float step, minor_step, stepx, stepy;
1512 step = minor_step = stepx = stepy = GetGridSize();
1514 int minor_power = Grid_getPower();
1517 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1521 int power = minor_power;
1522 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1524 step = float(two_to_the_power( power ) );
1526 mask = ( 1 << ( power - minor_power ) ) - 1;
1527 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1529 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1532 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1534 glDisable( GL_TEXTURE_2D );
1535 glDisable( GL_TEXTURE_1D );
1536 glDisable( GL_DEPTH_TEST );
1537 glDisable( GL_BLEND );
1540 w = ( m_nWidth / 2 / m_fScale );
1541 h = ( m_nHeight / 2 / m_fScale );
1543 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1544 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1546 xb = m_vOrigin[nDim1] - w;
1547 if ( xb < region_mins[nDim1] ) {
1548 xb = region_mins[nDim1];
1550 xb = step * floor( xb / step );
1552 xe = m_vOrigin[nDim1] + w;
1553 if ( xe > region_maxs[nDim1] ) {
1554 xe = region_maxs[nDim1];
1556 xe = step * ceil( xe / step );
1558 yb = m_vOrigin[nDim2] - h;
1559 if ( yb < region_mins[nDim2] ) {
1560 yb = region_mins[nDim2];
1562 yb = step * floor( yb / step );
1564 ye = m_vOrigin[nDim2] + h;
1565 if ( ye > region_maxs[nDim2] ) {
1566 ye = region_maxs[nDim2];
1568 ye = step * ceil( ye / step );
1570 #define COLORS_DIFFER( a,b ) \
1571 ( ( a )[0] != ( b )[0] || \
1572 ( a )[1] != ( b )[1] || \
1573 ( a )[2] != ( b )[2] )
1576 // draw minor blocks
1577 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1579 glEnable( GL_BLEND );
1582 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1583 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1585 glBegin( GL_LINES );
1587 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1588 if ( ( i & mask ) != 0 ) {
1589 glVertex2f( x, yb );
1590 glVertex2f( x, ye );
1594 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1595 if ( ( i & mask ) != 0 ) {
1596 glVertex2f( xb, y );
1597 glVertex2f( xe, y );
1603 // draw major blocks
1604 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1605 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1607 glBegin( GL_LINES );
1608 for ( x = xb ; x <= xe ; x += step ) {
1609 glVertex2f( x, yb );
1610 glVertex2f( x, ye );
1612 for ( y = yb ; y <= ye ; y += step ) {
1613 glVertex2f( xb, y );
1614 glVertex2f( xe, y );
1620 glDisable( GL_BLEND );
1624 // draw coordinate text if needed
1625 if ( g_xywindow_globals_private.show_coordinates ) {
1626 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1627 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1628 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1629 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1630 glRasterPos2f( x, offx );
1631 sprintf( text, "%g", x );
1632 GlobalOpenGL().drawString( text );
1634 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1635 glRasterPos2f( offy, y );
1636 sprintf( text, "%g", y );
1637 GlobalOpenGL().drawString( text );
1641 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1644 // we do this part (the old way) only if show_axis is disabled
1645 if ( !g_xywindow_globals_private.show_axis ) {
1646 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1648 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1652 XYWnd::XY_DrawAxis();
1654 // show current work zone?
1655 // the work zone is used to place dropped points and brushes
1656 if ( g_xywindow_globals_private.d_show_work ) {
1657 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1658 glBegin( GL_LINES );
1659 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1660 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1661 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1662 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1663 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1664 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1665 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1666 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1676 void XYWnd::XY_DrawBlockGrid(){
1677 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1680 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1681 if ( strlen( value ) ) {
1682 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1685 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1686 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1687 g_xywindow_globals_private.blockSize = 1024;
1690 float x, y, xb, xe, yb, ye;
1694 glDisable( GL_TEXTURE_2D );
1695 glDisable( GL_TEXTURE_1D );
1696 glDisable( GL_DEPTH_TEST );
1697 glDisable( GL_BLEND );
1699 w = ( m_nWidth / 2 / m_fScale );
1700 h = ( m_nHeight / 2 / m_fScale );
1702 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1703 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1705 xb = m_vOrigin[nDim1] - w;
1706 if ( xb < region_mins[nDim1] ) {
1707 xb = region_mins[nDim1];
1709 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
1711 xe = m_vOrigin[nDim1] + w;
1712 if ( xe > region_maxs[nDim1] ) {
1713 xe = region_maxs[nDim1];
1715 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
1717 yb = m_vOrigin[nDim2] - h;
1718 if ( yb < region_mins[nDim2] ) {
1719 yb = region_mins[nDim2];
1721 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
1723 ye = m_vOrigin[nDim2] + h;
1724 if ( ye > region_maxs[nDim2] ) {
1725 ye = region_maxs[nDim2];
1727 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
1729 // draw major blocks
1731 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
1734 glBegin( GL_LINES );
1736 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
1738 glVertex2f( x, yb );
1739 glVertex2f( x, ye );
1742 if ( m_viewType == XY ) {
1743 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
1745 glVertex2f( xb, y );
1746 glVertex2f( xe, y );
1753 // draw coordinate text if needed
1755 if ( m_viewType == XY && m_fScale > .1 ) {
1756 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
1757 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
1759 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
1760 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
1761 GlobalOpenGL().drawString( text );
1765 glColor4f( 0, 0, 0, 0 );
1768 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
1769 float x, y, fov, box;
1772 fov = 48 / m_fScale;
1773 box = 16 / m_fScale;
1775 if ( m_viewType == XY ) {
1778 a = degrees_to_radians( angles[CAMERA_YAW] );
1780 else if ( m_viewType == YZ ) {
1783 a = degrees_to_radians( angles[CAMERA_PITCH] );
1789 a = degrees_to_radians( angles[CAMERA_PITCH] );
1792 glColor3f( 0.0, 0.0, 1.0 );
1793 glBegin( GL_LINE_STRIP );
1794 glVertex3f( x - box,y,0 );
1795 glVertex3f( x,y + ( box / 2 ),0 );
1796 glVertex3f( x + box,y,0 );
1797 glVertex3f( x,y - ( box / 2 ),0 );
1798 glVertex3f( x - box,y,0 );
1799 glVertex3f( x + box,y,0 );
1802 glBegin( GL_LINE_STRIP );
1803 glVertex3f( x + static_cast<float>( fov * cos( a + c_pi / 4 ) ), y + static_cast<float>( fov * sin( a + c_pi / 4 ) ), 0 );
1804 glVertex3f( x, y, 0 );
1805 glVertex3f( x + static_cast<float>( fov * cos( a - c_pi / 4 ) ), y + static_cast<float>( fov * sin( a - c_pi / 4 ) ), 0 );
1811 float Betwixt( float f1, float f2 ){
1813 return f2 + ( ( f1 - f2 ) / 2 );
1816 return f1 + ( ( f2 - f1 ) / 2 );
1821 // can be greatly simplified but per usual i am in a hurry
1822 // which is not an excuse, just a fact
1823 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
1824 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
1827 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1828 typedef const char* OrgStrings[2];
1829 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1831 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
1833 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
1834 g_xywindow_globals.color_selbrushes[1] * .65f,
1835 g_xywindow_globals.color_selbrushes[2] * .65f );
1837 StringOutputStream dimensions( 16 );
1839 if ( m_viewType == XY ) {
1840 glBegin( GL_LINES );
1842 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1843 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1845 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1846 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1848 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1849 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1852 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1853 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1855 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1856 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1858 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1859 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1863 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
1864 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1865 GlobalOpenGL().drawString( dimensions.c_str() );
1868 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
1869 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1870 GlobalOpenGL().drawString( dimensions.c_str() );
1873 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
1874 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
1875 GlobalOpenGL().drawString( dimensions.c_str() );
1877 else if ( m_viewType == XZ ) {
1878 glBegin( GL_LINES );
1880 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
1881 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
1883 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1884 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1886 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
1887 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1890 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
1891 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
1893 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
1894 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
1896 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
1897 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
1901 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
1902 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1903 GlobalOpenGL().drawString( dimensions.c_str() );
1906 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
1907 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1908 GlobalOpenGL().drawString( dimensions.c_str() );
1911 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
1912 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
1913 GlobalOpenGL().drawString( dimensions.c_str() );
1917 glBegin( GL_LINES );
1919 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
1920 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
1922 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
1923 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
1925 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
1926 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
1929 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
1930 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
1932 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
1933 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
1935 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
1936 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
1940 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
1941 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1942 GlobalOpenGL().drawString( dimensions.c_str() );
1945 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
1946 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1947 GlobalOpenGL().drawString( dimensions.c_str() );
1950 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
1951 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
1952 GlobalOpenGL().drawString( dimensions.c_str() );
1956 class XYRenderer : public Renderer
1964 unsigned int m_highlight;
1968 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
1969 m_globalstate( globalstate ),
1970 m_state_selected( selected ){
1971 ASSERT_NOTNULL( selected );
1972 m_state_stack.push_back( state_type() );
1975 void SetState( Shader* state, EStyle style ){
1976 ASSERT_NOTNULL( state );
1977 if ( style == eWireframeOnly ) {
1978 m_state_stack.back().m_state = state;
1981 const EStyle getStyle() const {
1982 return eWireframeOnly;
1985 m_state_stack.push_back( m_state_stack.back() );
1988 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
1989 m_state_stack.pop_back();
1991 void Highlight( EHighlightMode mode, bool bEnable = true ){
1993 ? m_state_stack.back().m_highlight |= mode
1994 : m_state_stack.back().m_highlight &= ~mode;
1996 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
1997 if ( m_state_stack.back().m_highlight & ePrimitive ) {
1998 m_state_selected->addRenderable( renderable, localToWorld );
2002 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2006 void render( const Matrix4& modelview, const Matrix4& projection ){
2007 GlobalShaderCache().render( m_globalstate, modelview, projection );
2010 std::vector<state_type> m_state_stack;
2011 RenderStateFlags m_globalstate;
2012 Shader* m_state_selected;
2015 void XYWnd::updateProjection(){
2016 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2017 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2018 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2020 m_projection[12] = 0.0f;
2021 m_projection[13] = 0.0f;
2022 m_projection[14] = -1.0f;
2034 m_projection[11] = 0.0f;
2036 m_projection[15] = 1.0f;
2038 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2041 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2042 void XYWnd::updateModelview(){
2043 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2044 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2047 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2048 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2049 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2052 switch ( m_viewType )
2055 m_modelview[0] = m_fScale;
2060 m_modelview[5] = m_fScale;
2065 m_modelview[10] = -m_fScale;
2068 m_modelview[0] = m_fScale;
2074 m_modelview[6] = m_fScale;
2077 m_modelview[9] = m_fScale;
2078 m_modelview[10] = 0;
2083 m_modelview[2] = -m_fScale;
2085 m_modelview[4] = m_fScale;
2090 m_modelview[9] = m_fScale;
2091 m_modelview[10] = 0;
2095 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2096 m_modelview[15] = 1;
2098 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2107 //#define DBG_SCENEDUMP
2109 void XYWnd::XY_Draw(){
2113 glViewport( 0, 0, m_nWidth, m_nHeight );
2114 glClearColor( g_xywindow_globals.color_gridback[0],
2115 g_xywindow_globals.color_gridback[1],
2116 g_xywindow_globals.color_gridback[2],0 );
2118 glClear( GL_COLOR_BUFFER_BIT );
2124 glMatrixMode( GL_PROJECTION );
2125 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2127 glMatrixMode( GL_MODELVIEW );
2129 glScalef( m_fScale, m_fScale, 1 );
2130 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2131 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2132 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2134 glDisable( GL_LINE_STIPPLE );
2136 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2137 glDisableClientState( GL_NORMAL_ARRAY );
2138 glDisableClientState( GL_COLOR_ARRAY );
2139 glDisable( GL_TEXTURE_2D );
2140 glDisable( GL_LIGHTING );
2141 glDisable( GL_COLOR_MATERIAL );
2142 glDisable( GL_DEPTH_TEST );
2144 if ( m_backgroundActivated ) {
2145 XY_DrawBackground();
2149 if ( g_xywindow_globals_private.show_blocks ) {
2153 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2155 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2156 if ( !g_xywindow_globals.m_bNoStipple ) {
2157 globalstate |= RENDER_LINESTIPPLE;
2161 XYRenderer renderer( globalstate, m_state_selected );
2163 Scene_Render( renderer, m_view );
2165 GlobalOpenGL_debugAssertNoErrors();
2166 renderer.render( m_modelview, m_projection );
2167 GlobalOpenGL_debugAssertNoErrors();
2170 glDepthMask( GL_FALSE );
2172 GlobalOpenGL_debugAssertNoErrors();
2174 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2176 GlobalOpenGL_debugAssertNoErrors();
2177 glDisable( GL_LINE_STIPPLE );
2178 GlobalOpenGL_debugAssertNoErrors();
2180 GlobalOpenGL_debugAssertNoErrors();
2181 if ( GlobalOpenGL().GL_1_3() ) {
2182 glActiveTexture( GL_TEXTURE0 );
2183 glClientActiveTexture( GL_TEXTURE0 );
2185 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2186 GlobalOpenGL_debugAssertNoErrors();
2187 glDisableClientState( GL_NORMAL_ARRAY );
2188 GlobalOpenGL_debugAssertNoErrors();
2189 glDisableClientState( GL_COLOR_ARRAY );
2190 GlobalOpenGL_debugAssertNoErrors();
2191 glDisable( GL_TEXTURE_2D );
2192 GlobalOpenGL_debugAssertNoErrors();
2193 glDisable( GL_LIGHTING );
2194 GlobalOpenGL_debugAssertNoErrors();
2195 glDisable( GL_COLOR_MATERIAL );
2196 GlobalOpenGL_debugAssertNoErrors();
2198 GlobalOpenGL_debugAssertNoErrors();
2202 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2204 Select_GetBounds( min, max );
2205 PaintSizeInfo( nDim1, nDim2, min, max );
2208 if ( g_bCrossHairs ) {
2209 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2210 glBegin( GL_LINES );
2211 if ( m_viewType == XY ) {
2212 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2213 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2214 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2215 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2217 else if ( m_viewType == YZ ) {
2218 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2219 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2220 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2221 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2225 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2226 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2227 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2228 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2234 GlobalClipPoints_Draw( m_fScale );
2237 GlobalOpenGL_debugAssertNoErrors();
2241 glScalef( m_fScale, m_fScale, 1 );
2242 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2244 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2246 Feedback_draw2D( m_viewType );
2248 if ( g_xywindow_globals_private.show_outline ) {
2250 glMatrixMode( GL_PROJECTION );
2252 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2254 glMatrixMode( GL_MODELVIEW );
2257 // four view mode doesn't colorize
2258 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2259 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2263 switch ( m_viewType )
2266 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2269 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2272 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2276 glBegin( GL_LINE_LOOP );
2277 glVertex2f( 0.5, 0.5 );
2278 glVertex2f( m_nWidth - 0.5, 1 );
2279 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2280 glVertex2f( 0.5, m_nHeight - 0.5 );
2285 GlobalOpenGL_debugAssertNoErrors();
2290 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2291 xywnd->XY_ToPoint( x, y, point );
2292 xywnd->XY_SnapToGrid( point );
2294 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2295 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2296 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2299 void XYWnd::OnEntityCreate( const char* item ){
2300 StringOutputStream command;
2301 command << "entityCreate -class " << item;
2302 UndoableCommand undo( command.c_str() );
2304 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2305 Entity_createFromSelection( item, point );
2310 void GetFocusPosition( Vector3& position ){
2311 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2312 Select_GetMid( position );
2316 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2320 void XYWnd_Focus( XYWnd* xywnd ){
2322 GetFocusPosition( position );
2323 xywnd->PositionView( position );
2326 void XY_Split_Focus(){
2328 GetFocusPosition( position );
2329 if ( g_pParentWnd->GetXYWnd() ) {
2330 g_pParentWnd->GetXYWnd()->PositionView( position );
2332 if ( g_pParentWnd->GetXZWnd() ) {
2333 g_pParentWnd->GetXZWnd()->PositionView( position );
2335 if ( g_pParentWnd->GetYZWnd() ) {
2336 g_pParentWnd->GetYZWnd()->PositionView( position );
2341 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2342 // cannot do this in a split window
2343 // do something else that the user may want here
2348 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2349 XYWnd_Focus( xywnd );
2353 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2354 // cannot do this in a split window
2355 // do something else that the user may want here
2360 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2361 xywnd->SetViewType( XY );
2362 XYWnd_Focus( xywnd );
2366 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2367 // cannot do this in a split window
2368 // do something else that the user may want here
2373 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2374 xywnd->SetViewType( XZ );
2375 XYWnd_Focus( xywnd );
2379 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2380 // cannot do this in a split window
2381 // do something else that the user may want here
2386 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2387 xywnd->SetViewType( YZ );
2388 XYWnd_Focus( xywnd );
2392 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2393 // cannot do this in a split window
2394 // do something else that the user may want here
2399 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2400 if ( xywnd->GetViewType() == XY ) {
2401 xywnd->SetViewType( XZ );
2403 else if ( xywnd->GetViewType() == XZ ) {
2404 xywnd->SetViewType( YZ );
2407 xywnd->SetViewType( XY );
2409 XYWnd_Focus( xywnd );
2413 if ( g_pParentWnd->GetXYWnd() ) {
2414 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2416 if ( g_pParentWnd->GetXZWnd() ) {
2417 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2419 if ( g_pParentWnd->GetYZWnd() ) {
2420 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2425 XYWnd_ZoomIn( g_pParentWnd->ActiveXY() );
2428 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2429 // we don't go below a zoom factor corresponding to 10% of the max world size
2430 // (this has to be computed against the window size)
2432 XYWnd_ZoomOut( g_pParentWnd->ActiveXY() );
2437 void ToggleShowCrosshair(){
2439 XY_UpdateAllWindows();
2442 void ToggleShowSizeInfo(){
2443 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2444 XY_UpdateAllWindows();
2447 void ToggleShowGrid(){
2448 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2449 XY_UpdateAllWindows();
2452 ToggleShown g_xy_top_shown( true );
2454 void XY_Top_Shown_Construct( GtkWindow* parent ){
2455 g_xy_top_shown.connect( GTK_WIDGET( parent ) );
2458 ToggleShown g_yz_side_shown( false );
2460 void YZ_Side_Shown_Construct( GtkWindow* parent ){
2461 g_yz_side_shown.connect( GTK_WIDGET( parent ) );
2464 ToggleShown g_xz_front_shown( false );
2466 void XZ_Front_Shown_Construct( GtkWindow* parent ){
2467 g_xz_front_shown.connect( GTK_WIDGET( parent ) );
2471 class EntityClassMenu : public ModuleObserver
2473 std::size_t m_unrealised;
2475 EntityClassMenu() : m_unrealised( 1 ){
2478 if ( --m_unrealised == 0 ) {
2482 if ( ++m_unrealised == 1 ) {
2483 if ( XYWnd::m_mnuDrop != 0 ) {
2484 gtk_widget_destroy( GTK_WIDGET( XYWnd::m_mnuDrop ) );
2485 XYWnd::m_mnuDrop = 0;
2491 EntityClassMenu g_EntityClassMenu;
2496 void ShowNamesToggle(){
2497 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2498 XY_UpdateAllWindows();
2500 typedef FreeCaller<ShowNamesToggle> ShowNamesToggleCaller;
2501 void ShowNamesExport( const BoolImportCallback& importer ){
2502 importer( GlobalEntityCreator().getShowNames() );
2504 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2506 void ShowAnglesToggle(){
2507 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2508 XY_UpdateAllWindows();
2510 typedef FreeCaller<ShowAnglesToggle> ShowAnglesToggleCaller;
2511 void ShowAnglesExport( const BoolImportCallback& importer ){
2512 importer( GlobalEntityCreator().getShowAngles() );
2514 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2516 void ShowBlocksToggle(){
2517 g_xywindow_globals_private.show_blocks ^= 1;
2518 XY_UpdateAllWindows();
2520 typedef FreeCaller<ShowBlocksToggle> ShowBlocksToggleCaller;
2521 void ShowBlocksExport( const BoolImportCallback& importer ){
2522 importer( g_xywindow_globals_private.show_blocks );
2524 typedef FreeCaller1<const BoolImportCallback&, ShowBlocksExport> ShowBlocksExportCaller;
2526 void ShowCoordinatesToggle(){
2527 g_xywindow_globals_private.show_coordinates ^= 1;
2528 XY_UpdateAllWindows();
2530 typedef FreeCaller<ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2531 void ShowCoordinatesExport( const BoolImportCallback& importer ){
2532 importer( g_xywindow_globals_private.show_coordinates );
2534 typedef FreeCaller1<const BoolImportCallback&, ShowCoordinatesExport> ShowCoordinatesExportCaller;
2536 void ShowOutlineToggle(){
2537 g_xywindow_globals_private.show_outline ^= 1;
2538 XY_UpdateAllWindows();
2540 typedef FreeCaller<ShowOutlineToggle> ShowOutlineToggleCaller;
2541 void ShowOutlineExport( const BoolImportCallback& importer ){
2542 importer( g_xywindow_globals_private.show_outline );
2544 typedef FreeCaller1<const BoolImportCallback&, ShowOutlineExport> ShowOutlineExportCaller;
2546 void ShowAxesToggle(){
2547 g_xywindow_globals_private.show_axis ^= 1;
2548 XY_UpdateAllWindows();
2550 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2551 void ShowAxesExport( const BoolImportCallback& importer ){
2552 importer( g_xywindow_globals_private.show_axis );
2554 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2556 void ShowWorkzoneToggle(){
2557 g_xywindow_globals_private.d_show_work ^= 1;
2558 XY_UpdateAllWindows();
2560 typedef FreeCaller<ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2561 void ShowWorkzoneExport( const BoolImportCallback& importer ){
2562 importer( g_xywindow_globals_private.d_show_work );
2564 typedef FreeCaller1<const BoolImportCallback&, ShowWorkzoneExport> ShowWorkzoneExportCaller;
2566 ShowNamesExportCaller g_show_names_caller;
2567 BoolExportCallback g_show_names_callback( g_show_names_caller );
2568 ToggleItem g_show_names( g_show_names_callback );
2570 ShowAnglesExportCaller g_show_angles_caller;
2571 BoolExportCallback g_show_angles_callback( g_show_angles_caller );
2572 ToggleItem g_show_angles( g_show_angles_callback );
2574 ShowBlocksExportCaller g_show_blocks_caller;
2575 BoolExportCallback g_show_blocks_callback( g_show_blocks_caller );
2576 ToggleItem g_show_blocks( g_show_blocks_callback );
2578 ShowCoordinatesExportCaller g_show_coordinates_caller;
2579 BoolExportCallback g_show_coordinates_callback( g_show_coordinates_caller );
2580 ToggleItem g_show_coordinates( g_show_coordinates_callback );
2582 ShowOutlineExportCaller g_show_outline_caller;
2583 BoolExportCallback g_show_outline_callback( g_show_outline_caller );
2584 ToggleItem g_show_outline( g_show_outline_callback );
2586 ShowAxesExportCaller g_show_axes_caller;
2587 BoolExportCallback g_show_axes_callback( g_show_axes_caller );
2588 ToggleItem g_show_axes( g_show_axes_callback );
2590 ShowWorkzoneExportCaller g_show_workzone_caller;
2591 BoolExportCallback g_show_workzone_callback( g_show_workzone_caller );
2592 ToggleItem g_show_workzone( g_show_workzone_callback );
2594 void XYShow_registerCommands(){
2595 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2596 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
2597 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2598 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2599 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2600 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2601 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2604 void XYWnd_registerShortcuts(){
2605 command_connect_accelerator( "ToggleCrosshairs" );
2606 command_connect_accelerator( "ToggleSizePaint" );
2611 void Orthographic_constructPreferences( PreferencesPage& page ){
2612 page.appendCheckBox( "", "Solid selection boxes", g_xywindow_globals.m_bNoStipple );
2613 page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2614 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2615 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2617 void Orthographic_constructPage( PreferenceGroup& group ){
2618 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
2619 Orthographic_constructPreferences( page );
2621 void Orthographic_registerPreferencesPage(){
2622 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Orthographic_constructPage>() );
2625 void Clipper_constructPreferences( PreferencesPage& page ){
2626 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
2628 void Clipper_constructPage( PreferenceGroup& group ){
2629 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
2630 Clipper_constructPreferences( page );
2632 void Clipper_registerPreferencesPage(){
2633 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Clipper_constructPage>() );
2637 #include "preferencesystem.h"
2638 #include "stringio.h"
2643 void ToggleShown_importBool( ToggleShown& self, bool value ){
2646 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
2647 void ToggleShown_exportBool( const ToggleShown& self, const BoolImportCallback& importer ){
2648 importer( self.active() );
2650 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
2653 void XYWindow_Construct(){
2654 GlobalCommands_insert( "ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2655 GlobalCommands_insert( "ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator( 'J' ) );
2656 GlobalCommands_insert( "ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator( '0' ) );
2658 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 ) ) );
2659 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
2660 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
2661 GlobalCommands_insert( "NextView", FreeCaller<XY_Next>(), Accelerator( GDK_Tab, (GdkModifierType)GDK_CONTROL_MASK ) );
2662 GlobalCommands_insert( "ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator( GDK_Delete ) );
2663 GlobalCommands_insert( "ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator( GDK_Insert ) );
2664 GlobalCommands_insert( "ViewTop", FreeCaller<XY_Top>(), Accelerator( GDK_KP_Home ) );
2665 GlobalCommands_insert( "ViewSide", FreeCaller<XY_Side>(), Accelerator( GDK_KP_Page_Down ) );
2666 GlobalCommands_insert( "ViewFront", FreeCaller<XY_Front>(), Accelerator( GDK_KP_End ) );
2667 GlobalCommands_insert( "Zoom100", FreeCaller<XY_Zoom100>() );
2668 GlobalCommands_insert( "CenterXYView", FreeCaller<XY_Focus>(), Accelerator( GDK_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
2670 GlobalPreferenceSystem().registerPreference( "ClipCaulk", BoolImportStringCaller( g_clip_useCaulk ), BoolExportStringCaller( g_clip_useCaulk ) );
2672 GlobalPreferenceSystem().registerPreference( "NewRightClick", BoolImportStringCaller( g_xywindow_globals.m_bRightClick ), BoolExportStringCaller( g_xywindow_globals.m_bRightClick ) );
2673 GlobalPreferenceSystem().registerPreference( "ChaseMouse", BoolImportStringCaller( g_xywindow_globals_private.m_bChaseMouse ), BoolExportStringCaller( g_xywindow_globals_private.m_bChaseMouse ) );
2674 GlobalPreferenceSystem().registerPreference( "SizePainting", BoolImportStringCaller( g_xywindow_globals_private.m_bSizePaint ), BoolExportStringCaller( g_xywindow_globals_private.m_bSizePaint ) );
2675 GlobalPreferenceSystem().registerPreference( "NoStipple", BoolImportStringCaller( g_xywindow_globals.m_bNoStipple ), BoolExportStringCaller( g_xywindow_globals.m_bNoStipple ) );
2676 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", BoolImportStringCaller( g_xywindow_globals_private.show_coordinates ), BoolExportStringCaller( g_xywindow_globals_private.show_coordinates ) );
2677 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", BoolImportStringCaller( g_xywindow_globals_private.show_outline ), BoolExportStringCaller( g_xywindow_globals_private.show_outline ) );
2678 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", BoolImportStringCaller( g_xywindow_globals_private.show_axis ), BoolExportStringCaller( g_xywindow_globals_private.show_axis ) );
2679 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", BoolImportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ), BoolExportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ) );
2680 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", BoolImportStringCaller( g_xywindow_globals_private.d_show_work ), BoolExportStringCaller( g_xywindow_globals_private.d_show_work ) );
2682 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", Vector3ImportStringCaller( g_xywindow_globals.AxisColorX ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorX ) );
2683 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", Vector3ImportStringCaller( g_xywindow_globals.AxisColorY ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorY ) );
2684 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", Vector3ImportStringCaller( g_xywindow_globals.AxisColorZ ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorZ ) );
2685 GlobalPreferenceSystem().registerPreference( "SI_Colors1", Vector3ImportStringCaller( g_xywindow_globals.color_gridback ), Vector3ExportStringCaller( g_xywindow_globals.color_gridback ) );
2686 GlobalPreferenceSystem().registerPreference( "SI_Colors2", Vector3ImportStringCaller( g_xywindow_globals.color_gridminor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridminor ) );
2687 GlobalPreferenceSystem().registerPreference( "SI_Colors3", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor ) );
2688 GlobalPreferenceSystem().registerPreference( "SI_Colors6", Vector3ImportStringCaller( g_xywindow_globals.color_gridblock ), Vector3ExportStringCaller( g_xywindow_globals.color_gridblock ) );
2689 GlobalPreferenceSystem().registerPreference( "SI_Colors7", Vector3ImportStringCaller( g_xywindow_globals.color_gridtext ), Vector3ExportStringCaller( g_xywindow_globals.color_gridtext ) );
2690 GlobalPreferenceSystem().registerPreference( "SI_Colors8", Vector3ImportStringCaller( g_xywindow_globals.color_brushes ), Vector3ExportStringCaller( g_xywindow_globals.color_brushes ) );
2691 GlobalPreferenceSystem().registerPreference( "SI_Colors14", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor_alt ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor_alt ) );
2694 GlobalPreferenceSystem().registerPreference( "XZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_xz_front_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_xz_front_shown ) ) );
2695 GlobalPreferenceSystem().registerPreference( "YZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_yz_side_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_yz_side_shown ) ) );
2697 Orthographic_registerPreferencesPage();
2698 Clipper_registerPreferencesPage();
2700 XYWnd::captureStates();
2701 GlobalEntityClassManager().attach( g_EntityClassMenu );
2704 void XYWindow_Destroy(){
2705 GlobalEntityClassManager().detach( g_EntityClassMenu );
2706 XYWnd::releaseStates();