2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // Leonardo Zide (leo@lokigames.com)
32 #include "debugging/debugging.h"
39 #include "ifilesystem.h"
42 #include "gtkutil/messagebox.h"
44 #include <uilib/uilib.h>
45 #include <gdk/gdkkeysyms.h>
47 #include "generic/callback.h"
48 #include "string/string.h"
49 #include "stream/stringstream.h"
52 #include "eclasslib.h"
54 #include "moduleobserver.h"
56 #include "gtkutil/menu.h"
57 #include "gtkutil/container.h"
58 #include "gtkutil/widget.h"
59 #include "gtkutil/glwidget.h"
60 #include "gtkutil/filechooser.h"
61 #include "gtkutil/cursor.h"
65 #include "brushmanip.h"
66 #include "selection.h"
68 #include "camwindow.h"
69 #include "texwindow.h"
70 #include "mainframe.h"
71 #include "preferences.h"
75 #include "windowobservers.h"
77 void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight );
80 extern bool g_brush_always_caulk;
86 Vector3 m_ptClip; // the 3d point
93 m_ptClip[0] = m_ptClip[1] = m_ptClip[2] = 0.0;
107 /*! Draw clip/path point with rasterized number label */
108 void Draw( int num, float scale );
109 /*! Draw clip/path point with rasterized string label */
110 void Draw( const char *label, float scale );
113 VIEWTYPE g_clip_viewtype;
114 bool g_bSwitch = true;
115 bool g_clip_useCaulk = false;
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;
354 xywindow_globals_private_t() :
358 show_coordinates( true ),
360 show_outline( false ),
363 d_show_work( false ),
365 show_blocks( false ),
367 m_bCamXYUpdate( true ),
368 m_bChaseMouse( true ),
369 m_bSizePaint( true ),
371 g_bCrossHairs( false ){
376 xywindow_globals_t g_xywindow_globals;
377 xywindow_globals_private_t g_xywindow_globals_private;
379 const unsigned int RAD_NONE = 0x00;
380 const unsigned int RAD_SHIFT = 0x01;
381 const unsigned int RAD_ALT = 0x02;
382 const unsigned int RAD_CONTROL = 0x04;
383 const unsigned int RAD_PRESS = 0x08;
384 const unsigned int RAD_LBUTTON = 0x10;
385 const unsigned int RAD_MBUTTON = 0x20;
386 const unsigned int RAD_RBUTTON = 0x40;
388 inline ButtonIdentifier button_for_flags( unsigned int flags ){
389 if ( flags & RAD_LBUTTON ) {
392 if ( flags & RAD_RBUTTON ) {
393 return c_buttonRight;
395 if ( flags & RAD_MBUTTON ) {
396 return c_buttonMiddle;
398 return c_buttonInvalid;
401 inline ModifierFlags modifiers_for_flags( unsigned int flags ){
402 ModifierFlags modifiers = c_modifierNone;
403 if ( flags & RAD_SHIFT ) {
404 modifiers |= c_modifierShift;
406 if ( flags & RAD_CONTROL ) {
407 modifiers |= c_modifierControl;
409 if ( flags & RAD_ALT ) {
410 modifiers |= c_modifierAlt;
415 inline unsigned int buttons_for_button_and_modifiers( ButtonIdentifier button, ModifierFlags flags ){
416 unsigned int buttons = 0;
418 switch ( button.get() )
420 case ButtonEnumeration::INVALID: break;
421 case ButtonEnumeration::LEFT: buttons |= RAD_LBUTTON; break;
422 case ButtonEnumeration::MIDDLE: buttons |= RAD_MBUTTON; break;
423 case ButtonEnumeration::RIGHT: buttons |= RAD_RBUTTON; break;
426 if ( bitfield_enabled( flags, c_modifierControl ) ) {
427 buttons |= RAD_CONTROL;
430 if ( bitfield_enabled( flags, c_modifierShift ) ) {
431 buttons |= RAD_SHIFT;
434 if ( bitfield_enabled( flags, c_modifierAlt ) ) {
441 inline unsigned int buttons_for_event_button( GdkEventButton* event ){
442 unsigned int flags = 0;
444 switch ( event->button )
446 case 1: flags |= RAD_LBUTTON; break;
447 case 2: flags |= RAD_MBUTTON; break;
448 case 3: flags |= RAD_RBUTTON; break;
451 if ( ( event->state & GDK_CONTROL_MASK ) != 0 ) {
452 flags |= RAD_CONTROL;
455 if ( ( event->state & GDK_SHIFT_MASK ) != 0 ) {
459 if ( ( event->state & GDK_MOD1_MASK ) != 0 ) {
466 inline unsigned int buttons_for_state( guint state ){
467 unsigned int flags = 0;
469 if ( ( state & GDK_BUTTON1_MASK ) != 0 ) {
470 flags |= RAD_LBUTTON;
473 if ( ( state & GDK_BUTTON2_MASK ) != 0 ) {
474 flags |= RAD_MBUTTON;
477 if ( ( state & GDK_BUTTON3_MASK ) != 0 ) {
478 flags |= RAD_RBUTTON;
481 if ( ( state & GDK_CONTROL_MASK ) != 0 ) {
482 flags |= RAD_CONTROL;
485 if ( ( state & GDK_SHIFT_MASK ) != 0 ) {
489 if ( ( state & GDK_MOD1_MASK ) != 0 ) {
497 void XYWnd::SetScale( float f ){
501 XYWnd_Update( *this );
504 void XYWnd_ZoomIn( XYWnd* xy ){
505 float max_scale = 64;
506 float scale = xy->Scale() * 5.0f / 4.0f;
507 if ( scale > max_scale ) {
508 if ( xy->Scale() != max_scale ) {
509 xy->SetScale( max_scale );
514 xy->SetScale( scale );
519 // NOTE: the zoom out factor is 4/5, we could think about customizing it
520 // we don't go below a zoom factor corresponding to 10% of the max world size
521 // (this has to be computed against the window size)
522 void XYWnd_ZoomOut( XYWnd* xy ){
523 float min_scale = MIN( xy->Width(),xy->Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
524 float scale = xy->Scale() * 4.0f / 5.0f;
525 if ( scale < min_scale ) {
526 if ( xy->Scale() != min_scale ) {
527 xy->SetScale( min_scale );
532 xy->SetScale( scale );
536 void XYWnd::Redraw() {
537 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
538 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
539 GlobalOpenGL_debugAssertNoErrors();
541 GlobalOpenGL_debugAssertNoErrors();
543 m_XORRectangle.set( rectangle_t() );
545 glwidget_swap_buffers( m_gl_widget );
549 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
550 ASSERT_NOTNULL( g_pParentWnd );
551 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
552 return g_pParentWnd->ActiveXY()->GetViewType();
555 // =============================================================================
558 ui::Menu XYWnd::m_mnuDrop(ui::null);
560 // this is disabled, and broken
561 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
565 width = g_pParentWnd->ActiveXY()->Width();
566 height = g_pParentWnd->ActiveXY()->Height();
568 const char* filename;
570 filename = ui::file_dialog( MainFrame_getWindow( ), FALSE, "Save Image", 0, FILTER_BMP );
575 g_pParentWnd->ActiveXY()->MakeCurrent();
576 img = (unsigned char*)malloc( width * height * 3 );
577 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
580 fp = fopen( filename, "wb" );
583 unsigned long cmap, bfSize;
587 bfSize = 54 + width * height * 3;
589 long byteswritten = 0;
590 long pixoff = 54 + cmap * 4;
592 char m1 = 'B', m2 = 'M';
593 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
594 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
595 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
596 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
597 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
598 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
600 unsigned long biSize = 40, compress = 0, size = 0;
602 unsigned short planes = 1;
603 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
604 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
605 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
606 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
607 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
608 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
609 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
610 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
611 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
612 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
613 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
615 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
616 long row, row_size = width * 3;
617 for ( row = 0; row < height; row++ )
619 unsigned char* buf = img + row * row_size;
623 for ( col = 0; col < row_size; col += 3 )
625 putc( buf[col + 2], fp );
626 putc( buf[col + 1], fp );
627 putc( buf[col], fp );
629 byteswritten += row_size;
632 for ( count = row_size; count < widthDW; count++ )
634 putc( 0, fp ); // dummy
649 Timer g_chasemouse_timer;
651 void XYWnd::ChaseMouse(){
652 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
653 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
655 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
657 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
658 g_chasemouse_timer.start();
661 gboolean xywnd_chasemouse( gpointer data ){
662 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
666 inline const int& min_int( const int& left, const int& right ){
667 return std::min( left, right );
670 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
671 m_chasemouse_delta_x = 0;
672 m_chasemouse_delta_y = 0;
674 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
675 const int epsilon = 16;
677 if ( pointx < epsilon ) {
678 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
680 else if ( ( pointx - m_nWidth ) > -epsilon ) {
681 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
684 if ( pointy < epsilon ) {
685 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
687 else if ( ( pointy - m_nHeight ) > -epsilon ) {
688 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
691 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
692 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
693 m_chasemouse_current_x = pointx;
694 m_chasemouse_current_y = pointy;
695 if ( m_chasemouse_handler == 0 ) {
696 //globalOutputStream() << "chasemouse timer start... ";
697 g_chasemouse_timer.start();
698 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
704 if ( m_chasemouse_handler != 0 ) {
705 //globalOutputStream() << "chasemouse cancel\n";
706 g_source_remove( m_chasemouse_handler );
707 m_chasemouse_handler = 0;
713 if ( m_chasemouse_handler != 0 ) {
714 //globalOutputStream() << "chasemouse cancel\n";
715 g_source_remove( m_chasemouse_handler );
716 m_chasemouse_handler = 0;
722 // =============================================================================
724 Shader* XYWnd::m_state_selected = 0;
726 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
727 if ( self.GetWidget().visible() ) {
728 self.m_XORRectangle.set( rectangle_from_area( area.min, area.max, self.Width(), self.Height() ) );
732 gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
733 if ( event->type == GDK_BUTTON_PRESS ) {
734 g_pParentWnd->SetActiveXY( xywnd );
736 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
738 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
743 gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
744 if ( event->type == GDK_BUTTON_RELEASE ) {
745 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
747 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
752 gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
753 if ( event->type == GDK_FOCUS_CHANGE ) {
755 g_pParentWnd->SetActiveXY( xywnd );
761 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
762 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
765 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
768 gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
769 if ( event->direction == GDK_SCROLL_UP ) {
770 XYWnd_ZoomIn( xywnd );
772 else if ( event->direction == GDK_SCROLL_DOWN ) {
773 XYWnd_ZoomOut( xywnd );
778 gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){
779 xywnd->m_nWidth = allocation->width;
780 xywnd->m_nHeight = allocation->height;
781 xywnd->updateProjection();
782 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
786 gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
791 void XYWnd_CameraMoved( XYWnd& xywnd ){
792 if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
793 XYWnd_Update( xywnd );
798 m_gl_widget( glwidget_new( FALSE ) ),
799 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
800 m_deferred_motion( xywnd_motion, this ),
801 m_parent( ui::null ),
802 m_window_observer( NewWindowObserver() ),
803 m_XORRectangle( m_gl_widget ),
804 m_chasemouse_handler( 0 ) {
809 m_bNewBrushDrag = false;
810 m_move_started = false;
811 m_zoom_started = false;
822 m_backgroundActivated = false;
829 m_entityCreate = false;
831 m_mnuDrop = ui::Menu(ui::null);
833 GlobalWindowObservers_add( m_window_observer );
834 GlobalWindowObservers_connectWidget( m_gl_widget );
836 m_window_observer->setRectangleDrawCallback( ReferenceCaller<XYWnd, void(rect_t), xy_update_xor_rectangle>( *this ) );
837 m_window_observer->setView( m_view );
839 g_object_ref( m_gl_widget._handle );
841 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 );
842 gtk_widget_set_can_focus( m_gl_widget, true );
844 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
845 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
847 m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
848 m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
849 m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this );
850 m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
852 m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
854 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
856 // This reconstruct=false argument is used to avoid a circular dependency
857 // between modelview and projection initialization and a valgrind complaint
858 updateProjection( false );
859 updateModelview( false );
860 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
862 AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) );
863 AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) );
865 PressedButtons_connect( g_pressedButtons, m_gl_widget );
867 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
875 m_mnuDrop = ui::Menu(ui::null);
878 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
879 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
883 m_window_observer->release();
886 void XYWnd::captureStates(){
887 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
890 void XYWnd::releaseStates(){
891 GlobalShaderCache().release( "$XY_OVERLAY" );
894 const Vector3& XYWnd::GetOrigin(){
898 void XYWnd::SetOrigin( const Vector3& origin ){
903 void XYWnd::Scroll( int x, int y ){
904 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
905 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
906 m_vOrigin[nDim1] += x / m_fScale;
907 m_vOrigin[nDim2] += y / m_fScale;
912 unsigned int Clipper_buttons(){
916 void XYWnd::DropClipPoint( int pointx, int pointy ){
919 XY_ToPoint( pointx, pointy, point );
922 Select_GetMid( mid );
923 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
924 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
925 point[nDim] = mid[nDim];
926 vector3_snap( point, GetSnapGridSize() );
927 NewClipPoint( point );
930 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
931 Vector3 mousePosition;
932 XY_ToPoint( x, y, mousePosition );
933 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
934 if ( !g_pMovingClip ) {
935 DropClipPoint( x, y );
939 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
940 if ( g_pMovingClip ) {
945 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
946 if ( g_pMovingClip ) {
947 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
948 XY_SnapToGrid( g_pMovingClip->m_ptClip );
950 ClipperChangeNotify();
954 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
955 Vector3 mousePosition;
956 XY_ToPoint( x, y, mousePosition );
957 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
958 set_cursor ( m_gl_widget, GDK_CROSSHAIR );
962 default_cursor( m_gl_widget );
966 unsigned int MoveCamera_buttons(){
967 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
970 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
971 Vector3 origin( Camera_getOrigin( camwnd ) );
972 xywnd->XY_ToPoint( x, y, origin );
973 xywnd->XY_SnapToGrid( origin );
974 Camera_setOrigin( camwnd, origin );
977 unsigned int OrientCamera_buttons(){
978 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
979 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
984 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
985 Vector3 point = g_vector3_identity;
986 xywnd->XY_ToPoint( x, y, point );
987 xywnd->XY_SnapToGrid( point );
988 vector3_subtract( point, Camera_getOrigin( camwnd ) );
990 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
991 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
992 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
993 if ( point[n1] || point[n2] ) {
994 Vector3 angles( Camera_getAngles( camwnd ) );
995 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
996 Camera_setAngles( camwnd, angles );
1005 unsigned int NewBrushDrag_buttons(){
1009 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1011 m_nNewBrushPressx = x;
1012 m_nNewBrushPressy = y;
1014 m_bNewBrushDrag = true;
1015 GlobalUndoSystem().start();
1018 void XYWnd::NewBrushDrag_End( int x, int y ){
1019 if ( m_NewBrushDrag != 0 ) {
1020 GlobalUndoSystem().finish( "brushDragNew" );
1024 void XYWnd::NewBrushDrag( int x, int y ){
1026 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1027 XY_SnapToGrid( mins );
1028 XY_ToPoint( x, y, maxs );
1029 XY_SnapToGrid( maxs );
1031 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1033 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1034 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1036 if ( maxs[nDim] <= mins[nDim] ) {
1037 maxs[nDim] = mins[nDim] + GetGridSize();
1040 for ( int i = 0 ; i < 3 ; i++ )
1042 if ( mins[i] == maxs[i] ) {
1043 return; // don't create a degenerate brush
1045 if ( mins[i] > maxs[i] ) {
1046 float temp = mins[i];
1052 if ( m_NewBrushDrag == 0 ) {
1053 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1054 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1056 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1057 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1058 brushpath.push( makeReference( node.get() ) );
1059 selectPath( brushpath, true );
1061 m_NewBrushDrag = node.get_pointer();
1065 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1066 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1067 g_brush_always_caulk ?
1068 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1071 void entitycreate_activated( ui::Widget item ){
1072 scene::Node* world_node = Map_FindWorldspawn( g_map );
1073 const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) );
1075 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1076 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1079 GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(),
1080 "There's already a worldspawn in your map!",
1087 void EntityClassMenu_addItem( ui::Menu menu, const char* name ){
1088 auto item = ui::MenuItem( name );
1089 item.connect( "activate", G_CALLBACK( entitycreate_activated ), item );
1091 menu_add_item( menu, item );
1094 class EntityClassMenuInserter : public EntityClassVisitor
1096 typedef std::pair<ui::Menu, CopiedString> MenuPair;
1097 typedef std::vector<MenuPair> MenuStack;
1099 CopiedString m_previous;
1101 EntityClassMenuInserter( ui::Menu menu ){
1102 m_stack.reserve( 2 );
1103 m_stack.push_back( MenuPair( menu, "" ) );
1105 ~EntityClassMenuInserter(){
1106 if ( !string_empty( m_previous.c_str() ) ) {
1107 addItem( m_previous.c_str(), "" );
1110 void visit( EntityClass* e ){
1111 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1112 if ( !string_empty( m_previous.c_str() ) ) {
1113 addItem( m_previous.c_str(), e->name() );
1115 m_previous = e->name();
1117 void pushMenu( const CopiedString& name ){
1118 auto item = ui::MenuItem( name.c_str() );
1120 m_stack.back().first.add(item);
1122 auto submenu = ui::Menu(ui::New);
1123 gtk_menu_item_set_submenu( item, submenu );
1125 m_stack.push_back( MenuPair( submenu, name ) );
1130 void addItem( const char* name, const char* next ){
1131 const char* underscore = strchr( name, '_' );
1133 if ( underscore != 0 && underscore != name ) {
1134 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1135 const char* parent = m_stack.back().second.c_str();
1137 if ( !string_empty( parent )
1138 && string_length( parent ) == std::size_t( underscore - name )
1139 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1141 else if ( nextEqual ) {
1142 if ( m_stack.size() == 2 ) {
1145 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1147 else if ( m_stack.size() == 2 ) {
1151 else if ( m_stack.size() == 2 ) {
1155 EntityClassMenu_addItem( m_stack.back().first, name );
1159 void XYWnd::OnContextMenu(){
1160 if ( g_xywindow_globals.m_bRightClick == false ) {
1164 if ( !m_mnuDrop ) { // first time, load it up
1165 auto menu = m_mnuDrop = ui::Menu(ui::New);
1167 EntityClassMenuInserter inserter( menu );
1168 GlobalEntityClassManager().forEach( inserter );
1171 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1174 FreezePointer g_xywnd_freezePointer;
1176 unsigned int Move_buttons(){
1180 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1181 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1182 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1185 gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1190 void XYWnd::Move_Begin(){
1191 if ( m_move_started ) {
1194 m_move_started = true;
1195 g_xywnd_freezePointer.freeze_pointer( m_gl_widget, XYWnd_moveDelta, this );
1196 m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1199 void XYWnd::Move_End(){
1200 m_move_started = false;
1201 g_xywnd_freezePointer.unfreeze_pointer( m_gl_widget );
1202 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1205 unsigned int Zoom_buttons(){
1206 return RAD_RBUTTON | RAD_SHIFT;
1211 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1215 while ( abs( g_dragZoom ) > 8 )
1217 if ( g_dragZoom > 0 ) {
1218 XYWnd_ZoomOut( reinterpret_cast<XYWnd*>( data ) );
1223 XYWnd_ZoomIn( reinterpret_cast<XYWnd*>( data ) );
1230 gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1235 void XYWnd::Zoom_Begin(){
1236 if ( m_zoom_started ) {
1239 m_zoom_started = true;
1241 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
1242 m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1245 void XYWnd::Zoom_End(){
1246 m_zoom_started = false;
1247 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow() );
1248 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1251 // makes sure the selected brush or camera is in view
1252 void XYWnd::PositionView( const Vector3& position ){
1253 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1254 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1256 m_vOrigin[nDim1] = position[nDim1];
1257 m_vOrigin[nDim2] = position[nDim2];
1261 XYWnd_Update( *this );
1264 void XYWnd::SetViewType( VIEWTYPE viewType ){
1265 m_viewType = viewType;
1269 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1274 inline WindowVector WindowVector_forInteger( int x, int y ){
1275 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1278 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1279 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1281 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1282 if ( buttons == Move_buttons() ) {
1284 EntityCreate_MouseDown( x, y );
1286 else if ( buttons == Zoom_buttons() ) {
1289 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1290 Clipper_OnLButtonDown( x, y );
1292 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1293 NewBrushDrag_Begin( x, y );
1295 // control mbutton = move camera
1296 else if ( buttons == MoveCamera_buttons() ) {
1297 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1299 // mbutton = angle camera
1300 else if ( buttons == OrientCamera_buttons() ) {
1301 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1305 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1309 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1310 if ( m_move_started ) {
1312 EntityCreate_MouseUp( x, y );
1314 else if ( m_zoom_started ) {
1317 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1318 Clipper_OnLButtonUp( x, y );
1320 else if ( m_bNewBrushDrag ) {
1321 m_bNewBrushDrag = false;
1322 NewBrushDrag_End( x, y );
1326 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1330 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1331 // rbutton = drag xy origin
1332 if ( m_move_started ) {
1335 else if ( m_zoom_started ) {
1338 else if ( ClipMode() && g_pMovingClip != 0 ) {
1339 Clipper_OnMouseMoved( x, y );
1341 // lbutton without selection = drag new brush
1342 else if ( m_bNewBrushDrag ) {
1343 NewBrushDrag( x, y );
1346 // control mbutton = move camera
1347 else if ( getButtonState() == MoveCamera_buttons() ) {
1348 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1351 // mbutton = angle camera
1352 else if ( getButtonState() == OrientCamera_buttons() ) {
1353 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1358 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1360 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1361 XY_ToPoint( x, y, m_mousePosition );
1362 XY_SnapToGrid( m_mousePosition );
1364 StringOutputStream status( 64 );
1365 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1366 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1367 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1368 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1370 if ( g_xywindow_globals_private.g_bCrossHairs ) {
1371 XYWnd_Update( *this );
1374 Clipper_Crosshair_OnMouseMoved( x, y );
1378 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1379 m_entityCreate = true;
1380 m_entityCreate_x = x;
1381 m_entityCreate_y = y;
1384 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1385 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1386 m_entityCreate = false;
1390 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1391 if ( m_entityCreate ) {
1392 m_entityCreate = false;
1397 inline float screen_normalised( int pos, unsigned int size ){
1398 return ( ( 2.0f * pos ) / size ) - 1.0f;
1401 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1402 return world_origin + normalised * normalised2world_scale;
1406 // TTimo: watch it, this doesn't init one of the 3 coords
1407 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1408 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1409 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1410 if ( m_viewType == XY ) {
1411 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1412 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1414 else if ( m_viewType == YZ ) {
1415 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1416 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1420 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1421 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1425 void XYWnd::XY_SnapToGrid( Vector3& point ){
1426 if ( m_viewType == XY ) {
1427 point[0] = float_snapped( point[0], GetSnapGridSize() );
1428 point[1] = float_snapped( point[1], GetSnapGridSize() );
1430 else if ( m_viewType == YZ ) {
1431 point[1] = float_snapped( point[1], GetSnapGridSize() );
1432 point[2] = float_snapped( point[2], GetSnapGridSize() );
1436 point[0] = float_snapped( point[0], GetSnapGridSize() );
1437 point[2] = float_snapped( point[2], GetSnapGridSize() );
1441 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1442 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1443 if ( relative == name ) {
1444 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1447 char fileNameWithoutExt[512];
1448 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1449 fileNameWithoutExt[512 - 1] = '\0';
1450 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1452 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1454 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1457 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1458 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1459 globalOutputStream() << "Loaded background texture " << relative << "\n";
1460 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1463 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1480 Select_GetBounds( min, max );
1481 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1482 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1483 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1484 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1487 void XYWnd::XY_DisableBackground( void ){
1488 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1489 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1490 free( g_pParentWnd->ActiveXY()->m_tex );
1492 g_pParentWnd->ActiveXY()->m_tex = NULL;
1495 void WXY_BackgroundSelect( void ){
1496 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1498 ui::Window main_window = MainFrame_getWindow();
1500 if ( !brushesSelected ) {
1501 ui::alert( main_window, "You have to select some brushes to get the bounding box for.\n",
1502 "No selection", ui::alert_type::OK, ui::alert_icon::Error );
1506 const char *filename = main_window.file_dialog( TRUE, "Background Image", NULL, NULL );
1508 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1511 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1514 // Draw the background image immediately (do not wait for user input).
1515 g_pParentWnd->ActiveXY()->Redraw();
1519 ============================================================================
1523 ============================================================================
1532 double two_to_the_power( int power ){
1533 return pow( 2.0f, power );
1536 void XYWnd::XY_DrawAxis( void ){
1537 if ( g_xywindow_globals_private.show_axis ) {
1538 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1539 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1540 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1541 const int w = ( m_nWidth / 2 / m_fScale );
1542 const int h = ( m_nHeight / 2 / m_fScale );
1544 const Vector3& colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1545 const Vector3& colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1547 // draw two lines with corresponding axis colors to highlight current view
1548 // horizontal line: nDim1 color
1550 glBegin( GL_LINES );
1551 glColor3fv( vector3_to_array( colourX ) );
1552 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1553 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1555 glVertex2f( 32 / m_fScale, 0 );
1556 glColor3fv( vector3_to_array( colourY ) );
1557 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1558 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1560 glVertex2f( 0, 32 / m_fScale );
1563 // now print axis symbols
1564 glColor3fv( vector3_to_array( colourX ) );
1565 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1566 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1567 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1568 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1569 glColor3fv( vector3_to_array( colourY ) );
1570 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1571 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1572 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1573 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1577 void XYWnd::XY_DrawBackground( void ){
1578 glPushAttrib( GL_ALL_ATTRIB_BITS );
1580 glEnable( GL_TEXTURE_2D );
1581 glEnable( GL_BLEND );
1582 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1583 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1584 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1585 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1587 glPolygonMode( GL_FRONT, GL_FILL );
1589 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1590 glBegin( GL_QUADS );
1592 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1593 glTexCoord2f( 0.0, 1.0 );
1594 glVertex2f( m_xmin, m_ymin );
1596 glTexCoord2f( 1.0, 1.0 );
1597 glVertex2f( m_xmax, m_ymin );
1599 glTexCoord2f( 1.0, 0.0 );
1600 glVertex2f( m_xmax, m_ymax );
1602 glTexCoord2f( 0.0, 0.0 );
1603 glVertex2f( m_xmin, m_ymax );
1606 glBindTexture( GL_TEXTURE_2D, 0 );
1611 void XYWnd::XY_DrawGrid( void ) {
1612 float x, y, xb, xe, yb, ye;
1615 float step, minor_step, stepx, stepy;
1616 step = minor_step = stepx = stepy = GetGridSize();
1618 int minor_power = Grid_getPower();
1621 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1625 int power = minor_power;
1626 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1628 step = float(two_to_the_power( power ) );
1630 mask = ( 1 << ( power - minor_power ) ) - 1;
1631 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1633 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1636 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1638 glDisable( GL_TEXTURE_2D );
1639 glDisable( GL_TEXTURE_1D );
1640 glDisable( GL_DEPTH_TEST );
1641 glDisable( GL_BLEND );
1644 w = ( m_nWidth / 2 / m_fScale );
1645 h = ( m_nHeight / 2 / m_fScale );
1647 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1648 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1650 xb = m_vOrigin[nDim1] - w;
1651 if ( xb < region_mins[nDim1] ) {
1652 xb = region_mins[nDim1];
1654 xb = step * floor( xb / step );
1656 xe = m_vOrigin[nDim1] + w;
1657 if ( xe > region_maxs[nDim1] ) {
1658 xe = region_maxs[nDim1];
1660 xe = step * ceil( xe / step );
1662 yb = m_vOrigin[nDim2] - h;
1663 if ( yb < region_mins[nDim2] ) {
1664 yb = region_mins[nDim2];
1666 yb = step * floor( yb / step );
1668 ye = m_vOrigin[nDim2] + h;
1669 if ( ye > region_maxs[nDim2] ) {
1670 ye = region_maxs[nDim2];
1672 ye = step * ceil( ye / step );
1674 #define COLORS_DIFFER( a,b ) \
1675 ( ( a )[0] != ( b )[0] || \
1676 ( a )[1] != ( b )[1] || \
1677 ( a )[2] != ( b )[2] )
1680 // draw minor blocks
1681 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1683 glEnable( GL_BLEND );
1686 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1687 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1689 glBegin( GL_LINES );
1691 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1692 if ( ( i & mask ) != 0 ) {
1693 glVertex2f( x, yb );
1694 glVertex2f( x, ye );
1698 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1699 if ( ( i & mask ) != 0 ) {
1700 glVertex2f( xb, y );
1701 glVertex2f( xe, y );
1707 // draw major blocks
1708 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1709 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1711 glBegin( GL_LINES );
1712 for ( x = xb ; x <= xe ; x += step ) {
1713 glVertex2f( x, yb );
1714 glVertex2f( x, ye );
1716 for ( y = yb ; y <= ye ; y += step ) {
1717 glVertex2f( xb, y );
1718 glVertex2f( xe, y );
1724 glDisable( GL_BLEND );
1728 // draw coordinate text if needed
1729 if ( g_xywindow_globals_private.show_coordinates ) {
1730 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1731 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1732 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1733 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1734 glRasterPos2f( x, offx );
1735 sprintf( text, "%g", x );
1736 GlobalOpenGL().drawString( text );
1738 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1739 glRasterPos2f( offy, y );
1740 sprintf( text, "%g", y );
1741 GlobalOpenGL().drawString( text );
1745 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1748 // we do this part (the old way) only if show_axis is disabled
1749 if ( !g_xywindow_globals_private.show_axis ) {
1750 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1752 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1756 XYWnd::XY_DrawAxis();
1758 // show current work zone?
1759 // the work zone is used to place dropped points and brushes
1760 if ( g_xywindow_globals_private.d_show_work ) {
1761 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1762 glBegin( GL_LINES );
1763 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1764 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1765 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1766 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1767 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1768 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1769 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1770 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1780 void XYWnd::XY_DrawBlockGrid(){
1781 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1784 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1785 if ( strlen( value ) ) {
1786 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1789 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1790 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1791 g_xywindow_globals_private.blockSize = 1024;
1794 float x, y, xb, xe, yb, ye;
1798 glDisable( GL_TEXTURE_2D );
1799 glDisable( GL_TEXTURE_1D );
1800 glDisable( GL_DEPTH_TEST );
1801 glDisable( GL_BLEND );
1803 w = ( m_nWidth / 2 / m_fScale );
1804 h = ( m_nHeight / 2 / m_fScale );
1806 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1807 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1809 xb = m_vOrigin[nDim1] - w;
1810 if ( xb < region_mins[nDim1] ) {
1811 xb = region_mins[nDim1];
1813 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
1815 xe = m_vOrigin[nDim1] + w;
1816 if ( xe > region_maxs[nDim1] ) {
1817 xe = region_maxs[nDim1];
1819 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
1821 yb = m_vOrigin[nDim2] - h;
1822 if ( yb < region_mins[nDim2] ) {
1823 yb = region_mins[nDim2];
1825 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
1827 ye = m_vOrigin[nDim2] + h;
1828 if ( ye > region_maxs[nDim2] ) {
1829 ye = region_maxs[nDim2];
1831 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
1833 // draw major blocks
1835 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
1838 glBegin( GL_LINES );
1840 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
1842 glVertex2f( x, yb );
1843 glVertex2f( x, ye );
1846 if ( m_viewType == XY ) {
1847 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
1849 glVertex2f( xb, y );
1850 glVertex2f( xe, y );
1857 // draw coordinate text if needed
1859 if ( m_viewType == XY && m_fScale > .1 ) {
1860 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
1861 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
1863 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
1864 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
1865 GlobalOpenGL().drawString( text );
1869 glColor4f( 0, 0, 0, 0 );
1872 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
1873 float x, y, fov, box;
1876 fov = 48 / m_fScale;
1877 box = 16 / m_fScale;
1879 if ( m_viewType == XY ) {
1882 a = degrees_to_radians( angles[CAMERA_YAW] );
1884 else if ( m_viewType == YZ ) {
1887 a = degrees_to_radians( angles[CAMERA_PITCH] );
1893 a = degrees_to_radians( angles[CAMERA_PITCH] );
1896 glColor3f( 0.0, 0.0, 1.0 );
1897 glBegin( GL_LINE_STRIP );
1898 glVertex3f( x - box,y,0 );
1899 glVertex3f( x,y + ( box / 2 ),0 );
1900 glVertex3f( x + box,y,0 );
1901 glVertex3f( x,y - ( box / 2 ),0 );
1902 glVertex3f( x - box,y,0 );
1903 glVertex3f( x + box,y,0 );
1906 glBegin( GL_LINE_STRIP );
1907 glVertex3f( x + static_cast<float>( fov * cos( a + c_pi / 4 ) ), y + static_cast<float>( fov * sin( a + c_pi / 4 ) ), 0 );
1908 glVertex3f( x, y, 0 );
1909 glVertex3f( x + static_cast<float>( fov * cos( a - c_pi / 4 ) ), y + static_cast<float>( fov * sin( a - c_pi / 4 ) ), 0 );
1915 float Betwixt( float f1, float f2 ){
1917 return f2 + ( ( f1 - f2 ) / 2 );
1920 return f1 + ( ( f2 - f1 ) / 2 );
1925 // can be greatly simplified but per usual i am in a hurry
1926 // which is not an excuse, just a fact
1927 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
1928 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
1931 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1932 typedef const char* OrgStrings[2];
1933 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1935 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
1937 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
1938 g_xywindow_globals.color_selbrushes[1] * .65f,
1939 g_xywindow_globals.color_selbrushes[2] * .65f );
1941 StringOutputStream dimensions( 16 );
1943 if ( m_viewType == XY ) {
1944 glBegin( GL_LINES );
1946 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1947 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1949 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1950 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1952 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1953 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1956 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1957 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1959 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1960 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1962 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1963 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1967 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
1968 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1969 GlobalOpenGL().drawString( dimensions.c_str() );
1972 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
1973 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
1974 GlobalOpenGL().drawString( dimensions.c_str() );
1977 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
1978 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
1979 GlobalOpenGL().drawString( dimensions.c_str() );
1981 else if ( m_viewType == XZ ) {
1982 glBegin( GL_LINES );
1984 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
1985 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
1987 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1988 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1990 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
1991 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
1994 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
1995 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
1997 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
1998 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2000 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2001 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2005 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2006 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2007 GlobalOpenGL().drawString( dimensions.c_str() );
2010 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2011 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2012 GlobalOpenGL().drawString( dimensions.c_str() );
2015 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2016 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2017 GlobalOpenGL().drawString( dimensions.c_str() );
2021 glBegin( GL_LINES );
2023 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2024 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2026 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2027 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2029 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2030 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2033 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2034 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2036 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2037 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2039 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2040 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2044 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2045 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2046 GlobalOpenGL().drawString( dimensions.c_str() );
2049 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2050 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2051 GlobalOpenGL().drawString( dimensions.c_str() );
2054 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2055 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2056 GlobalOpenGL().drawString( dimensions.c_str() );
2060 class XYRenderer : public Renderer
2068 unsigned int m_highlight;
2072 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2073 m_globalstate( globalstate ),
2074 m_state_selected( selected ){
2075 ASSERT_NOTNULL( selected );
2076 m_state_stack.push_back( state_type() );
2079 void SetState( Shader* state, EStyle style ){
2080 ASSERT_NOTNULL( state );
2081 if ( style == eWireframeOnly ) {
2082 m_state_stack.back().m_state = state;
2085 EStyle getStyle() const {
2086 return eWireframeOnly;
2089 m_state_stack.push_back( m_state_stack.back() );
2092 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2093 m_state_stack.pop_back();
2095 void Highlight( EHighlightMode mode, bool bEnable = true ){
2097 ? m_state_stack.back().m_highlight |= mode
2098 : m_state_stack.back().m_highlight &= ~mode;
2100 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2101 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2102 m_state_selected->addRenderable( renderable, localToWorld );
2106 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2110 void render( const Matrix4& modelview, const Matrix4& projection ){
2111 GlobalShaderCache().render( m_globalstate, modelview, projection );
2114 std::vector<state_type> m_state_stack;
2115 RenderStateFlags m_globalstate;
2116 Shader* m_state_selected;
2119 void XYWnd::updateProjection( bool reconstruct ){
2120 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2121 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2122 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2124 m_projection[12] = 0.0f;
2125 m_projection[13] = 0.0f;
2126 m_projection[14] = -1.0f;
2138 m_projection[11] = 0.0f;
2140 m_projection[15] = 1.0f;
2143 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2147 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2148 void XYWnd::updateModelview( bool reconstruct ){
2149 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2150 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2153 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2154 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2155 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2158 switch ( m_viewType )
2161 m_modelview[0] = m_fScale;
2166 m_modelview[5] = m_fScale;
2171 m_modelview[10] = -m_fScale;
2174 m_modelview[0] = m_fScale;
2180 m_modelview[6] = m_fScale;
2183 m_modelview[9] = m_fScale;
2184 m_modelview[10] = 0;
2189 m_modelview[2] = -m_fScale;
2191 m_modelview[4] = m_fScale;
2196 m_modelview[9] = m_fScale;
2197 m_modelview[10] = 0;
2201 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2202 m_modelview[15] = 1;
2205 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2215 //#define DBG_SCENEDUMP
2217 void XYWnd::XY_Draw(){
2221 glViewport( 0, 0, m_nWidth, m_nHeight );
2222 glClearColor( g_xywindow_globals.color_gridback[0],
2223 g_xywindow_globals.color_gridback[1],
2224 g_xywindow_globals.color_gridback[2],0 );
2226 glClear( GL_COLOR_BUFFER_BIT );
2232 glMatrixMode( GL_PROJECTION );
2233 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2235 glMatrixMode( GL_MODELVIEW );
2237 glScalef( m_fScale, m_fScale, 1 );
2238 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2239 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2240 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2242 glDisable( GL_LINE_STIPPLE );
2244 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2245 glDisableClientState( GL_NORMAL_ARRAY );
2246 glDisableClientState( GL_COLOR_ARRAY );
2247 glDisable( GL_TEXTURE_2D );
2248 glDisable( GL_LIGHTING );
2249 glDisable( GL_COLOR_MATERIAL );
2250 glDisable( GL_DEPTH_TEST );
2252 if ( m_backgroundActivated ) {
2253 XY_DrawBackground();
2257 if ( g_xywindow_globals_private.show_blocks ) {
2261 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2263 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2264 if ( !g_xywindow_globals.m_bNoStipple ) {
2265 globalstate |= RENDER_LINESTIPPLE;
2269 XYRenderer renderer( globalstate, m_state_selected );
2271 Scene_Render( renderer, m_view );
2273 GlobalOpenGL_debugAssertNoErrors();
2274 renderer.render( m_modelview, m_projection );
2275 GlobalOpenGL_debugAssertNoErrors();
2278 glDepthMask( GL_FALSE );
2280 GlobalOpenGL_debugAssertNoErrors();
2282 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2284 GlobalOpenGL_debugAssertNoErrors();
2285 glDisable( GL_LINE_STIPPLE );
2286 GlobalOpenGL_debugAssertNoErrors();
2288 GlobalOpenGL_debugAssertNoErrors();
2289 if ( GlobalOpenGL().GL_1_3() ) {
2290 glActiveTexture( GL_TEXTURE0 );
2291 glClientActiveTexture( GL_TEXTURE0 );
2293 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2294 GlobalOpenGL_debugAssertNoErrors();
2295 glDisableClientState( GL_NORMAL_ARRAY );
2296 GlobalOpenGL_debugAssertNoErrors();
2297 glDisableClientState( GL_COLOR_ARRAY );
2298 GlobalOpenGL_debugAssertNoErrors();
2299 glDisable( GL_TEXTURE_2D );
2300 GlobalOpenGL_debugAssertNoErrors();
2301 glDisable( GL_LIGHTING );
2302 GlobalOpenGL_debugAssertNoErrors();
2303 glDisable( GL_COLOR_MATERIAL );
2304 GlobalOpenGL_debugAssertNoErrors();
2306 GlobalOpenGL_debugAssertNoErrors();
2310 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2312 Select_GetBounds( min, max );
2313 PaintSizeInfo( nDim1, nDim2, min, max );
2316 if ( g_xywindow_globals_private.g_bCrossHairs ) {
2317 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2318 glBegin( GL_LINES );
2319 if ( m_viewType == XY ) {
2320 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2321 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2322 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2323 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2325 else if ( m_viewType == YZ ) {
2326 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2327 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2328 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2329 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2333 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2334 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2335 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2336 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2342 GlobalClipPoints_Draw( m_fScale );
2345 GlobalOpenGL_debugAssertNoErrors();
2349 glScalef( m_fScale, m_fScale, 1 );
2350 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2352 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2354 Feedback_draw2D( m_viewType );
2356 if ( g_xywindow_globals_private.show_outline ) {
2358 glMatrixMode( GL_PROJECTION );
2360 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2362 glMatrixMode( GL_MODELVIEW );
2365 // four view mode doesn't colorize
2366 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2367 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2371 switch ( m_viewType )
2374 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2377 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2380 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2384 glBegin( GL_LINE_LOOP );
2385 glVertex2f( 0.5, 0.5 );
2386 glVertex2f( m_nWidth - 0.5, 1 );
2387 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2388 glVertex2f( 0.5, m_nHeight - 0.5 );
2393 GlobalOpenGL_debugAssertNoErrors();
2398 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2399 xywnd->XY_ToPoint( x, y, point );
2400 xywnd->XY_SnapToGrid( point );
2402 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2403 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2404 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2407 void XYWnd::OnEntityCreate( const char* item ){
2408 StringOutputStream command;
2409 command << "entityCreate -class " << item;
2410 UndoableCommand undo( command.c_str() );
2412 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2413 Entity_createFromSelection( item, point );
2418 void GetFocusPosition( Vector3& position ){
2419 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2420 Select_GetMid( position );
2424 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2428 void XYWnd_Focus( XYWnd* xywnd ){
2430 GetFocusPosition( position );
2431 xywnd->PositionView( position );
2434 void XY_Split_Focus(){
2436 GetFocusPosition( position );
2437 if ( g_pParentWnd->GetXYWnd() ) {
2438 g_pParentWnd->GetXYWnd()->PositionView( position );
2440 if ( g_pParentWnd->GetXZWnd() ) {
2441 g_pParentWnd->GetXZWnd()->PositionView( position );
2443 if ( g_pParentWnd->GetYZWnd() ) {
2444 g_pParentWnd->GetYZWnd()->PositionView( position );
2449 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2450 // cannot do this in a split window
2451 // do something else that the user may want here
2456 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2457 XYWnd_Focus( xywnd );
2461 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2462 // cannot do this in a split window
2463 // do something else that the user may want here
2468 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2469 xywnd->SetViewType( XY );
2470 XYWnd_Focus( xywnd );
2474 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2475 // cannot do this in a split window
2476 // do something else that the user may want here
2481 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2482 xywnd->SetViewType( XZ );
2483 XYWnd_Focus( xywnd );
2487 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2488 // cannot do this in a split window
2489 // do something else that the user may want here
2494 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2495 xywnd->SetViewType( YZ );
2496 XYWnd_Focus( xywnd );
2500 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2501 // cannot do this in a split window
2502 // do something else that the user may want here
2507 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2508 if ( xywnd->GetViewType() == XY ) {
2509 xywnd->SetViewType( XZ );
2511 else if ( xywnd->GetViewType() == XZ ) {
2512 xywnd->SetViewType( YZ );
2515 xywnd->SetViewType( XY );
2517 XYWnd_Focus( xywnd );
2521 if ( g_pParentWnd->GetXYWnd() ) {
2522 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2524 if ( g_pParentWnd->GetXZWnd() ) {
2525 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2527 if ( g_pParentWnd->GetYZWnd() ) {
2528 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2533 XYWnd_ZoomIn( g_pParentWnd->ActiveXY() );
2536 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2537 // we don't go below a zoom factor corresponding to 10% of the max world size
2538 // (this has to be computed against the window size)
2540 XYWnd_ZoomOut( g_pParentWnd->ActiveXY() );
2545 void ToggleShowCrosshair(){
2546 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2547 XY_UpdateAllWindows();
2550 void ToggleShowSizeInfo(){
2551 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2552 XY_UpdateAllWindows();
2555 void ToggleShowGrid(){
2556 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2557 XY_UpdateAllWindows();
2560 ToggleShown g_xy_top_shown( true );
2562 void XY_Top_Shown_Construct( ui::Window parent ){
2563 g_xy_top_shown.connect( parent );
2566 ToggleShown g_yz_side_shown( false );
2568 void YZ_Side_Shown_Construct( ui::Window parent ){
2569 g_yz_side_shown.connect( parent );
2572 ToggleShown g_xz_front_shown( false );
2574 void XZ_Front_Shown_Construct( ui::Window parent ){
2575 g_xz_front_shown.connect( parent );
2579 class EntityClassMenu : public ModuleObserver
2581 std::size_t m_unrealised;
2583 EntityClassMenu() : m_unrealised( 1 ){
2586 if ( --m_unrealised == 0 ) {
2590 if ( ++m_unrealised == 1 ) {
2591 if ( XYWnd::m_mnuDrop ) {
2592 XYWnd::m_mnuDrop.destroy();
2593 XYWnd::m_mnuDrop = ui::Menu(ui::null);
2599 EntityClassMenu g_EntityClassMenu;
2604 void ShowNamesToggle(){
2605 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2606 XY_UpdateAllWindows();
2608 typedef FreeCaller<void(), ShowNamesToggle> ShowNamesToggleCaller;
2609 void ShowNamesExport( const Callback<void(bool)> & importer ){
2610 importer( GlobalEntityCreator().getShowNames() );
2612 typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller;
2614 void ShowAnglesToggle(){
2615 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2616 XY_UpdateAllWindows();
2618 typedef FreeCaller<void(), ShowAnglesToggle> ShowAnglesToggleCaller;
2619 void ShowAnglesExport( const Callback<void(bool)> & importer ){
2620 importer( GlobalEntityCreator().getShowAngles() );
2622 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAnglesExport> ShowAnglesExportCaller;
2624 void ShowBlocksToggle(){
2625 g_xywindow_globals_private.show_blocks ^= 1;
2626 XY_UpdateAllWindows();
2628 typedef FreeCaller<void(), ShowBlocksToggle> ShowBlocksToggleCaller;
2629 void ShowBlocksExport( const Callback<void(bool)> & importer ){
2630 importer( g_xywindow_globals_private.show_blocks );
2632 typedef FreeCaller<void(const Callback<void(bool)> &), ShowBlocksExport> ShowBlocksExportCaller;
2634 void ShowCoordinatesToggle(){
2635 g_xywindow_globals_private.show_coordinates ^= 1;
2636 XY_UpdateAllWindows();
2638 typedef FreeCaller<void(), ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2639 void ShowCoordinatesExport( const Callback<void(bool)> & importer ){
2640 importer( g_xywindow_globals_private.show_coordinates );
2642 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCoordinatesExport> ShowCoordinatesExportCaller;
2644 void ShowOutlineToggle(){
2645 g_xywindow_globals_private.show_outline ^= 1;
2646 XY_UpdateAllWindows();
2648 typedef FreeCaller<void(), ShowOutlineToggle> ShowOutlineToggleCaller;
2649 void ShowOutlineExport( const Callback<void(bool)> & importer ){
2650 importer( g_xywindow_globals_private.show_outline );
2652 typedef FreeCaller<void(const Callback<void(bool)> &), ShowOutlineExport> ShowOutlineExportCaller;
2654 void ShowAxesToggle(){
2655 g_xywindow_globals_private.show_axis ^= 1;
2656 XY_UpdateAllWindows();
2658 typedef FreeCaller<void(), ShowAxesToggle> ShowAxesToggleCaller;
2659 void ShowAxesExport( const Callback<void(bool)> & importer ){
2660 importer( g_xywindow_globals_private.show_axis );
2662 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAxesExport> ShowAxesExportCaller;
2664 void ShowWorkzoneToggle(){
2665 g_xywindow_globals_private.d_show_work ^= 1;
2666 XY_UpdateAllWindows();
2668 typedef FreeCaller<void(), ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2669 void ShowWorkzoneExport( const Callback<void(bool)> & importer ){
2670 importer( g_xywindow_globals_private.d_show_work );
2672 typedef FreeCaller<void(const Callback<void(bool)> &), ShowWorkzoneExport> ShowWorkzoneExportCaller;
2674 ShowNamesExportCaller g_show_names_caller;
2675 Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller );
2676 ToggleItem g_show_names( g_show_names_callback );
2678 ShowAnglesExportCaller g_show_angles_caller;
2679 Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller );
2680 ToggleItem g_show_angles( g_show_angles_callback );
2682 ShowBlocksExportCaller g_show_blocks_caller;
2683 Callback<void(const Callback<void(bool)> &)> g_show_blocks_callback( g_show_blocks_caller );
2684 ToggleItem g_show_blocks( g_show_blocks_callback );
2686 ShowCoordinatesExportCaller g_show_coordinates_caller;
2687 Callback<void(const Callback<void(bool)> &)> g_show_coordinates_callback( g_show_coordinates_caller );
2688 ToggleItem g_show_coordinates( g_show_coordinates_callback );
2690 ShowOutlineExportCaller g_show_outline_caller;
2691 Callback<void(const Callback<void(bool)> &)> g_show_outline_callback( g_show_outline_caller );
2692 ToggleItem g_show_outline( g_show_outline_callback );
2694 ShowAxesExportCaller g_show_axes_caller;
2695 Callback<void(const Callback<void(bool)> &)> g_show_axes_callback( g_show_axes_caller );
2696 ToggleItem g_show_axes( g_show_axes_callback );
2698 ShowWorkzoneExportCaller g_show_workzone_caller;
2699 Callback<void(const Callback<void(bool)> &)> g_show_workzone_callback( g_show_workzone_caller );
2700 ToggleItem g_show_workzone( g_show_workzone_callback );
2702 void XYShow_registerCommands(){
2703 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2704 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
2705 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2706 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2707 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2708 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2709 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2712 void XYWnd_registerShortcuts(){
2713 command_connect_accelerator( "ToggleCrosshairs" );
2714 command_connect_accelerator( "ToggleSizePaint" );
2719 void Orthographic_constructPreferences( PreferencesPage& page ){
2720 page.appendCheckBox( "", "Solid selection boxes", g_xywindow_globals.m_bNoStipple );
2721 page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2722 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2723 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2725 void Orthographic_constructPage( PreferenceGroup& group ){
2726 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
2727 Orthographic_constructPreferences( page );
2729 void Orthographic_registerPreferencesPage(){
2730 PreferencesDialog_addSettingsPage( makeCallbackF(Orthographic_constructPage) );
2733 void Clipper_constructPreferences( PreferencesPage& page ){
2734 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
2736 void Clipper_constructPage( PreferenceGroup& group ){
2737 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
2738 Clipper_constructPreferences( page );
2740 void Clipper_registerPreferencesPage(){
2741 PreferencesDialog_addSettingsPage( makeCallbackF(Clipper_constructPage) );
2745 #include "preferencesystem.h"
2746 #include "stringio.h"
2749 struct ToggleShown_Bool {
2750 static void Export(const ToggleShown &self, const Callback<void(bool)> &returnz) {
2751 returnz(self.active());
2754 static void Import(ToggleShown &self, bool value) {
2760 void XYWindow_Construct(){
2761 GlobalCommands_insert( "ToggleCrosshairs", makeCallbackF(ToggleShowCrosshair), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2762 GlobalCommands_insert( "ToggleSizePaint", makeCallbackF(ToggleShowSizeInfo), Accelerator( 'J' ) );
2763 GlobalCommands_insert( "ToggleGrid", makeCallbackF(ToggleShowGrid), Accelerator( '0' ) );
2765 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 ) ) );
2766 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
2767 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
2768 GlobalCommands_insert( "NextView", makeCallbackF(XY_Next), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut
2769 GlobalCommands_insert( "ZoomIn", makeCallbackF(XY_ZoomIn), Accelerator( GDK_KEY_Delete ) );
2770 GlobalCommands_insert( "ZoomOut", makeCallbackF(XY_ZoomOut), Accelerator( GDK_KEY_Insert ) );
2771 GlobalCommands_insert( "ViewTop", makeCallbackF(XY_Top), Accelerator( GDK_KEY_KP_Home ) );
2772 GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) );
2773 GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) );
2774 GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) );
2775 GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
2777 GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) );
2779 GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
2780 GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) );
2781 GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) );
2782 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );
2783 GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) );
2784 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) );
2785 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) );
2786 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) );
2787 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
2788 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) );
2790 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) );
2791 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) );
2792 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) );
2793 GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) );
2794 GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) );
2795 GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) );
2796 GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) );
2797 GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) );
2798 GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) );
2799 GlobalPreferenceSystem().registerPreference( "SI_Colors14", make_property_string( g_xywindow_globals.color_gridmajor_alt ) );
2802 GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) );
2803 GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) );
2805 Orthographic_registerPreferencesPage();
2806 Clipper_registerPreferencesPage();
2808 XYWnd::captureStates();
2809 GlobalEntityClassManager().attach( g_EntityClassMenu );
2812 void XYWindow_Destroy(){
2813 GlobalEntityClassManager().detach( g_EntityClassMenu );
2814 XYWnd::releaseStates();