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(){
505 float max_scale = 64;
506 float scale = Scale() * 5.0f / 4.0f;
507 if ( scale > max_scale ) {
508 if ( Scale() != max_scale ) {
509 SetScale( max_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(){
523 float min_scale = MIN( Width(), Height() ) / ( 1.1f * ( g_MaxWorldCoord - g_MinWorldCoord ) );
524 float scale = Scale() * 4.0f / 5.0f;
525 if ( scale < min_scale ) {
526 if ( Scale() != min_scale ) {
527 SetScale( min_scale );
536 void XYWnd::ZoomInWithMouse( int pointx, int pointy ){
537 float old_scale = Scale();
539 if ( g_xywindow_globals.m_bImprovedWheelZoom ) {
540 float scale_diff = 1.0 / old_scale - 1.0 / Scale();
541 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
542 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
543 Vector3 origin = GetOrigin();
544 origin[nDim1] += scale_diff * (pointx - 0.5 * Width());
545 origin[nDim2] -= scale_diff * (pointy - 0.5 * Height());
550 void XYWnd::Redraw() {
551 if ( glwidget_make_current( m_gl_widget ) != FALSE ) {
552 if ( Map_Valid( g_map ) && ScreenUpdates_Enabled() ) {
553 GlobalOpenGL_debugAssertNoErrors();
555 GlobalOpenGL_debugAssertNoErrors();
557 m_XORRectangle.set( rectangle_t() );
559 glwidget_swap_buffers( m_gl_widget );
563 VIEWTYPE GlobalXYWnd_getCurrentViewType(){
564 ASSERT_NOTNULL( g_pParentWnd );
565 ASSERT_NOTNULL( g_pParentWnd->ActiveXY() );
566 return g_pParentWnd->ActiveXY()->GetViewType();
569 // =============================================================================
572 ui::Menu XYWnd::m_mnuDrop(ui::null);
574 // this is disabled, and broken
575 // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
579 width = g_pParentWnd->ActiveXY()->Width();
580 height = g_pParentWnd->ActiveXY()->Height();
582 const char* filename;
584 filename = ui::file_dialog( MainFrame_getWindow( ), FALSE, "Save Image", 0, FILTER_BMP );
589 g_pParentWnd->ActiveXY()->MakeCurrent();
590 img = (unsigned char*)malloc( width * height * 3 );
591 glReadPixels( 0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,img );
594 fp = fopen( filename, "wb" );
597 unsigned long cmap, bfSize;
601 bfSize = 54 + width * height * 3;
603 long byteswritten = 0;
604 long pixoff = 54 + cmap * 4;
606 char m1 = 'B', m2 = 'M';
607 fwrite( &m1, 1, 1, fp ); byteswritten++; // B
608 fwrite( &m2, 1, 1, fp ); byteswritten++; // M
609 fwrite( &bfSize, 4, 1, fp ); byteswritten += 4; // bfSize
610 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved1
611 fwrite( &res, 2, 1, fp ); byteswritten += 2; // bfReserved2
612 fwrite( &pixoff, 4, 1, fp ); byteswritten += 4; // bfOffBits
614 unsigned long biSize = 40, compress = 0, size = 0;
616 unsigned short planes = 1;
617 fwrite( &biSize, 4, 1, fp ); byteswritten += 4; // biSize
618 fwrite( &width, 4, 1, fp ); byteswritten += 4; // biWidth
619 fwrite( &height, 4, 1, fp ); byteswritten += 4; // biHeight
620 fwrite( &planes, 2, 1, fp ); byteswritten += 2; // biPlanes
621 fwrite( &bits, 2, 1, fp ); byteswritten += 2; // biBitCount
622 fwrite( &compress, 4, 1, fp ); byteswritten += 4; // biCompression
623 fwrite( &size, 4, 1, fp ); byteswritten += 4; // biSizeImage
624 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biXPelsPerMeter
625 fwrite( &pixels, 4, 1, fp ); byteswritten += 4; // biYPelsPerMeter
626 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrUsed
627 fwrite( &cmap, 4, 1, fp ); byteswritten += 4; // biClrImportant
629 unsigned long widthDW = ( ( ( width * 24 ) + 31 ) / 32 * 4 );
630 long row, row_size = width * 3;
631 for ( row = 0; row < height; row++ )
633 unsigned char* buf = img + row * row_size;
637 for ( col = 0; col < row_size; col += 3 )
639 putc( buf[col + 2], fp );
640 putc( buf[col + 1], fp );
641 putc( buf[col], fp );
643 byteswritten += row_size;
646 for ( count = row_size; count < widthDW; count++ )
648 putc( 0, fp ); // dummy
663 Timer g_chasemouse_timer;
665 void XYWnd::ChaseMouse(){
666 float multiplier = g_chasemouse_timer.elapsed_msec() / 10.0f;
667 Scroll( float_to_integer( multiplier * m_chasemouse_delta_x ), float_to_integer( multiplier * -m_chasemouse_delta_y ) );
669 //globalOutputStream() << "chasemouse: multiplier=" << multiplier << " x=" << m_chasemouse_delta_x << " y=" << m_chasemouse_delta_y << '\n';
671 XY_MouseMoved( m_chasemouse_current_x, m_chasemouse_current_y, getButtonState() );
672 g_chasemouse_timer.start();
675 gboolean xywnd_chasemouse( gpointer data ){
676 reinterpret_cast<XYWnd*>( data )->ChaseMouse();
680 inline const int& min_int( const int& left, const int& right ){
681 return std::min( left, right );
684 bool XYWnd::chaseMouseMotion( int pointx, int pointy ){
685 m_chasemouse_delta_x = 0;
686 m_chasemouse_delta_y = 0;
688 if ( g_xywindow_globals_private.m_bChaseMouse && getButtonState() == RAD_LBUTTON ) {
689 const int epsilon = 16;
691 if ( pointx < epsilon ) {
692 m_chasemouse_delta_x = std::max( pointx, 0 ) - epsilon;
694 else if ( ( pointx - m_nWidth ) > -epsilon ) {
695 m_chasemouse_delta_x = min_int( ( pointx - m_nWidth ), 0 ) + epsilon;
698 if ( pointy < epsilon ) {
699 m_chasemouse_delta_y = std::max( pointy, 0 ) - epsilon;
701 else if ( ( pointy - m_nHeight ) > -epsilon ) {
702 m_chasemouse_delta_y = min_int( ( pointy - m_nHeight ), 0 ) + epsilon;
705 if ( m_chasemouse_delta_y != 0 || m_chasemouse_delta_x != 0 ) {
706 //globalOutputStream() << "chasemouse motion: x=" << pointx << " y=" << pointy << "... ";
707 m_chasemouse_current_x = pointx;
708 m_chasemouse_current_y = pointy;
709 if ( m_chasemouse_handler == 0 ) {
710 //globalOutputStream() << "chasemouse timer start... ";
711 g_chasemouse_timer.start();
712 m_chasemouse_handler = g_idle_add( xywnd_chasemouse, this );
718 if ( m_chasemouse_handler != 0 ) {
719 //globalOutputStream() << "chasemouse cancel\n";
720 g_source_remove( m_chasemouse_handler );
721 m_chasemouse_handler = 0;
727 if ( m_chasemouse_handler != 0 ) {
728 //globalOutputStream() << "chasemouse cancel\n";
729 g_source_remove( m_chasemouse_handler );
730 m_chasemouse_handler = 0;
736 // =============================================================================
738 Shader* XYWnd::m_state_selected = 0;
740 void xy_update_xor_rectangle( XYWnd& self, rect_t area ){
741 if ( self.GetWidget().visible() ) {
742 rectangle_t rect = rectangle_from_area( area.min, area.max, self.Width(), self.Height() );
743 int nDim1 = ( self.GetViewType() == YZ ) ? 1 : 0;
744 int nDim2 = ( self.GetViewType() == XY ) ? 1 : 2;
745 rect.x /= self.Scale();
746 rect.y /= self.Scale();
747 rect.w /= self.Scale();
748 rect.h /= self.Scale();
749 rect.x += self.GetOrigin()[nDim1];
750 rect.y += self.GetOrigin()[nDim2];
751 self.m_XORRectangle.set( rect );
755 gboolean xywnd_button_press( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
756 if ( event->type == GDK_BUTTON_PRESS ) {
757 g_pParentWnd->SetActiveXY( xywnd );
759 xywnd->ButtonState_onMouseDown( buttons_for_event_button( event ) );
761 xywnd->onMouseDown( WindowVector( event->x, event->y ), button_for_button( event->button ), modifiers_for_state( event->state ) );
766 gboolean xywnd_button_release( ui::Widget widget, GdkEventButton* event, XYWnd* xywnd ){
767 if ( event->type == GDK_BUTTON_RELEASE ) {
768 xywnd->XY_MouseUp( static_cast<int>( event->x ), static_cast<int>( event->y ), buttons_for_event_button( event ) );
770 xywnd->ButtonState_onMouseUp( buttons_for_event_button( event ) );
775 gboolean xywnd_focus_in( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
776 if ( event->type == GDK_FOCUS_CHANGE ) {
778 g_pParentWnd->SetActiveXY( xywnd );
784 void xywnd_motion( gdouble x, gdouble y, guint state, void* data ){
785 if ( reinterpret_cast<XYWnd*>( data )->chaseMouseMotion( static_cast<int>( x ), static_cast<int>( y ) ) ) {
788 reinterpret_cast<XYWnd*>( data )->XY_MouseMoved( static_cast<int>( x ), static_cast<int>( y ), buttons_for_state( state ) );
791 gboolean xywnd_wheel_scroll( ui::Widget widget, GdkEventScroll* event, XYWnd* xywnd ){
792 if ( event->direction == GDK_SCROLL_UP ) {
793 xywnd->ZoomInWithMouse( (int)event->x, (int)event->y );
795 else if ( event->direction == GDK_SCROLL_DOWN ) {
801 gboolean xywnd_size_allocate( ui::Widget widget, GtkAllocation* allocation, XYWnd* xywnd ){
802 xywnd->m_nWidth = allocation->width;
803 xywnd->m_nHeight = allocation->height;
804 xywnd->updateProjection();
805 xywnd->m_window_observer->onSizeChanged( xywnd->Width(), xywnd->Height() );
809 gboolean xywnd_expose( ui::Widget widget, GdkEventExpose* event, XYWnd* xywnd ){
814 void XYWnd_CameraMoved( XYWnd& xywnd ){
815 if ( g_xywindow_globals_private.m_bCamXYUpdate ) {
816 XYWnd_Update( xywnd );
821 m_gl_widget( glwidget_new( FALSE ) ),
822 m_deferredDraw( WidgetQueueDrawCaller( m_gl_widget ) ),
823 m_deferred_motion( xywnd_motion, this ),
824 m_parent( ui::null ),
825 m_window_observer( NewWindowObserver() ),
826 m_XORRectangle( m_gl_widget ),
827 m_chasemouse_handler( 0 ){
832 m_bNewBrushDrag = false;
833 m_move_started = false;
834 m_zoom_started = false;
845 m_backgroundActivated = false;
852 m_entityCreate = false;
854 m_mnuDrop = ui::Menu(ui::null);
856 GlobalWindowObservers_add( m_window_observer );
857 GlobalWindowObservers_connectWidget( m_gl_widget );
859 m_window_observer->setRectangleDrawCallback( ReferenceCaller<XYWnd, void(rect_t), xy_update_xor_rectangle>( *this ) );
860 m_window_observer->setView( m_view );
862 g_object_ref( m_gl_widget._handle );
864 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 );
865 gtk_widget_set_can_focus( m_gl_widget, true );
867 m_sizeHandler = m_gl_widget.connect( "size_allocate", G_CALLBACK( xywnd_size_allocate ), this );
868 m_exposeHandler = m_gl_widget.on_render( G_CALLBACK( xywnd_expose ), this );
870 m_gl_widget.connect( "button_press_event", G_CALLBACK( xywnd_button_press ), this );
871 m_gl_widget.connect( "button_release_event", G_CALLBACK( xywnd_button_release ), this );
872 m_gl_widget.connect( "focus_in_event", G_CALLBACK( xywnd_focus_in ), this );
873 m_gl_widget.connect( "motion_notify_event", G_CALLBACK( DeferredMotion::gtk_motion ), &m_deferred_motion );
875 m_gl_widget.connect( "scroll_event", G_CALLBACK( xywnd_wheel_scroll ), this );
877 Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) );
879 // This reconstruct=false argument is used to avoid a circular dependency
880 // between modelview and projection initialization and a valgrind complaint
881 updateProjection( false );
882 updateModelview( false );
883 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
885 AddSceneChangeCallback( ReferenceCaller<XYWnd, void(), &XYWnd_Update>( *this ) );
886 AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *this ) );
888 PressedButtons_connect( g_pressedButtons, m_gl_widget );
890 onMouseDown.connectLast( makeSignalHandler3( MouseDownCaller(), *this ) );
898 m_mnuDrop = ui::Menu(ui::null);
901 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_sizeHandler );
902 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_exposeHandler );
906 m_window_observer->release();
909 void XYWnd::captureStates(){
910 m_state_selected = GlobalShaderCache().capture( "$XY_OVERLAY" );
913 void XYWnd::releaseStates(){
914 GlobalShaderCache().release( "$XY_OVERLAY" );
917 const Vector3& XYWnd::GetOrigin(){
921 void XYWnd::SetOrigin( const Vector3& origin ){
926 void XYWnd::Scroll( int x, int y ){
927 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
928 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
929 m_vOrigin[nDim1] += x / m_fScale;
930 m_vOrigin[nDim2] += y / m_fScale;
935 unsigned int Clipper_buttons(){
939 void XYWnd::DropClipPoint( int pointx, int pointy ){
942 XY_ToPoint( pointx, pointy, point );
945 Select_GetMid( mid );
946 g_clip_viewtype = static_cast<VIEWTYPE>( GetViewType() );
947 const int nDim = ( g_clip_viewtype == YZ ) ? 0 : ( ( g_clip_viewtype == XZ ) ? 1 : 2 );
948 point[nDim] = mid[nDim];
949 vector3_snap( point, GetSnapGridSize() );
950 NewClipPoint( point );
953 void XYWnd::Clipper_OnLButtonDown( int x, int y ){
954 Vector3 mousePosition;
955 XY_ToPoint( x, y, mousePosition );
956 g_pMovingClip = GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale );
957 if ( !g_pMovingClip ) {
958 DropClipPoint( x, y );
962 void XYWnd::Clipper_OnLButtonUp( int x, int y ){
963 if ( g_pMovingClip ) {
968 void XYWnd::Clipper_OnMouseMoved( int x, int y ){
969 if ( g_pMovingClip ) {
970 XY_ToPoint( x, y, g_pMovingClip->m_ptClip );
971 XY_SnapToGrid( g_pMovingClip->m_ptClip );
973 ClipperChangeNotify();
977 void XYWnd::Clipper_Crosshair_OnMouseMoved( int x, int y ){
978 Vector3 mousePosition;
979 XY_ToPoint( x, y, mousePosition );
980 if ( ClipMode() && GlobalClipPoints_Find( mousePosition, (VIEWTYPE)m_viewType, m_fScale ) != 0 ) {
981 set_cursor ( m_gl_widget, GDK_CROSSHAIR );
985 default_cursor( m_gl_widget );
989 unsigned int MoveCamera_buttons(){
990 return RAD_CONTROL | ( g_glwindow_globals.m_nMouseType == ETwoButton ? RAD_RBUTTON : RAD_MBUTTON );
993 void XYWnd_PositionCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
994 Vector3 origin( Camera_getOrigin( camwnd ) );
995 xywnd->XY_ToPoint( x, y, origin );
996 xywnd->XY_SnapToGrid( origin );
997 Camera_setOrigin( camwnd, origin );
1000 unsigned int OrientCamera_buttons(){
1001 if ( g_glwindow_globals.m_nMouseType == ETwoButton ) {
1002 return RAD_RBUTTON | RAD_SHIFT | RAD_CONTROL;
1007 void XYWnd_OrientCamera( XYWnd* xywnd, int x, int y, CamWnd& camwnd ){
1008 Vector3 point = g_vector3_identity;
1009 xywnd->XY_ToPoint( x, y, point );
1010 xywnd->XY_SnapToGrid( point );
1011 vector3_subtract( point, Camera_getOrigin( camwnd ) );
1013 int n1 = ( xywnd->GetViewType() == XY ) ? 1 : 2;
1014 int n2 = ( xywnd->GetViewType() == YZ ) ? 1 : 0;
1015 int nAngle = ( xywnd->GetViewType() == XY ) ? CAMERA_YAW : CAMERA_PITCH;
1016 if ( point[n1] || point[n2] ) {
1017 Vector3 angles( Camera_getAngles( camwnd ) );
1018 angles[nAngle] = static_cast<float>( radians_to_degrees( atan2( point[n1], point[n2] ) ) );
1019 Camera_setAngles( camwnd, angles );
1028 unsigned int NewBrushDrag_buttons(){
1032 void XYWnd::NewBrushDrag_Begin( int x, int y ){
1034 m_nNewBrushPressx = x;
1035 m_nNewBrushPressy = y;
1037 m_bNewBrushDrag = true;
1038 GlobalUndoSystem().start();
1041 void XYWnd::NewBrushDrag_End( int x, int y ){
1042 if ( m_NewBrushDrag != 0 ) {
1043 GlobalUndoSystem().finish( "brushDragNew" );
1047 void XYWnd::NewBrushDrag( int x, int y ){
1049 XY_ToPoint( m_nNewBrushPressx, m_nNewBrushPressy, mins );
1050 XY_SnapToGrid( mins );
1051 XY_ToPoint( x, y, maxs );
1052 XY_SnapToGrid( maxs );
1054 int nDim = ( m_viewType == XY ) ? 2 : ( m_viewType == YZ ) ? 0 : 1;
1056 mins[nDim] = float_snapped( Select_getWorkZone().d_work_min[nDim], GetSnapGridSize() );
1057 maxs[nDim] = float_snapped( Select_getWorkZone().d_work_max[nDim], GetSnapGridSize() );
1059 if ( maxs[nDim] <= mins[nDim] ) {
1060 maxs[nDim] = mins[nDim] + GetGridSize();
1063 for ( int i = 0 ; i < 3 ; i++ )
1065 if ( mins[i] == maxs[i] ) {
1066 return; // don't create a degenerate brush
1068 if ( mins[i] > maxs[i] ) {
1069 float temp = mins[i];
1075 if ( m_NewBrushDrag == 0 ) {
1076 NodeSmartReference node( GlobalBrushCreator().createBrush() );
1077 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
1079 scene::Path brushpath( makeReference( GlobalSceneGraph().root() ) );
1080 brushpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
1081 brushpath.push( makeReference( node.get() ) );
1082 selectPath( brushpath, true );
1084 m_NewBrushDrag = node.get_pointer();
1088 //Scene_BrushResize_Selected(GlobalSceneGraph(), aabb_for_minmax(mins, maxs), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
1089 Scene_BrushResize_Selected( GlobalSceneGraph(), aabb_for_minmax( mins, maxs ),
1090 g_brush_always_caulk ?
1091 "textures/common/caulk" : TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
1094 void entitycreate_activated( ui::Widget item ){
1095 scene::Node* world_node = Map_FindWorldspawn( g_map );
1096 const char* entity_name = gtk_label_get_text( GTK_LABEL( gtk_bin_get_child(GTK_BIN( item )) ) );
1098 if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) {
1099 g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
1102 GlobalRadiant().m_pfnMessageBox( MainFrame_getWindow(),
1103 "There's already a worldspawn in your map!",
1110 void EntityClassMenu_addItem( ui::Menu menu, const char* name ){
1111 auto item = ui::MenuItem( name );
1112 item.connect( "activate", G_CALLBACK( entitycreate_activated ), item );
1114 menu_add_item( menu, item );
1117 class EntityClassMenuInserter : public EntityClassVisitor
1119 typedef std::pair<ui::Menu, CopiedString> MenuPair;
1120 typedef std::vector<MenuPair> MenuStack;
1122 CopiedString m_previous;
1124 EntityClassMenuInserter( ui::Menu menu ){
1125 m_stack.reserve( 2 );
1126 m_stack.push_back( MenuPair( menu, "" ) );
1128 ~EntityClassMenuInserter(){
1129 if ( !string_empty( m_previous.c_str() ) ) {
1130 addItem( m_previous.c_str(), "" );
1133 void visit( EntityClass* e ){
1134 ASSERT_MESSAGE( !string_empty( e->name() ), "entity-class has no name" );
1135 if ( !string_empty( m_previous.c_str() ) ) {
1136 addItem( m_previous.c_str(), e->name() );
1138 m_previous = e->name();
1140 void pushMenu( const CopiedString& name ){
1141 auto item = ui::MenuItem( name.c_str() );
1143 m_stack.back().first.add(item);
1145 auto submenu = ui::Menu(ui::New);
1146 gtk_menu_item_set_submenu( item, submenu );
1148 m_stack.push_back( MenuPair( submenu, name ) );
1153 void addItem( const char* name, const char* next ){
1154 const char* underscore = strchr( name, '_' );
1156 if ( underscore != 0 && underscore != name ) {
1157 bool nextEqual = string_equal_n( name, next, ( underscore + 1 ) - name );
1158 const char* parent = m_stack.back().second.c_str();
1160 if ( !string_empty( parent )
1161 && string_length( parent ) == std::size_t( underscore - name )
1162 && string_equal_n( name, parent, underscore - name ) ) { // this is a child
1164 else if ( nextEqual ) {
1165 if ( m_stack.size() == 2 ) {
1168 pushMenu( CopiedString( StringRange( name, underscore ) ) );
1170 else if ( m_stack.size() == 2 ) {
1174 else if ( m_stack.size() == 2 ) {
1178 EntityClassMenu_addItem( m_stack.back().first, name );
1182 void XYWnd::OnContextMenu(){
1183 if ( g_xywindow_globals.m_bRightClick == false ) {
1187 if ( !m_mnuDrop ) { // first time, load it up
1188 auto menu = m_mnuDrop = ui::Menu(ui::New);
1190 EntityClassMenuInserter inserter( menu );
1191 GlobalEntityClassManager().forEach( inserter );
1194 gtk_menu_popup( m_mnuDrop, 0, 0, 0, 0, 1, GDK_CURRENT_TIME );
1197 FreezePointer g_xywnd_freezePointer;
1199 unsigned int Move_buttons(){
1203 void XYWnd_moveDelta( int x, int y, unsigned int state, void* data ){
1204 reinterpret_cast<XYWnd*>( data )->EntityCreate_MouseMove( x, y );
1205 reinterpret_cast<XYWnd*>( data )->Scroll( -x, y );
1208 gboolean XYWnd_Move_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1213 void XYWnd::Move_Begin(){
1214 if ( m_move_started ) {
1217 m_move_started = true;
1218 /* NetRadiantCustom did this instead:
1219 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_moveDelta, this ); */
1220 g_xywnd_freezePointer.freeze_pointer( m_gl_widget, XYWnd_moveDelta, this );
1221 m_move_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Move_focusOut ), this );
1224 void XYWnd::Move_End(){
1225 m_move_started = false;
1226 g_xywnd_freezePointer.unfreeze_pointer( m_gl_widget );
1227 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_move_focusOut );
1230 unsigned int Zoom_buttons(){
1231 return RAD_RBUTTON | RAD_SHIFT;
1236 void XYWnd_zoomDelta( int x, int y, unsigned int state, void* data ){
1239 while ( abs( g_dragZoom ) > 8 )
1241 if ( g_dragZoom > 0 ) {
1242 reinterpret_cast<XYWnd*>( data )->ZoomOut();
1247 reinterpret_cast<XYWnd*>( data )->ZoomIn();
1254 gboolean XYWnd_Zoom_focusOut( ui::Widget widget, GdkEventFocus* event, XYWnd* xywnd ){
1259 void XYWnd::Zoom_Begin(){
1260 if ( m_zoom_started ) {
1263 m_zoom_started = true;
1265 /* NetRadiantCustom did this instead:
1266 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), m_gl_widget, XYWnd_zoomDelta, this ); */
1267 g_xywnd_freezePointer.freeze_pointer( m_parent ? m_parent : MainFrame_getWindow(), XYWnd_zoomDelta, this );
1268 m_zoom_focusOut = m_gl_widget.connect( "focus_out_event", G_CALLBACK( XYWnd_Zoom_focusOut ), this );
1271 void XYWnd::Zoom_End(){
1272 m_zoom_started = false;
1273 g_xywnd_freezePointer.unfreeze_pointer( m_parent ? m_parent : MainFrame_getWindow() );
1274 g_signal_handler_disconnect( G_OBJECT( m_gl_widget ), m_zoom_focusOut );
1277 // makes sure the selected brush or camera is in view
1278 void XYWnd::PositionView( const Vector3& position ){
1279 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1280 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1282 m_vOrigin[nDim1] = position[nDim1];
1283 m_vOrigin[nDim2] = position[nDim2];
1287 XYWnd_Update( *this );
1290 void XYWnd::SetViewType( VIEWTYPE viewType ){
1291 m_viewType = viewType;
1295 gtk_window_set_title( m_parent, ViewType_getTitle( m_viewType ) );
1300 inline WindowVector WindowVector_forInteger( int x, int y ){
1301 return WindowVector( static_cast<float>( x ), static_cast<float>( y ) );
1304 void XYWnd::mouseDown( const WindowVector& position, ButtonIdentifier button, ModifierFlags modifiers ){
1305 XY_MouseDown( static_cast<int>( position.x() ), static_cast<int>( position.y() ), buttons_for_button_and_modifiers( button, modifiers ) );
1307 void XYWnd::XY_MouseDown( int x, int y, unsigned int buttons ){
1308 if ( buttons == Move_buttons() ) {
1310 EntityCreate_MouseDown( x, y );
1312 else if ( buttons == Zoom_buttons() ) {
1315 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1316 Clipper_OnLButtonDown( x, y );
1318 else if ( buttons == NewBrushDrag_buttons() && GlobalSelectionSystem().countSelected() == 0 ) {
1319 NewBrushDrag_Begin( x, y );
1321 // control mbutton = move camera
1322 else if ( buttons == MoveCamera_buttons() ) {
1323 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1325 // mbutton = angle camera
1326 else if ( buttons == OrientCamera_buttons() ) {
1327 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1331 m_window_observer->onMouseDown( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1335 void XYWnd::XY_MouseUp( int x, int y, unsigned int buttons ){
1336 if ( m_move_started ) {
1338 EntityCreate_MouseUp( x, y );
1340 else if ( m_zoom_started ) {
1343 else if ( ClipMode() && buttons == Clipper_buttons() ) {
1344 Clipper_OnLButtonUp( x, y );
1346 else if ( m_bNewBrushDrag ) {
1347 m_bNewBrushDrag = false;
1348 NewBrushDrag_End( x, y );
1349 if ( m_NewBrushDrag == 0 ) {
1350 //L button w/o created brush = tunnel selection
1351 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1356 m_window_observer->onMouseUp( WindowVector_forInteger( x, y ), button_for_flags( buttons ), modifiers_for_flags( buttons ) );
1360 void XYWnd::XY_MouseMoved( int x, int y, unsigned int buttons ){
1361 // rbutton = drag xy origin
1362 if ( m_move_started ) {
1365 else if ( m_zoom_started ) {
1368 else if ( ClipMode() && g_pMovingClip != 0 ) {
1369 Clipper_OnMouseMoved( x, y );
1371 // lbutton without selection = drag new brush
1372 else if ( m_bNewBrushDrag ) {
1373 NewBrushDrag( x, y );
1376 // control mbutton = move camera
1377 else if ( getButtonState() == MoveCamera_buttons() ) {
1378 XYWnd_PositionCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1381 // mbutton = angle camera
1382 else if ( getButtonState() == OrientCamera_buttons() ) {
1383 XYWnd_OrientCamera( this, x, y, *g_pParentWnd->GetCamWnd() );
1388 m_window_observer->onMouseMotion( WindowVector_forInteger( x, y ), modifiers_for_flags( buttons ) );
1390 m_mousePosition[0] = m_mousePosition[1] = m_mousePosition[2] = 0.0;
1391 XY_ToPoint( x, y, m_mousePosition );
1392 XY_SnapToGrid( m_mousePosition );
1394 StringOutputStream status( 64 );
1395 status << "x:: " << FloatFormat( m_mousePosition[0], 6, 1 )
1396 << " y:: " << FloatFormat( m_mousePosition[1], 6, 1 )
1397 << " z:: " << FloatFormat( m_mousePosition[2], 6, 1 );
1398 g_pParentWnd->SetStatusText( g_pParentWnd->m_position_status, status.c_str() );
1400 if ( g_xywindow_globals_private.g_bCrossHairs ) {
1401 XYWnd_Update( *this );
1404 Clipper_Crosshair_OnMouseMoved( x, y );
1408 void XYWnd::EntityCreate_MouseDown( int x, int y ){
1409 m_entityCreate = true;
1410 m_entityCreate_x = x;
1411 m_entityCreate_y = y;
1414 void XYWnd::EntityCreate_MouseMove( int x, int y ){
1415 if ( m_entityCreate && ( m_entityCreate_x != x || m_entityCreate_y != y ) ) {
1416 m_entityCreate = false;
1420 void XYWnd::EntityCreate_MouseUp( int x, int y ){
1421 if ( m_entityCreate ) {
1422 m_entityCreate = false;
1427 inline float screen_normalised( int pos, unsigned int size ){
1428 return ( ( 2.0f * pos ) / size ) - 1.0f;
1431 inline float normalised_to_world( float normalised, float world_origin, float normalised2world_scale ){
1432 return world_origin + normalised * normalised2world_scale;
1436 // TTimo: watch it, this doesn't init one of the 3 coords
1437 void XYWnd::XY_ToPoint( int x, int y, Vector3& point ){
1438 float normalised2world_scale_x = m_nWidth / 2 / m_fScale;
1439 float normalised2world_scale_y = m_nHeight / 2 / m_fScale;
1440 if ( m_viewType == XY ) {
1441 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1442 point[1] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[1], normalised2world_scale_y );
1444 else if ( m_viewType == YZ ) {
1445 point[1] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[1], normalised2world_scale_x );
1446 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1450 point[0] = normalised_to_world( screen_normalised( x, m_nWidth ), m_vOrigin[0], normalised2world_scale_x );
1451 point[2] = normalised_to_world( -screen_normalised( y, m_nHeight ), m_vOrigin[2], normalised2world_scale_y );
1455 void XYWnd::XY_SnapToGrid( Vector3& point ){
1456 if ( m_viewType == XY ) {
1457 point[0] = float_snapped( point[0], GetSnapGridSize() );
1458 point[1] = float_snapped( point[1], GetSnapGridSize() );
1460 else if ( m_viewType == YZ ) {
1461 point[1] = float_snapped( point[1], GetSnapGridSize() );
1462 point[2] = float_snapped( point[2], GetSnapGridSize() );
1466 point[0] = float_snapped( point[0], GetSnapGridSize() );
1467 point[2] = float_snapped( point[2], GetSnapGridSize() );
1471 void XYWnd::XY_LoadBackgroundImage( const char *name ){
1472 const char* relative = path_make_relative( name, GlobalFileSystem().findRoot( name ) );
1473 if ( relative == name ) {
1474 globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
1477 char fileNameWithoutExt[512];
1478 strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
1479 fileNameWithoutExt[512 - 1] = '\0';
1480 fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
1482 Image *image = QERApp_LoadImage( 0, fileNameWithoutExt );
1484 globalOutputStream() << "Could not load texture " << fileNameWithoutExt << "\n";
1487 g_pParentWnd->ActiveXY()->m_tex = (qtexture_t*)malloc( sizeof( qtexture_t ) );
1488 LoadTextureRGBA( g_pParentWnd->ActiveXY()->XYWnd::m_tex, image->getRGBAPixels(), image->getWidth(), image->getHeight() );
1489 globalOutputStream() << "Loaded background texture " << relative << "\n";
1490 g_pParentWnd->ActiveXY()->m_backgroundActivated = true;
1493 switch ( g_pParentWnd->ActiveXY()->m_viewType )
1510 Select_GetBounds( min, max );
1511 g_pParentWnd->ActiveXY()->m_xmin = min[m_ix];
1512 g_pParentWnd->ActiveXY()->m_ymin = min[m_iy];
1513 g_pParentWnd->ActiveXY()->m_xmax = max[m_ix];
1514 g_pParentWnd->ActiveXY()->m_ymax = max[m_iy];
1517 void XYWnd::XY_DisableBackground( void ){
1518 g_pParentWnd->ActiveXY()->m_backgroundActivated = false;
1519 if ( g_pParentWnd->ActiveXY()->m_tex ) {
1520 free( g_pParentWnd->ActiveXY()->m_tex );
1522 g_pParentWnd->ActiveXY()->m_tex = NULL;
1525 void WXY_BackgroundSelect( void ){
1526 bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
1528 ui::Window main_window = MainFrame_getWindow();
1530 if ( !brushesSelected ) {
1531 ui::alert( main_window, "You have to select some brushes to get the bounding box for.\n",
1532 "No selection", ui::alert_type::OK, ui::alert_icon::Error );
1536 const char *filename = main_window.file_dialog( TRUE, "Background Image", NULL, NULL );
1538 g_pParentWnd->ActiveXY()->XY_DisableBackground();
1541 g_pParentWnd->ActiveXY()->XY_LoadBackgroundImage( filename );
1544 // Draw the background image immediately (do not wait for user input).
1545 g_pParentWnd->ActiveXY()->Redraw();
1549 ============================================================================
1553 ============================================================================
1562 double two_to_the_power( int power ){
1563 return pow( 2.0f, power );
1566 void XYWnd::XY_DrawAxis( void ){
1567 if ( g_xywindow_globals_private.show_axis ) {
1568 const char g_AxisName[3] = { 'X', 'Y', 'Z' };
1569 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1570 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1571 const int w = ( m_nWidth / 2 / m_fScale );
1572 const int h = ( m_nHeight / 2 / m_fScale );
1574 const Vector3& colourX = ( m_viewType == YZ ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorX;
1575 const Vector3& colourY = ( m_viewType == XY ) ? g_xywindow_globals.AxisColorY : g_xywindow_globals.AxisColorZ;
1577 // draw two lines with corresponding axis colors to highlight current view
1578 // horizontal line: nDim1 color
1580 glBegin( GL_LINES );
1581 glColor3fv( vector3_to_array( colourX ) );
1582 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1583 glVertex2f( m_vOrigin[nDim1] - w + 65 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1585 glVertex2f( 32 / m_fScale, 0 );
1586 glColor3fv( vector3_to_array( colourY ) );
1587 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 45 / m_fScale );
1588 glVertex2f( m_vOrigin[nDim1] - w + 40 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1590 glVertex2f( 0, 32 / m_fScale );
1593 // now print axis symbols
1594 glColor3fv( vector3_to_array( colourX ) );
1595 glRasterPos2f( m_vOrigin[nDim1] - w + 55 / m_fScale, m_vOrigin[nDim2] + h - 55 / m_fScale );
1596 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1597 glRasterPos2f( 28 / m_fScale, -10 / m_fScale );
1598 GlobalOpenGL().drawChar( g_AxisName[nDim1] );
1599 glColor3fv( vector3_to_array( colourY ) );
1600 glRasterPos2f( m_vOrigin[nDim1] - w + 25 / m_fScale, m_vOrigin[nDim2] + h - 30 / m_fScale );
1601 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1602 glRasterPos2f( -10 / m_fScale, 28 / m_fScale );
1603 GlobalOpenGL().drawChar( g_AxisName[nDim2] );
1607 void XYWnd::XY_DrawBackground( void ){
1608 glPushAttrib( GL_ALL_ATTRIB_BITS );
1610 glEnable( GL_TEXTURE_2D );
1611 glEnable( GL_BLEND );
1612 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
1613 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1614 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1615 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1617 glPolygonMode( GL_FRONT, GL_FILL );
1619 glBindTexture( GL_TEXTURE_2D, m_tex->texture_number );
1620 glBegin( GL_QUADS );
1622 glColor4f( 1.0, 1.0, 1.0, m_alpha );
1623 glTexCoord2f( 0.0, 1.0 );
1624 glVertex2f( m_xmin, m_ymin );
1626 glTexCoord2f( 1.0, 1.0 );
1627 glVertex2f( m_xmax, m_ymin );
1629 glTexCoord2f( 1.0, 0.0 );
1630 glVertex2f( m_xmax, m_ymax );
1632 glTexCoord2f( 0.0, 0.0 );
1633 glVertex2f( m_xmin, m_ymax );
1636 glBindTexture( GL_TEXTURE_2D, 0 );
1641 void XYWnd::XY_DrawGrid( void ) {
1642 float x, y, xb, xe, yb, ye;
1645 float step, minor_step, stepx, stepy;
1646 step = minor_step = stepx = stepy = GetGridSize();
1648 int minor_power = Grid_getPower();
1651 while ( ( minor_step * m_fScale ) <= 4.0f ) { // make sure minor grid spacing is at least 4 pixels on the screen
1655 int power = minor_power;
1656 while ( ( power % 3 ) != 0 || ( step * m_fScale ) <= 32.0f ) { // make sure major grid spacing is at least 32 pixels on the screen
1658 step = float(two_to_the_power( power ) );
1660 mask = ( 1 << ( power - minor_power ) ) - 1;
1661 while ( ( stepx * m_fScale ) <= 32.0f ) // text step x must be at least 32
1663 while ( ( stepy * m_fScale ) <= 32.0f ) // text step y must be at least 32
1666 a = ( ( GetSnapGridSize() > 0.0f ) ? 1.0f : 0.3f );
1668 glDisable( GL_TEXTURE_2D );
1669 glDisable( GL_TEXTURE_1D );
1670 glDisable( GL_DEPTH_TEST );
1671 glDisable( GL_BLEND );
1674 w = ( m_nWidth / 2 / m_fScale );
1675 h = ( m_nHeight / 2 / m_fScale );
1677 const int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1678 const int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1680 xb = m_vOrigin[nDim1] - w;
1681 if ( xb < region_mins[nDim1] ) {
1682 xb = region_mins[nDim1];
1684 xb = step * floor( xb / step );
1686 xe = m_vOrigin[nDim1] + w;
1687 if ( xe > region_maxs[nDim1] ) {
1688 xe = region_maxs[nDim1];
1690 xe = step * ceil( xe / step );
1692 yb = m_vOrigin[nDim2] - h;
1693 if ( yb < region_mins[nDim2] ) {
1694 yb = region_mins[nDim2];
1696 yb = step * floor( yb / step );
1698 ye = m_vOrigin[nDim2] + h;
1699 if ( ye > region_maxs[nDim2] ) {
1700 ye = region_maxs[nDim2];
1702 ye = step * ceil( ye / step );
1704 #define COLORS_DIFFER( a,b ) \
1705 ( ( a )[0] != ( b )[0] || \
1706 ( a )[1] != ( b )[1] || \
1707 ( a )[2] != ( b )[2] )
1710 // draw minor blocks
1711 if ( g_xywindow_globals_private.d_showgrid || a < 1.0f ) {
1713 glEnable( GL_BLEND );
1716 if ( COLORS_DIFFER( g_xywindow_globals.color_gridminor, g_xywindow_globals.color_gridback ) ) {
1717 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridminor, a ) ) );
1719 glBegin( GL_LINES );
1721 for ( x = xb ; x < xe ; x += minor_step, ++i ) {
1722 if ( ( i & mask ) != 0 ) {
1723 glVertex2f( x, yb );
1724 glVertex2f( x, ye );
1728 for ( y = yb ; y < ye ; y += minor_step, ++i ) {
1729 if ( ( i & mask ) != 0 ) {
1730 glVertex2f( xb, y );
1731 glVertex2f( xe, y );
1737 // draw major blocks
1738 if ( COLORS_DIFFER( g_xywindow_globals.color_gridmajor, g_xywindow_globals.color_gridminor ) ) {
1739 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridmajor, a ) ) );
1741 glBegin( GL_LINES );
1742 for ( x = xb ; x <= xe ; x += step ) {
1743 glVertex2f( x, yb );
1744 glVertex2f( x, ye );
1746 for ( y = yb ; y <= ye ; y += step ) {
1747 glVertex2f( xb, y );
1748 glVertex2f( xe, y );
1754 glDisable( GL_BLEND );
1758 // draw coordinate text if needed
1759 if ( g_xywindow_globals_private.show_coordinates ) {
1760 glColor4fv( vector4_to_array( Vector4( g_xywindow_globals.color_gridtext, 1.0f ) ) );
1761 float offx = m_vOrigin[nDim2] + h - ( 4 + GlobalOpenGL().m_font->getPixelAscent() ) / m_fScale;
1762 float offy = m_vOrigin[nDim1] - w + 4 / m_fScale;
1763 for ( x = xb - fmod( xb, stepx ); x <= xe ; x += stepx ) {
1764 glRasterPos2f( x, offx );
1765 sprintf( text, "%g", x );
1766 GlobalOpenGL().drawString( text );
1768 for ( y = yb - fmod( yb, stepy ); y <= ye ; y += stepy ) {
1769 glRasterPos2f( offy, y );
1770 sprintf( text, "%g", y );
1771 GlobalOpenGL().drawString( text );
1775 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
1778 // we do this part (the old way) only if show_axis is disabled
1779 if ( !g_xywindow_globals_private.show_axis ) {
1780 glRasterPos2f( m_vOrigin[nDim1] - w + 35 / m_fScale, m_vOrigin[nDim2] + h - 20 / m_fScale );
1782 GlobalOpenGL().drawString( ViewType_getTitle( m_viewType ) );
1786 XYWnd::XY_DrawAxis();
1788 // show current work zone?
1789 // the work zone is used to place dropped points and brushes
1790 if ( g_xywindow_globals_private.d_show_work ) {
1791 glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
1792 glBegin( GL_LINES );
1793 glVertex2f( xb, Select_getWorkZone().d_work_min[nDim2] );
1794 glVertex2f( xe, Select_getWorkZone().d_work_min[nDim2] );
1795 glVertex2f( xb, Select_getWorkZone().d_work_max[nDim2] );
1796 glVertex2f( xe, Select_getWorkZone().d_work_max[nDim2] );
1797 glVertex2f( Select_getWorkZone().d_work_min[nDim1], yb );
1798 glVertex2f( Select_getWorkZone().d_work_min[nDim1], ye );
1799 glVertex2f( Select_getWorkZone().d_work_max[nDim1], yb );
1800 glVertex2f( Select_getWorkZone().d_work_max[nDim1], ye );
1810 void XYWnd::XY_DrawBlockGrid(){
1811 if ( Map_FindWorldspawn( g_map ) == 0 ) {
1814 const char *value = Node_getEntity( *Map_GetWorldspawn( g_map ) )->getKeyValue( "_blocksize" );
1815 if ( strlen( value ) ) {
1816 sscanf( value, "%i", &g_xywindow_globals_private.blockSize );
1819 if ( !g_xywindow_globals_private.blockSize || g_xywindow_globals_private.blockSize > 65536 || g_xywindow_globals_private.blockSize < 1024 ) {
1820 // don't use custom blocksize if it is less than the default, or greater than the maximum world coordinate
1821 g_xywindow_globals_private.blockSize = 1024;
1824 float x, y, xb, xe, yb, ye;
1828 glDisable( GL_TEXTURE_2D );
1829 glDisable( GL_TEXTURE_1D );
1830 glDisable( GL_DEPTH_TEST );
1831 glDisable( GL_BLEND );
1833 w = ( m_nWidth / 2 / m_fScale );
1834 h = ( m_nHeight / 2 / m_fScale );
1836 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
1837 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
1839 xb = m_vOrigin[nDim1] - w;
1840 if ( xb < region_mins[nDim1] ) {
1841 xb = region_mins[nDim1];
1843 xb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( xb / g_xywindow_globals_private.blockSize ) );
1845 xe = m_vOrigin[nDim1] + w;
1846 if ( xe > region_maxs[nDim1] ) {
1847 xe = region_maxs[nDim1];
1849 xe = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( xe / g_xywindow_globals_private.blockSize ) );
1851 yb = m_vOrigin[nDim2] - h;
1852 if ( yb < region_mins[nDim2] ) {
1853 yb = region_mins[nDim2];
1855 yb = static_cast<float>( g_xywindow_globals_private.blockSize * floor( yb / g_xywindow_globals_private.blockSize ) );
1857 ye = m_vOrigin[nDim2] + h;
1858 if ( ye > region_maxs[nDim2] ) {
1859 ye = region_maxs[nDim2];
1861 ye = static_cast<float>( g_xywindow_globals_private.blockSize * ceil( ye / g_xywindow_globals_private.blockSize ) );
1863 // draw major blocks
1865 glColor3fv( vector3_to_array( g_xywindow_globals.color_gridblock ) );
1868 glBegin( GL_LINES );
1870 for ( x = xb ; x <= xe ; x += g_xywindow_globals_private.blockSize )
1872 glVertex2f( x, yb );
1873 glVertex2f( x, ye );
1876 if ( m_viewType == XY ) {
1877 for ( y = yb ; y <= ye ; y += g_xywindow_globals_private.blockSize )
1879 glVertex2f( xb, y );
1880 glVertex2f( xe, y );
1887 // draw coordinate text if needed
1889 if ( m_viewType == XY && m_fScale > .1 ) {
1890 for ( x = xb ; x < xe ; x += g_xywindow_globals_private.blockSize )
1891 for ( y = yb ; y < ye ; y += g_xywindow_globals_private.blockSize )
1893 glRasterPos2f( x + ( g_xywindow_globals_private.blockSize / 2 ), y + ( g_xywindow_globals_private.blockSize / 2 ) );
1894 sprintf( text, "%i,%i",(int)floor( x / g_xywindow_globals_private.blockSize ), (int)floor( y / g_xywindow_globals_private.blockSize ) );
1895 GlobalOpenGL().drawString( text );
1899 glColor4f( 0, 0, 0, 0 );
1902 void XYWnd::DrawCameraIcon( const Vector3& origin, const Vector3& angles ){
1903 float x, y, fov, box;
1906 fov = 48 / m_fScale;
1907 box = 16 / m_fScale;
1909 if ( m_viewType == XY ) {
1912 a = degrees_to_radians( angles[CAMERA_YAW] );
1914 else if ( m_viewType == YZ ) {
1917 a = degrees_to_radians( angles[CAMERA_PITCH] );
1923 a = degrees_to_radians( angles[CAMERA_PITCH] );
1926 glColor3f( 0.0, 0.0, 1.0 );
1927 glBegin( GL_LINE_STRIP );
1928 glVertex3f( x - box,y,0 );
1929 glVertex3f( x,y + ( box / 2 ),0 );
1930 glVertex3f( x + box,y,0 );
1931 glVertex3f( x,y - ( box / 2 ),0 );
1932 glVertex3f( x - box,y,0 );
1933 glVertex3f( x + box,y,0 );
1936 glBegin( GL_LINE_STRIP );
1937 glVertex3f( x + static_cast<float>( fov * cos( a + c_pi / 4 ) ), y + static_cast<float>( fov * sin( a + c_pi / 4 ) ), 0 );
1938 glVertex3f( x, y, 0 );
1939 glVertex3f( x + static_cast<float>( fov * cos( a - c_pi / 4 ) ), y + static_cast<float>( fov * sin( a - c_pi / 4 ) ), 0 );
1945 float Betwixt( float f1, float f2 ){
1947 return f2 + ( ( f1 - f2 ) / 2 );
1950 return f1 + ( ( f2 - f1 ) / 2 );
1955 // can be greatly simplified but per usual i am in a hurry
1956 // which is not an excuse, just a fact
1957 void XYWnd::PaintSizeInfo( int nDim1, int nDim2, Vector3& vMinBounds, Vector3& vMaxBounds ){
1958 if ( vector3_equal( vMinBounds, vMaxBounds ) ) {
1961 const char* g_pDimStrings[] = {"x:", "y:", "z:"};
1962 typedef const char* OrgStrings[2];
1963 const OrgStrings g_pOrgStrings[] = { { "x:", "y:", }, { "x:", "z:", }, { "y:", "z:", } };
1965 Vector3 vSize( vector3_subtracted( vMaxBounds, vMinBounds ) );
1967 glColor3f( g_xywindow_globals.color_selbrushes[0] * .65f,
1968 g_xywindow_globals.color_selbrushes[1] * .65f,
1969 g_xywindow_globals.color_selbrushes[2] * .65f );
1971 StringOutputStream dimensions( 16 );
1973 if ( m_viewType == XY ) {
1974 glBegin( GL_LINES );
1976 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1977 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1979 glVertex3f( vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1980 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1982 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale, 0.0f );
1983 glVertex3f( vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale, 0.0f );
1986 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1987 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1989 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2], 0.0f );
1990 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1992 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1993 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2], 0.0f );
1997 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale, 0.0f );
1998 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
1999 GlobalOpenGL().drawString( dimensions.c_str() );
2002 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ), 0.0f );
2003 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2004 GlobalOpenGL().drawString( dimensions.c_str() );
2007 glRasterPos3f( vMinBounds[nDim1] + 4, vMaxBounds[nDim2] + 8 / m_fScale, 0.0f );
2008 dimensions << "(" << g_pOrgStrings[0][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[0][1] << vMaxBounds[nDim2] << ")";
2009 GlobalOpenGL().drawString( dimensions.c_str() );
2011 else if ( m_viewType == XZ ) {
2012 glBegin( GL_LINES );
2014 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 6.0f / m_fScale );
2015 glVertex3f( vMinBounds[nDim1], 0, vMinBounds[nDim2] - 10.0f / m_fScale );
2017 glVertex3f( vMinBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2018 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2020 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 6.0f / m_fScale );
2021 glVertex3f( vMaxBounds[nDim1], 0,vMinBounds[nDim2] - 10.0f / m_fScale );
2024 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMinBounds[nDim2] );
2025 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2027 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMinBounds[nDim2] );
2028 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2030 glVertex3f( vMaxBounds[nDim1] + 6.0f / m_fScale, 0,vMaxBounds[nDim2] );
2031 glVertex3f( vMaxBounds[nDim1] + 10.0f / m_fScale, 0,vMaxBounds[nDim2] );
2035 glRasterPos3f( Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), 0, vMinBounds[nDim2] - 20.0f / m_fScale );
2036 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2037 GlobalOpenGL().drawString( dimensions.c_str() );
2040 glRasterPos3f( vMaxBounds[nDim1] + 16.0f / m_fScale, 0, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2041 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2042 GlobalOpenGL().drawString( dimensions.c_str() );
2045 glRasterPos3f( vMinBounds[nDim1] + 4, 0, vMaxBounds[nDim2] + 8 / m_fScale );
2046 dimensions << "(" << g_pOrgStrings[1][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[1][1] << vMaxBounds[nDim2] << ")";
2047 GlobalOpenGL().drawString( dimensions.c_str() );
2051 glBegin( GL_LINES );
2053 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2054 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2056 glVertex3f( 0, vMinBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2057 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2059 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 6.0f / m_fScale );
2060 glVertex3f( 0, vMaxBounds[nDim1], vMinBounds[nDim2] - 10.0f / m_fScale );
2063 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMinBounds[nDim2] );
2064 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2066 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMinBounds[nDim2] );
2067 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2069 glVertex3f( 0, vMaxBounds[nDim1] + 6.0f / m_fScale, vMaxBounds[nDim2] );
2070 glVertex3f( 0, vMaxBounds[nDim1] + 10.0f / m_fScale, vMaxBounds[nDim2] );
2074 glRasterPos3f( 0, Betwixt( vMinBounds[nDim1], vMaxBounds[nDim1] ), vMinBounds[nDim2] - 20.0f / m_fScale );
2075 dimensions << g_pDimStrings[nDim1] << vSize[nDim1];
2076 GlobalOpenGL().drawString( dimensions.c_str() );
2079 glRasterPos3f( 0, vMaxBounds[nDim1] + 16.0f / m_fScale, Betwixt( vMinBounds[nDim2], vMaxBounds[nDim2] ) );
2080 dimensions << g_pDimStrings[nDim2] << vSize[nDim2];
2081 GlobalOpenGL().drawString( dimensions.c_str() );
2084 glRasterPos3f( 0, vMinBounds[nDim1] + 4.0f, vMaxBounds[nDim2] + 8 / m_fScale );
2085 dimensions << "(" << g_pOrgStrings[2][0] << vMinBounds[nDim1] << " " << g_pOrgStrings[2][1] << vMaxBounds[nDim2] << ")";
2086 GlobalOpenGL().drawString( dimensions.c_str() );
2090 class XYRenderer : public Renderer
2098 unsigned int m_highlight;
2102 XYRenderer( RenderStateFlags globalstate, Shader* selected ) :
2103 m_globalstate( globalstate ),
2104 m_state_selected( selected ){
2105 ASSERT_NOTNULL( selected );
2106 m_state_stack.push_back( state_type() );
2109 void SetState( Shader* state, EStyle style ){
2110 ASSERT_NOTNULL( state );
2111 if ( style == eWireframeOnly ) {
2112 m_state_stack.back().m_state = state;
2115 EStyle getStyle() const {
2116 return eWireframeOnly;
2119 m_state_stack.push_back( m_state_stack.back() );
2122 ASSERT_MESSAGE( !m_state_stack.empty(), "popping empty stack" );
2123 m_state_stack.pop_back();
2125 void Highlight( EHighlightMode mode, bool bEnable = true ){
2127 ? m_state_stack.back().m_highlight |= mode
2128 : m_state_stack.back().m_highlight &= ~mode;
2130 void addRenderable( const OpenGLRenderable& renderable, const Matrix4& localToWorld ){
2131 if ( m_state_stack.back().m_highlight & ePrimitive ) {
2132 m_state_selected->addRenderable( renderable, localToWorld );
2136 m_state_stack.back().m_state->addRenderable( renderable, localToWorld );
2140 void render( const Matrix4& modelview, const Matrix4& projection ){
2141 GlobalShaderCache().render( m_globalstate, modelview, projection );
2144 std::vector<state_type> m_state_stack;
2145 RenderStateFlags m_globalstate;
2146 Shader* m_state_selected;
2149 void XYWnd::updateProjection( bool reconstruct ){
2150 m_projection[0] = 1.0f / static_cast<float>( m_nWidth / 2 );
2151 m_projection[5] = 1.0f / static_cast<float>( m_nHeight / 2 );
2152 m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale );
2154 m_projection[12] = 0.0f;
2155 m_projection[13] = 0.0f;
2156 m_projection[14] = -1.0f;
2168 m_projection[11] = 0.0f;
2170 m_projection[15] = 1.0f;
2173 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2177 // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator.
2178 void XYWnd::updateModelview( bool reconstruct ){
2179 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2180 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2183 m_modelview[12] = -m_vOrigin[nDim1] * m_fScale;
2184 m_modelview[13] = -m_vOrigin[nDim2] * m_fScale;
2185 m_modelview[14] = g_MaxWorldCoord * m_fScale;
2188 switch ( m_viewType )
2191 m_modelview[0] = m_fScale;
2196 m_modelview[5] = m_fScale;
2201 m_modelview[10] = -m_fScale;
2204 m_modelview[0] = m_fScale;
2210 m_modelview[6] = m_fScale;
2213 m_modelview[9] = m_fScale;
2214 m_modelview[10] = 0;
2219 m_modelview[2] = -m_fScale;
2221 m_modelview[4] = m_fScale;
2226 m_modelview[9] = m_fScale;
2227 m_modelview[10] = 0;
2231 m_modelview[3] = m_modelview[7] = m_modelview[11] = 0;
2232 m_modelview[15] = 1;
2235 m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight );
2245 //#define DBG_SCENEDUMP
2247 void XYWnd::XY_Draw(){
2251 glViewport( 0, 0, m_nWidth, m_nHeight );
2252 glClearColor( g_xywindow_globals.color_gridback[0],
2253 g_xywindow_globals.color_gridback[1],
2254 g_xywindow_globals.color_gridback[2],0 );
2256 glClear( GL_COLOR_BUFFER_BIT );
2262 glMatrixMode( GL_PROJECTION );
2263 glLoadMatrixf( reinterpret_cast<const float*>( &m_projection ) );
2265 glMatrixMode( GL_MODELVIEW );
2267 glScalef( m_fScale, m_fScale, 1 );
2268 int nDim1 = ( m_viewType == YZ ) ? 1 : 0;
2269 int nDim2 = ( m_viewType == XY ) ? 1 : 2;
2270 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2272 glDisable( GL_LINE_STIPPLE );
2274 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2275 glDisableClientState( GL_NORMAL_ARRAY );
2276 glDisableClientState( GL_COLOR_ARRAY );
2277 glDisable( GL_TEXTURE_2D );
2278 glDisable( GL_LIGHTING );
2279 glDisable( GL_COLOR_MATERIAL );
2280 glDisable( GL_DEPTH_TEST );
2282 if ( m_backgroundActivated ) {
2283 XY_DrawBackground();
2287 if ( g_xywindow_globals_private.show_blocks ) {
2291 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2293 unsigned int globalstate = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_POLYGONSMOOTH | RENDER_LINESMOOTH;
2294 if ( !g_xywindow_globals.m_bNoStipple ) {
2295 globalstate |= RENDER_LINESTIPPLE;
2299 XYRenderer renderer( globalstate, m_state_selected );
2301 Scene_Render( renderer, m_view );
2303 GlobalOpenGL_debugAssertNoErrors();
2304 renderer.render( m_modelview, m_projection );
2305 GlobalOpenGL_debugAssertNoErrors();
2308 glDepthMask( GL_FALSE );
2310 GlobalOpenGL_debugAssertNoErrors();
2312 glLoadMatrixf( reinterpret_cast<const float*>( &m_modelview ) );
2314 GlobalOpenGL_debugAssertNoErrors();
2315 glDisable( GL_LINE_STIPPLE );
2316 GlobalOpenGL_debugAssertNoErrors();
2318 GlobalOpenGL_debugAssertNoErrors();
2319 if ( GlobalOpenGL().GL_1_3() ) {
2320 glActiveTexture( GL_TEXTURE0 );
2321 glClientActiveTexture( GL_TEXTURE0 );
2323 glDisableClientState( GL_TEXTURE_COORD_ARRAY );
2324 GlobalOpenGL_debugAssertNoErrors();
2325 glDisableClientState( GL_NORMAL_ARRAY );
2326 GlobalOpenGL_debugAssertNoErrors();
2327 glDisableClientState( GL_COLOR_ARRAY );
2328 GlobalOpenGL_debugAssertNoErrors();
2329 glDisable( GL_TEXTURE_2D );
2330 GlobalOpenGL_debugAssertNoErrors();
2331 glDisable( GL_LIGHTING );
2332 GlobalOpenGL_debugAssertNoErrors();
2333 glDisable( GL_COLOR_MATERIAL );
2334 GlobalOpenGL_debugAssertNoErrors();
2336 GlobalOpenGL_debugAssertNoErrors();
2340 if ( g_xywindow_globals_private.m_bSizePaint && GlobalSelectionSystem().countSelected() != 0 ) {
2342 Select_GetBounds( min, max );
2343 PaintSizeInfo( nDim1, nDim2, min, max );
2346 if ( g_xywindow_globals_private.g_bCrossHairs ) {
2347 glColor4f( 0.2f, 0.9f, 0.2f, 0.8f );
2348 glBegin( GL_LINES );
2349 if ( m_viewType == XY ) {
2350 glVertex2f( 2.0f * g_MinWorldCoord, m_mousePosition[1] );
2351 glVertex2f( 2.0f * g_MaxWorldCoord, m_mousePosition[1] );
2352 glVertex2f( m_mousePosition[0], 2.0f * g_MinWorldCoord );
2353 glVertex2f( m_mousePosition[0], 2.0f * g_MaxWorldCoord );
2355 else if ( m_viewType == YZ ) {
2356 glVertex3f( m_mousePosition[0], 2.0f * g_MinWorldCoord, m_mousePosition[2] );
2357 glVertex3f( m_mousePosition[0], 2.0f * g_MaxWorldCoord, m_mousePosition[2] );
2358 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2359 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2363 glVertex3f( 2.0f * g_MinWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2364 glVertex3f( 2.0f * g_MaxWorldCoord, m_mousePosition[1], m_mousePosition[2] );
2365 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MinWorldCoord );
2366 glVertex3f( m_mousePosition[0], m_mousePosition[1], 2.0f * g_MaxWorldCoord );
2372 GlobalClipPoints_Draw( m_fScale );
2375 GlobalOpenGL_debugAssertNoErrors();
2379 glScalef( m_fScale, m_fScale, 1 );
2380 glTranslatef( -m_vOrigin[nDim1], -m_vOrigin[nDim2], 0 );
2382 DrawCameraIcon( Camera_getOrigin( *g_pParentWnd->GetCamWnd() ), Camera_getAngles( *g_pParentWnd->GetCamWnd() ) );
2384 Feedback_draw2D( m_viewType );
2386 if ( g_xywindow_globals_private.show_outline ) {
2388 glMatrixMode( GL_PROJECTION );
2390 glOrtho( 0, m_nWidth, 0, m_nHeight, 0, 1 );
2392 glMatrixMode( GL_MODELVIEW );
2395 // four view mode doesn't colorize
2396 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2397 glColor3fv( vector3_to_array( g_xywindow_globals.color_viewname ) );
2401 switch ( m_viewType )
2404 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorX ) );
2407 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorY ) );
2410 glColor3fv( vector3_to_array( g_xywindow_globals.AxisColorZ ) );
2414 glBegin( GL_LINE_LOOP );
2415 glVertex2f( 0.5, 0.5 );
2416 glVertex2f( m_nWidth - 0.5, 1 );
2417 glVertex2f( m_nWidth - 0.5, m_nHeight - 0.5 );
2418 glVertex2f( 0.5, m_nHeight - 0.5 );
2423 GlobalOpenGL_debugAssertNoErrors();
2428 void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
2429 xywnd->XY_ToPoint( x, y, point );
2430 xywnd->XY_SnapToGrid( point );
2432 int nDim = ( xywnd->GetViewType() == XY ) ? 2 : ( xywnd->GetViewType() == YZ ) ? 0 : 1;
2433 float fWorkMid = float_mid( Select_getWorkZone().d_work_min[nDim], Select_getWorkZone().d_work_max[nDim] );
2434 point[nDim] = float_snapped( fWorkMid, GetGridSize() );
2437 void XYWnd::OnEntityCreate( const char* item ){
2438 StringOutputStream command;
2439 command << "entityCreate -class " << item;
2440 UndoableCommand undo( command.c_str() );
2442 XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );
2443 Entity_createFromSelection( item, point );
2448 void GetFocusPosition( Vector3& position ){
2449 if ( GlobalSelectionSystem().countSelected() != 0 ) {
2450 Select_GetMid( position );
2454 position = Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
2458 void XYWnd_Focus( XYWnd* xywnd ){
2460 GetFocusPosition( position );
2461 xywnd->PositionView( position );
2464 void XY_Split_Focus(){
2466 GetFocusPosition( position );
2467 if ( g_pParentWnd->GetXYWnd() ) {
2468 g_pParentWnd->GetXYWnd()->PositionView( position );
2470 if ( g_pParentWnd->GetXZWnd() ) {
2471 g_pParentWnd->GetXZWnd()->PositionView( position );
2473 if ( g_pParentWnd->GetYZWnd() ) {
2474 g_pParentWnd->GetYZWnd()->PositionView( position );
2479 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit ) {
2480 // cannot do this in a split window
2481 // do something else that the user may want here
2486 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2487 XYWnd_Focus( xywnd );
2491 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2492 // cannot do this in a split window
2493 // do something else that the user may want here
2498 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2499 xywnd->SetViewType( XY );
2500 XYWnd_Focus( xywnd );
2504 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2505 // cannot do this in a split window
2506 // do something else that the user may want here
2511 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2512 xywnd->SetViewType( XZ );
2513 XYWnd_Focus( xywnd );
2517 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2518 // cannot do this in a split window
2519 // do something else that the user may want here
2524 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2525 xywnd->SetViewType( YZ );
2526 XYWnd_Focus( xywnd );
2530 if ( g_pParentWnd->CurrentStyle() == MainFrame::eSplit || g_pParentWnd->CurrentStyle() == MainFrame::eFloating ) {
2531 // cannot do this in a split window
2532 // do something else that the user may want here
2537 XYWnd* xywnd = g_pParentWnd->GetXYWnd();
2538 if ( xywnd->GetViewType() == XY ) {
2539 xywnd->SetViewType( XZ );
2541 else if ( xywnd->GetViewType() == XZ ) {
2542 xywnd->SetViewType( YZ );
2545 xywnd->SetViewType( XY );
2547 XYWnd_Focus( xywnd );
2551 if ( g_pParentWnd->GetXYWnd() ) {
2552 g_pParentWnd->GetXYWnd()->SetScale( 1 );
2554 if ( g_pParentWnd->GetXZWnd() ) {
2555 g_pParentWnd->GetXZWnd()->SetScale( 1 );
2557 if ( g_pParentWnd->GetYZWnd() ) {
2558 g_pParentWnd->GetYZWnd()->SetScale( 1 );
2563 g_pParentWnd->ActiveXY()->ZoomIn();
2566 // NOTE: the zoom out factor is 4/5, we could think about customizing it
2567 // we don't go below a zoom factor corresponding to 10% of the max world size
2568 // (this has to be computed against the window size)
2570 g_pParentWnd->ActiveXY()->ZoomOut();
2575 void ToggleShowCrosshair(){
2576 g_xywindow_globals_private.g_bCrossHairs ^= 1;
2577 XY_UpdateAllWindows();
2580 void ToggleShowSizeInfo(){
2581 g_xywindow_globals_private.m_bSizePaint = !g_xywindow_globals_private.m_bSizePaint;
2582 XY_UpdateAllWindows();
2585 void ToggleShowGrid(){
2586 g_xywindow_globals_private.d_showgrid = !g_xywindow_globals_private.d_showgrid;
2587 XY_UpdateAllWindows();
2590 ToggleShown g_xy_top_shown( true );
2592 void XY_Top_Shown_Construct( ui::Window parent ){
2593 g_xy_top_shown.connect( parent );
2596 ToggleShown g_yz_side_shown( false );
2598 void YZ_Side_Shown_Construct( ui::Window parent ){
2599 g_yz_side_shown.connect( parent );
2602 ToggleShown g_xz_front_shown( false );
2604 void XZ_Front_Shown_Construct( ui::Window parent ){
2605 g_xz_front_shown.connect( parent );
2609 class EntityClassMenu : public ModuleObserver
2611 std::size_t m_unrealised;
2613 EntityClassMenu() : m_unrealised( 1 ){
2616 if ( --m_unrealised == 0 ) {
2620 if ( ++m_unrealised == 1 ) {
2621 if ( XYWnd::m_mnuDrop ) {
2622 XYWnd::m_mnuDrop.destroy();
2623 XYWnd::m_mnuDrop = ui::Menu(ui::null);
2629 EntityClassMenu g_EntityClassMenu;
2634 void ShowNamesToggle(){
2635 GlobalEntityCreator().setShowNames( !GlobalEntityCreator().getShowNames() );
2636 XY_UpdateAllWindows();
2638 typedef FreeCaller<void(), ShowNamesToggle> ShowNamesToggleCaller;
2639 void ShowNamesExport( const Callback<void(bool)> & importer ){
2640 importer( GlobalEntityCreator().getShowNames() );
2642 typedef FreeCaller<void(const Callback<void(bool)> &), ShowNamesExport> ShowNamesExportCaller;
2644 void ShowAnglesToggle(){
2645 GlobalEntityCreator().setShowAngles( !GlobalEntityCreator().getShowAngles() );
2646 XY_UpdateAllWindows();
2648 typedef FreeCaller<void(), ShowAnglesToggle> ShowAnglesToggleCaller;
2649 void ShowAnglesExport( const Callback<void(bool)> & importer ){
2650 importer( GlobalEntityCreator().getShowAngles() );
2652 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAnglesExport> ShowAnglesExportCaller;
2654 void ShowBlocksToggle(){
2655 g_xywindow_globals_private.show_blocks ^= 1;
2656 XY_UpdateAllWindows();
2658 typedef FreeCaller<void(), ShowBlocksToggle> ShowBlocksToggleCaller;
2659 void ShowBlocksExport( const Callback<void(bool)> & importer ){
2660 importer( g_xywindow_globals_private.show_blocks );
2662 typedef FreeCaller<void(const Callback<void(bool)> &), ShowBlocksExport> ShowBlocksExportCaller;
2664 void ShowCoordinatesToggle(){
2665 g_xywindow_globals_private.show_coordinates ^= 1;
2666 XY_UpdateAllWindows();
2668 typedef FreeCaller<void(), ShowCoordinatesToggle> ShowCoordinatesToggleCaller;
2669 void ShowCoordinatesExport( const Callback<void(bool)> & importer ){
2670 importer( g_xywindow_globals_private.show_coordinates );
2672 typedef FreeCaller<void(const Callback<void(bool)> &), ShowCoordinatesExport> ShowCoordinatesExportCaller;
2674 void ShowOutlineToggle(){
2675 g_xywindow_globals_private.show_outline ^= 1;
2676 XY_UpdateAllWindows();
2678 typedef FreeCaller<void(), ShowOutlineToggle> ShowOutlineToggleCaller;
2679 void ShowOutlineExport( const Callback<void(bool)> & importer ){
2680 importer( g_xywindow_globals_private.show_outline );
2682 typedef FreeCaller<void(const Callback<void(bool)> &), ShowOutlineExport> ShowOutlineExportCaller;
2684 void ShowAxesToggle(){
2685 g_xywindow_globals_private.show_axis ^= 1;
2686 XY_UpdateAllWindows();
2688 typedef FreeCaller<void(), ShowAxesToggle> ShowAxesToggleCaller;
2689 void ShowAxesExport( const Callback<void(bool)> & importer ){
2690 importer( g_xywindow_globals_private.show_axis );
2692 typedef FreeCaller<void(const Callback<void(bool)> &), ShowAxesExport> ShowAxesExportCaller;
2694 void ShowWorkzoneToggle(){
2695 g_xywindow_globals_private.d_show_work ^= 1;
2696 XY_UpdateAllWindows();
2698 typedef FreeCaller<void(), ShowWorkzoneToggle> ShowWorkzoneToggleCaller;
2699 void ShowWorkzoneExport( const Callback<void(bool)> & importer ){
2700 importer( g_xywindow_globals_private.d_show_work );
2702 typedef FreeCaller<void(const Callback<void(bool)> &), ShowWorkzoneExport> ShowWorkzoneExportCaller;
2704 ShowNamesExportCaller g_show_names_caller;
2705 Callback<void(const Callback<void(bool)> &)> g_show_names_callback( g_show_names_caller );
2706 ToggleItem g_show_names( g_show_names_callback );
2708 ShowAnglesExportCaller g_show_angles_caller;
2709 Callback<void(const Callback<void(bool)> &)> g_show_angles_callback( g_show_angles_caller );
2710 ToggleItem g_show_angles( g_show_angles_callback );
2712 ShowBlocksExportCaller g_show_blocks_caller;
2713 Callback<void(const Callback<void(bool)> &)> g_show_blocks_callback( g_show_blocks_caller );
2714 ToggleItem g_show_blocks( g_show_blocks_callback );
2716 ShowCoordinatesExportCaller g_show_coordinates_caller;
2717 Callback<void(const Callback<void(bool)> &)> g_show_coordinates_callback( g_show_coordinates_caller );
2718 ToggleItem g_show_coordinates( g_show_coordinates_callback );
2720 ShowOutlineExportCaller g_show_outline_caller;
2721 Callback<void(const Callback<void(bool)> &)> g_show_outline_callback( g_show_outline_caller );
2722 ToggleItem g_show_outline( g_show_outline_callback );
2724 ShowAxesExportCaller g_show_axes_caller;
2725 Callback<void(const Callback<void(bool)> &)> g_show_axes_callback( g_show_axes_caller );
2726 ToggleItem g_show_axes( g_show_axes_callback );
2728 ShowWorkzoneExportCaller g_show_workzone_caller;
2729 Callback<void(const Callback<void(bool)> &)> g_show_workzone_callback( g_show_workzone_caller );
2730 ToggleItem g_show_workzone( g_show_workzone_callback );
2732 void XYShow_registerCommands(){
2733 GlobalToggles_insert( "ShowAngles", ShowAnglesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_angles ) );
2734 GlobalToggles_insert( "ShowNames", ShowNamesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_names ) );
2735 GlobalToggles_insert( "ShowBlocks", ShowBlocksToggleCaller(), ToggleItem::AddCallbackCaller( g_show_blocks ) );
2736 GlobalToggles_insert( "ShowCoordinates", ShowCoordinatesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_coordinates ) );
2737 GlobalToggles_insert( "ShowWindowOutline", ShowOutlineToggleCaller(), ToggleItem::AddCallbackCaller( g_show_outline ) );
2738 GlobalToggles_insert( "ShowAxes", ShowAxesToggleCaller(), ToggleItem::AddCallbackCaller( g_show_axes ) );
2739 GlobalToggles_insert( "ShowWorkzone", ShowWorkzoneToggleCaller(), ToggleItem::AddCallbackCaller( g_show_workzone ) );
2742 void XYWnd_registerShortcuts(){
2743 command_connect_accelerator( "ToggleCrosshairs" );
2744 command_connect_accelerator( "ToggleSizePaint" );
2749 void Orthographic_constructPreferences( PreferencesPage& page ){
2750 page.appendCheckBox( "", "Solid selection boxes", g_xywindow_globals.m_bNoStipple );
2751 page.appendCheckBox( "", "Display size info", g_xywindow_globals_private.m_bSizePaint );
2752 page.appendCheckBox( "", "Chase mouse during drags", g_xywindow_globals_private.m_bChaseMouse );
2753 page.appendCheckBox( "", "Update views on camera move", g_xywindow_globals_private.m_bCamXYUpdate );
2755 void Orthographic_constructPage( PreferenceGroup& group ){
2756 PreferencesPage page( group.createPage( "Orthographic", "Orthographic View Preferences" ) );
2757 Orthographic_constructPreferences( page );
2759 void Orthographic_registerPreferencesPage(){
2760 PreferencesDialog_addSettingsPage( makeCallbackF(Orthographic_constructPage) );
2763 void Clipper_constructPreferences( PreferencesPage& page ){
2764 page.appendCheckBox( "", "Clipper tool uses caulk", g_clip_useCaulk );
2766 void Clipper_constructPage( PreferenceGroup& group ){
2767 PreferencesPage page( group.createPage( "Clipper", "Clipper Tool Settings" ) );
2768 Clipper_constructPreferences( page );
2770 void Clipper_registerPreferencesPage(){
2771 PreferencesDialog_addSettingsPage( makeCallbackF(Clipper_constructPage) );
2775 #include "preferencesystem.h"
2776 #include "stringio.h"
2779 struct ToggleShown_Bool {
2780 static void Export(const ToggleShown &self, const Callback<void(bool)> &returnz) {
2781 returnz(self.active());
2784 static void Import(ToggleShown &self, bool value) {
2790 void XYWindow_Construct(){
2791 GlobalCommands_insert( "ToggleCrosshairs", makeCallbackF(ToggleShowCrosshair), Accelerator( 'X', (GdkModifierType)GDK_SHIFT_MASK ) );
2792 GlobalCommands_insert( "ToggleSizePaint", makeCallbackF(ToggleShowSizeInfo), Accelerator( 'J' ) );
2793 GlobalCommands_insert( "ToggleGrid", makeCallbackF(ToggleShowGrid), Accelerator( '0' ) );
2795 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 ) ) );
2796 GlobalToggles_insert( "ToggleSideView", ToggleShown::ToggleCaller( g_yz_side_shown ), ToggleItem::AddCallbackCaller( g_yz_side_shown.m_item ) );
2797 GlobalToggles_insert( "ToggleFrontView", ToggleShown::ToggleCaller( g_xz_front_shown ), ToggleItem::AddCallbackCaller( g_xz_front_shown.m_item ) );
2798 GlobalCommands_insert( "NextView", makeCallbackF(XY_Next), Accelerator( GDK_KEY_Tab, (GdkModifierType)GDK_CONTROL_MASK ) ); // fixme: doesn't show its shortcut
2799 GlobalCommands_insert( "ZoomIn", makeCallbackF(XY_ZoomIn), Accelerator( GDK_KEY_Delete ) );
2800 GlobalCommands_insert( "ZoomOut", makeCallbackF(XY_ZoomOut), Accelerator( GDK_KEY_Insert ) );
2801 GlobalCommands_insert( "ViewTop", makeCallbackF(XY_Top), Accelerator( GDK_KEY_KP_Home ) );
2802 GlobalCommands_insert( "ViewSide", makeCallbackF(XY_Side), Accelerator( GDK_KEY_KP_Page_Down ) );
2803 GlobalCommands_insert( "ViewFront", makeCallbackF(XY_Front), Accelerator( GDK_KEY_KP_End ) );
2804 GlobalCommands_insert( "Zoom100", makeCallbackF(XY_Zoom100) );
2805 GlobalCommands_insert( "CenterXYView", makeCallbackF(XY_Focus), Accelerator( GDK_KEY_Tab, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
2807 GlobalPreferenceSystem().registerPreference( "ClipCaulk", make_property_string( g_clip_useCaulk ) );
2809 GlobalPreferenceSystem().registerPreference( "NewRightClick", make_property_string( g_xywindow_globals.m_bRightClick ) );
2810 GlobalPreferenceSystem().registerPreference( "ImprovedWheelZoom", make_property_string( g_xywindow_globals.m_bImprovedWheelZoom ) );
2811 GlobalPreferenceSystem().registerPreference( "ChaseMouse", make_property_string( g_xywindow_globals_private.m_bChaseMouse ) );
2812 GlobalPreferenceSystem().registerPreference( "SizePainting", make_property_string( g_xywindow_globals_private.m_bSizePaint ) );
2813 GlobalPreferenceSystem().registerPreference( "ShowCrosshair", make_property_string( g_xywindow_globals_private.g_bCrossHairs ) );
2814 GlobalPreferenceSystem().registerPreference( "NoStipple", make_property_string( g_xywindow_globals.m_bNoStipple ) );
2815 GlobalPreferenceSystem().registerPreference( "SI_ShowCoords", make_property_string( g_xywindow_globals_private.show_coordinates ) );
2816 GlobalPreferenceSystem().registerPreference( "SI_ShowOutlines", make_property_string( g_xywindow_globals_private.show_outline ) );
2817 GlobalPreferenceSystem().registerPreference( "SI_ShowAxis", make_property_string( g_xywindow_globals_private.show_axis ) );
2818 GlobalPreferenceSystem().registerPreference( "CamXYUpdate", make_property_string( g_xywindow_globals_private.m_bCamXYUpdate ) );
2819 GlobalPreferenceSystem().registerPreference( "ShowWorkzone", make_property_string( g_xywindow_globals_private.d_show_work ) );
2821 GlobalPreferenceSystem().registerPreference( "SI_AxisColors0", make_property_string( g_xywindow_globals.AxisColorX ) );
2822 GlobalPreferenceSystem().registerPreference( "SI_AxisColors1", make_property_string( g_xywindow_globals.AxisColorY ) );
2823 GlobalPreferenceSystem().registerPreference( "SI_AxisColors2", make_property_string( g_xywindow_globals.AxisColorZ ) );
2824 GlobalPreferenceSystem().registerPreference( "SI_Colors1", make_property_string( g_xywindow_globals.color_gridback ) );
2825 GlobalPreferenceSystem().registerPreference( "SI_Colors2", make_property_string( g_xywindow_globals.color_gridminor ) );
2826 GlobalPreferenceSystem().registerPreference( "SI_Colors3", make_property_string( g_xywindow_globals.color_gridmajor ) );
2827 GlobalPreferenceSystem().registerPreference( "SI_Colors6", make_property_string( g_xywindow_globals.color_gridblock ) );
2828 GlobalPreferenceSystem().registerPreference( "SI_Colors7", make_property_string( g_xywindow_globals.color_gridtext ) );
2829 GlobalPreferenceSystem().registerPreference( "SI_Colors8", make_property_string( g_xywindow_globals.color_brushes ) );
2830 GlobalPreferenceSystem().registerPreference( "SI_Colors14", make_property_string( g_xywindow_globals.color_gridmajor_alt ) );
2833 GlobalPreferenceSystem().registerPreference( "XZVIS", make_property_string<ToggleShown_Bool>( g_xz_front_shown ) );
2834 GlobalPreferenceSystem().registerPreference( "YZVIS", make_property_string<ToggleShown_Bool>( g_yz_side_shown ) );
2836 Orthographic_registerPreferencesPage();
2837 Clipper_registerPreferencesPage();
2839 XYWnd::captureStates();
2840 GlobalEntityClassManager().attach( g_EntityClassMenu );
2843 void XYWindow_Destroy(){
2844 GlobalEntityClassManager().detach( g_EntityClassMenu );
2845 XYWnd::releaseStates();