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>
46 #include <util/buffer.h>
48 #include "generic/callback.h"
49 #include "string/string.h"
50 #include "stream/stringstream.h"
53 #include "eclasslib.h"
55 #include "moduleobserver.h"
57 #include "gtkutil/menu.h"
58 #include "gtkutil/container.h"
59 #include "gtkutil/widget.h"
60 #include "gtkutil/glwidget.h"
61 #include "gtkutil/filechooser.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;
119 ClipPoint* g_pMovingClip = 0;
121 /* Drawing clip points */
122 void ClipPoint::Draw( int num, float scale ){
123 StringOutputStream label( 4 );
125 Draw( label.c_str(), scale );
128 void ClipPoint::Draw( const char *label, float scale ){
131 glColor3fv( vector3_to_array( g_xywindow_globals.color_clipper ) );
132 glBegin( GL_POINTS );
133 glVertex3fv( vector3_to_array( m_ptClip ) );
137 float offset = 2.0f / scale;
140 glRasterPos3f( m_ptClip[0] + offset, m_ptClip[1] + offset, m_ptClip[2] + offset );
141 glCallLists( GLsizei( strlen( label ) ), GL_UNSIGNED_BYTE, label );
144 float fDiff( float f1, float f2 ){
153 inline double ClipPoint_Intersect( const ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale ){
154 int nDim1 = ( viewtype == YZ ) ? 1 : 0;
155 int nDim2 = ( viewtype == XY ) ? 1 : 2;
156 double screenDistanceSquared( vector2_length_squared( Vector2( fDiff( clip.m_ptClip[nDim1], point[nDim1] ) * scale, fDiff( clip.m_ptClip[nDim2], point[nDim2] ) * scale ) ) );
157 if ( screenDistanceSquared < 8 * 8 ) {
158 return screenDistanceSquared;
163 inline void ClipPoint_testSelect( ClipPoint& clip, const Vector3& point, VIEWTYPE viewtype, float scale, double& bestDistance, ClipPoint*& bestClip ){
165 double distance = ClipPoint_Intersect( clip, point, viewtype, scale );
166 if ( distance < bestDistance ) {
167 bestDistance = distance;
173 inline ClipPoint* GlobalClipPoints_Find( const Vector3& point, VIEWTYPE viewtype, float scale ){
174 double bestDistance = FLT_MAX;
175 ClipPoint* bestClip = 0;
176 ClipPoint_testSelect( g_Clip1, point, viewtype, scale, bestDistance, bestClip );
177 ClipPoint_testSelect( g_Clip2, point, viewtype, scale, bestDistance, bestClip );
178 ClipPoint_testSelect( g_Clip3, point, viewtype, scale, bestDistance, bestClip );
182 inline void GlobalClipPoints_Draw( float scale ){
184 if ( g_Clip1.Set() ) {
185 g_Clip1.Draw( 1, scale );
187 if ( g_Clip2.Set() ) {
188 g_Clip2.Draw( 2, scale );
190 if ( g_Clip3.Set() ) {
191 g_Clip3.Draw( 3, scale );
195 inline bool GlobalClipPoints_valid(){
196 return g_Clip1.Set() && g_Clip2.Set();
199 void PlanePointsFromClipPoints( Vector3 planepts[3], const AABB& bounds, int viewtype ){
200 ASSERT_MESSAGE( GlobalClipPoints_valid(), "clipper points not initialised" );
201 planepts[0] = g_Clip1.m_ptClip;
202 planepts[1] = g_Clip2.m_ptClip;
203 planepts[2] = g_Clip3.m_ptClip;
204 Vector3 maxs( vector3_added( bounds.origin, bounds.extents ) );
205 Vector3 mins( vector3_subtracted( bounds.origin, bounds.extents ) );
206 if ( !g_Clip3.Set() ) {
207 int n = ( viewtype == XY ) ? 2 : ( viewtype == YZ ) ? 0 : 1;
208 int x = ( n == 0 ) ? 1 : 0;
209 int y = ( n == 2 ) ? 1 : 2;
211 if ( n == 1 ) { // on viewtype XZ, flip clip points
212 planepts[0][n] = maxs[n];
213 planepts[1][n] = maxs[n];
214 planepts[2][x] = g_Clip1.m_ptClip[x];
215 planepts[2][y] = g_Clip1.m_ptClip[y];
216 planepts[2][n] = mins[n];
220 planepts[0][n] = mins[n];
221 planepts[1][n] = mins[n];
222 planepts[2][x] = g_Clip1.m_ptClip[x];
223 planepts[2][y] = g_Clip1.m_ptClip[y];
224 planepts[2][n] = maxs[n];
231 if ( !GlobalClipPoints_valid() ) {
232 planepts[0] = Vector3( 0, 0, 0 );
233 planepts[1] = Vector3( 0, 0, 0 );
234 planepts[2] = Vector3( 0, 0, 0 );
235 Scene_BrushSetClipPlane( GlobalSceneGraph(), Plane3( 0, 0, 0, 0 ) );
239 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
240 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
242 std::swap( planepts[0], planepts[1] );
244 Scene_BrushSetClipPlane( GlobalSceneGraph(), plane3_for_points( planepts[0], planepts[1], planepts[2] ) );
246 ClipperChangeNotify();
249 const char* Clip_getShader(){
250 return g_clip_useCaulk ? "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
254 if ( ClipMode() && GlobalClipPoints_valid() ) {
256 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
257 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
258 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), ( !g_bSwitch ) ? eFront : eBack );
263 ClipperChangeNotify();
268 if ( ClipMode() && GlobalClipPoints_valid() ) {
270 AABB bounds( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
271 PlanePointsFromClipPoints( planepts, bounds, g_clip_viewtype );
272 Scene_BrushSplitByPlane( GlobalSceneGraph(), planepts[0], planepts[1], planepts[2], Clip_getShader(), eFrontAndBack );
277 ClipperChangeNotify();
282 g_bSwitch = !g_bSwitch;
284 ClipperChangeNotify();
287 void OnClipMode( bool enabled ){
292 if ( !enabled && g_pMovingClip ) {
297 ClipperChangeNotify();
301 return GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip;
304 void NewClipPoint( const Vector3& point ){
305 if ( g_Clip1.Set() == false ) {
306 g_Clip1.m_ptClip = point;
309 else if ( g_Clip2.Set() == false ) {
310 g_Clip2.m_ptClip = point;
313 else if ( g_Clip3.Set() == false ) {
314 g_Clip3.m_ptClip = point;
322 g_Clip1.m_ptClip = point;
327 ClipperChangeNotify();
332 struct xywindow_globals_private_t
336 // these are in the View > Show menu with Show coordinates
338 bool show_coordinates;
352 xywindow_globals_private_t() :
356 show_coordinates( true ),
358 show_outline( false ),
361 d_show_work( false ),
363 show_blocks( false ),
365 m_bCamXYUpdate( true ),
366 m_bChaseMouse( true ),
367 m_bSizePaint( true ){
372 xywindow_globals_t g_xywindow_globals;
373 xywindow_globals_private_t g_xywindow_globals_private;
375 const unsigned int RAD_NONE = 0x00;
376 const unsigned int RAD_SHIFT = 0x01;
377 const unsigned int RAD_ALT = 0x02;
378 const unsigned int RAD_CONTROL = 0x04;
379 const unsigned int RAD_PRESS = 0x08;
380 const unsigned int RAD_LBUTTON = 0x10;
381 const unsigned int RAD_MBUTTON = 0x20;
382 const unsigned int RAD_RBUTTON = 0x40;
384 inline ButtonIdentifier button_for_flags( unsigned int flags ){
385 if ( flags & RAD_LBUTTON ) {
388 if ( flags & RAD_RBUTTON ) {
389 return c_buttonRight;
391 if ( flags & RAD_MBUTTON ) {
392 return c_buttonMiddle;
394 return c_buttonInvalid;
397 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
398 ModifierFlags modifiers = c_modifierNone;
399 if ( flags & RAD_SHIFT ) {
400 modifiers |= c_modifierShift;
402 if ( flags & RAD_CONTROL ) {
403 modifiers |= c_modifierControl;
405 if ( flags & RAD_ALT ) {
406 modifiers |= c_modifierAlt;
411 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
412 unsigned int buttons = 0;
414 switch ( button.get() )
416 case ButtonEnumeration::INVALID: break;
417 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
418 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
419 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
422 if ( bitfield_enabled( flags, c_modifierControl ) ) {
423 buttons |= RAD_CONTROL;
426 if ( bitfield_enabled( flags, c_modifierShift ) ) {
427 buttons |= RAD_SHIFT;
430 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
437 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
438 unsigned int flags = 0;
440 switch ( event->button )
442 case 1: flags |= RAD_LBUTTON; break;
443 case 2: flags |= RAD_MBUTTON; break;
444 case 3: flags |= RAD_RBUTTON; break;
447 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
448 flags |= RAD_CONTROL;
451 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
455 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
462 inline unsigned int buttons_for_state( guint state ){
463 unsigned int flags = 0;
465 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
466 flags |= RAD_LBUTTON;
469 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
470 flags |= RAD_MBUTTON;
473 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
474 flags |= RAD_RBUTTON;
477 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
478 flags |= RAD_CONTROL;
481 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
485 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
493 void XYWnd::SetScale( float f ){
497 XYWnd_Update( *this );
500 void XYWnd_ZoomIn( XYWnd* xy ){
501 float max_scale = 64;
502 float scale = xy->Scale() * 5.0f / 4.0f;
503 if ( scale > max_scale ) {
504 if ( xy->Scale() != max_scale ) {
505 xy->SetScale( max_scale );
510 xy->SetScale( scale );
515 // NOTE: the zoom out factor is 4/5, we could think about customizing it
516 // we don't go below a zoom factor corresponding to 10% of the max world size
517 // (this has to be computed against the window size)
518 void XYWnd_ZoomOut( XYWnd* xy ){
519 float min_scale = MIN( xy->Width(),xy->Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
520 float scale = xy->Scale() * 4.0f / 5.0f;
521 if ( scale < min_scale ) {
522 if ( xy->Scale() != min_scale ) {
523 xy->SetScale( min_scale );
528 xy->SetScale( scale );
532 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
533 ASSERT_NOTNULL( g_pParentWnd );
534 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
535 return g_pParentWnd->ActiveXY()->GetViewType();
538 // =============================================================================
541 bool g_bCrossHairs = false;
543 ui::Menu XYWnd::m_mnuDrop(ui::null);
545 // this is disabled, and broken
546 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
550 width = g_pParentWnd->ActiveXY()->Width();
551 height = g_pParentWnd->ActiveXY()->Height();
553 const char* filename;
555 filename = ui::file_dialog( GTK_WIDGET( MainFrame_getWindow() ), FALSE, "Save Image", 0, FILTER_BMP );
560 g_pParentWnd->ActiveXY()->MakeCurrent();
561 img = (unsigned char*)malloc( width * height * 3 );
562 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
565 fp = fopen( filename, "wb" );
568 unsigned long cmap, bfSize;
572 bfSize = 54 + width * height * 3;
574 long byteswritten = 0;
575 long pixoff = 54 + cmap * 4;
577 char m1 = 'B', m2 = 'M';
578 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
579 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
580 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
581 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
582 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
583 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
585 unsigned long biSize = 40, compress = 0, size = 0;
587 unsigned short planes = 1;
588 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
589 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
590 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
591 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
592 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
593 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
594 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
595 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
596 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
597 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
598 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
600 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
601 long row, row_size = width * 3;
602 for ( row = 0; row < height; row++ )
604 unsigned char* buf = img + row * row_size;
608 for ( col = 0; col < row_size; col += 3 )
610 putc( buf[col + 2], fp );
611 putc( buf[col + 1], fp );
612 putc( buf[col], fp );
614 byteswritten += row_size;
617 for ( count = row_size; count < widthDW; count++ )
619 putc( 0, fp ); // dummy
634 Timer g_chasemouse_timer;
636 void XYWnd::ChaseMouse(){
637 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
638 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
640 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
642 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
643 g_chasemouse_timer.start();
646 gboolean xywnd_chasemouse( gpointer data ){
647 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
651 inline const int& min_int( const int& left, const int& right ){
652 return std::min( left, right );
655 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
656 m_chasemouse_delta_x = 0;
657 m_chasemouse_delta_y = 0;
659 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
660 const int epsilon = 16;
662 if ( pointx < epsilon ) {
663 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
665 else if ( ( pointx - m_nWidth ) > -epsilon ) {
666 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
669 if ( pointy < epsilon ) {
670 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
672 else if ( ( pointy - m_nHeight ) > -epsilon ) {
673 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
676 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
677 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
678 m_chasemouse_current_x = pointx;
679 m_chasemouse_current_y = pointy;
680 if ( m_chasemouse_handler == 0 ) {
681 //globalOutputStream() << "chasemouse timer start... ";
682 g_chasemouse_timer.start();
683 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
689 if ( m_chasemouse_handler != 0 ) {
690 //globalOutputStream() << "chasemouse cancel\n";
691 g_source_remove( m_chasemouse_handler );
692 m_chasemouse_handler = 0;
698 if ( m_chasemouse_handler != 0 ) {
699 //globalOutputStream() << "chasemouse cancel\n";
700 g_source_remove( m_chasemouse_handler );
701 m_chasemouse_handler = 0;
707 // =============================================================================
709 Shader* XYWnd::m_state_selected = 0;
711 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
712 if ( self.GetWidget().visible() ) {
713 self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.Width(), self.Height() ) );
717 gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
718 if ( event->type == GDK_BUTTON_PRESS ) {
719 g_pParentWnd->SetActiveXY( xywnd );
721 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
723 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
728 gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
729 if ( event->type == GDK_BUTTON_RELEASE ) {
730 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
732 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
737 gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
738 if ( event->type == GDK_FOCUS_CHANGE ) {
740 g_pParentWnd->SetActiveXY( xywnd );
746 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
747 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
750 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
753 gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
754 if ( event->direction == GDK_SCROLL_UP ) {
755 XYWnd_ZoomIn( xywnd );
757 else if ( event->direction == GDK_SCROLL_DOWN ) {
758 XYWnd_ZoomOut( xywnd );
763 gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){
764 xywnd->m_nWidth = allocation->width;
765 xywnd->m_nHeight = allocation->height;
766 xywnd->updateProjection();
767 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
771 gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
772 if ( glwidget_make_current( xywnd->GetWidget() ) != FALSE ) {
773 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
774 GlobalOpenGL_debugAssertNoErrors();
776 GlobalOpenGL_debugAssertNoErrors();
778 xywnd->m_XORRectangle.set( rectangle_t() );
780 glwidget_swap_buffers( xywnd->GetWidget() );
786 void XYWnd_CameraMoved( XYWnd& xywnd ){
787 if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
788 XYWnd_Update( xywnd );
793 m_gl_widget( glwidget_new( FALSE ) ),
794 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
795 m_deferred_motion( xywnd_motion, this ),
797 m_window_observer( NewWindowObserver() ),
798 m_XORRectangle( m_gl_widget ),
799 m_chasemouse_handler( 0 ){
803 m_bNewBrushDrag = false;
804 m_move_started = false;
805 m_zoom_started = false;
816 m_backgroundActivated = false;
823 m_entityCreate = false;
825 m_mnuDrop = ui::Menu(ui::null);
827 GlobalWindowObservers_add( m_window_observer );
828 GlobalWindowObservers_connectWidget( m_gl_widget );
830 m_window_observer->setRectangleDrawCallback( ReferenceCaller1<XYWnd, rect_t, xy_update_xor_rectangle>( *this ) );
831 m_window_observer->setView( m_view );
833 g_object_ref( m_gl_widget._handle );
835 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 );
836 gtk_widget_set_can_focus( m_gl_widget, true );
838 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
839 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
841 m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
842 m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
843 m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this );
844 m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
846 m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
848 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
853 AddSceneChangeCallback( ReferenceCaller<XYWnd, &XYWnd_Update>( *this ) );
854 AddCameraMovedCallback( ReferenceCaller<XYWnd, &XYWnd_CameraMoved>( *this ) );
856 PressedButtons_connect( g_pressedButtons, m_gl_widget );
858 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
865 gtk_widget_destroy( GTK_WIDGET( m_mnuDrop ) );
866 m_mnuDrop = ui::Menu(ui::null);
869 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
870 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
874 m_window_observer->release();
877 void XYWnd::captureStates(){
878 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
881 void XYWnd::releaseStates(){
882 GlobalShaderCache().release( "$XY_OVERLAY" );
885 const Vector3& XYWnd::GetOrigin(){
889 void XYWnd::SetOrigin( const Vector3& origin ){
894 void XYWnd::Scroll( int x, int y ){
895 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
896 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
897 m_vOrigin[nDim1] += x / m_fScale;
898 m_vOrigin[nDim2] += y / m_fScale;
903 unsigned int Clipper_buttons(){
907 void XYWnd::DropClipPoint( int pointx, int pointy ){
910 XY_ToPoint( pointx, pointy, point );
913 Select_GetMid( mid );
914 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
915 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
916 point[nDim] = mid[nDim];
917 vector3_snap( point, GetSnapGridSize() );
918 NewClipPoint( point );
921 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
922 Vector3 mousePosition;
923 XY_ToPoint( x, y, mousePosition );
924 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
925 if ( !g_pMovingClip ) {
926 DropClipPoint( x, y );
930 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
931 if ( g_pMovingClip ) {
936 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
937 if ( g_pMovingClip ) {
938 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
939 XY_SnapToGrid( g_pMovingClip->m_ptClip );
941 ClipperChangeNotify();
945 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
946 Vector3 mousePosition;
947 XY_ToPoint( x, y, mousePosition );
948 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
950 cursor = gdk_cursor_new( GDK_CROSSHAIR );
951 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), cursor );
952 gdk_cursor_unref( cursor );
956 gdk_window_set_cursor( gtk_widget_get_window(m_gl_widget), 0 );
960 unsigned int MoveCamera_buttons(){
961 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
964 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
965 Vector3 origin( Camera_getOrigin( camwnd ) );
966 xywnd->XY_ToPoint( x, y, origin );
967 xywnd->XY_SnapToGrid( origin );
968 Camera_setOrigin( camwnd, origin );
971 unsigned int OrientCamera_buttons(){
972 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
973 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
978 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
979 Vector3 point = g_vector3_identity;
980 xywnd->XY_ToPoint( x, y, point );
981 xywnd->XY_SnapToGrid( point );
982 vector3_subtract( point, Camera_getOrigin( camwnd ) );
984 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
985 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
986 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
987 if ( point[n1] || point[n2] ) {
988 Vector3 angles( Camera_getAngles( camwnd ) );
989 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
990 Camera_setAngles( camwnd, angles );
999 unsigned int NewBrushDrag_buttons(){
1003 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1005 m_nNewBrushPressx = x;
1006 m_nNewBrushPressy = y;
1008 m_bNewBrushDrag = true;
1009 GlobalUndoSystem().start();
1012 void XYWnd::NewBrushDrag_End( int x, int y ){
1013 if ( m_NewBrushDrag != 0 ) {
1014 GlobalUndoSystem().finish( "brushDragNew" );
1018 void XYWnd::NewBrushDrag( int x, int y ){
1020 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1021 XY_SnapToGrid( mins );
1022 XY_ToPoint( x, y, maxs );
1023 XY_SnapToGrid( maxs );
1025 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1027 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1028 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1030 if ( maxs[nDim] <= mins[nDim] ) {
1031 maxs[nDim] = mins[nDim] + GetGridSize();
1034 for ( int i = 0 ; i < 3 ; i++ )
1036 if ( mins[i] == maxs[i] ) {
1037 return; // don't create a degenerate brush
1039 if ( mins[i] > maxs[i] ) {
1040 float temp = mins[i];
1046 if ( m_NewBrushDrag == 0 ) {
1047 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1048 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1050 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1051 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1052 brushpath.push( makeReference( node.get() ) );
1053 selectPath( brushpath, true );
1055 m_NewBrushDrag = node.get_pointer();
1059 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1060 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1061 g_brush_always_caulk ?
1062 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1065 void entitycreate_activated( ui::Widget item ){
1066 scene::Node* world_node = Map_FindWorldspawn( g_map );
1067 const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) );
1069 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1070 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1073 GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(), "There's already a worldspawn in your map!"
1081 void EntityClassMenu_addItem( ui::Menu menu, const char* name ){
1082 auto item = ui::MenuItem( name );
1083 item.connect( "activate", G_CALLBACK( entitycreate_activated ), item );
1085 menu_add_item( menu, item );
1088 class EntityClassMenuInserter : public EntityClassVisitor
1090 typedef std::pair<ui::Menu, CopiedString> MenuPair;
1091 typedef std::vector<MenuPair> MenuStack;
1093 CopiedString m_previous;
1095 EntityClassMenuInserter( ui::Menu menu ){
1096 m_stack.reserve( 2 );
1097 m_stack.push_back( MenuPair( menu, "" ) );
1099 ~EntityClassMenuInserter(){
1100 if ( !string_empty( m_previous.c_str() ) ) {
1101 addItem( m_previous.c_str(), "" );
1104 void visit( EntityClass* e ){
1105 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1106 if ( !string_empty( m_previous.c_str() ) ) {
1107 addItem( m_previous.c_str(), e->name() );
1109 m_previous = e->name();
1111 void pushMenu( const CopiedString& name ){
1112 auto item = ui::MenuItem( name.c_str() );
1114 m_stack.back().first.add(item);
1116 auto submenu = ui::Menu(ui::New);
1117 gtk_menu_item_set_submenu( item, GTK_WIDGET( submenu ) );
1119 m_stack.push_back( MenuPair( submenu, name ) );
1124 void addItem( const char* name, const char* next ){
1125 const char* underscore = strchr( name, '_' );
1127 if ( underscore != 0 && underscore != name ) {
1128 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1129 const char* parent = m_stack.back().second.c_str();
1131 if ( !string_empty( parent )
1132 && string_length( parent ) == std::size_t( underscore - name )
1133 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1135 else if ( nextEqual ) {
1136 if ( m_stack.size() == 2 ) {
1139 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1141 else if ( m_stack.size() == 2 ) {
1145 else if ( m_stack.size() == 2 ) {
1149 EntityClassMenu_addItem( m_stack.back().first, name );
1153 void XYWnd::OnContextMenu(){
1154 if ( g_xywindow_globals.m_bRightClick == false ) {
1158 if ( !m_mnuDrop ) { // first time, load it up
1159 auto menu = m_mnuDrop = ui::Menu(ui::New);
1161 EntityClassMenuInserter inserter( menu );
1162 GlobalEntityClassManager().forEach( inserter );
1165 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1168 FreezePointer g_xywnd_freezePointer;
1170 unsigned int Move_buttons(){
1174 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1175 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1176 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1179 gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1184 void XYWnd::Move_Begin(){
1185 if ( m_move_started ) {
1188 m_move_started = true;
1189 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_moveDelta, this );
1190 m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1193 void XYWnd::Move_End(){
1194 m_move_started = false;
1195 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow() );
1196 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1199 unsigned int Zoom_buttons(){
1200 return RAD_RBUTTON | RAD_SHIFT;
1205 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1209 while ( abs( g_dragZoom ) > 8 )
1211 if ( g_dragZoom > 0 ) {
1212 XYWnd_ZoomOut( reinterpret_cast<XYWnd*>( data ) );
1217 XYWnd_ZoomIn( reinterpret_cast<XYWnd*>( data ) );
1224 gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1229 void XYWnd::Zoom_Begin(){
1230 if ( m_zoom_started ) {
1233 m_zoom_started = true;
1235 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
1236 m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1239 void XYWnd::Zoom_End(){
1240 m_zoom_started = false;
1241 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow() );
1242 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1245 // makes sure the selected brush or camera is in view
1246 void XYWnd::PositionView( const Vector3& position ){
1247 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1248 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1250 m_vOrigin[nDim1] = position[nDim1];
1251 m_vOrigin[nDim2] = position[nDim2];
1255 XYWnd_Update( *this );
1258 void XYWnd::SetViewType( VIEWTYPE viewType ){
1259 m_viewType = viewType;
1263 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1268 inline WindowVector WindowVector_forInteger( int x, int y ){
1269 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1272 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1273 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1275 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1276 if ( buttons == Move_buttons() ) {
1278 EntityCreate_MouseDown( x, y );
1280 else if ( buttons == Zoom_buttons() ) {
1283 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1284 Clipper_OnLButtonDown( x, y );
1286 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1287 NewBrushDrag_Begin( x, y );
1289 // control mbutton = move camera
1290 else if ( buttons == MoveCamera_buttons() ) {
1291 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1293 // mbutton = angle camera
1294 else if ( buttons == OrientCamera_buttons() ) {
1295 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1299 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1303 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1304 if ( m_move_started ) {
1306 EntityCreate_MouseUp( x, y );
1308 else if ( m_zoom_started ) {
1311 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1312 Clipper_OnLButtonUp( x, y );
1314 else if ( m_bNewBrushDrag ) {
1315 m_bNewBrushDrag = false;
1316 NewBrushDrag_End( x, y );
1320 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1324 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1325 // rbutton = drag xy origin
1326 if ( m_move_started ) {
1329 else if ( m_zoom_started ) {
1332 else if ( ClipMode() && g_pMovingClip != 0 ) {
1333 Clipper_OnMouseMoved( x, y );
1335 // lbutton without selection = drag new brush
1336 else if ( m_bNewBrushDrag ) {
1337 NewBrushDrag( x, y );
1340 // control mbutton = move camera
1341 else if ( getButtonState() == MoveCamera_buttons() ) {
1342 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1345 // mbutton = angle camera
1346 else if ( getButtonState() == OrientCamera_buttons() ) {
1347 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1352 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1354 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1355 XY_ToPoint( x, y, m_mousePosition );
1356 XY_SnapToGrid( m_mousePosition );
1358 StringOutputStream status( 64 );
1359 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1360 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1361 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1362 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1364 if ( g_bCrossHairs ) {
1365 XYWnd_Update( *this );
1368 Clipper_Crosshair_OnMouseMoved( x, y );
1372 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1373 m_entityCreate = true;
1374 m_entityCreate_x = x;
1375 m_entityCreate_y = y;
1378 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1379 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1380 m_entityCreate = false;
1384 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1385 if ( m_entityCreate ) {
1386 m_entityCreate = false;
1391 inline float screen_normalised( int pos, unsigned int size ){
1392 return ( ( 2.0f * pos ) / size ) - 1.0f;
1395 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1396 return world_origin + normalised * normalised2world_scale;
1400 // TTimo: watch it, this doesn't init one of the 3 coords
1401 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1402 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1403 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1404 if ( m_viewType == XY ) {
1405 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1406 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1408 else if ( m_viewType == YZ ) {
1409 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1410 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1414 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1415 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1419 void XYWnd::XY_SnapToGrid( Vector3& point ){
1420 if ( m_viewType == XY ) {
1421 point[0] = float_snapped( point[0], GetSnapGridSize() );
1422 point[1] = float_snapped( point[1], GetSnapGridSize() );
1424 else if ( m_viewType == YZ ) {
1425 point[1] = float_snapped( point[1], GetSnapGridSize() );
1426 point[2] = float_snapped( point[2], GetSnapGridSize() );
1430 point[0] = float_snapped( point[0], GetSnapGridSize() );
1431 point[2] = float_snapped( point[2], GetSnapGridSize() );
1435 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1436 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1437 if ( relative == name ) {
1438 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1441 auto fileNameWithoutExt = u::buffer<512>();
1442 fileNameWithoutExt.copy(relative);
1443 fileNameWithoutExt.terminate();
1444 fileNameWithoutExt.mut()[fileNameWithoutExt.strlen() - 4] = '\0';
1446 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1448 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1451 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1452 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1453 globalOutputStream() << "Loaded background texture " << relative << "\n";
1454 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1457 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1474 Select_GetBounds( min, max );
1475 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1476 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1477 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1478 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1481 void XYWnd::XY_DisableBackground( void ){
1482 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1483 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1484 free( g_pParentWnd->ActiveXY()->m_tex );
1486 g_pParentWnd->ActiveXY()->m_tex = NULL;
1489 void WXY_BackgroundSelect( void ){
1490 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1491 if ( !brushesSelected ) {
1492 ui::root.alert( "You have to select some brushes to get the bounding box for.\n",
1493 "No selection", ui::alert_type::OK, ui::alert_icon::Error );
1497 const char *filename = MainFrame_getWindow().file_dialog( TRUE, "Background Image", NULL, NULL );
1498 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1500 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1505 ============================================================================
1509 ============================================================================
1518 double two_to_the_power( int power ){
1519 return pow( 2.0f, power );
1522 void XYWnd::XY_DrawAxis( void ){
1523 if ( g_xywindow_globals_private.show_axis ) {
1524 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1525 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1526 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1527 const int w = ( m_nWidth / 2 / m_fScale );
1528 const int h = ( m_nHeight / 2 / m_fScale );
1530 const Vector3& colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1531 const Vector3& colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1533 // draw two lines with corresponding axis colors to highlight current view
1534 // horizontal line: nDim1 color
1536 glBegin( GL_LINES );
1537 glColor3fv( vector3_to_array( colourX ) );
1538 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1539 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1541 glVertex2f( 32 / m_fScale, 0 );
1542 glColor3fv( vector3_to_array( colourY ) );
1543 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1544 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1546 glVertex2f( 0, 32 / m_fScale );
1549 // now print axis symbols
1550 glColor3fv( vector3_to_array( colourX ) );
1551 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1552 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1553 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1554 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1555 glColor3fv( vector3_to_array( colourY ) );
1556 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1557 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1558 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1559 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1563 void XYWnd::XY_DrawBackground( void ){
1564 glPushAttrib( GL_ALL_ATTRIB_BITS );
1566 glEnable( GL_TEXTURE_2D );
1567 glEnable( GL_BLEND );
1568 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1569 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1570 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1571 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1573 glPolygonMode( GL_FRONT, GL_FILL );
1575 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1576 glBegin( GL_QUADS );
1578 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1579 glTexCoord2f( 0.0, 1.0 );
1580 glVertex2f( m_xmin, m_ymin );
1582 glTexCoord2f( 1.0, 1.0 );
1583 glVertex2f( m_xmax, m_ymin );
1585 glTexCoord2f( 1.0, 0.0 );
1586 glVertex2f( m_xmax, m_ymax );
1588 glTexCoord2f( 0.0, 0.0 );
1589 glVertex2f( m_xmin, m_ymax );
1592 glBindTexture( GL_TEXTURE_2D, 0 );
1597 void XYWnd::XY_DrawGrid( void ) {
1598 float x, y, xb, xe, yb, ye;
1600 auto text = u::buffer<32>();
1601 float step, minor_step, stepx, stepy;
1602 step = minor_step = stepx = stepy = GetGridSize();
1604 int minor_power = Grid_getPower();
1607 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1611 int power = minor_power;
1612 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1614 step = float(two_to_the_power( power ) );
1616 mask = ( 1 << ( power - minor_power ) ) - 1;
1617 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1619 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1622 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1624 glDisable( GL_TEXTURE_2D );
1625 glDisable( GL_TEXTURE_1D );
1626 glDisable( GL_DEPTH_TEST );
1627 glDisable( GL_BLEND );
1630 w = ( m_nWidth / 2 / m_fScale );
1631 h = ( m_nHeight / 2 / m_fScale );
1633 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1634 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1636 xb = m_vOrigin[nDim1] - w;
1637 if ( xb < region_mins[nDim1] ) {
1638 xb = region_mins[nDim1];
1640 xb = step * floor( xb / step );
1642 xe = m_vOrigin[nDim1] + w;
1643 if ( xe > region_maxs[nDim1] ) {
1644 xe = region_maxs[nDim1];
1646 xe = step * ceil( xe / step );
1648 yb = m_vOrigin[nDim2] - h;
1649 if ( yb < region_mins[nDim2] ) {
1650 yb = region_mins[nDim2];
1652 yb = step * floor( yb / step );
1654 ye = m_vOrigin[nDim2] + h;
1655 if ( ye > region_maxs[nDim2] ) {
1656 ye = region_maxs[nDim2];
1658 ye = step * ceil( ye / step );
1660 #define COLORS_DIFFER( a,b ) \
1661 ( ( a )[0] != ( b )[0] || \
1662 ( a )[1] != ( b )[1] || \
1663 ( a )[2] != ( b )[2] )
1666 // draw minor blocks
1667 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1669 glEnable( GL_BLEND );
1672 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1673 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1675 glBegin( GL_LINES );
1677 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1678 if ( ( i & mask ) != 0 ) {
1679 glVertex2f( x, yb );
1680 glVertex2f( x, ye );
1684 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1685 if ( ( i & mask ) != 0 ) {
1686 glVertex2f( xb, y );
1687 glVertex2f( xe, y );
1693 // draw major blocks
1694 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1695 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1697 glBegin( GL_LINES );
1698 for ( x = xb ; x <= xe ; x += step ) {
1699 glVertex2f( x, yb );
1700 glVertex2f( x, ye );
1702 for ( y = yb ; y <= ye ; y += step ) {
1703 glVertex2f( xb, y );
1704 glVertex2f( xe, y );
1710 glDisable( GL_BLEND );
1714 // draw coordinate text if needed
1715 if ( g_xywindow_globals_private.show_coordinates ) {
1716 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1717 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1718 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1719 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1720 glRasterPos2f( x, offx );
1721 text.sprintf( "%g", x );
1722 GlobalOpenGL().drawString( text );
1724 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1725 glRasterPos2f( offy, y );
1726 text.sprintf( "%g", y );
1727 GlobalOpenGL().drawString( text );
1731 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1734 // we do this part (the old way) only if show_axis is disabled
1735 if ( !g_xywindow_globals_private.show_axis ) {
1736 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1738 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1742 XYWnd::XY_DrawAxis();
1744 // show current work zone?
1745 // the work zone is used to place dropped points and brushes
1746 if ( g_xywindow_globals_private.d_show_work ) {
1747 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1748 glBegin( GL_LINES );
1749 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1750 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1751 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1752 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1753 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1754 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1755 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1756 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1766 void XYWnd::XY_DrawBlockGrid(){
1767 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1770 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1771 if ( strlen( value ) ) {
1772 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1775 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1776 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1777 g_xywindow_globals_private.blockSize = 1024;
1780 float x, y, xb, xe, yb, ye;
1782 auto text = u::buffer<32>();
1784 glDisable( GL_TEXTURE_2D );
1785 glDisable( GL_TEXTURE_1D );
1786 glDisable( GL_DEPTH_TEST );
1787 glDisable( GL_BLEND );
1789 w = ( m_nWidth / 2 / m_fScale );
1790 h = ( m_nHeight / 2 / m_fScale );
1792 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1793 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1795 xb = m_vOrigin[nDim1] - w;
1796 if ( xb < region_mins[nDim1] ) {
1797 xb = region_mins[nDim1];
1799 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
1801 xe = m_vOrigin[nDim1] + w;
1802 if ( xe > region_maxs[nDim1] ) {
1803 xe = region_maxs[nDim1];
1805 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
1807 yb = m_vOrigin[nDim2] - h;
1808 if ( yb < region_mins[nDim2] ) {
1809 yb = region_mins[nDim2];
1811 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
1813 ye = m_vOrigin[nDim2] + h;
1814 if ( ye > region_maxs[nDim2] ) {
1815 ye = region_maxs[nDim2];
1817 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
1819 // draw major blocks
1821 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
1824 glBegin( GL_LINES );
1826 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
1828 glVertex2f( x, yb );
1829 glVertex2f( x, ye );
1832 if ( m_viewType == XY ) {
1833 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
1835 glVertex2f( xb, y );
1836 glVertex2f( xe, y );
1843 // draw coordinate text if needed
1845 if ( m_viewType == XY && m_fScale > .1 ) {
1846 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
1847 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
1849 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
1850 text.sprintf( "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
1851 GlobalOpenGL().drawString( text );
1855 glColor4f( 0, 0, 0, 0 );
1858 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
1859 float x, y, fov, box;
1862 fov = 48 / m_fScale;
1863 box = 16 / m_fScale;
1865 if ( m_viewType == XY ) {
1868 a = degrees_to_radians( angles[CAMERA_YAW] );
1870 else if ( m_viewType == YZ ) {
1873 a = degrees_to_radians( angles[CAMERA_PITCH] );
1879 a = degrees_to_radians( angles[CAMERA_PITCH] );
1882 glColor3f( 0.0, 0.0, 1.0 );
1883 glBegin( GL_LINE_STRIP );
1884 glVertex3f( x - box,y,0 );
1885 glVertex3f( x,y + ( box / 2 ),0 );
1886 glVertex3f( x + box,y,0 );
1887 glVertex3f( x,y - ( box / 2 ),0 );
1888 glVertex3f( x - box,y,0 );
1889 glVertex3f( x + box,y,0 );
1892 glBegin( GL_LINE_STRIP );
1893 glVertex3f( x + static_cast<float>( fov * cos( a + c_pi / 4 ) ), y + static_cast<float>( fov * sin( a + c_pi / 4 ) ), 0 );
1894 glVertex3f( x, y, 0 );
1895 glVertex3f( x + static_cast<float>( fov * cos( a - c_pi / 4 ) ), y + static_cast<float>( fov * sin( a - c_pi / 4 ) ), 0 );
1901 float Betwixt( float f1, float f2 ){
1903 return f2 + ( ( f1 - f2 ) / 2 );
1906 return f1 + ( ( f2 - f1 ) / 2 );
1911 // can be greatly simplified but per usual i am in a hurry
1912 // which is not an excuse, just a fact
1913 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
1914 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
1917 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1918 typedef const char* OrgStrings[2];
1919 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1921 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
1923 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
1924 g_xywindow_globals.color_selbrushes[1] * .65f,
1925 g_xywindow_globals.color_selbrushes[2] * .65f );
1927 StringOutputStream dimensions( 16 );
1929 if ( m_viewType == XY ) {
1930 glBegin( GL_LINES );
1932 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1933 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1935 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1936 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1938 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1939 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1942 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1943 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1945 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1946 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1948 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1949 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1953 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
1954 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1955 GlobalOpenGL().drawString( dimensions.c_str() );
1958 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
1959 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1960 GlobalOpenGL().drawString( dimensions.c_str() );
1963 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
1964 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
1965 GlobalOpenGL().drawString( dimensions.c_str() );
1967 else if ( m_viewType == XZ ) {
1968 glBegin( GL_LINES );
1970 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
1971 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
1973 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1974 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1976 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
1977 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1980 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
1981 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
1983 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
1984 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
1986 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
1987 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
1991 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
1992 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1993 GlobalOpenGL().drawString( dimensions.c_str() );
1996 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
1997 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1998 GlobalOpenGL().drawString( dimensions.c_str() );
2001 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2002 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2003 GlobalOpenGL().drawString( dimensions.c_str() );
2007 glBegin( GL_LINES );
2009 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2010 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2012 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2013 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2015 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2016 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2019 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2020 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2022 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2023 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2025 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2026 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2030 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2031 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2032 GlobalOpenGL().drawString( dimensions.c_str() );
2035 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2036 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2037 GlobalOpenGL().drawString( dimensions.c_str() );
2040 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2041 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2042 GlobalOpenGL().drawString( dimensions.c_str() );
2046 class XYRenderer : public Renderer
2054 unsigned int m_highlight;
2058 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2059 m_globalstate( globalstate ),
2060 m_state_selected( selected ){
2061 ASSERT_NOTNULL( selected );
2062 m_state_stack.push_back( state_type() );
2065 void SetState( Shader* state, EStyle style ){
2066 ASSERT_NOTNULL( state );
2067 if ( style == eWireframeOnly ) {
2068 m_state_stack.back().m_state = state;
2071 EStyle getStyle() const {
2072 return eWireframeOnly;
2075 m_state_stack.push_back( m_state_stack.back() );
2078 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2079 m_state_stack.pop_back();
2081 void Highlight( EHighlightMode mode, bool bEnable = true ){
2083 ? m_state_stack.back().m_highlight |= mode
2084 : m_state_stack.back().m_highlight &= ~mode;
2086 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2087 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2088 m_state_selected->addRenderable( renderable, localToWorld );
2092 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2096 void render( const Matrix4& modelview, const Matrix4& projection ){
2097 GlobalShaderCache().render( m_globalstate, modelview, projection );
2100 std::vector<state_type> m_state_stack;
2101 RenderStateFlags m_globalstate;
2102 Shader* m_state_selected;
2105 void XYWnd::updateProjection(){
2106 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2107 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2108 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2110 m_projection[12] = 0.0f;
2111 m_projection[13] = 0.0f;
2112 m_projection[14] = -1.0f;
2124 m_projection[11] = 0.0f;
2126 m_projection[15] = 1.0f;
2128 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2131 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2132 void XYWnd::updateModelview(){
2133 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2134 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2137 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2138 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2139 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2142 switch ( m_viewType )
2145 m_modelview[0] = m_fScale;
2150 m_modelview[5] = m_fScale;
2155 m_modelview[10] = -m_fScale;
2158 m_modelview[0] = m_fScale;
2164 m_modelview[6] = m_fScale;
2167 m_modelview[9] = m_fScale;
2168 m_modelview[10] = 0;
2173 m_modelview[2] = -m_fScale;
2175 m_modelview[4] = m_fScale;
2180 m_modelview[9] = m_fScale;
2181 m_modelview[10] = 0;
2185 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2186 m_modelview[15] = 1;
2188 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2197 //#define DBG_SCENEDUMP
2199 void XYWnd::XY_Draw(){
2203 glViewport( 0, 0, m_nWidth, m_nHeight );
2204 glClearColor( g_xywindow_globals.color_gridback[0],
2205 g_xywindow_globals.color_gridback[1],
2206 g_xywindow_globals.color_gridback[2],0 );
2208 glClear( GL_COLOR_BUFFER_BIT );
2214 glMatrixMode( GL_PROJECTION );
2215 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2217 glMatrixMode( GL_MODELVIEW );
2219 glScalef( m_fScale, m_fScale, 1 );
2220 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2221 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2222 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2224 glDisable( GL_LINE_STIPPLE );
2226 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2227 glDisableClientState( GL_NORMAL_ARRAY );
2228 glDisableClientState( GL_COLOR_ARRAY );
2229 glDisable( GL_TEXTURE_2D );
2230 glDisable( GL_LIGHTING );
2231 glDisable( GL_COLOR_MATERIAL );
2232 glDisable( GL_DEPTH_TEST );
2234 if ( m_backgroundActivated ) {
2235 XY_DrawBackground();
2239 if ( g_xywindow_globals_private.show_blocks ) {
2243 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2245 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2246 if ( !g_xywindow_globals.m_bNoStipple ) {
2247 globalstate |= RENDER_LINESTIPPLE;
2251 XYRenderer renderer( globalstate, m_state_selected );
2253 Scene_Render( renderer, m_view );
2255 GlobalOpenGL_debugAssertNoErrors();
2256 renderer.render( m_modelview, m_projection );
2257 GlobalOpenGL_debugAssertNoErrors();
2260 glDepthMask( GL_FALSE );
2262 GlobalOpenGL_debugAssertNoErrors();
2264 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2266 GlobalOpenGL_debugAssertNoErrors();
2267 glDisable( GL_LINE_STIPPLE );
2268 GlobalOpenGL_debugAssertNoErrors();
2270 GlobalOpenGL_debugAssertNoErrors();
2271 if ( GlobalOpenGL().GL_1_3() ) {
2272 glActiveTexture( GL_TEXTURE0 );
2273 glClientActiveTexture( GL_TEXTURE0 );
2275 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2276 GlobalOpenGL_debugAssertNoErrors();
2277 glDisableClientState( GL_NORMAL_ARRAY );
2278 GlobalOpenGL_debugAssertNoErrors();
2279 glDisableClientState( GL_COLOR_ARRAY );
2280 GlobalOpenGL_debugAssertNoErrors();
2281 glDisable( GL_TEXTURE_2D );
2282 GlobalOpenGL_debugAssertNoErrors();
2283 glDisable( GL_LIGHTING );
2284 GlobalOpenGL_debugAssertNoErrors();
2285 glDisable( GL_COLOR_MATERIAL );
2286 GlobalOpenGL_debugAssertNoErrors();
2288 GlobalOpenGL_debugAssertNoErrors();
2292 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2294 Select_GetBounds( min, max );
2295 PaintSizeInfo( nDim1, nDim2, min, max );
2298 if ( g_bCrossHairs ) {
2299 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2300 glBegin( GL_LINES );
2301 if ( m_viewType == XY ) {
2302 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2303 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2304 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2305 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2307 else if ( m_viewType == YZ ) {
2308 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2309 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2310 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2311 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2315 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2316 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2317 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2318 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2324 GlobalClipPoints_Draw( m_fScale );
2327 GlobalOpenGL_debugAssertNoErrors();
2331 glScalef( m_fScale, m_fScale, 1 );
2332 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2334 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2336 Feedback_draw2D( m_viewType );
2338 if ( g_xywindow_globals_private.show_outline ) {
2340 glMatrixMode( GL_PROJECTION );
2342 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2344 glMatrixMode( GL_MODELVIEW );
2347 // four view mode doesn't colorize
2348 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2349 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2353 switch ( m_viewType )
2356 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2359 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2362 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2366 glBegin( GL_LINE_LOOP );
2367 glVertex2f( 0.5, 0.5 );
2368 glVertex2f( m_nWidth - 0.5, 1 );
2369 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2370 glVertex2f( 0.5, m_nHeight - 0.5 );
2375 GlobalOpenGL_debugAssertNoErrors();
2380 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2381 xywnd->XY_ToPoint( x, y, point );
2382 xywnd->XY_SnapToGrid( point );
2384 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2385 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2386 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2389 void XYWnd::OnEntityCreate( const char* item ){
2390 StringOutputStream command;
2391 command << "entityCreate -class " << item;
2392 UndoableCommand undo( command.c_str() );
2394 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2395 Entity_createFromSelection( item, point );
2400 void GetFocusPosition( Vector3& position ){
2401 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2402 Select_GetMid( position );
2406 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2410 void XYWnd_Focus( XYWnd* xywnd ){
2412 GetFocusPosition( position );
2413 xywnd->PositionView( position );
2416 void XY_Split_Focus(){
2418 GetFocusPosition( position );
2419 if ( g_pParentWnd->GetXYWnd() ) {
2420 g_pParentWnd->GetXYWnd()->PositionView( position );
2422 if ( g_pParentWnd->GetXZWnd() ) {
2423 g_pParentWnd->GetXZWnd()->PositionView( position );
2425 if ( g_pParentWnd->GetYZWnd() ) {
2426 g_pParentWnd->GetYZWnd()->PositionView( position );
2431 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2432 // cannot do this in a split window
2433 // do something else that the user may want here
2438 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2439 XYWnd_Focus( xywnd );
2443 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2444 // cannot do this in a split window
2445 // do something else that the user may want here
2450 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2451 xywnd->SetViewType( XY );
2452 XYWnd_Focus( xywnd );
2456 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2457 // cannot do this in a split window
2458 // do something else that the user may want here
2463 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2464 xywnd->SetViewType( XZ );
2465 XYWnd_Focus( xywnd );
2469 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2470 // cannot do this in a split window
2471 // do something else that the user may want here
2476 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2477 xywnd->SetViewType( YZ );
2478 XYWnd_Focus( xywnd );
2482 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2483 // cannot do this in a split window
2484 // do something else that the user may want here
2489 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2490 if ( xywnd->GetViewType() == XY ) {
2491 xywnd->SetViewType( XZ );
2493 else if ( xywnd->GetViewType() == XZ ) {
2494 xywnd->SetViewType( YZ );
2497 xywnd->SetViewType( XY );
2499 XYWnd_Focus( xywnd );
2503 if ( g_pParentWnd->GetXYWnd() ) {
2504 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2506 if ( g_pParentWnd->GetXZWnd() ) {
2507 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2509 if ( g_pParentWnd->GetYZWnd() ) {
2510 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2515 XYWnd_ZoomIn( g_pParentWnd->ActiveXY() );
2518 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2519 // we don't go below a zoom factor corresponding to 10% of the max world size
2520 // (this has to be computed against the window size)
2522 XYWnd_ZoomOut( g_pParentWnd->ActiveXY() );
2527 void ToggleShowCrosshair(){
2529 XY_UpdateAllWindows();
2532 void ToggleShowSizeInfo(){
2533 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2534 XY_UpdateAllWindows();
2537 void ToggleShowGrid(){
2538 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2539 XY_UpdateAllWindows();
2542 ToggleShown g_xy_top_shown( true );
2544 void XY_Top_Shown_Construct( ui::Window parent ){
2545 g_xy_top_shown.connect( parent );
2548 ToggleShown g_yz_side_shown( false );
2550 void YZ_Side_Shown_Construct( ui::Window parent ){
2551 g_yz_side_shown.connect( parent );
2554 ToggleShown g_xz_front_shown( false );
2556 void XZ_Front_Shown_Construct( ui::Window parent ){
2557 g_xz_front_shown.connect( parent );
2561 class EntityClassMenu : public ModuleObserver
2563 std::size_t m_unrealised;
2565 EntityClassMenu() : m_unrealised( 1 ){
2568 if ( --m_unrealised == 0 ) {
2572 if ( ++m_unrealised == 1 ) {
2573 if ( XYWnd::m_mnuDrop ) {
2574 gtk_widget_destroy( GTK_WIDGET( XYWnd::m_mnuDrop ) );
2575 XYWnd::m_mnuDrop = ui::Menu(ui::null);
2581 EntityClassMenu g_EntityClassMenu;
2586 void ShowNamesToggle(){
2587 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2588 XY_UpdateAllWindows();
2590 typedef FreeCaller<ShowNamesToggle> ShowNamesToggleCaller;
2591 void ShowNamesExport( const BoolImportCallback& importer ){
2592 importer( GlobalEntityCreator().getShowNames() );
2594 typedef FreeCaller1<const BoolImportCallback&, ShowNamesExport> ShowNamesExportCaller;
2596 void ShowAnglesToggle(){
2597 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2598 XY_UpdateAllWindows();
2600 typedef FreeCaller<ShowAnglesToggle> ShowAnglesToggleCaller;
2601 void ShowAnglesExport( const BoolImportCallback& importer ){
2602 importer( GlobalEntityCreator().getShowAngles() );
2604 typedef FreeCaller1<const BoolImportCallback&, ShowAnglesExport> ShowAnglesExportCaller;
2606 void ShowBlocksToggle(){
2607 g_xywindow_globals_private.show_blocks ^= 1;
2608 XY_UpdateAllWindows();
2610 typedef FreeCaller<ShowBlocksToggle> ShowBlocksToggleCaller;
2611 void ShowBlocksExport( const BoolImportCallback& importer ){
2612 importer( g_xywindow_globals_private.show_blocks );
2614 typedef FreeCaller1<const BoolImportCallback&, ShowBlocksExport> ShowBlocksExportCaller;
2616 void ShowCoordinatesToggle(){
2617 g_xywindow_globals_private.show_coordinates ^= 1;
2618 XY_UpdateAllWindows();
2620 typedef FreeCaller<ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2621 void ShowCoordinatesExport( const BoolImportCallback& importer ){
2622 importer( g_xywindow_globals_private.show_coordinates );
2624 typedef FreeCaller1<const BoolImportCallback&, ShowCoordinatesExport> ShowCoordinatesExportCaller;
2626 void ShowOutlineToggle(){
2627 g_xywindow_globals_private.show_outline ^= 1;
2628 XY_UpdateAllWindows();
2630 typedef FreeCaller<ShowOutlineToggle> ShowOutlineToggleCaller;
2631 void ShowOutlineExport( const BoolImportCallback& importer ){
2632 importer( g_xywindow_globals_private.show_outline );
2634 typedef FreeCaller1<const BoolImportCallback&, ShowOutlineExport> ShowOutlineExportCaller;
2636 void ShowAxesToggle(){
2637 g_xywindow_globals_private.show_axis ^= 1;
2638 XY_UpdateAllWindows();
2640 typedef FreeCaller<ShowAxesToggle> ShowAxesToggleCaller;
2641 void ShowAxesExport( const BoolImportCallback& importer ){
2642 importer( g_xywindow_globals_private.show_axis );
2644 typedef FreeCaller1<const BoolImportCallback&, ShowAxesExport> ShowAxesExportCaller;
2646 void ShowWorkzoneToggle(){
2647 g_xywindow_globals_private.d_show_work ^= 1;
2648 XY_UpdateAllWindows();
2650 typedef FreeCaller<ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2651 void ShowWorkzoneExport( const BoolImportCallback& importer ){
2652 importer( g_xywindow_globals_private.d_show_work );
2654 typedef FreeCaller1<const BoolImportCallback&, ShowWorkzoneExport> ShowWorkzoneExportCaller;
2656 ShowNamesExportCaller g_show_names_caller;
2657 BoolExportCallback g_show_names_callback( g_show_names_caller );
2658 ToggleItem g_show_names( g_show_names_callback );
2660 ShowAnglesExportCaller g_show_angles_caller;
2661 BoolExportCallback g_show_angles_callback( g_show_angles_caller );
2662 ToggleItem g_show_angles( g_show_angles_callback );
2664 ShowBlocksExportCaller g_show_blocks_caller;
2665 BoolExportCallback g_show_blocks_callback( g_show_blocks_caller );
2666 ToggleItem g_show_blocks( g_show_blocks_callback );
2668 ShowCoordinatesExportCaller g_show_coordinates_caller;
2669 BoolExportCallback g_show_coordinates_callback( g_show_coordinates_caller );
2670 ToggleItem g_show_coordinates( g_show_coordinates_callback );
2672 ShowOutlineExportCaller g_show_outline_caller;
2673 BoolExportCallback g_show_outline_callback( g_show_outline_caller );
2674 ToggleItem g_show_outline( g_show_outline_callback );
2676 ShowAxesExportCaller g_show_axes_caller;
2677 BoolExportCallback g_show_axes_callback( g_show_axes_caller );
2678 ToggleItem g_show_axes( g_show_axes_callback );
2680 ShowWorkzoneExportCaller g_show_workzone_caller;
2681 BoolExportCallback g_show_workzone_callback( g_show_workzone_caller );
2682 ToggleItem g_show_workzone( g_show_workzone_callback );
2684 void XYShow_registerCommands(){
2685 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2686 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
2687 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2688 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2689 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2690 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2691 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2694 void XYWnd_registerShortcuts(){
2695 command_connect_accelerator( "ToggleCrosshairs" );
2696 command_connect_accelerator( "ToggleSizePaint" );
2701 void Orthographic_constructPreferences( PreferencesPage& page ){
2702 page.appendCheckBox( "", "Solid selection boxes", g_xywindow_globals.m_bNoStipple );
2703 page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2704 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2705 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2707 void Orthographic_constructPage( PreferenceGroup& group ){
2708 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
2709 Orthographic_constructPreferences( page );
2711 void Orthographic_registerPreferencesPage(){
2712 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Orthographic_constructPage>() );
2715 void Clipper_constructPreferences( PreferencesPage& page ){
2716 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
2718 void Clipper_constructPage( PreferenceGroup& group ){
2719 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
2720 Clipper_constructPreferences( page );
2722 void Clipper_registerPreferencesPage(){
2723 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, Clipper_constructPage>() );
2727 #include "preferencesystem.h"
2728 #include "stringio.h"
2733 void ToggleShown_importBool( ToggleShown& self, bool value ){
2736 typedef ReferenceCaller1<ToggleShown, bool, ToggleShown_importBool> ToggleShownImportBoolCaller;
2737 void ToggleShown_exportBool( const ToggleShown& self, const BoolImportCallback& importer ){
2738 importer( self.active() );
2740 typedef ConstReferenceCaller1<ToggleShown, const BoolImportCallback&, ToggleShown_exportBool> ToggleShownExportBoolCaller;
2743 void XYWindow_Construct(){
2744 GlobalCommands_insert( "ToggleCrosshairs", FreeCaller<ToggleShowCrosshair>(), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2745 GlobalCommands_insert( "ToggleSizePaint", FreeCaller<ToggleShowSizeInfo>(), Accelerator( 'J' ) );
2746 GlobalCommands_insert( "ToggleGrid", FreeCaller<ToggleShowGrid>(), Accelerator( '0' ) );
2748 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 ) ) );
2749 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
2750 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
2751 GlobalCommands_insert( "NextView", FreeCaller<XY_Next>(), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut
2752 GlobalCommands_insert( "ZoomIn", FreeCaller<XY_ZoomIn>(), Accelerator( GDK_KEY_Delete ) );
2753 GlobalCommands_insert( "ZoomOut", FreeCaller<XY_ZoomOut>(), Accelerator( GDK_KEY_Insert ) );
2754 GlobalCommands_insert( "ViewTop", FreeCaller<XY_Top>(), Accelerator( GDK_KEY_KP_Home ) );
2755 GlobalCommands_insert( "ViewSide", FreeCaller<XY_Side>(), Accelerator( GDK_KEY_KP_Page_Down ) );
2756 GlobalCommands_insert( "ViewFront", FreeCaller<XY_Front>(), Accelerator( GDK_KEY_KP_End ) );
2757 GlobalCommands_insert( "Zoom100", FreeCaller<XY_Zoom100>() );
2758 GlobalCommands_insert( "CenterXYView", FreeCaller<XY_Focus>(), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
2760 GlobalPreferenceSystem().registerPreference( "ClipCaulk", BoolImportStringCaller( g_clip_useCaulk ), BoolExportStringCaller( g_clip_useCaulk ) );
2762 GlobalPreferenceSystem().registerPreference( "NewRightClick", BoolImportStringCaller( g_xywindow_globals.m_bRightClick ), BoolExportStringCaller( g_xywindow_globals.m_bRightClick ) );
2763 GlobalPreferenceSystem().registerPreference( "ChaseMouse", BoolImportStringCaller( g_xywindow_globals_private.m_bChaseMouse ), BoolExportStringCaller( g_xywindow_globals_private.m_bChaseMouse ) );
2764 GlobalPreferenceSystem().registerPreference( "SizePainting", BoolImportStringCaller( g_xywindow_globals_private.m_bSizePaint ), BoolExportStringCaller( g_xywindow_globals_private.m_bSizePaint ) );
2765 GlobalPreferenceSystem().registerPreference( "NoStipple", BoolImportStringCaller( g_xywindow_globals.m_bNoStipple ), BoolExportStringCaller( g_xywindow_globals.m_bNoStipple ) );
2766 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", BoolImportStringCaller( g_xywindow_globals_private.show_coordinates ), BoolExportStringCaller( g_xywindow_globals_private.show_coordinates ) );
2767 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", BoolImportStringCaller( g_xywindow_globals_private.show_outline ), BoolExportStringCaller( g_xywindow_globals_private.show_outline ) );
2768 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", BoolImportStringCaller( g_xywindow_globals_private.show_axis ), BoolExportStringCaller( g_xywindow_globals_private.show_axis ) );
2769 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", BoolImportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ), BoolExportStringCaller( g_xywindow_globals_private.m_bCamXYUpdate ) );
2770 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", BoolImportStringCaller( g_xywindow_globals_private.d_show_work ), BoolExportStringCaller( g_xywindow_globals_private.d_show_work ) );
2772 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", Vector3ImportStringCaller( g_xywindow_globals.AxisColorX ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorX ) );
2773 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", Vector3ImportStringCaller( g_xywindow_globals.AxisColorY ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorY ) );
2774 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", Vector3ImportStringCaller( g_xywindow_globals.AxisColorZ ), Vector3ExportStringCaller( g_xywindow_globals.AxisColorZ ) );
2775 GlobalPreferenceSystem().registerPreference( "SI_Colors1", Vector3ImportStringCaller( g_xywindow_globals.color_gridback ), Vector3ExportStringCaller( g_xywindow_globals.color_gridback ) );
2776 GlobalPreferenceSystem().registerPreference( "SI_Colors2", Vector3ImportStringCaller( g_xywindow_globals.color_gridminor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridminor ) );
2777 GlobalPreferenceSystem().registerPreference( "SI_Colors3", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor ) );
2778 GlobalPreferenceSystem().registerPreference( "SI_Colors6", Vector3ImportStringCaller( g_xywindow_globals.color_gridblock ), Vector3ExportStringCaller( g_xywindow_globals.color_gridblock ) );
2779 GlobalPreferenceSystem().registerPreference( "SI_Colors7", Vector3ImportStringCaller( g_xywindow_globals.color_gridtext ), Vector3ExportStringCaller( g_xywindow_globals.color_gridtext ) );
2780 GlobalPreferenceSystem().registerPreference( "SI_Colors8", Vector3ImportStringCaller( g_xywindow_globals.color_brushes ), Vector3ExportStringCaller( g_xywindow_globals.color_brushes ) );
2781 GlobalPreferenceSystem().registerPreference( "SI_Colors14", Vector3ImportStringCaller( g_xywindow_globals.color_gridmajor_alt ), Vector3ExportStringCaller( g_xywindow_globals.color_gridmajor_alt ) );
2784 GlobalPreferenceSystem().registerPreference( "XZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_xz_front_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_xz_front_shown ) ) );
2785 GlobalPreferenceSystem().registerPreference( "YZVIS", makeBoolStringImportCallback( ToggleShownImportBoolCaller( g_yz_side_shown ) ), makeBoolStringExportCallback( ToggleShownExportBoolCaller( g_yz_side_shown ) ) );
2787 Orthographic_registerPreferencesPage();
2788 Clipper_registerPreferencesPage();
2790 XYWnd::captureStates();
2791 GlobalEntityClassManager().attach( g_EntityClassMenu );
2794 void XYWindow_Destroy(){
2795 GlobalEntityClassManager().detach( g_EntityClassMenu );
2796 XYWnd::releaseStates();